diff --git a/res/values/strings.xml b/res/values/strings.xml
index 405960bcca8..0ab8828b0f5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10158,7 +10158,9 @@
All restrictions are removed from the device
You can uninstall the creditor app
-
+
+
+ Device Lock
{count, plural,
diff --git a/res/xml/more_security_privacy_settings.xml b/res/xml/more_security_privacy_settings.xml
index 5fce68fd5e2..1a9d788ea76 100644
--- a/res/xml/more_security_privacy_settings.xml
+++ b/res/xml/more_security_privacy_settings.xml
@@ -146,6 +146,13 @@
android:fragment="com.android.settings.enterprise.EnterprisePrivacySettings"
settings:controller="com.android.settings.enterprise.FinancedPrivacyPreferenceController"/>
+
+
+
+
+
+
{
+ // if kiosk apps present on the device, the device is provisioned by Device Lock
+ boolean isDeviceProvisionedByDeviceLock = result != null && !result.isEmpty();
+ Log.d(TAG, "Set preference visibility to " + isDeviceProvisionedByDeviceLock);
+ // TODO(b/282179089): find alternatives instead of calling setVisible
+ preference.setVisible(isDeviceProvisionedByDeviceLock);
+ });
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/devicelock/DeviceLockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/devicelock/DeviceLockPreferenceControllerTest.java
new file mode 100644
index 00000000000..317696902bc
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/devicelock/DeviceLockPreferenceControllerTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.devicelock;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.devicelock.DeviceLockManager;
+import android.os.OutcomeReceiver;
+
+import androidx.preference.Preference;
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+import java.util.Collections;
+import java.util.Map;
+
+@RunWith(RobolectricTestRunner.class)
+public final class DeviceLockPreferenceControllerTest {
+
+ private static final String TEST_PREFERENCE_KEY = "KEY";
+ private static final Map TEST_KIOSK_APPS = Map.of(0, "test");
+ @Mock
+ private DeviceLockManager mDeviceLockManager;
+ @Captor
+ private ArgumentCaptor, Exception>>
+ mOutcomeReceiverArgumentCaptor;
+ private DeviceLockPreferenceController mController;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = ApplicationProvider.getApplicationContext();
+ Context context = spy(mContext);
+ when(context.getSystemService(DeviceLockManager.class)).thenReturn(mDeviceLockManager);
+ mController = new DeviceLockPreferenceController(context, TEST_PREFERENCE_KEY);
+ }
+
+ @Test
+ public void testUpdateState_preferenceBecomesInvisibleIfNoKioskAppsPresent() {
+ Preference preference = new Preference(mContext, null, 0, 0);
+ preference.setVisible(true);
+
+ mController.updateState(preference);
+
+ verify(mDeviceLockManager).getKioskApps(any(), mOutcomeReceiverArgumentCaptor.capture());
+ OutcomeReceiver