Add toggle to hide private space entry point in All Apps

This change includes implementaion for below:
1. Add a preference inside private space settings page with a toggle switch to control hide/unhide
   private space entry in All Apps
2. Store the preference value in settingsprovider for persistence.

Bug: 302682054
Test: Manual
Change-Id: Ia1a56fc2c43550e23c00a61a5ce4742e42effcbe
This commit is contained in:
josephpv
2023-10-11 16:15:23 +00:00
committed by Joseph Vincent
parent 27dd22302f
commit eace275921
12 changed files with 392 additions and 15 deletions

View File

@@ -17,30 +17,59 @@
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;
import org.mockito.Mock;
@RunWith(AndroidJUnit4.class)
@RequiresFlagsEnabled(Flags.FLAG_ALLOW_PRIVATE_PROFILE)
public class HidePrivateSpaceControllerTest {
@Mock private Context mContext;
@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 = ApplicationProvider.getApplicationContext();
final String preferenceKey = "private_space_hidden";
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);
}
mHidePrivateSpaceController = new HidePrivateSpaceController(mContext, preferenceKey);
@After
public void tearDown() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT,
mOriginalHiddenValue);
}
/** Tests that the controller is always available. */
@@ -48,4 +77,33 @@ public class HidePrivateSpaceControllerTest {
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();
}
}

View File

@@ -0,0 +1,99 @@
/*
* 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)
public class HidePrivateSpaceSummaryControllerTest {
@Rule
public final CheckFlagsRule mCheckFlagsRule =
DeviceFlagsValueProvider.createCheckFlagsRule();
private Context mContext;
private HidePrivateSpaceSummaryController mHidePrivateSpaceSummaryController;
private ContentResolver mContentResolver;
private int mOriginalHiddenValue;
/** Required setup before a test. */
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mContentResolver = mContext.getContentResolver();
final String preferenceKey = "private_space_hidden";
mHidePrivateSpaceSummaryController =
new HidePrivateSpaceSummaryController(mContext, preferenceKey);
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(mHidePrivateSpaceSummaryController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
/** Tests that the preference summary displays On when hide is enabled.*/
@Test
public void setEnabled_shouldDisplayOn() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, 1);
assertThat(Settings.Secure.getInt(mContentResolver,
Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, -1)).isEqualTo(1);
assertThat(mHidePrivateSpaceSummaryController.getSummary().toString())
.isEqualTo("On");
}
/** Tests that the preference summary displays Off when hide is disabled.*/
@Test
public void setDisabled_shouldDisplayOff() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, 0);
assertThat(Settings.Secure.getInt(mContentResolver,
Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT, -1)).isEqualTo(0);
assertThat(mHidePrivateSpaceSummaryController.getSummary().toString())
.isEqualTo("Off");
}
}