Merge "Enable overlays on background thread."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a8101f1..8362fd6 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1825,7 +1825,7 @@
<activity
android:name="Settings$PrintSettingsActivity"
android:label="@string/print_settings"
- android:icon="@drawable/ic_settings_print"
+ android:icon="@*android:drawable/ic_settings_print"
android:parentActivityName="Settings">
<intent-filter android:priority="1">
<action android:name="android.settings.ACTION_PRINT_SETTINGS" />
@@ -2983,6 +2983,17 @@
</intent-filter>
</activity>
+ <activity-alias
+ android:name="MediaOutputSlice"
+ android:label="@string/media_output_panel_title"
+ android:permission="android.permission.BLUETOOTH_PRIVILEGED"
+ android:targetActivity=".panel.SettingsPanelActivity">
+ <intent-filter>
+ <action android:name="com.android.settings.panel.action.MEDIA_OUTPUT" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity-alias>
+
<provider android:name=".slices.SettingsSliceProvider"
android:authorities="com.android.settings.slices;android.settings.slices"
android:exported="true"
@@ -3048,7 +3059,7 @@
<intent-filter>
<action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER"/>
<action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR"/>
- <action android:name="android.settings.PROCESS_WIFI_DPP_QR_CODE"/>
+ <action android:name="android.settings.PROCESS_WIFI_EASY_CONNECT_QR_CODE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
diff --git a/protos/contextual_card_list.proto b/protos/contextual_card_list.proto
index 3496c8c..5645c87 100644
--- a/protos/contextual_card_list.proto
+++ b/protos/contextual_card_list.proto
@@ -19,6 +19,7 @@
POSSIBLE = 2;
IMPORTANT = 3;
EXCLUSIVE = 4;
+ DEFERRED_SETUP = 5;
}
/** Slice uri of the contextual card */
diff --git a/res/drawable-nodpi/gesture_silence b/res/drawable-nodpi/gesture_silence
deleted file mode 100644
index e69de29..0000000
--- a/res/drawable-nodpi/gesture_silence
+++ /dev/null
diff --git a/res/drawable-nodpi/gesture_skip b/res/drawable-nodpi/gesture_skip
deleted file mode 100644
index e69de29..0000000
--- a/res/drawable-nodpi/gesture_skip
+++ /dev/null
diff --git a/res/drawable/ic_expand.xml b/res/drawable/ic_expand.xml
index 72da2b9..f5b3f66 100644
--- a/res/drawable/ic_expand.xml
+++ b/res/drawable/ic_expand.xml
@@ -19,6 +19,6 @@
<item android:state_checked="true" android:drawable="@drawable/ic_expand_less" />
- <item android:drawable="@drawable/ic_expand_more" />
+ <item android:drawable="@*android:drawable/ic_expand_more" />
</selector>
diff --git a/res/drawable/ic_expand_more.xml b/res/drawable/ic_expand_more.xml
deleted file mode 100644
index edffde3..0000000
--- a/res/drawable/ic_expand_more.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24"
- android:viewportHeight="24"
- android:tint="?android:attr/colorControlNormal">
-
- <path
- android:fillColor="#000000"
- android:pathData="M8.12 9.29L12 13.17l3.88-3.88a.996 .996 0 1 1 1.41 1.41l-4.59 4.59a.996 .996 0 0
-1-1.41 0L6.7 10.7a.996 .996 0 0 1 0-1.41c.39-.38 1.03-.39 1.42 0z" />
-
-</vector>
diff --git a/res/layout/advanced_bt_entity_header.xml b/res/layout/advanced_bt_entity_header.xml
new file mode 100644
index 0000000..4aadad1
--- /dev/null
+++ b/res/layout/advanced_bt_entity_header.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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:id="@+id/entity_header"
+ style="@style/EntityHeader"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/entity_header_title"
+ style="@style/TextAppearance.EntityHeaderTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:singleLine="false"
+ android:ellipsize="marquee"
+ android:textDirection="locale"/>
+
+ <TextView
+ android:id="@+id/entity_header_summary"
+ style="@style/TextAppearance.EntityHeaderSummary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="2dp"
+ android:singleLine="false"
+ android:ellipsize="marquee"
+ android:textDirection="locale"
+ android:text="test_summary"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:orientation="horizontal">
+
+ <include
+ android:id="@+id/layout_left"
+ layout="@layout/advanced_bt_entity_sub"/>
+
+ <include
+ android:id="@+id/layout_middle"
+ layout="@layout/advanced_bt_entity_sub"/>
+
+ <include
+ android:id="@+id/layout_right"
+ layout="@layout/advanced_bt_entity_sub"/>
+
+ </LinearLayout>
+
+</LinearLayout>
diff --git a/res/layout/advanced_bt_entity_sub.xml b/res/layout/advanced_bt_entity_sub.xml
new file mode 100644
index 0000000..07ea814
--- /dev/null
+++ b/res/layout/advanced_bt_entity_sub.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:orientation="vertical">
+
+ <ImageView
+ android:id="@+id/header_icon"
+ android:layout_width="72dp"
+ android:layout_height="72dp"
+ android:scaleType="fitCenter"
+ android:layout_gravity="center_horizontal"
+ android:antialias="true"/>
+
+ <TextView
+ android:id="@+id/header_title"
+ style="@style/TextAppearance.EntityHeaderTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:singleLine="false"
+ android:ellipsize="marquee"
+ android:textDirection="locale"
+ android:layout_marginTop="24dp"/>
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="2dp"
+ android:layout_gravity="center_horizontal"
+ android:orientation="horizontal">
+ <ImageView
+ android:id="@+id/bt_battery_icon"
+ android:layout_width="13dp"
+ android:layout_height="20dp"/>
+ <TextView
+ android:id="@+id/bt_battery_summary"
+ style="@style/TextAppearance.EntityHeaderSummary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="4dp"
+ android:layout_gravity="center_horizontal"/>
+ </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/crypt_keeper_switch_input_method.xml b/res/layout/crypt_keeper_switch_input_method.xml
index b55db22..3fae593 100644
--- a/res/layout/crypt_keeper_switch_input_method.xml
+++ b/res/layout/crypt_keeper_switch_input_method.xml
@@ -22,7 +22,7 @@
android:id="@+id/switch_ime_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:src="@drawable/ic_lockscreen_ime"
+ android:src="@*android:drawable/ic_lockscreen_ime"
android:clickable="true"
android:contentDescription="@string/crypt_keeper_switch_input_method"
android:padding="@dimen/crypt_keeper_edit_text_ime_padding"
diff --git a/res/layout/homepage_condition_header.xml b/res/layout/homepage_condition_header.xml
index 8f3a92c..a2796ec 100644
--- a/res/layout/homepage_condition_header.xml
+++ b/res/layout/homepage_condition_header.xml
@@ -45,8 +45,8 @@
android:paddingTop="@dimen/homepage_condition_header_indicator_padding_top"
android:paddingStart="@dimen/homepage_condition_header_indicator_padding_start"
android:paddingEnd="@dimen/homepage_condition_header_indicator_padding_end"
- android:src="@drawable/ic_expand_more"/>
+ android:src="@*android:drawable/ic_expand_more"/>
</LinearLayout>
-</com.google.android.material.card.MaterialCardView>
\ No newline at end of file
+</com.google.android.material.card.MaterialCardView>
diff --git a/res/layout/homepage_slice_deferred_setup_tile.xml b/res/layout/homepage_slice_deferred_setup_tile.xml
new file mode 100644
index 0000000..8c83c09
--- /dev/null
+++ b/res/layout/homepage_slice_deferred_setup_tile.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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.
+ -->
+
+<com.google.android.material.card.MaterialCardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/ContextualCardStyle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <ViewFlipper
+ android:id="@+id/view_flipper"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:id="@+id/content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="left"
+ android:orientation="vertical"
+ android:paddingBottom="@dimen/homepage_deferred_setup_card_padding_bottom"
+ android:paddingEnd="@dimen/homepage_card_padding_end"
+ android:paddingStart="@dimen/homepage_card_padding_start"
+ android:paddingTop="@dimen/homepage_deferred_setup_card_padding_top">
+
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="@dimen/homepage_card_icon_size"
+ android:layout_height="@dimen/homepage_card_icon_size"/>
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/homepage_deferred_setup_card_title_margin_top"
+ android:ellipsize="end"
+ android:maxLines="2"
+ android:minLines="1"
+ android:textAppearance="@style/TextAppearance.DeferredSetupCardTitle"/>
+
+ <TextView
+ android:id="@android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/homepage_deferred_setup_card_summary_margin_top"
+ android:ellipsize="end"
+ android:maxLines="2"
+ android:minLines="1"
+ android:textAppearance="@style/TextAppearance.DeferredSetupCardSummary"/>
+
+ <Button
+ android:id="@+id/finish_setup"
+ style="@style/DeferredSetupCardButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/homepage_deferred_setup_card_button_margin_top"
+ android:text="@string/suggestion_button_text"/>
+
+ </LinearLayout>
+
+ <!--dismissal view-->
+ <include layout="@layout/homepage_dismissal_view"/>
+
+ </ViewFlipper>
+</com.google.android.material.card.MaterialCardView>
\ No newline at end of file
diff --git a/res/raw/gesture_silence.mp4 b/res/raw/gesture_silence.mp4
deleted file mode 100644
index e69de29..0000000
--- a/res/raw/gesture_silence.mp4
+++ /dev/null
diff --git a/res/raw/gesture_skip.mp4 b/res/raw/gesture_skip.mp4
deleted file mode 100644
index e69de29..0000000
--- a/res/raw/gesture_skip.mp4
+++ /dev/null
diff --git a/res/values/config.xml b/res/values/config.xml
index a6e5e1c..e6856ac 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -143,6 +143,15 @@
<!-- Whether or not homepage should display user's account avatar -->
<bool name="config_show_avatar_in_homepage">false</bool>
+ <!-- Whether or not emergency info tile should display in device info page -->
+ <bool name="config_show_emergency_info_in_device_info">true</bool>
+
+ <!-- Whether or not branded account info tile should display in device info page -->
+ <bool name="config_show_branded_account_in_device_info">true</bool>
+
+ <!-- Whether or not device header widget tile should display in device info page -->
+ <bool name="config_show_device_header_in_device_info">true</bool>
+
<!-- Whether or not TopLevelSettings should force rounded icon for injected tiles -->
<bool name="config_force_rounded_icon_TopLevelSettings">true</bool>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 087c870..dd06c37 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -333,6 +333,15 @@
<dimen name="homepage_half_card_padding_top">12dp</dimen>
<dimen name="homepage_half_card_padding_bottom">16dp</dimen>
<dimen name="homepage_half_card_title_margin_top">12dp</dimen>
+ <dimen name="homepage_deferred_setup_card_padding_top">16dp</dimen>
+ <dimen name="homepage_deferred_setup_card_padding_bottom">12dp</dimen>
+ <dimen name="homepage_deferred_setup_card_title_margin_top">12dp</dimen>
+ <dimen name="homepage_deferred_setup_card_summary_margin_top">2dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_margin_top">8dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_top">8dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_bottom">8dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_start">24dp</dimen>
+ <dimen name="homepage_deferred_setup_card_button_padding_end">24dp</dimen>
<!-- Homepage dismissal cards size and padding -->
<dimen name="homepage_card_dismissal_margin_top">12dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 81528f6..1a92f7b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2688,6 +2688,15 @@
<!-- Display settings screen, display white balance settings title [CHAR LIMIT=30] -->
<string name="display_white_balance_title">Display white balance</string>
+ <!-- Display settings screen, setting option name to enable adaptive sleep [CHAR LIMIT=30] -->
+ <string name="adaptive_sleep_title">Adaptive sleep</string>
+ <!-- Setting option summary when adaptive sleep is on [CHAR LIMIT=NONE] -->
+ <string name="adaptive_sleep_summary_on">On</string>
+ <!-- Setting option summary when adaptive sleep is off [CHAR LIMIT=NONE] -->
+ <string name="adaptive_sleep_summary_off">Off</string>
+ <!-- Description about the feature adaptive sleep [CHAR LIMIT=NONE]-->
+ <string name="adaptive_sleep_description">Your screen would not dim and go to sleep if the device detects your present attention.</string>
+
<!-- Night display screen, setting option name to enable night display (renamed "Night Light" with title caps). [CHAR LIMIT=30] -->
<string name="night_display_title">Night Light</string>
@@ -6707,6 +6716,8 @@
<string name="help_url_display_size" translatable="false"></string>
<!-- Help URL, Auto brightness [DO NOT TRANSLATE] -->
<string name="help_url_auto_brightness" translatable="false" />
+ <!-- Help URL, Adaptive sleep [DO NOT TRANSLATE] -->
+ <string name="help_url_adaptive_sleep" translatable="false" />
<!-- Help URL, Previously connected bluetooth devices [DO NOT TRANSLATE] -->
<string name="help_url_previously_connected_devices" translatable="false"></string>
<!-- Help URL, Top level privacy settings [DO NOT TRANSLATE] -->
@@ -7047,6 +7058,9 @@
<!-- Search keywords for adaptive brightness setting [CHAR LIMIT=NONE]-->
<string name="keywords_display_auto_brightness">dim screen, touchscreen, battery, smart brightness, dynamic brightness</string>
+ <!-- Search keywords for adaptive sleep setting [CHAR LIMIT=NONE]-->
+ <string name="keywords_display_adaptive_sleep">dim screen, sleep, battery, timeout, attention</string>
+
<!-- List of synonyms for the auto rotate (rotate the virtual display when the device rotates) setting, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_auto_rotate">rotate, flip, rotation, portrait, landscape, orientation, vertical, horizontal</string>
@@ -7317,7 +7331,7 @@
<!-- Do not disturb: Hide notifications summary [CHAR LIMIT=NONE] -->
<string name="zen_mode_restrict_notifications_hide_summary">You won\u2019t see or hear notifications</string>
<!-- Do not disturb: Hide notifications footer [CHAR LIMIT=NONE] -->
- <string name="zen_mode_restrict_notifications_hide_footer">Your phone won\u2019t show new or existing notifications, and won\u2019t make a sound or vibrate. Notifications won\u2019t appear when you swipe down from the top of your screen.\n\nKeep in mind, critical notifications for phone activity and status will still appear.</string>
+ <string name="zen_mode_restrict_notifications_hide_footer">Your phone won\u2019t show, vibrate or make sound for new or existing notifications. Keep in mind, critical notifications for phone activity and status will still appear.\n\nWhen you turn off Do Not Disturb, find missed notifications by swiping down from the top of your screen.</string>
<!-- Do not disturb: Custom settings option [CHAR LIMIT=60] -->
<string name="zen_mode_restrict_notifications_custom">Custom</string>
<!-- Do not disturb: restrict notifications page, menu option [CHAR LIMIT=60] -->
@@ -8044,7 +8058,7 @@
<string name="zen_mode_calls_title">Calls</string>
<!-- [CHAR LIMIT=NONE] Zen mode settings: Calls screen footer -->
- <string name="zen_mode_calls_footer">When Do Not Disturb is on, incoming calls are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.</string>
+ <string name="zen_mode_calls_footer">To be sure allowed calls make sound, check whether your device is set to ring, vibrate, or silent.</string>
<!-- [CHAR LIMIT=NONE] Zen mode custom rule settings: Calls screen footer -->
<string name="zen_mode_custom_calls_footer">For \u2018<xliff:g id="schedule_name" example="Schedule 1">%1$s</xliff:g>\u2019 incoming calls are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.</string>
@@ -8062,13 +8076,13 @@
<string name="zen_mode_messages">Allow text messages</string>
<!-- Do not disturb settings, messages, events and reminders footer [CHAR LIMIT=NONE]-->
- <string name="zen_mode_messages_footer">When Do Not Disturb is on, incoming text messages are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.</string>
+ <string name="zen_mode_messages_footer">To be sure allowed messages make sound, check whether your device is set to ring, vibrate, or silent.</string>
<!-- [CHAR LIMIT=NONE] Zen mode custom rule settings: Messages screen footer -->
<string name="zen_mode_custom_messages_footer">For \u2018<xliff:g id="schedule_name" example="Schedule 1">%1$s</xliff:g>\u2019 incoming text messages are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Allow messages to bypass DND title -->
- <string name="zen_mode_messages_title">Text messages</string>
+ <string name="zen_mode_messages_title">SMS, MMS, and messaging apps</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: From anyone -->
<string name="zen_mode_from_anyone">From anyone</string>
@@ -8104,7 +8118,7 @@
<string name="zen_mode_alarms_list">alarms</string>
<!-- [CHAR LIMIT=80] Zen mode settings: Allow media (sound from video) to bypass dnd -->
- <string name="zen_mode_media">Allow media sounds</string>
+ <string name="zen_mode_media">Play media sounds</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Media (ie: sound from video) -->
<string name="zen_mode_media_list">media</string>
@@ -9569,6 +9583,9 @@
<item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> apps can use unrestricted data</item>
</plurals>
+ <!-- Title for the More preference item in Special app access settings [CHAR LIMIT=30] -->
+ <string name="special_access_more">More</string>
+
<!-- Developer option to convert to file encryption - final warning -->
<string name="confirm_convert_to_fbe_warning">Really wipe user data and convert to file encryption?</string>
<!-- Developer option to convert to file encryption - final button -->
@@ -10129,25 +10146,27 @@
<!-- UI debug setting: ANGLE enabled app has been set [CHAR LIMIT=NONE] -->
<string name="angle_enabled_app_set">ANGLE enabled application: <xliff:g id="app_name" example="com.company.app">%1$s</xliff:g></string>
- <!-- Title for Game Update Package dashboard where developers can configure apps to use GUP or not [CHAR LIMIT=50] -->
- <string name="gup_dashboard_title">Game Update Package Preferences</string>
- <!-- Summary for Game Update Package dashboard [CHAR LIMIT=50] -->
- <string name="gup_dashboard_summary">Modify Game Update Package settings</string>
- <!-- Title for Game Update Package all apps preference [CHAR LIMIT=50] -->
- <string name="gup_all_apps_switch_title">Enable for all apps</string>
- <!-- Title for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_title">Select Graphics Driver</string>
- <!-- The default value for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_default">Default</string>
- <!-- The gup value for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_gup">Game Update Package</string>
- <!-- The system value for Game Update Package preference [CHAR LIMIT=50] -->
- <string name="gup_app_preference_system">System Graphics Driver</string>
- <!-- All the values for Game Update Package preference [CHAR LIMIT=50] -->
- <string-array name="gup_app_preference_values">
- <item>@string/gup_app_preference_default</item>
- <item>@string/gup_app_preference_gup</item>
- <item>@string/gup_app_preference_system</item>
+ <!-- Title for Game Driver dashboard where developers can configure apps to use game driver or not [CHAR LIMIT=50] -->
+ <string name="game_driver_dashboard_title">Game Driver Preferences</string>
+ <!-- Summary for Game Driver dashboard [CHAR LIMIT=50] -->
+ <string name="game_driver_dashboard_summary">Modify Game Driver settings</string>
+ <!-- Footer text for Game Driver dashboard [CHAR LIMIT=NONE] -->
+ <string name="game_driver_footer_text">When Game Driver is turned on, you can pick to use the updated graphics driver for Apps installed on the device.</string>
+ <!-- Title for Game Driver all apps preference [CHAR LIMIT=50] -->
+ <string name="game_driver_all_apps_preference_title">Enable for all apps</string>
+ <!-- Title for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_title">Select Graphics Driver</string>
+ <!-- The default value for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_default">Default</string>
+ <!-- The game driver value for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_game_driver">Game Driver</string>
+ <!-- The system value for Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_system">System Graphics Driver</string>
+ <!-- All the values for Game Driver app preference [CHAR LIMIT=50] -->
+ <string-array name="game_driver_app_preference_values">
+ <item>@string/game_driver_app_preference_default</item>
+ <item>@string/game_driver_app_preference_game_driver</item>
+ <item>@string/game_driver_app_preference_system</item>
</string-array>
<!-- Slices Strings -->
@@ -10498,6 +10517,13 @@
<!-- Title for no bluetooth devices in Bluetooth devices slice. [CHAR LIMIT=NONE] -->
<string name="no_bluetooth_devices">No Bluetooth devices</string>
+ <!-- Title for left bluetooth device. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_left_name">Left</string>
+ <!-- Title for right bluetooth device. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_right_name">Right</string>
+ <!-- Title for middle bluetooth device. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_middle_name">Case</string>
+
<!-- Default title for the settings panel [CHAR LIMIT=NONE] -->
<string name="settings_panel_title">Settings Panel</string>
@@ -10543,12 +10569,6 @@
<!-- String for talkback on the account avatar of the search bar. [CHAR LIMIT=NONE] -->
<string name="search_bar_account_avatar_content_description"></string>
- <!-- Preference title text for skip media gesture [CHAR LIMIT=60]-->
- <string name="gesture_skip_title">Skip gesture</string>
-
- <!-- Preference title text for silence gesture [CHAR LIMIT=60]-->
- <string name="gesture_silence_title">Silence alerts gesture</string>
-
<!-- Text to display when no app used permission. [CHAR LIMIT=NONE] -->
<string name="permission_bar_chart_empty_text">0 apps used permissions</string>
@@ -10568,4 +10588,8 @@
<item quantity="other"><xliff:g id="notification_channel_count">%1$d</xliff:g> notification channels. Tap to manage all.</item>
</plurals>
+ <!-- Title for the Switch output dialog (settings panel) with media related devices [CHAR LIMIT=50] -->
+ <string name="media_output_panel_title">Switch output</string>
+ <!-- Summary for represent which device is playing media [CHAR LIMIT=NONE] -->
+ <string name="media_output_panel_summary_of_playing_device">Currently playing on <xliff:g id="device_name" example="Bose headphone">%1$s</xliff:g></string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 8e8e86f..6d153e1 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -284,14 +284,8 @@
<item name="android:textSize">@dimen/search_bar_text_size</item>
</style>
- <style name="TextAppearance.SuggestionHeader"
- parent="@*android:style/TextAppearance.DeviceDefault.Subhead">
- <item name="android:textSize">14sp</item>
- <item name="android:textColor">?android:attr/colorAccent</item>
- </style>
-
<style name="TextAppearance.ConditionCardTitle"
- parent="@*android:style/TextAppearance.DeviceDefault.Body2">
+ parent="@*android:style/TextAppearance.DeviceDefault.Subhead">
<item name="android:textSize">16sp</item>
</style>
@@ -304,7 +298,7 @@
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">?android:attr/colorAccent</item>
- <item name="android:background">@drawable/btn_borderless_rect</item>
+ <item name="android:background">@*android:drawable/btn_borderless_rect</item>
<item name="android:gravity">center</item>
<item name="android:focusable">true</item>
<item name="android:padding">8dp</item>
@@ -468,4 +462,24 @@
<item name="titleSize">@*android:dimen/text_size_subhead_material</item>
</style>
+ <style name="TextAppearance.DeferredSetupCardTitle">
+ <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
+ <item name="android:textSize">16sp</item>
+ </style>
+
+ <style name="TextAppearance.DeferredSetupCardSummary"
+ parent="@*android:style/TextAppearance.DeviceDefault.Body1">
+ <item name="android:textColor">?android:attr/textColorSecondary</item>
+ </style>
+
+ <style name="DeferredSetupCardButton" parent="android:Widget.DeviceDefault.Button.Colored">
+ <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
+ <item name="android:paddingBottom">@dimen/homepage_deferred_setup_card_button_padding_bottom</item>
+ <item name="android:paddingEnd">@dimen/homepage_deferred_setup_card_button_padding_end</item>
+ <item name="android:paddingStart">@dimen/homepage_deferred_setup_card_button_padding_start</item>
+ <item name="android:paddingTop">@dimen/homepage_deferred_setup_card_button_padding_top</item>
+ <item name="android:textAllCaps">false</item>
+ <item name="android:textSize">14sp</item>
+ </style>
+
</resources>
diff --git a/res/xml/adaptive_sleep_detail.xml b/res/xml/adaptive_sleep_detail.xml
new file mode 100644
index 0000000..b7dabbb
--- /dev/null
+++ b/res/xml/adaptive_sleep_detail.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="adaptive_sleep_detail"
+ android:title="@string/adaptive_sleep_title">
+
+ <!-- TODO(111939367): add correct animation -->
+ <com.android.settings.widget.VideoPreference
+ android:key="adaptive_sleep_video"
+ android:title="@string/summary_placeholder"
+ settings:animation="@raw/aab_brightness"
+ settings:preview="@drawable/aab_brightness"
+ settings:controller="com.android.settings.widget.VideoPreferenceController"/>
+
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="adaptive_sleep"
+ android:title="@string/adaptive_sleep_title"
+ settings:keywords="@string/keywords_display_adaptive_sleep"
+ settings:controller="com.android.settings.display.AdaptiveSleepPreferenceController"
+ settings:useAdminDisabledSummary="true"
+ settings:allowDividerAbove="true" />
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/bluetooth_device_details_fragment.xml b/res/xml/bluetooth_device_details_fragment.xml
index cf9fbf9..f485c6a 100644
--- a/res/xml/bluetooth_device_details_fragment.xml
+++ b/res/xml/bluetooth_device_details_fragment.xml
@@ -23,7 +23,16 @@
android:key="bluetooth_device_header"
android:layout="@layout/settings_entity_header"
android:selectable="false"
- settings:allowDividerBelow="true"/>
+ settings:allowDividerBelow="true"
+ settings:searchable="false"/>
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="advanced_bluetooth_device_header"
+ android:layout="@layout/advanced_bt_entity_header"
+ android:selectable="false"
+ settings:allowDividerBelow="true"
+ settings:searchable="false"
+ settings:controller="com.android.settings.bluetooth.AdvancedBluetoothDetailsHeaderController"/>
<com.android.settingslib.widget.ActionButtonsPreference
android:key="action_buttons"
diff --git a/res/xml/connected_devices_advanced.xml b/res/xml/connected_devices_advanced.xml
index b5d2a99..28e9fdc 100644
--- a/res/xml/connected_devices_advanced.xml
+++ b/res/xml/connected_devices_advanced.xml
@@ -24,7 +24,7 @@
android:fragment="com.android.settings.connecteddevice.BluetoothDashboardFragment"
android:key="bluetooth_settings"
android:title="@string/bluetooth_settings_title"
- android:icon="@drawable/ic_settings_bluetooth"
+ android:icon="@*android:drawable/ic_settings_bluetooth"
android:order="-9"
settings:searchable="false"/>
@@ -48,7 +48,7 @@
android:key="connected_device_printing"
android:title="@string/print_settings"
android:summary="@string/summary_placeholder"
- android:icon="@drawable/ic_settings_print"
+ android:icon="@*android:drawable/ic_settings_print"
android:fragment="com.android.settings.print.PrintSettingsFragment"
android:order="-3"
settings:searchable="false"/>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 6d22a1d..9b43723 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -194,10 +194,10 @@
android:summary="@string/enable_gpu_debug_layers_summary" />
<Preference
- android:key="gup_dashboard"
- android:title="@string/gup_dashboard_title"
- android:summary="@string/gup_dashboard_summary"
- android:fragment="com.android.settings.development.gup.GupDashboard"
+ android:key="game_driver_dashboard"
+ android:title="@string/game_driver_dashboard_title"
+ android:summary="@string/game_driver_dashboard_summary"
+ android:fragment="com.android.settings.development.gamedriver.GameDriverDashboard"
settings:searchable="false" />
</PreferenceCategory>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 76b3d2e..b110b46 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -66,6 +66,13 @@
android:entryValues="@array/screen_timeout_values"
settings:keywords="@string/keywords_screen_timeout" />
+ <Preference
+ android:key="adaptive_sleep_entry"
+ android:title="@string/adaptive_sleep_title"
+ android:summary="@string/summary_placeholder"
+ android:fragment="com.android.settings.display.AdaptiveSleepSettings"
+ settings:controller="com.android.settings.display.AdaptiveSleepPreferenceController" />
+
<SwitchPreference
android:key="auto_rotate"
android:title="@string/accelerometer_title"
diff --git a/res/xml/game_driver_settings.xml b/res/xml/game_driver_settings.xml
new file mode 100644
index 0000000..a04724a
--- /dev/null
+++ b/res/xml/game_driver_settings.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2019 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="game_driver_settings"
+ android:title="@string/game_driver_dashboard_title">
+
+ <SwitchPreference
+ android:key="game_driver_all_apps_preference"
+ android:title="@string/game_driver_all_apps_preference_title"
+ settings:controller="com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController">
+ </SwitchPreference>
+
+ <PreferenceCategory
+ android:key="game_driver_category"
+ android:title="@string/game_driver_app_preference_title"
+ settings:controller="com.android.settings.development.gamedriver.GameDriverAppPreferenceController">
+ </PreferenceCategory>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="footer_preference"
+ android:title="@string/game_driver_footer_text"
+ android:selectable="false"
+ settings:controller="com.android.settings.development.gamedriver.GameDriverFooterPreferenceController">
+ </com.android.settingslib.widget.FooterPreference>
+
+</PreferenceScreen>
diff --git a/res/xml/gestures.xml b/res/xml/gestures.xml
index cd834df..4b17bd9 100644
--- a/res/xml/gestures.xml
+++ b/res/xml/gestures.xml
@@ -28,18 +28,6 @@
settings:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
<Preference
- android:key="gesture_skip_summary"
- android:title="@string/gesture_skip_title"
- android:fragment="com.android.settings.gestures.SkipGestureSettings"
- settings:controller="com.android.settings.gestures.SkipGesturePreferenceController" />
-
- <Preference
- android:key="gesture_silence_summary"
- android:title="@string/gesture_silence_title"
- android:fragment="com.android.settings.gestures.SilenceGestureSettings"
- settings:controller="com.android.settings.gestures.SilenceGesturePreferenceController" />
-
- <Preference
android:key="gesture_wake_screen_input_summary"
android:title="@string/ambient_display_wake_screen_title"
android:fragment="com.android.settings.gestures.WakeScreenGestureSettings"
diff --git a/res/xml/gup_settings.xml b/res/xml/gup_settings.xml
deleted file mode 100644
index 09bca71..0000000
--- a/res/xml/gup_settings.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto"
- android:key="gup_settings"
- android:title="@string/gup_dashboard_title">
-
- <SwitchPreference
- android:key="gup_all_apps_preference"
- android:title="@string/gup_all_apps_switch_title"
- settings:controller="com.android.settings.development.gup.GupEnableForAllAppsPreferenceController">
- </SwitchPreference>
-
- <PreferenceCategory
- android:key="gup_category"
- android:title="@string/gup_app_preference_title"
- settings:controller="com.android.settings.development.gup.GupPreferenceController">
- </PreferenceCategory>
-
-</PreferenceScreen>
diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml
index d669977..6323a14 100644
--- a/res/xml/my_device_info.xml
+++ b/res/xml/my_device_info.xml
@@ -25,7 +25,8 @@
android:key="my_device_info_header"
android:order="0"
android:layout="@layout/settings_entity_header"
- android:selectable="false"/>
+ android:selectable="false"
+ settings:isPreferenceVisible="false"/>
<!-- Device name -->
<com.android.settings.widget.ValidatedEditTextPreference
@@ -33,6 +34,7 @@
android:order="1"
android:title="@string/my_device_info_device_name_preference_title"
android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.deviceinfo.DeviceNamePreferenceController"
settings:enableCopying="true"/>
<!-- Account name -->
@@ -40,7 +42,8 @@
android:key="branded_account"
android:order="2"
android:title="@string/my_device_info_account_preference_title"
- android:summary="@string/summary_placeholder"/>
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.deviceinfo.BrandedAccountPreferenceController"/>
<!-- Phone number -->
<Preference
@@ -50,15 +53,15 @@
android:summary="@string/summary_placeholder"
android:selectable="false"
settings:allowDynamicSummaryInSlice="true"
- settings:controller=
- "com.android.settings.deviceinfo.PhoneNumberPreferenceController"
+ settings:controller="com.android.settings.deviceinfo.PhoneNumberPreferenceController"
settings:enableCopying="true"/>
<Preference
android:key="emergency_info"
android:order="4"
android:title="@string/emergency_info_title"
- android:summary="@string/summary_placeholder"/>
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.accounts.EmergencyInfoPreferenceController"/>
<!-- Legal information -->
<Preference
diff --git a/res/xml/silence_gesture_settings.xml b/res/xml/silence_gesture_settings.xml
deleted file mode 100644
index 208a41d..0000000
--- a/res/xml/silence_gesture_settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:key="silence_gesture"
- android:title="@string/gesture_silence_title">
-
- <com.android.settings.widget.VideoPreference
- android:key="gesture_silence_video"
- app:animation="@raw/gesture_silence"
- app:preview="@drawable/gesture_silence"/>
-</PreferenceScreen>
diff --git a/res/xml/skip_gesture_settings.xml b/res/xml/skip_gesture_settings.xml
deleted file mode 100644
index 3d88ac8..0000000
--- a/res/xml/skip_gesture_settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:key="skip_gesture"
- android:title="@string/gesture_skip_title">
-
- <com.android.settings.widget.VideoPreference
- android:key="gesture_skip_video"
- app:animation="@raw/gesture_skip"
- app:preview="@drawable/gesture_skip"/>
-</PreferenceScreen>
diff --git a/res/xml/special_access.xml b/res/xml/special_access.xml
index cb76693..4417d0f 100644
--- a/res/xml/special_access.xml
+++ b/res/xml/special_access.xml
@@ -135,4 +135,9 @@
android:title="@string/financial_apps_sms_access_title"
android:fragment="com.android.settings.applications.specialaccess.financialapps.FinancialAppsSmsAccess"
settings:keywords="@string/keywords_financial_apps_sms_access" />
+
+ <Preference
+ android:key="special_access_more"
+ android:title="@string/special_access_more"
+ settings:controller="com.android.settings.applications.specialaccess.MoreSpecialAccessPreferenceController" />
</PreferenceScreen>
diff --git a/src/com/android/settings/accounts/EmergencyInfoPreferenceController.java b/src/com/android/settings/accounts/EmergencyInfoPreferenceController.java
index 33e7771..7dc80d0 100644
--- a/src/com/android/settings/accounts/EmergencyInfoPreferenceController.java
+++ b/src/com/android/settings/accounts/EmergencyInfoPreferenceController.java
@@ -22,27 +22,25 @@
import android.content.res.Resources;
import android.os.UserHandle;
import android.os.UserManager;
+import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.preference.Preference;
import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.BasePreferenceController;
import com.android.settings.search.SearchIndexableRaw;
-import com.android.settingslib.core.AbstractPreferenceController;
import java.util.List;
-public class EmergencyInfoPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin {
+public class EmergencyInfoPreferenceController extends BasePreferenceController {
public static final String ACTION_EDIT_EMERGENCY_INFO = "android.settings.EDIT_EMERGENCY_INFO";
- private static final String KEY_EMERGENCY_INFO = "emergency_info";
private static final String PACKAGE_NAME_EMERGENCY = "com.android.emergency";
- public EmergencyInfoPreferenceController(Context context) {
- super(context);
+ public EmergencyInfoPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
}
@Override
@@ -56,6 +54,7 @@
}
}
+ @Override
public void updateState(Preference preference) {
UserInfo info = mContext.getSystemService(UserManager.class).getUserInfo(
UserHandle.myUserId());
@@ -64,7 +63,7 @@
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
- if (KEY_EMERGENCY_INFO.equals(preference.getKey())) {
+ if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
Intent intent = new Intent(getIntentAction(mContext));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
@@ -74,18 +73,19 @@
}
@Override
- public boolean isAvailable() {
- Intent intent = new Intent(getIntentAction(mContext)).setPackage(getPackageName(mContext));
- List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(intent, 0);
- return infos != null && !infos.isEmpty();
+ public int getAvailabilityStatus() {
+ if (!mContext.getResources().getBoolean(R.bool.config_show_emergency_info_in_device_info)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
+ final Intent intent = new Intent(getIntentAction(mContext)).setPackage(
+ getPackageName(mContext));
+ final List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(intent,
+ 0);
+ return infos != null && !infos.isEmpty()
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
- @Override
- public String getPreferenceKey() {
- return KEY_EMERGENCY_INFO;
- }
-
- private String getIntentAction(Context context) {
+ private static String getIntentAction(Context context) {
if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
return context.getResources().getString(R.string.config_emergency_intent_action);
}
@@ -93,7 +93,7 @@
return ACTION_EDIT_EMERGENCY_INFO;
}
- private String getPackageName(Context context) {
+ private static String getPackageName(Context context) {
if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
return context.getResources().getString(R.string.config_emergency_package_name);
}
diff --git a/src/com/android/settings/applications/specialaccess/MoreSpecialAccessPreferenceController.java b/src/com/android/settings/applications/specialaccess/MoreSpecialAccessPreferenceController.java
new file mode 100644
index 0000000..10d5c36
--- /dev/null
+++ b/src/com/android/settings/applications/specialaccess/MoreSpecialAccessPreferenceController.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2019 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.applications.specialaccess;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.text.TextUtils;
+
+import androidx.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+
+public class MoreSpecialAccessPreferenceController extends BasePreferenceController {
+
+ private final Intent mIntent;
+
+ public MoreSpecialAccessPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+
+ final PackageManager packageManager = context.getPackageManager();
+ final String packageName = packageManager.getPermissionControllerPackageName();
+ if (packageName != null) {
+ Intent intent = new Intent(Intent.ACTION_MANAGE_SPECIAL_APP_ACCESSES)
+ .setPackage(packageName);
+ ResolveInfo resolveInfo = packageManager.resolveActivity(intent,
+ PackageManager.MATCH_DEFAULT_ONLY);
+ mIntent = resolveInfo != null ? intent : null;
+ } else {
+ mIntent = null;
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mIntent != null ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (TextUtils.equals(preference.getKey(), mPreferenceKey)) {
+ if (mIntent != null) {
+ mContext.startActivity(mIntent);
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/com/android/settings/aware/AwareFeatureProvider.java b/src/com/android/settings/aware/AwareFeatureProvider.java
index a4db957..a24233f 100644
--- a/src/com/android/settings/aware/AwareFeatureProvider.java
+++ b/src/com/android/settings/aware/AwareFeatureProvider.java
@@ -21,4 +21,7 @@
public interface AwareFeatureProvider {
/** Returns true if the aware sensor is supported. */
boolean isSupported(Context context);
+
+ /** Returns true if the aware feature is enabled. */
+ boolean isEnabled(Context context);
}
diff --git a/src/com/android/settings/aware/AwareFeatureProviderImpl.java b/src/com/android/settings/aware/AwareFeatureProviderImpl.java
index af40634..44ec31b 100644
--- a/src/com/android/settings/aware/AwareFeatureProviderImpl.java
+++ b/src/com/android/settings/aware/AwareFeatureProviderImpl.java
@@ -23,4 +23,9 @@
public boolean isSupported(Context context) {
return false;
}
+
+ @Override
+ public boolean isEnabled(Context context) {
+ return false;
+ }
}
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
new file mode 100644
index 0000000..4b8efd4
--- /dev/null
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2019 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.bluetooth;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.graphics.drawable.Drawable;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.fuelgauge.BatteryMeterView;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.widget.LayoutPreference;
+
+/**
+ * This class adds a header with device name and status (connected/disconnected, etc.).
+ */
+public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceController {
+
+ @VisibleForTesting
+ LayoutPreference mLayoutPreference;
+ private CachedBluetoothDevice mCachedDevice;
+
+ public AdvancedBluetoothDetailsHeaderController(Context context, String prefKey) {
+ super(context, prefKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ final boolean unthetheredHeadset = Utils.getBooleanMetaData(mCachedDevice.getDevice(),
+ BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET);
+ return unthetheredHeadset ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mLayoutPreference = screen.findPreference(getPreferenceKey());
+ mLayoutPreference.setVisible(isAvailable());
+ refresh();
+ }
+
+ public void init(CachedBluetoothDevice cachedBluetoothDevice) {
+ mCachedDevice = cachedBluetoothDevice;
+ }
+
+ @VisibleForTesting
+ void refresh() {
+ if (mLayoutPreference != null && mCachedDevice != null) {
+ final TextView title = mLayoutPreference.findViewById(R.id.entity_header_title);
+ title.setText(mCachedDevice.getName());
+ final TextView summary = mLayoutPreference.findViewById(R.id.entity_header_summary);
+ summary.setText(mCachedDevice.getConnectionSummary());
+
+ updateSubLayout(mLayoutPreference.findViewById(R.id.layout_left),
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_ICON,
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_BATTERY,
+ R.string.bluetooth_left_name);
+
+ updateSubLayout(mLayoutPreference.findViewById(R.id.layout_middle),
+ BluetoothDevice.METADATA_UNTHETHERED_CASE_ICON,
+ BluetoothDevice.METADATA_UNTHETHERED_CASE_BATTERY,
+ R.string.bluetooth_middle_name);
+
+ updateSubLayout(mLayoutPreference.findViewById(R.id.layout_right),
+ BluetoothDevice.METADATA_UNTHETHERED_RIGHT_ICON,
+ BluetoothDevice.METADATA_UNTHETHERED_RIGHT_BATTERY,
+ R.string.bluetooth_right_name);
+ }
+ }
+
+ @VisibleForTesting
+ Drawable createBtBatteryIcon(Context context, int level) {
+ final BatteryMeterView.BatteryMeterDrawable drawable =
+ new BatteryMeterView.BatteryMeterDrawable(context,
+ context.getColor(R.color.meter_background_color));
+ drawable.setBatteryLevel(level);
+ drawable.setShowPercent(false);
+ drawable.setBatteryColorFilter(new PorterDuffColorFilter(
+ com.android.settings.Utils.getColorAttrDefaultColor(context,
+ android.R.attr.colorControlNormal),
+ PorterDuff.Mode.SRC_IN));
+
+ return drawable;
+ }
+
+ private void updateSubLayout(LinearLayout linearLayout, int iconMetaKey, int batteryMetaKey,
+ int titleResId) {
+ if (linearLayout == null) {
+ return;
+ }
+ final BluetoothDevice bluetoothDevice = mCachedDevice.getDevice();
+ final String iconUri = Utils.getStringMetaData(bluetoothDevice, iconMetaKey);
+ if (iconUri != null) {
+ final ImageView imageView = linearLayout.findViewById(R.id.header_icon);
+ final IconCompat iconCompat = IconCompat.createWithContentUri(iconUri);
+ imageView.setImageBitmap(iconCompat.getBitmap());
+ }
+
+ final int batteryLevel = Utils.getIntMetaData(bluetoothDevice, batteryMetaKey);
+ if (batteryLevel != Utils.META_INT_ERROR) {
+ final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
+ imageView.setImageDrawable(createBtBatteryIcon(mContext, batteryLevel));
+ final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
+ textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
+ }
+
+ final TextView textView = linearLayout.findViewById(R.id.header_title);
+ textView.setText(titleResId);
+ }
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsButtonsController.java b/src/com/android/settings/bluetooth/BluetoothDetailsButtonsController.java
index a438f09..af15052 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsButtonsController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsButtonsController.java
@@ -16,6 +16,7 @@
package com.android.settings.bluetooth;
+import android.bluetooth.BluetoothDevice;
import android.content.Context;
import androidx.preference.PreferenceFragmentCompat;
@@ -43,6 +44,13 @@
mIsConnected = device.isConnected();
}
+ @Override
+ public boolean isAvailable() {
+ final boolean unthetheredHeadset = Utils.getBooleanMetaData(mCachedDevice.getDevice(),
+ BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET);
+ return !unthetheredHeadset;
+ }
+
private void onForgetButtonPressed() {
ForgetDeviceDialogFragment fragment =
ForgetDeviceDialogFragment.newInstance(mCachedDevice.getAddress());
@@ -90,4 +98,4 @@
return KEY_ACTION_BUTTONS;
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsController.java b/src/com/android/settings/bluetooth/BluetoothDetailsController.java
index af5a628..bb48904 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsController.java
@@ -89,4 +89,4 @@
* should update the preferences it manages based on the new state.
*/
protected abstract void refresh();
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
index a41b791..95b16b9 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
@@ -62,7 +62,8 @@
protected void setHeaderProperties() {
final Pair<Drawable, String> pair = BluetoothUtils
.getBtClassDrawableWithDescription(mContext, mCachedDevice,
- mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1, 1));
+ mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1,
+ 1));
String summaryText = mCachedDevice.getConnectionSummary();
// If both the hearing aids are connected, two device status should be shown.
// If Second Summary is unavailable, to set it to null.
@@ -84,4 +85,4 @@
public String getPreferenceKey() {
return KEY_DEVICE_HEADER;
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java b/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java
index 987dbe4..835961d 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java
@@ -62,4 +62,4 @@
}
return mFooterPreference.getKey();
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
index 88cebcb..5c609e6 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
@@ -264,4 +264,4 @@
public String getPreferenceKey() {
return KEY_PROFILES_GROUP;
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java
index 6ff4309..98455f2 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java
@@ -108,6 +108,7 @@
mManager = getLocalBluetoothManager(context);
mCachedDevice = getCachedDevice(mDeviceAddress);
super.onAttach(context);
+ use(AdvancedBluetoothDetailsHeaderController.class).init(mCachedDevice);
final BluetoothFeatureProvider featureProvider = FeatureFactory.getFactory(
context).getBluetoothFeatureProvider(context);
@@ -137,7 +138,7 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem item = menu.add(0, EDIT_DEVICE_NAME_ITEM_ID, 0, R.string.bluetooth_rename_button);
- item.setIcon(R.drawable.ic_mode_edit);
+ item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
super.onCreateOptionsMenu(menu, inflater);
}
diff --git a/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java b/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java
index 59b8007..18df872 100644
--- a/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java
+++ b/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java
@@ -73,7 +73,7 @@
final boolean isBluetoothEnabled = isBluetoothEnabled();
final CharSequence title = context.getText(R.string.bluetooth_settings);
final IconCompat icon = IconCompat.createWithResource(context,
- R.drawable.ic_settings_bluetooth);
+ com.android.internal.R.drawable.ic_settings_bluetooth);
@ColorInt final int color = com.android.settings.Utils.getColorAccent(
context).getDefaultColor();
final PendingIntent toggleAction = getBroadcastIntent(context);
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index d6e395e..ff4a98f 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -47,6 +47,8 @@
static final boolean V = BluetoothUtils.V; // verbose logging
static final boolean D = BluetoothUtils.D; // regular logging
+ public static final int META_INT_ERROR = -1;
+
private Utils() {
}
@@ -152,4 +154,29 @@
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
}
+
+ public static boolean getBooleanMetaData(BluetoothDevice bluetoothDevice, int key) {
+ if (bluetoothDevice == null) {
+ return false;
+ }
+ return Boolean.parseBoolean(bluetoothDevice.getMetadata(key));
+ }
+
+ public static String getStringMetaData(BluetoothDevice bluetoothDevice, int key) {
+ if (bluetoothDevice == null) {
+ return null;
+ }
+ return bluetoothDevice.getMetadata(key);
+ }
+
+ public static int getIntMetaData(BluetoothDevice bluetoothDevice, int key) {
+ if (bluetoothDevice == null) {
+ return META_INT_ERROR;
+ }
+ try {
+ return Integer.parseInt(bluetoothDevice.getMetadata(key));
+ } catch (NumberFormatException e) {
+ return META_INT_ERROR;
+ }
+ }
}
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreference.java b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
index 3cbe1ea..481538d 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreference.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
+import android.net.ConnectivityManager;
import android.net.NetworkTemplate;
import android.os.Bundle;
import android.text.Spannable;
@@ -206,10 +207,12 @@
}
}
- private static void launchWifiDataUsage(Context context) {
+ @VisibleForTesting
+ static void launchWifiDataUsage(Context context) {
final Bundle args = new Bundle(1);
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE,
NetworkTemplate.buildTemplateWifiWildcard());
+ args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_WIFI);
final SubSettingLauncher launcher = new SubSettingLauncher(context)
.setArguments(args)
.setDestination(DataUsageList.class.getName())
diff --git a/src/com/android/settings/development/gup/GupPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
similarity index 61%
rename from src/com/android/settings/development/gup/GupPreferenceController.java
rename to src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
index d4cd2f1..3877c45 100644
--- a/src/com/android/settings/development/gup/GupPreferenceController.java
+++ b/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
@@ -14,13 +14,18 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.os.Handler;
+import android.os.Looper;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
@@ -31,6 +36,9 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import java.text.Collator;
@@ -42,62 +50,94 @@
import java.util.List;
import java.util.Set;
-public class GupPreferenceController
- extends BasePreferenceController implements Preference.OnPreferenceChangeListener {
+/**
+ * Controller of all the per App based list preferences.
+ */
+public class GameDriverAppPreferenceController extends BasePreferenceController
+ implements Preference.OnPreferenceChangeListener,
+ GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
private final CharSequence[] mEntryList;
private final String mPreferenceTitle;
private final String mPreferenceDefault;
- private final String mPreferenceGup;
+ private final String mPreferenceGameDriver;
private final String mPreferenceSystem;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
private final List<AppInfo> mAppInfos;
private final Set<String> mDevOptInApps;
private final Set<String> mDevOptOutApps;
- public GupPreferenceController(Context context, String key) {
+ private PreferenceGroup mPreferenceGroup;
+
+ public GameDriverAppPreferenceController(Context context, String key) {
super(context, key);
+ mContext = context;
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+
final Resources resources = context.getResources();
- mEntryList = resources.getStringArray(R.array.gup_app_preference_values);
- mPreferenceTitle = resources.getString(R.string.gup_app_preference_title);
- mPreferenceDefault = resources.getString(R.string.gup_app_preference_default);
- mPreferenceGup = resources.getString(R.string.gup_app_preference_gup);
- mPreferenceSystem = resources.getString(R.string.gup_app_preference_system);
+ mEntryList = resources.getStringArray(R.array.game_driver_app_preference_values);
+ mPreferenceTitle = resources.getString(R.string.game_driver_app_preference_title);
+ mPreferenceDefault = resources.getString(R.string.game_driver_app_preference_default);
+ mPreferenceGameDriver =
+ resources.getString(R.string.game_driver_app_preference_game_driver);
+ mPreferenceSystem = resources.getString(R.string.game_driver_app_preference_system);
// TODO: Move this task to background if there's potential ANR/Jank.
// Update the UI when all the app infos are ready.
mAppInfos = getAppInfos(context);
- final ContentResolver contentResolver = context.getContentResolver();
mDevOptInApps =
- getGlobalSettingsString(contentResolver, Settings.Global.GUP_DEV_OPT_IN_APPS);
+ getGlobalSettingsString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS);
mDevOptOutApps =
- getGlobalSettingsString(contentResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS);
+ getGlobalSettingsString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS);
}
@Override
public int getAvailabilityStatus() {
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
+ && (Settings.Global.getInt(mContentResolver,
+ Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF)
? AVAILABLE
- : DISABLED_DEPENDENT_SETTING;
+ : CONDITIONALLY_UNAVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- final PreferenceGroup preferenceGroup =
- (PreferenceGroup) screen.findPreference(getPreferenceKey());
- if (preferenceGroup == null) {
- return;
- }
+ mPreferenceGroup = (PreferenceGroup) screen.findPreference(getPreferenceKey());
+ final Context context = mPreferenceGroup.getContext();
for (AppInfo appInfo : mAppInfos) {
- preferenceGroup.addPreference(
- createListPreference(appInfo.info.packageName, appInfo.label));
+ mPreferenceGroup.addPreference(
+ createListPreference(context, appInfo.info.packageName, appInfo.label));
}
}
@Override
+ public void onStart() {
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setVisible(isAvailable());
+ }
+
+ @Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final ListPreference listPref = (ListPreference) preference;
final String value = newValue.toString();
@@ -108,7 +148,7 @@
if (value.equals(mPreferenceSystem)) {
mDevOptInApps.remove(packageName);
mDevOptOutApps.add(packageName);
- } else if (value.equals(mPreferenceGup)) {
+ } else if (value.equals(mPreferenceGameDriver)) {
mDevOptInApps.add(packageName);
mDevOptOutApps.remove(packageName);
} else {
@@ -119,15 +159,20 @@
listPref.setSummary(value);
// Push the updated Sets for opt-in and opt-out apps to
- // corresponding Settings.Global.GUP_DEV_OPT_(IN|OUT)_APPS
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.GUP_DEV_OPT_IN_APPS, String.join(",", mDevOptInApps));
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.GUP_DEV_OPT_OUT_APPS, String.join(",", mDevOptOutApps));
+ // corresponding Settings.Global.GAME_DRIVER_OPT_(IN|OUT)_APPS
+ Settings.Global.putString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS,
+ String.join(",", mDevOptInApps));
+ Settings.Global.putString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS,
+ String.join(",", mDevOptOutApps));
return true;
}
+ @Override
+ public void onGameDriverContentChanged() {
+ updateState(mPreferenceGroup);
+ }
+
// AppInfo class to achieve loading the application label only once
class AppInfo {
AppInfo(PackageManager packageManager, ApplicationInfo applicationInfo) {
@@ -176,8 +221,9 @@
};
@VisibleForTesting
- protected ListPreference createListPreference(String packageName, String appName) {
- final ListPreference listPreference = new ListPreference(mContext);
+ protected ListPreference createListPreference(
+ Context context, String packageName, String appName) {
+ final ListPreference listPreference = new ListPreference(context);
listPreference.setKey(packageName);
listPreference.setTitle(appName);
@@ -186,13 +232,13 @@
listPreference.setEntryValues(mEntryList);
// Initialize preference default and summary with the opt in/out choices
- // from Settings.Global.GUP_DEV_OPT_(IN|OUT)_APPS
+ // from Settings.Global.GAME_DRIVER_OPT_(IN|OUT)_APPS
if (mDevOptOutApps.contains(packageName)) {
listPreference.setValue(mPreferenceSystem);
listPreference.setSummary(mPreferenceSystem);
} else if (mDevOptInApps.contains(packageName)) {
- listPreference.setValue(mPreferenceGup);
- listPreference.setSummary(mPreferenceGup);
+ listPreference.setValue(mPreferenceGameDriver);
+ listPreference.setSummary(mPreferenceGameDriver);
} else {
listPreference.setValue(mPreferenceDefault);
listPreference.setSummary(mPreferenceDefault);
diff --git a/src/com/android/settings/development/gamedriver/GameDriverContentObserver.java b/src/com/android/settings/development/gamedriver/GameDriverContentObserver.java
new file mode 100644
index 0000000..e31e046
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverContentObserver.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import android.content.ContentResolver;
+import android.database.ContentObserver;
+import android.os.Handler;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+
+/**
+ * Helper class to observe Game Driver settings global change.
+ */
+public class GameDriverContentObserver extends ContentObserver {
+
+ interface OnGameDriverContentChangedListener {
+ void onGameDriverContentChanged();
+ }
+
+ @VisibleForTesting
+ OnGameDriverContentChangedListener mListener;
+
+ public GameDriverContentObserver(Handler handler, OnGameDriverContentChangedListener listener) {
+ super(handler);
+ mListener = listener;
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ mListener.onGameDriverContentChanged();
+ }
+
+ public void register(ContentResolver contentResolver) {
+ contentResolver.registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_ALL_APPS), false, this);
+ }
+
+ public void unregister(ContentResolver contentResolver) {
+ contentResolver.unregisterContentObserver(this);
+ }
+}
diff --git a/src/com/android/settings/development/gup/GupDashboard.java b/src/com/android/settings/development/gamedriver/GameDriverDashboard.java
similarity index 65%
rename from src/com/android/settings/development/gup/GupDashboard.java
rename to src/com/android/settings/development/gamedriver/GameDriverDashboard.java
index 0ab57e6..db456bd 100644
--- a/src/com/android/settings/development/gup/GupDashboard.java
+++ b/src/com/android/settings/development/gamedriver/GameDriverDashboard.java
@@ -14,29 +14,37 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.os.Bundle;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
+import com.android.settings.widget.SwitchBar;
+import com.android.settings.widget.SwitchBarController;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
+/**
+ * Dashboard for Game Driver preferences.
+ */
@SearchIndexable
-public class GupDashboard extends DashboardFragment {
- private static final String TAG = "GupDashboard";
+public class GameDriverDashboard extends DashboardFragment {
+
+ private static final String TAG = "GameDriverDashboard";
@Override
public int getMetricsCategory() {
- return SettingsEnums.SETTINGS_GUP_DASHBOARD;
+ return SettingsEnums.SETTINGS_GAME_DRIVER_DASHBOARD;
}
@Override
@@ -46,7 +54,7 @@
@Override
protected int getPreferenceScreenResId() {
- return R.xml.gup_settings;
+ return R.xml.game_driver_settings;
}
@Override
@@ -54,6 +62,19 @@
return 0;
}
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ final SettingsActivity activity = (SettingsActivity) getActivity();
+ final SwitchBar switchBar = activity.getSwitchBar();
+ final GameDriverGlobalSwitchBarController switchBarController =
+ new GameDriverGlobalSwitchBarController(
+ activity, new SwitchBarController(switchBar));
+ getSettingsLifecycle().addObserver(switchBarController);
+ switchBar.show();
+ }
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -61,7 +82,7 @@
Context context, boolean enabled) {
final List<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.gup_settings;
+ sir.xmlResId = R.xml.game_driver_settings;
result.add(sir);
return result;
}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java
new file mode 100644
index 0000000..68be526
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceController.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
+
+/**
+ * Controller of global switch to enable Game Driver for all Apps.
+ */
+public class GameDriverEnableForAllAppsPreferenceController extends BasePreferenceController
+ implements Preference.OnPreferenceChangeListener,
+ GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ public static final int GAME_DRIVER_DEFAULT = 0;
+ public static final int GAME_DRIVER_ALL_APPS = 1;
+ public static final int GAME_DRIVER_OFF = 2;
+
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
+
+ private SwitchPreference mPreference;
+
+ public GameDriverEnableForAllAppsPreferenceController(Context context, String key) {
+ super(context, key);
+ mContext = context;
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
+ && (Settings.Global.getInt(mContentResolver,
+ Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF)
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onStart() {
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final SwitchPreference switchPreference = (SwitchPreference) preference;
+ switchPreference.setVisible(isAvailable());
+ switchPreference.setChecked(
+ Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ == GAME_DRIVER_ALL_APPS);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Settings.Global.putInt(mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS,
+ (boolean) newValue ? GAME_DRIVER_ALL_APPS : GAME_DRIVER_DEFAULT);
+
+ return true;
+ }
+
+ @Override
+ public void onGameDriverContentChanged() {
+ updateState(mPreference);
+ }
+}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceController.java
new file mode 100644
index 0000000..12156df
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceController.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.widget.FooterPreference;
+
+/**
+ * Controller of footer preference for Game Driver.
+ */
+public class GameDriverFooterPreferenceController extends BasePreferenceController
+ implements GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ private final ContentResolver mContentResolver;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
+
+ private FooterPreference mPreference;
+
+ public GameDriverFooterPreferenceController(Context context) {
+ super(context, FooterPreference.KEY_FOOTER);
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ == GAME_DRIVER_OFF
+ ? AVAILABLE_UNSEARCHABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onStart() {
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setVisible(isAvailable());
+ }
+
+ @Override
+ public void onGameDriverContentChanged() {
+ updateState(mPreference);
+ }
+}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java b/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java
new file mode 100644
index 0000000..125d95b
--- /dev/null
+++ b/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarController.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.widget.SwitchWidgetController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
+
+/**
+ * Controller of global switch bar used to fully turn off Game Driver.
+ */
+public class GameDriverGlobalSwitchBarController
+ implements SwitchWidgetController.OnSwitchChangeListener,
+ GameDriverContentObserver.OnGameDriverContentChangedListener, LifecycleObserver,
+ OnStart, OnStop {
+
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
+ @VisibleForTesting
+ SwitchWidgetController mSwitchWidgetController;
+ @VisibleForTesting
+ GameDriverContentObserver mGameDriverContentObserver;
+
+ GameDriverGlobalSwitchBarController(
+ Context context, SwitchWidgetController switchWidgetController) {
+ mContext = context;
+ mContentResolver = context.getContentResolver();
+ mGameDriverContentObserver =
+ new GameDriverContentObserver(new Handler(Looper.getMainLooper()), this);
+ mSwitchWidgetController = switchWidgetController;
+ mSwitchWidgetController.setEnabled(
+ DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context));
+ mSwitchWidgetController.setChecked(
+ Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF);
+ mSwitchWidgetController.setListener(this);
+ }
+
+ @Override
+ public void onStart() {
+ mSwitchWidgetController.startListening();
+ mGameDriverContentObserver.register(mContentResolver);
+ }
+
+ @Override
+ public void onStop() {
+ mSwitchWidgetController.stopListening();
+ mGameDriverContentObserver.unregister(mContentResolver);
+ }
+
+ @Override
+ public boolean onSwitchToggled(boolean isChecked) {
+ if (!isChecked) {
+ Settings.Global.putInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ return true;
+ }
+
+ if (Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_ALL_APPS) {
+ Settings.Global.putInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onGameDriverContentChanged() {
+ mSwitchWidgetController.setChecked(
+ Settings.Global.getInt(
+ mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
+ != GAME_DRIVER_OFF);
+ }
+}
diff --git a/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceController.java b/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceController.java
deleted file mode 100644
index 43a28b6..0000000
--- a/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceController.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2019 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.gup;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.core.BasePreferenceController;
-import com.android.settingslib.development.DevelopmentSettingsEnabler;
-
-public class GupEnableForAllAppsPreferenceController
- extends BasePreferenceController implements Preference.OnPreferenceChangeListener {
- public static final int GUP_DEFAULT = 0;
- public static final int GUP_ALL_APPS = 1;
-
- private final ContentResolver mContentResolver;
-
- public GupEnableForAllAppsPreferenceController(Context context, String key) {
- super(context, key);
- mContentResolver = context.getContentResolver();
- }
-
- @Override
- public int getAvailabilityStatus() {
- return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
- ? AVAILABLE
- : DISABLED_DEPENDENT_SETTING;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- final SwitchPreference switchPreference = screen.findPreference(getPreferenceKey());
- if (switchPreference == null) {
- return;
- }
-
- switchPreference.setChecked(Settings.Global.getInt(mContentResolver,
- Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT)
- == GUP_ALL_APPS);
- switchPreference.setOnPreferenceChangeListener(this);
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- // When developer option is present, always overwrite GUP_DEV_ALL_APPS.
- Settings.Global.putInt(mContentResolver, Settings.Global.GUP_DEV_ALL_APPS,
- (boolean) newValue ? GUP_ALL_APPS : GUP_DEFAULT);
-
- return true;
- }
-}
diff --git a/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java b/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java
index b54b398..bdd76fc 100644
--- a/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java
@@ -32,11 +32,10 @@
import com.android.settings.overlay.FeatureFactory;
public class BrandedAccountPreferenceController extends BasePreferenceController {
- private static final String KEY_PREFERENCE_TITLE = "branded_account";
private final Account[] mAccounts;
- public BrandedAccountPreferenceController(Context context) {
- super(context, KEY_PREFERENCE_TITLE);
+ public BrandedAccountPreferenceController(Context context, String key) {
+ super(context, key);
final AccountFeatureProvider accountFeatureProvider = FeatureFactory.getFactory(
mContext).getAccountFeatureProvider();
mAccounts = accountFeatureProvider.getAccounts(mContext);
@@ -44,6 +43,10 @@
@Override
public int getAvailabilityStatus() {
+ if (!mContext.getResources().getBoolean(
+ R.bool.config_show_branded_account_in_device_info)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
if (mAccounts != null && mAccounts.length > 0) {
return AVAILABLE;
}
@@ -55,7 +58,7 @@
super.displayPreference(screen);
final AccountFeatureProvider accountFeatureProvider = FeatureFactory.getFactory(
mContext).getAccountFeatureProvider();
- final Preference accountPreference = screen.findPreference(KEY_PREFERENCE_TITLE);
+ final Preference accountPreference = screen.findPreference(getPreferenceKey());
if (accountPreference != null && (mAccounts == null || mAccounts.length == 0)) {
screen.removePreference(accountPreference);
return;
diff --git a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
index 0d7b1d3..fb20a2e 100644
--- a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
@@ -43,8 +43,6 @@
LifecycleObserver,
OnSaveInstanceState,
OnCreate {
- private static final String PREF_KEY = "device_name";
- public static final int DEVICE_NAME_SET_WARNING_ID = 1;
private static final String KEY_PENDING_DEVICE_NAME = "key_pending_device_name";
private String mDeviceName;
protected WifiManager mWifiManager;
@@ -54,8 +52,8 @@
private DeviceNamePreferenceHost mHost;
private String mPendingDeviceName;
- public DeviceNamePreferenceController(Context context) {
- super(context, PREF_KEY);
+ public DeviceNamePreferenceController(Context context, String key) {
+ super(context, key);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mWifiDeviceNameTextValidator = new WifiDeviceNameTextValidator();
@@ -67,7 +65,7 @@
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mPreference = (ValidatedEditTextPreference) screen.findPreference(PREF_KEY);
+ mPreference = screen.findPreference(getPreferenceKey());
final CharSequence deviceName = getSummary();
mPreference.setSummary(deviceName);
mPreference.setText(deviceName.toString());
@@ -95,11 +93,6 @@
}
@Override
- public String getPreferenceKey() {
- return PREF_KEY;
- }
-
- @Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPendingDeviceName = (String) newValue;
if (mHost != null) {
diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
index b61cb3c..0116c42 100644
--- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
+++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
@@ -28,10 +28,8 @@
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settings.accounts.EmergencyInfoPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.deviceinfo.BluetoothAddressPreferenceController;
-import com.android.settings.deviceinfo.BrandedAccountPreferenceController;
import com.android.settings.deviceinfo.BuildNumberPreferenceController;
import com.android.settings.deviceinfo.DeviceModelPreferenceController;
import com.android.settings.deviceinfo.DeviceNamePreferenceController;
@@ -82,6 +80,7 @@
use(FirmwareVersionPreferenceController.class).setHost(this /* parent */);
use(DeviceModelPreferenceController.class).setHost(this /* parent */);
use(ImeiInfoPreferenceController.class).setHost(this /* parent */);
+ use(DeviceNamePreferenceController.class).setHost(this /* parent */);
mBuildNumberPreferenceController = use(BuildNumberPreferenceController.class);
mBuildNumberPreferenceController.setHost(this /* parent */);
}
@@ -104,23 +103,12 @@
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, getActivity(), this /* fragment */,
- getSettingsLifecycle());
+ return buildPreferenceControllers(context, this /* fragment */, getSettingsLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(
- Context context, Activity activity, MyDeviceInfoFragment fragment,
- Lifecycle lifecycle) {
+ Context context, MyDeviceInfoFragment fragment, Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new EmergencyInfoPreferenceController(context));
- controllers.add(new BrandedAccountPreferenceController(context));
- DeviceNamePreferenceController deviceNamePreferenceController =
- new DeviceNamePreferenceController(context);
- deviceNamePreferenceController.setHost(fragment);
- if (lifecycle != null) {
- lifecycle.addObserver(deviceNamePreferenceController);
- }
- controllers.add(deviceNamePreferenceController);
controllers.add(new SimStatusPreferenceController(context, fragment));
controllers.add(new IpAddressPreferenceController(context, lifecycle));
controllers.add(new WifiMacAddressPreferenceController(context, lifecycle));
@@ -145,12 +133,18 @@
private void initHeader() {
// TODO: Migrate into its own controller.
final LayoutPreference headerPreference =
- (LayoutPreference) getPreferenceScreen().findPreference(KEY_MY_DEVICE_INFO_HEADER);
- final View appSnippet = headerPreference.findViewById(R.id.entity_header);
+ getPreferenceScreen().findPreference(KEY_MY_DEVICE_INFO_HEADER);
+ final boolean shouldDisplayHeader = getContext().getResources().getBoolean(
+ R.bool.config_show_device_header_in_device_info);
+ headerPreference.setVisible(shouldDisplayHeader);
+ if (!shouldDisplayHeader) {
+ return;
+ }
+ final View headerView = headerPreference.findViewById(R.id.entity_header);
final Activity context = getActivity();
final Bundle bundle = getArguments();
final EntityHeaderController controller = EntityHeaderController
- .newInstance(context, this, appSnippet)
+ .newInstance(context, this, headerView)
.setRecyclerView(getListView(), getSettingsLifecycle())
.setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
EntityHeaderController.ActionType.ACTION_NONE);
@@ -197,8 +191,8 @@
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
- return buildPreferenceControllers(context, null /* activity */,
- null /* fragment */, null /* lifecycle */);
+ return buildPreferenceControllers(context, null /* fragment */,
+ null /* lifecycle */);
}
};
}
diff --git a/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceController.java b/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceController.java
index d2ffd0d..dbee443 100644
--- a/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceController.java
@@ -35,7 +35,7 @@
@Override
public CharSequence getSummary() {
final DeviceNamePreferenceController deviceNamePreferenceController =
- new DeviceNamePreferenceController(mContext);
+ new DeviceNamePreferenceController(mContext, "dummy_key");
return deviceNamePreferenceController.getSummary();
}
}
diff --git a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
new file mode 100644
index 0000000..97bdb9e
--- /dev/null
+++ b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2019 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.display;
+
+import static android.provider.Settings.System.ADAPTIVE_SLEEP;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+
+
+public class AdaptiveSleepPreferenceController extends TogglePreferenceController {
+
+ private final String SYSTEM_KEY = ADAPTIVE_SLEEP;
+ private final int DEFAULT_VALUE = 0;
+
+ public AdaptiveSleepPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.System.getInt(mContext.getContentResolver(),
+ SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
+ isChecked ? 1 : DEFAULT_VALUE);
+ return true;
+ }
+
+ @Override
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_adaptive_sleep_available)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isSliceable() {
+ return true;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return mContext.getText(isChecked()
+ ? R.string.adaptive_sleep_summary_on
+ : R.string.adaptive_sleep_summary_off);
+ }
+}
diff --git a/src/com/android/settings/gestures/SkipGestureSettings.java b/src/com/android/settings/display/AdaptiveSleepSettings.java
similarity index 68%
rename from src/com/android/settings/gestures/SkipGestureSettings.java
rename to src/com/android/settings/display/AdaptiveSleepSettings.java
index 7d1090b..097d7dc 100644
--- a/src/com/android/settings/gestures/SkipGestureSettings.java
+++ b/src/com/android/settings/display/AdaptiveSleepSettings.java
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-package com.android.settings.gestures;
+package com.android.settings.display;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.os.Bundle;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
@@ -28,14 +29,21 @@
import java.util.Arrays;
import java.util.List;
-@SearchIndexable
-public class SkipGestureSettings extends DashboardFragment {
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class AdaptiveSleepSettings extends DashboardFragment {
- private static final String TAG = "SkipGestureSettings";
+ private static final String TAG = "AdaptiveSleepSettings";
@Override
- public int getMetricsCategory() {
- return SettingsEnums.SETTINGS_GESTURE_SKIP;
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ mFooterPreferenceMixin.createFooterPreference()
+ .setTitle(R.string.adaptive_sleep_description);
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.adaptive_sleep_detail;
}
@Override
@@ -44,8 +52,13 @@
}
@Override
- protected int getPreferenceScreenResId() {
- return R.xml.skip_gesture_settings;
+ public int getMetricsCategory() {
+ return SettingsEnums.SETTINGS_ADAPTIVE_SLEEP;
+ }
+
+ @Override
+ public int getHelpResource() {
+ return R.string.help_url_adaptive_sleep;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -54,10 +67,8 @@
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.skip_gesture_settings;
+ sir.xmlResId = R.xml.adaptive_sleep_detail;
return Arrays.asList(sir);
}
};
-
}
-
diff --git a/src/com/android/settings/fuelgauge/BatteryEntry.java b/src/com/android/settings/fuelgauge/BatteryEntry.java
index a93d522..c91cc8f 100644
--- a/src/com/android/settings/fuelgauge/BatteryEntry.java
+++ b/src/com/android/settings/fuelgauge/BatteryEntry.java
@@ -157,7 +157,7 @@
break;
case BLUETOOTH:
name = context.getResources().getString(R.string.power_bluetooth);
- iconId = R.drawable.ic_settings_bluetooth;
+ iconId = com.android.internal.R.drawable.ic_settings_bluetooth;
break;
case SCREEN:
name = context.getResources().getString(R.string.power_screen);
diff --git a/src/com/android/settings/gestures/SilenceGesturePreferenceController.java b/src/com/android/settings/gestures/SilenceGesturePreferenceController.java
deleted file mode 100644
index 8059304..0000000
--- a/src/com/android/settings/gestures/SilenceGesturePreferenceController.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2019 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.gestures;
-
-import static android.provider.Settings.Secure.SILENCE_GESTURE;
-
-import android.content.Context;
-import android.provider.Settings;
-import android.text.TextUtils;
-
-public class SilenceGesturePreferenceController extends GesturePreferenceController {
-
- private static final int ON = 1;
- private static final int OFF = 0;
-
- private static final String PREF_KEY_VIDEO = "gesture_silence_video";
-
- public SilenceGesturePreferenceController(Context context, String key) {
- super(context, key);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return mContext.getResources()
- .getBoolean(com.android.internal.R.bool.config_silenceSensorAvailable)
- ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
- }
-
- @Override
- public boolean isSliceable() {
- return true;
- }
-
- @Override
- protected String getVideoPrefKey() {
- return PREF_KEY_VIDEO;
- }
-
- @Override
- public boolean isChecked() {
- return Settings.Secure.getInt(mContext.getContentResolver(), SILENCE_GESTURE, ON) == ON;
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- return Settings.Secure.putInt(mContext.getContentResolver(), SILENCE_GESTURE,
- isChecked ? ON : OFF);
- }
-}
diff --git a/src/com/android/settings/gestures/SilenceGestureSettings.java b/src/com/android/settings/gestures/SilenceGestureSettings.java
deleted file mode 100644
index e4acab7..0000000
--- a/src/com/android/settings/gestures/SilenceGestureSettings.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2019 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.gestures;
-
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.provider.SearchIndexableResource;
-
-import com.android.settings.R;
-import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.search.SearchIndexable;
-
-import java.util.Arrays;
-import java.util.List;
-
-@SearchIndexable
-public class SilenceGestureSettings extends DashboardFragment {
-
- private static final String TAG = "SilenceGestureSettings";
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.SETTINGS_GESTURE_SILENCE;
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.silence_gesture_settings;
- }
-
- public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(
- Context context, boolean enabled) {
- final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.silence_gesture_settings;
- return Arrays.asList(sir);
- }
- };
-
-}
diff --git a/src/com/android/settings/gestures/SkipGesturePreferenceController.java b/src/com/android/settings/gestures/SkipGesturePreferenceController.java
deleted file mode 100644
index d1c0a03..0000000
--- a/src/com/android/settings/gestures/SkipGesturePreferenceController.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2019 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.gestures;
-
-import static android.provider.Settings.Secure.SKIP_GESTURE;
-
-import android.content.Context;
-import android.provider.Settings;
-import android.text.TextUtils;
-
-public class SkipGesturePreferenceController extends GesturePreferenceController {
-
- private static final int ON = 1;
- private static final int OFF = 0;
-
- private static final String PREF_KEY_VIDEO = "gesture_silence_video";
-
- public SkipGesturePreferenceController(Context context, String key) {
- super(context, key);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return mContext.getResources()
- .getBoolean(com.android.internal.R.bool.config_skipSensorAvailable) ? AVAILABLE
- : UNSUPPORTED_ON_DEVICE;
- }
-
- @Override
- public boolean isSliceable() {
- return true;
- }
-
- @Override
- protected String getVideoPrefKey() {
- return PREF_KEY_VIDEO;
- }
-
- @Override
- public boolean isChecked() {
- return Settings.Secure.getInt(mContext.getContentResolver(), SKIP_GESTURE, ON) == ON;
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- return Settings.Secure.putInt(mContext.getContentResolver(), SKIP_GESTURE,
- isChecked ? ON : OFF);
- }
-}
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
index 1f2e89b..e11ce30 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
@@ -80,6 +80,10 @@
LegacySuggestionContextualCardController.class,
LegacySuggestionContextualCardRenderer.class));
add(new ControllerRendererMapping(CardType.SLICE,
+ SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP,
+ SliceContextualCardController.class,
+ SliceContextualCardRenderer.class));
+ add(new ControllerRendererMapping(CardType.SLICE,
SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH,
SliceContextualCardController.class,
SliceContextualCardRenderer.class));
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
index 7a2c2e9..b35a38a 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
@@ -17,6 +17,7 @@
package com.android.settings.homepage.contextualcards;
import static com.android.settings.homepage.contextualcards.ContextualCardLoader.CARD_CONTENT_LOADER_ID;
+import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE;
import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE;
import static java.util.stream.Collectors.groupingBy;
@@ -71,17 +72,15 @@
@VisibleForTesting
final List<ContextualCard> mContextualCards;
+ private final Context mContext;
+ private final ControllerRendererPool mControllerRendererPool;
+ private final Lifecycle mLifecycle;
+ private final List<LifecycleObserver> mLifecycleObservers;
@VisibleForTesting
long mStartTime;
boolean mIsFirstLaunch;
@VisibleForTesting
List<String> mSavedCards;
-
- private final Context mContext;
- private final ControllerRendererPool mControllerRendererPool;
- private final Lifecycle mLifecycle;
- private final List<LifecycleObserver> mLifecycleObservers;
-
private ContextualCardUpdateListener mListener;
public ContextualCardManager(Context context, Lifecycle lifecycle, Bundle savedInstanceState) {
@@ -175,7 +174,7 @@
//replace with the new data
mContextualCards.clear();
final List<ContextualCard> sortedCards = sortCards(allCards);
- mContextualCards.addAll(assignCardWidth(sortedCards));
+ mContextualCards.addAll(getCardsWithViewType(sortedCards));
loadCardControllers();
@@ -228,10 +227,19 @@
}
@VisibleForTesting
- List<ContextualCard> assignCardWidth(List<ContextualCard> cards) {
- final List<ContextualCard> result = new ArrayList<>(cards);
+ List<ContextualCard> getCardsWithViewType(List<ContextualCard> cards) {
+ if (cards.isEmpty()) {
+ return cards;
+ }
+
+ final List<ContextualCard> result = getCardsWithDeferredSetupViewType(cards);
+ return getCardsWithSuggestionViewType(result);
+ }
+
+ private List<ContextualCard> getCardsWithSuggestionViewType(List<ContextualCard> cards) {
// Shows as half cards if 2 suggestion type of cards are next to each other.
// Shows as full card if 1 suggestion type of card lives alone.
+ final List<ContextualCard> result = new ArrayList<>(cards);
for (int index = 1; index < result.size(); index++) {
final ContextualCard previous = result.get(index - 1);
final ContextualCard current = result.get(index);
@@ -247,6 +255,22 @@
return result;
}
+ private List<ContextualCard> getCardsWithDeferredSetupViewType(List<ContextualCard> cards) {
+ // Find the deferred setup card and assign it with proper view type.
+ // Reason: The returned card list will mix deferred setup card and other suggestion cards
+ // after device running 1 days.
+ final List<ContextualCard> result = new ArrayList<>(cards);
+ for (int index = 0; index < result.size(); index++) {
+ final ContextualCard card = cards.get(index);
+ if (card.getCategory() == DEFERRED_SETUP_VALUE) {
+ result.set(index, card.mutate().setViewType(
+ SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP).build());
+ return result;
+ }
+ }
+ return result;
+ }
+
private List<ContextualCard> getCardsToKeep(List<ContextualCard> cards) {
if (mSavedCards != null) {
//screen rotate
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
index 03868ee..ea2a308 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
@@ -103,7 +103,7 @@
@Override
public Slice getSlice() {
final IconCompat icon = IconCompat.createWithResource(mContext,
- R.drawable.ic_settings_bluetooth);
+ com.android.internal.R.drawable.ic_settings_bluetooth);
final CharSequence title = mContext.getText(R.string.bluetooth_devices);
final CharSequence titleNoBluetoothDevices = mContext.getText(
R.string.no_bluetooth_devices);
@@ -236,7 +236,8 @@
if (pair.first != null) {
return IconCompat.createWithBitmap(getBitmapFromVectorDrawable(pair.first));
} else {
- return IconCompat.createWithResource(mContext, R.drawable.ic_settings_bluetooth);
+ return IconCompat.createWithResource(mContext,
+ com.android.internal.R.drawable.ic_settings_bluetooth);
}
}
@@ -303,4 +304,4 @@
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
index 66e0465..2d40efe 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java
@@ -52,6 +52,7 @@
public class SliceContextualCardRenderer implements ContextualCardRenderer, LifecycleObserver {
public static final int VIEW_TYPE_FULL_WIDTH = R.layout.homepage_slice_tile;
public static final int VIEW_TYPE_HALF_WIDTH = R.layout.homepage_slice_half_tile;
+ public static final int VIEW_TYPE_DEFERRED_SETUP = R.layout.homepage_slice_deferred_setup_tile;
private static final String TAG = "SliceCardRenderer";
@@ -64,6 +65,7 @@
private final LifecycleOwner mLifecycleOwner;
private final ControllerRendererPool mControllerRendererPool;
private final Set<ContextualCard> mCardSet;
+ private final SliceDeferredSetupCardRendererHelper mDeferredSetupCardHelper;
private final SliceFullCardRendererHelper mFullCardHelper;
private final SliceHalfCardRendererHelper mHalfCardHelper;
@@ -78,11 +80,14 @@
mLifecycleOwner.getLifecycle().addObserver(this);
mFullCardHelper = new SliceFullCardRendererHelper(context);
mHalfCardHelper = new SliceHalfCardRendererHelper(context);
+ mDeferredSetupCardHelper = new SliceDeferredSetupCardRendererHelper(context);
}
@Override
public RecyclerView.ViewHolder createViewHolder(View view, @LayoutRes int viewType) {
switch (viewType) {
+ case VIEW_TYPE_DEFERRED_SETUP:
+ return mDeferredSetupCardHelper.createViewHolder(view);
case VIEW_TYPE_HALF_WIDTH:
return mHalfCardHelper.createViewHolder(view);
default:
@@ -119,17 +124,25 @@
//TODO(b/120629936): Take this out once blank card issue is fixed.
Log.d(TAG, "Slice callback - uri = " + slice.getUri());
}
- if (holder.getItemViewType() == VIEW_TYPE_HALF_WIDTH) {
- mHalfCardHelper.bindView(holder, card, slice);
- } else {
- mFullCardHelper.bindView(holder, card, slice, mCardSet);
+ switch (holder.getItemViewType()) {
+ case VIEW_TYPE_DEFERRED_SETUP:
+ mDeferredSetupCardHelper.bindView(holder, card, slice);
+ break;
+ case VIEW_TYPE_HALF_WIDTH:
+ mHalfCardHelper.bindView(holder, card, slice);
+ break;
+ default:
+ mFullCardHelper.bindView(holder, card, slice, mCardSet);
}
});
- if (holder.getItemViewType() == VIEW_TYPE_HALF_WIDTH) {
- initDismissalActions(holder, card, R.id.content);
- } else {
- initDismissalActions(holder, card, R.id.slice_view);
+ switch (holder.getItemViewType()) {
+ case VIEW_TYPE_DEFERRED_SETUP:
+ case VIEW_TYPE_HALF_WIDTH:
+ initDismissalActions(holder, card, R.id.content);
+ break;
+ default:
+ initDismissalActions(holder, card, R.id.slice_view);
}
}
diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelper.java b/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelper.java
new file mode 100644
index 0000000..d0d51e7
--- /dev/null
+++ b/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelper.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2019 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.homepage.contextualcards.slices;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.slice.Slice;
+import androidx.slice.SliceMetadata;
+import androidx.slice.core.SliceAction;
+import androidx.slice.widget.EventInfo;
+
+import com.android.settings.R;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
+
+/**
+ * Card renderer helper for {@link ContextualCard} built as slice deferred setup card.
+ */
+class SliceDeferredSetupCardRendererHelper {
+ private static final String TAG = "SliceDSCRendererHelper";
+
+ private final Context mContext;
+
+ SliceDeferredSetupCardRendererHelper(Context context) {
+ mContext = context;
+ }
+
+ RecyclerView.ViewHolder createViewHolder(View view) {
+ return new DeferredSetupCardViewHolder(view);
+ }
+
+ void bindView(RecyclerView.ViewHolder holder, ContextualCard card, Slice slice) {
+ final DeferredSetupCardViewHolder view = (DeferredSetupCardViewHolder) holder;
+ final SliceMetadata sliceMetadata = SliceMetadata.from(mContext, slice);
+ final SliceAction primaryAction = sliceMetadata.getPrimaryAction();
+ view.icon.setImageDrawable(primaryAction.getIcon().loadDrawable(mContext));
+ view.title.setText(primaryAction.getTitle());
+ view.summary.setText(sliceMetadata.getSubtitle());
+ view.button.setOnClickListener(v -> {
+ try {
+ primaryAction.getAction().send();
+ } catch (PendingIntent.CanceledException e) {
+ Log.w(TAG, "Failed to start intent " + primaryAction.getTitle());
+ }
+ final ContextualCardFeatureProvider contextualCardFeatureProvider =
+ FeatureFactory.getFactory(mContext).getContextualCardFeatureProvider(mContext);
+ contextualCardFeatureProvider.logContextualCardClick(card, 0 /* row */,
+ EventInfo.ACTION_TYPE_CONTENT);
+ });
+ }
+
+ static class DeferredSetupCardViewHolder extends RecyclerView.ViewHolder {
+ public final LinearLayout content;
+ public final ImageView icon;
+ public final TextView title;
+ public final TextView summary;
+ public final Button button;
+
+ public DeferredSetupCardViewHolder(View itemView) {
+ super(itemView);
+ content = itemView.findViewById(R.id.content);
+ icon = itemView.findViewById(android.R.id.icon);
+ title = itemView.findViewById(android.R.id.title);
+ summary = itemView.findViewById(android.R.id.summary);
+ button = itemView.findViewById(R.id.finish_setup);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/location/LocationSlice.java b/src/com/android/settings/location/LocationSlice.java
index e2078e3..2759690 100644
--- a/src/com/android/settings/location/LocationSlice.java
+++ b/src/com/android/settings/location/LocationSlice.java
@@ -55,7 +55,7 @@
@Override
public Slice getSlice() {
final IconCompat icon = IconCompat.createWithResource(mContext,
- R.drawable.ic_signal_location);
+ com.android.internal.R.drawable.ic_signal_location);
final CharSequence title = mContext.getText(R.string.location_settings_title);
@ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
final PendingIntent primaryAction = getPrimaryAction();
diff --git a/src/com/android/settings/media/MediaDeviceUpdateWorker.java b/src/com/android/settings/media/MediaDeviceUpdateWorker.java
new file mode 100644
index 0000000..7416018
--- /dev/null
+++ b/src/com/android/settings/media/MediaDeviceUpdateWorker.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2019 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.media;
+
+import android.content.Context;
+import android.net.Uri;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.slices.SliceBackgroundWorker;
+import com.android.settingslib.media.LocalMediaManager;
+import com.android.settingslib.media.MediaDevice;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SliceBackgroundWorker for get MediaDevice list and handle MediaDevice state change event.
+ */
+public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
+ implements LocalMediaManager.DeviceCallback {
+
+ private final Context mContext;
+ private final List<MediaDevice> mMediaDevices = new ArrayList<>();
+
+ private String mPackageName;
+
+ @VisibleForTesting
+ LocalMediaManager mLocalMediaManager;
+
+ public MediaDeviceUpdateWorker(Context context, Uri uri) {
+ super(context, uri);
+ mContext = context;
+ }
+
+ public void setPackageName(String packageName) {
+ mPackageName = packageName;
+ }
+
+ @Override
+ protected void onSlicePinned() {
+ mMediaDevices.clear();
+ if (mLocalMediaManager == null) {
+ mLocalMediaManager = new LocalMediaManager(mContext, mPackageName, null);
+ }
+
+ mLocalMediaManager.registerCallback(this);
+ mLocalMediaManager.startScan();
+ }
+
+ @Override
+ protected void onSliceUnpinned() {
+ mLocalMediaManager.unregisterCallback(this);
+ mLocalMediaManager.stopScan();
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public void onDeviceListUpdate(List<MediaDevice> devices) {
+ buildMediaDevices(devices);
+ notifySliceChange();
+ }
+
+ private void buildMediaDevices(List<MediaDevice> devices) {
+ mMediaDevices.clear();
+ mMediaDevices.addAll(devices);
+ }
+
+ @Override
+ public void onSelectedDeviceStateChanged(MediaDevice device, int state) {
+ notifySliceChange();
+ }
+
+ public List<MediaDevice> getMediaDevices() {
+ return new ArrayList<>(mMediaDevices);
+ }
+
+ public void connectDevice(MediaDevice device) {
+ mLocalMediaManager.connectDevice(device);
+ }
+
+ public MediaDevice getMediaDeviceById(String id) {
+ return mLocalMediaManager.getMediaDeviceById(mMediaDevices, id);
+ }
+
+ public MediaDevice getCurrentConnectedMediaDevice() {
+ return mLocalMediaManager.getCurrentConnectedDevice();
+ }
+}
diff --git a/src/com/android/settings/media/MediaOutputSlice.java b/src/com/android/settings/media/MediaOutputSlice.java
new file mode 100644
index 0000000..5c5eb88
--- /dev/null
+++ b/src/com/android/settings/media/MediaOutputSlice.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2019 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.media;
+
+import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
+
+import android.annotation.ColorInt;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.os.UserHandle;
+import android.util.IconDrawableFactory;
+import android.util.Log;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.slice.Slice;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.slices.CustomSliceable;
+import com.android.settings.slices.SliceBackgroundWorker;
+import com.android.settings.slices.SliceBroadcastReceiver;
+import com.android.settingslib.media.MediaDevice;
+
+import java.util.List;
+
+/**
+ * Show the Media device that can be transfer the media.
+ */
+public class MediaOutputSlice implements CustomSliceable {
+
+ private static final String TAG = "MediaOutputSlice";
+ private static final String MEDIA_DEVICE_ID = "media_device_id";
+
+ public static final String MEDIA_PACKAGE_NAME = "media_package_name";
+
+ private final Context mContext;
+
+ private MediaDeviceUpdateWorker mWorker;
+ private String mPackageName;
+ private IconDrawableFactory mIconDrawableFactory;
+
+ public MediaOutputSlice(Context context) {
+ mContext = context;
+ mPackageName = getUri().getQueryParameter(MEDIA_PACKAGE_NAME);
+ mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
+ }
+
+ @VisibleForTesting
+ void init(String packageName, MediaDeviceUpdateWorker worker, IconDrawableFactory factory) {
+ mPackageName = packageName;
+ mWorker = worker;
+ mIconDrawableFactory = factory;
+ }
+
+ @Override
+ public Slice getSlice() {
+ final PackageManager pm = mContext.getPackageManager();
+
+ final List<MediaDevice> devices = getMediaDevices();
+ final CharSequence title = Utils.getApplicationLabel(mContext, mPackageName);
+ final CharSequence summary =
+ mContext.getString(R.string.media_output_panel_summary_of_playing_device,
+ getConnectedDeviceName());
+
+ final Drawable drawable =
+ Utils.getBadgedIcon(mIconDrawableFactory, pm, mPackageName, UserHandle.myUserId());
+ final IconCompat icon = IconCompat.createWithBitmap(getBitmapFromDrawable(drawable));
+
+ @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
+ final SliceAction primarySliceAction = SliceAction.createDeeplink(getPrimaryAction(), icon,
+ ListBuilder.ICON_IMAGE, title);
+
+ final ListBuilder listBuilder = new ListBuilder(mContext, MEDIA_OUTPUT_SLICE_URI,
+ ListBuilder.INFINITY)
+ .setAccentColor(color)
+ .addRow(new ListBuilder.RowBuilder()
+ .setTitleItem(icon, ListBuilder.ICON_IMAGE)
+ .setTitle(title)
+ .setSubtitle(summary)
+ .setPrimaryAction(primarySliceAction));
+
+ for (MediaDevice device : devices) {
+ listBuilder.addRow(getMediaDeviceRow(device));
+ }
+
+ return listBuilder.build();
+ }
+
+ private MediaDeviceUpdateWorker getWorker() {
+ if (mWorker == null) {
+ mWorker = (MediaDeviceUpdateWorker) SliceBackgroundWorker.getInstance(getUri());
+ mWorker.setPackageName(mPackageName);
+ }
+ return mWorker;
+ }
+
+ private List<MediaDevice> getMediaDevices() {
+ List<MediaDevice> devices = getWorker().getMediaDevices();
+ return devices;
+ }
+
+ private String getConnectedDeviceName() {
+ final MediaDevice device = getWorker().getCurrentConnectedMediaDevice();
+ return device != null ? device.getName() : "";
+ }
+
+ private PendingIntent getPrimaryAction() {
+ final PackageManager pm = mContext.getPackageManager();
+ final Intent launchIntent = pm.getLaunchIntentForPackage(mPackageName);
+ final Intent intent = launchIntent;
+ return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
+ }
+
+ private Bitmap getBitmapFromDrawable(Drawable drawable) {
+ final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
+ drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
+ final Canvas canvas = new Canvas(bitmap);
+
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+
+ return bitmap;
+ }
+
+ private ListBuilder.RowBuilder getMediaDeviceRow(MediaDevice device) {
+ final String title = device.getName();
+ final PendingIntent broadcastAction =
+ getBroadcastIntent(mContext, device.getId(), device.hashCode());
+ final IconCompat deviceIcon = IconCompat.createWithResource(mContext, device.getIcon());
+ final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
+ .setTitleItem(deviceIcon, ListBuilder.ICON_IMAGE)
+ .setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon,
+ ListBuilder.ICON_IMAGE, title))
+ .setTitle(title);
+
+ return rowBuilder;
+ }
+
+ private PendingIntent getBroadcastIntent(Context context, String id, int requestCode) {
+ final Intent intent = new Intent(getUri().toString());
+ intent.setClass(context, SliceBroadcastReceiver.class);
+ intent.putExtra(MEDIA_DEVICE_ID, id);
+ return PendingIntent.getBroadcast(context, requestCode /* requestCode */, intent,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ }
+
+ @Override
+ public Uri getUri() {
+ return MEDIA_OUTPUT_SLICE_URI;
+ }
+
+ @Override
+ public void onNotifyChange(Intent intent) {
+ final MediaDeviceUpdateWorker worker = getWorker();
+ final String id = intent != null ? intent.getStringExtra(MEDIA_DEVICE_ID) : "";
+ final MediaDevice device = worker.getMediaDeviceById(id);
+ if (device != null) {
+ Log.d(TAG, "onNotifyChange() device name : " + device.getName());
+ worker.connectDevice(device);
+ }
+ }
+
+ @Override
+ public Intent getIntent() {
+ return null;
+ }
+
+ @Override
+ public Class getBackgroundWorkerClass() {
+ return MediaDeviceUpdateWorker.class;
+ }
+}
diff --git a/src/com/android/settings/notification/ZenRuleButtonsPreferenceController.java b/src/com/android/settings/notification/ZenRuleButtonsPreferenceController.java
index a773908..a014ec9 100644
--- a/src/com/android/settings/notification/ZenRuleButtonsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenRuleButtonsPreferenceController.java
@@ -62,7 +62,7 @@
if (isAvailable()) {
mButtonsPref = ((ActionButtonsPreference) screen.findPreference(KEY))
.setButton1Text(R.string.zen_mode_rule_name_edit)
- .setButton1Icon(R.drawable.ic_mode_edit)
+ .setButton1Icon(com.android.internal.R.drawable.ic_mode_edit)
.setButton1OnClickListener(new EditRuleNameClickListener())
.setButton2Text(R.string.zen_mode_delete_rule_button)
.setButton2Icon(R.drawable.ic_settings_delete)
diff --git a/src/com/android/settings/panel/MediaOutputPanel.java b/src/com/android/settings/panel/MediaOutputPanel.java
new file mode 100644
index 0000000..f7639d9
--- /dev/null
+++ b/src/com/android/settings/panel/MediaOutputPanel.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2019 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.panel;
+
+import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
+import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
+
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+
+import com.android.settings.R;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents the Media output Panel.
+ *
+ * <p>
+ * Displays Media output item
+ * </p>
+ */
+public class MediaOutputPanel implements PanelContent {
+
+ private final Context mContext;
+ private final String mPackageName;
+
+ public static MediaOutputPanel create(Context context, String packageName) {
+ return new MediaOutputPanel(context, packageName);
+ }
+
+ private MediaOutputPanel(Context context, String packageName) {
+ mContext = context.getApplicationContext();
+ mPackageName = packageName;
+ }
+
+ @Override
+ public CharSequence getTitle() {
+ return mContext.getText(R.string.media_output_panel_title);
+ }
+
+ @Override
+ public List<Uri> getSlices() {
+ final List<Uri> uris = new ArrayList<>();
+ MEDIA_OUTPUT_SLICE_URI =
+ MEDIA_OUTPUT_SLICE_URI
+ .buildUpon()
+ .clearQuery()
+ .appendQueryParameter(MEDIA_PACKAGE_NAME, mPackageName)
+ .build();
+ uris.add(MEDIA_OUTPUT_SLICE_URI);
+ return uris;
+ }
+
+ @Override
+ public Intent getSeeMoreIntent() {
+ return null;
+ }
+}
diff --git a/src/com/android/settings/panel/PanelFeatureProvider.java b/src/com/android/settings/panel/PanelFeatureProvider.java
index 7d6c558..5af5ac8 100644
--- a/src/com/android/settings/panel/PanelFeatureProvider.java
+++ b/src/com/android/settings/panel/PanelFeatureProvider.java
@@ -21,7 +21,7 @@
public interface PanelFeatureProvider {
/**
- * Returns {@link PanelContent} as specified by the {@param panelType}.
+ * Returns {@link PanelContent} as specified by the {@code panelType} and {@code packageName}.
*/
- PanelContent getPanel(Context context, String panelType);
+ PanelContent getPanel(Context context, String panelType, String packageName);
}
diff --git a/src/com/android/settings/panel/PanelFeatureProviderImpl.java b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
index b4c37bf..c3d611d 100644
--- a/src/com/android/settings/panel/PanelFeatureProviderImpl.java
+++ b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
@@ -16,13 +16,15 @@
package com.android.settings.panel;
+import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
+
import android.content.Context;
import android.provider.Settings;
public class PanelFeatureProviderImpl implements PanelFeatureProvider {
@Override
- public PanelContent getPanel(Context context, String panelType) {
+ public PanelContent getPanel(Context context, String panelType, String packageName) {
switch (panelType) {
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
return InternetConnectivityPanel.create(context);
@@ -30,6 +32,8 @@
return VolumePanel.create(context);
case Settings.Panel.ACTION_NFC:
return NfcPanel.create(context);
+ case ACTION_MEDIA_OUTPUT:
+ return MediaOutputPanel.create(context, packageName);
}
throw new IllegalStateException("No matching panel for: " + panelType);
diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java
index 3d302fc..db0bf0e 100644
--- a/src/com/android/settings/panel/PanelFragment.java
+++ b/src/com/android/settings/panel/PanelFragment.java
@@ -70,10 +70,12 @@
final Bundle arguments = getArguments();
final String panelType = arguments.getString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT);
+ final String packageName =
+ arguments.getString(SettingsPanelActivity.KEY_PANEL_PACKAGE_NAME);
final PanelContent panel = FeatureFactory.getFactory(activity)
.getPanelFeatureProvider()
- .getPanel(activity, panelType);
+ .getPanel(activity, panelType, packageName);
mAdapter = new PanelSlicesAdapter(this, panel.getSlices());
@@ -86,6 +88,11 @@
mSeeMoreButton.setOnClickListener(getSeeMoreListener(panel.getSeeMoreIntent()));
mDoneButton.setOnClickListener(mDoneButtonListener);
+ //If getSeeMoreIntent() is null, hide the mSeeMoreButton.
+ if (panel.getSeeMoreIntent() == null) {
+ mSeeMoreButton.setVisibility(View.GONE);
+ }
+
return view;
}
diff --git a/src/com/android/settings/panel/SettingsPanelActivity.java b/src/com/android/settings/panel/SettingsPanelActivity.java
index 02e14e8..4cf535e 100644
--- a/src/com/android/settings/panel/SettingsPanelActivity.java
+++ b/src/com/android/settings/panel/SettingsPanelActivity.java
@@ -16,8 +16,12 @@
package com.android.settings.panel;
+import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
+import static com.android.settingslib.media.MediaOutputSliceConstants.EXTRA_PACKAGE_NAME;
+
import android.content.Intent;
import android.os.Bundle;
+import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
@@ -28,6 +32,7 @@
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
/**
@@ -37,10 +42,14 @@
private final String TAG = "panel_activity";
+ @VisibleForTesting
+ final Bundle mBundle = new Bundle();
+
/**
* Key specifying which Panel the app is requesting.
*/
public static final String KEY_PANEL_TYPE_ARGUMENT = "PANEL_TYPE_ARGUMENT";
+ public static final String KEY_PANEL_PACKAGE_NAME = "PANEL_PACKAGE_NAME";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -53,6 +62,16 @@
return;
}
+ final String packageName =
+ callingIntent.getStringExtra(EXTRA_PACKAGE_NAME);
+
+ if (TextUtils.equals(ACTION_MEDIA_OUTPUT, callingIntent.getAction())
+ && TextUtils.isEmpty(packageName)) {
+ Log.e(TAG, "Null package name, closing Panel Activity");
+ finish();
+ return;
+ }
+
setContentView(R.layout.settings_panel);
// Move the window to the bottom of screen, and make it take up the entire screen width.
@@ -61,11 +80,11 @@
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT);
- final Bundle bundle = new Bundle();
- bundle.putString(KEY_PANEL_TYPE_ARGUMENT, callingIntent.getAction());
+ mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, callingIntent.getAction());
+ mBundle.putString(KEY_PANEL_PACKAGE_NAME, packageName);
final PanelFragment panelFragment = new PanelFragment();
- panelFragment.setArguments(bundle);
+ panelFragment.setArguments(mBundle);
final FragmentManager fragmentManager = getSupportFragmentManager();
final Fragment fragment = fragmentManager.findFragmentById(R.id.main_content);
diff --git a/src/com/android/settings/slices/CustomSliceManager.java b/src/com/android/settings/slices/CustomSliceManager.java
index 8d07276..3786c5c 100644
--- a/src/com/android/settings/slices/CustomSliceManager.java
+++ b/src/com/android/settings/slices/CustomSliceManager.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.net.Uri;
+import android.text.TextUtils;
import android.util.ArrayMap;
import androidx.annotation.VisibleForTesting;
@@ -33,6 +34,7 @@
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
import com.android.settings.homepage.contextualcards.slices.NotificationChannelSlice;
import com.android.settings.location.LocationSlice;
+import com.android.settings.media.MediaOutputSlice;
import com.android.settings.wifi.slice.ContextualWifiSlice;
import com.android.settings.wifi.slice.WifiSlice;
@@ -65,20 +67,25 @@
* the only thing that should be needed to create the object.
*/
public CustomSliceable getSliceableFromUri(Uri uri) {
- if (mSliceableCache.containsKey(uri)) {
- return mSliceableCache.get(uri);
+ final Uri newUri = removeParameterFromUri(uri);
+ if (mSliceableCache.containsKey(newUri)) {
+ return mSliceableCache.get(newUri);
}
- final Class clazz = mUriMap.get(uri);
+ final Class clazz = mUriMap.get(newUri);
if (clazz == null) {
throw new IllegalArgumentException("No Slice found for uri: " + uri);
}
final CustomSliceable sliceable = CustomSliceable.createInstance(mContext, clazz);
- mSliceableCache.put(uri, sliceable);
+ mSliceableCache.put(newUri, sliceable);
return sliceable;
}
+ private Uri removeParameterFromUri(Uri uri) {
+ return uri != null ? uri.buildUpon().clearQuery().build() : null;
+ }
+
/**
* Return a {@link CustomSliceable} associated to the Action.
* <p>
@@ -94,7 +101,7 @@
* {@link CustomSliceManager}.
*/
public boolean isValidUri(Uri uri) {
- return mUriMap.containsKey(uri);
+ return mUriMap.containsKey(removeParameterFromUri(uri));
}
/**
@@ -120,5 +127,6 @@
NotificationChannelSlice.class);
mUriMap.put(CustomSliceRegistry.STORAGE_SLICE_URI, StorageSlice.class);
mUriMap.put(CustomSliceRegistry.WIFI_SLICE_URI, WifiSlice.class);
+ mUriMap.put(CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI, MediaOutputSlice.class);
}
}
diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java
index 3a213df..66e85c0 100644
--- a/src/com/android/settings/slices/CustomSliceRegistry.java
+++ b/src/com/android/settings/slices/CustomSliceRegistry.java
@@ -27,6 +27,7 @@
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
+import com.android.settingslib.media.MediaOutputSliceConstants;
/**
* A registry of custom slice Uris.
@@ -255,4 +256,14 @@
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath(ZEN_MODE_KEY)
.build();
+
+ /**
+ * Backing Uri for the Media output Slice.
+ */
+ public static Uri MEDIA_OUTPUT_SLICE_URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+ .appendPath(MediaOutputSliceConstants.KEY_MEDIA_OUTPUT)
+ .build();
}
diff --git a/src/com/android/settings/vpn2/AppDialogFragment.java b/src/com/android/settings/vpn2/AppDialogFragment.java
index 0d0022f..2f9cd7a 100644
--- a/src/com/android/settings/vpn2/AppDialogFragment.java
+++ b/src/com/android/settings/vpn2/AppDialogFragment.java
@@ -164,7 +164,8 @@
final int userId = getUserId();
try {
if (mPackageInfo.packageName.equals(VpnUtils.getConnectedPackage(mService, userId))) {
- mService.setAlwaysOnVpnPackage(userId, null, /* lockdownEnabled */ false);
+ mService.setAlwaysOnVpnPackage(userId, null, /* lockdownEnabled */ false,
+ /* lockdownWhitelist */ null);
mService.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
}
} catch (RemoteException e) {
diff --git a/src/com/android/settings/vpn2/AppManagementFragment.java b/src/com/android/settings/vpn2/AppManagementFragment.java
index 1571216..5f46446 100644
--- a/src/com/android/settings/vpn2/AppManagementFragment.java
+++ b/src/com/android/settings/vpn2/AppManagementFragment.java
@@ -225,7 +225,7 @@
private boolean setAlwaysOnVpn(boolean isEnabled, boolean isLockdown) {
return mConnectivityManager.setAlwaysOnVpnPackageForUser(mUserId,
- isEnabled ? mPackageName : null, isLockdown);
+ isEnabled ? mPackageName : null, isLockdown, /* lockdownWhitelist */ null);
}
private void updateUI() {
diff --git a/src/com/android/settings/vpn2/ConfigDialogFragment.java b/src/com/android/settings/vpn2/ConfigDialogFragment.java
index b72508e..c032fe5 100644
--- a/src/com/android/settings/vpn2/ConfigDialogFragment.java
+++ b/src/com/android/settings/vpn2/ConfigDialogFragment.java
@@ -176,7 +176,7 @@
final ConnectivityManager conn = ConnectivityManager.from(mContext);
conn.setAlwaysOnVpnPackageForUser(UserHandle.myUserId(), null,
- /* lockdownEnabled */ false);
+ /* lockdownEnabled */ false, /* lockdownWhitelist */ null);
VpnUtils.setLockdownVpn(mContext, profile.key);
} else {
// update only if lockdown vpn has been changed
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index c110107..2714859 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -344,7 +344,7 @@
if (mEditOnClickListener == null) {
button.setVisibility(View.GONE);
} else {
- button.setImageResource(R.drawable.ic_mode_edit);
+ button.setImageResource(com.android.internal.R.drawable.ic_mode_edit);
button.setVisibility(View.VISIBLE);
button.setOnClickListener(mEditOnClickListener);
}
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index 5ac0d28..ec43b0f 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -101,7 +101,7 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
- item.setIcon(R.drawable.ic_mode_edit);
+ item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
super.onCreateOptionsMenu(menu, inflater);
}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
index 9864ea9..52243d4 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
@@ -133,7 +133,8 @@
mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
mChooseDifferentNetwork.setOnClickListener(v ->
- mClickChooseDifferentNetworkListener.onClickChooseDifferentNetwork());
+ mClickChooseDifferentNetworkListener.onClickChooseDifferentNetwork()
+ );
mButtonLeft = view.findViewById(R.id.button_left);
mButtonLeft.setText(R.string.cancel);
diff --git a/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragment.java b/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragment.java
index 3817615..6a229a1 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragment.java
@@ -61,6 +61,10 @@
* WifiDppChooseSavedWifiNetworkFragment. */
final FragmentManager fragmentManager = getChildFragmentManager();
final WifiNetworkListFragment fragment = new WifiNetworkListFragment();
+ final Bundle args = getArguments();
+ if (args != null) {
+ fragment.setArguments(args);
+ }
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.wifi_network_list_container, fragment,
TAG_FRAGMENT_WIFI_NETWORK_LIST);
diff --git a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
index 3955456..e5beea0 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
@@ -21,6 +21,7 @@
import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.os.Bundle;
+import android.provider.Settings;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -45,7 +46,7 @@
* {@code WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY}
* {@code WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID}
*
- * For intent action {@code ACTION_PROCESS_WIFI_DPP_QR_CODE}, specify Wi-Fi (DPP)
+ * For intent action {@link Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE}, specify Wi-Fi (DPP)
* QR code in {@code WifiDppUtils.EXTRA_QR_CODE}
*/
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
@@ -62,8 +63,6 @@
"android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER";
public static final String ACTION_CONFIGURATOR_QR_CODE_GENERATOR =
"android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR";
- public static final String ACTION_PROCESS_WIFI_DPP_QR_CODE =
- "android.settings.PROCESS_WIFI_DPP_QR_CODE";
// Key for Bundle usage
private static final String KEY_QR_CODE = "key_qr_code";
@@ -78,8 +77,10 @@
/** The Wi-Fi network which will be configured */
private WifiNetworkConfig mWifiNetworkConfig;
- /** The Wi-Fi DPP QR code from intent ACTION_PROCESS_WIFI_DPP_QR_CODE */
+ /** The Wi-Fi DPP QR code from intent ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE */
private WifiQrCode mWifiDppQrCode;
+ /** Secret extra that allows fake networks to show in UI for testing purposes */
+ private boolean mIsTest;
@Override
public int getMetricsCategory() {
@@ -139,8 +140,9 @@
showQrCodeGeneratorFragment();
}
break;
- case ACTION_PROCESS_WIFI_DPP_QR_CODE:
- String qrCode = intent.getStringExtra(WifiDppUtils.EXTRA_QR_CODE);
+ case Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE:
+ String qrCode = intent.getStringExtra(Settings.EXTRA_QR_CODE);
+ mIsTest = intent.getBooleanExtra(WifiDppUtils.EXTRA_TEST, false);
mWifiDppQrCode = getValidWifiDppQrCodeOrNull(qrCode);
final boolean isDppSupported = WifiDppUtils.isWifiDppEnabled(this);
if (!isDppSupported) {
@@ -164,12 +166,17 @@
}
private void showQrCodeScannerFragment(boolean addToBackStack) {
+ WifiDppQrCodeScannerFragment fragment =
+ (WifiDppQrCodeScannerFragment) mFragmentManager.findFragmentByTag(
+ WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
// Avoid to replace the same fragment during configuration change
- if (mFragmentManager.findFragmentByTag(WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER) != null) {
+ if (fragment != null && fragment.isVisible()) {
return;
}
- final WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
+ if (fragment == null) {
+ fragment = new WifiDppQrCodeScannerFragment();
+ }
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment,
@@ -181,13 +188,15 @@
}
private void showQrCodeGeneratorFragment() {
+ WifiDppQrCodeGeneratorFragment fragment =
+ (WifiDppQrCodeGeneratorFragment) mFragmentManager.findFragmentByTag(
+ WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR);
// Avoid to replace the same fragment during configuration change
- if (mFragmentManager.findFragmentByTag(
- WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR) != null) {
+ if (fragment != null && fragment.isVisible()) {
return;
}
- final WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
+ fragment = new WifiDppQrCodeGeneratorFragment();
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment,
@@ -196,14 +205,22 @@
}
private void showChooseSavedWifiNetworkFragment(boolean addToBackStack) {
+ WifiDppChooseSavedWifiNetworkFragment fragment =
+ (WifiDppChooseSavedWifiNetworkFragment) mFragmentManager.findFragmentByTag(
+ WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK);
// Avoid to replace the same fragment during configuration change
- if (mFragmentManager.findFragmentByTag(
- WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK) != null) {
+ if (fragment != null && fragment.isVisible()) {
return;
}
- final WifiDppChooseSavedWifiNetworkFragment fragment =
- new WifiDppChooseSavedWifiNetworkFragment();
+ if (fragment == null) {
+ fragment = new WifiDppChooseSavedWifiNetworkFragment();
+ if (mIsTest) {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(WifiDppUtils.EXTRA_TEST, true);
+ fragment.setArguments(bundle);
+ }
+ }
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment,
@@ -215,14 +232,19 @@
}
private void showAddDeviceFragment(boolean addToBackStack) {
+ WifiDppAddDeviceFragment fragment =
+ (WifiDppAddDeviceFragment) mFragmentManager.findFragmentByTag(
+ WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE);
+
// Avoid to replace the same fragment during configuration change
if (mFragmentManager.findFragmentByTag(
WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE) != null) {
return;
}
- final WifiDppAddDeviceFragment fragment =
- new WifiDppAddDeviceFragment();
+ if (fragment == null) {
+ fragment = new WifiDppAddDeviceFragment();
+ }
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment,
diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
index e1b8ead..b43ee92 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
@@ -29,6 +29,8 @@
/**
* Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity
+ *
+ * @see WifiQrCode
*/
public class WifiDppUtils {
/**
@@ -67,8 +69,9 @@
/** The data corresponding to {@code WifiConfiguration} networkId */
public static final String EXTRA_WIFI_NETWORK_ID = "networkId";
- /** @see WifiQrCode */
- public static final String EXTRA_QR_CODE = "qrCode";
+ /** Used by {@link android.provider.Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE} to
+ * indicate test mode UI should be shown. Test UI does not make API calls. Value is a boolean.*/
+ public static final String EXTRA_TEST = "test";
/**
* Returns whether the user can share the network represented by this preference with QR code.
diff --git a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
index 08b5420..8e95b3e 100644
--- a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
+++ b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
@@ -42,6 +42,9 @@
* EXTRA_QR_CODE
*/
public class WifiNetworkConfig {
+
+ static final String FAKE_SSID = "fake network";
+ static final String FAKE_PASSWORD = "password";
private static final String TAG = "WifiNetworkConfig";
private String mSecurity;
diff --git a/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java b/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java
index 0a7a08c..b078b01 100644
--- a/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiNetworkListFragment.java
@@ -55,11 +55,14 @@
private PreferenceCategory mAccessPointsPreferenceCategory;
private AccessPointPreference.UserBadgeCache mUserBadgeCache;
private Preference mAddPreference;
+ // Only shows up if mIsTest == true
+ private Preference mFakeNetworkPreference;
private WifiManager mWifiManager;
private WifiTracker mWifiTracker;
private WifiManager.ActionListener mSaveListener;
+ private boolean mIsTest;
@VisibleForTesting
boolean mUseConnectedAccessPointDirectly;
@@ -99,6 +102,11 @@
getSettingsLifecycle(), /* includeSaved */true, /* includeScans */ true);
mWifiManager = mWifiTracker.getManager();
+ final Bundle args = getArguments();
+ if (args != null) {
+ mIsTest = args.getBoolean(WifiDppUtils.EXTRA_TEST, false);
+ }
+
mSaveListener = new WifiManager.ActionListener() {
@Override
public void onSuccess() {
@@ -138,6 +146,11 @@
mAccessPointsPreferenceCategory = (PreferenceCategory) findPreference(
PREF_KEY_ACCESS_POINTS);
+ mFakeNetworkPreference = new Preference(getPrefContext());
+ mFakeNetworkPreference.setIcon(R.drawable.ic_wifi_signal_0);
+ mFakeNetworkPreference.setKey("fake_key");
+ mFakeNetworkPreference.setTitle("fake network");
+
mAddPreference = new Preference(getPrefContext());
mAddPreference.setIcon(R.drawable.ic_menu_add);
mAddPreference.setTitle(R.string.wifi_add_network);
@@ -218,6 +231,16 @@
}
} else if (preference == mAddPreference) {
launchAddNetworkFragment();
+ } else if (preference == mFakeNetworkPreference) {
+ if (mOnChooseNetworkListener != null) {
+ mOnChooseNetworkListener.onChooseNetwork(
+ new WifiNetworkConfig(
+ WifiQrCode.SECURITY_WPA,
+ /* ssid */ WifiNetworkConfig.FAKE_SSID,
+ /* preSharedKey */ WifiNetworkConfig.FAKE_PASSWORD,
+ /* hiddenSsid */ true,
+ /* networkId */ WifiConfiguration.INVALID_NETWORK_ID));
+ }
} else {
return super.onPreferenceTreeClick(preference);
}
@@ -314,6 +337,11 @@
removeCachedPrefs(mAccessPointsPreferenceCategory);
mAddPreference.setOrder(index);
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
+
+ if (mIsTest) {
+ mFakeNetworkPreference.setOrder(index + 1);
+ mAccessPointsPreferenceCategory.addPreference(mFakeNetworkPreference);
+ }
}
private AccessPointPreference createAccessPointPreference(AccessPoint accessPoint) {
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 101a6b8..da71273 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -67,10 +67,13 @@
<bool name="config_show_device_name">false</bool>
<bool name="config_use_legacy_suggestion">false</bool>
<bool name="config_show_avatar_in_homepage">true</bool>
+ <bool name="config_show_branded_account_in_device_info">false</bool>
+ <bool name="config_show_emergency_info_in_device_info">false</bool>
<!-- Whether or not extra preview panels should be used for screen zoom setting. -->
<bool name="config_enable_extra_screen_zoom_preview">false</bool>
+
<!-- List of a11y components on the device allowed to be enabled by Settings Slices -->
<string-array name="config_settings_slices_accessibility_components" translatable="false">
<item>fake_package/fake_service</item>
diff --git a/tests/robotests/src/com/android/settings/accounts/EmergencyInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/EmergencyInfoPreferenceControllerTest.java
index 5901f55..65da1f7 100644
--- a/tests/robotests/src/com/android/settings/accounts/EmergencyInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/EmergencyInfoPreferenceControllerTest.java
@@ -70,10 +70,12 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new EmergencyInfoPreferenceController(mContext);
+ mController = new EmergencyInfoPreferenceController(mContext, "test_key");
mPreference = new Preference(Robolectric.setupActivity(Activity.class));
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
+ when(mContext.getResources().getBoolean(R.bool.config_show_emergency_info_in_device_info))
+ .thenReturn(true);
}
@After
@@ -104,6 +106,7 @@
mController.updateRawDataToIndex(data);
+ assertThat(mController.isAvailable()).isTrue();
assertThat(data).isNotEmpty();
}
@@ -152,7 +155,7 @@
final Activity activity = Robolectric.setupActivity(Activity.class);
final Preference preference = new Preference(activity);
preference.setKey("emergency_info");
- mController = new EmergencyInfoPreferenceController(activity);
+ mController = new EmergencyInfoPreferenceController(activity, preference.getKey());
mController.handlePreferenceTreeClick(preference);
diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/MoreSpecialAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/MoreSpecialAccessPreferenceControllerTest.java
new file mode 100644
index 0000000..534fdaf
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/specialaccess/MoreSpecialAccessPreferenceControllerTest.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2019 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.applications.specialaccess;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+
+import androidx.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class MoreSpecialAccessPreferenceControllerTest {
+
+ private static final String PREFERENCE_KEY = "more";
+ private static final String DIFFERENT_PREFERENCE_KEY = "different";
+
+ private static final String PERMISSION_CONTROLLER_PACKAGE_NAME =
+ "com.android.permissioncontroller";
+
+ @Mock
+ private Context mContext;
+ @Mock
+ private PackageManager mPackageManager;
+
+ @Before
+ public void setUp() throws PackageManager.NameNotFoundException {
+ MockitoAnnotations.initMocks(this);
+
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ }
+
+ @Test
+ public void constructor_shouldResolveActivityWithPermissionControllerPackageName() {
+ when(mPackageManager.getPermissionControllerPackageName()).thenReturn(
+ PERMISSION_CONTROLLER_PACKAGE_NAME);
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+
+ ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(mPackageManager).resolveActivity(intentCaptor.capture(), anyInt());
+ final Intent intent = intentCaptor.getValue();
+ assertThat(intent.getPackage()).isEqualTo(PERMISSION_CONTROLLER_PACKAGE_NAME);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noPermissionController_shouldReturnUnsupportedOnDevice() {
+ when(mPackageManager.getPermissionControllerPackageName()).thenReturn(null);
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+
+ assertThat(preferenceController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_canNotResolveActivity_shouldReturnUnsupportedOnDevice() {
+ when(mPackageManager.getPermissionControllerPackageName()).thenReturn(
+ PERMISSION_CONTROLLER_PACKAGE_NAME);
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+
+ assertThat(preferenceController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_canResolveActivity_shouldReturnAvailableUnsearchable() {
+ when(mPackageManager.getPermissionControllerPackageName()).thenReturn(
+ PERMISSION_CONTROLLER_PACKAGE_NAME);
+ when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
+ new ResolveInfo());
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+
+ assertThat(preferenceController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE_UNSEARCHABLE);
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_differentKey_shouldReturnFalse() {
+ when(mPackageManager.getPermissionControllerPackageName())
+ .thenReturn(PERMISSION_CONTROLLER_PACKAGE_NAME);
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+ Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(DIFFERENT_PREFERENCE_KEY);
+
+ assertThat(preferenceController.handlePreferenceTreeClick(preference)).isFalse();
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_sameKey_shouldReturnTrue() {
+ when(mPackageManager.getPermissionControllerPackageName())
+ .thenReturn(PERMISSION_CONTROLLER_PACKAGE_NAME);
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+ Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(PREFERENCE_KEY);
+
+ assertThat(preferenceController.handlePreferenceTreeClick(preference)).isTrue();
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_noPermissionController_shouldNotStartActivity() {
+ when(mPackageManager.getPermissionControllerPackageName()).thenReturn(null);
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+ Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(PREFERENCE_KEY);
+ preferenceController.handlePreferenceTreeClick(preference);
+
+ verify(mContext, never()).startActivity(any(Intent.class));
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_canNotResolveActivity_shouldNotStartActivity() {
+ when(mPackageManager.getPermissionControllerPackageName()).thenReturn(
+ PERMISSION_CONTROLLER_PACKAGE_NAME);
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+ Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(PREFERENCE_KEY);
+ preferenceController.handlePreferenceTreeClick(preference);
+
+ verify(mContext, never()).startActivity(any(Intent.class));
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_canResolveActivity_shouldStartActivityWithIntent() {
+ when(mPackageManager.getPermissionControllerPackageName())
+ .thenReturn(PERMISSION_CONTROLLER_PACKAGE_NAME);
+ when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
+ new ResolveInfo());
+ MoreSpecialAccessPreferenceController preferenceController =
+ new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
+ Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(PREFERENCE_KEY);
+ preferenceController.handlePreferenceTreeClick(preference);
+ ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+
+ verify(mContext).startActivity(intentCaptor.capture());
+ final Intent intent = intentCaptor.getValue();
+ assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MANAGE_SPECIAL_APP_ACCESSES);
+ assertThat(intent.getPackage()).isEqualTo(PERMISSION_CONTROLLER_PACKAGE_NAME);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
new file mode 100644
index 0000000..a74610e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2019 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.bluetooth;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.view.LayoutInflater;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.fuelgauge.BatteryMeterView;
+import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.widget.LayoutPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowEntityHeaderController.class)
+public class AdvancedBluetoothDetailsHeaderControllerTest{
+ private static final int BATTERY_LEVEL_MAIN = 30;
+ private static final int BATTERY_LEVEL_LEFT = 25;
+ private static final int BATTERY_LEVEL_RIGHT = 45;
+
+ private Context mContext;
+
+ @Mock
+ private BluetoothDevice mBluetoothDevice;
+ @Mock
+ private CachedBluetoothDevice mCachedDevice;
+ private AdvancedBluetoothDetailsHeaderController mController;
+ private LayoutPreference mLayoutPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mController = new AdvancedBluetoothDetailsHeaderController(mContext, "pref_Key");
+ mController.init(mCachedDevice);
+ mLayoutPreference = new LayoutPreference(mContext,
+ LayoutInflater.from(mContext).inflate(R.layout.advanced_bt_entity_header, null));
+ mController.mLayoutPreference = mLayoutPreference;
+ when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
+ }
+
+ @Test
+ public void createBatteryIcon_hasCorrectInfo() {
+ final Drawable drawable = mController.createBtBatteryIcon(mContext, BATTERY_LEVEL_MAIN);
+ assertThat(drawable).isInstanceOf(BatteryMeterView.BatteryMeterDrawable.class);
+
+ final BatteryMeterView.BatteryMeterDrawable iconDrawable =
+ (BatteryMeterView.BatteryMeterDrawable) drawable;
+ assertThat(iconDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL_MAIN);
+ }
+
+ @Test
+ public void refresh_updateCorrectInfo() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_LEFT));
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTHETHERED_RIGHT_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_RIGHT));
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTHETHERED_CASE_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_MAIN));
+ mController.refresh();
+
+ assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_left), BATTERY_LEVEL_LEFT);
+ assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_right), BATTERY_LEVEL_RIGHT);
+ assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN);
+ }
+
+ @Test
+ public void getAvailabilityStatus_unthetheredHeadset_returnAvailable() {
+ when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET))
+ .thenReturn("true");
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_notUnthetheredHeadset_returnUnavailable() {
+ when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET))
+ .thenReturn("false");
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
+ private void assertBatteryLevel(LinearLayout linearLayout, int batteryLevel) {
+ final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
+ assertThat(textView.getText().toString()).isEqualTo(
+ com.android.settings.Utils.formatPercentage(batteryLevel));
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
index 1e78075..930d9cb 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
@@ -50,7 +50,6 @@
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
-
@Config(shadows = ShadowEntityHeaderController.class)
public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
index 9e5b617..f6969ec 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
@@ -171,7 +171,8 @@
.thenReturn(new BluetoothClass(BluetoothClass.Device.Major.IMAGING));
mPreference.onDeviceAttributesChanged();
- DrawableTestHelper.assertDrawableResId(mPreference.getIcon(), R.drawable.ic_settings_print);
+ DrawableTestHelper.assertDrawableResId(mPreference.getIcon(),
+ com.android.internal.R.drawable.ic_settings_print);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
index 4504d84..f4a9d36 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
@@ -68,7 +68,7 @@
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
- R.drawable.ic_settings_bluetooth);
+ com.android.internal.R.drawable.ic_settings_bluetooth);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
index 1337f66..51e559f 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.bluetooth;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -22,6 +24,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.bluetooth.BluetoothDevice;
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -40,23 +43,68 @@
@RunWith(RobolectricTestRunner.class)
public class UtilsTest {
+ private static final String STRING_METADATA = "string_metadata";
+ private static final String BOOL_METADATA = "true";
+ private static final String INT_METADATA = "25";
+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
+ @Mock
+ private BluetoothDevice mBluetoothDevice;
private MetricsFeatureProvider mMetricsFeatureProvider;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+
mMetricsFeatureProvider = FakeFeatureFactory.setupForTest().getMetricsFeatureProvider();
}
@Test
- public void testShowConnectingError_shouldLogBluetoothConnectError() {
+ public void showConnectingError_shouldLogBluetoothConnectError() {
when(mContext.getString(anyInt(), anyString())).thenReturn("testMessage");
Utils.showConnectingError(mContext, "testName", mock(LocalBluetoothManager.class));
verify(mMetricsFeatureProvider).visible(eq(mContext), anyInt(),
eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
}
+
+ @Test
+ public void getStringMetaData_hasMetaData_getCorrectMetaData() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_ICON)).thenReturn(STRING_METADATA);
+
+ assertThat(Utils.getStringMetaData(mBluetoothDevice,
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_ICON)).isEqualTo(STRING_METADATA);
+ }
+
+ @Test
+ public void getIntMetaData_hasMetaData_getCorrectMetaData() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_BATTERY)).thenReturn(INT_METADATA);
+
+ assertThat(Utils.getIntMetaData(mBluetoothDevice,
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_BATTERY))
+ .isEqualTo(Integer.parseInt(INT_METADATA));
+ }
+
+ @Test
+ public void getIntMetaData_invalidMetaData_getErrorCode() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_BATTERY)).thenReturn(STRING_METADATA);
+
+ assertThat(Utils.getIntMetaData(mBluetoothDevice,
+ BluetoothDevice.METADATA_UNTHETHERED_LEFT_ICON)).isEqualTo(Utils.META_INT_ERROR);
+ }
+
+ @Test
+ public void getBooleanMetaData_hasMetaData_getCorrectMetaData() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET)).thenReturn(BOOL_METADATA);
+
+ assertThat(Utils.getBooleanMetaData(mBluetoothDevice,
+ BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET)).isEqualTo(true);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
index ae11954..525b82e 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
@@ -26,6 +26,7 @@
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Typeface;
+import android.net.ConnectivityManager;
import android.net.NetworkTemplate;
import android.os.Bundle;
import android.telephony.SubscriptionManager;
@@ -531,6 +532,18 @@
assertThat(mLaunchButton.isEnabled()).isFalse();
}
+ @Test
+ public void launchWifiDataUsage_shouldSetWifiNetworkTypeInIntentExtra() {
+ mSummaryPreference.launchWifiDataUsage(mActivity);
+
+ final Intent launchIntent = Shadows.shadowOf(mActivity).getNextStartedActivity();
+ final Bundle args =
+ launchIntent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
+
+ assertThat(args.getInt(DataUsageList.EXTRA_NETWORK_TYPE))
+ .isEqualTo(ConnectivityManager.TYPE_WIFI);
+ }
+
private void bindViewHolder() {
mSummaryPreference.onBindViewHolder(mHolder);
mUsageTitle = (TextView) mHolder.findViewById(R.id.usage_title);
diff --git a/tests/robotests/src/com/android/settings/development/gup/GupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
similarity index 68%
rename from tests/robotests/src/com/android/settings/development/gup/GupPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
index d5e7a85..f6fa8e0 100644
--- a/tests/robotests/src/com/android/settings/development/gup/GupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
@@ -14,14 +14,17 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
@@ -49,9 +52,10 @@
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
-public class GupPreferenceControllerTest {
+public class GameDriverAppPreferenceControllerTest {
+
private static final int DEFAULT = 0;
- private static final int GUP = 1;
+ private static final int GAME_DRIVER = 1;
private static final int SYSTEM = 2;
private static final String TEST_APP_NAME = "testApp";
private static final String TEST_PKG_NAME = "testPkg";
@@ -65,12 +69,14 @@
private PackageManager mPackageManager;
@Mock
private PreferenceScreen mScreen;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
private Context mContext;
private PreferenceGroup mGroup;
private PreferenceManager mPreferenceManager;
private ContentResolver mResolver;
- private GupPreferenceController mController;
+ private GameDriverAppPreferenceController mController;
private CharSequence[] mValueList;
private String mDialogTitle;
@@ -79,24 +85,35 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mResolver = mContext.getContentResolver();
- mValueList = mContext.getResources().getStringArray(R.array.gup_app_preference_values);
- mDialogTitle = mContext.getResources().getString(R.string.gup_app_preference_title);
+ mValueList =
+ mContext.getResources().getStringArray(R.array.game_driver_app_preference_values);
+ mDialogTitle = mContext.getResources().getString(R.string.game_driver_app_preference_title);
}
@Test
- public void getAvailability_developmentSettingsEnabled_available() {
+ public void getAvailability_developmentSettingsEnabledAndGameDriverOn_available() {
loadDefaultConfig();
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
- public void getAvailability_developmentSettingsDisabled_disabledDependentSetting() {
+ public void getAvailability_developmentSettingsDisabled_conditionallyUnavailable() {
loadDefaultConfig();
Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailability_gameDriverOff_conditionallyUnavailable() {
+ loadDefaultConfig();
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
@@ -111,10 +128,46 @@
}
@Test
+ public void onStart_shouldRegister() {
+ loadDefaultConfig();
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldUnregister() {
+ loadDefaultConfig();
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void updateState_available_visible() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ loadDefaultConfig();
+
+ assertThat(mGroup.isVisible()).isTrue();
+ }
+
+ @Test
+ public void updateState_gameDriverOff_notVisible() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ loadDefaultConfig();
+
+ assertThat(mGroup.isVisible()).isFalse();
+ }
+
+ @Test
public void createPreference_configDefault_shouldSetDefaultAttributes() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
@@ -127,26 +180,26 @@
}
@Test
- public void createPreference_configGup_shouldSetGupAttributes() {
+ public void createPreference_configGAME_DRIVER_shouldSetGameDriverAttributes() {
loadConfig(TEST_PKG_NAME, "");
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
assertThat(preference.getEntries()).isEqualTo(mValueList);
assertThat(preference.getEntryValues()).isEqualTo(mValueList);
- assertThat(preference.getEntry()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getValue()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getSummary()).isEqualTo(mValueList[GUP]);
+ assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
}
@Test
public void createPreference_configSystem_shouldSetSystemAttributes() {
loadConfig("", TEST_PKG_NAME);
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
@@ -162,31 +215,31 @@
public void onPreferenceChange_selectDefault_shouldUpdateAttributesAndSettingsGlobal() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
mController.onPreferenceChange(preference, mValueList[DEFAULT]);
assertThat(preference.getEntry()).isEqualTo(mValueList[DEFAULT]);
assertThat(preference.getValue()).isEqualTo(mValueList[DEFAULT]);
assertThat(preference.getSummary()).isEqualTo(mValueList[DEFAULT]);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
.isEqualTo("");
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
.isEqualTo("");
}
@Test
- public void onPreferenceChange_selectGup_shouldUpdateAttributesAndSettingsGlobal() {
+ public void onPreferenceChange_selectGAME_DRIVER_shouldUpdateAttributesAndSettingsGlobal() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
- mController.onPreferenceChange(preference, mValueList[GUP]);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
+ mController.onPreferenceChange(preference, mValueList[GAME_DRIVER]);
- assertThat(preference.getEntry()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getValue()).isEqualTo(mValueList[GUP]);
- assertThat(preference.getSummary()).isEqualTo(mValueList[GUP]);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS))
+ assertThat(preference.getEntry()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getValue()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(preference.getSummary()).isEqualTo(mValueList[GAME_DRIVER]);
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
.isEqualTo(TEST_PKG_NAME);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
.isEqualTo("");
}
@@ -194,15 +247,15 @@
public void onPreferenceChange_selectSystem_shouldUpdateAttributesAndSettingsGlobal() {
loadDefaultConfig();
final ListPreference preference =
- mController.createListPreference(TEST_PKG_NAME, TEST_APP_NAME);
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
mController.onPreferenceChange(preference, mValueList[SYSTEM]);
assertThat(preference.getEntry()).isEqualTo(mValueList[SYSTEM]);
assertThat(preference.getValue()).isEqualTo(mValueList[SYSTEM]);
assertThat(preference.getSummary()).isEqualTo(mValueList[SYSTEM]);
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS))
.isEqualTo("");
- assertThat(Settings.Global.getString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS))
+ assertThat(Settings.Global.getString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS))
.isEqualTo(TEST_PKG_NAME);
}
@@ -224,12 +277,13 @@
private void loadDefaultConfig() { loadConfig("", ""); }
private void loadConfig(String optIn, String optOut) {
- Settings.Global.putString(mResolver, Settings.Global.GUP_DEV_OPT_IN_APPS, optIn);
- Settings.Global.putString(mResolver, Settings.Global.GUP_DEV_OPT_OUT_APPS, optOut);
+ Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS, optIn);
+ Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut);
- mController = new GupPreferenceController(mContext, "testKey");
+ mController = new GameDriverAppPreferenceController(mContext, "testKey");
mGroup = spy(new PreferenceCategory(mContext));
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
+ when(mGroup.getContext()).thenReturn(mContext);
when(mGroup.getPreferenceManager()).thenReturn(preferenceManager);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mGroup);
mController.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverContentObserverTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverContentObserverTest.java
new file mode 100644
index 0000000..caaf896
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverContentObserverTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.ContentResolver;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverContentObserverTest {
+
+ @Mock
+ private ContentResolver mResolver;
+ @Mock
+ private GameDriverContentObserver.OnGameDriverContentChangedListener mListener;
+
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mGameDriverContentObserver = spy(new GameDriverContentObserver(null, null));
+ }
+
+ @Test
+ public void onChange_shouldCallListener() {
+ mGameDriverContentObserver.mListener = mListener;
+ mGameDriverContentObserver.onChange(true);
+
+ verify(mListener).onGameDriverContentChanged();
+ }
+
+ @Test
+ public void register_shouldRegisterContentObserver() {
+ mGameDriverContentObserver.register(mResolver);
+
+ verify(mResolver).registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_ALL_APPS), false,
+ mGameDriverContentObserver);
+ }
+
+ @Test
+ public void unregister_shouldUnregisterContentObserver() {
+ mGameDriverContentObserver.unregister(mResolver);
+
+ verify(mResolver).unregisterContentObserver(mGameDriverContentObserver);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gup/GupDashboardTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverDashboardTest.java
similarity index 67%
rename from tests/robotests/src/com/android/settings/development/gup/GupDashboardTest.java
rename to tests/robotests/src/com/android/settings/development/gamedriver/GameDriverDashboardTest.java
index 17278ef..f8f8add 100644
--- a/tests/robotests/src/com/android/settings/development/gup/GupDashboardTest.java
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverDashboardTest.java
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-package com.android.settings.development.gup;
+package com.android.settings.development.gamedriver;
import static com.google.common.truth.Truth.assertThat;
-import com.android.internal.logging.nano.MetricsProto;
+import android.app.settings.SettingsEnums;
+
import com.android.settings.R;
import org.junit.Before;
@@ -27,12 +28,13 @@
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
-public class GupDashboardTest {
- private GupDashboard mDashboard;
+public class GameDriverDashboardTest {
+
+ private GameDriverDashboard mDashboard;
@Before
public void setUp() {
- mDashboard = new GupDashboard();
+ mDashboard = new GameDriverDashboard();
}
@Test
@@ -41,14 +43,13 @@
}
@Test
- public void getMetricesCategory_shouldReturnGupDashboard() {
+ public void getMetricesCategory_shouldReturnGameDriverDashboard() {
assertThat(mDashboard.getMetricsCategory())
- .isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GUP_DASHBOARD);
+ .isEqualTo(SettingsEnums.SETTINGS_GAME_DRIVER_DASHBOARD);
}
@Test
- public void getPreferenceScreen_shouldReturnGupSettings() {
- assertThat(mDashboard.getPreferenceScreenResId())
- .isEqualTo(R.xml.gup_settings);
+ public void getPreferenceScreen_shouldReturnGameDriverSettings() {
+ assertThat(mDashboard.getPreferenceScreenResId()).isEqualTo(R.xml.game_driver_settings);
}
}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
new file mode 100644
index 0000000..094cd21
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverEnableForAllAppsPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private SwitchPreference mPreference;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ private Context mContext;
+ private ContentResolver mResolver;
+ private GameDriverEnableForAllAppsPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mResolver = mContext.getContentResolver();
+ mController = new GameDriverEnableForAllAppsPreferenceController(mContext, "testKey");
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ }
+
+ @Test
+ public void getAvailability_developmentSettingsEnabledAndGameDriverSettingsOn_available() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailability_developmentSettingsDisabled_conditionallyUnavailable() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailability_gameDriverOff_conditionallyUnavailable() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void displayPreference_shouldAddSwitchPreference() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void onStart_shouldRegister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldUnregister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void updateState_availableAndGameDriverDefault_visibleAndUncheck() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController.updateState(mPreference);
+
+ verify(mPreference, atLeastOnce()).setVisible(true);
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void updateState_availableAndGameDriverAllApps_visibleAndCheck() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
+ mController.updateState(mPreference);
+
+ verify(mPreference, atLeastOnce()).setVisible(true);
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void updateState_gameDriverOff_notVisibleAndUncheck() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(false);
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void onPreferenceChange_check_shouldUpdateSettingsGlobal() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController.onPreferenceChange(mPreference, true);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_ALL_APPS);
+ }
+
+ @Test
+ public void onPreferenceChange_uncheck_shouldUpdateSettingsGlobal() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
+ mController.onPreferenceChange(mPreference, false);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_DEFAULT);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceControllerTest.java
new file mode 100644
index 0000000..133791e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverFooterPreferenceControllerTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settingslib.widget.FooterPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverFooterPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private FooterPreference mPreference;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ private Context mContext;
+ private ContentResolver mResolver;
+ private GameDriverFooterPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mResolver = mContext.getContentResolver();
+ mController = spy(new GameDriverFooterPreferenceController(mContext));
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void getAvailabilityStatus_gameDriverOff_availableUnsearchable() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_gameDriverDefault_conditionallyUnavailable() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_gameDriverAllApps_conditionallyUnavailable() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_ALL_APPS);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void onStart_shouldRegister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldUnregister() {
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void updateState_available_visible() {
+ when(mController.getAvailabilityStatus()).thenReturn(AVAILABLE_UNSEARCHABLE);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(true);
+ }
+
+ @Test
+ public void updateState_unavailable_invisible() {
+ when(mController.getAvailabilityStatus()).thenReturn(CONDITIONALLY_UNAVAILABLE);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(false);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarControllerTest.java
new file mode 100644
index 0000000..f546c36
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverGlobalSwitchBarControllerTest.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2019 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.gamedriver;
+
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
+import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.widget.SwitchBar;
+import com.android.settings.widget.SwitchBarController;
+import com.android.settings.widget.SwitchWidgetController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class GameDriverGlobalSwitchBarControllerTest {
+
+ @Mock
+ private SwitchBar mSwitchBar;
+ @Mock
+ private SwitchWidgetController mSwitchWidgetController;
+ @Mock
+ private GameDriverContentObserver mGameDriverContentObserver;
+
+ private Context mContext;
+ private ContentResolver mResolver;
+ private GameDriverGlobalSwitchBarController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mResolver = mContext.getContentResolver();
+ }
+
+ @Test
+ public void constructor_gameDriverOn_shouldCheckSwitchBar() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setChecked(true);
+ }
+
+ @Test
+ public void constructor_gameDriverOff_shouldUncheckSwitchBar() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setChecked(false);
+ }
+
+ @Test
+ public void constructor_developmentSettingsEnabled_shouldEnableSwitchBar() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setEnabled(true);
+ }
+
+ @Test
+ public void constructor_developmentSettingsDisabled_shouldDisableSwitchBar() {
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+
+ verify(mSwitchBar).setEnabled(false);
+ }
+
+ @Test
+ public void onStart_shouldStartListeningAndRegister() {
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.mSwitchWidgetController = mSwitchWidgetController;
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStart();
+
+ verify(mSwitchWidgetController).startListening();
+ verify(mGameDriverContentObserver).register(mResolver);
+ }
+
+ @Test
+ public void onStop_shouldStopListeningAndUnregister() {
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.mSwitchWidgetController = mSwitchWidgetController;
+ mController.mGameDriverContentObserver = mGameDriverContentObserver;
+ mController.onStop();
+
+ verify(mSwitchWidgetController).stopListening();
+ verify(mGameDriverContentObserver).unregister(mResolver);
+ }
+
+ @Test
+ public void onSwitchToggled_checked_shouldTurnOnGameDriver() {
+ Settings.Global.putInt(mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_OFF);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.onSwitchToggled(true);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_DEFAULT);
+ }
+
+ @Test
+ public void onSwitchToggled_unchecked_shouldTurnOffGameDriver() {
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+ mController = new GameDriverGlobalSwitchBarController(
+ mContext, new SwitchBarController(mSwitchBar));
+ mController.onSwitchToggled(false);
+
+ assertThat(Settings.Global.getInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ .isEqualTo(GAME_DRIVER_OFF);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceControllerTest.java
deleted file mode 100644
index b7aadc3..0000000
--- a/tests/robotests/src/com/android/settings/development/gup/GupEnableForAllAppsPreferenceControllerTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2019 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.gup;
-
-import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
-import static com.android.settings.development.gup.GupEnableForAllAppsPreferenceController.GUP_ALL_APPS;
-import static com.android.settings.development.gup.GupEnableForAllAppsPreferenceController.GUP_DEFAULT;
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.provider.Settings;
-
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(RobolectricTestRunner.class)
-public class GupEnableForAllAppsPreferenceControllerTest {
- @Mock
- private PreferenceScreen mScreen;
- @Mock
- private SwitchPreference mPreference;
-
- private Context mContext;
- private ContentResolver mResolver;
- private GupEnableForAllAppsPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mResolver = mContext.getContentResolver();
- mController = new GupEnableForAllAppsPreferenceController(mContext, "testKey");
- when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
- }
-
- @Test
- public void getAvailability_developmentSettingsEnabled_available() {
- Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void getAvailability_developmentSettingsDisabled_disabledDependentSetting() {
- Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
- }
-
- @Test
- public void displayPreference_shouldAddSwitchPreference() {
- Settings.Global.putInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT);
- mController.displayPreference(mScreen);
-
- verify(mPreference).setChecked(false);
- }
-
- @Test
- public void onPreferenceChange_check_shouldUpdateSettingsGlobal() {
- Settings.Global.putInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT);
- mController.displayPreference(mScreen);
- mController.onPreferenceChange(mPreference, true);
-
- assertThat(Settings.Global.getInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT))
- .isEqualTo(GUP_ALL_APPS);
- }
-
- @Test
- public void onPreferenceChange_uncheck_shouldUpdateSettingsGlobal() {
- Settings.Global.putInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_ALL_APPS);
- mController.displayPreference(mScreen);
- mController.onPreferenceChange(mPreference, false);
-
- assertThat(Settings.Global.getInt(mResolver, Settings.Global.GUP_DEV_ALL_APPS, GUP_DEFAULT))
- .isEqualTo(GUP_DEFAULT);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java
index 564acfd..87dcb33 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java
@@ -29,36 +29,52 @@
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.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
public class BrandedAccountPreferenceControllerTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
- private BrandedAccountPreferenceController mController;
private FakeFeatureFactory fakeFeatureFactory;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
fakeFeatureFactory = FakeFeatureFactory.setupForTest();
- mController = new BrandedAccountPreferenceController(mContext);
+
}
@Test
- public void isAvailable_defaultOff() {
- assertThat(mController.isAvailable()).isFalse();
+ public void isAvailable_configOn_noAccount_off() {
+ final BrandedAccountPreferenceController controller =
+ new BrandedAccountPreferenceController(mContext, "test_key");
+ assertThat(controller.isAvailable()).isFalse();
}
@Test
- public void isAvailable_onWhenAccountIsAvailable() {
+ public void isAvailable_accountIsAvailable_on() {
when(fakeFeatureFactory.mAccountFeatureProvider.getAccounts(any(Context.class)))
- .thenReturn(new Account[] {new Account("fake@account.foo", "fake.reallyfake")});
- mController = new BrandedAccountPreferenceController(mContext);
- assertThat(mController.isAvailable()).isTrue();
+ .thenReturn(new Account[]{new Account("fake@account.foo", "fake.reallyfake")});
+
+ final BrandedAccountPreferenceController controller =
+ new BrandedAccountPreferenceController(mContext, "test_key");
+
+ assertThat(controller.isAvailable()).isTrue();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_configOff_hasAccount_off() {
+ when(fakeFeatureFactory.mAccountFeatureProvider.getAccounts(any(Context.class)))
+ .thenReturn(new Account[]{new Account("fake@account.foo", "fake.reallyfake")});
+
+ final BrandedAccountPreferenceController controller =
+ new BrandedAccountPreferenceController(mContext, "test_key");
+
+ assertThat(controller.isAvailable()).isFalse();
}
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java
index 5eb0114..21c0e74 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/DeviceNamePreferenceControllerTest.java
@@ -75,7 +75,7 @@
configuration.SSID = "test-ap";
when(mWifiManager.getWifiApConfiguration()).thenReturn(configuration);
- mController = new DeviceNamePreferenceController(mContext);
+ mController = new DeviceNamePreferenceController(mContext, "test_key");
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
@@ -99,17 +99,17 @@
public void constructor_deviceNameLoadedIfSet() {
Settings.Global.putString(
mContext.getContentResolver(), Settings.Global.DEVICE_NAME, "Test");
- mController = new DeviceNamePreferenceController(mContext);
+ mController = new DeviceNamePreferenceController(mContext, "test_key");
assertThat(mController.getSummary()).isEqualTo("Test");
}
@Test
- public void isTextValid_nameUnder33CharactersIsValid() {
+ public void isTextValid_nameUnder33Characters_isValid() {
assertThat(mController.isTextValid("12345678901234567890123456789012")).isTrue();
}
@Test
- public void isTextValid_nameTooLongIsInvalid() {
+ public void isTextValid_nameTooLong_isInvalid() {
assertThat(mController.isTextValid("123456789012345678901234567890123")).isFalse();
}
diff --git a/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java
new file mode 100644
index 0000000..d426e7a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2019 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.display;
+
+import static android.provider.Settings.System.ADAPTIVE_SLEEP;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class AdaptiveSleepPreferenceControllerTest {
+
+ private static final String PREFERENCE_KEY = "adaptive_sleep";
+
+ private Context mContext;
+ private AdaptiveSleepPreferenceController mController;
+ private ContentResolver mContentResolver;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mContentResolver = mContext.getContentResolver();
+ mController = new AdaptiveSleepPreferenceController(mContext, PREFERENCE_KEY);
+ }
+
+ @Test
+ public void onPreferenceChange_turnOn_returnOn() {
+ mController.onPreferenceChange(null, true);
+
+ final int mode = Settings.System.getInt(mContentResolver, ADAPTIVE_SLEEP, 0);
+ assertThat(mode).isEqualTo(1);
+ }
+
+ @Test
+ public void onPreferenceChange_turnOff_returnOff() {
+ mController.onPreferenceChange(null, false);
+
+ final int mode = Settings.System.getInt(mContentResolver, ADAPTIVE_SLEEP, 1);
+ assertThat(mode).isEqualTo(0);
+ }
+
+ @Test
+ public void setChecked_updatesCorrectly() {
+ mController.setChecked(true);
+
+ assertThat(mController.isChecked()).isTrue();
+
+ mController.setChecked(false);
+
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void isChecked_no() {
+ Settings.System.putInt(mContentResolver, ADAPTIVE_SLEEP, 0);
+
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void isChecked_yes() {
+ Settings.System.putInt(mContentResolver, ADAPTIVE_SLEEP, 1);
+
+ assertThat(mController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void getSummary_settingOn_shouldReturnOnSummary() {
+ mController.setChecked(true);
+
+ assertThat(mController.getSummary())
+ .isEqualTo(mContext.getText(R.string.adaptive_sleep_summary_on));
+ }
+
+ @Test
+ public void getSummary_settingOff_shouldReturnOffSummary() {
+ mController.setChecked(false);
+
+ assertThat(mController.getSummary())
+ .isEqualTo(mContext.getText(R.string.adaptive_sleep_summary_off));
+ }
+
+ @Test
+ public void isSliceable_returnsTrue() {
+ final AdaptiveSleepPreferenceController controller =
+ new AdaptiveSleepPreferenceController(mContext, "any_key");
+ assertThat(controller.isSliceable()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/SilenceGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SilenceGesturePreferenceControllerTest.java
deleted file mode 100644
index 2dc880b..0000000
--- a/tests/robotests/src/com/android/settings/gestures/SilenceGesturePreferenceControllerTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2019 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.gestures;
-
-import static android.provider.Settings.Secure.SILENCE_GESTURE;
-
-import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.provider.Settings;
-
-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.RobolectricTestRunner;
-
-@RunWith(RobolectricTestRunner.class)
-public class SilenceGesturePreferenceControllerTest {
-
- private static final String KEY_SILENCE = "gesture_silence";
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
- @Mock
- private Resources mResources;
-
- private SilenceGesturePreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- when(mContext.getResources()).thenReturn(mResources);
- mController = new SilenceGesturePreferenceController(mContext, KEY_SILENCE);
- }
-
- @Test
- public void getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_silenceSensorAvailable))
- .thenReturn(false);
- final int availabilityStatus = mController.getAvailabilityStatus();
-
- assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE);
- }
-
- @Test
- public void getAvailabilityStatus_gestureSupported_AVAILABLE() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_silenceSensorAvailable)).thenReturn(true);
- final int availabilityStatus = mController.getAvailabilityStatus();
-
- assertThat(availabilityStatus).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void isSliceableCorrectKey_returnsTrue() {
- assertThat(mController.isSliceable()).isTrue();
- }
-
- @Test
- public void isChecked_testTrue() {
- Settings.Secure.putInt(mContext.getContentResolver(), SILENCE_GESTURE, 1);
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void isChecked_testFalse() {
- Settings.Secure.putInt(mContext.getContentResolver(), SILENCE_GESTURE, 0);
- assertThat(mController.isChecked()).isFalse();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/gestures/SkipGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SkipGesturePreferenceControllerTest.java
deleted file mode 100644
index c544786..0000000
--- a/tests/robotests/src/com/android/settings/gestures/SkipGesturePreferenceControllerTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2019 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.gestures;
-
-import static android.provider.Settings.Secure.SKIP_GESTURE;
-
-import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.provider.Settings;
-
-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.RobolectricTestRunner;
-
-@RunWith(RobolectricTestRunner.class)
-public class SkipGesturePreferenceControllerTest {
-
- private static final String KEY_SKIP = "gesture_skip";
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
- @Mock
- private Resources mResources;
-
- private SkipGesturePreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- when(mContext.getResources()).thenReturn(mResources);
- mController = new SkipGesturePreferenceController(mContext, KEY_SKIP);
- }
-
- @Test
- public void getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_skipSensorAvailable))
- .thenReturn(false);
- final int availabilityStatus = mController.getAvailabilityStatus();
-
- assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE);
- }
-
- @Test
- public void getAvailabilityStatus_gestureSupported_AVAILABLE() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_skipSensorAvailable)).thenReturn(true);
- final int availabilityStatus = mController.getAvailabilityStatus();
-
- assertThat(availabilityStatus).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void isSliceableCorrectKey_returnsTrue() {
- assertThat(mController.isSliceable()).isTrue();
- }
-
- @Test
- public void isChecked_testTrue() {
- Settings.Secure.putInt(mContext.getContentResolver(), SKIP_GESTURE, 1);
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void isChecked_testFalse() {
- Settings.Secure.putInt(mContext.getContentResolver(), SKIP_GESTURE, 0);
- assertThat(mController.isChecked()).isFalse();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
index 3e6ba6c..1a0539c 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.homepage.contextualcards;
+import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH;
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_HALF_WIDTH;
@@ -210,7 +211,7 @@
@Test
- public void assignCardWidth_noSuggestionCards_shouldNotHaveHalfCards() {
+ public void getCardsWithViewType_noSuggestionCards_shouldNotHaveHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -221,7 +222,7 @@
final List<ContextualCard> noSuggestionCards = buildCategoriedCards(getContextualCardList(),
categories);
- final List<ContextualCard> result = mManager.assignCardWidth(noSuggestionCards);
+ final List<ContextualCard> result = mManager.getCardsWithViewType(noSuggestionCards);
assertThat(result).hasSize(5);
for (ContextualCard card : result) {
@@ -230,7 +231,7 @@
}
@Test
- public void assignCardWidth_oneSuggestionCards_shouldNotHaveHalfCards() {
+ public void getCardsWithViewType_oneSuggestionCards_shouldNotHaveHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -241,7 +242,7 @@
final List<ContextualCard> oneSuggestionCards = buildCategoriedCards(
getContextualCardList(), categories);
- final List<ContextualCard> result = mManager.assignCardWidth(oneSuggestionCards);
+ final List<ContextualCard> result = mManager.getCardsWithViewType(oneSuggestionCards);
assertThat(result).hasSize(5);
for (ContextualCard card : result) {
@@ -250,7 +251,7 @@
}
@Test
- public void assignCardWidth_twoConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
+ public void getCardsWithViewType_twoConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -264,7 +265,7 @@
VIEW_TYPE_FULL_WIDTH, VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH,
VIEW_TYPE_FULL_WIDTH);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
twoConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -274,7 +275,7 @@
}
@Test
- public void assignCardWidth_twoNonConsecutiveSuggestionCards_shouldNotHaveHalfCards() {
+ public void getCardsWithViewType_twoNonConsecutiveSuggestionCards_shouldNotHaveHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
@@ -285,7 +286,7 @@
final List<ContextualCard> twoNonConsecutiveSuggestionCards = buildCategoriedCards(
getContextualCardList(), categories);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
twoNonConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -295,7 +296,7 @@
}
@Test
- public void assignCardWidth_threeConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
+ public void getCardsWithViewType_threeConsecutiveSuggestionCards_shouldHaveTwoHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
@@ -309,7 +310,7 @@
VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_FULL_WIDTH,
VIEW_TYPE_FULL_WIDTH);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
threeConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -319,7 +320,7 @@
}
@Test
- public void assignCardWidth_fourConsecutiveSuggestionCards_shouldHaveFourHalfCards() {
+ public void getCardsWithViewType_fourConsecutiveSuggestionCards_shouldHaveFourHalfCards() {
final List<Integer> categories = Arrays.asList(
ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
@@ -333,7 +334,7 @@
VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH, VIEW_TYPE_HALF_WIDTH,
VIEW_TYPE_HALF_WIDTH);
- final List<ContextualCard> result = mManager.assignCardWidth(
+ final List<ContextualCard> result = mManager.getCardsWithViewType(
fourConsecutiveSuggestionCards);
assertThat(result).hasSize(5);
@@ -342,6 +343,55 @@
}
}
+ @Test
+ public void getCardsWithViewType_onlyDeferredSetupCard_shouldHaveDeferredSetupCard() {
+ final List<ContextualCard> oneDeferredSetupCards = getDeferredSetupCardList();
+
+ final List<ContextualCard> result = mManager.getCardsWithViewType(oneDeferredSetupCards);
+
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_DEFERRED_SETUP);
+ }
+
+ @Test
+ public void getCardsWithViewType_hasDeferredSetupCard_shouldHaveDeferredSetupCard() {
+ final List<Integer> categories = Arrays.asList(
+ ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE,
+ ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
+ );
+ final List<ContextualCard> cards = buildCategoriedCards(getContextualCardList(),
+ categories);
+
+ final List<ContextualCard> result = mManager.getCardsWithViewType(cards);
+
+ assertThat(result).hasSize(5);
+ assertThat(result.get(0).getViewType()).isEqualTo(VIEW_TYPE_DEFERRED_SETUP);
+ }
+
+ @Test
+ public void getCardsWithViewType_noDeferredSetupCard_shouldNotHaveDeferredSetupCard() {
+ final List<Integer> categories = Arrays.asList(
+ ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
+ ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE,
+ ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE
+ );
+ final List<ContextualCard> cards = buildCategoriedCards(
+ getContextualCardList(), categories);
+
+ final List<ContextualCard> result = mManager.getCardsWithViewType(cards);
+
+ assertThat(result).hasSize(5);
+ for (int i = 0; i < result.size(); i++) {
+ assertThat(result.get(i).getViewType()).isNotEqualTo(
+ ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE);
+ }
+ }
+
private ContextualCard buildContextualCard(String sliceUri) {
return new ContextualCard.Builder()
.setName(TEST_SLICE_NAME)
@@ -396,4 +446,16 @@
.build());
return cards;
}
+
+ private List<ContextualCard> getDeferredSetupCardList() {
+ final List<ContextualCard> cards = new ArrayList<>();
+ cards.add(new ContextualCard.Builder()
+ .setName("deferred_setup")
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setCategory(ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE)
+ .setSliceUri(new Uri.Builder().appendPath("test_deferred_setup_path").build())
+ .setViewType(VIEW_TYPE_FULL_WIDTH)
+ .build());
+ return cards;
+ }
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
index bc34fd5..02d7a9d 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java
@@ -83,7 +83,8 @@
mBluetoothDevicesSlice = spy(new BluetoothDevicesSlice(mContext));
// Mock the icon and detail intent of Bluetooth.
- mIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_bluetooth);
+ mIcon = IconCompat.createWithResource(mContext,
+ com.android.internal.R.drawable.ic_settings_bluetooth);
mDetailIntent = PendingIntent.getActivity(mContext, 0, new Intent("test action"), 0);
doReturn(mIcon).when(mBluetoothDevicesSlice).getBluetoothDeviceIcon(any());
doReturn(mDetailIntent).when(mBluetoothDevicesSlice).getBluetoothDetailIntent(any());
@@ -208,4 +209,4 @@
final CharSequence sliceTitle = metadata.getTitle();
return TextUtils.equals(sliceTitle, title);
}
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelperTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelperTest.java
new file mode 100644
index 0000000..740a45b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceDeferredSetupCardRendererHelperTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2019 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.homepage.contextualcards.slices;
+
+import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP;
+import static com.android.settings.homepage.contextualcards.slices.SliceDeferredSetupCardRendererHelper.DeferredSetupCardViewHolder;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.net.Uri;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.slice.Slice;
+import androidx.slice.SliceProvider;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
+import androidx.slice.widget.SliceLiveData;
+
+import com.android.settings.R;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.intelligence.ContextualCardProto;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class SliceDeferredSetupCardRendererHelperTest {
+ private static final Uri TEST_SLICE_URI = Uri.parse("content://test/test");
+ private static final CharSequence TITLE = "test_title";
+ private static final CharSequence SUMMARY = "test_summary";
+
+ private Activity mActivity;
+ private SliceDeferredSetupCardRendererHelper mHelper;
+
+ @Before
+ public void setUp() {
+ // Set-up specs for SliceMetadata.
+ SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+ mActivity = Robolectric.buildActivity(Activity.class).create().get();
+ mActivity.setTheme(R.style.Theme_Settings_Home);
+ mHelper = new SliceDeferredSetupCardRendererHelper(mActivity);
+ }
+
+ @Test
+ public void createViewHolder_shouldAlwaysReturnCustomViewHolder() {
+ final RecyclerView.ViewHolder viewHolder = getDeferredSetupCardViewHolder();
+
+ assertThat(viewHolder).isInstanceOf(
+ DeferredSetupCardViewHolder.class);
+ }
+
+ @Test
+ public void bindView_shouldSetTitle() {
+ final RecyclerView.ViewHolder viewHolder = getDeferredSetupCardViewHolder();
+
+ mHelper.bindView(viewHolder, buildContextualCard(), buildSlice());
+
+ assertThat(((DeferredSetupCardViewHolder) viewHolder).title.getText()).isEqualTo(TITLE);
+ }
+
+ @Test
+ public void bindView_shouldSetSummary() {
+ final RecyclerView.ViewHolder viewHolder = getDeferredSetupCardViewHolder();
+
+ mHelper.bindView(viewHolder, buildContextualCard(), buildSlice());
+
+ assertThat(((DeferredSetupCardViewHolder) viewHolder).summary.getText()).isEqualTo(SUMMARY);
+ }
+
+ private RecyclerView.ViewHolder getDeferredSetupCardViewHolder() {
+ final RecyclerView recyclerView = new RecyclerView(mActivity);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ final View view = LayoutInflater.from(mActivity).inflate(VIEW_TYPE_DEFERRED_SETUP,
+ recyclerView, false);
+
+ return mHelper.createViewHolder(view);
+ }
+
+ private ContextualCard buildContextualCard() {
+ return new ContextualCard.Builder()
+ .setName("test_name")
+ .setCategory(ContextualCardProto.ContextualCard.Category.DEFERRED_SETUP_VALUE)
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setSliceUri(TEST_SLICE_URI)
+ .setViewType(VIEW_TYPE_DEFERRED_SETUP)
+ .build();
+ }
+
+ private Slice buildSlice() {
+ final IconCompat icon = IconCompat.createWithResource(mActivity, R.drawable.empty_icon);
+ final PendingIntent pendingIntent = PendingIntent.getActivity(
+ mActivity,
+ TITLE.hashCode() /* requestCode */,
+ new Intent("test action"),
+ 0 /* flags */);
+ final SliceAction action
+ = SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, TITLE);
+ return new ListBuilder(mActivity, TEST_SLICE_URI, ListBuilder.INFINITY)
+ .addRow(new ListBuilder.RowBuilder()
+ .addEndItem(icon, ListBuilder.ICON_IMAGE)
+ .setTitle(TITLE)
+ .setSubtitle(SUMMARY)
+ .setPrimaryAction(action))
+ .build();
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/location/LocationSliceTest.java b/tests/robotests/src/com/android/settings/location/LocationSliceTest.java
index 0618cd9..a373b1f 100644
--- a/tests/robotests/src/com/android/settings/location/LocationSliceTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationSliceTest.java
@@ -47,7 +47,7 @@
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
- R.drawable.ic_signal_location);
+ com.android.internal.R.drawable.ic_signal_location);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
}
}
diff --git a/tests/robotests/src/com/android/settings/media/MediaDeviceUpdateWorkerTest.java b/tests/robotests/src/com/android/settings/media/MediaDeviceUpdateWorkerTest.java
new file mode 100644
index 0000000..28bf4e9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/media/MediaDeviceUpdateWorkerTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2019 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.media;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.net.Uri;
+
+import com.android.settingslib.media.MediaDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class MediaDeviceUpdateWorkerTest {
+
+ private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
+ private static final String TEST_DEVICE_1_ID = "test_device_1_id";
+ private static final String TEST_DEVICE_2_ID = "test_device_2_id";
+ private static final String TEST_DEVICE_3_ID = "test_device_3_id";
+
+ private final List<MediaDevice> mMediaDevices = new ArrayList<>();
+
+ private MediaDeviceUpdateWorker mMediaDeviceUpdateWorker;
+ private ContentResolver mResolver;
+ private Context mContext;
+ private MediaDevice mMediaDevice1;
+ private MediaDevice mMediaDevice2;
+
+ @Before
+ public void setUp() {
+ mContext = spy(RuntimeEnvironment.application);
+ mMediaDeviceUpdateWorker = new MediaDeviceUpdateWorker(mContext, URI);
+ mResolver = mock(ContentResolver.class);
+
+ mMediaDevice1 = mock(MediaDevice.class);
+ when(mMediaDevice1.getId()).thenReturn(TEST_DEVICE_1_ID);
+ mMediaDevice2 = mock(MediaDevice.class);
+ when(mMediaDevice2.getId()).thenReturn(TEST_DEVICE_2_ID);
+ mMediaDevices.add(mMediaDevice1);
+ mMediaDevices.add(mMediaDevice2);
+
+ doReturn(mResolver).when(mContext).getContentResolver();
+ }
+
+ @Test
+ public void onDeviceListUpdate_shouldNotifyChange() {
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
+
+ verify(mResolver).notifyChange(URI, null);
+ }
+
+ @Test
+ public void onSelectedDeviceStateChanged_shouldNotifyChange() {
+ mMediaDeviceUpdateWorker.onSelectedDeviceStateChanged(null, 0);
+
+ verify(mResolver).notifyChange(URI, null);
+ }
+
+ @Test
+ public void onDeviceListUpdate_sameDeviceList_shouldBeEqual() {
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
+
+ final List<MediaDevice> newDevices = new ArrayList<>();
+ newDevices.add(mMediaDevice1);
+ newDevices.add(mMediaDevice2);
+
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(newDevices);
+ final List<MediaDevice> devices = mMediaDeviceUpdateWorker.getMediaDevices();
+
+ assertThat(devices.get(0).getId()).isEqualTo(newDevices.get(0).getId());
+ assertThat(devices.get(1).getId()).isEqualTo(newDevices.get(1).getId());
+ }
+
+ @Test
+ public void onDeviceListUpdate_add1DeviceToDeviceList_shouldBeEqual() {
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
+
+ final List<MediaDevice> newDevices = new ArrayList<>();
+ final MediaDevice device3 = mock(MediaDevice.class);
+ when(mMediaDevice2.getId()).thenReturn(TEST_DEVICE_3_ID);
+ newDevices.add(mMediaDevice1);
+ newDevices.add(mMediaDevice2);
+ newDevices.add(device3);
+
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(newDevices);
+ final List<MediaDevice> devices = mMediaDeviceUpdateWorker.getMediaDevices();
+
+ assertThat(devices.size()).isEqualTo(newDevices.size());
+ }
+
+ @Test
+ public void onDeviceListUpdate_less1DeviceToDeviceList_shouldBeEqual() {
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
+
+ final List<MediaDevice> newDevices = new ArrayList<>();
+ newDevices.add(mMediaDevice1);
+
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(newDevices);
+ final List<MediaDevice> devices = mMediaDeviceUpdateWorker.getMediaDevices();
+
+ assertThat(devices.size()).isEqualTo(newDevices.size());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputSliceTest.java
new file mode 100644
index 0000000..daaba90
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputSliceTest.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2019 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.media;
+
+import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.os.UserHandle;
+import android.util.IconDrawableFactory;
+
+import androidx.slice.Slice;
+import androidx.slice.SliceMetadata;
+import androidx.slice.SliceProvider;
+import androidx.slice.core.SliceAction;
+import androidx.slice.widget.SliceLiveData;
+
+import com.android.settingslib.media.LocalMediaManager;
+import com.android.settingslib.media.MediaDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class MediaOutputSliceTest {
+
+ private static final String TEST_PACKAGE_NAME = "com.fake.android.music";
+ private static final String TEST_LABEL = "Test app";
+ private static final String TEST_DEVICE_1_ID = "test_device_1_id";
+
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private ApplicationInfo mApplicationInfo;
+ @Mock
+ private ApplicationInfo mApplicationInfo2;
+ @Mock
+ private LocalMediaManager mLocalMediaManager;
+ @Mock
+ private IconDrawableFactory mIconDrawableFactory;
+ @Mock
+ private Drawable mTestDrawable;
+
+ private final List<MediaDevice> mDevices = new ArrayList<>();
+
+ private Context mContext;
+ private MediaOutputSlice mMediaOutputSlice;
+ private MediaDeviceUpdateWorker mMediaDeviceUpdateWorker;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt()))
+ .thenReturn(mApplicationInfo);
+ when(mPackageManager.getApplicationInfoAsUser(eq(TEST_PACKAGE_NAME), anyInt(), anyInt()))
+ .thenReturn(mApplicationInfo2);
+ when(mApplicationInfo.loadLabel(mPackageManager)).thenReturn(TEST_LABEL);
+ when(mIconDrawableFactory.getBadgedIcon(mApplicationInfo2, UserHandle.myUserId()))
+ .thenReturn(mTestDrawable);
+ when(mTestDrawable.getIntrinsicWidth()).thenReturn(100);
+ when(mTestDrawable.getIntrinsicHeight()).thenReturn(100);
+
+ // Set-up specs for SliceMetadata.
+ SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+
+ mMediaOutputSlice = new MediaOutputSlice(mContext);
+ mMediaDeviceUpdateWorker = new MediaDeviceUpdateWorker(mContext, MEDIA_OUTPUT_SLICE_URI);
+ mMediaDeviceUpdateWorker.setPackageName(TEST_PACKAGE_NAME);
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
+ mMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;
+ mMediaOutputSlice.init(TEST_PACKAGE_NAME, mMediaDeviceUpdateWorker, mIconDrawableFactory);
+ }
+
+ @Test
+ public void getSlice_shouldHaveAppTitle() {
+ final Slice mediaSlice = mMediaOutputSlice.getSlice();
+ final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
+
+ final SliceAction primaryAction = metadata.getPrimaryAction();
+ assertThat(primaryAction.getTitle().toString()).isEqualTo(TEST_LABEL);
+ }
+
+ @Test
+ public void onNotifyChange_foundMediaDevice_connect() {
+ mDevices.clear();
+ final MediaDevice device = mock(MediaDevice.class);
+ when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
+ when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(device);
+ mDevices.add(device);
+
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
+
+ final Intent intent = new Intent();
+ intent.putExtra("media_device_id", TEST_DEVICE_1_ID);
+
+ mMediaOutputSlice.onNotifyChange(intent);
+
+ verify(mLocalMediaManager).connectDevice(device);
+ }
+
+ @Test
+ public void onNotifyChange_notFoundMediaDevice_doNothing() {
+ mDevices.clear();
+ final MediaDevice device = mock(MediaDevice.class);
+ when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
+ when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(device);
+ mDevices.add(device);
+
+ mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
+
+ final Intent intent = new Intent();
+ intent.putExtra("media_device_id", "fake_123");
+
+ mMediaOutputSlice.onNotifyChange(intent);
+
+ verify(mLocalMediaManager, never()).connectDevice(device);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java b/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
index 61fe025..a2ca62e 100644
--- a/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RedactionInterstitialTest.java
@@ -12,6 +12,7 @@
import android.content.ContentResolver;
import android.content.Intent;
import android.os.UserHandle;
+import android.os.UserManager;
import android.provider.Settings;
import android.view.View;
import android.widget.RadioButton;
@@ -20,7 +21,6 @@
import com.android.settings.RestrictedRadioButton;
import com.android.settings.notification.RedactionInterstitial.RedactionInterstitialFragment;
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
-import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.After;
@@ -30,12 +30,13 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.shadow.api.Shadow;
+import org.robolectric.shadows.ShadowUserManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowUtils.class,
ShadowRestrictedLockUtilsInternal.class,
- ShadowUserManager.class,
})
public class RedactionInterstitialTest {
private RedactionInterstitial mActivity;
@@ -103,7 +104,9 @@
@Test
public void managedProfileNoRestrictionsTest() {
setupSettings(1 /* show */, 1 /* showUnredacted */);
- ShadowUserManager.getShadow().addManagedProfile(UserHandle.myUserId());
+ final ShadowUserManager sum =
+ Shadow.extract(RuntimeEnvironment.application.getSystemService(UserManager.class));
+ sum.setManagedProfile(true);
setupActivity();
assertHideAllVisible(false);
@@ -114,7 +117,9 @@
@Test
public void managedProfileUnredactedRestrictionTest() {
setupSettings(1 /* show */, 1 /* showUnredacted */);
- ShadowUserManager.getShadow().addManagedProfile(UserHandle.myUserId());
+ final ShadowUserManager sum =
+ Shadow.extract(RuntimeEnvironment.application.getSystemService(UserManager.class));
+ sum.setManagedProfile(true);
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
setupActivity();
diff --git a/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java
new file mode 100644
index 0000000..b411037
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 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.panel;
+
+import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.net.Uri;
+
+import com.android.settings.slices.CustomSliceRegistry;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class MediaOutputPanelTest {
+
+ private static final String TEST_PACKAGENAME = "com.test.packagename";
+
+ private MediaOutputPanel mPanel;
+
+ @Before
+ public void setUp() {
+ mPanel = MediaOutputPanel.create(RuntimeEnvironment.application, TEST_PACKAGENAME);
+ }
+
+ @Test
+ public void getSlices_containsNecessarySlices() {
+ final List<Uri> uris = mPanel.getSlices();
+
+ assertThat(uris).containsExactly(CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI);
+ }
+
+ @Test
+ public void getSlices_verifyPackageName_isEqual() {
+ final List<Uri> uris = mPanel.getSlices();
+
+ assertThat(uris.get(0).getQueryParameter(MEDIA_PACKAGE_NAME)).isEqualTo(TEST_PACKAGENAME);
+ }
+
+ @Test
+ public void getSeeMoreIntent_isNull() {
+ assertThat(mPanel.getSeeMoreIntent()).isNull();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/panel/PanelFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
index 99d5d6c..ae57a77 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
@@ -17,6 +17,8 @@
package com.android.settings.panel;
+import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
+
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
@@ -32,6 +34,8 @@
@RunWith(RobolectricTestRunner.class)
public class PanelFeatureProviderImplTest {
+ private static final String TEST_PACKAGENAME = "com.test.packagename";
+
private Context mContext;
private PanelFeatureProviderImpl mProvider;
@@ -44,7 +48,7 @@
@Test
public void getPanel_internetConnectivityKey_returnsCorrectPanel() {
final PanelContent panel = mProvider.getPanel(mContext,
- Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
+ Settings.Panel.ACTION_INTERNET_CONNECTIVITY, TEST_PACKAGENAME);
assertThat(panel).isInstanceOf(InternetConnectivityPanel.class);
}
@@ -52,8 +56,16 @@
@Test
public void getPanel_volume_returnsCorrectPanel() {
final PanelContent panel = mProvider.getPanel(mContext,
- Settings.Panel.ACTION_VOLUME);
+ Settings.Panel.ACTION_VOLUME, TEST_PACKAGENAME);
assertThat(panel).isInstanceOf(VolumePanel.class);
}
+
+ @Test
+ public void getPanel_mediaOutputKey_returnsCorrectPanel() {
+ final PanelContent panel = mProvider.getPanel(mContext,
+ ACTION_MEDIA_OUTPUT, TEST_PACKAGENAME);
+
+ assertThat(panel).isInstanceOf(MediaOutputPanel.class);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
index 73318f2..389c31e 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
@@ -59,7 +59,7 @@
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
mFakePanelContent = new FakePanelContent();
- doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
+ doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
ActivityController<FakeSettingsPanelActivity> activityController =
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
diff --git a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
index 7648d23..abefa67 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
@@ -58,7 +58,7 @@
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
mFakePanelContent = new FakePanelContent();
- doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
+ doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
ActivityController<FakeSettingsPanelActivity> activityController =
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
diff --git a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
new file mode 100644
index 0000000..359cf5d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2019 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.panel;
+
+import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_PACKAGE_NAME;
+import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Intent;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class SettingsPanelActivityTest {
+
+ @Test
+ public void startMediaOutputSlice_withPackageName_bundleShouldHaveValue() {
+ final Intent intent = new Intent()
+ .setAction("com.android.settings.panel.action.MEDIA_OUTPUT")
+ .putExtra("com.android.settings.panel.extra.PACKAGE_NAME",
+ "com.google.android.music");
+
+ final SettingsPanelActivity activity =
+ Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
+
+ assertThat(activity.mBundle.getString(KEY_PANEL_PACKAGE_NAME))
+ .isEqualTo("com.google.android.music");
+ assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
+ .isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
+ }
+
+ @Test
+ public void startMediaOutputSlice_withoutPackageName_bundleShouldNotHaveValue() {
+ final Intent intent = new Intent()
+ .setAction("com.android.settings.panel.action.MEDIA_OUTPUT");
+
+ final SettingsPanelActivity activity =
+ Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
+
+ assertThat(activity.mBundle.containsKey(KEY_PANEL_PACKAGE_NAME)).isFalse();
+ assertThat(activity.mBundle.containsKey(KEY_PANEL_TYPE_ARGUMENT)).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
index d8703be..9a18c1f 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -99,15 +99,6 @@
}
@Implementation
- protected boolean isManagedProfile(@UserIdInt int userId) {
- return mManagedProfiles.contains(userId);
- }
-
- public void addManagedProfile(int userId) {
- mManagedProfiles.add(userId);
- }
-
- @Implementation
protected boolean isQuietModeEnabled(UserHandle userHandle) {
return mIsQuietModeEnabled;
}
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragmentTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragmentTest.java
index d2f6e6c..6ad6377 100644
--- a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragmentTest.java
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppChooseSavedWifiNetworkFragmentTest.java
@@ -29,6 +29,7 @@
import android.content.Context;
import android.content.Intent;
+import android.provider.Settings;
import androidx.fragment.app.FragmentManager;
import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
@@ -88,9 +89,8 @@
@Test
public void clickCancelButton_processWifiDppQrCodeIntent_shouldFinish() {
- final Intent intent =
- new Intent(WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
- intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
+ final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
+ intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
final WifiDppConfiguratorActivity hostActivity = mActivityRule.launchActivity(intent);
onView(withText(resourceString(CANCEL))).perform(click());
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
index 215b7e2..76df764 100644
--- a/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
@@ -18,12 +18,18 @@
import static com.google.common.truth.Truth.assertThat;
+import android.app.Instrumentation;
import android.content.Intent;
import android.content.pm.ActivityInfo;
+import android.os.RemoteException;
+import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
+import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,6 +44,13 @@
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
+ private UiDevice mDevice;
+
+ @Before
+ public void setUp() {
+ mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ }
+
@Test
public void launchActivity_qrCodeScanner_shouldNotAutoFinish() {
Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
@@ -65,9 +78,8 @@
@Test
public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
- Intent intent = new Intent(
- WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
- intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
+ Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
+ intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
mActivityRule.launchActivity(intent);
@@ -124,12 +136,17 @@
// setWifiDppQrCode and check if getWifiDppQrCode correctly after rotation
mActivityRule.launchActivity(intent);
mActivityRule.getActivity().setWifiDppQrCode(wifiQrCode);
- mActivityRule.getActivity().setRequestedOrientation(
- ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- mActivityRule.getActivity().setRequestedOrientation(
- ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- WifiQrCode restoredWifiDppQrCode = mActivityRule.getActivity().getWifiDppQrCode();
+ try {
+ mDevice.setOrientationLeft();
+ mDevice.setOrientationNatural();
+ mDevice.setOrientationRight();
+ mDevice.setOrientationNatural();
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+
+ WifiQrCode restoredWifiDppQrCode = mActivityRule.getActivity().getWifiDppQrCode();
assertThat(restoredWifiDppQrCode).isNotNull();
assertThat(restoredWifiDppQrCode.getQrCode()).isEqualTo(VALID_WIFI_DPP_QR_CODE);
}
@@ -138,17 +155,22 @@
public void rotateScreen_shouldGetCorrectWifiNetworkConfig() {
WifiNetworkConfig wifiNetworkConfig = new WifiNetworkConfig("WPA", "WifiSsid", "password",
/* hiddenSsid */ false, /* networkId */ 0);
- Intent intent = new Intent(
- WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
- intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
+ Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
+ intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
// setWifiNetworkConfig and check if getWifiNetworkConfig correctly after rotation
mActivityRule.launchActivity(intent);
mActivityRule.getActivity().setWifiNetworkConfig(wifiNetworkConfig);
- mActivityRule.getActivity().setRequestedOrientation(
- ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- mActivityRule.getActivity().setRequestedOrientation(
- ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+
+ try {
+ mDevice.setOrientationLeft();
+ mDevice.setOrientationNatural();
+ mDevice.setOrientationRight();
+ mDevice.setOrientationNatural();
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+
WifiNetworkConfig restoredWifiNetworkConfig =
mActivityRule.getActivity().getWifiNetworkConfig();
diff --git a/tests/unit/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java b/tests/unit/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java
index 8626dee..18d62c2 100644
--- a/tests/unit/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java
+++ b/tests/unit/src/com/android/settings/wifi/dpp/WifiNetworkListFragmentTest.java
@@ -103,8 +103,7 @@
/** Launch the activity via an Intent with a String extra. */
private void launchActivity(String extraName, String extraValue) {
- final Intent intent = new Intent(
- WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
+ final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
if (extraName != null && extraValue != null) {
intent.putExtra(extraName, extraValue);
}
@@ -168,7 +167,7 @@
setupConnectedAccessPoint();
when(mWifiTracker.isConnected()).thenReturn(true);
- launchActivity(WifiDppUtils.EXTRA_QR_CODE, TEST_DPP_URL);
+ launchActivity(Settings.EXTRA_QR_CODE, TEST_DPP_URL);
callOnWifiStateChanged(WifiManager.WIFI_STATE_ENABLED);
onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(