Merge "Fix transparency seekbar in accessibility button page is backwards" into sc-dev
diff --git a/res/layout/admin_support_details_dialog.xml b/res/layout/admin_support_details_dialog.xml
index 298cf24..0233a1b 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.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="@dimen/admin_details_dialog_padding"
- android:orientation="vertical">
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="@dimen/admin_details_dialog_padding"
+ android:paddingStart="@dimen/admin_details_dialog_padding"
+ android:paddingEnd="@dimen/admin_details_dialog_padding"
+ android:paddingBottom="@dimen/admin_details_dialog_padding_bottom"
+ android:orientation="vertical">
<LinearLayout
- android:layout_width="match_parent"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:gravity="center_horizontal"
+ android:paddingBottom="@dimen/admin_details_dialog_title_bottom_padding">
+ <ImageView
+ android:id="@+id/admin_support_icon"
+ android:layout_width="@dimen/admin_details_dialog_icon_size"
+ android:layout_height="@dimen/admin_details_dialog_icon_size"
+ android:scaleType="fitCenter"
+ android:contentDescription="@null"/>
+ <TextView
+ android:id="@+id/admin_support_dialog_title"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:gravity="center_vertical"
- android:paddingBottom="@dimen/admin_details_dialog_title_bottom_padding">
- <ImageView android:id="@+id/admin_support_icon"
- android:layout_width="@dimen/admin_details_dialog_icon_size"
- android:layout_height="@dimen/admin_details_dialog_icon_size"
- android:scaleType="fitCenter"
- android:contentDescription="@null" />
- <TextView android:id="@+id/admin_support_dialog_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingStart="@dimen/admin_details_dialog_padding"
- android:text="@string/disabled_by_policy_title"
- android:textAppearance="@style/TextAppearance.HeadLineFontFamily"/>
+ android:layout_marginTop="16dp"
+ android:gravity="center_horizontal"
+ android:text="@string/disabled_by_policy_title"
+ android:textAppearance="@style/TextAppearance.AdminDialogTitle"/>
</LinearLayout>
<ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:fadeScrollbars="false">
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:fadeScrollbars="false">
- <LinearLayout
+ android:orientation="vertical">
+ <TextView
+ android:id="@+id/admin_support_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView android:id="@+id/admin_support_msg"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="@style/TextAppearance.HeadLineFontFamily.Subhead"
- android:maxLength="200"
- android:autoLink="email|phone|web"
- android:textColor="?android:attr/textColorSecondary"/>
+ android:textAppearance="@style/TextAppearance.AdminDialogMessage"
+ android:maxLength="200"
+ android:gravity="center_horizontal"
+ android:autoLink="email|phone|web"
+ android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
diff --git a/res/layout/fingerprint_enroll_introduction.xml b/res/layout/fingerprint_enroll_introduction.xml
index 03a8e7f..f556f27 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" />
</LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:paddingTop="12dp">
-
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:contentDescription="@null"
- android:src="@drawable/ic_link_24dp"/>
- <Space
- android:layout_width="24dp"
- android:layout_height="wrap_content"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/security_settings_fingerprint_v2_enroll_introduction_message_learn_more" />
- </LinearLayout>
-
</LinearLayout>
<!-- Keep in mind -->
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index a9cda9e..168480e 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -262,8 +262,9 @@
<!-- Admin support contact details dialog. -->
<dimen name="admin_details_dialog_padding">24dp</dimen>
- <dimen name="admin_details_dialog_title_bottom_padding">20dp</dimen>
- <dimen name="admin_details_dialog_icon_size">48dp</dimen>
+ <dimen name="admin_details_dialog_padding_bottom">32dp</dimen>
+ <dimen name="admin_details_dialog_title_bottom_padding">16dp</dimen>
+ <dimen name="admin_details_dialog_icon_size">32dp</dimen>
<dimen name="admin_details_dialog_link_padding_top">36dp</dimen>
<dimen name="admin_details_dialog_learn_more_button_top_margin">24dp</dimen>
<dimen name="admin_details_dialog_learn_more_button_padding">8dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 34b8c22..bea0bcc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -685,24 +685,24 @@
<!-- Location settings, loading the number of apps which have location permission [CHAR LIMIT=30] -->
<string name="location_settings_loading_app_permission_stats">Loading\u2026</string>
<!-- Location settings footer warning text when location is on [CHAR LIMIT=NONE] -->
- <string name="location_settings_footer_location_on">
- <br><br>Apps with the Nearby devices permission can determine the
+ <string name="location_settings_footer_general">
+ Apps with the Nearby devices permission can determine the
relative position of connected devices.
-
- <br><br><a href="<xliff:g example="http://www.google.com" id="url">
- https://support.google.com/android/answer/3467281</xliff:g>">Learn more</a>
</string>
<!-- Location settings footer warning text when location is off [CHAR LIMIT=NONE] -->
<string name="location_settings_footer_location_off">
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="<xliff:g example="http://www.google.com"
+ </string>
+ <!-- Location settings footer link to support page [CHAR LIMIT=NONE] -->
+ <string name="location_settings_footer_learn_more">
+ <a href="<xliff:g example="http://www.google.com"
id="url"> https://support.google.com/android/answer/3467281</xliff:g>">Learn more</a>
</string>
+ <!-- Location settings footer link content description [CHAR LIMIT=NONE] -->
+ <string name="location_settings_footer_learn_more_content_description">
+ Learn more about Location Settings.
+ </string>
<!-- Main Settings screen setting option title for the item to take you to the accounts screen [CHAR LIMIT=22] -->
<string name="account_settings_title">Accounts</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index c72b3a5..a5b187b 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -871,4 +871,15 @@
<item name="android:textSize">16sp</item>
<item name="android:textColor">?android:attr/textColorSecondary</item>
</style>
+
+ <style name="TextAppearance.AdminDialogTitle"
+ parent="@*android:style/TextAppearance.DeviceDefault.Title">
+ <item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
+ <item name="android:textSize">24sp</item>
+ </style>
+
+ <style name="TextAppearance.AdminDialogMessage"
+ parent="@*android:style/TextAppearance.DeviceDefault">
+ <item name="android:textColor">?android:attr/textColorSecondary</item>
+ </style>
</resources>
diff --git a/res/values/styles_preference.xml b/res/values/styles_preference.xml
index ea2900f..1c8d015 100644
--- a/res/values/styles_preference.xml
+++ b/res/values/styles_preference.xml
@@ -48,7 +48,7 @@
<item name="android:layout">@layout/preference_widget_seekbar_settings</item>
</style>
- <style name="SyncSwitchPreference" parent="@style/Preference.Material">
+ <style name="SyncSwitchPreference" parent="@style/SettingsSwitchPreference.SettingsLib">
<item name="android:widgetLayout">@layout/preference_widget_sync_toggle</item>
</style>
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index 857885d..880a326 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -70,8 +70,9 @@
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference
- android:title="@string/location_settings_footer_location_on"
+ android:title="@string/location_settings_footer_general"
android:key="location_footer"
android:selectable="false"
+ settings:searchable="false"
settings:controller="com.android.settings.location.LocationSettingsFooterPreferenceController"/>
</PreferenceScreen>
diff --git a/res/xml/location_settings_personal.xml b/res/xml/location_settings_personal.xml
index 726a96c..bae1ac1 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"/>
<com.android.settingslib.widget.FooterPreference
- android:title="@string/location_settings_footer_location_on"
+ android:title="@string/location_settings_footer_general"
android:key="location_footer"
settings:controller="com.android.settings.location.LocationSettingsFooterPreferenceController"
android:selectable="false"/>
diff --git a/res/xml/location_settings_workprofile.xml b/res/xml/location_settings_workprofile.xml
index 99ccf14..51d8761 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"/>
<com.android.settingslib.widget.FooterPreference
- android:title="@string/location_settings_footer_location_on"
+ android:title="@string/location_settings_footer_general"
android:key="location_footer"
settings:controller="com.android.settings.location.LocationSettingsFooterPreferenceController"
android:selectable="false"/>
diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml
index cc281fa..4a67deb 100644
--- a/res/xml/wifi_configure_settings.xml
+++ b/res/xml/wifi_configure_settings.xml
@@ -60,12 +60,6 @@
</Preference>
<Preference
- android:key="network_scorer_picker"
- android:title="@string/network_scorer_picker_title"
- android:fragment="com.android.settings.network.NetworkScorerPicker"
- settings:controller="com.android.settings.network.NetworkScorerPickerPreferenceController" />
-
- <Preference
android:key="wifi_direct"
android:title="@string/wifi_menu_p2p"
android:fragment="com.android.settings.wifi.p2p.WifiP2pSettings" />
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index c81bfb2..4b1725f 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.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 @@
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 cb0d964..57fd7ea 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.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 @@
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 c639d1d..42bb34a 100644
--- a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
+++ b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
@@ -58,7 +58,6 @@
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/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
index 86ffa47..2a5eda2 100644
--- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
@@ -22,12 +22,8 @@
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.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 @@
@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 a36c2ef..f93f0a3 100644
--- a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
@@ -20,6 +20,7 @@
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 @@
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 @@
void setBatteryHistoryMap(
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
- mHandler.post(() -> setBatteryHistoryMapInner(batteryHistoryMap));
- }
-
- private void setBatteryHistoryMapInner(
- final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
// Resets all battery history data relative variables.
if (batteryHistoryMap == null || batteryHistoryMap.isEmpty()) {
mBatteryIndexedMap = null;
@@ -298,19 +293,15 @@
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 @@
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 @@
}
return batteryHistoryKeys;
}
+
+ // Loads all items icon and label in the background.
+ private final class LoadAllItemsInfoTask
+ extends AsyncTask<Void, Void, Map<Integer, List<BatteryDiffEntry>>> {
+
+ private long[] mBatteryHistoryKeysCache;
+ private Map<Long, Map<String, BatteryHistEntry>> mBatteryHistoryMap;
+
+ private LoadAllItemsInfoTask(
+ Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
+ this.mBatteryHistoryMap = batteryHistoryMap;
+ this.mBatteryHistoryKeysCache = mBatteryHistoryKeys;
+ }
+
+ @Override
+ protected Map<Integer, List<BatteryDiffEntry>> doInBackground(Void... voids) {
+ if (mPrefContext == null || mBatteryHistoryKeysCache == null) {
+ return null;
+ }
+ final long startTime = System.currentTimeMillis();
+ final Map<Integer, List<BatteryDiffEntry>> 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<BatteryDiffEntry> 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<Integer, List<BatteryDiffEntry>> 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 5ed1cf5..9db29f3 100644
--- a/src/com/android/settings/fuelgauge/BatteryDiffEntry.java
+++ b/src/com/android/settings/fuelgauge/BatteryDiffEntry.java
@@ -142,7 +142,7 @@
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 d2d5c1f..281cc5a 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.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 @@
*/
public class LocationSettingsFooterPreferenceController extends LocationBasePreferenceController {
private static final String TAG = "LocationFooter";
+ private static final String PARAGRAPH_SEPARATOR = "<br><br>";
private static final Intent INJECT_INTENT =
new Intent(LocationManager.SETTINGS_FOOTER_DISPLAYED_ACTION);
@@ -90,24 +92,33 @@
}
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 9ecab3b..0000000
--- 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<NetworkScorerAppData> 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 4b452c0..0000000
--- 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<NetworkScorerAppData> 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 c8d5ffd..d6cf0c6 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -153,7 +153,7 @@
}
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/utils/LocaleUtils.java b/src/com/android/settings/utils/LocaleUtils.java
new file mode 100644
index 0000000..8fab344
--- /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<CharSequence> 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/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
index 5350d45..5a44c79 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 @@
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 @@
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 @@
}
@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 c4e953c..0000000
--- 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<RadioButtonPreference> 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<RadioButtonPreference> 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<RadioButtonPreference> 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 542d2ff..0000000
--- 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));
- }
-}