Merge "Fixed fingerprint enroll test" into main
diff --git a/res/values/config.xml b/res/values/config.xml
index 9d71671..afd6fdd 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -679,6 +679,13 @@
<!-- The ratio to use when using the two-pane settings layout -->
<item name="config_activity_embed_split_ratio" format="float" type="dimen">0.3636</item>
+ <!-- The smallest value of the smallest-width (sw) of the window in any rotation when the split
+ should be used. -->
+ <integer name="config_activity_embed_split_min_sw_dp">600</integer>
+
+ <!-- The smallest value of current width of the window when the split should be used. -->
+ <integer name="config_activity_embed_split_min_cur_dp">720</integer>
+
<!-- The number of visible app icons while entering app list related pages for preloading.
Take the "Unrestricted data" page as the example, the visible app icons could be 15
on 6.4 inches screen size whether the font size and display size are both small. -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 12a4c72..ad35e26 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1372,6 +1372,12 @@
<string name="private_space_choose_your_password_header">Set a password for your private space</string>
<!-- Header for private space choose your pattern screen [CHAR LIMIT=40] -->
<string name="private_space_choose_your_pattern_header">Set a pattern for your private space</string>
+ <!-- Header for private space apps and notifications section [CHAR LIMIT=40] -->
+ <string name="private_space_apps_and_notifications_header">Apps and notifications</string>
+ <!-- Title for private space sensitive notifications toggle [CHAR LIMIT=80] -->
+ <string name="private_space_notifications_title">Sensitive notifications on lock screen</string>
+ <!-- Summary description for private space sensitive notifications toggle [CHAR LIMIT=200] -->
+ <string name="private_space_sensitive_notifications_description">Show sensitive content when private space is unlocked</string>
<!-- Text shown when "Add fingerprint" button is disabled -->
<string name="fingerprint_add_max">You can add up to <xliff:g id="count" example="5">%d</xliff:g> fingerprints</string>
@@ -11586,7 +11592,7 @@
<string name="primary_sim_calls_title">Calls</string>
<!-- Title of Texts item/dialog at dual sim onboarding's primary sim page or SIMs page. [CHAR LIMIT=30] -->
<string name="primary_sim_texts_title">Texts</string>
- <!-- Title of automatic data switching at dual sim onboarding's primary sim page or SIMs page. [CHAR LIMIT=30] -->
+ <!-- Title of automatic data switching at dual sim onboarding's primary sim page or SIMs page. [CHAR LIMIT=60] -->
<string name="primary_sim_automatic_data_title">Automatic data switching</string>
<!-- Body text of automatic data switching at dual sim onboarding's primary sim page or SIMs page. [CHAR LIMIT=NONE] -->
<string name="primary_sim_automatic_data_msg">Use data from either SIM depending on coverage and availability</string>
diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index f1c62bb..3268466 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -57,7 +57,7 @@
settings:controller="com.android.settings.datetime.LocationProviderStatusPreferenceController"/>
<!-- This preference gets removed if location-based time zone detection is not supported -->
- <SwitchPreference
+ <SwitchPreferenceCompat
android:key="location_time_zone_detection"
android:title="@string/location_time_zone_detection_toggle_title"
settings:controller="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceController"/>
@@ -77,12 +77,12 @@
android:key="time_format_preference_category"
android:title="@string/time_format_category_title"
settings:keywords="@string/keywords_time_format">
- <SwitchPreference
+ <SwitchPreferenceCompat
android:key="auto_24hour"
android:title="@string/date_time_24hour_auto"
settings:controller="com.android.settings.datetime.AutoTimeFormatPreferenceController" />
- <SwitchPreference
+ <SwitchPreferenceCompat
android:key="24 hour"
android:title="@string/date_time_24hour"
settings:controller="com.android.settings.datetime.TimeFormatPreferenceController" />
diff --git a/res/xml/private_space_settings.xml b/res/xml/private_space_settings.xml
index 0ed9c93..e718ca8 100644
--- a/res/xml/private_space_settings.xml
+++ b/res/xml/private_space_settings.xml
@@ -60,6 +60,17 @@
</PreferenceCategory>
<PreferenceCategory
+ android:title="@string/private_space_apps_and_notifications_header">
+
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="private_space_sensitive_notifications"
+ android:title="@string/private_space_notifications_title"
+ android:summary="@string/private_space_sensitive_notifications_description"
+ settings:controller="com.android.settings.privatespace.HidePrivateSpaceSensitiveNotificationsController" />
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
android:title="@string/private_space_category_system">
<Preference
diff --git a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
index 50134ba..4e39070 100644
--- a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
+++ b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
@@ -113,8 +113,9 @@
.setFinishPrimaryWithSecondary(finishPrimaryWithSecondary)
.setFinishSecondaryWithPrimary(finishSecondaryWithPrimary)
.setClearTop(clearTop)
- .setMinWidthDp(ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthDp())
- .setMinSmallestWidthDp(ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthDp())
+ .setMinWidthDp(ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthDp(context))
+ .setMinSmallestWidthDp(
+ ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthDp(context))
.setMaxAspectRatioInPortrait(EmbeddingAspectRatio.ALWAYS_ALLOW)
.setDefaultSplitAttributes(attributes)
.build();
@@ -234,8 +235,9 @@
.build();
final SplitPlaceholderRule placeholderRule = new SplitPlaceholderRule.Builder(
activityFilters, intent)
- .setMinWidthDp(ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthDp())
- .setMinSmallestWidthDp(ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthDp())
+ .setMinWidthDp(ActivityEmbeddingUtils.getMinCurrentScreenSplitWidthDp(mContext))
+ .setMinSmallestWidthDp(
+ ActivityEmbeddingUtils.getMinSmallestScreenSplitWidthDp(mContext))
.setMaxAspectRatioInPortrait(EmbeddingAspectRatio.ALWAYS_ALLOW)
.setSticky(false)
.setFinishPrimaryWithPlaceholder(SplitRule.FinishBehavior.ADJACENT)
diff --git a/src/com/android/settings/activityembedding/ActivityEmbeddingUtils.java b/src/com/android/settings/activityembedding/ActivityEmbeddingUtils.java
index 74a9673..b91e0e5 100644
--- a/src/com/android/settings/activityembedding/ActivityEmbeddingUtils.java
+++ b/src/com/android/settings/activityembedding/ActivityEmbeddingUtils.java
@@ -33,11 +33,6 @@
/** An util class collecting all common methods for the embedding activity features. */
public class ActivityEmbeddingUtils {
- // The smallest value of current width of the window when the split should be used.
- private static final int MIN_CURRENT_SCREEN_SPLIT_WIDTH_DP = 720;
- // The smallest value of the smallest-width (sw) of the window in any rotation when
- // the split should be used.
- private static final int MIN_SMALLEST_SCREEN_SPLIT_WIDTH_DP = 600;
// The minimum width of the activity to show the regular homepage layout.
private static final float MIN_REGULAR_HOMEPAGE_LAYOUT_WIDTH_DP = 380f;
@@ -58,16 +53,16 @@
private static final String TAG = "ActivityEmbeddingUtils";
/** Get the smallest width dp of the window when the split should be used. */
- public static int getMinCurrentScreenSplitWidthDp() {
- return MIN_CURRENT_SCREEN_SPLIT_WIDTH_DP;
+ public static int getMinCurrentScreenSplitWidthDp(Context context) {
+ return context.getResources().getInteger(R.integer.config_activity_embed_split_min_cur_dp);
}
/**
* Get the smallest dp value of the smallest-width (sw) of the window in any rotation when
* the split should be used.
*/
- public static int getMinSmallestScreenSplitWidthDp() {
- return MIN_SMALLEST_SCREEN_SPLIT_WIDTH_DP;
+ public static int getMinSmallestScreenSplitWidthDp(Context context) {
+ return context.getResources().getInteger(R.integer.config_activity_embed_split_min_sw_dp);
}
/**
diff --git a/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsController.java b/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsController.java
new file mode 100644
index 0000000..1a89d37
--- /dev/null
+++ b/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsController.java
@@ -0,0 +1,105 @@
+/*
+ * 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()
+ || !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 a283147..2d38ae2 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
@@ -45,6 +45,7 @@
import java.util.List;
// TODO(b/293569406): Update the javadoc when we have the setup flow in place to create PS
+
/** A class to help with the creation / deletion of Private Space */
public class PrivateSpaceMaintainer {
private static final String TAG = "PrivateSpaceMaintainer";
@@ -65,9 +66,9 @@
public static final int PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL = PRIVATE_SPACE_AUTO_LOCK_NEVER;
public enum ErrorDeletingPrivateSpace {
- DELETE_PS_ERROR_NONE,
- DELETE_PS_ERROR_NO_PRIVATE_SPACE,
- DELETE_PS_ERROR_INTERNAL
+ DELETE_PS_ERROR_NONE,
+ DELETE_PS_ERROR_NO_PRIVATE_SPACE,
+ DELETE_PS_ERROR_INTERNAL
}
/**
@@ -90,7 +91,7 @@
if (mUserHandle == null) {
try {
mUserHandle = mUserManager.createProfile(
- userName, USER_TYPE_PROFILE_PRIVATE, new ArraySet<>());
+ userName, USER_TYPE_PROFILE_PRIVATE, new ArraySet<>());
} catch (Exception e) {
Log.e(TAG, "Error creating private space", e);
return false;
@@ -117,7 +118,8 @@
return true;
}
- /** Returns the {@link ErrorDeletingPrivateSpace} enum representing the result of operation.
+ /**
+ * Returns the {@link ErrorDeletingPrivateSpace} enum representing the result of operation.
*
* <p> This method should be used ONLY by the delete-PS controller in the PS Settings page.
*/
@@ -212,6 +214,7 @@
// TODO(b/307281644): Remove this method once new auth change is merged
+
/**
* Returns true if private space exists and a separate private profile lock is set
* otherwise false when the private space does not exit or exists but does not have a
@@ -290,9 +293,20 @@
return false;
}
+ @GuardedBy("this")
private void resetPrivateSpaceSettings() {
setHidePrivateSpaceEntryPointSetting(HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
setPrivateSpaceAutoLockSetting(PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL);
+ setPrivateSpaceSensitiveNotificationsDefaultValue();
+ }
+
+ /** Sets private space sensitive notifications hidden on lockscreen by default */
+ @GuardedBy("this")
+ private void setPrivateSpaceSensitiveNotificationsDefaultValue() {
+ Settings.Secure.putIntForUser(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
+ HidePrivateSpaceSensitiveNotificationsController.DISABLED,
+ mUserHandle.getIdentifier());
}
/**
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index 0339f57..e99c4e0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -64,7 +64,7 @@
private static final String STATUS_CHARGING_NO_TIME = "50% - charging";
private static final String STATUS_CHARGING_TIME = "50% - 0 min left until full";
private static final String STATUS_NOT_CHARGING = "Not charging";
- private static final String STATUS_CHARGING_FUTURE_BYPASS = "50% - Charging optimized";
+ private static final String STATUS_CHARGING_FUTURE_BYPASS = "50% - Charging";
private static final String STATUS_CHARGING_PAUSED = "50% - Charging optimized";
private static final long REMAINING_TIME_NULL = -1;
private static final long REMAINING_TIME = 2;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java
index 4efd850..a605ee3 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTipTest.java
@@ -82,7 +82,7 @@
@Test
public void getIcon_showIcon() {
assertThat(mBatteryDefenderTip.getIconId())
- .isEqualTo(R.drawable.ic_battery_status_good_theme);
+ .isEqualTo(R.drawable.ic_battery_defender_tip_shield);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
index 635343e..c38e36a 100644
--- a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
+++ b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
@@ -2,53 +2,56 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import android.content.Context;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.testing.FragmentScenario;
+import androidx.test.core.app.ApplicationProvider;
-import androidx.fragment.app.FragmentActivity;
-
-import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.overlay.SurveyFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class SurveyMixinTest {
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
private static final String FAKE_KEY = "fake_key";
-
- private Context mContext;
private SurveyFeatureProvider mProvider;
- @Mock
- private InstrumentedPreferenceFragment mFragment;
@Before
public void setUp() {
// set up the fakefeature factory to mock out the survey provider
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mProvider = FakeFeatureFactory.setupForTest().getSurveyFeatureProvider(mContext);
+ mProvider = FakeFeatureFactory.setupForTest().getSurveyFeatureProvider(
+ ApplicationProvider.getApplicationContext());
}
- @Ignore("b/314929422")
@Test
public void onResume_noActionIfActivityDoesNotExist() {
- // Pretend we are an activity that is starting up
- FragmentActivity temp = Robolectric.setupActivity(FragmentActivity.class);
- when(mFragment.getActivity()).thenReturn(null);
- SurveyMixin mixin = new SurveyMixin(mFragment, FAKE_KEY);
+ // Initialize a fragment without associating with an activity
+ Fragment fragment = new Fragment();
+ SurveyMixin mixin = new SurveyMixin(fragment, FAKE_KEY);
mixin.onResume();
verify(mProvider, times(0)).sendActivityIfAvailable(FAKE_KEY);
}
+
+ @Test
+ public void onResume_sendActivityWhenSurveyFeatureExists() {
+ try (var fragmentScenario = FragmentScenario.launch(Fragment.class)) {
+ fragmentScenario.onFragment(fragment -> {
+ SurveyMixin mixin = new SurveyMixin(fragment, FAKE_KEY);
+ mixin.onResume();
+ });
+ }
+ // Verify one send activity action is attempted
+ verify(mProvider).sendActivityIfAvailable(FAKE_KEY);
+ }
}
diff --git a/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsControllerTest.java b/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsControllerTest.java
new file mode 100644
index 0000000..1430dfd
--- /dev/null
+++ b/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceSensitiveNotificationsControllerTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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);
+
+ 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);
+ 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 4bb5d43..8510b11 100644
--- a/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java
+++ b/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.privatespace;
+import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK;
import static com.android.settings.privatespace.PrivateSpaceMaintainer.HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL;
@@ -140,6 +141,24 @@
}
/**
+ * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} sets the PS sensitive
+ * notifications to hidden by default.
+ */
+ @Test
+ public void createPrivateSpace_psDoesNotExist_setsDefaultPsSensitiveNotificationsValue() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_ENABLE_PS_SENSITIVE_NOTIFICATIONS_TOGGLE);
+ PrivateSpaceMaintainer privateSpaceMaintainer =
+ PrivateSpaceMaintainer.getInstance(mContext);
+ privateSpaceMaintainer.deletePrivateSpace();
+ privateSpaceMaintainer.createPrivateSpace();
+ assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isTrue();
+ assertThat(getPsSensitiveNotificationsValue(privateSpaceMaintainer))
+ .isEqualTo(HidePrivateSpaceSensitiveNotificationsController.DISABLED);
+ }
+
+ /**
* Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exist does not reset
* hide PS Settings.
*/
@@ -287,4 +306,11 @@
0,
privateSpaceMaintainer.getPrivateProfileHandle().getIdentifier());
}
+
+ private int getPsSensitiveNotificationsValue(PrivateSpaceMaintainer privateSpaceMaintainer) {
+ return Settings.Secure.getIntForUser(mContentResolver,
+ LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
+ HidePrivateSpaceSensitiveNotificationsController.ENABLED,
+ privateSpaceMaintainer.getPrivateProfileHandle().getIdentifier());
+ }
}