summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/util/QuickActivity.java
diff options
context:
space:
mode:
authorPuneet Lall <puneetl@google.com>2014-10-06 18:05:07 -0700
committerPuneet Lall <puneetl@google.com>2014-10-07 17:35:56 +0000
commit3e236cc8e33be40e434e73f7777bd81446277512 (patch)
treecccb515662e61a1dda1d5647c5bfa16cb8a3c4ef /src/com/android/camera/util/QuickActivity.java
parent0dd0d5ef549b489d7711d60ea1988834313851a5 (diff)
downloadandroid_packages_apps_Camera2-3e236cc8e33be40e434e73f7777bd81446277512.tar.gz
android_packages_apps_Camera2-3e236cc8e33be40e434e73f7777bd81446277512.tar.bz2
android_packages_apps_Camera2-3e236cc8e33be40e434e73f7777bd81446277512.zip
Lockscreen workaround tuning
* Remove delay of onStartTasks. This fixes b/17868175, and appears to result in ~50ms improvements to cold starts from the lockscreen and warm starts from the secure lockscreen. * Disabled double-onResume() workaround for non-secure lockscreen launches since this no longer happens when singleTask is enabled. * Reduced the delay for the double-onResume() workaround by eliminating the delay on the second call to onResume() Bug:17868175 Bug:16035858 Change-Id: I7f7611901133e429def9a03d4009e1a99caaabd0
Diffstat (limited to 'src/com/android/camera/util/QuickActivity.java')
-rw-r--r--src/com/android/camera/util/QuickActivity.java57
1 files changed, 24 insertions, 33 deletions
diff --git a/src/com/android/camera/util/QuickActivity.java b/src/com/android/camera/util/QuickActivity.java
index 957b97276..965b541ec 100644
--- a/src/com/android/camera/util/QuickActivity.java
+++ b/src/com/android/camera/util/QuickActivity.java
@@ -25,15 +25,15 @@ import android.provider.MediaStore;
import com.android.camera.debug.Log;
/**
- * Workaround for lockscreen double-onResume() bug:
+ * Workaround for secure-lockscreen double-onResume() bug:
* <p>
- * If started from the lockscreen, the activity may be quickly started, resumed,
- * paused, stopped, and then started and resumed again. This is problematic for
- * launch time from the lockscreen because we typically open the camera in
- * onResume() and close it in onPause(). These camera operations take a long
- * time to complete. To workaround it, this class filters out high-frequency
- * onResume()->onPause() sequences if the current intent indicates that we have
- * started from the lockscreen.
+ * If started from the secure-lockscreen, the activity may be quickly started,
+ * resumed, paused, stopped, and then started and resumed again. This is
+ * problematic for launch time from the secure-lockscreen because we typically open the
+ * camera in onResume() and close it in onPause(). These camera operations take
+ * a long time to complete. To workaround it, this class filters out
+ * high-frequency onResume()->onPause() sequences if the current intent
+ * indicates that we have started from the secure-lockscreen.
* </p>
* <p>
* Subclasses should override the appropriate on[Create|Start...]Tasks() method
@@ -41,7 +41,7 @@ import com.android.camera.debug.Log;
* </p>
* <p>
* Sequences of onResume() followed quickly by onPause(), when the activity is
- * started from an unsecure lockscreen will result in a quick no-op.<br>
+ * started from a secure-lockscreen will result in a quick no-op.<br>
* </p>
*/
public abstract class QuickActivity extends Activity {
@@ -55,7 +55,13 @@ public abstract class QuickActivity extends Activity {
/** A reference to the main handler on which to run lifecycle methods. */
private Handler mMainHandler;
private boolean mPaused;
- private boolean mStopped;
+ /**
+ * True if the last call to onResume() resulted in a delayed call to
+ * mOnResumeTasks which was then canceled due to an immediate onPause().
+ * This allows optimizing the common case in which the subsequent
+ * call to onResume() should execute onResumeTasks() immediately.
+ */
+ private boolean mCanceledResumeTasks = false;
/**
* A runnable for deferring tasks to be performed in onResume() if starting
@@ -65,13 +71,10 @@ public abstract class QuickActivity extends Activity {
@Override
public void run() {
logLifecycle("onResumeTasks", true);
- if (mStopped) {
- onStartTasks();
- mStopped = false;
- }
if (mPaused) {
onResumeTasks();
mPaused = false;
+ mCanceledResumeTasks = false;
}
logLifecycle("onResumeTasks", false);
}
@@ -98,7 +101,6 @@ public abstract class QuickActivity extends Activity {
onCreateTasks(bundle);
mPaused = true;
- mStopped = true;
logLifecycle("onCreate", false);
}
@@ -106,15 +108,7 @@ public abstract class QuickActivity extends Activity {
@Override
protected final void onStart() {
logLifecycle("onStart", true);
- if (delayOnResumeOnStart()) {
- // Do nothing, instead wait for onResume() to be called and then
- // execute onStartTasks() in mOnResumeTasks.
- } else {
- if (mStopped) {
- onStartTasks();
- mStopped = false;
- }
- }
+ onStartTasks();
super.onStart();
logLifecycle("onStart", false);
}
@@ -123,12 +117,13 @@ public abstract class QuickActivity extends Activity {
protected final void onResume() {
logLifecycle("onResume", true);
mMainHandler.removeCallbacks(mOnResumeTasks);
- if (delayOnResumeOnStart()) {
+ if (delayOnResumeOnStart() && !mCanceledResumeTasks) {
mMainHandler.postDelayed(mOnResumeTasks, ON_RESUME_DELAY_MILLIS);
} else {
if (mPaused) {
onResumeTasks();
mPaused = false;
+ mCanceledResumeTasks = false;
}
}
super.onResume();
@@ -142,6 +137,8 @@ public abstract class QuickActivity extends Activity {
if (!mPaused) {
onPauseTasks();
mPaused = true;
+ } else {
+ mCanceledResumeTasks = true;
}
super.onPause();
logLifecycle("onPause", false);
@@ -153,11 +150,7 @@ public abstract class QuickActivity extends Activity {
Log.v(TAG, "changing configurations");
}
logLifecycle("onStop", true);
- mMainHandler.removeCallbacks(mOnResumeTasks);
- if (!mStopped) {
- onStopTasks();
- mStopped = true;
- }
+ onStopTasks();
super.onStop();
logLifecycle("onStop", false);
}
@@ -185,11 +178,9 @@ public abstract class QuickActivity extends Activity {
private boolean delayOnResumeOnStart() {
String action = getIntent().getAction();
- boolean isLockscreenCamera =
- action.equals(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
boolean isSecureLockscreenCamera =
action.equals(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
- return isLockscreenCamera || isSecureLockscreenCamera;
+ return isSecureLockscreenCamera;
}
/**