From aa31b9cb4ad804fe3dc7a4ee0888031049922d1d Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 9 Mar 2018 15:14:07 -0500 Subject: [PATCH 1/9] Updated dnd secondary text in sound settings Test: manual Bug: 74441398 Change-Id: I4dafd9082e03bc9fa8f5e3f9505a8a1bb2fcc4da --- res/values/strings.xml | 7 +++++-- .../settings/notification/ZenModeSettings.java | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c64880eb818..20a59de13ba 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7030,8 +7030,8 @@ %1$s. %2$s - - On / %1$s + + On / %1$s Off / %1$s @@ -7039,6 +7039,9 @@ Off + + On + 1 rule can turn on automatically diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java index fdb5cc6dbc5..557d6248960 100644 --- a/src/com/android/settings/notification/ZenModeSettings.java +++ b/src/com/android/settings/notification/ZenModeSettings.java @@ -23,6 +23,7 @@ import android.app.NotificationManager.Policy; import android.content.Context; import android.provider.SearchIndexableResource; import android.provider.Settings; +import android.service.notification.ZenModeConfig; import android.support.annotation.VisibleForTesting; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; @@ -122,9 +123,15 @@ public class ZenModeSettings extends ZenModeSettingsBase { int zenMode = NotificationManager.from(mContext).getZenMode(); if (zenMode != Settings.Global.ZEN_MODE_OFF) { - Policy policy = NotificationManager.from(mContext).getNotificationPolicy(); - return mContext.getString(R.string.zen_mode_sound_summary_on, - getBehaviorSettingSummary(policy, zenMode)); + ZenModeConfig config = NotificationManager.from(mContext).getZenModeConfig(); + String description = ZenModeConfig.getDescription(mContext, true, config); + + if (description == null) { + return mContext.getString(R.string.zen_mode_sound_summary_on); + } else { + return mContext.getString(R.string.zen_mode_sound_summary_on_with_info, + description); + } } else { final int count = getEnabledAutomaticRulesCount(); if (count > 0) { From ff6a90994f2f67a63a5cad52d67155008cdb2ceb Mon Sep 17 00:00:00 2001 From: Ajay Panicker Date: Wed, 7 Mar 2018 15:55:02 -0800 Subject: [PATCH 2/9] Bluetooth: Enable AVDTP Delay reports by default. Bug: 32755225 Test: See that delay reports are enabled when connecting to device Change-Id: Icba9be6fc8ba455d37df39d283e36129f6acb536 (cherry picked from commit a8cf0b9371bf9bcb2b92243ec29b822f1f021098) --- res/values/strings.xml | 8 +++---- res/xml/development_settings.xml | 6 ++--- ...toothDelayReportsPreferenceController.java | 24 +++++++++---------- ...hDelayReportsPreferenceControllerTest.java | 20 +++++++++------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c64880eb818..fdb83b3dadd 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1676,10 +1676,10 @@ Maximum connected Bluetooth audio devices Select maximum number of connected Bluetooth audio devices - - Enable Bluetooth AVDTP delay reports - - Allow receiving Bluetooth AVDTP delay reports + + Disable Bluetooth AVDTP delay reports + + Disallow receiving Bluetooth AVDTP delay reports Cast diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index 571f38ef509..282a5121533 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -264,9 +264,9 @@ android:summary="@string/bluetooth_disable_inband_ringing_summary" /> + android:key="bluetooth_disable_avdtp_delay_reports" + android:title="@string/bluetooth_disable_avdtp_delay_reports" + android:summary="@string/bluetooth_disable_avdtp_delay_reports_summary"/> Date: Fri, 9 Mar 2018 15:22:57 -0800 Subject: [PATCH 3/9] Fix failing testcases in SettingsAdapterTest. - added the shadow class for CardView to fix the not implemented error. Change-Id: I17a53f804310ffb3330c1cd3ca11943cf91335a6 Fixes: 74446970 Test: make RunSettingsRoboTests --- .../suggestions/SuggestionAdapterTest.java | 13 ++----- .../testutils/shadow/ShadowCardView.java | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/testutils/shadow/ShadowCardView.java diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java index 522067b501c..dc492a93907 100644 --- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java @@ -44,23 +44,25 @@ import com.android.settings.SettingsActivity; import com.android.settings.dashboard.DashboardAdapter; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.SettingsRobolectricTestRunner; +import com.android.settings.testutils.shadow.ShadowCardView; import com.android.settingslib.suggestions.SuggestionControllerMixin; import com.android.settingslib.utils.IconCache; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; import java.util.ArrayList; import java.util.List; @RunWith(SettingsRobolectricTestRunner.class) +@Config(shadows = ShadowCardView.class) public class SuggestionAdapterTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) @@ -143,7 +145,6 @@ public class SuggestionAdapterTest { .isEqualTo(R.layout.suggestion_tile_with_button); } - @Ignore @Test public void onBindViewHolder_shouldLog() { final View view = spy(LayoutInflater.from(mContext).inflate( @@ -164,7 +165,6 @@ public class SuggestionAdapterTest { mOneSuggestion.get(0).getId()); } - @Ignore @Test public void onBindViewHolder_itemViewShouldHandleClick() throws PendingIntent.CanceledException { @@ -178,7 +178,6 @@ public class SuggestionAdapterTest { verify(suggestions.get(0).getPendingIntent()).send(); } - @Ignore @Test public void onBindViewHolder_hasButton_buttonShouldHandleClick() throws PendingIntent.CanceledException { @@ -205,7 +204,6 @@ public class SuggestionAdapterTest { verify(pendingIntent).send(); } - @Ignore @Test public void getSuggestions_shouldReturnSuggestionWhenMatch() { final List suggestions = makeSuggestions("pkg1"); @@ -214,7 +212,6 @@ public class SuggestionAdapterTest { assertThat(mSuggestionAdapter.getSuggestion(0)).isNotNull(); } - @Ignore @Test public void onBindViewHolder_closeButtonShouldHandleClick() throws PendingIntent.CanceledException { @@ -236,7 +233,6 @@ public class SuggestionAdapterTest { verify(callback).onSuggestionClosed(suggestion); } - @Ignore @Test public void onBindViewHolder_iconNotTintable_shouldNotTintIcon() throws PendingIntent.CanceledException { @@ -263,7 +259,6 @@ public class SuggestionAdapterTest { verify(drawable, never()).setTint(anyInt()); } - @Ignore @Test public void onBindViewHolder_iconTintable_shouldTintIcon() throws PendingIntent.CanceledException { @@ -296,7 +291,6 @@ public class SuggestionAdapterTest { verify(drawable).setTint(colorAccent); } - @Ignore @Test public void onBindViewHolder_closeButtonShouldHaveContentDescription() throws PendingIntent.CanceledException { @@ -310,7 +304,6 @@ public class SuggestionAdapterTest { .isNotNull(); } - @Ignore @Test public void setCardLayout_twoCards_shouldSetCardWidthToHalfScreenMinusPadding() { final List suggestions = makeSuggestions("pkg1"); diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowCardView.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowCardView.java new file mode 100644 index 00000000000..e349ee36f0f --- /dev/null +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowCardView.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 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.testutils.shadow; + +import android.content.Context; +import android.support.v7.widget.CardView; +import android.util.AttributeSet; + +import org.robolectric.annotation.Implements; +import org.robolectric.shadows.ShadowFrameLayout; + +/** + * Shadow for CardView to get around view not implemented error. + */ +@Implements(CardView.class) +public class ShadowCardView extends ShadowFrameLayout { + + public void __constructor__(Context context, AttributeSet attrs, int defStyleAttr) { + // do nothing + } + +} From 1f61ff4cf9e8e7b9bd36c849a65839373b394070 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Mon, 5 Mar 2018 16:35:48 -0800 Subject: [PATCH 4/9] Introduce boolean flags to show/hide Encryption status. This adds one new flag: config_show_encryption_and_credentials_encryption_status Which when set to false, will hide Encryption status from Encryption & credentials. This is when the storage is not being handed by Android, and so this preference would not be necessarily correct. Bug: 74127210 Test: Updated robotests Change-Id: I13665fa369086ef29a4de5f99a78bfbaf96f2f6b (cherry picked from commit 2d5df469d3a50a1aea6245785e54d0d4ad301d39) --- res/values/bools.xml | 3 +++ .../EncryptionStatusPreferenceController.java | 6 ++++++ tests/robotests/res/values-mcc999/config.xml | 1 + ...ncryptionStatusPreferenceControllerTest.java | 17 +++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/res/values/bools.xml b/res/values/bools.xml index 4665f2eaed9..79285106465 100644 --- a/res/values/bools.xml +++ b/res/values/bools.xml @@ -96,6 +96,9 @@ true + + true + true diff --git a/src/com/android/settings/security/EncryptionStatusPreferenceController.java b/src/com/android/settings/security/EncryptionStatusPreferenceController.java index 234124827b5..81255991792 100644 --- a/src/com/android/settings/security/EncryptionStatusPreferenceController.java +++ b/src/com/android/settings/security/EncryptionStatusPreferenceController.java @@ -41,6 +41,12 @@ public class EncryptionStatusPreferenceController extends BasePreferenceControll @Override public int getAvailabilityStatus() { + if (TextUtils.equals(getPreferenceKey(), PREF_KEY_ENCRYPTION_DETAIL_PAGE) && + !mContext.getResources().getBoolean( + R.bool.config_show_encryption_and_credentials_encryption_status)) { + return DISABLED_UNSUPPORTED; + } + return mUserManager.isAdminUser() ? AVAILABLE : DISABLED_FOR_USER; } diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml index 788c593d2a2..d4e030c2ae6 100644 --- a/tests/robotests/res/values-mcc999/config.xml +++ b/tests/robotests/res/values-mcc999/config.xml @@ -34,6 +34,7 @@ false false false + false false false false diff --git a/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java index ee6d33aace0..2e6b703d2c8 100644 --- a/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java @@ -67,6 +67,23 @@ public class EncryptionStatusPreferenceControllerTest { assertThat(mController.isAvailable()).isFalse(); } + @Test + @Config(qualifiers = "mcc999") + public void isAvailable_notVisible_false() { + assertThat(mController.isAvailable()).isFalse(); + } + + @Test + @Config(qualifiers = "mcc999") + public void isAvailable_notVisible_butNotDetailPage_true() { + mController = new EncryptionStatusPreferenceController(mContext, + PREF_KEY_ENCRYPTION_SECURITY_PAGE); + + UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); + Shadows.shadowOf(userManager).setIsAdminUser(true); + assertThat(mController.isAvailable()).isTrue(); + } + @Test public void updateSummary_encrypted_shouldSayEncrypted() { ShadowLockPatternUtils.setDeviceEncryptionEnabled(true); From a53001dd139182cca867e06f5b7185670ca8d73f Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Wed, 7 Mar 2018 15:24:37 -0800 Subject: [PATCH 5/9] Introduce boolean flag to show/hide Reset Options. This adds one new flag: config_show_reset_dashboard Which when set to false, will hide Reset Options from System settings. Bug: 74127210 Test: Updated robotests Change-Id: I42b14a0abde575f5c4e51985125e8543716d206a (cherry picked from commit bd180a62ec597dbcc205ff55395851769cdbe730) --- res/values/bools.xml | 3 + res/xml/system_dashboard_fragment.xml | 3 +- .../system/ResetPreferenceController.java | 35 ++++++++++++ tests/robotests/res/values-mcc999/config.xml | 1 + .../system/ResetPreferenceControllerTest.java | 56 +++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/com/android/settings/system/ResetPreferenceController.java create mode 100644 tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java diff --git a/res/values/bools.xml b/res/values/bools.xml index 4665f2eaed9..8b0c5984e95 100644 --- a/res/values/bools.xml +++ b/res/values/bools.xml @@ -153,6 +153,9 @@ true + + true + true diff --git a/res/xml/system_dashboard_fragment.xml b/res/xml/system_dashboard_fragment.xml index d8459dd3c9f..c3f15b99ff5 100644 --- a/res/xml/system_dashboard_fragment.xml +++ b/res/xml/system_dashboard_fragment.xml @@ -46,7 +46,8 @@ android:summary="@string/reset_dashboard_summary" android:icon="@drawable/ic_restore" android:order="-50" - android:fragment="com.android.settings.system.ResetDashboardFragment" /> + android:fragment="com.android.settings.system.ResetDashboardFragment" + settings:controller="com.android.settings.system.ResetPreferenceController"/> false false false + false false false false diff --git a/tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java new file mode 100644 index 00000000000..3869903c887 --- /dev/null +++ b/tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2016 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.system; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; + +import com.android.settings.testutils.SettingsRobolectricTestRunner; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +@RunWith(SettingsRobolectricTestRunner.class) +public class ResetPreferenceControllerTest { + + private static final String KEY_RESET_DASHBOARD = "reset_dashboard"; + + private Context mContext; + private ResetPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mController = new ResetPreferenceController(mContext, KEY_RESET_DASHBOARD); + } + + @Test + public void isAvailable_byDefault_true() { + assertThat(mController.isAvailable()).isTrue(); + } + + @Test + @Config(qualifiers = "mcc999") + public void isAvailable_ifNotVisible_false() { + assertThat(mController.isAvailable()).isFalse(); + } +} \ No newline at end of file From 7b6422ee06991d44f52084cc286bf728a973028a Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 12 Mar 2018 10:08:19 -0400 Subject: [PATCH 6/9] Fix tests Test: make -j20 RunSettingsRoboTests Change-Id: I40fda22b4a9da3df7f4319bc68a78d291c1b943d Fixes: 74446970 --- src/com/android/settings/core/gateway/SettingsGateway.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java index f9c78479c16..0cbc5395de7 100644 --- a/src/com/android/settings/core/gateway/SettingsGateway.java +++ b/src/com/android/settings/core/gateway/SettingsGateway.java @@ -105,6 +105,7 @@ import com.android.settings.notification.SoundSettings; import com.android.settings.notification.ZenAccessSettings; import com.android.settings.notification.ZenModeAutomationSettings; import com.android.settings.notification.ZenModeBehaviorSettings; +import com.android.settings.notification.ZenModeBlockedEffectsSettings; import com.android.settings.notification.ZenModeEventRuleSettings; import com.android.settings.notification.ZenModeScheduleRuleSettings; import com.android.settings.notification.ZenModeSettings; @@ -220,6 +221,7 @@ public class SettingsGateway { ZenModeBehaviorSettings.class.getName(), ZenModeScheduleRuleSettings.class.getName(), ZenModeEventRuleSettings.class.getName(), + ZenModeBlockedEffectsSettings.class.getName(), ProcessStatsUi.class.getName(), AdvancedPowerUsageDetail.class.getName(), ProcessStatsSummary.class.getName(), From 3f3c8acce75e6cfdd4131930a51a229253ebaecb Mon Sep 17 00:00:00 2001 From: Beverly Date: Mon, 26 Feb 2018 09:19:41 -0500 Subject: [PATCH 7/9] Adding zen duration preference Test: make ROBOTEST_FILTER=ZenModeDurationPreferenceControllerTest RunSettingsRoboTests -j40 Bug: 73741459 Change-Id: I55a75897045ef059dc872bf6403a62f46cedc417 --- res/values/strings.xml | 18 +++ res/xml/zen_mode_settings.xml | 5 + .../AbstractZenModePreferenceController.java | 15 ++- .../SettingsZenDurationDialog.java | 37 ++++++ ...ZenModeAutomationPreferenceController.java | 16 +++ .../settings/notification/ZenModeBackend.java | 12 +- .../ZenModeBehaviorPreferenceController.java | 16 +++ .../ZenModeButtonPreferenceController.java | 30 ++++- .../ZenModeDurationPreferenceController.java | 86 ++++++++++++++ .../notification/ZenModeSettings.java | 3 + ...nModeDurationPreferenceControllerTest.java | 111 ++++++++++++++++++ 11 files changed, 341 insertions(+), 8 deletions(-) create mode 100644 src/com/android/settings/notification/SettingsZenDurationDialog.java create mode 100644 src/com/android/settings/notification/ZenModeDurationPreferenceController.java create mode 100644 tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index ab8c0111230..c84853f8b4f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -6917,6 +6917,9 @@ Exceptions + + Duration + Allow sounds and vibrations from @@ -7038,6 +7041,21 @@ On + + Ask every time (unless turned on automatically) + + + Until you turn off (unless turned on automatically) + + + + 1 hour (unless turned on automatically) + %d hours (unless turned on automatically) + + + + %d minutes (unless turned on automatically) + 1 rule can turn on automatically diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml index 1f863c20b13..65fb7ab94ad 100644 --- a/res/xml/zen_mode_settings.xml +++ b/res/xml/zen_mode_settings.xml @@ -31,6 +31,11 @@ android:title="@string/zen_mode_behavior_settings_title" android:fragment="com.android.settings.notification.ZenModeBehaviorSettings" /> + + + - new SettingsEnableZenModeDialog().show(mFragment, TAG)); + updateZenButtonOnClickListener(); } if (null == mZenButtonOff) { @@ -89,7 +88,34 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference case Settings.Global.ZEN_MODE_OFF: default: mZenButtonOff.setVisibility(View.GONE); + updateZenButtonOnClickListener(); mZenButtonOn.setVisibility(View.VISIBLE); } } + + private void updateZenButtonOnClickListener() { + int zenDuration = getZenDuration(); + switch (zenDuration) { + case Settings.Global.ZEN_DURATION_PROMPT: + mZenButtonOn.setOnClickListener(v -> { + mMetricsFeatureProvider.action(mContext, + MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false); + new SettingsEnableZenModeDialog().show(mFragment, TAG); + }); + break; + case Settings.Global.ZEN_DURATION_FOREVER: + mZenButtonOn.setOnClickListener(v -> { + mMetricsFeatureProvider.action(mContext, + MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false); + mBackend.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS); + }); + break; + default: + mZenButtonOn.setOnClickListener(v -> { + mMetricsFeatureProvider.action(mContext, + MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false); + mBackend.setZenModeForDuration(zenDuration); + }); + } + } } \ No newline at end of file diff --git a/src/com/android/settings/notification/ZenModeDurationPreferenceController.java b/src/com/android/settings/notification/ZenModeDurationPreferenceController.java new file mode 100644 index 00000000000..0cd0eb3d1b6 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeDurationPreferenceController.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2018 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.notification; + +import android.app.FragmentManager; +import android.content.Context; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.R; +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.core.lifecycle.Lifecycle; + +public class ZenModeDurationPreferenceController extends AbstractZenModePreferenceController + implements PreferenceControllerMixin, Preference.OnPreferenceClickListener { + + private static final String TAG = "ZenModeDurationDialog"; + protected static final String KEY = "zen_mode_duration_settings"; + private FragmentManager mFragment; + + public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle, FragmentManager + fragment) { + super(context, KEY, lifecycle); + mFragment = fragment; + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public String getPreferenceKey() { + return KEY; + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + screen.findPreference(KEY).setOnPreferenceClickListener(this); + } + + @Override + public void updateState(Preference preference) { + super.updateState(preference); + + String summary = ""; + int zenDuration = getZenDuration(); + if (zenDuration < 0) { + summary = mContext.getString(R.string.zen_mode_duration_summary_always_prompt); + } else if (zenDuration == 0) { + summary = mContext.getString(R.string.zen_mode_duration_summary_forever); + } else { + if (zenDuration >= 60) { + int hours = zenDuration / 60; + summary = mContext.getResources().getQuantityString( + R.plurals.zen_mode_duration_summary_time_hours, hours, hours); + } else { + summary = mContext.getResources().getString( + R.string.zen_mode_duration_summary_time_minutes, zenDuration); + } + } + + preference.setSummary(summary); + } + + @Override + public boolean onPreferenceClick(Preference preference) { + new SettingsZenDurationDialog().show(mFragment, TAG); + return true; + } +} \ No newline at end of file diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java index 557d6248960..b143b424496 100644 --- a/src/com/android/settings/notification/ZenModeSettings.java +++ b/src/com/android/settings/notification/ZenModeSettings.java @@ -65,6 +65,8 @@ public class ZenModeSettings extends ZenModeSettingsBase { List controllers = new ArrayList<>(); controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle)); controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle)); + controllers.add(new ZenModeDurationPreferenceController(context, lifecycle, + fragmentManager)); controllers.add(new ZenModeAutomationPreferenceController(context)); controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager)); controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle)); @@ -250,6 +252,7 @@ public class ZenModeSettings extends ZenModeSettingsBase { @Override public List getNonIndexableKeys(Context context) { List keys = super.getNonIndexableKeys(context); + keys.add(ZenModeDurationPreferenceController.KEY); keys.add(ZenModeButtonPreferenceController.KEY); return keys; } diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java new file mode 100644 index 00000000000..9a94e6c18a7 --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2018 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.notification; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.app.FragmentManager; +import android.app.NotificationManager; +import android.content.ContentResolver; +import android.content.Context; +import android.provider.Settings; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.R; +import com.android.settings.testutils.SettingsRobolectricTestRunner; +import com.android.settingslib.core.lifecycle.Lifecycle; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; +import org.robolectric.util.ReflectionHelpers; + +@RunWith(SettingsRobolectricTestRunner.class) +public class ZenModeDurationPreferenceControllerTest { + private ZenModeDurationPreferenceController mController; + + @Mock + private ZenModeBackend mBackend; + @Mock + private NotificationManager mNotificationManager; + @Mock + private Preference mockPref; + @Mock + private NotificationManager.Policy mPolicy; + @Mock + private PreferenceScreen mPreferenceScreen; + private ContentResolver mContentResolver; + private Context mContext; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + ShadowApplication shadowApplication = ShadowApplication.getInstance(); + shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager); + + mContext = shadowApplication.getApplicationContext(); + mContentResolver = RuntimeEnvironment.application.getContentResolver(); + mController = new ZenModeDurationPreferenceController(mContext, mock(Lifecycle.class), + mock(FragmentManager.class)); + when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy); + ReflectionHelpers.setField(mController, "mBackend", mBackend); + when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn( + mockPref); + mController.displayPreference(mPreferenceScreen); + } + + @Test + public void updateState_DurationForever() { + Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, + Settings.Global.ZEN_DURATION_FOREVER); + final Preference mockPref = mock(Preference.class); + mController.updateState(mockPref); + + verify(mockPref).setSummary(mContext.getString(R.string.zen_mode_duration_summary_forever)); + } + + @Test + public void updateState_DurationPrompt() { + Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, + Settings.Global.ZEN_DURATION_PROMPT); + final Preference mockPref = mock(Preference.class); + mController.updateState(mockPref); + + verify(mockPref).setSummary(mContext.getString( + R.string.zen_mode_duration_summary_always_prompt)); + } + + @Test + public void updateState_DurationCustom() { + int zenDuration = 45; + Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, + zenDuration); + final Preference mockPref = mock(Preference.class); + mController.updateState(mockPref); + + verify(mockPref).setSummary(mContext.getResources().getString( + R.string.zen_mode_duration_summary_time_minutes, zenDuration)); + } +} \ No newline at end of file From 9de138b8abc1e67918ea22dd4154d5a852911842 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Fri, 9 Mar 2018 11:17:34 -0800 Subject: [PATCH 8/9] Update suggestion title and summary text. Bug: 73164111 Test: rebuild Change-Id: I35db24cd78e88091154e5cbcc9fa089181f3edb2 --- res/values/strings.xml | 63 ++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c64880eb818..752c960ba50 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1136,25 +1136,25 @@ - - Set screen lock for security + + Secure your phone - - Prevent others from using your tablet - - Prevent others from using your device - - Prevent others from using your phone + + Set screen lock to protect tablet + + Set screen lock to protect device + + Set screen lock to protect phone - + Unlock with fingerprint - - Unlock with your fingerprint - - Unlock with your fingerprint - - Unlock with your fingerprint + + + + + + Choose screen lock @@ -2251,10 +2251,10 @@ Wi-Fi calling - - Extend call coverage with Wi\u2011Fi - - Turn on Wi\u2011Fi calling + + Extend calls with Wi\u2011Fi + + Turn on Wi\u2011Fi calling to extend coverage Calling preference @@ -2532,9 +2532,9 @@ Default Custom - + Change wallpaper - + Personalize your screen Choose wallpaper from @@ -6945,10 +6945,10 @@ Automatic rule - + Silence phone at certain times - + Set Do Not Disturb rules @@ -8558,10 +8558,10 @@ Apps, background sync, and other features related to your work profile are turned off. - + Set Night Light schedule - + Automatically tint screen every night @@ -8769,10 +8769,10 @@ Require password to start up your device. While off, this device can\'t receive calls, messages, notifications, or alarms. - + Add another fingerprint - + Unlock with a different finger @@ -9453,4 +9453,13 @@ Unavailable + + Improve tablet\'s battery life + + Improve device\'s battery life + + Improve phone\'s battery life + + + From 9cc92cd90e43eda3e7e50df6f7be6950d7ee9ac5 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Mon, 12 Mar 2018 15:41:19 +0000 Subject: [PATCH 9/9] Align the search view with the setting items - Remove the margin and paddings in the search view Bug: 73952488 Test: m RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.datetime.timezone Change-Id: I67fb420cf77fc427a550449a053f80dcf66d16ff --- .../datetime/timezone/BaseTimeZonePicker.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java index f20a110f978..032e2d296ea 100644 --- a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java +++ b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java @@ -25,7 +25,9 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.SearchView; +import android.widget.TextView; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; @@ -130,6 +132,19 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment mSearchView.setActivated(true); mSearchView.setQuery("", true /* submit */); } + + // Set zero margin and padding to align with the text horizontally in the preference + final TextView searchViewView = (TextView) mSearchView.findViewById( + com.android.internal.R.id.search_src_text); + searchViewView.setPadding(0, searchViewView.getPaddingTop(), 0, + searchViewView.getPaddingBottom()); + final View editFrame = mSearchView.findViewById( + com.android.internal.R.id.search_edit_frame); + final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) editFrame + .getLayoutParams(); + params.setMarginStart(0); + params.setMarginEnd(0); + editFrame.setLayoutParams(params); } }