Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 17 | package com.android.server; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 18 | |
Adrian Roos | 230635e | 2015-01-07 20:50:29 +0100 | [diff] [blame] | 19 | import android.app.admin.DevicePolicyManager; |
Amith Yamasani | 072543f | 2015-02-13 11:09:45 -0800 | [diff] [blame] | 20 | import android.app.backup.BackupManager; |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 22 | import android.content.ContentResolver; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Jim Miller | 158fe19 | 2013-04-17 15:23:55 -0700 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 27 | import android.content.pm.UserInfo; |
| 28 | |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 29 | import static android.Manifest.permission.ACCESS_KEYGUARD_SECURE_STORAGE; |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 30 | import static android.content.Context.USER_SERVICE; |
Jim Miller | 158fe19 | 2013-04-17 15:23:55 -0700 | [diff] [blame] | 31 | import static android.Manifest.permission.READ_PROFILE; |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 32 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 33 | import android.database.sqlite.SQLiteDatabase; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 34 | import android.os.Binder; |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 35 | import android.os.IBinder; |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 36 | import android.os.Process; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 37 | import android.os.RemoteException; |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 38 | import android.os.storage.IMountService; |
| 39 | import android.os.ServiceManager; |
Amith Yamasani | d1645f8 | 2012-06-12 11:53:26 -0700 | [diff] [blame] | 40 | import android.os.SystemProperties; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 42 | import android.os.UserManager; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 43 | import android.provider.Settings; |
| 44 | import android.provider.Settings.Secure; |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 45 | import android.provider.Settings.SettingNotFoundException; |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 46 | import android.security.KeyStore; |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 47 | import android.service.gatekeeper.IGateKeeperService; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 48 | import android.text.TextUtils; |
| 49 | import android.util.Slog; |
| 50 | |
Amith Yamasani | 072543f | 2015-02-13 11:09:45 -0800 | [diff] [blame] | 51 | import com.android.internal.util.ArrayUtils; |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 52 | import com.android.internal.widget.ILockSettings; |
| 53 | import com.android.internal.widget.LockPatternUtils; |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 54 | import com.android.server.LockSettingsStorage.CredentialHash; |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 55 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 56 | import java.util.Arrays; |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 57 | import java.util.List; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Keeps the lock pattern/password data and related settings for each user. |
| 61 | * Used by LockPatternUtils. Needs to be a service because Settings app also needs |
| 62 | * to be able to save lockscreen information for secondary users. |
| 63 | * @hide |
| 64 | */ |
| 65 | public class LockSettingsService extends ILockSettings.Stub { |
| 66 | |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 67 | private static final String PERMISSION = ACCESS_KEYGUARD_SECURE_STORAGE; |
Adrian Roos | 4f78845 | 2014-05-22 20:45:59 +0200 | [diff] [blame] | 68 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 69 | private static final String TAG = "LockSettingsService"; |
| 70 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 71 | private final Context mContext; |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 72 | |
| 73 | private final LockSettingsStorage mStorage; |
| 74 | |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 75 | private LockPatternUtils mLockPatternUtils; |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 76 | private boolean mFirstCallToVold; |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 77 | private IGateKeeperService mGateKeeperService; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 78 | |
| 79 | public LockSettingsService(Context context) { |
| 80 | mContext = context; |
| 81 | // Open the database |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 82 | |
| 83 | mLockPatternUtils = new LockPatternUtils(context); |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 84 | mFirstCallToVold = true; |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 85 | |
| 86 | IntentFilter filter = new IntentFilter(); |
| 87 | filter.addAction(Intent.ACTION_USER_ADDED); |
Adrian Roos | 3dcae68 | 2014-10-29 14:43:56 +0100 | [diff] [blame] | 88 | filter.addAction(Intent.ACTION_USER_STARTING); |
Adrian Roos | db0f76e | 2015-01-07 22:19:38 +0100 | [diff] [blame] | 89 | filter.addAction(Intent.ACTION_USER_REMOVED); |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 90 | mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null); |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 91 | |
| 92 | mStorage = new LockSettingsStorage(context, new LockSettingsStorage.Callback() { |
| 93 | @Override |
| 94 | public void initialize(SQLiteDatabase db) { |
| 95 | // Get the lockscreen default from a system property, if available |
| 96 | boolean lockScreenDisable = SystemProperties.getBoolean( |
| 97 | "ro.lockscreen.disable.default", false); |
| 98 | if (lockScreenDisable) { |
| 99 | mStorage.writeKeyValue(db, LockPatternUtils.DISABLE_LOCKSCREEN_KEY, "1", 0); |
| 100 | } |
| 101 | } |
| 102 | }); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 105 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 106 | @Override |
| 107 | public void onReceive(Context context, Intent intent) { |
Robin Lee | 1096cf8 | 2014-09-01 16:52:47 +0100 | [diff] [blame] | 108 | if (Intent.ACTION_USER_ADDED.equals(intent.getAction())) { |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 109 | final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); |
Robin Lee | 49d810c | 2014-09-23 13:50:22 +0100 | [diff] [blame] | 110 | final int userSysUid = UserHandle.getUid(userHandle, Process.SYSTEM_UID); |
| 111 | final KeyStore ks = KeyStore.getInstance(); |
| 112 | |
| 113 | // Clear up keystore in case anything was left behind by previous users |
| 114 | ks.resetUid(userSysUid); |
| 115 | |
| 116 | // If this user has a parent, sync with its keystore password |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 117 | final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE); |
| 118 | final UserInfo parentInfo = um.getProfileParent(userHandle); |
| 119 | if (parentInfo != null) { |
Robin Lee | 49d810c | 2014-09-23 13:50:22 +0100 | [diff] [blame] | 120 | final int parentSysUid = UserHandle.getUid(parentInfo.id, Process.SYSTEM_UID); |
| 121 | ks.syncUid(parentSysUid, userSysUid); |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 122 | } |
Adrian Roos | 3dcae68 | 2014-10-29 14:43:56 +0100 | [diff] [blame] | 123 | } else if (Intent.ACTION_USER_STARTING.equals(intent.getAction())) { |
| 124 | final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); |
| 125 | mStorage.prefetchUser(userHandle); |
Adrian Roos | db0f76e | 2015-01-07 22:19:38 +0100 | [diff] [blame] | 126 | } else if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) { |
| 127 | final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); |
| 128 | if (userHandle > 0) { |
| 129 | removeUser(userHandle); |
| 130 | } |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | }; |
| 134 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 135 | public void systemReady() { |
| 136 | migrateOldData(); |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 137 | getGateKeeperService(); |
Adrian Roos | 3dcae68 | 2014-10-29 14:43:56 +0100 | [diff] [blame] | 138 | mStorage.prefetchUser(UserHandle.USER_OWNER); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | private void migrateOldData() { |
| 142 | try { |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 143 | // These Settings moved before multi-user was enabled, so we only have to do it for the |
| 144 | // root user. |
| 145 | if (getString("migrated", null, 0) == null) { |
| 146 | final ContentResolver cr = mContext.getContentResolver(); |
| 147 | for (String validSetting : VALID_SETTINGS) { |
| 148 | String value = Settings.Secure.getString(cr, validSetting); |
| 149 | if (value != null) { |
| 150 | setString(validSetting, value, 0); |
| 151 | } |
| 152 | } |
| 153 | // No need to move the password / pattern files. They're already in the right place. |
| 154 | setString("migrated", "true", 0); |
| 155 | Slog.i(TAG, "Migrated lock settings to new location"); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 158 | // These Settings changed after multi-user was enabled, hence need to be moved per user. |
| 159 | if (getString("migrated_user_specific", null, 0) == null) { |
| 160 | final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE); |
| 161 | final ContentResolver cr = mContext.getContentResolver(); |
| 162 | List<UserInfo> users = um.getUsers(); |
| 163 | for (int user = 0; user < users.size(); user++) { |
Jim Miller | 2d8ecf9d | 2013-04-22 17:17:03 -0700 | [diff] [blame] | 164 | // Migrate owner info |
| 165 | final int userId = users.get(user).id; |
| 166 | final String OWNER_INFO = Secure.LOCK_SCREEN_OWNER_INFO; |
| 167 | String ownerInfo = Settings.Secure.getStringForUser(cr, OWNER_INFO, userId); |
| 168 | if (ownerInfo != null) { |
| 169 | setString(OWNER_INFO, ownerInfo, userId); |
| 170 | Settings.Secure.putStringForUser(cr, ownerInfo, "", userId); |
| 171 | } |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 172 | |
Jim Miller | 2d8ecf9d | 2013-04-22 17:17:03 -0700 | [diff] [blame] | 173 | // Migrate owner info enabled. Note there was a bug where older platforms only |
| 174 | // stored this value if the checkbox was toggled at least once. The code detects |
| 175 | // this case by handling the exception. |
| 176 | final String OWNER_INFO_ENABLED = Secure.LOCK_SCREEN_OWNER_INFO_ENABLED; |
| 177 | boolean enabled; |
| 178 | try { |
| 179 | int ivalue = Settings.Secure.getIntForUser(cr, OWNER_INFO_ENABLED, userId); |
| 180 | enabled = ivalue != 0; |
| 181 | setLong(OWNER_INFO_ENABLED, enabled ? 1 : 0, userId); |
| 182 | } catch (SettingNotFoundException e) { |
| 183 | // Setting was never stored. Store it if the string is not empty. |
| 184 | if (!TextUtils.isEmpty(ownerInfo)) { |
| 185 | setLong(OWNER_INFO_ENABLED, 1, userId); |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
Jim Miller | 2d8ecf9d | 2013-04-22 17:17:03 -0700 | [diff] [blame] | 188 | Settings.Secure.putIntForUser(cr, OWNER_INFO_ENABLED, 0, userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 189 | } |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 190 | // No need to move the password / pattern files. They're already in the right place. |
| 191 | setString("migrated_user_specific", "true", 0); |
| 192 | Slog.i(TAG, "Migrated per-user lock settings to new location"); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 193 | } |
Adrian Roos | 230635e | 2015-01-07 20:50:29 +0100 | [diff] [blame] | 194 | |
| 195 | // Migrates biometric weak such that the fallback mechanism becomes the primary. |
| 196 | if (getString("migrated_biometric_weak", null, 0) == null) { |
| 197 | final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE); |
| 198 | List<UserInfo> users = um.getUsers(); |
| 199 | for (int i = 0; i < users.size(); i++) { |
| 200 | int userId = users.get(i).id; |
| 201 | long type = getLong(LockPatternUtils.PASSWORD_TYPE_KEY, |
| 202 | DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, |
| 203 | userId); |
| 204 | long alternateType = getLong(LockPatternUtils.PASSWORD_TYPE_ALTERNATE_KEY, |
| 205 | DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, |
| 206 | userId); |
| 207 | if (type == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK) { |
| 208 | setLong(LockPatternUtils.PASSWORD_TYPE_KEY, |
| 209 | alternateType, |
| 210 | userId); |
| 211 | } |
| 212 | setLong(LockPatternUtils.PASSWORD_TYPE_ALTERNATE_KEY, |
| 213 | DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, |
| 214 | userId); |
| 215 | } |
| 216 | setString("migrated_biometric_weak", "true", 0); |
| 217 | Slog.i(TAG, "Migrated biometric weak to use the fallback instead"); |
| 218 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 219 | } catch (RemoteException re) { |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 220 | Slog.e(TAG, "Unable to migrate old data", re); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 224 | private final void checkWritePermission(int userId) { |
Jim Miller | 505329b | 2013-11-08 13:25:36 -0800 | [diff] [blame] | 225 | mContext.enforceCallingOrSelfPermission(PERMISSION, "LockSettingsWrite"); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 228 | private final void checkPasswordReadPermission(int userId) { |
Jim Miller | 505329b | 2013-11-08 13:25:36 -0800 | [diff] [blame] | 229 | mContext.enforceCallingOrSelfPermission(PERMISSION, "LockSettingsRead"); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Jim Miller | 158fe19 | 2013-04-17 15:23:55 -0700 | [diff] [blame] | 232 | private final void checkReadPermission(String requestedKey, int userId) { |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 233 | final int callingUid = Binder.getCallingUid(); |
Adrian Roos | 001b00d | 2015-02-24 17:08:48 +0100 | [diff] [blame] | 234 | |
Jim Miller | 158fe19 | 2013-04-17 15:23:55 -0700 | [diff] [blame] | 235 | for (int i = 0; i < READ_PROFILE_PROTECTED_SETTINGS.length; i++) { |
| 236 | String key = READ_PROFILE_PROTECTED_SETTINGS[i]; |
| 237 | if (key.equals(requestedKey) && mContext.checkCallingOrSelfPermission(READ_PROFILE) |
| 238 | != PackageManager.PERMISSION_GRANTED) { |
| 239 | throw new SecurityException("uid=" + callingUid |
| 240 | + " needs permission " + READ_PROFILE + " to read " |
| 241 | + requestedKey + " for user " + userId); |
| 242 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 243 | } |
Adrian Roos | 001b00d | 2015-02-24 17:08:48 +0100 | [diff] [blame] | 244 | |
| 245 | for (int i = 0; i < READ_PASSWORD_PROTECTED_SETTINGS.length; i++) { |
| 246 | String key = READ_PASSWORD_PROTECTED_SETTINGS[i]; |
| 247 | if (key.equals(requestedKey) && mContext.checkCallingOrSelfPermission(PERMISSION) |
| 248 | != PackageManager.PERMISSION_GRANTED) { |
| 249 | throw new SecurityException("uid=" + callingUid |
| 250 | + " needs permission " + PERMISSION + " to read " |
| 251 | + requestedKey + " for user " + userId); |
| 252 | } |
| 253 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public void setBoolean(String key, boolean value, int userId) throws RemoteException { |
| 258 | checkWritePermission(userId); |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 259 | setStringUnchecked(key, userId, value ? "1" : "0"); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void setLong(String key, long value, int userId) throws RemoteException { |
| 264 | checkWritePermission(userId); |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 265 | setStringUnchecked(key, userId, Long.toString(value)); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public void setString(String key, String value, int userId) throws RemoteException { |
| 270 | checkWritePermission(userId); |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 271 | setStringUnchecked(key, userId, value); |
| 272 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 273 | |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 274 | private void setStringUnchecked(String key, int userId, String value) { |
| 275 | mStorage.writeKeyValue(key, value, userId); |
Amith Yamasani | 072543f | 2015-02-13 11:09:45 -0800 | [diff] [blame] | 276 | if (ArrayUtils.contains(SETTINGS_TO_BACKUP, key)) { |
| 277 | BackupManager.dataChanged("com.android.providers.settings"); |
| 278 | } |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public boolean getBoolean(String key, boolean defaultValue, int userId) throws RemoteException { |
Jim Miller | 158fe19 | 2013-04-17 15:23:55 -0700 | [diff] [blame] | 283 | checkReadPermission(key, userId); |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 284 | String value = getStringUnchecked(key, null, userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 285 | return TextUtils.isEmpty(value) ? |
| 286 | defaultValue : (value.equals("1") || value.equals("true")); |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public long getLong(String key, long defaultValue, int userId) throws RemoteException { |
Jim Miller | 158fe19 | 2013-04-17 15:23:55 -0700 | [diff] [blame] | 291 | checkReadPermission(key, userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 292 | |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 293 | String value = getStringUnchecked(key, null, userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 294 | return TextUtils.isEmpty(value) ? defaultValue : Long.parseLong(value); |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public String getString(String key, String defaultValue, int userId) throws RemoteException { |
Jim Miller | 158fe19 | 2013-04-17 15:23:55 -0700 | [diff] [blame] | 299 | checkReadPermission(key, userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 300 | |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 301 | return getStringUnchecked(key, defaultValue, userId); |
| 302 | } |
| 303 | |
| 304 | public String getStringUnchecked(String key, String defaultValue, int userId) { |
| 305 | if (Settings.Secure.LOCK_PATTERN_ENABLED.equals(key)) { |
| 306 | return mLockPatternUtils.isLockPatternEnabled(userId) ? "1" : "0"; |
| 307 | } |
| 308 | |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 309 | return mStorage.readKeyValue(key, defaultValue, userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Adrian Roos | 4f78845 | 2014-05-22 20:45:59 +0200 | [diff] [blame] | 312 | @Override |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 313 | public boolean havePassword(int userId) throws RemoteException { |
| 314 | // Do we need a permissions check here? |
| 315 | |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 316 | return mStorage.hasPassword(userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | @Override |
| 320 | public boolean havePattern(int userId) throws RemoteException { |
| 321 | // Do we need a permissions check here? |
| 322 | |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 323 | return mStorage.hasPattern(userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 326 | private void maybeUpdateKeystore(String password, int userHandle) { |
| 327 | final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE); |
| 328 | final KeyStore ks = KeyStore.getInstance(); |
| 329 | |
| 330 | final List<UserInfo> profiles = um.getProfiles(userHandle); |
| 331 | boolean shouldReset = TextUtils.isEmpty(password); |
| 332 | |
| 333 | // For historical reasons, don't wipe a non-empty keystore if we have a single user with a |
| 334 | // single profile. |
| 335 | if (userHandle == UserHandle.USER_OWNER && profiles.size() == 1) { |
| 336 | if (!ks.isEmpty()) { |
| 337 | shouldReset = false; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | for (UserInfo pi : profiles) { |
| 342 | final int profileUid = UserHandle.getUid(pi.id, Process.SYSTEM_UID); |
| 343 | if (shouldReset) { |
| 344 | ks.resetUid(profileUid); |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 345 | } else { |
Robin Lee | f0246a8 | 2014-08-13 09:50:25 +0100 | [diff] [blame] | 346 | ks.passwordUid(password, profileUid); |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 351 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 352 | private byte[] getCurrentHandle(int userId) { |
| 353 | CredentialHash credential; |
| 354 | byte[] currentHandle; |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 355 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 356 | int currentHandleType = mStorage.getStoredCredentialType(userId); |
| 357 | switch (currentHandleType) { |
| 358 | case CredentialHash.TYPE_PATTERN: |
| 359 | credential = mStorage.readPatternHash(userId); |
| 360 | currentHandle = credential != null |
| 361 | ? credential.hash |
| 362 | : null; |
| 363 | break; |
| 364 | case CredentialHash.TYPE_PASSWORD: |
| 365 | credential = mStorage.readPasswordHash(userId); |
| 366 | currentHandle = credential != null |
| 367 | ? credential.hash |
| 368 | : null; |
| 369 | break; |
| 370 | case CredentialHash.TYPE_NONE: |
| 371 | default: |
| 372 | currentHandle = null; |
| 373 | break; |
| 374 | } |
| 375 | |
| 376 | // sanity check |
| 377 | if (currentHandleType != CredentialHash.TYPE_NONE && currentHandle == null) { |
| 378 | Slog.e(TAG, "Stored handle type [" + currentHandleType + "] but no handle available"); |
| 379 | } |
| 380 | |
| 381 | return currentHandle; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 384 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 385 | @Override |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 386 | public void setLockPattern(String pattern, String savedCredential, int userId) |
| 387 | throws RemoteException { |
| 388 | byte[] currentHandle = getCurrentHandle(userId); |
| 389 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 390 | if (pattern == null) { |
| 391 | mStorage.writePatternHash(null, userId); |
| 392 | return; |
| 393 | } |
| 394 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 395 | if (currentHandle == null) { |
| 396 | if (savedCredential != null) { |
| 397 | Slog.w(TAG, "Saved credential provided, but none stored"); |
| 398 | } |
| 399 | savedCredential = null; |
| 400 | } |
| 401 | |
| 402 | byte[] enrolledHandle = enrollCredential(currentHandle, savedCredential, pattern, userId); |
| 403 | if (enrolledHandle != null) { |
| 404 | mStorage.writePatternHash(enrolledHandle, userId); |
| 405 | } else { |
| 406 | Slog.e(TAG, "Failed to enroll pattern"); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | |
| 411 | @Override |
| 412 | public void setLockPassword(String password, String savedCredential, int userId) |
| 413 | throws RemoteException { |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 414 | byte[] currentHandle = getCurrentHandle(userId); |
| 415 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 416 | if (password == null) { |
| 417 | mStorage.writePasswordHash(null, userId); |
| 418 | return; |
| 419 | } |
| 420 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 421 | if (currentHandle == null) { |
| 422 | if (savedCredential != null) { |
| 423 | Slog.w(TAG, "Saved credential provided, but none stored"); |
| 424 | } |
| 425 | savedCredential = null; |
| 426 | } |
| 427 | |
| 428 | byte[] enrolledHandle = enrollCredential(currentHandle, savedCredential, password, userId); |
| 429 | if (enrolledHandle != null) { |
| 430 | mStorage.writePasswordHash(enrolledHandle, userId); |
| 431 | } else { |
| 432 | Slog.e(TAG, "Failed to enroll password"); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | private byte[] enrollCredential(byte[] enrolledHandle, |
| 437 | String enrolledCredential, String toEnroll, int userId) |
| 438 | throws RemoteException { |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 439 | checkWritePermission(userId); |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 440 | byte[] enrolledCredentialBytes = enrolledCredential == null |
| 441 | ? null |
| 442 | : enrolledCredential.getBytes(); |
| 443 | byte[] toEnrollBytes = toEnroll == null |
| 444 | ? null |
| 445 | : toEnroll.getBytes(); |
| 446 | byte[] hash = getGateKeeperService().enroll(userId, enrolledHandle, enrolledCredentialBytes, |
| 447 | toEnrollBytes); |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 448 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 449 | if (hash != null) { |
| 450 | maybeUpdateKeystore(toEnroll, userId); |
| 451 | } |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 452 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 453 | return hash; |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | @Override |
| 457 | public boolean checkPattern(String pattern, int userId) throws RemoteException { |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 458 | try { |
| 459 | doVerifyPattern(pattern, false, 0, userId); |
| 460 | } catch (VerificationFailedException ex) { |
| 461 | return false; |
| 462 | } |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 463 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 464 | return true; |
| 465 | } |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 466 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 467 | @Override |
| 468 | public byte[] verifyPattern(String pattern, long challenge, int userId) |
| 469 | throws RemoteException { |
| 470 | try { |
| 471 | return doVerifyPattern(pattern, true, challenge, userId); |
| 472 | } catch (VerificationFailedException ex) { |
| 473 | return null; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | private byte[] doVerifyPattern(String pattern, boolean hasChallenge, long challenge, |
| 478 | int userId) throws VerificationFailedException, RemoteException { |
| 479 | checkPasswordReadPermission(userId); |
| 480 | |
| 481 | CredentialHash storedHash = mStorage.readPatternHash(userId); |
| 482 | |
| 483 | if ((storedHash == null || storedHash.hash.length == 0) && TextUtils.isEmpty(pattern)) { |
| 484 | // don't need to pass empty passwords to GateKeeper |
| 485 | return null; |
| 486 | } |
| 487 | |
| 488 | if (TextUtils.isEmpty(pattern)) { |
| 489 | throw new VerificationFailedException(); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 490 | } |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 491 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 492 | if (storedHash.version == CredentialHash.VERSION_LEGACY) { |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 493 | byte[] hash = mLockPatternUtils.patternToHash( |
| 494 | mLockPatternUtils.stringToPattern(pattern)); |
| 495 | if (Arrays.equals(hash, storedHash.hash)) { |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 496 | maybeUpdateKeystore(pattern, userId); |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 497 | // migrate password to GateKeeper |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 498 | setLockPattern(pattern, null, userId); |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 499 | if (!hasChallenge) { |
| 500 | return null; |
| 501 | } |
| 502 | // Fall through to get the auth token. Technically this should never happen, |
| 503 | // as a user that had a legacy pattern would have to unlock their device |
| 504 | // before getting to a flow with a challenge, but supporting for consistency. |
| 505 | } else { |
| 506 | throw new VerificationFailedException(); |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 507 | } |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 510 | byte[] token = null; |
| 511 | if (hasChallenge) { |
| 512 | token = getGateKeeperService() |
| 513 | .verifyChallenge(userId, challenge, storedHash.hash, pattern.getBytes()); |
| 514 | if (token == null) { |
| 515 | throw new VerificationFailedException(); |
| 516 | } |
| 517 | } else if (!getGateKeeperService().verify(userId, storedHash.hash, pattern.getBytes())) { |
| 518 | throw new VerificationFailedException(); |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 519 | } |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 520 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 521 | // pattern has matched |
| 522 | maybeUpdateKeystore(pattern, userId); |
| 523 | return token; |
| 524 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | @Override |
Jim Miller | de1af08 | 2013-09-11 14:58:26 -0700 | [diff] [blame] | 528 | public boolean checkPassword(String password, int userId) throws RemoteException { |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 529 | try { |
| 530 | doVerifyPassword(password, false, 0, userId); |
| 531 | } catch (VerificationFailedException ex) { |
| 532 | return false; |
| 533 | } |
| 534 | return true; |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public byte[] verifyPassword(String password, long challenge, int userId) |
| 539 | throws RemoteException { |
| 540 | try { |
| 541 | return doVerifyPassword(password, true, challenge, userId); |
| 542 | } catch (VerificationFailedException ex) { |
| 543 | return null; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | private byte[] doVerifyPassword(String password, boolean hasChallenge, long challenge, |
| 548 | int userId) throws VerificationFailedException, RemoteException { |
| 549 | checkPasswordReadPermission(userId); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 550 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 551 | CredentialHash storedHash = mStorage.readPasswordHash(userId); |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 552 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 553 | if ((storedHash == null || storedHash.hash.length == 0) && TextUtils.isEmpty(password)) { |
| 554 | // don't need to pass empty passwords to GateKeeper |
| 555 | return null; |
| 556 | } |
| 557 | |
| 558 | if (TextUtils.isEmpty(password)) { |
| 559 | throw new VerificationFailedException(); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 560 | } |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 561 | |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 562 | if (storedHash.version == CredentialHash.VERSION_LEGACY) { |
| 563 | byte[] hash = mLockPatternUtils.passwordToHash(password, userId); |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 564 | if (Arrays.equals(hash, storedHash.hash)) { |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 565 | maybeUpdateKeystore(password, userId); |
| 566 | // migrate password to GateKeeper |
| 567 | setLockPassword(password, null, userId); |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 568 | if (!hasChallenge) { |
| 569 | return null; |
| 570 | } |
| 571 | // Fall through to get the auth token. Technically this should never happen, |
| 572 | // as a user that had a legacy password would have to unlock their device |
| 573 | // before getting to a flow with a challenge, but supporting for consistency. |
| 574 | } else { |
| 575 | throw new VerificationFailedException(); |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 576 | } |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 579 | byte[] token = null; |
| 580 | if (hasChallenge) { |
| 581 | token = getGateKeeperService() |
| 582 | .verifyChallenge(userId, challenge, storedHash.hash, password.getBytes()); |
| 583 | if (token == null) { |
| 584 | throw new VerificationFailedException(); |
| 585 | } |
| 586 | } else if (!getGateKeeperService().verify(userId, storedHash.hash, password.getBytes())) { |
| 587 | throw new VerificationFailedException(); |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 588 | } |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 589 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 590 | // password has matched |
| 591 | maybeUpdateKeystore(password, userId); |
| 592 | return token; |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 595 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 596 | @Override |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 597 | public boolean checkVoldPassword(int userId) throws RemoteException { |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 598 | if (!mFirstCallToVold) { |
| 599 | return false; |
| 600 | } |
| 601 | mFirstCallToVold = false; |
| 602 | |
| 603 | checkPasswordReadPermission(userId); |
| 604 | |
| 605 | // There's no guarantee that this will safely connect, but if it fails |
| 606 | // we will simply show the lock screen when we shouldn't, so relatively |
| 607 | // benign. There is an outside chance something nasty would happen if |
| 608 | // this service restarted before vold stales out the password in this |
| 609 | // case. The nastiness is limited to not showing the lock screen when |
| 610 | // we should, within the first minute of decrypting the phone if this |
| 611 | // service can't connect to vold, it restarts, and then the new instance |
| 612 | // does successfully connect. |
| 613 | final IMountService service = getMountService(); |
| 614 | String password = service.getPassword(); |
| 615 | service.clearPassword(); |
| 616 | if (password == null) { |
| 617 | return false; |
| 618 | } |
| 619 | |
| 620 | try { |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 621 | if (mLockPatternUtils.isLockPatternEnabled(userId)) { |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 622 | if (checkPattern(password, userId)) { |
| 623 | return true; |
| 624 | } |
| 625 | } |
| 626 | } catch (Exception e) { |
| 627 | } |
| 628 | |
| 629 | try { |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 630 | if (mLockPatternUtils.isLockPasswordEnabled(userId)) { |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 631 | if (checkPassword(password, userId)) { |
| 632 | return true; |
| 633 | } |
| 634 | } |
| 635 | } catch (Exception e) { |
| 636 | } |
| 637 | |
| 638 | return false; |
| 639 | } |
| 640 | |
Adrian Roos | db0f76e | 2015-01-07 22:19:38 +0100 | [diff] [blame] | 641 | private void removeUser(int userId) { |
Adrian Roos | 261d5ab | 2014-10-29 14:42:38 +0100 | [diff] [blame] | 642 | mStorage.removeUser(userId); |
Robin Lee | 49d810c | 2014-09-23 13:50:22 +0100 | [diff] [blame] | 643 | |
| 644 | final KeyStore ks = KeyStore.getInstance(); |
| 645 | final int userUid = UserHandle.getUid(userId, Process.SYSTEM_UID); |
| 646 | ks.resetUid(userUid); |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 649 | private static final String[] VALID_SETTINGS = new String[] { |
| 650 | LockPatternUtils.LOCKOUT_PERMANENT_KEY, |
| 651 | LockPatternUtils.LOCKOUT_ATTEMPT_DEADLINE, |
| 652 | LockPatternUtils.PATTERN_EVER_CHOSEN_KEY, |
| 653 | LockPatternUtils.PASSWORD_TYPE_KEY, |
| 654 | LockPatternUtils.PASSWORD_TYPE_ALTERNATE_KEY, |
| 655 | LockPatternUtils.LOCK_PASSWORD_SALT_KEY, |
| 656 | LockPatternUtils.DISABLE_LOCKSCREEN_KEY, |
| 657 | LockPatternUtils.LOCKSCREEN_OPTIONS, |
| 658 | LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, |
| 659 | LockPatternUtils.BIOMETRIC_WEAK_EVER_CHOSEN_KEY, |
| 660 | LockPatternUtils.LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, |
| 661 | LockPatternUtils.PASSWORD_HISTORY_KEY, |
| 662 | Secure.LOCK_PATTERN_ENABLED, |
| 663 | Secure.LOCK_BIOMETRIC_WEAK_FLAGS, |
| 664 | Secure.LOCK_PATTERN_VISIBLE, |
| 665 | Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 666 | }; |
| 667 | |
Adrian Roos | 001b00d | 2015-02-24 17:08:48 +0100 | [diff] [blame] | 668 | // Reading these settings needs the profile permission |
Jim Miller | 2d8ecf9d | 2013-04-22 17:17:03 -0700 | [diff] [blame] | 669 | private static final String[] READ_PROFILE_PROTECTED_SETTINGS = new String[] { |
Jim Miller | 187ec58 | 2013-04-15 18:27:54 -0700 | [diff] [blame] | 670 | Secure.LOCK_SCREEN_OWNER_INFO_ENABLED, |
| 671 | Secure.LOCK_SCREEN_OWNER_INFO |
| 672 | }; |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 673 | |
Adrian Roos | 001b00d | 2015-02-24 17:08:48 +0100 | [diff] [blame] | 674 | // Reading these settings needs the same permission as checking the password |
| 675 | private static final String[] READ_PASSWORD_PROTECTED_SETTINGS = new String[] { |
| 676 | LockPatternUtils.LOCK_PASSWORD_SALT_KEY, |
| 677 | LockPatternUtils.PASSWORD_HISTORY_KEY, |
Adrian Roos | 855fa30 | 2015-04-02 16:01:12 +0200 | [diff] [blame] | 678 | LockPatternUtils.PASSWORD_TYPE_KEY, |
Adrian Roos | 001b00d | 2015-02-24 17:08:48 +0100 | [diff] [blame] | 679 | }; |
| 680 | |
Amith Yamasani | 072543f | 2015-02-13 11:09:45 -0800 | [diff] [blame] | 681 | private static final String[] SETTINGS_TO_BACKUP = new String[] { |
| 682 | Secure.LOCK_SCREEN_OWNER_INFO_ENABLED, |
| 683 | Secure.LOCK_SCREEN_OWNER_INFO |
| 684 | }; |
| 685 | |
Paul Lawrence | 945490c | 2014-03-27 16:37:28 +0000 | [diff] [blame] | 686 | private IMountService getMountService() { |
| 687 | final IBinder service = ServiceManager.getService("mount"); |
| 688 | if (service != null) { |
| 689 | return IMountService.Stub.asInterface(service); |
| 690 | } |
| 691 | return null; |
| 692 | } |
Andres Morales | 8fa5665 | 2015-03-31 09:19:50 -0700 | [diff] [blame] | 693 | |
| 694 | private synchronized IGateKeeperService getGateKeeperService() { |
| 695 | if (mGateKeeperService != null) { |
| 696 | return mGateKeeperService; |
| 697 | } |
| 698 | |
| 699 | final IBinder service = |
| 700 | ServiceManager.getService("android.service.gatekeeper.IGateKeeperService"); |
| 701 | if (service != null) { |
| 702 | mGateKeeperService = IGateKeeperService.Stub.asInterface(service); |
| 703 | return mGateKeeperService; |
| 704 | } |
| 705 | |
| 706 | Slog.e(TAG, "Unable to acquire GateKeeperService"); |
| 707 | return null; |
| 708 | } |
| 709 | |
Andres Morales | d9fc85a | 2015-04-09 19:14:42 -0700 | [diff] [blame] | 710 | private class VerificationFailedException extends Exception {} |
| 711 | |
Amith Yamasani | 52c489c | 2012-03-28 11:42:42 -0700 | [diff] [blame] | 712 | } |