Jason parks | f821730 | 2011-01-26 13:11:42 -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 android.app.Activity; |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 20 | import android.app.StatusBarManager; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.os.Bundle; |
| 24 | import android.os.Handler; |
| 25 | import android.os.IBinder; |
| 26 | import android.os.ServiceManager; |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 27 | import android.os.UserHandle; |
Sudheer Shanka | ee2d592 | 2016-11-09 15:47:53 -0800 | [diff] [blame] | 28 | import android.os.storage.IStorageManager; |
Paul Lawrence | c04420c | 2015-05-18 13:25:01 -0700 | [diff] [blame] | 29 | import android.provider.Settings; |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 30 | import android.util.Log; |
| 31 | import android.view.LayoutInflater; |
| 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
| 34 | import android.widget.Button; |
| 35 | |
Tamas Berghammer | 265d3c2 | 2016-06-22 15:34:45 +0100 | [diff] [blame] | 36 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 37 | import com.android.internal.widget.LockPatternUtils; |
Fan Zhang | 2d0b344 | 2016-12-05 17:02:33 -0800 | [diff] [blame] | 38 | import com.android.settings.core.InstrumentedPreferenceFragment; |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 39 | |
Elliott Hughes | ed6a6ca | 2014-09-26 12:29:12 -0700 | [diff] [blame] | 40 | import java.util.Locale; |
| 41 | |
Fan Zhang | 2d0b344 | 2016-12-05 17:02:33 -0800 | [diff] [blame] | 42 | public class CryptKeeperConfirm extends InstrumentedPreferenceFragment { |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 43 | |
Elliott Hughes | ed6a6ca | 2014-09-26 12:29:12 -0700 | [diff] [blame] | 44 | private static final String TAG = "CryptKeeperConfirm"; |
| 45 | |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 46 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 47 | public int getMetricsCategory() { |
Chris Wren | 9d1bfd1 | 2016-01-26 18:04:01 -0500 | [diff] [blame] | 48 | return MetricsEvent.CRYPT_KEEPER_CONFIRM; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 51 | public static class Blank extends Activity { |
| 52 | private Handler mHandler = new Handler(); |
| 53 | |
| 54 | @Override |
| 55 | public void onCreate(Bundle savedInstanceState) { |
| 56 | super.onCreate(savedInstanceState); |
| 57 | |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 58 | setContentView(R.layout.crypt_keeper_blank); |
| 59 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 60 | if (Utils.isMonkeyRunning()) { |
| 61 | finish(); |
| 62 | } |
| 63 | |
| 64 | StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); |
| 65 | sbm.disable(StatusBarManager.DISABLE_EXPAND |
| 66 | | StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 67 | | StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
| 68 | | StatusBarManager.DISABLE_SYSTEM_INFO |
Daniel Sandler | 4d2bfd1 | 2011-10-12 15:34:23 -0400 | [diff] [blame] | 69 | | StatusBarManager.DISABLE_HOME |
Chris Wren | 0481dc7 | 2013-10-07 01:11:08 -0400 | [diff] [blame] | 70 | | StatusBarManager.DISABLE_SEARCH |
Daniel Sandler | 4d2bfd1 | 2011-10-12 15:34:23 -0400 | [diff] [blame] | 71 | | StatusBarManager.DISABLE_RECENT |
Andy Stadler | 13d6204 | 2011-01-31 19:21:37 -0800 | [diff] [blame] | 72 | | StatusBarManager.DISABLE_BACK); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 73 | |
| 74 | // Post a delayed message in 700 milliseconds to enable encryption. |
| 75 | // NOTE: The animation on this activity is set for 500 milliseconds |
| 76 | // I am giving it a little extra time to complete. |
| 77 | mHandler.postDelayed(new Runnable() { |
| 78 | public void run() { |
| 79 | IBinder service = ServiceManager.getService("mount"); |
| 80 | if (service == null) { |
Jason parks | 00046d6 | 2011-06-13 17:38:45 -0500 | [diff] [blame] | 81 | Log.e("CryptKeeper", "Failed to find the mount service"); |
| 82 | finish(); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
Sudheer Shanka | ee2d592 | 2016-11-09 15:47:53 -0800 | [diff] [blame] | 86 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 87 | try { |
| 88 | Bundle args = getIntent().getExtras(); |
Sudheer Shanka | ee2d592 | 2016-11-09 15:47:53 -0800 | [diff] [blame] | 89 | storageManager.encryptStorage(args.getInt("type", -1), args.getString("password")); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 90 | } catch (Exception e) { |
| 91 | Log.e("CryptKeeper", "Error while encrypting...", e); |
| 92 | } |
| 93 | } |
| 94 | }, 700); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | private View mContentView; |
| 99 | private Button mFinalButton; |
| 100 | private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { |
| 101 | |
| 102 | public void onClick(View v) { |
| 103 | if (Utils.isMonkeyRunning()) { |
| 104 | return; |
| 105 | } |
| 106 | |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 107 | /* WARNING - nasty hack! |
| 108 | Settings for the lock screen are not available to the crypto |
| 109 | screen (CryptKeeper) at boot. We duplicate the ones that |
| 110 | CryptKeeper needs to the crypto key/value store when they are |
| 111 | modified (see LockPatternUtils). |
| 112 | However, prior to encryption, the crypto key/value store is not |
| 113 | persisted across reboots, thus modified settings are lost to |
| 114 | CryptKeeper. |
| 115 | In order to make sure CryptKeeper had the correct settings after |
| 116 | first encrypting, we thus need to rewrite them, which ensures the |
| 117 | crypto key/value store is up to date. On encryption, this store |
| 118 | is then persisted, and the settings will be there on future |
| 119 | reboots. |
| 120 | */ |
Elliott Hughes | ed6a6ca | 2014-09-26 12:29:12 -0700 | [diff] [blame] | 121 | |
| 122 | // 1. The owner info. |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 123 | LockPatternUtils utils = new LockPatternUtils(getActivity()); |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 124 | utils.setVisiblePatternEnabled( |
Xiaohui Chen | b7c8fbf | 2015-08-27 15:46:32 -0700 | [diff] [blame] | 125 | utils.isVisiblePatternEnabled(UserHandle.USER_SYSTEM), |
| 126 | UserHandle.USER_SYSTEM); |
| 127 | if (utils.isOwnerInfoEnabled(UserHandle.USER_SYSTEM)) { |
| 128 | utils.setOwnerInfo(utils.getOwnerInfo(UserHandle.USER_SYSTEM), |
| 129 | UserHandle.USER_SYSTEM); |
Paul Lawrence | 0f11e15 | 2014-08-20 07:43:32 -0700 | [diff] [blame] | 130 | } |
Paul Lawrence | c04420c | 2015-05-18 13:25:01 -0700 | [diff] [blame] | 131 | int value = Settings.System.getInt(getContext().getContentResolver(), |
| 132 | Settings.System.TEXT_SHOW_PASSWORD, |
| 133 | 1); |
Xiaohui Chen | b7c8fbf | 2015-08-27 15:46:32 -0700 | [diff] [blame] | 134 | utils.setVisiblePasswordEnabled(value != 0, UserHandle.USER_SYSTEM); |
Paul Lawrence | c04420c | 2015-05-18 13:25:01 -0700 | [diff] [blame] | 135 | |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 136 | Intent intent = new Intent(getActivity(), Blank.class); |
| 137 | intent.putExtras(getArguments()); |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 138 | startActivity(intent); |
Elliott Hughes | ed6a6ca | 2014-09-26 12:29:12 -0700 | [diff] [blame] | 139 | |
| 140 | // 2. The system locale. |
| 141 | try { |
| 142 | IBinder service = ServiceManager.getService("mount"); |
Sudheer Shanka | ee2d592 | 2016-11-09 15:47:53 -0800 | [diff] [blame] | 143 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 144 | storageManager.setField("SystemLocale", Locale.getDefault().toLanguageTag()); |
Elliott Hughes | ed6a6ca | 2014-09-26 12:29:12 -0700 | [diff] [blame] | 145 | } catch (Exception e) { |
| 146 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 147 | } |
Jason parks | f821730 | 2011-01-26 13:11:42 -0600 | [diff] [blame] | 148 | } |
| 149 | }; |
| 150 | |
| 151 | private void establishFinalConfirmationState() { |
| 152 | mFinalButton = (Button) mContentView.findViewById(R.id.execute_encrypt); |
| 153 | mFinalButton.setOnClickListener(mFinalClickListener); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 158 | Bundle savedInstanceState) { |
| 159 | mContentView = inflater.inflate(R.layout.crypt_keeper_confirm, null); |
| 160 | establishFinalConfirmationState(); |
| 161 | return mContentView; |
| 162 | } |
| 163 | } |