Merge "[Fix]Test cast fail at BaseBluetoothDialogPreferenceTest" into sc-dev
diff --git a/res/layout/preference_labeled_continuous_slider.xml b/res/layout/preference_labeled_continuous_slider.xml
new file mode 100644
index 0000000..00e8796
--- /dev/null
+++ b/res/layout/preference_labeled_continuous_slider.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingStart="56dp"
+ android:paddingEnd="8dp"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp">
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="16dp"
+ android:layout_marginStart="16dp"
+ android:maxLines="1"
+ android:textAppearance="@android:style/TextAppearance.Material.Subhead"
+ android:textColor="?android:attr/textColorPrimary" />
+
+ <SeekBar
+ android:id="@*android:id/seekbar"
+ android:layout_gravity="center_vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="8dp"
+ android:orientation="horizontal">
+
+ <TextView
+ android:id="@android:id/text1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_weight="1"
+ android:maxLines="1"
+ android:textAlignment="viewStart"/>
+
+ <TextView
+ android:id="@android:id/text2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="16dp"
+ android:layout_weight="1"
+ android:maxLines="1"
+ android:textAlignment="viewEnd"/>
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/layout/reset_network.xml b/res/layout/reset_network.xml
index f6135a9..47fa56a 100644
--- a/res/layout/reset_network.xml
+++ b/res/layout/reset_network.xml
@@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
- <ScrollView
+ <androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_marginStart="@dimen/reset_network_margin_start"
@@ -38,7 +38,7 @@
android:text="@string/reset_network_desc" />
<include layout="@layout/reset_esim_checkbox"/>
</LinearLayout>
- </ScrollView>
+ </androidx.core.widget.NestedScrollView>
<Spinner android:id="@+id/reset_network_subscription"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
diff --git a/res/values/config.xml b/res/values/config.xml
index 57d5a75..984906f 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -503,4 +503,10 @@
<!-- Whether to handle slot change events -->
<bool name="config_handle_sim_slot_change">false</bool>
+
+ <!-- whether use partner overlay theme for outside setupwizard flow -->
+ <bool name="config_suc_use_partner_resource">false</bool>
+
+ <!-- Cell broacast receiver package name -->
+ <string name="config_cell_broadcast_receiver_package" translatable="false">com.android.cellbroadcastreceiver.module</string>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5abba1f..e707dc9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7519,9 +7519,6 @@
<!-- Summary of multimedia messaging service settings. [CHAR LIMIT=100] -->
<string name="mms_message_summary">Send & receive when mobile data is off</string>
- <!-- Cell broacast receiver package name [DO NOT TRANSLATE] -->
- <string name="cell_broadcast_receiver_package">com.android.cellbroadcastreceiver.module</string>
-
<!-- Title of a preference for whether to allow data during calls that is shown when mobile
data is turned off. This is needed for some multi-SIM scenarios, because the SIM that is
default for data might not be available during a phone call. [CHAR LIMIT=60] -->
@@ -12804,6 +12801,8 @@
<!-- Alert Dialog text when user didn't input the phone number [CHAR LIMIT=50]-->
<string name="smart_forwarding_missing_alert_dialog_text">OK</string>
- <!-- Enable 2G: Title for if user wants to enable 2G [CHAR LIMIT=40] -->
+ <!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=40] -->
<string name="enable_2g_title">Allow 2G</string>
+ <!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=NONE] -->
+ <string name="enable_2g_summary">Use 2G cellular connections. For emergency calls, 2G is always turned on.</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 993417a..0d773f1 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -606,7 +606,7 @@
<style name="SetupWizardPartnerResource">
<!-- Disable to use partner overlay theme for outside setupwizard flow. -->
- <item name="sucUsePartnerResource">false</item>
+ <item name="sucUsePartnerResource">@bool/config_suc_use_partner_resource</item>
<!-- Enable heavy theme style inside setupwizard flow. -->
<item name="sudUsePartnerHeavyTheme">true</item>
</style>
diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml
index bd2e85c..49d8e9b 100644
--- a/res/xml/app_and_notification.xml
+++ b/res/xml/app_and_notification.xml
@@ -90,7 +90,7 @@
settings:useAdminDisabledSummary="true">
<intent
android:action="android.intent.action.MAIN"
- android:targetPackage="@string/cell_broadcast_receiver_package"
+ android:targetPackage="@string/config_cell_broadcast_receiver_package"
android:targetClass="com.android.cellbroadcastreceiver.CellBroadcastSettings"/>
</com.android.settingslib.RestrictedPreference>
diff --git a/res/xml/configure_notification_settings_v2.xml b/res/xml/configure_notification_settings_v2.xml
index 6c3ec52..9029220 100644
--- a/res/xml/configure_notification_settings_v2.xml
+++ b/res/xml/configure_notification_settings_v2.xml
@@ -109,7 +109,7 @@
settings:useAdminDisabledSummary="true">
<intent
android:action="android.intent.action.MAIN"
- android:targetPackage="@string/cell_broadcast_receiver_package"
+ android:targetPackage="@string/config_cell_broadcast_receiver_package"
android:targetClass="com.android.cellbroadcastreceiver.CellBroadcastSettings"/>
</com.android.settingslib.RestrictedPreference>
diff --git a/res/xml/emergency_settings.xml b/res/xml/emergency_settings.xml
index 774e328..28ae8b1 100644
--- a/res/xml/emergency_settings.xml
+++ b/res/xml/emergency_settings.xml
@@ -39,7 +39,7 @@
settings:useAdminDisabledSummary="true">
<intent
android:action="android.intent.action.MAIN"
- android:targetPackage="@string/cell_broadcast_receiver_package"
+ android:targetPackage="@string/config_cell_broadcast_receiver_package"
android:targetClass="com.android.cellbroadcastreceiver.CellBroadcastSettings"/>
</com.android.settingslib.RestrictedPreference>
</PreferenceScreen>
diff --git a/res/xml/mobile_network_settings.xml b/res/xml/mobile_network_settings.xml
index 86f5a83..7ab9893 100644
--- a/res/xml/mobile_network_settings.xml
+++ b/res/xml/mobile_network_settings.xml
@@ -258,5 +258,6 @@
<SwitchPreference
android:key="enable_2g"
android:title="@string/enable_2g_title"
+ android:summary="@string/enable_2g_summary"
settings:controller="com.android.settings.network.telephony.Enable2gPreferenceController" />
</PreferenceScreen>
diff --git a/res/xml/reduce_bright_colors_settings.xml b/res/xml/reduce_bright_colors_settings.xml
index b9ca854..17e8b02 100644
--- a/res/xml/reduce_bright_colors_settings.xml
+++ b/res/xml/reduce_bright_colors_settings.xml
@@ -17,13 +17,16 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:persistent="false"
android:title="@string/reduce_bright_colors_preference_title">
- <com.android.settings.widget.SeekBarPreference
+ <com.android.settings.widget.LabeledContinuousSeekBarPreference
android:key="rbc_intensity"
android:persistent="false"
- android:title="@string/reduce_bright_colors_intensity_preference_title"/>
+ android:title="@string/reduce_bright_colors_intensity_preference_title"
+ settings:textStart="@string/reduce_bright_colors_intensity_preference_start_label"
+ settings:textEnd="@string/reduce_bright_colors_intensity_preference_end_label"/>
<SwitchPreference
android:key="rbc_persist"
diff --git a/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java b/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
index ea7fb7c..3b220e4 100644
--- a/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
+++ b/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
@@ -29,8 +29,11 @@
/** PreferenceController for feature intensity. */
public class ReduceBrightColorsIntensityPreferenceController extends SliderPreferenceController {
+ private final ColorDisplayManager mColorDisplayManager;
+
public ReduceBrightColorsIntensityPreferenceController(Context context, String key) {
super(context, key);
+ mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
}
@Override
@@ -59,31 +62,26 @@
@Override
public final void updateState(Preference preference) {
super.updateState(preference);
- preference.setEnabled(Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0) == 1);
+ preference.setEnabled(mColorDisplayManager.isReduceBrightColorsActivated());
}
@Override
public int getSliderPosition() {
- return Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0);
+ return mColorDisplayManager.getReduceBrightColorsStrength();
}
@Override
public boolean setSliderPosition(int position) {
- return Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, position);
+ return mColorDisplayManager.setReduceBrightColorsStrength(position);
}
@Override
public int getMax() {
- // TODO(b/170970675): Call into CDS to get config max intensity
- return 100;
+ return ColorDisplayManager.getMaximumReduceBrightColorsStrength(mContext);
}
@Override
public int getMin() {
- // TODO(b/170970675): Call into CDS to get config min intensity
- return 0;
+ return ColorDisplayManager.getMinimumReduceBrightColorsStrength(mContext);
}
}
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index 09690d9..f65bd62 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -29,9 +29,13 @@
import android.view.View;
import android.view.ViewGroup;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.SwitchPreference;
+
import com.android.internal.accessibility.AccessibilityShortcutController;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.widget.SeekBarPreference;
import com.android.settings.widget.SettingsMainSwitchPreference;
import com.android.settingslib.search.SearchIndexable;
@@ -75,7 +79,21 @@
}
};
- return super.onCreateView(inflater, container, savedInstanceState);
+ final View view = super.onCreateView(inflater, container, savedInstanceState);
+ updateGeneralCategoryOrder();
+ return view;
+ }
+
+ private void updateGeneralCategoryOrder() {
+ final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
+ final SeekBarPreference intensity = findPreference(KEY_INTENSITY);
+ getPreferenceScreen().removePreference(intensity);
+ intensity.setOrder(mShortcutPreference.getOrder() - 2);
+ generalCategory.addPreference(intensity);
+ final SwitchPreference persist = findPreference(KEY_PERSIST);
+ getPreferenceScreen().removePreference(persist);
+ persist.setOrder(mShortcutPreference.getOrder() - 1);
+ generalCategory.addPreference(persist);
}
@Override
@@ -83,17 +101,6 @@
super.onViewCreated(view, savedInstanceState);
}
- /** Customizes the order by preference key. */
- protected List<String> getPreferenceOrderList() {
- final List<String> lists = new ArrayList<>();
- lists.add(KEY_USE_SERVICE_PREFERENCE);
- lists.add(KEY_INTENSITY);
- lists.add(KEY_GENERAL_CATEGORY);
- lists.add(KEY_PERSIST);
- lists.add(KEY_INTRODUCTION_CATEGORY);
- return lists;
- }
-
@Override
public void onResume() {
super.onResume();
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index ff46722..dde5be1 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -128,8 +128,15 @@
@Override
protected void initSettingsPreference() {
+ // If the device doesn't support magnification area, it should hide the settings preference.
+ if (!getContext().getResources().getBoolean(
+ com.android.internal.R.bool.config_magnification_area)) {
+ return;
+ }
mSettingsPreference = new Preference(getPrefContext());
mSettingsPreference.setTitle(R.string.accessibility_menu_item_settings);
+ // TODO(b/177371954): "magnification area" should be brought up to the highest level of the
+ // settings UI so that it appears below "shortcut" to replace "settings.
mSettingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
mSettingsPreference.setPersistent(false);
diff --git a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
index 52b1a8d..5b74a88 100644
--- a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
+++ b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
@@ -180,6 +180,9 @@
// Keep Package Installer enabled.
keepEnabledPackages.add(mContext.getString(R.string.config_package_installer_package_name));
+ if (mPm.getWellbeingPackageName() != null) {
+ keepEnabledPackages.add(mPm.getWellbeingPackageName());
+ }
return keepEnabledPackages;
}
diff --git a/src/com/android/settings/datausage/DataSaverBackend.java b/src/com/android/settings/datausage/DataSaverBackend.java
index f13e88e..e39e41a 100644
--- a/src/com/android/settings/datausage/DataSaverBackend.java
+++ b/src/com/android/settings/datausage/DataSaverBackend.java
@@ -20,10 +20,7 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
-import android.net.INetworkPolicyListener;
import android.net.NetworkPolicyManager;
-import android.os.RemoteException;
-import android.telephony.SubscriptionPlan;
import android.util.SparseIntArray;
import com.android.settings.overlay.FeatureFactory;
@@ -180,33 +177,17 @@
}
- private final INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
- @Override
- public void onUidRulesChanged(int uid, int uidRules) throws RemoteException {
- }
-
+ private final NetworkPolicyManager.Listener mPolicyListener =
+ new NetworkPolicyManager.Listener() {
@Override
public void onUidPoliciesChanged(final int uid, final int uidPolicies) {
ThreadUtils.postOnMainThread(() -> handleUidPoliciesChanged(uid, uidPolicies));
}
@Override
- public void onMeteredIfacesChanged(String[] strings) throws RemoteException {
- }
-
- @Override
- public void onRestrictBackgroundChanged(final boolean isDataSaving) throws RemoteException {
+ public void onRestrictBackgroundChanged(final boolean isDataSaving) {
ThreadUtils.postOnMainThread(() -> handleRestrictBackgroundChanged(isDataSaving));
}
-
- @Override
- public void onSubscriptionOverride(int subId, int overrideMask, int overrideValue,
- int[] networkTypes) {
- }
-
- @Override
- public void onSubscriptionPlansChanged(int subId, SubscriptionPlan[] plans) {
- }
};
public interface Listener {
diff --git a/src/com/android/settings/network/SubscriptionUtil.java b/src/com/android/settings/network/SubscriptionUtil.java
index aa70459..be8f257 100644
--- a/src/com/android/settings/network/SubscriptionUtil.java
+++ b/src/com/android/settings/network/SubscriptionUtil.java
@@ -70,6 +70,9 @@
if (sActiveResultsForTesting != null) {
return sActiveResultsForTesting;
}
+ if (manager == null) {
+ return Collections.emptyList();
+ }
final List<SubscriptionInfo> subscriptions = manager.getActiveSubscriptionInfoList();
if (subscriptions == null) {
return new ArrayList<>();
diff --git a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
index 2c6c963..8d037fb 100644
--- a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
@@ -32,6 +32,7 @@
import com.android.settings.R;
import com.android.settings.network.SubscriptionUtil;
+import java.util.List;
import java.util.Objects;
/**
@@ -67,14 +68,22 @@
@Override
public int getAvailabilityStatus(int subId) {
- return hasBackupCallingFeature(subId) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ if (!hasBackupCallingFeature(subId)) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ List<SubscriptionInfo> subIdList = getActiveSubscriptionList();
+ SubscriptionInfo subInfo = getSubscriptionInfoFromList(subIdList, subId);
+ if (subInfo == null) { // given subId is not actives
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ return (subIdList.size() > 1) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
/**
* Implementation of abstract methods
**/
public boolean setChecked(boolean isChecked) {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager();
+ ImsMmTelManager imsMmTelMgr = getImsMmTelManager(mSubId);
if (imsMmTelMgr == null) {
return false;
}
@@ -92,7 +101,7 @@
* Implementation of abstract methods
**/
public boolean isChecked() {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager();
+ ImsMmTelManager imsMmTelMgr = getImsMmTelManager(mSubId);
if (imsMmTelMgr == null) {
return false;
}
@@ -110,16 +119,17 @@
if ((preference == null) || (!(preference instanceof SwitchPreference))) {
return;
}
+ SubscriptionInfo subInfo = getSubscriptionInfoFromActiveList(mSubId);
+
mPreference = preference;
final SwitchPreference switchPreference = (SwitchPreference) preference;
- switchPreference.setChecked(isChecked());
+ switchPreference.setChecked((subInfo != null) ? isChecked() : false);
- updateSummary(getLatestSummary());
+ updateSummary(getLatestSummary(subInfo));
}
- private String getLatestSummary() {
- SubscriptionInfo subInfo = getSubscriptionInfo();
+ private String getLatestSummary(SubscriptionInfo subInfo) {
return Objects.toString((subInfo == null) ? null
: SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext), "");
}
@@ -144,19 +154,34 @@
CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL, false);
}
- private ImsMmTelManager getImsMmTelManager() {
- if (!SubscriptionManager.isUsableSubscriptionId(mSubId)) {
+ private ImsMmTelManager getImsMmTelManager(int subId) {
+ if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
return null;
}
ImsManager imsMgr = mContext.getSystemService(ImsManager.class);
- return (imsMgr == null) ? null : imsMgr.getImsMmTelManager(mSubId);
+ return (imsMgr == null) ? null : imsMgr.getImsMmTelManager(subId);
}
- private SubscriptionInfo getSubscriptionInfo() {
- SubscriptionManager subInfoMgr = mContext.getSystemService(SubscriptionManager.class);
- if (subInfoMgr == null) {
+ private List<SubscriptionInfo> getActiveSubscriptionList() {
+ SubscriptionManager subscriptionManager =
+ mContext.getSystemService(SubscriptionManager.class);
+ return SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
+ }
+
+ private SubscriptionInfo getSubscriptionInfoFromList(
+ List<SubscriptionInfo> subInfoList, int subId) {
+ for (SubscriptionInfo subInfo : subInfoList) {
+ if ((subInfo != null) && (subInfo.getSubscriptionId() == subId)) {
+ return subInfo;
+ }
+ }
+ return null;
+ }
+
+ private SubscriptionInfo getSubscriptionInfoFromActiveList(int subId) {
+ if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
return null;
}
- return subInfoMgr.getActiveSubscriptionInfo(mSubId);
+ return getSubscriptionInfoFromList(getActiveSubscriptionList(), subId);
}
}
diff --git a/src/com/android/settings/users/UserDialogs.java b/src/com/android/settings/users/UserDialogs.java
index 0fb9636..9aab5b0 100644
--- a/src/com/android/settings/users/UserDialogs.java
+++ b/src/com/android/settings/users/UserDialogs.java
@@ -92,8 +92,7 @@
View view = inflater.inflate(R.layout.delete_managed_profile_dialog, null);
ImageView imageView =
(ImageView) view.findViewById(R.id.delete_managed_profile_mdm_icon_view);
- Drawable badgedApplicationIcon = packageManager.getUserBadgedIcon(
- packageManager.getApplicationIcon(mdmApplicationInfo), new UserHandle(userId));
+ Drawable badgedApplicationIcon = packageManager.getApplicationIcon(mdmApplicationInfo);
imageView.setImageDrawable(badgedApplicationIcon);
CharSequence appLabel = packageManager.getApplicationLabel(mdmApplicationInfo);
diff --git a/src/com/android/settings/widget/LabeledContinuousSeekBarPreference.java b/src/com/android/settings/widget/LabeledContinuousSeekBarPreference.java
new file mode 100644
index 0000000..e269818
--- /dev/null
+++ b/src/com/android/settings/widget/LabeledContinuousSeekBarPreference.java
@@ -0,0 +1,44 @@
+/*
+ * 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.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+import com.android.settings.R;
+
+/** A continuous labeled slider preference */
+public class LabeledContinuousSeekBarPreference extends LabeledSeekBarPreference {
+ public LabeledContinuousSeekBarPreference(Context context) {
+ this(context, null);
+ }
+
+ public LabeledContinuousSeekBarPreference(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public LabeledContinuousSeekBarPreference(Context context, AttributeSet attrs,
+ int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public LabeledContinuousSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ setLayoutResource(R.layout.preference_labeled_continuous_slider);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
index 3df6221..0ed6747 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
@@ -31,6 +31,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
@@ -75,7 +76,8 @@
"com.android.server.accessibility.MagnificationController";
private TestToggleScreenMagnificationPreferenceFragment mFragment;
- private Context mContext = ApplicationProvider.getApplicationContext();
+ private Context mContext;
+ private Resources mResources;
@Mock
private PreferenceManager mPreferenceManager;
@@ -86,10 +88,14 @@
public void setUpTestFragment() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(ApplicationProvider.getApplicationContext());
mFragment = spy(new TestToggleScreenMagnificationPreferenceFragment());
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
+ mResources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mFragment.getContext().getResources()).thenReturn(mResources);
doReturn(null).when(mFragment).getPreferenceScreen();
doReturn(mActivity).when(mFragment).getActivity();
}
@@ -250,6 +256,16 @@
assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP);
}
+ @Test
+ public void initSettingsPreference_notSupportsMagnificationArea_settingsPreferenceIsNull() {
+ when(mResources.getBoolean(
+ com.android.internal.R.bool.config_magnification_area))
+ .thenReturn(false);
+ mFragment.initSettingsPreference();
+
+ assertThat(mFragment.mSettingsPreference).isNull();
+ }
+
private void putStringIntoSettings(String key, String componentName) {
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
}
diff --git a/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java b/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
index dee8817..8dac893 100644
--- a/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
@@ -24,11 +24,14 @@
import android.content.Context;
import android.content.res.Resources;
+import android.hardware.display.ColorDisplayManager;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.internal.R;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -79,8 +82,19 @@
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
mPreferenceController.onPreferenceChange(/* preference= */ null, 20);
- assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0))
+ assertThat(
+ mContext.getSystemService(
+ ColorDisplayManager.class).getReduceBrightColorsStrength())
.isEqualTo(20);
}
+
+ @Test
+ public void rangeOfSlider_staysWithinValidRange() {
+ when(mResources.getInteger(
+ R.integer.config_reduceBrightColorsStrengthMax)).thenReturn(90);
+ when(mResources.getInteger(
+ R.integer.config_reduceBrightColorsStrengthMin)).thenReturn(10);
+ assertThat(mPreferenceController.getMax() - mPreferenceController.getMin())
+ .isEqualTo(80);
+ }
}