Merge "Remove LockdownButtonPreferenceController from java"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2bc391bb09
@@ -19,8 +19,6 @@ package com.android.settings.security;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.TwoStatePreference;
|
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -28,12 +26,10 @@ import com.android.settings.core.TogglePreferenceController;
|
|||||||
|
|
||||||
public class LockdownButtonPreferenceController extends TogglePreferenceController {
|
public class LockdownButtonPreferenceController extends TogglePreferenceController {
|
||||||
|
|
||||||
private static final String KEY_LOCKDOWN_ENALBED = "security_setting_lockdown_enabled";
|
|
||||||
|
|
||||||
private final LockPatternUtils mLockPatternUtils;
|
private final LockPatternUtils mLockPatternUtils;
|
||||||
|
|
||||||
public LockdownButtonPreferenceController(Context context) {
|
public LockdownButtonPreferenceController(Context context, String key) {
|
||||||
super(context, KEY_LOCKDOWN_ENALBED);
|
super(context, key);
|
||||||
mLockPatternUtils = new LockPatternUtils(context);
|
mLockPatternUtils = new LockPatternUtils(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,7 +93,6 @@ public class LockscreenDashboardFragment extends DashboardFragment
|
|||||||
mOwnerInfoPreferenceController =
|
mOwnerInfoPreferenceController =
|
||||||
new OwnerInfoPreferenceController(context, this, lifecycle);
|
new OwnerInfoPreferenceController(context, this, lifecycle);
|
||||||
controllers.add(mOwnerInfoPreferenceController);
|
controllers.add(mOwnerInfoPreferenceController);
|
||||||
controllers.add(new LockdownButtonPreferenceController(context));
|
|
||||||
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
@@ -124,7 +123,6 @@ public class LockscreenDashboardFragment extends DashboardFragment
|
|||||||
KEY_ADD_USER_FROM_LOCK_SCREEN, null /* lifecycle */));
|
KEY_ADD_USER_FROM_LOCK_SCREEN, null /* lifecycle */));
|
||||||
controllers.add(new OwnerInfoPreferenceController(
|
controllers.add(new OwnerInfoPreferenceController(
|
||||||
context, null /* fragment */, null /* lifecycle */));
|
context, null /* fragment */, null /* lifecycle */));
|
||||||
controllers.add(new LockdownButtonPreferenceController(context));
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,24 +51,24 @@ public class LockdownButtonPreferenceControllerTest {
|
|||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mPreference = new SwitchPreference(mContext);
|
mPreference = new SwitchPreference(mContext);
|
||||||
|
|
||||||
mController = spy(new LockdownButtonPreferenceController(mContext));
|
mController = spy(new LockdownButtonPreferenceController(mContext, "TestKey"));
|
||||||
ReflectionHelpers.setField(mController, "mLockPatternUtils", mLockPatternUtils);
|
ReflectionHelpers.setField(mController, "mLockPatternUtils", mLockPatternUtils);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_lockSet_shouldReturnTrue() throws Exception {
|
public void isAvailable_lockSet_shouldReturnTrue() {
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_lockUnset_shouldReturnFalse() throws Exception {
|
public void isAvailable_lockUnset_shouldReturnFalse() {
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onPreferenceChange_settingIsUpdated() throws Exception {
|
public void onPreferenceChange_settingIsUpdated() {
|
||||||
boolean state = Settings.Secure.getInt(mContext.getContentResolver(),
|
boolean state = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0) != 0;
|
Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0) != 0;
|
||||||
assertThat(mController.onPreferenceChange(mPreference, !state)).isTrue();
|
assertThat(mController.onPreferenceChange(mPreference, !state)).isTrue();
|
||||||
@@ -78,7 +78,7 @@ public class LockdownButtonPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSettingChange_preferenceIsUpdated() throws Exception {
|
public void onSettingChange_preferenceIsUpdated() {
|
||||||
boolean state = Settings.Secure.getInt(mContext.getContentResolver(),
|
boolean state = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0) != 0;
|
Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0) != 0;
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
Reference in New Issue
Block a user