Speed up lockscreen start-up time.
Bug: 16375664
- Avoid unnecessary camera open/close loop (~350ms)
- Don't load sounds and do other init work when not needed.
Change-Id: I5d297913dcbd3100034c3915119cc3c818f330d3
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index f3e5d6b..6d93d0b 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -438,8 +438,6 @@
// This must be done before startPreview.
mIsImageCaptureIntent = isImageCaptureIntent();
- mActivity.getCameraProvider().requestCamera(mCameraId);
-
mQuickCapture = mActivity.getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false);
mLocationManager = mActivity.getLocationManager();
mSensorManager = (SensorManager) (mActivity.getSystemService(Context.SENSOR_SERVICE));
@@ -1530,6 +1528,16 @@
return;
}
Log.v(TAG, "Executing onResumeTasks.");
+
+ mCountdownSoundPlayer.loadSounds();
+ if (mFocusManager != null) {
+ // If camera is not open when resume is called, focus manager will
+ // not be initialized yet, in which case it will start listening to
+ // preview area size change later in the initialization.
+ mAppController.addPreviewAreaSizeChangedListener(mFocusManager);
+ }
+ mAppController.addPreviewAreaSizeChangedListener(mUI);
+
CameraProvider camProvider = mActivity.getCameraProvider();
if (camProvider == null) {
// No camera provider, the Activity is destroyed already.
@@ -1560,6 +1568,9 @@
if (msensor != null) {
mSensorManager.registerListener(this, msensor, SensorManager.SENSOR_DELAY_NORMAL);
}
+
+ getServices().getRemoteShutterListener().onModuleReady(this);
+ SessionStatsCollector.instance().sessionActive(true);
}
/**
@@ -1596,25 +1607,23 @@
mAppController.addPreviewAreaSizeChangedListener(mFocusManager);
}
+ /**
+ * @return Whether we are resuming from within the lockscreen.
+ */
+ private boolean isResumeFromLockscreen() {
+ String action = mActivity.getIntent().getAction();
+ return (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(action)
+ || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action));
+ }
+
@Override
public void resume() {
mPaused = false;
- mCountdownSoundPlayer.loadSounds();
- if (mFocusManager != null) {
- // If camera is not open when resume is called, focus manager will
- // not
- // be initialized yet, in which case it will start listening to
- // preview area size change later in the initialization.
- mAppController.addPreviewAreaSizeChangedListener(mFocusManager);
- }
- mAppController.addPreviewAreaSizeChangedListener(mUI);
// Add delay on resume from lock screen only, in order to to speed up
// the onResume --> onPause --> onResume cycle from lock screen.
// Don't do always because letting go of thread can cause delay.
- String action = mActivity.getIntent().getAction();
- if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(action)
- || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)) {
+ if (isResumeFromLockscreen()) {
Log.v(TAG, "On resume, from lock screen.");
// Note: onPauseAfterSuper() will delete this runnable, so we will
// at most have 1 copy queued up.
@@ -1623,8 +1632,6 @@
Log.v(TAG, "On resume.");
onResumeTasks();
}
- getServices().getRemoteShutterListener().onModuleReady(this);
- SessionStatsCollector.instance().sessionActive(true);
}
@Override