diff --git a/res/values/strings.xml b/res/values/strings.xml index eb273107459..02455b1e145 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -744,6 +744,10 @@ Security & screen lock Encryption & credentials + + Lock screen preferences + + Access settings in lock screen Set My Location, screen unlock, SIM card lock, credential storage lock diff --git a/res/xml/security_lockscreen_settings.xml b/res/xml/security_lockscreen_settings.xml new file mode 100644 index 00000000000..e151b2b3219 --- /dev/null +++ b/res/xml/security_lockscreen_settings.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + diff --git a/res/xml/security_settings_chooser.xml b/res/xml/security_settings_chooser.xml index 6438771ecae..dc6e727f751 100644 --- a/res/xml/security_settings_chooser.xml +++ b/res/xml/security_settings_chooser.xml @@ -29,6 +29,11 @@ settings:keywords="@string/keywords_lockscreen" android:persistent="false"/> + + diff --git a/res/xml/security_settings_password.xml b/res/xml/security_settings_password.xml index 57f19ebe302..e3a5dfd3b23 100644 --- a/res/xml/security_settings_password.xml +++ b/res/xml/security_settings_password.xml @@ -28,6 +28,11 @@ android:summary="@string/unlock_set_unlock_mode_password" settings:keywords="@string/keywords_lockscreen" /> + + diff --git a/res/xml/security_settings_pattern.xml b/res/xml/security_settings_pattern.xml index ad57e82be4f..295e896e665 100644 --- a/res/xml/security_settings_pattern.xml +++ b/res/xml/security_settings_pattern.xml @@ -28,6 +28,11 @@ android:summary="@string/unlock_set_unlock_mode_pattern" settings:keywords="@string/keywords_lockscreen" /> + + diff --git a/res/xml/security_settings_pin.xml b/res/xml/security_settings_pin.xml index 31a57a2fc4b..5613177c609 100644 --- a/res/xml/security_settings_pin.xml +++ b/res/xml/security_settings_pin.xml @@ -28,6 +28,11 @@ android:summary="@string/unlock_set_unlock_mode_pin" settings:keywords="@string/keywords_lockscreen" /> + + diff --git a/src/com/android/settings/OwnerInfoSettings.java b/src/com/android/settings/OwnerInfoSettings.java index 7314da3e10d..18cfb8e35f8 100644 --- a/src/com/android/settings/OwnerInfoSettings.java +++ b/src/com/android/settings/OwnerInfoSettings.java @@ -31,6 +31,7 @@ import android.widget.EditText; import com.android.internal.logging.nano.MetricsProto; import com.android.internal.widget.LockPatternUtils; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; +import com.android.settings.security.OwnerInfoPreferenceController.OwnerInfoCallback; public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnClickListener { @@ -76,8 +77,8 @@ public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnC mLockPatternUtils.setOwnerInfoEnabled(!TextUtils.isEmpty(info), mUserId); mLockPatternUtils.setOwnerInfo(info, mUserId); - if (getTargetFragment() instanceof SecuritySettings.SecuritySubSettings) { - ((SecuritySettings.SecuritySubSettings) getTargetFragment()).updateOwnerInfo(); + if (getTargetFragment() instanceof OwnerInfoCallback) { + ((OwnerInfoCallback) getTargetFragment()).onOwnerInfoUpdated(); } } } diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index 1cb763b633c..37022f06aff 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -16,7 +16,6 @@ package com.android.settings; - import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -67,6 +66,7 @@ import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settings.search.SearchIndexableRaw; import com.android.settings.search2.SearchFeatureProvider; +import com.android.settings.security.OwnerInfoPreferenceController; import com.android.settings.security.SecurityFeatureProvider; import com.android.settings.trustagent.TrustAgentManager; import com.android.settings.widget.GearPreference; @@ -917,11 +917,10 @@ public class SecuritySettings extends SettingsPreferenceFragment } public static class SecuritySubSettings extends SettingsPreferenceFragment - implements OnPreferenceChangeListener { + implements OnPreferenceChangeListener, OwnerInfoPreferenceController.OwnerInfoCallback { private static final String KEY_VISIBLE_PATTERN = "visiblepattern"; private static final String KEY_LOCK_AFTER_TIMEOUT = "lock_after_timeout"; - private static final String KEY_OWNER_INFO_SETTINGS = "owner_info_settings"; private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks"; // These switch preferences need special handling since they're not all stored in Settings. @@ -931,11 +930,11 @@ public class SecuritySettings extends SettingsPreferenceFragment private TimeoutListPreference mLockAfter; private SwitchPreference mVisiblePattern; private SwitchPreference mPowerButtonInstantlyLocks; - private RestrictedPreference mOwnerInfoPref; private TrustAgentManager mTrustAgentManager; private LockPatternUtils mLockPatternUtils; private DevicePolicyManager mDPM; + private OwnerInfoPreferenceController mOwnerInfoPreferenceController; @Override public int getMetricsCategory() { @@ -950,6 +949,8 @@ public class SecuritySettings extends SettingsPreferenceFragment mTrustAgentManager = securityFeatureProvider.getTrustAgentManager(); mLockPatternUtils = new LockPatternUtils(getContext()); mDPM = getContext().getSystemService(DevicePolicyManager.class); + mOwnerInfoPreferenceController = + new OwnerInfoPreferenceController(getContext(), this, null /* lifecycle */); createPreferenceHierarchy(); } @@ -968,7 +969,7 @@ public class SecuritySettings extends SettingsPreferenceFragment mLockPatternUtils.getPowerButtonInstantlyLocks(MY_USER_ID)); } - updateOwnerInfo(); + mOwnerInfoPreferenceController.updateSummary(); } @Override @@ -1010,26 +1011,8 @@ public class SecuritySettings extends SettingsPreferenceFragment trustAgentLabel)); } - mOwnerInfoPref = (RestrictedPreference) findPreference(KEY_OWNER_INFO_SETTINGS); - if (mOwnerInfoPref != null) { - if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) { - EnforcedAdmin admin = RestrictedLockUtils.getDeviceOwner(getActivity()); - mOwnerInfoPref.setDisabledByAdmin(admin); - } else { - mOwnerInfoPref.setDisabledByAdmin(null); - mOwnerInfoPref.setEnabled(!mLockPatternUtils.isLockScreenDisabled(MY_USER_ID)); - if (mOwnerInfoPref.isEnabled()) { - mOwnerInfoPref.setOnPreferenceClickListener( - new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - OwnerInfoSettings.show(SecuritySubSettings.this); - return true; - } - }); - } - } - } + mOwnerInfoPreferenceController.displayPreference(getPreferenceScreen()); + mOwnerInfoPreferenceController.updateEnableState(); for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) { final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]); @@ -1093,17 +1076,9 @@ public class SecuritySettings extends SettingsPreferenceFragment mLockAfter.setSummary(summary); } - public void updateOwnerInfo() { - if (mOwnerInfoPref != null) { - if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) { - mOwnerInfoPref.setSummary( - mLockPatternUtils.getDeviceOwnerInfo()); - } else { - mOwnerInfoPref.setSummary(mLockPatternUtils.isOwnerInfoEnabled(MY_USER_ID) - ? mLockPatternUtils.getOwnerInfo(MY_USER_ID) - : getString(R.string.owner_info_settings_summary)); - } - } + @Override + public void onOwnerInfoUpdated() { + mOwnerInfoPreferenceController.updateSummary(); } private static int getResIdForLockUnlockSubScreen(Context context, diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java index 467b848f185..59cedf87484 100644 --- a/src/com/android/settings/core/gateway/SettingsGateway.java +++ b/src/com/android/settings/core/gateway/SettingsGateway.java @@ -111,6 +111,7 @@ import com.android.settings.notification.ZenModeSettings; import com.android.settings.notification.ZenModeVisualInterruptionSettings; import com.android.settings.print.PrintJobSettingsFragment; import com.android.settings.print.PrintSettingsFragment; +import com.android.settings.security.LockscreenDashboardFragment; import com.android.settings.sim.SimSettings; import com.android.settings.system.SystemDashboardFragment; import com.android.settings.tts.TextToSpeechSettings; @@ -242,6 +243,7 @@ public class SettingsGateway { UserAndAccountDashboardFragment.class.getName(), EnterprisePrivacySettings.class.getName(), WebViewAppPicker.class.getName(), + LockscreenDashboardFragment.class.getName(), }; public static final String[] SETTINGS_FOR_RESTRICTED = { diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index dd59e868ad3..f88d83033c0 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -70,6 +70,7 @@ import com.android.settings.notification.ZenModePrioritySettings; import com.android.settings.notification.ZenModeSettings; import com.android.settings.notification.ZenModeVisualInterruptionSettings; import com.android.settings.print.PrintSettingsFragment; +import com.android.settings.security.LockscreenDashboardFragment; import com.android.settings.sim.SimSettings; import com.android.settings.system.SystemDashboardFragment; import com.android.settings.tts.TtsEnginePreferenceFragment; @@ -170,6 +171,8 @@ public final class SearchIndexableResources { addIndex(PaymentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_nfc_payment); addIndex( TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language); + addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings, + R.drawable.ic_settings_security); } private SearchIndexableResources() { diff --git a/src/com/android/settings/security/LockscreenDashboardFragment.java b/src/com/android/settings/security/LockscreenDashboardFragment.java new file mode 100644 index 00000000000..b781fbb973b --- /dev/null +++ b/src/com/android/settings/security/LockscreenDashboardFragment.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2017 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.security; + +import android.content.Context; +import android.provider.SearchIndexableResource; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.settings.R; +import com.android.settings.accounts.AddUserWhenLockedPreferenceController; +import com.android.settings.core.PreferenceController; +import com.android.settings.core.lifecycle.Lifecycle; +import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.notification.LockScreenNotificationPreferenceController; +import com.android.settings.search.BaseSearchIndexProvider; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Settings screen for lock screen preference + */ +public class LockscreenDashboardFragment extends DashboardFragment + implements OwnerInfoPreferenceController.OwnerInfoCallback { + + private static final String TAG = "LockscreenDashboardFragment"; + + private OwnerInfoPreferenceController mOwnerInfoPreferenceController; + + @Override + public int getMetricsCategory() { + return MetricsEvent.SETTINGS_LOCK_SCREEN_PREFERENCES; + } + + @Override + protected String getLogTag() { + return TAG; + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.security_lockscreen_settings; + } + + @Override + protected List getPreferenceControllers(Context context) { + final List controllers = new ArrayList<>(); + final Lifecycle lifecycle = getLifecycle(); + final LockScreenNotificationPreferenceController notificationController = + new LockScreenNotificationPreferenceController(context); + lifecycle.addObserver(notificationController); + controllers.add(notificationController); + final AddUserWhenLockedPreferenceController addUserWhenLockedController = + new AddUserWhenLockedPreferenceController(context); + lifecycle.addObserver(addUserWhenLockedController); + controllers.add(addUserWhenLockedController); + mOwnerInfoPreferenceController = + new OwnerInfoPreferenceController(context, this, lifecycle); + controllers.add(mOwnerInfoPreferenceController); + return controllers; + } + + @Override + public void onOwnerInfoUpdated() { + if (mOwnerInfoPreferenceController != null) { + mOwnerInfoPreferenceController.updateSummary(); + } + } + + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.security_lockscreen_settings; + return Arrays.asList(sir); + } + + @Override + public List getPreferenceControllers(Context context) { + final List controllers = new ArrayList<>(); + controllers.add(new LockScreenNotificationPreferenceController(context)); + controllers.add(new AddUserWhenLockedPreferenceController(context)); + controllers.add(new OwnerInfoPreferenceController( + context, null /* fragment */, null /* lifecycle */)); + return controllers; + } + }; +} diff --git a/src/com/android/settings/security/OwnerInfoPreferenceController.java b/src/com/android/settings/security/OwnerInfoPreferenceController.java new file mode 100644 index 00000000000..259ef124ac4 --- /dev/null +++ b/src/com/android/settings/security/OwnerInfoPreferenceController.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2017 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.security; + +import android.app.Fragment; +import android.content.Context; +import android.os.UserHandle; +import android.support.annotation.VisibleForTesting; +import android.support.v7.preference.Preference; +import android.support.v7.preference.Preference.OnPreferenceClickListener; +import android.support.v7.preference.PreferenceScreen; +import com.android.internal.widget.LockPatternUtils; +import com.android.settings.OwnerInfoSettings; +import com.android.settings.core.PreferenceController; +import com.android.settings.core.lifecycle.Lifecycle; +import com.android.settings.core.lifecycle.LifecycleObserver; +import com.android.settings.core.lifecycle.events.OnResume; +import com.android.settingslib.RestrictedLockUtils; +import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; +import com.android.settingslib.RestrictedPreference; + +public class OwnerInfoPreferenceController extends PreferenceController + implements LifecycleObserver, OnResume { + + private static final String KEY_OWNER_INFO = "owner_info_settings"; + private static final int MY_USER_ID = UserHandle.myUserId(); + + private final LockPatternUtils mLockPatternUtils; + private final Fragment mParent; + private RestrictedPreference mOwnerInfoPref; + + // Container fragment should implement this in order to show the correct summary + public interface OwnerInfoCallback { + public void onOwnerInfoUpdated(); + } + + public OwnerInfoPreferenceController(Context context, Fragment parent, Lifecycle lifecycle ) { + super(context); + mParent = parent; + mLockPatternUtils = new LockPatternUtils(context); + if (lifecycle != null) { + lifecycle.addObserver(this); + } + } + + @Override + public void displayPreference(PreferenceScreen screen) { + mOwnerInfoPref = (RestrictedPreference) screen.findPreference(KEY_OWNER_INFO); + } + + @Override + public void onResume() { + updateEnableState(); + updateSummary(); + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public String getPreferenceKey() { + return KEY_OWNER_INFO; + } + + public void updateEnableState() { + if (mOwnerInfoPref == null) { + return; + } + if (isDeviceOwnerInfoEnabled()) { + EnforcedAdmin admin = getDeviceOwner(); + mOwnerInfoPref.setDisabledByAdmin(admin); + } else { + mOwnerInfoPref.setDisabledByAdmin(null); + mOwnerInfoPref.setEnabled(!mLockPatternUtils.isLockScreenDisabled(MY_USER_ID)); + if (mOwnerInfoPref.isEnabled()) { + mOwnerInfoPref.setOnPreferenceClickListener( + new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + OwnerInfoSettings.show(mParent); + return true; + } + }); + } + } + } + + public void updateSummary() { + if (mOwnerInfoPref != null) { + if (isDeviceOwnerInfoEnabled()) { + mOwnerInfoPref.setSummary( + getDeviceOwnerInfo()); + } else { + mOwnerInfoPref.setSummary(isOwnerInfoEnabled() + ? getOwnerInfo() + : mContext.getString( + com.android.settings.R.string.owner_info_settings_summary)); + } + } + } + + // Wrapper methods to allow testing + @VisibleForTesting + boolean isDeviceOwnerInfoEnabled() { + return mLockPatternUtils.isDeviceOwnerInfoEnabled(); + } + + @VisibleForTesting + String getDeviceOwnerInfo() { + return mLockPatternUtils.getDeviceOwnerInfo(); + } + + @VisibleForTesting + boolean isOwnerInfoEnabled() { + return mLockPatternUtils.isOwnerInfoEnabled(MY_USER_ID); + } + + @VisibleForTesting + String getOwnerInfo() { + return mLockPatternUtils.getOwnerInfo(MY_USER_ID); + } + + @VisibleForTesting + EnforcedAdmin getDeviceOwner() { + return RestrictedLockUtils.getDeviceOwner(mContext); + } +} diff --git a/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java new file mode 100644 index 00000000000..d81768a12ef --- /dev/null +++ b/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2017 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.security; + +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.content.Context; +import android.support.v7.preference.PreferenceScreen; +import android.support.v14.preference.PreferenceFragment; + +import com.android.internal.widget.LockPatternUtils; +import com.android.settings.OwnerInfoSettings; +import com.android.settings.R; +import com.android.settings.SettingsRobolectricTestRunner; +import com.android.settings.TestConfig; +import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; +import com.android.settingslib.RestrictedPreference; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; +import org.robolectric.util.ReflectionHelpers; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Answers.RETURNS_DEEP_STUBS; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class OwnerInfoPreferenceControllerTest { + + @Mock(answer = RETURNS_DEEP_STUBS) + private PreferenceFragment mFragment; + @Mock + private PreferenceScreen mScreen; + @Mock + private FragmentManager mFragmentManager; + @Mock + private FragmentTransaction mFragmentTransaction; + @Mock + private RestrictedPreference mPreference; + @Mock + private LockPatternUtils mLockPatternUtils; + + private Context mContext; + private OwnerInfoPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + ShadowApplication shadowContext = ShadowApplication.getInstance(); + mContext = spy(shadowContext.getApplicationContext()); + + when(mFragment.isAdded()).thenReturn(true); + when(mFragment.getPreferenceScreen()).thenReturn(mScreen); + when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext); + when(mFragment.getFragmentManager()).thenReturn(mFragmentManager); + when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction); + + mController = spy(new OwnerInfoPreferenceController(mContext, mFragment, null)); + when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); + ReflectionHelpers.setField(mController, "mLockPatternUtils", mLockPatternUtils); + } + + @Test + public void isAvailable_shouldReturnTrue() { + assertThat(mController.isAvailable()).isTrue(); + } + + @Test + public void onResume_shouldUpdateEnableState() { + mController.onResume(); + + verify(mController).updateEnableState(); + } + + @Test + public void onResume_shouldUpdateSummary() { + mController.onResume(); + + verify(mController).updateSummary(); + } + + @Test + public void updateSummary_deviceOwnerInfoEnabled_shouldSetDeviceOwnerInfoSummary() { + final String deviceOwnerInfo = "Test Device Owner Info"; + doReturn(true).when(mController).isDeviceOwnerInfoEnabled(); + doReturn(deviceOwnerInfo).when(mController).getDeviceOwnerInfo(); + mController.displayPreference(mScreen); + + mController.updateSummary(); + + verify(mPreference).setSummary(deviceOwnerInfo); + } + + @Test + public void updateSummary_ownerInfoEnabled_shouldSetOwnerInfoSummary() { + final String ownerInfo = "Test Owner Info"; + doReturn(false).when(mController).isDeviceOwnerInfoEnabled(); + doReturn(true).when(mController).isOwnerInfoEnabled(); + doReturn(ownerInfo).when(mController).getOwnerInfo(); + mController.displayPreference(mScreen); + + mController.updateSummary(); + + verify(mPreference).setSummary(ownerInfo); + } + + @Test + public void updateSummary_ownerInfoDisabled_shouldSetDefaultSummary() { + doReturn(false).when(mController).isDeviceOwnerInfoEnabled(); + doReturn(false).when(mController).isOwnerInfoEnabled(); + mController.displayPreference(mScreen); + + mController.updateSummary(); + + verify(mPreference).setSummary(mContext.getString( + com.android.settings.R.string.owner_info_settings_summary)); + } + + @Test + public void updateEnableState_deviceOwnerInfoEnabled_shouldSetDisabledByAdmin() { + doReturn(true).when(mController).isDeviceOwnerInfoEnabled(); + doReturn(mock(EnforcedAdmin.class)).when(mController).getDeviceOwner(); + mController.displayPreference(mScreen); + + mController.updateEnableState(); + + verify(mPreference).setDisabledByAdmin(any(EnforcedAdmin.class)); + } + + @Test + public void updateEnableState_lockScreenDisabled_shouldDisablePreference() { + doReturn(false).when(mController).isDeviceOwnerInfoEnabled(); + doReturn(true).when(mLockPatternUtils).isLockScreenDisabled(anyInt()); + mController.displayPreference(mScreen); + + mController.updateEnableState(); + + verify(mPreference).setEnabled(false); + } + + @Test + public void updateEnableState_lockScreenEnabled_shouldEnablePreference() { + doReturn(false).when(mController).isDeviceOwnerInfoEnabled(); + doReturn(false).when(mLockPatternUtils).isLockScreenDisabled(anyInt()); + mController.displayPreference(mScreen); + + mController.updateEnableState(); + + verify(mPreference).setEnabled(true); + } + + @Test + public void performClick_shouldLaunchOwnerInfoSettings() { + final ShadowApplication application = ShadowApplication.getInstance(); + final RestrictedPreference preference = + new RestrictedPreference(application.getApplicationContext()); + when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(preference); + doReturn(false).when(mController).isDeviceOwnerInfoEnabled(); + doReturn(false).when(mLockPatternUtils).isLockScreenDisabled(anyInt()); + mController.displayPreference(mScreen); + mController.updateEnableState(); + + preference.performClick(); + + verify(mFragment).getFragmentManager(); + verify(mFragment.getFragmentManager().beginTransaction()) + .add(any(OwnerInfoSettings.class), anyString()); + } + +} \ No newline at end of file