Reset Private Space settings on new space creation
Also added PrivateSpaceMaintainerTest Bug: 310217645 Test: atest PrivateSpaceMaintainerTest Test: atest HidePrivateSpaceControllerTest Test: manual Change-Id: Ic1096fd652d23ae6aa9da1421017c08f6bc480aa
This commit is contained in:
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings.privatespace;
|
package com.android.settings.privatespace;
|
||||||
|
|
||||||
import static android.provider.Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT;
|
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.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
@@ -28,11 +28,11 @@ import com.android.settings.core.TogglePreferenceController;
|
|||||||
* in All Apps.
|
* in All Apps.
|
||||||
*/
|
*/
|
||||||
public class HidePrivateSpaceController extends TogglePreferenceController {
|
public class HidePrivateSpaceController extends TogglePreferenceController {
|
||||||
private static final int DISABLED_VALUE = 0;
|
private final PrivateSpaceMaintainer mPrivateSpaceMaintainer;
|
||||||
private static final int ENABLED_VALUE = 1;
|
|
||||||
|
|
||||||
public HidePrivateSpaceController(Context context, String key) {
|
public HidePrivateSpaceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
|
mPrivateSpaceMaintainer = PrivateSpaceMaintainer.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,14 +43,15 @@ public class HidePrivateSpaceController extends TogglePreferenceController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
return mPrivateSpaceMaintainer.getHidePrivateSpaceEntryPointSetting()
|
||||||
HIDE_PRIVATESPACE_ENTRY_POINT, DISABLED_VALUE) != DISABLED_VALUE;
|
!= HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), HIDE_PRIVATESPACE_ENTRY_POINT,
|
mPrivateSpaceMaintainer.setHidePrivateSpaceEntryPointSetting(
|
||||||
isChecked ? ENABLED_VALUE : DISABLED_VALUE);
|
isChecked ? HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL
|
||||||
|
: HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.privatespace;
|
package com.android.settings.privatespace;
|
||||||
|
|
||||||
import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE;
|
import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE;
|
||||||
|
import static android.provider.Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.IActivityManager;
|
import android.app.IActivityManager;
|
||||||
@@ -27,6 +28,7 @@ import android.content.pm.UserInfo;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ import java.util.List;
|
|||||||
/** A class to help with the creation / deletion of Private Space */
|
/** A class to help with the creation / deletion of Private Space */
|
||||||
public class PrivateSpaceMaintainer {
|
public class PrivateSpaceMaintainer {
|
||||||
private static final String TAG = "PrivateSpaceMaintainer";
|
private static final String TAG = "PrivateSpaceMaintainer";
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private static PrivateSpaceMaintainer sPrivateSpaceMaintainer;
|
private static PrivateSpaceMaintainer sPrivateSpaceMaintainer;
|
||||||
|
|
||||||
@@ -49,6 +52,10 @@ public class PrivateSpaceMaintainer {
|
|||||||
private UserHandle mUserHandle;
|
private UserHandle mUserHandle;
|
||||||
private final KeyguardManager mKeyguardManager;
|
private final KeyguardManager mKeyguardManager;
|
||||||
|
|
||||||
|
/** This is the default value for the hide private space entry point settings. */
|
||||||
|
public static final int HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL = 0;
|
||||||
|
public static final int HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL = 1;
|
||||||
|
|
||||||
public enum ErrorDeletingPrivateSpace {
|
public enum ErrorDeletingPrivateSpace {
|
||||||
DELETE_PS_ERROR_NONE,
|
DELETE_PS_ERROR_NONE,
|
||||||
DELETE_PS_ERROR_NO_PRIVATE_SPACE,
|
DELETE_PS_ERROR_NO_PRIVATE_SPACE,
|
||||||
@@ -91,6 +98,7 @@ public class PrivateSpaceMaintainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log.i(TAG, "Private space created with id: " + mUserHandle.getIdentifier());
|
Log.i(TAG, "Private space created with id: " + mUserHandle.getIdentifier());
|
||||||
|
resetPrivateSpaceSettings();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -197,4 +205,21 @@ public class PrivateSpaceMaintainer {
|
|||||||
return doesPrivateSpaceExist()
|
return doesPrivateSpaceExist()
|
||||||
&& mKeyguardManager.isDeviceSecure(mUserHandle.getIdentifier());
|
&& mKeyguardManager.isDeviceSecure(mUserHandle.getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the setting to show PS entry point to the provided value. */
|
||||||
|
public void setHidePrivateSpaceEntryPointSetting(int value) {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), HIDE_PRIVATESPACE_ENTRY_POINT, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the setting to show PS entry point. */
|
||||||
|
public int getHidePrivateSpaceEntryPointSetting() {
|
||||||
|
return Settings.Secure.getInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
HIDE_PRIVATESPACE_ENTRY_POINT,
|
||||||
|
HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPrivateSpaceSettings() {
|
||||||
|
setHidePrivateSpaceEntryPointSetting(HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* 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.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.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.privatespace.PrivateSpaceMaintainer.ErrorDeletingPrivateSpace;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class PrivateSpaceMaintainerTest {
|
||||||
|
private Context mContext;
|
||||||
|
private ContentResolver mContentResolver;
|
||||||
|
|
||||||
|
/** Required setup before a test. */
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
mContentResolver = mContext.getContentResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tests that {@link PrivateSpaceMaintainer#deletePrivateSpace()} deletes PS when PS exists. */
|
||||||
|
@Test
|
||||||
|
public void deletePrivateSpace_psExists_deletesPS() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
privateSpaceMaintainer.createPrivateSpace();
|
||||||
|
ErrorDeletingPrivateSpace errorDeletingPrivateSpace =
|
||||||
|
privateSpaceMaintainer.deletePrivateSpace();
|
||||||
|
assertThat(errorDeletingPrivateSpace)
|
||||||
|
.isEqualTo(ErrorDeletingPrivateSpace.DELETE_PS_ERROR_NONE);
|
||||||
|
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that {@link PrivateSpaceMaintainer#deletePrivateSpace()} returns error when PS does
|
||||||
|
* not exist.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void deletePrivateSpace_psDoesNotExist_returnsNoPSError() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
ErrorDeletingPrivateSpace errorDeletingPrivateSpace =
|
||||||
|
privateSpaceMaintainer.deletePrivateSpace();
|
||||||
|
assertThat(errorDeletingPrivateSpace)
|
||||||
|
.isEqualTo(ErrorDeletingPrivateSpace.DELETE_PS_ERROR_NO_PRIVATE_SPACE);
|
||||||
|
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exists creates PS. */
|
||||||
|
@Test
|
||||||
|
public void createPrivateSpace_psDoesNotExist_createsPS() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
privateSpaceMaintainer.deletePrivateSpace();
|
||||||
|
assertThat(privateSpaceMaintainer.createPrivateSpace()).isTrue();
|
||||||
|
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exists still
|
||||||
|
* returns true.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void createPrivateSpace_psExists_returnsFalse() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
privateSpaceMaintainer.deletePrivateSpace();
|
||||||
|
assertThat(privateSpaceMaintainer.createPrivateSpace()).isTrue();
|
||||||
|
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isTrue();
|
||||||
|
assertThat(privateSpaceMaintainer.createPrivateSpace()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when no PS exists resets PS
|
||||||
|
* Settings.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void createPrivateSpace_psDoesNotExist_resetsPSSettings() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
Settings.Secure.putInt(
|
||||||
|
mContentResolver,
|
||||||
|
Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT,
|
||||||
|
HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL);
|
||||||
|
|
||||||
|
privateSpaceMaintainer.deletePrivateSpace();
|
||||||
|
privateSpaceMaintainer.createPrivateSpace();
|
||||||
|
assertThat(privateSpaceMaintainer.getHidePrivateSpaceEntryPointSetting())
|
||||||
|
.isEqualTo(HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exist does not reset
|
||||||
|
* PS Settings.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void createPrivateSpace_psExists_doesNotResetPSSettings() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
privateSpaceMaintainer.createPrivateSpace();
|
||||||
|
Settings.Secure.putInt(
|
||||||
|
mContentResolver,
|
||||||
|
Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT,
|
||||||
|
HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL);
|
||||||
|
|
||||||
|
privateSpaceMaintainer.createPrivateSpace();
|
||||||
|
assertThat(privateSpaceMaintainer.getHidePrivateSpaceEntryPointSetting())
|
||||||
|
.isEqualTo(HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user