Merge "Show Alert dialog on Hide when locked is enabled" into main
diff --git a/res/values/strings.xml b/res/values/strings.xml
index dd51f52..d5fd621 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1263,6 +1263,12 @@
<string name="privatespace_hide_off_summary">Off</string>
<!-- Used to describe the off state of Private space hidden [CHAR LIMIT=30] -->
<string name="privatespace_hide_on_summary">On</string>
+ <!-- Title for the dialog shown when Private space hidden setting is turned on. [CHAR LIMIT=60] -->
+ <string name="private_space_hide_dialog_title">Private space will hide when you lock it next</string>
+ <!-- Text message in the dialog shown when Private space hidden setting is turned on. [CHAR LIMIT=90] -->
+ <string name="private_space_hide_dialog_message">To access your space when it’s hidden, enter \“private space\” in the search bar on your apps list</string>
+ <!-- Label for the dialog shown when Private space hidden setting is turned on. [CHAR LIMIT=90] -->
+ <string name="private_space_hide_dialog_button">Got it</string>
<!-- System category for the Private Space page. [CHAR LIMIT=30] -->
<string name="private_space_category_system">System</string>
<!-- Title for the preference to delete Private Space. [CHAR LIMIT=40] -->
diff --git a/src/com/android/settings/privatespace/HidePrivateSpaceController.java b/src/com/android/settings/privatespace/HidePrivateSpaceController.java
index 903defa..81814ad 100644
--- a/src/com/android/settings/privatespace/HidePrivateSpaceController.java
+++ b/src/com/android/settings/privatespace/HidePrivateSpaceController.java
@@ -19,13 +19,21 @@
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 android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
+import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
/**
- * A class that is used to show details page for the setting to hide private space entry point
- * in All Apps.
+ * Toggle Preference Controller responsible for managing the visibility of private space entry point
+ * in the "All Apps" section. This includes:
+ *
+ * <p>Toggling the entry point's visibility (hiding/unhiding)
+ *
+ * <p>Displaying a dialog to inform the user that the entry point will be hidden when private space
+ * is locked (if the hide option is enabled)
*/
public class HidePrivateSpaceController extends TogglePreferenceController {
private final PrivateSpaceMaintainer mPrivateSpaceMaintainer;
@@ -39,7 +47,7 @@
@AvailabilityStatus
public int getAvailabilityStatus() {
return android.os.Flags.allowPrivateProfile()
- && android.multiuser.Flags.enablePrivateSpaceFeatures()
+ && android.multiuser.Flags.enablePrivateSpaceFeatures()
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@@ -55,6 +63,9 @@
mPrivateSpaceMaintainer.setHidePrivateSpaceEntryPointSetting(
isChecked ? HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL
: HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
+ if (isChecked) {
+ showAlertDialog();
+ }
return true;
}
@@ -62,4 +73,16 @@
public int getSliceHighlightMenuRes() {
return 0;
}
+
+ private void showAlertDialog() {
+ new AlertDialog.Builder(mContext)
+ .setTitle(R.string.private_space_hide_dialog_title)
+ .setMessage(R.string.private_space_hide_dialog_message)
+ .setPositiveButton(
+ R.string.private_space_hide_dialog_button,
+ (DialogInterface dialog, int which) -> {
+ dialog.dismiss();
+ })
+ .show();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/privatespace/HidePrivateSpaceControllerTest.java b/tests/robotests/src/com/android/settings/privatespace/HidePrivateSpaceControllerTest.java
new file mode 100644
index 0000000..7ff18a5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/privatespace/HidePrivateSpaceControllerTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import androidx.fragment.app.FragmentActivity;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadow.api.Shadow;
+import org.robolectric.shadows.ShadowAlertDialog;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowAlertDialog.class})
+public class HidePrivateSpaceControllerTest {
+ @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ private static final String KEY = "private_space_hidden";
+ private static final String DETAIL_PAGE_KEY = "private_space_hidden_details";
+ private HidePrivateSpaceController mHidePrivateSpaceController;
+ private HidePrivateSpaceSummaryController mHidePrivateSpaceSummaryController;
+ private FragmentActivity mActivity;
+
+ @Before
+ public void setUp() {
+ Context context = RuntimeEnvironment.application;
+ mHidePrivateSpaceController = new HidePrivateSpaceController(context, DETAIL_PAGE_KEY);
+ mHidePrivateSpaceSummaryController = new HidePrivateSpaceSummaryController(context, KEY);
+ mActivity = Robolectric.setupActivity(FragmentActivity.class);
+ }
+
+ /** Tests that when flags enabled the controller is available. */
+ @Test
+ public void getAvailabilityStatus_flagEnabled_returnsAvailable() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+
+ assertThat(mHidePrivateSpaceController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ /** Tests that when flags disabled the controller is unsupported. */
+ @Test
+ public void getAvailabilityStatus_flagDisabled_returnsUnsupported() {
+ mSetFlagsRule.disableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+
+ assertThat(mHidePrivateSpaceController.getAvailabilityStatus())
+ .isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ /** Tests that when hide toggle is enabled dialog is displayed. */
+ @Test
+ public void setChecked_enabled_showsDialog() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+ mHidePrivateSpaceController.setChecked(true);
+
+ ShadowAlertDialog shadowAlertDialog = getShadowAlertDialog();
+ assertThat(shadowAlertDialog).isNotNull();
+ assertThat(shadowAlertDialog.getTitle().toString())
+ .isEqualTo(mActivity.getString(R.string.private_space_hide_dialog_title));
+ assertThat(shadowAlertDialog.getMessage().toString())
+ .isEqualTo(mActivity.getString(R.string.private_space_hide_dialog_message));
+ }
+
+ /** Tests that when hide toggle is disabled dialog is not displayed. */
+ @Test
+ public void setChecked_disabled_NoDialogShown() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+ mHidePrivateSpaceController.setChecked(false);
+
+ ShadowAlertDialog shadowAlertDialog = getShadowAlertDialog();
+ assertThat(shadowAlertDialog).isNull();
+ }
+
+ /** Tests that when hide toggle is enabled then isChecked returns true. */
+ @Test
+ public void setChecked_enabled_isCheckedIsTrue() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+ mHidePrivateSpaceController.setChecked(true);
+ assertThat(mHidePrivateSpaceController.isChecked()).isTrue();
+ }
+
+ /** Tests that when hide toggle is disabled then isChecked returns false. */
+ @Test
+ public void setChecked_disabled_isCheckedIsFalse() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+ mHidePrivateSpaceController.setChecked(false);
+ assertThat(mHidePrivateSpaceController.isChecked()).isFalse();
+ }
+
+ /** Tests that hide preference summary displays On when toggle is enabled. */
+ @Test
+ public void setChecked_enable_summaryShouldDisplayOn() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+ mHidePrivateSpaceController.setChecked(true);
+
+ assertThat(mHidePrivateSpaceSummaryController.getSummary().toString()).isEqualTo("On");
+ }
+
+ /** Tests that hide preference summary displays Off when toggle is disabled. */
+ @Test
+ public void setChecked_disable_summaryShouldDisplayOff() {
+ mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
+ mHidePrivateSpaceController.setChecked(false);
+
+ assertThat(mHidePrivateSpaceSummaryController.getSummary().toString()).isEqualTo("Off");
+ }
+
+ private ShadowAlertDialog getShadowAlertDialog() {
+ ShadowApplication shadowApplication =
+ Shadow.extract(ApplicationProvider.getApplicationContext());
+ ShadowAlertDialog shadowAlertDialog = shadowApplication.getLatestAlertDialog();
+ return shadowAlertDialog;
+ }
+}
diff --git a/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceControllerTest.java b/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceControllerTest.java
deleted file mode 100644
index b71547b..0000000
--- a/tests/unit/src/com/android/settings/privatespace/HidePrivateSpaceControllerTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2023 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.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.spy;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.os.Flags;
-import android.platform.test.annotations.RequiresFlagsEnabled;
-import android.platform.test.flag.junit.CheckFlagsRule;
-import android.platform.test.flag.junit.DeviceFlagsValueProvider;
-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;
-
-@RunWith(AndroidJUnit4.class)
-@RequiresFlagsEnabled({Flags.FLAG_ALLOW_PRIVATE_PROFILE,
- android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES})
-public class HidePrivateSpaceControllerTest {
- @Rule
- public final CheckFlagsRule mCheckFlagsRule =
- DeviceFlagsValueProvider.createCheckFlagsRule();
-
- private static final String KEY = "private_space_hidden";
- private static final String DETAIL_PAGE_KEY = "private_space_hidden_details";
- private Context mContext;
- private HidePrivateSpaceSummaryController mHidePrivateSpaceSummaryController;
- private HidePrivateSpaceController mHidePrivateSpaceController;
- private ContentResolver mContentResolver;
- private int mOriginalHiddenValue;
-
- /** Required setup before a test. */
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
- mContentResolver = mContext.getContentResolver();
- mHidePrivateSpaceSummaryController = new HidePrivateSpaceSummaryController(mContext, KEY);
- mHidePrivateSpaceController =
- new HidePrivateSpaceController(mContext, DETAIL_PAGE_KEY);
- mOriginalHiddenValue = Settings.Secure.getInt(mContentResolver,
- Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, 0);
- }
-
- @After
- public void tearDown() {
- Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT,
- mOriginalHiddenValue);
- }
-
- /** Tests that the controller is always available. */
- @Test
- public void getAvailabilityStatus_returnsAvailable() {
- assertThat(mHidePrivateSpaceController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
- }
-
- /** Tests that hide preference summary displays On when hide toggle is enabled.*/
- @Test
- public void setChecked_enable_shouldDisplayOn() {
- Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT,
- 0);
- assertThat(mHidePrivateSpaceController.isChecked()).isFalse();
-
- mHidePrivateSpaceController.setChecked(true);
-
- assertThat(mHidePrivateSpaceSummaryController.getSummary().toString())
- .isEqualTo("On");
- assertThat(mHidePrivateSpaceController.isChecked()).isTrue();
- }
-
- /** Tests that hide preference summary displays Off when toggle is disabled.*/
- @Test
- public void setChecked_disable_shouldDisplayOff() {
- Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT,
- 1);
-
- assertThat(mHidePrivateSpaceController.isChecked()).isTrue();
-
- mHidePrivateSpaceController.setChecked(false);
-
- assertThat(mHidePrivateSpaceSummaryController.getSummary().toString())
- .isEqualTo("Off");
- assertThat(mHidePrivateSpaceController.isChecked()).isFalse();
- }
-}