Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09204171 authored by Mark Harman's avatar Mark Harman
Browse files

Set timeout of 2 second for focusing with original camera API.

parent 8e4aadd0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ FIXED Allow trying to switch between photo and video mode if camera fails to o
ADDED   Support for zoom with camera vendor extensions (for supported Android 13+ devices).
ADDED   Support for displaying on-screen ISO and exposure time with camera vendor extensions (for
        supported Android 13+ devices).
UPDATED Applied a timeout of 2 second for focusing with original camera API.
UPDATED Improved performance for NR photo mode.
UPDATED Drop support for notifications for background saving, due to Android 13 permissions faff.
UPDATED No longer allow a screenshot of the camera preview to show in "recent apps" view (for
+24 −2
Original line number Diff line number Diff line
@@ -1628,17 +1628,36 @@ public class CameraController1 extends CameraController {
    public void autoFocus(final CameraController.AutoFocusCallback cb, boolean capture_follows_autofocus_hint) {
        if( MyDebug.LOG )
            Log.d(TAG, "autoFocus");
        Camera.AutoFocusCallback camera_cb = new Camera.AutoFocusCallback() {
        class MyAutoFocusCallback implements Camera.AutoFocusCallback {
            boolean done_autofocus = false;
            private final Handler handler = new Handler();
            private final Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    if( MyDebug.LOG )
                        Log.d(TAG, "autofocus timeout check");
                    if( !done_autofocus ) {
                        Log.e(TAG, "autofocus timeout!");
                        done_autofocus = true;
                        cb.onAutoFocus(false);
                    }
                }
            };

            private void setTimeout() {
                handler.postDelayed(runnable, 2000); // set autofocus timeout
            }

            @Override
            public void onAutoFocus(boolean success, Camera camera) {
                if( MyDebug.LOG )
                    Log.d(TAG, "autoFocus.onAutoFocus");
                handler.removeCallbacks(runnable);
                // in theory we should only ever get one call to onAutoFocus(), but some Samsung phones at least can call the callback multiple times
                // see http://stackoverflow.com/questions/36316195/take-picture-fails-on-samsung-phones
                // needed to fix problem on Samsung S7 with flash auto/on and continuous picture focus where it would claim failed to take picture even though it'd succeeded,
                // because we repeatedly call takePicture(), and the subsequent ones cause a runtime exception
                // update: also the done_autofocus flag is needed in case we had an autofocus timeout, see above
                if( !done_autofocus ) {
                    done_autofocus = true;
                    cb.onAutoFocus(success);
@@ -1648,8 +1667,11 @@ public class CameraController1 extends CameraController {
                        Log.e(TAG, "ignore repeated autofocus");
                }
            }
        };
        }
        MyAutoFocusCallback camera_cb = new MyAutoFocusCallback();

        try {
            camera_cb.setTimeout();
            camera.autoFocus(camera_cb);
        }
        catch(RuntimeException e) {