Restart encryption display after screen power cycle

Bug: 3414241
Change-Id: I881fc14c3e0850089b98fcbdbd86c39dde22771c
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index 770ee12..3d752a3 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -99,6 +99,7 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+        // If we are not encrypted or encrypting, get out quickly.
         String state = SystemProperties.get("vold.decrypt");
         if ("".equals(state) || DECRYPT_STATE.equals(state)) {
             // Disable the crypt keeper.
@@ -108,17 +109,6 @@
             return;
         }
 
-        // Check to see why we were started.
-        String progress = SystemProperties.get("vold.encrypt_progress");
-
-        if (!"".equals(progress)) {
-            setContentView(R.layout.crypt_keeper_progress);
-            encryptionProgressInit();
-        } else {
-            setContentView(R.layout.crypt_keeper_password_entry);
-            passwordEntryInit();
-        }
-
         // Disable the status bar
         StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE);
         sbm.disable(StatusBarManager.DISABLE_EXPAND
@@ -136,6 +126,26 @@
         }
     }
 
+    /**
+     * Note, we defer the state check and screen setup to onStart() because this will be
+     * re-run if the user clicks the power button (sleeping/waking the screen), and this is
+     * especially important if we were to lose the wakelock for any reason.
+     */
+    @Override
+    public void onStart() {
+        super.onStart();
+
+        // Check to see why we were started.
+        String progress = SystemProperties.get("vold.encrypt_progress");
+        if (!"".equals(progress)) {
+            setContentView(R.layout.crypt_keeper_progress);
+            encryptionProgressInit();
+        } else {
+            setContentView(R.layout.crypt_keeper_password_entry);
+            passwordEntryInit();
+        }
+    }
+
     @Override
     public void onStop() {
         super.onStop();