欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

snapcam对焦失败导致无法拍照

程序员文章站 2022-05-08 22:35:21
...

问题:相机中,连续4、5次点屏手动对焦,会出现对焦框不消失,此时无法拍照
分析:
底层对焦没有返回,导致上层卡死
方案:
添加对焦超时机制,超时后直接判定为对焦失败

Index: packages/apps/SnapdragonCamera/src/com/android/camera/PhotoModule.java
===================================================================
--- packages/apps/SnapdragonCamera/src/com/android/camera/PhotoModule.java	(版本 1795)
+++ packages/apps/SnapdragonCamera/src/com/android/camera/PhotoModule.java	(版本 1798)
@@ -1430,6 +1430,8 @@
         public void onAutoFocus(
                 boolean focused, CameraProxy camera) {
             if (mPaused) return;
+            Log.d(TAG, "onAutoFocus focused = " + focused + ", and remove timeout runnable!");
+            mHandler.removeCallbacks(focusTimeoutResetStateRunnable); // @ + for BUG #
 
             mAutoFocusTime = System.currentTimeMillis() - mFocusStartTime;
             Log.v(TAG, "mAutoFocusTime = " + mAutoFocusTime + "ms");
@@ -2497,6 +2499,12 @@
         mFocusStartTime = System.currentTimeMillis();
         mCameraDevice.autoFocus(mHandler, mAutoFocusCallback);
         setCameraState(FOCUSING);
+        // @ + for BUG # {
+        if (mHandler.hasCallbacks(focusTimeoutResetStateRunnable)) {
+            mHandler.removeCallbacks(focusTimeoutResetStateRunnable);
+        }
+        mHandler.postDelayed(focusTimeoutResetStateRunnable, DELAY_TIME);
+        // @ + for BUG # }
     }
 
     @Override
@@ -2508,6 +2516,18 @@
         }
     }
 
+    // @ + for BUG # {
+    private final int DELAY_TIME = 5 * 1000; // 5s
+    Runnable focusTimeoutResetStateRunnable = new Runnable() {
+	    @Override
+        public void run() {
+            Log.d(TAG, "focus timeout and reset camera state");
+		    setCameraState(IDLE);
+            mFocusManager.onAutoFocus(false, false);
+        }
+    };
+    // @ + for BUG # }
+
     // Preview area is touched. Handle touch focus.
     @Override
     public void onSingleTapUp(View view, int x, int y) {
相关标签: android_camera