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

Commit 45c652ad authored by Chien-Yu Chen's avatar Chien-Yu Chen Committed by Android Git Automerger
Browse files

am bdde49a0: am 8f2ea4cc: am 951e2633: am 6eec00ec: Merge "Camera: Reconnect...

am bdde49a0: am 8f2ea4cc: am 951e2633: am 6eec00ec: Merge "Camera: Reconnect after camera service crashes" into mnc-dev

* commit 'bdde49a0':
  Camera: Reconnect after camera service crashes
parents b4d4cc9d bdde49a0
Loading
Loading
Loading
Loading
+47 −8
Original line number Original line Diff line number Diff line
@@ -723,6 +723,8 @@ public final class CameraManager {
        private static final String TAG = "CameraManagerGlobal";
        private static final String TAG = "CameraManagerGlobal";
        private final boolean DEBUG = false;
        private final boolean DEBUG = false;


        private final int CAMERA_SERVICE_RECONNECT_DELAY_MS = 1000;

        // Singleton instance
        // Singleton instance
        private static final CameraManagerGlobal gCameraManager =
        private static final CameraManagerGlobal gCameraManager =
            new CameraManagerGlobal();
            new CameraManagerGlobal();
@@ -1157,6 +1159,45 @@ public final class CameraManager {
            }
            }
        }
        }


        /**
         * Try to connect to camera service after some delay if any client registered camera
         * availability callback or torch status callback.
         */
        private void scheduleCameraServiceReconnectionLocked() {
            final Handler handler;

            if (mCallbackMap.size() > 0) {
                handler = mCallbackMap.valueAt(0);
            } else if (mTorchCallbackMap.size() > 0) {
                handler = mTorchCallbackMap.valueAt(0);
            } else {
                // Not necessary to reconnect camera service if no client registers a callback.
                return;
            }

            if (DEBUG) {
                Log.v(TAG, "Reconnecting Camera Service in " + CAMERA_SERVICE_RECONNECT_DELAY_MS +
                        " ms");
            }

            handler.postDelayed(
                    new Runnable() {
                        @Override
                        public void run() {
                            ICameraService cameraService = getCameraService();
                            if (cameraService == null) {
                                synchronized(mLock) {
                                    if (DEBUG) {
                                        Log.v(TAG, "Reconnecting Camera Service failed.");
                                    }
                                    scheduleCameraServiceReconnectionLocked();
                                }
                            }
                        }
                    },
                    CAMERA_SERVICE_RECONNECT_DELAY_MS);
        }

        /**
        /**
         * Listener for camera service death.
         * Listener for camera service death.
         *
         *
@@ -1171,21 +1212,19 @@ public final class CameraManager {


                mCameraService = null;
                mCameraService = null;


                // Tell listeners that the cameras and torch modes are _available_, because any
                // Tell listeners that the cameras and torch modes are unavailable and schedule a
                // existing clients will have gotten disconnected. This is optimistic under the
                // reconnection to camera service. When camera service is reconnected, the camera
                // assumption that the service will be back shortly.
                // and torch statuses will be updated.
                //
                // Without this, a camera service crash while a camera is open will never signal
                // to listeners that previously in-use cameras are now available.
                for (int i = 0; i < mDeviceStatus.size(); i++) {
                for (int i = 0; i < mDeviceStatus.size(); i++) {
                    String cameraId = mDeviceStatus.keyAt(i);
                    String cameraId = mDeviceStatus.keyAt(i);
                    onStatusChangedLocked(STATUS_PRESENT, cameraId);
                    onStatusChangedLocked(STATUS_NOT_PRESENT, cameraId);
                }
                }
                for (int i = 0; i < mTorchStatus.size(); i++) {
                for (int i = 0; i < mTorchStatus.size(); i++) {
                    String cameraId = mTorchStatus.keyAt(i);
                    String cameraId = mTorchStatus.keyAt(i);
                    onTorchStatusChangedLocked(TORCH_STATUS_AVAILABLE_OFF, cameraId);
                    onTorchStatusChangedLocked(TORCH_STATUS_NOT_AVAILABLE, cameraId);
                }
                }


                scheduleCameraServiceReconnectionLocked();
            }
            }
        }
        }