Merge "Import translations. DO NOT MERGE"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 99013f0..4300e58 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -70,7 +70,7 @@
<uses-permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY" />
<uses-permission android:name="android.permission.CONFIGURE_DISPLAY_COLOR_MODE" />
<uses-permission android:name="android.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS" />
- <uses-permission android:name="android.permission.SET_TIME" />
+ <uses-permission android:name="android.permission.SUGGEST_MANUAL_TIME_AND_ZONE" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATIONS" />
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
@@ -1387,6 +1387,8 @@
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
</activity>
<activity
@@ -2763,6 +2765,8 @@
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
</activity>
<activity
@@ -2787,6 +2791,8 @@
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
</activity>
<activity
@@ -2810,6 +2816,8 @@
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
</activity>
<activity android:name="Settings$ManageAppExternalSourcesActivity"
diff --git a/res/layout/accessibility_shortcut_secondary_action.xml b/res/layout/accessibility_shortcut_secondary_action.xml
index caf9b1c..1b575da 100644
--- a/res/layout/accessibility_shortcut_secondary_action.xml
+++ b/res/layout/accessibility_shortcut_secondary_action.xml
@@ -31,19 +31,14 @@
android:gravity="start|center_vertical"
android:focusable="true"
android:clickable="true"
- android:background="?android:attr/selectableItemBackground"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+ android:background="?android:attr/selectableItemBackground">
<FrameLayout
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="start|center_vertical"
+ android:layout_height="match_parent"
+ android:layout_marginEnd="16dp"
android:minWidth="56dp"
android:orientation="horizontal"
- android:paddingRight="16dp"
- android:paddingTop="4dp"
- android:paddingBottom="4dp"
android:focusable="false"
android:clickable="false">
diff --git a/res/layout/daltonizer_preview.xml b/res/layout/daltonizer_preview.xml
new file mode 100644
index 0000000..24c0f76
--- /dev/null
+++ b/res/layout/daltonizer_preview.xml
@@ -0,0 +1,29 @@
+<?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:id="@+id/preview_viewport"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <com.android.settings.accessibility.PaletteListView
+ android:id="@+id/palette_listView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:contentDescription="@null" />
+
+</FrameLayout>
diff --git a/res/layout/palette_listview_item.xml b/res/layout/palette_listview_item.xml
new file mode 100644
index 0000000..e8cc940
--- /dev/null
+++ b/res/layout/palette_listview_item.xml
@@ -0,0 +1,31 @@
+<?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="wrap_content"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/item_textview"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="10dp"
+ android:textSize="20dp"
+ android:maxLength="20"
+ android:singleLine="true"/>
+
+</FrameLayout>
diff --git a/res/values-night/colors.xml b/res/values-night/colors.xml
index b1f9dfb..c88158b 100644
--- a/res/values-night/colors.xml
+++ b/res/values-night/colors.xml
@@ -22,11 +22,21 @@
<color name="homepage_card_dismissal_background">@*android:color/material_grey_900</color>
<color name="contextual_card_background">@*android:color/material_grey_900</color>
<color name="search_bar_background">@*android:color/material_grey_800</color>
- <!-- Dialog background color -->
+ <!-- Dialog background color. -->
<color name="dialog_background">@*android:color/material_grey_800</color>
<color name="notification_importance_selection_bg">@*android:color/material_grey_800</color>
<color name="notification_importance_button_selected">#AECBFA</color> <!-- material blue 200 -->
<color name="notification_importance_button_unselected">#5F6368</color>
<color name="face_intro_outline">?android:attr/colorAccent</color>
+ <!-- Palette list preference colors. -->
+ <color name="palette_list_gradient_background">@android:color/black</color>
+ <color name="palette_list_color_red">@color/palette_list_dark_mode_color_red</color>
+ <color name="palette_list_color_orange">@color/palette_list_dark_mode_color_orange</color>
+ <color name="palette_list_color_yellow">@color/palette_list_dark_mode_color_yellow</color>
+ <color name="palette_list_color_green">@color/palette_list_dark_mode_color_green</color>
+ <color name="palette_list_color_cyan">@color/palette_list_dark_mode_color_cyan</color>
+ <color name="palette_list_color_blue">@color/palette_list_dark_mode_color_blue</color>
+ <color name="palette_list_color_purple">@color/palette_list_dark_mode_color_purple</color>
+ <color name="palette_list_color_pink">@color/palette_list_dark_mode_color_pink</color>
</resources>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index f1b2626..e302905 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -23,19 +23,19 @@
strings. --> <skip />
<!-- The time zone picker screen has two levels. The first level allows the user to choose a region. -->
<string-array name="timezone_filters">
- <!-- The next level of the time zoner picker should show time zones from the Americas. -->
+ <!-- The next level of the time zoner picker should show time zones from the Americas. -->
<item>America</item>
- <!-- The next level of the time zoner picker should show time zones from Europe. -->
+ <!-- The next level of the time zoner picker should show time zones from Europe. -->
<item>Europe</item>
- <!-- The next level of the time zoner picker should show time zones from Africa. -->
+ <!-- The next level of the time zoner picker should show time zones from Africa. -->
<item>Africa</item>
- <!-- The next level of the time zoner picker should show time zones from Asia. -->
+ <!-- The next level of the time zoner picker should show time zones from Asia. -->
<item>Asia</item>
- <!-- The next level of the time zoner picker should show time zones from Australia. -->
+ <!-- The next level of the time zoner picker should show time zones from Australia. -->
<item>Australia</item>
- <!-- The next level of the time zoner picker should show time zones from Pacific. -->
+ <!-- The next level of the time zoner picker should show time zones from Pacific. -->
<item>Pacific</item>
- <!-- The next level of the time zoner picker should show time zones from ALL regions. -->
+ <!-- The next level of the time zoner picker should show time zones from ALL regions. -->
<item>All</item>
</string-array>
@@ -274,8 +274,8 @@
<item>Require all non-trusted certificate statuses</item>
</string-array>
- <!-- Wi-Fi AP band settings. Either Auto, 2.4GHz or 5GHz. -->
- <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
+ <!-- Wi-Fi AP band settings. Either Auto, 2.4GHz or 5GHz. -->
+ <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
<string-array translatable="false" name="wifi_ap_band_config_full">
<item>1</item>
<item>2</item>
@@ -301,8 +301,8 @@
<item>@string/wifi_ap_choose_2G</item>
</string-array>
- <!-- Wi-Fi WPS setup for p2p connections. -->
- <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
+ <!-- Wi-Fi WPS setup for p2p connections. -->
+ <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
<string-array name="wifi_p2p_wps_setup">
<!-- Push button based configuration involves pushing a button on two connecting devices [CHAR LIMIT=30]-->
<item>Push button</item>
@@ -320,7 +320,7 @@
<item>Unsuccessful</item>
<item>Available</item>
<item>Out-of-range</item>
- </string-array>
+ </string-array>
<!-- Bluetooth Settings -->
@@ -410,7 +410,7 @@
</string-array>
<!-- Wi-Fi IP settings. -->
- <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
+ <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
<string-array name="wifi_ip_settings">
<!-- Use DHCP (Dynamic Host Configuration Protocol) for obtaining IP settings [CHAR LIMIT=25] -->
<item>DHCP</item>
@@ -1432,15 +1432,15 @@
<!-- WiFi calling mode array -->
<string-array name="wifi_calling_mode_summaries" translatable="false">
- <item>@string/wifi_calling_mode_wifi_preferred_summary</item>
- <item>@string/wifi_calling_mode_cellular_preferred_summary</item>
- <item>@string/wifi_calling_mode_wifi_only_summary</item>
+ <item>@string/wifi_calling_mode_wifi_preferred_summary</item>
+ <item>@string/wifi_calling_mode_cellular_preferred_summary</item>
+ <item>@string/wifi_calling_mode_wifi_only_summary</item>
</string-array>
<!-- WiFi calling mode array without wifi only mode -->
<string-array name="wifi_calling_mode_summaries_without_wifi_only" translatable="false">
- <item>@string/wifi_calling_mode_wifi_preferred_summary</item>
- <item>@string/wifi_calling_mode_cellular_preferred_summary</item>
+ <item>@string/wifi_calling_mode_wifi_preferred_summary</item>
+ <item>@string/wifi_calling_mode_cellular_preferred_summary</item>
</string-array>
<!-- Carrier variant of Enhaced 4G LTE Mode title. [CHAR LIMIT=NONE] -->
@@ -1469,4 +1469,27 @@
<item>"com.google.android.googlequicksearchbox"</item>
</string-array>
-</resources>
+ <!-- Array of titles palette list for accessibility. -->
+ <string-array name="setting_palette_colors" translatable="false" >
+ <item>@string/color_red</item>
+ <item>@string/color_orange</item>
+ <item>@string/color_yellow</item>
+ <item>@string/color_green</item>
+ <item>@string/color_cyan</item>
+ <item>@string/color_blue</item>
+ <item>@string/color_purple</item>
+ <item>@string/color_pink</item>
+ </string-array>
+
+ <!-- Values for palette list view preference. -->
+ <array name="setting_palette_data" translatable="false" >
+ <item>@color/palette_list_color_red</item>
+ <item>@color/palette_list_color_orange</item>
+ <item>@color/palette_list_color_yellow</item>
+ <item>@color/palette_list_color_green</item>
+ <item>@color/palette_list_color_cyan</item>
+ <item>@color/palette_list_color_blue</item>
+ <item>@color/palette_list_color_purple</item>
+ <item>@color/palette_list_color_pink</item>
+ </array>
+</resources>
\ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 3fd77e8..1c18c6a 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -148,4 +148,26 @@
<color name="face_intro_outline">#ffdadce0</color>
<color name="back_gesture_indicator">#4182ef</color>
+
+ <!-- Palette list preference colors. -->
+ <color name="palette_list_gradient_background">@android:color/white</color>
+ <color name="palette_list_color_red">#d93025</color> <!-- Material Red 600 -->
+ <color name="palette_list_color_orange">#e8710a</color> <!-- Material Orange 600 -->
+ <color name="palette_list_color_yellow">#f9ab00</color> <!-- Material Yellow 600 -->
+ <color name="palette_list_color_green">#1e8e3e</color> <!-- Material Green 600 -->
+ <color name="palette_list_color_cyan">#12b5cb</color> <!-- Material Cyan 600 -->
+ <color name="palette_list_color_blue">#1a73e8</color> <!-- Material Blue 600 -->
+ <color name="palette_list_color_purple">#9334e6</color> <!-- Material Purple 600 -->
+ <color name="palette_list_color_pink">#e52592</color> <!-- Material Pink 600 -->
+
+ <!-- Palette list preference dark mode colors. -->
+ <color name="palette_list_dark_mode_color_red">#f28b82</color> <!-- Material Red 300 -->
+ <color name="palette_list_dark_mode_color_orange">#fcad70</color> <!-- Material Orange 300 -->
+ <color name="palette_list_dark_mode_color_yellow">#fdd663</color> <!-- Material Yellow 300 -->
+ <color name="palette_list_dark_mode_color_green">#81c995</color> <!-- Material Green 300 -->
+ <color name="palette_list_dark_mode_color_cyan">#78d9ec</color> <!-- Material Cyan 300 -->
+ <color name="palette_list_dark_mode_color_blue">#8AB4F8</color> <!-- Material Blue 300 -->
+ <color name="palette_list_dark_mode_color_purple">#c58af9</color> <!-- Material Purple 300 -->
+ <color name="palette_list_dark_mode_color_pink">#ff8bcb</color> <!-- Material Pink 300 -->
+
</resources>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 74f4621..885d57c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -694,7 +694,7 @@
<!-- In the security screen, the header title for settings related to Passwords-->
<string name="security_passwords_title">Privacy</string>
<!-- Summary for settings preference disabled by administrator [CHAR LIMIT=50] -->
- <string name="disabled_by_administrator_summary">Disabled by admin</string>
+ <string name="disabled_by_administrator_summary">Not available</string>
<!-- In the security screen, the header title for security statuses -->
<string name="security_status_title">Security status</string>
<!-- Summary for Security settings, explaining a few important settings under it [CHAR LIMIT=NONE] -->
@@ -2091,6 +2091,10 @@
<string name="wifi_dpp_wifi_password">Wi\u2011Fi password: <xliff:g id="password" example="my password">%1$s</xliff:g></string>
<!-- Hint for Wi-Fi hotspot password [CHAR LIMIT=50] -->
<string name="wifi_dpp_hotspot_password">Hotspot password: <xliff:g id="password" example="my password">%1$s</xliff:g></string>
+ <!-- Label for specifying if a Wi-Fi network supports auto connection [CHAR LIMIT=50] -->
+ <string name="wifi_auto_connect_title">Auto\u2011connect</string>
+ <!-- Hint for Wi-Fi Auto-connect [CHAR LIMIT=NONE] -->
+ <string name="wifi_auto_connect_summary">Allow connection to this network when in range</string>
<!-- Label for "Use a QR code to add a device to this network" [CHAR LIMIT=50] -->
<string name="wifi_dpp_add_device">Add device</string>
<!-- Hint for "Add device" [CHAR LIMIT=NONE] -->
@@ -7228,6 +7232,8 @@
<string name="color_orange">Orange</string>
<!-- Purple label. [CHAR LIMIT=40] -->
<string name="color_purple">Purple</string>
+ <!-- Pink label. [CHAR LIMIT=40] -->
+ <string name="color_pink">Pink</string>
<!-- Message informing the user that no SIM card is inserted [CHAR LIMIT=60] -->
<string name="sim_no_inserted_msg">No SIM cards inserted</string>
<!-- SIM status title [CHAR LIMIT=40] -->
diff --git a/res/xml/accessibility_daltonizer_settings.xml b/res/xml/accessibility_daltonizer_settings.xml
index 22e0510..75386f5 100644
--- a/res/xml/accessibility_daltonizer_settings.xml
+++ b/res/xml/accessibility_daltonizer_settings.xml
@@ -21,6 +21,13 @@
android:persistent="false"
android:title="@string/accessibility_display_daltonizer_preference_title">
+ <com.android.settings.accessibility.PaletteListPreference
+ android:key="daltonizer_preview"
+ android:persistent="false"
+ android:selectable="false"
+ android:title="@string/summary_placeholder"
+ settings:searchable="false"/>
+
<com.android.settingslib.widget.RadioButtonPreference
android:key="daltonizer_mode_deuteranomaly"
android:persistent="false"
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 9a4add4..acd50ad 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -303,6 +303,13 @@
android:entries="@array/bluetooth_avrcp_versions"
android:entryValues="@array/bluetooth_avrcp_version_values" />
+ <ListPreference
+ android:key="bluetooth_select_map_version"
+ android:title="@string/bluetooth_select_map_version_string"
+ android:dialogTitle="@string/bluetooth_select_map_version_dialog_title"
+ android:entries="@array/bluetooth_map_versions"
+ android:entryValues="@array/bluetooth_map_version_values" />
+
<SwitchPreference
android:key="bluetooth_hd_audio_settings"
android:title="@string/bluetooth_profile_a2dp_high_quality_unknown_codec"/>
diff --git a/res/xml/wifi_network_details_fragment2.xml b/res/xml/wifi_network_details_fragment2.xml
new file mode 100644
index 0000000..3058678
--- /dev/null
+++ b/res/xml/wifi_network_details_fragment2.xml
@@ -0,0 +1,141 @@
+<?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.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ settings:initialExpandedChildrenCount="5">
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="connection_header"
+ android:layout="@layout/settings_entity_header"
+ android:selectable="false"
+ android:order="-10000"
+ settings:allowDividerBelow="true"/>
+
+ <com.android.settings.datausage.DataUsageSummaryPreference
+ android:key="status_header"
+ android:selectable="false"
+ settings:isPreferenceVisible="false"/>
+
+ <!-- Buttons -->
+ <com.android.settingslib.widget.ActionButtonsPreference
+ android:key="buttons"
+ android:selectable="false" />
+
+ <!-- General Details Preferences -->
+ <Preference
+ android:key="signal_strength"
+ android:title="@string/wifi_signal"
+ android:selectable="false"
+ settings:allowDividerAbove="true"/>
+
+ <Preference
+ android:key="frequency"
+ android:icon="@drawable/ic_frequency_antenna"
+ android:title="@string/wifi_frequency"
+ android:selectable="false"/>
+
+ <Preference
+ android:key="security"
+ android:icon="@drawable/ic_security_lock_24dp"
+ android:title="@string/wifi_security"
+ android:selectable="false"/>
+
+ <DropDownPreference
+ android:key="metered"
+ android:icon="@drawable/ic_attach_money_black_24dp"
+ android:title="@string/wifi_metered_title"
+ android:entries="@array/wifi_metered_entries"
+ android:entryValues="@array/wifi_metered_values"/>
+
+ <DropDownPreference
+ android:key="privacy"
+ android:icon="@drawable/ic_wifi_privacy_24dp"
+ android:title="@string/wifi_privacy_settings"
+ android:entries="@array/wifi_privacy_entries"
+ android:entryValues="@array/wifi_privacy_values"/>
+
+ <SwitchPreference
+ android:key="auto_connect"
+ android:title="@string/wifi_auto_connect_title"
+ android:summary="@string/wifi_auto_connect_summary"
+ settings:allowDividerAbove="true"/>
+
+ <!-- Add device Preference -->
+ <Preference
+ android:key="add_device_to_network"
+ android:title="@string/wifi_dpp_add_device"
+ android:summary="@string/wifi_dpp_connect_network_using_qr_code"
+ settings:allowDividerAbove="true"/>
+
+ <!-- Network Details -->
+ <PreferenceCategory
+ android:key="ip_details_category"
+ android:title="@string/wifi_setup_detail">
+ <Preference
+ android:key="ssid"
+ android:title="@string/wifi_advanced_ssid_title"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ <Preference
+ android:key="mac_address"
+ android:title="@string/wifi_advanced_randomized_mac_address_title"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ <Preference
+ android:key="ip_address"
+ android:title="@string/wifi_ip_address"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ <Preference
+ android:key="gateway"
+ android:title="@string/wifi_gateway"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ <Preference
+ android:key="subnet_mask"
+ android:title="@string/wifi_details_subnet_mask"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ <Preference
+ android:key="dns"
+ android:title="@string/wifi_details_dns"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ <Preference
+ android:key="tx_link_speed"
+ android:title="@string/tx_wifi_speed"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ <Preference
+ android:key="rx_link_speed"
+ android:title="@string/rx_wifi_speed"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ </PreferenceCategory>
+
+ <!-- IPv6 Details -->
+ <PreferenceCategory
+ android:key="ipv6_category"
+ android:title="@string/wifi_details_ipv6_address_header"
+ android:selectable="false">
+ <Preference
+ android:key="ipv6_addresses"
+ android:selectable="false"
+ settings:enableCopying="true"/>
+ </PreferenceCategory>
+</PreferenceScreen>
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 4144914..2f198cf 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -749,7 +749,7 @@
| PackageManager.MATCH_ANY_USER);
return appInfo.loadLabel(context.getPackageManager());
} catch (PackageManager.NameNotFoundException e) {
- Log.w(TAG, "Unable to find info for package: " + packageName);
+ Log.e(TAG, "Unable to find info for package: " + packageName);
}
return null;
}
diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java
index 4b3a341..371afa1 100644
--- a/src/com/android/settings/accessibility/AccessibilityUtil.java
+++ b/src/com/android/settings/accessibility/AccessibilityUtil.java
@@ -19,16 +19,20 @@
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import android.accessibilityservice.AccessibilityServiceInfo;
+import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
+import android.text.TextUtils;
import androidx.annotation.IntDef;
+import androidx.annotation.NonNull;
import com.android.settings.R;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.StringJoiner;
/** Provides utility methods to accessibility settings only. */
final class AccessibilityUtil {
@@ -56,6 +60,12 @@
int INTUITIVE = 2;
}
+ // TODO(b/147021230): Will move common functions and variables to
+ // android/internal/accessibility folder
+ private static final char COMPONENT_NAME_SEPARATOR = ':';
+ private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
+ new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
+
/**
* Annotation for different shortcut type UI type.
*
@@ -69,14 +79,14 @@
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef({
- ShortcutType.DEFAULT,
- ShortcutType.SOFTWARE,
- ShortcutType.HARDWARE,
- ShortcutType.TRIPLETAP,
+ PreferredShortcutType.DEFAULT,
+ PreferredShortcutType.SOFTWARE,
+ PreferredShortcutType.HARDWARE,
+ PreferredShortcutType.TRIPLETAP,
})
/** Denotes the shortcut type. */
- public @interface ShortcutType {
+ public @interface PreferredShortcutType {
int DEFAULT = 0;
int SOFTWARE = 1; // 1 << 0
int HARDWARE = 2; // 1 << 1
@@ -129,7 +139,7 @@
}
/**
- * Gets the corresponding fragment type of a given accessibility service
+ * Gets the corresponding fragment type of a given accessibility service.
*
* @param accessibilityServiceInfo The accessibilityService's info
* @return int from {@link AccessibilityServiceFragmentType}
@@ -148,4 +158,112 @@
? AccessibilityServiceFragmentType.INVISIBLE
: AccessibilityServiceFragmentType.INTUITIVE;
}
+
+ /**
+ * Opts in component name into colon-separated {@code shortcutType} key's string in Settings.
+ *
+ * @param context The current context.
+ * @param shortcutType The preferred shortcut type user selected.
+ * @param componentName The component name that need to be opted in Settings.
+ */
+ static void optInValueToSettings(Context context, @PreferredShortcutType int shortcutType,
+ @NonNull ComponentName componentName) {
+ final String targetKey = convertKeyFromSettings(shortcutType);
+ final String targetString = Settings.Secure.getString(context.getContentResolver(),
+ targetKey);
+
+ if (TextUtils.isEmpty(targetString)) {
+ return;
+ }
+
+ if (hasValueInSettings(context, shortcutType, componentName)) {
+ return;
+ }
+
+ final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
+
+ joiner.add(targetString);
+ joiner.add(componentName.flattenToString());
+
+ Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
+ }
+
+ /**
+ * Opts out component name into colon-separated {@code shortcutType} key's string in Settings.
+ *
+ * @param context The current context.
+ * @param shortcutType The preferred shortcut type user selected.
+ * @param componentName The component name that need to be opted out from Settings.
+ */
+ static void optOutValueFromSettings(Context context, @PreferredShortcutType int shortcutType,
+ @NonNull ComponentName componentName) {
+ final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
+ final String targetKey = convertKeyFromSettings(shortcutType);
+ final String targetString = Settings.Secure.getString(context.getContentResolver(),
+ targetKey);
+
+ if (TextUtils.isEmpty(targetString)) {
+ return;
+ }
+
+ sStringColonSplitter.setString(targetString);
+ while (sStringColonSplitter.hasNext()) {
+ final String name = sStringColonSplitter.next();
+ if (TextUtils.isEmpty(name) || (componentName.flattenToString()).equals(name)) {
+ continue;
+ }
+ joiner.add(name);
+ }
+
+ Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
+ }
+
+ /**
+ * Returns if component name existed in Settings.
+ *
+ * @param context The current context.
+ * @param shortcutType The preferred shortcut type user selected.
+ * @param componentName The component name that need to be checked existed in Settings.
+ * @return {@code true} if componentName existed in Settings.
+ */
+ static boolean hasValueInSettings(Context context, @PreferredShortcutType int shortcutType,
+ @NonNull ComponentName componentName) {
+ final String targetKey = convertKeyFromSettings(shortcutType);
+ final String targetString = Settings.Secure.getString(context.getContentResolver(),
+ targetKey);
+
+ if (TextUtils.isEmpty(targetString)) {
+ return false;
+ }
+
+ sStringColonSplitter.setString(targetString);
+
+ while (sStringColonSplitter.hasNext()) {
+ final String name = sStringColonSplitter.next();
+ if ((componentName.flattenToString()).equals(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Converts {@link PreferredShortcutType} to key in Settings.
+ *
+ * @param shortcutType The shortcut type.
+ * @return Mapping key in Settings.
+ */
+ static String convertKeyFromSettings(@PreferredShortcutType int shortcutType) {
+ switch (shortcutType) {
+ case PreferredShortcutType.SOFTWARE:
+ return Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
+ case PreferredShortcutType.HARDWARE:
+ return Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
+ case PreferredShortcutType.TRIPLETAP:
+ return Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED;
+ default:
+ throw new IllegalArgumentException(
+ "Unsupported preferredShortcutType " + shortcutType);
+ }
+ }
}
diff --git a/src/com/android/settings/accessibility/PaletteListPreference.java b/src/com/android/settings/accessibility/PaletteListPreference.java
new file mode 100644
index 0000000..c75da7f
--- /dev/null
+++ b/src/com/android/settings/accessibility/PaletteListPreference.java
@@ -0,0 +1,88 @@
+/*
+ * 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.accessibility;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.widget.FrameLayout;
+import android.widget.ListView;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+
+import com.android.settingslib.widget.R;
+
+/** Preference that easier preview by matching name to color. */
+public class PaletteListPreference extends Preference {
+
+ /**
+ * Constructs a new PaletteListPreference with the given context's theme and the supplied
+ * attribute set.
+ *
+ * @param context The Context this is associated with, through which it can access the current
+ * theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ */
+ public PaletteListPreference(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ /**
+ * Constructs a new PaletteListPreference with the given context's theme, the supplied
+ * attribute set, and default style attribute.
+ *
+ * @param context The Context this is associated with, through which it can access the
+ * current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ * @param defStyleAttr An attribute in the current theme that contains a reference to a style
+ * resource that supplies default
+ * values for the view. Can be 0 to not look for
+ * defaults.
+ */
+ public PaletteListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ setLayoutResource(R.layout.daltonizer_preview);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ final View rootView = holder.itemView;
+ final ListView listView = rootView.findViewById(R.id.palette_listView);
+ listView.getViewTreeObserver().addOnGlobalLayoutListener(
+ new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ final int listViewHeight = listView.getMeasuredHeight();
+ final int listViewWidth = listView.getMeasuredWidth();
+ // Removes the callback after get result of measure view.
+ listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+
+ // Resets layout parameters to display whole items from listView.
+ final FrameLayout.LayoutParams layoutParams =
+ (FrameLayout.LayoutParams) listView.getLayoutParams();
+ layoutParams.height = listViewHeight * listView.getAdapter().getCount();
+ layoutParams.width = listViewWidth;
+ listView.setLayoutParams(layoutParams);
+ listView.invalidateViews();
+ }
+ });
+ }
+}
diff --git a/src/com/android/settings/accessibility/PaletteListView.java b/src/com/android/settings/accessibility/PaletteListView.java
new file mode 100644
index 0000000..0030817
--- /dev/null
+++ b/src/com/android/settings/accessibility/PaletteListView.java
@@ -0,0 +1,292 @@
+/*
+ * 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.accessibility;
+
+import android.annotation.NonNull;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Color;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.GradientDrawable.Orientation;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.view.Display;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settingslib.widget.R;
+
+import com.google.common.collect.Iterables;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Custom ListView {@link ListView} which displays palette to deploy the color code preview.
+ *
+ * <p>The preview shows gradient from color white to specific color code on each list view item, in
+ * addition, text view adjusts the attribute of width for adapting the text length.
+ *
+ * <p>The text cannot fills the whole view for ensuring the gradient color preview can purely
+ * display also the view background shows the color beside the text variable end point.
+ */
+public class PaletteListView extends ListView {
+ private static final float VIEW_PITCH = 0.05f;
+ private final Context mContext;
+ private final DisplayAdapter mDisplayAdapter;
+ private final LayoutInflater mLayoutInflater;
+ private final String mDefaultGradientColorCodeString;
+ private final int mDefaultGradientColor;
+ private float mTextBound;
+
+ public PaletteListView(Context context) {
+ this(context, null);
+ }
+
+ public PaletteListView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public PaletteListView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ mContext = context;
+ mDisplayAdapter = new DisplayAdapter();
+ mLayoutInflater = LayoutInflater.from(context);
+ mDefaultGradientColorCodeString =
+ getResources().getString(R.color.palette_list_gradient_background);
+ mDefaultGradientColor =
+ getResources().getColor(R.color.palette_list_gradient_background, null);
+ mTextBound = 0.0f;
+ init();
+ }
+
+ private static int getScreenWidth(WindowManager windowManager) {
+ final Display display = windowManager.getDefaultDisplay();
+ final DisplayMetrics displayMetrics = new DisplayMetrics();
+ display.getMetrics(displayMetrics);
+ return displayMetrics.widthPixels;
+ }
+
+ private void init() {
+ final TypedArray colorNameArray = getResources().obtainTypedArray(
+ R.array.setting_palette_colors);
+ final TypedArray colorCodeArray = getResources().obtainTypedArray(
+ R.array.setting_palette_data);
+ final int colorNameArrayLength = colorNameArray.length();
+ final List<ColorAttributes> colorList = new ArrayList<>();
+ computeTextWidthBounds(colorNameArray);
+
+ for (int index = 0; index < colorNameArrayLength; index++) {
+ colorList.add(
+ new ColorAttributes(
+ /* colorName= */ colorNameArray.getString(index),
+ /* colorCode= */ colorCodeArray.getColor(index, mDefaultGradientColor),
+ /* textBound= */ mTextBound,
+ /* gradientDrawable= */
+ new GradientDrawable(Orientation.LEFT_RIGHT, null)));
+ }
+
+ mDisplayAdapter.setColorList(colorList);
+ setAdapter(mDisplayAdapter);
+ setDividerHeight(/* height= */ 0);
+ }
+
+ /**
+ * Sets string array that required the color name and color code for deploy the new color
+ * preview.
+ *
+ * <p>The parameters not allow null define but two array length inconsistent are acceptable, in
+ * addition, to prevent IndexOutOfBoundsException the algorithm will check array data, and base
+ * on the array size to display data, or fills color code array if length less than other.
+ *
+ * @param colorNames a string array of color name
+ * @param colorCodes a string array of color code
+ * @return true if new array data apply successful
+ */
+ @VisibleForTesting
+ boolean setPaletteListColors(@NonNull String[] colorNames, @NonNull String[] colorCodes) {
+ if (colorNames == null || colorCodes == null) {
+ return false;
+ }
+
+ final int colorNameArrayLength = colorNames.length;
+ final int colorCodeArrayLength = colorCodes.length;
+ final List<ColorAttributes> colorList = new ArrayList<>();
+ final String[] colorCodeArray = fillColorCodeArray(colorCodes, colorNameArrayLength,
+ colorCodeArrayLength);
+ computeTextWidthBounds(colorNames);
+
+ for (int index = 0; index < colorNameArrayLength; index++) {
+ colorList.add(
+ new ColorAttributes(
+ /* colorName= */ colorNames[index],
+ /* colorCode= */ Color.parseColor(colorCodeArray[index]),
+ /* textBound= */ mTextBound,
+ /* gradientDrawable= */
+ new GradientDrawable(Orientation.LEFT_RIGHT, null)));
+ }
+
+ mDisplayAdapter.setColorList(colorList);
+ mDisplayAdapter.notifyDataSetChanged();
+ return true;
+ }
+
+ private String[] fillColorCodeArray(String[] colorCodes, int colorNameArrayLength,
+ int colorCodeArrayLength) {
+ if (colorNameArrayLength == colorCodeArrayLength
+ || colorNameArrayLength < colorCodeArrayLength) {
+ return colorCodes;
+ }
+
+ final String[] colorCodeArray = new String[colorNameArrayLength];
+ for (int index = 0; index < colorNameArrayLength; index++) {
+ if (index < colorCodeArrayLength) {
+ colorCodeArray[index] = colorCodes[index];
+ } else {
+ colorCodeArray[index] = mDefaultGradientColorCodeString;
+ }
+ }
+ return colorCodeArray;
+ }
+
+ private void computeTextWidthBounds(TypedArray colorNameTypedArray) {
+ final int colorNameArrayLength = colorNameTypedArray.length();
+ final String[] colorNames = new String[colorNameArrayLength];
+ for (int index = 0; index < colorNameArrayLength; index++) {
+ colorNames[index] = colorNameTypedArray.getString(index);
+ }
+
+ measureBound(colorNames);
+ }
+
+ private void computeTextWidthBounds(String[] colorNameArray) {
+ final int colorNameArrayLength = colorNameArray.length;
+ final String[] colorNames = new String[colorNameArrayLength];
+ for (int index = 0; index < colorNameArrayLength; index++) {
+ colorNames[index] = colorNameArray[index];
+ }
+
+ measureBound(colorNames);
+ }
+
+ private void measureBound(String[] dataArray) {
+ final WindowManager windowManager = (WindowManager) mContext.getSystemService(
+ Context.WINDOW_SERVICE);
+ final View view = mLayoutInflater.inflate(R.layout.palette_listview_item, null);
+ final TextView textView = view.findViewById(R.id.item_textview);
+ final List<String> colorNameList = new ArrayList<>(Arrays.asList(dataArray));
+ Collections.sort(colorNameList, Comparator.comparing(String::length));
+ // Gets the last index of list which sort by text length.
+ textView.setText(Iterables.getLast(colorNameList));
+
+ final float textWidth = textView.getPaint().measureText(textView.getText().toString());
+ // Computes rate of text width compare to screen width, and measures the round the double
+ // to two decimal places manually.
+ final float textBound = Math.round(textWidth / getScreenWidth(windowManager) * 100) / 100f;
+ mTextBound = textBound + VIEW_PITCH;
+ }
+
+ private static class ViewHolder {
+ public TextView textView;
+ }
+
+ /** An adapter that converts color text title and color code to text views. */
+ private final class DisplayAdapter extends BaseAdapter {
+
+ private List<ColorAttributes> mColorList;
+
+ @Override
+ public int getCount() {
+ return mColorList.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mColorList.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ final ViewHolder viewHolder;
+ final ColorAttributes paletteAttribute = mColorList.get(position);
+ final String colorName = paletteAttribute.getColorName();
+ final GradientDrawable gradientDrawable = paletteAttribute.getGradientDrawable();
+
+ if (convertView == null) {
+ convertView = mLayoutInflater.inflate(R.layout.palette_listview_item, null);
+ viewHolder = new ViewHolder();
+ viewHolder.textView = convertView.findViewById(R.id.item_textview);
+ convertView.setTag(viewHolder);
+ } else {
+ viewHolder = (ViewHolder) convertView.getTag();
+ }
+
+ viewHolder.textView.setText(colorName);
+ viewHolder.textView.setBackground(gradientDrawable);
+ return convertView;
+ }
+
+ protected void setColorList(List<ColorAttributes> colorList) {
+ mColorList = colorList;
+ }
+ }
+
+ private final class ColorAttributes {
+ private final int mColorIndex = 2; // index for inject color.
+ private final int mColorOffsetIndex = 1; // index for offset effect.
+ private final String mColorName;
+ private final GradientDrawable mGradientDrawable;
+ private final int[] mGradientColors =
+ {/* startColor=*/ mDefaultGradientColor, /* centerColor=*/ mDefaultGradientColor,
+ /* endCode= */ 0};
+ private final float[] mGradientOffsets =
+ {/* starOffset= */ 0.0f, /* centerOffset= */ 0.5f, /* endOffset= */ 1.0f};
+
+ ColorAttributes(
+ String colorName, int colorCode, float textBound,
+ GradientDrawable gradientDrawable) {
+ mGradientColors[mColorIndex] = colorCode;
+ mGradientOffsets[mColorOffsetIndex] = textBound;
+ gradientDrawable.setColors(mGradientColors, mGradientOffsets);
+ mColorName = colorName;
+ mGradientDrawable = gradientDrawable;
+ }
+
+ public String getColorName() {
+ return mColorName;
+ }
+
+ public GradientDrawable getGradientDrawable() {
+ return mGradientDrawable;
+ }
+ }
+}
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index 269bc04..e53154a 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -47,7 +47,7 @@
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
-import com.android.settings.accessibility.AccessibilityUtil.ShortcutType;
+import com.android.settings.accessibility.AccessibilityUtil.PreferredShortcutType;
import com.android.settings.password.ConfirmDeviceCredentialActivity;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
@@ -64,11 +64,11 @@
ToggleFeaturePreferenceFragment implements ShortcutPreference.OnClickListener {
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
- private static final String EXTRA_SHORTCUT_TYPE = "shortcutType";
+ private static final String EXTRA_PREFERRED_SHORTCUT_TYPE = "preferred_shortcutType";
// TODO(b/142530063): Check the new setting key to decide which summary should be shown.
- private static final String KEY_SHORTCUT_TYPE = Settings.System.MASTER_MONO;
+ private static final String KEY_PREFERRED_SHORTCUT_TYPE = Settings.System.MASTER_MONO;
private ShortcutPreference mShortcutPreference;
- private int mShortcutType = ShortcutType.DEFAULT;
+ private int mPreferredShortcutType = PreferredShortcutType.DEFAULT;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
@@ -136,15 +136,16 @@
@Override
public void onSaveInstanceState(Bundle outState) {
- outState.putInt(EXTRA_SHORTCUT_TYPE, mShortcutType);
+ outState.putInt(EXTRA_PREFERRED_SHORTCUT_TYPE, mPreferredShortcutType);
super.onSaveInstanceState(outState);
}
@Override
public void onResume() {
+ super.onResume();
mSettingsContentObserver.register(getContentResolver());
updateSwitchBarToggleSwitch();
- super.onResume();
+ updateShortcutPreference();
}
@Override
@@ -225,8 +226,8 @@
}
private void updateAlertDialogCheckState() {
- updateCheckStatus(mSoftwareTypeCheckBox, ShortcutType.SOFTWARE);
- updateCheckStatus(mHardwareTypeCheckBox, ShortcutType.HARDWARE);
+ updateCheckStatus(mSoftwareTypeCheckBox, PreferredShortcutType.SOFTWARE);
+ updateCheckStatus(mHardwareTypeCheckBox, PreferredShortcutType.HARDWARE);
}
private void updateAlertDialogEnableState() {
@@ -240,48 +241,48 @@
}
}
- private void updateCheckStatus(CheckBox checkBox, @ShortcutType int type) {
- checkBox.setChecked((mShortcutType & type) == type);
+ private void updateCheckStatus(CheckBox checkBox, @PreferredShortcutType int type) {
+ checkBox.setChecked((mPreferredShortcutType & type) == type);
checkBox.setOnClickListener(v -> {
- updateShortcutType(false);
+ updatePreferredShortcutType(false);
updateAlertDialogEnableState();
});
}
- private void updateShortcutType(boolean saveToDB) {
- mShortcutType = ShortcutType.DEFAULT;
+ private void updatePreferredShortcutType(boolean saveToDB) {
+ mPreferredShortcutType = PreferredShortcutType.DEFAULT;
if (mSoftwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.SOFTWARE;
+ mPreferredShortcutType |= PreferredShortcutType.SOFTWARE;
}
if (mHardwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.HARDWARE;
+ mPreferredShortcutType |= PreferredShortcutType.HARDWARE;
}
if (saveToDB) {
- setShortcutType(mShortcutType);
+ setPreferredShortcutType(mPreferredShortcutType);
}
}
- private void setSecureIntValue(String key, @ShortcutType int value) {
+ private void setSecureIntValue(String key, @PreferredShortcutType int value) {
Settings.Secure.putIntForUser(getPrefContext().getContentResolver(),
key, value, getPrefContext().getContentResolver().getUserId());
}
- private void setShortcutType(@ShortcutType int type) {
- setSecureIntValue(KEY_SHORTCUT_TYPE, type);
+ private void setPreferredShortcutType(@PreferredShortcutType int type) {
+ setSecureIntValue(KEY_PREFERRED_SHORTCUT_TYPE, type);
}
private String getShortcutTypeSummary(Context context) {
- final int shortcutType = getShortcutType(context);
+ final int shortcutType = getPreferredShortcutType(context);
final CharSequence softwareTitle =
context.getText(AccessibilityUtil.isGestureNavigateEnabled(context)
? R.string.accessibility_shortcut_edit_dialog_title_software_gesture
: R.string.accessibility_shortcut_edit_dialog_title_software);
List<CharSequence> list = new ArrayList<>();
- if ((shortcutType & ShortcutType.SOFTWARE) == ShortcutType.SOFTWARE) {
+ if ((shortcutType & PreferredShortcutType.SOFTWARE) == PreferredShortcutType.SOFTWARE) {
list.add(softwareTitle);
}
- if ((shortcutType & ShortcutType.HARDWARE) == ShortcutType.HARDWARE) {
+ if ((shortcutType & PreferredShortcutType.HARDWARE) == PreferredShortcutType.HARDWARE) {
final CharSequence hardwareTitle = context.getText(
R.string.accessibility_shortcut_edit_dialog_title_hardware);
list.add(hardwareTitle);
@@ -295,20 +296,22 @@
return AccessibilityUtil.capitalize(joinStrings);
}
- @ShortcutType
- private int getShortcutType(Context context) {
- return getSecureIntValue(context, KEY_SHORTCUT_TYPE, ShortcutType.SOFTWARE);
+ @PreferredShortcutType
+ private int getPreferredShortcutType(Context context) {
+ return getSecureIntValue(context, KEY_PREFERRED_SHORTCUT_TYPE,
+ PreferredShortcutType.SOFTWARE);
}
- @ShortcutType
- private int getSecureIntValue(Context context, String key, @ShortcutType int defaultValue) {
+ @PreferredShortcutType
+ private int getSecureIntValue(Context context, String key,
+ @PreferredShortcutType int defaultValue) {
return Settings.Secure.getIntForUser(
context.getContentResolver(),
key, defaultValue, context.getContentResolver().getUserId());
}
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
- updateShortcutType(true);
+ updatePreferredShortcutType(true);
mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext()));
}
@@ -339,12 +342,13 @@
}
private void initShortcutPreference(Bundle savedInstanceState) {
- // Restore the Shortcut type
+ // Restore the PreferredShortcut type
if (savedInstanceState != null) {
- mShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE, ShortcutType.DEFAULT);
+ mPreferredShortcutType = savedInstanceState.getInt(EXTRA_PREFERRED_SHORTCUT_TYPE,
+ PreferredShortcutType.DEFAULT);
}
- if (mShortcutType == ShortcutType.DEFAULT) {
- mShortcutType = getShortcutType(getPrefContext());
+ if (mPreferredShortcutType == PreferredShortcutType.DEFAULT) {
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
}
// Initial ShortcutPreference widget
@@ -353,17 +357,31 @@
preferenceScreen.getContext(), null);
mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey());
- mShortcutPreference.setOrder(-1);
mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
- mShortcutPreference.setOnClickListener(this);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
+ mShortcutPreference.setOnClickListener(this);
// Put the shortcutPreference before settingsPreference.
mShortcutPreference.setOrder(-1);
- preferenceScreen.addPreference(mShortcutPreference);
// TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
+ preferenceScreen.addPreference(mShortcutPreference);
}
- public String getShortcutPreferenceKey() {
+ private void updateShortcutPreference() {
+ final PreferenceScreen preferenceScreen = getPreferenceScreen();
+ ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
+ getShortcutPreferenceKey());
+
+ if (shortcutPreference != null) {
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ shortcutPreference.setChecked(
+ AccessibilityUtil.hasValueInSettings(getContext(),
+ PreferredShortcutType.SOFTWARE,
+ mComponentName));
+ }
+ }
+
+ protected String getShortcutPreferenceKey() {
return KEY_SHORTCUT_PREFERENCE;
}
@@ -464,15 +482,21 @@
@Override
public void onCheckboxClicked(ShortcutPreference preference) {
if (preference.getChecked()) {
- // TODO(b/142530063): Enable shortcut when checkbox is checked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ AccessibilityUtil.optInValueToSettings(getContext(), PreferredShortcutType.SOFTWARE,
+ mComponentName);
} else {
- // TODO(b/142530063): Disable shortcut when checkbox is unchecked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ AccessibilityUtil.optOutValueFromSettings(getContext(), PreferredShortcutType.SOFTWARE,
+ mComponentName);
}
}
@Override
public void onSettingsClicked(ShortcutPreference preference) {
- mShortcutType = getShortcutType(getPrefContext());
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
showDialog(DialogType.EDIT_SHORTCUT);
}
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index 1c7a5f3..c32248d 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -16,8 +16,11 @@
package com.android.settings.accessibility;
+import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME;
+
import android.app.Dialog;
import android.app.settings.SettingsEnums;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
@@ -36,7 +39,7 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.accessibility.AccessibilityUtil.ShortcutType;
+import com.android.settings.accessibility.AccessibilityUtil.PreferredShortcutType;
import com.android.settings.accessibility.AccessibilityUtil.State;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
@@ -62,7 +65,7 @@
private final Handler mHandler = new Handler();
private ShortcutPreference mShortcutPreference;
private SettingsContentObserver mSettingsContentObserver;
- private int mShortcutType = ShortcutType.DEFAULT;
+ private int mPreferredShortcutType = PreferredShortcutType.DEFAULT;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
@@ -139,11 +142,17 @@
@Override
public void onSaveInstanceState(Bundle outState) {
- outState.putInt(EXTRA_SHORTCUT_TYPE, mShortcutType);
+ outState.putInt(EXTRA_SHORTCUT_TYPE, mPreferredShortcutType);
super.onSaveInstanceState(outState);
}
@Override
+ public void onResume() {
+ super.onResume();
+ updateShortcutPreference();
+ }
+
+ @Override
public Dialog onCreateDialog(int dialogId) {
if (dialogId == DIALOG_ID_EDIT_SHORTCUT) {
final CharSequence dialogTitle = getActivity().getString(
@@ -167,8 +176,8 @@
}
private void updateAlertDialogCheckState() {
- updateCheckStatus(mSoftwareTypeCheckBox, ShortcutType.SOFTWARE);
- updateCheckStatus(mHardwareTypeCheckBox, ShortcutType.HARDWARE);
+ updateCheckStatus(mSoftwareTypeCheckBox, PreferredShortcutType.SOFTWARE);
+ updateCheckStatus(mHardwareTypeCheckBox, PreferredShortcutType.HARDWARE);
}
private void updateAlertDialogEnableState() {
@@ -182,48 +191,48 @@
}
}
- private void updateCheckStatus(CheckBox checkBox, @ShortcutType int type) {
- checkBox.setChecked((mShortcutType & type) == type);
+ private void updateCheckStatus(CheckBox checkBox, @PreferredShortcutType int type) {
+ checkBox.setChecked((mPreferredShortcutType & type) == type);
checkBox.setOnClickListener(v -> {
- updateShortcutType(false);
+ updatePreferredShortcutType(false);
updateAlertDialogEnableState();
});
}
- private void updateShortcutType(boolean saveToDB) {
- mShortcutType = ShortcutType.DEFAULT;
+ private void updatePreferredShortcutType(boolean saveToDB) {
+ mPreferredShortcutType = PreferredShortcutType.DEFAULT;
if (mSoftwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.SOFTWARE;
+ mPreferredShortcutType |= PreferredShortcutType.SOFTWARE;
}
if (mHardwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.HARDWARE;
+ mPreferredShortcutType |= PreferredShortcutType.HARDWARE;
}
if (saveToDB) {
- setShortcutType(mShortcutType);
+ setPreferredShortcutType(mPreferredShortcutType);
}
}
- private void setSecureIntValue(String key, @ShortcutType int value) {
+ private void setSecureIntValue(String key, @PreferredShortcutType int value) {
Settings.Secure.putIntForUser(getPrefContext().getContentResolver(),
key, value, getPrefContext().getContentResolver().getUserId());
}
- private void setShortcutType(@ShortcutType int type) {
+ private void setPreferredShortcutType(@PreferredShortcutType int type) {
setSecureIntValue(KEY_SHORTCUT_TYPE, type);
}
private String getShortcutTypeSummary(Context context) {
- final int shortcutType = getShortcutType(context);
+ final int shortcutType = getPreferredShortcutType(context);
final CharSequence softwareTitle =
context.getText(AccessibilityUtil.isGestureNavigateEnabled(context)
? R.string.accessibility_shortcut_edit_dialog_title_software_gesture
: R.string.accessibility_shortcut_edit_dialog_title_software);
List<CharSequence> list = new ArrayList<>();
- if ((shortcutType & ShortcutType.SOFTWARE) == ShortcutType.SOFTWARE) {
+ if ((shortcutType & PreferredShortcutType.SOFTWARE) == PreferredShortcutType.SOFTWARE) {
list.add(softwareTitle);
}
- if ((shortcutType & ShortcutType.HARDWARE) == ShortcutType.HARDWARE) {
+ if ((shortcutType & PreferredShortcutType.HARDWARE) == PreferredShortcutType.HARDWARE) {
final CharSequence hardwareTitle = context.getText(
R.string.accessibility_shortcut_edit_dialog_title_hardware);
list.add(hardwareTitle);
@@ -237,20 +246,21 @@
return AccessibilityUtil.capitalize(joinStrings);
}
- @ShortcutType
- private int getShortcutType(Context context) {
- return getSecureIntValue(context, KEY_SHORTCUT_TYPE, ShortcutType.SOFTWARE);
+ @PreferredShortcutType
+ private int getPreferredShortcutType(Context context) {
+ return getSecureIntValue(context, KEY_SHORTCUT_TYPE, PreferredShortcutType.SOFTWARE);
}
- @ShortcutType
- private int getSecureIntValue(Context context, String key, @ShortcutType int defaultValue) {
+ @PreferredShortcutType
+ private int getSecureIntValue(Context context, String key,
+ @PreferredShortcutType int defaultValue) {
return Settings.Secure.getIntForUser(
context.getContentResolver(),
key, defaultValue, context.getContentResolver().getUserId());
}
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
- updateShortcutType(true);
+ updatePreferredShortcutType(true);
mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext()));
}
@@ -264,12 +274,13 @@
}
private void initShortcutPreference(Bundle savedInstanceState) {
- // Restore the Shortcut type
+ // Restore the PreferredShortcut type
if (savedInstanceState != null) {
- mShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE, ShortcutType.DEFAULT);
+ mPreferredShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
+ PreferredShortcutType.DEFAULT);
}
- if (mShortcutType == ShortcutType.DEFAULT) {
- mShortcutType = getShortcutType(getPrefContext());
+ if (mPreferredShortcutType == PreferredShortcutType.DEFAULT) {
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
}
// Initial ShortcutPreference widget
@@ -277,33 +288,58 @@
mShortcutPreference = new ShortcutPreference(
preferenceScreen.getContext(), null);
final Preference previewPreference = findPreference(PREVIEW_PREFERENCE_KEY);
- // Put the shortcutPreference before radioButtonPreference.
mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
- mShortcutPreference.setOnClickListener(this);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
+ mShortcutPreference.setOnClickListener(this);
+ // Put the shortcutPreference before previewPreference.
mShortcutPreference.setOrder(previewPreference.getOrder() - 1);
- preferenceScreen.addPreference(mShortcutPreference);
// TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
+ preferenceScreen.addPreference(mShortcutPreference);
}
- public String getShortcutPreferenceKey() {
+ private void updateShortcutPreference() {
+ final PreferenceScreen preferenceScreen = getPreferenceScreen();
+ final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
+ getShortcutPreferenceKey());
+
+ if (shortcutPreference != null) {
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ shortcutPreference.setChecked(
+ AccessibilityUtil.hasValueInSettings(getContext(),
+ PreferredShortcutType.SOFTWARE,
+ getComponentName()));
+ }
+ }
+
+ private String getShortcutPreferenceKey() {
return KEY_SHORTCUT_PREFERENCE;
}
+ private ComponentName getComponentName() {
+ return COLOR_INVERSION_COMPONENT_NAME;
+ }
+
@Override
public void onCheckboxClicked(ShortcutPreference preference) {
if (preference.getChecked()) {
- // TODO(b/142530063): Enable shortcut when checkbox is checked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ AccessibilityUtil.optInValueToSettings(getContext(), PreferredShortcutType.SOFTWARE,
+ getComponentName());
} else {
- // TODO(b/142530063): Disable shortcut when checkbox is unchecked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ AccessibilityUtil.optOutValueFromSettings(getContext(), PreferredShortcutType.SOFTWARE,
+ getComponentName());
}
}
@Override
public void onSettingsClicked(ShortcutPreference preference) {
- mShortcutType = getShortcutType(getPrefContext());
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
showDialog(DIALOG_ID_EDIT_SHORTCUT);
}
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 7fb05da..7a77b91 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -16,8 +16,11 @@
package com.android.settings.accessibility;
+import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME;
+
import android.app.Dialog;
import android.app.settings.SettingsEnums;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
@@ -35,7 +38,7 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.accessibility.AccessibilityUtil.ShortcutType;
+import com.android.settings.accessibility.AccessibilityUtil.PreferredShortcutType;
import com.android.settings.accessibility.AccessibilityUtil.State;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
@@ -57,10 +60,11 @@
private static final String EXTRA_SHORTCUT_TYPE = "shortcutType";
// TODO(b/142530063): Check the new setting key to decide which summary should be shown.
private static final String KEY_SHORTCUT_TYPE = Settings.System.MASTER_MONO;
+ private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private static final int DIALOG_ID_EDIT_SHORTCUT = 1;
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
private ShortcutPreference mShortcutPreference;
- private int mShortcutType = ShortcutType.DEFAULT;
+ private int mPreferredShortcutType = PreferredShortcutType.DEFAULT;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
@@ -95,7 +99,7 @@
@Override
public void onSaveInstanceState(Bundle outState) {
- outState.putInt(EXTRA_SHORTCUT_TYPE, mShortcutType);
+ outState.putInt(EXTRA_SHORTCUT_TYPE, mPreferredShortcutType);
super.onSaveInstanceState(outState);
}
@@ -108,6 +112,7 @@
((DaltonizerRadioButtonPreferenceController) controller).displayPreference(
getPreferenceScreen());
}
+ updateShortcutPreference();
}
@Override
@@ -143,8 +148,8 @@
}
private void updateAlertDialogCheckState() {
- updateCheckStatus(mSoftwareTypeCheckBox, ShortcutType.SOFTWARE);
- updateCheckStatus(mHardwareTypeCheckBox, ShortcutType.HARDWARE);
+ updateCheckStatus(mSoftwareTypeCheckBox, PreferredShortcutType.SOFTWARE);
+ updateCheckStatus(mHardwareTypeCheckBox, PreferredShortcutType.HARDWARE);
}
private void updateAlertDialogEnableState() {
@@ -158,48 +163,48 @@
}
}
- private void updateCheckStatus(CheckBox checkBox, @ShortcutType int type) {
- checkBox.setChecked((mShortcutType & type) == type);
+ private void updateCheckStatus(CheckBox checkBox, @PreferredShortcutType int type) {
+ checkBox.setChecked((mPreferredShortcutType & type) == type);
checkBox.setOnClickListener(v -> {
- updateShortcutType(false);
+ updatePreferredShortcutType(false);
updateAlertDialogEnableState();
});
}
- private void updateShortcutType(boolean saveToDB) {
- mShortcutType = ShortcutType.DEFAULT;
+ private void updatePreferredShortcutType(boolean saveToDB) {
+ mPreferredShortcutType = PreferredShortcutType.DEFAULT;
if (mSoftwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.SOFTWARE;
+ mPreferredShortcutType |= PreferredShortcutType.SOFTWARE;
}
if (mHardwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.HARDWARE;
+ mPreferredShortcutType |= PreferredShortcutType.HARDWARE;
}
if (saveToDB) {
- setShortcutType(mShortcutType);
+ setPreferredShortcutType(mPreferredShortcutType);
}
}
- private void setSecureIntValue(String key, @ShortcutType int value) {
+ private void setSecureIntValue(String key, @PreferredShortcutType int value) {
Settings.Secure.putIntForUser(getPrefContext().getContentResolver(),
key, value, getPrefContext().getContentResolver().getUserId());
}
- private void setShortcutType(@ShortcutType int type) {
+ private void setPreferredShortcutType(@PreferredShortcutType int type) {
setSecureIntValue(KEY_SHORTCUT_TYPE, type);
}
private String getShortcutTypeSummary(Context context) {
- final int shortcutType = getShortcutType(context);
+ final int shortcutType = getPreferredShortcutType(context);
final CharSequence softwareTitle =
context.getText(AccessibilityUtil.isGestureNavigateEnabled(context)
? R.string.accessibility_shortcut_edit_dialog_title_software_gesture
: R.string.accessibility_shortcut_edit_dialog_title_software);
List<CharSequence> list = new ArrayList<>();
- if ((shortcutType & ShortcutType.SOFTWARE) == ShortcutType.SOFTWARE) {
+ if ((shortcutType & PreferredShortcutType.SOFTWARE) == PreferredShortcutType.SOFTWARE) {
list.add(softwareTitle);
}
- if ((shortcutType & ShortcutType.HARDWARE) == ShortcutType.HARDWARE) {
+ if ((shortcutType & PreferredShortcutType.HARDWARE) == PreferredShortcutType.HARDWARE) {
final CharSequence hardwareTitle = context.getText(
R.string.accessibility_shortcut_edit_dialog_title_hardware);
list.add(hardwareTitle);
@@ -213,20 +218,21 @@
return AccessibilityUtil.capitalize(joinStrings);
}
- @ShortcutType
- private int getShortcutType(Context context) {
- return getSecureIntValue(context, KEY_SHORTCUT_TYPE, ShortcutType.SOFTWARE);
+ @PreferredShortcutType
+ private int getPreferredShortcutType(Context context) {
+ return getSecureIntValue(context, KEY_SHORTCUT_TYPE, PreferredShortcutType.SOFTWARE);
}
- @ShortcutType
- private int getSecureIntValue(Context context, String key, @ShortcutType int defaultValue) {
+ @PreferredShortcutType
+ private int getSecureIntValue(Context context, String key,
+ @PreferredShortcutType int defaultValue) {
return Settings.Secure.getIntForUser(
context.getContentResolver(),
key, defaultValue, context.getContentResolver().getUserId());
}
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
- updateShortcutType(true);
+ updatePreferredShortcutType(true);
mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext()));
}
@@ -288,39 +294,72 @@
@Override
public void onCheckboxClicked(ShortcutPreference preference) {
if (preference.getChecked()) {
- // TODO(b/142530063): Enable shortcut when checkbox is checked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ AccessibilityUtil.optInValueToSettings(getContext(), PreferredShortcutType.SOFTWARE,
+ getComponentName());
} else {
- // TODO(b/142530063): Disable shortcut when checkbox is unchecked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ AccessibilityUtil.optOutValueFromSettings(getContext(), PreferredShortcutType.SOFTWARE,
+ getComponentName());
}
}
@Override
public void onSettingsClicked(ShortcutPreference preference) {
- mShortcutType = getShortcutType(getPrefContext());
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
showDialog(DIALOG_ID_EDIT_SHORTCUT);
}
private void initShortcutPreference(Bundle savedInstanceState) {
- // Restore the Shortcut type
+ // Restore the PreferredShortcut type
if (savedInstanceState != null) {
- mShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE, ShortcutType.DEFAULT);
+ mPreferredShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
+ PreferredShortcutType.DEFAULT);
}
- if (mShortcutType == ShortcutType.DEFAULT) {
- mShortcutType = getShortcutType(getPrefContext());
+ if (mPreferredShortcutType == PreferredShortcutType.DEFAULT) {
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
}
// Initial ShortcutPreference widget
final PreferenceScreen preferenceScreen = getPreferenceScreen();
mShortcutPreference = new ShortcutPreference(
preferenceScreen.getContext(), null);
+ mShortcutPreference.setPersistent(false);
+ mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setTitle(R.string.accessibility_shortcut_title);
- mShortcutPreference.setOnClickListener(this);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
- // Put the shortcutPreference before radioButtonPreference.
+ mShortcutPreference.setOnClickListener(this);
final RadioButtonPreference radioButtonPreference = findPreference(PREFERENCE_KEY);
+ // Put the shortcutPreference before radioButtonPreference.
mShortcutPreference.setOrder(radioButtonPreference.getOrder() - 1);
- preferenceScreen.addPreference(mShortcutPreference);
// TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
+ preferenceScreen.addPreference(mShortcutPreference);
+ }
+
+ private void updateShortcutPreference() {
+ final PreferenceScreen preferenceScreen = getPreferenceScreen();
+ final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
+ getShortcutPreferenceKey());
+
+ if (shortcutPreference != null) {
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ shortcutPreference.setChecked(
+ AccessibilityUtil.hasValueInSettings(getContext(),
+ PreferredShortcutType.SOFTWARE,
+ getComponentName()));
+ }
+
+ }
+
+ private String getShortcutPreferenceKey() {
+ return KEY_SHORTCUT_PREFERENCE;
+ }
+
+ private ComponentName getComponentName() {
+ return DALTONIZER_COMPONENT_NAME;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 515d80c..8693690 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -16,6 +16,8 @@
package com.android.settings.accessibility;
+import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
+
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
@@ -45,13 +47,14 @@
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
-import com.android.settings.accessibility.AccessibilityUtil.ShortcutType;
+import com.android.settings.accessibility.AccessibilityUtil.PreferredShortcutType;
import com.android.settings.widget.SwitchBar;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
+import java.util.StringJoiner;
public class ToggleScreenMagnificationPreferenceFragment extends
ToggleFeaturePreferenceFragment implements SwitchBar.OnSwitchChangeListener,
@@ -62,10 +65,18 @@
// TODO(b/142530063): Check the new setting key to decide which summary should be shown.
private static final String KEY_SHORTCUT_TYPE = Settings.System.MASTER_MONO;
private ShortcutPreference mShortcutPreference;
- private int mShortcutType = ShortcutType.DEFAULT;
+ private int mPreferredShortcutType = PreferredShortcutType.DEFAULT;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
private CheckBox mTripleTapTypeCheckBox;
+ private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
+
+ // TODO(b/147021230): Will move common functions and variables to
+ // android/internal/accessibility folder. For now, magnification need to be treated
+ // individually.
+ private static final char COMPONENT_NAME_SEPARATOR = ':';
+ private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
+ new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
protected class VideoPreference extends Preference {
private ImageView mVideoBackgroundView;
@@ -187,7 +198,7 @@
@Override
public void onSaveInstanceState(Bundle outState) {
- outState.putInt(EXTRA_SHORTCUT_TYPE, mShortcutType);
+ outState.putInt(EXTRA_SHORTCUT_TYPE, mPreferredShortcutType);
super.onSaveInstanceState(outState);
}
@@ -201,6 +212,7 @@
}
updateConfigurationWarningIfNeeded();
+ updateShortcutPreference();
}
@Override
@@ -243,9 +255,9 @@
}
private void updateAlertDialogCheckState() {
- updateCheckStatus(mSoftwareTypeCheckBox, ShortcutType.SOFTWARE);
- updateCheckStatus(mHardwareTypeCheckBox, ShortcutType.HARDWARE);
- updateCheckStatus(mTripleTapTypeCheckBox, ShortcutType.TRIPLETAP);
+ updateCheckStatus(mSoftwareTypeCheckBox, PreferredShortcutType.SOFTWARE);
+ updateCheckStatus(mHardwareTypeCheckBox, PreferredShortcutType.HARDWARE);
+ updateCheckStatus(mTripleTapTypeCheckBox, PreferredShortcutType.TRIPLETAP);
}
private void updateAlertDialogEnableState() {
@@ -262,57 +274,57 @@
}
}
- private void updateCheckStatus(CheckBox checkBox, @ShortcutType int type) {
- checkBox.setChecked((mShortcutType & type) == type);
+ private void updateCheckStatus(CheckBox checkBox, @PreferredShortcutType int type) {
+ checkBox.setChecked((mPreferredShortcutType & type) == type);
checkBox.setOnClickListener(v -> {
- updateShortcutType(false);
+ updatePreferredShortcutType(false);
updateAlertDialogEnableState();
});
}
- private void updateShortcutType(boolean saveToDB) {
- mShortcutType = ShortcutType.DEFAULT;
+ private void updatePreferredShortcutType(boolean saveToDB) {
+ mPreferredShortcutType = PreferredShortcutType.DEFAULT;
if (mSoftwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.SOFTWARE;
+ mPreferredShortcutType |= PreferredShortcutType.SOFTWARE;
}
if (mHardwareTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.HARDWARE;
+ mPreferredShortcutType |= PreferredShortcutType.HARDWARE;
}
if (mTripleTapTypeCheckBox.isChecked()) {
- mShortcutType |= ShortcutType.TRIPLETAP;
+ mPreferredShortcutType |= PreferredShortcutType.TRIPLETAP;
}
if (saveToDB) {
- setShortcutType(mShortcutType);
+ setPreferredShortcutType(mPreferredShortcutType);
}
}
- private void setSecureIntValue(String key, @ShortcutType int value) {
+ private void setSecureIntValue(String key, @PreferredShortcutType int value) {
Settings.Secure.putIntForUser(getPrefContext().getContentResolver(),
key, value, getPrefContext().getContentResolver().getUserId());
}
- private void setShortcutType(@ShortcutType int type) {
+ private void setPreferredShortcutType(@PreferredShortcutType int type) {
setSecureIntValue(KEY_SHORTCUT_TYPE, type);
}
private String getShortcutTypeSummary(Context context) {
- final int shortcutType = getShortcutType(context);
+ final int shortcutType = getPreferredShortcutType(context);
final CharSequence softwareTitle =
context.getText(AccessibilityUtil.isGestureNavigateEnabled(context)
? R.string.accessibility_shortcut_edit_dialog_title_software_gesture
: R.string.accessibility_shortcut_edit_dialog_title_software);
List<CharSequence> list = new ArrayList<>();
- if ((shortcutType & ShortcutType.SOFTWARE) == ShortcutType.SOFTWARE) {
+ if ((shortcutType & PreferredShortcutType.SOFTWARE) == PreferredShortcutType.SOFTWARE) {
list.add(softwareTitle);
}
- if ((shortcutType & ShortcutType.HARDWARE) == ShortcutType.HARDWARE) {
+ if ((shortcutType & PreferredShortcutType.HARDWARE) == PreferredShortcutType.HARDWARE) {
final CharSequence hardwareTitle = context.getText(
R.string.accessibility_shortcut_edit_dialog_title_hardware);
list.add(hardwareTitle);
}
- if ((shortcutType & ShortcutType.TRIPLETAP) == ShortcutType.TRIPLETAP) {
+ if ((shortcutType & PreferredShortcutType.TRIPLETAP) == PreferredShortcutType.TRIPLETAP) {
final CharSequence tripleTapTitle = context.getText(
R.string.accessibility_shortcut_edit_dialog_title_triple_tap);
list.add(tripleTapTitle);
@@ -326,20 +338,21 @@
return AccessibilityUtil.capitalize(joinStrings);
}
- @ShortcutType
- private int getShortcutType(Context context) {
- return getSecureIntValue(context, KEY_SHORTCUT_TYPE, ShortcutType.SOFTWARE);
+ @PreferredShortcutType
+ private int getPreferredShortcutType(Context context) {
+ return getSecureIntValue(context, KEY_SHORTCUT_TYPE, PreferredShortcutType.SOFTWARE);
}
- @ShortcutType
- private int getSecureIntValue(Context context, String key, @ShortcutType int defaultValue) {
+ @PreferredShortcutType
+ private int getSecureIntValue(Context context, String key,
+ @PreferredShortcutType int defaultValue) {
return Settings.Secure.getIntForUser(
context.getContentResolver(),
key, defaultValue, context.getContentResolver().getUserId());
}
private void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
- updateShortcutType(true);
+ updatePreferredShortcutType(true);
mShortcutPreference.setSummary(
getShortcutTypeSummary(getPrefContext()));
}
@@ -428,38 +441,67 @@
@Override
public void onCheckboxClicked(ShortcutPreference preference) {
if (preference.getChecked()) {
- // TODO(b/142530063): Enable shortcut when checkbox is checked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ // TODO(b/142531156): ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED need to be treated
+ // as special case in this file.
+ optInMagnificationValueToSettings(getContext(), PreferredShortcutType.SOFTWARE);
} else {
- // TODO(b/142530063): Disable shortcut when checkbox is unchecked.
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ // TODO(b/142531156): ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED need to be treated
+ // as special case in this file.
+ optOutMagnificationValueFromSettings(getContext(), PreferredShortcutType.SOFTWARE);
}
}
@Override
public void onSettingsClicked(ShortcutPreference preference) {
- mShortcutType = getShortcutType(getPrefContext());
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
showDialog(DialogType.EDIT_SHORTCUT);
}
private void initShortcutPreference(Bundle savedInstanceState) {
- // Restore the Shortcut type
+ // Restore the PreferredShortcut type
if (savedInstanceState != null) {
- mShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE, ShortcutType.DEFAULT);
+ mPreferredShortcutType = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
+ PreferredShortcutType.DEFAULT);
}
- if (mShortcutType == ShortcutType.DEFAULT) {
- mShortcutType = getShortcutType(getPrefContext());
+ if (mPreferredShortcutType == PreferredShortcutType.DEFAULT) {
+ mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
}
// Initial ShortcutPreference widget
final PreferenceScreen preferenceScreen = getPreferenceScreen();
mShortcutPreference = new ShortcutPreference(
preferenceScreen.getContext(), null);
+ mShortcutPreference.setPersistent(false);
+ mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setTitle(R.string.accessibility_magnification_shortcut_title);
- mShortcutPreference.setOnClickListener(this);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
+ mShortcutPreference.setOnClickListener(this);
// Put the shortcutPreference before videoPreference.
mShortcutPreference.setOrder(mVideoPreference.getOrder() - 1);
+ // TODO(b/142530063): Check the new setting key to decide which summary should be shown.
preferenceScreen.addPreference(mShortcutPreference);
- // TODO(b/142530063): Check the new key to decide whether checkbox should be checked.
+ }
+
+ private void updateShortcutPreference() {
+ final PreferenceScreen preferenceScreen = getPreferenceScreen();
+ final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
+ getShortcutPreferenceKey());
+
+ if (shortcutPreference != null) {
+ // TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
+ // preferred key.
+ shortcutPreference.setChecked(
+ hasMagnificationValueInSettings(getContext(),
+ PreferredShortcutType.SOFTWARE));
+ }
+ }
+
+ private String getShortcutPreferenceKey() {
+ return KEY_SHORTCUT_PREFERENCE;
}
private void updateConfigurationWarningIfNeeded() {
@@ -479,4 +521,68 @@
int EDIT_SHORTCUT = 3;
}
+ private static void optInMagnificationValueToSettings(Context context,
+ @PreferredShortcutType int shortcutType) {
+ final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
+ final String targetString = Settings.Secure.getString(context.getContentResolver(),
+ targetKey);
+
+ if (TextUtils.isEmpty(targetString)) {
+ return;
+ }
+
+ if (hasMagnificationValueInSettings(context, shortcutType)) {
+ return;
+ }
+
+ final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
+
+ joiner.add(Settings.Secure.getString(context.getContentResolver(), targetKey));
+ joiner.add(MAGNIFICATION_CONTROLLER_NAME);
+
+ Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
+ }
+
+ private static void optOutMagnificationValueFromSettings(Context context,
+ @PreferredShortcutType int shortcutType) {
+ final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
+ final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
+ final String targetString = Settings.Secure.getString(context.getContentResolver(),
+ targetKey);
+
+ if (TextUtils.isEmpty(targetString)) {
+ return;
+ }
+
+ sStringColonSplitter.setString(targetString);
+ while (sStringColonSplitter.hasNext()) {
+ final String name = sStringColonSplitter.next();
+ if (TextUtils.isEmpty(name) || MAGNIFICATION_CONTROLLER_NAME.equals(name)) {
+ continue;
+ }
+ joiner.add(name);
+ }
+
+ Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
+ }
+
+ private static boolean hasMagnificationValueInSettings(Context context,
+ @PreferredShortcutType int shortcutType) {
+ final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
+ final String targetString = Settings.Secure.getString(context.getContentResolver(),
+ targetKey);
+
+ if (TextUtils.isEmpty(targetString)) {
+ return false;
+ }
+
+ sStringColonSplitter.setString(targetString);
+ while (sStringColonSplitter.hasNext()) {
+ final String name = sStringColonSplitter.next();
+ if (MAGNIFICATION_CONTROLLER_NAME.equals(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/src/com/android/settings/biometrics/face/FaceSettings.java b/src/com/android/settings/biometrics/face/FaceSettings.java
index e1ca4f7..08cfa70 100644
--- a/src/com/android/settings/biometrics/face/FaceSettings.java
+++ b/src/com/android/settings/biometrics/face/FaceSettings.java
@@ -329,10 +329,13 @@
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
- final FaceManager faceManager = context.getSystemService(FaceManager.class);
- final boolean hasEnrolled = faceManager.hasEnrolledTemplates(
- UserHandle.myUserId());
- keys.add(hasEnrolled ? PREF_KEY_ENROLL_FACE_UNLOCK : PREF_KEY_DELETE_FACE_DATA);
+ if (isAvailable(context)) {
+ final FaceManager faceManager = context.getSystemService(FaceManager.class);
+ final boolean hasEnrolled = faceManager.hasEnrolledTemplates(
+ UserHandle.myUserId());
+ keys.add(hasEnrolled ? PREF_KEY_ENROLL_FACE_UNLOCK
+ : PREF_KEY_DELETE_FACE_DATA);
+ }
return keys;
}
};
diff --git a/src/com/android/settings/development/BluetoothMapVersionPreferenceController.java b/src/com/android/settings/development/BluetoothMapVersionPreferenceController.java
new file mode 100644
index 0000000..ac20627
--- /dev/null
+++ b/src/com/android/settings/development/BluetoothMapVersionPreferenceController.java
@@ -0,0 +1,79 @@
+/*
+ * 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.development;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.text.TextUtils;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+/**
+ * Preference controller to control Bluetooth MAP version
+ */
+public class BluetoothMapVersionPreferenceController extends DeveloperOptionsPreferenceController
+ implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+
+ private static final String BLUETOOTH_SELECT_MAP_VERSION_KEY =
+ "bluetooth_select_map_version";
+
+ @VisibleForTesting
+ static final String BLUETOOTH_MAP_VERSION_PROPERTY = "persist.bluetooth.mapversion";
+
+ private final String[] mListValues;
+ private final String[] mListSummaries;
+
+ public BluetoothMapVersionPreferenceController(Context context) {
+ super(context);
+
+ mListValues = context.getResources().getStringArray(R.array.bluetooth_map_version_values);
+ mListSummaries = context.getResources().getStringArray(R.array.bluetooth_map_versions);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return BLUETOOTH_SELECT_MAP_VERSION_KEY;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ SystemProperties.set(BLUETOOTH_MAP_VERSION_PROPERTY, newValue.toString());
+ updateState(mPreference);
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final ListPreference listPreference = (ListPreference) preference;
+ final String currentValue = SystemProperties.get(BLUETOOTH_MAP_VERSION_PROPERTY);
+ int index = 0; // Defaults to MAP 1.2
+ for (int i = 0; i < mListValues.length; i++) {
+ if (TextUtils.equals(currentValue, mListValues[i])) {
+ index = i;
+ break;
+ }
+ }
+ listPreference.setValue(mListValues[index]);
+ listPreference.setSummary(mListSummaries[index]);
+ }
+}
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 88f2c50..1c08131 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -465,6 +465,7 @@
controllers.add(new BluetoothAbsoluteVolumePreferenceController(context));
controllers.add(new BluetoothGabeldorschePreferenceController(context));
controllers.add(new BluetoothAvrcpVersionPreferenceController(context));
+ controllers.add(new BluetoothMapVersionPreferenceController(context));
controllers.add(new BluetoothA2dpHwOffloadPreferenceController(context, fragment));
controllers.add(new BluetoothMaxConnectedAudioDevicesPreferenceController(context));
controllers.add(new ShowTapsPreferenceController(context));
diff --git a/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java b/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
index cd79ea0..cb7b14e 100644
--- a/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
+++ b/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
@@ -30,7 +30,6 @@
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settingslib.utils.StringUtil;
import java.util.List;
@@ -78,7 +77,12 @@
holder.appIcon.setImageDrawable(
Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, app.packageName,
UserHandle.getUserId(app.uid)));
- holder.appName.setText(Utils.getApplicationLabel(mContext, app.packageName));
+ CharSequence label = Utils.getApplicationLabel(mContext, app.packageName);
+ if (label == null) {
+ label = app.packageName;
+ }
+
+ holder.appName.setText(label);
}
@Override
diff --git a/src/com/android/settings/network/ApnSettings.java b/src/com/android/settings/network/ApnSettings.java
index b31154f..88a13ae 100755
--- a/src/com/android/settings/network/ApnSettings.java
+++ b/src/com/android/settings/network/ApnSettings.java
@@ -38,6 +38,8 @@
import android.os.UserManager;
import android.provider.Telephony;
import android.telephony.CarrierConfigManager;
+import android.telephony.PhoneStateListener;
+import android.telephony.PreciseDataConnectionState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -52,8 +54,6 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -107,6 +107,7 @@
private static boolean mRestoreDefaultApnMode;
private UserManager mUserManager;
+ private TelephonyManager mTelephonyManager;
private RestoreApnUiHandler mRestoreApnUiHandler;
private RestoreApnProcessHandler mRestoreApnProcessHandler;
private HandlerThread mRestoreDefaultApnThread;
@@ -130,22 +131,24 @@
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
}
+ private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
+ @Override
+ public void onPreciseDataConnectionStateChanged(
+ PreciseDataConnectionState dataConnectionState) {
+ if (dataConnectionState.getState() == TelephonyManager.DATA_CONNECTED) {
+ if (!mRestoreDefaultApnMode) {
+ fillList();
+ } else {
+ showDialog(DIALOG_RESTORE_DEFAULTAPN);
+ }
+ }
+ }
+ };
+
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(
- TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
- PhoneConstants.DataState state = getMobileDataState(intent);
- switch (state) {
- case CONNECTED:
- if (!mRestoreDefaultApnMode) {
- fillList();
- } else {
- showDialog(DIALOG_RESTORE_DEFAULTAPN);
- }
- break;
- }
- } else if(intent.getAction().equals(
TelephonyManager.ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED)) {
if (!mRestoreDefaultApnMode) {
int extraSubId = intent.getIntExtra(TelephonyManager.EXTRA_SUBSCRIPTION_ID,
@@ -156,6 +159,7 @@
// subscription has changed
mSubId = extraSubId;
mSubscriptionInfo = getSubscriptionInfo(mSubId);
+ restartPhoneStateListener(mSubId);
}
fillList();
}
@@ -163,13 +167,25 @@
}
};
- private static PhoneConstants.DataState getMobileDataState(Intent intent) {
- String str = intent.getStringExtra(PhoneConstants.STATE_KEY);
- if (str != null) {
- return Enum.valueOf(PhoneConstants.DataState.class, str);
- } else {
- return PhoneConstants.DataState.DISCONNECTED;
+ private void restartPhoneStateListener(int subId) {
+ if (mRestoreDefaultApnMode) {
+ return;
}
+
+ final TelephonyManager updatedTelephonyManager =
+ mTelephonyManager.createForSubscriptionId(subId);
+ if (updatedTelephonyManager == null) {
+ return;
+ }
+
+ // restart monitoring when subscription has been changed
+ mTelephonyManager.listen(mPhoneStateListener,
+ PhoneStateListener.LISTEN_NONE);
+
+ mTelephonyManager = updatedTelephonyManager;
+
+ mTelephonyManager.listen(mPhoneStateListener,
+ PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE);
}
@Override
@@ -185,12 +201,12 @@
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mPhoneId = SubscriptionUtil.getPhoneId(activity, mSubId);
mIntentFilter = new IntentFilter(
- TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
- mIntentFilter.addAction(TelephonyManager.ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED);
+ TelephonyManager.ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED);
setIfOnlyAvailableForAdmins(true);
mSubscriptionInfo = getSubscriptionInfo(mSubId);
+ mTelephonyManager = activity.getSystemService(TelephonyManager.class);
CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE);
@@ -235,6 +251,8 @@
getActivity().registerReceiver(mReceiver, mIntentFilter);
+ restartPhoneStateListener(mSubId);
+
if (!mRestoreDefaultApnMode) {
fillList();
}
@@ -249,6 +267,9 @@
}
getActivity().unregisterReceiver(mReceiver);
+
+ mTelephonyManager.listen(mPhoneStateListener,
+ PhoneStateListener.LISTEN_NONE);
}
@Override
diff --git a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
index 00f5ebc..b428b22 100644
--- a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
+++ b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
@@ -88,7 +88,7 @@
@Override
public boolean setChecked(boolean isChecked) {
- return mSubscriptionManager.setAlwaysAllowMmsData(mSubId, isChecked);
+ return mTelephonyManager.setAlwaysAllowMmsData(isChecked);
}
@Override
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index c6b4702..90f1397 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -341,7 +341,7 @@
if ((!mWifiEntry.isSaved()
&& mWifiEntry.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED
- && !WifiEntryShell.isPasspoint(mWifiEntry))
+ && !mWifiEntry.isSubscription())
|| mMode != WifiConfigUiBase2.MODE_VIEW) {
showSecurityFields(/* refreshEapMethods */ true, /* refreshCertificates */ true);
showIpConfigFields();
@@ -417,7 +417,7 @@
}
if (mWifiEntry.isSaved()
|| mWifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED
- || WifiEntryShell.isPasspoint(mWifiEntry)) {
+ || mWifiEntry.isSubscription()) {
mConfigUi.setForgetButton(res.getString(R.string.wifi_forget));
}
}
diff --git a/src/com/android/settings/wifi/WifiEntryShell.java b/src/com/android/settings/wifi/WifiEntryShell.java
index 781bc84..2af0d7b 100644
--- a/src/com/android/settings/wifi/WifiEntryShell.java
+++ b/src/com/android/settings/wifi/WifiEntryShell.java
@@ -16,8 +16,6 @@
package com.android.settings.wifi;
-import android.net.wifi.WifiConfiguration;
-
import com.android.wifitrackerlib.WifiEntry;
/**
@@ -51,20 +49,6 @@
public static final int HIGHER_FREQ_5GHZ = 5900;
/**
- * Mapping of the corresponding {@link WifiConfiguration} field
- */
- public static int getNetworkId(WifiEntry wifiEntry) {
- return 0;
- }
-
- /**
- * Mapping of the corresponding {@link WifiConfiguration} field
- */
- public static boolean hiddenSSID(WifiEntry wifiEntry) {
- return false;
- }
-
- /**
* Mapping of the corresponding {@link AccessPoint} method
*/
public static String getSecurityString(WifiEntry wifiEntry, boolean concise) {
@@ -76,13 +60,6 @@
/**
* Mapping of the corresponding {@link AccessPoint} method
*/
- public static boolean isPasspoint(WifiEntry wifiEntry) {
- return false;
- }
-
- /**
- * Mapping of the corresponding {@link AccessPoint} method
- */
public static boolean isExpired(WifiEntry wifiEntry) {
return false;
}
diff --git a/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2.java
new file mode 100644
index 0000000..ffbb682
--- /dev/null
+++ b/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2.java
@@ -0,0 +1,57 @@
+/*
+ * 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.wifi.details2;
+
+import android.content.Context;
+
+import com.android.settings.core.TogglePreferenceController;
+import com.android.wifitrackerlib.WifiEntry;
+
+/**
+ * {@link TogglePreferenceController} that controls whether the Wi-Fi Auto-connect feature should be
+ * enabled.
+ */
+public class WifiAutoConnectPreferenceController2 extends TogglePreferenceController {
+
+ private static final String KEY_AUTO_CONNECT = "auto_connect";
+
+ private WifiEntry mWifiEntry;
+
+ public WifiAutoConnectPreferenceController2(Context context) {
+ super(context, KEY_AUTO_CONNECT);
+ }
+
+ public void setWifiEntry(WifiEntry wifiEntry) {
+ mWifiEntry = wifiEntry;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mWifiEntry.canSetAutoJoinEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mWifiEntry.isAutoJoinEnabled();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ mWifiEntry.setAutoJoinEnabled(isChecked);
+ return true;
+ }
+}
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index 5eed9e3..5193213 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -537,7 +537,7 @@
}
private void refreshSsid() {
- if (WifiEntryShell.isPasspoint(mWifiEntry) || WifiEntryShell.isOsuProvider(mWifiEntry)) {
+ if (mWifiEntry.isSubscription() || WifiEntryShell.isOsuProvider(mWifiEntry)) {
mSsidPref.setVisible(true);
mSsidPref.setSummary(mWifiEntry.getTitle());
} else {
@@ -723,7 +723,7 @@
* Forgets the wifi network associated with this preference.
*/
private void forgetNetwork() {
- if (WifiEntryShell.isPasspoint(mWifiEntry)) {
+ if (mWifiEntry.isSubscription()) {
// Post a dialog to confirm if user really want to forget the passpoint network.
showConfirmForgetDialog();
return;
@@ -851,7 +851,7 @@
// For saved Passpoint network, framework doesn't have the field to keep the MAC choice
// persistently, so Passpoint network will always use the default value so far, which is
// randomized MAC address, so don't need to modify title.
- if (WifiEntryShell.isPasspoint(mWifiEntry)) {
+ if (mWifiEntry.isSubscription()) {
return;
}
diff --git a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
index bdd63dc..d07d6d6 100644
--- a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
+++ b/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
@@ -91,7 +91,7 @@
@Override
protected int getPreferenceScreenResId() {
- return R.xml.wifi_network_details_fragment;
+ return R.xml.wifi_network_details_fragment2;
}
@Override
@@ -155,6 +155,11 @@
mMetricsFeatureProvider);
controllers.add(mWifiDetailPreferenceController2);
+ final WifiAutoConnectPreferenceController2 wifiAutoConnectPreferenceController2 =
+ new WifiAutoConnectPreferenceController2(context);
+ wifiAutoConnectPreferenceController2.setWifiEntry(wifiEntry);
+ controllers.add(wifiAutoConnectPreferenceController2);
+
final AddDevicePreferenceController2 addDevicePreferenceController2 =
new AddDevicePreferenceController2(context);
addDevicePreferenceController2.setWifiEntry(wifiEntry);
diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
index 22180c3..8862830 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
@@ -32,7 +32,6 @@
import android.text.TextUtils;
import com.android.settings.R;
-import com.android.settings.wifi.WifiEntryShell;
import com.android.settingslib.wifi.AccessPoint;
import com.android.wifitrackerlib.WifiEntry;
@@ -150,24 +149,6 @@
return wifiConfiguration.preSharedKey;
}
- private static String getPresharedKey(WifiManager wifiManager, WifiEntry wifiEntry) {
- final List<WifiConfiguration> privilegedWifiConfigurations =
- wifiManager.getPrivilegedConfiguredNetworks();
-
- for (WifiConfiguration privilegedWifiConfiguration : privilegedWifiConfigurations) {
- if (privilegedWifiConfiguration.networkId == WifiEntryShell.getNetworkId(wifiEntry)) {
- // WEP uses a shared key hence the AuthAlgorithm.SHARED is used to identify it.
- if (wifiEntry.getSecurity() == WifiEntry.SECURITY_WEP) {
- return privilegedWifiConfiguration
- .wepKeys[privilegedWifiConfiguration.wepTxKeyIndex];
- } else {
- return privilegedWifiConfiguration.preSharedKey;
- }
- }
- }
- return "";
- }
-
private static String removeFirstAndLastDoubleQuotes(String str) {
if (TextUtils.isEmpty(str)) {
return str;
@@ -268,7 +249,8 @@
return null;
}
- setConfiguratorIntentExtra(intent, wifiManager, wifiEntry);
+ final WifiConfiguration wifiConfiguration = wifiEntry.getWifiConfiguration();
+ setConfiguratorIntentExtra(intent, wifiManager, wifiConfiguration);
// For a transition mode Wi-Fi AP, creates a QR code that's compatible with more devices
if (wifiEntry.getSecurity() == WifiEntry.SECURITY_PSK_SAE_TRANSITION) {
@@ -326,13 +308,13 @@
return null;
}
- setConfiguratorIntentExtra(intent, wifiManager, wifiEntry);
+ final WifiConfiguration wifiConfiguration = wifiEntry.getWifiConfiguration();
+ setConfiguratorIntentExtra(intent, wifiManager, wifiConfiguration);
- final int networkId = WifiEntryShell.getNetworkId(wifiEntry);
- if (networkId == WifiConfiguration.INVALID_NETWORK_ID) {
+ if (wifiConfiguration.networkId == WifiConfiguration.INVALID_NETWORK_ID) {
throw new IllegalArgumentException("Invalid network ID");
} else {
- intent.putExtra(EXTRA_WIFI_NETWORK_ID, networkId);
+ intent.putExtra(EXTRA_WIFI_NETWORK_ID, wifiConfiguration.networkId);
}
return intent;
@@ -417,28 +399,6 @@
intent.putExtra(EXTRA_WIFI_HIDDEN_SSID, wifiConfiguration.hiddenSSID);
}
- private static void setConfiguratorIntentExtra(Intent intent, WifiManager wifiManager,
- WifiEntry wifiEntry) {
- final String ssid = removeFirstAndLastDoubleQuotes(wifiEntry.getTitle());
- final String security = getSecurityString(wifiEntry);
-
- // When the value of this key is read, the actual key is not returned, just a "*".
- // Call privileged system API to obtain actual key.
- final String preSharedKey = removeFirstAndLastDoubleQuotes(getPresharedKey(wifiManager,
- wifiEntry));
-
- if (!TextUtils.isEmpty(ssid)) {
- intent.putExtra(EXTRA_WIFI_SSID, ssid);
- }
- if (!TextUtils.isEmpty(security)) {
- intent.putExtra(EXTRA_WIFI_SECURITY, security);
- }
- if (!TextUtils.isEmpty(preSharedKey)) {
- intent.putExtra(EXTRA_WIFI_PRE_SHARED_KEY, preSharedKey);
- }
- intent.putExtra(EXTRA_WIFI_HIDDEN_SSID, WifiEntryShell.hiddenSSID(wifiEntry));
- }
-
/**
* Shows authentication screen to confirm credentials (pin, pattern or password) for the current
* user of the device.
@@ -504,7 +464,7 @@
* @param wifiEntry The {@link WifiEntry} of the Wi-Fi network
*/
public static boolean isSupportConfiguratorQrCodeScanner(Context context, WifiEntry wifiEntry) {
- if (WifiEntryShell.isPasspoint(wifiEntry)) {
+ if (wifiEntry.isSubscription()) {
return false;
}
return isSupportWifiDpp(context, wifiEntry.getSecurity());
diff --git a/tests/robotests/assets/grandfather_slice_controller_not_in_xml b/tests/robotests/assets/grandfather_slice_controller_not_in_xml
index 94d5815..5cd855f 100644
--- a/tests/robotests/assets/grandfather_slice_controller_not_in_xml
+++ b/tests/robotests/assets/grandfather_slice_controller_not_in_xml
@@ -7,4 +7,5 @@
com.android.settings.testutils.FakeToggleController
com.android.settings.testutils.FakeSliderController
com.android.settings.testutils.FakeInvalidSliderController
+com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java
index 2ccfd05..89ad812 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java
@@ -28,6 +28,7 @@
import android.provider.Settings;
import com.android.settings.R;
+import com.android.settings.accessibility.AccessibilityUtil.PreferredShortcutType;
import org.junit.Before;
import org.junit.Test;
@@ -45,7 +46,14 @@
private static final String SECURE_TEST_KEY = "secure_test_key";
private static final String DUMMY_PACKAGE_NAME = "com.dummy.example";
private static final String DUMMY_CLASS_NAME = DUMMY_PACKAGE_NAME + ".dummy_a11y_service";
- private static final String DUMMY_COMPONENT_NAME = DUMMY_PACKAGE_NAME + "/" + DUMMY_CLASS_NAME;
+ private static final String DUMMY_CLASS_NAME2 = DUMMY_PACKAGE_NAME + ".dummy_a11y_service2";
+ private static final ComponentName DUMMY_COMPONENT_NAME = new ComponentName(DUMMY_PACKAGE_NAME,
+ DUMMY_CLASS_NAME);
+ private static final ComponentName DUMMY_COMPONENT_NAME2 = new ComponentName(DUMMY_PACKAGE_NAME,
+ DUMMY_CLASS_NAME2);
+ private static final String SOFTWARE_SHORTCUT_KEY =
+ Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
+
private Context mContext;
@Before
@@ -124,6 +132,57 @@
AccessibilityUtil.AccessibilityServiceFragmentType.INTUITIVE);
}
+ @Test
+ public void hasValueInSettings_dummyComponentName_hasValue() {
+ putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
+
+ assertThat(AccessibilityUtil.hasValueInSettings(mContext, PreferredShortcutType.SOFTWARE,
+ DUMMY_COMPONENT_NAME)).isTrue();
+ }
+
+ @Test
+ public void optInValueToSettings_optInDummyComponentName2_haveDummyComponentName2String() {
+ putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
+ AccessibilityUtil.optInValueToSettings(mContext, PreferredShortcutType.SOFTWARE,
+ DUMMY_COMPONENT_NAME2);
+
+ assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
+ DUMMY_COMPONENT_NAME.flattenToString() + ":"
+ + DUMMY_COMPONENT_NAME2.flattenToString());
+ }
+
+ @Test
+ public void optInValueToSettings_optInTwoDummyComponentName_haveOneDummyComponentName2String() {
+ putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
+ AccessibilityUtil.optInValueToSettings(mContext, PreferredShortcutType.SOFTWARE,
+ DUMMY_COMPONENT_NAME2);
+ AccessibilityUtil.optInValueToSettings(mContext, PreferredShortcutType.SOFTWARE,
+ DUMMY_COMPONENT_NAME2);
+
+ assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
+ DUMMY_COMPONENT_NAME.flattenToString() + ":"
+ + DUMMY_COMPONENT_NAME2.flattenToString());
+ }
+
+ @Test
+ public void optOutValueFromSettings_optOutDummyComponentName_emptyValue() {
+ putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
+ AccessibilityUtil.optOutValueFromSettings(mContext, PreferredShortcutType.SOFTWARE,
+ DUMMY_COMPONENT_NAME);
+
+ assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty();
+ }
+
+ @Test
+ public void optOutValueFromSettings_optOutDummyComponentName2_haveDummyComponentName() {
+ putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString() + ":"
+ + DUMMY_COMPONENT_NAME2.flattenToString());
+ AccessibilityUtil.optOutValueFromSettings(mContext, PreferredShortcutType.SOFTWARE,
+ DUMMY_COMPONENT_NAME2);
+
+ assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
+ DUMMY_COMPONENT_NAME.flattenToString());
+ }
private AccessibilityServiceInfo getMockAccessibilityServiceInfo() {
final ApplicationInfo applicationInfo = new ApplicationInfo();
@@ -139,9 +198,7 @@
try {
final AccessibilityServiceInfo info = new AccessibilityServiceInfo(resolveInfo,
mContext);
- final ComponentName componentName = ComponentName.unflattenFromString(
- DUMMY_COMPONENT_NAME);
- info.setComponentName(componentName);
+ info.setComponentName(DUMMY_COMPONENT_NAME);
return info;
} catch (XmlPullParserException | IOException e) {
// Do nothing
@@ -149,4 +206,12 @@
return null;
}
+
+ private void putStringIntoSettings(String key, String componentName) {
+ Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
+ }
+
+ private String getStringFromSettings(String key) {
+ return Settings.Secure.getString(mContext.getContentResolver(), key);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/PaletteListViewTest.java b/tests/robotests/src/com/android/settings/accessibility/PaletteListViewTest.java
new file mode 100644
index 0000000..13e76d7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/PaletteListViewTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.accessibility;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+/** Tests for {@link PaletteListView} */
+@RunWith(RobolectricTestRunner.class)
+public class PaletteListViewTest {
+
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private PaletteListView mPaletteListView;
+
+ @Before
+ public void setUp() {
+ mPaletteListView = new PaletteListView(mContext);
+ }
+
+ @Test
+ public void setColors_applySameLengthArray_configureSuccessful() {
+ final String[] colorName = {"White", "Black", "Yellow"};
+ final String[] colorCode = {"#ffffff", "#000000", "#f9ab00"};
+
+ assertThat(mPaletteListView.setPaletteListColors(colorName, colorCode)).isTrue();
+ }
+
+ @Test
+ public void setColors_applyDifferentLengthArray_configureSuccessful() {
+ final String[] colorName = {"White", "Black", "Yellow", "Orange", "Red"};
+ final String[] colorCode = {"#ffffff", "#000000", "#f9ab00"};
+
+ assertThat(mPaletteListView.setPaletteListColors(colorName, colorCode)).isTrue();
+ }
+
+ @Test
+ public void setColors_configureFailed() {
+ final String[] colorName = null;
+ final String[] colorCode = null;
+
+ assertThat(mPaletteListView.setPaletteListColors(colorName, colorCode)).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothMapVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothMapVersionPreferenceControllerTest.java
new file mode 100644
index 0000000..f897fdf
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/BluetoothMapVersionPreferenceControllerTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.development;
+import static com.android.settings.development.BluetoothMapVersionPreferenceController
+ .BLUETOOTH_MAP_VERSION_PROPERTY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.SystemProperties;
+
+import androidx.preference.ListPreference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class BluetoothMapVersionPreferenceControllerTest {
+ @Mock
+ private ListPreference mPreference;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+ private Context mContext;
+ private BluetoothMapVersionPreferenceController mController;
+ /**
+ * 0: MAP 1.2 (Default)
+ * 1: MAP 1.3
+ * 2: MAP 1.4
+ */
+ private String[] mListValues;
+ private String[] mListSummaries;
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ final Resources resources = mContext.getResources();
+ mListValues = resources.getStringArray(R.array.bluetooth_map_version_values);
+ mListSummaries = resources.getStringArray(R.array.bluetooth_map_versions);
+ mController = new BluetoothMapVersionPreferenceController(mContext);
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
+ .thenReturn(mPreference);
+ mController.displayPreference(mPreferenceScreen);
+ }
+ @Test
+ public void onPreferenceChange_setMap13_shouldEnableMap13() {
+ mController.onPreferenceChange(mPreference, mListValues[1]);
+
+ final String currentValue = SystemProperties.get(BLUETOOTH_MAP_VERSION_PROPERTY);
+ assertThat(currentValue).isEqualTo(mListValues[1]);
+ }
+ @Test
+ public void onPreferenceChange_setMap14_shouldEnableMap14() {
+ mController.onPreferenceChange(mPreference, mListValues[2]);
+
+ final String currentValue = SystemProperties.get(BLUETOOTH_MAP_VERSION_PROPERTY);
+ assertThat(currentValue).isEqualTo(mListValues[2]);
+ }
+ @Test
+ public void updateState_setMap13_shouldSetPreferenceToMap13() {
+ SystemProperties.set(BLUETOOTH_MAP_VERSION_PROPERTY, mListValues[1]);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setValue(mListValues[1]);
+ verify(mPreference).setSummary(mListSummaries[1]);
+ }
+ @Test
+ public void updateState_setMap14_shouldSetPreferenceToMap14() {
+ SystemProperties.set(BLUETOOTH_MAP_VERSION_PROPERTY, mListValues[2]);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setValue(mListValues[2]);
+ verify(mPreference).setSummary(mListSummaries[2]);
+ }
+ @Test
+ public void updateState_noValueSet_shouldSetDefaultToMap12() {
+ mController.updateState(mPreference);
+
+ verify(mPreference).setValue(mListValues[0]);
+ verify(mPreference).setSummary(mListSummaries[0]);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
index 0263fe9..a612657 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
@@ -115,9 +115,9 @@
@Test
public void setChecked_setDataIntoSubscriptionManager() {
mController.setChecked(true);
- verify(mSubscriptionManager).setAlwaysAllowMmsData(SUB_ID, true);
+ verify(mTelephonyManager).setAlwaysAllowMmsData(true);
mController.setChecked(false);
- verify(mSubscriptionManager).setAlwaysAllowMmsData(SUB_ID, false);
+ verify(mTelephonyManager).setAlwaysAllowMmsData(false);
}
}
diff --git a/tests/robotests/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2Test.java b/tests/robotests/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2Test.java
new file mode 100644
index 0000000..7e604a3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/details2/WifiAutoConnectPreferenceController2Test.java
@@ -0,0 +1,89 @@
+/*
+ * 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.wifi.details2;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.android.wifitrackerlib.WifiEntry;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class WifiAutoConnectPreferenceController2Test {
+
+ private WifiAutoConnectPreferenceController2 mController;
+ @Mock
+ private WifiEntry mWifiEntry;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mController = new WifiAutoConnectPreferenceController2(RuntimeEnvironment.application);
+ mController.setWifiEntry(mWifiEntry);
+ }
+
+ @Test
+ public void getAvailabilityStatus_shouldFollowCanSetAutoJoinEnabled() {
+ // Test able to set auto join.
+ when(mWifiEntry.canSetAutoJoinEnabled()).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+
+ // Test not able to set auto join.
+ when(mWifiEntry.canSetAutoJoinEnabled()).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void isChecked_shouldFollowIsAutoJoinEnabled() {
+ // Test auto join enabled.
+ when(mWifiEntry.isAutoJoinEnabled()).thenReturn(true);
+
+ assertThat(mController.isChecked()).isTrue();
+
+ // Test auto join disabled.
+ when(mWifiEntry.isAutoJoinEnabled()).thenReturn(false);
+
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void setChecked_shouldSetAutoJoinEnabled() {
+ // Test checked.
+ mController.setChecked(true);
+
+ verify(mWifiEntry).setAutoJoinEnabled(true);
+
+ // Test unchecked.
+ mController.setChecked(false);
+
+ verify(mWifiEntry).setAutoJoinEnabled(false);
+ }
+}