[automerge] Provide data to LockScreenSafetySource 2p: fc9b13e865
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/16931921 Bug: 215515298 Change-Id: I7f743e6f9931f26e6b8b653895bbe387a3add100
This commit is contained in:
committed by
Presubmit Automerger Backend
commit
a7cdcb15b9
@@ -19,19 +19,22 @@ package com.android.settings.safetycenter;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
import android.safetycenter.SafetySourceStatus.IconAction;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.password.ChooseLockGeneric;
|
||||
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -44,6 +47,10 @@ import org.mockito.MockitoAnnotations;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class LockScreenSafetySourceTest {
|
||||
|
||||
private static final String SUMMARY = "summary";
|
||||
private static final String FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT = "choose_lock_generic";
|
||||
private static final String FAKE_ACTION_SCREEN_LOCK_SETTINGS = "screen_lock_settings";
|
||||
|
||||
private Context mApplicationContext;
|
||||
|
||||
@Mock
|
||||
@@ -52,6 +59,9 @@ public class LockScreenSafetySourceTest {
|
||||
@Mock
|
||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||
|
||||
@Mock
|
||||
private ScreenLockPreferenceDetailsUtils mScreenLockPreferenceDetailsUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -70,30 +80,160 @@ public class LockScreenSafetySourceTest {
|
||||
public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() {
|
||||
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext);
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenSafetyCenterIsEnabled_sendsPlaceholderData() {
|
||||
public void sendSafetyData_whenScreenLockIsDisabled_sendsNoData() {
|
||||
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenScreenLockIsEnabled_sendsData() {
|
||||
whenScreenLockIsEnabled();
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext);
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceData.getId()).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID);
|
||||
assertThat(safetySourceStatus.getTitle().toString()).isEqualTo("Lock Screen");
|
||||
assertThat(safetySourceStatus.getTitle().toString())
|
||||
.isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext,
|
||||
"unlock_set_unlock_launch_picker_title_profile"));
|
||||
assertThat(safetySourceStatus.getSummary().toString())
|
||||
.isEqualTo("Lock screen settings");
|
||||
.isEqualTo(SUMMARY);
|
||||
assertThat(safetySourceStatus.getPendingIntent().getIntent()).isNotNull();
|
||||
assertThat(safetySourceStatus.getPendingIntent().getIntent().getAction())
|
||||
.isEqualTo(FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenLockPatternIsSecure_sendsStatusLevelOk() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.getStatusLevel())
|
||||
.isEqualTo(SafetySourceStatus.STATUS_LEVEL_OK);
|
||||
assertThat(safetySourceStatus.getPendingIntent()).isNotNull();
|
||||
assertThat(safetySourceStatus.getPendingIntent().getIntent().getStringExtra(
|
||||
SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(ChooseLockGeneric.ChooseLockGenericFragment.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenLockPatternIsNotSecure_sendsStatusLevelRecommendation() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.getStatusLevel())
|
||||
.isEqualTo(SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenPasswordQualityIsManaged_sendsDisabled() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mScreenLockPreferenceDetailsUtils.isPasswordQualityManaged(anyInt(), any()))
|
||||
.thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenPasswordQualityIsNotManaged_sendsEnabled() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mScreenLockPreferenceDetailsUtils.isPasswordQualityManaged(anyInt(), any()))
|
||||
.thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenShouldShowGearMenu_sendsGearMenuActionIcon() {
|
||||
whenScreenLockIsEnabled();
|
||||
final Intent launchScreenLockSettings = new Intent(FAKE_ACTION_SCREEN_LOCK_SETTINGS);
|
||||
when(mScreenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent())
|
||||
.thenReturn(launchScreenLockSettings);
|
||||
when(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).thenReturn(true);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
final ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(
|
||||
SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
final IconAction iconAction = captor.getValue().getStatus().getIconAction();
|
||||
|
||||
assertThat(iconAction.getIconType()).isEqualTo(IconAction.ICON_TYPE_GEAR);
|
||||
assertThat(iconAction.getPendingIntent().getIntent().getAction())
|
||||
.isEqualTo(FAKE_ACTION_SCREEN_LOCK_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSafetyData_whenShouldNotShowGearMenu_sendsNoGearMenuActionIcon() {
|
||||
whenScreenLockIsEnabled();
|
||||
when(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).thenReturn(false);
|
||||
|
||||
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||
mScreenLockPreferenceDetailsUtils);
|
||||
|
||||
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||
SafetySourceData safetySourceData = captor.getValue();
|
||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||
|
||||
assertThat(safetySourceStatus.getIconAction()).isNull();
|
||||
}
|
||||
|
||||
private void whenScreenLockIsEnabled() {
|
||||
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(true);
|
||||
when(mScreenLockPreferenceDetailsUtils.getSummary(anyInt())).thenReturn(SUMMARY);
|
||||
|
||||
Intent launchChooseLockGenericFragment = new Intent(
|
||||
FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT);
|
||||
when(mScreenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent())
|
||||
.thenReturn(launchChooseLockGenericFragment);
|
||||
}
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
||||
.thenReturn(mDevicePolicyManager);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
doNothing().when(mContext).startActivity(any());
|
||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
|
||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
|
||||
|
||||
final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||
@@ -253,6 +253,20 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isLockPatternSecure_patternIsSecure_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isLockPatternSecure_patternIsNotSecure_shouldReturnFalse() {
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowGearMenu_patternIsSecure_shouldReturnTrue() {
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
@@ -274,6 +288,13 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
||||
assertFragmentLaunchRequested(ScreenLockSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLaunchScreenLockSettingsIntent_returnsIntent() {
|
||||
final Intent intent = mScreenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent();
|
||||
|
||||
assertFragmentLaunchIntent(intent, ScreenLockSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openChooseLockGenericFragment_noQuietMode_shouldSendIntent_shouldReturnTrue() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
||||
@@ -282,6 +303,17 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
||||
assertFragmentLaunchRequested(ChooseLockGeneric.ChooseLockGenericFragment.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLaunchChooseLockGenericFragmentIntent_noQuietMode_returnsIntent() {
|
||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
||||
|
||||
final Intent intent =
|
||||
mScreenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent();
|
||||
|
||||
assertFragmentLaunchIntent(intent,
|
||||
ChooseLockGeneric.ChooseLockGenericFragment.class.getName());
|
||||
}
|
||||
|
||||
private void whenConfigShowUnlockSetOrChangeIsEnabled(boolean enabled) {
|
||||
final int resId = ResourcesUtils.getResourcesId(
|
||||
ApplicationProvider.getApplicationContext(), "bool",
|
||||
@@ -301,6 +333,10 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
||||
verify(mContext).startActivity(intentCaptor.capture());
|
||||
|
||||
Intent intent = intentCaptor.getValue();
|
||||
assertFragmentLaunchIntent(intent, fragmentClassName);
|
||||
}
|
||||
|
||||
private void assertFragmentLaunchIntent(Intent intent, String fragmentClassName) {
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(fragmentClassName);
|
||||
assertThat(intent.getIntExtra(
|
||||
|
Reference in New Issue
Block a user