Restore separate challenge state on error

Otherwise if something goes wrong when tying the profile to the primary
user, challenge will remain in inconsistent state and the user won't
be able to unlock the profile.

Bug: 110262879
Test: manual, unified both compliant and uncompliant challenge.
Change-Id: I2bea3867541f43cbabd5cabbe8a0f61acc2602ca
This commit is contained in:
Pavel Grafov
2018-06-25 12:13:38 +01:00
parent 0eb2be3a67
commit f10ae7e731

View File

@@ -955,12 +955,18 @@ public class LockSettingsService extends ILockSettings.Stub {
@GuardedBy("mSeparateChallengeLock")
private void setSeparateProfileChallengeEnabledLocked(@UserIdInt int userId, boolean enabled,
String managedUserPassword) {
final boolean old = getBoolean(SEPARATE_PROFILE_CHALLENGE_KEY, false, userId);
setBoolean(SEPARATE_PROFILE_CHALLENGE_KEY, enabled, userId);
if (enabled) {
mStorage.removeChildProfileLock(userId);
removeKeystoreProfileKey(userId);
} else {
tieManagedProfileLockIfNecessary(userId, managedUserPassword);
try {
if (enabled) {
mStorage.removeChildProfileLock(userId);
removeKeystoreProfileKey(userId);
} else {
tieManagedProfileLockIfNecessary(userId, managedUserPassword);
}
} catch (IllegalStateException e) {
setBoolean(SEPARATE_PROFILE_CHALLENGE_KEY, old, userId);
throw e;
}
}