private boolean setLockCredentialInternal(LockscreenCredential credential,LockscreenCredential savedCredential,int userId, boolean isLockTiedToParent){Objects.requireNonNull(credential);Objects.requireNonNull(savedCredential);synchronized (mSpManager){--------------------------------------------------//暫不介紹mSpManager機制if(isSyntheticPasswordBasedCredentialLocked(userId)){returnspBasedSetLockCredentialInternalLocked(credential, savedCredential, userId,isLockTiedToParent);}}if(credential.isNone()){--------------------------------------------------//,其實就是密碼類型選擇了None,可以理解為,這是清除密碼的流程clearUserKeyProtection(userId, null);gateKeeperClearSecureUserId(userId);mStorage.writeCredentialHash(CredentialHash.createEmptyHash(), userId);// Still update PASSWORD_TYPE_KEY if we are running in pre-synthetic password code path,// since it forms part of the state that determines the credential type// @see getCredentialTypeInternalsetKeyguardStoredQuality(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userId);setKeystorePassword(null, userId);fixateNewestUserKeyAuth(userId);synchronizeUnifiedWorkChallengeForProfiles(userId, null);setUserPasswordMetrics(LockscreenCredential.createNone(), userId);sendCredentialsOnChangeIfRequired(credential, userId, isLockTiedToParent);return true;}CredentialHash currentHandle = mStorage.readCredentialHash(userId);--------------------// 讀取原來的密碼if(isManagedProfileWithUnifiedLock(userId)){// get credential from keystore when managed profile has unified lockif(savedCredential.isNone()){try {//TODO: remove as part of b/80170828savedCredential =getDecryptedPasswordForTiedProfile(userId);} catch (FileNotFoundException e){Slog.i(TAG,"Child profile key not found");} catch (UnrecoverableKeyException | InvalidKeyException | KeyStoreException| NoSuchAlgorithmException | NoSuchPaddingException| InvalidAlgorithmParameterException | IllegalBlockSizeException| BadPaddingException | CertificateException | IOException e){Slog.e(TAG,"Failed to decrypt child profile key", e);}}}else{if(currentHandle.hash == null){if(!savedCredential.isNone()){Slog.w(TAG,"Saved credential provided, but none stored");}savedCredential.close();savedCredential = LockscreenCredential.createNone();}}synchronized (mSpManager){if(shouldMigrateToSyntheticPasswordLocked(userId)){initializeSyntheticPasswordLocked(currentHandle.hash, savedCredential, userId);returnspBasedSetLockCredentialInternalLocked(credential, savedCredential, userId,isLockTiedToParent);}}if(DEBUG) Slog.d(TAG,"setLockCredentialInternal: user="+ userId);byte[] enrolledHandle =enrollCredential(currentHandle.hash,--------------------------------// 調(diào)用底層,完成enrollsavedCredential.getCredential(), credential.getCredential(), userId);if(enrolledHandle == null){Slog.w(TAG, String.format("Failed to enroll %s: incorrect credential",-------------------------------// 如果底層enroll錯誤了,則返回failedcredential.isPattern()?"pattern":"password"));return false;}CredentialHash willStore = CredentialHash.create(enrolledHandle, credential.getType());-----------------------------//創(chuàng)建hashmStorage.writeCredentialHash(willStore, userId);-----------------------------//保存hash// Still update PASSWORD_TYPE_KEY if we are running in pre-synthetic password code path,// since it forms part of the state that determines the credential type// @see getCredentialTypeInternalsetKeyguardStoredQuality(LockPatternUtils.credentialTypeToPasswordQuality(credential.getType()), userId);// push new secret and auth token to voldGateKeeperResponse gkResponse;try {gkResponse =getGateKeeperService().verifyChallenge(userId,0, willStore.hash,-----------------------------//驗證challengecredential.getCredential());} catch (RemoteException e){throw new IllegalStateException("Failed to verify current credential", e);}setUserKeyProtection(userId, credential,convertResponse(gkResponse));fixateNewestUserKeyAuth(userId);// Refresh the auth tokendoVerifyCredential(credential, CHALLENGE_FROM_CALLER,0, userId,-----------------------------//再做一次verifynull /* progressCallback */);synchronizeUnifiedWorkChallengeForProfiles(userId, null);sendCredentialsOnChangeIfRequired(credential, userId, isLockTiedToParent);return true;}