From 7851c33bbda1b6ee8915fb431e9202d754bd7d98 Mon Sep 17 00:00:00 2001 From: Olivier Nshimiye Date: Thu, 28 Mar 2024 11:06:03 +0000 Subject: [PATCH] Remove 'Hide Sensitive Notifications' item from PS settings page Remove the hide sensitive notifications toggle, but keep private space sensitive notifications always hidden on lockscreen Bug: 329657118 Test: atest PrivateSpaceMaintainerTest Test: Manual - verified that PS sensitive notifications are always hidden on lockscreen. Change-Id: Id4229c11a2c5a3a4d3fedaf710c51f25af64bf86 --- res/values/strings.xml | 6 - res/xml/private_space_settings.xml | 11 -- ...SpaceSensitiveNotificationsController.java | 106 ----------- .../privatespace/PrivateSpaceMaintainer.java | 4 +- ...eSensitiveNotificationsControllerTest.java | 164 ------------------ .../PrivateSpaceMaintainerTest.java | 5 +- 6 files changed, 6 insertions(+), 290 deletions(-) delete mode 100644 src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsController.java delete mode 100644 tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 3268b2f06dd..9fbce465110 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1380,12 +1380,6 @@ Set a password for your private space Set a pattern for your private space - - Apps and notifications - - Sensitive notifications on lock screen - - Show sensitive content when private space is unlocked Create a Google Account to help keep your data private diff --git a/res/xml/private_space_settings.xml b/res/xml/private_space_settings.xml index f9795990903..b1233b9d797 100644 --- a/res/xml/private_space_settings.xml +++ b/res/xml/private_space_settings.xml @@ -59,17 +59,6 @@ - - - - - - diff --git a/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsController.java b/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsController.java deleted file mode 100644 index 6cb54a1cd89..00000000000 --- a/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsController.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.privatespace; - -import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS; - -import android.content.Context; -import android.os.UserHandle; -import android.provider.Settings; - -import androidx.annotation.NonNull; - -import com.android.settings.core.TogglePreferenceController; - -import java.util.Objects; - -/** - * A controller object for sensitive notifications in Private Space settings page. - */ -public class HidePrivateSpaceSensitiveNotificationsController extends TogglePreferenceController { - private final PrivateSpaceMaintainer mPrivateSpaceMaintainer; - private final UserHandle mPrivateProfileId; - public static final int ENABLED = 1; - public static final int DISABLED = 0; - private static final int DEVICE_SENSITIVE_NOTIFICATIONS_DEFAULT = ENABLED; - private static final int DEVICE_LOCK_SCREEN_NOTIFICATIONS_DEFAULT = ENABLED; - private static final int PRIVATE_SPACE_SENSITIVE_NOTIFICATIONS_DEFAULT = DISABLED; - - public HidePrivateSpaceSensitiveNotificationsController(@NonNull Context context, - @NonNull String preferenceKey) { - super(context, preferenceKey); - mPrivateSpaceMaintainer = PrivateSpaceMaintainer.getInstance(context); - mPrivateProfileId = Objects.requireNonNull( - mPrivateSpaceMaintainer.getPrivateProfileHandle()); - } - - @Override - public int getAvailabilityStatus() { - if (!android.os.Flags.allowPrivateProfile() - || !android.multiuser.Flags.enablePsSensitiveNotificationsToggle() - || !android.multiuser.Flags.enablePrivateSpaceFeatures() - || !mPrivateSpaceMaintainer.doesPrivateSpaceExist()) { - return UNSUPPORTED_ON_DEVICE; - } - if (!getLockscreenNotificationsEnabled(mContext) - || !getLockscreenSensitiveNotificationsEnabledOnDevice(mContext)) { - return DISABLED_DEPENDENT_SETTING; - } - return AVAILABLE; - } - - @Override - public boolean isChecked() { - return Settings.Secure.getIntForUser(mContext.getContentResolver(), - LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - PRIVATE_SPACE_SENSITIVE_NOTIFICATIONS_DEFAULT, mPrivateProfileId.getIdentifier()) - != DISABLED; - } - - @Override - public boolean setChecked(boolean isChecked) { - Settings.Secure.putIntForUser(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - isChecked ? ENABLED : DISABLED, mPrivateProfileId.getIdentifier()); - return true; - } - - @Override - public int getSliceHighlightMenuRes() { - return 0; - } - - /** - * If notifications are disabled on the device, the toggle for private space sensitive - * notifications should be unavailable. - */ - private static boolean getLockscreenNotificationsEnabled(Context context) { - return Settings.Secure.getInt(context.getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, - DEVICE_LOCK_SCREEN_NOTIFICATIONS_DEFAULT) != DISABLED; - } - - /** - * If sensitive notifications are hidden on the device, they should be hidden for private space - * also. - */ - private static boolean getLockscreenSensitiveNotificationsEnabledOnDevice(Context context) { - return Settings.Secure.getInt(context.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - DEVICE_SENSITIVE_NOTIFICATIONS_DEFAULT) != DISABLED; - } -} diff --git a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java index 6a9ea9dcbca..300cbdbb2fb 100644 --- a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java +++ b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java @@ -65,6 +65,8 @@ public class PrivateSpaceMaintainer { @Settings.Secure.PrivateSpaceAutoLockOption public static final int PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL = PRIVATE_SPACE_AUTO_LOCK_AFTER_DEVICE_RESTART; + /** Default value for the hide private space sensitive notifications on lockscreen. */ + public static final int HIDE_PRIVATE_SPACE_SENSITIVE_NOTIFICATIONS_DISABLED_VAL = 0; public enum ErrorDeletingPrivateSpace { DELETE_PS_ERROR_NONE, @@ -316,7 +318,7 @@ public class PrivateSpaceMaintainer { private void setPrivateSpaceSensitiveNotificationsDefaultValue() { Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - HidePrivateSpaceSensitiveNotificationsController.DISABLED, + HIDE_PRIVATE_SPACE_SENSITIVE_NOTIFICATIONS_DISABLED_VAL, mUserHandle.getIdentifier()); } diff --git a/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsControllerTest.java b/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsControllerTest.java deleted file mode 100644 index 88503a525b6..00000000000 --- a/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsControllerTest.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.privatespace; - -import static com.android.settings.core.BasePreferenceController.AVAILABLE; -import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING; -import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; - -import static com.google.common.truth.Truth.assertThat; - -import static org.junit.Assume.assumeTrue; -import static org.mockito.Mockito.spy; - -import android.content.ContentResolver; -import android.content.Context; -import android.platform.test.flag.junit.SetFlagsRule; -import android.provider.Settings; - -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; - -/** - * Tests for HidePrivateSpaceSensitiveNotificationsController. - * Run as {@code atest SettingsUnitTests:HidePrivateSpaceSensitiveNotificationsControllerTest} - */ -@RunWith(AndroidJUnit4.class) -public class HidePrivateSpaceSensitiveNotificationsControllerTest { - @Rule - public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); - - private Context mContext; - private HidePrivateSpaceSensitiveNotificationsController - mHidePrivateSpaceSensitiveNotificationsController; - @Mock - private ContentResolver mContentResolver; - private int mOriginalDeviceSensitiveNotifValue; - private int mOriginalDeviceNotifValue; - private int mOriginalPsSensitiveNotifValue; - private int mPrivateProfileId; - - @Before - public void setUp() { - mContext = spy(ApplicationProvider.getApplicationContext()); - mContentResolver = mContext.getContentResolver(); - assumeTrue(PrivateSpaceMaintainer.getInstance(mContext).doesPrivateSpaceExist()); - - mSetFlagsRule.enableFlags( - android.multiuser.Flags.FLAG_ENABLE_PS_SENSITIVE_NOTIFICATIONS_TOGGLE); - mSetFlagsRule.enableFlags(android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE, - android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES); - - mPrivateProfileId = PrivateSpaceMaintainer.getInstance( - mContext).getPrivateProfileHandle().getIdentifier(); - - mOriginalDeviceSensitiveNotifValue = Settings.Secure.getInt(mContentResolver, - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1); - mOriginalDeviceNotifValue = Settings.Secure.getInt(mContentResolver, - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); - mOriginalPsSensitiveNotifValue = Settings.Secure.getIntForUser(mContentResolver, - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mPrivateProfileId); - - final String preferenceKey = "private_space_sensitive_notifications"; - mHidePrivateSpaceSensitiveNotificationsController = - new HidePrivateSpaceSensitiveNotificationsController(mContext, preferenceKey); - } - - @After - public void tearDown() { - Settings.Secure.putInt(mContentResolver, - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - mOriginalDeviceSensitiveNotifValue - ); - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, mOriginalDeviceNotifValue); - Settings.Secure.putIntForUser(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - mOriginalPsSensitiveNotifValue, mPrivateProfileId); - } - - /** - * Tests that the controller is unavailable if lockscreen sensitive notifications are disabled - * on the device. - */ - @Test - public void getAvailabilityStatus_lockScreenPrivateNotificationsOff() { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0); - assertThat(mHidePrivateSpaceSensitiveNotificationsController.getAvailabilityStatus()) - .isEqualTo(DISABLED_DEPENDENT_SETTING); - } - - /** - * Tests that the controller is unavailable if lockscreen notifications are disabled on the - * device. - */ - @Test - public void getAvailabilityStatus_lockScreenNotificationsOff() { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0); - assertThat(mHidePrivateSpaceSensitiveNotificationsController.getAvailabilityStatus()) - .isEqualTo(DISABLED_DEPENDENT_SETTING); - } - - /** - * Tests that the controller is available if lockscreen notifications and lockscreen private - * notifications are enabled on the device. - */ - @Test - public void getAvailabilityStatus_returnAvailable() { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1); - assertThat(mHidePrivateSpaceSensitiveNotificationsController.getAvailabilityStatus()) - .isEqualTo(AVAILABLE); - } - - - /** - * Tests that toggle is not available if the flag for this feature and MVP flag are disabled. - */ - @Test - public void getAvailabilityStatus_flagDisabled() { - mSetFlagsRule.disableFlags( - android.multiuser.Flags.FLAG_ENABLE_PS_SENSITIVE_NOTIFICATIONS_TOGGLE); - mSetFlagsRule.disableFlags(android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE, - android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES); - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1); - assertThat(mHidePrivateSpaceSensitiveNotificationsController.getAvailabilityStatus()) - .isEqualTo(UNSUPPORTED_ON_DEVICE); - } - - @Test - public void testSetChecked() { - assertThat(mHidePrivateSpaceSensitiveNotificationsController.setChecked(true)).isTrue(); - assertThat(mHidePrivateSpaceSensitiveNotificationsController.isChecked()).isEqualTo(true); - assertThat(mHidePrivateSpaceSensitiveNotificationsController.setChecked(false)).isTrue(); - assertThat(mHidePrivateSpaceSensitiveNotificationsController.isChecked()).isEqualTo(false); - } -} diff --git a/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java b/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java index 98797d5cfcd..e0f855acbbe 100644 --- a/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java +++ b/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java @@ -21,6 +21,7 @@ import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK; import static com.android.settings.privatespace.PrivateSpaceMaintainer.HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL; import static com.android.settings.privatespace.PrivateSpaceMaintainer.HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL; +import static com.android.settings.privatespace.PrivateSpaceMaintainer.HIDE_PRIVATE_SPACE_SENSITIVE_NOTIFICATIONS_DISABLED_VAL; import static com.android.settings.privatespace.PrivateSpaceMaintainer.PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL; import static com.google.common.truth.Truth.assertThat; @@ -162,7 +163,7 @@ public class PrivateSpaceMaintainerTest { privateSpaceMaintainer.createPrivateSpace(); assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isTrue(); assertThat(getPsSensitiveNotificationsValue(privateSpaceMaintainer)) - .isEqualTo(HidePrivateSpaceSensitiveNotificationsController.DISABLED); + .isEqualTo(HIDE_PRIVATE_SPACE_SENSITIVE_NOTIFICATIONS_DISABLED_VAL); } /** @@ -374,7 +375,7 @@ public class PrivateSpaceMaintainerTest { private int getPsSensitiveNotificationsValue(PrivateSpaceMaintainer privateSpaceMaintainer) { return Settings.Secure.getIntForUser(mContentResolver, LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, - HidePrivateSpaceSensitiveNotificationsController.ENABLED, + /* enabled */ 1, privateSpaceMaintainer.getPrivateProfileHandle().getIdentifier()); } }