Lock Private space at the end of PS setup.
This change is to call UserManager requestQuietModeEnabled() API at the end of PS setup to enable quitemode for private space. Bug: 313652502 Test: atest PrivateSpaceMaintainerTest Verify Private space is locked state after private space setup completion. Change-Id: I1d863f6d51ffa4bb58318696603905d35c3109b6
This commit is contained in:
@@ -34,6 +34,7 @@ import android.util.ArraySet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
|
|
||||||
@@ -226,6 +227,26 @@ public class PrivateSpaceMaintainer {
|
|||||||
HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if private space exists and quiet mode is successfully enabled, otherwise
|
||||||
|
* returns false
|
||||||
|
*/
|
||||||
|
public synchronized boolean lockPrivateSpace() {
|
||||||
|
if (isPrivateProfileRunning()) {
|
||||||
|
return mUserManager.requestQuietModeEnabled(true, mUserHandle);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if private space exists and is running, otherwise returns false */
|
||||||
|
@VisibleForTesting
|
||||||
|
synchronized boolean isPrivateProfileRunning() {
|
||||||
|
if (doesPrivateSpaceExist() && mUserHandle != null) {
|
||||||
|
return mUserManager.isUserRunning(mUserHandle);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void resetPrivateSpaceSettings() {
|
private void resetPrivateSpaceSettings() {
|
||||||
setHidePrivateSpaceEntryPointSetting(HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
setHidePrivateSpaceEntryPointSetting(HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);
|
||||||
}
|
}
|
||||||
|
@@ -84,6 +84,8 @@ public class SetupSuccessFragment extends InstrumentedFragment {
|
|||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_DONE);
|
getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_DONE);
|
||||||
|
//TODO(b/307729746): Add a test to verify PS is locked after setup completion.
|
||||||
|
PrivateSpaceMaintainer.getInstance(activity).lockPrivateSpace();
|
||||||
Intent allAppsIntent = new Intent(Intent.ACTION_ALL_APPS);
|
Intent allAppsIntent = new Intent(Intent.ACTION_ALL_APPS);
|
||||||
ResolveInfo resolveInfo =
|
ResolveInfo resolveInfo =
|
||||||
activity.getPackageManager()
|
activity.getPackageManager()
|
||||||
|
@@ -21,8 +21,11 @@ import static com.android.settings.privatespace.PrivateSpaceMaintainer.HIDE_PRIV
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.app.IActivityManager;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -30,6 +33,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|||||||
|
|
||||||
import com.android.settings.privatespace.PrivateSpaceMaintainer.ErrorDeletingPrivateSpace;
|
import com.android.settings.privatespace.PrivateSpaceMaintainer.ErrorDeletingPrivateSpace;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -37,6 +42,7 @@ import org.mockito.MockitoAnnotations;
|
|||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class PrivateSpaceMaintainerTest {
|
public class PrivateSpaceMaintainerTest {
|
||||||
|
private static final String TAG = "PSMaintainerTest";
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
|
|
||||||
@@ -48,6 +54,13 @@ public class PrivateSpaceMaintainerTest {
|
|||||||
mContentResolver = mContext.getContentResolver();
|
mContentResolver = mContext.getContentResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
privateSpaceMaintainer.deletePrivateSpace();
|
||||||
|
}
|
||||||
|
|
||||||
/** Tests that {@link PrivateSpaceMaintainer#deletePrivateSpace()} deletes PS when PS exists. */
|
/** Tests that {@link PrivateSpaceMaintainer#deletePrivateSpace()} deletes PS when PS exists. */
|
||||||
@Test
|
@Test
|
||||||
public void deletePrivateSpace_psExists_deletesPS() {
|
public void deletePrivateSpace_psExists_deletesPS() {
|
||||||
@@ -137,4 +150,52 @@ public class PrivateSpaceMaintainerTest {
|
|||||||
assertThat(privateSpaceMaintainer.getHidePrivateSpaceEntryPointSetting())
|
assertThat(privateSpaceMaintainer.getHidePrivateSpaceEntryPointSetting())
|
||||||
.isEqualTo(HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL);
|
.isEqualTo(HIDE_PRIVATE_SPACE_ENTRY_POINT_ENABLED_VAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exists and is running
|
||||||
|
* locks the private profile.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void lockPrivateSpace_psExistsAndPrivateProfileRunning_locksCreatedPrivateSpace() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
privateSpaceMaintainer.createPrivateSpace();
|
||||||
|
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isTrue();
|
||||||
|
assertThat(privateSpaceMaintainer.isPrivateProfileRunning()).isTrue();
|
||||||
|
assertThat(privateSpaceMaintainer.isPrivateSpaceLocked()).isFalse();
|
||||||
|
assertThat(privateSpaceMaintainer.lockPrivateSpace()).isTrue();
|
||||||
|
assertThat(privateSpaceMaintainer.isPrivateSpaceLocked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exist and private
|
||||||
|
* profile not running returns false.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void lockPrivateSpace_psExistsAndPrivateProfileNotRunning_returnsFalse() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
privateSpaceMaintainer.createPrivateSpace();
|
||||||
|
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isTrue();
|
||||||
|
assertThat(privateSpaceMaintainer.isPrivateProfileRunning()).isTrue();
|
||||||
|
IActivityManager am = ActivityManager.getService();
|
||||||
|
try {
|
||||||
|
am.stopProfile(privateSpaceMaintainer.getPrivateProfileHandle().getIdentifier());
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Assert.fail("Stop profile failed with exception " + e.getMessage());
|
||||||
|
}
|
||||||
|
assertThat(privateSpaceMaintainer.isPrivateProfileRunning()).isFalse();
|
||||||
|
assertThat(privateSpaceMaintainer.lockPrivateSpace()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when no PS exists returns false.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void lockPrivateSpace_psDoesNotExist_returnsFalse() {
|
||||||
|
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||||
|
PrivateSpaceMaintainer.getInstance(mContext);
|
||||||
|
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isFalse();
|
||||||
|
assertThat(privateSpaceMaintainer.lockPrivateSpace()).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user