Add enterprise popup to notif lockscreen settings
Test: Robotests, manual with TestDPC Fixes: 137638270 Change-Id: I22c492d1455cd0a3b6036333cd51a13d87d8a475
This commit is contained in:
@@ -79,13 +79,13 @@
|
|||||||
android:singleLineTitle="false"
|
android:singleLineTitle="false"
|
||||||
android:summary="@string/summary_placeholder" />
|
android:summary="@string/summary_placeholder" />
|
||||||
|
|
||||||
<SwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="lock_screen_redact"
|
android:key="lock_screen_redact"
|
||||||
android:title="@string/lock_screen_notifs_redact"
|
android:title="@string/lock_screen_notifs_redact"
|
||||||
android:summary="@string/lock_screen_notifs_redact_summary"
|
android:summary="@string/lock_screen_notifs_redact_summary"
|
||||||
settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />
|
settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="lock_screen_work_redact"
|
android:key="lock_screen_work_redact"
|
||||||
android:title="@string/lock_screen_notifs_redact_work"
|
android:title="@string/lock_screen_notifs_redact_work"
|
||||||
android:summary="@string/lock_screen_notifs_redact_work_summary"
|
android:summary="@string/lock_screen_notifs_redact_work_summary"
|
||||||
|
@@ -84,14 +84,14 @@
|
|||||||
android:singleLineTitle="false"
|
android:singleLineTitle="false"
|
||||||
android:summary="@string/summary_placeholder" />
|
android:summary="@string/summary_placeholder" />
|
||||||
|
|
||||||
<SwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="lock_screen_redact"
|
android:key="lock_screen_redact"
|
||||||
android:order="14"
|
android:order="14"
|
||||||
android:title="@string/lock_screen_notifs_redact"
|
android:title="@string/lock_screen_notifs_redact"
|
||||||
android:summary="@string/lock_screen_notifs_redact_summary"
|
android:summary="@string/lock_screen_notifs_redact_summary"
|
||||||
settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />
|
settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="lock_screen_work_redact"
|
android:key="lock_screen_work_redact"
|
||||||
android:order="15"
|
android:order="15"
|
||||||
android:title="@string/lock_screen_notifs_redact_work"
|
android:title="@string/lock_screen_notifs_redact_work"
|
||||||
|
@@ -21,7 +21,6 @@ import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_
|
|||||||
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
|
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
|
||||||
|
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -30,13 +29,14 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.Utils;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
@@ -51,11 +51,10 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
static final String KEY_LOCKSCREEN_REDACT = "lock_screen_redact";
|
static final String KEY_LOCKSCREEN_REDACT = "lock_screen_redact";
|
||||||
static final String KEY_LOCKSCREEN_WORK_PROFILE_REDACT = "lock_screen_work_redact";
|
static final String KEY_LOCKSCREEN_WORK_PROFILE_REDACT = "lock_screen_work_redact";
|
||||||
|
|
||||||
private DevicePolicyManager mDpm;
|
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
private KeyguardManager mKm;
|
private KeyguardManager mKm;
|
||||||
private final int mProfileUserId;
|
int mProfileUserId;
|
||||||
private Preference mPreference;
|
private RestrictedSwitchPreference mPreference;
|
||||||
private ContentObserver mContentObserver =
|
private ContentObserver mContentObserver =
|
||||||
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||||
@Override
|
@Override
|
||||||
@@ -71,16 +70,28 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
super(context, settingKey);
|
super(context, settingKey);
|
||||||
|
|
||||||
mUm = context.getSystemService(UserManager.class);
|
mUm = context.getSystemService(UserManager.class);
|
||||||
mDpm = context.getSystemService(DevicePolicyManager.class);
|
|
||||||
mKm = context.getSystemService(KeyguardManager.class);
|
mKm = context.getSystemService(KeyguardManager.class);
|
||||||
|
|
||||||
mProfileUserId = Utils.getManagedProfileId(mUm, UserHandle.myUserId());
|
mProfileUserId = UserHandle.myUserId();
|
||||||
|
final int[] profileIds = mUm.getProfileIdsWithDisabled(UserHandle.myUserId());
|
||||||
|
|
||||||
|
for (int profileId : profileIds) {
|
||||||
|
if (profileId != UserHandle.myUserId()) {
|
||||||
|
mProfileUserId = profileId;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
|
||||||
|
int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
|
||||||
|
? UserHandle.myUserId() : mProfileUserId;
|
||||||
|
if (userId != UserHandle.USER_NULL) {
|
||||||
|
mPreference.setDisabledByAdmin(getEnforcedAdmin(userId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -120,10 +131,8 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
return CONDITIONALLY_UNAVAILABLE;
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// all notifs hidden? admin doesn't allow notifs or redacted notifs? disabled
|
// all notifs hidden? disabled
|
||||||
if (!getLockscreenNotificationsEnabled(userId)
|
if (!getLockscreenNotificationsEnabled(userId)) {
|
||||||
|| !adminAllowsNotifications(userId)
|
|
||||||
|| !adminAllowsUnredactedNotifications(userId)) {
|
|
||||||
return DISABLED_DEPENDENT_SETTING;
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,14 +158,16 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean adminAllowsNotifications(int userId) {
|
private RestrictedLockUtils.EnforcedAdmin getEnforcedAdmin(int userId) {
|
||||||
final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
|
RestrictedLockUtils.EnforcedAdmin admin =
|
||||||
return (dpmFlags & KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
|
RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
|
||||||
|
mContext, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS, userId);
|
||||||
|
if (admin != null) {
|
||||||
|
return admin;
|
||||||
}
|
}
|
||||||
|
admin = RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
|
||||||
private boolean adminAllowsUnredactedNotifications(int userId) {
|
mContext, KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS, userId);
|
||||||
final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
|
return admin;
|
||||||
return (dpmFlags & KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getAllowPrivateNotifications(int userId) {
|
private boolean getAllowPrivateNotifications(int userId) {
|
||||||
|
@@ -28,9 +28,7 @@ import static com.android.settings.core.BasePreferenceController.DISABLED_DEPEND
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
@@ -39,11 +37,17 @@ import android.content.Context;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
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.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -51,14 +55,13 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {
|
||||||
|
ShadowUtils.class,
|
||||||
|
ShadowRestrictedLockUtilsInternal.class,
|
||||||
|
})
|
||||||
public class RedactNotificationPreferenceControllerTest {
|
public class RedactNotificationPreferenceControllerTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@@ -77,8 +80,8 @@ public class RedactNotificationPreferenceControllerTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private RedactNotificationPreferenceController mController;
|
private RedactNotificationPreferenceController mController;
|
||||||
private RedactNotificationPreferenceController mWorkController;
|
private RedactNotificationPreferenceController mWorkController;
|
||||||
private Preference mPreference;
|
private RestrictedSwitchPreference mPreference;
|
||||||
private Preference mWorkPreference;
|
private RestrictedSwitchPreference mWorkPreference;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -92,21 +95,29 @@ public class RedactNotificationPreferenceControllerTest {
|
|||||||
when(mMockContext.getSystemService(UserManager.class)).thenReturn(mUm);
|
when(mMockContext.getSystemService(UserManager.class)).thenReturn(mUm);
|
||||||
when(mMockContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDpm);
|
when(mMockContext.getSystemService(DevicePolicyManager.class)).thenReturn(mDpm);
|
||||||
when(mMockContext.getSystemService(KeyguardManager.class)).thenReturn(mKm);
|
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(
|
mController = new RedactNotificationPreferenceController(
|
||||||
mMockContext, RedactNotificationPreferenceController.KEY_LOCKSCREEN_REDACT);
|
mMockContext, RedactNotificationPreferenceController.KEY_LOCKSCREEN_REDACT);
|
||||||
mPreference = new Preference(mContext);
|
mPreference = new RestrictedSwitchPreference(mContext);
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
when(mScreen.findPreference(
|
when(mScreen.findPreference(
|
||||||
mController.getPreferenceKey())).thenReturn(mPreference);
|
mController.getPreferenceKey())).thenReturn(mPreference);
|
||||||
|
assertThat(mController.mProfileUserId).isEqualTo(0);
|
||||||
|
|
||||||
|
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {0, 10});
|
||||||
mWorkController = new RedactNotificationPreferenceController(mMockContext,
|
mWorkController = new RedactNotificationPreferenceController(mMockContext,
|
||||||
RedactNotificationPreferenceController.KEY_LOCKSCREEN_WORK_PROFILE_REDACT);
|
RedactNotificationPreferenceController.KEY_LOCKSCREEN_WORK_PROFILE_REDACT);
|
||||||
mWorkPreference = new Preference(mContext);
|
mWorkPreference = new RestrictedSwitchPreference(mContext);
|
||||||
mWorkPreference.setKey(mWorkController.getPreferenceKey());
|
mWorkPreference.setKey(mWorkController.getPreferenceKey());
|
||||||
when(mScreen.findPreference(
|
when(mScreen.findPreference(
|
||||||
mWorkController.getPreferenceKey())).thenReturn(mWorkPreference);
|
mWorkController.getPreferenceKey())).thenReturn(mWorkPreference);
|
||||||
|
assertThat(mWorkController.mProfileUserId).isEqualTo(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
ShadowRestrictedLockUtilsInternal.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -143,21 +154,47 @@ public class RedactNotificationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_adminSaysNoRedaction() {
|
public void displayPreference_adminSaysNoRedaction() {
|
||||||
when(mDpm.getKeyguardDisabledFeatures(eq(null), anyInt())).thenReturn(
|
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||||
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
||||||
|
|
||||||
// should otherwise show
|
mController.displayPreference(mScreen);
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
RestrictedSwitchPreference primaryPref =
|
||||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
mScreen.findPreference(mController.getPreferenceKey());
|
||||||
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
assertThat(primaryPref.isDisabledByAdmin()).isTrue();
|
||||||
1, 0);
|
mWorkController.displayPreference(mScreen);
|
||||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
RestrictedSwitchPreference workPref =
|
||||||
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
mScreen.findPreference(mWorkController.getPreferenceKey());
|
||||||
1, 10);
|
assertThat(workPref.isDisabledByAdmin()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
@Test
|
||||||
assertThat(mWorkController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
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
|
@Test
|
||||||
@@ -174,8 +211,8 @@ public class RedactNotificationPreferenceControllerTest {
|
|||||||
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
LOCK_SCREEN_SHOW_NOTIFICATIONS,
|
||||||
1, 10);
|
1, 10);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
assertThat(mWorkController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
assertThat(mWorkController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user