Merge "[Settings] Avoid from crash UI when querying data usage" into tm-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 762d84d..4117b2e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -866,6 +866,7 @@
<activity
android:name=".localepicker.AppLocalePickerActivity"
android:label="@string/app_locale_picker_title"
+ android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="true" >
<intent-filter>
<action android:name="android.settings.APP_LOCALE_SETTINGS" />
@@ -1451,7 +1452,8 @@
<activity
android:name=".datausage.AppDataUsageActivity"
android:exported="true"
- android:noHistory="true">
+ android:noHistory="true"
+ android:permission="android.permission.QUERY_ALL_PACKAGES">
<intent-filter android:priority="1">
<action android:name="android.settings.IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
@@ -1521,6 +1523,7 @@
<activity-alias android:name=".applications.InstalledAppDetails"
android:label="@string/application_info_label"
android:exported="true"
+ android:permission="android.permission.QUERY_ALL_PACKAGES"
android:targetActivity=".applications.InstalledAppDetailsTop">
<intent-filter android:priority="1">
<action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
@@ -1534,7 +1537,8 @@
<activity android:name=".applications.InstalledAppOpenByDefaultActivity"
android:label="@string/application_info_label"
- android:exported="true">
+ android:exported="true"
+ android:permission="android.permission.QUERY_ALL_PACKAGES">
<intent-filter android:priority="1">
<action android:name="android.settings.APP_OPEN_BY_DEFAULT_SETTINGS" />
<!-- Also catch legacy "com." prefixed action. -->
@@ -1905,7 +1909,8 @@
<activity
android:name="Settings$AppUsageAccessSettingsActivity"
android:exported="true"
- android:label="@string/usage_access_title">
+ android:label="@string/usage_access_title"
+ android:permission="android.permission.QUERY_ALL_PACKAGES">
<intent-filter>
<action android:name="android.settings.USAGE_ACCESS_SETTINGS"/>
<category android:name="android.intent.category.DEFAULT"/>
diff --git a/res/drawable/ic_fast_pair_24dp.xml b/res/drawable/ic_fast_pair_24dp.xml
deleted file mode 100644
index 17bfdd9..0000000
--- a/res/drawable/ic_fast_pair_24dp.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (C) 2022 The Android Open Source Project
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24"
- android:viewportHeight="24"
- android:tint="?android:attr/colorControlNormal">
-
- <path
- android:fillColor="#FF000000"
- android:pathData="M20.65,19.27c-0.35,0-0.69-0.13-0.96-0.4l-8.66-8.66c-0.53-0.53-0.53-1.38,0-1.91 c0.53-0.53,1.38-0.53,1.91,0l8.66,8.66c0.53,0.53,0.53,1.38,0,1.91C21.34,19.14,20.99,19.27,20.65,19.27z" />
- <path
- android:fillColor="#FF000000"
- android:pathData="M12.01,16.09c-0.35,0-0.69-0.13-0.96-0.4L2.4,7.04c-0.53-0.53-0.53-1.38,0-1.91s1.38-0.53,1.91,0l8.66,8.66 c0.53,0.53,0.53,1.38,0,1.91C12.7,15.96,12.36,16.09,12.01,16.09z" />
- <path
- android:fillColor="#FF000000"
- android:pathData="M6.32,19.06c0-0.34,0.13-0.69,0.4-0.95l1.85-1.85c0.53-0.53,1.38-0.53,1.91,0c0.53,0.53,0.53,1.38,0,1.91 l-1.85,1.85c-0.53,0.53-1.38,0.53-1.91,0C6.45,19.75,6.32,19.4,6.32,19.06z" />
- <path
- android:fillColor="#FF000000"
- android:pathData="M13.13,6.79c0-0.34,0.13-0.69,0.4-0.95l1.85-1.85c0.53-0.53,1.38-0.53,1.91,0c0.53,0.53,0.53,1.38,0,1.91 l-1.85,1.85c-0.53,0.53-1.38,0.53-1.91,0C13.27,7.48,13.13,7.13,13.13,6.79z" />
-</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_settings_safety_center.xml b/res/drawable/ic_settings_safety_center.xml
index f43359f..e817b71 100644
--- a/res/drawable/ic_settings_safety_center.xml
+++ b/res/drawable/ic_settings_safety_center.xml
@@ -13,17 +13,19 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<!-- TODO(b/208624929): Update to an UX approved icon. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
- android:viewportHeight="24"
android:viewportWidth="24"
- android:tint="?android:attr/colorControlNormal">
+ android:viewportHeight="24"
+ android:tint="?android:attr/textColorPrimary">
+
<path
- android:fillColor="#FFFFFFFF"
- android:pathData="M12,15m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:fillColor="#FFFFFFFF"
- android:pathData="M18.5,1C16.01,1 14,3.01 14,5.5V8H6c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V10c0,-1.1 -0.9,-2 -2,-2h-2V5.5C16,4.12 17.12,3 18.5,3C19.88,3 21,4.12 21,5.5V6h2V5.5C23,3.01 20.99,1 18.5,1zM18,10v10H6V10H18z"/>
+ android:fillColor="#000000"
+ android:pathData="M12,4.14l6,2.25v4.71c0,2.12-0.62,4-1.88,5.74c-1.13,1.55-2.48,2.56-4.12,3.09c-1.64-0.52-2.99-1.54-4.12-3.09 C6.62,15.1,6,13.22,6,11.1V6.39L12,4.14 M12,2L4,5v6.1c0,2.53,0.75,4.84,2.26,6.91C7.77,20.09,9.68,21.42,12,22 c2.32-0.58,4.23-1.91,5.74-3.99C19.25,15.94,20,13.63,20,11.1V5L12,2L12,2z" />
+ <path
+ android:fillColor="#000000"
+ android:pathData="M 10.95 15.55 L 7.42 12.02 L 8.85 10.6 L 10.95 12.7 L 15.17 8.47 L 16.6 9.9 Z" />
</vector>
\ No newline at end of file
diff --git a/res/layout/bluetooth_pin_confirm.xml b/res/layout/bluetooth_pin_confirm.xml
index 28ad1f6..0024ad4 100644
--- a/res/layout/bluetooth_pin_confirm.xml
+++ b/res/layout/bluetooth_pin_confirm.xml
@@ -81,6 +81,7 @@
android:id="@+id/phonebook_sharing_message_confirm_pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:minHeight="@dimen/min_tap_target_size"
android:layout_marginStart="@dimen/bluetooth_dialog_padding"
android:layout_marginEnd="@dimen/bluetooth_dialog_padding"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1" />
diff --git a/res/layout/dialog_edittext_dropdown.xml b/res/layout/dialog_edittext_dropdown.xml
new file mode 100644
index 0000000..0e77968
--- /dev/null
+++ b/res/layout/dialog_edittext_dropdown.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingStart="20dp"
+ android:paddingEnd="20dp"
+ android:paddingTop="16dp"
+ android:paddingBottom="12dp">
+
+ <EditText
+ android:id="@+id/edittext"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:inputType="textCapSentences"
+ android:minHeight="@dimen/min_tap_target_size"
+ android:maxLength="50"
+ android:singleLine="true" />
+
+ <Spinner
+ android:id="@+id/spinner"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:minHeight="@dimen/min_tap_target_size" />
+</LinearLayout>
diff --git a/res/layout/running_service_details.xml b/res/layout/running_service_details.xml
index 68ddb1c..d544704 100644
--- a/res/layout/running_service_details.xml
+++ b/res/layout/running_service_details.xml
@@ -16,7 +16,7 @@
** limitations under the License.
*/
-->
-<ScrollView
+<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -35,4 +35,4 @@
</LinearLayout>
-</ScrollView>
+</androidx.core.widget.NestedScrollView>
diff --git a/res/layout/tare_homepage.xml b/res/layout/tare_homepage.xml
index ddc9333..4cd649f 100644
--- a/res/layout/tare_homepage.xml
+++ b/res/layout/tare_homepage.xml
@@ -27,7 +27,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
- android:text="On"
+ android:textOff="@string/tare_off"
+ android:textOn="@string/tare_on"
+ android:showText="true"
android:background="?android:attr/colorBackground" />
<TextView
android:id="@+id/alarmmanager"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index c80e42c..f11cee5 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -452,6 +452,7 @@
<!-- Text padding for EmptyTextSettings -->
<dimen name="empty_text_padding">24dp</dimen>
+ <dimen name="empty_text_layout_height">450dp</dimen>
<!-- Choose SIM Activity dimens -->
<dimen name="subtitle_bottom_padding">24dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f87b489..e333969 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5577,6 +5577,10 @@
<string name="accessibility_vibration_settings_title">Vibration & haptics</string>
<!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] -->
<string name="accessibility_vibration_settings_summary">Control the vibration strength for different usages</string>
+ <!-- "Vibration & haptics" preference's state when enabled. This text is shown next to the "Vibration & haptics" preference title. [CHAR LIMIT=NONE] -->
+ <string name="accessibility_vibration_settings_state_on">On</string>
+ <!-- "Vibration & haptics" preference's state when disabled. This text is shown next to the "Vibration & haptics" preference title. [CHAR LIMIT=NONE] -->
+ <string name="accessibility_vibration_settings_state_off">Off</string>
<!-- Summary for vibration preference shown when it is disabled because the device is in silent mode. [CHAR LIMIT=NONE] -->
<string name="accessibility_vibration_setting_disabled_for_silent_mode_summary">Setting disabled because device is set to silent</string>
<!-- Title for the category of preferences to configure device vibrations related to calls. [CHAR LIMIT=NONE] -->
@@ -5978,19 +5982,6 @@
<!-- List of synonyms used in the settings search bar to find the “Voice Access”. [CHAR LIMIT=NONE] -->
<string name="keywords_voice_access"></string>
- <!-- Fast Pair settings -->
- <skip />
-
- <!-- Title in main settings screen for Fast Pair settings [CHAR LIMIT=15] -->
- <string name="fast_pair_settings">Fast Pair</string>
-
- <!-- Fast Pair setting summary in settings screen [CHAR LIMIT=50] -->
- <string name="fast_pair_settings_summary">Nearby detection of Fast Pair bluetooth devices.</string>
- <!-- Title for Fast Pair main switch preferences. [CHAR LIMIT=50] -->
- <string name="fast_pair_main_switch_title">Scan for nearby devices</string>
- <!-- Title for Fast Pair saved devices preferences. [CHAR LIMIT=50] -->
- <string name="fast_pair_saved_devices_title">Saved devices</string>
- <!-- Printing settings -->
<skip />
<!-- Title in main settings screen for printing settings [CHAR LIMIT=15] -->
@@ -8418,9 +8409,6 @@
<!-- List of synonyms for the Bluetooth setting, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_bluetooth_settings">connected, device, headphones, headset, speaker, wireless, pair, earbuds, music, media </string>
- <!-- List of synonyms for the Fast Pair setting, used to match in settings search [CHAR LIMIT=NONE] -->
- <string name="keywords_fast_pair">pair, earbuds, bluetooth</string>
-
<!-- List of synonyms for the Wallpaper picker setting, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_wallpaper">background, theme, grid, customize, personalize</string>
@@ -10207,18 +10195,18 @@
<string name="screen_pinning_description">
When an app is pinned, the pinned app may open other apps and personal data may be accessible.
\n\nTo use app pinning:
- \t\n1.\tTurn on app pinning
- \t\n2.\tOpen Overview
- \t\n3.\tTap the app icon at the top of the screen, then tap Pin
+ \t\n1. Turn on app pinning
+ \t\n2. Open Overview
+ \t\n3. Tap the app icon at the top of the screen, then tap Pin
</string>
<!-- [CHAR LIMIT=none] Screen pinning description -->
<string name="screen_pinning_guest_user_description">
When an app is pinned, the pinned app may open other apps and personal data may be accessible.
\n\nIf you want to securely share your device with someone, try using a guest user instead.
\n\nTo use app pinning:
- \t\n1.\tTurn on app pinning
- \t\n2.\tOpen Overview
- \t\n3.\tTap the app icon at the top of the screen, then tap Pin
+ \t\n1. Turn on app pinning
+ \t\n2. Open Overview
+ \t\n3. Tap the app icon at the top of the screen, then tap Pin
</string>
<!-- [CHAR LIMIT=300] Screen pinning title -->
<string name="screen_pinning_dialog_message">
@@ -13854,6 +13842,10 @@
<!-- TARE settings title in developer options; "TARE" is the name of the feature and cannot be
translated. [CHAR LIMIT=40] -->
<string name="tare_settings">TARE Settings</string>
+ <!-- Summary for the TARE feature being on (ie. enabled) [CHAR LIMIT=NONE] -->
+ <string name="tare_on">On</string>
+ <!-- Summary for the TARE feature being off (ie. disabled) [CHAR LIMIT=NONE] -->
+ <string name="tare_off">Off</string>
<!-- Allows user to revert the TARE settings to their default values [CHAR LIMIT=40] -->
<string name="tare_revert">Revert to Default Settings</string>
<!-- Allows user to view AlarmManager policy factors. Alarm in this context is referring to the
@@ -13904,7 +13896,7 @@
<string name="tare_rewards_instantaneous">Rewards per single event</string>
<!-- Title for the rewards apps can obtain for the total duration (in seconds) of an event that
implies the user finds the app behavior useful. [CHAR LIMIT=40]-->
- <string name="tare_rewards_ongoing">Rewards for total event duration</string>
+ <string name="tare_rewards_ongoing">Rewards per second of event duration</string>
<!-- Title for the max rewards apps can obtain within a 24 hour period for different actions
that benefit the user. [CHAR LIMIT=40]-->
<string name="tare_rewards_max">Maximum Rewards Per Day</string>
@@ -14071,6 +14063,13 @@
</string-array>
<!-- TARE dialog button to proceed with a value change [CHAR LIMIT=none] -->
<string name="tare_dialog_confirm_button_title">Confirm</string>
+ <!-- Array used to populate dropdown menu to select the units of the factor value. Not
+ translatable since they're base units. [CHAR LIMIT=40]-->
+ <string-array name="tare_units" translatable="false">
+ <item>ARC</item>
+ <item>Cake</item>
+ </string-array>
+
<!-- Button to preview the selected screensaver in settings [CHAR LIMIT=40] -->
<string name="dream_preview_button_title">Preview</string>
<!-- The title of the category to show for the screensaver selector in settings [CHAR LIMIT=none] -->
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 509aed6..0287fc6 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -41,7 +41,8 @@
android:icon="@drawable/ic_adaptive_font_download"
android:key="text_reading_options"
android:persistent="false"
- android:title="@string/accessibility_text_reading_options_title" />
+ android:title="@string/accessibility_text_reading_options_title"
+ settings:controller="com.android.settings.accessibility.TextReadingFragmentForA11ySettingsController"/>
<Preference
android:fragment="com.android.settings.accessibility.ColorAndMotionFragment"
diff --git a/res/xml/accessibility_settings_for_setup_wizard.xml b/res/xml/accessibility_settings_for_setup_wizard.xml
index a50e7dd..6929d54 100644
--- a/res/xml/accessibility_settings_for_setup_wizard.xml
+++ b/res/xml/accessibility_settings_for_setup_wizard.xml
@@ -26,7 +26,8 @@
android:key="text_reading_options"
android:persistent="false"
android:title="@string/accessibility_text_reading_options_title"
- settings:keywords="text_reading_options" />
+ settings:keywords="text_reading_options"
+ settings:controller="com.android.settings.accessibility.TextReadingFragmentForSuwController"/>
<Preference
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard"
diff --git a/res/xml/app_data_usage.xml b/res/xml/app_data_usage.xml
index e64a1c5..e94c4ff 100644
--- a/res/xml/app_data_usage.xml
+++ b/res/xml/app_data_usage.xml
@@ -21,8 +21,7 @@
android:title="@string/data_usage_app_summary_title">
<com.android.settings.datausage.SpinnerPreference
- android:key="cycle"
- settings:isPreferenceVisible="false" />
+ android:key="cycle" />
<PreferenceCategory
android:key="app_data_usage_summary_category">
@@ -31,19 +30,22 @@
android:key="total_usage"
android:title="@string/total_size_label"
android:selectable="false"
- android:layout="@layout/horizontal_preference" />
+ android:layout="@layout/horizontal_preference"
+ android:summary="@string/summary_placeholder" />
<Preference
android:key="foreground_usage"
android:title="@string/data_usage_label_foreground"
android:selectable="false"
- android:layout="@layout/horizontal_preference" />
+ android:layout="@layout/horizontal_preference"
+ android:summary="@string/summary_placeholder" />
<Preference
android:key="background_usage"
android:title="@string/data_usage_label_background"
android:selectable="false"
- android:layout="@layout/horizontal_preference" />
+ android:layout="@layout/horizontal_preference"
+ android:summary="@string/summary_placeholder" />
</PreferenceCategory>
diff --git a/res/xml/connected_devices_advanced.xml b/res/xml/connected_devices_advanced.xml
index e7d178c..152446c 100644
--- a/res/xml/connected_devices_advanced.xml
+++ b/res/xml/connected_devices_advanced.xml
@@ -67,15 +67,6 @@
android:summary="@string/summary_placeholder"
settings:controller="com.android.settings.uwb.UwbPreferenceController"/>
- <Preference
- android:key="connected_device_fast_pair"
- android:title="@string/fast_pair_settings"
- android:summary="@string/fast_pair_settings_summary"
- android:icon="@drawable/ic_fast_pair_24dp"
- android:fragment="com.android.settings.nearby.FastPairSettingsFragment"
- settings:controller="com.android.settings.nearby.FastPairPreferenceController"
- android:order="-2"/>
-
<PreferenceCategory
android:key="dashboard_tile_placeholder"
android:order="-8"/>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 03d073b..2336c15 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -72,7 +72,8 @@
android:fragment="com.android.settings.accessibility.TextReadingPreferenceFragment"
android:key="text_reading_options"
android:persistent="false"
- android:title="@string/accessibility_text_reading_options_title" />
+ android:title="@string/accessibility_text_reading_options_title"
+ settings:controller="com.android.settings.accessibility.TextReadingFragmentForDisplaySettingsController"/>
</PreferenceCategory>
<PreferenceCategory
diff --git a/res/xml/fast_pair_settings.xml b/res/xml/fast_pair_settings.xml
deleted file mode 100644
index 95662fc..0000000
--- a/res/xml/fast_pair_settings.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-~ Copyright (C) 2022 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"
- android:title="@string/fast_pair_settings"
- settings:keywords="@string/keywords_fast_pair">
-
- <com.android.settingslib.widget.MainSwitchPreference
- android:key="fast_pair_scan_switch"
- android:title="@string/fast_pair_main_switch_title" />
-
- <Preference
- android:key="saved_devices"
- android:title="@string/fast_pair_saved_devices_title" />
-
-</PreferenceScreen>
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index da21729..012996b 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -416,8 +416,11 @@
if (usbTethered) {
mUsbTether.setEnabled(!mDataSaverEnabled);
mUsbTether.setChecked(true);
- mUsbTether.setDisabledByAdmin(
- checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
+ final RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
+ checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId());
+ if (enforcedAdmin != null) {
+ mUsbTether.setDisabledByAdmin(enforcedAdmin);
+ }
} else {
mUsbTether.setChecked(false);
updateUsbPreference();
diff --git a/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java b/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java
index 434157d..d8a887d 100644
--- a/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java
+++ b/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java
@@ -16,6 +16,16 @@
package com.android.settings.accessibility;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.BOLD_TEXT_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.DISPLAY_SIZE_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.DISPLAY_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_ANYTHING_ELSE;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_VISION_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.FONT_SIZE_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.HIGH_TEXT_CONTRAST_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.RESET_KEY;
+
import android.content.ComponentName;
import com.android.settings.core.instrumentation.SettingsStatsLog;
@@ -58,4 +68,48 @@
.ACCESSIBILITY_PRIVACY_WARNING_STATUS_SERVICE_DISABLED,
durationMills);
}
+
+ /**
+ * Converts to the key name for logging.
+ *
+ * @param prefKey the preference key
+ * @return the int value which maps to the key name
+ */
+ static int convertToItemKeyName(String prefKey) {
+ switch (prefKey) {
+ case FONT_SIZE_KEY:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_FONT_SIZE;
+ case DISPLAY_SIZE_KEY:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_DISPLAY_SIZE;
+ case BOLD_TEXT_KEY:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_BOLD_TEXT;
+ case HIGH_TEXT_CONTRAST_KEY:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_HIGH_CONTRAST_TEXT;
+ case RESET_KEY:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_RESET;
+ default:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_UNKNOWN_ITEM;
+ }
+ }
+
+ /**
+ * Converts to the entry point for logging.
+ *
+ * @param entryPoint the entry point
+ * @return the int value which maps to the entry point
+ */
+ static int convertToEntryPoint(int entryPoint) {
+ switch (entryPoint) {
+ case SUW_VISION_SETTINGS:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_VISION_SETTINGS;
+ case SUW_ANYTHING_ELSE:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_ANYTHING_ELSE;
+ case DISPLAY_SETTINGS:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_DISPLAY_SETTINGS;
+ case ACCESSIBILITY_SETTINGS:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_ACCESSIBILITY_SETTINGS;
+ default:
+ return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_UNKNOWN_ENTRY;
+ }
+ }
}
diff --git a/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java b/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
index e3c1b9e..923e880 100644
--- a/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
+++ b/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
@@ -21,7 +21,9 @@
import android.provider.Settings;
import com.android.settings.R;
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
/** PreferenceController for displaying all text in bold. */
public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController implements
@@ -29,6 +31,9 @@
static final int BOLD_TEXT_ADJUSTMENT =
FontStyle.FONT_WEIGHT_BOLD - FontStyle.FONT_WEIGHT_NORMAL;
+ @EntryPoint
+ private int mEntryPoint;
+
public FontWeightAdjustmentPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@@ -46,6 +51,12 @@
@Override
public boolean setChecked(boolean isChecked) {
+ SettingsStatsLog.write(
+ SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+ AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+ isChecked ? 1 : 0,
+ AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
+
return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.FONT_WEIGHT_ADJUSTMENT, (isChecked ? BOLD_TEXT_ADJUSTMENT : 0));
}
@@ -59,4 +70,13 @@
public void resetState() {
setChecked(false);
}
+
+ /**
+ * The entry point is used for logging.
+ *
+ * @param entryPoint from which settings page
+ */
+ void setEntryPoint(@EntryPoint int entryPoint) {
+ mEntryPoint = entryPoint;
+ }
}
diff --git a/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java b/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
index 8c9d234..9f645f1 100644
--- a/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
+++ b/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
@@ -23,7 +23,9 @@
import androidx.preference.SwitchPreference;
import com.android.settings.R;
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
/**
* PreferenceController for displaying all text in high contrast style.
@@ -32,6 +34,9 @@
TextReadingResetController.ResetStateListener {
private SwitchPreference mSwitchPreference;
+ @EntryPoint
+ private int mEntryPoint;
+
public HighTextContrastPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@@ -49,6 +54,12 @@
@Override
public boolean setChecked(boolean isChecked) {
+ SettingsStatsLog.write(
+ SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+ AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+ isChecked ? 1 : 0,
+ AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
+
return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, (isChecked ? 1 : 0));
}
@@ -69,4 +80,13 @@
setChecked(false);
updateState(mSwitchPreference);
}
+
+ /**
+ * The entry point is used for logging.
+ *
+ * @param entryPoint from which settings page
+ */
+ void setEntryPoint(@EntryPoint int entryPoint) {
+ mEntryPoint = entryPoint;
+ }
}
diff --git a/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java b/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
index c7dfd61..711eb0f 100644
--- a/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
+++ b/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
@@ -22,7 +22,9 @@
import androidx.annotation.NonNull;
import androidx.preference.PreferenceScreen;
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
import com.android.settings.widget.LabeledSeekBarPreference;
/**
@@ -36,6 +38,9 @@
private ProgressInteractionListener mInteractionListener;
private LabeledSeekBarPreference mSeekBarPreference;
+ @EntryPoint
+ private int mEntryPoint;
+
private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener =
new SeekBar.OnSeekBarChangeListener() {
@Override
@@ -45,6 +50,12 @@
if (!mSeekByTouch && mInteractionListener != null) {
mInteractionListener.onProgressChanged();
}
+
+ SettingsStatsLog.write(
+ SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+ AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+ progress,
+ AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
}
@Override
@@ -97,6 +108,15 @@
}
/**
+ * The entry point is used for logging.
+ *
+ * @param entryPoint from which settings page
+ */
+ void setEntryPoint(@EntryPoint int entryPoint) {
+ mEntryPoint = entryPoint;
+ }
+
+ /**
* Interface for callbacks when users interact with the seek bar.
*/
interface ProgressInteractionListener {
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentBaseController.java b/src/com/android/settings/accessibility/TextReadingFragmentBaseController.java
new file mode 100644
index 0000000..f26ca96
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentBaseController.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2022 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.android.settings.accessibility.TextReadingPreferenceFragment.EXTRA_LAUNCHED_FROM;
+
+import android.content.Context;
+import android.os.Bundle;
+
+import androidx.preference.Preference;
+
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * The base controller for the fragment{@link TextReadingPreferenceFragment}.
+ */
+public class TextReadingFragmentBaseController extends BasePreferenceController {
+ @EntryPoint
+ private int mEntryPoint;
+
+ private TextReadingFragmentBaseController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ TextReadingFragmentBaseController(Context context, String preferenceKey,
+ @EntryPoint int entryPoint) {
+ this(context, preferenceKey);
+ mEntryPoint = entryPoint;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (getPreferenceKey().equals(preference.getKey())) {
+ final Bundle extras = preference.getExtras();
+ extras.putInt(EXTRA_LAUNCHED_FROM, mEntryPoint);
+ }
+
+ return super.handlePreferenceTreeClick(preference);
+ }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentForA11ySettingsController.java b/src/com/android/settings/accessibility/TextReadingFragmentForA11ySettingsController.java
new file mode 100644
index 0000000..434877c
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentForA11ySettingsController.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2022 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.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
+
+import android.content.Context;
+
+/**
+ * The controller for the {@link TextReadingPreferenceFragment} from the accessibility settings.
+ */
+public class TextReadingFragmentForA11ySettingsController extends
+ TextReadingFragmentBaseController {
+ public TextReadingFragmentForA11ySettingsController(Context context, String preferenceKey) {
+ // Pass the fixed entry point to the parent controller for logging.
+ super(context, preferenceKey, ACCESSIBILITY_SETTINGS);
+ }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentForDisplaySettingsController.java b/src/com/android/settings/accessibility/TextReadingFragmentForDisplaySettingsController.java
new file mode 100644
index 0000000..4d603f9
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentForDisplaySettingsController.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2022 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.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.DISPLAY_SETTINGS;
+
+import android.content.Context;
+
+/**
+ * The controller for the {@link TextReadingPreferenceFragment} from the display settings.
+ */
+public class TextReadingFragmentForDisplaySettingsController extends
+ TextReadingFragmentBaseController {
+ public TextReadingFragmentForDisplaySettingsController(Context context, String preferenceKey) {
+ // Pass the fixed entry point to the parent controller for logging.
+ super(context, preferenceKey, DISPLAY_SETTINGS);
+ }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentForSuwController.java b/src/com/android/settings/accessibility/TextReadingFragmentForSuwController.java
new file mode 100644
index 0000000..332d9c5
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentForSuwController.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2022 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.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_VISION_SETTINGS;
+
+import android.content.Context;
+
+/**
+ * The controller for the {@link TextReadingPreferenceFragment} during the SetupWizard.
+ */
+public class TextReadingFragmentForSuwController extends TextReadingFragmentBaseController {
+ public TextReadingFragmentForSuwController(Context context, String preferenceKey) {
+ // Pass the fixed entry point to the parent controller for logging.
+ super(context, preferenceKey, SUW_VISION_SETTINGS);
+ }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
index a4ee961c..104be26 100644
--- a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
@@ -22,9 +22,11 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
+import androidx.annotation.IntDef;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
@@ -36,8 +38,11 @@
import com.google.common.annotations.VisibleForTesting;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -46,15 +51,40 @@
*/
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class TextReadingPreferenceFragment extends DashboardFragment {
+ public static final String EXTRA_LAUNCHED_FROM = "launched_from";
private static final String TAG = "TextReadingPreferenceFragment";
- private static final String FONT_SIZE_KEY = "font_size";
- private static final String DISPLAY_SIZE_KEY = "display_size";
+ private static final String CATEGORY_FOR_ANYTHING_ELSE =
+ "com.android.settings.suggested.category.DISPLAY_SETTINGS";
+ static final String FONT_SIZE_KEY = "font_size";
+ static final String DISPLAY_SIZE_KEY = "display_size";
+ static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
+ static final String HIGH_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
+ static final String RESET_KEY = "reset";
private static final String PREVIEW_KEY = "preview";
- private static final String RESET_KEY = "reset";
- private static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
- private static final String HIGHT_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
private static final String NEED_RESET_SETTINGS = "need_reset_settings";
private FontWeightAdjustmentPreferenceController mFontWeightAdjustmentController;
+ private int mEntryPoint = EntryPoint.UNKNOWN_ENTRY;
+
+ /**
+ * The entry point which launches the {@link TextReadingPreferenceFragment}.
+ *
+ * <p>This should only be used for logging.
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ EntryPoint.UNKNOWN_ENTRY,
+ EntryPoint.SUW_VISION_SETTINGS,
+ EntryPoint.SUW_ANYTHING_ELSE,
+ EntryPoint.DISPLAY_SETTINGS,
+ EntryPoint.ACCESSIBILITY_SETTINGS,
+ })
+ @interface EntryPoint {
+ int UNKNOWN_ENTRY = 0;
+ int SUW_VISION_SETTINGS = 1;
+ int SUW_ANYTHING_ELSE = 2;
+ int DISPLAY_SETTINGS = 3;
+ int ACCESSIBILITY_SETTINGS = 4;
+ }
@VisibleForTesting
List<ResetStateListener> mResetStateListeners;
@@ -91,6 +121,8 @@
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ updateEntryPoint();
+
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final FontSizeData fontSizeData = new FontSizeData(context);
final DisplaySizeData displaySizeData = createDisplaySizeData(context);
@@ -102,24 +134,29 @@
final PreviewSizeSeekBarController fontSizeController = new PreviewSizeSeekBarController(
context, FONT_SIZE_KEY, fontSizeData);
fontSizeController.setInteractionListener(previewController);
+ fontSizeController.setEntryPoint(mEntryPoint);
controllers.add(fontSizeController);
final PreviewSizeSeekBarController displaySizeController = new PreviewSizeSeekBarController(
context, DISPLAY_SIZE_KEY, displaySizeData);
displaySizeController.setInteractionListener(previewController);
+ displaySizeController.setEntryPoint(mEntryPoint);
controllers.add(displaySizeController);
mFontWeightAdjustmentController =
new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY);
+ mFontWeightAdjustmentController.setEntryPoint(mEntryPoint);
controllers.add(mFontWeightAdjustmentController);
final HighTextContrastPreferenceController highTextContrastController =
- new HighTextContrastPreferenceController(context, HIGHT_TEXT_CONTRAST_KEY);
+ new HighTextContrastPreferenceController(context, HIGH_TEXT_CONTRAST_KEY);
+ highTextContrastController.setEntryPoint(mEntryPoint);
controllers.add(highTextContrastController);
final TextReadingResetController resetController =
new TextReadingResetController(context, RESET_KEY,
v -> showDialog(DialogEnums.DIALOG_RESET_SETTINGS));
+ resetController.setEntryPoint(mEntryPoint);
controllers.add(resetController);
return controllers;
@@ -162,6 +199,24 @@
return new DisplaySizeData(context);
}
+ private void updateEntryPoint() {
+ final Bundle bundle = getArguments();
+ if (bundle != null && bundle.containsKey(EXTRA_LAUNCHED_FROM)) {
+ mEntryPoint = bundle.getInt(EXTRA_LAUNCHED_FROM, EntryPoint.UNKNOWN_ENTRY);
+ return;
+ }
+
+ final Intent intent = getIntent();
+ if (intent == null) {
+ mEntryPoint = EntryPoint.UNKNOWN_ENTRY;
+ return;
+ }
+
+ final Set<String> categories = intent.getCategories();
+ mEntryPoint = categories != null && categories.contains(CATEGORY_FOR_ANYTHING_ELSE)
+ ? EntryPoint.SUW_ANYTHING_ELSE : EntryPoint.UNKNOWN_ENTRY;
+ }
+
private void onPositiveButtonClicked(DialogInterface dialog, int which) {
// To avoid showing the dialog again, probably the onDetach() of SettingsDialogFragment
// was interrupted by unexpectedly recreating the activity.
diff --git a/src/com/android/settings/accessibility/TextReadingResetController.java b/src/com/android/settings/accessibility/TextReadingResetController.java
index 152ad5f..30a94c2 100644
--- a/src/com/android/settings/accessibility/TextReadingResetController.java
+++ b/src/com/android/settings/accessibility/TextReadingResetController.java
@@ -23,7 +23,9 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
import com.android.settingslib.widget.LayoutPreference;
/**
@@ -32,6 +34,9 @@
class TextReadingResetController extends BasePreferenceController {
private final View.OnClickListener mOnResetClickListener;
+ @EntryPoint
+ private int mEntryPoint;
+
TextReadingResetController(Context context, String preferenceKey,
@Nullable View.OnClickListener listener) {
super(context, preferenceKey);
@@ -52,11 +57,26 @@
view.setOnClickListener(v -> {
if (mOnResetClickListener != null) {
mOnResetClickListener.onClick(v);
+
+ SettingsStatsLog.write(
+ SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+ AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+ /* reset */ -1,
+ AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
}
});
}
/**
+ * The entry point is used for logging.
+ *
+ * @param entryPoint from which settings page
+ */
+ void setEntryPoint(@EntryPoint int entryPoint) {
+ mEntryPoint = entryPoint;
+ }
+
+ /**
* Interface for resetting to default state.
*/
interface ResetStateListener {
diff --git a/src/com/android/settings/accessibility/VibrationPreferenceController.java b/src/com/android/settings/accessibility/VibrationPreferenceController.java
index d1faedd..61606b8 100644
--- a/src/com/android/settings/accessibility/VibrationPreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationPreferenceController.java
@@ -44,6 +44,9 @@
public CharSequence getSummary() {
final boolean isVibrateOn = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.VIBRATE_ON, ON) == ON;
- return mContext.getText(isVibrateOn ? R.string.switch_on_text : R.string.switch_off_text);
+ return mContext.getText(
+ isVibrateOn
+ ? R.string.accessibility_vibration_settings_state_on
+ : R.string.accessibility_vibration_settings_state_off);
}
}
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 3eae885..062bfc5 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -330,8 +330,8 @@
if (className.equals(Settings.NotificationReviewPermissionsActivity.class.getName())) {
// Special-case for a case where a user is directed to the all apps notification
// preferences page via a notification prompt to review permissions settings.
- android.provider.Settings.Secure.putInt(getContext().getContentResolver(),
- android.provider.Settings.Secure.REVIEW_PERMISSIONS_NOTIFICATION_STATE,
+ android.provider.Settings.Global.putInt(getContext().getContentResolver(),
+ android.provider.Settings.Global.REVIEW_PERMISSIONS_NOTIFICATION_STATE,
1); // USER_INTERACTED
}
} else if (className.equals(AppLocaleDetails.class.getName())) {
diff --git a/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java b/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java
index f1c578e..3df19be 100644
--- a/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java
+++ b/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java
@@ -68,7 +68,7 @@
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- setLoading(true, false);
+ setEmptyText(R.string.premium_sms_none);
}
@Override
@@ -138,8 +138,6 @@
private void updatePrefs(ArrayList<AppEntry> apps) {
if (apps == null) return;
- setEmptyText(R.string.premium_sms_none);
- setLoading(false, true);
final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll();
screen.setOrderingAsAdded(true);
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 460f390..531a341 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -144,8 +144,7 @@
mForegroundUsage = findPreference(KEY_FOREGROUND_USAGE);
mBackgroundUsage = findPreference(KEY_BACKGROUND_USAGE);
- mCycle = findPreference(KEY_CYCLE);
- mCycleAdapter = new CycleAdapter(mContext, mCycle, mCycleListener);
+ initCycle();
final UidDetailProvider uidDetailProvider = getUidDetailProvider();
@@ -211,6 +210,8 @@
removePreference(KEY_RESTRICT_BACKGROUND);
removePreference(KEY_APP_LIST);
}
+
+ addEntityHeader();
}
@Override
@@ -276,6 +277,17 @@
return new UidDetailProvider(mContext);
}
+ private void initCycle() {
+ mCycle = findPreference(KEY_CYCLE);
+ mCycleAdapter = new CycleAdapter(mContext, mCycle, mCycleListener);
+ if (mCycles != null) {
+ // If coming from a page like DataUsageList where already has a selected cycle, display
+ // that before loading to reduce flicker.
+ mCycleAdapter.setInitialCycleList(mCycles, mSelectedCycle);
+ mCycle.setHasCycles(true);
+ }
+ }
+
private void updatePrefs(boolean restrictBackground, boolean unrestrictData) {
final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfMeteredDataRestricted(
mContext, mPackageName, UserHandle.getUserId(mAppItem.key));
@@ -308,9 +320,9 @@
final long backgroundBytes, foregroundBytes;
if (mUsageData == null || position >= mUsageData.size()) {
backgroundBytes = foregroundBytes = 0;
- mCycle.setVisible(false);
+ mCycle.setHasCycles(false);
} else {
- mCycle.setVisible(true);
+ mCycle.setHasCycles(true);
final NetworkCycleDataForUid data = mUsageData.get(position);
backgroundBytes = data.getBackgroudUsage();
foregroundBytes = data.getForegroudUsage();
@@ -335,10 +347,8 @@
return false;
}
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
+ @VisibleForTesting
+ void addEntityHeader() {
String pkg = mPackages.size() != 0 ? mPackages.valueAt(0) : null;
int uid = 0;
if (pkg != null) {
diff --git a/src/com/android/settings/datausage/CycleAdapter.java b/src/com/android/settings/datausage/CycleAdapter.java
index 2cabd8d..b41b6aa 100644
--- a/src/com/android/settings/datausage/CycleAdapter.java
+++ b/src/com/android/settings/datausage/CycleAdapter.java
@@ -13,24 +13,13 @@
*/
package com.android.settings.datausage;
-import android.annotation.NonNull;
-import android.app.usage.NetworkStats;
import android.content.Context;
-import android.net.NetworkPolicy;
-import android.net.NetworkPolicyManager;
-import android.text.format.DateUtils;
-import android.util.Pair;
-import android.util.Range;
import android.widget.AdapterView;
-import com.android.net.module.util.NetworkStatsUtils;
import com.android.settings.Utils;
-import com.android.settingslib.net.ChartData;
import com.android.settingslib.net.NetworkCycleData;
import com.android.settingslib.widget.SettingsSpinnerAdapter;
-import java.time.ZonedDateTime;
-import java.util.Iterator;
import java.util.List;
import java.util.Objects;
@@ -45,7 +34,6 @@
mSpinner = spinner;
mListener = listener;
mSpinner.setAdapter(this);
- mSpinner.setOnItemSelectedListener(mListener);
}
/**
@@ -65,128 +53,14 @@
return 0;
}
- protected static long getTotalBytesForTimeRange(List<NetworkStats.Bucket> stats,
- Range<Long> range) {
- long bytes = 0L;
- for (NetworkStats.Bucket bucket : stats) {
- final Range<Long> bucketSpan = new Range<>(
- bucket.getStartTimeStamp(), bucket.getEndTimeStamp());
- // Only record bytes that overlapped with the given time range. For partially
- // overlapped bucket, record rational bytes assuming the traffic is uniform
- // distributed within the bucket.
- try {
- final Range<Long> overlapped = range.intersect(bucketSpan);
- final long totalOfBucket = bucket.getRxBytes() + bucket.getTxBytes();
- bytes += NetworkStatsUtils.multiplySafeByRational(totalOfBucket,
- overlapped.getUpper() - overlapped.getLower(),
- bucketSpan.getUpper() - bucketSpan.getLower());
- } catch (IllegalArgumentException e) {
- // Range disjoint, ignore.
- continue;
- }
- }
- return bytes;
- }
-
- @NonNull
- private Range getTimeRangeOf(@NonNull List<NetworkStats.Bucket> stats) {
- long start = Long.MAX_VALUE;
- long end = Long.MIN_VALUE;
- for (NetworkStats.Bucket bucket : stats) {
- start = Math.min(start, bucket.getStartTimeStamp());
- end = Math.max(end, bucket.getEndTimeStamp());
- }
- return new Range(start, end);
- }
-
- /**
- * Rebuild list based on {@link NetworkPolicy} and available
- * {@link List<NetworkStats.Bucket>} data. Always selects the newest item,
- * updating the inspection range on chartData.
- */
- @Deprecated
- public boolean updateCycleList(NetworkPolicy policy, ChartData chartData) {
- // stash away currently selected cycle to try restoring below
- final CycleAdapter.CycleItem previousItem = (CycleAdapter.CycleItem)
- mSpinner.getSelectedItem();
+ void setInitialCycleList(List<Long> cycles, long selectedCycle) {
clear();
-
- final Context context = getContext();
-
- long historyStart;
- long historyEnd;
- try {
- final Range<Long> historyTimeRange = getTimeRangeOf(chartData.network);
- historyStart = historyTimeRange.getLower();
- historyEnd = historyTimeRange.getUpper();
- } catch (IllegalArgumentException e) {
- // Empty history.
- final long now = System.currentTimeMillis();
- historyStart = now;
- historyEnd = now + 1;
- }
-
- boolean hasCycles = false;
- if (policy != null) {
- final Iterator<Pair<ZonedDateTime, ZonedDateTime>> it = NetworkPolicyManager
- .cycleIterator(policy);
- while (it.hasNext()) {
- final Pair<ZonedDateTime, ZonedDateTime> cycle = it.next();
- final long cycleStart = cycle.first.toInstant().toEpochMilli();
- final long cycleEnd = cycle.second.toInstant().toEpochMilli();
-
- final boolean includeCycle;
- if (chartData != null) {
- final long bytesInCycle = getTotalBytesForTimeRange(chartData.network,
- new Range<>(cycleStart, cycleEnd));
- includeCycle = bytesInCycle > 0;
- } else {
- includeCycle = true;
- }
-
- if (includeCycle) {
- add(new CycleAdapter.CycleItem(context, cycleStart, cycleEnd));
- hasCycles = true;
- }
+ for (int i = 0; i < cycles.size() - 1; i++) {
+ add(new CycleAdapter.CycleItem(getContext(), cycles.get(i + 1), cycles.get(i)));
+ if (cycles.get(i) == selectedCycle) {
+ mSpinner.setSelection(i);
}
}
-
- if (!hasCycles) {
- // no policy defined cycles; show entry for each four-week period
- long cycleEnd = historyEnd;
- while (cycleEnd > historyStart) {
- final long cycleStart = cycleEnd - (DateUtils.WEEK_IN_MILLIS * 4);
-
- final boolean includeCycle;
- if (chartData != null) {
- final long bytesInCycle = getTotalBytesForTimeRange(chartData.network,
- new Range<>(cycleStart, cycleEnd));
- includeCycle = bytesInCycle > 0;
- } else {
- includeCycle = true;
- }
-
- if (includeCycle) {
- add(new CycleAdapter.CycleItem(context, cycleStart, cycleEnd));
- }
- cycleEnd = cycleStart;
- }
- }
-
- // force pick the current cycle (first item)
- if (getCount() > 0) {
- final int position = findNearestPosition(previousItem);
- mSpinner.setSelection(position);
-
- // only force-update cycle when changed; skipping preserves any
- // user-defined inspection region.
- final CycleAdapter.CycleItem selectedItem = getItem(position);
- if (!Objects.equals(selectedItem, previousItem)) {
- mListener.onItemSelected(null, null, position, 0);
- return false;
- }
- }
- return true;
}
/**
@@ -194,6 +68,7 @@
* updating the inspection range on chartData.
*/
public boolean updateCycleList(List<? extends NetworkCycleData> cycleData) {
+ mSpinner.setOnItemSelectedListener(mListener);
// stash away currently selected cycle to try restoring below
final CycleAdapter.CycleItem previousItem = (CycleAdapter.CycleItem)
mSpinner.getSelectedItem();
@@ -228,10 +103,6 @@
public long start;
public long end;
- public CycleItem(CharSequence label) {
- this.label = label;
- }
-
public CycleItem(Context context, long start, long end) {
this.label = Utils.formatDateRange(context, start, end);
this.start = start;
diff --git a/src/com/android/settings/datausage/SpinnerPreference.java b/src/com/android/settings/datausage/SpinnerPreference.java
index 867930b..c4b7a4e 100644
--- a/src/com/android/settings/datausage/SpinnerPreference.java
+++ b/src/com/android/settings/datausage/SpinnerPreference.java
@@ -31,6 +31,8 @@
private AdapterView.OnItemSelectedListener mListener;
private Object mCurrentObject;
private int mPosition;
+ private View mItemView;
+ private boolean mItemViewVisible = false;
public SpinnerPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -63,12 +65,24 @@
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
+ mItemView = holder.itemView;
+ mItemView.setVisibility(mItemViewVisible ? View.VISIBLE : View.INVISIBLE);
Spinner spinner = (Spinner) holder.findViewById(R.id.cycles_spinner);
spinner.setAdapter(mAdapter);
spinner.setSelection(mPosition);
spinner.setOnItemSelectedListener(mOnSelectedListener);
}
+ void setHasCycles(boolean hasData) {
+ setVisible(hasData);
+ if (hasData) {
+ mItemViewVisible = true;
+ if (mItemView != null) {
+ mItemView.setVisibility(View.VISIBLE);
+ }
+ }
+ }
+
@Override
protected void performClick(View view) {
view.findViewById(R.id.cycles_spinner).performClick();
diff --git a/src/com/android/settings/development/tare/AlarmManagerFragment.java b/src/com/android/settings/development/tare/AlarmManagerFragment.java
index 980954d..b9de81d 100644
--- a/src/com/android/settings/development/tare/AlarmManagerFragment.java
+++ b/src/com/android/settings/development/tare/AlarmManagerFragment.java
@@ -98,6 +98,7 @@
resources.getString(R.string.tare_actions_ctp),
resources.getString(R.string.tare_actions_base_price),
resources.getString(R.string.tare_rewards_instantaneous),
+ resources.getString(R.string.tare_rewards_ongoing),
resources.getString(R.string.tare_rewards_max)
};
@@ -109,6 +110,7 @@
resources.getStringArray(R.array.tare_alarm_manager_actions),
resources.getStringArray(R.array.tare_alarm_manager_actions),
resources.getStringArray(R.array.tare_rewards_subfactors),
+ {resources.getString(R.string.tare_top_activity)},
resources.getStringArray(R.array.tare_rewards_subfactors)
};
@@ -150,12 +152,13 @@
EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE
},
{
- EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_MAX,
- EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
- EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
- EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
- EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
+ EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_INSTANT,
+ EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_INSTANT,
+ EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT,
+ EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_INSTANT,
+ EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_INSTANT,
},
+ {EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_ONGOING},
{
EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_MAX,
EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
diff --git a/src/com/android/settings/development/tare/JobSchedulerFragment.java b/src/com/android/settings/development/tare/JobSchedulerFragment.java
index bffd648..4c5fcc6 100644
--- a/src/com/android/settings/development/tare/JobSchedulerFragment.java
+++ b/src/com/android/settings/development/tare/JobSchedulerFragment.java
@@ -99,7 +99,7 @@
resources.getString(R.string.tare_actions_ctp),
resources.getString(R.string.tare_actions_base_price),
resources.getString(R.string.tare_rewards_instantaneous),
- // resources.getString(R.string.tare_rewards_ongoing),
+ resources.getString(R.string.tare_rewards_ongoing),
resources.getString(R.string.tare_rewards_max)
};
@@ -111,7 +111,7 @@
resources.getStringArray(R.array.tare_job_scheduler_actions),
resources.getStringArray(R.array.tare_job_scheduler_actions),
resources.getStringArray(R.array.tare_rewards_subfactors),
- // {resources.getString(R.string.tare_top_activity)},
+ {resources.getString(R.string.tare_top_activity)},
resources.getStringArray(R.array.tare_rewards_subfactors)
};
@@ -154,13 +154,13 @@
EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE
},
{
- EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_MAX,
- EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_MAX,
- EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_MAX,
- EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_MAX,
- EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_MAX,
+ EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_INSTANT,
+ EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_INSTANT,
+ EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_INSTANT,
+ EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_INSTANT,
+ EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_INSTANT,
},
- // {EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_ONGOING},
+ {EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_ONGOING},
{
EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_MAX,
EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_MAX,
diff --git a/src/com/android/settings/development/tare/TareFactorController.java b/src/com/android/settings/development/tare/TareFactorController.java
index 62fde6d..5772392 100644
--- a/src/com/android/settings/development/tare/TareFactorController.java
+++ b/src/com/android/settings/development/tare/TareFactorController.java
@@ -16,6 +16,12 @@
package com.android.settings.development.tare;
+import static android.app.tare.EconomyManager.CAKE_IN_ARC;
+import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE_CAKES;
+import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE_CAKES;
+import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP_CAKES;
+import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE_CAKES;
+import static android.app.tare.EconomyManager.parseCreditValue;
import static android.provider.Settings.Global.TARE_ALARM_MANAGER_CONSTANTS;
import static android.provider.Settings.Global.TARE_JOB_SCHEDULER_CONSTANTS;
@@ -93,182 +99,180 @@
private void initAlarmManagerMap() {
mAlarmManagerMap.put(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED,
new TareFactorData(mResources.getString(R.string.tare_min_balance_exempted),
- EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_EXEMPTED,
+ EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_EXEMPTED_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP,
new TareFactorData(mResources.getString(R.string.tare_min_balance_headless_app),
- EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP,
+ EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP,
new TareFactorData(mResources.getString(R.string.tare_min_balance_other_app),
- EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_OTHER_APP,
+ EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_OTHER_APP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_MAX_SATIATED_BALANCE,
new TareFactorData(mResources.getString(R.string.tare_max_satiated_balance),
- EconomyManager.DEFAULT_AM_MAX_SATIATED_BALANCE,
+ EconomyManager.DEFAULT_AM_MAX_SATIATED_BALANCE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT,
new TareFactorData(mResources.getString(R.string.tare_initial_consumption_limit),
- EconomyManager.DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT,
+ EconomyManager.DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT,
new TareFactorData(mResources.getString(R.string.tare_hard_consumption_limit),
- EconomyManager.DEFAULT_AM_HARD_CONSUMPTION_LIMIT,
+ EconomyManager.DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_top_activity),
- EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_INSTANT,
+ EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_INSTANT_CAKES,
POLICY_ALARM_MANAGER));
- // TODO: Add support to handle floats
- // mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_ONGOING,
- // new TareFactorData(mResources.getString(R.string.tare_top_activity),
- // EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_ONGOING));
+ mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_ONGOING,
+ new TareFactorData(mResources.getString(R.string.tare_top_activity),
+ EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_ONGOING_CAKES,
+ POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_MAX,
new TareFactorData(mResources.getString(R.string.tare_top_activity),
- EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_MAX, POLICY_ALARM_MANAGER));
+ EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_MAX_CAKES,
+ POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_notification_seen),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_INSTANT,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_INSTANT_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_notification_seen),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_ONGOING,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_ONGOING_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
new TareFactorData(mResources.getString(R.string.tare_notification_seen),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_MAX,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_MAX_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_notification_seen_15_min),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_INSTANT,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_INSTANT_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_notification_seen_15_min),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_ONGOING,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_ONGOING_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_MAX,
new TareFactorData(mResources.getString(R.string.tare_notification_seen_15_min),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_MAX,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_WITHIN_15_MAX_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_notification_interaction),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_notification_interaction),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
new TareFactorData(mResources.getString(R.string.tare_notification_interaction),
- EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
+ EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_MAX_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_widget_interaction),
- EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_INSTANT,
+ EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_INSTANT_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_widget_interaction),
- EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_ONGOING,
+ EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_ONGOING_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
new TareFactorData(mResources.getString(R.string.tare_widget_interaction),
- EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_MAX,
+ EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_MAX_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_other_interaction),
- EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_INSTANT,
+ EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_INSTANT_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_other_interaction),
- EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_ONGOING,
+ EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_ONGOING_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
new TareFactorData(mResources.getString(R.string.tare_other_interaction),
- EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_MAX,
+ EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_MAX_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_wakeup_exact_idle),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP,
+ EconomyManager
+ .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_wakeup_inexact_idle),
EconomyManager
- .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP,
+ .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_EXACT_WAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_wakeup_exact),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_CTP,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_wakeup_inexact),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(
EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_nonwakeup_exact_idle),
EconomyManager
- .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP,
+ .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_nonwakeup_exact),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(
EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_nonwakeup_inexact_idle),
- EconomyManager
- .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP,
+ DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP,
new TareFactorData(mResources.getString(R.string.tare_nonwakeup_inexact),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_CTP,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_CTP,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_CTP_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(
EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager
- .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE,
+ DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(
EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager
- .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE,
+ DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(
EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(
EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager
- .DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE,
+ DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
mAlarmManagerMap.put(EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_alarm_clock),
- EconomyManager.DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE,
+ EconomyManager.DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE_CAKES,
POLICY_ALARM_MANAGER));
}
@@ -279,180 +283,181 @@
private void initJobSchedulerMap() {
mJobSchedulerMap.put(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED,
new TareFactorData(mResources.getString(R.string.tare_min_balance_exempted),
- EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_EXEMPTED,
+ EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_EXEMPTED_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP,
new TareFactorData(mResources.getString(R.string.tare_min_balance_headless_app),
- EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP,
+ EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP,
new TareFactorData(mResources.getString(R.string.tare_min_balance_other_app),
- EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_OTHER_APP,
+ EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_OTHER_APP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_MAX_SATIATED_BALANCE,
new TareFactorData(mResources.getString(R.string.tare_max_satiated_balance),
- EconomyManager.DEFAULT_JS_MAX_SATIATED_BALANCE,
+ EconomyManager.DEFAULT_JS_MAX_SATIATED_BALANCE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT,
new TareFactorData(mResources.getString(R.string.tare_initial_consumption_limit),
- EconomyManager.DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT,
+ EconomyManager.DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT,
new TareFactorData(mResources.getString(R.string.tare_hard_consumption_limit),
- EconomyManager.DEFAULT_JS_HARD_CONSUMPTION_LIMIT,
+ EconomyManager.DEFAULT_JS_HARD_CONSUMPTION_LIMIT_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_top_activity),
- EconomyManager.DEFAULT_JS_REWARD_TOP_ACTIVITY_INSTANT,
+ EconomyManager.DEFAULT_JS_REWARD_TOP_ACTIVITY_INSTANT_CAKES,
POLICY_JOB_SCHEDULER));
- // TODO: Add support to handle floats
- // mAlarmManagerMap.put(EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_ONGOING,
- // new TareFactorData(mResources.getString(R.string.tare_top_activity),
- // EconomyManager.DEFAULT_JS_REWARD_TOP_ACTIVITY_ONGOING));
+ mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_ONGOING,
+ new TareFactorData(mResources.getString(R.string.tare_top_activity),
+ EconomyManager.DEFAULT_JS_REWARD_TOP_ACTIVITY_ONGOING_CAKES,
+ POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_MAX,
new TareFactorData(mResources.getString(R.string.tare_top_activity),
- EconomyManager.DEFAULT_JS_REWARD_TOP_ACTIVITY_MAX, POLICY_JOB_SCHEDULER));
+ EconomyManager.DEFAULT_JS_REWARD_TOP_ACTIVITY_MAX_CAKES,
+ POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_notification_seen),
- EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_SEEN_INSTANT,
+ EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_SEEN_INSTANT_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_notification_seen),
- EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_SEEN_ONGOING,
+ EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_SEEN_ONGOING_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_MAX,
new TareFactorData(mResources.getString(R.string.tare_notification_seen),
- EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_SEEN_MAX,
+ EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_SEEN_MAX_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_notification_interaction),
- EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_INTERACTION_INSTANT,
+ EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_INTERACTION_INSTANT_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_notification_interaction),
- EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_INTERACTION_ONGOING,
+ EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_INTERACTION_ONGOING_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_MAX,
new TareFactorData(mResources.getString(R.string.tare_notification_interaction),
- EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_INTERACTION_MAX,
+ EconomyManager.DEFAULT_JS_REWARD_NOTIFICATION_INTERACTION_MAX_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_widget_interaction),
- EconomyManager.DEFAULT_JS_REWARD_WIDGET_INTERACTION_INSTANT,
+ EconomyManager.DEFAULT_JS_REWARD_WIDGET_INTERACTION_INSTANT_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_widget_interaction),
- EconomyManager.DEFAULT_JS_REWARD_WIDGET_INTERACTION_ONGOING,
+ EconomyManager.DEFAULT_JS_REWARD_WIDGET_INTERACTION_ONGOING_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_MAX,
new TareFactorData(mResources.getString(R.string.tare_widget_interaction),
- EconomyManager.DEFAULT_JS_REWARD_WIDGET_INTERACTION_MAX,
+ EconomyManager.DEFAULT_JS_REWARD_WIDGET_INTERACTION_MAX_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_INSTANT,
new TareFactorData(mResources.getString(R.string.tare_other_interaction),
- EconomyManager.DEFAULT_JS_REWARD_OTHER_USER_INTERACTION_INSTANT,
+ EconomyManager.DEFAULT_JS_REWARD_OTHER_USER_INTERACTION_INSTANT_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_ONGOING,
new TareFactorData(mResources.getString(R.string.tare_other_interaction),
- EconomyManager.DEFAULT_JS_REWARD_OTHER_USER_INTERACTION_ONGOING,
+ EconomyManager.DEFAULT_JS_REWARD_OTHER_USER_INTERACTION_ONGOING_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_MAX,
new TareFactorData(mResources.getString(R.string.tare_other_interaction),
- EconomyManager.DEFAULT_JS_REWARD_OTHER_USER_INTERACTION_MAX,
+ EconomyManager.DEFAULT_JS_REWARD_OTHER_USER_INTERACTION_MAX_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_MAX_START_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_max_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_START_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_START_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_MAX_RUNNING_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_max_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_RUNNING_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_RUNNING_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_HIGH_START_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_high_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_START_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_START_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_HIGH_RUNNING_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_high_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_RUNNING_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_RUNNING_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_START_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_default_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_START_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_START_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_RUNNING_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_default_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_RUNNING_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_RUNNING_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_LOW_START_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_low_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_START_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_START_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(
EconomyManager.KEY_JS_ACTION_JOB_LOW_RUNNING_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_low_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_RUNNING_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_RUNNING_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_MIN_START_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_min_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_START_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_START_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(
EconomyManager.KEY_JS_ACTION_JOB_MIN_RUNNING_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_min_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_RUNNING_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_RUNNING_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_CTP,
new TareFactorData(mResources.getString(R.string.tare_job_timeout_penalty),
- EconomyManager.DEFAULT_JS_ACTION_JOB_TIMEOUT_PENALTY_CTP,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_TIMEOUT_PENALTY_CTP_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_MAX_START_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_max_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_START_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_START_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(
EconomyManager.KEY_JS_ACTION_JOB_MAX_RUNNING_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_max_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_RUNNING_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MAX_RUNNING_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(
EconomyManager.KEY_JS_ACTION_JOB_HIGH_START_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_high_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_START_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_START_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_HIGH_RUNNING_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_high_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_RUNNING_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_HIGH_RUNNING_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_START_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_default_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_START_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_START_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(
EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_RUNNING_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_default_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_RUNNING_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_DEFAULT_RUNNING_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_LOW_START_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_low_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_START_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_START_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(
EconomyManager.KEY_JS_ACTION_JOB_LOW_RUNNING_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_low_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_RUNNING_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_LOW_RUNNING_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_MIN_START_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_min_start),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_START_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_START_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_MIN_RUNNING_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_min_running),
- EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_RUNNING_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_RUNNING_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
mJobSchedulerMap.put(EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE,
new TareFactorData(mResources.getString(R.string.tare_job_timeout_penalty),
- EconomyManager.DEFAULT_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE,
+ EconomyManager.DEFAULT_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE_CAKES,
POLICY_JOB_SCHEDULER));
}
@@ -480,7 +485,7 @@
for (int i = map.size() - 1; i >= 0; --i) {
final String key = map.keyAt(i);
final TareFactorData data = map.valueAt(i);
- data.currentValue = mParser.getInt(key, data.defaultValue);
+ data.currentValue = parseCreditValue(mParser.getString(key, null), data.defaultValue);
}
}
@@ -513,7 +518,7 @@
* @param key the key of the factor you want to get the default value of
* @param factorPolicy the policy you want the current value of
*/
- private int getCurrentValue(String key, int factorPolicy) {
+ private long getCurrentValue(String key, int factorPolicy) {
final ArrayMap<String, TareFactorData> currentMap = getMap(factorPolicy);
return currentMap.get(key).currentValue;
}
@@ -535,7 +540,7 @@
return currentMap.get(key).factorPolicy;
}
- int getValue(String key) {
+ long getValue(String key) {
final int policy = getFactorType(key);
return getCurrentValue(key, policy);
}
@@ -548,7 +553,7 @@
* @param editedValue the value entered by the user in the dialog
* @param factorPolicy policy being updated
*/
- public void updateValue(String key, int editedValue, int factorPolicy) {
+ public void updateValue(String key, long editedValue, int factorPolicy) {
final ArrayMap<String, TareFactorData> map = getMap(factorPolicy);
final TareFactorData data = map.get(key);
@@ -592,8 +597,16 @@
constantsStringBuilder
.append(factorMap.keyAt(i))
- .append("=")
- .append(factor.currentValue);
+ .append("=");
+ if (factor.currentValue % CAKE_IN_ARC == 0) {
+ constantsStringBuilder
+ .append(factor.currentValue / CAKE_IN_ARC)
+ .append("A");
+ } else {
+ constantsStringBuilder
+ .append(factor.currentValue)
+ .append("ck");
+ }
}
Settings.Global.putString(mContentResolver, settingsKey, constantsStringBuilder.toString());
@@ -615,11 +628,11 @@
*/
private static class TareFactorData {
public final String title;
- public final int defaultValue;
+ public final long defaultValue;
public final int factorPolicy;
- public int currentValue;
+ public long currentValue;
- TareFactorData(String title, int defaultValue, int factorPolicy) {
+ TareFactorData(String title, long defaultValue, int factorPolicy) {
this.title = title;
this.defaultValue = defaultValue;
this.factorPolicy = factorPolicy;
diff --git a/src/com/android/settings/development/tare/TareFactorDialogFragment.java b/src/com/android/settings/development/tare/TareFactorDialogFragment.java
index 8d2f341..6d2f5ca 100644
--- a/src/com/android/settings/development/tare/TareFactorDialogFragment.java
+++ b/src/com/android/settings/development/tare/TareFactorDialogFragment.java
@@ -16,6 +16,8 @@
package com.android.settings.development.tare;
+import static android.app.tare.EconomyManager.CAKE_IN_ARC;
+
import android.annotation.NonNull;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -26,7 +28,10 @@
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.EditText;
+import android.widget.Spinner;
import com.android.settings.R;
import com.android.settings.Utils;
@@ -35,39 +40,35 @@
* Dialog Fragment for changing tare factor values
*/
public class TareFactorDialogFragment extends DialogFragment {
-
private static final String TAG = "TareDialogFragment";
+ // This follows the order in strings.xml:tare_units array.
+ private static final int UNIT_IDX_ARC = 0;
+ private static final int UNIT_IDX_CAKE = 1;
+
private final String mFactorKey;
private final String mFactorTitle;
- private final int mFactorValue;
+ private final long mFactorValue;
private final int mFactorPolicy;
- private int mFactorEditedValue;
+ private final TareFactorController mTareFactorController;
private EditText mFactorValueView;
- private TareFactorController mTareFactorController;
+ private Spinner mUnitSpinner;
/**
* @param title the title that will show at the top of the Dialog for the Factor
* @param key the key of the Factor being initialized.
- * @param defaultValue the initial value set for the Factor before any changes
+ * @param currentValue the current value set for the Factor
*/
- public TareFactorDialogFragment(@NonNull String title, @NonNull String key, int defaultValue,
+ public TareFactorDialogFragment(@NonNull String title, @NonNull String key, long currentValue,
int factorPolicy, TareFactorController tareFactorController) {
mFactorTitle = title;
mFactorKey = key;
- mFactorValue = defaultValue;
+ mFactorValue = currentValue;
mFactorPolicy = factorPolicy;
mTareFactorController = tareFactorController;
}
- /**
- * Gets the current value of the Factor
- */
- private String getFactorValue() {
- return Integer.toString(mFactorValue);
- }
-
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -78,15 +79,18 @@
.setPositiveButton(R.string.tare_dialog_confirm_button_title, (dialog, which) -> {
final String stringValue = mFactorValueView.getText().toString();
- mFactorEditedValue = mFactorValue;
+ long newVal = mFactorValue;
try {
- mFactorEditedValue = Integer.parseInt(stringValue);
+ newVal = Long.parseLong(stringValue);
+ if (mUnitSpinner.getSelectedItemPosition() == UNIT_IDX_ARC) {
+ // Convert ARC to cake
+ newVal *= CAKE_IN_ARC;
+ }
} catch (NumberFormatException e) {
- Log.e(TAG, "Error converting '" + stringValue + "' to integer. Using "
+ Log.e(TAG, "Error parsing '" + stringValue + "'. Using "
+ mFactorValue + " instead", e);
}
- mTareFactorController.updateValue(mFactorKey, mFactorEditedValue,
- mFactorPolicy);
+ mTareFactorController.updateValue(mFactorKey, newVal, mFactorPolicy);
})
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
// When the negative button is clicked do nothing
@@ -102,12 +106,58 @@
private View createDialogView() {
final LayoutInflater layoutInflater = (LayoutInflater) getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View layout = layoutInflater.inflate(R.layout.dialog_edittext, null);
+ View layout = layoutInflater.inflate(R.layout.dialog_edittext_dropdown, null);
mFactorValueView = layout.findViewById(R.id.edittext);
mFactorValueView.setInputType(InputType.TYPE_CLASS_NUMBER);
- mFactorValueView.setText(getFactorValue());
- Utils.setEditTextCursorPosition(mFactorValueView);
+ mUnitSpinner = layout.findViewById(R.id.spinner);
+ final String[] units = getResources().getStringArray(R.array.tare_units);
+ ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(
+ getActivity(), android.R.layout.simple_spinner_item, units);
+ mUnitSpinner.setAdapter(spinnerArrayAdapter);
+
+ final int unitIdx;
+ if (mFactorValue % CAKE_IN_ARC == 0) {
+ mFactorValueView.setText(String.format("%d", mFactorValue / CAKE_IN_ARC));
+ unitIdx = UNIT_IDX_ARC;
+ } else {
+ mFactorValueView.setText(String.format("%d", mFactorValue));
+ unitIdx = UNIT_IDX_CAKE;
+ }
+ mUnitSpinner.setSelection(unitIdx);
+ mUnitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ private int mSelectedPosition = unitIdx;
+
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ if (mSelectedPosition == position) {
+ return;
+ }
+ mSelectedPosition = position;
+ final String stringValue = mFactorValueView.getText().toString();
+
+ try {
+ long newVal = Long.parseLong(stringValue);
+ if (mUnitSpinner.getSelectedItemPosition() == UNIT_IDX_ARC) {
+ // Convert cake to ARC
+ newVal /= CAKE_IN_ARC;
+ } else {
+ // Convert ARC to cake
+ newVal *= CAKE_IN_ARC;
+ }
+ mFactorValueView.setText(String.format("%d", newVal));
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "Error parsing '" + stringValue + "'", e);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+
+ }
+ });
+
+ Utils.setEditTextCursorPosition(mFactorValueView);
return layout;
}
}
diff --git a/src/com/android/settings/development/tare/TareFactorExpandableListAdapter.java b/src/com/android/settings/development/tare/TareFactorExpandableListAdapter.java
index 8fe4c05..79b7d41 100644
--- a/src/com/android/settings/development/tare/TareFactorExpandableListAdapter.java
+++ b/src/com/android/settings/development/tare/TareFactorExpandableListAdapter.java
@@ -16,6 +16,8 @@
package com.android.settings.development.tare;
+import static android.app.tare.EconomyManager.CAKE_IN_ARC;
+
import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.view.LayoutInflater;
@@ -130,12 +132,32 @@
TextView value = convertView.findViewById(R.id.factor_number);
factor.setText(getChild(groupPosition, childPosition).toString());
- value.setText(String.valueOf(
+ value.setText(cakeToString(
mFactorController.getValue(getKey(groupPosition, childPosition))));
return convertView;
}
+ @NonNull
+ private static String cakeToString(long cakes) {
+ // Resources.getQuantityString doesn't handle floating point numbers, so doing this manually
+ if (cakes == 0) {
+ return "0";
+ }
+ final long sub = cakes % CAKE_IN_ARC;
+ final long arcs = (int) (cakes / CAKE_IN_ARC);
+ if (arcs == 0) {
+ return sub + " c";
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(arcs);
+ if (sub > 0) {
+ sb.append(".").append(String.format("%03d", sub / (CAKE_IN_ARC / 1000)));
+ }
+ sb.append(" A");
+ return sb.toString();
+ }
+
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index f3085bc..b1ffcf1 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -69,7 +69,7 @@
mCm = cm;
mVm = vm;
mResources = resources;
- mWorkPolicyUtils = new WorkPolicyUtils(mContext, mPm, mUm, mDpm);
+ mWorkPolicyUtils = new WorkPolicyUtils(mContext);
}
@Override
diff --git a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
index 8fb0d1e..db4cc53 100644
--- a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
@@ -424,6 +424,9 @@
@VisibleForTesting
void setUsageSummary(Preference preference, BatteryEntry entry) {
+ if (entry.getUid() == Process.SYSTEM_UID) {
+ return;
+ }
// Only show summary when usage time is longer than one minute
final long usageTimeMs = entry.getTimeInForegroundMs();
if (shouldShowSummary(entry) && usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index 98f19fe..b1e4c34 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -153,6 +153,7 @@
new AsyncTask<Void, Void, BatteryInfo>() {
@Override
protected BatteryInfo doInBackground(Void... params) {
+ boolean shouldCloseBatteryUsageStats = false;
BatteryUsageStats stats;
if (batteryUsageStats != null) {
stats = batteryUsageStats;
@@ -160,6 +161,7 @@
try {
stats = context.getSystemService(BatteryStatsManager.class)
.getBatteryUsageStats();
+ shouldCloseBatteryUsageStats = true;
} catch (RuntimeException e) {
Log.e(TAG, "getBatteryInfo() from getBatteryUsageStats()", e);
// Use default BatteryUsageStats.
@@ -168,10 +170,12 @@
}
final BatteryInfo batteryInfo =
getBatteryInfo(context, stats, shortString);
- try {
- stats.close();
- } catch (Exception e) {
- Log.e(TAG, "BatteryUsageStats.close() failed", e);
+ if (shouldCloseBatteryUsageStats) {
+ try {
+ stats.close();
+ } catch (Exception e) {
+ Log.e(TAG, "BatteryUsageStats.close() failed", e);
+ }
}
return batteryInfo;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index e950679..6563155 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -83,6 +83,7 @@
public void onStop() {
super.onStop();
mBatteryBroadcastReceiver.unRegister();
+ closeBatteryUsageStatsIfNeeded();
}
protected void restartBatteryStatsLoader(int refreshType) {
@@ -104,16 +105,6 @@
final long startTime = System.currentTimeMillis();
historyPref.setBatteryUsageStats(mBatteryUsageStats);
BatteryUtils.logRuntime(TAG, "updatePreference", startTime);
- if (mBatteryUsageStats == null) {
- return;
- }
- try {
- mBatteryUsageStats.close();
- } catch (Exception e) {
- Log.e(TAG, "BatteryUsageStats.close() failed", e);
- } finally {
- mBatteryUsageStats = null;
- }
}
private class BatteryUsageStatsLoaderCallbacks
@@ -130,6 +121,7 @@
@Override
public void onLoadFinished(Loader<BatteryUsageStats> loader,
BatteryUsageStats batteryUsageStats) {
+ closeBatteryUsageStatsIfNeeded();
mBatteryUsageStats = batteryUsageStats;
PowerUsageBase.this.onLoadFinished(mRefreshType);
}
@@ -138,4 +130,17 @@
public void onLoaderReset(Loader<BatteryUsageStats> loader) {
}
}
+
+ private void closeBatteryUsageStatsIfNeeded() {
+ if (mBatteryUsageStats == null) {
+ return;
+ }
+ try {
+ mBatteryUsageStats.close();
+ } catch (Exception e) {
+ Log.e(TAG, "BatteryUsageStats.close() failed", e);
+ } finally {
+ mBatteryUsageStats = null;
+ }
+ }
}
diff --git a/src/com/android/settings/localepicker/AppLocalePickerActivity.java b/src/com/android/settings/localepicker/AppLocalePickerActivity.java
index 4700f3f..1ed6f5b 100644
--- a/src/com/android/settings/localepicker/AppLocalePickerActivity.java
+++ b/src/com/android/settings/localepicker/AppLocalePickerActivity.java
@@ -30,7 +30,6 @@
import android.widget.FrameLayout;
import android.widget.ListView;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.LocalePickerWithRegion;
import com.android.internal.app.LocaleStore;
import com.android.settings.R;
@@ -38,10 +37,6 @@
import com.android.settings.applications.appinfo.AppLocaleDetails;
import com.android.settings.core.SettingsBaseActivity;
-/**
- * TODO(b/223503670): Add unit test for AppLocalePickerActivity.
- * A activity to show the locale picker and information page.
- */
public class AppLocalePickerActivity extends SettingsBaseActivity
implements LocalePickerWithRegion.LocaleSelectedListener {
private static final String TAG = AppLocalePickerActivity.class.getSimpleName();
@@ -128,8 +123,7 @@
return appLocaleDetailsContainer;
}
- @VisibleForTesting
- void launchLocalePickerPage() {
+ private void launchLocalePickerPage() {
// LocalePickerWithRegion use android.app.ListFragment. Thus, it can not use
// getSupportFragmentManager() to add this into container.
android.app.FragmentManager fragmentManager = getFragmentManager();
diff --git a/src/com/android/settings/nearby/FastPairPreferenceController.java b/src/com/android/settings/nearby/FastPairPreferenceController.java
deleted file mode 100644
index a115202..0000000
--- a/src/com/android/settings/nearby/FastPairPreferenceController.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2022 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.nearby;
-
-import android.content.Context;
-
-import androidx.lifecycle.LifecycleObserver;
-
-import com.android.settings.core.BasePreferenceController;
-
-/**
- * {@link BasePreferenceController} for Fast Pair settings.
- */
-public class FastPairPreferenceController extends BasePreferenceController implements
- LifecycleObserver {
- public static final String TAG = "FastPairPrefController";
- public static final String KEY_FAST_PAIR_SETTINGS = "connected_device_fast_pair";
-
- public FastPairPreferenceController(Context context) {
- super(context, KEY_FAST_PAIR_SETTINGS);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-}
diff --git a/src/com/android/settings/nearby/FastPairSettingsFragment.java b/src/com/android/settings/nearby/FastPairSettingsFragment.java
deleted file mode 100644
index a92833a..0000000
--- a/src/com/android/settings/nearby/FastPairSettingsFragment.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2022 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.nearby;
-
-import android.app.settings.SettingsEnums;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.os.Bundle;
-import android.provider.Settings;
-import android.text.TextUtils;
-import android.util.Log;
-
-import androidx.annotation.Nullable;
-import androidx.preference.Preference;
-
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.search.SearchIndexable;
-import com.android.settingslib.widget.MainSwitchPreference;
-
-import java.util.Objects;
-
-/**
- * Fragment with the top level fast pair settings.
- */
-@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
-public class FastPairSettingsFragment extends SettingsPreferenceFragment {
-
- private static final String TAG = "FastPairSettingsFrag";
-
- private static final String SCAN_SWITCH_KEY = "fast_pair_scan_switch";
- private static final String SAVED_DEVICES_PREF_KEY = "saved_devices";
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- MainSwitchPreference mainSwitchPreference = Objects.requireNonNull(
- findPreference(SCAN_SWITCH_KEY));
- mainSwitchPreference.setChecked(false);
-
- Preference savedDevicePref = Objects.requireNonNull(
- findPreference(SAVED_DEVICES_PREF_KEY));
- savedDevicePref.setOnPreferenceClickListener(preference -> {
- Intent savedDevicesIntent = getSavedDevicesIntent();
- if (savedDevicesIntent != null && getActivity() != null) {
- getActivity().startActivity(savedDevicesIntent);
- }
- return true;
- });
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.CONNECTION_DEVICE_ADVANCED_FAST_PAIR;
- }
-
- @Override
- public int getHelpResource() {
- return 0;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.fast_pair_settings;
- }
-
- public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider(R.xml.fast_pair_settings);
-
- @Nullable
- private ComponentName getSavedDevicesComponent() {
- String savedDevicesComponent = Settings.Secure.getString(
- getContentResolver(),
- Settings.Secure.NEARBY_FAST_PAIR_SETTINGS_DEVICES_COMPONENT);
- if (TextUtils.isEmpty(savedDevicesComponent)) {
- savedDevicesComponent = getString(
- com.android.internal.R.string.config_defaultNearbyFastPairSettingsDevicesComponent);
- }
-
- if (TextUtils.isEmpty(savedDevicesComponent)) {
- return null;
- }
-
- return ComponentName.unflattenFromString(savedDevicesComponent);
- }
-
- @Nullable
- private Intent getSavedDevicesIntent() {
- ComponentName componentName = getSavedDevicesComponent();
- if (componentName == null) {
- return null;
- }
-
- PackageManager pm = getPackageManager();
- Intent intent = getIntent();
- intent.setAction(Intent.ACTION_VIEW);
- intent.setComponent(componentName);
-
- final ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.GET_META_DATA);
- if (resolveInfo == null || resolveInfo.activityInfo == null) {
- Log.e(TAG, "Device-specified fast pair component (" + componentName
- + ") not available");
- return null;
- }
- return intent;
- }
-}
diff --git a/src/com/android/settings/network/SubscriptionsPreferenceController.java b/src/com/android/settings/network/SubscriptionsPreferenceController.java
index 218e3ec..44ad411 100644
--- a/src/com/android/settings/network/SubscriptionsPreferenceController.java
+++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java
@@ -232,11 +232,11 @@
connectCarrierNetwork();
return true;
});
-
- mSubsGearPref.setOnGearClickListener(p ->
- MobileNetworkUtils.launchMobileNetworkSettings(mContext, subInfo));
}
+ mSubsGearPref.setOnGearClickListener(p ->
+ MobileNetworkUtils.launchMobileNetworkSettings(mContext, subInfo));
+
if (!(mContext.getSystemService(UserManager.class)).isAdminUser()) {
mSubsGearPref.setGearEnabled(false);
}
diff --git a/src/com/android/settings/network/helper/LifecycleCallbackIntentReceiver.java b/src/com/android/settings/network/helper/LifecycleCallbackIntentReceiver.java
deleted file mode 100644
index 8aaa53e..0000000
--- a/src/com/android/settings/network/helper/LifecycleCallbackIntentReceiver.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network.helper;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Handler;
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.Lifecycle;
-import java.util.function.Consumer;
-
-/**
- * A {@link BroadcastReceiver} for {@link Intent}.
- *
- * This is {@link BroadcastReceiver} supported by {@link LifecycleCallbackConverter},
- * and only register when state is either START or RESUME.
- */
-@VisibleForTesting
-public class LifecycleCallbackIntentReceiver extends LifecycleCallbackConverter<Intent> {
- private static final String TAG = "LifecycleCallbackIntentReceiver";
-
- @VisibleForTesting
- protected final BroadcastReceiver mReceiver;
-
- private final Runnable mRegisterCallback;
- private final Runnable mUnRegisterCallback;
-
- /**
- * Constructor
- * @param lifecycle {@link Lifecycle} to monitor
- * @param context for this BroadcastReceiver
- * @param filter the IntentFilter for BroadcastReceiver
- * @param broadcastPermission for permission when listening
- * @param scheduler for running in background thread
- * @param resultCallback for the Intent from BroadcastReceiver
- */
- @VisibleForTesting
- public LifecycleCallbackIntentReceiver(@NonNull Lifecycle lifecycle,
- @NonNull Context context, @NonNull IntentFilter filter,
- String broadcastPermission, Handler scheduler,
- @NonNull Consumer<Intent> resultCallback) {
- super(lifecycle, resultCallback);
-
- // BroadcastReceiver
- mReceiver = new BroadcastReceiver() {
- public void onReceive(Context context, Intent intent) {
- if (isInitialStickyBroadcast()) {
- return;
- }
- final String action = intent.getAction();
- if ((action == null) || (action.length() <= 0)) {
- return;
- }
- postResult(intent);
- }
- };
-
- // Register operation
- mRegisterCallback = () -> {
- Intent initIntent = context.registerReceiver(mReceiver,
- filter, broadcastPermission, scheduler);
- if (initIntent != null) {
- postResult(initIntent);
- }
- };
-
- // Un-Register operation
- mUnRegisterCallback = () -> {
- context.unregisterReceiver(mReceiver);
- };
- }
-
- @Override
- public void setCallbackActive(boolean isActive) {
- super.setCallbackActive(isActive);
- Runnable op = (isActive) ? mRegisterCallback : mUnRegisterCallback;
- op.run();
- }
-
- @Override
- public void close() {
- super.close();
- if (isCallbackActive()) {
- setCallbackActive(false);
- }
- }
-}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index 763962c..4eb8a85 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -37,6 +37,7 @@
import com.android.settings.R;
import com.android.settings.Settings.MobileNetworkActivity;
+import com.android.settings.SettingsActivity;
import com.android.settings.datausage.BillingCyclePreferenceController;
import com.android.settings.datausage.DataUsageSummaryPreferenceController;
import com.android.settings.network.ActiveSubscriptionsListener;
@@ -54,6 +55,7 @@
import java.util.Arrays;
import java.util.List;
+import java.util.function.Consumer;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
@@ -275,17 +277,37 @@
Log.d(LOG_TAG, "Callback during onResume()");
return;
}
+
+ final SubscriptionInfo subInfo = SubscriptionUtil
+ .getSubscriptionOrDefault(getContext(), mSubId);
+
+ if (subInfo != null) {
+ /**
+ * Update the title when SIM stats got changed
+ */
+ final Consumer<Activity> renameTitle = activity -> {
+ if (activity != null && !activity.isFinishing()) {
+ if (activity instanceof SettingsActivity) {
+ final CharSequence displayName = SubscriptionUtil
+ .getUniqueSubscriptionDisplayName(subInfo, activity);
+ ((SettingsActivity)activity).setTitle(displayName);
+ }
+ }
+ };
+
+ ThreadUtils.postOnMainThread(() -> renameTitle.accept(getActivity()));
+ }
+
mActiveSubscriptionsListenerCount++;
if (mActiveSubscriptionsListenerCount != 1) {
return;
}
- if (SubscriptionUtil.getSubscriptionOrDefault(getContext(), mSubId) == null) {
- finishFragment();
- return;
- }
-
ThreadUtils.postOnMainThread(() -> {
+ if (subInfo == null) {
+ finishFragment();
+ return;
+ }
mActiveSubscriptionsListenerCount = 0;
redrawPreferenceControllers();
});
diff --git a/src/com/android/settings/notification/MediaVolumePreferenceController.java b/src/com/android/settings/notification/MediaVolumePreferenceController.java
index 978a4b4..c0d5610 100644
--- a/src/com/android/settings/notification/MediaVolumePreferenceController.java
+++ b/src/com/android/settings/notification/MediaVolumePreferenceController.java
@@ -35,6 +35,7 @@
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settingslib.media.MediaDevice;
+import com.android.settingslib.media.MediaOutputConstants;
public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceController {
private static final String TAG = "MediaVolumePreCtrl";
@@ -106,8 +107,10 @@
final Intent intent = new Intent();
if (getWorker().isDeviceBroadcasting()) {
- // TODO(b/229577323) : Get the intent action for the Media Output Broadcast Dialog
- // in SystemUI
+ intent.setPackage(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME);
+ intent.setAction(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG);
+ intent.putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME,
+ getWorker().getActiveLocalMediaController().getPackageName());
} else {
// TODO(b/229577518) : Get the intent action of the Bluetooth Broadcast Dialog
// for user to choose the action
diff --git a/src/com/android/settings/widget/EmptyTextSettings.java b/src/com/android/settings/widget/EmptyTextSettings.java
index 87513dd..a6e5c60 100644
--- a/src/com/android/settings/widget/EmptyTextSettings.java
+++ b/src/com/android/settings/widget/EmptyTextSettings.java
@@ -43,8 +43,10 @@
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, value, true);
mEmpty.setTextAppearance(value.resourceId);
+ final int layoutHeight = getContext().getResources()
+ .getDimensionPixelSize(R.dimen.empty_text_layout_height);
((ViewGroup) view.findViewById(android.R.id.list_container)).addView(mEmpty,
- new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+ new LayoutParams(LayoutParams.MATCH_PARENT, layoutHeight));
setEmptyView(mEmpty);
}
diff --git a/src/com/android/settings/widget/SettingsMainSwitchPreference.java b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
index f1eb603..b7c6901 100644
--- a/src/com/android/settings/widget/SettingsMainSwitchPreference.java
+++ b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
@@ -199,9 +199,10 @@
* Set the OnBeforeCheckedChangeListener.
*/
public void setOnBeforeCheckedChangeListener(OnBeforeCheckedChangeListener listener) {
- if (mMainSwitchBar == null) {
+ if (!mBeforeCheckedChangeListeners.contains(listener)) {
mBeforeCheckedChangeListeners.add(listener);
- } else {
+ }
+ if (mMainSwitchBar != null) {
mMainSwitchBar.setOnBeforeCheckedChangeListener(listener);
}
}
@@ -210,9 +211,10 @@
* Adds a listener for switch changes
*/
public void addOnSwitchChangeListener(OnMainSwitchChangeListener listener) {
- if (mMainSwitchBar == null) {
+ if (!mSwitchChangeListeners.contains(listener)) {
mSwitchChangeListeners.add(listener);
- } else {
+ }
+ if (mMainSwitchBar != null) {
mMainSwitchBar.addOnSwitchChangeListener(listener);
}
}
@@ -221,9 +223,8 @@
* Remove a listener for switch changes
*/
public void removeOnSwitchChangeListener(OnMainSwitchChangeListener listener) {
- if (mMainSwitchBar == null) {
- mSwitchChangeListeners.remove(listener);
- } else {
+ mSwitchChangeListeners.remove(listener);
+ if (mMainSwitchBar != null) {
mMainSwitchBar.removeOnSwitchChangeListener(listener);
}
}
@@ -254,7 +255,5 @@
for (OnMainSwitchChangeListener listener : mSwitchChangeListeners) {
mMainSwitchBar.addOnSwitchChangeListener(listener);
}
- mBeforeCheckedChangeListeners.clear();
- mSwitchChangeListeners.clear();
}
}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
index 821c6e4..3fd6c45 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -37,6 +37,7 @@
import android.os.SimpleClock;
import android.os.SystemClock;
import android.text.TextUtils;
+import android.util.EventLog;
import android.util.Log;
import android.util.Size;
import android.view.LayoutInflater;
@@ -58,6 +59,7 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.qrcode.QrCamera;
import com.android.settingslib.qrcode.QrDecorateView;
+import com.android.settingslib.wifi.WifiPermissionChecker;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker;
@@ -117,9 +119,9 @@
private int mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE;
- @VisibleForTesting
- WifiPickerTracker mWifiPickerTracker;
+ private WifiPickerTracker mWifiPickerTracker;
private HandlerThread mWorkerThread;
+ private WifiPermissionChecker mWifiPermissionChecker;
private final Handler mHandler = new Handler() {
@Override
@@ -363,6 +365,15 @@
mIsConfiguratorMode = true;
}
+ public WifiDppQrCodeScannerFragment(WifiPickerTracker wifiPickerTracker,
+ WifiPermissionChecker wifiPermissionChecker) {
+ super();
+
+ mIsConfiguratorMode = true;
+ mWifiPickerTracker = wifiPickerTracker;
+ mWifiPermissionChecker = wifiPermissionChecker;
+ }
+
/**
* Enrollee container activity of the fragment should create instance with this constructor and
* specify the SSID string of the WI-Fi network to be provisioned.
@@ -719,6 +730,28 @@
resultIntent.putExtra(KEY_WIFI_CONFIGURATION, mEnrolleeWifiConfiguration);
final Activity hostActivity = getActivity();
+ if (hostActivity == null) return;
+ if (mWifiPermissionChecker == null) {
+ mWifiPermissionChecker = new WifiPermissionChecker(hostActivity);
+ }
+
+ if (!mWifiPermissionChecker.canAccessWifiState()) {
+ Log.w(TAG, "Calling package does not have ACCESS_WIFI_STATE permission for result.");
+ EventLog.writeEvent(0x534e4554, "187176859",
+ mWifiPermissionChecker.getLaunchedPackage(), "no ACCESS_WIFI_STATE permission");
+ hostActivity.finish();
+ return;
+ }
+
+ if (!mWifiPermissionChecker.canAccessFineLocation()) {
+ Log.w(TAG, "Calling package does not have ACCESS_FINE_LOCATION permission for result.");
+ EventLog.writeEvent(0x534e4554, "187176859",
+ mWifiPermissionChecker.getLaunchedPackage(),
+ "no ACCESS_FINE_LOCATION permission");
+ hostActivity.finish();
+ return;
+ }
+
hostActivity.setResult(Activity.RESULT_OK, resultIntent);
hostActivity.finish();
}
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java b/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java
index db150da..5d73fa4 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pPreferenceController.java
@@ -15,18 +15,17 @@
*/
package com.android.settings.wifi.p2p;
-import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.location.LocationManager;
import android.net.wifi.WifiManager;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -70,6 +69,9 @@
super.displayPreference(screen);
mWifiDirectPref = screen.findPreference(KEY_WIFI_DIRECT);
togglePreferences();
+ if (!mIsWifiDirectAllow) {
+ mWifiDirectPref.setSummary(R.string.not_allowed_by_ent);
+ }
}
@Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
index 94bd78a..73ff31d 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
@@ -46,12 +46,9 @@
private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
- private final TetheringManager mTetheringManager;
- private final String[] mWifiRegexs;
- private final WifiManager mWifiManager;
- private final Lifecycle mLifecycle;
- @VisibleForTesting
- boolean mIsWifiTetheringAllow;
+ private boolean mIsWifiTetherable;
+ private WifiManager mWifiManager;
+ private boolean mIsWifiTetheringAllow;
private int mSoftApState;
@VisibleForTesting
Preference mPreference;
@@ -59,18 +56,32 @@
WifiTetherSoftApManager mWifiTetherSoftApManager;
public WifiTetherPreferenceController(Context context, Lifecycle lifecycle) {
- this(context, lifecycle, true /* initSoftApManager */);
+ this(context, lifecycle,
+ context.getSystemService(WifiManager.class),
+ context.getSystemService(TetheringManager.class),
+ true /* initSoftApManager */,
+ WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context));
}
@VisibleForTesting
- WifiTetherPreferenceController(Context context, Lifecycle lifecycle,
- boolean initSoftApManager) {
+ WifiTetherPreferenceController(
+ Context context,
+ Lifecycle lifecycle,
+ WifiManager wifiManager,
+ TetheringManager tetheringManager,
+ boolean initSoftApManager,
+ boolean isWifiTetheringAllow) {
super(context);
- mTetheringManager = context.getSystemService(TetheringManager.class);
- mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- mWifiRegexs = mTetheringManager.getTetherableWifiRegexs();
- mIsWifiTetheringAllow = WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context);
- mLifecycle = lifecycle;
+ final String[] wifiRegexs = tetheringManager.getTetherableWifiRegexs();
+ if (wifiRegexs != null && wifiRegexs.length != 0) {
+ mIsWifiTetherable = true;
+ }
+
+ mIsWifiTetheringAllow = isWifiTetheringAllow;
+ if (!isWifiTetheringAllow) return;
+
+ mWifiManager = wifiManager;
+
if (lifecycle != null) {
lifecycle.addObserver(this);
}
@@ -81,9 +92,7 @@
@Override
public boolean isAvailable() {
- return mWifiRegexs != null
- && mWifiRegexs.length != 0
- && !Utils.isMonkeyRunning();
+ return mIsWifiTetherable && !Utils.isMonkeyRunning();
}
@Override
@@ -94,7 +103,10 @@
// unavailable
return;
}
- mPreference.setEnabled(mIsWifiTetheringAllow);
+ if (!mIsWifiTetheringAllow && mPreference.isEnabled()) {
+ mPreference.setEnabled(false);
+ mPreference.setSummary(R.string.not_allowed_by_ent);
+ }
}
@Override
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingFragmentBaseControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingFragmentBaseControllerTest.java
new file mode 100644
index 0000000..ad6a895
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingFragmentBaseControllerTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2022 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.android.settings.accessibility.TextReadingPreferenceFragment.EXTRA_LAUNCHED_FROM;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.UNKNOWN_ENTRY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.preference.Preference;
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Tests for {@link TextReadingFragmentBaseController}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class TextReadingFragmentBaseControllerTest {
+ private static final String FRAGMENT_PREF_KEY = "FRAGMENT_PREF_KEY";
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+
+ @Test
+ public void handlePreferenceClick_getExtraWithA11ySettingsEntryPoint() {
+ final Preference a11ySettingsPreference = new Preference(mContext);
+ a11ySettingsPreference.setKey(FRAGMENT_PREF_KEY);
+ final TextReadingFragmentBaseController mA11ySettingsFragmentController =
+ new TextReadingFragmentBaseController(mContext, FRAGMENT_PREF_KEY,
+ ACCESSIBILITY_SETTINGS);
+
+ mA11ySettingsFragmentController.handlePreferenceTreeClick(a11ySettingsPreference);
+
+ assertThat(a11ySettingsPreference.getExtras().getInt(EXTRA_LAUNCHED_FROM,
+ UNKNOWN_ENTRY)).isEqualTo(ACCESSIBILITY_SETTINGS);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/VibrationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/VibrationPreferenceControllerTest.java
index 40e31fd..a045dea 100644
--- a/tests/robotests/src/com/android/settings/accessibility/VibrationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/VibrationPreferenceControllerTest.java
@@ -92,7 +92,7 @@
controller.updateState(mPreference);
assertThat(mPreference.getSummary().toString()).isEqualTo(
- mContext.getString(R.string.switch_on_text));
+ mContext.getString(R.string.accessibility_vibration_settings_state_on));
}
@Test
@@ -103,7 +103,7 @@
controller.updateState(mPreference);
assertThat(mPreference.getSummary().toString()).isEqualTo(
- mContext.getString(R.string.switch_on_text));
+ mContext.getString(R.string.accessibility_vibration_settings_state_on));
}
@Test
@@ -114,7 +114,7 @@
controller.updateState(mPreference);
assertThat(mPreference.getSummary().toString()).isEqualTo(
- mContext.getString(R.string.switch_off_text));
+ mContext.getString(R.string.accessibility_vibration_settings_state_off));
}
private VibrationPreferenceController createPreferenceController() {
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
index 09c5734..f043ec7 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
@@ -43,7 +43,6 @@
import android.telephony.SubscriptionManager;
import android.text.format.DateUtils;
import android.util.ArraySet;
-import android.view.View;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
@@ -96,6 +95,10 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+
+ ShadowEntityHeaderController.setUseMock(mHeaderController);
+ when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
+ when(mHeaderController.setUid(anyInt())).thenReturn(mHeaderController);
}
@After
@@ -163,10 +166,6 @@
@Test
public void bindAppHeader_allWorkApps_shouldNotShowAppInfoLink() {
- ShadowEntityHeaderController.setUseMock(mHeaderController);
- when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
- when(mHeaderController.setUid(anyInt())).thenReturn(mHeaderController);
-
mFragment = spy(new AppDataUsage());
when(mFragment.getPreferenceManager())
@@ -174,7 +173,7 @@
doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
ReflectionHelpers.setField(mFragment, "mAppItem", mock(AppItem.class));
- mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
+ mFragment.addEntityHeader();
verify(mHeaderController).setHasAppInfoLink(false);
}
@@ -196,16 +195,13 @@
when(mPackageManager.getPackageUidAsUser(anyString(), anyInt()))
.thenReturn(fakeUserId);
- ShadowEntityHeaderController.setUseMock(mHeaderController);
- when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
- when(mHeaderController.setUid(fakeUserId)).thenReturn(mHeaderController);
when(mHeaderController.setHasAppInfoLink(anyBoolean())).thenReturn(mHeaderController);
when(mFragment.getPreferenceManager())
.thenReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS));
doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
- mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
+ mFragment.addEntityHeader();
verify(mHeaderController).setHasAppInfoLink(true);
verify(mHeaderController).setUid(fakeUserId);
@@ -268,7 +264,7 @@
mFragment.bindData(0 /* position */);
- verify(cycle).setVisible(false);
+ verify(cycle).setHasCycles(false);
}
@Test
@@ -293,7 +289,7 @@
mFragment.bindData(0 /* position */);
- verify(cycle).setVisible(true);
+ verify(cycle).setHasCycles(true);
verify(totalPref).setSummary(
DataUsageUtils.formatDataUsage(context, backgroundBytes + foregroundBytes));
verify(backgroundPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index 0005e71..87a447d 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -105,6 +105,10 @@
when(mContext.getApplicationContext()).thenReturn(mContext);
resetAndInitializePackageManager();
when(mUserManager.getProfiles(mUserId)).thenReturn(mProfiles);
+ when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
+ .thenReturn(mDevicePolicyManager);
+ when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
mProfiles.add(new UserInfo(mUserId, "", "", 0 /* flags */));
mResources = RuntimeEnvironment.application.getResources();
diff --git a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
new file mode 100644
index 0000000..4d5e0b9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2022 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.localepicker;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.app.ApplicationPackageManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.InstallSourceInfo;
+import android.net.Uri;
+import android.os.Process;
+import android.os.UserHandle;
+import android.telephony.TelephonyManager;
+
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.R;
+import com.android.settings.applications.AppInfoBase;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.Shadows;
+import org.robolectric.android.controller.ActivityController;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.shadows.ShadowTelephonyManager;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(
+ shadows = {
+ AppLocalePickerActivityTest.ShadowApplicationPackageManager.class,
+ })
+public class AppLocalePickerActivityTest {
+ private static final String TEST_PACKAGE_NAME = "com.android.settings";
+ private static final Uri TEST_PACKAGE_URI = Uri.parse("package:" + TEST_PACKAGE_NAME);
+
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
+
+ @Test
+ public void launchAppLocalePickerActivity_hasPackageName_success() {
+ ActivityController<TestAppLocalePickerActivity> controller =
+ initActivityController(true);
+
+ controller.create();
+
+ assertThat(controller.get().isFinishing()).isFalse();
+ }
+
+ @Test
+ public void launchAppLocalePickerActivity_intentWithoutPackageName_failed() {
+ ActivityController<TestAppLocalePickerActivity> controller =
+ initActivityController(false);
+
+ controller.create();
+
+ assertThat(controller.get().isFinishing()).isTrue();
+ }
+
+ private ActivityController<TestAppLocalePickerActivity> initActivityController(
+ boolean hasPackageName) {
+ Intent data = new Intent();
+ if (hasPackageName) {
+ data.setData(TEST_PACKAGE_URI);
+ }
+ data.putExtra(AppInfoBase.ARG_PACKAGE_UID, UserHandle.getUserId(Process.myUid()));
+ ActivityController<TestAppLocalePickerActivity> activityController =
+ Robolectric.buildActivity(TestAppLocalePickerActivity.class, data);
+ Activity activity = activityController.get();
+
+ ShadowTelephonyManager shadowTelephonyManager = Shadows.shadowOf(
+ activity.getSystemService(TelephonyManager.class));
+ shadowTelephonyManager.setSimCountryIso("US");
+ shadowTelephonyManager.setNetworkCountryIso("US");
+
+ return activityController;
+ }
+
+ private static class TestAppLocalePickerActivity extends AppLocalePickerActivity {
+ @Override
+ public Context createContextAsUser(UserHandle user, int flags) {
+ // return the current context as a work profile
+ return this;
+ }
+ }
+
+ @Implements(ApplicationPackageManager.class)
+ public static class ShadowApplicationPackageManager extends
+ org.robolectric.shadows.ShadowApplicationPackageManager {
+
+ @Implementation
+ protected Object getInstallSourceInfo(String packageName) {
+ return new InstallSourceInfo("", null, null, "");
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/zen/ZenModeScheduleRuleSettingsTest.java b/tests/robotests/src/com/android/settings/notification/zen/ZenModeScheduleRuleSettingsTest.java
index 601ec09..a8a551f 100644
--- a/tests/robotests/src/com/android/settings/notification/zen/ZenModeScheduleRuleSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/zen/ZenModeScheduleRuleSettingsTest.java
@@ -18,31 +18,27 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.robolectric.RuntimeEnvironment.application;
-import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Looper;
import androidx.fragment.app.FragmentActivity;
+import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowToast;
@RunWith(RobolectricTestRunner.class)
@@ -54,42 +50,32 @@
@Mock
private Intent mIntent;
- @Mock
- private NotificationManager mNotificationManager;
-
- private TestFragment mFragment;
+ private ZenModeScheduleRuleSettings mFragment;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- ShadowApplication shadowApplication = ShadowApplication.getInstance();
- shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
- mContext = application;
+ mContext = ApplicationProvider.getApplicationContext();
- mFragment = spy(new TestFragment());
- mFragment.onAttach(application);
-
- doReturn(mActivity).when(mFragment).getActivity();
-
- Resources res = application.getResources();
-
- doReturn(res).when(mFragment).getResources();
+ Resources res = mContext.getResources();
when(mActivity.getTheme()).thenReturn(res.newTheme());
when(mActivity.getIntent()).thenReturn(mIntent);
when(mActivity.getResources()).thenReturn(res);
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
+
+ mFragment = spy(new ZenModeScheduleRuleSettings());
+ when(mFragment.getActivity()).thenReturn(mActivity);
when(mFragment.getContext()).thenReturn(mContext);
+ when(mFragment.getResources()).thenReturn(res);
+ mFragment.onAttach(mContext);
}
@Test
- @Ignore
- public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() {
+ public void onAttach_noRuleId_shouldToastAndFinishAndNoCrash() {
final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text);
- mFragment.onCreate(null);
-
// verify the toast
assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(expected);
@@ -98,12 +84,4 @@
//should not crash
}
-
- public static class TestFragment extends ZenModeScheduleRuleSettings {
-
- @Override
- protected Object getSystemService(final String name) {
- return null;
- }
- }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
index 1046418..bf978c7 100644
--- a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragmentTest.java
@@ -19,11 +19,19 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.Activity;
+
+import androidx.fragment.app.FragmentActivity;
+
+import com.android.settingslib.wifi.WifiPermissionChecker;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker;
@@ -49,6 +57,10 @@
WifiPickerTracker mWifiPickerTracker;
@Mock
WifiEntry mWifiEntry;
+ @Mock
+ WifiPermissionChecker mWifiPermissionChecker;
+ @Mock
+ FragmentActivity mActivity;
WifiDppQrCodeScannerFragment mFragment;
@@ -57,8 +69,8 @@
when(mWifiEntry.getSsid()).thenReturn(WIFI_SSID);
when(mWifiPickerTracker.getWifiEntries()).thenReturn(Arrays.asList(mWifiEntry));
- mFragment = spy(new WifiDppQrCodeScannerFragment());
- mFragment.mWifiPickerTracker = mWifiPickerTracker;
+ mFragment = spy(
+ new WifiDppQrCodeScannerFragment(mWifiPickerTracker, mWifiPermissionChecker));
}
@Test
@@ -84,4 +96,52 @@
assertThat(mFragment.canConnectWifi(WIFI_SSID)).isFalse();
verify(mFragment).showErrorMessageAndRestartCamera(anyInt());
}
+
+ @Test
+ public void onSuccess_noWifiPermission_finishActivityWithoutSetResult() {
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(false);
+ when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(false);
+
+ mFragment.onSuccess();
+
+ verify(mActivity).finish();
+ verify(mActivity, never()).setResult(eq(Activity.RESULT_OK), any());
+ }
+
+ @Test
+ public void onSuccess_hasAccessWifiStatePermissionOnly_finishActivityWithoutSetResult() {
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(true);
+ when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(false);
+
+ mFragment.onSuccess();
+
+ verify(mActivity).finish();
+ verify(mActivity, never()).setResult(eq(Activity.RESULT_OK), any());
+ }
+
+ @Test
+ public void onSuccess_hasAccessFineLocationPermissionOnly_finishActivityWithoutSetResult() {
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(false);
+ when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(true);
+
+ mFragment.onSuccess();
+
+ verify(mActivity).finish();
+ verify(mActivity, never()).setResult(eq(Activity.RESULT_OK), any());
+ }
+
+ @Test
+ public void onSuccess_hasRequiredPermissions_finishActivityWithSetResult() {
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ when(mWifiPermissionChecker.canAccessWifiState()).thenReturn(true);
+ when(mWifiPermissionChecker.canAccessFineLocation()).thenReturn(true);
+
+ mFragment.onSuccess();
+
+ verify(mActivity).setResult(eq(Activity.RESULT_OK), any());
+ verify(mActivity).finish();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
index a9d5611..e292f24 100644
--- a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
@@ -22,12 +22,10 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -40,6 +38,7 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
@@ -142,6 +141,7 @@
mController.displayPreference(mScreen);
verify(mWifiDirectPreference).setEnabled(false);
+ verify(mWifiDirectPreference).setSummary(R.string.not_allowed_by_ent);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
index 7ce2bf3..e8ee7c3 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -19,30 +19,29 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.TetheringManager;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiManager;
-import android.os.Bundle;
-import android.os.UserManager;
-import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@@ -56,53 +55,44 @@
private static final String SSID = "Pixel";
- private Context mContext;
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ private Lifecycle mLifecycle;
@Mock
private TetheringManager mTetheringManager;
@Mock
private WifiManager mWifiManager;
@Mock
- private UserManager mUserManager;
- @Mock
- private Bundle mBundle;
- @Mock
private PreferenceScreen mScreen;
private SoftApConfiguration mSoftApConfiguration;
private WifiTetherPreferenceController mController;
- private Lifecycle mLifecycle;
- private LifecycleOwner mLifecycleOwner;
private PrimarySwitchPreference mPreference;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = spy(RuntimeEnvironment.application);
- mLifecycleOwner = () -> mLifecycle;
- mLifecycle = new Lifecycle(mLifecycleOwner);
FakeFeatureFactory.setupForTest();
- mPreference = new PrimarySwitchPreference(RuntimeEnvironment.application);
+ mPreference = new PrimarySwitchPreference(mContext);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
- when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
- when(mUserManager.getUserRestrictions()).thenReturn(mBundle);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
- mController = new WifiTetherPreferenceController(mContext, mLifecycle,
- false /* initSoftApManager */);
- mController.mIsWifiTetheringAllow = true;
+ mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
+ mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
mController.displayPreference(mScreen);
}
@Test
public void isAvailable_noTetherRegex_shouldReturnFalse() {
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
- mController = new WifiTetherPreferenceController(mContext, mLifecycle,
- false /* initSoftApManager */);
+ mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
+ mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
assertThat(mController.isAvailable()).isFalse();
}
@@ -114,16 +104,19 @@
@Test
public void displayPreference_wifiTetheringNotAllowed_shouldDisable() {
- mController.mIsWifiTetheringAllow = false;
+ mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
+ mTetheringManager, false /* initSoftApManager */, false /* isWifiTetheringAllow */);
mController.displayPreference(mScreen);
assertThat(mPreference.isEnabled()).isFalse();
+ assertThat(mPreference.getSummary()).isEqualTo("Not allowed by your organization");
}
@Test
public void displayPreference_wifiTetheringAllowed_shouldEnable() {
- mController.mIsWifiTetheringAllow = true;
+ mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
+ mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
mController.displayPreference(mScreen);
diff --git a/tests/unit/src/com/android/settings/nearby/FastPairPreferenceControllerTest.java b/tests/unit/src/com/android/settings/nearby/FastPairPreferenceControllerTest.java
deleted file mode 100644
index f06be4b..0000000
--- a/tests/unit/src/com/android/settings/nearby/FastPairPreferenceControllerTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2022 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.nearby;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.spy;
-
-import android.content.Context;
-import android.os.Looper;
-
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class FastPairPreferenceControllerTest {
-
- private Context mContext;
- private FastPairPreferenceController mController;
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
- mController = new FastPairPreferenceController(mContext);
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
- }
-
- @Test
- public void isAvailable_shouldBeTrue() {
- assertThat(mController.isAvailable()).isTrue();
- }
-}
diff --git a/tests/unit/src/com/android/settings/nearby/FastPairSettingsFragmentTest.java b/tests/unit/src/com/android/settings/nearby/FastPairSettingsFragmentTest.java
deleted file mode 100644
index faabe8f..0000000
--- a/tests/unit/src/com/android/settings/nearby/FastPairSettingsFragmentTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2022 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.nearby;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.app.Instrumentation;
-import android.app.settings.SettingsEnums;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.platform.app.InstrumentationRegistry;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class FastPairSettingsFragmentTest {
-
- private FastPairSettingsFragment mFragment;
-
- @Before
- public void setUp() {
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
- instrumentation.runOnMainSync(() -> mFragment = new FastPairSettingsFragment());
- }
-
- @Test
- public void getCategoryKey_isNetwork() {
- assertThat(mFragment.getMetricsCategory())
- .isEqualTo(SettingsEnums.CONNECTION_DEVICE_ADVANCED_FAST_PAIR);
- }
-}
diff --git a/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackConverterTest.java b/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackConverterTest.java
index 149fd8293..2237746 100644
--- a/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackConverterTest.java
+++ b/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackConverterTest.java
@@ -43,6 +43,9 @@
public void setUp() {
mTestData = new Object();
mConsumer = new TestConsumer();
+ }
+
+ private void initEnvPerTestCase() {
mConverter = new LifecycleCallbackConverter<Object>(getLifecycle(), mConsumer);
}
@@ -52,6 +55,7 @@
@Test
public void converter_dropResult_whenInActive() {
+ initEnvPerTestCase();
mConverter.postResult(mTestData);
assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
@@ -59,6 +63,7 @@
@Test
public void converter_callbackResult_whenActive() {
+ initEnvPerTestCase();
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
@@ -69,6 +74,7 @@
@Test
public void converter_dropResult_whenBackToInActive() {
+ initEnvPerTestCase();
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
@@ -79,6 +85,7 @@
@Test
public void converter_passResultToUiThread_whenActive() {
+ initEnvPerTestCase();
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
diff --git a/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackIntentReceiverTest.java b/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackIntentReceiverTest.java
deleted file mode 100644
index c85937d..0000000
--- a/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackIntentReceiverTest.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.network.helper;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Handler;
-import android.os.HandlerThread;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.LifecycleOwner;
-import androidx.lifecycle.LifecycleRegistry;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.util.function.Consumer;
-
-@RunWith(AndroidJUnit4.class)
-public class LifecycleCallbackIntentReceiverTest implements LifecycleOwner {
-
- private final LifecycleRegistry mRegistry = LifecycleRegistry.createUnsafe(this);
-
- private static final String TEST_SCHEDULER_HANDLER = "testScheduler";
- private static final String TEST_INTENT_ACTION = "testAction";
- private static final String TEST_INTENT_PERMISSION = "testPermission";
-
- private Context mContext;
- private Intent mIntent;
- private IntentFilter mIntentFilter;
- private Handler mHandler;
- private TestConsumer mConsumer;
-
- private TestObj mTarget;
-
- @Before
- public void setUp() {
- mContext = ApplicationProvider.getApplicationContext();
-
- mIntentFilter = new IntentFilter(TEST_INTENT_ACTION);
- mIntent = new Intent(TEST_INTENT_ACTION);
-
- HandlerThread thread = new HandlerThread(TEST_SCHEDULER_HANDLER);
- thread.start();
-
- mHandler = new Handler(thread.getLooper());
- mConsumer = new TestConsumer();
-
- mTarget = new TestObj(getLifecycle(), mContext,
- mIntentFilter, TEST_INTENT_PERMISSION,
- mHandler, mConsumer);
- }
-
- public Lifecycle getLifecycle() {
- return mRegistry;
- }
-
- @Test
- public void receiver_register_whenActive() {
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
-
- assertThat(mTarget.getCallbackActiveCount(true)
- + mTarget.getCallbackActiveCount(false)).isEqualTo(0);
-
- mTarget.mReceiver.onReceive(mContext, mIntent);
-
- assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
-
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
-
- assertThat(mTarget.getCallbackActiveCount(true)).isEqualTo(1);
- assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
-
- mTarget.mReceiver.onReceive(mContext, mIntent);
-
- assertThat(mConsumer.getCallbackCount()).isEqualTo(1);
- assertThat(mConsumer.getData()).isEqualTo(mIntent);
- }
-
- @Test
- public void receiver_unregister_whenInActive() {
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
-
- assertThat(mTarget.getCallbackActiveCount(false)).isEqualTo(1);
-
- mTarget.mReceiver.onReceive(mContext, mIntent);
-
- assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
- }
-
- @Test
- public void receiver_register_whenReActive() {
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
-
- assertThat(mTarget.getCallbackActiveCount(true)).isEqualTo(2);
-
- mTarget.mReceiver.onReceive(mContext, mIntent);
-
- assertThat(mConsumer.getCallbackCount()).isEqualTo(1);
- assertThat(mConsumer.getData()).isEqualTo(mIntent);
- }
-
- @Test
- public void receiver_close_whenDestroy() {
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
- mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
-
- assertThat(mTarget.getCallbackActiveCount(false)).isEqualTo(1);
-
- mTarget.mReceiver.onReceive(mContext, mIntent);
-
- assertThat(mConsumer.getCallbackCount()).isEqualTo(0);
- }
-
- public static class TestConsumer implements Consumer<Intent> {
- long mNumberOfCallback;
- Intent mLatestData;
-
- public TestConsumer() {}
-
- public void accept(Intent data) {
- mLatestData = data;
- mNumberOfCallback ++;
- }
-
- protected long getCallbackCount() {
- return mNumberOfCallback;
- }
-
- protected Intent getData() {
- return mLatestData;
- }
- }
-
- public static class TestObj extends LifecycleCallbackIntentReceiver {
- long mCallbackActiveCount;
- long mCallbackInActiveCount;
-
- public TestObj(Lifecycle lifecycle, Context context, IntentFilter filter,
- String broadcastPermission, Handler scheduler, Consumer<Intent> resultCallback) {
- super(lifecycle, context, filter, broadcastPermission, scheduler, resultCallback);
- }
-
- @Override
- public void setCallbackActive(boolean isActive) {
- if (isActive) {
- mCallbackActiveCount ++;
- } else {
- mCallbackInActiveCount ++;
- }
- super.setCallbackActive(isActive);
- }
-
- protected long getCallbackActiveCount(boolean forActive) {
- return forActive ? mCallbackActiveCount : mCallbackInActiveCount;
- }
- }
-}