Merge "Hide Device Lock settings screen if device lock manager is not available" into udc-devicelock-prod
This commit is contained in:
@@ -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
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user