Merge "Keystore 2.0: Integrate onLockScreenEvent." am: 01460b0bd8 am: 2670006095
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1546381 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ia6476683a88f2df398f54cf119c8d62ac97cf7d7
This commit is contained in:
@@ -17,11 +17,13 @@
|
|||||||
package android.security;
|
package android.security;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.hardware.security.keymint.HardwareAuthToken;
|
import android.hardware.security.keymint.HardwareAuthToken;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.ServiceSpecificException;
|
import android.os.ServiceSpecificException;
|
||||||
import android.security.authorization.IKeystoreAuthorization;
|
import android.security.authorization.IKeystoreAuthorization;
|
||||||
|
import android.security.authorization.LockScreenEvent;
|
||||||
import android.system.keystore2.ResponseCode;
|
import android.system.keystore2.ResponseCode;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -75,4 +77,31 @@ public class Authorization {
|
|||||||
return addAuthToken(AuthTokenUtils.toHardwareAuthToken(authToken));
|
return addAuthToken(AuthTokenUtils.toHardwareAuthToken(authToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Informs keystore2 about lock screen event.
|
||||||
|
*
|
||||||
|
* @param locked - whether it is a lock (true) or unlock (false) event
|
||||||
|
* @param syntheticPassword - if it is an unlock event with the password, pass the synthetic
|
||||||
|
* password provided by the LockSettingService
|
||||||
|
*
|
||||||
|
* @return 0 if successful or a {@code ResponseCode}.
|
||||||
|
*/
|
||||||
|
public int onLockScreenEvent(@NonNull boolean locked, @NonNull int userId,
|
||||||
|
@Nullable byte[] syntheticPassword) {
|
||||||
|
if (!android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) return 0;
|
||||||
|
try {
|
||||||
|
if (locked) {
|
||||||
|
getService().onLockScreenEvent(LockScreenEvent.LOCK, userId, null);
|
||||||
|
} else {
|
||||||
|
getService().onLockScreenEvent(LockScreenEvent.UNLOCK, userId, syntheticPassword);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Can not connect to keystore", e);
|
||||||
|
return SYSTEM_ERROR;
|
||||||
|
} catch (ServiceSpecificException e) {
|
||||||
|
return e.errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ import android.os.storage.StorageManager;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
import android.provider.Settings.SettingNotFoundException;
|
||||||
|
import android.security.Authorization;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
import android.security.keystore.AndroidKeyStoreProvider;
|
import android.security.keystore.AndroidKeyStoreProvider;
|
||||||
import android.security.keystore.KeyProperties;
|
import android.security.keystore.KeyProperties;
|
||||||
@@ -1272,6 +1273,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
|||||||
|
|
||||||
private void unlockKeystore(byte[] password, int userHandle) {
|
private void unlockKeystore(byte[] password, int userHandle) {
|
||||||
if (DEBUG) Slog.v(TAG, "Unlock keystore for user: " + userHandle);
|
if (DEBUG) Slog.v(TAG, "Unlock keystore for user: " + userHandle);
|
||||||
|
new Authorization().onLockScreenEvent(false, userHandle, password);
|
||||||
// TODO(b/120484642): Update keystore to accept byte[] passwords
|
// TODO(b/120484642): Update keystore to accept byte[] passwords
|
||||||
String passwordString = password == null ? null : new String(password);
|
String passwordString = password == null ? null : new String(password);
|
||||||
final KeyStore ks = KeyStore.getInstance();
|
final KeyStore ks = KeyStore.getInstance();
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import android.os.SystemClock;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.security.Authorization;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
import android.service.trust.TrustAgentService;
|
import android.service.trust.TrustAgentService;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -185,6 +186,8 @@ public class TrustManagerService extends SystemService {
|
|||||||
private boolean mTrustAgentsCanRun = false;
|
private boolean mTrustAgentsCanRun = false;
|
||||||
private int mCurrentUser = UserHandle.USER_SYSTEM;
|
private int mCurrentUser = UserHandle.USER_SYSTEM;
|
||||||
|
|
||||||
|
private Authorization mAuthorizationService;
|
||||||
|
|
||||||
public TrustManagerService(Context context) {
|
public TrustManagerService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -194,6 +197,7 @@ public class TrustManagerService extends SystemService {
|
|||||||
mStrongAuthTracker = new StrongAuthTracker(context);
|
mStrongAuthTracker = new StrongAuthTracker(context);
|
||||||
mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
|
mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
|
||||||
mSettingsObserver = new SettingsObserver(mHandler);
|
mSettingsObserver = new SettingsObserver(mHandler);
|
||||||
|
mAuthorizationService = new Authorization();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -696,11 +700,13 @@ public class TrustManagerService extends SystemService {
|
|||||||
if (changed) {
|
if (changed) {
|
||||||
dispatchDeviceLocked(userId, locked);
|
dispatchDeviceLocked(userId, locked);
|
||||||
|
|
||||||
|
mAuthorizationService.onLockScreenEvent(locked, userId, null);
|
||||||
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
||||||
// Also update the user's profiles who have unified challenge, since they
|
// Also update the user's profiles who have unified challenge, since they
|
||||||
// share the same unlocked state (see {@link #isDeviceLocked(int)})
|
// share the same unlocked state (see {@link #isDeviceLocked(int)})
|
||||||
for (int profileHandle : mUserManager.getEnabledProfileIds(userId)) {
|
for (int profileHandle : mUserManager.getEnabledProfileIds(userId)) {
|
||||||
if (mLockPatternUtils.isManagedProfileWithUnifiedChallenge(profileHandle)) {
|
if (mLockPatternUtils.isManagedProfileWithUnifiedChallenge(profileHandle)) {
|
||||||
|
mAuthorizationService.onLockScreenEvent(locked, profileHandle, null);
|
||||||
KeyStore.getInstance().onUserLockedStateChanged(profileHandle, locked);
|
KeyStore.getInstance().onUserLockedStateChanged(profileHandle, locked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1252,6 +1258,7 @@ public class TrustManagerService extends SystemService {
|
|||||||
mDeviceLockedForUser.put(userId, locked);
|
mDeviceLockedForUser.put(userId, locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAuthorizationService.onLockScreenEvent(locked, userId, null);
|
||||||
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
KeyStore.getInstance().onUserLockedStateChanged(userId, locked);
|
||||||
|
|
||||||
if (locked) {
|
if (locked) {
|
||||||
|
|||||||
Reference in New Issue
Block a user