选择解锁方式页面的加载
首先还是从ChooseLockGenericFragment开始分析,由上一篇链接 我们知道当第一次选择密码时,会执行helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,getString(R.string.unlock_set_unlock_launch_picker_title), true, mUserId)方法并返回false,从而执行updatePreferencesOrFinish(savedInstanceState != null);这个方法,我们来看下此方法,代码如下:
private void updatePreferencesOrFinish(boolean isRecreatingActivity) {
Intent intent = getActivity().getIntent();
int quality = intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
Log.d("faceid", "quality = " + quality+ " :isRecreatingActivity: "+isRecreatingActivity);
//由于没有设置过密码,此时quality为-1
if (quality == -1) {
// If caller didn't specify password quality, show UI and allow the user to choose.
quality = intent.getIntExtra(MINIMUM_QUALITY_KEY, -1);
quality = mController.upgradeQuality(quality);//quality:0
final boolean hideDisabledPrefs = intent.getBooleanExtra(
HIDE_DISABLED_PREFS, false);//hideDisabledPrefs false
final PreferenceScreen prefScreen = getPreferenceScreen();
if (prefScreen != null) {
prefScreen.removeAll();
}
addPreferences();//添加布局
removePreferencesForFaceid();
disableUnusablePreferences(quality, hideDisabledPrefs); //如果此时是人脸跳到此页面时hideDisabledPrefs为true,会disable 无和滑动两种锁屏方式
updatePreferenceText();//更新每个解锁方式的文字
updateCurrentPreference();//更新当前选中的解锁方式的文字状态
updatePreferenceSummaryIfNeeded();
} else if (!isRecreatingActivity) { //todo 为什么不走这里
// Don't start the activity again if we are recreated for configuration change
updateUnlockMethodAndFinish(quality, false, true /* chooseLockSkipped */);
}
}
此时布局已经加载完成,界面截图如下:
选择解锁方式
当选择解锁方式时,点击任意一种都会执行onPreferenceTreeClick方法,我们来看下,如果我们选择patten,会执行甚麽,代码如下:
// /vendor/mediatek/proprietary/package/apps/MTKSettings/src/
//com/android/settings/password/ChooseLockGeneric.java/ChooseLockGenericFragment
@Override
public boolean onPreferenceTreeClick(Preference preference) {
final String key = preference.getKey();//此时key为:unlock_set_pattern
//isUnlockMethodSecure会判断key是否为none或者swipe,此时key为pattern,返回false
if (!isUnlockMethodSecure(key) && mLockPatternUtils.isSecure(mUserId)) {
......
} else if (KEY_SKIP_FINGERPRINT.equals(key)) {
......
} else {
//此时会执行setUnlockMethod(unlock_set_pattern)方法
return setUnlockMethod(key);
}
}
接着来看setUnlockMethod方法,代码如下:
// /vendor/mediatek/proprietary/package/apps/MTKSettings/src/
//com/android/settings/password/ChooseLockGeneric.java/ChooseLockGenericFragment
private boolean setUnlockMethod(String unlockMethod) {
EventLog.writeEvent(EventLogTags.LOCK_SCREEN_TYPE, unlockMethod);
//此时的unlockMethod为unlock_set_pattern,所以lock为PATTERN
ScreenLockType lock = ScreenLockType.fromKey(unlockMethod);
if (lock != null) {
switch (lock) {
case NONE:
case SWIPE:
......
return true;
case PATTERN:
case PIN:
case PASSWORD:
case MANAGED:
//所以会执行此方法
maybeEnableEncryption(lock.defaultQuality, false);
return true;
}
}
return false;
}
接着我们来看下maybeEnableEncryption(lock.defaultQuality, false);方法,方法如下:
// /vendor/mediatek/proprietary/package/apps/MTKSettings/src/
//com/android/settings/password/ChooseLockGeneric.java/ChooseLockGenericFragment
private void maybeEnableEncryption(int quality, boolean disabled) {
DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
if (UserManager.get(getActivity()).isAdminUser()
&& mUserId == UserHandle.myUserId()
&& LockPatternUtils.isDeviceEncryptionEnabled()
&& !LockPatternUtils.isFileEncryptionEnabled()
&& !dpm.getDoNotAskCredentialsOnBoot()) {
//此时的quality为65535为图案
mEncryptionRequestQuality = quality;
//mEncryptionRequestDisabled为false
mEncryptionRequestDisabled = disabled;
//此时获取到的intent为ChooseLockPattern.java
Intent unlockMethodIntent = getIntentForUnlockMethod(quality);
//mForChangeCredRequiredForBoot为false
unlockMethodIntent.putExtra(
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT,
mForChangeCredRequiredForBoot);
final Context context = getActivity();
// If accessibility is enabled and the user hasn't seen this dialog before, set the
// default state to agree with that which is compatible with accessibility
// (password not required).
final boolean accEn = AccessibilityManager.getInstance(context).isEnabled();
final boolean required = mLockPatternUtils.isCredentialRequiredToDecrypt(!accEn);
//此方法新建里个Intent,值为EncryptionInterstitial.class,并将unlockMethodIntent
//作为参数放到此intent中。
Intent intent = getEncryptionInterstitialIntent(context, quality, required,
unlockMethodIntent);