Loading src/com/android/settings/safetycenter/LockScreenSafetySource.java +7 −2 Original line number Diff line number Diff line Loading @@ -95,8 +95,7 @@ public final class LockScreenSafetySource { new SafetySourceStatus.Builder( context.getString(R.string.unlock_set_unlock_launch_picker_title), lockScreenAllowedByAdmin ? screenLockPreferenceDetailsUtils.getSummary( UserHandle.myUserId()) ? getScreenLockSummary(screenLockPreferenceDetailsUtils) : context.getString(R.string.disabled_by_policy_title), severityLevel) .setPendingIntent(lockScreenAllowedByAdmin ? pendingIntent : null) Loading @@ -114,6 +113,12 @@ public final class LockScreenSafetySource { .setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent); } private static String getScreenLockSummary( ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) { String summary = screenLockPreferenceDetailsUtils.getSummary(UserHandle.myUserId()); return summary != null ? summary : ""; } /** Notifies Safety Center of a change in lock screen settings. */ public static void onLockScreenChange(Context context) { setSafetySourceData( Loading src/com/android/settings/security/ScreenLockPreferenceDetailsUtils.java +8 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.os.storage.StorageManager; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import com.android.internal.app.UnlaunchableAppActivity; Loading @@ -43,6 +44,7 @@ public class ScreenLockPreferenceDetailsUtils { private final int mUserId = UserHandle.myUserId(); private final Context mContext; @Nullable private final LockPatternUtils mLockPatternUtils; private final int mProfileChallengeUserId; private final UserManager mUm; Loading Loading @@ -85,7 +87,7 @@ public class ScreenLockPreferenceDetailsUtils { * Returns whether the lock pattern is secure. */ public boolean isLockPatternSecure() { return mLockPatternUtils.isSecure(mUserId); return mLockPatternUtils != null && mLockPatternUtils.isSecure(mUserId); } /** Loading Loading @@ -148,6 +150,7 @@ public class ScreenLockPreferenceDetailsUtils { // profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be // able to complete the operation due to the lack of (old) encryption key. if (mProfileChallengeUserId != UserHandle.USER_NULL && mLockPatternUtils != null && !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId) && StorageManager.isFileEncrypted()) { if (mUm.isQuietModeEnabled(UserHandle.of(mProfileChallengeUserId))) { Loading @@ -166,8 +169,12 @@ public class ScreenLockPreferenceDetailsUtils { .toIntent(); } @Nullable @StringRes private Integer getSummaryResId(int userId) { if (mLockPatternUtils == null) { return null; } if (!mLockPatternUtils.isSecure(userId)) { if (userId == mProfileChallengeUserId || mLockPatternUtils.isLockScreenDisabled(userId)) { Loading tests/unit/src/com/android/settings/security/ScreenLockPreferenceDetailsUtilsTest.java +35 −2 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public class ScreenLockPreferenceDetailsUtilsTest { private StorageManager mStorageManager; private Context mContext; private FakeFeatureFactory mFeatureFactory; private ScreenLockPreferenceDetailsUtils mScreenLockPreferenceDetailsUtils; Loading @@ -95,8 +96,8 @@ public class ScreenLockPreferenceDetailsUtilsTest { doNothing().when(mContext).startActivity(any()); when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{}); final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest(); when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) mFeatureFactory = FakeFeatureFactory.setupForTest(); when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(mLockPatternUtils); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); Loading Loading @@ -230,6 +231,15 @@ public class ScreenLockPreferenceDetailsUtilsTest { assertNull(mScreenLockPreferenceDetailsUtils.getSummary(USER_ID)); } @Test public void getSummary_noLockPatternUtils_shouldReturnNull() { when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(null); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); assertNull(mScreenLockPreferenceDetailsUtils.getSummary(USER_ID)); } @Test public void isPasswordQualityManaged_withoutAdmin_shouldReturnFalse() { final RestrictedLockUtils.EnforcedAdmin admin = null; Loading Loading @@ -274,6 +284,15 @@ public class ScreenLockPreferenceDetailsUtilsTest { assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isFalse(); } @Test public void isLockPatternSecure_noLockPatterUtils_shouldReturnFalse() { when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(null); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isFalse(); } @Test @RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_ONBOARDING_EDUCATION) public void shouldShowGearMenu_patternIsSecure_flagOn_shouldReturnFalse() { Loading Loading @@ -341,6 +360,20 @@ public class ScreenLockPreferenceDetailsUtilsTest { ChooseLockGeneric.ChooseLockGenericFragment.class.getName()); } @Test public void getLaunchChooseLockGenericFragmentIntent_noLockPatternUtils_returnsIntent() { when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(null); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); when(mUserManager.isQuietModeEnabled(any())).thenReturn(false); final Intent intent = mScreenLockPreferenceDetailsUtils .getLaunchChooseLockGenericFragmentIntent(SOURCE_METRICS_CATEGORY); assertFragmentLaunchIntent(intent, ChooseLockGeneric.ChooseLockGenericFragment.class.getName()); } private void whenConfigShowUnlockSetOrChangeIsEnabled(boolean enabled) { final int resId = ResourcesUtils.getResourcesId( ApplicationProvider.getApplicationContext(), "bool", Loading Loading
src/com/android/settings/safetycenter/LockScreenSafetySource.java +7 −2 Original line number Diff line number Diff line Loading @@ -95,8 +95,7 @@ public final class LockScreenSafetySource { new SafetySourceStatus.Builder( context.getString(R.string.unlock_set_unlock_launch_picker_title), lockScreenAllowedByAdmin ? screenLockPreferenceDetailsUtils.getSummary( UserHandle.myUserId()) ? getScreenLockSummary(screenLockPreferenceDetailsUtils) : context.getString(R.string.disabled_by_policy_title), severityLevel) .setPendingIntent(lockScreenAllowedByAdmin ? pendingIntent : null) Loading @@ -114,6 +113,12 @@ public final class LockScreenSafetySource { .setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent); } private static String getScreenLockSummary( ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) { String summary = screenLockPreferenceDetailsUtils.getSummary(UserHandle.myUserId()); return summary != null ? summary : ""; } /** Notifies Safety Center of a change in lock screen settings. */ public static void onLockScreenChange(Context context) { setSafetySourceData( Loading
src/com/android/settings/security/ScreenLockPreferenceDetailsUtils.java +8 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.os.storage.StorageManager; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import com.android.internal.app.UnlaunchableAppActivity; Loading @@ -43,6 +44,7 @@ public class ScreenLockPreferenceDetailsUtils { private final int mUserId = UserHandle.myUserId(); private final Context mContext; @Nullable private final LockPatternUtils mLockPatternUtils; private final int mProfileChallengeUserId; private final UserManager mUm; Loading Loading @@ -85,7 +87,7 @@ public class ScreenLockPreferenceDetailsUtils { * Returns whether the lock pattern is secure. */ public boolean isLockPatternSecure() { return mLockPatternUtils.isSecure(mUserId); return mLockPatternUtils != null && mLockPatternUtils.isSecure(mUserId); } /** Loading Loading @@ -148,6 +150,7 @@ public class ScreenLockPreferenceDetailsUtils { // profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be // able to complete the operation due to the lack of (old) encryption key. if (mProfileChallengeUserId != UserHandle.USER_NULL && mLockPatternUtils != null && !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId) && StorageManager.isFileEncrypted()) { if (mUm.isQuietModeEnabled(UserHandle.of(mProfileChallengeUserId))) { Loading @@ -166,8 +169,12 @@ public class ScreenLockPreferenceDetailsUtils { .toIntent(); } @Nullable @StringRes private Integer getSummaryResId(int userId) { if (mLockPatternUtils == null) { return null; } if (!mLockPatternUtils.isSecure(userId)) { if (userId == mProfileChallengeUserId || mLockPatternUtils.isLockScreenDisabled(userId)) { Loading
tests/unit/src/com/android/settings/security/ScreenLockPreferenceDetailsUtilsTest.java +35 −2 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public class ScreenLockPreferenceDetailsUtilsTest { private StorageManager mStorageManager; private Context mContext; private FakeFeatureFactory mFeatureFactory; private ScreenLockPreferenceDetailsUtils mScreenLockPreferenceDetailsUtils; Loading @@ -95,8 +96,8 @@ public class ScreenLockPreferenceDetailsUtilsTest { doNothing().when(mContext).startActivity(any()); when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{}); final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest(); when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) mFeatureFactory = FakeFeatureFactory.setupForTest(); when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(mLockPatternUtils); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); Loading Loading @@ -230,6 +231,15 @@ public class ScreenLockPreferenceDetailsUtilsTest { assertNull(mScreenLockPreferenceDetailsUtils.getSummary(USER_ID)); } @Test public void getSummary_noLockPatternUtils_shouldReturnNull() { when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(null); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); assertNull(mScreenLockPreferenceDetailsUtils.getSummary(USER_ID)); } @Test public void isPasswordQualityManaged_withoutAdmin_shouldReturnFalse() { final RestrictedLockUtils.EnforcedAdmin admin = null; Loading Loading @@ -274,6 +284,15 @@ public class ScreenLockPreferenceDetailsUtilsTest { assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isFalse(); } @Test public void isLockPatternSecure_noLockPatterUtils_shouldReturnFalse() { when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(null); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isFalse(); } @Test @RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_ONBOARDING_EDUCATION) public void shouldShowGearMenu_patternIsSecure_flagOn_shouldReturnFalse() { Loading Loading @@ -341,6 +360,20 @@ public class ScreenLockPreferenceDetailsUtilsTest { ChooseLockGeneric.ChooseLockGenericFragment.class.getName()); } @Test public void getLaunchChooseLockGenericFragmentIntent_noLockPatternUtils_returnsIntent() { when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext)) .thenReturn(null); mScreenLockPreferenceDetailsUtils = new ScreenLockPreferenceDetailsUtils(mContext); when(mUserManager.isQuietModeEnabled(any())).thenReturn(false); final Intent intent = mScreenLockPreferenceDetailsUtils .getLaunchChooseLockGenericFragmentIntent(SOURCE_METRICS_CATEGORY); assertFragmentLaunchIntent(intent, ChooseLockGeneric.ChooseLockGenericFragment.class.getName()); } private void whenConfigShowUnlockSetOrChangeIsEnabled(boolean enabled) { final int resId = ResourcesUtils.getResourcesId( ApplicationProvider.getApplicationContext(), "bool", Loading