diff options
author | Andy Huibers <andyhuibers@google.com> | 2013-11-19 22:48:14 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-11-19 22:48:14 -0800 |
commit | 6cff67680ec985520b1a4e8fd5ddaa5f682f303d (patch) | |
tree | 6ba344b248084c8b891d0014ee33672d5359beab | |
parent | 9b75b68274f42f5fe2a30ca774e2ac1bf25faf82 (diff) | |
parent | 7dc6e97c508125b94fffc15c4a8f0b6c989f396c (diff) | |
download | android_packages_apps_Snap-6cff67680ec985520b1a4e8fd5ddaa5f682f303d.tar.gz android_packages_apps_Snap-6cff67680ec985520b1a4e8fd5ddaa5f682f303d.tar.bz2 android_packages_apps_Snap-6cff67680ec985520b1a4e8fd5ddaa5f682f303d.zip |
am 7dc6e97c: Delay onResume tasks to speed up lockscreen onResume->onPause->onResume launch sequence.
* commit '7dc6e97c508125b94fffc15c4a8f0b6c989f396c':
Delay onResume tasks to speed up lockscreen onResume->onPause->onResume launch sequence.
-rw-r--r-- | src/com/android/camera/PhotoModule.java | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index daf8cfcd1..9b1853a8a 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -110,9 +110,9 @@ public class PhotoModule private static final int UPDATE_PARAM_PREFERENCE = 4; private static final int UPDATE_PARAM_ALL = -1; - // This is the timeout to keep the camera in onPause for the first time - // after screen on if the activity is started from secure lock screen. - private static final int KEEP_CAMERA_TIMEOUT = 1000; // ms + // This is the delay before we execute onResume tasks when coming + // from the lock screen, to allow time for onPause to execute. + private static final int ON_RESUME_TASKS_DELAY_MSEC = 20; private static final String DEBUG_IMAGE_PREFIX = "DEBUG_"; @@ -1172,6 +1172,7 @@ public class PhotoModule private boolean prepareCamera() { // We need to check whether the activity is paused before long // operations to ensure that onPause() can be done ASAP. + Log.v(TAG, "Open camera device."); mCameraDevice = CameraUtil.openCamera( mActivity, mCameraId, mHandler, mActivity.getCameraOpenErrorCallback()); @@ -1194,7 +1195,28 @@ public class PhotoModule @Override public void onResumeAfterSuper() { - Log.v(TAG, "On resume."); + // 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)) { + Log.v(TAG, "On resume, from lock screen."); + // Note: onPauseAfterSuper() will delete this runnable, so we will + // at most have 1 copy queued up. + mHandler.postDelayed(new Runnable() { + public void run() { + onResumeTasks(); + } + }, ON_RESUME_TASKS_DELAY_MSEC); + } else { + Log.v(TAG, "On resume."); + onResumeTasks(); + } + } + + private void onResumeTasks() { + Log.v(TAG, "Executing onResumeTasks."); if (mOpenCameraFail || mCameraDisabled) return; mJpegPictureCallbackTime = 0; @@ -1247,15 +1269,7 @@ public class PhotoModule public void onPauseAfterSuper() { Log.v(TAG, "On pause."); mUI.showPreviewCover(); - // When camera is started from secure lock screen for the first time - // after screen on, the activity gets onCreate->onResume->onPause->onResume. - // To reduce the latency, keep the camera for a short time so it does - // not need to be opened again. - if (mCameraDevice != null && mActivity.isSecureCamera() - && CameraActivity.isFirstStartAfterScreenOn()) { - CameraActivity.resetFirstStartAfterScreenOn(); - CameraHolder.instance().keep(KEEP_CAMERA_TIMEOUT); - } + // Reset the focus first. Camera CTS does not guarantee that // cancelAutoFocus is allowed after preview stops. if (mCameraDevice != null && mCameraState != PREVIEW_STOPPED) { @@ -1277,9 +1291,6 @@ public class PhotoModule // Remove the messages and runnables in the queue. mHandler.removeCallbacksAndMessages(null); - // Postpones actually releasing for KEEP_CAMERA_TIMEOUT, - // so if onResume is directly called after this, the camera - // simply needs to reconnect (takes about 2-5ms). closeCamera(); resetScreenOn(); @@ -1442,6 +1453,7 @@ public class PhotoModule } private void closeCamera() { + Log.v(TAG, "Close camera device."); if (mCameraDevice != null) { mCameraDevice.setZoomChangeListener(null); mCameraDevice.setFaceDetectionCallback(null, null); |