OSDN Git Service

Show time to go while encrypting drive
authorPaul Lawrence <paullawrence@google.com>
Thu, 5 Jun 2014 14:24:23 +0000 (07:24 -0700)
committerPaul Lawrence <paullawrence@google.com>
Thu, 5 Jun 2014 20:15:37 +0000 (20:15 +0000)
Bug: 15159008
Change-Id: I9bb6f86c2941cbd93572c25716d21691a4fefbef

res/values/strings.xml
src/com/android/settings/CryptKeeper.java

index 4fc861a..ee37715 100644 (file)
     <!-- Informational text on the progress screen while encrypting the device -->
     <string name="crypt_keeper_setup_description" product="default">Wait while your phone
     is being encrypted. <xliff:g id="percent" example="50">^1</xliff:g>% complete.</string>
+    <string name="crypt_keeper_setup_time_remaining" product="tablet">Wait while your tablet
+    is being encrypted. Time remaining: <xliff:g id="duration" example="1:23">^1</xliff:g></string>
+    <string name="crypt_keeper_setup_time_remaining" product="default">Wait while your phone
+    is being encrypted. Time remaining: <xliff:g id="duration" example="1:23">^1</xliff:g></string>
 
     <!-- Informational text on the password entry screen when password entry fails-->
     <string name="crypt_keeper_cooldown">Try again in <xliff:g id="delay" example="15">^1</xliff:g> seconds.</string>
index d24c741..4e20823 100644 (file)
@@ -40,6 +40,7 @@ import android.telephony.TelephonyManager;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
+import android.text.format.DateUtils;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
@@ -508,23 +509,40 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
             return;
         }
 
-        int progress = 0;
+        // Get status as percentage first
+        CharSequence status = getText(R.string.crypt_keeper_setup_description);
+        int percent = 0;
         try {
             // Force a 50% progress state when debugging the view.
-            progress = isDebugView() ? 50 : Integer.parseInt(state);
+            percent = isDebugView() ? 50 : Integer.parseInt(state);
         } catch (Exception e) {
             Log.w(TAG, "Error parsing progress: " + e.toString());
         }
+        String progress = Integer.toString(percent);
 
-        final CharSequence status = getText(R.string.crypt_keeper_setup_description);
+        // Now try to get status as time remaining and replace as appropriate
         Log.v(TAG, "Encryption progress: " + progress);
+        try {
+            final String timeProperty = SystemProperties.get("vold.encrypt_time_remaining");
+            int time = Integer.parseInt(timeProperty);
+            if (time >= 0) {
+                // Round up to multiple of 10 - this way display is less jerky
+                time = (time + 9) / 10 * 10;
+                progress = DateUtils.formatElapsedTime(time);
+                status = getText(R.string.crypt_keeper_setup_time_remaining);
+            }
+        } catch (Exception e) {
+            // Will happen if no time etc - show percentage
+        }
+
         final TextView tv = (TextView) findViewById(R.id.status);
         if (tv != null) {
-            tv.setText(TextUtils.expandTemplate(status, Integer.toString(progress)));
+            tv.setText(TextUtils.expandTemplate(status, progress));
         }
-        // Check the progress every 5 seconds
+
+        // Check the progress every 1 seconds
         mHandler.removeMessages(MESSAGE_UPDATE_PROGRESS);
-        mHandler.sendEmptyMessageDelayed(MESSAGE_UPDATE_PROGRESS, 5000);
+        mHandler.sendEmptyMessageDelayed(MESSAGE_UPDATE_PROGRESS, 1000);
     }
 
     /** Disable password input for a while to force the user to waste time between retries */