Accquire a wakelock while encrypting.
Bug: 3375491 Change-Id: Ief7dbb450800104f4977ab31f93a1e1a994b25ad
This commit is contained in:
@@ -30,6 +30,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.storage.IMountService;
|
import android.os.storage.IMountService;
|
||||||
@@ -46,7 +47,7 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class CryptKeeper extends Activity implements TextView.OnEditorActionListener {
|
public class CryptKeeper extends Activity implements TextView.OnEditorActionListener {
|
||||||
private static final String TAG = "CryptKeeper";
|
private static final String TAG = "CryptKeeper";
|
||||||
|
|
||||||
private static final String DECRYPT_STATE = "trigger_restart_framework";
|
private static final String DECRYPT_STATE = "trigger_restart_framework";
|
||||||
|
|
||||||
private static final int UPDATE_PROGRESS = 1;
|
private static final int UPDATE_PROGRESS = 1;
|
||||||
@@ -60,15 +61,15 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
|
|||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
|
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
|
|
||||||
case UPDATE_PROGRESS:
|
case UPDATE_PROGRESS:
|
||||||
String state = SystemProperties.get("vold.encrypt_progress");
|
String state = SystemProperties.get("vold.encrypt_progress");
|
||||||
|
|
||||||
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
|
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
|
||||||
progressBar.setProgress(0);
|
progressBar.setProgress(0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int progress = Integer.parseInt(state);
|
int progress = Integer.parseInt(state);
|
||||||
progressBar.setProgress(progress);
|
progressBar.setProgress(progress);
|
||||||
@@ -79,21 +80,21 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
|
|||||||
// Check the status every 5 second
|
// Check the status every 5 second
|
||||||
sendEmptyMessageDelayed(UPDATE_PROGRESS, 5000);
|
sendEmptyMessageDelayed(UPDATE_PROGRESS, 5000);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COOLDOWN:
|
case COOLDOWN:
|
||||||
TextView tv = (TextView) findViewById(R.id.status);
|
TextView tv = (TextView) findViewById(R.id.status);
|
||||||
if (mCooldown <= 0) {
|
if (mCooldown <= 0) {
|
||||||
// Re-enable the password entry
|
// Re-enable the password entry
|
||||||
EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry);
|
EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry);
|
||||||
passwordEntry.setEnabled(true);
|
passwordEntry.setEnabled(true);
|
||||||
|
|
||||||
tv.setText(R.string.try_again);
|
tv.setText(R.string.try_again);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
CharSequence tempalte = getText(R.string.crypt_keeper_cooldown);
|
CharSequence tempalte = getText(R.string.crypt_keeper_cooldown);
|
||||||
tv.setText(TextUtils.expandTemplate(tempalte, Integer.toString(mCooldown)));
|
tv.setText(TextUtils.expandTemplate(tempalte, Integer.toString(mCooldown)));
|
||||||
|
|
||||||
mCooldown--;
|
mCooldown--;
|
||||||
mHandler.sendEmptyMessageDelayed(COOLDOWN, 1000); // Tick every second
|
mHandler.sendEmptyMessageDelayed(COOLDOWN, 1000); // Tick every second
|
||||||
}
|
}
|
||||||
@@ -101,23 +102,23 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private int mFailedAttempts = 0;
|
private int mFailedAttempts = 0;
|
||||||
private int mCooldown;
|
private int mCooldown;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
String state = SystemProperties.get("vold.decrypt");
|
String state = SystemProperties.get("vold.decrypt");
|
||||||
if ("".equals(state) || DECRYPT_STATE.equals(state)) {
|
if ("".equals(state) || DECRYPT_STATE.equals(state)) {
|
||||||
// Disable the crypt keeper.
|
// Disable the crypt keeper.
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
ComponentName name = new ComponentName(this, CryptKeeper.class);
|
ComponentName name = new ComponentName(this, CryptKeeper.class);
|
||||||
pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
|
pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see why we were started.
|
// Check to see why we were started.
|
||||||
String progress = SystemProperties.get("vold.encrypt_progress");
|
String progress = SystemProperties.get("vold.encrypt_progress");
|
||||||
|
|
||||||
@@ -135,17 +136,26 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
|
|||||||
| StatusBarManager.DISABLE_NOTIFICATION_ALERTS
|
| StatusBarManager.DISABLE_NOTIFICATION_ALERTS
|
||||||
| StatusBarManager.DISABLE_SYSTEM_INFO | StatusBarManager.DISABLE_NAVIGATION);
|
| StatusBarManager.DISABLE_SYSTEM_INFO | StatusBarManager.DISABLE_NAVIGATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void encryptionProgressInit() {
|
private void encryptionProgressInit() {
|
||||||
|
// Accquire a partial wakelock to prevent the device from sleeping. Note
|
||||||
|
// we never release this wakelock as we will be restarted after the device
|
||||||
|
// is encrypted.
|
||||||
|
|
||||||
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
|
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||||
|
|
||||||
|
wakeLock.acquire();
|
||||||
|
|
||||||
mHandler.sendEmptyMessage(UPDATE_PROGRESS);
|
mHandler.sendEmptyMessage(UPDATE_PROGRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void passwordEntryInit() {
|
private void passwordEntryInit() {
|
||||||
TextView passwordEntry = (TextView) findViewById(R.id.passwordEntry);
|
TextView passwordEntry = (TextView) findViewById(R.id.passwordEntry);
|
||||||
passwordEntry.setOnEditorActionListener(this);
|
passwordEntry.setOnEditorActionListener(this);
|
||||||
|
|
||||||
KeyboardView keyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
|
KeyboardView keyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
|
||||||
|
|
||||||
PasswordEntryKeyboardHelper keyboardHelper = new PasswordEntryKeyboardHelper(this,
|
PasswordEntryKeyboardHelper keyboardHelper = new PasswordEntryKeyboardHelper(this,
|
||||||
keyboardView, passwordEntry, false);
|
keyboardView, passwordEntry, false);
|
||||||
keyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
|
keyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
|
||||||
@@ -176,7 +186,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
|
|||||||
if (TextUtils.isEmpty(password)) {
|
if (TextUtils.isEmpty(password)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we have the password clear the password field.
|
// Now that we have the password clear the password field.
|
||||||
v.setText(null);
|
v.setText(null);
|
||||||
|
|
||||||
@@ -202,7 +212,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Error while decrypting...", e);
|
Log.e(TAG, "Error while decrypting...", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user