Provide data to LockScreenSafetySource
Test: atest SettingsUnitTests Bug: 215515298 Change-Id: I59640e9f691754a2225870d40f5db3e6fd8557f8
This commit is contained in:
@@ -17,51 +17,76 @@
|
|||||||
package com.android.settings.safetycenter;
|
package com.android.settings.safetycenter;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.settings.SettingsEnums;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.safetycenter.SafetySourceData;
|
import android.safetycenter.SafetySourceData;
|
||||||
import android.safetycenter.SafetySourceStatus;
|
import android.safetycenter.SafetySourceStatus;
|
||||||
|
import android.safetycenter.SafetySourceStatus.IconAction;
|
||||||
|
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.R;
|
||||||
import com.android.settings.password.ChooseLockGeneric;
|
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
|
|
||||||
/** Lock Screen Safety Source for Safety Center. */
|
/** Lock Screen Safety Source for Safety Center. */
|
||||||
public final class LockScreenSafetySource {
|
public final class LockScreenSafetySource {
|
||||||
|
|
||||||
public static final String SAFETY_SOURCE_ID = "LockScreenSafetySource";
|
public static final String SAFETY_SOURCE_ID = "LockScreenSafetySource";
|
||||||
|
|
||||||
private LockScreenSafetySource() {}
|
private LockScreenSafetySource() {
|
||||||
|
}
|
||||||
|
|
||||||
/** Sends lock screen safety data to Safety Center. */
|
/** Sends lock screen safety data to Safety Center. */
|
||||||
public static void sendSafetyData(Context context) {
|
public static void sendSafetyData(Context context,
|
||||||
|
ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
|
||||||
if (!SafetyCenterStatusHolder.get().isEnabled(context)) {
|
if (!SafetyCenterStatusHolder.get().isEnabled(context)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(b/215515298): Replace placeholder SafetySourceData with real data.
|
if (!screenLockPreferenceDetailsUtils.isAvailable()) {
|
||||||
// TODO(b/217409995): Replace SECURITY_ALTERNATIVE with Safety Center metrics category.
|
return;
|
||||||
Intent clickIntent = new SubSettingLauncher(context)
|
}
|
||||||
.setDestination(ChooseLockGeneric.ChooseLockGenericFragment.class.getName())
|
|
||||||
.setSourceMetricsCategory(SettingsEnums.SECURITY_ALTERNATIVE)
|
final int userId = UserHandle.myUserId();
|
||||||
.setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
|
final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtilsInternal
|
||||||
.toIntent();
|
.checkIfPasswordQualityIsSet(context, userId);
|
||||||
PendingIntent pendingIntent = PendingIntent
|
final PendingIntent pendingIntent = createPendingIntent(context,
|
||||||
.getActivity(
|
screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent());
|
||||||
context,
|
final IconAction gearMenuIconAction = createGearMenuIconAction(context,
|
||||||
0 /* requestCode */,
|
screenLockPreferenceDetailsUtils);
|
||||||
clickIntent,
|
|
||||||
PendingIntent.FLAG_IMMUTABLE);
|
final SafetySourceStatus status = new SafetySourceStatus.Builder(
|
||||||
SafetySourceData safetySourceData =
|
context.getString(R.string.unlock_set_unlock_launch_picker_title_profile),
|
||||||
new SafetySourceData.Builder(SAFETY_SOURCE_ID).setStatus(
|
screenLockPreferenceDetailsUtils.getSummary(UserHandle.myUserId()),
|
||||||
new SafetySourceStatus.Builder(
|
screenLockPreferenceDetailsUtils.isLockPatternSecure()
|
||||||
"Lock Screen",
|
? SafetySourceStatus.STATUS_LEVEL_OK
|
||||||
"Lock screen settings",
|
: SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION,
|
||||||
SafetySourceStatus.STATUS_LEVEL_OK,
|
pendingIntent)
|
||||||
pendingIntent).build()
|
.setEnabled(
|
||||||
).build();
|
!screenLockPreferenceDetailsUtils.isPasswordQualityManaged(userId, admin))
|
||||||
|
.setIconAction(gearMenuIconAction).build();
|
||||||
|
final SafetySourceData safetySourceData = new SafetySourceData.Builder(
|
||||||
|
SAFETY_SOURCE_ID).setStatus(status).build();
|
||||||
|
|
||||||
SafetyCenterManagerWrapper.get().sendSafetyCenterUpdate(context, safetySourceData);
|
SafetyCenterManagerWrapper.get().sendSafetyCenterUpdate(context, safetySourceData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IconAction createGearMenuIconAction(Context context,
|
||||||
|
ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
|
||||||
|
return screenLockPreferenceDetailsUtils.shouldShowGearMenu() ? new IconAction(
|
||||||
|
IconAction.ICON_TYPE_GEAR,
|
||||||
|
createPendingIntent(context,
|
||||||
|
screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent()))
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PendingIntent createPendingIntent(Context context, Intent intent) {
|
||||||
|
return PendingIntent
|
||||||
|
.getActivity(
|
||||||
|
context,
|
||||||
|
0 /* requestCode */,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,10 +20,13 @@ import static android.content.Intent.ACTION_BOOT_COMPLETED;
|
|||||||
import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES;
|
import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES;
|
||||||
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
|
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -54,7 +57,8 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
private static void refreshSafetySources(Context context, List<String> sourceIds) {
|
private static void refreshSafetySources(Context context, List<String> sourceIds) {
|
||||||
if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
|
if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
|
||||||
LockScreenSafetySource.sendSafetyData(context);
|
LockScreenSafetySource.sendSafetyData(context,
|
||||||
|
new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
|
if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
|
||||||
@@ -63,7 +67,8 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void refreshAllSafetySources(Context context) {
|
private static void refreshAllSafetySources(Context context) {
|
||||||
LockScreenSafetySource.sendSafetyData(context);
|
LockScreenSafetySource.sendSafetyData(context,
|
||||||
|
new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER));
|
||||||
BiometricsSafetySource.sendSafetyData(context);
|
BiometricsSafetySource.sendSafetyData(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,12 +18,14 @@ package com.android.settings.security;
|
|||||||
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
|
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
|
||||||
|
import com.android.internal.app.UnlaunchableAppActivity;
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
@@ -81,21 +83,35 @@ public class ScreenLockPreferenceDetailsUtils {
|
|||||||
== DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
|
== DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the lock pattern is secure.
|
||||||
|
*/
|
||||||
|
public boolean isLockPatternSecure() {
|
||||||
|
return mLockPatternUtils.isSecure(mUserId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the Gear Menu should be shown.
|
* Returns whether the Gear Menu should be shown.
|
||||||
*/
|
*/
|
||||||
public boolean shouldShowGearMenu() {
|
public boolean shouldShowGearMenu() {
|
||||||
return mLockPatternUtils.isSecure(mUserId);
|
return isLockPatternSecure();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launches the {@link ScreenLockSettings}.
|
* Launches the {@link ScreenLockSettings}.
|
||||||
*/
|
*/
|
||||||
public void openScreenLockSettings() {
|
public void openScreenLockSettings() {
|
||||||
new SubSettingLauncher(mContext)
|
mContext.startActivity(getLaunchScreenLockSettingsIntent());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@link Intent} to launch the {@link ScreenLockSettings}.
|
||||||
|
*/
|
||||||
|
public Intent getLaunchScreenLockSettingsIntent() {
|
||||||
|
return new SubSettingLauncher(mContext)
|
||||||
.setDestination(ScreenLockSettings.class.getName())
|
.setDestination(ScreenLockSettings.class.getName())
|
||||||
.setSourceMetricsCategory(mSourceMetricsCategory)
|
.setSourceMetricsCategory(mSourceMetricsCategory)
|
||||||
.launch();
|
.toIntent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,6 +121,29 @@ public class ScreenLockPreferenceDetailsUtils {
|
|||||||
* @return true if the {@link ChooseLockGenericFragment} is launching.
|
* @return true if the {@link ChooseLockGenericFragment} is launching.
|
||||||
*/
|
*/
|
||||||
public boolean openChooseLockGenericFragment() {
|
public boolean openChooseLockGenericFragment() {
|
||||||
|
final Intent quietModeDialogIntent = getQuietModeDialogIntent();
|
||||||
|
if (quietModeDialogIntent != null) {
|
||||||
|
mContext.startActivity(quietModeDialogIntent);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mContext.startActivity(getChooseLockGenericFragmentIntent());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@link Intent} to launch an appropriate Settings screen.
|
||||||
|
*
|
||||||
|
* <p>If Quiet Mode is enabled for managed profile, returns {@link Intent} to launch a dialog
|
||||||
|
* to disable the Quiet Mode, otherwise returns {@link Intent} to launch
|
||||||
|
* {@link ChooseLockGenericFragment}.
|
||||||
|
*/
|
||||||
|
public Intent getLaunchChooseLockGenericFragmentIntent() {
|
||||||
|
final Intent quietModeDialogIntent = getQuietModeDialogIntent();
|
||||||
|
return quietModeDialogIntent != null ? quietModeDialogIntent
|
||||||
|
: getChooseLockGenericFragmentIntent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Intent getQuietModeDialogIntent() {
|
||||||
// TODO(b/35930129): Remove once existing password can be passed into vold directly.
|
// TODO(b/35930129): Remove once existing password can be passed into vold directly.
|
||||||
// Currently we need this logic to ensure that the QUIET_MODE is off for any work
|
// Currently we need this logic to ensure that the QUIET_MODE is off for any work
|
||||||
// profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be
|
// profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be
|
||||||
@@ -112,17 +151,20 @@ public class ScreenLockPreferenceDetailsUtils {
|
|||||||
if (mProfileChallengeUserId != UserHandle.USER_NULL
|
if (mProfileChallengeUserId != UserHandle.USER_NULL
|
||||||
&& !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)
|
&& !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)
|
||||||
&& StorageManager.isFileEncryptedNativeOnly()) {
|
&& StorageManager.isFileEncryptedNativeOnly()) {
|
||||||
if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) {
|
if (mUm.isQuietModeEnabled(UserHandle.of(mProfileChallengeUserId))) {
|
||||||
return false;
|
return UnlaunchableAppActivity.createInQuietModeDialogIntent(
|
||||||
|
mProfileChallengeUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
new SubSettingLauncher(mContext)
|
private Intent getChooseLockGenericFragmentIntent() {
|
||||||
|
return new SubSettingLauncher(mContext)
|
||||||
.setDestination(ChooseLockGenericFragment.class.getName())
|
.setDestination(ChooseLockGenericFragment.class.getName())
|
||||||
.setSourceMetricsCategory(mSourceMetricsCategory)
|
.setSourceMetricsCategory(mSourceMetricsCategory)
|
||||||
.setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
|
.setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
|
||||||
.launch();
|
.toIntent();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@StringRes
|
@StringRes
|
||||||
|
@@ -19,19 +19,22 @@ package com.android.settings.safetycenter;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.safetycenter.SafetySourceData;
|
import android.safetycenter.SafetySourceData;
|
||||||
import android.safetycenter.SafetySourceStatus;
|
import android.safetycenter.SafetySourceStatus;
|
||||||
|
import android.safetycenter.SafetySourceStatus.IconAction;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||||
import com.android.settings.password.ChooseLockGeneric;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -44,6 +47,10 @@ import org.mockito.MockitoAnnotations;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class LockScreenSafetySourceTest {
|
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;
|
private Context mApplicationContext;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@@ -52,6 +59,9 @@ public class LockScreenSafetySourceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
private SafetyCenterStatusHolder mSafetyCenterStatusHolder;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ScreenLockPreferenceDetailsUtils mScreenLockPreferenceDetailsUtils;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
@@ -70,30 +80,160 @@ public class LockScreenSafetySourceTest {
|
|||||||
public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() {
|
public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() {
|
||||||
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(false);
|
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(false);
|
||||||
|
|
||||||
LockScreenSafetySource.sendSafetyData(mApplicationContext);
|
LockScreenSafetySource.sendSafetyData(mApplicationContext,
|
||||||
|
mScreenLockPreferenceDetailsUtils);
|
||||||
|
|
||||||
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendSafetyData_whenSafetyCenterIsEnabled_sendsPlaceholderData() {
|
public void sendSafetyData_whenScreenLockIsDisabled_sendsNoData() {
|
||||||
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);
|
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);
|
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
|
||||||
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
|
||||||
SafetySourceData safetySourceData = captor.getValue();
|
SafetySourceData safetySourceData = captor.getValue();
|
||||||
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
|
||||||
|
|
||||||
assertThat(safetySourceData.getId()).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID);
|
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())
|
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())
|
assertThat(safetySourceStatus.getStatusLevel())
|
||||||
.isEqualTo(SafetySourceStatus.STATUS_LEVEL_OK);
|
.isEqualTo(SafetySourceStatus.STATUS_LEVEL_OK);
|
||||||
assertThat(safetySourceStatus.getPendingIntent()).isNotNull();
|
}
|
||||||
assertThat(safetySourceStatus.getPendingIntent().getIntent().getStringExtra(
|
|
||||||
SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
@Test
|
||||||
.isEqualTo(ChooseLockGeneric.ChooseLockGenericFragment.class.getName());
|
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);
|
.thenReturn(mDevicePolicyManager);
|
||||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||||
doNothing().when(mContext).startActivity(any());
|
doNothing().when(mContext).startActivity(any());
|
||||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
|
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
|
||||||
|
|
||||||
final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
|
final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
|
||||||
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
@@ -253,6 +253,20 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
|||||||
.isFalse();
|
.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
|
@Test
|
||||||
public void shouldShowGearMenu_patternIsSecure_shouldReturnTrue() {
|
public void shouldShowGearMenu_patternIsSecure_shouldReturnTrue() {
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
@@ -274,6 +288,13 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
|||||||
assertFragmentLaunchRequested(ScreenLockSettings.class.getName());
|
assertFragmentLaunchRequested(ScreenLockSettings.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLaunchScreenLockSettingsIntent_returnsIntent() {
|
||||||
|
final Intent intent = mScreenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent();
|
||||||
|
|
||||||
|
assertFragmentLaunchIntent(intent, ScreenLockSettings.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void openChooseLockGenericFragment_noQuietMode_shouldSendIntent_shouldReturnTrue() {
|
public void openChooseLockGenericFragment_noQuietMode_shouldSendIntent_shouldReturnTrue() {
|
||||||
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
when(mUserManager.isQuietModeEnabled(any())).thenReturn(false);
|
||||||
@@ -282,6 +303,17 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
|||||||
assertFragmentLaunchRequested(ChooseLockGeneric.ChooseLockGenericFragment.class.getName());
|
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) {
|
private void whenConfigShowUnlockSetOrChangeIsEnabled(boolean enabled) {
|
||||||
final int resId = ResourcesUtils.getResourcesId(
|
final int resId = ResourcesUtils.getResourcesId(
|
||||||
ApplicationProvider.getApplicationContext(), "bool",
|
ApplicationProvider.getApplicationContext(), "bool",
|
||||||
@@ -301,6 +333,10 @@ public class ScreenLockPreferenceDetailsUtilsTest {
|
|||||||
verify(mContext).startActivity(intentCaptor.capture());
|
verify(mContext).startActivity(intentCaptor.capture());
|
||||||
|
|
||||||
Intent intent = intentCaptor.getValue();
|
Intent intent = intentCaptor.getValue();
|
||||||
|
assertFragmentLaunchIntent(intent, fragmentClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertFragmentLaunchIntent(Intent intent, String fragmentClassName) {
|
||||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||||
.isEqualTo(fragmentClassName);
|
.isEqualTo(fragmentClassName);
|
||||||
assertThat(intent.getIntExtra(
|
assertThat(intent.getIntExtra(
|
||||||
|
Reference in New Issue
Block a user