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/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" /> - - - - - - - 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/strings.xml b/res/values/strings.xml index 34b8c2258b3..bea0bcc26e4 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/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/res/values/styles_preference.xml b/res/values/styles_preference.xml index ea2900f2ebe..1c8d0153db9 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/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"/> @@ -55,6 +56,7 @@ 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/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 @@ - - maxValue) ? DEFAULT_OPACITY : value; + return (transparencyValue < minValue || transparencyValue > maxValue) + ? DEFAULT_TRANSPARENCY : transparencyValue; } } - 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/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; 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) 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 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; } 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; } /** diff --git a/src/com/android/settings/network/NetworkScorerPicker.java b/src/com/android/settings/network/NetworkScorerPicker.java deleted file mode 100644 index 9ecab3bfb6f..00000000000 --- a/src/com/android/settings/network/NetworkScorerPicker.java +++ /dev/null @@ -1,145 +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.app.settings.SettingsEnums; -import android.content.Context; -import android.net.NetworkScoreManager; -import android.net.NetworkScorerAppData; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.VisibleForTesting; -import androidx.preference.Preference; -import androidx.preference.PreferenceScreen; - -import com.android.settings.R; -import com.android.settings.core.InstrumentedPreferenceFragment; -import com.android.settingslib.widget.RadioButtonPreference; - -import java.util.List; - -/** - * Fragment for choosing default network scorer. - */ -public class NetworkScorerPicker extends InstrumentedPreferenceFragment implements - RadioButtonPreference.OnClickListener { - - private NetworkScoreManager mNetworkScoreManager; - - @Override - public int getMetricsCategory() { - return SettingsEnums.SETTINGS_NETWORK_SCORER; - } - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - super.onCreatePreferences(savedInstanceState, rootKey); - updateCandidates(); - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); - mNetworkScoreManager = createNetworkScorerManager(context); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = super.onCreateView(inflater, container, savedInstanceState); - // this is needed so the back button goes back to previous fragment - setHasOptionsMenu(true); - return view; - } - - @Override - protected int getPreferenceScreenResId() { - return R.xml.network_scorer_picker_prefs; - } - - @VisibleForTesting - public void updateCandidates() { - final PreferenceScreen screen = getPreferenceScreen(); - screen.removeAll(); - - final List 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/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(); } } 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); } 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()); + } +} 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 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 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)); - } -}