Merge "Hide Device Lock settings screen if device lock manager is not available" into udc-devicelock-prod am: 2db0f47240

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23684870

Change-Id: Ie16f3870f7e6d5f0939c762f7be2be2b9a8f1f22
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yanli Wan
2023-06-15 21:09:44 +00:00
committed by Automerger Merge Worker
2 changed files with 18 additions and 0 deletions

View File

@@ -47,6 +47,11 @@ public final class DeviceLockPreferenceController extends BasePreferenceControll
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mDeviceLockManager == null) {
Log.w(TAG, "DeviceLockManager is not available");
preference.setVisible(false);
return;
}
mDeviceLockManager.getKioskApps(mContext.getMainExecutor(),
result -> {
// if kiosk apps present on the device, the device is provisioned by Device Lock

View File

@@ -93,4 +93,17 @@ public final class DeviceLockPreferenceControllerTest {
outcomeReceiver.onResult(TEST_KIOSK_APPS);
assertThat(preference.isVisible()).isTrue();
}
@Test
public void testUpdateState_preferenceBecomesInvisibleIfDeviceLockManagerIsNotAvailable() {
Context context = spy(mContext);
when(context.getSystemService(DeviceLockManager.class)).thenReturn(null);
mController = new DeviceLockPreferenceController(context, TEST_PREFERENCE_KEY);
Preference preference = new Preference(mContext, null, 0, 0);
preference.setVisible(true);
mController.updateState(preference);
assertThat(preference.isVisible()).isFalse();
}
}