Merge "Remove lockdown toggle" into sc-dev am: 20e57d33ff am: 97b8a6409d
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15290234
Change-Id: I0770404823036e30f4e38cf8ff298b90d78e34a6
diff --git a/res/drawable-night/accessibility_captions_banner.xml b/res/drawable-night/accessibility_captions_banner.xml
new file mode 100644
index 0000000..7ee30f2
--- /dev/null
+++ b/res/drawable-night/accessibility_captions_banner.xml
@@ -0,0 +1,52 @@
+<?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.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="412dp"
+ android:height="300dp"
+ android:viewportWidth="412"
+ android:viewportHeight="300">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M383.9,300H28.1C12.6,300 0,287.4 0,271.9V28.1C0,12.6 12.6,0 28.1,0h355.8C399.4,0 412,12.6 412,28.1v243.8C412,287.4 399.4,300 383.9,300z"/>
+ <path
+ android:pathData="M79.2,179.6h53.6v8.5h-53.6z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M142.5,179.6h30.4v8.5h-30.4z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M79.2,195.5h79.2v8.5h-79.2z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M168.1,195.5h34.1v8.5h-34.1z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M211.9,195.5h34.1v8.5h-34.1z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M182.7,179.6h73.1v8.5h-73.1z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M265.5,179.6h26.8v8.5h-26.8z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M302.1,179.6h26.8v8.5h-26.8z"
+ android:fillColor="#669DF6"/>
+ <path
+ android:pathData="M142.7,67.9h-11.5c-1.6,0 -2.9,1.3 -2.9,2.9H67.8c-7.9,0 -14.4,6.5 -14.4,14.4v132.4c0,7.9 6.5,14.4 14.4,14.4h276.4c7.9,0 14.4,-6.5 14.4,-14.4V85.2c0,-7.9 -6.5,-14.4 -14.4,-14.4H203.1c0,-1.6 -1.3,-2.9 -2.9,-2.9h-28.8c-1.6,0 -2.9,1.3 -2.9,2.9h-23C145.5,69.2 144.3,67.9 142.7,67.9zM344.2,73.7c6.4,0 11.5,5.2 11.5,11.5v132.4c0,6.3 -5.2,11.5 -11.5,11.5H67.8c-6.4,0 -11.5,-5.2 -11.5,-11.5V85.2c0,-6.3 5.2,-11.5 11.5,-11.5H344.2z"
+ android:fillColor="#80868B"/>
+</vector>
diff --git a/res/drawable/accessibility_captions.png b/res/drawable/accessibility_captions.png
deleted file mode 100644
index 718f4ef..0000000
--- a/res/drawable/accessibility_captions.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/accessibility_captions_banner.xml b/res/drawable/accessibility_captions_banner.xml
new file mode 100644
index 0000000..6597ffb
--- /dev/null
+++ b/res/drawable/accessibility_captions_banner.xml
@@ -0,0 +1,52 @@
+<?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.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="412dp"
+ android:height="300dp"
+ android:viewportWidth="412"
+ android:viewportHeight="300">
+ <path
+ android:pathData="M383.9,300H28.1C12.6,300 0,287.4 0,271.9V28.1C0,12.6 12.6,0 28.1,0h355.8C399.4,0 412,12.6 412,28.1v243.8C412,287.4 399.4,300 383.9,300z"
+ android:fillColor="#FFFFFF"/>
+ <path
+ android:pathData="M79.2,179.6h53.6v8.5h-53.6z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M142.5,179.6h30.4v8.5h-30.4z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M79.2,195.5h79.2v8.5h-79.2z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M168.1,195.5h34.1v8.5h-34.1z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M211.9,195.5h34.1v8.5h-34.1z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M182.7,179.6h73.1v8.5h-73.1z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M265.5,179.6h26.8v8.5h-26.8z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M302.1,179.6h26.8v8.5h-26.8z"
+ android:fillColor="#1A73E8"/>
+ <path
+ android:pathData="M142.7,67.9h-11.5c-1.6,0 -2.9,1.3 -2.9,2.9H67.8c-7.9,0 -14.4,6.5 -14.4,14.4v132.4c0,7.9 6.5,14.4 14.4,14.4h276.4c7.9,0 14.4,-6.5 14.4,-14.4V85.2c0,-7.9 -6.5,-14.4 -14.4,-14.4H203.1c0,-1.6 -1.3,-2.9 -2.9,-2.9h-28.8c-1.6,0 -2.9,1.3 -2.9,2.9h-23C145.5,69.2 144.3,67.9 142.7,67.9zM344.2,73.7c6.4,0 11.5,5.2 11.5,11.5v132.4c0,6.3 -5.2,11.5 -11.5,11.5H67.8c-6.4,0 -11.5,-5.2 -11.5,-11.5V85.2c0,-6.3 5.2,-11.5 11.5,-11.5H344.2z"
+ android:fillColor="#DADCE0"/>
+</vector>
diff --git a/res/layout/accessibility_captions_preview.xml b/res/layout/accessibility_captions_preview.xml
deleted file mode 100644
index 1818e64..0000000
--- a/res/layout/accessibility_captions_preview.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-
-<FrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="@dimen/captioning_preview_height"
- android:contentDescription="@null"
- android:scaleType="fitCenter"
- android:src="@drawable/accessibility_captions" />
-
-</FrameLayout>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 3450665..7d6745c 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1529,8 +1529,6 @@
<!-- An allowlist which packages won't show summary in battery usage screen.
[CHAR LIMIT=NONE] -->
<string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
- <!-- Google -->
- <item>"com.google.android.googlequicksearchbox"</item>
</string-array>
<!-- An allowlist which packages won't show entry in battery usage screen.
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2f65ddd..715041d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5259,8 +5259,18 @@
<string name="select_to_speak_summary">Tap items on your screen to hear them read aloud</string>
<!-- Title for the accessibility preference screen to enable video captioning. [CHAR LIMIT=35] -->
<string name="accessibility_captioning_title">Caption preferences</string>
+ <!-- Title for accessibility captioning footer. [CHAR LIMIT=60] -->
+ <string name="accessibility_captioning_about_title">About caption preferences</string>
+ <!-- Accessibility captioning footer link content description [CHAR LIMIT=NONE] -->
+ <string name="accessibility_captioning_footer_learn_more_content_description">Learn more about caption preferences</string>
<!-- Title for the accessibility preference screen to enable screen magnification. [CHAR LIMIT=35] -->
<string name="accessibility_screen_magnification_title">Magnification</string>
+ <!-- Title for accessibility shortcut preference for magnification. [CHAR LIMIT=60] -->
+ <string name="accessibility_screen_magnification_shortcut_title">Magnification shortcut</string>
+ <!-- Title for screen magnification footer. [CHAR LIMIT=60] -->
+ <string name="accessibility_screen_magnification_about_title">About magnification</string>
+ <!-- Screen magnification footer link content description [CHAR LIMIT=NONE] -->
+ <string name="accessibility_screen_magnification_footer_learn_more_content_description">Learn more about magnification</string>
<!-- Title for the accessibility preference screen to edit magnification area. [CHAR LIMIT=35] -->
<string name="accessibility_magnification_mode_title">Magnification type</string>
<!-- Message for the accessibility preference screen to edit magnification area dialog. [CHAR LIMIT=none] -->
@@ -5411,6 +5421,12 @@
<string name="accessibility_button_title">Accessibility button</string>
<!-- Title for the accessibility button & gesture page. [CHAR LIMIT=35] -->
<string name="accessibility_button_gesture_title">Accessibility button & gesture</string>
+ <!-- Title for the accessibility button footer. [CHAR LIMIT=35] -->
+ <string name="accessibility_button_about_title">About accessibility button</string>
+ <!-- Title for the accessibility button & gesture footer. [CHAR LIMIT=55] -->
+ <string name="accessibility_button_gesture_about_title">About accessibility button & gesture</string>
+ <!-- Accessibility button & gestures footer link content description [CHAR LIMIT=NONE] -->
+ <string name="accessibility_button_gesture_footer_learn_more_content_description">Learn more about accessibility button & gesture</string>
<!-- Intro for the accessibility button page. [CHAR LIMIT=100] -->
<string name="accessibility_button_intro">Using the accessibility button. The gesture isn\u2019t available with 3-button navigation.</string>
<!-- Summary text for the accessibility button preference. [CHAR LIMIT=50] -->
@@ -5472,6 +5488,10 @@
<string name="accessibility_timeout_2mins">2 minutes</string>
<!-- Title for accessibility settings timeout item. [CHAR LIMIT=43] -->
<string name="accessibility_setting_item_control_timeout_title">Time to take action (Accessibility timeout)</string>
+ <!-- Title for accessibility timeout footer. [CHAR LIMIT=65] -->
+ <string name="accessibility_control_timeout_about_title">About time to take action (Accessibility timeout)</string>
+ <!-- Accessibility timeout footer link content description [CHAR LIMIT=NONE] -->
+ <string name="accessibility_control_timeout_footer_learn_more_content_description">Learn more about time to take action (Accessibility timeout)</string>
<!-- Title for accessibility preference to accessibility timeout. [CHAR LIMIT=35] -->
<string name="accessibility_control_timeout_preference_title">Time to take action</string>
<!-- Descriptive text for accessibility preference to accessibility control timeout. [CHAR LIMIT=NONE] -->
@@ -5483,6 +5503,8 @@
<string name="accessibility_display_inversion_preference_title">Color inversion</string>
<!-- Used in the accessibility service settings to control turning display color inversion on/off entirely. [CHAR LIMIT=NONE] -->
<string name="accessibility_display_inversion_switch_title">Use color inversion</string>
+ <!-- Title for accessibility shortcut preference for color inversion. [CHAR LIMIT=60] -->
+ <string name="accessibility_display_inversion_shortcut_title">Color inversion shortcut</string>
<!-- Subtitle for the accessibility preference to configure display color inversion. [CHAR LIMIT=NONE] -->
<string name="accessibility_display_inversion_preference_subtitle">
<![CDATA[Color inversion turns light screens dark.<br/><br/>
@@ -5496,6 +5518,10 @@
</string>
<!-- Title for accessibility preference for configuring feature that performs click action soon after mouse/trackpad pointer stops moving. [CHAR LIMIT=NONE] -->
<string name="accessibility_autoclick_preference_title">Autoclick (dwell timing)</string>
+ <!-- Title for accessibility dwell timing footer. [CHAR LIMIT=35] -->
+ <string name="accessibility_autoclick_about_title">About autoclick (dwell timing)</string>
+ <!-- Accessibility dwell timing footer link content description [CHAR LIMIT=NONE] -->
+ <string name="accessibility_autoclick_footer_learn_more_content_description">Learn more about autoclick (dwell timing)</string>
<!-- Footer text to explain what autoclick does -->
<string name="accessibility_autoclick_description">Autoclick works with a connected mouse. You can set the mouse cursor to click automatically when the cursor stops moving for a certain amount of time.</string>
<!-- Option heading to leave the auto click requirement for accessibility users at its default level. [CHAR LIMIT=50] -->
@@ -5534,6 +5560,16 @@
<string name="accessibility_service_primary_open_title">Open <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
<!-- Used in the Color correction settings screen to control turning on/off the feature entirely [CHAR LIMIT=60] -->
<string name="accessibility_daltonizer_primary_switch_title">Use color correction</string>
+ <!-- Title for accessibility shortcut preference for color correction. [CHAR LIMIT=60] -->
+ <string name="accessibility_daltonizer_shortcut_title">Color correction shortcut</string>
+ <!-- Title for Color correction footer. [CHAR LIMIT=35] -->
+ <string name="accessibility_daltonizer_about_title">About color correction</string>
+ <!-- Color inversion footer link content description [CHAR LIMIT=NONE] -->
+ <string name="accessibility_daltonizer_footer_learn_more_content_description">Learn more about color correction</string>
+ <!-- Title for Color inversion footer. [CHAR LIMIT=35] -->
+ <string name="accessibility_color_inversion_about_title">About color inversion</string>
+ <!-- Color correction footer link content description [CHAR LIMIT=NONE] -->
+ <string name="accessibility_color_inversion_footer_learn_more_content_description">Learn more about color inversion</string>
<!-- Title for Captions settings screen to control turning on/off the feature entirely [CHAR LIMIT=60] -->
<string name="accessibility_caption_primary_switch_title">Show captions</string>
<!-- Summary for Captions settings screen to control turning on/off the feature entirely [CHAR LIMIT=NONE] -->
@@ -5613,6 +5649,10 @@
<string name="reduce_bright_colors_preference_title">Extra dim</string>
<!-- Title for the activation switch of the Reduce Brightness feature. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_switch_title">Make screen extra dim</string>
+ <!-- Title for accessibility shortcut preference for Reduce Brightness. [CHAR LIMIT=60] -->
+ <string name="reduce_bright_colors_shortcut_title">Extra dim shortcut</string>
+ <!-- Title for Reduce Brightness feature footer. [CHAR LIMIT=35] -->
+ <string name="reduce_bright_colors_about_title">About extra dim</string>
<!-- Summary for the accessibility preference to configure Reduce Brightness feature. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_preference_summary" product="default">Dim screen beyond your phone\u2019s minimum brightness</string>
<!-- Summary for the accessibility preference to configure Reduce Brightness feature. [CHAR LIMIT=NONE] -->
diff --git a/res/xml/captioning_settings.xml b/res/xml/captioning_settings.xml
index b397146..f5059e5 100644
--- a/res/xml/captioning_settings.xml
+++ b/res/xml/captioning_settings.xml
@@ -21,12 +21,11 @@
android:persistent="false"
android:title="@string/accessibility_captioning_title">
- <com.android.settingslib.widget.LayoutPreference
+ <com.android.settingslib.widget.IllustrationPreference
android:key="captions_preview"
- android:layout="@layout/accessibility_captions_preview"
android:persistent="false"
android:selectable="false"
- android:title="@string/summary_placeholder"
+ settings:lottie_rawRes="@drawable/accessibility_captions_banner"
settings:searchable="false" />
<com.android.settings.widget.SettingsMainSwitchPreference
diff --git a/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java
index de90374..044c9d7 100644
--- a/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java
+++ b/src/com/android/settings/accessibility/AccessibilityButtonFooterPreferenceController.java
@@ -33,8 +33,14 @@
}
@Override
- protected String getLabelName() {
- return mContext.getString(R.string.accessibility_button_title);
+ protected String getLearnMoreContentDescription() {
+ return mContext.getString(
+ R.string.accessibility_button_gesture_footer_learn_more_content_description);
+ }
+
+ @Override
+ protected String getIntroductionTitle() {
+ return mContext.getString(R.string.accessibility_button_about_title);
}
@Override
diff --git a/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java
index 0e65ac5..498b767 100644
--- a/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java
+++ b/src/com/android/settings/accessibility/AccessibilityControlTimeoutFooterPreferenceController.java
@@ -31,8 +31,14 @@
}
@Override
- protected String getLabelName() {
- return mContext.getString(R.string.accessibility_setting_item_control_timeout_title);
+ protected String getLearnMoreContentDescription() {
+ return mContext.getString(
+ R.string.accessibility_control_timeout_footer_learn_more_content_description);
+ }
+
+ @Override
+ protected String getIntroductionTitle() {
+ return mContext.getString(R.string.accessibility_control_timeout_about_title);
}
@Override
diff --git a/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java b/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java
index e3422e4..08e5906 100644
--- a/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java
+++ b/src/com/android/settings/accessibility/AccessibilityFooterPreferenceController.java
@@ -21,14 +21,18 @@
import androidx.preference.PreferenceScreen;
-import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.HelpUtils;
/**
- * Base class for accessibility preference footer.
+ * Preference controller that controls the help link and customizes the preference title in {@link
+ * AccessibilityFooterPreference}.
*/
-public abstract class AccessibilityFooterPreferenceController extends BasePreferenceController {
+public class AccessibilityFooterPreferenceController extends BasePreferenceController {
+
+ private int mHelpResource;
+ private String mLearnMoreContentDescription;
+ private String mIntroductionTitle;
public AccessibilityFooterPreferenceController(Context context, String key) {
super(context, key);
@@ -49,23 +53,55 @@
}
/**
- * Override this if showing a help item in the footer bar, by returning the resource id.
+ * Setups a help item in the {@link AccessibilityFooterPreference} with specific content
+ * description.
+ */
+ public void setupHelpLink(int helpResource, String learnMoreContentDescription) {
+ mHelpResource = helpResource;
+ mLearnMoreContentDescription = learnMoreContentDescription;
+ }
+
+ /**
+ * Overrides this if showing a help item in the {@link AccessibilityFooterPreference}, by
+ * returning the resource id.
*
* @return the resource id for the help url
*/
protected int getHelpResource() {
- return 0;
+ return mHelpResource;
}
- /** Returns the accessibility feature name. */
- protected abstract String getLabelName();
+ /**
+ * Overrides this if showing a help item in the {@link AccessibilityFooterPreference} with
+ * specific content description.
+ *
+ * @return the content description for the help url
+ */
+ protected String getLearnMoreContentDescription() {
+ return mLearnMoreContentDescription;
+ }
+
+ /**
+ * Sets the announcement the specific features introduction in the {@link
+ * AccessibilityFooterPreference}.
+ */
+ public void setIntroductionTitle(String introductionTitle) {
+ mIntroductionTitle = introductionTitle;
+ }
+
+ /**
+ * Overrides this if announcement the specific features introduction in the {@link
+ * AccessibilityFooterPreference}.
+ *
+ * @return the extended content description for specific features introduction
+ */
+ protected String getIntroductionTitle() {
+ return mIntroductionTitle;
+ }
private void updateFooterPreferences(AccessibilityFooterPreference footerPreference) {
final StringBuffer sb = new StringBuffer();
- sb.append(mContext.getString(
- R.string.accessibility_introduction_title, getLabelName()))
- .append("\n\n")
- .append(footerPreference.getTitle());
+ sb.append(getIntroductionTitle()).append("\n\n").append(footerPreference.getTitle());
footerPreference.setContentDescription(sb);
if (getHelpResource() != 0) {
@@ -75,10 +111,10 @@
mContext.getClass().getName());
view.startActivityForResult(helpIntent, 0);
});
-
- final String learnMoreContentDescription = mContext.getString(
- R.string.footer_learn_more_content_description, getLabelName());
- footerPreference.setLearnMoreContentDescription(learnMoreContentDescription);
+ footerPreference.setLearnMoreContentDescription(getLearnMoreContentDescription());
+ footerPreference.setLinkEnabled(true);
+ } else {
+ footerPreference.setLinkEnabled(false);
}
}
}
diff --git a/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java b/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java
index 4e50b89..495d395 100644
--- a/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java
+++ b/src/com/android/settings/accessibility/CaptionFooterPreferenceController.java
@@ -30,12 +30,18 @@
}
@Override
- protected String getLabelName() {
- return mContext.getString(R.string.accessibility_captioning_title);
+ protected String getLearnMoreContentDescription() {
+ return mContext.getString(
+ R.string.accessibility_captioning_footer_learn_more_content_description);
}
@Override
- protected int getHelpResource() {
+ protected String getIntroductionTitle() {
+ return mContext.getString(R.string.accessibility_captioning_about_title);
+ }
+
+ @Override
+ protected int getHelpResource() {
return R.string.help_url_caption;
}
}
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index 9349071..0e209aa 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -55,7 +55,6 @@
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.password.ConfirmDeviceCredentialActivity;
-import com.android.settings.widget.SettingsMainSwitchPreference;
import com.android.settingslib.accessibility.AccessibilityUtils;
import java.util.List;
@@ -222,15 +221,6 @@
}
@Override
- protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
- final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
- final String switchBarText = (info == null) ? "" :
- getString(R.string.accessibility_service_primary_switch_title,
- info.getResolveInfo().loadLabel(getPackageManager()));
- switchPreference.setTitle(switchBarText);
- }
-
- @Override
protected void updateSwitchBarToggleSwitch() {
final boolean checked = isAccessibilityServiceEnabled();
if (mToggleServiceSwitchPreference.isChecked() == checked) {
diff --git a/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java b/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java
index 053fa9d..962ffec 100644
--- a/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java
+++ b/src/com/android/settings/accessibility/ToggleAutoclickFooterPreferenceController.java
@@ -31,8 +31,14 @@
}
@Override
- protected String getLabelName() {
- return mContext.getString(R.string.accessibility_autoclick_preference_title);
+ protected String getLearnMoreContentDescription() {
+ return mContext.getString(
+ R.string.accessibility_autoclick_footer_learn_more_content_description);
+ }
+
+ @Override
+ protected String getIntroductionTitle() {
+ return mContext.getString(R.string.accessibility_autoclick_about_title);
}
@Override
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index b41bafd..419514f 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -38,8 +38,7 @@
import java.util.List;
/** Settings page for color inversion. */
-public class ToggleColorInversionPreferenceFragment extends
- ToggleFeaturePreferenceFragment {
+public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment {
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
private final Handler mHandler = new Handler();
@@ -73,6 +72,11 @@
}
@Override
+ protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
+ shortcutPreference.setTitle(R.string.accessibility_display_inversion_shortcut_title);
+ }
+
+ @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mComponentName = COLOR_INVERSION_COMPONENT_NAME;
@@ -90,7 +94,20 @@
updateSwitchBarToggleSwitch();
}
};
- return super.onCreateView(inflater, container, savedInstanceState);
+
+ final View view = super.onCreateView(inflater, container, savedInstanceState);
+ updateFooterPreference();
+ return view;
+ }
+
+ private void updateFooterPreference() {
+ final String title = getPrefContext().getString(
+ R.string.accessibility_color_inversion_about_title);
+ final String learnMoreContentDescription = getPrefContext().getString(
+ R.string.accessibility_color_inversion_footer_learn_more_content_description);
+ mFooterPreferenceController.setIntroductionTitle(title);
+ mFooterPreferenceController.setupHelpLink(getHelpResource(), learnMoreContentDescription);
+ mFooterPreferenceController.displayPreference(getPreferenceScreen());
}
@Override
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 4bcf478..c9449d24 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -92,12 +92,20 @@
updateSwitchBarToggleSwitch();
}
};
- return super.onCreateView(inflater, container, savedInstanceState);
+
+ final View view = super.onCreateView(inflater, container, savedInstanceState);
+ updateFooterPreference();
+ return view;
}
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
+ private void updateFooterPreference() {
+ final String title = getPrefContext()
+ .getString(R.string.accessibility_daltonizer_about_title);
+ final String learnMoreContentDescription = getPrefContext()
+ .getString(R.string.accessibility_daltonizer_footer_learn_more_content_description);
+ mFooterPreferenceController.setIntroductionTitle(title);
+ mFooterPreferenceController.setupHelpLink(getHelpResource(), learnMoreContentDescription);
+ mFooterPreferenceController.displayPreference(getPreferenceScreen());
}
/** Customizes the order by preference key. */
@@ -168,6 +176,11 @@
}
@Override
+ protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
+ shortcutPreference.setTitle(R.string.accessibility_daltonizer_shortcut_title);
+ }
+
+ @Override
int getUserShortcutTypes() {
return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
mComponentName);
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 510f8d3..7cefced 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -57,7 +57,6 @@
import com.android.settings.utils.LocaleUtils;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settings.widget.SettingsMainSwitchPreference;
-import com.android.settingslib.HelpUtils;
import com.android.settingslib.accessibility.AccessibilityUtils;
import com.android.settingslib.widget.IllustrationPreference;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
@@ -78,6 +77,7 @@
protected SettingsMainSwitchPreference mToggleServiceSwitchPreference;
protected ShortcutPreference mShortcutPreference;
protected Preference mSettingsPreference;
+ protected AccessibilityFooterPreferenceController mFooterPreferenceController;
protected String mPreferenceKey;
protected CharSequence mSettingsTitle;
@@ -284,7 +284,14 @@
abstract int getUserShortcutTypes();
protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
- switchPreference.setTitle(R.string.accessibility_service_primary_switch_title);
+ final CharSequence title =
+ getString(R.string.accessibility_service_primary_switch_title, mPackageName);
+ switchPreference.setTitle(title);
+ }
+
+ protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
+ final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
+ shortcutPreference.setTitle(title);
}
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
@@ -434,8 +441,7 @@
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setOnClickCallback(this);
- final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
- mShortcutPreference.setTitle(title);
+ updateShortcutTitle(mShortcutPreference);
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
generalCategory.addPreference(mShortcutPreference);
@@ -463,33 +469,19 @@
final PreferenceScreen screen = getPreferenceScreen();
final CharSequence htmlDescription = Html.fromHtml(mHtmlDescription.toString(),
Html.FROM_HTML_MODE_COMPACT, mImageGetter, /* tagHandler= */ null);
- final String iconContentDescription =
- getString(R.string.accessibility_introduction_title, mPackageName);
final AccessibilityFooterPreference htmlFooterPreference =
new AccessibilityFooterPreference(screen.getContext());
htmlFooterPreference.setKey(KEY_HTML_DESCRIPTION_PREFERENCE);
htmlFooterPreference.setSummary(htmlDescription);
- htmlFooterPreference.setContentDescription(
- generateFooterContentDescription(htmlDescription));
-
- // Only framework tools support help link
- if (getHelpResource() != 0) {
- htmlFooterPreference.setLearnMoreAction(view -> {
- final Intent helpIntent = HelpUtils.getHelpIntent(
- getContext(), getContext().getString(getHelpResource()),
- getContext().getClass().getName());
- view.startActivityForResult(helpIntent, 0);
- });
-
- final String learnMoreContentDescription = getPrefContext().getString(
- R.string.footer_learn_more_content_description, mPackageName);
- htmlFooterPreference.setLearnMoreContentDescription(learnMoreContentDescription);
- htmlFooterPreference.setLinkEnabled(true);
- } else {
- htmlFooterPreference.setLinkEnabled(false);
- }
screen.addPreference(htmlFooterPreference);
+
+ // TODO(b/171272809): Migrate to DashboardFragment.
+ final String title = getString(R.string.accessibility_introduction_title, mPackageName);
+ mFooterPreferenceController = new AccessibilityFooterPreferenceController(
+ screen.getContext(), htmlFooterPreference.getKey());
+ mFooterPreferenceController.setIntroductionTitle(title);
+ mFooterPreferenceController.displayPreference(screen);
}
private void initFooterPreference() {
@@ -512,41 +504,22 @@
*
* @param screen The preference screen to add the footer preference
* @param summary The summary of the preference summary.
- * @param iconContentDescription The content description of icon in the footer.
+ * @param introductionTitle The title of introduction in the footer.
*/
@VisibleForTesting
void createFooterPreference(PreferenceScreen screen, CharSequence summary,
- String iconContentDescription) {
+ String introductionTitle) {
final AccessibilityFooterPreference footerPreference =
new AccessibilityFooterPreference(screen.getContext());
footerPreference.setSummary(summary);
- footerPreference.setContentDescription(
- generateFooterContentDescription(summary));
-
- // Only framework tools support help link
- if (getHelpResource() != 0) {
- footerPreference.setLearnMoreAction(view -> {
- final Intent helpIntent = HelpUtils.getHelpIntent(
- getContext(), getContext().getString(getHelpResource()),
- getContext().getClass().getName());
- view.startActivityForResult(helpIntent, 0);
- });
-
- final String learnMoreContentDescription = getPrefContext().getString(
- R.string.footer_learn_more_content_description, mPackageName);
- footerPreference.setLearnMoreContentDescription(learnMoreContentDescription);
- }
screen.addPreference(footerPreference);
+
+ mFooterPreferenceController = new AccessibilityFooterPreferenceController(
+ screen.getContext(), footerPreference.getKey());
+ mFooterPreferenceController.setIntroductionTitle(introductionTitle);
+ mFooterPreferenceController.displayPreference(screen);
}
- private CharSequence generateFooterContentDescription(CharSequence footerContent) {
- final StringBuffer sb = new StringBuffer();
- sb.append(getPrefContext().getString(
- R.string.accessibility_introduction_title, mPackageName))
- .append("\n\n")
- .append(footerContent);
- return sb;
- }
@VisibleForTesting
void setupEditShortcutDialog(Dialog dialog) {
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index e60751e..81bd45a 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -86,6 +86,7 @@
// Parent sets the title when creating the view, so set it after calling super
mToggleServiceSwitchPreference.setTitle(R.string.reduce_bright_colors_switch_title);
updateGeneralCategoryOrder();
+ updateFooterPreference();
return view;
}
@@ -101,6 +102,12 @@
generalCategory.addPreference(persist);
}
+ private void updateFooterPreference() {
+ final String title = getPrefContext().getString(R.string.reduce_bright_colors_about_title);
+ mFooterPreferenceController.setIntroductionTitle(title);
+ mFooterPreferenceController.displayPreference(getPreferenceScreen());
+ }
+
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@@ -135,7 +142,6 @@
return R.xml.reduce_bright_colors_settings;
}
-
@Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled);
@@ -155,6 +161,11 @@
}
@Override
+ protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
+ shortcutPreference.setTitle(R.string.reduce_bright_colors_shortcut_title);
+ }
+
+ @Override
int getUserShortcutTypes() {
return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
mComponentName);
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 9266f72..4f25430 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -95,7 +95,20 @@
removeDialog(DialogEnums.EDIT_SHORTCUT);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
};
- return super.onCreateView(inflater, container, savedInstanceState);
+
+ final View view = super.onCreateView(inflater, container, savedInstanceState);
+ updateFooterPreference();
+ return view;
+ }
+
+ private void updateFooterPreference() {
+ final String title = getPrefContext().getString(
+ R.string.accessibility_screen_magnification_about_title);
+ final String learnMoreContentDescription = getPrefContext().getString(
+ R.string.accessibility_screen_magnification_footer_learn_more_content_description);
+ mFooterPreferenceController.setIntroductionTitle(title);
+ mFooterPreferenceController.setupHelpLink(getHelpResource(), learnMoreContentDescription);
+ mFooterPreferenceController.displayPreference(getPreferenceScreen());
}
@Override
@@ -397,6 +410,11 @@
}
@Override
+ protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
+ shortcutPreference.setTitle(R.string.accessibility_screen_magnification_shortcut_title);
+ }
+
+ @Override
protected void updateShortcutPreference() {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
diff --git a/src/com/android/settings/fuelgauge/BatteryEntry.java b/src/com/android/settings/fuelgauge/BatteryEntry.java
index 0478c8b..5c9d071 100644
--- a/src/com/android/settings/fuelgauge/BatteryEntry.java
+++ b/src/com/android/settings/fuelgauge/BatteryEntry.java
@@ -572,7 +572,8 @@
name = context.getResources().getString(R.string.process_kernel_label);
} else if ("mediaserver".equals(name)) {
name = context.getResources().getString(R.string.process_mediaserver_label);
- } else if ("dex2oat".equals(name)) {
+ } else if ("dex2oat".equals(name) || "dex2oat32".equals(name) ||
+ "dex2oat64".equals(name)) {
name = context.getResources().getString(R.string.process_dex2oat_label);
}
return new NameAndIcon(name, icon, 0 /* iconId */);
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index 7c69618..afbb71f 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -19,8 +19,11 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.database.ContentObserver;
+import android.net.Uri;
import android.os.BatteryManager;
import android.os.Bundle;
+import android.os.Handler;
import android.provider.SearchIndexableResource;
import android.util.Log;
@@ -31,6 +34,7 @@
import com.android.settings.R;
import com.android.settings.SettingsActivity;
+import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -63,6 +67,17 @@
private BatteryChartPreferenceController mBatteryChartPreferenceController;
private BatteryAppListPreferenceController mBatteryAppListPreferenceController;
+ private final ContentObserver mBatteryObserver =
+ new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ Log.d(TAG, "onBatteryContentChange: " + selfChange);
+ mIsChartDataLoaded = false;
+ restartBatteryStatsLoader(
+ BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
+ }
+ };
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -104,6 +119,20 @@
super.onPause();
// Resets the flag to reload usage data in onResume() callback.
mIsChartDataLoaded = false;
+ final Uri uri = mPowerUsageFeatureProvider.getBatteryHistoryUri();
+ if (uri != null) {
+ getContext().getContentResolver().unregisterContentObserver(mBatteryObserver);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ final Uri uri = mPowerUsageFeatureProvider.getBatteryHistoryUri();
+ if (uri != null) {
+ getContext().getContentResolver().registerContentObserver(
+ uri, /*notifyForDescendants*/ true, mBatteryObserver);
+ }
}
@Override
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 61abe6b..d914825 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.content.Intent;
+import android.net.Uri;
import android.util.SparseIntArray;
import com.android.internal.os.BatterySipper;
@@ -141,4 +142,9 @@
* Returns battery history data with corresponding timestamp key.
*/
Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context);
+
+ /**
+ * Returns {@link Uri} to monitor battery history data is update.
+ */
+ Uri getBatteryHistoryUri();
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 1dcdab0..895bbb2 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.net.Uri;
import android.os.Process;
import android.util.SparseIntArray;
@@ -167,4 +168,9 @@
public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
return null;
}
+
+ @Override
+ public Uri getBatteryHistoryUri() {
+ return null;
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java
new file mode 100644
index 0000000..d6c8d99
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.accessibility;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.PreferenceViewHolder;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Tests for {@link AccessibilityFooterPreferenceController}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class AccessibilityFooterPreferenceControllerTest {
+
+ private static final String TEST_KEY = "test_pref_key";
+ private static final String TEST_TITLE = "test_title";
+ private static final String TEST_INTRODUCTION_TITLE = "test_introduction_title";
+ private static final String TEST_CONTENT_DESCRIPTION = "test_content_description";
+ private static final int TEST_HELP_ID = 12345;
+
+ @Rule
+ public final MockitoRule mockito = MockitoJUnit.rule();
+
+ @Spy
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ private PreferenceScreen mScreen;
+ private AccessibilityFooterPreferenceController mController;
+ private AccessibilityFooterPreference mPreference;
+ private PreferenceViewHolder mPreferenceViewHolder;
+
+ @Before
+ public void setUp() {
+ mController = new AccessibilityFooterPreferenceController(mContext, TEST_KEY);
+ mPreference = new AccessibilityFooterPreference(mContext);
+ mPreference.setKey(TEST_KEY);
+ mPreference.setTitle(TEST_TITLE);
+
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final View view = inflater.inflate(R.layout.preference_footer, null);
+ mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
+ mPreference.onBindViewHolder(mPreferenceViewHolder);
+
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void setIntroductionTitle_setCorrectIntroductionTitle() {
+ mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE);
+
+ assertThat(mController.getIntroductionTitle()).isEqualTo(TEST_INTRODUCTION_TITLE);
+ }
+
+ @Test
+ public void onBindViewHolder_setIntroductionTitle_setCorrectIntroductionTitle() {
+ mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE);
+ mController.displayPreference(mScreen);
+
+ mPreference.onBindViewHolder(mPreferenceViewHolder);
+
+ final TextView summaryView = (TextView) mPreferenceViewHolder
+ .findViewById(android.R.id.title);
+ assertThat(summaryView.getContentDescription().toString())
+ .contains(TEST_INTRODUCTION_TITLE);
+ }
+
+ @Test
+ public void setupHelpLink_setCorrectHelpLinkAndContentDescription() {
+ mController.setupHelpLink(TEST_HELP_ID, TEST_CONTENT_DESCRIPTION);
+
+ assertThat(mController.getHelpResource()).isEqualTo(TEST_HELP_ID);
+ assertThat(mController.getLearnMoreContentDescription())
+ .isEqualTo(TEST_CONTENT_DESCRIPTION);
+ }
+
+ @Test
+ public void onBindViewHolder_setupHelpLink_setCorrectHelpLinkAndContentDescription() {
+ mController.setupHelpLink(TEST_HELP_ID, TEST_CONTENT_DESCRIPTION);
+ mController.displayPreference(mScreen);
+
+ mPreference.onBindViewHolder(mPreferenceViewHolder);
+
+ final TextView learnMoreView = (TextView) mPreferenceViewHolder
+ .findViewById(com.android.settingslib.R.id.settingslib_learn_more);
+ assertThat(learnMoreView.getContentDescription().toString())
+ .contains(TEST_CONTENT_DESCRIPTION);
+ assertThat(mPreference.isLinkEnabled()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryAppListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryAppListPreferenceControllerTest.java
index 1faa75f..c3b3075 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryAppListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryAppListPreferenceControllerTest.java
@@ -25,6 +25,7 @@
import android.content.Context;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.os.UserManager;
import android.text.format.DateUtils;
@@ -72,11 +73,14 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ final Resources resources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(resources);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
-
+ when(resources.getTextArray(R.array.allowlist_hide_summary_in_battery_usage))
+ .thenReturn(new String[] {"com.android.googlequicksearchbox"});
FakeFeatureFactory.setupForTest();
mPreference = new PowerGaugePreference(mContext);
@@ -119,7 +123,7 @@
public void testSetUsageSummary_timeMoreThanOneMinute_GoogleApp_shouldNotSetScreenSummary() {
when(mBatteryEntry.getTimeInForegroundMs()).thenReturn(2 * DateUtils.MINUTE_IN_MILLIS);
when(mBatteryEntry.getDefaultPackageName())
- .thenReturn("com.google.android.googlequicksearchbox");
+ .thenReturn("com.android.googlequicksearchbox");
doReturn(mContext.getText(R.string.battery_used_for)).when(mFragment).getText(
R.string.battery_used_for);
doReturn(mContext).when(mFragment).getContext();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
index ef76eee..fd4e82d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
@@ -101,8 +101,11 @@
mFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
mContext = spy(RuntimeEnvironment.application);
- mContext.getResources().getConfiguration().setLocales(
- new LocaleList(new Locale("en_US")));
+ final Resources resources = spy(mContext.getResources());
+ resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
+ doReturn(resources).when(mContext).getResources();
+ doReturn(new String[] {"com.android.googlequicksearchbox"})
+ .when(resources).getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mPrefContext = mContext;
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
@@ -467,7 +470,7 @@
spy(createBatteryDiffEntry(
/*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
/*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
- doReturn("com.google.android.googlequicksearchbox").when(batteryDiffEntry)
+ doReturn("com.android.googlequicksearchbox").when(batteryDiffEntry)
.getPackageName();
mBatteryChartPreferenceController.setPreferenceSummary(pref, batteryDiffEntry);
@@ -678,7 +681,7 @@
// Verifies the item which is defined in the array list.
assertThat(mBatteryChartPreferenceController
- .isValidToShowSummary("com.google.android.googlequicksearchbox"))
+ .isValidToShowSummary("com.android.googlequicksearchbox"))
.isFalse();
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
index 96f0ec7..c1b1761 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
@@ -22,6 +22,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -36,6 +37,7 @@
import android.os.UserManager;
import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryEntry.NameAndIcon;
import org.junit.Before;
import org.junit.Rule;
@@ -64,6 +66,7 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mMockContext;
+ private Context mContext;
@Mock private Handler mockHandler;
@Mock private PackageManager mockPackageManager;
@Mock private UserManager mockUserManager;
@@ -71,6 +74,7 @@
@Before
public void stubContextToReturnMockPackageManager() {
+ mContext = spy(RuntimeEnvironment.application);
when(mMockContext.getPackageManager()).thenReturn(mockPackageManager);
}
@@ -248,4 +252,77 @@
final String key = entry.getKey();
assertThat(key).isEqualTo("U|2");
}
+
+ @Test
+ public void getNameAndIconFromUserId_nullUserInfo_returnDefaultNameAndIcon() {
+ final int userId = 1001;
+ doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class);
+ doReturn(null).when(mockUserManager).getUserInfo(userId);
+
+ final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUserId(
+ mContext, userId);
+ assertThat(nameAndIcon.name).isEqualTo(getString(
+ R.string.running_process_item_removed_user_label));
+ assertThat(nameAndIcon.icon).isNull();
+ }
+
+ @Test
+ public void getNameAndIconFromUid_rerturnExpectedName() {
+ final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUid(
+ mContext, /* name */ null, /* uid */ 0);
+ assertThat(nameAndIcon.name).isEqualTo(getString(R.string.process_kernel_label));
+
+ assertNameAndIcon("mediaserver", R.string.process_mediaserver_label);
+ assertNameAndIcon("dex2oat32", R.string.process_dex2oat_label);
+ assertNameAndIcon("dex2oat64", R.string.process_dex2oat_label);
+ assertNameAndIcon("dex2oat", R.string.process_dex2oat_label);
+ }
+
+ @Test
+ public void getNameAndIconFromPowerComponent_rerturnExpectedNameAndIcon() {
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY,
+ R.string.ambient_display_screen_title,
+ R.drawable.ic_settings_aod);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_BLUETOOTH,
+ R.string.power_bluetooth,
+ com.android.internal.R.drawable.ic_settings_bluetooth);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_CAMERA,
+ R.string.power_camera,
+ R.drawable.ic_settings_camera);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO,
+ R.string.power_cell,
+ R.drawable.ic_cellular_1_bar);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_FLASHLIGHT,
+ R.string.power_flashlight,
+ R.drawable.ic_settings_display);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_PHONE,
+ R.string.power_phone,
+ R.drawable.ic_settings_voice_calls);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_SCREEN,
+ R.string.power_screen,
+ R.drawable.ic_settings_display);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_WIFI,
+ R.string.power_wifi,
+ R.drawable.ic_settings_wireless);
+ assertNameAndIcon(BatteryConsumer.POWER_COMPONENT_IDLE,
+ R.string.power_idle,
+ R.drawable.ic_settings_phone_idle);
+ }
+
+ private void assertNameAndIcon(String name, int stringId) {
+ final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUid(
+ mContext, name, /* uid */ 1000);
+ assertThat(nameAndIcon.name).isEqualTo(getString(stringId));
+ }
+
+ private void assertNameAndIcon(int powerComponentId, int stringId, int iconId) {
+ final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromPowerComponent(
+ mContext, powerComponentId);
+ assertThat(nameAndIcon.name).isEqualTo(getString(stringId));
+ assertThat(nameAndIcon.iconId).isEqualTo(iconId);
+ }
+
+ private String getString(int stringId) {
+ return mContext.getResources().getString(stringId);
+ }
}