Merge "On Settings lockscreen changes send new safety status to Safety Center." into tm-dev

This commit is contained in:
Marie Matheson
2022-03-01 07:18:02 +00:00
committed by Android (Google) Code Review
5 changed files with 51 additions and 3 deletions

View File

@@ -75,6 +75,7 @@ import com.android.settings.biometrics.BiometricEnrollActivity;
import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.safetycenter.LockScreenSafetySource;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settingslib.RestrictedPreference;
@@ -856,6 +857,7 @@ public class ChooseLockGeneric extends SettingsActivity {
}
mLockPatternUtils.setLockScreenDisabled(disabled, mUserId);
getActivity().setResult(Activity.RESULT_OK);
LockScreenSafetySource.onLockScreenChange(getContext());
finish();
}
}

View File

@@ -18,13 +18,13 @@ package com.android.settings.password;
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
import static android.app.admin.DevicePolicyResources.Strings.UNDEFINED;
import static android.app.admin.DevicePolicyResources.Strings.Settings.PASSWORD_RECENTLY_USED;
import static android.app.admin.DevicePolicyResources.Strings.Settings.PIN_RECENTLY_USED;
import static android.app.admin.DevicePolicyResources.Strings.Settings.REENTER_WORK_PROFILE_PASSWORD_HEADER;
import static android.app.admin.DevicePolicyResources.Strings.Settings.REENTER_WORK_PROFILE_PIN_HEADER;
import static android.app.admin.DevicePolicyResources.Strings.Settings.SET_WORK_PROFILE_PASSWORD_HEADER;
import static android.app.admin.DevicePolicyResources.Strings.Settings.SET_WORK_PROFILE_PIN_HEADER;
import static android.app.admin.DevicePolicyResources.Strings.UNDEFINED;
import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_NONE;
import static com.android.internal.widget.PasswordValidationError.CONTAINS_INVALID_CHARACTERS;

View File

@@ -30,6 +30,7 @@ import androidx.fragment.app.Fragment;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockscreenCredential;
import com.android.settings.R;
import com.android.settings.safetycenter.LockScreenSafetySource;
/**
* An invisible retained worker fragment to track the AsyncWork that saves (and optionally
@@ -110,6 +111,7 @@ abstract class SaveChosenLockWorkerBase extends Fragment {
if (mUnificationProfileCredential != null) {
mUnificationProfileCredential.zeroize();
}
LockScreenSafetySource.onLockScreenChange(getContext());
}
public void setBlocking(boolean blocking) {

View File

@@ -17,6 +17,7 @@
package com.android.settings.safetycenter;
import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
@@ -72,6 +73,13 @@ public final class LockScreenSafetySource {
SafetyCenterManagerWrapper.get().sendSafetyCenterUpdate(context, safetySourceData);
}
/** Notifies Safety Center of a change in lock screen settings. */
public static void onLockScreenChange(Context context) {
sendSafetyData(
context,
new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER));
}
private static IconAction createGearMenuIconAction(Context context,
ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
return screenLockPreferenceDetailsUtils.shouldShowGearMenu() ? new IconAction(

View File

@@ -33,7 +33,9 @@ import android.safetycenter.SafetySourceStatus.IconAction;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.After;
@@ -59,11 +61,17 @@ public class LockScreenSafetySourceTest {
@Mock
private ScreenLockPreferenceDetailsUtils mScreenLockPreferenceDetailsUtils;
@Mock
private LockPatternUtils mLockPatternUtils;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mApplicationContext = ApplicationProvider.getApplicationContext();
SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper;
final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mApplicationContext))
.thenReturn(mLockPatternUtils);
}
@After
@@ -72,8 +80,10 @@ public class LockScreenSafetySourceTest {
}
@Test
public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() {
public void sendSafetyData_whenScreenLockIsEnabled_whenSafetyCenterIsDisabled_sendsNoData() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(true);
LockScreenSafetySource.sendSafetyData(mApplicationContext,
mScreenLockPreferenceDetailsUtils);
@@ -95,6 +105,7 @@ public class LockScreenSafetySourceTest {
@Test
public void sendSafetyData_whenScreenLockIsEnabled_sendsData() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
LockScreenSafetySource.sendSafetyData(mApplicationContext,
mScreenLockPreferenceDetailsUtils);
@@ -119,6 +130,7 @@ public class LockScreenSafetySourceTest {
@Test
public void sendSafetyData_whenLockPatternIsSecure_sendsStatusLevelOk() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(true);
LockScreenSafetySource.sendSafetyData(mApplicationContext,
@@ -136,6 +148,7 @@ public class LockScreenSafetySourceTest {
@Test
public void sendSafetyData_whenLockPatternIsNotSecure_sendsStatusLevelRecommendation() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(false);
LockScreenSafetySource.sendSafetyData(mApplicationContext,
@@ -153,6 +166,7 @@ public class LockScreenSafetySourceTest {
@Test
public void sendSafetyData_whenPasswordQualityIsManaged_sendsDisabled() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.isPasswordQualityManaged(anyInt(), any()))
.thenReturn(true);
@@ -170,6 +184,7 @@ public class LockScreenSafetySourceTest {
@Test
public void sendSafetyData_whenPasswordQualityIsNotManaged_sendsEnabled() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.isPasswordQualityManaged(anyInt(), any()))
.thenReturn(false);
@@ -187,6 +202,7 @@ public class LockScreenSafetySourceTest {
@Test
public void sendSafetyData_whenShouldShowGearMenu_sendsGearMenuActionIcon() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
final Intent launchScreenLockSettings = new Intent(FAKE_ACTION_SCREEN_LOCK_SETTINGS);
when(mScreenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent())
.thenReturn(launchScreenLockSettings);
@@ -208,6 +224,7 @@ public class LockScreenSafetySourceTest {
@Test
public void sendSafetyData_whenShouldNotShowGearMenu_sendsNoGearMenuActionIcon() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).thenReturn(false);
LockScreenSafetySource.sendSafetyData(mApplicationContext,
@@ -221,8 +238,27 @@ public class LockScreenSafetySourceTest {
assertThat(safetySourceStatus.getIconAction()).isNull();
}
private void whenScreenLockIsEnabled() {
@Test
public void onLockScreenChange_whenSafetyCenterEnabled_sendsData() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
LockScreenSafetySource.onLockScreenChange(mApplicationContext);
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), any());
}
@Test
public void onLockScreenChange_whenSafetyCenterDisabled_sendsNoData() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
LockScreenSafetySource.onLockScreenChange(mApplicationContext);
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
}
private void whenScreenLockIsEnabled() {
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.getSummary(anyInt())).thenReturn(SUMMARY);