/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings; import android.app.Activity; import android.app.StatusBarManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.res.Resources.NotFoundException; import android.media.AudioManager; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemProperties; import android.os.UserHandle; import android.os.storage.IMountService; import android.os.storage.StorageManager; import android.provider.Settings; import android.telecom.TelecomManager; 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; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.View.OnClickListener; import android.view.View.OnKeyListener; import android.view.View.OnTouchListener; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.android.internal.telephony.PhoneConstants; import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternView; import com.android.internal.widget.LockPatternView.Cell; import java.util.ArrayList; import java.util.List; import static com.android.internal.widget.LockPatternView.DisplayMode; /** * Settings screens to show the UI flows for encrypting/decrypting the device. * * This may be started via adb for debugging the UI layout, without having to go through * encryption flows everytime. It should be noted that starting the activity in this manner * is only useful for verifying UI-correctness - the behavior will not be identical. *
 * $ adb shell pm enable com.android.settings/.CryptKeeper
 * $ adb shell am start \
 *     -e "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW" "progress" \
 *     -n com.android.settings/.CryptKeeper
 * 
*/ public class CryptKeeper extends Activity implements TextView.OnEditorActionListener, OnKeyListener, OnTouchListener, TextWatcher, OnClickListener { private static final String TAG = "CryptKeeper"; private static final String DECRYPT_STATE = "trigger_restart_framework"; /** Message sent to us to indicate encryption update progress. */ private static final int MESSAGE_UPDATE_PROGRESS = 1; /** Message sent to us to indicate alerting the user that we are waiting for password entry */ private static final int MESSAGE_NOTIFY = 2; // Constants used to control policy. private static final int MAX_FAILED_ATTEMPTS = 30; private static final int COOL_DOWN_ATTEMPTS = 10; // Intent action for launching the Emergency Dialer activity. static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL"; // Debug Intent extras so that this Activity may be started via adb for debugging UI layouts private static final String EXTRA_FORCE_VIEW = "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW"; private static final String FORCE_VIEW_PROGRESS = "progress"; private static final String FORCE_VIEW_ERROR = "error"; private static final String FORCE_VIEW_PASSWORD = "password"; /** When encryption is detected, this flag indicates whether or not we've checked for errors. */ private boolean mValidationComplete; private boolean mValidationRequested; /** A flag to indicate that the volume is in a bad state (e.g. partially encrypted). */ private boolean mEncryptionGoneBad; /** If gone bad, should we show encryption failed (false) or corrupt (true)*/ private boolean mCorrupt; /** If gone bad and mdtp is activated we should not allow recovery screen, only wipe the data */ private boolean mMdtpActivated; /** A flag to indicate when the back event should be ignored */ /** When set, blocks unlocking. Set every COOL_DOWN_ATTEMPTS attempts, only cleared by power cycling phone. */ private boolean mCooldown = false; PowerManager.WakeLock mWakeLock; private EditText mPasswordEntry; private LockPatternView mLockPatternView; private TextView mStatusText; private List