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

This commit is contained in:
Yanli Wan
2023-06-15 20:34:59 +00:00
committed by Android (Google) Code Review
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();
}
}