Merge "Check for user restrictions disallowing BT in BluetoothEnabler."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 7a23fd5..66068eb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -73,6 +73,7 @@
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
<uses-permission android:name="android.permission.READ_SEARCH_INDEXABLES" />
<uses-permission android:name="android.permission.OEM_UNLOCK_STATE" />
+ <uses-permission android:name="android.permission.MANAGE_USER_OEM_UNLOCK_STATE" />
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.MANAGE_FINGERPRINT" />
@@ -166,7 +167,7 @@
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.network.NetworkDashboardFragment"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/network_dashboard_summary"/>
+ android:resource="@string/network_dashboard_summary"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
@@ -193,7 +194,7 @@
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/connected_devices_dashboard_summary"/>
+ android:resource="@string/connected_devices_dashboard_summary"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
@@ -877,7 +878,7 @@
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
<meta-data android:name="com.android.settings.summary"
- android:value="@string/display_dashboard_summary"/>
+ android:resource="@string/display_dashboard_summary"/>
</activity>
<!-- Keep compatibility with old shortcuts. -->
@@ -2519,7 +2520,7 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
- <intent-filter android:priority="120">
+ <intent-filter android:priority="160">
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
<meta-data android:name="com.android.settings.category"
@@ -2560,7 +2561,7 @@
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
<meta-data android:name="com.android.settings.summary"
- android:value="@string/sound_dashboard_summary"/>
+ android:resource="@string/sound_dashboard_summary"/>
</activity>
<!-- Keep compatibility with old shortcuts. -->
@@ -2582,7 +2583,7 @@
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.apps" />
+ android:value="com.android.settings.category.ia.notifications" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.NotificationApps" />
</activity>
@@ -2645,6 +2646,10 @@
android:value="true" />
</activity>
+ <!-- Confirmation dialog for enabling notification access from CompanionDeviceManager -->
+ <activity android:name=".notification.NotificationAccessConfirmationActivity"
+ android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" />
+
<receiver android:name=".widget.SettingsAppWidgetProvider"
android:label="@string/gadget_title"
android:exported="false"
@@ -2966,7 +2971,7 @@
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/app_and_notification_dashboard_summary"/>
+ android:resource="@string/app_and_notification_dashboard_summary"/>
</activity>
<activity android:name=".Settings$UserAndAccountDashboardActivity"
@@ -2998,7 +3003,7 @@
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.system.SystemDashboardFragment"/>
<meta-data android:name="com.android.settings.summary"
- android:value="@string/system_dashboard_summary"/>
+ android:resource="@string/system_dashboard_summary"/>
</activity>
<activity android:name=".Settings$SupportDashboardActivity"
diff --git a/res/color/battery_icon_color_error.xml b/res/color/battery_icon_color_error.xml
new file mode 100644
index 0000000..3a71aae
--- /dev/null
+++ b/res/color/battery_icon_color_error.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:alpha="@*android:dimen/secondary_content_alpha_material_dark"
+ android:color="?android:attr/colorError"/>
+</selector>
\ No newline at end of file
diff --git a/res/drawable/action_bar_dropshadow.xml b/res/drawable/action_bar_dropshadow.xml
new file mode 100644
index 0000000..dd85877
--- /dev/null
+++ b/res/drawable/action_bar_dropshadow.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:angle="270"
+ android:startColor="#4D000000"
+ android:endColor="@android:color/transparent"
+ android:type="linear" />
+ <size android:height="8dp" />
+</shape>
\ No newline at end of file
diff --git a/res/drawable/ic_auto_wifi.xml b/res/drawable/ic_auto_wifi.xml
new file mode 100644
index 0000000..82e42f0
--- /dev/null
+++ b/res/drawable/ic_auto_wifi.xml
@@ -0,0 +1,35 @@
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="M18 10l3 0 -10 -9 -10 9 3 0 0 8 7.1 0c0 -0.3 -0.1 -0.7 -0.1 -1 0 -3.9 3.1 -7 7 -7z"
+ android:fillColor="#FFFFFFFF" />
+ <path
+ android:pathData="M18 14l0 1.6 2.1 -2.1 -2.1 -2.2 0 1.6c-2.3 0 -4.2 1.9 -4.2 4.3 0 0.8 0.2 1.6 0.7 2.3l0.8 -0.8C15.1 18.3 14.9 17.8 14.9 17.2 14.8 15.4 16.2 14 18 14"
+ android:strokeWidth="0.5"
+ android:fillColor="#FFFFFFFF"
+ android:strokeMiterLimit="10" />
+ <path
+ android:pathData="M20.8 15.7c0.2 0.4 0.4 0.9 0.4 1.5 0 1.8 -1.4 3.2 -3.2 3.2l0 -1.6 -2.1 2.1 2.1 2.1 0 -1.6c2.3 0 4.2 -1.9 4.2 -4.2 0 -0.8 -0.2 -1.6 -0.7 -2.3l-0.7 0.8z"
+ android:strokeWidth="0.5"
+ android:fillColor="#FFFFFFFF"
+ android:strokeMiterLimit="10" />
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_instant_apps_badge.xml b/res/drawable/ic_instant_apps_badge.xml
deleted file mode 100644
index 115aa83..0000000
--- a/res/drawable/ic_instant_apps_badge.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (C) 2017 The Android Open Source Project
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License
- -->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="48dp"
- android:height="48dp"
- android:viewportWidth="48"
- android:viewportHeight="48">
- <path
- android:fillColor="#FFFFFF"
- android:fillType="evenOdd"
- android:pathData="M 24.5 2.7 C 35.5456949966 2.7 44.5 11.6543050034 44.5 22.7 C 44.5 33.7456949966 35.5456949966 42.7 24.5 42.7 C 13.4543050034 42.7 4.5 33.7456949966 4.5 22.7 C 4.5 11.6543050034 13.4543050034 2.7 24.5 2.7 Z" />
- <path
- android:fillColor="#757575"
- android:fillType="evenOdd"
- android:pathData="M 33.3 19.1 L 26.4 19.1 L 26.4 5.8 L 16.6 26.4 L 23.5 26.3 L 23.5 39.6 Z" />
- <path
- android:fillType="evenOdd"
- android:pathData="M 0.5 0 H 48.5 V 48 H 0.5 V 0 Z" />
-</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_instant_apps_badge_bg.xml b/res/drawable/ic_instant_apps_badge_bg.xml
deleted file mode 100644
index bf8d3ea..0000000
--- a/res/drawable/ic_instant_apps_badge_bg.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (C) 2017 The Android Open Source Project
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License
- -->
-<shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="oval">
- <gradient android:type="radial"
- android:startColor="#4d000000"
- android:endColor="#00000000"
- android:gradientRadius="12dp"/>
-</shape>
\ No newline at end of file
diff --git a/res/drawable/ic_media_stream_on_24dp.xml b/res/drawable/ic_media_stream_on_24dp.xml
new file mode 100644
index 0000000..3db55dd
--- /dev/null
+++ b/res/drawable/ic_media_stream_on_24dp.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M18,3h-5c-0.55,0 -1,0.45 -1,1v8.3a3.88,3.88 0,0 0,-2.9 -0.04c-1.79,0.67 -3.11,2.35 -3.1,4.26A4.483,4.483 0,0 0,10.5 21c2.5,0 4.5,-2.3 4.5,-4.5V6h3c0.55,0 1,-0.45 1,-1V4c0,-0.55 -0.45,-1 -1,-1z"/>
+</vector>
diff --git a/res/drawable/ic_open_wifi_autoconnect.xml b/res/drawable/ic_open_wifi_autoconnect.xml
new file mode 100644
index 0000000..c752522
--- /dev/null
+++ b/res/drawable/ic_open_wifi_autoconnect.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="M12.7 10C11.9 7.7 9.7 6 7 6 3.7 6 1 8.7 1 12c0 3.3 2.7 6 6 6 2.6 0 4.8 -1.7 5.7 -4l4.3 0 0 4 4 0 0 -4 2 0 0 -4 -10.3 0zM7 16C4.8 16 3 14.2 3 12 3 9.8 4.8 8 7 8 8.1 8 9 8.4 9.6 9.1L8.5 10.2C8.3 9.9 7.8 9.5 7 9.5 5.6 9.5 4.6 10.6 4.6 12c0 1.4 1.1 2.5 2.4 2.5 1.6 0 2.1 -1.1 2.2 -1.7l-2.2 0 0 -1.4 3.8 0c0 0.2 0.1 0.4 0.1 0.6 -0.1 2.3 -1.7 4 -3.9 4z"
+ android:fillColor="#FFFFFFFF"/>
+</vector>
diff --git a/res/drawable/ic_open_wifi_notifications.xml b/res/drawable/ic_open_wifi_notifications.xml
new file mode 100644
index 0000000..5435bdb
--- /dev/null
+++ b/res/drawable/ic_open_wifi_notifications.xml
@@ -0,0 +1,37 @@
+<!--
+ Copyright (C) 2016 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="24.0dp"
+ android:height="24.0dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="M8 22.5c0.8 0 1.5 -0.7 1.5 -1.5l-3 0c0 0.8 0.7 1.5 1.5 1.5z"
+ android:fillColor="#FFFFFFFF" />
+ <path
+ android:pathData="M12.5 17.8l0 -3.6C12.5 12 11.3 10.1 9.1 9.6l0 -0.5C9.1 8.5 8.6 8 8 8 7.4 8 6.9 8.5 6.9 9.1l0 0.5C4.8 10.1 3.5 12 3.5 14.2l0 3.6 -1.5 1.5 0 0.7 12 0 0 -0.7 -1.5 -1.5z"
+ android:fillColor="#FFFFFFFF" />
+ <path
+ android:pathData="M10 4.6l1.1 1.1c2.8 -2.8 7.4 -2.8 10.2 0L22.4 4.6C19 1.1 13.5 1.1 10 4.6"
+ android:fillColor="#FFFFFFFF" />
+ <path
+ android:pathData="M14.5 9.1L16.2 10.8 18 9.1C17 8.2 15.5 8.2 14.5 9.1"
+ android:fillColor="#FFFFFFFF" />
+ <path
+ android:pathData="M12.3 6.9L13.4 8C15 6.4 17.5 6.4 19.1 8L20.2 6.9C18 4.7 14.5 4.7 12.3 6.9"
+ android:fillColor="#FFFFFFFF" />
+</vector>
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 5ffeec5..b05c0dc 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -17,49 +17,27 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/app_snippet"
- style="@style/EntityHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|top"
- android:orientation="vertical"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:paddingTop="24dp"
- android:paddingBottom="24dp"
- android:clipChildren="false"
- android:clipToPadding="false">
+ android:orientation="vertical">
<!-- App snippet with buttons -->
<RelativeLayout
+ android:id="@+id/app_snippet"
+ style="@style/EntityHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:paddingStart="8dp"
- android:clipChildren="false"
- android:clipToPadding="false">
-
- <FrameLayout android:id="@+id/app_icon_frame"
- android:layout_width="80dp"
- android:layout_height="80dp"
- android:clipChildren="false"
- android:clipToPadding="false">
- <ImageView
- android:id="@+id/app_detail_icon"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="fitXY"
- android:layout_gravity="center_horizontal"
- android:antialias="true"/>
- <ImageView android:id="@+id/app_icon_instant_apps_badge"
- android:layout_width="22dp"
- android:layout_height="22dp"
- android:layout_gravity="end|bottom"
- android:layout_margin="8dp"
- android:visibility="gone"
- android:elevation="20dp"
- android:background="@drawable/ic_instant_apps_badge_bg"
- android:src="@drawable/ic_instant_apps_badge" />
- </FrameLayout>
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="0dp"
+ android:paddingTop="24dp"
+ android:paddingBottom="24dp">
+ <ImageView
+ android:id="@+id/app_detail_icon"
+ android:layout_width="56dp"
+ android:layout_height="56dp"
+ android:scaleType="fitXY"
+ android:layout_gravity="center_horizontal"
+ android:antialias="true"/>
<LinearLayout
android:id="@+id/app_detail_links"
@@ -70,19 +48,22 @@
<ImageButton
android:id="@+id/right_button"
- style="@android:style/Widget.Material.Button.Borderless"
+ style="?android:attr/actionOverflowButtonStyle"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="0dp"
+ android:minWidth="@dimen/min_tap_target_size"
android:src="@drawable/ic_settings_24dp"
android:tint="?android:attr/colorAccent"/>
<ImageButton
android:id="@+id/left_button"
- style="@android:style/Widget.Material.Button.Borderless"
+ style="?android:attr/actionOverflowButtonStyle"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="0dp"
+ android:minWidth="@dimen/min_tap_target_size"
+ android:src="@null"
android:tint="?android:attr/colorAccent"/>
</LinearLayout>
@@ -90,7 +71,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_toEndOf="@id/app_icon_frame"
+ android:layout_toEndOf="@id/app_detail_icon"
android:layout_toStartOf="@id/app_detail_links"
android:paddingStart="24dp"
android:paddingEnd="24dp"
@@ -131,4 +112,9 @@
</RelativeLayout>
+ <!-- Drop shadow -->
+ <View android:layout_width="match_parent"
+ android:layout_height="5dp"
+ android:background="@drawable/action_bar_dropshadow"/>
+
</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/master_clear.xml b/res/layout/master_clear.xml
index 662b7db..4423e10 100644
--- a/res/layout/master_clear.xml
+++ b/res/layout/master_clear.xml
@@ -102,6 +102,38 @@
android:text="@string/erase_external_storage_description" />
</LinearLayout>
</LinearLayout>
+ <LinearLayout android:id="@+id/erase_esim_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:focusable="true"
+ android:clickable="true">
+ <CheckBox android:id="@+id/erase_esim"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:paddingEnd="8dp"
+ android:focusable="false"
+ android:clickable="false"
+ android:duplicateParentState="true" />
+ <LinearLayout android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:orientation="vertical">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="12dp"
+ android:textSize="18sp"
+ android:text="@string/erase_esim_storage" />
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="4sp"
+ android:textSize="14sp"
+ android:text="@string/erase_esim_storage_description" />
+ </LinearLayout>
+ </LinearLayout>
</LinearLayout>
</ScrollView>
<Button
diff --git a/res/layout/preference_wallpaper_type.xml b/res/layout/preference_wallpaper_type.xml
deleted file mode 100644
index a35a24e..0000000
--- a/res/layout/preference_wallpaper_type.xml
+++ /dev/null
@@ -1,43 +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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:gravity="center_vertical"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" >
-
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="40dp"
- android:layout_height="40dp"
- android:layout_gravity="center"
- android:scaleType="fitXY"
- android:layout_marginEnd="16dip"
- android:contentDescription="@null" />
-
- <TextView android:id="@android:id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textAppearance="@android:style/TextAppearance.Material.Subhead"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal"
- android:layout_weight="1" />
-
-</LinearLayout>
diff --git a/res/layout/screen_zoom_preview_settings.xml b/res/layout/screen_zoom_preview_settings.xml
index a635612..9a0cc59 100644
--- a/res/layout/screen_zoom_preview_settings.xml
+++ b/res/layout/screen_zoom_preview_settings.xml
@@ -42,7 +42,7 @@
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
- android:src="@drawable/wifi_signal_dark"
+ android:src="@drawable/ic_settings_wireless"
android:tint="?android:attr/colorAccent"
android:scaleType="center" />
diff --git a/res/layout/storage_item.xml b/res/layout/storage_item.xml
index 33f4f9e..0c1f60c 100644
--- a/res/layout/storage_item.xml
+++ b/res/layout/storage_item.xml
@@ -76,6 +76,7 @@
android:id="@android:id/progress"
android:layout_width="match_parent"
android:layout_height="8dp"
+ android:layout_marginStart="60dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:visibility="gone"
diff --git a/res/mipmap-hdpi/ic_accessibility_generic.png b/res/mipmap-hdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..e54166b
--- /dev/null
+++ b/res/mipmap-hdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-hdpi/ic_accessibility_magnification.png b/res/mipmap-hdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..a91bc6e
--- /dev/null
+++ b/res/mipmap-hdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-mdpi/ic_accessibility_generic.png b/res/mipmap-mdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..77dc47b
--- /dev/null
+++ b/res/mipmap-mdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-mdpi/ic_accessibility_magnification.png b/res/mipmap-mdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..9ec5107
--- /dev/null
+++ b/res/mipmap-mdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_accessibility_generic.png b/res/mipmap-xhdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..1152c42
--- /dev/null
+++ b/res/mipmap-xhdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_accessibility_magnification.png b/res/mipmap-xhdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..0b3a32e
--- /dev/null
+++ b/res/mipmap-xhdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_accessibility_generic.png b/res/mipmap-xxhdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..48f39c2
--- /dev/null
+++ b/res/mipmap-xxhdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_accessibility_magnification.png b/res/mipmap-xxhdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..3eeb1c9
--- /dev/null
+++ b/res/mipmap-xxhdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_accessibility_generic.png b/res/mipmap-xxxhdpi/ic_accessibility_generic.png
new file mode 100755
index 0000000..e9ca879
--- /dev/null
+++ b/res/mipmap-xxxhdpi/ic_accessibility_generic.png
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_accessibility_magnification.png b/res/mipmap-xxxhdpi/ic_accessibility_magnification.png
new file mode 100755
index 0000000..7d37612
--- /dev/null
+++ b/res/mipmap-xxxhdpi/ic_accessibility_magnification.png
Binary files differ
diff --git a/res/values/colors.xml b/res/values/colors.xml
index ec8fca9..4a09594 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -79,6 +79,8 @@
<!-- Accessibility SUW colors -->
<color name="material_blue_500">#4285F4</color>
<color name="material_blue_700">#3367D6</color>
+ <color name="material_grey_100">#f5f5f5</color>
+ <color name="material_grey_200">#ffffff</color>
<color name="message_text_incoming">#ffffffff</color>
<color name="message_text_outgoing">#ff323232</color>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 09f7cda..6495ab0 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -22,6 +22,7 @@
<dimen name="action_bar_switch_padding">16dip</dimen>
<dimen name="app_icon_size">40dip</dimen>
+ <dimen name="min_tap_target_size">48dp</dimen>
<dimen name="screen_margin_sides">64dip</dimen>
<dimen name="screen_margin_top">72dip</dimen>
<dimen name="screen_margin_bottom">48dip</dimen>
@@ -241,7 +242,6 @@
<dimen name="mdm_app_icon_width_height">56dp</dimen>
<!-- Launcher Icons -->
- <dimen name="launcher_icon_elevation">6dp</dimen>
<dimen name="shortcut_size_maskable">120dp</dimen>
<dimen name="shortcut_size">40dp</dimen>
<dimen name="shortcut_icon_size">16dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f95a25c..11ecfbf 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1628,6 +1628,8 @@
<string name="wifi_wakeup">Turn on Wi\u2011Fi automatically</string>
<!-- Checkbox summary for option to enable Wi-Fi when high quality saved networks are nearby-->
<string name="wifi_wakeup_summary">Wi\u2011Fi will turn back on near high\u2011quality saved networks, like your home network</string>
+ <!-- Checkbox summary for Wi-Fi wakeup option to explain that Wi-Fi wakeup is disabled because Wi-Fi scanning is turned off -->
+ <string name="wifi_wakeup_summary_scanning_disabled">Unavailable because Wi\u2011Fi scanning is turned off</string>
<!-- Checkbox title for option to toggle poor network detection -->
<string name="wifi_poor_network_detection">Avoid poor connections</string>
<!-- Checkbox summary for option to toggle poor network detection -->
@@ -2376,7 +2378,7 @@
<!-- [CHAR LIMIT=40] Display settings screen, setting option name to change whether the device wakes up when a lift gesture is detected. -->
<string name="lift_to_wake_title">Lift to wake</string>
<!-- [CHAR LIMIT=30] Display settings screen, setting option name to change whether the ambient display feature is enabled. -->
- <string name="doze_title">Incoming notification screen</string>
+ <string name="doze_title">Ambient display</string>
<!-- [CHAR LIMIT=NONE] Display settings screen, setting description for the ambient display feature. -->
<string name="doze_summary">Wake screen when you receive notifications</string>
<!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size -->
@@ -3033,6 +3035,12 @@
<string name="erase_external_storage_description" product="nosdcard">Erase all the data on the internal USB storage, such as music or photos</string>
<!-- SD card & phone storage settings screen, description for check box to erase USB storage [CHAR LIMIT=NONE] -->
<string name="erase_external_storage_description" product="default">Erase all the data on the SD card, such as music or photos</string>
+ <!-- SD card & phone storage settings screen, label for check box to erase all the carriers information on the embedded SIM card [CHAR LIMIT=30] -->
+ <string name="erase_esim_storage">Erase eSIMs</string>
+ <!-- SD card & phone storage settings screen, description for check box to erase eSIMs for default devices [CHAR LIMIT=NONE] -->
+ <string name="erase_esim_storage_description" product="default">Erase all eSIMs on the phone. This will not cancel your mobile service plan.</string>
+ <!-- SD card & phone storage settings screen, description for check box to erase eSIMs for tablets [CHAR LIMIT=NONE] -->
+ <string name="erase_esim_storage_description" product="tablet">Erase all eSIMs on the tablet. This will not cancel your mobile service plan.</string>
<!-- SD card & phone storage settings screen, button on screen after user selects Factory data reset -->
<string name="master_clear_button_text" product="tablet">Reset tablet</string>
<!-- SD card & phone storage settings screen, button on screen after user selects Factory data reset -->
@@ -3740,6 +3748,9 @@
<!-- Manage applications, individual application info screen, summary for the option which will trigger application info in it's installer [CHAR_LIMIT=50] -->
<string name="app_install_details_summary">App installed from <xliff:g id="app_store">%1$s</xliff:g></string>
+ <!-- Manage applications, individual application info screen, summary for the option which will trigger instant app info in it's installer [CHAR_LIMIT=50] -->
+ <string name="instant_app_details_summary">More info on <xliff:g id="app_store">%1$s</xliff:g></string>
+
<!-- App Ops Settings --> <skip />
<!-- [CHAR LIMIT=NONE] App ops settings title, on main settings screen. If clicked, the user is taken to a settings screen for app operations -->
<string name="app_ops_settings">App ops</string>
@@ -4683,9 +4694,9 @@
<string name="battery_last_full_charge">Last full charge</string>
<!-- Description for text in battery footer. [CHAR LIMIT=120] -->
<string name="battery_footer_summary">Remaining battery time is approximate and can change based on usage</string>
- <!-- Title for battery usage detail in foreground. [CHAR LIMIT=80] -->
+ <!-- Title for text that shows the amount of time an app has been running while in the foreground. [CHAR LIMIT=80] -->
<string name="battery_detail_foreground">While in active use</string>
- <!-- Title for battery usage detail in background. [CHAR LIMIT=80] -->
+ <!-- Title for text that shows the amount of time an app has been running while in the background. [CHAR LIMIT=80] -->
<string name="battery_detail_background">While in background</string>
<!-- Title for battery usage amount by this app. [CHAR LIMIT=80] -->
<string name="battery_detail_power_usage">Battery usage</string>
@@ -6364,6 +6375,12 @@
<!-- Sound: Title for the option defining the default notification sound. [CHAR LIMIT=30] -->
<string name="notification_ringtone_title">Default notification sound</string>
+ <!-- Sound: Sound title for apps that have not provided a title. [CHAR LIMIT=30] -->
+ <string name="notification_unknown_sound_title">App provided sound</string>
+
+ <!-- Notification sound summary when chosen sound is the system default. -->
+ <string name="notification_sound_default">Default notification sound</string>
+
<!-- Sound: Title for the option defining the default alarm sound. [CHAR LIMIT=30] -->
<string name="alarm_ringtone_title">Default alarm sound</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index e9d25ff..bae36b3 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -416,7 +416,7 @@
<style name="TextAppearance.EntityHeaderTitle"
parent="@android:style/TextAppearance.Material.Subhead">
<item name="android:textColor">?android:attr/textColorPrimary</item>
- <item name="android:textSize">24sp</item>
+ <item name="android:textSize">16sp</item>
</style>
<style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 5198f76..006788f 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -149,16 +149,17 @@
<!-- Accessibility portion of Setup Wizard -->
<style name="SetupWizardAccessibilityTheme" parent="Theme.SettingsBase">
<item name="android:windowLightStatusBar">false</item>
- <item name="android:colorPrimary">@color/material_blue_700</item>
- <item name="android:colorPrimaryDark">@color/material_blue_700</item>
- <item name="android:actionBarTheme">@android:style/ThemeOverlay.Material.Dark.ActionBar</item>
+ <item name="android:colorPrimary">@color/material_grey_100</item>
+ <item name="android:colorAccent">@color/material_blue_700</item>
+ <item name="android:titleTextColor">@color/material_blue_700</item>
<item name="preferenceTheme">@style/PreferenceTheme</item>
<item name="switchBarTheme">@style/SetupWizardAccessibilitySwitchBarTheme</item>
</style>
<style name="SetupWizardAccessibilitySwitchBarTheme" parent="ThemeOverlay.SwitchBar.Settings">
- <item name="switchBarBackgroundColor">@color/material_blue_500</item>
- <item name="android:colorControlActivated">@android:color/white</item>
+ <item name="switchBarBackgroundColor">@color/material_grey_200</item>
+ <item name="android:colorControlActivated">@color/material_blue_500</item>
+ <item name="android:textColorPrimary">@android:color/black</item>
</style>
<!-- Theme with no local references, used by AccountPreferenceBase where we have to inflate
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 48e11af..02b9949 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -54,12 +54,8 @@
<Preference
android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
android:key="magnification_preference_screen"
- android:title="@string/accessibility_screen_magnification_title"/>
-
- <Preference
- android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
- android:key="daltonizer_preference_screen"
- android:title="@string/accessibility_display_daltonizer_preference_title" />
+ android:title="@string/accessibility_screen_magnification_title"
+ android:icon="@mipmap/ic_accessibility_magnification" />
<SwitchPreference
android:key="toggle_large_pointer_icon"
@@ -117,6 +113,11 @@
android:key="toggle_high_text_contrast_preference"
android:title="@string/accessibility_toggle_high_text_contrast_preference_title" />
+ <Preference
+ android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
+ android:key="daltonizer_preference_screen"
+ android:title="@string/accessibility_display_daltonizer_preference_title" />
+
<SwitchPreference
android:key="toggle_inversion_preference"
android:title="@string/accessibility_display_inversion_preference_title"
diff --git a/res/xml/app_memory_settings.xml b/res/xml/app_memory_settings.xml
index 53a71ff..308f189 100644
--- a/res/xml/app_memory_settings.xml
+++ b/res/xml/app_memory_settings.xml
@@ -18,26 +18,25 @@
android:title="@string/memory_usage">
<PreferenceCategory
- android:title="@string/average_memory_use"/>
+ android:title="@string/average_memory_use">
- <com.android.settings.SummaryPreference
- android:key="status_header"
- android:selectable="false" />
+ <com.android.settings.SummaryPreference
+ android:key="status_header"
+ android:selectable="false" />
- <com.android.settings.applications.SpacePreference
- android:layout_height="5dp" />
+ <Preference
+ android:key="frequency"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/running_frequency" />
- <Preference
- android:key="frequency"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/running_frequency" />
+ <Preference
+ android:key="max_usage"
+ android:selectable="false"
+ android:layout="@layout/horizontal_preference"
+ android:title="@string/memory_maximum_usage" />
- <Preference
- android:key="max_usage"
- android:selectable="false"
- android:layout="@layout/horizontal_preference"
- android:title="@string/memory_maximum_usage" />
+ </PreferenceCategory>
<PreferenceCategory
android:key="processes"
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
index 5b848e6..ccaa724 100644
--- a/res/xml/channel_notification_settings.xml
+++ b/res/xml/channel_notification_settings.xml
@@ -32,10 +32,12 @@
android:title="@string/notification_importance_title" />
<!-- Default ringtone -->
- <com.android.settings.notification.DefaultNotificationTonePreference
+ <com.android.settings.notification.NotificationSoundPreference
android:key="ringtone"
- android:title="@string/notification_ringtone_title"
- android:dialogTitle="@string/notification_ringtone_title"
+ android:title="@string/notification_channel_sound_title"
+ android:dialogTitle="@string/notification_channel_sound_title"
+ android:showSilent="true"
+ android:showDefault="true"
android:ringtoneType="notification" />
<!-- Vibration -->
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index 626cd33..a6ffff4 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -18,6 +18,10 @@
android:title="@string/configure_notification_settings"
android:key="configure_notification_settings">
+ <PreferenceCategory
+ android:key="dashboard_tile_placeholder"
+ android:order="1"/>
+
<!-- Pulse notification light -->
<SwitchPreference
android:key="notification_pulse"
diff --git a/res/xml/installed_app_details_ia.xml b/res/xml/installed_app_details_ia.xml
index b092753..538205f 100644
--- a/res/xml/installed_app_details_ia.xml
+++ b/res/xml/installed_app_details_ia.xml
@@ -52,6 +52,11 @@
android:summary="@string/summary_placeholder"
android:selectable="true"/>
+ <com.android.settings.applications.AppDomainsPreference
+ android:key="instant_app_launch_supported_domain_urls"
+ android:title="@string/app_launch_supported_domain_urls_title"
+ android:selectable="true" />
+
<Preference
android:key="data_settings"
android:title="@string/data_usage_summary_title"
diff --git a/res/xml/legacy_channel_notification_settings.xml b/res/xml/legacy_channel_notification_settings.xml
new file mode 100644
index 0000000..4e341a9
--- /dev/null
+++ b/res/xml/legacy_channel_notification_settings.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" >
+
+
+ <!-- Importance toggle -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="allow_sound"
+ android:title="@string/allow_sound" />
+
+ <!-- Visibility Override -->
+ <com.android.settings.notification.RestrictedDropDownPreference
+ android:key="visibility_override"
+ android:title="@string/app_notification_visibility_override_title" />
+
+ <!-- Bypass DND -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="bypass_dnd"
+ android:title="@string/app_notification_override_dnd_title"
+ android:summary="@string/app_notification_override_dnd_summary"
+ settings:useAdditionalSummary="true" />
+
+</PreferenceScreen>
diff --git a/res/xml/power_usage_detail_ia.xml b/res/xml/power_usage_detail_ia.xml
index cfaa712..39e6c38 100644
--- a/res/xml/power_usage_detail_ia.xml
+++ b/res/xml/power_usage_detail_ia.xml
@@ -56,7 +56,7 @@
<Preference
android:key="battery_optimization"
- android:title="@string/battery_detail_background"
+ android:title="@string/high_power_apps"
android:summary="@string/high_power_off"
android:selectable="true"/>
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index 2866767..abd659e 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -46,7 +46,7 @@
<com.android.settings.widget.MasterSwitchPreference
android:fragment="com.android.settings.fuelgauge.BatterySaverSettings"
- android:key="battery_saver"
+ android:key="battery_saver_summary"
android:title="@string/battery_saver"/>
<SwitchPreference
@@ -56,14 +56,14 @@
<!-- Cross-listed item, if you change this, also change it in ia_display_settings.xml -->
<SwitchPreference
- android:key="auto_brightness"
+ android:key="auto_brightness_battery"
android:title="@string/auto_brightness_title"
android:summary="@string/auto_brightness_summary"
settings:keywords="@string/keywords_display_auto_brightness"/>
<!-- Cross-listed item, if you change this, also change it in ia_display_settings.xml -->
<com.android.settings.TimeoutListPreference
- android:key="screen_timeout"
+ android:key="screen_timeout_battery"
android:title="@string/screen_timeout"
android:summary="@string/screen_timeout_summary"
android:entries="@array/screen_timeout_entries"
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index 86e3b16..7946dd9 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -60,7 +60,7 @@
<Preference
android:key="encryption_and_credential"
android:title="@string/encryption_and_credential_settings_title"
- android:summary="@string/encryption_and_credential_settings_summary"/>
+ android:summary="@string/encryption_and_credential_settings_summary"
android:fragment="com.android.settings.EncryptionAndCredential"/>
<Preference android:key="manage_trust_agents"
diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml
index b1625cc..14990a5 100644
--- a/res/xml/wifi_configure_settings.xml
+++ b/res/xml/wifi_configure_settings.xml
@@ -22,19 +22,19 @@
<SwitchPreference
android:key="enable_wifi_wakeup"
android:title="@string/wifi_wakeup"
- android:icon="@drawable/ic_settings_home"
+ android:icon="@drawable/ic_auto_wifi"
android:summary="@string/wifi_wakeup_summary" />
<SwitchPreference
android:key="use_open_wifi_automatically"
- android:icon="@drawable/ic_vpn_key"
+ android:icon="@drawable/ic_open_wifi_autoconnect"
android:title="@string/use_open_wifi_automatically_title"
android:summary="@string/use_open_wifi_automatically_summary" />
<Preference
android:key="notify_open_networks"
android:title="@string/wifi_notify_open_networks"
- android:icon="@drawable/ic_settings_notifications"/>
+ android:icon="@drawable/ic_open_wifi_notifications"/>
<SwitchPreference
android:key="wifi_cellular_data_fallback"
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index 3e9304d..546b11e 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -129,6 +129,7 @@
private boolean mHideDrawer = false;
private ManagedLockPasswordProvider mManagedPasswordProvider;
private boolean mIsSetNewPassword = false;
+ private UserManager mUserManager;
protected boolean mForFingerprint = false;
@@ -166,6 +167,7 @@
ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
+ mUserManager = UserManager.get(getActivity());
if (savedInstanceState != null) {
mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED);
@@ -751,11 +753,10 @@
if (mFingerprintManager != null && mFingerprintManager.isHardwareDetected()) {
mFingerprintManager.setActiveUser(UserHandle.myUserId());
}
- final UserManager um = UserManager.get(getActivity());
boolean hasChildProfile = false;
- if (!um.getUserInfo(parentUserId).isManagedProfile()) {
+ if (!mUserManager.getUserInfo(parentUserId).isManagedProfile()) {
// Current user is primary profile, remove work profile fingerprints if necessary
- final List<UserInfo> profiles = um.getProfiles(parentUserId);
+ final List<UserInfo> profiles = mUserManager.getProfiles(parentUserId);
final int profilesSize = profiles.size();
for (int i = 0; i < profilesSize; i++) {
final UserInfo userInfo = profiles.get(i);
diff --git a/src/com/android/settings/DefaultRingtonePreference.java b/src/com/android/settings/DefaultRingtonePreference.java
index 823c970..9f9f832 100644
--- a/src/com/android/settings/DefaultRingtonePreference.java
+++ b/src/com/android/settings/DefaultRingtonePreference.java
@@ -19,40 +19,15 @@
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.media.RingtoneManager;
-import android.os.UserHandle;
-import android.os.UserManager;
import android.net.Uri;
import android.util.AttributeSet;
-import android.util.Log;
public class DefaultRingtonePreference extends RingtonePreference {
private static final String TAG = "DefaultRingtonePreference";
- private int mUserId = UserHandle.USER_CURRENT;
- protected Context mUserContext;
-
public DefaultRingtonePreference(Context context, AttributeSet attrs) {
super(context, attrs);
- mUserContext = getContext();
- }
-
- public void setUserId(int userId) {
- mUserId = userId;
- mUserContext = Utils.createPackageContextAsUser(getContext(), mUserId);
- }
-
- @Override
- public void performClick() {
- if (mUserId != UserHandle.USER_CURRENT) {
- if (Utils.confirmWorkProfileCredentialsIfNecessary(getContext(), mUserId) ||
- Utils.startQuietModeDialogIfNecessary(getContext(),
- UserManager.get(getContext()), mUserId)) {
- return;
- }
- }
- super.performClick();
}
@Override
@@ -64,9 +39,6 @@
* doesn't make sense to show a 'Default' item.
*/
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
- if (mUserId != UserHandle.USER_CURRENT) {
- ringtonePickerIntent.putExtra(Intent.EXTRA_USER_ID, mUserId);
- }
}
@Override
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 1230ae5..2bb79b1 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -51,6 +51,9 @@
public class DisplaySettings extends DashboardFragment {
private static final String TAG = "DisplaySettings";
+ public static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
+ private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
+
@Override
public int getMetricsCategory() {
return MetricsEvent.DISPLAY;
@@ -85,7 +88,7 @@
private static List<PreferenceController> buildPreferenceControllers(
Context context, Lifecycle lifecycle) {
final List<PreferenceController> controllers = new ArrayList<>();
- controllers.add(new AutoBrightnessPreferenceController(context));
+ controllers.add(new AutoBrightnessPreferenceController(context, KEY_AUTO_BRIGHTNESS));
controllers.add(new AutoRotatePreferenceController(context));
controllers.add(new CameraGesturePreferenceController(context));
controllers.add(new DozePreferenceController(context));
@@ -100,11 +103,11 @@
controllers.add(new DoubleTapScreenPreferenceController(
context, lifecycle, ambientDisplayConfig, UserHandle.myUserId()));
controllers.add(new TapToWakePreferenceController(context));
- controllers.add(new TimeoutPreferenceController(context));
+ controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
controllers.add(new VrDisplayPreferenceController(context));
controllers.add(new WallpaperPreferenceController(context));
controllers.add(new ThemePreferenceController(context));
- controllers.add(new BrightnessLevelPreferenceController(context));
+ controllers.add(new BrightnessLevelPreferenceController(context, lifecycle));
return controllers;
}
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index fa9410d..ef4190b 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -33,6 +33,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
+import android.telephony.euicc.EuiccManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -71,11 +72,14 @@
private static final int KEYGUARD_REQUEST = 55;
static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
+ static final String ERASE_ESIMS_EXTRA = "erase_esim";
private View mContentView;
private Button mInitiateButton;
private View mExternalStorageContainer;
- private CheckBox mExternalStorage;
+ @VisibleForTesting CheckBox mExternalStorage;
+ private View mEsimStorageContainer;
+ @VisibleForTesting CheckBox mEsimStorage;
private ScrollView mScrollView;
private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
@@ -115,9 +119,11 @@
}
}
- private void showFinalConfirmation() {
+ @VisibleForTesting
+ void showFinalConfirmation() {
Bundle args = new Bundle();
args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
+ args.putBoolean(ERASE_ESIMS_EXTRA, mEsimStorage.isChecked());
((SettingsActivity) getActivity()).startPreferencePanel(
this, MasterClearConfirm.class.getName(),
args, R.string.master_clear_confirm_title, null, null, 0);
@@ -165,6 +171,8 @@
mInitiateButton.setOnClickListener(mInitiateListener);
mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
+ mEsimStorageContainer = mContentView.findViewById(R.id.erase_esim_container);
+ mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
mScrollView = (ScrollView) mContentView.findViewById(R.id.master_clear_scrollview);
/*
@@ -198,6 +206,20 @@
});
}
+ EuiccManager euiccManager =
+ (EuiccManager) getActivity().getSystemService(Context.EUICC_SERVICE);
+ if (euiccManager.isEnabled()) {
+ mEsimStorageContainer.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ mEsimStorage.toggle();
+ }
+ });
+ } else {
+ mEsimStorageContainer.setVisibility(View.GONE);
+ }
+
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
loadAccountList(um);
StringBuffer contentDescription = new StringBuffer();
@@ -284,11 +306,13 @@
.getAuthenticatorTypesAsUser(profileId);
final int M = descs.length;
- View titleView = Utils.inflateCategoryHeader(inflater, contents);
- final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
- titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
- : R.string.category_personal);
- contents.addView(titleView);
+ if (profilesSize > 1) {
+ View titleView = Utils.inflateCategoryHeader(inflater, contents);
+ final TextView titleText = (TextView) titleView.findViewById(android.R.id.title);
+ titleText.setText(userInfo.isManagedProfile() ? R.string.category_work
+ : R.string.category_personal);
+ contents.addView(titleView);
+ }
for (int i = 0; i < N; i++) {
Account account = accounts[i];
diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java
index 218ebbb..7a85dbe 100644
--- a/src/com/android/settings/MasterClearConfirm.java
+++ b/src/com/android/settings/MasterClearConfirm.java
@@ -25,6 +25,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
+import android.service.oemlock.OemLockManager;
import android.service.persistentdata.PersistentDataBlockManager;
import android.view.LayoutInflater;
import android.view.View;
@@ -51,6 +52,7 @@
private View mContentView;
private boolean mEraseSdCard;
+ private boolean mEraseEsims;
/**
* The user has gone through the multiple confirmation, so now we go ahead
@@ -66,12 +68,14 @@
final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
+ final OemLockManager oemLockManager = (OemLockManager)
+ getActivity().getSystemService(Context.OEM_LOCK_SERVICE);
- if (pdbManager != null && !pdbManager.getOemUnlockEnabled() &&
+ if (pdbManager != null && !oemLockManager.isOemUnlockAllowed() &&
Utils.isDeviceProvisioned(getActivity())) {
- // if OEM unlock is enabled, this will be wiped during FR process. If disabled, it
- // will be wiped here, unless the device is still being provisioned, in which case
- // the persistent data block will be preserved.
+ // if OEM unlock is allowed, the persistent data block will be wiped during FR
+ // process. If disabled, it will be wiped here, unless the device is still being
+ // provisioned, in which case the persistent data block will be preserved.
new AsyncTask<Void, Void, Void>() {
int mOldOrientation;
ProgressDialog mProgressDialog;
@@ -125,6 +129,7 @@
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");
intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard);
+ intent.putExtra(Intent.EXTRA_WIPE_ESIMS, mEraseEsims);
getActivity().sendBroadcast(intent);
// Intent handling is asynchronous -- assume it will happen soon.
}
@@ -175,6 +180,8 @@
Bundle args = getArguments();
mEraseSdCard = args != null
&& args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
+ mEraseEsims = args != null
+ && args.getBoolean(MasterClear.ERASE_ESIMS_EXTRA);
}
@Override
diff --git a/src/com/android/settings/RingtonePreference.java b/src/com/android/settings/RingtonePreference.java
index 41318f0..52ab65b 100644
--- a/src/com/android/settings/RingtonePreference.java
+++ b/src/com/android/settings/RingtonePreference.java
@@ -22,6 +22,7 @@
import android.media.AudioAttributes;
import android.media.RingtoneManager;
import android.net.Uri;
+import android.os.UserHandle;
import android.provider.Settings.System;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
@@ -54,6 +55,8 @@
private boolean mShowSilent;
private int mRequestCode;
+ protected int mUserId;
+ protected Context mUserContext;
public RingtonePreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -67,9 +70,19 @@
mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
true);
setIntent(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER));
+ setUserId(UserHandle.myUserId());
a.recycle();
}
+ public void setUserId(int userId) {
+ mUserId = userId;
+ mUserContext = Utils.createPackageContextAsUser(getContext(), mUserId);
+ }
+
+ public int getUserId() {
+ return mUserId;
+ }
+
/**
* Returns the sound type(s) that are shown in the picker.
*
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 1e64b7f..bdf9644 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -1227,55 +1227,18 @@
@Override
public void setListening(boolean listening) {
- if (!listening) {
- return;
- }
- int packageVerifierState = Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.PACKAGE_VERIFIER_STATE, 0);
- DashboardFeatureProvider dashboardFeatureProvider =
- FeatureFactory.getFactory(mContext).getDashboardFeatureProvider(mContext);
- if (packageVerifierState == PACKAGE_VERIFIER_STATE_ENABLED) {
- // Calling the feature provider could potentially be slow, so do this on a separate
- // thread so as to not block the loading of Settings.
- Executors.newSingleThreadExecutor().execute(new Runnable() {
- @Override
- public void run() {
- DashboardCategory dashboardCategory =
- dashboardFeatureProvider.getTilesForCategory(
- CategoryKey.CATEGORY_SECURITY);
- mSummaryLoader.setSummary(SummaryProvider.this,
- getPackageVerifierSummary(dashboardCategory));
- }
- });
- } else {
- final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(mContext);
+ if (listening) {
+ final FingerprintManager fpm =
+ Utils.getFingerprintManagerOrNull(mContext);
if (fpm != null && fpm.isHardwareDetected()) {
mSummaryLoader.setSummary(this,
- mContext.getString(R.string.security_dashboard_summary));
+ mContext.getString(R.string.security_dashboard_summary));
} else {
- mSummaryLoader.setSummary(this, null);
+ mSummaryLoader.setSummary(this, mContext.getString(
+ R.string.security_dashboard_summary_no_fingerprint));
}
}
}
-
- @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
- String getPackageVerifierSummary(DashboardCategory dashboardCategory) {
- int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
- if (tilesCount == 0) {
- return null;
- }
- for (int i = 0; i < tilesCount; i++) {
- Tile tile = dashboardCategory.getTile(i);
- if (!KEY_PACKAGE_VERIFIER_STATUS.equals(tile.key)) {
- continue;
- }
- String summaryUri = tile.metaData.getString(
- TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
- return TileUtils.getTextFromUri(mContext, summaryUri,
- new ArrayMap<>(), TileUtils.META_DATA_PREFERENCE_SUMMARY);
- }
- return null;
- }
}
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 015af17..34990ec 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -83,7 +83,10 @@
// Constants for state save/restore
private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
- private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
+ @VisibleForTesting
+ static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
+ @VisibleForTesting
+ static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
/**
* When starting this activity, the invoking Intent can contain this extra
@@ -192,8 +195,10 @@
private Button mNextButton;
- private boolean mDisplayHomeAsUpEnabled;
- private boolean mDisplaySearch;
+ @VisibleForTesting
+ boolean mDisplayHomeAsUpEnabled;
+ @VisibleForTesting
+ boolean mDisplaySearch;
private boolean mIsShowingDashboard;
private boolean mIsShortcut;
@@ -230,7 +235,6 @@
if (!mDisplaySearch) {
return false;
}
-
mSearchFeatureProvider.setUpSearchMenu(menu, this);
return true;
}
@@ -513,12 +517,28 @@
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
+ saveState(outState);
+ }
+ /**
+ * For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState.
+ */
+ @VisibleForTesting
+ void saveState(Bundle outState) {
if (mCategories.size() > 0) {
outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
}
outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
+ outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ mDisplayHomeAsUpEnabled = savedInstanceState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
+ mDisplaySearch = savedInstanceState.getBoolean(SAVE_KEY_SHOW_SEARCH);
}
@Override
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 70743e2..761e8cf 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -440,6 +440,7 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ super.onCreateOptionsMenu(menu, inflater);
if (mHelpUri != null && getActivity() != null) {
HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
}
diff --git a/src/com/android/settings/SetupChooseLockGeneric.java b/src/com/android/settings/SetupChooseLockGeneric.java
index 61545a6..2c8195d 100644
--- a/src/com/android/settings/SetupChooseLockGeneric.java
+++ b/src/com/android/settings/SetupChooseLockGeneric.java
@@ -17,10 +17,8 @@
package com.android.settings;
import android.app.admin.DevicePolicyManager;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
@@ -120,12 +118,6 @@
data.putExtra(EXTRA_PASSWORD_QUALITY,
lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId()));
- PackageManager packageManager = getPackageManager();
- ComponentName componentName = new ComponentName("com.android.settings",
- "com.android.settings.SetupRedactionInterstitial");
- packageManager.setComponentEnabledSetting(componentName,
- PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
- PackageManager.DONT_KILL_APP);
super.onActivityResult(requestCode, resultCode, data);
}
// If the started activity was cancelled (e.g. the user presses back), then this
diff --git a/src/com/android/settings/SetupChooseLockPassword.java b/src/com/android/settings/SetupChooseLockPassword.java
index f0a9a26..f2c24d0 100644
--- a/src/com/android/settings/SetupChooseLockPassword.java
+++ b/src/com/android/settings/SetupChooseLockPassword.java
@@ -87,6 +87,9 @@
@Override
protected Intent getRedactionInterstitialIntent(Context context) {
+ // Setup wizard's redaction interstitial is deferred to optional step. Enable that
+ // optional step if the lock screen was set up.
+ SetupRedactionInterstitial.setEnabled(context, true);
return null;
}
}
diff --git a/src/com/android/settings/SetupChooseLockPattern.java b/src/com/android/settings/SetupChooseLockPattern.java
index 09b951e..30a3c7c 100644
--- a/src/com/android/settings/SetupChooseLockPattern.java
+++ b/src/com/android/settings/SetupChooseLockPattern.java
@@ -73,6 +73,9 @@
@Override
protected Intent getRedactionInterstitialIntent(Context context) {
+ // Setup wizard's redaction interstitial is deferred to optional step. Enable that
+ // optional step if the lock screen was set up.
+ SetupRedactionInterstitial.setEnabled(context, false);
return null;
}
}
diff --git a/src/com/android/settings/SetupRedactionInterstitial.java b/src/com/android/settings/SetupRedactionInterstitial.java
index d527585..321040e 100644
--- a/src/com/android/settings/SetupRedactionInterstitial.java
+++ b/src/com/android/settings/SetupRedactionInterstitial.java
@@ -16,11 +16,11 @@
package com.android.settings;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.content.res.Resources;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
import com.android.settings.notification.RedactionInterstitial;
@@ -33,6 +33,20 @@
*/
public class SetupRedactionInterstitial extends RedactionInterstitial {
+ /**
+ * Set the enabled state of SetupRedactionInterstitial activity to configure whether it is shown
+ * as part of setup wizard's optional steps.
+ */
+ public static void setEnabled(Context context, boolean enabled) {
+ PackageManager packageManager = context.getPackageManager();
+ ComponentName componentName = new ComponentName(context, SetupRedactionInterstitial.class);
+ packageManager.setComponentEnabledSetting(
+ componentName,
+ enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+ : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+
@Override
public Intent getIntent() {
Intent modIntent = new Intent(super.getIntent());
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 760755c..44dd353 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -31,6 +31,7 @@
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
+import android.support.v4.content.ContextCompat;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
@@ -76,11 +77,12 @@
private static final String CATEGORY_AUDIO_AND_CAPTIONS = "audio_and_captions_category";
private static final String CATEGORY_DISPLAY = "display_category";
private static final String CATEGORY_INTERACTION_CONTROL = "interaction_control_category";
+ private static final String CATEGORY_EXPERIMENTAL = "experimental_category";
private static final String CATEGORY_DOWNLOADED_SERVICES = "user_installed_services_category";
private static final String[] CATEGORIES = new String[] {
CATEGORY_SCREEN_READER, CATEGORY_AUDIO_AND_CAPTIONS, CATEGORY_DISPLAY,
- CATEGORY_INTERACTION_CONTROL, CATEGORY_DOWNLOADED_SERVICES
+ CATEGORY_INTERACTION_CONTROL, CATEGORY_EXPERIMENTAL, CATEGORY_DOWNLOADED_SERVICES
};
// Preferences
@@ -387,6 +389,7 @@
// Display magnification.
mDisplayMagnificationPreferenceScreen = findPreference(
DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
+ configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreferenceScreen);
// Font size.
mFontSizePreferenceScreen = findPreference(FONT_SIZE_PREFERENCE_SCREEN);
@@ -454,9 +457,11 @@
new RestrictedPreference(downloadedServicesCategory.getContext());
String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();
- Drawable icon = info.getResolveInfo().loadIcon(getPackageManager());
- if (icon == null) {
- // todo (saigem): add a default
+ Drawable icon;
+ if (info.getResolveInfo().getIconResource() == 0) {
+ icon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_accessibility_generic);
+ } else {
+ icon = info.getResolveInfo().loadIcon(getPackageManager());
}
ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
@@ -545,6 +550,22 @@
}
private void updateSystemPreferences() {
+ // Move color inversion and color correction preferences to Display category if device
+ // supports HWC hardware-accelerated color transform.
+ if (isColorTransformAccelerated(getContext())) {
+ PreferenceCategory experimentalCategory =
+ mCategoryToPrefCategoryMap.get(CATEGORY_EXPERIMENTAL);
+ PreferenceCategory displayCategory =
+ mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY);
+ experimentalCategory.removePreference(mToggleInversionPreference);
+ experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen);
+ mToggleInversionPreference.setOrder(mToggleLargePointerIconPreference.getOrder());
+ mDisplayDaltonizerPreferenceScreen.setOrder(mToggleInversionPreference.getOrder());
+ mToggleInversionPreference.setSummary(R.string.summary_empty);
+ displayCategory.addPreference(mToggleInversionPreference);
+ displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
+ }
+
// Text contrast.
mToggleHighTextContrastPreference.setChecked(
Settings.Secure.getInt(getContentResolver(),
@@ -596,6 +617,11 @@
updateAccessibilityShortcut(mAccessibilityShortcutPreferenceScreen);
}
+ private boolean isColorTransformAccelerated(Context context) {
+ return context.getResources()
+ .getBoolean(com.android.internal.R.bool.config_setColorTransformAccelerated);
+ }
+
private void updateMagnificationSummary(Preference pref) {
final boolean tripleTapEnabled = Settings.Secure.getInt(getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1;
@@ -678,6 +704,19 @@
}
}
+ private static void configureMagnificationPreferenceIfNeeded(Preference preference) {
+ // Some devices support only a single magnification mode. In these cases, we redirect to
+ // the magnification mode's UI directly, rather than showing a PreferenceScreen with a
+ // single list item.
+ final Context context = preference.getContext();
+ if (!MagnificationPreferenceFragment.isApplicable(context.getResources())) {
+ preference.setFragment(ToggleScreenMagnificationPreferenceFragment.class.getName());
+ final Bundle extras = preference.getExtras();
+ MagnificationPreferenceFragment.populateMagnificationGesturesPreferenceExtras(extras,
+ context);
+ }
+ }
+
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
diff --git a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
index 8c76fb7..55b79ba 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
@@ -18,9 +18,9 @@
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName;
+import android.content.Context;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
-import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityManager;
@@ -79,6 +79,7 @@
findService(SCREEN_READER_PACKAGE_NAME, SCREEN_READER_SERVICE_NAME));
updateAccessibilityServicePreference(mSelectToSpeakPreference,
findService(SELECT_TO_SPEAK_PACKAGE_NAME, SELECT_TO_SPEAK_SERVICE_NAME));
+ configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreference);
}
@Override
@@ -145,4 +146,18 @@
}
extras.putString(AccessibilitySettings.EXTRA_SUMMARY, description);
}
+
+ private static void configureMagnificationPreferenceIfNeeded(Preference preference) {
+ // Some devices support only a single magnification mode. In these cases, we redirect to
+ // the magnification mode's UI directly, rather than showing a PreferenceScreen with a
+ // single list item.
+ final Context context = preference.getContext();
+ if (!MagnificationPreferenceFragment.isApplicable(context.getResources())) {
+ preference.setFragment(
+ ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
+ final Bundle extras = preference.getExtras();
+ MagnificationPreferenceFragment.populateMagnificationGesturesPreferenceExtras(extras,
+ context);
+ }
+ }
}
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index 6ed06da..24320b3 100644
--- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
@@ -42,12 +42,9 @@
public static final String SHORTCUT_SERVICE_KEY = "accessibility_shortcut_service";
public static final String ON_LOCK_SCREEN_KEY = "accessibility_shortcut_on_lock_screen";
- // ID for dialog that confirms shortcut capabilities
- private static final int DIALOG_ID_ADD_SHORTCUT_WARNING = 1;
private Preference mServicePreference;
private SwitchPreference mOnLockScreenSwitchPreference;
- private String mSelectedServiceComponentNameString;
@Override
public int getMetricsCategory() {
diff --git a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
index 22706d7..83299e8 100644
--- a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
@@ -19,6 +19,7 @@
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName;
import android.content.Context;
+import android.content.res.Resources;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
@@ -34,6 +35,7 @@
import com.android.settings.search.Indexable;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
public final class MagnificationPreferenceFragment extends SettingsPreferenceFragment implements
@@ -123,18 +125,7 @@
private void handleMagnificationGesturesPreferenceScreenClick() {
Bundle extras = mMagnificationGesturesPreference.getExtras();
- extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
- Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
- extras.putString(AccessibilitySettings.EXTRA_TITLE, getString(
- R.string.accessibility_screen_magnification_gestures_title));
- extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY,
- getActivity().getResources().getText(
- R.string.accessibility_screen_magnification_summary));
- extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED,
- Settings.Secure.getInt(getContentResolver(),
- Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1);
- extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
- R.raw.accessibility_screen_magnification);
+ populateMagnificationGesturesPreferenceExtras(extras, getContext());
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mLaunchedFromSuw);
}
@@ -188,14 +179,40 @@
return null;
}
+ static void populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context) {
+ extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
+ Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
+ extras.putString(AccessibilitySettings.EXTRA_TITLE, context.getString(
+ R.string.accessibility_screen_magnification_gestures_title));
+ extras.putCharSequence(AccessibilitySettings.EXTRA_SUMMARY, context.getResources().getText(
+ R.string.accessibility_screen_magnification_summary));
+ extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED,
+ Settings.Secure.getInt(context.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1);
+ extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
+ R.raw.accessibility_screen_magnification);
+ }
+
+ /**
+ * @return {@code true} if this fragment should be shown, {@code false} otherwise. This
+ * fragment is shown in the case that more than one magnification mode is available.
+ */
+ static boolean isApplicable(Resources res) {
+ return res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
+ }
+
public static final Indexable.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.accessibility_magnification_settings;
- return Arrays.asList(sir);
+ if (isApplicable(context.getResources())) {
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.accessibility_magnification_settings;
+ return Arrays.asList(sir);
+ } else {
+ return Collections.emptyList();
+ }
}
};
}
diff --git a/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java b/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java
index 8b6d52a..3250521 100644
--- a/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java
+++ b/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.accessibility;
+import static android.content.DialogInterface.BUTTON_POSITIVE;
+
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Activity;
import android.app.AlertDialog;
@@ -147,7 +149,7 @@
@Override
public void onClick(DialogInterface dialog, int which) {
final Fragment fragment = getTargetFragment();
- if (fragment instanceof DefaultAppPickerFragment) {
+ if ((which == BUTTON_POSITIVE) && (fragment instanceof DefaultAppPickerFragment)) {
final Bundle bundle = getArguments();
((ShortcutServicePickerFragment) fragment).onServiceConfirmed(
bundle.getString(EXTRA_KEY));
diff --git a/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java b/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java
index 79776a0..f5d7b64 100644
--- a/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java
+++ b/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java
@@ -28,8 +28,8 @@
import android.os.UserManager;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
-
import android.util.Log;
+
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
@@ -41,9 +41,10 @@
private static final String TAG_CONFIRM_AUTO_SYNC_CHANGE = "confirmAutoSyncChange";
private static final String KEY_AUTO_SYNC_ACCOUNT = "auto_sync_account_data";
- protected UserManager mUserManager;
- private UserHandle mUserHandle;
- private Fragment mParentFragment;
+ protected final UserManager mUserManager;
+ private final Fragment mParentFragment;
+
+ protected UserHandle mUserHandle;
public AutoSyncDataPreferenceController(Context context, Fragment parent) {
super(context);
diff --git a/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java b/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java
index 899f77d..1d08968 100644
--- a/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java
+++ b/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java
@@ -18,6 +18,8 @@
import android.app.Fragment;
import android.content.Context;
+import com.android.settings.Utils;
+
public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPreferenceController {
private static final String TAG = "AutoSyncWorkData";
@@ -25,11 +27,11 @@
public AutoSyncWorkDataPreferenceController(Context context, Fragment parent) {
super(context, parent);
+ mUserHandle = Utils.getManagedProfile(mUserManager);
}
@Override
public String getPreferenceKey() {
return KEY_AUTO_SYNC_WORK_ACCOUNT;
}
-
}
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index 9e41679..45938ae 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -18,25 +18,26 @@
import android.annotation.IdRes;
import android.annotation.UserIdInt;
+import android.app.ActionBar;
+import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.graphics.Outline;
-import android.graphics.drawable.AdaptiveIconDrawable;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.support.annotation.IntDef;
+import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewOutlineProvider;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
+
import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.Utils;
@@ -64,23 +65,12 @@
public static final String PREF_KEY_APP_HEADER = "pref_app_header";
- public static final ViewOutlineProvider OUTLINE_PROVIDER = new ViewOutlineProvider() {
- @Override
- public void getOutline(View view, Outline outline) {
- Drawable background = ((ImageView)view).getDrawable();
- if (background != null) {
- background.getOutline(outline);
- }
- }
- };
-
private static final String TAG = "AppDetailFeature";
private final Context mContext;
private final Fragment mFragment;
private final int mMetricsCategory;
private final View mAppHeader;
- private final int mIconElevation;
private Drawable mIcon;
private CharSequence mLabel;
@@ -107,8 +97,6 @@
mAppHeader = LayoutInflater.from(fragment.getContext())
.inflate(R.layout.app_details, null /* root */);
}
- mIconElevation = mContext.getResources()
- .getDimensionPixelSize(R.dimen.launcher_icon_elevation);
}
public AppHeaderController setIcon(Drawable icon) {
@@ -175,39 +163,10 @@
}
/**
- * Binds app header view and data from {@code PackageInfo} and {@code AppEntry}.
- */
- public void bindAppHeader(PackageInfo packageInfo, ApplicationsState.AppEntry appEntry) {
- final String versionName = packageInfo == null ? null : packageInfo.versionName;
- final Resources res = mAppHeader.getResources();
-
- // Set Icon
- final ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
- if (appEntry.icon != null) {
- iconView.setImageDrawable(appEntry.icon.getConstantState().newDrawable(res));
- }
-
- // Set application name.
- final TextView labelView = (TextView) mAppHeader.findViewById(R.id.app_detail_title);
- labelView.setText(appEntry.label);
-
- // Version number of application
- final TextView appVersion = (TextView) mAppHeader.findViewById(R.id.app_detail_summary);
-
- if (!TextUtils.isEmpty(versionName)) {
- appVersion.setSelected(true);
- appVersion.setVisibility(View.VISIBLE);
- appVersion.setText(res.getString(R.string.version_text, String.valueOf(versionName)));
- } else {
- appVersion.setVisibility(View.INVISIBLE);
- }
- }
-
- /**
* Done mutating appheader, rebinds everything and return a new {@link LayoutPreference}.
*/
- public LayoutPreference done(Context context) {
- final LayoutPreference pref = new LayoutPreference(context, done());
+ public LayoutPreference done(Activity activity, Context uiContext) {
+ final LayoutPreference pref = new LayoutPreference(uiContext, done(activity));
// Makes sure it's the first preference onscreen.
pref.setOrder(-1000);
pref.setKey(PREF_KEY_APP_HEADER);
@@ -215,30 +174,13 @@
}
/**
- * Done mutating appheader, rebinds everything.
- */
- public View done() {
- return done(true);
- }
-
- /**
* Done mutating appheader, rebinds everything (optionally skip rebinding buttons).
*/
- public View done(boolean rebindActions) {
- ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
+ public View done(Activity activity, boolean rebindActions) {
+ styleActionBar(activity);
+ ImageView iconView = mAppHeader.findViewById(R.id.app_detail_icon);
if (iconView != null) {
iconView.setImageDrawable(mIcon);
- if (mIcon instanceof AdaptiveIconDrawable) {
- iconView.setElevation(mIconElevation);
- iconView.setOutlineProvider(OUTLINE_PROVIDER);
- } else {
- iconView.setElevation(0);
- iconView.setOutlineProvider(null);
- }
- ImageView badgeView = mAppHeader.findViewById(R.id.app_icon_instant_apps_badge);
- if (badgeView != null) {
- badgeView.setVisibility(mIsInstantApp ? View.VISIBLE : View.GONE);
- }
}
setText(R.id.app_detail_title, mLabel);
setText(R.id.app_detail_summary, mSummary);
@@ -257,12 +199,38 @@
/**
* Only binds app header with button actions.
*/
- public void bindAppHeaderButtons() {
- ImageButton leftButton = (ImageButton) mAppHeader.findViewById(R.id.left_button);
- ImageButton rightButton = (ImageButton) mAppHeader.findViewById(R.id.right_button);
+ public AppHeaderController bindAppHeaderButtons() {
+ ImageButton leftButton = mAppHeader.findViewById(R.id.left_button);
+ ImageButton rightButton = mAppHeader.findViewById(R.id.right_button);
bindButton(leftButton, mLeftAction);
bindButton(rightButton, mRightAction);
+ return this;
+ }
+
+ public AppHeaderController styleActionBar(Activity activity) {
+ if (activity == null) {
+ Log.w(TAG, "No activity, cannot style actionbar.");
+ return this;
+ }
+ final ActionBar actionBar = activity.getActionBar();
+ if (actionBar == null) {
+ Log.w(TAG, "No actionbar, cannot style actionbar.");
+ return this;
+ }
+ actionBar.setBackgroundDrawable(
+ new ColorDrawable(Utils.getColorAttr(activity, android.R.attr.colorSecondary)));
+ actionBar.setElevation(0);
+
+ return this;
+ }
+
+ /**
+ * Done mutating appheader, rebinds everything.
+ */
+ @VisibleForTesting
+ View done(Activity activity) {
+ return done(activity, true /* rebindActions */);
}
private void bindButton(ImageButton button, @ActionType int action) {
@@ -346,10 +314,10 @@
}
private void setText(@IdRes int id, CharSequence text) {
- TextView textView = (TextView) mAppHeader.findViewById(id);
+ TextView textView = mAppHeader.findViewById(id);
if (textView != null) {
textView.setText(text);
textView.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/applications/AppInfoWithHeader.java b/src/com/android/settings/applications/AppInfoWithHeader.java
index 768a726..6b1ef67 100644
--- a/src/com/android/settings/applications/AppInfoWithHeader.java
+++ b/src/com/android/settings/applications/AppInfoWithHeader.java
@@ -16,16 +16,17 @@
package com.android.settings.applications;
+import static com.android.settings.applications.AppHeaderController.ActionType;
+
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.preference.Preference;
+import android.util.IconDrawableFactory;
import android.util.Log;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.AppUtils;
-import static com.android.settings.applications.AppHeaderController.ActionType;
-
public abstract class AppInfoWithHeader extends AppInfoBase {
private boolean mCreated;
@@ -41,16 +42,17 @@
if (mPackageInfo == null) return;
final Activity activity = getActivity();
final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, null /* appHeader */)
- .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
- .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
- .setSummary(mPackageInfo)
- .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
- .setPackageName(mPackageName)
- .setUid(mPackageInfo.applicationInfo.uid)
- .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
- .done(getPrefContext());
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, null /* appHeader */)
+ .setIcon(IconDrawableFactory.newInstance(activity)
+ .getBadgedIcon(mPackageInfo.applicationInfo))
+ .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
+ .setSummary(mPackageInfo)
+ .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
+ .setPackageName(mPackageName)
+ .setUid(mPackageInfo.applicationInfo.uid)
+ .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
}
diff --git a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
index 97e5b7b..b39ec3b 100644
--- a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
+++ b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
@@ -19,6 +19,7 @@
import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.UserHandle;
import android.util.Log;
@@ -27,6 +28,8 @@
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+import java.io.IOException;
+
/**
* Fetches the storage stats using the StorageStatsManager for a given package and user tuple.
*/
@@ -49,7 +52,7 @@
AppStorageStats result = null;
try {
result = mSource.getStatsForPackage(mInfo.volumeUuid, mInfo.packageName, mUser);
- } catch (IllegalStateException e) {
+ } catch (NameNotFoundException | IOException e) {
Log.w(TAG, "Package may have been removed during query, failing gracefully", e);
}
return result;
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 2fcecd8..09771f2 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -16,6 +16,8 @@
package com.android.settings.applications;
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
import android.Manifest.permission;
import android.app.Activity;
import android.app.ActivityManager;
@@ -112,8 +114,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import java.util.Set;
/**
* Activity to display application information from Settings. This activity presents
@@ -158,6 +159,8 @@
private static final String KEY_BATTERY = "battery";
private static final String KEY_MEMORY = "memory";
private static final String KEY_VERSION = "app_version";
+ private static final String KEY_INSTANT_APP_SUPPORTED_LINKS =
+ "instant_app_launch_supported_domain_urls";
private final HashSet<String> mHomePackages = new HashSet<>();
@@ -175,6 +178,7 @@
private Preference mDataPreference;
private Preference mMemoryPreference;
private Preference mVersionPreference;
+ private AppDomainsPreference mInstantAppDomainsPreference;
private boolean mDisableAfterUninstall;
@@ -408,12 +412,13 @@
mHeader = (LayoutPreference) findPreference(KEY_HEADER);
mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
- .setPackageName(mPackageName)
- .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
- AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
- .bindAppHeaderButtons();
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
+ .setPackageName(mPackageName)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
+ AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
+ .styleActionBar(activity)
+ .bindAppHeaderButtons();
prepareUninstallAndStop();
mNotificationPreference = findPreference(KEY_NOTIFICATION);
@@ -432,7 +437,8 @@
mMemoryPreference = findPreference(KEY_MEMORY);
mMemoryPreference.setOnPreferenceClickListener(this);
mVersionPreference = findPreference(KEY_VERSION);
-
+ mInstantAppDomainsPreference =
+ (AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
mLaunchPreference = findPreference(KEY_LAUNCH);
if (mAppEntry != null && mAppEntry.info != null) {
if ((mAppEntry.info.flags&ApplicationInfo.FLAG_INSTALLED) == 0 ||
@@ -550,6 +556,25 @@
public void onLoaderReset(Loader<AppStorageStats> loader) {
}
+ /**
+ * Utility method to hide and show specific preferences based on whether the app being displayed
+ * is an Instant App or an installed app.
+ */
+ @VisibleForTesting
+ void prepareInstantAppPrefs() {
+ final boolean isInstant = AppUtils.isInstant(mPackageInfo.applicationInfo);
+ if (isInstant) {
+ Set<String> handledDomainSet = Utils.getHandledDomains(mPm, mPackageInfo.packageName);
+ String[] handledDomains = handledDomainSet.toArray(new String[handledDomainSet.size()]);
+ mInstantAppDomainsPreference.setTitles(handledDomains);
+ // Dummy values, unused in the implementation
+ mInstantAppDomainsPreference.setValues(new int[handledDomains.length]);
+ getPreferenceScreen().removePreference(mLaunchPreference);
+ } else {
+ getPreferenceScreen().removePreference(mInstantAppDomainsPreference);
+ }
+ }
+
// Utility method to set application label and icon.
private void setAppLabelAndIcon(PackageInfo pkgInfo) {
final View appSnippet = mHeader.findViewById(R.id.app_snippet);
@@ -565,7 +590,7 @@
.setIcon(mAppEntry)
.setSummary(summary)
.setIsInstantApp(isInstantApp)
- .done(false /* rebindActions */);
+ .done(activity, false /* rebindActions */);
mVersionPreference.setSummary(getString(R.string.version_text, pkgInfo.versionName));
}
@@ -641,6 +666,7 @@
checkForceStop();
setAppLabelAndIcon(mPackageInfo);
initUninstallButtons();
+ prepareInstantAppPrefs();
// Update the preference summaries.
Activity context = getActivity();
@@ -1114,13 +1140,16 @@
if (installerLabel == null) {
return;
}
+ final int detailsStringId = AppUtils.isInstant(mPackageInfo.applicationInfo)
+ ? R.string.instant_app_details_summary
+ : R.string.app_install_details_summary;
PreferenceCategory category = new PreferenceCategory(getPrefContext());
category.setTitle(R.string.app_install_details_group_title);
screen.addPreference(category);
Preference pref = new Preference(getPrefContext());
pref.setTitle(R.string.app_install_details_title);
pref.setKey("app_info_store");
- pref.setSummary(getString(R.string.app_install_details_summary, installerLabel));
+ pref.setSummary(getString(detailsStringId, installerLabel));
Intent intent =
AppStoreUtil.getAppStoreLink(getContext(), installerPackageName, mPackageName);
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 3cc40151..f24c3f7 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -23,7 +23,6 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
-import android.graphics.drawable.AdaptiveIconDrawable;
import android.icu.text.AlphabeticIndex;
import android.os.Bundle;
import android.os.Environment;
@@ -35,7 +34,6 @@
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.ArraySet;
-import android.util.LauncherIcons;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -55,8 +53,8 @@
import android.widget.ListView;
import android.widget.SectionIndexer;
import android.widget.Spinner;
-
import android.widget.TextView;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Settings.AllApplicationsActivity;
@@ -826,7 +824,6 @@
private final AppStateBaseBridge mExtraInfoBridge;
private final Handler mBgHandler;
private final Handler mFgHandler;
- private final LauncherIcons mLauncherIcons;
private int mFilterMode;
private ArrayList<ApplicationsState.AppEntry> mBaseEntries;
@@ -882,7 +879,6 @@
mContext = manageApplications.getActivity();
mPm = mContext.getPackageManager();
mFilterMode = filterMode;
- mLauncherIcons = new LauncherIcons(mContext);
if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) {
mExtraInfoBridge = new AppStateNotificationBridge(mContext, mState, this,
manageApplications.mNotifBackend);
@@ -1317,9 +1313,6 @@
}
mState.ensureIcon(entry);
if (entry.icon != null) {
- if (entry.icon instanceof AdaptiveIconDrawable) {
- entry.icon = mLauncherIcons.wrapIconDrawableWithShadow(entry.icon);
- }
holder.appIcon.setImageDrawable(entry.icon);
}
updateSummary(holder);
diff --git a/src/com/android/settings/applications/MusicViewHolderController.java b/src/com/android/settings/applications/MusicViewHolderController.java
index 4599fcc..1bca26a 100644
--- a/src/com/android/settings/applications/MusicViewHolderController.java
+++ b/src/com/android/settings/applications/MusicViewHolderController.java
@@ -23,15 +23,20 @@
import android.provider.DocumentsContract;
import android.support.annotation.WorkerThread;
import android.text.format.Formatter;
+import android.util.Log;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.applications.StorageStatsSource;
+import java.io.IOException;
+
/**
* MusicViewHolderController controls an Audio/Music file view in the ManageApplications view.
*/
public class MusicViewHolderController implements FileViewHolderController {
+ private static final String TAG = "MusicViewHolderController";
+
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
private Context mContext;
@@ -51,7 +56,12 @@
@Override
@WorkerThread
public void queryStats() {
- mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
+ try {
+ mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
+ } catch (IOException e) {
+ mMusicSize = 0;
+ Log.w(TAG, e);
+ }
}
@Override
@@ -61,7 +71,7 @@
@Override
public void setupView(AppViewHolder holder) {
- holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.empty_icon));
+ holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.ic_media_stream_on_24dp));
holder.appName.setText(mContext.getText(R.string.audio_files_title));
holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
}
diff --git a/src/com/android/settings/applications/ProcessStatsDetail.java b/src/com/android/settings/applications/ProcessStatsDetail.java
index 9b6f41e..6c0928c 100644
--- a/src/com/android/settings/applications/ProcessStatsDetail.java
+++ b/src/com/android/settings/applications/ProcessStatsDetail.java
@@ -16,6 +16,8 @@
package com.android.settings.applications;
+import static com.android.settings.applications.AppHeaderController.ActionType;
+
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
@@ -37,6 +39,7 @@
import android.support.v7.preference.PreferenceCategory;
import android.text.format.Formatter;
import android.util.ArrayMap;
+import android.util.IconDrawableFactory;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -58,8 +61,6 @@
import java.util.HashMap;
import java.util.List;
-import static com.android.settings.applications.AppHeaderController.ActionType;
-
public class ProcessStatsDetail extends SettingsPreferenceFragment {
private static final String TAG = "ProcessStatsDetail";
@@ -129,7 +130,7 @@
.getApplicationFeatureProvider(activity)
.newAppHeaderController(this, null /* appHeader */)
.setIcon(mApp.mUiTargetApp != null
- ? mApp.mUiTargetApp.loadIcon(mPm)
+ ? IconDrawableFactory.newInstance(activity).getBadgedIcon(mApp.mUiTargetApp)
: new ColorDrawable(0))
.setLabel(mApp.mUiLabel)
.setPackageName(mApp.mPackage)
@@ -137,7 +138,7 @@
? mApp.mUiTargetApp.uid
: UserHandle.USER_NULL)
.setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
diff --git a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
index 747ce4d..b8d6a87 100644
--- a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
+++ b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
@@ -24,6 +24,7 @@
import android.service.voice.VoiceInteractionService;
import android.service.voice.VoiceInteractionServiceInfo;
+import android.support.annotation.VisibleForTesting;
import com.android.internal.app.AssistUtils;
import com.android.settings.applications.defaultapps.DefaultAppInfo;
import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
@@ -56,13 +57,10 @@
if (services == null || services.isEmpty()) {
return null;
}
- final ResolveInfo resolveInfo = services.get(0);
- final VoiceInteractionServiceInfo voiceInfo =
- new VoiceInteractionServiceInfo(pm, resolveInfo.serviceInfo);
- if (!voiceInfo.getSupportsAssist()) {
+ final String activity = getAssistSettingsActivity(cn, services.get(0), pm);
+ if (activity == null) {
return null;
}
- final String activity = voiceInfo.getSettingsActivity();
return new Intent(Intent.ACTION_MAIN)
.setComponent(new ComponentName(cn.getPackageName(), activity));
}
@@ -85,4 +83,14 @@
}
return new DefaultAppInfo(mPackageManager, mUserId, cn);
}
+
+ @VisibleForTesting
+ String getAssistSettingsActivity(ComponentName cn, ResolveInfo resolveInfo, PackageManager pm) {
+ final VoiceInteractionServiceInfo voiceInfo =
+ new VoiceInteractionServiceInfo(pm, resolveInfo.serviceInfo);
+ if (!voiceInfo.getSupportsAssist()) {
+ return null;
+ }
+ return voiceInfo.getSettingsActivity();
+ }
}
diff --git a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
index c65c316..dddfb1b 100644
--- a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
+++ b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
@@ -30,6 +30,7 @@
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.language.LanguageAndInputSettings;
import com.android.settings.network.NetworkDashboardFragment;
+import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.SoundSettings;
import com.android.settings.system.SystemDashboardFragment;
import com.android.settingslib.drawer.CategoryKey;
@@ -83,6 +84,8 @@
CategoryKey.CATEGORY_SYSTEM_LANGUAGE);
PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettings.class.getName(),
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
+ PARENT_TO_CATEGORY_KEY_MAP.put(ConfigureNotificationSettings.class.getName(),
+ CategoryKey.CATEGORY_NOTIFICATIONS);
CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java b/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java
index 9a92c93..1be2c68 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java
@@ -68,7 +68,11 @@
} else if (className.equals(ScreenLockSuggestionActivity.class.getName())) {
return isDeviceSecured();
} else if (className.equals(FingerprintEnrollSuggestionActivity.class.getName())) {
- return isDeviceSecured() || !isFingerprintEnabled();
+ FingerprintManager manager = Utils.getFingerprintManagerOrNull(mContext);
+ if (manager == null || !isFingerprintEnabled()) {
+ return true;
+ }
+ return manager.hasEnrolledFingerprints();
}
SuggestionFeatureProvider provider =
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 5c79c7b..96740e2 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -14,6 +14,8 @@
package com.android.settings.datausage;
+import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
+
import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
@@ -38,6 +40,7 @@
import android.support.v7.preference.PreferenceCategory;
import android.text.format.Formatter;
import android.util.ArraySet;
+import android.util.IconDrawableFactory;
import android.view.View;
import android.widget.AdapterView;
@@ -58,8 +61,6 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
-
public class AppDataUsage extends DataUsageBase implements Preference.OnPreferenceChangeListener,
DataSaverBackend.Listener {
@@ -159,7 +160,7 @@
PackageManager pm = getPackageManager();
try {
ApplicationInfo info = pm.getApplicationInfo(mPackages.valueAt(0), 0);
- mIcon = info.loadIcon(pm);
+ mIcon = IconDrawableFactory.newInstance(getActivity()).getBadgedIcon(info);
mLabel = info.loadLabel(pm);
mPackageName = info.packageName;
} catch (PackageManager.NameNotFoundException e) {
@@ -353,7 +354,7 @@
.setUid(uid)
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NONE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index dda984b..aca4809 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -14,13 +14,16 @@
package com.android.settings.datausage;
+import static android.net.NetworkPolicy.LIMIT_DISABLED;
+import static android.net.NetworkPolicy.WARNING_DISABLED;
+
import android.app.AlertDialog;
import android.app.Dialog;
-import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
+import android.icu.text.NumberFormat;
import android.net.NetworkPolicy;
import android.net.NetworkTemplate;
import android.os.Bundle;
@@ -42,8 +45,7 @@
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.net.DataUsageController;
-import static android.net.NetworkPolicy.LIMIT_DISABLED;
-import static android.net.NetworkPolicy.WARNING_DISABLED;
+import java.text.ParseException;
public class BillingCycleSettings extends DataUsageBase implements
Preference.OnPreferenceChangeListener, DataUsageEditController {
@@ -246,7 +248,6 @@
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
final long bytes = isLimit ? editor.getPolicyLimitBytes(template)
: editor.getPolicyWarningBytes(template);
- final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;
if (bytes > 1.5f * GB_IN_BYTES) {
final String bytesText = formatText(bytes / (float) GB_IN_BYTES);
@@ -265,7 +266,7 @@
private String formatText(float v) {
v = Math.round(v * 100) / 100f;
- return String.valueOf(v);
+ return NumberFormat.getInstance().format(v);
}
@Override
@@ -278,15 +279,20 @@
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
- EditText bytesField = (EditText) mView.findViewById(R.id.bytes);
- Spinner spinner = (Spinner) mView.findViewById(R.id.size_spinner);
+ EditText bytesField = mView.findViewById(R.id.bytes);
+ Spinner spinner = mView.findViewById(R.id.size_spinner);
String bytesString = bytesField.getText().toString();
- if (bytesString.isEmpty()) {
- bytesString = "0";
+
+ double input = 0;
+ try {
+ input = NumberFormat.getInstance().parse(bytesString).doubleValue();
+ } catch (ParseException e) {
+ Log.w(TAG, "Failed to parse byte value " + bytesString);
}
- final long bytes = (long) (Float.valueOf(bytesString)
- * (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
+
+ final long bytes = (long) (input
+ * (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
// to fix the overflow problem
final long correctedBytes = Math.min(MAX_DATA_LIMIT_BYTES, bytes);
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index bfb9f0f..376005c 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -59,7 +59,7 @@
import android.os.storage.IStorageManager;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
-import android.service.persistentdata.PersistentDataBlockManager;
+import android.service.oemlock.OemLockManager;
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.ListPreference;
@@ -238,7 +238,6 @@
private static final int RESULT_DEBUG_APP = 1000;
private static final int RESULT_MOCK_LOCATION_APP = 1001;
- private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked";
private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
@@ -252,7 +251,7 @@
private IWebViewUpdateService mWebViewUpdateService;
private UserManager mUm;
private WifiManager mWifiManager;
- private PersistentDataBlockManager mOemUnlockManager;
+ private OemLockManager mOemLockManager;
private TelephonyManager mTelephonyManager;
private SwitchBar mSwitchBar;
@@ -383,8 +382,7 @@
mBackupManager = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
mWebViewUpdateService = WebViewFactory.getUpdateService();
- mOemUnlockManager = (PersistentDataBlockManager) getActivity()
- .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
+ mOemLockManager = (OemLockManager) getSystemService(Context.OEM_LOCK_SERVICE);
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
@@ -431,7 +429,7 @@
mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
- if (!showEnableOemUnlockPreference()) {
+ if (!showEnableOemUnlockPreference(getActivity())) {
removePreference(mEnableOemUnlock);
mEnableOemUnlock = null;
}
@@ -1070,18 +1068,17 @@
Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
}
- private static boolean showEnableOemUnlockPreference() {
- return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
+ private static boolean showEnableOemUnlockPreference(Context context) {
+ return context.getSystemService(Context.OEM_LOCK_SERVICE) != null;
}
private boolean enableOemUnlockPreference() {
- return !isBootloaderUnlocked() && OemUnlockUtils.isOemUnlockAllowed(mUm);
+ return !isBootloaderUnlocked() && mOemLockManager.canUserAllowOemUnlock();
}
private void updateOemUnlockOptions() {
if (mEnableOemUnlock != null) {
- updateSwitchPreference(mEnableOemUnlock,
- OemUnlockUtils.isOemUnlockEnabled(getActivity()));
+ updateSwitchPreference(mEnableOemUnlock, mOemLockManager.isOemUnlockAllowed());
updateOemUnlockSettingDescription();
// Showing mEnableOemUnlock preference as device has persistent data block.
mEnableOemUnlock.setDisabledByAdmin(null);
@@ -2339,7 +2336,7 @@
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
- OemUnlockUtils.setOemUnlockEnabled(getActivity(), true);
+ mOemLockManager.setOemUnlockAllowedByUser(true);
}
}
};
@@ -2410,7 +2407,7 @@
if (mEnableOemUnlock.isChecked()) {
confirmEnableOemUnlock();
} else {
- OemUnlockUtils.setOemUnlockEnabled(getActivity(), false);
+ mOemLockManager.setOemUnlockAllowedByUser(false);
}
}
} else {
@@ -2480,7 +2477,7 @@
confirmEnableOemUnlock();
}
} else {
- OemUnlockUtils.setOemUnlockEnabled(getActivity(), false);
+ mOemLockManager.setOemUnlockAllowedByUser(false);
}
} else if (preference == mMockLocationAppPref) {
Intent intent = new Intent(getActivity(), AppPicker.class);
@@ -2821,7 +2818,7 @@
}
final List<String> keys = new ArrayList<String>();
- if (!showEnableOemUnlockPreference()) {
+ if (!showEnableOemUnlockPreference(context)) {
keys.add(ENABLE_OEM_UNLOCK);
}
return keys;
@@ -2849,11 +2846,10 @@
oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_bootloader_unlocked;
} else if (isSimLockedDevice()) {
oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_sim_locked_device;
- } else if (!OemUnlockUtils.isOemUnlockAllowed(mUm)) {
- // If the device isn't SIM-locked but OEM unlock is disabled by the system via the
- // user restriction, this means either some other carrier restriction is in place or
- // the device hasn't been able to confirm which restrictions (SIM-lock or otherwise)
- // apply.
+ } else if (!mOemLockManager.canUserAllowOemUnlock()) {
+ // If the device isn't SIM-locked but OEM unlock is disallowed by some party, this
+ // means either some other carrier restriction is in place or the device hasn't been
+ // able to confirm which restrictions (SIM-lock or otherwise) apply.
oemUnlockSummary =
R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked;
}
@@ -2876,12 +2872,7 @@
* Returns {@code true} if the bootloader has been unlocked. Otherwise, returns {code false}.
*/
private boolean isBootloaderUnlocked() {
- int flashLockState = PersistentDataBlockManager.FLASH_LOCK_UNKNOWN;
- if (mOemUnlockManager != null) {
- flashLockState = mOemUnlockManager.getFlashLockState();
- }
-
- return flashLockState == PersistentDataBlockManager.FLASH_LOCK_UNLOCKED;
+ return mOemLockManager.isDeviceOemUnlocked();
}
diff --git a/src/com/android/settings/development/OemUnlockUtils.java b/src/com/android/settings/development/OemUnlockUtils.java
deleted file mode 100644
index cee3679..0000000
--- a/src/com/android/settings/development/OemUnlockUtils.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.development;
-
-import android.content.Context;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.service.persistentdata.PersistentDataBlockManager;
-import android.util.Log;
-
-public class OemUnlockUtils {
- private static final String TAG = "OemUnlockUtils";
-
- /**
- * Returns whether or not this device is able to be OEM unlocked.
- */
- static boolean isOemUnlockEnabled(Context context) {
- PersistentDataBlockManager manager = (PersistentDataBlockManager)
- context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
- return manager.getOemUnlockEnabled();
- }
-
- /**
- * Allows enabling or disabling OEM unlock on this device. OEM unlocked
- * devices allow users to flash other OSes to them.
- */
- static void setOemUnlockEnabled(Context context, boolean enabled) {
- try {
- PersistentDataBlockManager manager = (PersistentDataBlockManager)
- context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
- manager.setOemUnlockEnabled(enabled);
- } catch (SecurityException e) {
- Log.e(TAG, "Fail to set oem unlock.", e);
- }
- }
-
- /**
- * Returns {@code true} if OEM unlock is disallowed by user restriction
- * {@link UserManager#DISALLOW_FACTORY_RESET} or {@link UserManager#DISALLOW_OEM_UNLOCK}.
- * Otherwise, returns {@code false}.
- */
- static boolean isOemUnlockAllowed(UserManager um) {
- final UserHandle userHandle = UserHandle.of(UserHandle.myUserId());
- return !(um.hasBaseUserRestriction(UserManager.DISALLOW_OEM_UNLOCK, userHandle)
- || um.hasBaseUserRestriction(UserManager.DISALLOW_FACTORY_RESET, userHandle));
- }
-}
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index b5d7ddf..10df004 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -59,7 +59,6 @@
import com.android.settings.Utils;
import com.android.settings.applications.ManageApplications;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import com.android.settings.deviceinfo.StorageSettings.MountTask;
import com.android.settingslib.deviceinfo.StorageMeasurement;
import com.android.settingslib.deviceinfo.StorageMeasurement.MeasurementDetails;
@@ -126,7 +125,6 @@
private int mItemPoolIndex;
private Preference mExplore;
- private Preference mAutomaticStorageManagement;
private boolean mNeedsUpdate;
@@ -185,7 +183,6 @@
mCurrentUser = mUserManager.getUserInfo(UserHandle.myUserId());
mExplore = buildAction(R.string.storage_menu_explore);
- mAutomaticStorageManagement = buildAction(R.string.storage_menu_manage);
mNeedsUpdate = true;
@@ -212,9 +209,6 @@
screen.removeAll();
- if (getResources().getBoolean(R.bool.config_storage_manager_settings_enabled)) {
- addPreference(screen, mAutomaticStorageManagement);
- }
addPreference(screen, mSummary);
List<UserInfo> allUsers = mUserManager.getUsers();
@@ -331,6 +325,7 @@
private StorageItemPreference buildItem() {
final StorageItemPreference item = new StorageItemPreference(getPrefContext());
+ item.setIcon(R.drawable.empty_icon);
return item;
}
@@ -511,11 +506,6 @@
case R.string.storage_menu_explore: {
intent = mSharedVolume.buildBrowseIntent();
} break;
- case R.string.storage_menu_manage: {
- startFragment(this, AutomaticStorageManagerSettings.class.getCanonicalName(),
- R.string.automatic_storage_manager_settings, 0, null);
- return true;
- }
case 0: {
UserInfoFragment.show(this, pref.getTitle(), pref.getSummary());
return true;
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index bc64ffa..2a5ac17 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -16,9 +16,9 @@
package com.android.settings.deviceinfo;
+import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
-import android.content.Intent;
import android.content.Loader;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -28,16 +28,11 @@
import android.os.storage.VolumeInfo;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
-import android.util.Log;
import android.util.SparseArray;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settings.applications.PackageManagerWrapper;
import com.android.settings.applications.PackageManagerWrapperImpl;
import com.android.settings.applications.UserManagerWrapper;
import com.android.settings.applications.UserManagerWrapperImpl;
@@ -57,7 +52,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Objects;
public class StorageDashboardFragment extends DashboardFragment
implements LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
@@ -78,16 +72,15 @@
super.onCreate(icicle);
// Initialize the storage sizes that we can quickly calc.
- final Context context = getActivity();
- StorageManager sm = context.getSystemService(StorageManager.class);
+ final Activity activity = getActivity();
+ StorageManager sm = activity.getSystemService(StorageManager.class);
mVolume = Utils.maybeInitializeVolume(sm, getArguments());
if (mVolume == null) {
- getActivity().finish();
+ activity.finish();
return;
}
- mOptionMenuController = new PrivateVolumeOptionMenuController(
- context, mVolume, new PackageManagerWrapperImpl(context.getPackageManager()));
+ initializeOptionsMenu(activity);
final long sharedDataSize = mVolume.getPath().getTotalSpace();
long totalSize = sm.getPrimaryStorageSize();
@@ -101,8 +94,7 @@
final long usedBytes = totalSize - mVolume.getPath().getFreeSpace();
mSummaryController.updateBytes(usedBytes, totalSize);
mPreferenceController.setVolume(mVolume);
- mPreferenceController.setSystemSize(systemSize);
-
+ mPreferenceController.setUsedSize(usedBytes);
mPreferenceController.setTotalSize(totalSize);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
PreferenceController controller = mSecondaryUsers.get(i);
@@ -114,6 +106,15 @@
}
}
+ @VisibleForTesting
+ void initializeOptionsMenu(Activity activity) {
+ mOptionMenuController = new PrivateVolumeOptionMenuController(
+ activity, mVolume, new PackageManagerWrapperImpl(activity.getPackageManager()));
+ getLifecycle().addObserver(mOptionMenuController);
+ setHasOptionsMenu(true);
+ activity.invalidateOptionsMenu();
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -156,7 +157,6 @@
new AutomaticStorageManagementSwitchPreferenceController(
context, mMetricsFeatureProvider, getFragmentManager());
getLifecycle().addObserver(asmController);
- getLifecycle().addObserver(mOptionMenuController);
controllers.add(asmController);
return controllers;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
index 86472f9..fb162cd 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.UserInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.UserHandle;
import android.util.Log;
import android.util.SparseArray;
@@ -32,6 +33,7 @@
import com.android.settings.utils.AsyncLoader;
import com.android.settingslib.applications.StorageStatsSource;
+import java.io.IOException;
import java.util.List;
/**
@@ -83,7 +85,7 @@
StorageStatsSource.AppStorageStats stats;
try {
stats = mStatsManager.getStatsForPackage(mUuid, app.packageName, myUser);
- } catch (IllegalStateException e) {
+ } catch (NameNotFoundException | IOException e) {
// This may happen if the package was removed during our calculation.
continue;
}
@@ -121,7 +123,11 @@
}
Log.d(TAG, "Loading external stats");
- result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
+ try {
+ result.externalStats = mStatsManager.getExternalStorageStats(mUuid, UserHandle.of(userId));
+ } catch (IOException e) {
+ Log.w(TAG, e);
+ }
Log.d(TAG, "Obtaining result completed");
return result;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 36694f0..5c4e354 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -78,7 +78,7 @@
private final StorageVolumeProvider mSvp;
private VolumeInfo mVolume;
private int mUserId;
- private long mSystemSize;
+ private long mUsedBytes;
private long mTotalSize;
private StorageItemPreference mPhotoPreference;
@@ -226,17 +226,29 @@
mGamePreference.setStorageSize(data.gamesSize, mTotalSize);
mMoviesPreference.setStorageSize(data.videoAppsSize, mTotalSize);
mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
- if (mSystemPreference != null) {
- mSystemPreference.setStorageSize(mSystemSize + data.systemSize, mTotalSize);
- }
- long unattributedBytes = data.externalStats.totalBytes - data.externalStats.audioBytes
- - data.externalStats.videoBytes - data.externalStats.imageBytes;
- mFilePreference.setStorageSize(unattributedBytes, mTotalSize);
+ long unattributedExternalBytes =
+ data.externalStats.totalBytes
+ - data.externalStats.audioBytes
+ - data.externalStats.videoBytes
+ - data.externalStats.imageBytes;
+ mFilePreference.setStorageSize(unattributedExternalBytes, mTotalSize);
+
+ // We define the system size as everything we can't classify.
+ if (mSystemPreference != null) {
+ mSystemPreference.setStorageSize(
+ mUsedBytes
+ - data.externalStats.totalBytes
+ - data.musicAppsSize
+ - data.gamesSize
+ - data.videoAppsSize
+ - data.otherAppsSize,
+ mTotalSize);
+ }
}
- public void setSystemSize(long systemSizeBytes) {
- mSystemSize = systemSizeBytes;
+ public void setUsedSize(long usedSizeBytes) {
+ mUsedBytes = usedSizeBytes;
}
public void setTotalSize(long totalSizeBytes) {
diff --git a/src/com/android/settings/display/AutoBrightnessPreferenceController.java b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
index 83304c2..f36ed36 100644
--- a/src/com/android/settings/display/AutoBrightnessPreferenceController.java
+++ b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
@@ -14,14 +14,17 @@
package com.android.settings.display;
import android.content.Context;
+import android.content.Intent;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.util.ArrayMap;
import com.android.settings.core.PreferenceController;
+import com.android.settings.search2.DatabaseIndexingUtils;
import com.android.settings.search2.InlineSwitchPayload;
import com.android.settings.search2.ResultPayload;
+import com.android.settings.R;
import java.util.Map;
@@ -33,10 +36,11 @@
public class AutoBrightnessPreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
- private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
+ private final String mAutoBrightnessKey;
- public AutoBrightnessPreferenceController(Context context) {
+ public AutoBrightnessPreferenceController(Context context, String key) {
super(context);
+ mAutoBrightnessKey = key;
}
@Override
@@ -47,7 +51,7 @@
@Override
public String getPreferenceKey() {
- return KEY_AUTO_BRIGHTNESS;
+ return mAutoBrightnessKey;
}
@Override
@@ -71,7 +75,11 @@
valueMap.put(SCREEN_BRIGHTNESS_MODE_AUTOMATIC, true);
valueMap.put(SCREEN_BRIGHTNESS_MODE_MANUAL, false);
+ final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
+ getClass().getName(), mAutoBrightnessKey,
+ mContext.getString(R.string.display_settings));
+
return new InlineSwitchPayload(SCREEN_BRIGHTNESS_MODE,
- ResultPayload.SettingsSource.SYSTEM, valueMap);
+ ResultPayload.SettingsSource.SYSTEM, valueMap, intent);
}
}
diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceController.java b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
index e0000d6..d012ac3 100644
--- a/src/com/android/settings/display/BrightnessLevelPreferenceController.java
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
@@ -13,20 +13,79 @@
*/
package com.android.settings.display;
-import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
-
+import android.content.ContentResolver;
import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.PowerManager;
+import android.os.RemoteException;
+import android.os.ServiceManager;
import android.provider.Settings;
+import android.provider.Settings.System;
+import android.service.vr.IVrManager;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.util.Log;
+
import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
+import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.core.lifecycle.events.OnPause;
+import com.android.settings.core.lifecycle.events.OnResume;
+
import java.text.NumberFormat;
-public class BrightnessLevelPreferenceController extends PreferenceController {
+public class BrightnessLevelPreferenceController extends PreferenceController implements
+ LifecycleObserver, OnResume, OnPause {
+ private static final String TAG = "BrightnessPrefCtrl";
private static final String KEY_BRIGHTNESS = "brightness";
+ private static final Uri BRIGHTNESS_MODE_URI;
+ private static final Uri BRIGHTNESS_URI;
+ private static final Uri BRIGHTNESS_FOR_VR_URI;
+ private static final Uri BRIGHTNESS_ADJ_URI;
- public BrightnessLevelPreferenceController(Context context) {
+ private final int mMinBrightness;
+ private final int mMaxBrightness;
+ private final int mMinVrBrightness;
+ private final int mMaxVrBrightness;
+ private final ContentResolver mContentResolver;
+
+ private Preference mPreference;
+
+ static {
+ BRIGHTNESS_MODE_URI = System.getUriFor(System.SCREEN_BRIGHTNESS_MODE);
+ BRIGHTNESS_URI = System.getUriFor(System.SCREEN_BRIGHTNESS);
+ BRIGHTNESS_FOR_VR_URI = System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR);
+ BRIGHTNESS_ADJ_URI = System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ);
+ }
+
+ private ContentObserver mBrightnessObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ updatedSummary(mPreference);
+ }
+ };
+
+ public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
+ this(context, lifecycle, new PowerManagerWrapper(
+ (PowerManager) context.getSystemService(Context.POWER_SERVICE)));
+ }
+
+ @VisibleForTesting
+ public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle,
+ PowerManagerWrapper powerManagerWrapper) {
super(context);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ mMinBrightness = powerManagerWrapper.getMinimumScreenBrightnessSetting();
+ mMaxBrightness = powerManagerWrapper.getMaximumScreenBrightnessSetting();
+ mMinVrBrightness = powerManagerWrapper.getMinimumScreenBrightnessForVrSetting();
+ mMaxVrBrightness = powerManagerWrapper.getMaximumScreenBrightnessForVrSetting();
+ mContentResolver = mContext.getContentResolver();
}
@Override
@@ -40,10 +99,66 @@
}
@Override
- public void updateState(Preference preference) {
- final double brightness = Settings.System.getInt(mContext.getContentResolver(),
- SCREEN_BRIGHTNESS, 0);
- preference.setSummary(NumberFormat.getPercentInstance().format(brightness / 255));
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(KEY_BRIGHTNESS);
}
+ @Override
+ public void updateState(Preference preference) {
+ updatedSummary(preference);
+ }
+
+ @Override
+ public void onResume() {
+ mContentResolver.registerContentObserver(BRIGHTNESS_MODE_URI, false, mBrightnessObserver);
+ mContentResolver.registerContentObserver(BRIGHTNESS_URI, false, mBrightnessObserver);
+ mContentResolver.registerContentObserver(BRIGHTNESS_FOR_VR_URI, false, mBrightnessObserver);
+ mContentResolver.registerContentObserver(BRIGHTNESS_ADJ_URI, false, mBrightnessObserver);
+ }
+
+ @Override
+ public void onPause() {
+ mContentResolver.unregisterContentObserver(mBrightnessObserver);
+ }
+
+ private void updatedSummary(Preference preference) {
+ if (preference != null) {
+ preference.setSummary(NumberFormat.getPercentInstance().format(getCurrentBrightness()));
+ }
+ }
+
+ private double getCurrentBrightness() {
+ if (isInVrMode()) {
+ final double value = System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR,
+ mMaxBrightness);
+ return getPercentage(value, mMinVrBrightness, mMaxVrBrightness);
+ }
+ final int brightnessMode = Settings.System.getInt(mContentResolver,
+ System.SCREEN_BRIGHTNESS_MODE, System.SCREEN_BRIGHTNESS_MODE_MANUAL);
+ if (brightnessMode == System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
+ final float value = Settings.System.getFloat(mContentResolver,
+ System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0);
+ // auto brightness is between -1 and 1
+ return ((value + 1)) / 2;
+ }
+ final double value = Settings.System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS,
+ mMinBrightness);
+ return getPercentage(value, mMinBrightness, mMaxBrightness);
+ }
+
+ private double getPercentage(double value, int min, int max) {
+ return (value - min) / (max - min);
+ }
+
+ @VisibleForTesting
+ boolean isInVrMode() {
+ try {
+ return IVrManager.Stub.asInterface(ServiceManager.getService(Context.VR_SERVICE))
+ .getVrModeState();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to check vr mode!", e);
+ }
+ return false;
+ }
}
diff --git a/src/com/android/settings/display/PowerManagerWrapper.java b/src/com/android/settings/display/PowerManagerWrapper.java
new file mode 100644
index 0000000..afa2f33
--- /dev/null
+++ b/src/com/android/settings/display/PowerManagerWrapper.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.display;
+
+import android.os.PowerManager;
+
+/**
+ * This class replicates a subset of the android.os.PowerManager. The class exists so that we can
+ * use a thin wrapper around the PowerManager in production code and a mock in tests. We cannot
+ * directly mock or shadow the PowerManager, because some of the methods we rely on are newer than
+ * the API version supported by Robolectric or are hidden.
+ */
+public class PowerManagerWrapper {
+ private final PowerManager mPowerManager;
+
+ public PowerManagerWrapper(PowerManager powerManager) {
+ mPowerManager = powerManager;
+ }
+
+ public int getMinimumScreenBrightnessSetting() {
+ return mPowerManager.getMinimumScreenBrightnessSetting();
+ }
+
+ public int getMaximumScreenBrightnessSetting() {
+ return mPowerManager.getMaximumScreenBrightnessSetting();
+ }
+
+ public int getMinimumScreenBrightnessForVrSetting() {
+ return mPowerManager.getMinimumScreenBrightnessForVrSetting();
+ }
+
+ public int getMaximumScreenBrightnessForVrSetting() {
+ return mPowerManager.getMaximumScreenBrightnessForVrSetting();
+ }
+}
diff --git a/src/com/android/settings/display/TimeoutPreferenceController.java b/src/com/android/settings/display/TimeoutPreferenceController.java
index d409656..b2890c2 100644
--- a/src/com/android/settings/display/TimeoutPreferenceController.java
+++ b/src/com/android/settings/display/TimeoutPreferenceController.java
@@ -35,10 +35,11 @@
/** If there is no setting in the provider, use this. */
public static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000;
- private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
+ private final String mScreenTimeoutKey;
- public TimeoutPreferenceController(Context context) {
+ public TimeoutPreferenceController(Context context, String key) {
super(context);
+ mScreenTimeoutKey = key;
}
@Override
@@ -48,7 +49,7 @@
@Override
public String getPreferenceKey() {
- return KEY_SCREEN_TIMEOUT;
+ return mScreenTimeoutKey;
}
@Override
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index 01670fe..fb59c59 100644
--- a/src/com/android/settings/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/fingerprint/FingerprintSettings.java
@@ -47,6 +47,7 @@
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.style.URLSpan;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@@ -604,7 +605,9 @@
private void renameFingerPrint(int fingerId, String newName) {
mFingerprintManager.rename(fingerId, mUserId, newName);
- mFingerprintsRenaming.put(fingerId, newName);
+ if (!TextUtils.isEmpty(newName)) {
+ mFingerprintsRenaming.put(fingerId, newName);
+ }
updatePreferences();
}
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 320031e..0c798a6 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -17,16 +17,12 @@
package com.android.settings.fuelgauge;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.BatteryStats;
import android.os.Bundle;
-import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
@@ -179,7 +175,7 @@
@VisibleForTesting
void initHeader() {
final View appSnippet = mHeaderPreference.findViewById(R.id.app_snippet);
- final Context context = getContext();
+ final Activity context = getActivity();
final Bundle bundle = getArguments();
AppHeaderController controller = FeatureFactory.getFactory(context)
.getApplicationFeatureProvider(context)
@@ -203,7 +199,7 @@
controller.setSummary(getString(Utils.getInstallationStatus(mAppEntry.info)));
}
- controller.done(true /* rebindActions */);
+ controller.done(context, true /* rebindActions */);
}
@Override
@@ -230,7 +226,7 @@
controllers.add(new BackgroundActivityPreferenceController(context, uid));
controllers.add(new BatteryOptimizationPreferenceController(
- (SettingsActivity) getActivity(), this));
+ (SettingsActivity) getActivity(), this, packageName));
mAppButtonsPreferenceController = new AppButtonsPreferenceController(
(SettingsActivity) getActivity(), this, getLifecycle(), packageName, mState, mDpm,
mUserManager, mPackageManager, REQUEST_UNINSTALL, REQUEST_REMOVE_DEVICE_ADMIN);
diff --git a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
index 463d4dc..60a94dd 100644
--- a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
@@ -55,16 +55,14 @@
public void updateState(Preference preference) {
final int mode = mAppOpsManager
.checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage);
-
if (mode == AppOpsManager.MODE_ERRORED) {
preference.setEnabled(false);
- preference.setSummary(R.string.background_activity_summary_disabled);
} else {
final boolean checked = mode != AppOpsManager.MODE_IGNORED;
((SwitchPreference) preference).setChecked(checked);
- preference.setSummary(checked ? R.string.background_activity_summary_on
- : R.string.background_activity_summary_off);
}
+
+ updateSummary(preference);
}
@Override
@@ -92,6 +90,8 @@
boolean switchOn = (Boolean) newValue;
mAppOpsManager.setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage,
switchOn ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
+
+ updateSummary(preference);
return true;
}
@@ -113,4 +113,18 @@
return false;
}
+
+ @VisibleForTesting
+ void updateSummary(Preference preference) {
+ final int mode = mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage);
+
+ if (mode == AppOpsManager.MODE_ERRORED) {
+ preference.setSummary(R.string.background_activity_summary_disabled);
+ } else {
+ final boolean checked = mode != AppOpsManager.MODE_IGNORED;
+ preference.setSummary(checked ? R.string.background_activity_summary_on
+ : R.string.background_activity_summary_off);
+ }
+ }
}
diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
new file mode 100644
index 0000000..9d37333
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.fuelgauge;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settings.Utils;
+
+/**
+ * Use this broadcastReceiver to listen to the battery change, and it will invoke
+ * {@link OnBatteryChangedListener} if any of the following happens:
+ *
+ * 1. Battery level has been changed
+ * 2. Battery status has been changed
+ */
+public class BatteryBroadcastReceiver extends BroadcastReceiver {
+
+ interface OnBatteryChangedListener {
+ void onBatteryChanged();
+ }
+
+ @VisibleForTesting
+ String mBatteryLevel;
+ @VisibleForTesting
+ String mBatteryStatus;
+ private OnBatteryChangedListener mBatteryListener;
+ private Context mContext;
+
+ public BatteryBroadcastReceiver(Context context) {
+ mContext = context;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (mBatteryListener != null && Intent.ACTION_BATTERY_CHANGED.equals(action)
+ && updateBatteryStatus(intent)) {
+ mBatteryListener.onBatteryChanged();
+ }
+ }
+
+ public void setBatteryChangedListener(OnBatteryChangedListener lsn) {
+ mBatteryListener = lsn;
+ }
+
+ public void register() {
+ mContext.registerReceiver(this,
+ new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ }
+
+ public void unRegister() {
+ mContext.unregisterReceiver(this);
+ }
+
+ private boolean updateBatteryStatus(Intent intent) {
+ if (intent != null) {
+ String batteryLevel = Utils.getBatteryPercentage(intent);
+ String batteryStatus = Utils.getBatteryStatus(
+ mContext.getResources(), intent);
+ if (!batteryLevel.equals(mBatteryLevel) || !batteryStatus.equals(mBatteryStatus)) {
+ mBatteryLevel = batteryLevel;
+ mBatteryStatus = batteryStatus;
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
index 7b89fb1..8588f77 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java
@@ -511,7 +511,7 @@
elapsedRealtimeUs);
mDrainString = "";
mChargeDurationString = "";
- setContentDescription(mInfo.mChargeLabelString);
+ setContentDescription(mInfo.chargeLabelString);
int pos = 0;
int lastInteresting = 0;
@@ -589,7 +589,7 @@
mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
- mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.mChargeLabelString);
+ mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.chargeLabelString);
mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
mTextAscent = (int)mTextPaint.ascent();
mTextDescent = (int)mTextPaint.descent();
@@ -974,7 +974,7 @@
}
}
}
-
+
i++;
}
mStats.finishIteratingHistoryLocked();
@@ -983,9 +983,9 @@
if (lastY < 0 || lastX < 0) {
// Didn't get any data...
x = lastX = mLevelLeft;
- y = lastY = mLevelTop + levelh - ((mInfo.mBatteryLevel-batLow)*(levelh-1))/batChange;
+ y = lastY = mLevelTop + levelh - ((mInfo.batteryLevel -batLow)*(levelh-1))/batChange;
Path path;
- byte value = (byte)mInfo.mBatteryLevel;
+ byte value = (byte)mInfo.batteryLevel;
if (value <= mBatteryCriticalLevel) path = mBatCriticalPath;
else if (value <= mBatteryWarnLevel) path = mBatWarnPath;
else path = null; //mBatGoodPath;
@@ -1014,7 +1014,7 @@
mTimeRemainPath.moveTo(x, lastY);
int fullY = mLevelTop + levelh - ((100-batLow)*(levelh-1))/batChange;
int emptyY = mLevelTop + levelh - ((0-batLow)*(levelh-1))/batChange;
- if (mInfo.mDischarging) {
+ if (mInfo.discharging) {
mTimeRemainPath.lineTo(mLevelRight, emptyY);
} else {
mTimeRemainPath.lineTo(mLevelRight, fullY);
@@ -1211,8 +1211,8 @@
int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
mHeaderTextPaint.setTextAlign(textAlignLeft);
- if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.mChargeLabelString);
- canvas.drawText(mInfo.mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
+ if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.chargeLabelString);
+ canvas.drawText(mInfo.chargeLabelString, textStartX, headerTop, mHeaderTextPaint);
int stringHalfWidth = mChargeDurationStringWidth / 2;
if (layoutRtl) stringHalfWidth = -stringHalfWidth;
int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
diff --git a/src/com/android/settings/fuelgauge/BatteryMeterView.java b/src/com/android/settings/fuelgauge/BatteryMeterView.java
index dcbf472..c450b90 100644
--- a/src/com/android/settings/fuelgauge/BatteryMeterView.java
+++ b/src/com/android/settings/fuelgauge/BatteryMeterView.java
@@ -18,17 +18,25 @@
import android.annotation.Nullable;
import android.content.Context;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.VisibleForTesting;
import android.util.AttributeSet;
import android.widget.ImageView;
+
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.graph.BatteryMeterDrawableBase;
public class BatteryMeterView extends ImageView {
- private BatteryMeterDrawable mDrawable;
+ @VisibleForTesting
+ BatteryMeterDrawable mDrawable;
+ @VisibleForTesting
+ ColorFilter mErrorColorFilter;
+ @VisibleForTesting
+ ColorFilter mAccentColorFilter;
public BatteryMeterView(Context context) {
this(context, null, 0);
@@ -42,21 +50,30 @@
super(context, attrs, defStyleAttr);
final int frameColor = context.getColor(R.color.batterymeter_frame_color);
- final int tintColor = Utils.getColorAttr(context, android.R.attr.colorAccent);
+ mAccentColorFilter = new PorterDuffColorFilter(
+ Utils.getColorAttr(context, android.R.attr.colorAccent), PorterDuff.Mode.SRC_IN);
+ mErrorColorFilter = new PorterDuffColorFilter(
+ context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
mDrawable = new BatteryMeterDrawable(context, frameColor);
- mDrawable.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
mDrawable.setShowPercent(false);
+ mDrawable.setBatteryColorFilter(mAccentColorFilter);
+ mDrawable.setWarningColorFilter(
+ new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
setImageDrawable(mDrawable);
}
- public void setBatteryInfo(int level) {
+ public void setBatteryLevel(int level) {
mDrawable.setBatteryLevel(level);
+ if (level < mDrawable.getCriticalLevel()) {
+ mDrawable.setBatteryColorFilter(mErrorColorFilter);
+ } else {
+ mDrawable.setBatteryColorFilter(mAccentColorFilter);
+ }
}
- @VisibleForTesting
- void setBatteryDrawable(BatteryMeterDrawable drawable) {
- mDrawable = drawable;
+ public void setCharging(boolean charging) {
+ mDrawable.setCharging(charging);
}
public static class BatteryMeterDrawable extends BatteryMeterDrawableBase {
@@ -81,6 +98,16 @@
public int getIntrinsicHeight() {
return mIntrinsicHeight;
}
+
+ public void setWarningColorFilter(@Nullable ColorFilter colorFilter) {
+ mWarningTextPaint.setColorFilter(colorFilter);
+ }
+
+ public void setBatteryColorFilter(@Nullable ColorFilter colorFilter) {
+ mFramePaint.setColorFilter(colorFilter);
+ mBatteryPaint.setColorFilter(colorFilter);
+ mBoltPaint.setColorFilter(colorFilter);
+ }
}
}
diff --git a/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceController.java
index 946a9b8..7c5bda2 100644
--- a/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceController.java
@@ -17,6 +17,7 @@
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
@@ -33,14 +34,29 @@
private static final String KEY_BACKGROUND_ACTIVITY = "battery_optimization";
+
+ private PowerWhitelistBackend mBackend;
private Fragment mFragment;
private SettingsActivity mSettingsActivity;
+ private String mPackageName;
public BatteryOptimizationPreferenceController(SettingsActivity settingsActivity,
- Fragment fragment) {
+ Fragment fragment, String packageName) {
super(settingsActivity);
mFragment = fragment;
mSettingsActivity = settingsActivity;
+ mPackageName = packageName;
+ mBackend = PowerWhitelistBackend.getInstance();
+ }
+
+ @VisibleForTesting
+ BatteryOptimizationPreferenceController(SettingsActivity settingsActivity,
+ Fragment fragment, String packageName, PowerWhitelistBackend backend) {
+ super(settingsActivity);
+ mFragment = fragment;
+ mSettingsActivity = settingsActivity;
+ mPackageName = packageName;
+ mBackend = backend;
}
@Override
@@ -49,6 +65,12 @@
}
@Override
+ public void updateState(Preference preference) {
+ final boolean isWhitelisted = mBackend.isWhitelisted(mPackageName);
+ preference.setSummary(isWhitelisted ? R.string.high_power_on : R.string.high_power_off);
+ }
+
+ @Override
public String getPreferenceKey() {
return KEY_BACKGROUND_ACTIVITY;
}
@@ -66,4 +88,5 @@
R.string.high_power_apps, null, null, 0);
return true;
}
+
}
diff --git a/src/com/android/settings/fuelgauge/BatterySaverController.java b/src/com/android/settings/fuelgauge/BatterySaverController.java
index 08d570a..34c9a26 100644
--- a/src/com/android/settings/fuelgauge/BatterySaverController.java
+++ b/src/com/android/settings/fuelgauge/BatterySaverController.java
@@ -43,7 +43,7 @@
public class BatterySaverController extends PreferenceController implements
Preference.OnPreferenceChangeListener, LifecycleObserver, OnStart, OnStop {
- private static final String KEY_BATTERY_SAVER = "battery_saver";
+ private static final String KEY_BATTERY_SAVER = "battery_saver_summary";
private static final String TAG = "BatterySaverController";
private static final boolean DEBUG = false;
diff --git a/src/com/android/settings/fuelgauge/FakeUid.java b/src/com/android/settings/fuelgauge/FakeUid.java
index 770c567..8bb7d88 100644
--- a/src/com/android/settings/fuelgauge/FakeUid.java
+++ b/src/com/android/settings/fuelgauge/FakeUid.java
@@ -266,11 +266,6 @@
}
@Override
- public long getCpuPowerMaUs(int which) {
- return 0;
- }
-
- @Override
public BatteryStats.ControllerActivityCounter getWifiControllerActivity() {
return null;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index 3509834..722f4ad 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -172,7 +172,7 @@
mUsageListGroup.removeAll();
for (int i = 0, size = dataList.size(); i < size; i++) {
final PowerUsageData batteryData = dataList.get(i);
- if (shouldHide(batteryData)) {
+ if (shouldHideCategory(batteryData)) {
continue;
}
final PowerGaugePreference pref = new PowerGaugePreference(getPrefContext());
@@ -217,13 +217,15 @@
}
@VisibleForTesting
- boolean shouldHide(PowerUsageData powerUsageData) {
- if (powerUsageData.usageType == UsageType.UNACCOUNTED
- || powerUsageData.usageType == UsageType.OVERCOUNTED) {
- return true;
- }
+ boolean shouldHideCategory(PowerUsageData powerUsageData) {
+ return powerUsageData.usageType == UsageType.UNACCOUNTED
+ || powerUsageData.usageType == UsageType.OVERCOUNTED
+ || (powerUsageData.usageType == UsageType.USER && mUserManager.getUserCount() == 1);
+ }
- return false;
+ @VisibleForTesting
+ boolean shouldShowBatterySipper(BatterySipper batterySipper) {
+ return batterySipper.drainType != DrainType.SCREEN;
}
@VisibleForTesting
@@ -245,7 +247,9 @@
BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, STATUS_TYPE);
}
usageData.totalUsageTimeMs += sipper.usageTimeMs;
- usageData.usageList.add(sipper);
+ if (shouldShowBatterySipper(sipper)) {
+ usageData.usageList.add(sipper);
+ }
}
final List<PowerUsageData> batteryDataList = new ArrayList<>(batteryDataMap.values());
@@ -264,6 +268,9 @@
@VisibleForTesting
void updateUsageDataSummary(PowerUsageData usageData, double totalPower, int dischargeAmount) {
+ if (shouldHideSummary(usageData)) {
+ return;
+ }
if (usageData.usageList.size() <= 1) {
usageData.summary = getString(R.string.battery_used_for,
Utils.formatElapsedTime(getContext(), usageData.totalUsageTimeMs, false));
@@ -278,6 +285,13 @@
}
@VisibleForTesting
+ boolean shouldHideSummary(PowerUsageData powerUsageData) {
+ @UsageType final int usageType = powerUsageData.usageType;
+
+ return usageType == UsageType.CELL;
+ }
+
+ @VisibleForTesting
BatterySipper findBatterySipperWithMaxBatteryUsage(List<BatterySipper> usageList) {
BatterySipper sipper = usageList.get(0);
for (int i = 1, size = usageList.size(); i < size; i++) {
@@ -299,6 +313,10 @@
void setPowerUsageFeatureProvider(PowerUsageFeatureProvider provider) {
mPowerUsageFeatureProvider = provider;
}
+ @VisibleForTesting
+ void setUserManager(UserManager userManager) {
+ mUserManager = userManager;
+ }
/**
* Class that contains data used in {@link PowerGaugePreference}.
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 0236a30..1d9a228 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -45,9 +45,7 @@
protected BatteryStatsHelper mStatsHelper;
protected UserManager mUm;
-
- private String mBatteryLevel;
- private String mBatteryStatus;
+ private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
@Override
public void onAttach(Activity activity) {
@@ -61,6 +59,13 @@
super.onCreate(icicle);
mStatsHelper.create(icicle);
setHasOptionsMenu(true);
+
+ mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
+ mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
+ if (!mHandler.hasMessages(MSG_REFRESH_STATS)) {
+ mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500);
+ }
+ });
}
@Override
@@ -73,8 +78,7 @@
public void onResume() {
super.onResume();
BatteryStatsHelper.dropFile(getActivity(), BatteryHistoryDetail.BATTERY_HISTORY_FILE);
- updateBatteryStatus(getActivity().registerReceiver(mBatteryInfoReceiver,
- new IntentFilter(Intent.ACTION_BATTERY_CHANGED)));
+ mBatteryBroadcastReceiver.register();
if (mHandler.hasMessages(MSG_REFRESH_STATS)) {
mHandler.removeMessages(MSG_REFRESH_STATS);
mStatsHelper.clearStats();
@@ -84,7 +88,7 @@
@Override
public void onPause() {
super.onPause();
- getActivity().unregisterReceiver(mBatteryInfoReceiver);
+ mBatteryBroadcastReceiver.unRegister();
}
@Override
@@ -109,20 +113,6 @@
historyPref.setStats(mStatsHelper);
}
- private boolean updateBatteryStatus(Intent intent) {
- if (intent != null) {
- String batteryLevel = com.android.settings.Utils.getBatteryPercentage(intent);
- String batteryStatus = com.android.settings.Utils.getBatteryStatus(getResources(),
- intent);
- if (!batteryLevel.equals(mBatteryLevel) || !batteryStatus.equals(mBatteryStatus)) {
- mBatteryLevel = batteryLevel;
- mBatteryStatus = batteryStatus;
- return true;
- }
- }
- return false;
- }
-
static final int MSG_REFRESH_STATS = 100;
private final Handler mHandler = new Handler() {
@@ -137,17 +127,4 @@
}
};
- private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (Intent.ACTION_BATTERY_CHANGED.equals(action)
- && updateBatteryStatus(intent)) {
- if (!mHandler.hasMessages(MSG_REFRESH_STATS)) {
- mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500);
- }
- }
- }
- };
-
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index f701684..078a9b3 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -86,6 +86,9 @@
private static final String KEY_SCREEN_USAGE = "screen_usage";
private static final String KEY_TIME_SINCE_LAST_FULL_CHARGE = "last_full_charge";
+ private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness_battery";
+ private static final String KEY_SCREEN_TIMEOUT = "screen_timeout_battery";
+ private static final String KEY_BATTERY_SAVER_SUMMARY = "battery_saver_summary";
private static final int MENU_STATS_TYPE = Menu.FIRST;
@VisibleForTesting
@@ -185,8 +188,8 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
final List<PreferenceController> controllers = new ArrayList<>();
- controllers.add(new AutoBrightnessPreferenceController(context));
- controllers.add(new TimeoutPreferenceController(context));
+ controllers.add(new AutoBrightnessPreferenceController(context, KEY_AUTO_BRIGHTNESS));
+ controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
controllers.add(new BatterySaverController(context, getLifecycle()));
controllers.add(new BatteryPercentagePreferenceController(context));
return controllers;
@@ -561,14 +564,15 @@
.findViewById(R.id.battery_header_icon);
final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
- timeText.setText(Utils.formatPercentage(info.mBatteryLevel));
+ timeText.setText(Utils.formatPercentage(info.batteryLevel));
if (info.remainingLabel == null ) {
summary1.setText(info.statusLabel);
} else {
summary1.setText(info.remainingLabel);
}
- batteryView.setBatteryInfo(info.mBatteryLevel);
+ batteryView.setBatteryLevel(info.batteryLevel);
+ batteryView.setCharging(!info.discharging);
}
@VisibleForTesting
@@ -682,22 +686,28 @@
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
private final Context mContext;
private final SummaryLoader mLoader;
+ private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
private SummaryProvider(Context context, SummaryLoader loader) {
mContext = context;
mLoader = loader;
+ mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
+ mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
+ BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
+ @Override
+ public void onBatteryInfoLoaded(BatteryInfo info) {
+ mLoader.setSummary(SummaryProvider.this, info.chargeLabelString);
+ }
+ });
+ });
}
@Override
public void setListening(boolean listening) {
if (listening) {
- // TODO: Listen.
- BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
- @Override
- public void onBatteryInfoLoaded(BatteryInfo info) {
- mLoader.setSummary(SummaryProvider.this, info.mChargeLabelString);
- }
- });
+ mBatteryBroadcastReceiver.register();
+ } else {
+ mBatteryBroadcastReceiver.unRegister();
}
}
}
@@ -711,6 +721,16 @@
sir.xmlResId = R.xml.power_usage_summary;
return Arrays.asList(sir);
}
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ List<String> niks = new ArrayList<>();
+ // Duplicates in display
+ niks.add(KEY_AUTO_BRIGHTNESS);
+ niks.add(KEY_SCREEN_TIMEOUT);
+ niks.add(KEY_BATTERY_SAVER_SUMMARY);
+ return niks;
+ }
};
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
diff --git a/src/com/android/settings/fuelgauge/PowerWhitelistBackend.java b/src/com/android/settings/fuelgauge/PowerWhitelistBackend.java
index 7199af8..5590a46 100644
--- a/src/com/android/settings/fuelgauge/PowerWhitelistBackend.java
+++ b/src/com/android/settings/fuelgauge/PowerWhitelistBackend.java
@@ -18,6 +18,8 @@
import android.os.IDeviceIdleController;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.support.annotation.VisibleForTesting;
+
import android.util.ArraySet;
import android.util.Log;
@@ -31,7 +33,7 @@
private static final String DEVICE_IDLE_SERVICE = "deviceidle";
- private static final PowerWhitelistBackend INSTANCE = new PowerWhitelistBackend();
+ private static PowerWhitelistBackend sInstance;
private final IDeviceIdleController mDeviceIdleService;
private final ArraySet<String> mWhitelistedApps = new ArraySet<>();
@@ -73,7 +75,8 @@
}
}
- private void refreshList() {
+ @VisibleForTesting
+ void refreshList() {
mSysWhitelistedApps.clear();
mWhitelistedApps.clear();
try {
@@ -91,7 +94,10 @@
}
public static PowerWhitelistBackend getInstance() {
- return INSTANCE;
+ if (sInstance == null) {
+ sInstance = new PowerWhitelistBackend();
+ }
+ return sInstance;
}
}
diff --git a/src/com/android/settings/network/NetworkResetActionMenuController.java b/src/com/android/settings/network/NetworkResetActionMenuController.java
index 028ac7b..254834b 100644
--- a/src/com/android/settings/network/NetworkResetActionMenuController.java
+++ b/src/com/android/settings/network/NetworkResetActionMenuController.java
@@ -17,9 +17,6 @@
package com.android.settings.network;
import android.content.Context;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.support.annotation.VisibleForTesting;
import android.view.Menu;
import android.view.MenuItem;
@@ -27,15 +24,16 @@
import com.android.settings.R;
import com.android.settings.ResetNetwork;
import com.android.settings.Utils;
-import com.android.settingslib.RestrictedLockUtils;
public class NetworkResetActionMenuController {
private static final int MENU_NETWORK_RESET = Menu.FIRST + 200;
private final Context mContext;
+ private final NetworkResetRestrictionChecker mRestrictionChecker;
public NetworkResetActionMenuController(Context context) {
mContext = context;
+ mRestrictionChecker = new NetworkResetRestrictionChecker(context);
}
public void buildMenuItem(Menu menu) {
@@ -53,14 +51,8 @@
}
}
- @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+
boolean isAvailable() {
- return isAvailable(mContext);
+ return !mRestrictionChecker.hasRestriction();
}
-
- static boolean isAvailable(Context context) {
- return !RestrictedLockUtils.hasBaseUserRestriction(context,
- UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId());
- }
-
}
diff --git a/src/com/android/settings/network/NetworkResetPreferenceController.java b/src/com/android/settings/network/NetworkResetPreferenceController.java
index 04573c9..ce36a7f 100644
--- a/src/com/android/settings/network/NetworkResetPreferenceController.java
+++ b/src/com/android/settings/network/NetworkResetPreferenceController.java
@@ -22,13 +22,16 @@
public class NetworkResetPreferenceController extends PreferenceController {
+ private final NetworkResetRestrictionChecker mRestrictionChecker;
+
public NetworkResetPreferenceController(Context context) {
super(context);
+ mRestrictionChecker = new NetworkResetRestrictionChecker(context);
}
@Override
public boolean isAvailable() {
- return NetworkResetActionMenuController.isAvailable(mContext);
+ return !mRestrictionChecker.hasRestriction();
}
@Override
diff --git a/src/com/android/settings/network/NetworkResetRestrictionChecker.java b/src/com/android/settings/network/NetworkResetRestrictionChecker.java
new file mode 100644
index 0000000..4fe9f59
--- /dev/null
+++ b/src/com/android/settings/network/NetworkResetRestrictionChecker.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settingslib.RestrictedLockUtils;
+
+public class NetworkResetRestrictionChecker {
+
+ private final Context mContext;
+ private final UserManager mUserManager;
+
+ public NetworkResetRestrictionChecker(Context context) {
+ mContext = context;
+ mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ }
+
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ boolean hasUserBaseRestriction() {
+ return RestrictedLockUtils.hasBaseUserRestriction(mContext,
+ UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId());
+ }
+
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ boolean isRestrictionEnforcedByAdmin() {
+ return RestrictedLockUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId()) != null;
+ }
+
+ boolean hasRestriction() {
+ return !mUserManager.isAdminUser()
+ || hasUserBaseRestriction()
+ || isRestrictionEnforcedByAdmin();
+ }
+}
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index e359da6..bcf9c3f 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -16,6 +16,7 @@
package com.android.settings.notification;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
@@ -49,7 +50,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import java.util.Objects;
/** These settings are per app, so should not be returned in global search results. */
public class AppNotificationSettings extends NotificationSettingsBase {
@@ -57,9 +57,13 @@
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private static final String KEY_BLOCK = "block";
+ private static final String KEY_IMPORTANCE = "allow_sound";
private List<NotificationChannelGroup> mChannelGroupList;
private List<PreferenceCategory> mChannelGroups = new ArrayList();
+ private RestrictedSwitchPreference mImportanceToggle;
+
+ private boolean mShowLegacyChannelConfig = false;
@Override
public int getMetricsCategory() {
@@ -109,8 +113,9 @@
}
}.execute();
- final Preference pref = FeatureFactory.getFactory(getActivity())
- .getApplicationFeatureProvider(getActivity())
+ final Activity activity = getActivity();
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
.newAppHeaderController(this /* fragment */, null /* appHeader */)
.setIcon(mAppRow.icon)
.setLabel(mAppRow.label)
@@ -118,7 +123,7 @@
.setUid(mAppRow.uid)
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
@@ -139,6 +144,15 @@
empty.setTitle(R.string.no_channels);
empty.setEnabled(false);
groupCategory.addPreference(empty);
+
+ } else if (mChannelGroupList.size() == 1 &&
+ mChannelGroupList.get(0).getChannels().get(0).getId()
+ .equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
+ // Legacy app using only default channel. Hoist default channel settings to main panel.
+ mShowLegacyChannelConfig = true;
+ mChannel = mChannelGroupList.get(0).getChannels().get(0);
+ populateDefaultChannelPrefs();
+
} else {
for (NotificationChannelGroup group : mChannelGroupList) {
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
@@ -159,39 +173,7 @@
int N = channels.size();
for (int i = 0; i < N; i++) {
final NotificationChannel channel = channels.get(i);
- MasterSwitchPreference channelPref = new MasterSwitchPreference(
- getPrefContext());
- channelPref.setDisabledByAdmin(mSuspendedAppsAdmin);
- channelPref.setKey(channel.getId());
- channelPref.setTitle(channel.getName());
- channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
- channelPref.setSummary(getImportanceSummary(channel.getImportance()));
- Bundle channelArgs = new Bundle();
- channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
- channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
- channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
- channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
- Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
- ChannelNotificationSettings.class.getName(),
- channelArgs, null, 0, null, false, getMetricsCategory());
- channelPref.setIntent(channelIntent);
-
- channelPref.setOnPreferenceChangeListener(
- new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference,
- Object o) {
- boolean value = (Boolean) o;
- int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
- channel.setImportance(importance);
- channel.lockFields(
- NotificationChannel.USER_LOCKED_IMPORTANCE);
- mBackend.updateChannel(mPkg, mUid, channel);
-
- return true;
- }
- });
- groupCategory.addPreference(channelPref);
+ populateSingleChannelPrefs(groupCategory, channel);
}
}
@@ -215,6 +197,74 @@
updateDependents(mAppRow.banned);
}
+ private void populateSingleChannelPrefs(PreferenceCategory groupCategory,
+ final NotificationChannel channel) {
+ MasterSwitchPreference channelPref = new MasterSwitchPreference(
+ getPrefContext());
+ channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && !mAppRow.systemApp);
+ channelPref.setKey(channel.getId());
+ channelPref.setTitle(channel.getName());
+ channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
+ channelPref.setSummary(getImportanceSummary(channel.getImportance()));
+ Bundle channelArgs = new Bundle();
+ channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
+ channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
+ channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
+ channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
+ Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
+ ChannelNotificationSettings.class.getName(),
+ channelArgs, null, 0, null, false, getMetricsCategory());
+ channelPref.setIntent(channelIntent);
+
+ channelPref.setOnPreferenceChangeListener(
+ new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference,
+ Object o) {
+ boolean value = (Boolean) o;
+ int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
+ channel.setImportance(importance);
+ channel.lockFields(
+ NotificationChannel.USER_LOCKED_IMPORTANCE);
+ mBackend.updateChannel(mPkg, mUid, channel);
+
+ return true;
+ }
+ });
+ groupCategory.addPreference(channelPref);
+ }
+
+ private void populateDefaultChannelPrefs() {
+ addPreferencesFromResource(R.xml.legacy_channel_notification_settings);
+ mPriority =
+ (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
+ mVisibilityOverride =
+ (RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
+ mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_IMPORTANCE);
+
+ if (mPkgInfo != null && mChannel != null) {
+ setupPriorityPref(mChannel.canBypassDnd());
+ setupVisOverridePref(mChannel.getLockscreenVisibility());
+ setupImportanceToggle();
+ }
+ }
+
+ private void setupImportanceToggle() {
+ mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin);
+ mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT);
+ mImportanceToggle.setOnPreferenceChangeListener(
+ new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final int importance = ((Boolean) newValue ? IMPORTANCE_DEFAULT : IMPORTANCE_LOW);
+ mChannel.setImportance(importance);
+ mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
+ mBackend.updateChannel(mPkg, mUid, mChannel);
+ return true;
+ }
+ });
+ }
+
private void setupBadge() {
mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
mBadge.setChecked(mAppRow.showBadge);
@@ -254,6 +304,11 @@
setVisible(category, !banned);
}
setVisible(mBadge, !banned);
+ if (mShowLegacyChannelConfig) {
+ setVisible(mImportanceToggle, !banned);
+ setVisible(mPriority, !banned);
+ setVisible(mVisibilityOverride, !banned);
+ }
if (mAppRow.systemApp && !mAppRow.banned) {
setVisible(mBlock, false);
}
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index b24e92c..f6a7b42 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -22,17 +22,13 @@
import static android.app.NotificationManager.IMPORTANCE_NONE;
import android.app.Activity;
-import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
-import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.net.Uri;
-import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
-import android.service.notification.NotificationListenerService.Ranking;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -45,7 +41,6 @@
import com.android.settings.RingtonePreference;
import com.android.settings.applications.AppHeaderController;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import java.util.ArrayList;
@@ -54,19 +49,13 @@
public class ChannelNotificationSettings extends NotificationSettingsBase {
private static final String TAG = "ChannelSettings";
- protected static final String KEY_BYPASS_DND = "bypass_dnd";
- protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
- protected static final String KEY_IMPORTANCE = "importance";
protected static final String KEY_LIGHTS = "lights";
protected static final String KEY_VIBRATE = "vibrate";
protected static final String KEY_RINGTONE = "ringtone";
protected RestrictedSwitchPreference mLights;
protected RestrictedSwitchPreference mVibrate;
- protected DefaultNotificationTonePreference mRingtone;
- protected RestrictedDropDownPreference mImportance;
- protected RestrictedSwitchPreference mPriority;
- protected RestrictedDropDownPreference mVisibilityOverride;
+ protected NotificationSoundPreference mRingtone;
@Override
public int getMetricsCategory() {
@@ -102,7 +91,7 @@
(RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
mLights = (RestrictedSwitchPreference) findPreference(KEY_LIGHTS);
mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
- mRingtone = (DefaultNotificationTonePreference) findPreference(KEY_RINGTONE);
+ mRingtone = (NotificationSoundPreference) findPreference(KEY_RINGTONE);
if (mPkgInfo != null && mChannel != null) {
setupPriorityPref(mChannel.canBypassDnd());
@@ -113,8 +102,9 @@
setupBlockAndImportance();
updateDependents();
}
- final Preference pref = FeatureFactory.getFactory(getActivity())
- .getApplicationFeatureProvider(getActivity())
+ final Activity activity = getActivity();
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
.newAppHeaderController(this /* fragment */, null /* appHeader */)
.setIcon(mAppRow.icon)
.setLabel(mChannel.getName())
@@ -123,7 +113,7 @@
.setUid(mAppRow.uid)
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
- .done(getPrefContext());
+ .done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
if (mAppRow.settingsIntent != null) {
@@ -177,9 +167,7 @@
mRingtone.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- Uri ringtone = Uri.parse((String) newValue);
- mRingtone.setRingtone(ringtone);
- mChannel.setSound(ringtone, mChannel.getAudioAttributes());
+ mChannel.setSound((Uri) newValue, mChannel.getAudioAttributes());
mChannel.lockFields(NotificationChannel.USER_LOCKED_SOUND);
mBackend.updateChannel(mPkg, mUid, mChannel);
return false;
@@ -226,7 +214,7 @@
final int numImportances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1;
List<String> summaries = new ArrayList<>();
List<String> values = new ArrayList<>();
- ;
+
for (int i = 0; i < numImportances; i++) {
int importance = i + 1;
summaries.add(getImportanceSummary(importance));
@@ -240,7 +228,7 @@
mImportance.setEntryValues(values.toArray(new String[0]));
mImportance.setEntries(summaries.toArray(new String[0]));
mImportance.setValue(String.valueOf(mChannel.getImportance()));
- mImportance.setSummary("%s");
+ mImportance.setSummary(getImportanceSummary(mChannel.getImportance()));
if (mAppRow.lockedImportance) {
mImportance.setEnabled(false);
} else {
@@ -258,105 +246,6 @@
}
}
- protected void setupPriorityPref(boolean priority) {
- mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
- mPriority.setChecked(priority);
- mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean bypassZenMode = (Boolean) newValue;
- mChannel.setBypassDnd(bypassZenMode);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return true;
- }
- });
- }
-
- protected void setupVisOverridePref(int sensitive) {
- ArrayList<CharSequence> entries = new ArrayList<>();
- ArrayList<CharSequence> values = new ArrayList<>();
-
- mVisibilityOverride.clearRestrictedItems();
- if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
- final String summaryShowEntry =
- getString(R.string.lock_screen_notifications_summary_show);
- final String summaryShowEntryValue =
- Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE);
- entries.add(summaryShowEntry);
- values.add(summaryShowEntryValue);
- setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue,
- DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS
- | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
- }
-
- final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
- final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE);
- entries.add(summaryHideEntry);
- values.add(summaryHideEntryValue);
- setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue,
- DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
- entries.add(getString(R.string.lock_screen_notifications_summary_disable));
- values.add(Integer.toString(Notification.VISIBILITY_SECRET));
- mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()]));
- mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()]));
-
- if (sensitive == Ranking.VISIBILITY_NO_OVERRIDE) {
- mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility()));
- } else {
- mVisibilityOverride.setValue(Integer.toString(sensitive));
- }
- mVisibilityOverride.setSummary("%s");
-
- mVisibilityOverride.setOnPreferenceChangeListener(
- new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- int sensitive = Integer.parseInt((String) newValue);
- if (sensitive == getGlobalVisibility()) {
- sensitive = Ranking.VISIBILITY_NO_OVERRIDE;
- }
- mChannel.setLockscreenVisibility(sensitive);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return true;
- }
- });
- mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
- }
-
- private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
- CharSequence entryValue, int keyguardNotificationFeatures) {
- RestrictedLockUtils.EnforcedAdmin admin =
- RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
- mContext, keyguardNotificationFeatures, mUserId);
- if (admin != null) {
- RestrictedDropDownPreference.RestrictedItem item =
- new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
- mVisibilityOverride.addRestrictedItem(item);
- }
- }
-
- private int getGlobalVisibility() {
- int globalVis = Ranking.VISIBILITY_NO_OVERRIDE;
- if (!getLockscreenNotificationsEnabled()) {
- globalVis = Notification.VISIBILITY_SECRET;
- } else if (!getLockscreenAllowPrivateNotifications()) {
- globalVis = Notification.VISIBILITY_PRIVATE;
- }
- return globalVis;
- }
-
- private boolean getLockscreenNotificationsEnabled() {
- return Settings.Secure.getInt(getContentResolver(),
- Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
- }
-
- private boolean getLockscreenAllowPrivateNotifications() {
- return Settings.Secure.getInt(getContentResolver(),
- Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
- }
-
private boolean isLockScreenSecure() {
LockPatternUtils utils = new LockPatternUtils(getActivity());
boolean lockscreenSecure = utils.isSecure(UserHandle.myUserId());
diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
new file mode 100644
index 0000000..a78fed7
--- /dev/null
+++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package com.android.settings.notification;
+
+import static com.android.internal.notification.NotificationAccessConfirmationActivityContract
+ .EXTRA_COMPONENT_NAME;
+import static com.android.internal.notification.NotificationAccessConfirmationActivityContract
+ .EXTRA_PACKAGE_TITLE;
+import static com.android.internal.notification.NotificationAccessConfirmationActivityContract
+ .EXTRA_USER_ID;
+
+import android.Manifest;
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.DialogInterface;
+import android.content.pm.PackageManager;
+import android.content.pm.ServiceInfo;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.provider.SettingsStringUtil;
+import android.util.Slog;
+import android.view.accessibility.AccessibilityEvent;
+
+import com.android.internal.app.AlertActivity;
+import com.android.internal.app.AlertController;
+import com.android.settings.R;
+import com.android.settings.core.TouchOverlayManager;
+
+/** @hide */
+public class NotificationAccessConfirmationActivity extends Activity
+ implements DialogInterface {
+
+ private static final boolean DEBUG = false;
+ private static final String LOG_TAG = "NotificationAccessConfirmationActivity";
+
+ private int mUserId;
+ private ComponentName mComponentName;
+ private TouchOverlayManager mTouchOverlayManager;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mTouchOverlayManager = new TouchOverlayManager(this);
+
+ mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
+ mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
+ String pkgTitle = getIntent().getStringExtra(EXTRA_PACKAGE_TITLE);
+
+ AlertController.AlertParams p = new AlertController.AlertParams(this);
+ p.mTitle = getString(
+ R.string.notification_listener_security_warning_title,
+ pkgTitle);
+ p.mMessage = getString(
+ R.string.notification_listener_security_warning_summary,
+ pkgTitle);
+ p.mPositiveButtonText = getString(R.string.allow);
+ p.mPositiveButtonListener = (a, b) -> onAllow();
+ p.mNegativeButtonText = getString(R.string.deny);
+ p.mNegativeButtonListener = (a, b) -> cancel();
+ AlertController
+ .create(this, this, getWindow())
+ .installContent(p);
+ }
+
+ private void onAllow() {
+ String requiredPermission = Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE;
+ try {
+ ServiceInfo serviceInfo = getPackageManager().getServiceInfo(mComponentName, 0);
+ if (!requiredPermission.equals(serviceInfo.permission)) {
+ Slog.e(LOG_TAG,
+ "Service " + mComponentName + " lacks permission " + requiredPermission);
+ return;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ Slog.e(LOG_TAG, "Failed to get service info for " + mComponentName, e);
+ return;
+ }
+
+ final SettingsStringUtil.SettingStringHelper setting =
+ new SettingsStringUtil.SettingStringHelper(
+ getContentResolver(),
+ Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
+ mUserId);
+ setting.write(SettingsStringUtil.ComponentNameSet.add(setting.read(), mComponentName));
+
+ finish();
+ }
+
+ @Override
+ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ return AlertActivity.dispatchPopulateAccessibilityEvent(this, event);
+ }
+
+ @Override
+ public void cancel() {
+ finish();
+ }
+
+ @Override
+ public void dismiss() {
+ // This is called after the click, since we finish when handling the
+ // click, don't do that again here.
+ if (!isFinishing()) {
+ finish();
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mTouchOverlayManager.setOverlayAllowed(false);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mTouchOverlayManager.setOverlayAllowed(true);
+ }
+}
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index c1ef018..6226eac 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -18,7 +18,6 @@
import android.app.INotificationManager;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
-import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -28,6 +27,7 @@
import android.graphics.drawable.Drawable;
import android.os.ServiceManager;
import android.os.UserHandle;
+import android.util.IconDrawableFactory;
import android.util.Log;
import com.android.settingslib.Utils;
@@ -48,7 +48,7 @@
Log.e(TAG, "Error loading application label for " + row.pkg, t);
row.label = row.pkg;
}
- row.icon = app.loadIcon(pm);
+ row.icon = IconDrawableFactory.newInstance(context).getBadgedIcon(app);
row.banned = getNotificationsBanned(row.pkg, row.uid);
row.showBadge = canShowBadge(row.pkg, row.uid);
row.userId = UserHandle.getUserId(row.uid);
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 960c3b8..ff0a512 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -18,15 +18,14 @@
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import android.app.Notification;
import android.app.NotificationChannel;
-import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
+import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -39,6 +38,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
+import android.service.notification.NotificationListenerService;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -47,6 +47,7 @@
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import java.util.ArrayList;
import java.util.List;
abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
@@ -59,6 +60,9 @@
protected static final String KEY_BLOCK = "block";
protected static final String KEY_BADGE = "badge";
+ protected static final String KEY_BYPASS_DND = "bypass_dnd";
+ protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
+ protected static final String KEY_IMPORTANCE = "importance";
protected PackageManager mPm;
protected UserManager mUm;
@@ -71,6 +75,10 @@
protected PackageInfo mPkgInfo;
protected RestrictedSwitchPreference mBlock;
protected RestrictedSwitchPreference mBadge;
+ protected RestrictedDropDownPreference mImportance;
+ protected RestrictedSwitchPreference mPriority;
+ protected RestrictedDropDownPreference mVisibilityOverride;
+
protected EnforcedAdmin mSuspendedAppsAdmin;
protected boolean mDndVisualEffectsSuppressed;
@@ -249,4 +257,105 @@
return getContext().getString(R.string.notification_importance_high);
}
}
+
+ protected void setupPriorityPref(boolean priority) {
+ mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
+ mPriority.setChecked(priority);
+ mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean bypassZenMode = (Boolean) newValue;
+ mChannel.setBypassDnd(bypassZenMode);
+ mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
+ mBackend.updateChannel(mPkg, mUid, mChannel);
+ return true;
+ }
+ });
+ }
+
+ protected void setupVisOverridePref(int sensitive) {
+ ArrayList<CharSequence> entries = new ArrayList<>();
+ ArrayList<CharSequence> values = new ArrayList<>();
+
+ mVisibilityOverride.clearRestrictedItems();
+ if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
+ final String summaryShowEntry =
+ getString(R.string.lock_screen_notifications_summary_show);
+ final String summaryShowEntryValue =
+ Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE);
+ entries.add(summaryShowEntry);
+ values.add(summaryShowEntryValue);
+ setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue,
+ DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS
+ | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
+ }
+
+ final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
+ final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE);
+ entries.add(summaryHideEntry);
+ values.add(summaryHideEntryValue);
+ setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue,
+ DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
+ entries.add(getString(R.string.lock_screen_notifications_summary_disable));
+ values.add(Integer.toString(Notification.VISIBILITY_SECRET));
+ mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()]));
+ mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()]));
+
+ if (sensitive == NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE) {
+ mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility()));
+ } else {
+ mVisibilityOverride.setValue(Integer.toString(sensitive));
+ }
+ mVisibilityOverride.setSummary("%s");
+
+ mVisibilityOverride.setOnPreferenceChangeListener(
+ new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ int sensitive = Integer.parseInt((String) newValue);
+ if (sensitive == getGlobalVisibility()) {
+ sensitive = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
+ }
+ mChannel.setLockscreenVisibility(sensitive);
+ mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
+ mBackend.updateChannel(mPkg, mUid, mChannel);
+ return true;
+ }
+ });
+ mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
+ }
+
+
+ private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
+ CharSequence entryValue, int keyguardNotificationFeatures) {
+ RestrictedLockUtils.EnforcedAdmin admin =
+ RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
+ mContext, keyguardNotificationFeatures, mUserId);
+ if (admin != null) {
+ RestrictedDropDownPreference.RestrictedItem item =
+ new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
+ mVisibilityOverride.addRestrictedItem(item);
+ }
+ }
+
+ private int getGlobalVisibility() {
+ int globalVis = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
+ if (!getLockscreenNotificationsEnabled()) {
+ globalVis = Notification.VISIBILITY_SECRET;
+ } else if (!getLockscreenAllowPrivateNotifications()) {
+ globalVis = Notification.VISIBILITY_PRIVATE;
+ }
+ return globalVis;
+ }
+
+
+ private boolean getLockscreenNotificationsEnabled() {
+ return Settings.Secure.getInt(getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
+ }
+
+ private boolean getLockscreenAllowPrivateNotifications() {
+ return Settings.Secure.getInt(getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
+ }
}
diff --git a/src/com/android/settings/notification/NotificationSoundPreference.java b/src/com/android/settings/notification/NotificationSoundPreference.java
new file mode 100644
index 0000000..c007485
--- /dev/null
+++ b/src/com/android/settings/notification/NotificationSoundPreference.java
@@ -0,0 +1,67 @@
+package com.android.settings.notification;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.util.AttributeSet;
+
+import com.android.settings.R;
+import com.android.settings.RingtonePreference;
+
+public class NotificationSoundPreference extends RingtonePreference {
+ private Uri mRingtone;
+
+ public NotificationSoundPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ protected Uri onRestoreRingtone() {
+ return mRingtone;
+ }
+
+ public void setRingtone(Uri ringtone) {
+ mRingtone = ringtone;
+ setSummary("\u00A0");
+ updateRingtoneName(mRingtone);
+ }
+
+ @Override
+ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (data != null) {
+ Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
+ setRingtone(uri);
+ callChangeListener(uri);
+ }
+
+ return true;
+ }
+
+ private void updateRingtoneName(final Uri uri) {
+ AsyncTask ringtoneNameTask = new AsyncTask<Object, Void, CharSequence>() {
+ @Override
+ protected CharSequence doInBackground(Object... params) {
+ if (uri == null) {
+ return getContext().getString(com.android.internal.R.string.ringtone_silent);
+ } else if (RingtoneManager.isDefault(uri)) {
+ return getContext().getString(R.string.notification_sound_default);
+ } else if(ContentResolver.SCHEME_ANDROID_RESOURCE.equals(uri.getScheme())) {
+ return getContext().getString(R.string.notification_unknown_sound_title);
+ } else {
+ return Ringtone.getTitle(getContext(), uri, false /* followSettingsUri */,
+ true /* allowRemote */);
+ }
+ }
+
+ @Override
+ protected void onPostExecute(CharSequence name) {
+ setSummary(name);
+ }
+ };
+ ringtoneNameTask.execute();
+ }
+}
diff --git a/src/com/android/settings/notification/RedactionInterstitial.java b/src/com/android/settings/notification/RedactionInterstitial.java
index 08474a0..b269062 100644
--- a/src/com/android/settings/notification/RedactionInterstitial.java
+++ b/src/com/android/settings/notification/RedactionInterstitial.java
@@ -16,7 +16,11 @@
package com.android.settings.notification;
-import android.app.admin.DevicePolicyManager;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
+
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -26,7 +30,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
-import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
@@ -34,18 +37,13 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.RestrictedCheckBox;
import com.android.settings.RestrictedRadioButton;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.SetupRedactionInterstitial;
import com.android.settings.Utils;
import com.android.settingslib.RestrictedLockUtils;
-import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
-import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
-
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
public class RedactionInterstitial extends SettingsActivity {
@Override
@@ -128,6 +126,7 @@
@Override
public void onClick(View v) {
if (v.getId() == R.id.redaction_done_button) {
+ SetupRedactionInterstitial.setEnabled(getContext(), false);
final RedactionInterstitial activity = (RedactionInterstitial) getActivity();
if (activity != null) {
activity.setResult(RESULT_OK, null);
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index 79a8970..552c4d3 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -22,6 +22,7 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
+import android.os.UserHandle;
import android.preference.SeekBarVolumizer;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.Preference;
@@ -85,7 +86,11 @@
if (preference instanceof RingtonePreference) {
mRequestPreference = (RingtonePreference) preference;
mRequestPreference.onPrepareRingtonePickerIntent(mRequestPreference.getIntent());
- startActivityForResult(preference.getIntent(), REQUEST_CODE);
+ startActivityForResultAsUser(
+ mRequestPreference.getIntent(),
+ REQUEST_CODE,
+ null,
+ UserHandle.of(mRequestPreference.getUserId()));
return true;
}
return super.onPreferenceTreeClick(preference);
diff --git a/src/com/android/settings/search2/CursorToSearchResultConverter.java b/src/com/android/settings/search2/CursorToSearchResultConverter.java
index 71d999e..706f33b 100644
--- a/src/com/android/settings/search2/CursorToSearchResultConverter.java
+++ b/src/com/android/settings/search2/CursorToSearchResultConverter.java
@@ -17,21 +17,15 @@
package com.android.settings.search2;
-import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.BadParcelableException;
-import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.SettingsActivity;
-import com.android.settings.Utils;
import com.android.settings.dashboard.SiteMapManager;
import java.util.ArrayList;
@@ -46,9 +40,6 @@
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_CLASS_NAME;
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ICON;
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ID;
-import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_INTENT_ACTION;
-import static com.android.settings.search2.DatabaseResultLoader
- .COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS;
import static com.android.settings.search2.DatabaseResultLoader
.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_KEY;
@@ -132,7 +123,6 @@
mKeys.add(docId);
final String pkgName = cursor.getString(COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
- final String action = cursor.getString(COLUMN_INDEX_INTENT_ACTION);
final String title = cursor.getString(COLUMN_INDEX_TITLE);
final String summaryOn = cursor.getString(COLUMN_INDEX_SUMMARY_ON);
final String className = cursor.getString(COLUMN_INDEX_CLASS_NAME);
@@ -140,16 +130,7 @@
final String iconResStr = cursor.getString(COLUMN_INDEX_ICON);
final int payloadType = cursor.getInt(COLUMN_INDEX_PAYLOAD_TYPE);
final byte[] marshalledPayload = cursor.getBlob(COLUMN_INDEX_PAYLOAD);
- final ResultPayload payload;
-
- if (marshalledPayload != null) {
- payload = getUnmarshalledPayload(marshalledPayload, payloadType);
- } else if (payloadType == ResultPayload.PayloadType.INTENT) {
- payload = getIntentPayload(cursor, action, key, className, pkgName);
- } else {
- Log.w(TAG, "Error creating payload - bad marshalling data or mismatched types");
- return null;
- }
+ final ResultPayload payload = getUnmarshalledPayload(marshalledPayload, payloadType);
final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor);
final int rank = getRank(title, breadcrumbs, baseRank, key);
@@ -196,34 +177,12 @@
return icon;
}
- private IntentPayload getIntentPayload(Cursor cursor, String action, String key,
- String className, String pkgName ) {
- IntentPayload payload;
- if (TextUtils.isEmpty(action)) {
- final String screenTitle = cursor.getString(COLUMN_INDEX_SCREEN_TITLE);
- // Action is null, we will launch it as a sub-setting
- final Bundle args = new Bundle();
- args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
- final Intent intent = Utils.onBuildStartFragmentIntent(mContext,
- className, args, null, 0, screenTitle, false,
- MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
- payload = new IntentPayload(intent);
- } else {
- final Intent intent = new Intent(action);
- final String targetClass = cursor.getString(COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS);
- if (!TextUtils.isEmpty(pkgName) && !TextUtils.isEmpty(targetClass)) {
- final ComponentName component = new ComponentName(pkgName, targetClass);
- intent.setComponent(component);
- }
- intent.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
- payload = new IntentPayload(intent);
- }
- return payload;
- }
-
private ResultPayload getUnmarshalledPayload(byte[] unmarshalledPayload, int payloadType) {
try {
switch (payloadType) {
+ case ResultPayload.PayloadType.INTENT:
+ return ResultPayloadUtils.unmarshall(unmarshalledPayload,
+ ResultPayload.CREATOR);
case ResultPayload.PayloadType.INLINE_SWITCH:
return ResultPayloadUtils.unmarshall(unmarshalledPayload,
InlineSwitchPayload.CREATOR);
@@ -269,5 +228,4 @@
}
return baseRank;
}
-
}
diff --git a/src/com/android/settings/search2/DatabaseIndexingManager.java b/src/com/android/settings/search2/DatabaseIndexingManager.java
index 533884d..c2e6ba8 100644
--- a/src/com/android/settings/search2/DatabaseIndexingManager.java
+++ b/src/com/android/settings/search2/DatabaseIndexingManager.java
@@ -17,6 +17,7 @@
package com.android.settings.search2;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -39,6 +40,7 @@
import android.util.Log;
import android.util.Xml;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.PreferenceController;
import com.android.settings.search.IndexDatabaseHelper;
import com.android.settings.search.Indexable;
@@ -515,7 +517,7 @@
if (count > 0) {
while (cursor.moveToNext()) {
final int providerRank = cursor.getInt(COLUMN_INDEX_XML_RES_RANK);
-
+ // TODO remove provider rank
final int xmlResId = cursor.getInt(COLUMN_INDEX_XML_RES_RESID);
final String className = cursor.getString(COLUMN_INDEX_XML_RES_CLASS_NAME);
@@ -560,7 +562,7 @@
if (count > 0) {
while (cursor.moveToNext()) {
final int providerRank = cursor.getInt(COLUMN_INDEX_RAW_RANK);
-
+ // TODO Remove rank
final String title = cursor.getString(COLUMN_INDEX_RAW_TITLE);
final String summaryOn = cursor.getString(COLUMN_INDEX_RAW_SUMMARY_ON);
final String summaryOff = cursor.getString(COLUMN_INDEX_RAW_SUMMARY_OFF);
@@ -927,7 +929,7 @@
.setNormalizedSummaryOff(normalizedSummaryOff)
.setSpaceDelimitedKeywords(spaceDelimitedKeywords);
- updateOneRow(database, builder.build());
+ updateOneRow(database, builder.build(mContext));
}
private void updateOneRow(SQLiteDatabase database, DatabaseRow row) {
@@ -1212,7 +1214,45 @@
return this;
}
- public DatabaseRow build() {
+ /**
+ * Adds intent to inline payloads, or creates an Intent Payload as a fallback if the
+ * payload is null.
+ */
+ private void setIntent(Context context) {
+ if (mPayload != null) {
+ return;
+ }
+ final Intent intent = buildIntent(context);
+ mPayload = new ResultPayload(intent);
+ mPayloadType = ResultPayload.PayloadType.INTENT;
+ }
+
+ /**
+ * Adds Intent payload to builder.
+ */
+ private Intent buildIntent(Context context) {
+ final Intent intent;
+
+ if (TextUtils.isEmpty(mIntentAction)) {
+ // Action is null, we will launch it as a sub-setting
+ intent = DatabaseIndexingUtils.buildSubsettingIntent(context, mClassName, mKey,
+ mScreenTitle);
+ } else {
+ intent = new Intent(mIntentAction);
+ final String targetClass = mIntentTargetClass;
+ if (!TextUtils.isEmpty(mIntentTargetPackage)
+ && !TextUtils.isEmpty(targetClass)) {
+ final ComponentName component = new ComponentName(mIntentTargetPackage,
+ targetClass);
+ intent.setComponent(component);
+ }
+ intent.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mKey);
+ }
+ return intent;
+ }
+
+ public DatabaseRow build(Context context) {
+ setIntent(context);
return new DatabaseRow(this);
}
}
diff --git a/src/com/android/settings/search2/DatabaseIndexingUtils.java b/src/com/android/settings/search2/DatabaseIndexingUtils.java
index bd06ef3..b93fa10 100644
--- a/src/com/android/settings/search2/DatabaseIndexingUtils.java
+++ b/src/com/android/settings/search2/DatabaseIndexingUtils.java
@@ -19,15 +19,20 @@
import android.Manifest;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
+import android.os.Bundle;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.SettingsActivity;
+import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
import com.android.settings.search.Indexable;
@@ -58,6 +63,18 @@
= Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
/**
+ * Builds intent into a subsetting.
+ */
+ public static Intent buildSubsettingIntent(Context context, String className, String key,
+ String screenTitle) {
+ final Bundle args = new Bundle();
+ args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
+ return Utils.onBuildStartFragmentIntent(context,
+ className, args, null, 0, screenTitle, false,
+ MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
+ }
+
+ /**
* @param className which wil provide the map between from {@link Uri}s to
* {@link PreferenceController}
* @param context
diff --git a/src/com/android/settings/search2/InlinePayload.java b/src/com/android/settings/search2/InlinePayload.java
index 4b1c168..9b1dadd 100644
--- a/src/com/android/settings/search2/InlinePayload.java
+++ b/src/com/android/settings/search2/InlinePayload.java
@@ -16,6 +16,8 @@
package com.android.settings.search2;
+import android.content.Intent;
+
/**
* Abstract Payload for inline settings results.
*/
@@ -35,7 +37,9 @@
*/
@SettingsSource public int settingSource;
- public InlinePayload(String uri, @PayloadType int type, @SettingsSource int source) {
+ public InlinePayload(String uri, @PayloadType int type, @SettingsSource int source,
+ Intent intent) {
+ super(intent);
settingsUri = uri;
inlineType = type;
settingSource = source;
diff --git a/src/com/android/settings/search2/InlineSwitchPayload.java b/src/com/android/settings/search2/InlineSwitchPayload.java
index b009976..b223ce8 100644
--- a/src/com/android/settings/search2/InlineSwitchPayload.java
+++ b/src/com/android/settings/search2/InlineSwitchPayload.java
@@ -18,6 +18,7 @@
package com.android.settings.search2;
import android.content.Context;
+import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.Settings;
@@ -38,14 +39,15 @@
public final Map<Integer, Boolean> valueMap;
public InlineSwitchPayload(String newUri, @SettingsSource int settingsSource,
- Map<Integer, Boolean> map) {
- super(newUri, PayloadType.INLINE_SWITCH, settingsSource);
+ Map<Integer, Boolean> map, Intent intent) {
+ super(newUri, PayloadType.INLINE_SWITCH, settingsSource, intent);
valueMap = map;
}
private InlineSwitchPayload(Parcel in) {
super(in.readString() /* Uri */ , in.readInt() /* Payload Type */,
- in.readInt() /* Settings Source */);
+ in.readInt() /* Settings Source */,
+ (Intent) in.readParcelable(Intent.class.getClassLoader()) /* Intent */);
valueMap = in.readHashMap(Integer.class.getClassLoader());
}
@@ -64,6 +66,7 @@
dest.writeString(settingsUri);
dest.writeInt(inlineType);
dest.writeInt(settingSource);
+ dest.writeParcelable(mIntent, flags);
dest.writeMap(valueMap);
}
diff --git a/src/com/android/settings/search2/InstalledAppResultLoader.java b/src/com/android/settings/search2/InstalledAppResultLoader.java
index 47e1f67..978693c 100644
--- a/src/com/android/settings/search2/InstalledAppResultLoader.java
+++ b/src/com/android/settings/search2/InstalledAppResultLoader.java
@@ -34,7 +34,6 @@
import com.android.settings.applications.ManageApplications;
import com.android.settings.applications.PackageManagerWrapper;
import com.android.settings.dashboard.SiteMapManager;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.utils.AsyncLoader;
import java.util.ArrayList;
@@ -98,7 +97,7 @@
.addTitle(info.loadLabel(pm))
.addRank(getRank(wordDiff))
.addBreadcrumbs(getBreadCrumb())
- .addPayload(new IntentPayload(intent));
+ .addPayload(new ResultPayload(intent));
results.add(builder.build());
}
}
diff --git a/src/com/android/settings/search2/IntentPayload.java b/src/com/android/settings/search2/IntentPayload.java
deleted file mode 100644
index 3e1049e..0000000
--- a/src/com/android/settings/search2/IntentPayload.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2016 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.search2;
-
-import android.content.Intent;
-import android.os.Parcel;
-
-/**
- * Encapsulates the standard intent based results as seen in first party apps and Settings results.
- */
-public class IntentPayload extends ResultPayload {
- public final Intent intent;
-
- private IntentPayload(Parcel in) {
- intent = in.readParcelable(IntentPayload.class.getClassLoader());
- }
-
- public IntentPayload(Intent newIntent) {
- intent = newIntent;
- }
-
- @ResultPayload.PayloadType public int getType() {
- return PayloadType.INTENT;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeParcelable(intent, flags);
- }
-
- public static final Creator<IntentPayload> CREATOR = new Creator<IntentPayload>() {
- @Override
- public IntentPayload createFromParcel(Parcel in) {
- return new IntentPayload(in);
- }
-
- @Override
- public IntentPayload[] newArray(int size) {
- return new IntentPayload[size];
- }
- };
-
-}
\ No newline at end of file
diff --git a/src/com/android/settings/search2/IntentSearchViewHolder.java b/src/com/android/settings/search2/IntentSearchViewHolder.java
index 0596397..e81056a 100644
--- a/src/com/android/settings/search2/IntentSearchViewHolder.java
+++ b/src/com/android/settings/search2/IntentSearchViewHolder.java
@@ -40,7 +40,7 @@
itemView.setOnClickListener(v -> {
fragment.onSearchResultClicked();
- final Intent intent = ((IntentPayload) result.payload).intent;
+ final Intent intent = result.payload.getIntent();
final ComponentName cn = intent.getComponent();
final Pair<Integer, Object> rank = Pair.create(
MetricsEvent.FIELD_SETTINGS_SERACH_RESULT_RANK, getAdapterPosition());
diff --git a/src/com/android/settings/search2/ResultPayload.java b/src/com/android/settings/search2/ResultPayload.java
index 4294234..fe4cea0 100644
--- a/src/com/android/settings/search2/ResultPayload.java
+++ b/src/com/android/settings/search2/ResultPayload.java
@@ -17,6 +17,8 @@
package com.android.settings.search2;
import android.annotation.IntDef;
+import android.content.Intent;
+import android.os.Parcel;
import android.os.Parcelable;
import java.lang.annotation.Retention;
@@ -26,14 +28,15 @@
* A interface for search results types. Examples include Inline results, third party apps
* or any future possibilities.
*/
-public abstract class ResultPayload implements Parcelable {
+public class ResultPayload implements Parcelable {
+ protected final Intent mIntent;
@IntDef({PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH,
PayloadType.INTENT, PayloadType.SAVED_QUERY})
@Retention(RetentionPolicy.SOURCE)
public @interface PayloadType {
/**
- * Resulting page will be started using an intent
+ * Resulting page will be started using an mIntent
*/
int INTENT = 0;
@@ -64,6 +67,42 @@
}
+ private ResultPayload(Parcel in) {
+ mIntent = in.readParcelable(ResultPayload.class.getClassLoader());
+ }
+
+ public ResultPayload(Intent intent) {
+ mIntent = intent;
+ }
+
@ResultPayload.PayloadType
- public abstract int getType();
+ public int getType() {
+ return PayloadType.INTENT;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeParcelable(mIntent, flags);
+ }
+
+ public static final Creator<ResultPayload> CREATOR = new Creator<ResultPayload>() {
+ @Override
+ public ResultPayload createFromParcel(Parcel in) {
+ return new ResultPayload(in);
+ }
+
+ @Override
+ public ResultPayload[] newArray(int size) {
+ return new ResultPayload[size];
+ }
+ };
+
+ public Intent getIntent() {
+ return mIntent;
+ }
}
diff --git a/src/com/android/settings/search2/SavedQueryPayload.java b/src/com/android/settings/search2/SavedQueryPayload.java
index 6316894..7e0e213 100644
--- a/src/com/android/settings/search2/SavedQueryPayload.java
+++ b/src/com/android/settings/search2/SavedQueryPayload.java
@@ -27,11 +27,13 @@
public final String query;
public SavedQueryPayload(String query) {
+ super(null /* Intent */);
this.query = query;
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
SavedQueryPayload(Parcel in) {
+ super(null /* Intent */);
query = in.readString();
}
diff --git a/src/com/android/settings/search2/SearchFragment.java b/src/com/android/settings/search2/SearchFragment.java
index a8d219c..545a225 100644
--- a/src/com/android/settings/search2/SearchFragment.java
+++ b/src/com/android/settings/search2/SearchFragment.java
@@ -168,6 +168,17 @@
}
@Override
+ public void onResume() {
+ super.onResume();
+ if (TextUtils.isEmpty(mQuery)) {
+ return;
+ }
+ final String query = mQuery;
+ mQuery = "";
+ onQueryTextChange(query);
+ }
+
+ @Override
public void onStop() {
super.onStop();
final Activity activity = getActivity();
@@ -206,7 +217,6 @@
mResultClickCount = 0;
mNeverEnteredQuery = false;
mQuery = query;
- mSearchAdapter.clearResults();
if (isEmptyQuery) {
final LoaderManager loaderManager = getLoaderManager();
@@ -251,8 +261,15 @@
if (mUnfinishedLoadersCount.decrementAndGet() != 0) {
return;
}
+
final int resultCount = mSearchAdapter.displaySearchResults(mQuery);
- mNoResultsView.setVisibility(resultCount == 0 ? View.VISIBLE : View.GONE);
+
+ if (resultCount == 0) {
+ mNoResultsView.setVisibility(View.VISIBLE);
+ } else {
+ mNoResultsView.setVisibility(View.GONE);
+ mResultsRecyclerView.scrollToPosition(0);
+ }
mSearchFeatureProvider.showFeedbackButton(this, getView());
}
diff --git a/src/com/android/settings/search2/SearchResult.java b/src/com/android/settings/search2/SearchResult.java
index 6b27d89..36fe5b3 100644
--- a/src/com/android/settings/search2/SearchResult.java
+++ b/src/com/android/settings/search2/SearchResult.java
@@ -93,7 +93,7 @@
icon = builder.mIcon;
payload = builder.mResultPayload;
viewType = payload.getType();
- stableId = Objects.hash(title, summary, breadcrumbs, rank, icon, payload, viewType);
+ stableId = Objects.hash(title, summary, breadcrumbs, rank, viewType);
}
@Override
@@ -104,6 +104,22 @@
return this.rank - searchResult.rank;
}
+ @Override
+ public boolean equals(Object that) {
+ if (this == that) {
+ return true;
+ }
+ if (!(that instanceof SearchResult)) {
+ return false;
+ }
+ return this.stableId == ((SearchResult) that).stableId;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) stableId;
+ }
+
public static class Builder {
protected CharSequence mTitle;
protected CharSequence mSummary;
@@ -127,19 +143,19 @@
return this;
}
- public Builder addRank(int rank) {
+ public Builder addRank(int rank) {
if (rank >= 0 && rank <= 9) {
mRank = rank;
}
return this;
}
- public Builder addIcon(Drawable icon) {
+ public Builder addIcon(Drawable icon) {
mIcon = icon;
return this;
}
- public Builder addPayload(ResultPayload payload) {
+ public Builder addPayload(ResultPayload payload) {
mResultPayload = payload;
return this;
}
diff --git a/src/com/android/settings/search2/SearchResultDiffCallback.java b/src/com/android/settings/search2/SearchResultDiffCallback.java
new file mode 100644
index 0000000..9bd1bde
--- /dev/null
+++ b/src/com/android/settings/search2/SearchResultDiffCallback.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.search2;
+
+import android.support.v7.util.DiffUtil;
+
+import java.util.List;
+
+/**
+ * Callback for DiffUtil to elegantly update search data when the query changes.
+ */
+public class SearchResultDiffCallback extends DiffUtil.Callback {
+
+ private List<SearchResult> mOldList;
+ private List<SearchResult> mNewList;
+
+ public SearchResultDiffCallback(List<SearchResult> oldList, List<SearchResult> newList) {
+ mOldList = oldList;
+ mNewList = newList;
+ }
+
+ @Override
+ public int getOldListSize() {
+ return mOldList.size();
+ }
+
+ @Override
+ public int getNewListSize() {
+ return mNewList.size();
+ }
+
+ @Override
+ public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
+ return mOldList.get(oldItemPosition).equals(mNewList.get(newItemPosition));
+ }
+
+ @Override
+ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
+ return mOldList.get(oldItemPosition).equals(mNewList.get(newItemPosition));
+ }
+}
diff --git a/src/com/android/settings/search2/SearchResultsAdapter.java b/src/com/android/settings/search2/SearchResultsAdapter.java
index d0ea5bf..5da5966 100644
--- a/src/com/android/settings/search2/SearchResultsAdapter.java
+++ b/src/com/android/settings/search2/SearchResultsAdapter.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.support.annotation.MainThread;
import android.support.annotation.VisibleForTesting;
+import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.util.ArrayMap;
import android.view.LayoutInflater;
@@ -37,8 +38,9 @@
public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder> {
- private final List<SearchResult> mSearchResults;
private final SearchFragment mFragment;
+
+ private List<SearchResult> mSearchResults;
private Map<String, List<? extends SearchResult>> mResultsMap;
private final SearchFeatureProvider mSearchFeatureProvider;
@@ -132,7 +134,7 @@
.get(InstalledAppResultLoader.class.getName());
final int dbSize = (databaseResults != null) ? databaseResults.size() : 0;
final int appSize = (installedAppResults != null) ? installedAppResults.size() : 0;
- final List<SearchResult> results = new ArrayList<>(dbSize + appSize);
+ final List<SearchResult> newResults = new ArrayList<>(dbSize + appSize);
int dbIndex = 0;
int appIndex = 0;
@@ -140,29 +142,34 @@
while (rank <= BOTTOM_RANK) {
while ((dbIndex < dbSize) && (databaseResults.get(dbIndex).rank == rank)) {
- results.add(databaseResults.get(dbIndex++));
+ newResults.add(databaseResults.get(dbIndex++));
}
while ((appIndex < appSize) && (installedAppResults.get(appIndex).rank == rank)) {
- results.add(installedAppResults.get(appIndex++));
+ newResults.add(installedAppResults.get(appIndex++));
}
rank++;
}
while (dbIndex < dbSize) {
- results.add(databaseResults.get(dbIndex++));
+ newResults.add(databaseResults.get(dbIndex++));
}
while (appIndex < appSize) {
- results.add(installedAppResults.get(appIndex++));
+ newResults.add(installedAppResults.get(appIndex++));
}
- if (mSearchFeatureProvider
- .isSmartSearchRankingEnabled(mFragment.getContext().getApplicationContext())) {
+ final boolean isSmartSearchRankingEnabled = mSearchFeatureProvider
+ .isSmartSearchRankingEnabled(mFragment.getContext().getApplicationContext());
+
+ if (isSmartSearchRankingEnabled) {
// TODO: run this in parallel to loading the results if takes too long
- mSearchFeatureProvider.rankSearchResults(query, results);
+ mSearchFeatureProvider.rankSearchResults(query, newResults);
}
- mSearchResults.addAll(results);
- notifyDataSetChanged();
+ final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(
+ new SearchResultDiffCallback(mSearchResults, newResults),
+ isSmartSearchRankingEnabled);
+ mSearchResults = newResults;
+ diffResult.dispatchUpdatesTo(this);
return mSearchResults.size();
}
diff --git a/src/com/android/settings/tts/TextToSpeechSettings.java b/src/com/android/settings/tts/TextToSpeechSettings.java
index 37993bf..0dfdab6 100644
--- a/src/com/android/settings/tts/TextToSpeechSettings.java
+++ b/src/com/android/settings/tts/TextToSpeechSettings.java
@@ -265,6 +265,19 @@
}
}
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ // Save the mLocalePreference values, so we can repopulate it with entries.
+ outState.putCharSequenceArray(STATE_KEY_LOCALE_ENTRIES,
+ mLocalePreference.getEntries());
+ outState.putCharSequenceArray(STATE_KEY_LOCALE_ENTRY_VALUES,
+ mLocalePreference.getEntryValues());
+ outState.putCharSequence(STATE_KEY_LOCALE_VALUE,
+ mLocalePreference.getValue());
+ }
+
private void initSettings() {
final ContentResolver resolver = getContentResolver();
diff --git a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
index 6efdcf72..bef4777 100644
--- a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
+++ b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
@@ -67,7 +67,6 @@
// Add Preference items for each of the matching activities
for (ResolveInfo info : rList) {
Preference pref = new Preference(getPrefContext());
- pref.setLayoutResource(R.layout.preference_wallpaper_type);
Intent prefIntent = new Intent(intent);
prefIntent.setComponent(new ComponentName(
info.activityInfo.packageName, info.activityInfo.name));
diff --git a/src/com/android/settings/widget/MasterSwitchPreference.java b/src/com/android/settings/widget/MasterSwitchPreference.java
index cf22207..002cb77 100644
--- a/src/com/android/settings/widget/MasterSwitchPreference.java
+++ b/src/com/android/settings/widget/MasterSwitchPreference.java
@@ -36,6 +36,7 @@
private Switch mSwitch;
private boolean mChecked;
+ private boolean mEnableSwitch = true;
public MasterSwitchPreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
@@ -67,6 +68,9 @@
widgetView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
+ if (mSwitch != null && !mSwitch.isEnabled()) {
+ return;
+ }
setChecked(!mChecked);
if (!callChangeListener(mChecked)) {
setChecked(!mChecked);
@@ -76,9 +80,11 @@
}
});
}
+
mSwitch = (Switch) holder.findViewById(R.id.switchWidget);
if (mSwitch != null) {
mSwitch.setChecked(mChecked);
+ mSwitch.setEnabled(mEnableSwitch);
}
}
@@ -94,6 +100,7 @@
}
public void setSwitchEnabled(boolean enabled) {
+ mEnableSwitch = enabled;
if (mSwitch != null) {
mSwitch.setEnabled(enabled);
}
diff --git a/src/com/android/settings/wifi/LinkablePreference.java b/src/com/android/settings/wifi/LinkablePreference.java
index 5bf51ed..9a6b11a 100644
--- a/src/com/android/settings/wifi/LinkablePreference.java
+++ b/src/com/android/settings/wifi/LinkablePreference.java
@@ -21,6 +21,7 @@
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.Spannable;
+import android.text.method.LinkMovementMethod;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.widget.TextView;
@@ -81,6 +82,7 @@
mContentTitle.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(boldSpan);
+ textView.setMovementMethod(new LinkMovementMethod());
}
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 38f5a43..a87bd19 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -90,6 +90,7 @@
WifiDialog.WifiDialogListener {
private static final String TAG = "WifiSettings";
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
/* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
@@ -190,8 +191,10 @@
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- getPreferenceManager().setPreferenceComparisonCallback(
- new PreferenceManager.SimplePreferenceComparisonCallback());
+ // TODO(b/37429702): Add animations and preference comparator back after initial screen is
+ // loaded (ODR).
+ setAnimationAllowed(false);
+
addPreferencesFromResource(R.xml.wifi_settings);
mConnectedAccessPointPreferenceCategory =
@@ -335,6 +338,21 @@
mWifiEnabler = createWifiEnabler();
mWifiTracker.startTracking();
+
+ if (!isUiRestricted() && mWifiManager.isWifiEnabled()) {
+ forceUpdateAPs();
+ }
+ }
+
+ private void forceUpdateAPs() {
+ setProgressBarVisible(true);
+ mWifiTracker.forceUpdate();
+ if (DEBUG) {
+ Log.d(TAG, "WifiSettings force update APs: " + mWifiTracker.getAccessPoints());
+ }
+
+ getView().removeCallbacks(mUpdateAccessPointsRunnable);
+ updateAccessPointPreferences();
}
/**
@@ -353,8 +371,6 @@
if (mWifiEnabler != null) {
mWifiEnabler.resume(activity);
}
-
- activity.invalidateOptionsMenu();
}
@Override
@@ -651,7 +667,7 @@
final int wifiState = mWifiManager.getWifiState();
switch (wifiState) {
case WifiManager.WIFI_STATE_ENABLED:
- updateAccessPointsDelayed();
+ forceUpdateAPs();
break;
case WifiManager.WIFI_STATE_ENABLING:
@@ -733,7 +749,7 @@
removeCachedPrefs(mAccessPointsPreferenceCategory);
mAddPreference.setOrder(index);
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
- setConfigureWifiSettingsVisibility();
+ setAdditionalSettingsSummaries();
if (!hasAvailableAccessPoints) {
setProgressBarVisible(true);
@@ -812,8 +828,8 @@
// in the Wifi Network Details Fragment
pref.getAccessPoint().saveWifiState(pref.getExtras());
pref.setFragment(WifiNetworkDetailsFragment.class.getName());
-
pref.refresh();
+
mConnectedAccessPointPreferenceCategory.addPreference(pref);
mConnectedAccessPointPreferenceCategory.setVisible(true);
}
@@ -824,7 +840,7 @@
mConnectedAccessPointPreferenceCategory.setVisible(false);
}
- private void setConfigureWifiSettingsVisibility() {
+ private void setAdditionalSettingsSummaries() {
mAdditionalSettingsPreferenceCategory.addPreference(mConfigureWifiSettingsPreference);
boolean wifiWakeupEnabled = Settings.Global.getInt(
getContentResolver(), Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
index 122e524..2c33fc5 100644
--- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
@@ -26,6 +26,7 @@
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
+import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
@@ -97,10 +98,20 @@
return;
}
final SwitchPreference enableWifiWakeup = (SwitchPreference) preference;
+
enableWifiWakeup.setChecked(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1);
- enableWifiWakeup.setEnabled(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1);
+
+ boolean wifiScanningEnabled = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+ boolean networkRecommendationsEnabled = Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
+ enableWifiWakeup.setEnabled(networkRecommendationsEnabled && wifiScanningEnabled);
+
+ enableWifiWakeup.setSummary(wifiScanningEnabled ?
+ R.string.wifi_wakeup_summary :
+ R.string.wifi_wakeup_summary_scanning_disabled);
}
class SettingObserver extends ContentObserver {
diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
index faa2a77..21fda30 100644
--- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
+++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
@@ -15,7 +15,11 @@
*/
package com.android.settings.wifi.details;
+import android.app.Fragment;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.IpPrefix;
@@ -39,6 +43,7 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.core.lifecycle.events.OnPause;
import com.android.settings.core.lifecycle.events.OnResume;
import com.android.settings.wifi.WifiDetailPreference;
import com.android.settingslib.wifi.AccessPoint;
@@ -55,8 +60,9 @@
* {@link WifiNetworkDetailsFragment}.
*/
public class WifiDetailPreferenceController extends PreferenceController implements
- LifecycleObserver, OnResume {
+ LifecycleObserver, OnPause, OnResume {
private static final String TAG = "WifiDetailsPrefCtrl";
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@VisibleForTesting
static final String KEY_CONNECTION_DETAIL_PREF = "connection_detail";
@@ -82,14 +88,15 @@
static final String KEY_IPV6_ADDRESS_CATEGORY = "ipv6_details_category";
private AccessPoint mAccessPoint;
+ private final ConnectivityManager mConnectivityManager;
+ private final Fragment mFragment;
private NetworkInfo mNetworkInfo;
private Context mPrefContext;
private int mRssi;
private String[] mSignalStr;
- private WifiConfiguration mWifiConfig;
+ private final WifiConfiguration mWifiConfig;
private WifiInfo mWifiInfo;
private final WifiManager mWifiManager;
- private final ConnectivityManager mConnectivityManager;
// Preferences - in order of appearance
private Preference mConnectionDetailPref;
@@ -104,18 +111,39 @@
private WifiDetailPreference mDnsPref;
private PreferenceCategory mIpv6AddressCategory;
- public WifiDetailPreferenceController(AccessPoint accessPoint, Context context,
- Lifecycle lifecycle, WifiManager wifiManager, ConnectivityManager connectivityManager) {
+ private final IntentFilter mFilter;
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ switch (intent.getAction()) {
+ case WifiManager.NETWORK_STATE_CHANGED_ACTION:
+ case WifiManager.RSSI_CHANGED_ACTION:
+ updateInfo();
+ }
+ }
+ };
+
+ public WifiDetailPreferenceController(
+ AccessPoint accessPoint,
+ ConnectivityManager connectivityManager,
+ Context context,
+ Fragment fragment,
+ Lifecycle lifecycle,
+ WifiManager wifiManager) {
super(context);
mAccessPoint = accessPoint;
+ mConnectivityManager = connectivityManager;
+ mFragment = fragment;
mNetworkInfo = accessPoint.getNetworkInfo();
mRssi = accessPoint.getRssi();
mSignalStr = context.getResources().getStringArray(R.array.wifi_signal);
mWifiConfig = accessPoint.getConfig();
mWifiManager = wifiManager;
- mConnectivityManager = connectivityManager;
- mWifiInfo = wifiManager.getConnectionInfo();
+
+ mFilter = new IntentFilter();
+ mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+ mFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
lifecycle.addObserver(this);
}
@@ -163,39 +191,33 @@
@Override
public void onResume() {
- mWifiInfo = mWifiManager.getConnectionInfo();
+ updateInfo();
- refreshFromWifiInfo();
- setIpText();
+ mContext.registerReceiver(mReceiver, mFilter);
}
- private void refreshFromWifiInfo() {
- if (mWifiInfo == null) {
+ @Override
+ public void onPause() {
+ mContext.unregisterReceiver(mReceiver);
+ }
+
+ private void updateInfo() {
+ mNetworkInfo = mConnectivityManager.getNetworkInfo(mWifiManager.getCurrentNetwork());
+ mWifiInfo = mWifiManager.getConnectionInfo();
+ if (mNetworkInfo == null || mWifiInfo == null) {
+ exitActivity();
return;
}
- mAccessPoint.update(mWifiConfig, mWifiInfo, mNetworkInfo);
- int iconSignalLevel = WifiManager.calculateSignalLevel(
- mWifiInfo.getRssi(), WifiManager.RSSI_LEVELS);
- Drawable wifiIcon = NetworkBadging.getWifiIcon(
- iconSignalLevel, NetworkBadging.BADGING_NONE, mContext.getTheme()).mutate();
+ refreshNetworkState();
- // Connected Header Pref
- mConnectionDetailPref.setIcon(wifiIcon);
- mConnectionDetailPref.setTitle(mAccessPoint.getSettingsSummary());
+ // Update Connection Header icon and Signal Strength Preference
+ mRssi = mWifiInfo.getRssi();
+ refreshRssiViews();
// MAC Address Pref
mMacAddressPref.setDetailText(mWifiInfo.getMacAddress());
- // Signal Strength Pref
- Drawable wifiIconDark = wifiIcon.getConstantState().newDrawable().mutate();
- wifiIconDark.setTint(mContext.getResources().getColor(
- R.color.wifi_details_icon_color, mContext.getTheme()));
- mSignalStrengthPref.setIcon(wifiIconDark);
-
- int summarySignalLevel = mAccessPoint.getLevel();
- mSignalStrengthPref.setDetailText(mSignalStr[summarySignalLevel]);
-
// Link Speed Pref
int linkSpeedMbps = mWifiInfo.getLinkSpeed();
mLinkSpeedPref.setVisible(linkSpeedMbps >= 0);
@@ -215,6 +237,37 @@
Log.e(TAG, "Unexpected frequency " + frequency);
}
mFrequencyPref.setDetailText(band);
+
+ setIpText();
+ }
+
+ private void exitActivity() {
+ if (DEBUG) {
+ Log.d(TAG, "Exiting the WifiNetworkDetailsPage");
+ }
+ mFragment.getActivity().finish();
+ }
+
+ private void refreshNetworkState() {
+ mAccessPoint.update(mWifiConfig, mWifiInfo, mNetworkInfo);
+ mConnectionDetailPref.setTitle(mAccessPoint.getSettingsSummary());
+ }
+
+ private void refreshRssiViews() {
+ int iconSignalLevel = WifiManager.calculateSignalLevel(
+ mRssi, WifiManager.RSSI_LEVELS);
+ Drawable wifiIcon = NetworkBadging.getWifiIcon(
+ iconSignalLevel, NetworkBadging.BADGING_NONE, mContext.getTheme()).mutate();
+
+ mConnectionDetailPref.setIcon(wifiIcon);
+
+ Drawable wifiIconDark = wifiIcon.getConstantState().newDrawable().mutate();
+ wifiIconDark.setTint(mContext.getResources().getColor(
+ R.color.wifi_details_icon_color, mContext.getTheme()));
+ mSignalStrengthPref.setIcon(wifiIconDark);
+
+ int summarySignalLevel = mAccessPoint.getLevel();
+ mSignalStrengthPref.setDetailText(mSignalStr[summarySignalLevel]);
}
private void setIpText() {
@@ -248,6 +301,7 @@
Preference pref = new Preference(mPrefContext);
pref.setKey(ip);
pref.setTitle(ip);
+ pref.setSelectable(false);
mIpv6AddressCategory.addPreference(pref);
mIpv6AddressCategory.setVisible(true);
}
@@ -321,5 +375,6 @@
mWifiManager.forget(mWifiConfig.networkId, null /* action listener */);
}
}
+ mFragment.getActivity().finish();
}
}
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index ebd1143..adcfcc0 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -69,7 +69,6 @@
private void forgetNetwork() {
mMetricsFeatureProvider.action(getActivity(), MetricsProto.MetricsEvent.ACTION_WIFI_FORGET);
mWifiDetailPreferenceController.forgetNetwork();
- getActivity().finish();
}
@Override
@@ -91,10 +90,11 @@
protected List<PreferenceController> getPreferenceControllers(Context context) {
mWifiDetailPreferenceController = new WifiDetailPreferenceController(
mAccessPoint,
+ context.getSystemService(ConnectivityManager.class),
context,
+ this,
getLifecycle(),
- context.getSystemService(WifiManager.class),
- context.getSystemService(ConnectivityManager.class));
+ context.getSystemService(WifiManager.class));
ArrayList<PreferenceController> controllers = new ArrayList(1);
controllers.add(mWifiDetailPreferenceController);
diff --git a/tests/robotests/assets/whitelist_duplicate_index_key b/tests/robotests/assets/whitelist_duplicate_index_key
new file mode 100644
index 0000000..4446403
--- /dev/null
+++ b/tests/robotests/assets/whitelist_duplicate_index_key
@@ -0,0 +1,12 @@
+dashboard_tile_placeholder
+gesture_pick_up
+add_users_when_locked
+additional_system_update_settings
+gesture_assist
+screen_zoom
+gesture_swipe_down_fingerprint
+gesture_double_twist
+lock_screen_notifications
+gesture_double_tap_power
+gesture_double_tap_screen
+usage_access
\ No newline at end of file
diff --git a/tests/robotests/src/android/service/oemlock/OemLockManager.java b/tests/robotests/src/android/service/oemlock/OemLockManager.java
new file mode 100644
index 0000000..7c015cf
--- /dev/null
+++ b/tests/robotests/src/android/service/oemlock/OemLockManager.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.oemlock;
+
+/**
+ * Make OemLockManager available to Robolectric.
+ */
+public class OemLockManager {
+ public void setOemUnlockAllowedByCarrier(boolean allowed, byte[] signature) {}
+
+ public boolean isOemUnlockAllowedByCarrier() {
+ return true;
+ }
+
+ public void setOemUnlockAllowedByUser(boolean allowed) {}
+
+ public boolean isOemUnlockAllowedByUser() {
+ return false;
+ }
+
+ public boolean canUserAllowOemUnlock() {
+ return true;
+ }
+ public boolean isOemUnlockAllowed() {
+ return false;
+ }
+
+ public boolean isDeviceOemUnlocked() {
+ return false;
+ }
+}
diff --git a/tests/robotests/src/android/util/IconDrawableFactory.java b/tests/robotests/src/android/util/IconDrawableFactory.java
new file mode 100644
index 0000000..9d0d7df
--- /dev/null
+++ b/tests/robotests/src/android/util/IconDrawableFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.util;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageItemInfo;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+
+/**
+ * This class is only needed to get around Robolectric issue.
+ */
+public class IconDrawableFactory {
+
+ public static IconDrawableFactory newInstance(Context context) {
+ return new IconDrawableFactory();
+ }
+
+ public Drawable getBadgedIcon(ApplicationInfo appInfo) {
+ return getBadgedIcon(appInfo, 0);
+ }
+
+ public Drawable getBadgedIcon(ApplicationInfo appInfo, int userId) {
+ return getBadgedIcon(appInfo, appInfo, userId);
+ }
+
+ public Drawable getBadgedIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo, int userId) {
+ return new ColorDrawable(0);
+ }
+}
diff --git a/tests/robotests/src/android/util/LauncherIcons.java b/tests/robotests/src/android/util/LauncherIcons.java
deleted file mode 100644
index a18cfae..0000000
--- a/tests/robotests/src/android/util/LauncherIcons.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package android.util;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-/**
- * This class is only needed to get around RoboElectric issue.
- */
-public final class LauncherIcons {
-
- public LauncherIcons(Context context) {
- }
-
- public Drawable wrapIconDrawableWithShadow(Drawable drawable) {
- return drawable;
- }
-}
diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java
index 721d0e0..98b33d3 100644
--- a/tests/robotests/src/com/android/settings/MasterClearTest.java
+++ b/tests/robotests/src/com/android/settings/MasterClearTest.java
@@ -17,30 +17,65 @@
package com.android.settings;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
+import android.app.Activity;
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ScrollView;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowActivity;
+
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class MasterClearTest {
+
+ @Mock
private MasterClear mMasterClear;
@Mock
private ScrollView mScrollView;
@Mock
private LinearLayout mLinearLayout;
+ private ShadowActivity mShadowActivity;
+ private Activity mActivity;
+ private View mContentView;
+
+ private class ActivityForTest extends SettingsActivity {
+ private Bundle mArgs;
+
+ @Override
+ public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
+ int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
+ mArgs = args;
+ }
+
+ public Bundle getArgs() {
+ return mArgs;
+ }
+ }
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mMasterClear = new MasterClear();
+ mMasterClear = spy(new MasterClear());
+ mActivity = Robolectric.setupActivity(Activity.class);
+ mShadowActivity = shadowOf(mActivity);
+ mContentView = LayoutInflater.from(mActivity).inflate(R.layout.master_clear, null);
// Make scrollView only have one child
when(mScrollView.getChildAt(0)).thenReturn(mLinearLayout);
@@ -48,6 +83,32 @@
}
@Test
+ public void testShowFinalConfirmation_EraseEsimChecked() {
+ ActivityForTest testActivity = new ActivityForTest();
+ when(mMasterClear.getActivity()).thenReturn(testActivity);
+
+ mMasterClear.mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
+ mMasterClear.mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
+ mMasterClear.mEsimStorage.setChecked(true);
+ mMasterClear.showFinalConfirmation();
+ assertThat(testActivity.getArgs().getBoolean(MasterClear.ERASE_ESIMS_EXTRA, false))
+ .isTrue();
+ }
+
+ @Test
+ public void testShowFinalConfirmation_EraseEsimUnchecked() {
+ ActivityForTest testActivity = new ActivityForTest();
+ when(mMasterClear.getActivity()).thenReturn(testActivity);
+
+ mMasterClear.mEsimStorage = (CheckBox) mContentView.findViewById(R.id.erase_esim);
+ mMasterClear.mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);
+ mMasterClear.mEsimStorage.setChecked(false);
+ mMasterClear.showFinalConfirmation();
+ assertThat(testActivity.getArgs().getBoolean(MasterClear.ERASE_ESIMS_EXTRA, true))
+ .isFalse();
+ }
+
+ @Test
public void testHasReachedBottom_NotScrollDown_returnFalse() {
initScrollView(100, 0, 200);
diff --git a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
index 9bdf502..c636748 100644
--- a/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/SecuritySettingsTest.java
@@ -101,24 +101,7 @@
}
@Test
- @Config(shadows = {
- ShadowSecureSettings.class,
- })
- public void testSummaryProvider_packageVerifierDisabled() {
- // Package verifier state is set to disabled.
- ShadowSecureSettings.putInt(null, Settings.Secure.PACKAGE_VERIFIER_STATE, -1);
- mSummaryProvider.setListening(true);
-
- verify(mSummaryLoader, times(1)).setSummary(any(), isNull(String.class));
- }
-
- @Test
- @Config(shadows = {
- ShadowSecureSettings.class,
- })
public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
- // Package verifier state is set to disabled.
- ShadowSecureSettings.putInt(null, Settings.Secure.PACKAGE_VERIFIER_STATE, -1);
final FingerprintManager fpm = mock(FingerprintManager.class);
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
.thenReturn(true);
@@ -133,37 +116,29 @@
}
@Test
- public void testGetPackageVerifierSummary_nullInput() {
- assertThat(mSummaryProvider.getPackageVerifierSummary(null)).isNull();
+ public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
+ final FingerprintManager fpm = mock(FingerprintManager.class);
+ when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+ .thenReturn(false);
- when(mDashboardCategory.getTilesCount()).thenReturn(0);
+ mSummaryProvider.setListening(true);
- assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory)).isNull();
+ verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
}
@Test
- public void testGetPackageVerifierSummary_noMatchingTile() {
- when(mDashboardCategory.getTilesCount()).thenReturn(1);
- when(mDashboardCategory.getTile(0)).thenReturn(new Tile());
+ public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
+ final FingerprintManager fpm = mock(FingerprintManager.class);
+ when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+ .thenReturn(true);
- assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory)).isNull();
- }
+ // Cast to Object to workaround a robolectric casting bug
+ when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
+ when(fpm.isHardwareDetected()).thenReturn(false);
- @Test
- @Config(shadows = {
- ShadowTileUtils.class,
- })
- public void testGetPackageVerifierSummary_matchingTile() {
- when(mDashboardCategory.getTilesCount()).thenReturn(1);
- Tile tile = new Tile();
- tile.key = SecuritySettings.KEY_PACKAGE_VERIFIER_STATUS;
- Bundle bundle = new Bundle();
- bundle.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, "content://host/path");
- tile.metaData = bundle;
- when(mDashboardCategory.getTile(0)).thenReturn(tile);
+ mSummaryProvider.setListening(true);
- assertThat(mSummaryProvider.getPackageVerifierSummary(mDashboardCategory))
- .isEqualTo(MOCK_SUMMARY);
+ verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index 9d53bc8..65e9708 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -16,20 +16,28 @@
package com.android.settings;
+import android.app.Activity;
import android.app.ActivityManager;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
+import android.os.Bundle;
+import android.view.Menu;
+import com.android.settings.testutils.FakeFeatureFactory;
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.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -42,6 +50,9 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsActivityTest {
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+
@Mock
private FragmentManager mFragmentManager;
@Mock
@@ -50,10 +61,15 @@
private Bitmap mBitmap;
private SettingsActivity mActivity;
+ private FakeFeatureFactory mFeatureFactory;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mContext);
+ mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+
mActivity = spy(new SettingsActivity());
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
}
@@ -61,7 +77,6 @@
@Test
public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash()
throws ClassNotFoundException {
- mActivity = spy(new SettingsActivity());
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
@@ -76,4 +91,51 @@
verify(mTaskDescription).setIcon(any());
}
+
+ @Test
+ public void testCreateOptionsMenu_setsUpSearch() {
+ ReflectionHelpers.setField(mActivity, "mSearchFeatureProvider",
+ mFeatureFactory.getSearchFeatureProvider());
+ mActivity.mDisplaySearch = true;
+ mActivity.onCreateOptionsMenu(null);
+
+ verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(any(Menu.class),
+ any(Activity.class));
+ }
+
+ @Test
+ public void testSaveState_DisplaySearchSaved() {
+ mActivity.mDisplaySearch = true;
+ Bundle bundle = new Bundle();
+ mActivity.saveState(bundle);
+
+ assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_SEARCH)).isTrue();
+ }
+
+ @Test
+ public void testSaveState_EnabledHomeSaved() {
+ mActivity.mDisplayHomeAsUpEnabled = true;
+ Bundle bundle = new Bundle();
+ mActivity.saveState(bundle);
+
+ assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_HOME_AS_UP)).isTrue();
+ }
+
+ @Test
+ public void testRestoreState_DisplaySearchRestored() {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
+ mActivity.onRestoreInstanceState(bundle);
+
+ assertThat(mActivity.mDisplaySearch).isTrue();
+ }
+
+ @Test
+ public void testRestoreState_EnabledHomeRestored() {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
+ mActivity.onRestoreInstanceState(bundle);
+
+ assertThat(mActivity.mDisplaySearch).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java
new file mode 100644
index 0000000..d93d3a7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.accounts;
+
+
+import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.when;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AutoSyncWorkDataPreferenceControllerTest {
+
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private UserManager mUserManager;
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private Fragment mFragment;
+ @Mock
+ private Context mContext;
+
+ private AutoSyncWorkDataPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+
+ mController = new AutoSyncWorkDataPreferenceController(mContext, mFragment);
+ }
+
+ @Test
+ public void checkIsAvailable_managedProfile_shouldNotDisplay() {
+ when(mUserManager.isManagedProfile()).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void checkIsAvailable_linkedUser_shouldNotDisplay() {
+ when(mUserManager.isManagedProfile()).thenReturn(false);
+ when(mUserManager.isLinkedUser()).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void checkIsAvailable_singleUserProfile_shouldNotDisplay() {
+ final List<UserInfo> infos = new ArrayList<>();
+ infos.add(new UserInfo(1, "user 1", 0));
+ when(mUserManager.isManagedProfile()).thenReturn(false);
+ when(mUserManager.isLinkedUser()).thenReturn(false);
+ when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void multipleProfile_shouldInitWithWorkProfileUserHandle() {
+ final int id1 = 1;
+ final int id2 = 2;
+ final UserInfo managedUser = new UserInfo(id2, "user 2", FLAG_MANAGED_PROFILE);
+ final List<UserHandle> infos = new ArrayList<>();
+ infos.add(new UserHandle(id1));
+ infos.add(new UserHandle(id2));
+ when(mUserManager.getUserProfiles()).thenReturn(infos);
+ when(mUserManager.getUserHandle()).thenReturn(id1);
+ when(mUserManager.getUserInfo(id2)).thenReturn(managedUser);
+
+ mController = new AutoSyncWorkDataPreferenceController(mContext, mFragment);
+
+ assertThat(mController.mUserHandle.getIdentifier()).isEqualTo(id2);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
index 0d878ed..37a7521 100644
--- a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
@@ -17,6 +17,16 @@
package com.android.settings.applications;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
@@ -24,17 +34,16 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
+import android.graphics.drawable.ColorDrawable;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.ImageView;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settingslib.applications.ApplicationsState;
import org.junit.Before;
import org.junit.Test;
@@ -45,14 +54,6 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AppHeaderControllerTest {
@@ -60,11 +61,9 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ApplicationsState.AppEntry mAppEntry;
+ private Activity mActivity;
@Mock
private Fragment mFragment;
- @Mock
- private View mAppHeader;
private Context mShadowContext;
private LayoutInflater mLayoutInflater;
@@ -85,7 +84,7 @@
@Test
public void testBuildView_constructedWithoutView_shouldCreateNewView() {
mController = new AppHeaderController(mShadowContext, mFragment, null);
- View view = mController.done();
+ View view = mController.done(mActivity);
assertThat(view).isNotNull();
}
@@ -93,7 +92,7 @@
@Test
public void testBuildView_withContext_shouldBuildPreference() {
mController = new AppHeaderController(mShadowContext, mFragment, null);
- Preference preference = mController.done(mShadowContext);
+ Preference preference = mController.done(mActivity, mShadowContext);
assertThat(preference instanceof LayoutPreference).isTrue();
}
@@ -102,7 +101,7 @@
public void testBuildView_constructedWithView_shouldReturnSameView() {
View inputView = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
mController = new AppHeaderController(mShadowContext, mFragment, inputView);
- View view = mController.done();
+ View view = mController.done(mActivity);
assertThat(view).isSameAs(inputView);
}
@@ -111,14 +110,14 @@
public void bindViews_shouldBindAllData() {
final String testString = "test";
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
- final TextView label = (TextView) appHeader.findViewById(R.id.app_detail_title);
- final TextView version = (TextView) appHeader.findViewById(R.id.app_detail_summary);
+ final TextView label = appHeader.findViewById(R.id.app_detail_title);
+ final TextView version = appHeader.findViewById(R.id.app_detail_summary);
mController = new AppHeaderController(mShadowContext, mFragment, appHeader);
mController.setLabel(testString);
mController.setSummary(testString);
mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
- mController.done();
+ mController.done(mActivity);
assertThat(label.getText()).isEqualTo(testString);
assertThat(version.getText()).isEqualTo(testString);
@@ -139,7 +138,7 @@
mController.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.VISIBLE);
@@ -164,7 +163,7 @@
mController.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
@@ -183,7 +182,7 @@
mController.setButtonActions(
AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
@@ -201,7 +200,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
@@ -221,7 +220,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.VISIBLE);
@@ -242,7 +241,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getContentDescription())
.isEqualTo("App Info");
@@ -258,7 +257,7 @@
.setButtonActions(
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
AppHeaderController.ActionType.ACTION_NONE);
- mController.done();
+ mController.done(mActivity);
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.VISIBLE);
@@ -272,32 +271,19 @@
public void instantApps_normalAppsDontGetLabel() {
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
mController = new AppHeaderController(mContext, mFragment, appHeader);
- mController.done();
+ mController.done(mActivity);
assertThat(appHeader.findViewById(R.id.install_type).getVisibility())
.isEqualTo(View.GONE);
}
- // Ensure that the instant app label does not show up when we haven't told the controller the
- // app is instant.
- @Test
- public void instantApps_normalAppsDontGetInstantAppsBadge() {
- final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
- mController = new AppHeaderController(mContext, mFragment, appHeader);
- mController.done();
- assertThat(appHeader.findViewById(R.id.app_icon_instant_apps_badge).getVisibility())
- .isEqualTo(View.GONE);
- }
-
// Test that the "instant apps" label is present in the header when we have an instant app.
@Test
public void instantApps_expectedHeaderItem() {
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
mController = new AppHeaderController(mContext, mFragment, appHeader);
mController.setIsInstantApp(true);
- mController.done();
- TextView label = (TextView)appHeader.findViewById(R.id.install_type);
- ImageView badgeView = appHeader.findViewById(R.id.app_icon_instant_apps_badge);
- assertThat(badgeView.getVisibility()).isEqualTo(View.VISIBLE);
+ mController.done(mActivity);
+ TextView label = appHeader.findViewById(R.id.install_type);
assertThat(label.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(label.getText()).isEqualTo(
appHeader.getResources().getString(R.string.install_type_instant));
@@ -306,6 +292,30 @@
}
@Test
+ public void styleActionBar_invalidObjects_shouldNotCrash() {
+ mController = new AppHeaderController(mShadowContext, mFragment, null);
+ mController.styleActionBar(null);
+
+ when(mActivity.getActionBar()).thenReturn(null);
+ mController.styleActionBar(mActivity);
+
+ verify(mActivity).getActionBar();
+ }
+
+ @Test
+ public void styleActionBar_setElevationAndBackground() {
+ final ActionBar actionBar = mActivity.getActionBar();
+
+ mController = new AppHeaderController(mShadowContext, mFragment, null);
+ mController.styleActionBar(mActivity);
+
+ verify(actionBar).setElevation(0);
+ // Enforce a color drawable as background here, as image based drawables might not be
+ // wide enough to cover entire action bar.
+ verify(actionBar).setBackgroundDrawable(any(ColorDrawable.class));
+ }
+
+ @Test
public void initAppHeaderController_appHeaderNull_useFragmentContext() {
mController = new AppHeaderController(mContext, mFragment, null);
diff --git a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
index 04eeb02..36116c0 100644
--- a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
@@ -40,6 +40,8 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import java.io.IOException;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class FetchPackageStorageAsyncLoaderTest {
@@ -56,7 +58,7 @@
}
@Test
- public void worksForValidPackageNameAndUid() {
+ public void worksForValidPackageNameAndUid() throws Exception {
AppStorageStats stats = mock(AppStorageStats.class);
when(stats.getCodeBytes()).thenReturn(1L);
when(stats.getDataBytes()).thenReturn(2L);
@@ -72,9 +74,9 @@
}
@Test
- public void installerExceptionHandledCleanly() {
+ public void installerExceptionHandledCleanly() throws Exception {
when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class))).
- thenThrow(new IllegalStateException("intentional failure"));
+ thenThrow(new IOException("intentional failure"));
ApplicationInfo info = new ApplicationInfo();
info.packageName = PACKAGE_NAME;
FetchPackageStorageAsyncLoader task = new FetchPackageStorageAsyncLoader(
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index 5b1019e..f372836 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -17,21 +17,34 @@
package com.android.settings.applications;
-import android.app.Activity;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.app.AlertDialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.os.BatteryStats;
import android.os.UserManager;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
import android.view.View;
import android.widget.Button;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
-import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -39,8 +52,8 @@
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
-import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
import org.junit.Before;
import org.junit.Test;
@@ -52,18 +65,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
-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;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -315,4 +316,43 @@
verify(buttonsController).setPackageName(anyString());
verify(buttonsController).show();
}
+
+ @Test
+ public void instantApps_removeCorrectPref() {
+ PreferenceScreen mockPreferenceScreen = mock(PreferenceScreen.class);
+ PreferenceManager mockPreferenceManager = mock(PreferenceManager.class);
+ AppDomainsPreference mockAppDomainsPref = mock(AppDomainsPreference.class);
+ Preference mockLaunchPreference = mock(Preference.class);
+ PackageInfo mockPackageInfo = mock(PackageInfo.class);
+ PackageManager mockPackageManager = mock(PackageManager.class);
+ ReflectionHelpers.setField(
+ mAppDetail, "mLaunchPreference", mockLaunchPreference);
+ ReflectionHelpers.setField(
+ mAppDetail, "mInstantAppDomainsPreference", mockAppDomainsPref);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPreferenceManager", mockPreferenceManager);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPackageInfo", mockPackageInfo);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPm", mockPackageManager);
+ when(mockPreferenceManager.getPreferenceScreen()).thenReturn(mockPreferenceScreen);
+
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> false));
+ mAppDetail.prepareInstantAppPrefs();
+
+ // For the non instant case we remove the app domain pref, and leave the launch pref
+ verify(mockPreferenceScreen).removePreference(mockAppDomainsPref);
+ verify(mockPreferenceScreen, never()).removePreference(mockLaunchPreference);
+
+ // For the instant app case we remove the launch preff, and leave the app domain pref
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+
+ mAppDetail.prepareInstantAppPrefs();
+ verify(mockPreferenceScreen).removePreference(mockLaunchPreference);
+ // Will be 1 still due to above call
+ verify(mockPreferenceScreen, times(1))
+ .removePreference(mockAppDomainsPref);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
index 9bc7482..6440141 100644
--- a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
@@ -81,7 +81,7 @@
}
@Test
- public void storageShouldRepresentStorageStatsQuery() {
+ public void storageShouldRepresentStorageStatsQuery() throws Exception {
when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
diff --git a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
index 1182762..728a8a5 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
@@ -16,7 +16,16 @@
package com.android.settings.applications.assist;
+import android.Manifest;
+import android.app.SearchManager;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
import android.provider.Settings;
import com.android.settings.SettingsRobolectricTestRunner;
@@ -24,6 +33,8 @@
import com.android.settings.applications.defaultapps.DefaultAppInfo;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,6 +43,13 @@
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -39,6 +57,10 @@
@Mock
private Context mContext;
+ @Mock
+ private SearchManager mSearchManager;
+ @Mock
+ private PackageManager mPackageManager;
private DefaultAssistPreferenceController mController;
@Before
@@ -61,4 +83,33 @@
assertThat(appInfo.getKey()).isEqualTo(flattenKey);
}
+
+ @Test
+ public void getSettingIntent_noSettingsActivity_shouldNotCrash() {
+ final String flattenKey = "com.android.settings/assist";
+ ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT, flattenKey);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ DefaultAssistPreferenceController controller =
+ spy(new DefaultAssistPreferenceController(mContext));
+ final ResolveInfo resolveInfo = new ResolveInfo();
+ resolveInfo.activityInfo = new ActivityInfo();
+ resolveInfo.activityInfo.name = "assist";
+ resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
+ resolveInfo.activityInfo.applicationInfo.packageName = "com.android.settings";
+ when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), anyInt()))
+ .thenReturn(resolveInfo);
+ when(mContext.getSystemService(Context.SEARCH_SERVICE)).thenReturn(mSearchManager);
+ when(mSearchManager.getAssistIntent(anyBoolean())).thenReturn(mock(Intent.class));
+ final ServiceInfo serviceInfo = new ServiceInfo();
+ serviceInfo.permission = Manifest.permission.BIND_VOICE_INTERACTION;
+ resolveInfo.serviceInfo = serviceInfo;
+ final List<ResolveInfo> services = new ArrayList<>();
+ services.add(resolveInfo);
+ when(mPackageManager.queryIntentServices(any(Intent.class), anyInt())).thenReturn(services);
+ doReturn(null).when(controller).getAssistSettingsActivity(
+ ComponentName.unflattenFromString(flattenKey), resolveInfo, mPackageManager);
+
+ controller.getSettingIntent(null);
+ // should not crash
+ }
}
diff --git a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspector.java b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspector.java
index 86c14a5..2f786f8 100644
--- a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspector.java
+++ b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspector.java
@@ -70,7 +70,7 @@
return true;
}
- protected void initializeGrandfatherList(List<String> grandfather, String filename) {
+ public static void initializeGrandfatherList(List<String> grandfather, String filename) {
try {
final InputStream in = ShadowApplication.getInstance().getApplicationContext()
.getAssets()
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionsChecksTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionsChecksTest.java
new file mode 100644
index 0000000..72231b2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionsChecksTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2017 Google Inc.
+ *
+ * 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.dashboard.suggestions;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintManager;
+
+import com.android.settings.Settings;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settingslib.drawer.Tile;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SuggestionsChecksTest {
+
+ @Mock
+ private Context mContext;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private FingerprintManager mFingerprintManager;
+ @Mock
+ private DevicePolicyManager mDevicePolicyManager;
+
+ private SuggestionsChecks mSuggestionsChecks;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ when(mContext.getApplicationContext()).thenReturn(mContext);
+ mSuggestionsChecks = new SuggestionsChecks(mContext);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mContext.getSystemService(eq(Context.DEVICE_POLICY_SERVICE)))
+ .thenReturn(mDevicePolicyManager);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(), anyInt()))
+ .thenReturn(0);
+ when(mContext.getSystemService(FingerprintManager.class)).thenReturn(mFingerprintManager);
+ }
+
+ @Test
+ public void testFingerprintEnrollmentIntroductionIsCompleteWhenFingerprintAdded() {
+ stubFingerprintSupported(true);
+ when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(true);
+ Tile tile = createFingerprintTile();
+ assertThat(mSuggestionsChecks.isSuggestionComplete(tile)).isTrue();
+ }
+
+ @Test
+ public void testFingerprintEnrollmentIntroductionIsNotCompleteWhenNoFingerprintAdded() {
+ stubFingerprintSupported(true);
+ when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(false);
+ Tile tile = createFingerprintTile();
+ assertThat(mSuggestionsChecks.isSuggestionComplete(tile)).isFalse();
+ }
+
+
+ @Test
+ public void testFingerprintEnrollmentIntroductionIsCompleteWhenFingerprintNotSupported() {
+ stubFingerprintSupported(false);
+ Tile tile = createFingerprintTile();
+ assertThat(mSuggestionsChecks.isSuggestionComplete(tile)).isTrue();
+ }
+
+ @Test
+ public void testFingerprintEnrollmentIntroductionIsCompleteWhenFingerprintDisabled() {
+ stubFingerprintSupported(true);
+ when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(false);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(), anyInt()))
+ .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
+
+ Tile tile = createFingerprintTile();
+ assertThat(mSuggestionsChecks.isSuggestionComplete(tile)).isTrue();
+ }
+
+ private void stubFingerprintSupported(boolean enabled) {
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+ .thenReturn(enabled);
+ }
+
+ private Tile createFingerprintTile() {
+ Tile tile = new Tile();
+ tile.intent = new Intent();
+ tile.intent.setComponent(new ComponentName(mContext,
+ Settings.FingerprintEnrollSuggestionActivity.class));
+ return tile;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
index b3253f9..0c9988b 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
@@ -18,6 +18,10 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.app.Activity;
import android.os.storage.StorageManager;
import android.provider.SearchIndexableResource;
@@ -56,6 +60,15 @@
}
@Test
+ public void test_initializeOptionsMenuInvalidatesExistingMenu() {
+ Activity activity = mock(Activity.class);
+
+ mFragment.initializeOptionsMenu(activity);
+
+ verify(activity).invalidateOptionsMenu();
+ }
+
+ @Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
StorageDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
index 95f9fbe..17abab1 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
@@ -70,7 +70,7 @@
}
@Test
- public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() {
+ public void updateSummary_shouldDisplayUsedPercentAndFreeSpace() throws Exception {
final SummaryLoader loader = mock(SummaryLoader.class);
final SummaryLoader.SummaryProvider provider =
StorageSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index 47faf92..2231c22 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -242,21 +242,19 @@
eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
mController.displayPreference(screen);
- mController.setSystemSize(KILOBYTE * 6);
+ mController.setUsedSize(KILOBYTE * 200); // There should 87kB attributed.
StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
result.gamesSize = KILOBYTE * 8;
result.videoAppsSize = KILOBYTE * 16;
result.musicAppsSize = KILOBYTE * 4;
result.otherAppsSize = KILOBYTE * 9;
- result.systemSize = KILOBYTE * 10;
+ result.systemSize = KILOBYTE * 10; // This value is ignored and overriden now.
result.externalStats = new StorageStatsSource.ExternalStorageStats(
KILOBYTE * 50, // total
KILOBYTE * 10, // audio
KILOBYTE * 15, // video
KILOBYTE * 20); // image
- result.gamesSize = KILOBYTE * 8;
- result.otherAppsSize = KILOBYTE * 9;
mController.onLoadFinished(result);
assertThat(audio.getSummary().toString()).isEqualTo("14.00KB"); // 4KB apps + 10KB files
@@ -264,7 +262,7 @@
assertThat(games.getSummary().toString()).isEqualTo("8.00KB");
assertThat(movies.getSummary().toString()).isEqualTo("16.00KB");
assertThat(apps.getSummary().toString()).isEqualTo("9.00KB");
- assertThat(system.getSummary().toString()).isEqualTo("16.00KB");
+ assertThat(system.getSummary().toString()).isEqualTo("113KB");
assertThat(files.getSummary().toString()).isEqualTo("5.00KB");
}
diff --git a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
index cc9b6d0..6d8696f 100644
--- a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
@@ -43,12 +43,13 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private AutoBrightnessPreferenceController mController;
+ private final String PREFERENCE_KEY = "auto_brightness";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new AutoBrightnessPreferenceController(mContext);
+ mController = new AutoBrightnessPreferenceController(mContext, PREFERENCE_KEY);
}
@Test
@@ -72,7 +73,7 @@
@Test
public void testPreferenceController_ProperResultPayloadType() {
final Context context = ShadowApplication.getInstance().getApplicationContext();
- mController = new AutoBrightnessPreferenceController(context);
+ mController = new AutoBrightnessPreferenceController(context, PREFERENCE_KEY);
ResultPayload payload = mController.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}
@@ -80,7 +81,7 @@
@Test
public void testPreferenceController_CorrectPayload() {
final Context context = ShadowApplication.getInstance().getApplicationContext();
- mController = new AutoBrightnessPreferenceController(context);
+ mController = new AutoBrightnessPreferenceController(context, PREFERENCE_KEY);
InlineSwitchPayload payload = (InlineSwitchPayload) mController.getResultPayload();
assertThat(payload.settingsUri).isEqualTo("screen_brightness_mode");
assertThat(payload.settingSource).isEqualTo(ResultPayload.SettingsSource.SYSTEM);
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
index 025e1ae..0b33089 100644
--- a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
@@ -16,27 +16,31 @@
package com.android.settings.display;
-import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.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 android.provider.Settings.System;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
-import java.text.NumberFormat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.internal.ShadowExtractor;
+import org.robolectric.shadows.ShadowContentResolver;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -46,6 +50,10 @@
@Mock
private ContentResolver mContentResolver;
@Mock
+ private PowerManagerWrapper mPowerManager;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
private Preference mPreference;
private BrightnessLevelPreferenceController mController;
@@ -53,8 +61,15 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ when(mPowerManager.getMinimumScreenBrightnessSetting()).thenReturn(0);
+ when(mPowerManager.getMaximumScreenBrightnessSetting()).thenReturn(100);
+ when(mPowerManager.getMinimumScreenBrightnessForVrSetting()).thenReturn(0);
+ when(mPowerManager.getMaximumScreenBrightnessForVrSetting()).thenReturn(100);
+ when(mScreen.findPreference(anyString())).thenReturn(mPreference);
+ mController = spy(new BrightnessLevelPreferenceController(mContext, null, mPowerManager));
+ doReturn(false).when(mController).isInVrMode();
- mController = new BrightnessLevelPreferenceController(mContext);
}
@Test
@@ -63,14 +78,80 @@
}
@Test
- public void updateState_shouldSetSummary() {
- final NumberFormat formatter = NumberFormat.getPercentInstance();
- when(mContext.getContentResolver()).thenReturn(mContentResolver);
- Settings.System.putInt(mContentResolver, SCREEN_BRIGHTNESS, 45);
+ public void onResume_shouldRegisterObserver() {
+ Context context = RuntimeEnvironment.application;
+ BrightnessLevelPreferenceController controller =
+ new BrightnessLevelPreferenceController(context, null, mPowerManager);
+ ShadowContentResolver shadowContentResolver =
+ (ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
+
+ controller.onResume();
+
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isNotEmpty();
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_BRIGHTNESS))).isNotEmpty();
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty();
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isNotEmpty();
+ }
+
+ @Test
+ public void onPause_shouldUnregisterObserver() {
+ Context context = RuntimeEnvironment.application;
+ BrightnessLevelPreferenceController controller =
+ new BrightnessLevelPreferenceController(context, null, mPowerManager);
+ ShadowContentResolver shadowContentResolver =
+ (ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
+
+ controller.displayPreference(mScreen);
+ controller.onResume();
+ controller.onPause();
+
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isEmpty();
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_BRIGHTNESS))).isEmpty();
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isEmpty();
+ assertThat(shadowContentResolver.getContentObservers(
+ System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isEmpty();
+ }
+
+ @Test
+ public void updateState_inVrMode_shouldSetSummaryToVrBrightness() {
+ doReturn(true).when(mController).isInVrMode();
+ System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR, 85);
mController.updateState(mPreference);
- verify(mPreference).setSummary(formatter.format(45.0 / 255));
+ verify(mPreference).setSummary("85%");
}
+ @Test
+ public void updateState_autoBrightness_shouldSetSummaryToVrBrightness() {
+ doReturn(false).when(mController).isInVrMode();
+ System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
+ System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
+
+ System.putFloat(mContentResolver, System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary("50%");
+ }
+
+ @Test
+ public void updateState_manualBrightness_shouldSetSummaryToVrBrightness() {
+ doReturn(false).when(mController).isInVrMode();
+ System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
+ System.SCREEN_BRIGHTNESS_MODE_MANUAL);
+
+ System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 45);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary("45%");
+ }
}
diff --git a/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java
index ec142c2..2ebad46 100644
--- a/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java
@@ -42,11 +42,13 @@
private TimeoutListPreference mPreference;
private TimeoutPreferenceController mController;
+ private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new TimeoutPreferenceController(mContext);
+ mController = new TimeoutPreferenceController(mContext, KEY_SCREEN_TIMEOUT);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 03892a3..801034c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -17,7 +17,18 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doAnswer;
+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 android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -25,12 +36,12 @@
import android.graphics.drawable.Drawable;
import android.os.BatteryStats;
import android.os.Bundle;
-import android.os.UserHandle;
import android.view.View;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.AppHeaderController;
import com.android.settings.applications.LayoutPreference;
@@ -46,22 +57,10 @@
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-@RunWith(RobolectricTestRunner.class)
+@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AdvancedPowerUsageDetailTest {
private static final String APP_LABEL = "app label";
@@ -77,6 +76,8 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Activity mActivity;
@Mock
private AppHeaderController mAppHeaderController;
@Mock
@@ -86,8 +87,6 @@
@Mock
private ApplicationsState.AppEntry mAppEntry;
@Mock
- private Drawable mIconDrawable;
- @Mock
private Bundle mBundle;
@Mock
private BatteryEntry mBatteryEntry;
@@ -111,6 +110,7 @@
mFragment = spy(new AdvancedPowerUsageDetail());
doReturn(mContext).when(mFragment).getContext();
+ doReturn(mActivity).when(mFragment).getActivity();
doReturn(SUMMARY).when(mFragment).getString(anyInt());
doReturn(APP_LABEL).when(mBundle).getString(anyString());
doReturn(mBundle).when(mFragment).getArguments();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
index 0813478..4f48945 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -23,7 +23,9 @@
import android.os.Build;
import android.support.v14.preference.SwitchPreference;
+import com.android.settings.R;
import com.android.settings.TestConfig;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,9 +33,12 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -54,17 +59,18 @@
@Mock
private AppOpsManager mAppOpsManager;
@Mock
- private SwitchPreference mPreference;
- @Mock
private ApplicationInfo mHighApplicationInfo;
@Mock
private ApplicationInfo mLowApplicationInfo;
private BackgroundActivityPreferenceController mController;
+ private SwitchPreference mPreference;
+ private Context mShadowContext;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+ mShadowContext = RuntimeEnvironment.application;
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
when(mPackageManager.getPackagesForUid(UID_NORMAL)).thenReturn(PACKAGES_NORMAL);
@@ -77,7 +83,8 @@
mHighApplicationInfo.targetSdkVersion = Build.VERSION_CODES.O;
mLowApplicationInfo.targetSdkVersion = Build.VERSION_CODES.L;
- mController = new BackgroundActivityPreferenceController(mContext, UID_NORMAL);
+ mPreference = new SwitchPreference(mShadowContext);
+ mController = spy(new BackgroundActivityPreferenceController(mContext, UID_NORMAL));
mController.isAvailable();
}
@@ -87,14 +94,16 @@
verify(mAppOpsManager).setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL,
mController.getTargetPackage(), AppOpsManager.MODE_ALLOWED);
+ verify(mController).updateSummary(mPreference);
}
@Test
public void testOnPreferenceChange_TurnOffCheck_MethodInvoked() {
- mController.onPreferenceChange(null, false);
+ mController.onPreferenceChange(mPreference, false);
verify(mAppOpsManager).setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL,
mController.getTargetPackage(), AppOpsManager.MODE_IGNORED);
+ verify(mController).updateSummary(mPreference);
}
@Test
@@ -105,7 +114,8 @@
mController.updateState(mPreference);
- verify(mPreference).setChecked(true);
+ assertThat(mPreference.isChecked()).isTrue();
+ verify(mController).updateSummary(mPreference);
}
@Test
@@ -116,7 +126,46 @@
mController.updateState(mPreference);
- verify(mPreference).setChecked(false);
+ assertThat(mPreference.isChecked()).isFalse();
+ verify(mController).updateSummary(mPreference);
+ }
+
+ @Test
+ public void testUpdateSummary_modeError_showSummaryDisabled() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_ERRORED);
+ final CharSequence expectedSummary = mShadowContext.getText(
+ R.string.background_activity_summary_disabled);
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
+ }
+
+ @Test
+ public void testUpdateSummary_modeDefault_showSummaryOn() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_DEFAULT);
+ final CharSequence expectedSummary = mShadowContext.getText(
+ R.string.background_activity_summary_on);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
+ }
+
+ @Test
+ public void testUpdateSummary_modeIgnored_showSummaryOff() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_IGNORED);
+ final CharSequence expectedSummary = mShadowContext.getText(
+ R.string.background_activity_summary_off);
+
+ mController.updateSummary(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
}
@Test
@@ -144,6 +193,6 @@
assertThat(available).isTrue();
// Should get status from LOW_SDK_PACKAGE
- verify(mPreference).setChecked(true);
+ assertThat(mPreference.isChecked()).isTrue();
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
new file mode 100644
index 0000000..799dab9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.fuelgauge;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.BatteryManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.Utils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BatteryBroadcastReceiverTest {
+ private static final String BATTERY_INIT_LEVEL = "100%";
+ private static final String BATTERY_INIT_STATUS = "Not charging";
+ private static final int BATTERY_INTENT_LEVEL = 80;
+ private static final int BATTERY_INTENT_SCALE = 100;
+
+ @Mock
+ private BatteryBroadcastReceiver.OnBatteryChangedListener mBatteryListener;
+ private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
+ private Context mContext;
+ private Intent mChargingIntent;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+
+ mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
+ mBatteryBroadcastReceiver.mBatteryLevel = BATTERY_INIT_LEVEL;
+ mBatteryBroadcastReceiver.mBatteryStatus = BATTERY_INIT_STATUS;
+ mBatteryBroadcastReceiver.setBatteryChangedListener(mBatteryListener);
+
+ mChargingIntent = new Intent(Intent.ACTION_BATTERY_CHANGED);
+ mChargingIntent.putExtra(BatteryManager.EXTRA_LEVEL, BATTERY_INTENT_LEVEL);
+ mChargingIntent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_INTENT_SCALE);
+ mChargingIntent.putExtra(BatteryManager.EXTRA_STATUS,
+ BatteryManager.BATTERY_STATUS_CHARGING);
+ }
+
+ @Test
+ public void testOnReceive_batteryDataChanged_dataUpdated() {
+ mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
+
+ assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(
+ Utils.getBatteryPercentage(mChargingIntent));
+ assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(
+ Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
+ verify(mBatteryListener).onBatteryChanged();
+ }
+
+ @Test
+ public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
+ final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
+ final String batteryStatus = Utils.getBatteryStatus(mContext.getResources(),
+ mChargingIntent);
+ mBatteryBroadcastReceiver.mBatteryLevel = batteryLevel;
+ mBatteryBroadcastReceiver.mBatteryStatus = batteryStatus;
+
+ mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
+
+ assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(batteryLevel);
+ assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(batteryStatus);
+ verify(mBatteryListener, never()).onBatteryChanged();
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
index 85b893a..cb37a6e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java
@@ -15,12 +15,17 @@
*/
package com.android.settings.fuelgauge;
+import static com.google.common.truth.Truth.assertThat;
+
import android.content.Context;
+import android.graphics.ColorFilter;
+
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,6 +34,8 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -42,10 +49,15 @@
})
public class BatteryMeterViewTest {
private static final int BATTERY_LEVEL = 100;
+ private static final int BATTERY_CRITICAL_LEVEL = 15;
+ private static final int BATTERY_LOW_LEVEL = 3;
@Mock
- private BatteryMeterView.BatteryMeterDrawable mDrawable;
+ private ColorFilter mErrorColorFilter;
+ @Mock
+ private ColorFilter mAccentColorFilter;
private Context mContext;
private BatteryMeterView mBatteryMeterView;
+ private BatteryMeterView.BatteryMeterDrawable mDrawable;
@Before
public void setUp() {
@@ -53,13 +65,33 @@
mContext = RuntimeEnvironment.application;
mBatteryMeterView = new BatteryMeterView(mContext);
- mBatteryMeterView.setBatteryDrawable(mDrawable);
+ mDrawable = spy(new BatteryMeterView.BatteryMeterDrawable(mContext, 0));
+
+ mBatteryMeterView.mDrawable = mDrawable;
+ mBatteryMeterView.mAccentColorFilter = mAccentColorFilter;
+ mBatteryMeterView.mErrorColorFilter = mErrorColorFilter;
+
+ doReturn(BATTERY_CRITICAL_LEVEL).when(mDrawable).getCriticalLevel();
}
@Test
- public void testSetBatteryInfo_SetCorrectly() {
- mBatteryMeterView.setBatteryInfo(BATTERY_LEVEL);
+ public void testSetBatteryInfo_setCorrectly() {
+ mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
- verify(mDrawable).setBatteryLevel(BATTERY_LEVEL);
+ assertThat(mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
+ }
+
+ @Test
+ public void testSetBatteryInfo_levelLow_setErrorColor() {
+ mBatteryMeterView.setBatteryLevel(BATTERY_LOW_LEVEL);
+
+ verify(mDrawable).setBatteryColorFilter(mErrorColorFilter);
+ }
+
+ @Test
+ public void testSetBatteryInfo_levelNormal_setNormalColor() {
+ mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
+
+ verify(mDrawable).setBatteryColorFilter(mAccentColorFilter);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
index 2c5296a..b3afbb4 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
@@ -22,14 +22,18 @@
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import android.app.Fragment;
+import android.content.Context;
import android.os.Bundle;
+import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
@@ -39,11 +43,14 @@
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(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BatteryOptimizationPreferenceControllerTest {
+ private static final String PKG_IN_WHITELIST = "com.pkg.in.whitelist";
+ private static final String PKG_NOT_IN_WHITELIST = "com.pkg.not.in.whitelist";
private static final String KEY_OPTIMIZATION = "battery_optimization";
private static final String KEY_OTHER = "other";
@Mock
@@ -51,20 +58,28 @@
@Mock
private Fragment mFragment;
@Mock
- private Preference mPreference;
+ private TestPowerWhitelistBackend mBackend;
private BatteryOptimizationPreferenceController mController;
+ private Preference mPreference;
+ private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new BatteryOptimizationPreferenceController(mSettingsActivity, mFragment);
+ mContext = RuntimeEnvironment.application;
+ doReturn(false).when(mBackend).isWhitelisted(PKG_NOT_IN_WHITELIST);
+ doReturn(true).when(mBackend).isWhitelisted(PKG_IN_WHITELIST);
+
+ mPreference = new SwitchPreference(mContext);
+ mController = spy(new BatteryOptimizationPreferenceController(mSettingsActivity, mFragment,
+ PKG_NOT_IN_WHITELIST, mBackend));
}
@Test
public void testHandlePreferenceTreeClick_OptimizationPreference_HandleClick() {
- when(mPreference.getKey()).thenReturn(KEY_OPTIMIZATION);
+ mPreference.setKey(KEY_OPTIMIZATION);
final boolean handled = mController.handlePreferenceTreeClick(mPreference);
@@ -76,7 +91,7 @@
@Test
public void testHandlePreferenceTreeClick_OtherPreference_NotHandleClick() {
- when(mPreference.getKey()).thenReturn(KEY_OTHER);
+ mPreference.setKey(KEY_OTHER);
final boolean handled = mController.handlePreferenceTreeClick(mPreference);
@@ -85,4 +100,33 @@
anyString(), any(Bundle.class), anyInt(), any(CharSequence.class),
any(Fragment.class), anyInt());
}
+
+ @Test
+ public void testUpdateState_appInWhitelist_showSummaryNotOptimized() {
+ BatteryOptimizationPreferenceController controller =
+ new BatteryOptimizationPreferenceController(mSettingsActivity, mFragment,
+ PKG_IN_WHITELIST, mBackend);
+
+ controller.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.high_power_on));
+ }
+
+ @Test
+ public void testUpdateState_appNotInWhitelist_showSummaryOptimized() {
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.high_power_off));
+ }
+
+ /**
+ * Create this test class so we could mock it
+ */
+ public static class TestPowerWhitelistBackend extends PowerWhitelistBackend {
+
+ @Override
+ void refreshList() {
+ // Do nothing so we could mock it without error
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 4216d57..66d2c1a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.content.pm.PackageManager;
+import android.os.UserManager;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatterySipper.DrainType;
@@ -75,6 +76,8 @@
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@Mock
private PackageManager mPackageManager;
+ @Mock
+ private UserManager mUserManager;
private PowerUsageAdvanced mPowerUsageAdvanced;
private PowerUsageData mPowerUsageData;
private Context mShadowContext;
@@ -104,6 +107,7 @@
doReturn(STUB_STRING).when(mPowerUsageAdvanced).getString(anyInt(), any());
mPowerUsageAdvanced.setPackageManager(mPackageManager);
mPowerUsageAdvanced.setPowerUsageFeatureProvider(mPowerUsageFeatureProvider);
+ mPowerUsageAdvanced.setUserManager(mUserManager);
mPowerUsageData = new PowerUsageData(UsageType.APP);
mMaxBatterySipper.totalPowerMah = TYPE_BLUETOOTH_USAGE;
@@ -225,25 +229,68 @@
}
@Test
- public void testShouldHide_typeUnAccounted_returnTrue() {
+ public void testShouldHideCategory_typeUnAccounted_returnTrue() {
mPowerUsageData.usageType = UsageType.UNACCOUNTED;
- assertThat(mPowerUsageAdvanced.shouldHide(mPowerUsageData)).isTrue();
+ assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isTrue();
}
-
@Test
- public void testShouldHide_typeOverCounted_returnTrue() {
+ public void testShouldHideCategory_typeOverCounted_returnTrue() {
mPowerUsageData.usageType = UsageType.OVERCOUNTED;
- assertThat(mPowerUsageAdvanced.shouldHide(mPowerUsageData)).isTrue();
+ assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isTrue();
}
-
@Test
- public void testShouldHide_typeNormal_returnFalse() {
+ public void testShouldHideCategory_typeUserAndOnlyOne_returnTrue() {
+ mPowerUsageData.usageType = UsageType.USER;
+ doReturn(1).when(mUserManager).getUserCount();
+
+ assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isTrue();
+ }
+
+ @Test
+ public void testShouldHideCategory_typeUserAndMoreThanOne_returnFalse() {
+ mPowerUsageData.usageType = UsageType.USER;
+ doReturn(2).when(mUserManager).getUserCount();
+
+ assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isFalse();
+ }
+
+ @Test
+ public void testShouldHideCategory_typeNormal_returnFalse() {
mPowerUsageData.usageType = UsageType.APP;
- assertThat(mPowerUsageAdvanced.shouldHide(mPowerUsageData)).isFalse();
+ assertThat(mPowerUsageAdvanced.shouldHideCategory(mPowerUsageData)).isFalse();
}
+
+ @Test
+ public void testShouldHideSummary_typeCell_returnTrue() {
+ mPowerUsageData.usageType = UsageType.CELL;
+
+ assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isTrue();
+ }
+
+ @Test
+ public void testShouldHideSummary_typeNormal_returnFalse() {
+ mPowerUsageData.usageType = UsageType.APP;
+
+ assertThat(mPowerUsageAdvanced.shouldHideSummary(mPowerUsageData)).isFalse();
+ }
+
+ @Test
+ public void testShouldShowBatterySipper_typeScreen_returnFalse() {
+ mNormalBatterySipper.drainType = DrainType.SCREEN;
+
+ assertThat(mPowerUsageAdvanced.shouldShowBatterySipper(mNormalBatterySipper)).isFalse();
+ }
+
+ @Test
+ public void testShouldShowBatterySipper_typeNormal_returnTrue() {
+ mNormalBatterySipper.drainType = DrainType.APP;
+
+ assertThat(mPowerUsageAdvanced.shouldShowBatterySipper(mNormalBatterySipper)).isTrue();
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 72dd28e..5611371 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -36,7 +36,11 @@
import com.android.settings.TestConfig;
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
+import com.android.settings.core.PreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
+import com.android.settings.testutils.XmlTestUtils;
import com.android.settingslib.BatteryInfo;
import org.junit.Before;
@@ -74,7 +78,13 @@
*/
// TODO: Improve this test class so that it starts up the real activity and fragment.
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH,
+ sdk = TestConfig.SDK_VERSION,
+ shadows = {
+ SettingsShadowResources.class,
+ SettingsShadowResources.SettingsShadowTheme.class,
+ ShadowDynamicIndexableContentMonitor.class
+ })
public class PowerUsageSummaryTest {
private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"};
private static final String TIME_LEFT = "2h30min";
@@ -119,8 +129,6 @@
@Mock
private LayoutPreference mBatteryLayoutPref;
@Mock
- private BatteryMeterView mBatteryMeterView;
- @Mock
private TextView mBatteryPercentText;
@Mock
private TextView mSummary1;
@@ -141,6 +149,7 @@
private Context mRealContext;
private TestFragment mFragment;
private FakeFeatureFactory mFeatureFactory;
+ private BatteryMeterView mBatteryMeterView;
@Before
public void setUp() {
@@ -153,6 +162,8 @@
mFragment = spy(new TestFragment(mContext));
mFragment.initFeatureProvider();
+ mBatteryMeterView = new BatteryMeterView(mRealContext);
+ mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
when(mAdditionalBatteryInfoMenu.getItemId())
@@ -192,7 +203,7 @@
mFragment.mScreenUsagePref = mScreenUsagePref;
mFragment.mLastFullChargePref = mLastFullChargePref;
- mBatteryInfo.mBatteryLevel = BATTERY_LEVEL;
+ mBatteryInfo.batteryLevel = BATTERY_LEVEL;
}
@Test
@@ -317,6 +328,18 @@
}
@Test
+ public void testUpdatePreference_updateBatteryInfo() {
+ mBatteryInfo.remainingLabel = TIME_LEFT;
+ mBatteryInfo.batteryLevel = BATTERY_LEVEL;
+ mBatteryInfo.discharging = true;
+
+ mFragment.updateHeaderPreference(mBatteryInfo);
+
+ assertThat(mBatteryMeterView.mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
+ assertThat(mBatteryMeterView.mDrawable.getCharging()).isEqualTo(false);
+ }
+
+ @Test
public void testUpdatePreference_noRemainingTime_showStatusLabel() {
mBatteryInfo.remainingLabel = null;
@@ -402,6 +425,33 @@
TIME_SINCE_LAST_FULL_CHARGE_MS);
}
+ @Test
+ public void testNonIndexableKeys_MatchPreferenceKeys() {
+ final Context context = RuntimeEnvironment.application;
+ final List<String> niks = PowerUsageSummary.SEARCH_INDEX_DATA_PROVIDER
+ .getNonIndexableKeys(context);
+
+ final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context,
+ R.xml.power_usage_summary);
+
+ assertThat(keys).containsAllIn(niks);
+ }
+
+ @Test
+ public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
+ final Context context = RuntimeEnvironment.application;
+ final PowerUsageSummary fragment = new PowerUsageSummary();
+ final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context,
+ fragment.getPreferenceScreenResId());
+ final List<String> preferenceKeys = new ArrayList<>();
+
+ for (PreferenceController controller : fragment.getPreferenceControllers(context)) {
+ preferenceKeys.add(controller.getPreferenceKey());
+ }
+
+ assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys);
+ }
+
public static class TestFragment extends PowerUsageSummary {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
index 7cd76d3..ee6ef69 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
@@ -19,9 +19,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -39,6 +37,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -50,19 +49,21 @@
private Menu mMenu;
@Mock
private MenuItem mMenuItem;
+ @Mock
+ private NetworkResetRestrictionChecker mRestrictionChecker;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mController = spy(new NetworkResetActionMenuController(mContext));
+ mController = new NetworkResetActionMenuController(mContext);
+ ReflectionHelpers.setField(mController, "mRestrictionChecker", mRestrictionChecker);
when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);
}
@Test
public void buildMenuItem_available_shouldAddToMenu() {
- doReturn(true).when(mController).isAvailable();
-
+ when(mRestrictionChecker.hasRestriction()).thenReturn(false);
mController.buildMenuItem(mMenu);
verify(mMenu).add(anyInt(), anyInt(), anyInt(), anyInt());
@@ -71,7 +72,7 @@
@Test
public void buildMenuItem_notAvailable_shouldNotAddToMenu() {
- doReturn(false).when(mController).isAvailable();
+ when(mRestrictionChecker.hasRestriction()).thenReturn(true);
mController.buildMenuItem(mMenu);
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java
new file mode 100644
index 0000000..b1c88d5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+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.when;
+
+import android.content.Context;
+import android.os.UserManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class NetworkResetRestrictionCheckerTest {
+
+ @Mock
+ private UserManager mUserManager;
+ @Mock
+ private Context mContext;
+ private NetworkResetRestrictionChecker mRestrictionChecker;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+ mRestrictionChecker = spy(new NetworkResetRestrictionChecker(mContext));
+ }
+
+ @Test
+ public void testHasRestriction_notAdmin_shouldReturnTrue() {
+ final Context context = mock(Context.class);
+ when(context.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+ when(mUserManager.isAdminUser()).thenReturn(false);
+
+ assertThat(mRestrictionChecker.hasRestriction()).isTrue();
+ }
+
+ @Test
+ public void testHasRestriction_hasUserRestriction_shouldReturnTrue() {
+ when(mUserManager.isAdminUser()).thenReturn(true);
+ doReturn(true).when(mRestrictionChecker).hasUserBaseRestriction();
+ doReturn(false).when(mRestrictionChecker).isRestrictionEnforcedByAdmin();
+
+ assertThat(mRestrictionChecker.hasRestriction()).isTrue();
+ }
+
+ @Test
+ public void testHasRestriction_hasAdminRestriction_shouldReturnTrue() {
+ when(mUserManager.isAdminUser()).thenReturn(true);
+ doReturn(false).when(mRestrictionChecker).hasUserBaseRestriction();
+ doReturn(true).when(mRestrictionChecker).isRestrictionEnforcedByAdmin();
+
+ assertThat(mRestrictionChecker.hasRestriction()).isTrue();
+ }
+
+ @Test
+ public void testHasRestriction_noRestriction_shouldReturnFalse() {
+ when(mUserManager.isAdminUser()).thenReturn(true);
+ doReturn(false).when(mRestrictionChecker).hasUserBaseRestriction();
+ doReturn(false).when(mRestrictionChecker).isRestrictionEnforcedByAdmin();
+
+ assertThat(mRestrictionChecker.hasRestriction()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
index d996750..520e1f0 100644
--- a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
@@ -27,6 +27,7 @@
import com.android.settings.DefaultRingtonePreference;
import com.android.settings.R;
+import com.android.settings.RingtonePreference;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -251,4 +252,26 @@
verify(mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
.setSummary(eq(notAvailable));
}
+
+ @Test
+ public void onResume_shouldSetUserIdToPreference() {
+ final int managedProfileUserId = 10;
+ when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ .thenReturn(managedProfileUserId);
+ when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isSingleVolume()).thenReturn(false);
+ when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
+ when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
+
+ mController.displayPreference(mScreen);
+ mController.onResume();
+
+ verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
+ .setUserId(managedProfileUserId);
+ verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
+ .setUserId(managedProfileUserId);
+ verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
+ .setUserId(managedProfileUserId);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/search/DataIntegrityTest.java b/tests/robotests/src/com/android/settings/search/DataIntegrityTest.java
new file mode 100644
index 0000000..f10752a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/search/DataIntegrityTest.java
@@ -0,0 +1,123 @@
+package com.android.settings.search;
+
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+import android.util.ArraySet;
+import com.android.settings.DateTimeSettings;
+import com.android.settings.R;
+import com.android.settings.SecuritySettings;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.codeinspection.CodeInspector;
+import com.android.settings.datausage.DataUsageSummary;
+import com.android.settings.search2.DatabaseIndexingUtils;
+import com.android.settings.testutils.XmlTestUtils;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+ assetDir = "/tests/robotests/assets")
+public class DataIntegrityTest {
+
+ @Test
+ @Config(shadows = {
+ SettingsShadowResources.class,
+ SettingsShadowResources.SettingsShadowTheme.class,
+ })
+ public void testIndexableResources_uniqueKeys() {
+ final Context context = RuntimeEnvironment.application;
+ // Aggregation of all keys
+ final Set<String> masterKeys = new ArraySet<>();
+ // Aggregation of the incorrectly duplicate keys
+ final Set<String> duplicateKeys = new ArraySet<>();
+ // Keys for a specific page
+ final Set<String> pageKeys = new ArraySet<>();
+ // List of all Xml preferences
+ final Set<Integer> xmlList = new ArraySet<>();
+ // Duplicates we know about.
+ List<String> grandfatheredKeys = new ArrayList<>();
+ CodeInspector.initializeGrandfatherList(grandfatheredKeys,
+ "whitelist_duplicate_index_key");
+
+ // Get a list of all Xml.
+ for (SearchIndexableResource val : SearchIndexableResources.values()) {
+ final int xmlResId = val.xmlResId;
+ if (xmlResId != 0) {
+ xmlList.add(xmlResId);
+ } else {
+ // Take class and get all keys
+ final Class clazz = DatabaseIndexingUtils.getIndexableClass(val.className);
+
+ // Skip classes that are invalid or cannot be mocked. Add them as special Xml below.
+ if (clazz == null
+ || clazz == DateTimeSettings.class
+ || clazz == DataUsageSummary.class
+ || clazz == SecuritySettings.class) {
+ continue;
+ }
+
+ Indexable.SearchIndexProvider provider = DatabaseIndexingUtils
+ .getSearchIndexProvider(clazz);
+
+ if (provider == null) {
+ continue;
+ }
+
+ List<SearchIndexableResource> subXml =
+ provider.getXmlResourcesToIndex(context, true);
+
+ if (subXml == null) {
+ continue;
+ }
+ for (SearchIndexableResource resource : subXml) {
+ final int subXmlResId = resource.xmlResId;
+ if (subXmlResId != 0) {
+ xmlList.add(subXmlResId);
+ }
+ }
+ }
+ }
+ addSpecialXml(xmlList);
+
+ // Get keys from all Xml and check for duplicates.
+ for (Integer xmlResId : xmlList) {
+ // Get all keys to be indexed
+ final List<String> prefKeys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlResId);
+
+ pageKeys.addAll(prefKeys);
+ // Remove grandfathered keys.
+ pageKeys.removeAll(grandfatheredKeys);
+ // Find all already-existing keys.
+ pageKeys.retainAll(masterKeys);
+ // Keep list of offending duplicate keys.
+ duplicateKeys.addAll(pageKeys);
+ // Add all keys to master key list.
+ masterKeys.addAll(prefKeys);
+ pageKeys.clear();
+ }
+ assertThat(duplicateKeys).isEmpty();
+ }
+
+ /**
+ * Add XML preferences from Fragments which have issues being instantiated in robolectric.
+ */
+ private void addSpecialXml(Set<Integer> xmlList) {
+ xmlList.add(R.xml.date_time_prefs);
+ xmlList.add(R.xml.data_usage);
+ xmlList.add(R.xml.data_usage_cellular);
+ xmlList.add(R.xml.data_usage_wifi);
+ xmlList.add(R.xml.security_settings_misc);
+ }
+
+
+}
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
index f4370fc..474a3c4 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
@@ -17,35 +17,29 @@
package com.android.settings.search;
-import android.content.Context;
+import static com.google.common.truth.Truth.assertThat;
+import android.content.Context;
import android.util.ArrayMap;
+
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
-import com.android.settings.display.AutoBrightnessPreferenceController;
-import com.android.settings.gestures.DoubleTapPowerPreferenceController;
-import com.android.settings.gestures.DoubleTapScreenPreferenceController;
-import com.android.settings.gestures.DoubleTwistPreferenceController;
-import com.android.settings.gestures.PickupGesturePreferenceController;
-import com.android.settings.gestures.SwipeToNotificationPreferenceController;
+import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
import com.android.settings.search2.DatabaseIndexingUtils;
-
-import com.android.settings.search2.IntentPayload;
import com.android.settings.search2.ResultPayload;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
import java.util.Map;
-import static com.google.common.truth.Truth.assertThat;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DatabaseIndexingUtilsTest {
@@ -57,7 +51,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = ShadowApplication.getInstance().getApplicationContext();
+ mContext = RuntimeEnvironment.application;
}
@Test
@@ -74,11 +68,11 @@
@Test
public void testGetPreferenceControllerUriMap_CompatibleClass_ReturnsValidMap() {
- String className = "com.android.settings.DisplaySettings";
-
- Map map = DatabaseIndexingUtils.getPreferenceControllerUriMap(className, mContext);
- assertThat(map.get("auto_brightness"))
- .isInstanceOf(AutoBrightnessPreferenceController.class);
+ final String className = "com.android.settings.system.SystemDashboardFragment";
+ final Map<String, PreferenceController> map =
+ DatabaseIndexingUtils.getPreferenceControllerUriMap(className, mContext);
+ assertThat(map.get("system_update_settings"))
+ .isInstanceOf(SystemUpdatePreferenceController.class);
}
@Test
@@ -103,13 +97,13 @@
@Override
public ResultPayload getResultPayload() {
- return new IntentPayload(null);
+ return new ResultPayload(null);
}
};
- ArrayMap<String,PreferenceController> map = new ArrayMap<>();
+ ArrayMap<String, PreferenceController> map = new ArrayMap<>();
map.put(key, prefController);
ResultPayload payload = DatabaseIndexingUtils.getPayloadFromUriMap(map, key);
- assertThat(payload).isInstanceOf(IntentPayload.class);
+ assertThat(payload).isInstanceOf(ResultPayload.class);
}
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
index 701679c..03c7eed 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
@@ -17,6 +17,7 @@
package com.android.settings.search;
+import android.content.Intent;
import android.os.Parcel;
import android.util.ArrayMap;
import android.content.Context;
@@ -43,7 +44,7 @@
final int source = ResultPayload.SettingsSource.SECURE;
final Context context = ShadowApplication.getInstance().getApplicationContext();
- InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, null);
+ InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, null, null);
try {
payload.getSwitchValue(context);
fail("Should have thrown exception for null map");
@@ -59,7 +60,7 @@
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
final Context context = ShadowApplication.getInstance().getApplicationContext();
- InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
+ InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, null);
try {
payload.getSwitchValue(context);
fail("Should have thrown exception for bad map");
@@ -76,13 +77,19 @@
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
map.put(1, true);
map.put(0, false);
+ final String intentKey = "key";
+ final String intentVal = "value";
+ final Intent intent = new Intent();
+ intent.putExtra(intentKey, intentVal);
- InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
+ InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, intent);
+ final Intent retainedIntent = payload.getIntent();
assertThat(payload.settingsUri).isEqualTo(uri);
assertThat(payload.inlineType).isEqualTo(type);
assertThat(payload.settingSource).isEqualTo(source);
assertThat(payload.valueMap.get(1)).isTrue();
assertThat(payload.valueMap.get(0)).isFalse();
+ assertThat(retainedIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
}
@Test
@@ -93,20 +100,27 @@
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
map.put(1, true);
map.put(0, false);
+ final String intentKey = "key";
+ final String intentVal = "value";
+ final Intent intent = new Intent();
+ intent.putExtra(intentKey, intentVal);
Parcel parcel = Parcel.obtain();
parcel.writeString(uri);
parcel.writeInt(type);
parcel.writeInt(source);
+ parcel.writeParcelable(intent, 0);
parcel.writeMap(map);
parcel.setDataPosition(0);
InlineSwitchPayload payload = InlineSwitchPayload.CREATOR.createFromParcel(parcel);
+ final Intent builtIntent = payload.getIntent();
assertThat(payload.settingsUri).isEqualTo(uri);
assertThat(payload.inlineType).isEqualTo(type);
assertThat(payload.settingSource).isEqualTo(source);
assertThat(payload.valueMap.get(1)).isTrue();
assertThat(payload.valueMap.get(0)).isFalse();
+ assertThat(builtIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
}
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
index ba9feb3..c72d4e8 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
@@ -117,7 +117,7 @@
builder.addTitle(TITLE)
.addSummary(SUMMARY)
.addRank(1)
- .addPayload(new InlineSwitchPayload("", 0, null))
+ .addPayload(new InlineSwitchPayload("", 0, null, null))
.addBreadcrumbs(new ArrayList<>())
.addIcon(mIcon)
.addPayload(mPayload);
diff --git a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
index 012d616..89afcaa 100644
--- a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
@@ -19,9 +19,7 @@
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
import static com.android.settings.search.SearchIndexableResources.NO_DATA_RES_ID;
-import static com.android.settings.search.SearchIndexableResources.sResMap;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.annotation.DrawableRes;
@@ -35,12 +33,14 @@
import com.android.settings.TestConfig;
import com.android.settings.wifi.WifiSettings;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.HashMap;
+import java.util.Map;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -51,6 +51,21 @@
@DrawableRes
private static final int ICON_RES_ID = R.drawable.ic_settings_language;
+ Map<String, SearchIndexableResource> sResMapCopy;
+
+ @Before
+ public void setUp() {
+ sResMapCopy = new HashMap<>(SearchIndexableResources.sResMap);
+ }
+
+ @After
+ public void cleanUp() {
+ SearchIndexableResources.sResMap.clear();
+ for (String key : sResMapCopy.keySet()) {
+ SearchIndexableResources.sResMap.put(key, sResMapCopy.get(key));
+ }
+ }
+
@Test
public void testAddIndex() {
// Confirms that String.class isn't contained in SearchIndexableResources.
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
index f83b595..0c496c8 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
@@ -18,12 +18,12 @@
package com.android.settings.search;
import android.content.Context;
+import android.content.Intent;
import android.graphics.drawable.Drawable;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.search2.IntentPayload;
import com.android.settings.search2.ResultPayload;
import com.android.settings.search2.SearchResult;
import com.android.settings.search2.SearchResult.Builder;
@@ -57,7 +57,7 @@
mSummary = "summary";
mBreadcrumbs = new ArrayList<>();
mRank = 3;
- mResultPayload = new IntentPayload(null);
+ mResultPayload = new ResultPayload(new Intent());
final Context context = ShadowApplication.getInstance().getApplicationContext();
mIcon = context.getDrawable(R.drawable.ic_search_history);
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
index f5a29ce..3007f5e 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
@@ -31,9 +31,8 @@
import com.android.settings.search2.DatabaseResultLoader;
import com.android.settings.search2.InlineSwitchViewHolder;
import com.android.settings.search2.InstalledAppResultLoader;
-import com.android.settings.search2.IntentPayload;
-import com.android.settings.search2.IntentSearchViewHolder;
import com.android.settings.search2.ResultPayload;
+import com.android.settings.search2.IntentSearchViewHolder;
import com.android.settings.search2.SearchFeatureProvider;
import com.android.settings.search2.SearchFragment;
import com.android.settings.search2.SearchResult;
@@ -58,6 +57,7 @@
import static org.mockito.Mockito.when;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
@@ -76,6 +76,8 @@
private Context mContext;
private String mLoaderClassName;
+ private String[] TITLES = {"alpha", "bravo", "charlie", "appAlpha", "appBravo", "appCharlie"};
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -87,13 +89,13 @@
}
@Test
- public void testNoResultsAdded_EmptyListReturned() {
+ public void testNoResultsAdded_emptyListReturned() {
List<SearchResult> updatedResults = mAdapter.getSearchResults();
assertThat(updatedResults).isEmpty();
}
@Test
- public void testSingleSourceMerge_ExactCopyReturned() {
+ public void testSingleSourceMerge_exactCopyReturned() {
ArrayList<SearchResult> intentResults = getIntentSampleResults();
mAdapter.addSearchResults(intentResults, mLoaderClassName);
mAdapter.displaySearchResults("");
@@ -103,7 +105,7 @@
}
@Test
- public void testCreateViewHolder_ReturnsIntentResult() {
+ public void testCreateViewHolder_returnsIntentResult() {
ViewGroup group = new FrameLayout(mContext);
SearchViewHolder view = mAdapter.onCreateViewHolder(group,
ResultPayload.PayloadType.INTENT);
@@ -111,7 +113,7 @@
}
@Test
- public void testCreateViewHolder_ReturnsInlineSwitchResult() {
+ public void testCreateViewHolder_returnsInlineSwitchResult() {
ViewGroup group = new FrameLayout(mContext);
SearchViewHolder view = mAdapter.onCreateViewHolder(group,
ResultPayload.PayloadType.INLINE_SWITCH);
@@ -119,20 +121,42 @@
}
@Test
- public void testEndToEndSearch_ProperResultsMerged() {
- mAdapter.addSearchResults(getDummyAppResults(),
- InstalledAppResultLoader.class.getName());
- mAdapter.addSearchResults(getDummyDbResults(),
- DatabaseResultLoader.class.getName());
+ public void testEndToEndSearch_properResultsMerged_correctOrder() {
+ mAdapter.addSearchResults(getDummyAppResults(), InstalledAppResultLoader.class.getName());
+ mAdapter.addSearchResults(getDummyDbResults(), DatabaseResultLoader.class.getName());
int count = mAdapter.displaySearchResults("");
List<SearchResult> results = mAdapter.getSearchResults();
- assertThat(results.get(0).title).isEqualTo("alpha");
- assertThat(results.get(1).title).isEqualTo("appAlpha");
- assertThat(results.get(2).title).isEqualTo("appBravo");
- assertThat(results.get(3).title).isEqualTo("bravo");
- assertThat(results.get(4).title).isEqualTo("appCharlie");
- assertThat(results.get(5).title).isEqualTo("Charlie");
+ assertThat(results.get(0).title).isEqualTo(TITLES[0]); // alpha
+ assertThat(results.get(1).title).isEqualTo(TITLES[3]); // appAlpha
+ assertThat(results.get(2).title).isEqualTo(TITLES[4]); // appBravo
+ assertThat(results.get(3).title).isEqualTo(TITLES[1]); // bravo
+ assertThat(results.get(4).title).isEqualTo(TITLES[5]); // appCharlie
+ assertThat(results.get(5).title).isEqualTo(TITLES[2]); // charlie
+ assertThat(count).isEqualTo(6);
+ }
+
+ @Test
+ public void testEndToEndSearch_addResults_resultsAddedInOrder() {
+ List<AppSearchResult> appResults = getDummyAppResults();
+ List<SearchResult> dbResults = getDummyDbResults();
+ // Add two individual items
+ mAdapter.addSearchResults(appResults.subList(0,1),
+ InstalledAppResultLoader.class.getName());
+ mAdapter.addSearchResults(dbResults.subList(0,1), DatabaseResultLoader.class.getName());
+ mAdapter.displaySearchResults("");
+ // Add super-set of items
+ mAdapter.addSearchResults(appResults, InstalledAppResultLoader.class.getName());
+ mAdapter.addSearchResults(dbResults, DatabaseResultLoader.class.getName());
+ int count = mAdapter.displaySearchResults("");
+
+ List<SearchResult> results = mAdapter.getSearchResults();
+ assertThat(results.get(0).title).isEqualTo(TITLES[0]); // alpha
+ assertThat(results.get(1).title).isEqualTo(TITLES[3]); // appAlpha
+ assertThat(results.get(2).title).isEqualTo(TITLES[4]); // appBravo
+ assertThat(results.get(3).title).isEqualTo(TITLES[1]); // bravo
+ assertThat(results.get(4).title).isEqualTo(TITLES[5]); // appCharlie
+ assertThat(results.get(5).title).isEqualTo(TITLES[2]); // charlie
assertThat(count).isEqualTo(6);
}
@@ -147,26 +171,46 @@
@Test
public void testDisplayResults_ShouldRunSmartRankingIfEnabled() {
when(mSearchFeatureProvider.isSmartSearchRankingEnabled(any()))
- .thenReturn(true);
+ .thenReturn(true);
mAdapter.displaySearchResults("");
verify(mSearchFeatureProvider, times(1)).rankSearchResults(anyString(), anyList());
}
+ @Test
+ public void testEndToEndSearch_removeResults_resultsAdded() {
+ List<AppSearchResult> appResults = getDummyAppResults();
+ List<SearchResult> dbResults = getDummyDbResults();
+ // Add list of items
+ mAdapter.addSearchResults(appResults, InstalledAppResultLoader.class.getName());
+ mAdapter.addSearchResults(dbResults, DatabaseResultLoader.class.getName());
+ mAdapter.displaySearchResults("");
+ // Add subset of items
+ mAdapter.addSearchResults(appResults.subList(0,1),
+ InstalledAppResultLoader.class.getName());
+ mAdapter.addSearchResults(dbResults.subList(0,1), DatabaseResultLoader.class.getName());
+ int count = mAdapter.displaySearchResults("");
+
+ List<SearchResult> results = mAdapter.getSearchResults();
+ assertThat(results.get(0).title).isEqualTo(TITLES[0]);
+ assertThat(results.get(1).title).isEqualTo(TITLES[3]);
+ assertThat(count).isEqualTo(2);
+ }
+
private List<SearchResult> getDummyDbResults() {
List<SearchResult> results = new ArrayList<>();
- IntentPayload payload = new IntentPayload(new Intent());
+ ResultPayload payload = new ResultPayload(new Intent());
SearchResult.Builder builder = new SearchResult.Builder();
builder.addPayload(payload);
- builder.addTitle("alpha")
+ builder.addTitle(TITLES[0])
.addRank(1);
results.add(builder.build());
- builder.addTitle("bravo")
+ builder.addTitle(TITLES[1])
.addRank(3);
results.add(builder.build());
- builder.addTitle("Charlie")
+ builder.addTitle(TITLES[2])
.addRank(6);
results.add(builder.build());
@@ -175,19 +219,19 @@
private List<AppSearchResult> getDummyAppResults() {
List<AppSearchResult> results = new ArrayList<>();
- IntentPayload payload = new IntentPayload(new Intent());
+ ResultPayload payload = new ResultPayload(new Intent());
AppSearchResult.Builder builder = new AppSearchResult.Builder();
builder.addPayload(payload);
- builder.addTitle("appAlpha")
+ builder.addTitle(TITLES[3])
.addRank(1);
results.add(builder.build());
- builder.addTitle("appBravo")
+ builder.addTitle(TITLES[4])
.addRank(2);
results.add(builder.build());
- builder.addTitle("appCharlie")
+ builder.addTitle(TITLES[5])
.addRank(4);
results.add(builder.build());
@@ -198,7 +242,7 @@
ArrayList<SearchResult> sampleResults = new ArrayList<>();
ArrayList<String> breadcrumbs = new ArrayList<>();
final Drawable icon = mContext.getDrawable(R.drawable.ic_search_history);
- final ResultPayload payload = new IntentPayload(null);
+ final ResultPayload payload = new ResultPayload(null);
final SearchResult.Builder builder = new Builder();
builder.addTitle("title")
.addSummary("summary")
diff --git a/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java b/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java
index ab55605..7d05729 100644
--- a/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java
@@ -20,7 +20,9 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.database.Cursor;
import android.database.MatrixCursor;
+import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.util.ArrayMap;
@@ -58,6 +60,7 @@
private static final String TARGET_PACKAGE = "a.b.c";
private static final String TARGET_CLASS = "a.b.c.class";
private static final String QUERY = "query";
+ private static final String KEY = "key";
private static final Intent INTENT = new Intent("com.android.settings");
private static final int ICON = R.drawable.ic_search_history;
private static final int BASE_RANK = 1;
@@ -78,20 +81,20 @@
@Test
public void testParseNullResults_ReturnsNull() {
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, null, BASE_RANK);
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, null, BASE_RANK);
assertThat(results).isNull();
}
@Test
public void testParseCursor_NotNull() {
- List<SearchResult> results = mConverter.convertCursor(
+ final List<SearchResult> results = mConverter.convertCursor(
mSiteMapManager, getDummyCursor(), BASE_RANK);
assertThat(results).isNotNull();
}
@Test
public void testParseCursor_MatchesRank() {
- List<SearchResult> results = mConverter.convertCursor(
+ final List<SearchResult> results = mConverter.convertCursor(
mSiteMapManager, getDummyCursor(), BASE_RANK);
for (int i = 0; i < EXAMPLES; i++) {
assertThat(results.get(i).rank).isEqualTo(BASE_RANK);
@@ -100,7 +103,7 @@
@Test
public void testParseCursor_MatchesTitle() {
- List<SearchResult> results = mConverter.convertCursor(
+ final List<SearchResult> results = mConverter.convertCursor(
mSiteMapManager, getDummyCursor(), BASE_RANK);
for (int i = 0; i < EXAMPLES; i++) {
assertThat(results.get(i).title).isEqualTo(TITLES[i]);
@@ -109,7 +112,7 @@
@Test
public void testParseCursor_MatchesSummary() {
- List<SearchResult> results = mConverter.convertCursor(
+ final List<SearchResult> results = mConverter.convertCursor(
mSiteMapManager, getDummyCursor(), BASE_RANK);
for (int i = 0; i < EXAMPLES; i++) {
assertThat(results.get(i).summary).isEqualTo(SUMMARY);
@@ -118,19 +121,38 @@
@Test
public void testParseCursor_MatchesIcon() {
- List<SearchResult> results = mConverter.convertCursor(
- mSiteMapManager, getDummyCursor(), BASE_RANK);
- for (int i = 0; i < EXAMPLES; i++) {
- Drawable resultDrawable = results.get(i).icon;
- assertThat(resultDrawable).isNotNull();
- assertThat(resultDrawable.toString()).isEqualTo(mDrawable.toString());
- }
+ final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
+ final String BLANK = "";
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ "Longer than 20 characters", // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ DisplaySettings.class.getName(),
+ BLANK, // screen title
+ ICON, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ BLANK, // Key
+ PayloadType.INTENT, // Payload Type
+ payload // Payload
+ });
+
+ final List<SearchResult> results = mConverter.convertCursor(
+ mSiteMapManager, cursor, BASE_RANK);
+
+ Drawable resultDrawable = results.get(0).icon;
+ assertThat(resultDrawable).isNotNull();
+ assertThat(resultDrawable.toString()).isEqualTo(mDrawable.toString());
}
@Test
public void testParseCursor_NoIcon() {
- List<SearchResult> results = mConverter.convertCursor(
- mSiteMapManager, getDummyCursor(false /* hasIcon */), BASE_RANK);
+ final List<SearchResult> results = mConverter.convertCursor(
+ mSiteMapManager, getDummyCursor(false /* hasIcon */, "" /* className */,
+ "" /* key */), BASE_RANK);
for (int i = 0; i < EXAMPLES; i++) {
Drawable resultDrawable = results.get(i).icon;
assertThat(resultDrawable).isNull();
@@ -139,7 +161,7 @@
@Test
public void testParseCursor_MatchesPayloadType() {
- List<SearchResult> results = mConverter.convertCursor(
+ final List<SearchResult> results = mConverter.convertCursor(
mSiteMapManager, getDummyCursor(), BASE_RANK);
ResultPayload payload;
for (int i = 0; i < EXAMPLES; i++) {
@@ -150,7 +172,8 @@
@Test
public void testLongTitle_PenalizedInRank() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
final String BLANK = "";
cursor.addRow(new Object[]{
ID, // Doc ID
@@ -164,75 +187,26 @@
null, // target package
BLANK, // target class
BLANK, // Key
- 0, // Payload Type
- null // Payload
+ PayloadType.INTENT, // Payload Type
+ payload // Payload
});
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(BASE_RANK + 2);
}
@Test
- public void testParseCursor_MatchesIntentForSubSettings() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- SwipeToNotificationSettings.class.getName(),
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- BLANK, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
- IntentPayload payload = (IntentPayload) results.get(0).payload;
- Intent intent = payload.intent;
- assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
- }
-
- @Test
- public void testParseCursor_MatchesIntentPayload() {
- List<SearchResult> results = mConverter.convertCursor(
+ public void testParseCursor_MatchesResultPayload() {
+ final List<SearchResult> results = mConverter.convertCursor(
mSiteMapManager, getDummyCursor(), BASE_RANK);
- IntentPayload payload;
+ ResultPayload payload;
for (int i = 0; i < EXAMPLES; i++) {
- payload = (IntentPayload) results.get(i).payload;
- Intent intent = payload.intent;
+ payload = results.get(i).payload;
+ Intent intent = payload.getIntent();
assertThat(intent.getAction()).isEqualTo(INTENT.getAction());
}
}
- @Test
- public void testParseCursor_MatchesIntentPayloadForExternalApps() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- null, // class
- TITLES[0], // Title
- null, // icon
- Intent.ACTION_VIEW, // action
- TARGET_PACKAGE, // target package
- TARGET_CLASS, // target class
- QUERY, // Key
- PayloadType.INTENT, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
- IntentPayload payload = (IntentPayload) results.get(0).payload;
- Intent intent = payload.intent;
-
- assertThat(intent.getComponent().getPackageName()).isEqualTo(TARGET_PACKAGE);
- assertThat(intent.getComponent().getClassName()).isEqualTo(TARGET_CLASS);
- }
@Test
public void testParseCursor_MatchesInlineSwitchPayload() {
@@ -244,7 +218,11 @@
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
map.put(1, true);
map.put(0, false);
- final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
+ final String intentKey = "key";
+ final String intentVal = "value";
+ final Intent intent = new Intent();
+ intent.putExtra(intentKey, intentVal);
+ final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, intent);
cursor.addRow(new Object[]{
ID, // Doc ID
@@ -261,14 +239,16 @@
type, // Payload Type
ResultPayloadUtils.marshall(payload) // Payload
});
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
- InlineSwitchPayload newPayload = (InlineSwitchPayload) results.get(0).payload;
-
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
+ final InlineSwitchPayload newPayload = (InlineSwitchPayload) results.get(0).payload;
+ final Intent rebuiltIntent = newPayload.getIntent();
assertThat(newPayload.settingsUri).isEqualTo(uri);
assertThat(newPayload.inlineType).isEqualTo(type);
assertThat(newPayload.settingSource).isEqualTo(source);
assertThat(newPayload.valueMap.get(1)).isTrue();
assertThat(newPayload.valueMap.get(0)).isFalse();
+ assertThat(rebuiltIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
}
// The following tests are temporary, and should be removed when we replace the Search
@@ -276,77 +256,28 @@
@Test
public void testWifiKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "main_toggle_wifi";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@Test
public void testBluetoothKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "main_toggle_bluetooth";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@Test
public void testAirplaneKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "toggle_airplane";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
@@ -354,156 +285,60 @@
@Test
public void testHotspotKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "tether_settings";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@Test
public void testBatterySaverKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "battery_saver";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@Test
public void testNFCKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "toggle_nfc";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@Test
public void testDataSaverKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "restrict_background";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@Test
public void testDataUsageKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "data_usage_enable";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@Test
public void testRoamingKey_PrioritizedResult() {
- MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
- final String BLANK = "";
final String key = "button_roaming_key";
-
- cursor.addRow(new Object[]{
- ID, // Doc ID
- TITLES[0], // Title
- SUMMARY, // Summary on
- SUMMARY, // summary off
- WifiSettings.class.getName(), // ClassName
- BLANK, // screen title
- null, // icon
- BLANK, // action
- null, // target package
- BLANK, // target class
- key, // Key
- 0, // Payload Type
- null // Payload
- });
- List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
+ final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
+ BASE_RANK);
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
}
@@ -511,28 +346,33 @@
// End of temporary tests
private MatrixCursor getDummyCursor() {
- return getDummyCursor(true /* hasIcon */);
+ return getDummyCursor(true /* hasIcon */, KEY, "" /* className */);
}
- private MatrixCursor getDummyCursor(boolean hasIcon) {
+ private MatrixCursor getDummyCursor(String key, String className) {
+ return getDummyCursor(false, key, className);
+ }
+
+ private MatrixCursor getDummyCursor(boolean hasIcon, String key, String className) {
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
final String BLANK = "";
+ final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
for (int i = 0; i < EXAMPLES; i++) {
- ArrayList<String> item = new ArrayList<>(DatabaseResultLoader.SELECT_COLUMNS.length);
+ ArrayList<Object> item = new ArrayList<>(DatabaseResultLoader.SELECT_COLUMNS.length);
item.add(ID + i); // Doc ID
item.add(TITLES[i]); // Title
item.add(SUMMARY); // Summary on
item.add(BLANK); // summary off
- item.add(BLANK); // classname
+ item.add(className); // classname
item.add(BLANK); // screen title
item.add(hasIcon ? Integer.toString(ICON) : null); // Icon
item.add(INTENT.getAction()); // Intent action
- item.add(BLANK); // target package
- item.add(BLANK); // target class
- item.add(BLANK); // Key
+ item.add(TARGET_PACKAGE); // target package
+ item.add(TARGET_CLASS); // target class
+ item.add(key); // Key
item.add(Integer.toString(0)); // Payload Type
- item.add(null); // Payload
+ item.add(payload); // Payload
cursor.addRow(item);
}
diff --git a/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java b/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java
index aa4e4f9..0e89e04 100644
--- a/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java
+++ b/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java
@@ -225,7 +225,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
@Test
@@ -319,7 +322,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload - should be updated to real payloads as controllers are added
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
@Test
@@ -401,7 +407,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload - should be updated to real payloads as controllers are added
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
@Test
@@ -455,7 +464,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload - should be updated to real payloads as controllers are added
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
@Test
@@ -509,7 +521,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload - should be updated to real payloads as controllers are added
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
// Tests for the flow: IndexOneResource -> IndexFromProvider -> IndexFromResource ->
@@ -578,7 +593,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload - should be updated to real payloads as controllers are added
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
@Test
@@ -643,7 +661,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload - should be updated to real payloads as controllers are added
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
@Test
@@ -880,7 +901,10 @@
// Payload Type - default is 0
assertThat(cursor.getInt(19)).isEqualTo(0);
// Payload
- assertThat(cursor.getBlob(20)).isNull();
+ byte[] payload = cursor.getBlob(20);
+ ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
+ ResultPayload.CREATOR);
+ assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/search2/DatabaseResultLoaderTest.java b/tests/robotests/src/com/android/settings/search2/DatabaseResultLoaderTest.java
index 8b97a91..3b65913 100644
--- a/tests/robotests/src/com/android/settings/search2/DatabaseResultLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/search2/DatabaseResultLoaderTest.java
@@ -59,6 +59,7 @@
private SiteMapManager mSiteMapManager;
private Context mContext;
private DatabaseResultLoader loader;
+ private ResultPayload mResultPayload;
private final String titleOne = "titleOne";
private final String titleTwo = "titleTwo";
@@ -74,6 +75,7 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
+ mResultPayload = new ResultPayload(new Intent());
FakeFeatureFactory.setupForTest(mMockContext);
FakeFeatureFactory factory =
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
@@ -215,12 +217,11 @@
public void testDeDupe_noDuplicates_originalListReturn() {
// Three elements with unique titles and summaries
List<SearchResult> results = new ArrayList();
- IntentPayload intentPayload = new IntentPayload(new Intent());
SearchResult.Builder builder = new SearchResult.Builder();
builder.addTitle(titleOne)
.addSummary(summaryOne)
- .addPayload(intentPayload);
+ .addPayload(mResultPayload);
SearchResult resultOne = builder.build();
results.add(resultOne);
@@ -245,13 +246,12 @@
@Test
public void testDeDupe_oneDuplicate_duplicateRemoved() {
List<SearchResult> results = new ArrayList();
- IntentPayload intentPayload = new IntentPayload(new Intent());
SearchResult.Builder builder = new SearchResult.Builder();
builder.addTitle(titleOne)
.addSummary(summaryOne)
.addRank(0)
- .addPayload(intentPayload);
+ .addPayload(mResultPayload);
SearchResult resultOne = builder.build();
results.add(resultOne);
@@ -278,9 +278,7 @@
@Test
public void testDeDupe_firstDupeInline_secondDuplicateRemoved() {
List<SearchResult> results = new ArrayList();
- InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0,
- null);
- IntentPayload intentPayload = new IntentPayload(new Intent());
+ InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0, null, null);
SearchResult.Builder builder = new SearchResult.Builder();
// Inline result
@@ -295,7 +293,7 @@
builder.addTitle(titleOne)
.addSummary(summaryOne)
.addRank(1)
- .addPayload(intentPayload);
+ .addPayload(mResultPayload);
SearchResult resultTwo = builder.build();
results.add(resultTwo);
@@ -329,23 +327,20 @@
* (1) Intent One
*/
List<SearchResult> results = new ArrayList();
- InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0,
- null);
- IntentPayload intentPayload = new IntentPayload(new Intent());
-
+ InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0, null, null);
SearchResult.Builder builder = new SearchResult.Builder();
// Intent One
builder.addTitle(titleOne)
.addSummary(summaryOne)
- .addPayload(intentPayload);
+ .addPayload(mResultPayload);
SearchResult resultOne = builder.build();
results.add(resultOne);
// Intent Two
builder.addTitle(titleTwo)
.addSummary(summaryTwo)
- .addPayload(intentPayload);
+ .addPayload(mResultPayload);
SearchResult resultTwo = builder.build();
results.add(resultTwo);
@@ -365,7 +360,7 @@
// Intent Four
builder.addTitle(titleFour)
.addSummary(summaryOne)
- .addPayload(intentPayload);
+ .addPayload(mResultPayload);
SearchResult resultFive = builder.build();
results.add(resultFive);
@@ -395,6 +390,7 @@
private void insertSpecialCase(String specialCase) {
String normalized = DatabaseIndexingUtils.normalizeHyphen(specialCase);
normalized = DatabaseIndexingUtils.normalizeString(normalized);
+ final ResultPayload payload = new ResultPayload(new Intent());
ContentValues values = new ContentValues();
values.put(IndexDatabaseHelper.IndexColumns.DOCID, normalized.hashCode());
@@ -419,12 +415,14 @@
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
- values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
+ values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, ResultPayloadUtils.marshall(payload));
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
}
private void setUpDb() {
+ final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(new Intent()));
+
ContentValues values = new ContentValues();
values.put(IndexDatabaseHelper.IndexColumns.DOCID, 0);
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
@@ -448,7 +446,7 @@
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
- values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
+ values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
@@ -475,7 +473,7 @@
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
- values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
+ values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
values = new ContentValues();
@@ -501,7 +499,7 @@
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
- values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
+ values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
}
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseRowTest.java b/tests/robotests/src/com/android/settings/search2/DatabaseRowTest.java
similarity index 61%
rename from tests/robotests/src/com/android/settings/search/DatabaseRowTest.java
rename to tests/robotests/src/com/android/settings/search2/DatabaseRowTest.java
index 34626bd..f3a25ed 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseRowTest.java
+++ b/tests/robotests/src/com/android/settings/search2/DatabaseRowTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -10,32 +10,37 @@
* 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 static for the specific language governing permissions and
+ * See the License for the specific language governing permissions and
* limitations under the License.
*
*/
-package com.android.settings.search;
+package com.android.settings.search2;
+import android.content.ComponentName;
import android.content.Intent;
+import android.content.Context;
+
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow;
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow.Builder;
-import com.android.settings.search2.IntentPayload;
-import com.android.settings.search2.ResultPayload;
-import com.android.settings.search2.ResultPayloadUtils;
+
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.Result;
import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import java.util.HashMap;
+
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DatabaseRowTest {
- private Builder builder;
+ private Builder mBuilder;
private static final String LOCALE = "locale";
private static final String UPDATED_TITLE = "updated title";
@@ -46,7 +51,7 @@
private static final String NORMALIZED_SUMMARY_OFF = "normalized summary off";
private static final String ENTRIES = "entries";
private static final String CLASS_NAME = "class name";
- private static final String SCREEN_TITLE = "sceen title";
+ private static final String SCREEN_TITLE = "screen title";
private static final int ICON_RES_ID = 0xff;
private static final int RANK = 1;
private static final String SPACE_DELIMITED_KEYWORDS = "keywords";
@@ -56,28 +61,23 @@
private static final boolean ENABLED = true;
private static final String KEY = "key";
private static final int USER_ID = 1;
- private static IntentPayload intentPayload;
- private final String EXTRA_KEY = "key";
- private final String EXTRA_VALUE = "value";
+ private Context mContext;
@Before
public void setUp() {
- Intent intent = new Intent();
- intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
- intentPayload = new IntentPayload(intent);
-
- builder = new DatabaseRow.Builder();
+ mContext = RuntimeEnvironment.application;
+ mBuilder = createBuilder();
}
@Test
- public void testFullRowBuild_NonNull() {
+ public void testFullRowBuild_nonNull() {
DatabaseRow row = generateRow();
assertThat(row).isNotNull();
}
@Test
- public void testPrimativesBuild_NoDataLoss() {
+ public void testPrimitivesBuild_noDataLoss() {
DatabaseRow row = generateRow();
assertThat(row.locale).isEqualTo(LOCALE);
@@ -100,30 +100,61 @@
assertThat(row.userId).isEqualTo(USER_ID);
assertThat(row.key).isEqualTo(KEY);
assertThat(row.payloadType).isEqualTo(ResultPayload.PayloadType.INTENT);
+ assertThat(row.payload).isNotNull();
}
@Test
- public void testPayload_PayloadTypeAdded() {
- DatabaseRow row = generateRow();
- byte[] marshalledPayload = row.payload;
- IntentPayload payload = ResultPayloadUtils.unmarshall(marshalledPayload,
- IntentPayload.CREATOR);
-
- Intent intent = payload.intent;
- assertThat(intent.getExtra(EXTRA_KEY)).isEqualTo(EXTRA_VALUE);
+ public void testGenericIntent_addedToPayload() {
+ final DatabaseRow row = generateRow();
+ final ResultPayload payload = ResultPayloadUtils.unmarshall(row.payload,
+ ResultPayload.CREATOR);
+ final ComponentName name = payload.getIntent().getComponent();
+ assertThat(name.getClassName()).isEqualTo(INTENT_TARGET_CLASS);
+ assertThat(name.getPackageName()).isEqualTo(INTENT_TARGET_PACKAGE);
}
@Test
- public void TestNullPayload_NoCrash() {
- Builder builder = new Builder();
- builder.setPayload(null);
- DatabaseRow row = builder.build();
+ public void testRowWithInlinePayload_genericPayloadNotAdded() {
+ final String URI = "test uri";
+ final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0,
+ new HashMap<Integer, Boolean>(), null);
+ mBuilder.setPayload(payload);
+ final DatabaseRow row = generateRow();
+ final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
+ .unmarshall(row.payload, InlineSwitchPayload.CREATOR);
- assertThat(row.payload).isNull();
+ assertThat(row.payloadType).isEqualTo(ResultPayload.PayloadType.INLINE_SWITCH);
+ assertThat(unmarshalledPayload.settingsUri).isEqualTo(URI);
}
+ @Test
+ public void testRowWithInlinePayload_intentAddedToInlinePayload() {
+ final String URI = "test uri";
+ final ComponentName component = new ComponentName(INTENT_TARGET_PACKAGE,
+ INTENT_TARGET_CLASS);
+ final Intent intent = new Intent();
+ intent.setComponent(component);
+
+ final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0,
+ new HashMap<Integer, Boolean>(), intent);
+ mBuilder.setPayload(payload);
+ final DatabaseRow row = generateRow();
+ final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
+ .unmarshall(row.payload, InlineSwitchPayload.CREATOR);
+ final ComponentName name = unmarshalledPayload.getIntent().getComponent();
+
+ assertThat(name.getClassName()).isEqualTo(INTENT_TARGET_CLASS);
+ assertThat(name.getPackageName()).isEqualTo(INTENT_TARGET_PACKAGE);
+ }
+
+
private DatabaseRow generateRow() {
- builder.setLocale(LOCALE)
+ return mBuilder.build(mContext);
+ }
+
+ private DatabaseRow.Builder createBuilder() {
+ mBuilder = new DatabaseRow.Builder();
+ mBuilder.setLocale(LOCALE)
.setUpdatedTitle(UPDATED_TITLE)
.setNormalizedTitle(NORMALIZED_TITLE)
.setUpdatedSummaryOn(UPDATED_SUMMARY_ON)
@@ -141,10 +172,7 @@
.setIntentTargetClass(INTENT_TARGET_CLASS)
.setEnabled(ENABLED)
.setKey(KEY)
- .setUserId(USER_ID)
- .setPayload(intentPayload);
-
- return(builder.build());
+ .setUserId(USER_ID);
+ return mBuilder;
}
-}
-;
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java b/tests/robotests/src/com/android/settings/search2/IntentSearchViewHolderTest.java
similarity index 90%
rename from tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
rename to tests/robotests/src/com/android/settings/search2/IntentSearchViewHolderTest.java
index 7ba77df..477c03b 100644
--- a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search2/IntentSearchViewHolderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*
*/
-package com.android.settings.search;
+package com.android.settings.search2;
import android.content.ComponentName;
import android.content.Context;
@@ -29,10 +29,6 @@
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.search2.IntentPayload;
-import com.android.settings.search2.IntentSearchViewHolder;
-import com.android.settings.search2.SearchFragment;
-import com.android.settings.search2.SearchResult;
import com.android.settings.search2.SearchResult.Builder;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -105,7 +101,7 @@
verify(mFragment).startActivity(any(Intent.class));
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
eq(MetricsProto.MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_RESULT),
- eq(((IntentPayload)result.payload).intent.getComponent().flattenToString()),
+ eq(((ResultPayload)result.payload).getIntent().getComponent().flattenToString()),
any(Pair.class));
}
@@ -113,7 +109,7 @@
public void testBindViewElements_emptySummary_hideSummaryView() {
final SearchResult result = new Builder().addTitle(TITLE)
.addRank(1)
- .addPayload(new IntentPayload(null))
+ .addPayload(new ResultPayload(null))
.addIcon(mIcon)
.build();
@@ -129,7 +125,7 @@
breadcrumbs.add("c");
final SearchResult result = new Builder().addTitle(TITLE)
.addRank(1)
- .addPayload(new IntentPayload(null))
+ .addPayload(new ResultPayload(null))
.addBreadcrumbs(breadcrumbs)
.addIcon(mIcon)
.build();
@@ -144,7 +140,7 @@
builder.addTitle(TITLE)
.addSummary(SUMMARY)
.addRank(1)
- .addPayload(new IntentPayload(
+ .addPayload(new ResultPayload(
new Intent().setComponent(new ComponentName("pkg", "class"))))
.addBreadcrumbs(new ArrayList<>())
.addIcon(mIcon);
diff --git a/tests/robotests/src/com/android/settings/search/IntentPayloadTest.java b/tests/robotests/src/com/android/settings/search2/ResultPayloadTest.java
similarity index 75%
rename from tests/robotests/src/com/android/settings/search/IntentPayloadTest.java
rename to tests/robotests/src/com/android/settings/search2/ResultPayloadTest.java
index 6f42622..02906ab 100644
--- a/tests/robotests/src/com/android/settings/search/IntentPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search2/ResultPayloadTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,13 +15,12 @@
*
*/
-package com.android.settings.search;
+package com.android.settings.search2;
import android.content.Intent;
import android.os.Parcel;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.search2.IntentPayload;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,8 +30,8 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class IntentPayloadTest {
- private IntentPayload mPayload;
+public class ResultPayloadTest {
+ private ResultPayload mPayload;
private final String EXTRA_KEY = "key";
private final String EXTRA_VALUE = "value";
@@ -43,14 +42,14 @@
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
Parcel parcel = Parcel.obtain();
- mPayload = new IntentPayload(intent);
+ mPayload = new ResultPayload(intent);
mPayload.writeToParcel(parcel, 0);
// Reset parcel for reading
parcel.setDataPosition(0);
- IntentPayload newPayload = IntentPayload.CREATOR.createFromParcel(parcel);
+ ResultPayload newPayload = ResultPayload.CREATOR.createFromParcel(parcel);
- String originalIntentExtra = mPayload.intent.getStringExtra(EXTRA_KEY);
- String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
+ String originalIntentExtra = mPayload.getIntent().getStringExtra(EXTRA_KEY);
+ String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
}
}
diff --git a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java b/tests/robotests/src/com/android/settings/search2/ResultPayloadUtilsTest.java
similarity index 73%
rename from tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
rename to tests/robotests/src/com/android/settings/search2/ResultPayloadUtilsTest.java
index 3875d86..e9a834a 100644
--- a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search2/ResultPayloadUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,28 +15,23 @@
*
*/
-package com.android.settings.search;
+package com.android.settings.search2;
import android.content.Intent;
-import android.os.BadParcelableException;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.search2.IntentPayload;
-import com.android.settings.search2.ResultPayloadUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
-import java.io.StreamCorruptedException;
-
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.fail;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ResultPayloadUtilsTest {
- private IntentPayload payload;
+ private ResultPayload payload;
private final String EXTRA_KEY = "key";
private final String EXTRA_VALUE = "value";
@@ -45,14 +40,14 @@
public void setUp() {
Intent intent = new Intent();
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
- payload = new IntentPayload(intent);
+ payload = new ResultPayload(intent);
}
@Test
public void testUnmarshallBadData_ExceptionThrown() {
byte[] badData = "I'm going to fail :)".getBytes();
try {
- ResultPayloadUtils.unmarshall(badData, IntentPayload.CREATOR);
+ ResultPayloadUtils.unmarshall(badData, ResultPayload.CREATOR);
fail("unmarshall should throw exception");
} catch ( RuntimeException e) {
assertThat(e).isNotNull();
@@ -60,7 +55,7 @@
}
@Test
- public void testMarshallIntentPayload_NonEmptyArray() {
+ public void testMarshallResultPayload_NonEmptyArray() {
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
assertThat(marshalledPayload).isNotNull();
assertThat(marshalledPayload).isNotEmpty();
@@ -69,11 +64,11 @@
@Test
public void testUnmarshall_PreservedData() {
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
- IntentPayload newPayload = ResultPayloadUtils.unmarshall(marshalledPayload,
- IntentPayload.CREATOR);
+ ResultPayload newPayload = ResultPayloadUtils.unmarshall(marshalledPayload,
+ ResultPayload.CREATOR);
- String originalIntentExtra = payload.intent.getStringExtra(EXTRA_KEY);
- String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
+ String originalIntentExtra = payload.getIntent().getStringExtra(EXTRA_KEY);
+ String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
}
diff --git a/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java b/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
new file mode 100644
index 0000000..20b3f89
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
@@ -0,0 +1,57 @@
+package com.android.settings.testutils;
+
+import android.content.res.Resources;
+import android.content.res.XmlResourceParser;
+
+import android.content.Context;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.util.Xml;
+import com.android.settings.search2.XmlParserUtils;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Util class for parsing XML
+ */
+public class XmlTestUtils {
+
+ /**
+ * Parses a preference screen's xml, collects and returns all keys used by preferences
+ * on the screen.
+ *
+ * @param context of the preference screen.
+ * @param xmlId of the Preference Xml to be parsed.
+ * @return List of all keys in the preference Xml
+ */
+ public static List<String> getKeysFromPreferenceXml(Context context, int xmlId) {
+ final XmlResourceParser parser = context.getResources().getXml(xmlId);
+ final AttributeSet attrs = Xml.asAttributeSet(parser);
+ final List<String> keys = new ArrayList<>();
+ String key;
+ try {
+ while (parser.next() != XmlPullParser.END_DOCUMENT) {
+ try {
+ key = XmlParserUtils.getDataKey(context, attrs);
+ if (!TextUtils.isEmpty(key)) {
+ keys.add(key);
+ }
+ } catch (NullPointerException e) {
+ continue;
+ } catch (Resources.NotFoundException e) {
+ continue;
+ }
+ }
+ } catch (java.io.IOException e) {
+ return null;
+ } catch (XmlPullParserException e) {
+ return null;
+ }
+
+ return keys;
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
index e87e9c5..724909d 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
@@ -5,9 +5,12 @@
import android.content.res.Resources.NotFoundException;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
+import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.ArrayRes;
+import android.support.annotation.ColorRes;
+import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
@@ -53,6 +56,14 @@
}
@Implementation
+ public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException {
+ if (id == R.color.battery_icon_color_error) {
+ return Color.WHITE;
+ }
+ return directlyOn(realResources, Resources.class).getColor(id, theme);
+ }
+
+ @Implementation
public Drawable loadDrawable(TypedValue value, int id, Theme theme)
throws NotFoundException {
// The drawable item in switchbar_background.xml refers to a very recent color attribute
diff --git a/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java b/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java
index 4267ed1..4ee42e0 100644
--- a/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java
@@ -16,16 +16,17 @@
package com.android.settings.utils;
-import com.android.settings.TestConfig;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
-@RunWith(RobolectricTestRunner.class)
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ThreadUtilsTest {
diff --git a/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java
index e4d303c..3747dda 100644
--- a/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java
@@ -91,6 +91,19 @@
}
@Test
+ public void setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound() {
+ final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ LayoutInflater.from(mContext).inflate(
+ R.layout.preference_widget_master_switch, null));
+ final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
+
+ preference.setSwitchEnabled(false);
+ preference.onBindViewHolder(holder);
+ assertThat(toggle.isEnabled()).isFalse();
+ }
+
+ @Test
public void clickWidgetView_shouldToggleButton() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
@@ -109,6 +122,22 @@
}
@Test
+ public void clickWidgetView_shouldNotToggleButtonIfDisabled() {
+ final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ inflater.inflate(R.layout.preference_two_target, null));
+ final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
+ inflater.inflate(R.layout.preference_widget_master_switch, widgetView, true);
+ final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
+ preference.onBindViewHolder(holder);
+ toggle.setEnabled(false);
+
+ widgetView.performClick();
+ assertThat(toggle.isChecked()).isFalse();
+ }
+
+ @Test
public void clickWidgetView_shouldNotifyPreferenceChanged() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
diff --git a/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
new file mode 100644
index 0000000..96cb217
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.settings.LinkifyUtils;
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LinkablePreferenceTest {
+
+ private static final String TITLE = "Title";
+
+ private Context mContext = RuntimeEnvironment.application;
+
+ private LinkablePreference mPreference;
+ private PreferenceViewHolder mHolder;
+ private View mView;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mPreference = new LinkablePreference(mContext);
+ final CharSequence linkableDescription =
+ mContext.getResources().getText(R.string.wifi_scan_notify_text);
+ final LinkifyUtils.OnClickListener clickListener = () -> {/* Do nothing */ };
+ mPreference.setText(TITLE, linkableDescription, clickListener);
+
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ mView = inflater.inflate(
+ mPreference.getLayoutResource(), new LinearLayout(mContext), false);
+ mHolder = PreferenceViewHolder.createInstanceForTests(mView);
+
+ mPreference.onBindViewHolder(mHolder);
+ }
+
+ @Test
+ public void prefWithLinkShouldHaveAccessibilityMovementMethodSet() {
+ TextView textView = mView.findViewById(android.R.id.title);
+ assertThat(textView.getMovementMethod()).isNotNull();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index d6243ac..7df5c9a 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -17,6 +17,7 @@
package com.android.settings.wifi;
import static android.provider.Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED;
+import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
import static com.google.common.truth.Truth.assertThat;
@@ -29,6 +30,7 @@
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.lifecycle.Lifecycle;
@@ -52,6 +54,7 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new WifiWakeupPreferenceController(mContext, mock(Lifecycle.class));
+ Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
}
@Test
@@ -95,6 +98,7 @@
verify(preference).setChecked(true);
verify(preference).setEnabled(true);
+ verify(preference).setSummary(R.string.wifi_wakeup_summary);
}
@Test
@@ -107,5 +111,20 @@
verify(preference).setChecked(false);
verify(preference).setEnabled(false);
+ verify(preference).setSummary(R.string.wifi_wakeup_summary);
+ }
+
+ @Test
+ public void updateState_preferenceSetUncheckedAndSetDisabledWhenWifiScanningDisabled() {
+ final SwitchPreference preference = mock(SwitchPreference.class);
+ Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 1);
+ Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
+
+ mController.updateState(preference);
+
+ verify(preference).setChecked(true);
+ verify(preference).setEnabled(false);
+ verify(preference).setSummary(R.string.wifi_wakeup_summary_scanning_disabled);
}
}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index 7cb69ea..8d28dee 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -24,7 +24,9 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.IpPrefix;
@@ -52,14 +54,13 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
+import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -74,17 +75,20 @@
private static final String SECURITY = "None";
private InetAddress mIpv4Address;
+ private Inet6Address mIpv6Address;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mockScreen;
@Mock private AccessPoint mockAccessPoint;
- @Mock private WifiManager mockWifiManager;
+ @Mock private Activity mockActivity;
@Mock private ConnectivityManager mockConnectivityManager;
+ @Mock private Network mockNetwork;
@Mock private NetworkInfo mockNetworkInfo;
@Mock private WifiConfiguration mockWifiConfig;
@Mock private WifiInfo mockWifiInfo;
- @Mock private Network mockNetwork;
+ @Mock private WifiNetworkDetailsFragment mockFragment;
+ @Mock private WifiManager mockWifiManager;
@Mock private Preference mockConnectionDetailPref;
@Mock private WifiDetailPreference mockSignalStrengthPref;
@@ -112,6 +116,12 @@
try {
mIpv4Address = InetAddress.getByAddress(
new byte[] { (byte) 255, (byte) 255, (byte) 255, (byte) 255 });
+ mIpv6Address = Inet6Address.getByAddress(
+ "123", /* host */
+ new byte[] {
+ (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x11, 0x25,
+ (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C, (byte) 0xB2},
+ 1 /*scope id */);
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
@@ -122,6 +132,9 @@
when(mockAccessPoint.getRssi()).thenReturn(RSSI);
when(mockAccessPoint.getSecurityString(false)).thenReturn(SECURITY);
+ when(mockConnectivityManager.getNetworkInfo(any(Network.class)))
+ .thenReturn(mockNetworkInfo);
+
when(mockWifiInfo.getLinkSpeed()).thenReturn(LINK_SPEED);
when(mockWifiInfo.getRssi()).thenReturn(RSSI);
when(mockWifiInfo.getMacAddress()).thenReturn(MAC_ADDRESS);
@@ -131,13 +144,26 @@
mLinkProperties = new LinkProperties();
when(mockConnectivityManager.getLinkProperties(mockNetwork)).thenReturn(mLinkProperties);
- mController = new WifiDetailPreferenceController(
- mockAccessPoint, mContext, mLifecycle, mockWifiManager, mockConnectivityManager);
+ when(mockFragment.getActivity()).thenReturn(mockActivity);
+
+ mController = newWifiDetailPreferenceController();
setupMockedPreferenceScreen();
}
+ private WifiDetailPreferenceController newWifiDetailPreferenceController() {
+ return new WifiDetailPreferenceController(
+ mockAccessPoint,
+ mockConnectivityManager,
+ mContext,
+ mockFragment,
+ mLifecycle,
+ mockWifiManager);
+ }
+
private void setupMockedPreferenceScreen() {
+ when(mockScreen.getPreferenceManager().getContext()).thenReturn(mContext);
+
when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_CONNECTION_DETAIL_PREF))
.thenReturn(mockConnectionDetailPref);
when(mockScreen.findPreference(WifiDetailPreferenceController.KEY_SIGNAL_STRENGTH_PREF))
@@ -175,11 +201,17 @@
}
@Test
- public void latestWifiInfoAndConfig_shouldBeFetchedOnResume() {
+ public void latestWifiInfo_shouldBeFetchedOnResume() {
mController.onResume();
- // Once in construction, once in onResume
- verify(mockWifiManager, times(2)).getConnectionInfo();
+ verify(mockWifiManager, times(1)).getConnectionInfo();
+ }
+
+ @Test
+ public void latestNetworkInfo_shouldBeFetchedOnResume() {
+ mController.onResume();
+
+ verify(mockConnectivityManager, times(1)).getNetworkInfo(any(Network.class));
}
@Test
@@ -321,9 +353,9 @@
@Test
public void canForgetNetwork_noNetwork() {
when(mockAccessPoint.getConfig()).thenReturn(null);
-
- mController = new WifiDetailPreferenceController(
- mockAccessPoint, mContext, mLifecycle, mockWifiManager, mockConnectivityManager);
+ mController = newWifiDetailPreferenceController();
+ mController.displayPreference(mockScreen);
+ mController.onResume();
assertThat(mController.canForgetNetwork()).isFalse();
}
@@ -332,9 +364,9 @@
public void canForgetNetwork_ephemeral() {
when(mockWifiInfo.isEphemeral()).thenReturn(true);
when(mockAccessPoint.getConfig()).thenReturn(null);
-
- mController = new WifiDetailPreferenceController(
- mockAccessPoint, mContext, mLifecycle, mockWifiManager, mockConnectivityManager);
+ mController = newWifiDetailPreferenceController();
+ mController.displayPreference(mockScreen);
+ mController.onResume();
assertThat(mController.canForgetNetwork()).isTrue();
}
@@ -347,10 +379,11 @@
@Test
public void forgetNetwork_ephemeral() {
String ssid = "ssid";
-
when(mockWifiInfo.isEphemeral()).thenReturn(true);
when(mockWifiInfo.getSSID()).thenReturn(ssid);
+ mController.onResume();
+
mController.forgetNetwork();
verify(mockWifiManager).disableEphemeralNetwork(ssid);
@@ -364,4 +397,64 @@
verify(mockWifiManager).forget(mockWifiConfig.networkId, null);
}
+
+ @Test
+ public void networkStateChangedIntent_shouldRefetchInfo() {
+ mController.onResume();
+ verify(mockConnectivityManager, times(1)).getNetworkInfo(any(Network.class));
+ verify(mockWifiManager, times(1)).getConnectionInfo();
+
+ mContext.sendBroadcast(new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION));
+
+ verify(mockConnectivityManager, times(2)).getNetworkInfo(any(Network.class));
+ verify(mockWifiManager, times(2)).getConnectionInfo();
+ }
+
+ @Test
+ public void rssiChangedIntent_shouldRefetchInfo() {
+ mController.onResume();
+ verify(mockConnectivityManager, times(1)).getNetworkInfo(any(Network.class));
+ verify(mockWifiManager, times(1)).getConnectionInfo();
+
+ mContext.sendBroadcast(new Intent(WifiManager.RSSI_CHANGED_ACTION));
+
+ verify(mockConnectivityManager, times(2)).getNetworkInfo(any(Network.class));
+ verify(mockWifiManager, times(2)).getConnectionInfo();
+ }
+
+ @Test
+ public void networkDisconnectdState_shouldFinishActivity() {
+ mController.onResume();
+
+ when(mockConnectivityManager.getNetworkInfo(any(Network.class))).thenReturn(null);
+ mContext.sendBroadcast(new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION));
+
+ verify(mockActivity).finish();
+ }
+
+ @Test
+ public void ipv6AddressPref_shouldHaveHostAddressTextSet() {
+ LinkAddress ipv6Address = new LinkAddress(mIpv6Address, 128);
+
+ mLinkProperties.addLinkAddress(ipv6Address);
+
+ mController.onResume();
+
+ ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
+ verify(mockIpv6AddressCategory).addPreference(preferenceCaptor.capture());
+ assertThat(preferenceCaptor.getValue().getTitle()).isEqualTo(mIpv6Address.getHostAddress());
+ }
+
+ @Test
+ public void ipv6AddressPref_shouldNotBeSelectable() {
+ LinkAddress ipv6Address = new LinkAddress(mIpv6Address, 128);
+
+ mLinkProperties.addLinkAddress(ipv6Address);
+
+ mController.onResume();
+
+ ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(Preference.class);
+ verify(mockIpv6AddressCategory).addPreference(preferenceCaptor.capture());
+ assertThat(preferenceCaptor.getValue().isSelectable()).isFalse();
+ }
}
diff --git a/tests/unit/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java b/tests/unit/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java
new file mode 100644
index 0000000..70087ae
--- /dev/null
+++ b/tests/unit/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings;
+
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.RootMatchers.isDialog;
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static junit.framework.Assert.fail;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class RegulatoryInfoDisplayActivityTest {
+
+ private Instrumentation mInstrumentation;
+ private Intent mRegulatoryInfoIntent;
+
+ @Before
+ public void setUp() {
+ mInstrumentation = InstrumentationRegistry.getInstrumentation();
+ mRegulatoryInfoIntent = new Intent("android.settings.SHOW_REGULATORY_INFO")
+ .addCategory(Intent.CATEGORY_DEFAULT)
+ .setPackage(mInstrumentation.getTargetContext().getPackageName());
+ }
+
+ @Test
+ public void resolveRegulatoryInfoIntent_intentShouldMatchConfig() {
+ // Load intent from PackageManager and load config from Settings app
+ final Context context = mInstrumentation.getTargetContext();
+
+ final boolean hasRegulatoryInfo = context.getResources()
+ .getBoolean(R.bool.config_show_regulatory_info);
+ final ResolveInfo resolveInfo = mInstrumentation.getTargetContext().getPackageManager()
+ .resolveActivity(mRegulatoryInfoIntent, 0 /* flags */);
+
+ // Check config and intent both enable or both disabled.
+ if (hasRegulatoryInfo && resolveInfo == null) {
+ fail("Config enables regulatory info but there is no handling intent");
+ return;
+ }
+ if (!hasRegulatoryInfo && resolveInfo != null) {
+ fail("Config disables regulatory info but there is at least one handling intent");
+ return;
+ }
+ }
+
+ @Test
+ public void launchRegulatoryInfo_shouldNotCrash() {
+ final Context context = mInstrumentation.getTargetContext();
+ final boolean hasRegulatoryInfo = context.getResources()
+ .getBoolean(R.bool.config_show_regulatory_info);
+
+ if (!hasRegulatoryInfo) {
+ return;
+ }
+ // Launch intent
+ mInstrumentation.startActivitySync(mRegulatoryInfoIntent);
+
+ onView(withId(R.id.regulatoryInfo))
+ .inRoot(isDialog())
+ .check(matches(isDisplayed()));
+ }
+
+}
diff --git a/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java b/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java
deleted file mode 100644
index 4448307..0000000
--- a/tests/unit/src/com/android/settings/WallpaperPreferenceLayoutTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2016 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;
-
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
-import android.view.LayoutInflater;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class WallpaperPreferenceLayoutTest {
- @Test
- public void testInflateWallpaperPreferenceLayout_doesNotCrash() {
- LayoutInflater.from(InstrumentationRegistry.getTargetContext())
- .inflate(R.layout.preference_wallpaper_type, null, false);
- }
-}
diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
index f7131b3..546ea4b 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
@@ -194,8 +194,8 @@
// Should not crash.
}
- private ApplicationInfo addPackage(
- String packageName, long cacheSize, long codeSize, long dataSize, int category) {
+ private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize,
+ long dataSize, int category) throws Exception {
StorageStatsSource.AppStorageStats storageStats =
mock(StorageStatsSource.AppStorageStats.class);
when(storageStats.getCodeBytes()).thenReturn(codeSize);
diff --git a/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java b/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java
new file mode 100644
index 0000000..4011d9a
--- /dev/null
+++ b/tests/unit/src/com/android/settings/display/NightDisplaySettingsActivityTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings.display;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.provider.Settings;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.settings.Settings.NightDisplaySettingsActivity;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class NightDisplaySettingsActivityTest {
+
+ private Context mTargetContext;
+
+ @Before
+ public void setUp() throws Exception {
+ Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ mTargetContext = instrumentation.getTargetContext();
+ }
+
+ @Test
+ public void nightDisplaySettingsIntent_resolvesCorrectly() {
+ final boolean nightDisplayAvailable = mTargetContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_nightDisplayAvailable);
+ final PackageManager pm = mTargetContext.getPackageManager();
+ final Intent intent = new Intent(Settings.ACTION_NIGHT_DISPLAY_SETTINGS);
+ final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
+
+ if (nightDisplayAvailable) {
+ Assert.assertNotNull("No activity for " + Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
+ Assert.assertEquals(mTargetContext.getPackageName(), ri.activityInfo.packageName);
+ Assert.assertEquals(NightDisplaySettingsActivity.class.getName(),
+ ri.activityInfo.name);
+ } else {
+ Assert.assertNull("Should have no activity for "
+ + Settings.ACTION_NIGHT_DISPLAY_SETTINGS, ri);
+ }
+ }
+
+}