Jason parks | 8fd5bc9 | 2011-01-12 16:03:31 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import com.android.internal.widget.PasswordEntryKeyboardHelper; |
| 20 | import com.android.internal.widget.PasswordEntryKeyboardView; |
| 21 | |
| 22 | import android.app.Activity; |
| 23 | import android.app.StatusBarManager; |
| 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
| 26 | import android.content.pm.PackageManager; |
| 27 | import android.inputmethodservice.KeyboardView; |
| 28 | import android.os.Bundle; |
| 29 | import android.os.IBinder; |
| 30 | import android.os.ServiceManager; |
| 31 | import android.os.SystemProperties; |
| 32 | import android.os.storage.IMountService; |
| 33 | import android.text.format.DateFormat; |
| 34 | import android.util.Log; |
| 35 | import android.view.KeyEvent; |
| 36 | import android.view.inputmethod.EditorInfo; |
| 37 | import android.widget.TextView; |
| 38 | |
| 39 | import java.util.Date; |
| 40 | |
| 41 | public class CryptKeeper extends Activity implements TextView.OnEditorActionListener { |
| 42 | private static final String DECRYPT_STATE = "trigger_restart_framework"; |
| 43 | |
| 44 | @Override |
| 45 | public void onCreate(Bundle savedInstanceState) { |
| 46 | super.onCreate(savedInstanceState); |
| 47 | setContentView(R.layout.crypt_keeper); |
| 48 | |
| 49 | String state = SystemProperties.get("vold.decrypt"); |
| 50 | if ("".equals(state) || DECRYPT_STATE.equals(state)) { |
| 51 | PackageManager pm = getPackageManager(); |
| 52 | ComponentName name = new ComponentName(this, CryptKeeper.class); |
| 53 | pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | TextView passwordEntry = (TextView) findViewById(R.id.passwordEntry); |
| 58 | passwordEntry.setOnEditorActionListener(this); |
| 59 | |
| 60 | KeyboardView keyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard); |
| 61 | |
| 62 | PasswordEntryKeyboardHelper keyboardHelper = new PasswordEntryKeyboardHelper(this, |
| 63 | keyboardView, passwordEntry, false); |
| 64 | keyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA); |
| 65 | |
| 66 | |
| 67 | passwordEntry.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_lock_idle_lock, |
| 68 | 0, 0, 0); |
| 69 | |
| 70 | String dateFormatString = getString(com.android.internal.R.string.full_wday_month_day_no_year); |
| 71 | TextView date = (TextView) findViewById(R.id.date); |
| 72 | date.setText(DateFormat.format(dateFormatString, new Date())); |
| 73 | |
| 74 | // Disable the status bar |
| 75 | StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); |
| 76 | sbm.disable(StatusBarManager.DISABLE_EXPAND | StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 77 | | StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
| 78 | | StatusBarManager.DISABLE_SYSTEM_INFO | StatusBarManager.DISABLE_NAVIGATION); |
| 79 | } |
| 80 | |
| 81 | private IMountService getMountService() { |
| 82 | IBinder service = ServiceManager.getService("mount"); |
| 83 | if (service != null) { |
| 84 | return IMountService.Stub.asInterface(service); |
| 85 | } |
| 86 | return null; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
| 91 | if (actionId == EditorInfo.IME_NULL) { |
| 92 | // Get the password |
| 93 | String password = v.getText().toString(); |
| 94 | |
| 95 | // Now that we have the password clear the password field. |
| 96 | v.setText(null); |
| 97 | |
| 98 | IMountService service = getMountService(); |
| 99 | try { |
| 100 | service.decryptStorage(password); |
| 101 | |
| 102 | // For now the only way to get here is for the password to be |
| 103 | // wrong. |
| 104 | |
| 105 | TextView tv = (TextView) findViewById(R.id.status); |
| 106 | tv.setText(R.string.try_again); |
| 107 | |
| 108 | } catch (Exception e) { |
| 109 | Log.e("CryptKeeper", "Error while decrypting...", e); |
| 110 | } |
| 111 | |
| 112 | return true; |
| 113 | } |
| 114 | return false; |
| 115 | } |
| 116 | } |