From 791b6fadc72bf47e23c6f944486ca05374e21bd7 Mon Sep 17 00:00:00 2001 From: Yu-Han Yang Date: Tue, 18 May 2021 15:59:37 -0700 Subject: [PATCH 01/12] Fix footer issues 1. setContentDescription for "learn more" 2. set searchable="false" Bug: 187471260 Bug: 188490701 Test: on device Change-Id: Iaa6907fdf2b6c47cbc1386a88a08ac31f3676367 --- res/values/strings.xml | 20 +++++++------- res/xml/location_settings.xml | 3 ++- res/xml/location_settings_personal.xml | 2 +- res/xml/location_settings_workprofile.xml | 2 +- ...ionSettingsFooterPreferenceController.java | 27 +++++++++++++------ 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index bf56cc41d11..76305ecdb9d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -685,24 +685,24 @@ Loading\u2026 - - <br><br>Apps with the Nearby devices permission can determine the + + Apps with the Nearby devices permission can determine the relative position of connected devices. - - <br><br><a href=" - https://support.google.com/android/answer/3467281">Learn more</a> Location access is off for apps and services. Your device location may still be sent to emergency responders when you call or text an emergency number. - - <br><br>Apps with the Nearby devices permission can determine the relative - position of connected devices. - - <br><br><a href=" + + + <a href=" https://support.google.com/android/answer/3467281">Learn more</a> + + + Learn more about Location Settings. + Accounts diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index 857885dee39..880a326a221 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -70,8 +70,9 @@ diff --git a/res/xml/location_settings_personal.xml b/res/xml/location_settings_personal.xml index 726a96c302a..bae1ac16db3 100644 --- a/res/xml/location_settings_personal.xml +++ b/res/xml/location_settings_personal.xml @@ -54,7 +54,7 @@ settings:controller="com.android.settings.location.LocationServicesPreferenceController"/> diff --git a/res/xml/location_settings_workprofile.xml b/res/xml/location_settings_workprofile.xml index 99ccf14bc70..51d8761bc4b 100644 --- a/res/xml/location_settings_workprofile.xml +++ b/res/xml/location_settings_workprofile.xml @@ -62,7 +62,7 @@ settings:controller="com.android.settings.location.LocationServicesForWorkPreferenceController"/> diff --git a/src/com/android/settings/location/LocationSettingsFooterPreferenceController.java b/src/com/android/settings/location/LocationSettingsFooterPreferenceController.java index d2d5c1ffa5b..281cc5abf9d 100644 --- a/src/com/android/settings/location/LocationSettingsFooterPreferenceController.java +++ b/src/com/android/settings/location/LocationSettingsFooterPreferenceController.java @@ -24,6 +24,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.location.LocationManager; import android.text.Html; +import android.text.TextUtils; import android.util.Log; import androidx.preference.Preference; @@ -42,6 +43,7 @@ import java.util.List; */ public class LocationSettingsFooterPreferenceController extends LocationBasePreferenceController { private static final String TAG = "LocationFooter"; + private static final String PARAGRAPH_SEPARATOR = "

"; private static final Intent INJECT_INTENT = new Intent(LocationManager.SETTINGS_FOOTER_DISPLAYED_ACTION); @@ -90,24 +92,33 @@ public class LocationSettingsFooterPreferenceController extends LocationBasePref } private void updateFooterPreference() { - String footerString = mContext.getString( - mLocationEnabled ? R.string.location_settings_footer_location_on - : R.string.location_settings_footer_location_off); + String footerString = mContext.getString(R.string.location_settings_footer_general); if (mLocationEnabled) { - footerString = mInjectedFooterString + footerString; + if (!TextUtils.isEmpty(mInjectedFooterString)) { + footerString = Html.escapeHtml(mInjectedFooterString) + PARAGRAPH_SEPARATOR + + footerString; + } + } else { + footerString = mContext.getString(R.string.location_settings_footer_location_off) + + PARAGRAPH_SEPARATOR + + footerString; } if (mFooterPreference != null) { - mFooterPreference.setTitle(Html.fromHtml(footerString)); + mFooterPreference.setTitle(Html.fromHtml(footerString + + PARAGRAPH_SEPARATOR + + mContext.getString( + R.string.location_settings_footer_learn_more))); + mFooterPreference.setContentDescription(Html.fromHtml(footerString + mContext.getString( + R.string.location_settings_footer_learn_more_content_description))); } } /** - * Location footer preference group should be displayed if there is at least one footer to - * inject. + * Location footer preference group should always be displayed. */ @Override public int getAvailabilityStatus() { - return !getFooterData().isEmpty() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return AVAILABLE; } /** From e6c11957b873370615b20851dbc918e77cd09de5 Mon Sep 17 00:00:00 2001 From: alexylli Date: Fri, 21 May 2021 11:44:57 +0800 Subject: [PATCH 02/12] [Settings] Adjusts the result code to cancel when complete redaction interstitial setting This change can make redaction interstitial can be setup repeatedly in anything else page. Test: manual Bug: 185430009 Change-Id: I7ed459ca3017286ab01bc8274704dd01fc50391d --- .../android/settings/notification/RedactionInterstitial.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java index c8d5ffd321c..d6cf0c60ecb 100644 --- a/src/com/android/settings/notification/RedactionInterstitial.java +++ b/src/com/android/settings/notification/RedactionInterstitial.java @@ -153,7 +153,7 @@ public class RedactionInterstitial extends SettingsActivity { } final RedactionInterstitial activity = (RedactionInterstitial) getActivity(); if (activity != null) { - activity.setResult(RESULT_OK, null); + activity.setResult(RESULT_CANCELED, null); finish(); } } From 964872ab96f0d53a0d5a19169a31128418af3964 Mon Sep 17 00:00:00 2001 From: ryanlwlin Date: Thu, 13 May 2021 14:01:29 +0800 Subject: [PATCH 03/12] Fix incorrect seperator while concatenating shortcuts We concatenate the selected shortcut with a comma that is not localized. To fix it we use listformatter to concatenate them. Bug: 186891004 Test: manually test with differnt languages. Change-Id: I2c6692facd457b434c56a0633e784ce771905b29 --- .../ToggleFeaturePreferenceFragment.java | 4 +- ...ScreenMagnificationPreferenceFragment.java | 4 +- .../android/settings/utils/LocaleUtils.java | 47 +++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/com/android/settings/utils/LocaleUtils.java diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java index c81bfb254c0..4b1725ffe63 100644 --- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java @@ -52,6 +52,7 @@ import com.android.settings.SettingsActivity; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.accessibility.AccessibilityEditDialogUtils.DialogType; import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; +import com.android.settings.utils.LocaleUtils; import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settings.widget.SettingsMainSwitchPreference; import com.android.settingslib.accessibility.AccessibilityUtils; @@ -659,10 +660,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference if (list.isEmpty()) { list.add(softwareTitle); } - final String joinStrings = TextUtils.join(/* delimiter= */", ", list); return CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(), /* iter= */ - null, joinStrings); + null, LocaleUtils.getConcatenatedString(list)); } /** diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index cb0d964a833..57fd7ea9918 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -46,6 +46,7 @@ import com.android.settings.DialogCreatable; import com.android.settings.R; import com.android.settings.accessibility.AccessibilityEditDialogUtils.DialogType; import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; +import com.android.settings.utils.LocaleUtils; import com.google.android.setupcompat.util.WizardManagerHelper; @@ -282,10 +283,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends if (list.isEmpty()) { list.add(softwareTitle); } - final String joinStrings = TextUtils.join(/* delimiter= */", ", list); return CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(), /* iter= */ - null, joinStrings); + null, LocaleUtils.getConcatenatedString(list)); } @Override diff --git a/src/com/android/settings/utils/LocaleUtils.java b/src/com/android/settings/utils/LocaleUtils.java new file mode 100644 index 00000000000..8fab344829a --- /dev/null +++ b/src/com/android/settings/utils/LocaleUtils.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 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.utils; + +import android.icu.text.ListFormatter; +import android.text.TextUtils; + +import java.util.List; +import java.util.Locale; + +/** + * This class implements some common methods to process with locales + */ +public class LocaleUtils { + + /** + * Returns a character sequence concatenating the items with the localized comma. + * + * @param items items to be concatenated + */ + public static CharSequence getConcatenatedString(List items) { + final ListFormatter listFormatter = ListFormatter.getInstance(Locale.getDefault()); + final CharSequence lastItem = items.get(items.size() - 1); + items.add("fake last item"); + + // For English with "{0}, {1}, and {2}", the pattern is "{0}, {1}, and {2}". + // To get "{0}, {1}, {2}", we add a {fake item}, then the pattern result would be + // "{0}, {1}, {2} and {fake item}", then get the substring with the end index of the + // last item. + final String formatted = listFormatter.format(items); + return formatted.subSequence(0, TextUtils.indexOf(formatted, lastItem) + lastItem.length()); + } +} From 8267a2757f23b736b72e4bb7c87618aa922f38ac Mon Sep 17 00:00:00 2001 From: changbetty Date: Thu, 13 May 2021 17:12:38 +0800 Subject: [PATCH 04/12] Remove the Network rating provider item Bug: 187119482 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=ConfigureWifiSettingsTest Change-Id: Iff4a7663c0bca8f0553fcd16673a9aa766050ff4 --- res/xml/wifi_configure_settings.xml | 6 - .../settings/network/NetworkScorerPicker.java | 145 ------------ ...tworkScorerPickerPreferenceController.java | 67 ------ .../network/NetworkScorerPickerTest.java | 206 ------------------ ...kScorerPickerPreferenceControllerTest.java | 148 ------------- 5 files changed, 572 deletions(-) delete mode 100644 src/com/android/settings/network/NetworkScorerPicker.java delete mode 100644 src/com/android/settings/network/NetworkScorerPickerPreferenceController.java delete mode 100644 tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java delete mode 100644 tests/unit/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml index cc281fa8768..4a67deb486c 100644 --- a/res/xml/wifi_configure_settings.xml +++ b/res/xml/wifi_configure_settings.xml @@ -59,12 +59,6 @@ - - scorers = mNetworkScoreManager.getAllValidScorers(); - final String defaultAppKey = getActiveScorerPackage(); - - final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext()); - nonePref.setTitle(R.string.network_scorer_picker_none_preference); - if (scorers.isEmpty()) { - nonePref.setChecked(true); - } else { - nonePref.setKey(null); - nonePref.setChecked(TextUtils.isEmpty(defaultAppKey)); - nonePref.setOnClickListener(this); - } - screen.addPreference(nonePref); - - final int numScorers = scorers.size(); - for (int i = 0; i < numScorers; i++) { - final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext()); - final NetworkScorerAppData appData = scorers.get(i); - final String appKey = appData.getRecommendationServicePackageName(); - pref.setTitle(appData.getRecommendationServiceLabel()); - pref.setKey(appKey); - pref.setChecked(TextUtils.equals(defaultAppKey, appKey)); - pref.setOnClickListener(this); - screen.addPreference(pref); - } - } - - private String getActiveScorerPackage() { - return mNetworkScoreManager.getActiveScorerPackage(); - } - - private boolean setActiveScorer(String key) { - if (!TextUtils.equals(key, getActiveScorerPackage())) { - return mNetworkScoreManager.setActiveScorer(key); - } - return false; - } - - @Override - public void onRadioButtonClicked(RadioButtonPreference selected) { - final String selectedKey = selected.getKey(); - final boolean success = setActiveScorer(selectedKey); - if (success) { - updateCheckedState(selectedKey); - } - } - - private void updateCheckedState(String selectedKey) { - final PreferenceScreen screen = getPreferenceScreen(); - final int count = screen.getPreferenceCount(); - for (int i = 0; i < count; i++) { - final Preference pref = screen.getPreference(i); - if (pref instanceof RadioButtonPreference) { - final RadioButtonPreference radioPref = (RadioButtonPreference) pref; - radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey)); - } - } - } - - @VisibleForTesting - NetworkScoreManager createNetworkScorerManager(Context context) { - return (NetworkScoreManager) context.getSystemService(Context.NETWORK_SCORE_SERVICE); - } -} diff --git a/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java b/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java deleted file mode 100644 index 4b452c01c15..00000000000 --- a/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.network; - -import android.content.Context; -import android.net.NetworkScoreManager; -import android.net.NetworkScorerAppData; - -import androidx.preference.Preference; - -import com.android.settings.R; -import com.android.settings.core.BasePreferenceController; - -import java.util.List; - -/** - * {@link AbstractPreferenceController} that shows the active network scorer and toggles the - * preference based on whether or not there are valid scorers installed. - */ -public class NetworkScorerPickerPreferenceController extends BasePreferenceController { - - private final NetworkScoreManager mNetworkScoreManager; - - public NetworkScorerPickerPreferenceController(Context context, String key) { - super(context, key); - mNetworkScoreManager = - (NetworkScoreManager) mContext.getSystemService(Context.NETWORK_SCORE_SERVICE); - } - - @Override - public int getAvailabilityStatus() { - return AVAILABLE; - } - - @Override - public void updateState(Preference preference) { - final List allValidScorers = - mNetworkScoreManager.getAllValidScorers(); - boolean enabled = !allValidScorers.isEmpty(); - preference.setEnabled(enabled); - if (!enabled) { - preference.setSummary(null); - return; - } - - NetworkScorerAppData scorer = mNetworkScoreManager.getActiveScorer(); - if (scorer == null) { - preference.setSummary(mContext.getString( - R.string.network_scorer_picker_none_preference)); - } else { - preference.setSummary(scorer.getRecommendationServiceLabel()); - } - } -} diff --git a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java deleted file mode 100644 index c4e953c7acc..00000000000 --- a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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.network; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.content.ComponentName; -import android.content.Context; -import android.net.NetworkScoreManager; -import android.net.NetworkScorerAppData; - -import androidx.preference.PreferenceManager; -import androidx.preference.PreferenceScreen; - -import com.android.settings.R; -import com.android.settingslib.widget.RadioButtonPreference; - -import com.google.android.collect.Lists; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -import java.util.ArrayList; - -@RunWith(RobolectricTestRunner.class) -public class NetworkScorerPickerTest { - - private static final String TEST_SCORER_PACKAGE_1 = "Test Package 1"; - private static final String TEST_SCORER_CLASS_1 = "Test Class 1"; - private static final String TEST_SCORER_LABEL_1 = "Test Label 1"; - private static final String TEST_SCORER_PACKAGE_2 = "Test Package 2"; - - private Context mContext; - @Mock - private NetworkScoreManager mNetworkScoreManager; - @Mock - private PreferenceScreen mPreferenceScreen; - - private TestFragment mFragment; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; - mFragment = new TestFragment(mContext, mPreferenceScreen, mNetworkScoreManager); - mFragment.onAttach(mContext); - } - - @Test - public void testOnRadioButtonClicked_success() { - RadioButtonPreference pref = new RadioButtonPreference(mContext); - pref.setKey(TEST_SCORER_PACKAGE_1); - when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref); - when(mPreferenceScreen.getPreferenceCount()).thenReturn(1); - when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true); - when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_2); - - mFragment.onRadioButtonClicked(pref); - - verify(mNetworkScoreManager).setActiveScorer(TEST_SCORER_PACKAGE_1); - assertThat(pref.isChecked()).isTrue(); - } - - @Test - public void testOnRadioButtonClicked_currentScorer_doNothing() { - RadioButtonPreference pref = new RadioButtonPreference(mContext); - pref.setKey(TEST_SCORER_PACKAGE_1); - pref.setChecked(true); - when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref); - when(mPreferenceScreen.getPreferenceCount()).thenReturn(1); - when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true); - when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1); - - mFragment.onRadioButtonClicked(pref); - - verify(mNetworkScoreManager, never()).setActiveScorer(any()); - assertThat(pref.isChecked()).isTrue(); - } - - @Test - public void testUpdateCandidates_noValidScorers_nonePreference() { - when(mNetworkScoreManager.getAllValidScorers()).thenReturn(new ArrayList<>()); - ArgumentCaptor arg = - ArgumentCaptor.forClass(RadioButtonPreference.class); - - mFragment.updateCandidates(); - - verify(mPreferenceScreen).addPreference(arg.capture()); - assertThat(arg.getValue().getTitle()) - .isEqualTo(mContext.getString(R.string.network_scorer_picker_none_preference)); - assertThat(arg.getValue().isChecked()).isTrue(); - } - - @Test - public void testUpdateCandidates_validScorers_noActiveScorer() { - ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE_1, TEST_SCORER_CLASS_1); - NetworkScorerAppData scorerAppData = new NetworkScorerAppData( - 0, scorer, TEST_SCORER_LABEL_1, null /* enableUseOpenWifiActivity */, - null /* networkAvailableNotificationChannelId */); - when(mNetworkScoreManager.getAllValidScorers()).thenReturn( - Lists.newArrayList(scorerAppData)); - when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(null); - - ArgumentCaptor arg = - ArgumentCaptor.forClass(RadioButtonPreference.class); - - mFragment.updateCandidates(); - - verify(mPreferenceScreen, times(2)).addPreference(arg.capture()); - - final RadioButtonPreference nonePref = arg.getAllValues().get(0); - assertThat(nonePref.getKey()).isNull(); - assertThat(nonePref.isChecked()).isTrue(); - - final RadioButtonPreference testScorerPref = arg.getAllValues().get(1); - assertThat(testScorerPref.getTitle()).isEqualTo(TEST_SCORER_LABEL_1); - assertThat(testScorerPref.isChecked()).isFalse(); - } - - @Test - public void testUpdateCandidates_validScorer() { - ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE_1, TEST_SCORER_CLASS_1); - NetworkScorerAppData scorerAppData = new NetworkScorerAppData( - 0, scorer, TEST_SCORER_LABEL_1, null /* enableUseOpenWifiActivity */, - null /* networkAvailableNotificationChannelId */); - when(mNetworkScoreManager.getAllValidScorers()).thenReturn( - Lists.newArrayList(scorerAppData)); - when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1); - ArgumentCaptor arg = - ArgumentCaptor.forClass(RadioButtonPreference.class); - - mFragment.updateCandidates(); - - // The first preference added is the "none" preference and the second is the - // pref for the test scorer. - verify(mPreferenceScreen, times(2)).addPreference(arg.capture()); - // Returns the last captured value which is expected to be the test scorer pref. - RadioButtonPreference pref = arg.getValue(); - assertThat(pref.getTitle()).isEqualTo(TEST_SCORER_LABEL_1); - assertThat(pref.isChecked()).isTrue(); - } - - public static class TestFragment extends NetworkScorerPicker { - - private final Context mContext; - private final PreferenceScreen mScreen; - private final PreferenceManager mPrefManager; - private final NetworkScoreManager mNetworkScoreManager; - - public TestFragment(Context context, PreferenceScreen preferenceScreen, - NetworkScoreManager networkScoreManager) { - mContext = context; - mScreen = preferenceScreen; - mNetworkScoreManager = networkScoreManager; - mPrefManager = mock(PreferenceManager.class); - when(mPrefManager.getContext()).thenReturn(context); - } - - @Override - public Context getContext() { - return mContext; - } - - @Override - public PreferenceManager getPreferenceManager() { - return mPrefManager; - } - - @Override - public PreferenceScreen getPreferenceScreen() { - return mScreen; - } - - @Override - NetworkScoreManager createNetworkScorerManager(Context context) { - return mNetworkScoreManager; - } - } -} diff --git a/tests/unit/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java deleted file mode 100644 index 542d2ff5d21..00000000000 --- a/tests/unit/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2020 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.network; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.content.ComponentName; -import android.content.Context; -import android.net.NetworkScoreManager; -import android.net.NetworkScorerAppData; - -import androidx.preference.Preference; -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.util.Collections; - -@RunWith(AndroidJUnit4.class) -public class NetworkScorerPickerPreferenceControllerTest { - - private static final String TEST_SCORER_PACKAGE = "Test Package"; - private static final String TEST_SCORER_CLASS = "Test Class"; - private static final String TEST_SCORER_LABEL = "Test Label"; - - private Context mContext; - @Mock - private NetworkScoreManager mNetworkScorer; - - private NetworkScorerPickerPreferenceController mController; - - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mContext = spy(ApplicationProvider.getApplicationContext()); - doReturn(mNetworkScorer).when(mContext).getSystemService(Context.NETWORK_SCORE_SERVICE); - - mController = new NetworkScorerPickerPreferenceController(mContext, "test_key"); - } - - @Test - public void testIsAvailable_shouldAlwaysReturnTrue() { - assertThat(mController.isAvailable()).isTrue(); - } - - @Test - public void updateState_preferenceSetSummaryAsActiveScorerLabel() { - - ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE, TEST_SCORER_CLASS); - - NetworkScorerAppData scorerAppData = new NetworkScorerAppData( - 0, scorer, TEST_SCORER_LABEL, null /* enableUseOpenWifiActivity */, - null /* networkAvailableNotificationChannelId */); - - when(mNetworkScorer.getAllValidScorers()) - .thenReturn(Collections.singletonList(scorerAppData)); - - when(mNetworkScorer.getActiveScorer()).thenReturn(scorerAppData); - - Preference preference = mock(Preference.class); - - mController.updateState(preference); - - verify(preference).setSummary(TEST_SCORER_LABEL); - } - - @Test - public void updateState_scorersAvailable_noActiveScorer_preferenceSetSummaryToNone() { - ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE, TEST_SCORER_CLASS); - NetworkScorerAppData scorerAppData = new NetworkScorerAppData( - 0, scorer, TEST_SCORER_LABEL, null /* enableUseOpenWifiActivity */, - null /* networkAvailableNotificationChannelId */); - when(mNetworkScorer.getAllValidScorers()) - .thenReturn(Collections.singletonList(scorerAppData)); - when(mNetworkScorer.getActiveScorer()).thenReturn(null); - - Preference preference = mock(Preference.class); - - mController.updateState(preference); - - Context context = ApplicationProvider.getApplicationContext(); - - verify(preference).setSummary( - resourceString("network_scorer_picker_none_preference")); - } - - @Test - public void updateState_scorersAvailable_preferenceEnabled() { - ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE, TEST_SCORER_CLASS); - NetworkScorerAppData scorerAppData = new NetworkScorerAppData( - 0, scorer, TEST_SCORER_LABEL, null /* enableUseOpenWifiActivity */, - null /* networkAvailableNotificationChannelId */); - when(mNetworkScorer.getAllValidScorers()) - .thenReturn(Collections.singletonList(scorerAppData)); - - Preference preference = mock(Preference.class); - - mController.updateState(preference); - - verify(preference).setEnabled(true); - } - - @Test - public void updateState_noScorersAvailable_preferenceDisabled() { - when(mNetworkScorer.getAllValidScorers()) - .thenReturn(Collections.emptyList()); - Preference preference = mock(Preference.class); - - mController.updateState(preference); - - verify(preference).setEnabled(false); - verify(preference).setSummary(null); - } - - public int resourceId(String type, String name) { - return mContext.getResources().getIdentifier(name, type, mContext.getPackageName()); - } - - public String resourceString(String name) { - return mContext.getResources().getString(resourceId("string", name)); - } -} From 8dfa74f6b8df816169eed80934304da749eff992 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Sat, 22 May 2021 01:46:39 +0800 Subject: [PATCH 05/12] Remove redundant learn more link Fix: 188579822 Test: visual verified Change-Id: If542976f8d04db5e3bab13da248c555caf75638f --- .../fingerprint_enroll_introduction.xml | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/res/layout/fingerprint_enroll_introduction.xml b/res/layout/fingerprint_enroll_introduction.xml index 03a8e7f3010..f556f274114 100644 --- a/res/layout/fingerprint_enroll_introduction.xml +++ b/res/layout/fingerprint_enroll_introduction.xml @@ -133,26 +133,6 @@ android:text="@string/security_settings_fingerprint_v2_enroll_introduction_footer_message_4" /> - - - - - - - From de88f5244ca0951d675a1be2c9d5cd7b6efda297 Mon Sep 17 00:00:00 2001 From: Edgar Wang Date: Sat, 22 May 2021 03:13:14 +0800 Subject: [PATCH 06/12] Update Policy transparency dialog to new style - Tweak layout - Update app icon - Update font Size Bug: 188756125 Test: manual Change-Id: I7ddd73c80ead95d57202d1753408b437611a76b4 --- res/layout/admin_support_details_dialog.xml | 69 +++++++++++-------- res/values/dimens.xml | 5 +- res/values/styles.xml | 11 +++ .../ActionDisabledByAdminDialogHelper.java | 22 +----- 4 files changed, 55 insertions(+), 52 deletions(-) diff --git a/res/layout/admin_support_details_dialog.xml b/res/layout/admin_support_details_dialog.xml index 298cf24e196..0233a1b4694 100644 --- a/res/layout/admin_support_details_dialog.xml +++ b/res/layout/admin_support_details_dialog.xml @@ -13,45 +13,54 @@ See the License for the specific language governing permissions and limitations under the License. --> - + + + - - + android:layout_marginTop="16dp" + android:gravity="center_horizontal" + android:text="@string/disabled_by_policy_title" + android:textAppearance="@style/TextAppearance.AdminDialogTitle"/> + - + - + android:textAppearance="@style/TextAppearance.AdminDialogMessage" + android:maxLength="200" + android:gravity="center_horizontal" + android:autoLink="email|phone|web" + android:textColor="?android:attr/textColorSecondary"/> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index a9cda9e75ac..168480ea856 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -262,8 +262,9 @@ 24dp - 20dp - 48dp + 32dp + 16dp + 32dp 36dp 24dp 8dp diff --git a/res/values/styles.xml b/res/values/styles.xml index c72b3a513ff..a5b187bf94e 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -871,4 +871,15 @@ 16sp ?android:attr/textColorSecondary + + + + diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java index 86ffa47fa54..2a5eda217a6 100644 --- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java +++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java @@ -22,12 +22,8 @@ import android.app.Activity; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; -import android.content.res.ColorStateList; -import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; import android.os.Process; import android.os.UserHandle; -import android.util.IconDrawableFactory; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -38,7 +34,6 @@ import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.AlertDialog; import com.android.settings.R; -import com.android.settings.Utils; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import com.android.settingslib.RestrictedLockUtilsInternal; @@ -143,21 +138,8 @@ public class ActionDisabledByAdminDialogHelper { @VisibleForTesting void setAdminSupportIcon(View root, ComponentName admin, int userId) { ImageView supportIconView = root.requireViewById(R.id.admin_support_icon); - if (isNotCurrentUserOrProfile(admin, userId)) { - supportIconView.setImageDrawable( - mActivity.getDrawable(com.android.internal.R.drawable.ic_info)); - - TypedArray ta = mActivity.obtainStyledAttributes(new int[]{android.R.attr.colorAccent}); - supportIconView.setImageTintList(ColorStateList.valueOf(ta.getColor(0, 0))); - ta.recycle(); - } else { - final Drawable badgedIcon = Utils.getBadgedIcon( - IconDrawableFactory.newInstance(mActivity), - mActivity.getPackageManager(), - admin.getPackageName(), - userId); - supportIconView.setImageDrawable(badgedIcon); - } + supportIconView.setImageDrawable( + mActivity.getDrawable(com.android.internal.R.drawable.ic_corp_badge)); } @VisibleForTesting From 4d41945d77b4e3cf88bdc87a84e794e1551a4fa6 Mon Sep 17 00:00:00 2001 From: Tim Peng Date: Sat, 22 May 2021 14:25:56 +0800 Subject: [PATCH 07/12] [Rohan] fix test failing for AdvancedBluetoothDetailsHeaderControllerTest -design changes and no battery icon Bug: 188727945 bug: 188498118 Test: make -j50 RunSettingsRoboTests ROBOTEST_FILTER=AdvancedBluetoothDetailsHeaderControllerTest Change-Id: Ic5ebb3b5c06180090d54cd436c88c0bebe0d79f5 --- ...dBluetoothDetailsHeaderControllerTest.java | 61 ++----------------- 1 file changed, 6 insertions(+), 55 deletions(-) diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java index 5350d45e436..5a44c7940ce 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java @@ -68,6 +68,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest { private static final int BATTERY_LEVEL_50 = 50; private static final String ICON_URI = "content://test.provider/icon.png"; private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C"; + private static final String DEVICE_SUMMARY = "test summary"; private Context mContext; @@ -133,7 +134,6 @@ public class AdvancedBluetoothDetailsHeaderControllerTest { View.GONE); assertThat(mLayoutPreference.findViewById(R.id.layout_middle).getVisibility()).isEqualTo( View.VISIBLE); - assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN); } @Test @@ -232,67 +232,18 @@ public class AdvancedBluetoothDetailsHeaderControllerTest { } @Test - public void refresh_underLowBatteryThreshold_showAlertIcon() { + public void refresh_connectedWatch_checkSummary() { when(mBluetoothDevice.getMetadata( BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_BATTERY)).thenReturn( - String.valueOf(BATTERY_LEVEL_5).getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_LOW_BATTERY_THRESHOLD)).thenReturn( - String.valueOf(LOW_BATTERY_LEVEL_THRESHOLD).getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_CHARGING)).thenReturn( - String.valueOf(false).getBytes()); when(mCachedDevice.isConnected()).thenReturn(true); + when(mCachedDevice.getConnectionSummary(/* shortSummary= */ true)) + .thenReturn(DEVICE_SUMMARY); mController.refresh(); - assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_middle), - R.drawable.ic_battery_alert_24dp); - } - - @Test - public void refresh_underLowBatteryThresholdInCharging_showAlertIcon() { - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( - BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_BATTERY)).thenReturn( - String.valueOf(BATTERY_LEVEL_5).getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_LOW_BATTERY_THRESHOLD)).thenReturn( - String.valueOf(LOW_BATTERY_LEVEL_THRESHOLD).getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_CHARGING)).thenReturn( - String.valueOf(true).getBytes()); - when(mCachedDevice.isConnected()).thenReturn(true); - - mController.refresh(); - - assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_middle), /* resId= */-1); - } - - @Test - public void refresh_aboveLowBatteryThreshold_noAlertIcon() { - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( - BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_BATTERY)).thenReturn( - String.valueOf(BATTERY_LEVEL_50).getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_LOW_BATTERY_THRESHOLD)).thenReturn( - String.valueOf(LOW_BATTERY_LEVEL_THRESHOLD).getBytes()); - when(mBluetoothDevice.getMetadata( - BluetoothDevice.METADATA_MAIN_CHARGING)).thenReturn( - String.valueOf(false).getBytes()); - when(mCachedDevice.isConnected()).thenReturn(true); - - mController.refresh(); - - assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_middle), /* resId= */-1); + assertThat(((TextView) (mLayoutPreference.findViewById(R.id.entity_header_summary))) + .getText()).isEqualTo(DEVICE_SUMMARY); } @Test From 4b1d1e21d5cf6433c248f1d8565c73c93c3d7989 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Mon, 24 May 2021 10:13:53 +0800 Subject: [PATCH 08/12] Align the items in account sync page to the start border The prefernces haven't been applied to the SettingsLib preference theme which sets iconSpaceReserved false. Fixes: 187670431 Test: visual, robotest Change-Id: Ifa797fbec4f207248fd0254e26d456b8889e25d8 --- res/values/styles_preference.xml | 2 +- .../android/settings/accounts/AccountTypePreferenceLoader.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/res/values/styles_preference.xml b/res/values/styles_preference.xml index 42ed0e989e9..2c4b03756f4 100644 --- a/res/values/styles_preference.xml +++ b/res/values/styles_preference.xml @@ -48,7 +48,7 @@ @layout/preference_widget_seekbar_settings - diff --git a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java index c639d1df2eb..42bb34a0ee4 100644 --- a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java +++ b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java @@ -58,7 +58,6 @@ public class AccountTypePreferenceLoader { private static final String LAUNCHING_LOCATION_SETTINGS = "com.android.settings.accounts.LAUNCHING_LOCATION_SETTINGS"; - private AuthenticatorHelper mAuthenticatorHelper; private UserHandle mUserHandle; private PreferenceFragmentCompat mFragment; From 3ad391b0de34519cb4d501c9e118fc80d516a258 Mon Sep 17 00:00:00 2001 From: ykhung Date: Mon, 24 May 2021 12:20:17 +0800 Subject: [PATCH 09/12] Move load battery consumer icon and label into the background move high latency icon and label loading into the background thread to improve the performance and first frame response time, which is also the pre-work for checking whether a item is tappable or not feature (will work this on the next patch) Bug: 188751551 Test: make SettingsgRoboTests Change-Id: I4e5712e995fce055d2735135c28be60fb70e5796 --- .../BatteryChartPreferenceController.java | 70 ++++++++++++++----- .../settings/fuelgauge/BatteryDiffEntry.java | 2 +- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java index a36c2ef964a..f93f0a30b00 100644 --- a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java +++ b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java @@ -20,6 +20,7 @@ import android.app.settings.SettingsEnums; import android.content.Context; import android.content.res.Configuration; import android.graphics.drawable.Drawable; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -64,7 +65,6 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll ExpandDividerPreference.OnExpandListener { private static final String TAG = "BatteryChartPreferenceController"; private static final String KEY_FOOTER_PREF = "battery_graph_footer"; - private static final int ADD_FOOTER_DELAYED_MS = 250; /** Desired battery history size for timestamp slots. */ public static final int DESIRED_HISTORY_SIZE = 25; @@ -267,11 +267,6 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll void setBatteryHistoryMap( final Map> batteryHistoryMap) { - mHandler.post(() -> setBatteryHistoryMapInner(batteryHistoryMap)); - } - - private void setBatteryHistoryMapInner( - final Map> batteryHistoryMap) { // Resets all battery history data relative variables. if (batteryHistoryMap == null || batteryHistoryMap.isEmpty()) { mBatteryIndexedMap = null; @@ -298,19 +293,15 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll mBatteryHistoryLevels[index] = Math.round(batteryLevelCounter / entryMap.size()); } - // Generates indexed usage map for chart. - mBatteryIndexedMap = - ConvertUtils.getIndexedUsageMap( - mPrefContext, /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1, - mBatteryHistoryKeys, batteryHistoryMap, - /*purgeLowPercentageAndFakeData=*/ true); forceRefreshUi(); - Log.d(TAG, String.format( "setBatteryHistoryMap() size=%d\nkeys=%s\nlevels=%s", batteryHistoryMap.size(), utcToLocalTime(mBatteryHistoryKeys), Arrays.toString(mBatteryHistoryLevels))); + + // Loads item icon and label in the background. + new LoadAllItemsInfoTask(batteryHistoryMap).execute(); } void setBatteryChartView(final BatteryChartView batteryChartView) { @@ -599,9 +590,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll containAppItems ? R.string.battery_usage_screen_footer : R.string.battery_usage_screen_footer_empty)); - mHandler.postDelayed( - () -> mPreferenceScreen.addPreference(mFooterPreference), - ADD_FOOTER_DELAYED_MS); + mHandler.post(() -> mPreferenceScreen.addPreference(mFooterPreference)); } private static String utcToLocalTime(long[] timestamps) { @@ -670,4 +659,53 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll } return batteryHistoryKeys; } + + // Loads all items icon and label in the background. + private final class LoadAllItemsInfoTask + extends AsyncTask>> { + + private long[] mBatteryHistoryKeysCache; + private Map> mBatteryHistoryMap; + + private LoadAllItemsInfoTask( + Map> batteryHistoryMap) { + this.mBatteryHistoryMap = batteryHistoryMap; + this.mBatteryHistoryKeysCache = mBatteryHistoryKeys; + } + + @Override + protected Map> doInBackground(Void... voids) { + if (mPrefContext == null || mBatteryHistoryKeysCache == null) { + return null; + } + final long startTime = System.currentTimeMillis(); + final Map> indexedUsageMap = + ConvertUtils.getIndexedUsageMap( + mPrefContext, /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1, + mBatteryHistoryKeysCache, mBatteryHistoryMap, + /*purgeLowPercentageAndFakeData=*/ true); + // Pre-loads each BatteryDiffEntry relative icon and label for all slots. + for (List entries : indexedUsageMap.values()) { + entries.forEach(entry -> entry.loadLabelAndIcon()); + } + Log.d(TAG, String.format("execute LoadAllItemsInfoTask in %d/ms", + (System.currentTimeMillis() - startTime))); + return indexedUsageMap; + } + + @Override + protected void onPostExecute( + Map> indexedUsageMap) { + mBatteryHistoryMap = null; + mBatteryHistoryKeysCache = null; + if (indexedUsageMap == null) { + return; + } + // Posts results back to main thread to refresh UI. + mHandler.post(() -> { + mBatteryIndexedMap = indexedUsageMap; + forceRefreshUi(); + }); + } + } } diff --git a/src/com/android/settings/fuelgauge/BatteryDiffEntry.java b/src/com/android/settings/fuelgauge/BatteryDiffEntry.java index 5ed1cf52a74..9db29f33fb7 100644 --- a/src/com/android/settings/fuelgauge/BatteryDiffEntry.java +++ b/src/com/android/settings/fuelgauge/BatteryDiffEntry.java @@ -142,7 +142,7 @@ public class BatteryDiffEntry { return false; } - private void loadLabelAndIcon() { + void loadLabelAndIcon() { if (mIsLoaded) { return; } From c3ce01cdde1cd52d68f9b53d20aac83062ff2578 Mon Sep 17 00:00:00 2001 From: menghanli Date: Mon, 24 May 2021 19:54:29 +0800 Subject: [PATCH 10/12] Apply color extraction for sub settings in SuW Bug: 183713013 Test: Run initBCTestEnv_S.sh and apply different color Change-Id: Ia06983a8bcfa9cbf190d0c73496b5d70660ffa4e --- src/com/android/settings/core/SettingsBaseActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/android/settings/core/SettingsBaseActivity.java b/src/com/android/settings/core/SettingsBaseActivity.java index 6af95b2ee9d..a032a8bbe80 100644 --- a/src/com/android/settings/core/SettingsBaseActivity.java +++ b/src/com/android/settings/core/SettingsBaseActivity.java @@ -107,6 +107,7 @@ public class SettingsBaseActivity extends FragmentActivity { final int appliedTheme = ThemeHelper.isSetupWizardDayNightEnabled(this) ? R.style.SubSettings_SetupWizard : R.style.SudThemeGlifV3_Light; setTheme(appliedTheme); + ThemeHelper.trySetDynamicColor(this); } if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SILKY_HOME) From 05f20f44f25a9436d4d198bc48996736420d75ab Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 24 May 2021 09:02:24 -0400 Subject: [PATCH 11/12] Improve entrance animations on convo page By moving loading in each controller to the same thread. There will still be shifting as the conversation prefs are added, but it won't be the over thte top shift up and shift down motion that existed prior to this cl. Test: manual Fixes: 188734400 Change-Id: I202981b603b8f9308b2b352a0939182910869cd6 --- res/xml/conversation_list_settings.xml | 4 ++- .../AllConversationsPreferenceController.java | 19 +++----------- .../ConversationListPreferenceController.java | 4 +-- ...rityConversationsPreferenceController.java | 19 +++----------- ...centConversationsPreferenceController.java | 26 +++++-------------- 5 files changed, 19 insertions(+), 53 deletions(-) diff --git a/res/xml/conversation_list_settings.xml b/res/xml/conversation_list_settings.xml index 040a9687f7c..f61d2016868 100644 --- a/res/xml/conversation_list_settings.xml +++ b/res/xml/conversation_list_settings.xml @@ -29,7 +29,7 @@ @@ -55,6 +56,7 @@ diff --git a/src/com/android/settings/notification/app/AllConversationsPreferenceController.java b/src/com/android/settings/notification/app/AllConversationsPreferenceController.java index 03e321bbae1..f61e167e56d 100644 --- a/src/com/android/settings/notification/app/AllConversationsPreferenceController.java +++ b/src/com/android/settings/notification/app/AllConversationsPreferenceController.java @@ -68,21 +68,10 @@ public class AllConversationsPreferenceController extends ConversationListPrefer public void updateState(Preference preference) { PreferenceCategory pref = (PreferenceCategory) preference; // Load conversations - new AsyncTask() { - @Override - protected Void doInBackground(Void... unused) { - mConversations = mBackend.getConversations(false).getList(); - Collections.sort(mConversations, mConversationComparator); - return null; - } - @Override - protected void onPostExecute(Void unused) { - if (mContext == null) { - return; - } - populateList(mConversations, pref); - } - }.execute(); + mConversations = mBackend.getConversations(false).getList(); + Collections.sort(mConversations, mConversationComparator); + + populateList(mConversations, pref); } } diff --git a/src/com/android/settings/notification/app/ConversationListPreferenceController.java b/src/com/android/settings/notification/app/ConversationListPreferenceController.java index 948a3611cb7..0c4f2274340 100644 --- a/src/com/android/settings/notification/app/ConversationListPreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationListPreferenceController.java @@ -63,7 +63,7 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe protected void populateList(List conversations, PreferenceGroup containerGroup) { - // TODO: if preference has children, compare with newly loaded list + containerGroup.setVisible(false); containerGroup.removeAll(); if (conversations != null) { populateConversations(conversations, containerGroup); @@ -72,11 +72,11 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe if (containerGroup.getPreferenceCount() == 0) { containerGroup.setVisible(false); } else { - containerGroup.setVisible(true); Preference summaryPref = getSummaryPreference(); if (summaryPref != null) { containerGroup.addPreference(summaryPref); } + containerGroup.setVisible(true); } } diff --git a/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java b/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java index 5533912d85b..3888a0ac7ed 100644 --- a/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java +++ b/src/com/android/settings/notification/app/PriorityConversationsPreferenceController.java @@ -67,22 +67,9 @@ public class PriorityConversationsPreferenceController extends public void updateState(Preference preference) { PreferenceCategory pref = (PreferenceCategory) preference; // Load conversations - new AsyncTask() { - @Override - protected Void doInBackground(Void... unused) { - mConversations = mBackend.getConversations(true).getList(); - Collections.sort(mConversations, mConversationComparator); - return null; - } - - @Override - protected void onPostExecute(Void unused) { - if (mContext == null) { - return; - } - populateList(mConversations, pref); - } - }.execute(); + mConversations = mBackend.getConversations(true).getList(); + Collections.sort(mConversations, mConversationComparator); + populateList(mConversations, pref); } } diff --git a/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java b/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java index 8bb64e2fd7c..5b2cdb9fe81 100644 --- a/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java +++ b/src/com/android/settings/notification/app/RecentConversationsPreferenceController.java @@ -104,26 +104,14 @@ public class RecentConversationsPreferenceController extends AbstractPreferenceC public void updateState(Preference preference) { PreferenceCategory pref = (PreferenceCategory) preference; // Load conversations - new AsyncTask() { - @Override - protected Void doInBackground(Void... unused) { - try { - mConversations = mPs.getRecentConversations().getList(); - } catch (RemoteException e) { - Slog.w(TAG, "Could get recents", e); - } - Collections.sort(mConversations, mConversationComparator); - return null; - } + try { + mConversations = mPs.getRecentConversations().getList(); + } catch (RemoteException e) { + Slog.w(TAG, "Could get recents", e); + } + Collections.sort(mConversations, mConversationComparator); - @Override - protected void onPostExecute(Void unused) { - if (mContext == null) { - return; - } - populateList(mConversations, pref); - } - }.execute(); + populateList(mConversations, pref); } From ea6bb2dc4a0d458cc5c03a0f7e95584882fbdec4 Mon Sep 17 00:00:00 2001 From: jasonwshsu Date: Sun, 23 May 2021 02:51:40 +0800 Subject: [PATCH 12/12] Fix transparency seekbar in accessibility button page is backwards Root Cause: Store value in opacity value, need to be inverted to transparency value. Solution: transfer to transparency value and rename related field. Bug: 183980065 Test: atest FloatingMenuTransparencyPreferenceControllerTest Change-Id: I763dda47854e7cf945a95f4a7d4965725cd73824 --- res/xml/accessibility_button_settings.xml | 2 +- ...MenuTransparencyPreferenceController.java} | 37 ++++++++++--------- ...TransparencyPreferenceControllerTest.java} | 26 +++++++------ 3 files changed, 36 insertions(+), 29 deletions(-) rename src/com/android/settings/accessibility/{FloatingMenuOpacityPreferenceController.java => FloatingMenuTransparencyPreferenceController.java} (78%) rename tests/robotests/src/com/android/settings/accessibility/{FloatingMenuOpacityPreferenceControllerTest.java => FloatingMenuTransparencyPreferenceControllerTest.java} (80%) diff --git a/res/xml/accessibility_button_settings.xml b/res/xml/accessibility_button_settings.xml index 4732da5526e..02b1c7d4693 100644 --- a/res/xml/accessibility_button_settings.xml +++ b/res/xml/accessibility_button_settings.xml @@ -57,7 +57,7 @@ android:key="accessibility_button_opacity" android:title="@string/accessibility_button_opacity_title" android:persistent="false" - settings:controller="com.android.settings.accessibility.FloatingMenuOpacityPreferenceController"/> + settings:controller="com.android.settings.accessibility.FloatingMenuTransparencyPreferenceController"/> maxValue) ? DEFAULT_OPACITY : value; + return (transparencyValue < minValue || transparencyValue > maxValue) + ? DEFAULT_TRANSPARENCY : transparencyValue; } } - diff --git a/tests/robotests/src/com/android/settings/accessibility/FloatingMenuOpacityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/FloatingMenuTransparencyPreferenceControllerTest.java similarity index 80% rename from tests/robotests/src/com/android/settings/accessibility/FloatingMenuOpacityPreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/accessibility/FloatingMenuTransparencyPreferenceControllerTest.java index 1638f907407..55637cd137d 100644 --- a/tests/robotests/src/com/android/settings/accessibility/FloatingMenuOpacityPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/FloatingMenuTransparencyPreferenceControllerTest.java @@ -19,8 +19,9 @@ package com.android.settings.accessibility; import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU; import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR; -import static com.android.settings.accessibility.FloatingMenuOpacityPreferenceController.DEFAULT_OPACITY; -import static com.android.settings.accessibility.FloatingMenuOpacityPreferenceController.PRECISION; +import static com.android.settings.accessibility.FloatingMenuTransparencyPreferenceController.DEFAULT_TRANSPARENCY; +import static com.android.settings.accessibility.FloatingMenuTransparencyPreferenceController.MAXIMUM_TRANSPARENCY; +import static com.android.settings.accessibility.FloatingMenuTransparencyPreferenceController.PRECISION; import static com.android.settings.core.BasePreferenceController.AVAILABLE; import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING; @@ -47,9 +48,9 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.robolectric.RobolectricTestRunner; -/** Tests for {@link FloatingMenuOpacityPreferenceController}. */ +/** Tests for {@link FloatingMenuTransparencyPreferenceController}. */ @RunWith(RobolectricTestRunner.class) -public class FloatingMenuOpacityPreferenceControllerTest { +public class FloatingMenuTransparencyPreferenceControllerTest { @Rule public MockitoRule mocks = MockitoJUnit.rule(); @@ -58,12 +59,12 @@ public class FloatingMenuOpacityPreferenceControllerTest { private final Context mContext = ApplicationProvider.getApplicationContext(); @Mock private ContentResolver mContentResolver; - private FloatingMenuOpacityPreferenceController mController; + private FloatingMenuTransparencyPreferenceController mController; @Before public void setUp() { when(mContext.getContentResolver()).thenReturn(mContentResolver); - mController = new FloatingMenuOpacityPreferenceController(mContext, "test_key"); + mController = new FloatingMenuTransparencyPreferenceController(mContext, "test_key"); } @Test @@ -95,10 +96,12 @@ public class FloatingMenuOpacityPreferenceControllerTest { @Test public void getSliderPosition_putNormalOpacityValue_expectedValue() { + final float transparencyValue = 0.65f; Settings.Secure.putFloat(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY, 0.35f); + Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY, + (MAXIMUM_TRANSPARENCY - transparencyValue)); - assertThat(mController.getSliderPosition()).isEqualTo(35); + assertThat(mController.getSliderPosition()).isEqualTo((int) (transparencyValue * 100)); } @Test @@ -106,17 +109,18 @@ public class FloatingMenuOpacityPreferenceControllerTest { Settings.Secure.putFloat(mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY, 0.01f); - final int defaultValue = Math.round(DEFAULT_OPACITY * PRECISION); + final int defaultValue = Math.round(DEFAULT_TRANSPARENCY * PRECISION); assertThat(mController.getSliderPosition()).isEqualTo(defaultValue); } @Test public void setSliderPosition_expectedValue() { - mController.setSliderPosition(27); + final float transparencyValue = 0.27f; + mController.setSliderPosition((int) (transparencyValue * 100)); final float value = Settings.Secure.getFloat(mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY, -1); - assertThat(value).isEqualTo(0.27f); + assertThat(value).isEqualTo((MAXIMUM_TRANSPARENCY - transparencyValue)); } @Test