Merge "Add enterprise popup to notif lockscreen settings" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
16861ac068
@@ -28,9 +28,7 @@ import static com.android.settings.core.BasePreferenceController.DISABLED_DEPEND
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
@@ -39,11 +37,17 @@ import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.Adjustment;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,14 +55,13 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowUtils.class,
|
||||
ShadowRestrictedLockUtilsInternal.class,
|
||||
})
|
||||
public class RedactNotificationPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
@@ -77,8 +80,8 @@ public class RedactNotificationPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private RedactNotificationPreferenceController mController;
|
||||
private RedactNotificationPreferenceController mWorkController;
|
||||
private Preference mPreference;
|
||||
private Preference mWorkPreference;
|
||||
private RestrictedSwitchPreference mPreference;
|
||||
private RestrictedSwitchPreference mWorkPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -92,21 +95,29 @@ public class RedactNotificationPreferenceControllerTest {
|
||||
when(mMockContext.getSystemService(UserManager.class)).thenReturn(mUm);
|
||||
when(mMockContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDpm);
|
||||
when(mMockContext.getSystemService(KeyguardManager.class)).thenReturn(mKm);
|
||||
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {10});
|
||||
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {0});
|
||||
|
||||
mController = new RedactNotificationPreferenceController(
|
||||
mMockContext, RedactNotificationPreferenceController.KEY_LOCKSCREEN_REDACT);
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference = new RestrictedSwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
when(mScreen.findPreference(
|
||||
mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
assertThat(mController.mProfileUserId).isEqualTo(0);
|
||||
|
||||
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {0, 10});
|
||||
mWorkController = new RedactNotificationPreferenceController(mMockContext,
|
||||
RedactNotificationPreferenceController.KEY_LOCKSCREEN_WORK_PROFILE_REDACT);
|
||||
mWorkPreference = new Preference(mContext);
|
||||
mWorkPreference = new RestrictedSwitchPreference(mContext);
|
||||
mWorkPreference.setKey(mWorkController.getPreferenceKey());
|
||||
when(mScreen.findPreference(
|
||||
mWorkController.getPreferenceKey())).thenReturn(mWorkPreference);
|
||||
assertThat(mWorkController.mProfileUserId).isEqualTo(10);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowRestrictedLockUtilsInternal.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,21 +154,47 @@ public class RedactNotificationPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_adminSaysNoRedaction() {
|
||||
when(mDpm.getKeyguardDisabledFeatures(eq(null), anyInt())).thenReturn(
|
||||
public void displayPreference_adminSaysNoRedaction() {
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
||||
|
||||
// should otherwise show
|
||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
||||
1, 0);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
||||
1, 10);
|
||||
mController.displayPreference(mScreen);
|
||||
RestrictedSwitchPreference primaryPref =
|
||||
mScreen.findPreference(mController.getPreferenceKey());
|
||||
assertThat(primaryPref.isDisabledByAdmin()).isTrue();
|
||||
mWorkController.displayPreference(mScreen);
|
||||
RestrictedSwitchPreference workPref =
|
||||
mScreen.findPreference(mWorkController.getPreferenceKey());
|
||||
assertThat(workPref.isDisabledByAdmin()).isTrue();
|
||||
}
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
assertThat(mWorkController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
@Test
|
||||
public void displayPreference_adminSaysNoSecure() {
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
RestrictedSwitchPreference primaryPref =
|
||||
mScreen.findPreference(mController.getPreferenceKey());
|
||||
assertThat(primaryPref.isDisabledByAdmin()).isTrue();
|
||||
mWorkController.displayPreference(mScreen);
|
||||
RestrictedSwitchPreference workPref =
|
||||
mScreen.findPreference(mWorkController.getPreferenceKey());
|
||||
assertThat(workPref.isDisabledByAdmin()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference() {
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
RestrictedSwitchPreference primaryPref =
|
||||
mScreen.findPreference(mController.getPreferenceKey());
|
||||
assertThat(primaryPref.isDisabledByAdmin()).isFalse();
|
||||
mWorkController.displayPreference(mScreen);
|
||||
RestrictedSwitchPreference workPref =
|
||||
mScreen.findPreference(mWorkController.getPreferenceKey());
|
||||
assertThat(workPref.isDisabledByAdmin()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,8 +211,8 @@ public class RedactNotificationPreferenceControllerTest {
|
||||
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
||||
1, 10);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
assertThat(mWorkController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
assertThat(mWorkController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user