From cee83e4bbf80da6193feb65b67a29a2a970fc73e Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Thu, 6 Apr 2017 16:01:37 -0700 Subject: [PATCH] Add summary text to Lock screen preferences. Each time we refresh the security preference page, get the current summary text from "On the lock screen" and populate to Lock screen preferences summary. Bug: 36540633 Test: make RunSettingsRoboTests Change-Id: I317e3892b35b30981b62f7b7aee9cfdacd04a3ed --- res/values/strings.xml | 2 -- res/xml/security_settings_chooser.xml | 1 - res/xml/security_settings_password.xml | 1 - res/xml/security_settings_pattern.xml | 1 - res/xml/security_settings_pin.xml | 1 - .../android/settings/SecuritySettings.java | 16 ++++++++++++++ ...creenNotificationPreferenceController.java | 16 ++++++++------ .../settings/SecuritySettingsTest.java | 21 +++++++++++++++++++ 8 files changed, 47 insertions(+), 12 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 35a6f5144da..fd3562ee3f9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -750,8 +750,6 @@ Phone encrypted Lock screen preferences - - Show all notification content Set My Location, screen unlock, SIM card lock, credential storage lock diff --git a/res/xml/security_settings_chooser.xml b/res/xml/security_settings_chooser.xml index dc6e727f751..067ebaba0d0 100644 --- a/res/xml/security_settings_chooser.xml +++ b/res/xml/security_settings_chooser.xml @@ -31,7 +31,6 @@ diff --git a/res/xml/security_settings_password.xml b/res/xml/security_settings_password.xml index e3a5dfd3b23..7de65f7cc0b 100644 --- a/res/xml/security_settings_password.xml +++ b/res/xml/security_settings_password.xml @@ -30,7 +30,6 @@ diff --git a/res/xml/security_settings_pattern.xml b/res/xml/security_settings_pattern.xml index 295e896e665..1585f016ee8 100644 --- a/res/xml/security_settings_pattern.xml +++ b/res/xml/security_settings_pattern.xml @@ -30,7 +30,6 @@ diff --git a/res/xml/security_settings_pin.xml b/res/xml/security_settings_pin.xml index 5613177c609..f7705b7e9cd 100644 --- a/res/xml/security_settings_pin.xml +++ b/res/xml/security_settings_pin.xml @@ -30,7 +30,6 @@ diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index a56889d252d..1e64b7f1bae 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -60,6 +60,7 @@ import com.android.settings.enterprise.EnterprisePrivacyPreferenceController; import com.android.settings.enterprise.ManageDeviceAdminPreferenceController; import com.android.settings.fingerprint.FingerprintSettings; import com.android.settings.location.LocationPreferenceController; +import com.android.settings.notification.LockScreenNotificationPreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; @@ -103,6 +104,8 @@ public class SecuritySettings extends SettingsPreferenceFragment @VisibleForTesting static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents"; private static final String KEY_UNIFICATION = "unification"; + @VisibleForTesting + static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences"; private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123; private static final int CHANGE_TRUST_AGENT_SETTINGS = 126; @@ -169,6 +172,7 @@ public class SecuritySettings extends SettingsPreferenceFragment private LocationPreferenceController mLocationcontroller; private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController; private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController; + private LockScreenNotificationPreferenceController mLockScreenNotificationPreferenceController; @Override public int getMetricsCategory() { @@ -210,6 +214,8 @@ public class SecuritySettings extends SettingsPreferenceFragment = new ManageDeviceAdminPreferenceController(activity); mEnterprisePrivacyPreferenceController = new EnterprisePrivacyPreferenceController(activity, null /* lifecycle */); + mLockScreenNotificationPreferenceController + = new LockScreenNotificationPreferenceController(activity); } private static int getResIdForLockUnlockScreen(Context context, @@ -317,6 +323,7 @@ public class SecuritySettings extends SettingsPreferenceFragment if (securityCategory != null) { maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId()); numberOfTrustAgent = addTrustAgentSettings(securityCategory); + setLockscreenPreferencesSummary(securityCategory); } mVisiblePatternProfile = @@ -423,6 +430,15 @@ public class SecuritySettings extends SettingsPreferenceFragment } } + @VisibleForTesting + void setLockscreenPreferencesSummary(PreferenceGroup group) { + final Preference lockscreenPreferences = group.findPreference(KEY_LOCKSCREEN_PREFERENCES); + if (lockscreenPreferences != null) { + lockscreenPreferences.setSummary( + mLockScreenNotificationPreferenceController.getSummaryResource()); + } + } + /* * Sets the preference as disabled by admin if PASSWORD_QUALITY_MANAGED is set. * The preference must be a RestrictedPreference. diff --git a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java index a7ebbe13dc0..547ff801756 100644 --- a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java +++ b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java @@ -267,16 +267,20 @@ public class LockScreenNotificationPreferenceController extends PreferenceContro } } + public int getSummaryResource() { + final boolean enabled = getLockscreenNotificationsEnabled(UserHandle.myUserId()); + final boolean allowPrivate = !mSecure + || getLockscreenAllowPrivateNotifications(UserHandle.myUserId()); + return !enabled ? R.string.lock_screen_notifications_summary_disable : + allowPrivate ? R.string.lock_screen_notifications_summary_show : + R.string.lock_screen_notifications_summary_hide; + } + private void updateLockscreenNotifications() { if (mLockscreen == null) { return; } - final boolean enabled = getLockscreenNotificationsEnabled(UserHandle.myUserId()); - final boolean allowPrivate = !mSecure - || getLockscreenAllowPrivateNotifications(UserHandle.myUserId()); - mLockscreenSelectedValue = !enabled ? R.string.lock_screen_notifications_summary_disable : - allowPrivate ? R.string.lock_screen_notifications_summary_show : - R.string.lock_screen_notifications_summary_hide; + mLockscreenSelectedValue = getSummaryResource(); mLockscreen.setValue(Integer.toString(mLockscreenSelectedValue)); } diff --git a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java index 91111a8b005..9bdf502b9b8 100644 --- a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java +++ b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java @@ -24,10 +24,12 @@ import android.hardware.fingerprint.FingerprintManager; import android.os.Bundle; import android.provider.Settings; import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceScreen; import com.android.internal.widget.LockPatternUtils; import com.android.settings.dashboard.SummaryLoader; +import com.android.settings.notification.LockScreenNotificationPreferenceController; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.shadow.ShadowSecureSettings; import com.android.settingslib.drawer.DashboardCategory; @@ -47,6 +49,7 @@ import org.robolectric.shadows.ShadowApplication; import org.robolectric.util.ReflectionHelpers; import java.util.Map; +import org.robolectric.util.ReflectionHelpers; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; @@ -186,4 +189,22 @@ public class SecuritySettingsTest { verify(preference).setSummary(context.getResources().getQuantityString( R.plurals.manage_trust_agents_summary_on, 2, 2)); } + + @Test + public void testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification() { + final Preference preference = mock(Preference.class); + final PreferenceGroup group = mock(PreferenceGroup.class); + when(group.findPreference(SecuritySettings.KEY_LOCKSCREEN_PREFERENCES)) + .thenReturn(preference); + final LockScreenNotificationPreferenceController controller = + mock(LockScreenNotificationPreferenceController.class); + + final SecuritySettings securitySettings = new SecuritySettings(); + ReflectionHelpers.setField(securitySettings, + "mLockScreenNotificationPreferenceController", controller); + + when(controller.getSummaryResource()).thenReturn(1234); + securitySettings.setLockscreenPreferencesSummary(group); + verify(preference).setSummary(1234); + } }