diff options
author | Andy Stadler <stadler@google.com> | 2011-02-01 15:34:59 -0800 |
---|---|---|
committer | Andy Stadler <stadler@google.com> | 2011-02-01 15:34:59 -0800 |
commit | 1499740c13af5fbd5766a87825c3e789b37bab24 (patch) | |
tree | afa12ae237cc028df604a9b6530946b3b0db6561 | |
parent | 71863f3b48588cbbcae93bc784ebefbeec47c25f (diff) | |
download | packages_apps_settings-1499740c13af5fbd5766a87825c3e789b37bab24.zip packages_apps_settings-1499740c13af5fbd5766a87825c3e789b37bab24.tar.gz packages_apps_settings-1499740c13af5fbd5766a87825c3e789b37bab24.tar.bz2 |
Preserve wakelock through rotation
Bug: 3381450
Change-Id: Iea09d050231dfe31848666bdb186a5531d90e7bc
-rw-r--r-- | src/com/android/settings/CryptKeeper.java | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index cbad3f0..770ee12 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -57,6 +57,20 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList private static final int COOL_DOWN_ATTEMPTS = 10; private static final int COOL_DOWN_INTERVAL = 30; // 30 seconds + private int mCooldown; + PowerManager.WakeLock mWakeLock; + + /** + * Used to propagate state through configuration changes (e.g. screen rotation) + */ + private static class NonConfigurationInstanceState { + final PowerManager.WakeLock wakelock; + + NonConfigurationInstanceState(PowerManager.WakeLock _wakelock) { + wakelock = _wakelock; + } + } + // This activity is used to fade the screen to black after the password is entered. public static class Blank extends Activity { @Override @@ -81,9 +95,6 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } }; - private int mCooldown; - PowerManager.WakeLock mWakeLock; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -116,6 +127,13 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList | StatusBarManager.DISABLE_SYSTEM_INFO | StatusBarManager.DISABLE_NAVIGATION | StatusBarManager.DISABLE_BACK); + + // Check for (and recover) retained instance data + Object lastInstance = getLastNonConfigurationInstance(); + if (lastInstance instanceof NonConfigurationInstanceState) { + NonConfigurationInstanceState retained = (NonConfigurationInstanceState) lastInstance; + mWakeLock = retained.wakelock; + } } @Override @@ -124,6 +142,23 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList mHandler.removeMessages(COOLDOWN); mHandler.removeMessages(UPDATE_PROGRESS); + } + + /** + * Reconfiguring, so propagate the wakelock to the next instance. This runs between onStop() + * and onDestroy() and only if we are changing configuration (e.g. rotation). Also clears + * mWakeLock so the subsequent call to onDestroy does not release it. + */ + @Override + public Object onRetainNonConfigurationInstance() { + NonConfigurationInstanceState state = new NonConfigurationInstanceState(mWakeLock); + mWakeLock = null; + return state; + } + + @Override + public void onDestroy() { + super.onDestroy(); if (mWakeLock != null) { mWakeLock.release(); |