blob: f85e2cc10800351b947d2e3a0363d37ec6f88697 [file] [log] [blame]
Rubin Xu0cbc19e2016-12-09 14:00:21 +00001/*
2 * Copyright (C) 2017 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
Andrew Scull507d11c2017-05-03 17:19:01 +010017package com.android.server.locksettings;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000018
19import static org.mockito.Mockito.mock;
20
21import android.app.IActivityManager;
22import android.content.Context;
Andrew Sculle6527c12018-01-05 18:33:58 +000023import android.hardware.authsecret.V1_0.IAuthSecret;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000024import android.os.Handler;
Rubin Xu7cf45092017-08-28 11:47:35 +010025import android.os.Looper;
Rubin Xu3bf722a2016-12-15 16:07:38 +000026import android.os.Process;
27import android.os.RemoteException;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000028import android.os.storage.IStorageManager;
29import android.security.KeyStore;
Rubin Xu3bf722a2016-12-15 16:07:38 +000030import android.security.keystore.KeyPermanentlyInvalidatedException;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000031
32import com.android.internal.widget.LockPatternUtils;
Annie Meng086ddc82019-03-29 17:43:35 +000033import com.android.server.locksettings.recoverablekeystore.RecoverableKeyStoreManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000034
35import java.io.FileNotFoundException;
36
37public class LockSettingsServiceTestable extends LockSettingsService {
38
39 private static class MockInjector extends LockSettingsService.Injector {
40
41 private LockSettingsStorage mLockSettingsStorage;
42 private KeyStore mKeyStore;
43 private IActivityManager mActivityManager;
44 private LockPatternUtils mLockPatternUtils;
45 private IStorageManager mStorageManager;
Rubin Xu7b7424b2017-03-31 18:03:20 +010046 private SyntheticPasswordManager mSpManager;
Andrew Sculle6527c12018-01-05 18:33:58 +000047 private IAuthSecret mAuthSecretService;
David Anderson6ebc25b2019-02-12 16:25:56 -080048 private FakeGsiService mGsiService;
Annie Meng086ddc82019-03-29 17:43:35 +000049 private RecoverableKeyStoreManager mRecoverableKeyStoreManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000050
51 public MockInjector(Context context, LockSettingsStorage storage, KeyStore keyStore,
52 IActivityManager activityManager, LockPatternUtils lockPatternUtils,
Andrew Sculle6527c12018-01-05 18:33:58 +000053 IStorageManager storageManager, SyntheticPasswordManager spManager,
Annie Meng086ddc82019-03-29 17:43:35 +000054 IAuthSecret authSecretService, FakeGsiService gsiService,
55 RecoverableKeyStoreManager recoverableKeyStoreManager) {
Rubin Xu0cbc19e2016-12-09 14:00:21 +000056 super(context);
57 mLockSettingsStorage = storage;
58 mKeyStore = keyStore;
59 mActivityManager = activityManager;
60 mLockPatternUtils = lockPatternUtils;
61 mStorageManager = storageManager;
Rubin Xu7b7424b2017-03-31 18:03:20 +010062 mSpManager = spManager;
David Anderson6ebc25b2019-02-12 16:25:56 -080063 mGsiService = gsiService;
Annie Meng086ddc82019-03-29 17:43:35 +000064 mRecoverableKeyStoreManager = recoverableKeyStoreManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000065 }
66
67 @Override
68 public Handler getHandler() {
Rubin Xu7cf45092017-08-28 11:47:35 +010069 return new Handler(Looper.getMainLooper());
Rubin Xu0cbc19e2016-12-09 14:00:21 +000070 }
71
72 @Override
73 public LockSettingsStorage getStorage() {
74 return mLockSettingsStorage;
75 }
76
77 @Override
78 public LockSettingsStrongAuth getStrongAuth() {
79 return mock(LockSettingsStrongAuth.class);
80 }
81
82 @Override
83 public SynchronizedStrongAuthTracker getStrongAuthTracker() {
84 return mock(SynchronizedStrongAuthTracker.class);
85 }
86
87 @Override
88 public IActivityManager getActivityManager() {
89 return mActivityManager;
90 }
91
92 @Override
93 public LockPatternUtils getLockPatternUtils() {
94 return mLockPatternUtils;
95 }
96
97 @Override
98 public KeyStore getKeyStore() {
99 return mKeyStore;
100 }
101
102 @Override
103 public IStorageManager getStorageManager() {
104 return mStorageManager;
105 }
Rubin Xu3bf722a2016-12-15 16:07:38 +0000106
107 @Override
108 public SyntheticPasswordManager getSyntheticPasswordManager(LockSettingsStorage storage) {
Rubin Xu7b7424b2017-03-31 18:03:20 +0100109 return mSpManager;
Rubin Xu3bf722a2016-12-15 16:07:38 +0000110 }
111
112 @Override
Kevin Chyn71db85f2019-05-14 15:32:47 -0700113 public boolean hasEnrolledBiometrics() {
Kevin Chyncf1a62e2019-02-21 11:11:59 -0800114 return false;
115 }
116
117 @Override
Rubin Xu3bf722a2016-12-15 16:07:38 +0000118 public int binderGetCallingUid() {
119 return Process.SYSTEM_UID;
120 }
David Anderson6ebc25b2019-02-12 16:25:56 -0800121
122 @Override
123 public boolean isGsiRunning() {
124 return mGsiService.isGsiRunning();
125 }
Annie Meng086ddc82019-03-29 17:43:35 +0000126
127 @Override
128 public RecoverableKeyStoreManager getRecoverableKeyStoreManager(KeyStore keyStore) {
129 return mRecoverableKeyStoreManager;
130 }
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000131 }
132
133 protected LockSettingsServiceTestable(Context context, LockPatternUtils lockPatternUtils,
Rubin Xu16c823e2017-06-27 14:44:58 +0100134 LockSettingsStorage storage, FakeGateKeeperService gatekeeper, KeyStore keystore,
Rubin Xu7b7424b2017-03-31 18:03:20 +0100135 IStorageManager storageManager, IActivityManager mActivityManager,
David Anderson6ebc25b2019-02-12 16:25:56 -0800136 SyntheticPasswordManager spManager, IAuthSecret authSecretService,
Annie Meng086ddc82019-03-29 17:43:35 +0000137 FakeGsiService gsiService, RecoverableKeyStoreManager recoverableKeyStoreManager) {
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000138 super(new MockInjector(context, storage, keystore, mActivityManager, lockPatternUtils,
Annie Meng086ddc82019-03-29 17:43:35 +0000139 storageManager, spManager, authSecretService, gsiService,
140 recoverableKeyStoreManager));
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000141 mGateKeeperService = gatekeeper;
Andrew Sculle6527c12018-01-05 18:33:58 +0000142 mAuthSecretService = authSecretService;
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000143 }
144
145 @Override
Rich Canningsf64ec632019-02-21 12:40:36 -0800146 protected void tieProfileLockToParent(int userId, byte[] password) {
147 mStorage.writeChildProfileLock(userId, password);
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000148 }
149
150 @Override
Rich Canningsf64ec632019-02-21 12:40:36 -0800151 protected byte[] getDecryptedPasswordForTiedProfile(int userId) throws FileNotFoundException,
Rubin Xu7b7424b2017-03-31 18:03:20 +0100152 KeyPermanentlyInvalidatedException {
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000153 byte[] storedData = mStorage.readChildProfileLock(userId);
154 if (storedData == null) {
155 throw new FileNotFoundException("Child profile lock file not found");
156 }
Rubin Xu3bf722a2016-12-15 16:07:38 +0000157 try {
158 if (mGateKeeperService.getSecureUserId(userId) == 0) {
159 throw new KeyPermanentlyInvalidatedException();
160 }
161 } catch (RemoteException e) {
162 // shouldn't happen.
163 }
Rich Canningsf64ec632019-02-21 12:40:36 -0800164 return storedData;
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000165 }
Rubin Xu0cbc19e2016-12-09 14:00:21 +0000166}