Merge "Tweak app notification page title and expand button cutoff"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8c1ab56..fe3b792 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1006,7 +1006,7 @@
<meta-data android:name="com.android.settings.title"
android:resource="@string/about_settings" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.DeviceInfoSettings" />
+ android:value="com.android.settings.deviceinfo.DeviceInfoSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
@@ -1782,45 +1782,6 @@
<activity android:name=".EncryptionInterstitial"
android:theme="@style/GlifTheme.Light" />
- <activity android:name=".Settings$StatusActivity"
- android:label="@string/device_status_activity_title"
- android:taskAffinity="com.android.settings"
- android:parentActivityName="Settings$DeviceInfoSettingsActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.VOICE_LAUNCH" />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.deviceinfo.Status" />
- </activity>
-
- <!-- Runs in the phone process since it needs access to the Phone object -->
- <activity android:name=".Settings$SimStatusActivity"
- android:label="@string/sim_status_title"
- android:process="com.android.phone">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.VOICE_LAUNCH" />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.deviceinfo.SimStatus" />
- </activity>
-
- <!-- Runs in the phone process since it needs access to the Phone object -->
- <activity android:name=".Settings$ImeiInformationActivity"
- android:label="@string/imei_information_title"
- android:process="com.android.phone">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.VOICE_LAUNCH" />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.deviceinfo.ImeiInformation" />
- </activity>
-
<activity android:name=".Settings$StorageDashboardActivity"
android:label="@string/storage_settings"
android:icon="@drawable/ic_settings_storage"
@@ -3220,6 +3181,26 @@
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
+ <service
+ android:name=".development.qstile.DevelopmentTiles$WindowTrace"
+ android:label="@string/window_trace_quick_settings_title"
+ android:icon="@drawable/tile_icon_window_trace"
+ android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
+ android:enabled="false">
+ <intent-filter>
+ <action android:name="android.service.quicksettings.action.QS_TILE" />
+ </intent-filter>
+ </service>
+ <service
+ android:name=".development.qstile.DevelopmentTiles$LayerTrace"
+ android:label="@string/layer_trace_quick_settings_title"
+ android:icon="@drawable/tile_icon_layer_trace"
+ android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
+ android:enabled="false">
+ <intent-filter>
+ <action android:name="android.service.quicksettings.action.QS_TILE" />
+ </intent-filter>
+ </service>
<activity android:name=".HelpTrampoline"
android:exported="true"
diff --git a/res/drawable/tile_icon_layer_trace.xml b/res/drawable/tile_icon_layer_trace.xml
new file mode 100644
index 0000000..21dafd3
--- /dev/null
+++ b/res/drawable/tile_icon_layer_trace.xml
@@ -0,0 +1,29 @@
+<!--
+ Copyright (C) 2018 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.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="M11.709,11.712 L7.061,8.098 6.039,8.893l5.676,4.415 5.676,-4.415 -1.028,-0.801zM11.716,10.11 L16.357,6.496 17.392,5.695 11.716,1.281 6.039,5.695 7.067,6.496Z"
+ android:fillColor="#FFFFFFFF"/>
+ <path
+ android:pathData="m20.27,15.235c0,0.82 -0.671,1.491 -1.491,1.491 -0.134,0 -0.261,-0.015 -0.38,-0.052l-2.654,2.646C15.782,19.439 15.797,19.573 15.797,19.708c0,0.82 -0.671,1.491 -1.491,1.491 -0.82,0 -1.491,-0.671 -1.491,-1.491 0,-0.134 0.015,-0.268 0.052,-0.388L10.966,17.419C10.847,17.456 10.713,17.471 10.579,17.471 10.444,17.471 10.31,17.456 10.191,17.419L6.799,20.818C6.836,20.938 6.851,21.064 6.851,21.199 6.851,22.019 6.18,22.689 5.36,22.689 4.54,22.689 3.869,22.019 3.869,21.199c0,-0.82 0.671,-1.491 1.491,-1.491 0.134,0 0.261,0.015 0.38,0.052L9.14,16.368C9.103,16.249 9.088,16.114 9.088,15.98 9.088,15.16 9.759,14.489 10.579,14.489c0.82,0 1.491,0.671 1.491,1.491 0,0.134 -0.015,0.268 -0.052,0.388l1.901,1.901C14.038,18.232 14.172,18.217 14.306,18.217c0.134,0 0.268,0.015 0.388,0.052L17.34,15.615C17.303,15.496 17.288,15.369 17.288,15.235c0,-0.82 0.671,-1.491 1.491,-1.491 0.82,0 1.491,0.671 1.491,1.491z"
+ android:fillColor="#FFFFFFFF"/>
+</vector>
+
diff --git a/res/drawable/tile_icon_window_trace.xml b/res/drawable/tile_icon_window_trace.xml
new file mode 100644
index 0000000..2563049
--- /dev/null
+++ b/res/drawable/tile_icon_window_trace.xml
@@ -0,0 +1,29 @@
+<!--
+ Copyright (C) 2018 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.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="M17.115,1.535L9.984,1.535C9.38,1.535 8.887,2.029 8.887,2.632L8.887,5.923L7.241,5.923C6.638,5.923 6.144,6.417 6.144,7.021l0,5.486c0,0.603 0.494,1.097 1.097,1.097l7.131,0c0.603,0 1.097,-0.494 1.097,-1.097l0,-3.291l1.646,0c0.603,0 1.097,-0.494 1.097,-1.097L18.212,2.632C18.212,2.029 17.718,1.535 17.115,1.535ZM14.372,12.506L7.241,12.506l0,-4.388l7.131,0zM17.115,8.118L15.469,8.118L15.469,7.021C15.469,6.417 14.976,5.923 14.372,5.923L9.984,5.923L9.984,3.729l7.131,0z"
+ android:fillColor="#FFFFFFFF"/>
+ <path
+ android:pathData="m20.27,15.235c0,0.82 -0.671,1.491 -1.491,1.491 -0.134,0 -0.261,-0.015 -0.38,-0.052l-2.654,2.646C15.782,19.439 15.797,19.573 15.797,19.708c0,0.82 -0.671,1.491 -1.491,1.491 -0.82,0 -1.491,-0.671 -1.491,-1.491 0,-0.134 0.015,-0.268 0.052,-0.388L10.966,17.419C10.847,17.456 10.713,17.471 10.579,17.471 10.444,17.471 10.31,17.456 10.191,17.419L6.799,20.818C6.836,20.938 6.851,21.064 6.851,21.199 6.851,22.019 6.18,22.689 5.36,22.689 4.54,22.689 3.869,22.019 3.869,21.199c0,-0.82 0.671,-1.491 1.491,-1.491 0.134,0 0.261,0.015 0.38,0.052L9.14,16.368C9.103,16.249 9.088,16.114 9.088,15.98 9.088,15.16 9.759,14.489 10.579,14.489c0.82,0 1.491,0.671 1.491,1.491 0,0.134 -0.015,0.268 -0.052,0.388l1.901,1.901C14.038,18.232 14.172,18.217 14.306,18.217c0.134,0 0.268,0.015 0.388,0.052L17.34,15.615C17.303,15.496 17.288,15.369 17.288,15.235c0,-0.82 0.671,-1.491 1.491,-1.491 0.82,0 1.491,0.671 1.491,1.491z"
+ android:fillColor="#FFFFFFFF"/>
+</vector>
+
diff --git a/res/layout/dialog_firmware_version.xml b/res/layout/dialog_firmware_version.xml
index e49255f..874d7af 100644
--- a/res/layout/dialog_firmware_version.xml
+++ b/res/layout/dialog_firmware_version.xml
@@ -47,7 +47,9 @@
style="@style/device_info_dialog_value"
android:id="@+id/security_patch_level_value"
android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
+ android:layout_height="wrap_content"
+ android:background="?android:attr/selectableItemBackground"
+ android:textColor="?android:attr/colorAccent"/>
<TextView
style="@style/device_info_dialog_label"
diff --git a/res/layout/time_zone_list.xml b/res/layout/time_zone_list.xml
new file mode 100644
index 0000000..a3c47cd
--- /dev/null
+++ b/res/layout/time_zone_list.xml
@@ -0,0 +1,44 @@
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:id="@+id/tz_region_spinner_layout"
+ android:layout_width="match_parent"
+ android:layout_height="?android:attr/actionBarSize"
+ android:background="?android:attr/colorAccent"
+ android:gravity="center_vertical"
+ android:paddingEnd="@dimen/switchbar_subsettings_margin_end"
+ android:orientation="horizontal">
+
+ <Spinner
+ android:id="@+id/tz_region_spinner"
+ android:layout_height="wrap_content"
+ android:layout_width="0dp"
+ android:paddingStart="64dp"
+ android:layout_weight="1"
+ android:background="@drawable/app_filter_spinner_background"/>
+ </LinearLayout>
+
+ <android.support.v7.widget.RecyclerView
+ android:id="@+id/tz_list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+</LinearLayout>
diff --git a/res/layout/time_zone_list_item.xml b/res/layout/time_zone_list_item.xml
new file mode 100644
index 0000000..471c9d8
--- /dev/null
+++ b/res/layout/time_zone_list_item.xml
@@ -0,0 +1,62 @@
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="?android:attr/selectableItemBackground"
+ android:gravity="center_vertical"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:orientation="vertical"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+
+ <TextView
+ android:id="@+id/tz_item_name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="TimeZone name"
+ android:textAppearance="?android:attr/textAppearanceListItem" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:id="@+id/tz_item_details"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+ android:textColor="?android:attr/textColorSecondary" />
+
+ <TextView
+ android:id="@+id/tz_item_time"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAlignment="viewEnd"
+ android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+ android:textColor="?android:attr/textColorSecondary" />
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/tz_item_dst"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+ android:textColor="?android:attr/textColorSecondary" />
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/wifi_network_details_two_buttons_panel.xml b/res/layout/wifi_network_details_two_buttons_panel.xml
index f076eeaf..57f76b5 100644
--- a/res/layout/wifi_network_details_two_buttons_panel.xml
+++ b/res/layout/wifi_network_details_two_buttons_panel.xml
@@ -37,7 +37,7 @@
<Button
style="@android:style/Widget.Material.Button.Colored"
android:id="@+id/signin_button"
- android:text="@string/support_sign_in_button_text"
+ android:text="@string/wifi_sign_in_button_text"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
diff --git a/res/values/bools.xml b/res/values/bools.xml
index c490365..e733d5f 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -57,9 +57,33 @@
<!-- Whether location mode is available or not. -->
<bool name="config_location_mode_available">true</bool>
+ <!-- Whether location scanning is available or not. -->
+ <bool name="config_show_location_scanning">true</bool>
+
<!-- Whether high_power_apps should be shown or not. -->
<bool name="config_show_high_power_apps">true</bool>
+ <!-- Whether media_volume should be shown or not. -->
+ <bool name="config_show_media_volume">true</bool>
+
+ <!-- Whether alarm_volume should be shown or not. -->
+ <bool name="config_show_alarm_volume">true</bool>
+
+ <!-- Whether notification_volume should be shown or not. -->
+ <bool name="config_show_notification_volume">true</bool>
+
+ <!-- Whether notification_ringtone should be shown or not. -->
+ <bool name="config_show_notification_ringtone">true</bool>
+
+ <!-- Whether screen_locking_sounds should be shown or not. -->
+ <bool name="config_show_screen_locking_sounds">true</bool>
+
+ <!-- Whether charging_sounds should be shown or not. -->
+ <bool name="config_show_charging_sounds">true</bool>
+
+ <!-- Whether touch_sounds should be shown or not. -->
+ <bool name="config_show_touch_sounds">true</bool>
+
<!-- Whether device_administrators should be shown or not. -->
<bool name="config_show_device_administrators">true</bool>
@@ -99,6 +123,12 @@
<!-- Whether default_home should be shown or not. -->
<bool name="config_show_default_home">true</bool>
+ <!-- Whether color correction preference should be shown or not. -->
+ <bool name="config_show_color_correction_preference">true</bool>
+
+ <!-- Whether color inversion preference should be shown or not. -->
+ <bool name="config_show_color_inversion_preference">true</bool>
+
<!-- Whether accessibility shortcut preference should be shown or not. -->
<bool name="config_show_accessibility_shortcut_preference">true</bool>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 31a059a..46411e6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -752,6 +752,17 @@
<string name="zone_list_menu_sort_alphabetically">Sort alphabetically</string>
<!-- Menu item on Select time zone screen -->
<string name="zone_list_menu_sort_by_timezone">Sort by time zone</string>
+ <!-- Label describing when a given time zone changes to DST or standard time -->
+ <string name="zone_change_to_from_dst"><xliff:g id="time_type" example="Pacific Summer Time">%1$s</xliff:g> starts on <xliff:g id="transition_date" example="Mar 11 2018">%2$s</xliff:g>.</string>
+ <!-- Describes the time type "daylight savings time" (used in zone_change_to_from_dst, when no zone specific name is available) -->
+ <string name="zone_time_type_dst">Daylight savings time</string>
+ <!-- Describes the time type "standard time" (used in zone_change_to_from_dst, when no zone specific name is available) -->
+ <string name="zone_time_type_standard">Standard time</string>
+ <!-- The menu item to switch to selecting a time zone by region (default) -->
+ <string name="zone_menu_by_region">Time zone by region</string>
+ <!-- The menu item to switch to selecting a time zone with a fixed offset (such as UTC or GMT+0200) -->
+ <string name="zone_menu_by_offset">Fixed offset time zones</string>
+
<!-- Title string shown above DatePicker, letting a user select system date
[CHAR LIMIT=20] -->
<string name="date_picker_title">Date</string>
@@ -1685,6 +1696,8 @@
<string name="wifi_band_24ghz">2.4 GHz</string>
<!-- Wifi Internal 5GHz as an universal itendifier for 5GHz band -->
<string name="wifi_band_5ghz">5 GHz</string>
+ <!-- Wifi Sign in text for button [CHAR LIMIT = 40]-->
+ <string name="wifi_sign_in_button_text">Sign in</string>
<!-- Link speed on Wifi Status screen -->
<string name="link_speed">%1$d Mbps</string>
@@ -3438,6 +3451,8 @@
<!-- Main settings screen, setting title for the user to go into the About phone screen -->
<string name="about_settings" product="default">About phone</string>
<!-- Main settings screen, setting title for the user to go into the About phone screen -->
+ <string name="about_settings" product="device">About device</string>
+ <!-- Main settings screen, setting title for the user to go into the About phone screen -->
<string name="about_settings" product="emulator">About emulated device</string>
<!-- Main settings screen, setting summary for the user to go into the About phone screen-->
<string name="about_settings_summary">View legal info, status, software version</string>
@@ -3712,6 +3727,15 @@
result from their use.
</string>
+ <!-- Warning that appears below the unknown sources switch in settings -->
+ <string name="install_all_warning" product="device">
+ Your device and personal data are more vulnerable
+ to attack by unknown apps. By installing apps from
+ this source, you agree that you are responsible for
+ any damage to your device or loss of data that may
+ result from their use.
+ </string>
+
<!-- Applications settings screen, setting check box title. If checked, applications show more settings options. -->
<string name="advanced_settings">Advanced settings</string>
<!-- Applications settings screen, setting check box summary. This is the summary for "Advanced settings" checkbox -->
@@ -4785,6 +4809,10 @@
<string name="battery_tip_low_battery_title">Low battery capacity</string>
<!-- Summary for the low battery tip [CHAR LIMIT=NONE] -->
<string name="battery_tip_low_battery_summary">Battery can\'t provide good battery life</string>
+ <!-- Title for the smart battery tip [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_smart_battery_title">Turn on smart battery manager</string>
+ <!-- Summary for the smart battery tip [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_smart_battery_summary">Turn on to optimize battery usage</string>
<!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
<string name="battery_tip_high_usage_title" product="default">Phone used heavily</string>
<!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
@@ -5615,6 +5643,8 @@
<string name="really_remove_account_message" product="tablet">Removing this account will delete all of its messages, contacts, and other data from the tablet!</string>
<!-- Remove account message in dialog [CHAR LIMIT=NONE] -->
<string name="really_remove_account_message" product="default">Removing this account will delete all of its messages, contacts, and other data from the phone!</string>
+ <!-- Remove account message in dialog [CHAR LIMIT=NONE] -->
+ <string name="really_remove_account_message" product="device">Removing this account will delete all of its messages, contacts, and other data from the device!</string>
<!-- This is shown if the autheticator for a given account fails to remove it. [CHAR LIMIT=NONE] -->
<string name="remove_account_failed">This change isn\'t allowed by your admin</string>
<!-- What to show in messaging that refers to this provider, e.g. AccountSyncSettings -->
@@ -8698,6 +8728,12 @@
<!-- [CHAR LIMIT=60] Name of dev option to enable extra quick settings tiles -->
<string name="quick_settings_developer_tiles">Quick settings developer tiles</string>
+ <!-- [CHAR LIMIT=25] Title of developer tile to toggle window trace -->
+ <string name="window_trace_quick_settings_title">Window Trace</string>
+
+ <!-- [CHAR LIMIT=25] Title of developer tile to toggle layer trace -->
+ <string name="layer_trace_quick_settings_title">Layer Trace</string>
+
<!-- [CHAR LIMIT=60] Title of work profile setting page -->
<string name="managed_profile_settings_title">Work profile settings</string>
<!-- [CHAR LIMIT=60] The preference title for enabling cross-profile remote contact search -->
diff --git a/res/xml/device_info_settings_v2.xml b/res/xml/device_info_settings.xml
similarity index 100%
rename from res/xml/device_info_settings_v2.xml
rename to res/xml/device_info_settings.xml
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 2d9fd54..4b285d3 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -22,12 +22,14 @@
settings:keywords="@string/keywords_display"
settings:initialExpandedChildrenCount="4">
- <Preference
+ <com.android.settingslib.RestrictedPreference
android:key="brightness"
android:title="@string/brightness"
- settings:keywords="@string/keywords_display_brightness_level">
- <intent android:action="com.android.intent.action.SHOW_BRIGHTNESS_DIALOG" />
- </Preference>
+ settings:keywords="@string/keywords_display_brightness_level"
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness">
+ <intent android:action="com.android.intent.action.SHOW_BRIGHTNESS_DIALOG" />
+ </com.android.settingslib.RestrictedPreference>
<com.android.settings.display.NightDisplayPreference
android:key="night_display"
@@ -38,12 +40,13 @@
settings:keywords="@string/keywords_display_night_display" />
<!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="auto_brightness"
android:title="@string/auto_brightness_title"
settings:keywords="@string/keywords_display_auto_brightness"
android:summary="@string/auto_brightness_summary"
- settings:controller="com.android.settings.display.AutoBrightnessPreferenceController" />
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness" />
<com.android.settingslib.RestrictedPreference
android:key="wallpaper"
diff --git a/res/xml/power_usage_summary_legacy.xml b/res/xml/power_usage_summary_legacy.xml
index 80179c0..5af6bc1 100644
--- a/res/xml/power_usage_summary_legacy.xml
+++ b/res/xml/power_usage_summary_legacy.xml
@@ -61,11 +61,13 @@
android:summary="@string/battery_percentage_description"/>
<!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="auto_brightness_battery"
android:title="@string/auto_brightness_title"
android:summary="@string/auto_brightness_summary"
- settings:keywords="@string/keywords_display_auto_brightness"/>
+ settings:keywords="@string/keywords_display_auto_brightness"
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness" />
<!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
<com.android.settings.TimeoutListPreference
diff --git a/res/xml/smart_battery_detail.xml b/res/xml/smart_battery_detail.xml
index 8cfd797..a236cb8 100644
--- a/res/xml/smart_battery_detail.xml
+++ b/res/xml/smart_battery_detail.xml
@@ -16,6 +16,7 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:key="smart_battery_detail"
android:title="@string/smart_battery_manager_title">
<!-- TODO(b/71722498): Add header back, otherwise also remove smart_battery_header
diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml
index 57bc4fd..8d2c28c 100644
--- a/res/xml/zen_mode_behavior_settings.xml
+++ b/res/xml/zen_mode_behavior_settings.xml
@@ -47,16 +47,19 @@
android:key="zen_mode_events"
android:title="@string/zen_mode_events"/>
- <Preference
+ <!-- Messages -->
+ <ListPreference
android:key="zen_mode_messages"
android:title="@string/zen_mode_messages"
- android:fragment="com.android.settings.notification.ZenModeMessagesSettings" />
+ android:entries="@array/zen_mode_contacts_entries"
+ android:entryValues="@array/zen_mode_contacts_values"/>
<!-- Calls -->
- <Preference
+ <ListPreference
android:key="zen_mode_calls"
android:title="@string/zen_mode_calls"
- android:fragment="com.android.settings.notification.ZenModeCallsSettings" />
+ android:entries="@array/zen_mode_contacts_entries"
+ android:entryValues="@array/zen_mode_contacts_values"/>
<!-- Repeat callers -->
<SwitchPreference
diff --git a/res/xml/zen_mode_calls_settings.xml b/res/xml/zen_mode_calls_settings.xml
deleted file mode 100644
index aa84216..0000000
--- a/res/xml/zen_mode_calls_settings.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2017 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:key="zen_mode_calls_settings"
- android:title="@string/zen_mode_calls" />
diff --git a/res/xml/zen_mode_messages_settings.xml b/res/xml/zen_mode_messages_settings.xml
deleted file mode 100644
index 4b4a1e2..0000000
--- a/res/xml/zen_mode_messages_settings.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2017 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:key="zen_mode_messages_settings"
- android:title="@string/zen_mode_messages" />
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index cc72280..df8d4c8 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -90,8 +90,6 @@
// Preferences
private static final String TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE =
"toggle_high_text_contrast_preference";
- private static final String TOGGLE_INVERSION_PREFERENCE =
- "toggle_inversion_preference";
private static final String TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE =
"toggle_power_button_ends_call_preference";
private static final String TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE =
@@ -113,9 +111,11 @@
"tts_settings_preference";
private static final String AUTOCLICK_PREFERENCE_SCREEN =
"autoclick_preference_screen";
- private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
- "daltonizer_preference_screen";
+ @VisibleForTesting static final String TOGGLE_INVERSION_PREFERENCE =
+ "toggle_inversion_preference";
+ @VisibleForTesting static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
+ "daltonizer_preference_screen";
@VisibleForTesting static final String ACCESSIBILITY_SHORTCUT_PREFERENCE =
"accessibility_shortcut_preference";
@@ -619,6 +619,8 @@
displayCategory.addPreference(mToggleInversionPreference);
displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
}
+ checkColorCorrectionVisibility(mDisplayDaltonizerPreferenceScreen);
+ checkColorInversionVisibility(mToggleInversionPreference);
// Text contrast.
mToggleHighTextContrastPreference.setChecked(
@@ -769,6 +771,20 @@
}
}
+ @VisibleForTesting void checkColorCorrectionVisibility(Preference preference) {
+ if (!getContext().getResources().getBoolean(
+ R.bool.config_show_color_correction_preference)) {
+ removePreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
+ }
+ }
+
+ @VisibleForTesting void checkColorInversionVisibility(Preference preference) {
+ if (!getContext().getResources().getBoolean(
+ R.bool.config_show_color_inversion_preference)) {
+ removePreference(TOGGLE_INVERSION_PREFERENCE);
+ }
+ }
+
@VisibleForTesting void checkAccessibilityShortcutVisibility(Preference preference) {
if (!getContext().getResources().getBoolean(
R.bool.config_show_accessibility_shortcut_preference)) {
diff --git a/src/com/android/settings/accounts/ManagedProfileSettings.java b/src/com/android/settings/accounts/ManagedProfileSettings.java
index 50b9ecc..3ea7cf7 100644
--- a/src/com/android/settings/accounts/ManagedProfileSettings.java
+++ b/src/com/android/settings/accounts/ManagedProfileSettings.java
@@ -129,7 +129,7 @@
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mWorkModePreference) {
boolean quietModeEnabled = !(boolean) newValue;
- mUserManager.trySetQuietModeEnabled(quietModeEnabled, mManagedUser);
+ mUserManager.requestQuietModeEnabled(quietModeEnabled, mManagedUser);
return true;
}
if (preference == mContactPrefrence) {
diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java
index e88fb11..7d9b331 100644
--- a/src/com/android/settings/core/FeatureFlags.java
+++ b/src/com/android/settings/core/FeatureFlags.java
@@ -26,4 +26,5 @@
public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
public static final String BATTERY_DISPLAY_APP_LIST = "settings_battery_display_app_list";
public static final String SECURITY_SETTINGS_V2 = "settings_security_settings_v2";
+ public static final String ZONE_PICKER_V2 = "settings_zone_picker_v2";
}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 664dda8..44f576c 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -20,7 +20,6 @@
import com.android.settings.ApnSettings;
import com.android.settings.DateTimeSettings;
import com.android.settings.DeviceAdminSettings;
-import com.android.settings.DeviceInfoSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.IccLockSettings;
import com.android.settings.MasterClear;
@@ -64,6 +63,7 @@
import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
+import com.android.settings.deviceinfo.DeviceInfoSettings;
import com.android.settings.deviceinfo.PrivateVolumeForget;
import com.android.settings.deviceinfo.PrivateVolumeSettings;
import com.android.settings.deviceinfo.PublicVolumeSettings;
diff --git a/src/com/android/settings/dashboard/conditional/WorkModeCondition.java b/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
index 297e35a..b637137 100644
--- a/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
+++ b/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
@@ -91,7 +91,7 @@
public void onActionClick(int index) {
if (index == 0) {
if (mUserHandle != null) {
- mUm.trySetQuietModeEnabled(false, mUserHandle);
+ mUm.requestQuietModeEnabled(false, mUserHandle);
}
setActive(false);
} else {
diff --git a/src/com/android/settings/datetime/TimeZonePreferenceController.java b/src/com/android/settings/datetime/TimeZonePreferenceController.java
index 435b1fe..e29e245 100644
--- a/src/com/android/settings/datetime/TimeZonePreferenceController.java
+++ b/src/com/android/settings/datetime/TimeZonePreferenceController.java
@@ -20,7 +20,10 @@
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
+import android.util.FeatureFlagUtils;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.datetime.timezone.ZonePicker;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.datetime.ZoneGetter;
@@ -33,11 +36,13 @@
private static final String KEY_TIMEZONE = "timezone";
private final AutoTimeZonePreferenceController mAutoTimeZonePreferenceController;
+ private final boolean mZonePickerV2;
public TimeZonePreferenceController(Context context,
AutoTimeZonePreferenceController autoTimeZonePreferenceController) {
super(context);
mAutoTimeZonePreferenceController = autoTimeZonePreferenceController;
+ mZonePickerV2 = FeatureFlagUtils.isEnabled(mContext, FeatureFlags.ZONE_PICKER_V2);
}
@Override
@@ -45,6 +50,9 @@
if (!(preference instanceof RestrictedPreference)) {
return;
}
+ if (mZonePickerV2) {
+ preference.setFragment(ZonePicker.class.getName());
+ }
preference.setSummary(getTimeZoneOffsetAndName());
if( !((RestrictedPreference) preference).isDisabledByAdmin()) {
preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled());
diff --git a/src/com/android/settings/datetime/timezone/DataLoader.java b/src/com/android/settings/datetime/timezone/DataLoader.java
new file mode 100644
index 0000000..038558a
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/DataLoader.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import android.graphics.Paint;
+import android.icu.text.Collator;
+import android.icu.text.LocaleDisplayNames;
+import android.icu.text.TimeZoneFormat;
+import android.icu.text.TimeZoneNames;
+import android.icu.text.TimeZoneNames.NameType;
+import android.icu.util.Region;
+import android.icu.util.Region.RegionType;
+import android.icu.util.TimeZone;
+import android.icu.util.TimeZone.SystemTimeZoneType;
+import com.android.settingslib.datetime.ZoneGetter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Provides data for manual selection of time zones based associated to regions. This class makes no
+ * attempt to avoid IO and processing intensive actions. This means it should not be called from the
+ * UI thread.
+ */
+public class DataLoader {
+
+ private static final int MIN_HOURS_OFFSET = -14;
+ private static final int MAX_HOURS_OFFSET = +12;
+
+ private final Locale mLocale;
+
+ private final Collator mCollator;
+ private final LocaleDisplayNames mLocaleDisplayNames;
+ private final TimeZoneFormat mTimeZoneFormat;
+ private final Paint mPaint;
+ private final AtomicLong nextItemId = new AtomicLong(1);
+ private final long mNow = System.currentTimeMillis();
+
+ public DataLoader(Locale locale) {
+ mLocale = locale;
+ mCollator = Collator.getInstance(locale);
+ mLocaleDisplayNames = LocaleDisplayNames.getInstance(locale);
+ mTimeZoneFormat = TimeZoneFormat.getInstance(locale);
+ mPaint = new Paint();
+ }
+
+ /**
+ * Returns a {@link RegionInfo} object for each region that has selectable time zones. The
+ * returned list will be sorted properly for display in the locale.
+ */
+ public List<RegionInfo> loadRegionInfos() {
+ final Set<Region> regions = Region.getAvailable(RegionType.TERRITORY);
+ final TreeSet<RegionInfo> regionInfos = new TreeSet<>(new RegionInfoComparator());
+ for (final Region region : regions) {
+ final String regionId = region.toString();
+ final Set<String> timeZoneIds = getTimeZoneIds(regionId);
+ if (timeZoneIds.isEmpty()) {
+ continue;
+ }
+
+ final String name = mLocaleDisplayNames.regionDisplayName(regionId);
+ final String regionalIndicator = createRegionalIndicator(regionId);
+
+ regionInfos.add(new RegionInfo(regionId, name, regionalIndicator, timeZoneIds));
+ }
+
+ return Collections.unmodifiableList(new ArrayList<>(regionInfos));
+ }
+
+ /**
+ * Returns a list of {@link TimeZoneInfo} objects. The returned list will be sorted properly for
+ * display in the locale.It may be smaller than the input collection, if equivalent IDs are
+ * passed in.
+ *
+ * @param timeZoneIds a list of Olson IDs.
+ */
+ public List<TimeZoneInfo> loadTimeZoneInfos(Collection<String> timeZoneIds) {
+ final TreeSet<TimeZoneInfo> timeZoneInfos = new TreeSet<>(new TimeZoneInfoComparator());
+ outer:
+ for (final String timeZoneId : timeZoneIds) {
+ final TimeZone timeZone = TimeZone.getFrozenTimeZone(timeZoneId);
+ for (final TimeZoneInfo other : timeZoneInfos) {
+ if (other.getTimeZone().hasSameRules(timeZone)) {
+ continue outer;
+ }
+ }
+ timeZoneInfos.add(createTimeZoneInfo(timeZone));
+ }
+ return Collections.unmodifiableList(new ArrayList<>(timeZoneInfos));
+ }
+
+ /**
+ * Returns a {@link TimeZoneInfo} for each fixed offset time zone, such as UTC or GMT+4. The
+ * returned list will be sorted in a reasonable way for display.
+ */
+ public List<TimeZoneInfo> loadFixedOffsets() {
+ final List<TimeZoneInfo> timeZoneInfos = new ArrayList<>();
+ timeZoneInfos.add(createTimeZoneInfo(TimeZone.getFrozenTimeZone("Etc/UTC")));
+ for (int hoursOffset = MAX_HOURS_OFFSET; hoursOffset >= MIN_HOURS_OFFSET; --hoursOffset) {
+ if (hoursOffset == 0) {
+ // UTC is handled above, so don't add GMT +/-0 again.
+ continue;
+ }
+ final String id = String.format("Etc/GMT%+d", hoursOffset);
+ timeZoneInfos.add(createTimeZoneInfo(TimeZone.getFrozenTimeZone(id)));
+ }
+ return Collections.unmodifiableList(timeZoneInfos);
+ }
+
+ /**
+ * Gets the set of ids for relevant TimeZones in the given region.
+ */
+ private Set<String> getTimeZoneIds(String regionId) {
+ return TimeZone.getAvailableIDs(
+ SystemTimeZoneType.CANONICAL_LOCATION, regionId, /* rawOffset */ null);
+ }
+
+ private TimeZoneInfo createTimeZoneInfo(TimeZone timeZone) {
+ // Every timezone we handle must be an OlsonTimeZone.
+ final String id = timeZone.getID();
+ final TimeZoneNames timeZoneNames = mTimeZoneFormat.getTimeZoneNames();
+ final java.util.TimeZone javaTimeZone = android.icu.impl.TimeZoneAdapter.wrap(timeZone);
+ final CharSequence gmtOffset = ZoneGetter.getGmtOffsetText(mTimeZoneFormat, mLocale,
+ javaTimeZone, new Date(mNow));
+ return new TimeZoneInfo.Builder(timeZone)
+ .setGenericName(timeZoneNames.getDisplayName(id, NameType.LONG_GENERIC, mNow))
+ .setStandardName(timeZoneNames.getDisplayName(id, NameType.LONG_STANDARD, mNow))
+ .setDaylightName(timeZoneNames.getDisplayName(id, NameType.LONG_DAYLIGHT, mNow))
+ .setExemplarLocation(timeZoneNames.getExemplarLocationName(id))
+ .setGmtOffset(gmtOffset)
+ .setItemId(nextItemId.getAndIncrement())
+ .build();
+ }
+
+ /**
+ * Create a Unicode Region Indicator Symbol for a given region id (a.k.a flag emoji). If the
+ * system can't render a flag for this region or the input is not a region id, this returns
+ * {@code null}.
+ *
+ * @param id the two-character region id.
+ * @return a String representing the flag of the region or {@code null}.
+ */
+ private String createRegionalIndicator(String id) {
+ if (id.length() != 2) {
+ return null;
+ }
+ final char c1 = id.charAt(0);
+ final char c2 = id.charAt(1);
+ if ('A' > c1 || c1 > 'Z' || 'A' > c2 || c2 > 'Z') {
+ return null;
+ }
+ // Regional Indicator A is U+1F1E6 which is 0xD83C 0xDDE6 in UTF-16.
+ final String regionalIndicator = new String(
+ new char[]{0xd83c, (char) (0xdde6 - 'A' + c1), 0xd83c, (char) (0xdde6 - 'A' + c2)});
+ if (!mPaint.hasGlyph(regionalIndicator)) {
+ return null;
+ }
+ return regionalIndicator;
+ }
+
+ private class TimeZoneInfoComparator implements Comparator<TimeZoneInfo> {
+
+ @Override
+ public int compare(TimeZoneInfo tzi1, TimeZoneInfo tzi2) {
+ int result =
+ Integer
+ .compare(tzi1.getTimeZone().getRawOffset(), tzi2.getTimeZone().getRawOffset());
+ if (result == 0) {
+ result = mCollator.compare(tzi1.getExemplarLocation(), tzi2.getExemplarLocation());
+ }
+ if (result == 0 && tzi1.getGenericName() != null && tzi2.getGenericName() != null) {
+ result = mCollator.compare(tzi1.getGenericName(), tzi2.getGenericName());
+ }
+ return result;
+ }
+ }
+
+ private class RegionInfoComparator implements Comparator<RegionInfo> {
+
+ @Override
+ public int compare(RegionInfo r1, RegionInfo r2) {
+ return mCollator.compare(r1.getName(), r2.getName());
+ }
+ }
+}
diff --git a/src/com/android/settings/datetime/timezone/RegionInfo.java b/src/com/android/settings/datetime/timezone/RegionInfo.java
new file mode 100644
index 0000000..99fbaf0
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/RegionInfo.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Data object describing a geographical region.
+ *
+ * Regions are roughly equivalent to countries, but not every region is a country (for example "U.S.
+ * overseas territories" is treated as a country).
+ */
+public class RegionInfo {
+
+ private final String mId;
+ private final String mName;
+ private final String mRegionalIndicator;
+ private final Collection<String> mTimeZoneIds;
+
+ public RegionInfo(String id, String name, String regionalIndicator,
+ Collection<String> timeZoneIds) {
+ mId = id;
+ mName = name;
+ mRegionalIndicator = regionalIndicator;
+ mTimeZoneIds = Collections.unmodifiableList(new ArrayList<>(timeZoneIds));
+ }
+
+ public String getId() {
+ return mId;
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public Collection<String> getTimeZoneIds() {
+ return mTimeZoneIds;
+ }
+
+ @Override
+ public String toString() {
+ return mRegionalIndicator != null ? mRegionalIndicator + " " + mName : mName;
+ }
+}
diff --git a/src/com/android/settings/datetime/timezone/TimeZoneAdapter.java b/src/com/android/settings/datetime/timezone/TimeZoneAdapter.java
new file mode 100644
index 0000000..79075ca
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/TimeZoneAdapter.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import android.content.Context;
+import android.graphics.Typeface;
+import android.icu.impl.OlsonTimeZone;
+import android.icu.text.DateFormat;
+import android.icu.text.DisplayContext;
+import android.icu.text.SimpleDateFormat;
+import android.icu.util.Calendar;
+import android.icu.util.TimeZone;
+import android.icu.util.TimeZoneTransition;
+import android.support.annotation.NonNull;
+import android.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import com.android.settings.R;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Adapter for showing {@link TimeZoneInfo} objects in a recycler view.
+ */
+class TimeZoneAdapter extends RecyclerView.Adapter {
+
+ static final int VIEW_TYPE_NORMAL = 1;
+ static final int VIEW_TYPE_SELECTED = 2;
+
+ private final DateFormat mTimeFormat;
+ private final DateFormat mDateFormat;
+ private final View.OnClickListener mOnClickListener;
+ private final Context mContext;
+ private final String mCurrentTimeZone;
+
+ private List<TimeZoneInfo> mTimeZoneInfos;
+
+ TimeZoneAdapter(View.OnClickListener onClickListener, Context context) {
+ mOnClickListener = onClickListener;
+ mContext = context;
+ mTimeFormat = DateFormat.getTimeInstance(SimpleDateFormat.SHORT);
+ mDateFormat = DateFormat.getDateInstance(SimpleDateFormat.MEDIUM);
+ mDateFormat.setContext(DisplayContext.CAPITALIZATION_NONE);
+ mCurrentTimeZone = TimeZone.getDefault().getID();
+ setHasStableIds(true);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return getItem(position).getItemId();
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ final View view = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.time_zone_list_item, parent, false);
+ view.setOnClickListener(mOnClickListener);
+ final ViewHolder viewHolder = new ViewHolder(view);
+ if (viewType == VIEW_TYPE_SELECTED) {
+ viewHolder.mNameView.setTypeface(
+ viewHolder.mNameView.getTypeface(), Typeface.BOLD);
+ }
+ return viewHolder;
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+ final TimeZoneInfo item = getItem(position);
+ final ViewHolder tzHolder = (ViewHolder) holder;
+ tzHolder.mNameView.setText(formatName(item));
+ tzHolder.mDetailsView.setText(formatDetails(item));
+ tzHolder.mTimeView.setText(formatTime(item));
+ String dstText = formatDstText(item);
+ tzHolder.mDstView.setText(dstText);
+ // Hide DST TextView when it has no content.
+ tzHolder.mDstView.setVisibility(dstText != null ? View.VISIBLE : View.GONE);
+
+ }
+
+ @Override
+ public int getItemCount() {
+ return getTimeZones().size();
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ final TimeZoneInfo tz = getItem(position);
+ if (tz.getId().equals(mCurrentTimeZone)) {
+ return VIEW_TYPE_SELECTED;
+ } else {
+ return VIEW_TYPE_NORMAL;
+ }
+ }
+
+ public TimeZoneInfo getItem(int position) {
+ return getTimeZones().get(position);
+ }
+
+ private CharSequence formatName(TimeZoneInfo item) {
+ CharSequence name = item.getExemplarLocation();
+ if (name == null) {
+ name = item.getGenericName();
+ }
+ if (name == null && item.getTimeZone().inDaylightTime(new Date())) {
+ name = item.getDaylightName();
+ }
+ if (name == null) {
+ name = item.getStandardName();
+ }
+ if (name == null) {
+ name = item.getGmtOffset();
+ }
+ return name;
+ }
+
+ private CharSequence formatDetails(TimeZoneInfo item) {
+ String name = item.getGenericName();
+ if (name == null) {
+ if (item.getTimeZone().inDaylightTime(new Date())) {
+ name = item.getDaylightName();
+ } else {
+ name = item.getStandardName();
+ }
+ }
+ if (name == null) {
+ return item.getGmtOffset();
+ } else {
+ return TextUtils.concat(item.getGmtOffset(), " ", name);
+ }
+ }
+
+ private String formatDstText(TimeZoneInfo item) {
+ final TimeZone timeZone = item.getTimeZone();
+ if (!timeZone.observesDaylightTime()) {
+ return null;
+ }
+
+ final TimeZoneTransition nextDstTransition = findNextDstTransition(timeZone);
+ if (nextDstTransition == null) {
+ return null;
+ }
+ final boolean toDst = nextDstTransition.getTo().getDSTSavings() != 0;
+ String timeType = toDst ? item.getDaylightName() : item.getStandardName();
+ if (timeType == null) {
+ // Fall back to generic "summer time" and "standard time" if the time zone has no
+ // specific names.
+ timeType = toDst ?
+ mContext.getString(R.string.zone_time_type_dst) :
+ mContext.getString(R.string.zone_time_type_standard);
+
+ }
+ final Calendar transitionTime = Calendar.getInstance(timeZone);
+ transitionTime.setTimeInMillis(nextDstTransition.getTime());
+ final String date = mDateFormat.format(transitionTime);
+ return mContext.getString(R.string.zone_change_to_from_dst, timeType, date);
+ }
+
+ private TimeZoneTransition findNextDstTransition(TimeZone timeZone) {
+ if (!(timeZone instanceof OlsonTimeZone)) {
+ return null;
+ }
+ final OlsonTimeZone olsonTimeZone = (OlsonTimeZone) timeZone;
+ TimeZoneTransition transition = olsonTimeZone.getNextTransition(
+ System.currentTimeMillis(), /* inclusive */ false);
+ do {
+ if (transition.getTo().getDSTSavings() != transition.getFrom().getDSTSavings()) {
+ break;
+ }
+ transition = olsonTimeZone.getNextTransition(
+ transition.getTime(), /*inclusive */ false);
+ } while (transition != null);
+ return transition;
+ }
+
+ private String formatTime(TimeZoneInfo item) {
+ return mTimeFormat.format(Calendar.getInstance(item.getTimeZone()));
+ }
+
+ private List<TimeZoneInfo> getTimeZones() {
+ if (mTimeZoneInfos == null) {
+ return Collections.emptyList();
+ }
+ return mTimeZoneInfos;
+ }
+
+ void setTimeZoneInfos(List<TimeZoneInfo> timeZoneInfos) {
+ mTimeZoneInfos = timeZoneInfos;
+ notifyDataSetChanged();
+ }
+}
diff --git a/src/com/android/settings/datetime/timezone/TimeZoneInfo.java b/src/com/android/settings/datetime/timezone/TimeZoneInfo.java
new file mode 100644
index 0000000..96a2067
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/TimeZoneInfo.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import android.icu.util.TimeZone;
+import android.text.TextUtils;
+
+/**
+ * Data object containing information for displaying a time zone for the user to select.
+ */
+public class TimeZoneInfo {
+
+ private final String mId;
+ private final TimeZone mTimeZone;
+ private final String mGenericName;
+ private final String mStandardName;
+ private final String mDaylightName;
+ private final String mExemplarLocation;
+ private final CharSequence mGmtOffset;
+ // Arbitrary id that's unique within all TimeZoneInfo objects created by a given DataLoader instance.
+ private final long mItemId;
+
+ public TimeZoneInfo(Builder builder) {
+ mTimeZone = builder.mTimeZone;
+ mId = mTimeZone.getID();
+ mGenericName = builder.mGenericName;
+ mStandardName = builder.mStandardName;
+ mDaylightName = builder.mDaylightName;
+ mExemplarLocation = builder.mExemplarLocation;
+ mGmtOffset = builder.mGmtOffset;
+ mItemId = builder.mItemId;
+ }
+
+ public String getId() {
+ return mId;
+ }
+
+ public TimeZone getTimeZone() {
+ return mTimeZone;
+ }
+
+ public String getExemplarLocation() {
+ return mExemplarLocation;
+ }
+
+ public String getGenericName() {
+ return mGenericName;
+ }
+
+ public String getStandardName() {
+ return mStandardName;
+ }
+
+ public String getDaylightName() {
+ return mDaylightName;
+ }
+
+ public CharSequence getGmtOffset() {
+ return mGmtOffset;
+ }
+
+ public long getItemId() {
+ return mItemId;
+ }
+
+ public static class Builder {
+ private final TimeZone mTimeZone;
+ private String mGenericName;
+ private String mStandardName;
+ private String mDaylightName;
+ private String mExemplarLocation;
+ private CharSequence mGmtOffset;
+ private long mItemId = -1;
+
+ public Builder(TimeZone timeZone) {
+ if (timeZone == null) {
+ throw new IllegalArgumentException("TimeZone must not be null!");
+ }
+ mTimeZone = timeZone;
+ }
+
+ public Builder setGenericName(String genericName) {
+ this.mGenericName = genericName;
+ return this;
+ }
+
+ public Builder setStandardName(String standardName) {
+ this.mStandardName = standardName;
+ return this;
+ }
+
+ public Builder setDaylightName(String daylightName) {
+ mDaylightName = daylightName;
+ return this;
+ }
+
+ public Builder setExemplarLocation(String exemplarLocation) {
+ mExemplarLocation = exemplarLocation;
+ return this;
+ }
+
+ public Builder setGmtOffset(CharSequence gmtOffset) {
+ mGmtOffset = gmtOffset;
+ return this;
+ }
+
+ public Builder setItemId(long itemId) {
+ mItemId = itemId;
+ return this;
+ }
+
+ public TimeZoneInfo build() {
+ if (TextUtils.isEmpty(mGmtOffset)) {
+ throw new IllegalStateException("gmtOffset must not be empty!");
+ }
+ if (mItemId == -1) {
+ throw new IllegalStateException("ItemId not set!");
+ }
+ return new TimeZoneInfo(this);
+ }
+
+ }
+}
diff --git a/src/com/android/settings/datetime/timezone/ViewHolder.java b/src/com/android/settings/datetime/timezone/ViewHolder.java
new file mode 100644
index 0000000..3cb2c4e
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/ViewHolder.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.widget.TextView;
+import com.android.settings.R;
+
+/**
+ * View holder for a time zone list item.
+ */
+class ViewHolder extends RecyclerView.ViewHolder {
+
+ final TextView mNameView;
+ final TextView mDstView;
+ final TextView mDetailsView;
+ final TextView mTimeView;
+
+ public ViewHolder(View itemView) {
+ super(itemView);
+ mNameView = itemView.findViewById(R.id.tz_item_name);
+ mDstView = itemView.findViewById(R.id.tz_item_dst);
+ mDetailsView = itemView.findViewById(R.id.tz_item_details);
+ mTimeView = itemView.findViewById(R.id.tz_item_time);
+ }
+}
diff --git a/src/com/android/settings/datetime/timezone/ZonePicker.java b/src/com/android/settings/datetime/timezone/ZonePicker.java
new file mode 100644
index 0000000..eafbaa2
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/ZonePicker.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import android.app.Activity;
+import android.app.AlarmManager;
+import android.content.Context;
+import android.icu.util.TimeZone;
+import android.os.Bundle;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Spinner;
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.InstrumentedFragment;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * The class displaying a region list and a list of time zones for the selected region.
+ * Choosing an item from the list will set the time zone. Pressing Back without choosing from the
+ * list will not result in a change in the time zone setting.
+ */
+public class ZonePicker extends InstrumentedFragment
+ implements AdapterView.OnItemSelectedListener, View.OnClickListener {
+
+ private static final int MENU_BY_REGION = Menu.FIRST;
+ private static final int MENU_BY_OFFSET = Menu.FIRST + 1;
+
+ private Locale mLocale;
+ private List<RegionInfo> mRegions;
+ private Map<String, List<TimeZoneInfo>> mZoneInfos;
+ private List<TimeZoneInfo> mFixedOffsetTimeZones;
+ private TimeZoneAdapter mTimeZoneAdapter;
+ private String mSelectedTimeZone;
+ private boolean mSelectByRegion;
+ private DataLoader mDataLoader;
+ private RecyclerView mRecyclerView;
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.ZONE_PICKER;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ final View view = inflater.inflate(R.layout.time_zone_list, container, false);
+
+ mLocale = getContext().getResources().getConfiguration().locale;
+ mDataLoader = new DataLoader(mLocale);
+ // TOOD: move this off the UI thread.
+ mRegions = mDataLoader.loadRegionInfos();
+ mZoneInfos = new HashMap<>();
+ mSelectByRegion = true;
+ mSelectedTimeZone = TimeZone.getDefault().getID();
+
+ mTimeZoneAdapter = new TimeZoneAdapter(this, getContext());
+ mRecyclerView = view.findViewById(R.id.tz_list);
+ mRecyclerView.setAdapter(mTimeZoneAdapter);
+ mRecyclerView.setLayoutManager(
+ new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, /* reverseLayout */ false));
+
+ final ArrayAdapter<RegionInfo> regionAdapter = new ArrayAdapter<>(getContext(),
+ R.layout.filter_spinner_item, mRegions);
+ regionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ final Spinner spinner = view.findViewById(R.id.tz_region_spinner);
+ spinner.setAdapter(regionAdapter);
+ spinner.setOnItemSelectedListener(this);
+ setupForCurrentTimeZone(spinner);
+ setHasOptionsMenu(true);
+ return view;
+ }
+
+ private void setupForCurrentTimeZone(Spinner spinner) {
+ final String localeRegionId = mLocale.getCountry().toUpperCase(Locale.ROOT);
+ final String currentTimeZone = TimeZone.getDefault().getID();
+ boolean fixedOffset = currentTimeZone.startsWith("Etc/GMT") ||
+ currentTimeZone.equals("Etc/UTC");
+
+ for (int regionIndex = 0; regionIndex < mRegions.size(); regionIndex++) {
+ final RegionInfo region = mRegions.get(regionIndex);
+ if (localeRegionId.equals(region.getId())) {
+ spinner.setSelection(regionIndex);
+ }
+ if (!fixedOffset) {
+ for (String timeZoneId: region.getTimeZoneIds()) {
+ if (TextUtils.equals(timeZoneId, mSelectedTimeZone)) {
+ spinner.setSelection(regionIndex);
+ return;
+ }
+ }
+ }
+ }
+
+ if (fixedOffset) {
+ setSelectByRegion(false);
+ }
+ }
+
+ @Override
+ public void onClick(View view) {
+ // Ignore extra clicks
+ if (!isResumed()) {
+ return;
+ }
+ final int position = mRecyclerView.getChildAdapterPosition(view);
+ if (position == RecyclerView.NO_POSITION) {
+ return;
+ }
+ final TimeZoneInfo timeZoneInfo = mTimeZoneAdapter.getItem(position);
+
+ // Update the system timezone value
+ final Activity activity = getActivity();
+ final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
+ alarm.setTimeZone(timeZoneInfo.getId());
+
+ activity.onBackPressed();
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ menu.add(0, MENU_BY_REGION, 0, R.string.zone_menu_by_region);
+ menu.add(0, MENU_BY_OFFSET, 0, R.string.zone_menu_by_offset);
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ if (mSelectByRegion) {
+ menu.findItem(MENU_BY_REGION).setVisible(false);
+ menu.findItem(MENU_BY_OFFSET).setVisible(true);
+ } else {
+ menu.findItem(MENU_BY_REGION).setVisible(true);
+ menu.findItem(MENU_BY_OFFSET).setVisible(false);
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+
+ case MENU_BY_REGION:
+ setSelectByRegion(true);
+ return true;
+
+ case MENU_BY_OFFSET:
+ setSelectByRegion(false);
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ private void setSelectByRegion(boolean selectByRegion) {
+ mSelectByRegion = selectByRegion;
+ getView().findViewById(R.id.tz_region_spinner_layout).setVisibility(
+ mSelectByRegion ? View.VISIBLE : View.GONE);
+ List<TimeZoneInfo> tzInfos;
+ if (selectByRegion) {
+ Spinner regionSpinner = getView().findViewById(R.id.tz_region_spinner);
+ int selectedRegion = regionSpinner.getSelectedItemPosition();
+ if (selectedRegion == -1) {
+ // Arbitrarily pick the first item if no region was selected above.
+ selectedRegion = 0;
+ regionSpinner.setSelection(selectedRegion);
+ }
+ tzInfos = getTimeZoneInfos(mRegions.get(selectedRegion));
+ } else {
+ if (mFixedOffsetTimeZones == null) {
+ mFixedOffsetTimeZones = mDataLoader.loadFixedOffsets();
+ }
+ tzInfos = mFixedOffsetTimeZones;
+ }
+ mTimeZoneAdapter.setTimeZoneInfos(tzInfos);
+ }
+
+ private List<TimeZoneInfo> getTimeZoneInfos(RegionInfo regionInfo) {
+ List<TimeZoneInfo> tzInfos = mZoneInfos.get(regionInfo.getId());
+ if (tzInfos == null) {
+ // TODO: move this off the UI thread.
+ Collection<String> tzIds = regionInfo.getTimeZoneIds();
+ tzInfos = mDataLoader.loadTimeZoneInfos(tzIds);
+ mZoneInfos.put(regionInfo.getId(), tzInfos);
+ }
+ return tzInfos;
+ }
+
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ mTimeZoneAdapter.setTimeZoneInfos(getTimeZoneInfos(mRegions.get(position)));
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ mTimeZoneAdapter.setTimeZoneInfos(null);
+ }
+
+}
diff --git a/src/com/android/settings/development/qstile/DevelopmentTiles.java b/src/com/android/settings/development/qstile/DevelopmentTiles.java
index bc3fcb5..fea6588 100644
--- a/src/com/android/settings/development/qstile/DevelopmentTiles.java
+++ b/src/com/android/settings/development/qstile/DevelopmentTiles.java
@@ -16,20 +16,27 @@
package com.android.settings.development.qstile;
+import android.os.IBinder;
+import android.os.Parcel;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
+import android.support.annotation.VisibleForTesting;
+import android.util.Log;
import android.view.IWindowManager;
import android.view.ThreadedRenderer;
import android.view.View;
import android.view.WindowManagerGlobal;
import com.android.internal.app.LocalePicker;
+import com.android.settings.wrapper.IWindowManagerWrapper;
import com.android.settingslib.development.SystemPropPoker;
public abstract class DevelopmentTiles extends TileService {
+ private static final String TAG = "DevelopmentTiles";
protected abstract boolean isEnabled();
@@ -131,4 +138,106 @@
} catch (RemoteException e) { }
}
}
+
+ /**
+ * Tile to toggle Window Trace.
+ */
+ public static class WindowTrace extends DevelopmentTiles {
+ @VisibleForTesting
+ IWindowManagerWrapper mWindowManager;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mWindowManager = new IWindowManagerWrapper(WindowManagerGlobal
+ .getWindowManagerService());
+ }
+
+ @Override
+ protected boolean isEnabled() {
+ try {
+ return mWindowManager.isWindowTraceEnabled();
+ } catch (RemoteException e) {
+ Log.e(TAG,
+ "Could not get window trace status, defaulting to false." + e.toString());
+ }
+ return false;
+ }
+
+ @Override
+ protected void setIsEnabled(boolean isEnabled) {
+ try {
+ if (isEnabled) {
+ mWindowManager.startWindowTrace();
+ } else {
+ mWindowManager.stopWindowTrace();
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not set window trace status." + e.toString());
+ }
+ }
+ }
+
+ /**
+ * Tile to toggle Layer Trace.
+ */
+ public static class LayerTrace extends DevelopmentTiles {
+ @VisibleForTesting
+ static final int SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE = 1025;
+ @VisibleForTesting
+ static final int SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE = 1026;
+ @VisibleForTesting
+ IBinder mSurfaceFlinger;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mSurfaceFlinger = ServiceManager.getService("SurfaceFlinger");
+ }
+
+ @Override
+ protected boolean isEnabled() {
+ boolean surfaceTraceEnabled = false;
+ Parcel reply = null;
+ Parcel data = null;
+ try {
+ if (mSurfaceFlinger != null) {
+ reply = Parcel.obtain();
+ data = Parcel.obtain();
+ data.writeInterfaceToken("android.ui.ISurfaceComposer");
+ mSurfaceFlinger.transact(SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE,
+ data, reply, 0 /* flags */ );
+ surfaceTraceEnabled = reply.readBoolean();
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not get layer trace status, defaulting to false." + e.toString());
+ } finally {
+ if (data != null) {
+ data.recycle();
+ reply.recycle();
+ }
+ }
+ return surfaceTraceEnabled;
+ }
+
+ @Override
+ protected void setIsEnabled(boolean isEnabled) {
+ Parcel data = null;
+ try {
+ if (mSurfaceFlinger != null) {
+ data = Parcel.obtain();
+ data.writeInterfaceToken("android.ui.ISurfaceComposer");
+ data.writeInt(isEnabled ? 1 : 0);
+ mSurfaceFlinger.transact(SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE,
+ data, null, 0 /* flags */);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not set layer tracing." + e.toString());
+ } finally {
+ if (data != null) {
+ data.recycle();
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/deviceinfo/DeviceInfoSettings.java
similarity index 83%
rename from src/com/android/settings/DeviceInfoSettings.java
rename to src/com/android/settings/deviceinfo/DeviceInfoSettings.java
index 7e32e5e..9b99e8b 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/deviceinfo/DeviceInfoSettings.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings;
+package com.android.settings.deviceinfo;
import android.app.Activity;
import android.app.Fragment;
@@ -26,23 +26,13 @@
import android.telephony.TelephonyManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.deviceinfo.BluetoothAddressPreferenceController;
-import com.android.settings.deviceinfo.BuildNumberPreferenceController;
-import com.android.settings.deviceinfo.DeviceModelPreferenceController;
-import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController;
-import com.android.settings.deviceinfo.FeedbackPreferenceController;
-import com.android.settings.deviceinfo.ImsStatusPreferenceController;
-import com.android.settings.deviceinfo.IpAddressPreferenceController;
-import com.android.settings.deviceinfo.ManualPreferenceController;
-import com.android.settings.deviceinfo.PhoneNumberPreferenceController;
-import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
-import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
-import com.android.settings.deviceinfo.WifiMacAddressPreferenceController;
-import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceControllerV2;
-import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
-import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceControllerV2;
+import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController;
+import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceController;
+import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -84,8 +74,8 @@
|| !arguments.containsKey(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY)) {
// Increase the number of children when the device contains more than 1 sim.
- final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(
- Context.TELEPHONY_SERVICE);
+ final TelephonyManager telephonyManager = (TelephonyManager) getContext()
+ .getSystemService(Context.TELEPHONY_SERVICE);
final int numberOfChildren = Math.max(SIM_PREFERENCES_COUNT,
SIM_PREFERENCES_COUNT * telephonyManager.getPhoneCount())
+ NON_SIM_PREFERENCES_COUNT;
@@ -110,7 +100,7 @@
@Override
protected int getPreferenceScreenResId() {
- return R.xml.device_info_settings_v2;
+ return R.xml.device_info_settings;
}
@Override
@@ -148,10 +138,10 @@
Activity activity, Fragment fragment, Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new PhoneNumberPreferenceController(context));
- controllers.add(new SimStatusPreferenceControllerV2(context, fragment));
+ controllers.add(new SimStatusPreferenceController(context, fragment));
controllers.add(new DeviceModelPreferenceController(context, fragment));
- controllers.add(new ImeiInfoPreferenceControllerV2(context, fragment));
- controllers.add(new FirmwareVersionPreferenceControllerV2(context, fragment));
+ controllers.add(new ImeiInfoPreferenceController(context, fragment));
+ controllers.add(new FirmwareVersionPreferenceController(context, fragment));
controllers.add(new ImsStatusPreferenceController(context, lifecycle));
controllers.add(new IpAddressPreferenceController(context, lifecycle));
controllers.add(new WifiMacAddressPreferenceController(context, lifecycle));
@@ -176,7 +166,7 @@
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.device_info_settings_v2;
+ sir.xmlResId = R.xml.device_info_settings;
return Arrays.asList(sir);
}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerV2.java b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceController.java
similarity index 91%
rename from src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerV2.java
rename to src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceController.java
index 3ce9ee1..7629890 100644
--- a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerV2.java
+++ b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceController.java
@@ -26,20 +26,19 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
-public class FirmwareVersionPreferenceControllerV2 extends AbstractPreferenceController implements
+public class FirmwareVersionPreferenceController extends AbstractPreferenceController implements
PreferenceControllerMixin {
private final static String FIRMWARE_VERSION_KEY = "firmware_version";
private final Fragment mFragment;
- public FirmwareVersionPreferenceControllerV2(Context context, Fragment fragment) {
+ public FirmwareVersionPreferenceController(Context context, Fragment fragment) {
super(context);
mFragment = fragment;
}
-
@Override
public boolean isAvailable() {
return true;
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
similarity index 96%
rename from src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2.java
rename to src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
index dcc6db6..52ba94e 100644
--- a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2.java
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
@@ -35,7 +35,7 @@
/**
* Controller that manages preference for single and multi sim devices.
*/
-public class ImeiInfoPreferenceControllerV2 extends
+public class ImeiInfoPreferenceController extends
AbstractSimStatusImeiInfoPreferenceController implements PreferenceControllerMixin {
private static final String KEY_IMEI_INFO = "imei_info";
@@ -45,7 +45,7 @@
private final List<Preference> mPreferenceList = new ArrayList<>();
private final Fragment mFragment;
- public ImeiInfoPreferenceControllerV2(Context context, Fragment fragment) {
+ public ImeiInfoPreferenceController(Context context, Fragment fragment) {
super(context);
mFragment = fragment;
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerV2.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
similarity index 96%
rename from src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerV2.java
rename to src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
index 55493dc..00910e4 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerV2.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceController.java
@@ -32,7 +32,7 @@
import java.util.ArrayList;
import java.util.List;
-public class SimStatusPreferenceControllerV2 extends
+public class SimStatusPreferenceController extends
AbstractSimStatusImeiInfoPreferenceController implements PreferenceControllerMixin {
private static final String KEY_SIM_STATUS = "sim_status";
@@ -42,7 +42,7 @@
private final Fragment mFragment;
private final List<Preference> mPreferenceList = new ArrayList<>();
- public SimStatusPreferenceControllerV2(Context context, Fragment fragment) {
+ public SimStatusPreferenceController(Context context, Fragment fragment) {
super(context);
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 67bdada..79675cb 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -109,4 +109,13 @@
* Checks whether to display the battery v2.
*/
boolean isBatteryV2Enabled();
+
+ /**
+ * Returns a signal to indicate if the device will need to warn the user they may not make it
+ * to their next charging time.
+ *
+ * @param id Optional string used to identify the caller for metrics. Usually the class name of
+ * the caller
+ */
+ boolean getEarlyWarningSignal(Context context, String id);
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 3d99386..93c4e03 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.net.Uri;
import android.os.Process;
import android.util.FeatureFlagUtils;
import android.util.SparseIntArray;
@@ -132,4 +131,9 @@
public boolean isBatteryV2Enabled() {
return FeatureFlagUtils.isEnabled(mContext, BATTERY_SETTINGS_V2);
}
+
+ @Override
+ public boolean getEarlyWarningSignal(Context context, String id) {
+ return false;
+ }
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 205ac0b..ec54291 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -266,7 +266,7 @@
KEY_APP_LIST, lifecycle, activity, this);
controllers.add(mBatteryAppListPreferenceController);
mBatteryTipPreferenceController = new BatteryTipPreferenceController(context,
- KEY_BATTERY_TIP, this, this);
+ KEY_BATTERY_TIP, (SettingsActivity) getActivity(), this, this);
controllers.add(mBatteryTipPreferenceController);
controllers.add(new BatterySaverController(context, getLifecycle()));
controllers.add(new BatteryPercentagePreferenceController(context));
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
index 3e091b3..942c42b 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
@@ -27,8 +27,10 @@
import android.view.LayoutInflater;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController.BatteryTipListener;
+import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
@@ -97,7 +99,11 @@
if (lsn == null) {
return;
}
- mBatteryTip.action();
+ final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(mBatteryTip,
+ (SettingsActivity) getActivity(), this);
+ if (action != null) {
+ action.handlePositiveAction();
+ }
lsn.onBatteryTipHandled(mBatteryTip);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
index a1db57a..fc6aa57 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
@@ -25,6 +25,7 @@
import com.android.settings.fuelgauge.batterytip.detectors.BatteryTipDetector;
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
+import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
import com.android.settings.fuelgauge.batterytip.detectors.SummaryDetector;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
@@ -68,6 +69,8 @@
addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
addBatteryTipFromDetector(tips,
new HighUsageDetector(getContext(), policy, mBatteryStatsHelper));
+ addBatteryTipFromDetector(tips,
+ new SmartBatteryDetector(policy, getContext().getContentResolver()));
// Add summary detector at last since it need other detectors to update the mVisibleTips
addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
index 9aa70c5..9f5209f 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
@@ -23,7 +23,9 @@
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
@@ -41,6 +43,7 @@
private BatteryTipListener mBatteryTipListener;
private List<BatteryTip> mBatteryTips;
private Map<String, BatteryTip> mBatteryTipMap;
+ private SettingsActivity mSettingsActivity;
@VisibleForTesting
PreferenceGroup mPreferenceGroup;
@VisibleForTesting
@@ -48,15 +51,17 @@
PreferenceFragment mFragment;
public BatteryTipPreferenceController(Context context, String preferenceKey) {
- this(context, preferenceKey, null, null);
+ this(context, preferenceKey, null, null, null);
}
public BatteryTipPreferenceController(Context context, String preferenceKey,
- PreferenceFragment fragment, BatteryTipListener batteryTipListener) {
+ SettingsActivity settingsActivity, PreferenceFragment fragment,
+ BatteryTipListener batteryTipListener) {
super(context, preferenceKey);
mBatteryTipListener = batteryTipListener;
mBatteryTipMap = new HashMap<>();
mFragment = fragment;
+ mSettingsActivity = settingsActivity;
}
@Override
@@ -107,7 +112,11 @@
dialogFragment.setTargetFragment(mFragment, REQUEST_ANOMALY_ACTION);
dialogFragment.show(mFragment.getFragmentManager(), TAG);
} else {
- batteryTip.action();
+ final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(batteryTip,
+ mSettingsActivity, mFragment);
+ if (action != null) {
+ action.handlePositiveAction();
+ }
if (mBatteryTipListener != null) {
mBatteryTipListener.onBatteryTipHandled(batteryTip);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
new file mode 100644
index 0000000..d10fa37
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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.fuelgauge.batterytip;
+
+import android.app.Fragment;
+
+import com.android.settings.SettingsActivity;
+import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
+import com.android.settings.fuelgauge.batterytip.actions.SmartBatteryAction;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+
+/**
+ * Utility class for {@link BatteryTip}
+ */
+public class BatteryTipUtils {
+
+ /**
+ * Get a corresponding action based on {@code batteryTip}
+ * @param batteryTip used to detect which action to choose
+ * @param settingsActivity used to populate {@link BatteryTipAction}
+ * @param fragment used to populate {@link BatteryTipAction}
+ * @return an action for {@code batteryTip}
+ */
+ public static BatteryTipAction getActionForBatteryTip(BatteryTip batteryTip,
+ SettingsActivity settingsActivity, Fragment fragment) {
+ switch (batteryTip.getType()) {
+ case BatteryTip.TipType.SMART_BATTERY_MANAGER:
+ return new SmartBatteryAction(settingsActivity, fragment);
+ default:
+ return null;
+ }
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java
new file mode 100644
index 0000000..9fa69fd
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 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.fuelgauge.batterytip.actions;
+
+import android.content.Context;
+
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+
+/**
+ * Abstract class for battery tip action, which is triggered if we need to handle the battery tip
+ */
+public abstract class BatteryTipAction {
+ protected Context mContext;
+
+ public BatteryTipAction(Context context) {
+ mContext = context;
+ }
+
+ /**
+ * Handle the action when user clicks positive button
+ */
+ public abstract void handlePositiveAction();
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
new file mode 100644
index 0000000..a19471e
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 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.fuelgauge.batterytip.actions;
+
+import android.app.Fragment;
+import android.os.UserHandle;
+import android.support.v14.preference.PreferenceFragment;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.fuelgauge.SmartBatterySettings;
+
+public class SmartBatteryAction extends BatteryTipAction {
+ private SettingsActivity mSettingsActivity;
+ private Fragment mFragment;
+
+ public SmartBatteryAction(SettingsActivity settingsActivity, Fragment fragment) {
+ super(settingsActivity.getApplicationContext());
+ mSettingsActivity = settingsActivity;
+ mFragment = fragment;
+ }
+
+ /**
+ * Handle the action when user clicks positive button
+ */
+ @Override
+ public void handlePositiveAction() {
+ mSettingsActivity.startPreferencePanelAsUser(mFragment,
+ SmartBatterySettings.class.getName(), null /* args */,
+ R.string.smart_battery_manager_title, null /* titleText */,
+ new UserHandle(UserHandle.myUserId()));
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java
new file mode 100644
index 0000000..bff324d
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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.fuelgauge.batterytip.detectors;
+
+import android.content.ContentResolver;
+import android.provider.Settings;
+
+import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
+
+/**
+ * Detect whether to show smart battery tip.
+ */
+public class SmartBatteryDetector implements BatteryTipDetector {
+ private BatteryTipPolicy mPolicy;
+ private ContentResolver mContentResolver;
+
+ public SmartBatteryDetector(BatteryTipPolicy policy, ContentResolver contentResolver) {
+ mPolicy = policy;
+ mContentResolver = contentResolver;
+ }
+
+ @Override
+ public BatteryTip detect() {
+ // Show it if there is no other tips shown
+ final boolean smartBatteryOn = Settings.Global.getInt(mContentResolver,
+ Settings.Global.APP_STANDBY_ENABLED, 1) != 0;
+ final int state =
+ smartBatteryOn ? BatteryTip.StateType.INVISIBLE : BatteryTip.StateType.NEW;
+ return new SmartBatteryTip(state);
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
index eadd0e1..292849d 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
@@ -105,11 +105,6 @@
*/
public abstract void updateState(BatteryTip tip);
- /**
- * Execute the action for this {@link BatteryTip}
- */
- public abstract void action();
-
public Preference buildPreference(Context context) {
Preference preference = new Preference(context);
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
index 001a48e..0316832 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
@@ -78,11 +78,6 @@
mState = tip.mState;
}
- @Override
- public void action() {
- // do nothing
- }
-
public long getScreenTimeMs() {
return mScreenTimeMs;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
index 4a207e0..32cbe02 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
@@ -55,11 +55,6 @@
mState = tip.mState;
}
- @Override
- public void action() {
- // do nothing
- }
-
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public BatteryTip createFromParcel(Parcel in) {
return new LowBatteryTip(in);
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java
new file mode 100644
index 0000000..7b408bb
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 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.fuelgauge.batterytip.tips;
+
+import android.content.Context;
+import android.os.Parcel;
+import android.provider.Settings;
+
+import com.android.settings.R;
+
+/**
+ * Tip to suggest turn on smart battery if it is not on
+ */
+public class SmartBatteryTip extends BatteryTip {
+
+ public SmartBatteryTip(@StateType int state) {
+ super(TipType.SMART_BATTERY_MANAGER, state, false /* showDialog */);
+ }
+
+ private SmartBatteryTip(Parcel in) {
+ super(in);
+ }
+
+ @Override
+ public CharSequence getTitle(Context context) {
+ return context.getString(R.string.battery_tip_smart_battery_title);
+ }
+
+ @Override
+ public CharSequence getSummary(Context context) {
+ return context.getString(R.string.battery_tip_smart_battery_summary);
+ }
+
+ @Override
+ public int getIconId() {
+ return R.drawable.ic_perm_device_information_red_24dp;
+ }
+
+ @Override
+ public void updateState(BatteryTip tip) {
+ mState = tip.mState;
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new SmartBatteryTip(in);
+ }
+
+ public BatteryTip[] newArray(int size) {
+ return new SmartBatteryTip[size];
+ }
+ };
+
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
index 51019a8..458bd2e 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
@@ -55,11 +55,6 @@
mState = tip.mState;
}
- @Override
- public void action() {
- // do nothing
- }
-
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public BatteryTip createFromParcel(Parcel in) {
return new SummaryTip(in);
diff --git a/src/com/android/settings/location/LocationScanningPreferenceController.java b/src/com/android/settings/location/LocationScanningPreferenceController.java
new file mode 100644
index 0000000..ec487e4
--- /dev/null
+++ b/src/com/android/settings/location/LocationScanningPreferenceController.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 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.location;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.R;
+
+import android.support.annotation.VisibleForTesting;
+
+
+public class LocationScanningPreferenceController extends BasePreferenceController {
+
+ @VisibleForTesting static final String KEY_LOCATION_SCANNING = "location_scanning";
+
+ public LocationScanningPreferenceController(Context context) {
+ super(context, KEY_LOCATION_SCANNING);
+ }
+
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : DISABLED_UNSUPPORTED;
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index 563352e..d0fca16 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -141,6 +141,7 @@
new RecentLocationRequestPreferenceController(context, fragment, lifecycle));
controllers.add(
new LocationServicePreferenceController(context, fragment, lifecycle));
+ controllers.add(new LocationScanningPreferenceController(context));
return controllers;
}
diff --git a/src/com/android/settings/notification/AlarmVolumePreferenceController.java b/src/com/android/settings/notification/AlarmVolumePreferenceController.java
index cd1f6e3..c9b283b 100644
--- a/src/com/android/settings/notification/AlarmVolumePreferenceController.java
+++ b/src/com/android/settings/notification/AlarmVolumePreferenceController.java
@@ -21,6 +21,7 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class AlarmVolumePreferenceController extends
@@ -43,7 +44,8 @@
@Override
public boolean isAvailable() {
- return !mHelper.isSingleVolume();
+ return mContext.getResources().getBoolean(R.bool.config_show_alarm_volume)
+ && !mHelper.isSingleVolume();
}
@Override
diff --git a/src/com/android/settings/notification/ChargingSoundPreferenceController.java b/src/com/android/settings/notification/ChargingSoundPreferenceController.java
index 55cba96..e280177 100644
--- a/src/com/android/settings/notification/ChargingSoundPreferenceController.java
+++ b/src/com/android/settings/notification/ChargingSoundPreferenceController.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.provider.Settings.Global;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -33,7 +34,10 @@
super(context, parent, lifecycle);
mPreference = new SettingPref(
TYPE_GLOBAL, KEY_CHARGING_SOUNDS, Global.CHARGING_SOUNDS_ENABLED, DEFAULT_ON);
-
}
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_charging_sounds);
+ }
}
diff --git a/src/com/android/settings/notification/MediaVolumePreferenceController.java b/src/com/android/settings/notification/MediaVolumePreferenceController.java
index 4f167f8..381135e 100644
--- a/src/com/android/settings/notification/MediaVolumePreferenceController.java
+++ b/src/com/android/settings/notification/MediaVolumePreferenceController.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.media.AudioManager;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class MediaVolumePreferenceController extends
@@ -32,7 +33,7 @@
@Override
public boolean isAvailable() {
- return true;
+ return mContext.getResources().getBoolean(R.bool.config_show_media_volume);
}
@Override
diff --git a/src/com/android/settings/notification/NotificationRingtonePreferenceController.java b/src/com/android/settings/notification/NotificationRingtonePreferenceController.java
index 72e8d8f..00f478f 100644
--- a/src/com/android/settings/notification/NotificationRingtonePreferenceController.java
+++ b/src/com/android/settings/notification/NotificationRingtonePreferenceController.java
@@ -19,6 +19,8 @@
import android.content.Context;
import android.media.RingtoneManager;
+import com.android.settings.R;
+
public class NotificationRingtonePreferenceController extends RingtonePreferenceControllerBase {
private static final String KEY_NOTIFICATION_RINGTONE = "notification_ringtone";
@@ -28,6 +30,11 @@
}
@Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_notification_ringtone);
+ }
+
+ @Override
public String getPreferenceKey() {
return KEY_NOTIFICATION_RINGTONE;
}
diff --git a/src/com/android/settings/notification/NotificationVolumePreferenceController.java b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
index 5f888f8..4024f9f 100644
--- a/src/com/android/settings/notification/NotificationVolumePreferenceController.java
+++ b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
@@ -20,6 +20,7 @@
import android.media.AudioManager;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -45,7 +46,8 @@
@Override
public boolean isAvailable() {
- return !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
+ return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
+ && !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
}
@Override
diff --git a/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java b/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java
index b08b8f8..11aaa92 100644
--- a/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java
+++ b/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.provider.Settings.System;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -35,4 +36,8 @@
TYPE_SYSTEM, KEY_SCREEN_LOCKING_SOUNDS, System.LOCKSCREEN_SOUNDS_ENABLED, DEFAULT_ON);
}
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_screen_locking_sounds);
+ }
}
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index 6e998f6..4a27b11 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -33,6 +33,7 @@
import com.android.settings.RingtonePreference;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -201,15 +202,45 @@
controllers.add(new WorkSoundPreferenceController(context, fragment, lifecycle));
// === Other Sound Settings ===
- controllers.add(new DialPadTonePreferenceController(context, fragment, lifecycle));
- controllers.add(new ScreenLockSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new ChargingSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new DockingSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new TouchSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new VibrateOnTouchPreferenceController(context, fragment, lifecycle));
- controllers.add(new DockAudioMediaPreferenceController(context, fragment, lifecycle));
- controllers.add(new BootSoundPreferenceController(context));
- controllers.add(new EmergencyTonePreferenceController(context, fragment, lifecycle));
+ final DialPadTonePreferenceController dialPadTonePreferenceController =
+ new DialPadTonePreferenceController(context, fragment, lifecycle);
+ final ScreenLockSoundPreferenceController screenLockSoundPreferenceController =
+ new ScreenLockSoundPreferenceController(context, fragment, lifecycle);
+ final ChargingSoundPreferenceController chargingSoundPreferenceController =
+ new ChargingSoundPreferenceController(context, fragment, lifecycle);
+ final DockingSoundPreferenceController dockingSoundPreferenceController =
+ new DockingSoundPreferenceController(context, fragment, lifecycle);
+ final TouchSoundPreferenceController touchSoundPreferenceController =
+ new TouchSoundPreferenceController(context, fragment, lifecycle);
+ final VibrateOnTouchPreferenceController vibrateOnTouchPreferenceController =
+ new VibrateOnTouchPreferenceController(context, fragment, lifecycle);
+ final DockAudioMediaPreferenceController dockAudioMediaPreferenceController =
+ new DockAudioMediaPreferenceController(context, fragment, lifecycle);
+ final BootSoundPreferenceController bootSoundPreferenceController =
+ new BootSoundPreferenceController(context);
+ final EmergencyTonePreferenceController emergencyTonePreferenceController =
+ new EmergencyTonePreferenceController(context, fragment, lifecycle);
+
+ controllers.add(dialPadTonePreferenceController);
+ controllers.add(screenLockSoundPreferenceController);
+ controllers.add(chargingSoundPreferenceController);
+ controllers.add(dockingSoundPreferenceController);
+ controllers.add(touchSoundPreferenceController);
+ controllers.add(vibrateOnTouchPreferenceController);
+ controllers.add(dockAudioMediaPreferenceController);
+ controllers.add(bootSoundPreferenceController);
+ controllers.add(emergencyTonePreferenceController);
+ controllers.add(new PreferenceCategoryController(context,
+ "other_sounds_and_vibrations_category",
+ Arrays.asList(dialPadTonePreferenceController,
+ screenLockSoundPreferenceController,
+ chargingSoundPreferenceController,
+ dockingSoundPreferenceController,
+ touchSoundPreferenceController,
+ vibrateOnTouchPreferenceController,
+ dockAudioMediaPreferenceController,
+ bootSoundPreferenceController,
+ emergencyTonePreferenceController)));
return controllers;
}
diff --git a/src/com/android/settings/notification/TouchSoundPreferenceController.java b/src/com/android/settings/notification/TouchSoundPreferenceController.java
index 4e25507..20c9cee 100644
--- a/src/com/android/settings/notification/TouchSoundPreferenceController.java
+++ b/src/com/android/settings/notification/TouchSoundPreferenceController.java
@@ -23,6 +23,7 @@
import android.media.AudioManager;
import android.os.AsyncTask;
import android.provider.Settings.System;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -53,4 +54,9 @@
}
};
}
+
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_touch_sounds);
+ }
}
diff --git a/src/com/android/settings/notification/ZenModeBackend.java b/src/com/android/settings/notification/ZenModeBackend.java
index 6cee28e..158f9ac 100644
--- a/src/com/android/settings/notification/ZenModeBackend.java
+++ b/src/com/android/settings/notification/ZenModeBackend.java
@@ -103,11 +103,18 @@
}
protected int getPriorityCallSenders() {
- return mPolicy.priorityCallSenders;
+ if (isPriorityCategoryEnabled(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS)) {
+ return mPolicy.priorityCallSenders;
+ }
+
+ return SOURCE_NONE;
}
protected int getPriorityMessageSenders() {
- return mPolicy.priorityMessageSenders;
+ if (isPriorityCategoryEnabled(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES)) {
+ return mPolicy.priorityMessageSenders;
+ }
+ return SOURCE_NONE;
}
protected void saveVisualEffectsPolicy(int category, boolean canBypass) {
diff --git a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
index 3e2f802..ef1b09a 100644
--- a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
@@ -19,16 +19,27 @@
import android.app.NotificationManager;
import android.content.Context;
import android.provider.Settings;
+import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController {
+public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController implements
+ Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_calls";
+ private final ZenModeBackend mBackend;
+ private ListPreference mPreference;
+ private final String[] mListValues;
public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
+ mBackend = ZenModeBackend.getInstance(context);
+ mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
}
@Override
@@ -42,20 +53,54 @@
}
@Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (ListPreference) screen.findPreference(KEY);
+ }
+
+ @Override
public void updateState(Preference preference) {
super.updateState(preference);
+ updateFromContactsValue(preference);
+ }
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
+ mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
+ ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
+ updateFromContactsValue(preference);
+ return true;
+ }
+
+ private void updateFromContactsValue(Preference preference) {
+ mPreference = (ListPreference) preference;
switch (getZenMode()) {
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
case Settings.Global.ZEN_MODE_ALARMS:
- preference.setEnabled(false);
- preference.setSummary(mBackend.getContactsSummary(mBackend.SOURCE_NONE));
+ mPreference.setEnabled(false);
+ mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
+ mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
break;
default:
preference.setEnabled(true);
preference.setSummary(mBackend.getContactsSummary(
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS));
+
+ final String currentVal = ZenModeBackend.getKeyFromSetting(
+ mBackend.getPriorityCallSenders());
+ mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
+ }
+ }
+
+ @VisibleForTesting
+ protected int getIndexOfSendersValue(String currentVal) {
+ int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
+ for (int i = 0; i < mListValues.length; i++) {
+ if (TextUtils.equals(currentVal, mListValues[i])) {
+ return i;
+ }
}
+ return index;
}
}
diff --git a/src/com/android/settings/notification/ZenModeCallsSettings.java b/src/com/android/settings/notification/ZenModeCallsSettings.java
deleted file mode 100644
index 6874dc0..0000000
--- a/src/com/android/settings/notification/ZenModeCallsSettings.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import android.app.NotificationManager;
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.R;
-import com.android.settings.widget.RadioButtonPickerFragment;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ZenModeCallsSettings extends RadioButtonPickerFragment {
- private ZenModeBackend mBackend;
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- mBackend = ZenModeBackend.getInstance(context);
- }
-
- @Override
- public int getMetricsCategory() {
- return MetricsProto.MetricsEvent.NOTIFICATION_ZEN_MODE_CALLS;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_calls_settings;
- }
-
- @Override
- protected List<? extends RadioButtonPickerFragment.CandidateInfo> getCandidates() {
- final String[] entries = entries();
- final String[] values = keys();
- final List<CallsCandidateInfo> candidates = new ArrayList<>();
-
- if (entries == null || entries.length <= 0) return null;
- if (values == null || values.length != entries.length) {
- throw new IllegalArgumentException("Entries and values must be of the same length.");
- }
-
- for (int i = 0; i < entries.length; i++) {
- candidates.add(new CallsCandidateInfo(entries[i], values[i]));
- }
-
- return candidates;
- }
-
- private String[] entries() {
- return getResources().getStringArray(R.array.zen_mode_contacts_entries);
- }
-
- private String[] keys() {
- return getResources().getStringArray(R.array.zen_mode_contacts_values);
- }
-
- @Override
- protected String getDefaultKey() {
- return mBackend.getSendersKey(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS);
- }
-
- @Override
- protected boolean setDefaultKey(String key) {
- mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
- mBackend.getSettingFromPrefKey(key));
- return true;
- }
-
- private static final class CallsCandidateInfo extends RadioButtonPickerFragment.CandidateInfo {
- private final String name;
- private final String key;
-
- CallsCandidateInfo(String title, String value) {
- super(true);
-
- name = title;
- key = value;
- }
-
- @Override
- public CharSequence loadLabel() {
- return name;
- }
-
- @Override
- public Drawable loadIcon() {
- return null;
- }
-
- @Override
- public String getKey() {
- return key;
- }
- }
-}
diff --git a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
index 0ffc44d..93d4aa7 100644
--- a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
@@ -3,16 +3,28 @@
import android.app.NotificationManager;
import android.content.Context;
import android.provider.Settings;
+import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController {
+public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController
+ implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_messages";
+ private final ZenModeBackend mBackend;
+ private ListPreference mPreference;
+ private final String[] mListValues;
+
public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
+ mBackend = ZenModeBackend.getInstance(context);
+ mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
}
@Override
@@ -26,19 +38,54 @@
}
@Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (ListPreference) screen.findPreference(KEY);
+ }
+
+ @Override
public void updateState(Preference preference) {
super.updateState(preference);
+ updateFromContactsValue(preference);
+ }
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
+ mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
+ ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
+ updateFromContactsValue(preference);
+ return true;
+ }
+
+ private void updateFromContactsValue(Preference preference) {
+ mPreference = (ListPreference) preference;
switch (getZenMode()) {
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
case Settings.Global.ZEN_MODE_ALARMS:
- preference.setEnabled(false);
- preference.setSummary(mBackend.getContactsSummary(mBackend.SOURCE_NONE));
+ mPreference.setEnabled(false);
+ mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
+ mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
break;
default:
preference.setEnabled(true);
preference.setSummary(mBackend.getContactsSummary(
NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES));
+
+ final String currentVal = ZenModeBackend.getKeyFromSetting(
+ mBackend.getPriorityMessageSenders());
+ mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
}
}
+
+ @VisibleForTesting
+ protected int getIndexOfSendersValue(String currentVal) {
+ int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
+ for (int i = 0; i < mListValues.length; i++) {
+ if (TextUtils.equals(currentVal, mListValues[i])) {
+ return i;
+ }
+ }
+
+ return index;
+ }
}
diff --git a/src/com/android/settings/notification/ZenModeMessagesSettings.java b/src/com/android/settings/notification/ZenModeMessagesSettings.java
deleted file mode 100644
index 9cbf248..0000000
--- a/src/com/android/settings/notification/ZenModeMessagesSettings.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import android.app.NotificationManager;
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.R;
-import com.android.settings.widget.RadioButtonPickerFragment;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ZenModeMessagesSettings extends RadioButtonPickerFragment {
- private ZenModeBackend mBackend;
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- mBackend = ZenModeBackend.getInstance(context);
- }
- @Override
- public int getMetricsCategory() {
- return MetricsProto.MetricsEvent.NOTIFICATION_ZEN_MODE_MESSAGES;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_messages_settings;
- }
-
- @Override
- protected List<? extends RadioButtonPickerFragment.CandidateInfo> getCandidates() {
- final String[] entries = entries();
- final String[] values = keys();
- final List<MessagesCandidateInfo> candidates = new ArrayList<>();
-
- if (entries == null || entries.length <= 0) return null;
- if (values == null || values.length != entries.length) {
- throw new IllegalArgumentException("Entries and values must be of the same length.");
- }
-
- for (int i = 0; i < entries.length; i++) {
- candidates.add(new MessagesCandidateInfo(entries[i], values[i]));
- }
-
- return candidates;
- }
-
- private String[] entries() {
- return getResources().getStringArray(R.array.zen_mode_contacts_entries);
- }
-
- private String[] keys() {
- return getResources().getStringArray(R.array.zen_mode_contacts_values);
- }
-
- @Override
- protected String getDefaultKey() {
- return mBackend.getSendersKey(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES);
- }
-
- @Override
- protected boolean setDefaultKey(String key) {
- mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
- mBackend.getSettingFromPrefKey(key));
- return true;
- }
-
- private final class MessagesCandidateInfo extends RadioButtonPickerFragment.CandidateInfo {
- private final String name;
- private final String key;
-
- MessagesCandidateInfo(String title, String value) {
- super(true);
-
- name = title;
- key = value;
- }
-
- @Override
- public CharSequence loadLabel() {
- return name;
- }
-
- @Override
- public Drawable loadIcon() {
- return null;
- }
-
- @Override
- public String getKey() {
- return key;
- }
- }
-}
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index f8125cb..b0159cf 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -19,7 +19,6 @@
import android.support.annotation.VisibleForTesting;
import com.android.settings.DateTimeSettings;
-import com.android.settings.DeviceInfoSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.LegalSettings;
import com.android.settings.accessibility.AccessibilitySettings;
@@ -39,6 +38,7 @@
import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
+import com.android.settings.deviceinfo.DeviceInfoSettings;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.display.AmbientDisplaySettings;
diff --git a/src/com/android/settings/security/ScreenPinningPreferenceController.java b/src/com/android/settings/security/ScreenPinningPreferenceController.java
index 60279c7..01ccbaa 100644
--- a/src/com/android/settings/security/ScreenPinningPreferenceController.java
+++ b/src/com/android/settings/security/ScreenPinningPreferenceController.java
@@ -19,7 +19,6 @@
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@@ -38,19 +37,16 @@
}
@Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- final Preference preference = screen.findPreference(getPreferenceKey());
- if (preference == null) {
- return;
- }
- if (Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
- preference.setSummary(
- mContext.getString(R.string.switch_on_text));
- } else {
- preference.setSummary(
- mContext.getString(R.string.switch_off_text));
- }
+ public String getSummary() {
+ return Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.LOCK_TO_APP_ENABLED, 0) != 0
+ ? mContext.getString(R.string.switch_on_text)
+ : mContext.getString(R.string.switch_off_text);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ preference.setSummary(getSummary());
}
}
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 7136182..4df4d50 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -79,7 +79,7 @@
}
private Slice getHoldingSlice(Uri uri) {
- return new ListBuilder(uri).build();
+ return new ListBuilder(getContext(), uri).build();
}
// TODO (b/70622039) remove this when the proper wifi slice is enabled.
@@ -106,7 +106,7 @@
}
boolean finalWifiEnabled = wifiEnabled;
- return new ListBuilder(sliceUri)
+ return new ListBuilder(getContext(), sliceUri)
.setColor(R.color.material_blue_500)
.addRow(b -> b
.setTitle(getContext().getString(R.string.wifi_settings))
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index 3663e89..014ead2 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -59,7 +59,7 @@
? sliceData.getScreenTitle()
: summaryText;
- RowBuilder builder = new RowBuilder(sliceData.getUri())
+ RowBuilder builder = new RowBuilder(context, sliceData.getUri())
.setTitle(sliceData.getTitle())
.setTitleItem(icon)
.setSubtitle(subtitleText)
@@ -75,7 +75,7 @@
sliceData.getKey());
}
- return new ListBuilder(sliceData.getUri())
+ return new ListBuilder(context, sliceData.getUri())
.addRow(builder)
.build();
}
@@ -122,4 +122,4 @@
intent.setClassName("com.android.settings", SubSettings.class.getName());
return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/wrapper/IWindowManagerWrapper.java b/src/com/android/settings/wrapper/IWindowManagerWrapper.java
new file mode 100644
index 0000000..8c2ed35
--- /dev/null
+++ b/src/com/android/settings/wrapper/IWindowManagerWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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.wrapper;
+
+import android.os.RemoteException;
+import android.view.IWindowManager;
+
+/**
+ * This class replicates a subset of the android.view.IWindowManager. The class
+ * exists so that we can use a thin wrapper around the IWindowManager in production code
+ * and a mock in tests.
+ */
+public class IWindowManagerWrapper {
+
+ private final IWindowManager mWindowManager;
+
+ public IWindowManagerWrapper(IWindowManager wm) {
+ mWindowManager = wm;
+ }
+
+ /**
+ * Returns true if window trace is enabled.
+ */
+ public boolean isWindowTraceEnabled() throws RemoteException {
+ return mWindowManager.isWindowTraceEnabled();
+ }
+
+ /**
+ * Starts a window trace.
+ */
+ public void startWindowTrace() throws RemoteException {
+ mWindowManager.startWindowTrace();
+ }
+
+ /**
+ * Stops a window trace.
+ */
+ public void stopWindowTrace() throws RemoteException {
+ mWindowManager.stopWindowTrace();
+ }
+}
diff --git a/tests/robotests/OWNERS b/tests/robotests/OWNERS
new file mode 100644
index 0000000..8a7a27e
--- /dev/null
+++ b/tests/robotests/OWNERS
@@ -0,0 +1,2 @@
+# We do not guard tests - everyone is welcomed to contribute to tests.
+per-file *.java=*
\ No newline at end of file
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 7bb80e8..c3ae911 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -22,11 +22,19 @@
<bool name="config_display_recent_apps">false</bool>
<bool name="config_show_wifi_settings">false</bool>
<bool name="config_show_high_power_apps">false</bool>
+ <bool name="config_show_alarm_volume">false</bool>
+ <bool name="config_show_charging_sounds">false</bool>
+ <bool name="config_show_media_volume">false</bool>
+ <bool name="config_show_notification_ringtone">false</bool>
+ <bool name="config_show_notification_volume">false</bool>
+ <bool name="config_show_screen_locking_sounds">false</bool>
+ <bool name="config_show_touch_sounds">false</bool>
<bool name="config_show_device_administrators">false</bool>
<bool name="config_show_premium_sms">false</bool>
<bool name="config_show_data_saver">false</bool>
<bool name="config_show_enabled_vr_listeners">false</bool>
<bool name="config_location_mode_available">false</bool>
+ <bool name="config_show_location_scanning">false</bool>
<bool name="config_show_wallpaper_attribution">false</bool>
<bool name="config_show_default_home">false</bool>
<bool name="config_show_accessibility_shortcut_preference">false</bool>
@@ -37,4 +45,6 @@
<bool name="config_show_tts_settings_summary">false</bool>
<bool name="config_show_pointer_speed">false</bool>
<bool name="config_show_vibrate_input_devices">false</bool>
+ <bool name="config_show_color_correction_preference">false</bool>
+ <bool name="config_show_color_inversion_preference">false</bool>
</resources>
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index c721fc9..96ce183 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -45,6 +45,8 @@
private Context mContext;
private AccessibilitySettings mFragment;
private boolean mAccessibilityShortcutPreferenceRemoved;
+ private boolean mColorInversionPreferenceRemoved;
+ private boolean mColorCorrectionPreferenceRemoved;
@Before
public void setUp() {
@@ -60,7 +62,16 @@
protected boolean removePreference(String key) {
if (AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE.equals(key)) {
mAccessibilityShortcutPreferenceRemoved = true;
+ return true;
+ }
+ if (AccessibilitySettings.TOGGLE_INVERSION_PREFERENCE.equals(key)) {
+ mColorInversionPreferenceRemoved = true;
+ return true;
+ }
+
+ if (AccessibilitySettings.DISPLAY_DALTONIZER_PREFERENCE_SCREEN.equals(key)) {
+ mColorCorrectionPreferenceRemoved = true;
return true;
}
return false;
@@ -104,4 +115,38 @@
assertThat(niks).contains(AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE);
}
+
+ @Test
+ public void testColorInversionPreference_byDefault_shouldBeShown() {
+ final Preference preference = new Preference(mContext);
+ mFragment.checkColorInversionVisibility(preference);
+
+ assertThat(mColorInversionPreferenceRemoved).isEqualTo(false);
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void testColorInversionPreference_ifDisabled_shouldNotBeShown() {
+ final Preference preference = new Preference(mContext);
+ mFragment.checkColorInversionVisibility(preference);
+
+ assertThat(mColorInversionPreferenceRemoved).isEqualTo(true);
+ }
+
+ @Test
+ public void testColorCorrectionPreference_byDefault_shouldBeShown() {
+ final Preference preference = new Preference(mContext);
+ mFragment.checkColorCorrectionVisibility(preference);
+
+ assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(false);
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void testColorCorrectionPreference_ifDisabled_shouldNotBeShown() {
+ final Preference preference = new Preference(mContext);
+ mFragment.checkColorCorrectionVisibility(preference);
+
+ assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(true);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
index f409095..73a58bf 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
@@ -17,15 +17,14 @@
package com.android.settings.accounts;
import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME;
-
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import android.accounts.Account;
import android.app.Activity;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.Bundle;
import android.os.UserHandle;
@@ -55,9 +54,9 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
- manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
- shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
+ manifest = TestConfig.MANIFEST_PATH,
+ sdk = TestConfig.SDK_VERSION,
+ shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
)
public class AccountHeaderPreferenceControllerTest {
@@ -74,8 +73,8 @@
private AccountHeaderPreferenceController mController;
- private Lifecycle mLifecycle =
- new Lifecycle(() -> AccountHeaderPreferenceControllerTest.this.mLifecycle);
+ private LifecycleOwner mLifecycleOwner;
+ private Lifecycle mLifecycle;
@Before
public void setUp() {
@@ -84,7 +83,8 @@
mHeaderPreference = new LayoutPreference(
RuntimeEnvironment.application, R.layout.settings_entity_header);
doReturn(mContext).when(mActivity).getApplicationContext();
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java
index c59ac18..968f049 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
@@ -57,13 +58,15 @@
private AssistContextPreferenceController.SettingObserver mObserver;
private Context mContext;
private AssistContextPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mContext = RuntimeEnvironment.application;
mController = new AssistContextPreferenceController(mContext, mLifecycle);
ReflectionHelpers.setField(mController, "mSettingObserver", mObserver);
diff --git a/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java
index 1dec8d0..57b809e 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java
@@ -28,6 +28,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -64,13 +65,15 @@
private AssistFlashScreenPreferenceController.SettingObserver mObserver;
private Context mContext;
private AssistFlashScreenPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mContext = RuntimeEnvironment.application;
mController = spy(new AssistFlashScreenPreferenceController(mContext, mLifecycle));
mLifecycle.addObserver(mController);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
index 8f3d3c2..7f58254 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
@@ -19,6 +19,7 @@
import static org.mockito.Mockito.when;
import android.app.Activity;
+import android.arch.lifecycle.LifecycleOwner;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
@@ -44,6 +45,7 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BluetoothDetailsControllerTestBase {
protected Context mContext;
+ private LifecycleOwner mLifecycleOwner;
protected Lifecycle mLifecycle;
protected DeviceConfig mDeviceConfig;
protected BluetoothDevice mDevice;
@@ -73,7 +75,8 @@
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
- mLifecycle = spy(new Lifecycle(() -> mLifecycle));
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = spy(new Lifecycle(mLifecycleOwner));
mBluetoothManager = new BluetoothManager(mContext);
mBluetoothAdapter = mBluetoothManager.getAdapter();
}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceGroupControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceGroupControllerTest.java
index aa5eb67..78be742 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceGroupControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceGroupControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
@@ -63,6 +64,7 @@
private Context mContext;
private Preference mPreference;
private ConnectedDeviceGroupController mConnectedDeviceGroupController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
@@ -72,7 +74,8 @@
mContext = RuntimeEnvironment.application;
mPreference = new Preference(mContext);
mPreference.setKey(PREFERENCE_KEY_1);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mPreferenceGroup = spy(new PreferenceScreen(mContext, null));
doReturn(mPreferenceManager).when(mPreferenceGroup).getPreferenceManager();
doReturn(mContext).when(mDashboardFragment).getContext();
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java
index bceb865..822cb10 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionControllerMixinTest.java
@@ -24,6 +24,7 @@
import static org.mockito.Mockito.when;
import android.app.LoaderManager;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import com.android.settings.TestConfig;
@@ -49,7 +50,9 @@
@Mock
private SuggestionControllerMixin.SuggestionControllerHost mHost;
+
private Context mContext;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private SuggestionControllerMixin mMixin;
@@ -58,7 +61,8 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
FakeFeatureFactory.setupForTest();
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
}
@After
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/DataLoaderTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/DataLoaderTest.java
new file mode 100644
index 0000000..23bfabb
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/DataLoaderTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class DataLoaderTest {
+
+ @Test
+ public void testHasData() {
+ List<RegionInfo> regions = new DataLoader(Locale.US).loadRegionInfos();
+ // Sanity check. Real size is closer to 200.
+ assertNotNull(regions);
+ assertTrue(regions.size() > 100);
+ assertEquals("Afghanistan", regions.get(0).getName());
+ assertEquals("Zimbabwe", regions.get(regions.size() - 1).getName());
+ }
+
+ @Test
+ public void testRegionsWithTimeZone() {
+ List<RegionInfo> regions = new DataLoader(Locale.US).loadRegionInfos();
+ checkRegionHasTimeZone(regions, "AT", "Europe/Vienna");
+ checkRegionHasTimeZone(regions, "US", "America/Los_Angeles");
+ checkRegionHasTimeZone(regions, "CN", "Asia/Shanghai");
+ checkRegionHasTimeZone(regions, "AU", "Australia/Sydney");
+ }
+
+ @Test
+ public void testFixedOffsetTimeZones() {
+ List<TimeZoneInfo> timeZones = new DataLoader(Locale.US).loadFixedOffsets();
+ // Etc/GMT would be equivalent to Etc/UTC, except for how it is labelled. Users have
+ // explicitly asked for UTC to be supported, so make sure we label it as such.
+ checkHasTimeZone(timeZones, "Etc/UTC");
+ checkHasTimeZone(timeZones, "Etc/GMT-1");
+ checkHasTimeZone(timeZones, "Etc/GMT-14");
+ checkHasTimeZone(timeZones, "Etc/GMT+1");
+ checkHasTimeZone(timeZones, "Etc/GMT+12");
+ }
+
+ private void checkRegionHasTimeZone(List<RegionInfo> regions, String regionId, String tzId) {
+ RegionInfo ri = findRegion(regions, regionId);
+ assertTrue("Region " + regionId + " does not have time zone " + tzId,
+ ri.getTimeZoneIds().contains(tzId));
+ }
+
+ private void checkHasTimeZone(List<TimeZoneInfo> timeZoneInfos, String tzId) {
+ for (TimeZoneInfo tz : timeZoneInfos) {
+ if (tz.getId().equals(tzId)) {
+ return;
+ }
+ }
+ fail("Fixed offset time zones do not contain " + tzId);
+ }
+
+ private RegionInfo findRegion(List<RegionInfo> regions, String regionId) {
+ for (RegionInfo region : regions) {
+ if (region.getId().equals(regionId)) {
+ assertNotNull(region.getName());
+ return region;
+ }
+
+ }
+ fail("No region with id " + regionId + " found.");
+ return null; // can't reach.
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneAdapterTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneAdapterTest.java
new file mode 100644
index 0000000..5f29a0b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneAdapterTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.datetime.timezone;
+
+import android.icu.util.TimeZone;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.FrameLayout;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.Collections;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+ shadows = {
+ SettingsShadowResources.class,
+ SettingsShadowResources.SettingsShadowTheme.class})
+public class TimeZoneAdapterTest {
+ @Mock
+ private View.OnClickListener mOnClickListener;
+
+ private TimeZoneAdapter mTimeZoneAdapter;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, RuntimeEnvironment.application);
+ }
+
+ @Test
+ public void getItemViewType_onDefaultTimeZone_returnsTypeSelected() {
+ final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getDefault());
+ mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
+ assertThat(mTimeZoneAdapter.getItemViewType(0)).isEqualTo(TimeZoneAdapter.VIEW_TYPE_SELECTED);
+ }
+
+ @Test
+ public void getItemViewType_onNonDefaultTimeZone_returnsTypeNormal() {
+ final TimeZoneInfo tzi = dummyTimeZoneInfo(getNonDefaultTimeZone());
+ mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
+ assertThat(mTimeZoneAdapter.getItemViewType(0)).isEqualTo(TimeZoneAdapter.VIEW_TYPE_NORMAL);
+ }
+
+ @Test
+ public void bindViewHolder_onDstTimeZone_showsDstLabel() {
+ final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("America/Los_Angeles"));
+ mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
+
+ final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
+
+ final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
+ mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
+ assertThat(viewHolder.mDstView.getVisibility()).isEqualTo(View.VISIBLE);
+ }
+
+ @Test
+ public void bindViewHolder_onNonDstTimeZone_hidesDstLabel() {
+ final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("Etc/UTC"));
+ mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
+
+ final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
+
+ final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
+ mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
+ assertThat(viewHolder.mDstView.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ // Pick an arbitrary time zone that's not the current default.
+ private static TimeZone getNonDefaultTimeZone() {
+ final String[] availableIDs = TimeZone.getAvailableIDs();
+ int index = 0;
+ if (TextUtils.equals(availableIDs[index], TimeZone.getDefault().getID())) {
+ index++;
+ }
+ return TimeZone.getTimeZone(availableIDs[index]);
+ }
+
+ private TimeZoneInfo dummyTimeZoneInfo(TimeZone timeZone) {
+ return new TimeZoneInfo.Builder(timeZone).setGmtOffset("GMT+0").setItemId(1).build();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java
index 582400d..a7ae938 100644
--- a/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java
@@ -27,6 +27,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothCodecConfig;
import android.content.Context;
@@ -60,6 +61,7 @@
@Mock
private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private Context mContext;
private AbstractBluetoothA2dpPreferenceController mController;
@@ -68,7 +70,8 @@
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new AbstractBluetoothA2dpPreferenceControllerImpl(mContext, mLifecycle,
mBluetoothA2dpConfigStore));
doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig();
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothAudioBitsPerSamplePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothAudioBitsPerSamplePreferenceControllerTest.java
index fe0a41a..7074c58 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothAudioBitsPerSamplePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothAudioBitsPerSamplePreferenceControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.bluetooth.BluetoothCodecConfig;
import android.content.Context;
import android.support.v7.preference.ListPreference;
@@ -61,13 +62,15 @@
private String[] mListValues;
private Context mContext;
private BluetoothAudioBitsPerSamplePreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new BluetoothAudioBitsPerSamplePreferenceController(mContext,
mLifecycle, mBluetoothA2dpConfigStore));
mListValues = mController.getListValues();
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothAudioChannelModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothAudioChannelModePreferenceControllerTest.java
index c4dcc19..fd7b096 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothAudioChannelModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothAudioChannelModePreferenceControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.bluetooth.BluetoothCodecConfig;
import android.content.Context;
import android.support.v7.preference.ListPreference;
@@ -60,13 +61,15 @@
private String[] mListValues;
private Context mContext;
private BluetoothAudioChannelModePreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new BluetoothAudioChannelModePreferenceController(mContext,
mLifecycle, mBluetoothA2dpConfigStore));
mListValues = mController.getListValues();
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothAudioCodecPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothAudioCodecPreferenceControllerTest.java
index 29d8047..43bf3ea 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothAudioCodecPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothAudioCodecPreferenceControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.bluetooth.BluetoothCodecConfig;
import android.content.Context;
import android.support.v7.preference.ListPreference;
@@ -65,13 +66,15 @@
private String[] mListValues;
private Context mContext;
private BluetoothAudioCodecPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new BluetoothAudioCodecPreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore));
mListValues = mController.getListValues();
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothAudioQualityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothAudioQualityPreferenceControllerTest.java
index e76f1d0..1aff160 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothAudioQualityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothAudioQualityPreferenceControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.bluetooth.BluetoothCodecConfig;
import android.content.Context;
import android.support.v7.preference.ListPreference;
@@ -60,13 +61,15 @@
private String[] mListValues;
private Context mContext;
private BluetoothAudioQualityPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new BluetoothAudioQualityPreferenceController(mContext,
mLifecycle, mBluetoothA2dpConfigStore));
mListValues = mController.getListValues();
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothAudioSampleRatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothAudioSampleRatePreferenceControllerTest.java
index 4c113b1..3eab359 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothAudioSampleRatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothAudioSampleRatePreferenceControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.bluetooth.BluetoothCodecConfig;
import android.content.Context;
import android.support.v7.preference.ListPreference;
@@ -60,6 +61,7 @@
* 4: 96.0 kHz
*/
private String[] mListValues;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private Context mContext;
private BluetoothAudioSampleRatePreferenceController mController;
@@ -68,7 +70,8 @@
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new BluetoothAudioSampleRatePreferenceController(mContext, mLifecycle,
mBluetoothA2dpConfigStore));
mListValues = mController.getListValues();
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java
index bfe30fb..a5dfa56 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSwitchBarControllerTest.java
@@ -23,6 +23,7 @@
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import com.android.settings.TestConfig;
@@ -53,6 +54,7 @@
@Mock
private DevelopmentSettingsDashboardFragment mSettings;
private Context mContext;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private SwitchBar mSwitchBar;
private DevelopmentSwitchBarController mController;
@@ -61,7 +63,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mSwitchBar = new SwitchBar(mContext);
when(mSettings.getContext()).thenReturn(mContext);
}
diff --git a/tests/robotests/src/com/android/settings/development/HardwareOverlaysPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/HardwareOverlaysPreferenceControllerTest.java
index 09e48d3..8522b99 100644
--- a/tests/robotests/src/com/android/settings/development/HardwareOverlaysPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/HardwareOverlaysPreferenceControllerTest.java
@@ -37,6 +37,7 @@
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowParcel;
import org.junit.Before;
import org.junit.Test;
diff --git a/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerTest.java
index 1dc1255..57978a6 100644
--- a/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.SystemProperties;
import android.support.v7.preference.ListPreference;
@@ -53,13 +54,15 @@
private Context mContext;
private LogPersistPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new LogPersistPreferenceController(mContext, mFragment, mLifecycle);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
SystemProperties.set("ro.debuggable", "1");
diff --git a/tests/robotests/src/com/android/settings/development/PictureColorModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/PictureColorModePreferenceControllerTest.java
index fac74ac..8a7198d 100644
--- a/tests/robotests/src/com/android/settings/development/PictureColorModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/PictureColorModePreferenceControllerTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.preference.PreferenceScreen;
@@ -55,13 +56,15 @@
@Mock
private Resources mResources;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private PictureColorModePreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new PictureColorModePreferenceController(mContext, mLifecycle);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
mPreference);
diff --git a/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java
index 6b55984..8719bb4 100644
--- a/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java
@@ -33,6 +33,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.usb.UsbManager;
@@ -70,6 +71,7 @@
private PackageManager mPackageManager;
private Context mContext;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private SelectUsbConfigPreferenceController mController;
@@ -89,7 +91,8 @@
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUsbManager).when(mContext).getSystemService(Context.USB_SERVICE);
doReturn(mPackageManager).when(mContext).getPackageManager();
diff --git a/tests/robotests/src/com/android/settings/development/ShadowParcel.java b/tests/robotests/src/com/android/settings/development/ShadowParcel.java
deleted file mode 100644
index 965c959..0000000
--- a/tests/robotests/src/com/android/settings/development/ShadowParcel.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.android.settings.development;
-
-import android.os.Parcel;
-
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-
-/**
- * This class provides helpers to test logic that reads from parcels.
- */
-@Implements(Parcel.class)
-public class ShadowParcel {
-
- static int sReadIntResult;
-
- @Implementation
- public int readInt() {
- return sReadIntResult;
- }
-}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java
index a5cfa22..32768b6 100644
--- a/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java
@@ -37,6 +37,7 @@
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowParcel;
import org.junit.Before;
import org.junit.Test;
diff --git a/tests/robotests/src/com/android/settings/development/featureflags/FeatureFlagPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/featureflags/FeatureFlagPreferenceControllerTest.java
index f831506..8c38d22 100644
--- a/tests/robotests/src/com/android/settings/development/featureflags/FeatureFlagPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/featureflags/FeatureFlagPreferenceControllerTest.java
@@ -25,6 +25,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.support.v7.preference.PreferenceScreen;
@@ -47,6 +48,7 @@
@Mock
private PreferenceScreen mScreen;
private Context mContext;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private FeatureFlagsPreferenceController mController;
@@ -54,7 +56,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new FeatureFlagsPreferenceController(mContext, mLifecycle);
when(mScreen.getContext()).thenReturn(mContext);
mController.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/development/qstile/LayerTraceTest.java b/tests/robotests/src/com/android/settings/development/qstile/LayerTraceTest.java
new file mode 100644
index 0000000..594b96c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/qstile/LayerTraceTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development.qstile;
+
+import static com.android.settings.development.qstile.DevelopmentTiles.LayerTrace
+ .SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE;
+import static com.android.settings.development.qstile.DevelopmentTiles.LayerTrace
+ .SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+import android.os.IBinder;
+import android.os.RemoteException;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.ShadowParcel;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LayerTraceTest {
+ @Mock
+ private IBinder mSurfaceFlinger;
+
+ private DevelopmentTiles.LayerTrace mLayerTraceTile;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mLayerTraceTile = spy(new DevelopmentTiles.LayerTrace());
+ mLayerTraceTile.onCreate();
+ ReflectionHelpers.setField(mLayerTraceTile, "mSurfaceFlinger", mSurfaceFlinger);
+ }
+
+ @After
+ public void after() {
+ verifyNoMoreInteractions(mSurfaceFlinger);
+ }
+
+ @Test
+ @Config(shadows = {ShadowParcel.class})
+ public void sfReturnsTraceEnabled_shouldReturnEnabled() throws RemoteException {
+ ShadowParcel.sReadBoolResult = true;
+ assertThat(mLayerTraceTile.isEnabled()).isTrue();
+ verify(mSurfaceFlinger)
+ .transact(eq(SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE), any(), any(),
+ eq(0 /* flags */));
+ }
+
+ @Test
+ @Config(shadows = {ShadowParcel.class})
+ public void sfReturnsTraceDisabled_shouldReturnDisabled() throws RemoteException {
+ ShadowParcel.sReadBoolResult = false;
+ assertThat(mLayerTraceTile.isEnabled()).isFalse();
+ verify(mSurfaceFlinger)
+ .transact(eq(SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE), any(), any(),
+ eq(0 /* flags */));
+ }
+
+ @Test
+ public void sfUnavailable_shouldReturnDisabled() throws RemoteException {
+ ReflectionHelpers.setField(mLayerTraceTile, "mSurfaceFlinger", null);
+ assertThat(mLayerTraceTile.isEnabled()).isFalse();
+ }
+
+ @Test
+ @Config(shadows = {ShadowParcel.class})
+ public void setIsEnableTrue_shouldEnableLayerTrace() throws RemoteException {
+ mLayerTraceTile.setIsEnabled(true);
+ assertThat(ShadowParcel.sWriteIntResult).isEqualTo(1);
+ verify(mSurfaceFlinger)
+ .transact(eq(SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE), any(), isNull(),
+ eq(0 /* flags */));
+ }
+
+ @Test
+ @Config(shadows = {ShadowParcel.class})
+ public void setIsEnableFalse_shouldDisableLayerTrace() throws RemoteException {
+ mLayerTraceTile.setIsEnabled(false);
+ assertThat(ShadowParcel.sWriteIntResult).isEqualTo(0);
+ verify(mSurfaceFlinger)
+ .transact(eq(SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE), any(), isNull(),
+ eq(0 /* flags */));
+ }
+
+ @Test
+ public void setIsEnableAndSfUnavailable_shouldDoNothing() throws RemoteException {
+ ReflectionHelpers.setField(mLayerTraceTile, "mSurfaceFlinger", null);
+ mLayerTraceTile.setIsEnabled(true);
+ mLayerTraceTile.setIsEnabled(false);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/qstile/WindowTraceTest.java b/tests/robotests/src/com/android/settings/development/qstile/WindowTraceTest.java
new file mode 100644
index 0000000..3c4d9ba
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/qstile/WindowTraceTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development.qstile;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+import android.os.RemoteException;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.ShadowParcel;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.wrapper.IWindowManagerWrapper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WindowTraceTest {
+ @Mock
+ private IWindowManagerWrapper mWindowManager;
+
+ private DevelopmentTiles.WindowTrace mWindowTrace;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mWindowTrace = spy(new DevelopmentTiles.WindowTrace());
+ mWindowTrace.onCreate();
+ ReflectionHelpers.setField(mWindowTrace, "mWindowManager", mWindowManager);
+ }
+
+ @Test
+ public void wmReturnsTraceEnabled_shouldReturnEnabled() throws RemoteException {
+ doReturn(true).when(mWindowManager).isWindowTraceEnabled();
+ assertThat(mWindowTrace.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void wmReturnsTraceDisabled_shouldReturnDisabled() throws RemoteException {
+ doReturn(false).when(mWindowManager).isWindowTraceEnabled();
+ assertThat(mWindowTrace.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void wmThrowsRemoteException_shouldReturnDisabled() throws RemoteException {
+ doThrow(new RemoteException("Unknown"))
+ .when(mWindowManager).isWindowTraceEnabled();
+ assertThat(mWindowTrace.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void setIsEnableTrue_shouldEnableWindowTrace() throws RemoteException {
+ mWindowTrace.setIsEnabled(true);
+ verify(mWindowManager).startWindowTrace();
+ verifyNoMoreInteractions(mWindowManager);
+ }
+
+ @Test
+ @Config(shadows = {ShadowParcel.class})
+ public void setIsEnableFalse_shouldDisableWindowTrace() throws RemoteException {
+ mWindowTrace.setIsEnabled(false);
+ verify(mWindowManager).stopWindowTrace();
+ verifyNoMoreInteractions(mWindowManager);
+ }
+
+ @Test
+ public void setIsEnableAndWmThrowsRemoteException_shouldDoNothing() throws RemoteException {
+ doThrow(new RemoteException("Unknown")).when(mWindowManager).isWindowTraceEnabled();
+ mWindowTrace.setIsEnabled(true);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
index ab68c17..ee5d5d0 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
@@ -28,6 +28,7 @@
import android.app.Activity;
import android.app.Fragment;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.Build;
import android.os.UserManager;
@@ -74,6 +75,7 @@
@Mock
private UserManager mUserManager;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private FakeFeatureFactory mFactory;
private Preference mPreference;
@@ -83,7 +85,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
mController = new BuildNumberPreferenceController(
mContext, mActivity, mFragment, mLifecycle);
diff --git a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java b/tests/robotests/src/com/android/settings/deviceinfo/DeviceInfoSettingsTest.java
similarity index 89%
rename from tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
rename to tests/robotests/src/com/android/settings/deviceinfo/DeviceInfoSettingsTest.java
index 09ff9db..7555d8e 100644
--- a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/DeviceInfoSettingsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 The Android Open Source Project
+ * Copyright (C) 2018 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.
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-package com.android.settings;
+package com.android.settings.deviceinfo;
-import static com.android.settings.DeviceInfoSettings.NON_SIM_PREFERENCES_COUNT;
-import static com.android.settings.DeviceInfoSettings.SIM_PREFERENCES_COUNT;
import static com.android.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
+import static com.android.settings.deviceinfo.DeviceInfoSettings.NON_SIM_PREFERENCES_COUNT;
+import static com.android.settings.deviceinfo.DeviceInfoSettings.SIM_PREFERENCES_COUNT;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
@@ -33,6 +33,8 @@
import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -51,6 +53,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
import java.util.List;
@@ -82,12 +85,14 @@
mSettings = spy(new DeviceInfoSettings());
doReturn(mActivity).when(mSettings).getActivity();
+ doReturn(mContext).when(mSettings).getContext();
doReturn(mContext.getTheme()).when(mActivity).getTheme();
doReturn(mContext.getResources()).when(mSettings).getResources();
doNothing().when(mSettings).onCreatePreferences(any(), any());
doReturn(mScreen).when(mSettings).getPreferenceScreen();
- doReturn(mTelephonyManager).when(mSettings).getSystemService(Context.TELEPHONY_SERVICE);
+ ShadowApplication.getInstance().setSystemService(Context.TELEPHONY_SERVICE,
+ mTelephonyManager);
}
@Test
@@ -95,7 +100,7 @@
SettingsShadowSystemProperties.class
})
public void getPrefXml_shouldReturnDeviceInfoXml() {
- assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.device_info_settings_v2);
+ assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.device_info_settings);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerTest.java
similarity index 93%
rename from tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerTest.java
index 5fa8a91..b3440f4 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerTest.java
@@ -44,7 +44,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class FirmwareVersionPreferenceControllerV2Test {
+public class FirmwareVersionPreferenceControllerTest {
@Mock
private Preference mPreference;
@@ -54,13 +54,13 @@
private Fragment mFragment;
private Context mContext;
- private FirmwareVersionPreferenceControllerV2 mController;
+ private FirmwareVersionPreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mController = new FirmwareVersionPreferenceControllerV2(mContext, mFragment);
+ mController = new FirmwareVersionPreferenceController(mContext, mFragment);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java
similarity index 96%
rename from tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java
index 186d9b7..610ccfd 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerTest.java
@@ -50,7 +50,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class ImeiInfoPreferenceControllerV2Test {
+public class ImeiInfoPreferenceControllerTest {
@Mock
private Preference mPreference;
@@ -66,14 +66,14 @@
private Fragment mFragment;
private Context mContext;
- private ImeiInfoPreferenceControllerV2 mController;
+ private ImeiInfoPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
- mController = spy(new ImeiInfoPreferenceControllerV2(mContext, mFragment));
+ mController = spy(new ImeiInfoPreferenceController(mContext, mFragment));
doReturn(true).when(mController).isAvailable();
when(mScreen.getContext()).thenReturn(mContext);
doReturn(mSecondSimPreference).when(mController).createNewPreference(mContext);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
index 2f896ac..cea4580 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
@@ -47,6 +47,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
@@ -94,6 +95,7 @@
private SimStatusDialogController mController;
private Context mContext;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
@@ -101,7 +103,8 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
when(mDialog.getContext()).thenReturn(mContext);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(
new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */));
doReturn(mServiceState).when(mController).getCurrentServiceState();
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerTest.java
similarity index 95%
rename from tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerTest.java
index 8e9cb0b..1419304 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusPreferenceControllerTest.java
@@ -47,7 +47,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class SimStatusPreferenceControllerV2Test {
+public class SimStatusPreferenceControllerTest {
@Mock
private Preference mPreference;
@@ -63,14 +63,14 @@
private Fragment mFragment;
private Context mContext;
- private SimStatusPreferenceControllerV2 mController;
+ private SimStatusPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
- mController = spy(new SimStatusPreferenceControllerV2(mContext, mFragment));
+ mController = spy(new SimStatusPreferenceController(mContext, mFragment));
doReturn(true).when(mController).isAvailable();
when(mScreen.getContext()).thenReturn(mContext);
doReturn(mSecondSimPreference).when(mController).createNewPreference(mContext);
diff --git a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
index f3a1edd..affb40b 100644
--- a/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoRotatePreferenceControllerTest.java
@@ -21,6 +21,7 @@
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -56,6 +57,7 @@
private Context mContext;
@Mock
private PackageManager mPackageManager;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private SwitchPreference mPreference;
private ContentResolver mContentResolver;
@@ -66,7 +68,8 @@
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
mContentResolver = RuntimeEnvironment.application.getContentResolver();
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mPreference = new SwitchPreference(RuntimeEnvironment.application);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getContentResolver()).thenReturn(mContentResolver);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
index 9276424..58bc14b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
@@ -30,6 +30,7 @@
import static org.mockito.Mockito.when;
import android.app.Activity;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
@@ -89,13 +90,15 @@
private TextView mSummary2;
private LayoutPreference mBatteryLayoutPref;
private Intent mBatteryIntent;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mContext = spy(RuntimeEnvironment.application);
mBatteryMeterView = new BatteryMeterView(mContext);
mBatteryPercentText = new TextView(mContext);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
index 9f0c61f..b4149c1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
@@ -15,6 +15,9 @@
*/
package com.android.settings.fuelgauge.batterytip;
+import static com.android.settings.fuelgauge.batterytip.tips.BatteryTip.TipType
+ .SMART_BATTERY_MANAGER;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
@@ -29,6 +32,7 @@
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
@@ -57,6 +61,8 @@
private PreferenceScreen mPreferenceScreen;
@Mock
private BatteryTip mBatteryTip;
+ @Mock
+ private SettingsActivity mSettingsActivity;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceManager mPreferenceManager;
@@ -85,7 +91,7 @@
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE));
mBatteryTipPreferenceController = new BatteryTipPreferenceController(mContext, KEY_PREF,
- null, mBatteryTipListener);
+ mSettingsActivity, null, mBatteryTipListener);
mBatteryTipPreferenceController.mPreferenceGroup = mPreferenceGroup;
mBatteryTipPreferenceController.mPrefContext = mContext;
}
@@ -109,7 +115,8 @@
}
@Test
- public void testHandlePreferenceTreeClick_noDialog_invokeAction() {
+ public void testHandlePreferenceTreeClick_noDialog_invokeCallback() {
+ doReturn(SMART_BATTERY_MANAGER).when(mBatteryTip).getType();
List<BatteryTip> batteryTips = new ArrayList<>();
batteryTips.add(mBatteryTip);
doReturn(mPreference).when(mBatteryTip).buildPreference(any());
@@ -119,7 +126,7 @@
mBatteryTipPreferenceController.handlePreferenceTreeClick(mPreference);
- verify(mBatteryTip).action();
+ verify(mBatteryTipListener).onBatteryTipHandled(mBatteryTip);
}
private void assertOnlyContainsSummaryTip(final PreferenceGroup preferenceGroup) {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetectorTest.java
new file mode 100644
index 0000000..8400d89
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetectorTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 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.fuelgauge.batterytip.detectors;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.TestConfig;
+import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SmartBatteryDetectorTest {
+ private Context mContext;
+ private BatteryTipPolicy mPolicy;
+ private SmartBatteryDetector mSmartBatteryDetector;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mPolicy = spy(new BatteryTipPolicy(mContext));
+ mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContext.getContentResolver());
+ }
+
+ @Test
+ public void testDetect_smartBatteryOff_tipVisible() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.APP_STANDBY_ENABLED, 0);
+
+ assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
+ }
+
+ @Test
+ public void testDetect_smartBatteryOn_tipInvisible() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.APP_STANDBY_ENABLED, 1);
+
+ assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
index 1c6c868..6efd5d3 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
@@ -107,11 +107,6 @@
// do nothing
}
- @Override
- public void action() {
- // do nothing
- }
-
public final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public BatteryTip createFromParcel(Parcel in) {
return new TestBatteryTip(in);
diff --git a/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java b/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
index 1e50770..462b926 100644
--- a/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
@@ -30,6 +30,7 @@
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.Intent;
import android.content.pm.UserInfo;
@@ -66,6 +67,7 @@
private Context mContext;
private LocationEnabler mEnabler;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
@@ -73,7 +75,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mEnabler = spy(new LocationEnabler(mContext, mListener, mLifecycle));
}
diff --git a/tests/robotests/src/com/android/settings/location/LocationForWorkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationForWorkPreferenceControllerTest.java
index 97fdb83..5b2455f 100644
--- a/tests/robotests/src/com/android/settings/location/LocationForWorkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationForWorkPreferenceControllerTest.java
@@ -25,6 +25,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.pm.UserInfo;
import android.os.UserHandle;
@@ -68,6 +69,7 @@
private Context mContext;
private LocationForWorkPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
@@ -75,7 +77,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new LocationForWorkPreferenceController(mContext, mLifecycle));
mockManagedProfile();
ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler);
diff --git a/tests/robotests/src/com/android/settings/location/LocationModeBatterySavingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationModeBatterySavingPreferenceControllerTest.java
index aa05cc6..41e9f1e 100644
--- a/tests/robotests/src/com/android/settings/location/LocationModeBatterySavingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationModeBatterySavingPreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static org.mockito.Mockito.mock;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
@@ -35,11 +36,13 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationModeBatterySavingPreferenceControllerTest {
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/location/LocationModeHighAccuracyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationModeHighAccuracyPreferenceControllerTest.java
index fd1bb02..9c8bac6 100644
--- a/tests/robotests/src/com/android/settings/location/LocationModeHighAccuracyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationModeHighAccuracyPreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static org.mockito.Mockito.mock;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
@@ -35,11 +36,13 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationModeHighAccuracyPreferenceControllerTest {
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/location/LocationModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationModePreferenceControllerTest.java
index 5383ed3..a28cb20 100644
--- a/tests/robotests/src/com/android/settings/location/LocationModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationModePreferenceControllerTest.java
@@ -24,6 +24,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.UserManager;
import android.provider.Settings;
@@ -61,6 +62,7 @@
private Context mContext;
private LocationModePreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
@@ -68,7 +70,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new LocationModePreferenceController(mContext, mFragment, mLifecycle);
when(mFragment.getActivity()).thenReturn(mActivity);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
diff --git a/tests/robotests/src/com/android/settings/location/LocationModeRadioButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationModeRadioButtonPreferenceControllerTest.java
index ae98acc..2766788 100644
--- a/tests/robotests/src/com/android/settings/location/LocationModeRadioButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationModeRadioButtonPreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.PreferenceScreen;
@@ -49,13 +50,15 @@
private Context mContext;
private LocationModeRadioButtonPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new LocationModeRadioButtonPreferenceControllerTestable(mContext, mLifecycle);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
diff --git a/tests/robotests/src/com/android/settings/location/LocationModeSensorsOnlyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationModeSensorsOnlyPreferenceControllerTest.java
index 8561c97..4ed75d2 100644
--- a/tests/robotests/src/com/android/settings/location/LocationModeSensorsOnlyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationModeSensorsOnlyPreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static org.mockito.Mockito.mock;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
@@ -35,11 +36,13 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LocationModeSensorsOnlyPreferenceControllerTest {
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
index fe45a93..2c92b44 100644
--- a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
@@ -25,6 +25,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -62,6 +63,7 @@
@Mock
private PreferenceScreen mScreen;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private LocationPreferenceController mController;
@@ -71,7 +73,8 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new LocationPreferenceController(mContext, mLifecycle);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
diff --git a/tests/robotests/src/com/android/settings/location/LocationScanningPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationScanningPreferenceControllerTest.java
new file mode 100644
index 0000000..7577ac1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/location/LocationScanningPreferenceControllerTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2018 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.location;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LocationScanningPreferenceControllerTest {
+
+ private Context mContext;
+ private LocationScanningPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+ mController = new LocationScanningPreferenceController(mContext);
+ }
+
+ @Test
+ public void testLocationScanning_byDefault_shouldBeShown() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void testLocationScanning_ifDisabled_shouldNotBeShown() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/location/LocationServicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationServicePreferenceControllerTest.java
index caf15f8..51a375e 100644
--- a/tests/robotests/src/com/android/settings/location/LocationServicePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationServicePreferenceControllerTest.java
@@ -25,6 +25,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
@@ -62,13 +63,15 @@
private Context mContext;
private LocationServicePreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new LocationServicePreferenceController(
mContext, mFragment, mLifecycle, mSettingsInjector));
final String key = mController.getPreferenceKey();
diff --git a/tests/robotests/src/com/android/settings/location/LocationSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationSwitchBarControllerTest.java
index 35c0f82..6d824ac 100644
--- a/tests/robotests/src/com/android/settings/location/LocationSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationSwitchBarControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.provider.Settings;
@@ -54,6 +55,7 @@
private Context mContext;
private LocationSwitchBarController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
@@ -61,7 +63,8 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
ReflectionHelpers.setField(mSwitchBar, "mSwitch", mSwitch);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new LocationSwitchBarController(
mContext, mSwitchBar, mLifecycle));
ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler);
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
index a9794c2..f114ff3 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
@@ -25,6 +25,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
@@ -33,6 +34,7 @@
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
+
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
@@ -44,8 +46,7 @@
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.location.RecentLocationApps.Request;
-import java.util.ArrayList;
-import java.util.List;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,6 +58,9 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import java.util.ArrayList;
+import java.util.List;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RecentLocationRequestPreferenceControllerTest {
@@ -72,13 +76,15 @@
private Context mContext;
private RecentLocationRequestPreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new RecentLocationRequestPreferenceController(
mContext, mFragment, mLifecycle, mRecentLocationApps));
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mCategory);
diff --git a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
index 9dea6f5..b1072b1 100644
--- a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
@@ -21,6 +21,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
@@ -56,6 +57,7 @@
private PackageManager mPackageManager;
private AirplaneModePreferenceController mController;
+ private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
private FakeFeatureFactory mFactory;
@@ -66,7 +68,8 @@
doReturn(mResources).when(mContext).getResources();
doReturn(mPackageManager).when(mContext).getPackageManager();
mController = spy(new AirplaneModePreferenceController(mContext, null));
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mLifecycle.addObserver(mController);
}
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
index d593b58..f070f7a 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
@@ -27,6 +27,7 @@
import static org.mockito.Mockito.when;
import static org.robolectric.shadow.api.Shadow.extract;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.UserManager;
@@ -66,13 +67,15 @@
private PreferenceScreen mScreen;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private MobileNetworkPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE))
.thenReturn(mTelephonyManager);
}
diff --git a/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
index c35f1cf..d030531 100644
--- a/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
@@ -27,6 +27,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
@@ -65,6 +66,7 @@
private Preference mPreference;
private VpnPreferenceController mController;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
@Before
public void setUp() {
@@ -77,7 +79,8 @@
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mController = spy(new VpnPreferenceController(mContext));
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mLifecycle.addObserver(mController);
}
diff --git a/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
index 7b0b033..b2fbb00 100644
--- a/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
@@ -27,9 +27,12 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -37,19 +40,25 @@
public class AlarmVolumePreferenceControllerTest {
@Mock
- private Context mContext;
- @Mock
private AudioHelper mHelper;
+ private Context mContext;
private AlarmVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
mController = new AlarmVolumePreferenceController(mContext, null, null, mHelper);
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void isAvailable_singleVolume_shouldReturnFalse() {
when(mHelper.isSingleVolume()).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
index 2b2d024..c24f02e 100644
--- a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
@@ -31,11 +31,13 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -50,15 +52,15 @@
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
- @Mock
- private Context mContext;
+ private Context mContext;
private ChargingSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
@@ -68,11 +70,17 @@
}
@Test
- public void isAvailable_isAlwaysTrue() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void displayPreference_chargingSoundEnabled_shouldCheckedPreference() {
Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1);
diff --git a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
index ca7fc44..688575a 100644
--- a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
@@ -27,31 +27,39 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.spy;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class MediaVolumePreferenceControllerTest {
- @Mock
private Context mContext;
-
private MediaVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
mController = new MediaVolumePreferenceController(mContext, null, null);
}
@Test
- public void isAlwaysAvailable() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void getAudioStream_shouldReturnMusic() {
assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_MUSIC);
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
index 940a948..f712ec8 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
@@ -27,25 +27,39 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.spy;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationRingtonePreferenceControllerTest {
- @Mock
private Context mContext;
private NotificationRingtonePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
mController = new NotificationRingtonePreferenceController(mContext);
}
@Test
+ public void isAvailable_byDefault_isTrue() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void getRingtoneType_shouldReturnNotification() {
assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_NOTIFICATION);
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
index f919e7b..131fb18 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
@@ -29,9 +29,12 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -39,8 +42,6 @@
public class NotificationVolumePreferenceControllerTest {
@Mock
- private Context mContext;
- @Mock
private AudioHelper mHelper;
@Mock
private TelephonyManager mTelephonyManager;
@@ -49,11 +50,13 @@
@Mock
private Vibrator mVibrator;
+ private Context mContext;
private NotificationVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
@@ -61,6 +64,12 @@
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_shouldReturnFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void isAvailable_singleVolume_shouldReturnFalse() {
when(mHelper.isSingleVolume()).thenReturn(true);
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
diff --git a/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
index f94f8bf..e6a8718 100644
--- a/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
@@ -31,11 +31,13 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -50,15 +52,15 @@
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
- @Mock
- private Context mContext;
+ private Context mContext;
private ScreenLockSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
@@ -68,11 +70,17 @@
}
@Test
- public void isAvailable_isAlwaysTrue() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void displayPreference_lockScreenSoundEnabled_shouldCheckedPreference() {
System.putInt(mContentResolver, System.LOCKSCREEN_SOUNDS_ENABLED, 1);
diff --git a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
index 9025979..33d5073 100644
--- a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
@@ -20,14 +20,11 @@
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
-
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
-
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -50,8 +47,10 @@
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.RestrictedLockUtils;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -62,7 +61,9 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+ SettingsShadowResources.class
+})
public class SoundPreferenceControllerTest {
private Context mContext;
@@ -87,11 +88,18 @@
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ SettingsShadowResources.overrideResource(com.android.internal.R.string.ringtone_silent,
+ "silent");
mContext = shadowApplication.getApplicationContext();
mController = spy(new SoundPreferenceController(
mContext, mFragment, mImportanceListener, mBackend));
}
+ @After
+ public void tearDown() {
+ SettingsShadowResources.reset();
+ }
+
@Test
public void testNoCrashIfNoOnResume() throws Exception {
mController.isAvailable();
diff --git a/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
index eaf9bb5..d9145ff 100644
--- a/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
@@ -32,11 +32,13 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -54,15 +56,15 @@
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
- @Mock
- private Context mContext;
+ private Context mContext;
private TouchSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mActivity.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
@@ -73,11 +75,17 @@
}
@Test
- public void isAvailable_isAlwaysTrue() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void displayPreference_soundEffectEnabled_shouldCheckedPreference() {
System.putInt(mContentResolver, System.SOUND_EFFECTS_ENABLED, 1);
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeCallsPreferenceControllerTest.java
index 21eea0e..18f9e71 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeCallsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeCallsPreferenceControllerTest.java
@@ -21,9 +21,6 @@
import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
-import static junit.framework.Assert.assertEquals;
-
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -32,7 +29,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
-import android.support.v7.preference.Preference;
+import android.support.v7.preference.ListPreference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
@@ -45,9 +42,9 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -60,7 +57,7 @@
@Mock
private NotificationManager mNotificationManager;
@Mock
- private Preference mockPref;
+ private ListPreference mockPref;
@Mock
private NotificationManager.Policy mPolicy;
@Mock
@@ -68,6 +65,15 @@
private ContentResolver mContentResolver;
private Context mContext;
+ /**
+ * Array Values Key
+ * 0: anyone
+ * 1: contacts
+ * 2: starred
+ * 3: none
+ */
+ private String[] mValues;
+
private final boolean CALLS_SETTINGS = true;
private final int MOCK_CALLS_SENDERS = NotificationManager.Policy.PRIORITY_SENDERS_STARRED;
private final int SUMMARY_ID_MOCK_CALLS_SENDERS = R.string.zen_mode_from_starred;
@@ -79,8 +85,11 @@
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = shadowApplication.getApplicationContext();
+ mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ when(mBackend.getPriorityCallSenders()).thenReturn(MOCK_CALLS_SENDERS);
when(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE))
.thenCallRealMethod();
when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
@@ -97,10 +106,11 @@
@Test
public void updateState_TotalSilence() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
+
when(mBackend.isPriorityCategoryEnabled(
- NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
+ NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
.thenReturn(false);
- final Preference mockPref = mock(Preference.class);
+ final ListPreference mockPref = mock(ListPreference.class);
mController.updateState(mockPref);
verify(mockPref).setEnabled(false);
@@ -111,7 +121,7 @@
public void updateState_AlarmsOnly() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
- final Preference mockPref = mock(Preference.class);
+ final ListPreference mockPref = mock(ListPreference.class);
mController.updateState(mockPref);
verify(mockPref).setEnabled(false);
@@ -121,14 +131,53 @@
@Test
public void updateState_Priority() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+
when(mBackend.isPriorityCategoryEnabled(
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
.thenReturn(CALLS_SETTINGS);
- when(mBackend.getPriorityCallSenders()).thenReturn(MOCK_CALLS_SENDERS);
mController.updateState(mockPref);
verify(mockPref).setEnabled(true);
verify(mockPref).setSummary(SUMMARY_ID_MOCK_CALLS_SENDERS);
}
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_any() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_ANY);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_ANYONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_none() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(ZenModeBackend.SOURCE_NONE);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_NONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_starred() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_STARRED)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_contacts() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_CONTACTS)]);
+ }
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
deleted file mode 100644
index 8ed0075..0000000
--- a/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.Activity;
-import android.app.NotificationManager;
-import android.content.Context;
-import android.os.UserManager;
-import android.provider.Settings;
-
-import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class ZenModeCallsTest {
- private ZenModeCallsSettings mCalls;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ZenModeBackend mBackend;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Activity mActivity;
- @Mock
- private UserManager mUserManager;
- @Mock
- private NotificationManager mNotificationManager;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- when(mActivity.getSystemService(Context.NOTIFICATION_SERVICE))
- .thenReturn(mNotificationManager);
- FakeFeatureFactory.setupForTest();
-
- mCalls = new ZenModeCallsSettings();
- mCalls.onAttach((Context)mActivity);
-
- ReflectionHelpers.setField(mCalls, "mBackend", mBackend);
- }
-
- @Test
- public void getDefaultKeyReturnsBasedOnZen() {
- when(mBackend.getSendersKey(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
- .thenCallRealMethod();
- when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_NO_INTERRUPTIONS);
- assertThat(mCalls.getDefaultKey())
- .isEqualTo(mBackend.getKeyFromSetting(mBackend.SOURCE_NONE));
-
- when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_ALARMS);
- assertThat(mCalls.getDefaultKey())
- .isEqualTo(mBackend.getKeyFromSetting(mBackend.SOURCE_NONE));
-
- when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.isPriorityCategoryEnabled(
- NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
- .thenReturn(true);
- when(mBackend.getPriorityMessageSenders())
- .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
- assertThat(mCalls.getDefaultKey())
- .isEqualTo(mBackend.getKeyFromSetting(
- NotificationManager.Policy.PRIORITY_SENDERS_ANY));
- }
-
- @Test
- public void setAnySender() {
- String key = mBackend.getKeyFromSetting(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
- mCalls.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
- mBackend.getSettingFromPrefKey(key));
- }
-
- @Test
- public void setNoSender() {
- String key = mBackend.getKeyFromSetting(ZenModeBackend.SOURCE_NONE);
- mCalls.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
- mBackend.getSettingFromPrefKey(key));
- }
-
- @Test
- public void setStarredSenders() {
- String key = mBackend.getKeyFromSetting(
- NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
- mCalls.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
- mBackend.getSettingFromPrefKey(key));
- }
-
- @Test
- public void setContactsOnlySenders() {
- String key = mBackend.getKeyFromSetting(
- NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
- mCalls.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
- mBackend.getSettingFromPrefKey(key));
- }
-}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.java
index 9625623..460534e 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.java
@@ -21,9 +21,6 @@
import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
-import static junit.framework.Assert.assertEquals;
-
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -32,6 +29,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
+import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -45,9 +43,9 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -60,7 +58,7 @@
@Mock
private NotificationManager mNotificationManager;
@Mock
- private Preference mockPref;
+ private ListPreference mockPref;
@Mock
private NotificationManager.Policy mPolicy;
@Mock
@@ -68,6 +66,15 @@
private ContentResolver mContentResolver;
private Context mContext;
+ /**
+ * Array Values Key
+ * 0: anyone
+ * 1: contacts
+ * 2: starred
+ * 3: none
+ */
+ private String[] mValues;
+
private final boolean MESSAGES_SETTINGS = true;
private final int MOCK_MESSAGES_SENDERS = NotificationManager.Policy.PRIORITY_SENDERS_STARRED;
private final int SUMMARY_ID_MOCK_MESSAGES_SENDERS = R.string.zen_mode_from_starred;
@@ -79,6 +86,7 @@
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = shadowApplication.getApplicationContext();
+ mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
@@ -103,7 +111,7 @@
when(mBackend.isPriorityCategoryEnabled(
NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
.thenReturn(false);
- final Preference mockPref = mock(Preference.class);
+ final ListPreference mockPref = mock(ListPreference.class);
mController.updateState(mockPref);
verify(mockPref).setEnabled(false);
@@ -114,7 +122,7 @@
public void updateState_AlarmsOnly() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
- final Preference mockPref = mock(Preference.class);
+ final ListPreference mockPref = mock(ListPreference.class);
mController.updateState(mockPref);
verify(mockPref).setEnabled(false);
@@ -134,4 +142,43 @@
verify(mockPref).setEnabled(true);
verify(mockPref).setSummary(SUMMARY_ID_MOCK_MESSAGES_SENDERS);
}
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_any() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_ANY);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_ANYONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_none() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(ZenModeBackend.SOURCE_NONE);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_NONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_starred() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_STARRED)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_contacts() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_CONTACTS)]);
+ }
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
deleted file mode 100644
index 181a238..0000000
--- a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.Activity;
-import android.app.NotificationManager;
-import android.content.Context;
-import android.os.UserManager;
-import android.provider.Settings;
-
-import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class ZenModeMessagesTest {
- private ZenModeMessagesSettings mMessages;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ZenModeBackend mBackend;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Activity mActivity;
- @Mock
- private UserManager mUserManager;
- @Mock
- private NotificationManager mNotificationManager;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- when(mActivity.getSystemService(Context.NOTIFICATION_SERVICE))
- .thenReturn(mNotificationManager);
- FakeFeatureFactory.setupForTest();
-
- mMessages = new ZenModeMessagesSettings();
- mMessages.onAttach((Context)mActivity);
-
- ReflectionHelpers.setField(mMessages, "mBackend", mBackend);
- }
-
- @Test
- public void getDefaultKeyReturnsBasedOnZen() {
- when(mBackend.getSendersKey(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
- .thenCallRealMethod();
- when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_NO_INTERRUPTIONS);
- assertThat(mMessages.getDefaultKey())
- .isEqualTo(mBackend.getKeyFromSetting(mBackend.SOURCE_NONE));
-
- when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_ALARMS);
- assertThat(mMessages.getDefaultKey())
- .isEqualTo(mBackend.getKeyFromSetting(mBackend.SOURCE_NONE));
-
- when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.isPriorityCategoryEnabled(
- NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
- .thenReturn(true);
- when(mBackend.getPriorityMessageSenders())
- .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
- assertThat(mMessages.getDefaultKey())
- .isEqualTo(mBackend.getKeyFromSetting(
- NotificationManager.Policy.PRIORITY_SENDERS_ANY));
- }
-
- @Test
- public void setAnySender() {
- String key = mBackend.getKeyFromSetting(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
- mMessages.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
- mBackend.getSettingFromPrefKey(key));
- }
-
- @Test
- public void setNoSender() {
- String key = mBackend.getKeyFromSetting(ZenModeBackend.SOURCE_NONE);
- mMessages.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
- mBackend.getSettingFromPrefKey(key));
- }
-
- @Test
- public void setStarredSenders() {
- String key = mBackend.getKeyFromSetting(
- NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
- mMessages.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
- mBackend.getSettingFromPrefKey(key));
- }
-
- @Test
- public void setContactsOnlySenders() {
- String key = mBackend.getKeyFromSetting(
- NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
- mMessages.setDefaultKey(key);
- verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
- mBackend.getSettingFromPrefKey(key));
- }
-}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java
index ef3f9cd..ee3f0ec 100644
--- a/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/RestrictedEncryptionPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.UserManager;
@@ -47,11 +48,13 @@
private ResetCredentialsPreferenceController mResetCredentialsPreferenceController;
private UserCredentialsPreferenceController mUserCredentialsPreferenceController;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mCredentialStoragePreferenceController =
new CredentialStoragePreferenceController(mContext);
mInstallCredentialsPreferenceController =
diff --git a/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java
index 797e7d0..4ee9206 100644
--- a/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/ScreenPinningPreferenceControllerTest.java
@@ -18,23 +18,19 @@
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -43,10 +39,6 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ScreenPinningPreferenceControllerTest {
- @Mock
- private PreferenceScreen mScreen;
-
- private FakeFeatureFactory mFeatureFactory;
private Context mContext;
private ScreenPinningPreferenceController mController;
private Preference mPreference;
@@ -55,12 +47,9 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new ScreenPinningPreferenceController(mContext);
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
- when(mScreen.findPreference(mController.getPreferenceKey()))
- .thenReturn(mPreference);
}
@After
@@ -75,22 +64,22 @@
}
@Test
- public void displayPreference_isOff_shouldDisableOffSummary() {
+ public void updateState_isOff_shouldDisableOffSummary() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.LOCK_TO_APP_ENABLED, 0);
- mController.displayPreference(mScreen);
+ mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.switch_off_text));
}
@Test
- public void displayPreference_isOn_shouldDisableOnSummary() {
+ public void updateState_isOn_shouldDisableOnSummary() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.LOCK_TO_APP_ENABLED, 1);
- mController.displayPreference(mScreen);
+ mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.switch_on_text));
diff --git a/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java
index dd98372..23d2731 100644
--- a/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java
@@ -27,6 +27,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
@@ -63,6 +64,7 @@
private UserManager mUm;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private FakeFeatureFactory mFeatureFactory;
private Context mContext;
private VisiblePatternProfilePreferenceController mController;
@@ -82,7 +84,8 @@
.thenReturn(mLockPatternUtils);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new VisiblePatternProfilePreferenceController(mContext, mLifecycle);
}
diff --git a/tests/robotests/src/com/android/settings/security/screenlock/LockScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/screenlock/LockScreenPreferenceControllerTest.java
index 671807b..f1a5d9b 100644
--- a/tests/robotests/src/com/android/settings/security/screenlock/LockScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/screenlock/LockScreenPreferenceControllerTest.java
@@ -26,6 +26,7 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
@@ -60,6 +61,7 @@
private PreferenceScreen mScreen;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private FakeFeatureFactory mFeatureFactory;
private Context mContext;
private LockScreenPreferenceController mController;
@@ -78,7 +80,8 @@
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
mPreference = new Preference(mContext);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mController = new LockScreenPreferenceController(mContext, mLifecycle);
}
diff --git a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java
index 6913c0c..684274c 100644
--- a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java
@@ -29,6 +29,7 @@
import static org.mockito.Mockito.when;
import android.app.Activity;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.ComponentName;
import android.content.Context;
import android.support.v7.preference.Preference;
@@ -69,6 +70,7 @@
private SecuritySettingsV2 mFragment;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private FakeFeatureFactory mFeatureFactory;
private Activity mActivity;
@@ -79,7 +81,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.buildActivity(Activity.class).get();
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(any(Context.class)))
.thenReturn(mLockPatternUtils);
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowParcel.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowParcel.java
new file mode 100644
index 0000000..6e42fea
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowParcel.java
@@ -0,0 +1,32 @@
+package com.android.settings.testutils.shadow;
+
+import android.os.Parcel;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+/**
+ * This class provides helpers to test logic that reads from parcels.
+ */
+@Implements(Parcel.class)
+public class ShadowParcel {
+
+ public static int sReadIntResult;
+ public static int sWriteIntResult;
+ public static boolean sReadBoolResult;
+
+ @Implementation
+ public int readInt() {
+ return sReadIntResult;
+ }
+
+ @Implementation
+ public void writeInt(int val) {
+ sWriteIntResult = val;
+ }
+
+ @Implementation
+ public boolean readBoolean() {
+ return sReadBoolResult;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java b/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
index 0f3eb31..d53af9d 100644
--- a/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
@@ -29,6 +29,7 @@
import android.app.ActionBar;
import android.app.Activity;
+import android.arch.lifecycle.LifecycleOwner;
import android.support.v7.widget.RecyclerView;
import android.view.View;
@@ -55,6 +56,7 @@
@Mock
private ActionBar mActionBar;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private View mView;
@Before
@@ -62,7 +64,8 @@
MockitoAnnotations.initMocks(this);
when(mActivity.getActionBar()).thenReturn(mActionBar);
mView = new View(RuntimeEnvironment.application);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
index cf3cca7..08ee0ef 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
@@ -61,12 +62,14 @@
private Preference mMacPreference;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private WifiInfoPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getSystemService(WifiManager.class))
.thenReturn(mWifiManager);
when(mScreen.findPreference(anyString()))
diff --git a/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
index 7a734e5..e4dfea4 100644
--- a/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WpsPreferenceControllerTest.java
@@ -27,6 +27,7 @@
import static org.mockito.Mockito.when;
import android.app.FragmentManager;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -65,12 +66,14 @@
private Preference mWpsPinPref;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private WpsPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getSystemService(WifiManager.class))
.thenReturn(mWifiManager);
when(mScreen.findPreference(anyString()))
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index 6a36a79..4f77435 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -33,6 +33,7 @@
import static org.mockito.Mockito.when;
import android.app.Activity;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -154,6 +155,7 @@
private Context mContext;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private LinkProperties mLinkProperties;
private WifiDetailPreferenceController mController;
@@ -214,7 +216,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
when(mockAccessPoint.getConfig()).thenReturn(mockWifiConfig);
when(mockAccessPoint.getLevel()).thenReturn(LEVEL);
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 e809431..5c141ec 100644
--- a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2PPreferenceControllerTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -60,12 +61,14 @@
private Preference mWifiDirectPreference;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private WifiP2pPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
when(mContext.getSystemService(WifiManager.class))
.thenReturn(mWifiManager);
when(mScreen.findPreference(anyString()))
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 2a39515..00d9585 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.arch.lifecycle.LifecycleOwner;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -78,12 +79,14 @@
private WifiTetherPreferenceController mController;
private Lifecycle mLifecycle;
+ private LifecycleOwner mLifecycleOwner;
private MasterSwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
FakeFeatureFactory.setupForTest();
mPreference = new MasterSwitchPreference(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
diff --git a/tests/unit/src/com/android/settings/core/UserRestrictionTest.java b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
index da09d3c..f37c30b 100644
--- a/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
+++ b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
@@ -64,7 +64,8 @@
UserManager.DISALLOW_CONFIG_TETHERING,
UserManager.DISALLOW_CONFIG_VPN,
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,
- UserManager.DISALLOW_AIRPLANE_MODE
+ UserManager.DISALLOW_AIRPLANE_MODE,
+ UserManager.DISALLOW_CONFIG_BRIGHTNESS
);
@Before