diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index f84afec09fc..357818cd137 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1483,4 +1483,18 @@
- 2
+
+
+ - @string/private_space_auto_lock_every_time
+ - @string/private_space_auto_lock_after_inactivity
+ - @string/private_space_auto_lock_never
+
+
+
+
+ - 0
+ - 1
+ - 2
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 491cd0aee7a..6bf13433928 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1237,10 +1237,22 @@
Face Unlock for Private Space
Ways to unlock
-
+
Same as device screen lock
Choose a new lock for Private Space?
+
+ Lock automatically
+
+ Lock private space automatically
+
+ You can lock your private space automatically if you haven\’t used your device for a period of time
+
+ Every time device locks
+
+ After 5 minutes of inactivity
+
+ Never
Hide when locked
diff --git a/res/xml/private_space_auto_lock_settings.xml b/res/xml/private_space_auto_lock_settings.xml
new file mode 100644
index 00000000000..82f6c57b667
--- /dev/null
+++ b/res/xml/private_space_auto_lock_settings.xml
@@ -0,0 +1,20 @@
+
+
+
+
diff --git a/res/xml/private_space_settings.xml b/res/xml/private_space_settings.xml
index 4af02dd7cea..244c792c7e5 100644
--- a/res/xml/private_space_settings.xml
+++ b/res/xml/private_space_settings.xml
@@ -36,6 +36,13 @@
+
+
getCandidates() {
+ final List candidates = new ArrayList<>();
+ if (mAutoLockRadioValues != null) {
+ for (int i = 0; i < mAutoLockRadioValues.length; ++i) {
+ candidates.add(
+ new AutoLockCandidateInfo(
+ mAutoLockRadioOptions[i], mAutoLockRadioValues[i].toString()));
+ }
+ } else {
+ Log.e(TAG, "Autolock options do not exist.");
+ }
+ return candidates;
+ }
+
+ @Override
+ protected String getDefaultKey() {
+ return Integer.toString(mPrivateSpaceMaintainer.getPrivateSpaceAutoLockSetting());
+ }
+
+ @Override
+ protected boolean setDefaultKey(String key) {
+ try {
+ @Settings.Secure.PrivateSpaceAutoLockOption final int value = Integer.parseInt(key);
+ mPrivateSpaceMaintainer.setPrivateSpaceAutoLockSetting(value);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "could not persist screen timeout setting", e);
+ }
+ return true;
+ }
+
+ private static class AutoLockCandidateInfo extends CandidateInfo {
+ private final CharSequence mLabel;
+ private final String mKey;
+
+ AutoLockCandidateInfo(CharSequence label, String key) {
+ super(true);
+ mLabel = label;
+ mKey = key;
+ }
+
+ @NonNull
+ @Override
+ public CharSequence loadLabel() {
+ return mLabel;
+ }
+
+ @Nullable
+ @Override
+ public Drawable loadIcon() {
+ return null;
+ }
+
+ @NonNull
+ @Override
+ public String getKey() {
+ return mKey;
+ }
+ }
+}
diff --git a/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java b/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java
index 1605ae66694..4bb5d43b59d 100644
--- a/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java
+++ b/tests/unit/src/com/android/settings/privatespace/PrivateSpaceMaintainerTest.java
@@ -16,8 +16,11 @@
package com.android.settings.privatespace;
+import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK;
+
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.android.settings.privatespace.PrivateSpaceMaintainer.PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL;
import static com.google.common.truth.Truth.assertThat;
@@ -25,7 +28,9 @@ import android.app.ActivityManager;
import android.app.IActivityManager;
import android.content.ContentResolver;
import android.content.Context;
+import android.os.Flags;
import android.os.RemoteException;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
@@ -36,6 +41,7 @@ import com.android.settings.privatespace.PrivateSpaceMaintainer.ErrorDeletingPri
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -45,6 +51,7 @@ public class PrivateSpaceMaintainerTest {
private static final String TAG = "PSMaintainerTest";
private Context mContext;
private ContentResolver mContentResolver;
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
/** Required setup before a test. */
@Before
@@ -75,8 +82,8 @@ public class PrivateSpaceMaintainerTest {
}
/**
- * Tests that {@link PrivateSpaceMaintainer#deletePrivateSpace()} returns error when PS does
- * not exist.
+ * Tests that {@link PrivateSpaceMaintainer#deletePrivateSpace()} returns error when PS does not
+ * exist.
*/
@Test
public void deletePrivateSpace_psDoesNotExist_returnsNoPSError() {
@@ -100,8 +107,8 @@ public class PrivateSpaceMaintainerTest {
}
/**
- * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exists still
- * returns true.
+ * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exists still returns
+ * true.
*/
@Test
public void createPrivateSpace_psExists_returnsFalse() {
@@ -114,11 +121,11 @@ public class PrivateSpaceMaintainerTest {
}
/**
- * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when no PS exists resets PS
- * Settings.
+ * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when no PS exists resets hide
+ * PS Settings.
*/
@Test
- public void createPrivateSpace_psDoesNotExist_resetsPSSettings() {
+ public void createPrivateSpace_psDoesNotExist_resetsHidePSSettings() {
PrivateSpaceMaintainer privateSpaceMaintainer =
PrivateSpaceMaintainer.getInstance(mContext);
Settings.Secure.putInt(
@@ -134,10 +141,10 @@ public class PrivateSpaceMaintainerTest {
/**
* Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exist does not reset
- * PS Settings.
+ * hide PS Settings.
*/
@Test
- public void createPrivateSpace_psExists_doesNotResetPSSettings() {
+ public void createPrivateSpace_psExists_doesNotResetHidePSSettings() {
PrivateSpaceMaintainer privateSpaceMaintainer =
PrivateSpaceMaintainer.getInstance(mContext);
privateSpaceMaintainer.createPrivateSpace();
@@ -212,8 +219,8 @@ public class PrivateSpaceMaintainerTest {
}
/**
- * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exists does not
- * change USER_SETUP_COMPLETE setting.
+ * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exists does not change
+ * USER_SETUP_COMPLETE setting.
*/
@Test
public void createPrivateSpace_pSExists_doesNotChangeUserSetupSetting() {
@@ -225,6 +232,52 @@ public class PrivateSpaceMaintainerTest {
assertThat(getSecureUserSetupComplete()).isEqualTo(1);
}
+ /**
+ * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when no PS exists resets PS
+ * auto lock Settings.
+ */
+ @Test
+ public void createPrivateSpace_psDoesNotExist_resetsPSAutoLockSettings() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+ final int autoLockOption = 2;
+ PrivateSpaceMaintainer privateSpaceMaintainer =
+ PrivateSpaceMaintainer.getInstance(mContext);
+ Settings.Secure.putInt(
+ mContentResolver, Settings.Secure.PRIVATE_SPACE_AUTO_LOCK, autoLockOption);
+
+ privateSpaceMaintainer.deletePrivateSpace();
+ privateSpaceMaintainer.createPrivateSpace();
+ assertThat(privateSpaceMaintainer.getPrivateSpaceAutoLockSetting())
+ .isEqualTo(PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL);
+ assertThat(Settings.Secure.getInt(mContentResolver, PRIVATE_SPACE_AUTO_LOCK, -1))
+ .isEqualTo(PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL);
+ }
+
+ /**
+ * Tests that {@link PrivateSpaceMaintainer#createPrivateSpace()} when PS exist does not reset
+ * PS auto lock setting.
+ */
+ @Test
+ public void createPrivateSpace_psExists_doesNotResetPSAutoLockSettings() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+ final int privateSpaceAutLockValue = 1;
+ PrivateSpaceMaintainer privateSpaceMaintainer =
+ PrivateSpaceMaintainer.getInstance(mContext);
+ privateSpaceMaintainer.createPrivateSpace();
+ Settings.Secure.putInt(
+ mContentResolver,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK,
+ privateSpaceAutLockValue);
+
+ privateSpaceMaintainer.createPrivateSpace();
+ assertThat(privateSpaceMaintainer.getPrivateSpaceAutoLockSetting())
+ .isEqualTo(privateSpaceAutLockValue);
+ }
+
private int getSecureUserSetupComplete() {
PrivateSpaceMaintainer privateSpaceMaintainer =
PrivateSpaceMaintainer.getInstance(mContext);
diff --git a/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockPreferenceControllerTest.java b/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockPreferenceControllerTest.java
new file mode 100644
index 00000000000..01381d8320b
--- /dev/null
+++ b/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockPreferenceControllerTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.autolock;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+import static com.android.settings.privatespace.PrivateSpaceMaintainer.PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL;
+
+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.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;
+
+@RunWith(AndroidJUnit4.class)
+public class AutoLockPreferenceControllerTest {
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ private static final String KEY = "private_space_auto_lock";
+ private Context mContext;
+ private AutoLockPreferenceController mAutoLockPreferenceController;
+ private ContentResolver mContentResolver;
+ @Settings.Secure.PrivateSpaceAutoLockOption private int mOriginalAutoLockValue;
+
+ /** Required setup before a test. */
+ @Before
+ public void setUp() {
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mContentResolver = mContext.getContentResolver();
+ mAutoLockPreferenceController = new AutoLockPreferenceController(mContext, KEY);
+ mOriginalAutoLockValue =
+ Settings.Secure.getInt(
+ mContentResolver,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK,
+ PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL);
+ }
+
+ @After
+ public void tearDown() {
+ Settings.Secure.putInt(
+ mContentResolver, Settings.Secure.PRIVATE_SPACE_AUTO_LOCK, mOriginalAutoLockValue);
+ }
+
+ /**
+ * Tests that the controller is available when both allow private profile and auto lock support
+ * flags are enabled.
+ */
+ @Test
+ public void getAvailabilityStatus_withAutoLockFlagEnabled_returnsAvailable() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+
+ assertThat(mAutoLockPreferenceController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ /** Tests that the controller is not available when auto lock flag is off. */
+ @Test
+ public void getAvailabilityStatus_withAutoLockFlagDisabled_returnsNull() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
+ mSetFlagsRule.disableFlags(android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+
+ assertThat(mAutoLockPreferenceController.getAvailabilityStatus())
+ .isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ /**
+ * Tests that auto lock preference displays the correct summary for option - every time device
+ * locks.
+ */
+ @Test
+ public void getSummary_whenOptionEveryTimeDeviceLocks_returnsEveryTimeDeviceLocks() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+
+ Settings.Secure.putInt(
+ mContentResolver,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_ON_DEVICE_LOCK);
+ assertThat(mAutoLockPreferenceController.getSummary().toString())
+ .isEqualTo("Every time device locks");
+ }
+
+ /**
+ * Tests that auto lock preference displays the correct summary for option - lock after 5
+ * minutes of inactivity.
+ */
+ @Test
+ public void getSummary_whenOptionAfter5MinutesOfInactivity_returnsAfter5MinutesOfInactivity() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+
+ Settings.Secure.putInt(
+ mContentResolver,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_AFTER_INACTIVITY);
+ assertThat(mAutoLockPreferenceController.getSummary().toString())
+ .isEqualTo("After 5 minutes of inactivity");
+ }
+
+ /** Tests that auto lock preference displays the correct summary for option - Never. */
+ @Test
+ public void getSummary_whenOptionNever_returnsNever() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+
+ Settings.Secure.putInt(
+ mContentResolver,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_NEVER);
+ assertThat(mAutoLockPreferenceController.getSummary().toString()).isEqualTo("Never");
+ }
+}
diff --git a/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockSettingsFragmentTest.java b/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockSettingsFragmentTest.java
new file mode 100644
index 00000000000..971ca40c8e1
--- /dev/null
+++ b/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockSettingsFragmentTest.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.autolock;
+
+import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK;
+import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_AFTER_INACTIVITY;
+import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_NEVER;
+import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_ON_DEVICE_LOCK;
+
+import static com.android.settings.privatespace.PrivateSpaceMaintainer.PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.settings.SettingsEnums;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.Flags;
+import android.platform.test.flag.junit.SetFlagsRule;
+import android.provider.Settings;
+
+import androidx.test.annotation.UiThreadTest;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settingslib.widget.CandidateInfo;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public class AutoLockSettingsFragmentTest {
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+ private AutoLockSettingsFragment mFragment;
+ private Context mContext;
+ private Resources mResources;
+ private ContentResolver mContentResolver;
+ @Settings.Secure.PrivateSpaceAutoLockOption private int mOriginalAutoLockValue;
+
+ @Before
+ @UiThreadTest
+ public void setup() {
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mFragment = spy(new AutoLockSettingsFragment());
+ mContentResolver = mContext.getContentResolver();
+ mResources = spy(mContext.getResources());
+ mOriginalAutoLockValue =
+ Settings.Secure.getInt(
+ mContentResolver,
+ Settings.Secure.PRIVATE_SPACE_AUTO_LOCK,
+ PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL);
+ when(mResources.getStringArray(
+ com.android.settings.R.array.private_space_auto_lock_options))
+ .thenReturn(
+ new String[] {
+ "Every time device locks", "After 5 minutes of inactivity", "Never"
+ });
+ when(mResources.getStringArray(
+ com.android.settings.R.array.private_space_auto_lock_options_values))
+ .thenReturn(new String[] {"0", "1", "2"});
+ doReturn(mResources).when(mContext).getResources();
+ }
+
+ @After
+ public void tearDown() {
+ Settings.Secure.putInt(
+ mContentResolver, Settings.Secure.PRIVATE_SPACE_AUTO_LOCK, mOriginalAutoLockValue);
+ }
+
+ @Test
+ public void verifyMetricsConstant() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+ assertThat(mFragment.getMetricsCategory()).isEqualTo(SettingsEnums.PRIVATE_SPACE_SETTINGS);
+ }
+
+ @Test
+ @UiThreadTest
+ public void getCandidates_returnsCandidateInfoListWithAllKeys() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+ mFragment.onAttach(mContext);
+
+ final List extends CandidateInfo> candidates = mFragment.getCandidates();
+
+ assertThat(candidates.size()).isEqualTo(3);
+
+ assertThat(candidates.get(0).getKey()).isEqualTo("0");
+ assertThat(candidates.get(1).getKey()).isEqualTo("1");
+ assertThat(candidates.get(2).getKey()).isEqualTo("2");
+ }
+
+ @Test
+ @UiThreadTest
+ public void getDefaultKey_returnsStoredAutoLockOptionsValue() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+
+ mFragment.onAttach(mContext);
+
+ Settings.Secure.putInt(
+ mContentResolver, PRIVATE_SPACE_AUTO_LOCK, PRIVATE_SPACE_AUTO_LOCK_NEVER);
+ assertThat(mFragment.getDefaultKey()).isEqualTo("2");
+
+ Settings.Secure.putInt(
+ mContentResolver, PRIVATE_SPACE_AUTO_LOCK, PRIVATE_SPACE_AUTO_LOCK_ON_DEVICE_LOCK);
+ assertThat(mFragment.getDefaultKey()).isEqualTo("0");
+
+ Settings.Secure.putInt(
+ mContentResolver,
+ PRIVATE_SPACE_AUTO_LOCK,
+ PRIVATE_SPACE_AUTO_LOCK_AFTER_INACTIVITY);
+ assertThat(mFragment.getDefaultKey()).isEqualTo("1");
+ }
+
+ @Test
+ @UiThreadTest
+ public void setDefaultKey_storesCorrectAutoLockOptionValue() {
+ mSetFlagsRule.enableFlags(
+ Flags.FLAG_ALLOW_PRIVATE_PROFILE,
+ android.multiuser.Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);
+
+ mFragment.onAttach(mContext);
+ mFragment.setDefaultKey("2");
+ assertThat(Settings.Secure.getInt(mContentResolver, PRIVATE_SPACE_AUTO_LOCK, -1))
+ .isEqualTo(PRIVATE_SPACE_AUTO_LOCK_NEVER);
+
+ mFragment.setDefaultKey("1");
+ assertThat(Settings.Secure.getInt(mContentResolver, PRIVATE_SPACE_AUTO_LOCK, -1))
+ .isEqualTo(PRIVATE_SPACE_AUTO_LOCK_AFTER_INACTIVITY);
+
+ mFragment.setDefaultKey("0");
+ assertThat(Settings.Secure.getInt(mContentResolver, PRIVATE_SPACE_AUTO_LOCK, -1))
+ .isEqualTo(PRIVATE_SPACE_AUTO_LOCK_ON_DEVICE_LOCK);
+ }
+}