Pick default notification setting for work profile
Managed profiles cannot completely hide notifications, so this setting should be treated as always "true" for them. Change-Id: I9808c1e9736d83efccb0e947d9097379bda59ebb Fixes: 78194020 Test: atest RedactionInterstitialTest
This commit is contained in:
@@ -18,6 +18,8 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
|
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
|
||||||
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
|
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
|
||||||
|
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
|
||||||
|
import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS;
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
@@ -164,15 +166,17 @@ public class RedactionInterstitial extends SettingsActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadFromSettings() {
|
private void loadFromSettings() {
|
||||||
final boolean managed = UserManager.get(getContext()).isManagedProfile(mUserId);
|
final boolean managedProfile = UserManager.get(getContext()).isManagedProfile(mUserId);
|
||||||
final boolean enabled = !managed || Settings.Secure.getIntForUser(getContentResolver(),
|
// Hiding all notifications is device-wide setting, managed profiles can only set
|
||||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, mUserId) != 0;
|
// whether their notifications are show in full or redacted.
|
||||||
final boolean show = Settings.Secure.getIntForUser(getContentResolver(),
|
final boolean showNotifications = managedProfile || Settings.Secure.getIntForUser(
|
||||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mUserId) != 0;
|
getContentResolver(), LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, mUserId) != 0;
|
||||||
|
final boolean showUnredacted = Settings.Secure.getIntForUser(
|
||||||
|
getContentResolver(), LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mUserId) != 0;
|
||||||
|
|
||||||
int checkedButtonId = R.id.hide_all;
|
int checkedButtonId = R.id.hide_all;
|
||||||
if (enabled) {
|
if (showNotifications) {
|
||||||
if (show && !mShowAllButton.isDisabledByAdmin()) {
|
if (showUnredacted && !mShowAllButton.isDisabledByAdmin()) {
|
||||||
checkedButtonId = R.id.show_all;
|
checkedButtonId = R.id.show_all;
|
||||||
} else if (!mRedactSensitiveButton.isDisabledByAdmin()) {
|
} else if (!mRedactSensitiveButton.isDisabledByAdmin()) {
|
||||||
checkedButtonId = R.id.redact_sensitive;
|
checkedButtonId = R.id.redact_sensitive;
|
||||||
@@ -188,9 +192,9 @@ public class RedactionInterstitial extends SettingsActivity {
|
|||||||
final boolean enabled = (checkedId != R.id.hide_all);
|
final boolean enabled = (checkedId != R.id.hide_all);
|
||||||
|
|
||||||
Settings.Secure.putIntForUser(getContentResolver(),
|
Settings.Secure.putIntForUser(getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0, mUserId);
|
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0, mUserId);
|
||||||
Settings.Secure.putIntForUser(getContentResolver(),
|
Settings.Secure.putIntForUser(getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0, mUserId);
|
LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0, mUserId);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,175 @@
|
|||||||
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
|
||||||
|
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
|
||||||
|
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
|
||||||
|
import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.robolectric.Robolectric.buildActivity;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.RestrictedRadioButton;
|
||||||
|
import com.android.settings.notification.RedactionInterstitial.RedactionInterstitialFragment;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {
|
||||||
|
SettingsShadowResources.class,
|
||||||
|
SettingsShadowResourcesImpl.class,
|
||||||
|
SettingsShadowResources.SettingsShadowTheme.class,
|
||||||
|
ShadowUtils.class,
|
||||||
|
ShadowRestrictedLockUtils.class,
|
||||||
|
ShadowUserManager.class,
|
||||||
|
})
|
||||||
|
public class RedactionInterstitialTest {
|
||||||
|
private RedactionInterstitial mActivity;
|
||||||
|
private RedactionInterstitialFragment mFragment;
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
ShadowUserManager.getShadow().reset();
|
||||||
|
ShadowRestrictedLockUtils.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primaryUserDefaultStateTest() {
|
||||||
|
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||||
|
setupActivity();
|
||||||
|
|
||||||
|
assertHideAllVisible(true);
|
||||||
|
assertEnabledButtons(true /* all */, true /* redact */);
|
||||||
|
assertSelectedButton(R.id.show_all);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primaryUserRedactSensitiveTest() {
|
||||||
|
setupSettings(1 /* show */, 0 /* showUnredacted */);
|
||||||
|
setupActivity();
|
||||||
|
|
||||||
|
assertHideAllVisible(true);
|
||||||
|
assertEnabledButtons(true /* all */, true /* redact */);
|
||||||
|
assertSelectedButton(R.id.redact_sensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primaryUserHideAllTest() {
|
||||||
|
setupSettings(0 /* show */, 0 /* showUnredacted */);
|
||||||
|
setupActivity();
|
||||||
|
|
||||||
|
assertHideAllVisible(true);
|
||||||
|
assertEnabledButtons(true /* all */, true /* redact */);
|
||||||
|
assertSelectedButton(R.id.hide_all);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primaryUserUnredactedRestrictionTest() {
|
||||||
|
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||||
|
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(
|
||||||
|
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
||||||
|
setupActivity();
|
||||||
|
|
||||||
|
assertHideAllVisible(true);
|
||||||
|
assertEnabledButtons(false /* all */, true /* redact */);
|
||||||
|
assertSelectedButton(R.id.redact_sensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primaryUserNotificationRestrictionTest() {
|
||||||
|
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||||
|
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(
|
||||||
|
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
|
||||||
|
setupActivity();
|
||||||
|
|
||||||
|
assertHideAllVisible(true);
|
||||||
|
assertEnabledButtons(false /* all */, false /* redact */);
|
||||||
|
assertSelectedButton(R.id.hide_all);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void managedProfileNoRestrictionsTest() {
|
||||||
|
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||||
|
ShadowUserManager.getShadow().addManagedProfile(UserHandle.myUserId());
|
||||||
|
setupActivity();
|
||||||
|
|
||||||
|
assertHideAllVisible(false);
|
||||||
|
assertEnabledButtons(true /* all */, true /* redact */);
|
||||||
|
assertSelectedButton(R.id.show_all);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void managedProfileUnredactedRestrictionTest() {
|
||||||
|
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||||
|
ShadowUserManager.getShadow().addManagedProfile(UserHandle.myUserId());
|
||||||
|
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(
|
||||||
|
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
||||||
|
setupActivity();
|
||||||
|
|
||||||
|
assertHideAllVisible(false);
|
||||||
|
assertEnabledButtons(false /* all */, true /* redact */);
|
||||||
|
assertSelectedButton(R.id.redact_sensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupActivity() {
|
||||||
|
mActivity = buildActivity(RedactionInterstitial.class, new Intent()).setup().get();
|
||||||
|
mFragment = (RedactionInterstitialFragment)
|
||||||
|
mActivity.getFragmentManager().findFragmentById(R.id.main_content);
|
||||||
|
assertThat(mActivity).isNotNull();
|
||||||
|
assertThat(mFragment).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupSettings(int show, int showUnredacted) {
|
||||||
|
final ContentResolver resolver = RuntimeEnvironment.application.getContentResolver();
|
||||||
|
Settings.Secure.putIntForUser(resolver,
|
||||||
|
LOCK_SCREEN_SHOW_NOTIFICATIONS, show, UserHandle.myUserId());
|
||||||
|
Settings.Secure.putIntForUser(resolver,
|
||||||
|
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, showUnredacted, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertHideAllVisible(boolean visible) {
|
||||||
|
Assert.assertEquals(visible, getButton(R.id.hide_all).getVisibility() != View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertEnabledButtons(boolean all, boolean redact) {
|
||||||
|
Assert.assertEquals(all, buttonEnabled(R.id.show_all));
|
||||||
|
Assert.assertEquals(redact, buttonEnabled(R.id.redact_sensitive));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertSelectedButton(int resId) {
|
||||||
|
Assert.assertEquals(resId == R.id.show_all, buttonChecked(R.id.show_all));
|
||||||
|
Assert.assertEquals(resId == R.id.redact_sensitive, buttonChecked(R.id.redact_sensitive));
|
||||||
|
Assert.assertEquals(resId == R.id.hide_all, buttonChecked(R.id.hide_all));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean buttonChecked(int resource) {
|
||||||
|
return getButton(resource).isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean buttonEnabled(int resource) {
|
||||||
|
return !((RestrictedRadioButton) getButton(resource)).isDisabledByAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
private RadioButton getButton(int resource) {
|
||||||
|
return (RadioButton) mFragment.getView().findViewById(resource);
|
||||||
|
}
|
||||||
|
}
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.testutils.shadow;
|
package com.android.settings.testutils.shadow;
|
||||||
|
|
||||||
|
import android.annotation.UserIdInt;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
@@ -23,15 +24,25 @@ import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|||||||
|
|
||||||
import org.robolectric.annotation.Implementation;
|
import org.robolectric.annotation.Implementation;
|
||||||
import org.robolectric.annotation.Implements;
|
import org.robolectric.annotation.Implements;
|
||||||
|
import org.robolectric.annotation.Resetter;
|
||||||
|
|
||||||
@Implements(RestrictedLockUtils.class)
|
@Implements(RestrictedLockUtils.class)
|
||||||
public class ShadowRestrictedLockUtils {
|
public class ShadowRestrictedLockUtils {
|
||||||
private static boolean isRestricted;
|
private static boolean isRestricted;
|
||||||
private static String[] restrictedPkgs;
|
private static String[] restrictedPkgs;
|
||||||
private static boolean adminSupportDetailsIntentLaunched;
|
private static boolean adminSupportDetailsIntentLaunched;
|
||||||
|
private static int keyguardDisabledFeatures;
|
||||||
|
|
||||||
|
@Resetter
|
||||||
|
public static void reset() {
|
||||||
|
isRestricted = false;
|
||||||
|
restrictedPkgs = null;
|
||||||
|
adminSupportDetailsIntentLaunched = false;
|
||||||
|
keyguardDisabledFeatures = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
public static RestrictedLockUtils.EnforcedAdmin checkIfMeteredDataRestricted(Context context,
|
public static EnforcedAdmin checkIfMeteredDataRestricted(Context context,
|
||||||
String packageName, int userId) {
|
String packageName, int userId) {
|
||||||
if (isRestricted) {
|
if (isRestricted) {
|
||||||
return new EnforcedAdmin();
|
return new EnforcedAdmin();
|
||||||
@@ -47,6 +58,12 @@ public class ShadowRestrictedLockUtils {
|
|||||||
adminSupportDetailsIntentLaunched = true;
|
adminSupportDetailsIntentLaunched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context,
|
||||||
|
int features, final @UserIdInt int userId) {
|
||||||
|
return (keyguardDisabledFeatures & features) == 0 ? null : new EnforcedAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasAdminSupportDetailsIntentLaunched() {
|
public static boolean hasAdminSupportDetailsIntentLaunched() {
|
||||||
return adminSupportDetailsIntentLaunched;
|
return adminSupportDetailsIntentLaunched;
|
||||||
}
|
}
|
||||||
@@ -62,4 +79,8 @@ public class ShadowRestrictedLockUtils {
|
|||||||
public static void setRestrictedPkgs(String... pkgs) {
|
public static void setRestrictedPkgs(String... pkgs) {
|
||||||
restrictedPkgs = pkgs;
|
restrictedPkgs = pkgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setKeyguardDisabledFeatures(int features) {
|
||||||
|
keyguardDisabledFeatures = features;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,8 +31,10 @@ import org.robolectric.shadow.api.Shadow;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Implements(value = UserManager.class, inheritImplementationMethods = true)
|
@Implements(value = UserManager.class, inheritImplementationMethods = true)
|
||||||
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
|
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
|
||||||
@@ -40,12 +42,16 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
|||||||
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
|
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
|
||||||
private final List<String> mRestrictions = new ArrayList<>();
|
private final List<String> mRestrictions = new ArrayList<>();
|
||||||
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
|
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
|
||||||
private List<UserInfo> mUserProfileInfos = new ArrayList<>();
|
private final List<UserInfo> mUserProfileInfos = new ArrayList<>();
|
||||||
|
private final Set<Integer> mManagedProfiles = new HashSet<>();
|
||||||
|
|
||||||
@Resetter
|
@Resetter
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
mUserInfos.clear();
|
||||||
mRestrictions.clear();
|
mRestrictions.clear();
|
||||||
mUserProfileInfos.clear();
|
mUserProfileInfos.clear();
|
||||||
|
mRestrictionSources.clear();
|
||||||
|
mManagedProfiles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserInfo(int userHandle, UserInfo userInfo) {
|
public void setUserInfo(int userHandle, UserInfo userInfo) {
|
||||||
@@ -95,4 +101,13 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
|||||||
String restrictionKey, UserHandle userHandle, List<EnforcingUser> enforcers) {
|
String restrictionKey, UserHandle userHandle, List<EnforcingUser> enforcers) {
|
||||||
mRestrictionSources.put(restrictionKey + userHandle.getIdentifier(), enforcers);
|
mRestrictionSources.put(restrictionKey + userHandle.getIdentifier(), enforcers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public boolean isManagedProfile(@UserIdInt int userId) {
|
||||||
|
return mManagedProfiles.contains(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addManagedProfile(int userId) {
|
||||||
|
mManagedProfiles.add(userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user