Merge "Don't crash on opening ejecting USB." into oc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4f94bf8..2d8e06a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -945,7 +945,6 @@
<activity android:name="Settings$ManageApplicationsActivity"
android:label="@string/applications_settings"
- android:icon="@drawable/ic_settings_applications"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="android.settings.APPLICATION_SETTINGS" />
@@ -2507,7 +2506,6 @@
<activity android:name="Settings$ConfigureNotificationSettingsActivity"
android:label="@string/configure_notification_settings"
- android:icon="@drawable/ic_settings_notifications"
android:exported="true"
android:taskAffinity="">
<intent-filter android:priority="1">
@@ -2850,7 +2848,7 @@
android:label="@string/install_other_apps"
android:taskAffinity="">
<intent-filter android:priority="1">
- <action android:name="android.settings.action.MANAGE_UNKNOWN_APP_SOURCES" />
+ <action android:name="android.settings.MANAGE_UNKNOWN_APP_SOURCES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
@@ -2861,7 +2859,7 @@
android:label="@string/install_other_apps"
android:taskAffinity="">
<intent-filter android:priority="1">
- <action android:name="android.settings.action.MANAGE_UNKNOWN_APP_SOURCES" />
+ <action android:name="android.settings.MANAGE_UNKNOWN_APP_SOURCES" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
@@ -2882,8 +2880,7 @@
<activity android:name="Settings$AdvancedAppsActivity"
android:taskAffinity=""
android:exported="true"
- android:label="@string/app_default_dashboard_title"
- android:icon="@drawable/ic_adb">
+ android:label="@string/app_default_dashboard_title">
<intent-filter android:priority="1">
<action android:name="android.settings.MANAGE_DEFAULT_APPS_SETTINGS" />
<action android:name="android.settings.HOME_SETTINGS" />
@@ -3080,6 +3077,16 @@
android:permission="android.permission.DUMP"
android:enabled="@bool/config_has_help" />
+ <activity android:name=".applications.defaultapps.AutofillPickerActivity"
+ android:taskAffinity=""
+ android:noHistory="true">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.REQUEST_SET_AUTOFILL_SERVICE" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:scheme="package" />
+ </intent-filter>
+ </activity>
+
<!-- This is the longest AndroidManifest.xml ever. -->
</application>
</manifest>
diff --git a/res/drawable/ic_adb.xml b/res/drawable/ic_adb.xml
deleted file mode 100644
index af28aa1..0000000
--- a/res/drawable/ic_adb.xml
+++ /dev/null
@@ -1,25 +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.
--->
-<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="M5,16c0,3.87 3.13,7 7,7s7,-3.13 7,-7v-4L5,12v4zM16.12,4.37l2.1,-2.1 -0.82,-0.83 -2.3,2.31C14.16,3.28 13.12,3 12,3s-2.16,0.28 -3.09,0.75L6.6,1.44l-0.82,0.83 2.1,2.1C6.14,5.64 5,7.68 5,10v1h14v-1c0,-2.32 -1.14,-4.36 -2.88,-5.63zM9,9c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM15,9c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1z"
- android:fillColor="#FFFFFFFF"/>
-</vector>
diff --git a/res/drawable/ic_find_device_disabled.xml b/res/drawable/ic_find_device_disabled.xml
index ac23101..0658707 100644
--- a/res/drawable/ic_find_device_disabled.xml
+++ b/res/drawable/ic_find_device_disabled.xml
@@ -14,24 +14,15 @@
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:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
<path
- android:pathData="M0,0l24,0l0,24l-24,0z"
- android:strokeColor="#000000"
- android:fillColor="#00000000"
- android:strokeWidth="1.33333335e-11"
- android:strokeAlpha="0.00784313771"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:pathData="M5,20l0,2l14,0l0,-2z"
- android:strokeColor="#00000000"
- android:fillColor="#F09300"
- android:strokeWidth="1"/>
- <path
- android:pathData="M12,5.917C13.15,5.917 14.083,6.85 14.083,8C14.083,8.613 13.813,9.158 13.392,9.542L16.417,12.567C17.229,11.017 17.833,9.404 17.833,8C17.833,4.779 15.221,2.167 12,2.167C10.35,2.167 8.863,2.854 7.804,3.954L10.458,6.608C10.837,6.188 11.387,5.917 12,5.917ZM15.646,13.917L11.792,10.063L11.7,9.971L4.725,3L3.667,4.063L6.317,6.713C6.221,7.125 6.167,7.554 6.167,8C6.167,12.375 12,18.833 12,18.833C12,18.833 13.392,17.292 14.813,15.208L17.604,18L18.667,16.938L15.646,13.917Z"
- android:strokeColor="#00000000"
- android:fillColor="#F09300"
- android:strokeWidth="1"/>
+ android:fillColor="#000000"
+ android:pathData="M14,10.5v9.06C12.87,21,12,22,12,22S5,14.25,5,9A7,7,0,0,1,18.93,8H14.29A2.5,2.5,0,1,0,14,10.5ZM16,22h2V20H16Zm0-4h2V10H16Z" />
</vector>
diff --git a/res/drawable/ic_find_device_enabled.xml b/res/drawable/ic_find_device_enabled.xml
index c47b9f0..37c2bdc 100644
--- a/res/drawable/ic_find_device_enabled.xml
+++ b/res/drawable/ic_find_device_enabled.xml
@@ -14,19 +14,17 @@
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:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
<path
- android:pathData="M0,0l24,0l0,24l-24,0z"
- android:strokeColor="#000000"
- android:fillColor="#00000000"
- android:strokeWidth="1.33333335e-11"
- android:strokeAlpha="0.00784313771"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:pathData="M18,8C18,4.69 15.31,2 12,2C8.69,2 6,4.69 6,8C6,12.5 12,19 12,19C12,19 18,12.5 18,8ZM10,8C10,6.9 10.9,6 12,6C13.1,6 14,6.9 14,8C14,9.1 13.11,10 12,10C10.9,10 10,9.1 10,8ZM5,20L5,22L19,22L19,20L5,20Z"
- android:strokeColor="#00000000"
- android:fillColor="#4A90E2"
- android:strokeWidth="1"/>
+ android:fillColor="#000000"
+ android:pathData="M12,2 C8.13400675,2 5,5.13400675 5,9 C5,14.25 12,22 12,22 C12,22 19,14.25 19,9
+C19,5.13400675 15.8659932,2 12,2 L12,2 Z M8.2,9.66 L9.61,8.24 L11,9.66
+L15.24,5.42 L16.65,6.83 L11,12.49 L8.2,9.66 Z" />
</vector>
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_ota_update_available.xml b/res/drawable/ic_ota_update_available.xml
index e2d7f33..34d0a64 100644
--- a/res/drawable/ic_ota_update_available.xml
+++ b/res/drawable/ic_ota_update_available.xml
@@ -14,19 +14,15 @@
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:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
<path
- android:pathData="M0,0l24,0l0,24l-24,0z"
- android:strokeColor="#000000"
- android:fillColor="#00000000"
- android:strokeWidth="1.33333335e-11"
- android:strokeAlpha="0.00784313771"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3L5,21C5,22.1 5.9,23 7,23L17,23C18.1,23 19,22.1 19,21L19,3C19,1.9 18.1,1.01 17,1.01ZM17,19L7,19L7,5L17,5L17,19ZM16,13L13,13L13,8L11,8L11,13L8,13L12,17L16,13Z"
- android:strokeColor="#00000000"
- android:fillColor="#4A90E2"
- android:strokeWidth="1"/>
+ android:fillColor="#000000"
+ android:pathData="M17,1H7A2,2,0,0,0,5,3V21a2,2,0,0,0,2,2H17a2,2,0,0,0,2-2V3A2,2,0,0,0,17,1Zm0,18H7V5H17Zm-1-6H13V8H11v5H8l4,4Z" />
</vector>
diff --git a/res/drawable/ic_ota_update_current.xml b/res/drawable/ic_ota_update_current.xml
index d7a2f84..6a1d7a4 100644
--- a/res/drawable/ic_ota_update_current.xml
+++ b/res/drawable/ic_ota_update_current.xml
@@ -14,19 +14,15 @@
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:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
<path
- android:pathData="M0,0l24,0l0,24l-24,0z"
- android:strokeColor="#000000"
- android:fillColor="#00000000"
- android:strokeWidth="1.33333335e-11"
- android:strokeAlpha="0.00784313771"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3L5,21C5,22.1 5.9,23 7,23L17,23C18.1,23 19,22.1 19,21L19,3C19,1.9 18.1,1.01 17,1.01ZM17,19L7,19L7,5L17,5L17,19ZM10.627,13.093L9.144,11.746L8.054,12.79L10.627,15.181L16.156,10.044L15.066,9L10.627,13.093Z"
- android:strokeColor="#00000000"
- android:fillColor="#4A90E2"
- android:strokeWidth="1"/>
+ android:fillColor="#000000"
+ android:pathData="M17,1H7A2,2,0,0,0,5,3V21a2,2,0,0,0,2,2H17a2,2,0,0,0,2-2V3A2,2,0,0,0,17,1ZM9.11,14.06h0l1.41,1.41,5.66-5.66-1.42-1.4-4.24,4.24L9.11,11.24,7.7,12.66ZM17,19H7V5H17Z" />
</vector>
diff --git a/res/drawable/ic_ota_update_stale.xml b/res/drawable/ic_ota_update_stale.xml
index 9145be8..8e51a23 100644
--- a/res/drawable/ic_ota_update_stale.xml
+++ b/res/drawable/ic_ota_update_stale.xml
@@ -14,19 +14,15 @@
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:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
<path
- android:pathData="M0,0l24,0l0,24l-24,0z"
- android:strokeColor="#000000"
- android:fillColor="#00000000"
- android:strokeWidth="1.33333335e-11"
- android:strokeAlpha="0.00784313771"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3L5,21C5,22.1 5.9,23 7,23L17,23C18.1,23 19,22.1 19,21L19,3C19,1.9 18.1,1.01 17,1.01ZM17,19L7,19L7,5L17,5L17,19ZM16,13L13,13L13,8L11,8L11,13L8,13L12,17L16,13Z"
- android:strokeColor="#00000000"
- android:fillColor="#F09300"
- android:strokeWidth="1"/>
+ android:fillColor="#000000"
+ android:pathData="M17,1a2,2,0,0,1,2,2V21a2,2,0,0,1-2,2H7a2,2,0,0,1-2-2V3A2,2,0,0,1,7,1Zm0,18V5H7V19ZM11,6.5h2v7H11Zm0,9h2v2H11Z" />
</vector>
diff --git a/res/drawable/ic_package_verifier_disabled.xml b/res/drawable/ic_package_verifier_disabled.xml
index 5f19fec..b4054f3 100644
--- a/res/drawable/ic_package_verifier_disabled.xml
+++ b/res/drawable/ic_package_verifier_disabled.xml
@@ -14,18 +14,15 @@
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:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
<path
- android:pathData="M5.785,3.762L12,1L21,5L21,11C21,13.231 20.381,15.402 19.306,17.283L5.785,3.762ZM4.386,4.384L3,5L3,11C3,16.555 6.835,21.735 12,23C14.622,22.358 16.902,20.706 18.511,18.509L4.386,4.384Z"
- android:strokeColor="#00000000"
- android:fillColor="#F09300"
- android:strokeWidth="1"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:pathData="M2.808,2.808l17.678,17.678l-1.01,1.01l-17.678,-17.678z"
- android:strokeColor="#00000000"
- android:fillColor="#F09300"
- android:strokeWidth="1"/>
+ android:fillColor="#000000"
+ android:pathData="M13.45,11l2.12-2.12L14.16,7.5,12,9.62,9.91,7.5,8.5,8.91,10.62,11,8.5,13.16l1.41,1.41L12,12.45l2.12,2.12,1.41-1.41Zm8.1-7.11A16.54,16.54,0,0,1,22,7.77a16.65,16.65,0,0,1-.47,4,16.56,16.56,0,0,1-3.79,7.14A16.66,16.66,0,0,1,12,23,16.61,16.61,0,0,1,2.45,3.93,33.57,33.57,0,0,1,12,1a33.57,33.57,0,0,1,9.55,2.93Z" />
</vector>
diff --git a/res/drawable/ic_package_verifier_enabled.xml b/res/drawable/ic_package_verifier_enabled.xml
index 1059442..90f1490 100644
--- a/res/drawable/ic_package_verifier_enabled.xml
+++ b/res/drawable/ic_package_verifier_enabled.xml
@@ -14,19 +14,15 @@
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:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
<path
- android:pathData="M0,0l24,0l0,24l-24,0z"
- android:strokeColor="#000000"
- android:fillColor="#00000000"
- android:strokeWidth="1.33333335e-11"
- android:strokeAlpha="0.00784313771"/>
+ android:pathData="M 0 0 H 24 V 24 H 0 V 0 Z" />
<path
- android:pathData="M12,1L3,5L3,11C3,16.55 6.84,21.74 12,23C17.16,21.74 21,16.55 21,11L21,5L12,1Z"
- android:strokeColor="#00000000"
- android:fillColor="#4A90E2"
- android:strokeWidth="1"/>
+ android:fillColor="#000000"
+ android:pathData="M21.55,3.93A16.54,16.54,0,0,1,22,7.77a16.65,16.65,0,0,1-.47,4,16.56,16.56,0,0,1-3.79,7.14A16.66,16.66,0,0,1,12,23,16.61,16.61,0,0,1,2.45,3.93,33.57,33.57,0,0,1,12,1,33.57,33.57,0,0,1,21.55,3.93ZM15.27,8.41,9.61,14.07,11,15.49l5.66-5.66ZM9.61,11.24,8.2,12.66l1.41,1.41L11,12.66Z" />
</vector>
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 8cfa8b9..c3ffe1a 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -31,28 +31,13 @@
android:paddingEnd="0dp"
android:paddingTop="24dp"
android:paddingBottom="24dp">
-
- <FrameLayout android:id="@+id/app_icon_frame"
- android:layout_width="56dp"
- android:layout_height="56dp"
- 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="4dp"
- android:elevation="20dp"
- android:background="@drawable/ic_instant_apps_badge_bg"
- android:src="@drawable/ic_instant_apps_badge" />
- </FrameLayout>
+ <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"
@@ -86,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"
@@ -127,9 +112,4 @@
</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/battery_header.xml b/res/layout/battery_header.xml
index 04ef74d..97cc016 100644
--- a/res/layout/battery_header.xml
+++ b/res/layout/battery_header.xml
@@ -46,8 +46,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
- android:textAppearance="@android:style/TextAppearance.Material.Small"
- android:text="@string/estimated_time_left"/>
+ android:textAppearance="@android:style/TextAppearance.Material.Small"/>
</LinearLayout>
diff --git a/res/layout/connection_detail_pref.xml b/res/layout/connection_detail_pref.xml
index 15f1c77..182f2cb 100644
--- a/res/layout/connection_detail_pref.xml
+++ b/res/layout/connection_detail_pref.xml
@@ -43,6 +43,7 @@
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:singleLine="false"
android:paddingLeft="20dp"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textColor="@android:color/white"/>
diff --git a/res/layout/search_breadcrumb_view.xml b/res/layout/search_breadcrumb_view.xml
index a78b745..08a2651 100644
--- a/res/layout/search_breadcrumb_view.xml
+++ b/res/layout/search_breadcrumb_view.xml
@@ -20,7 +20,7 @@
android:id="@+id/breadcrumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingTop="8dp"
+ android:paddingTop="5dp"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary"
- android:ellipsize="marquee"/>
\ No newline at end of file
+ android:ellipsize="marquee"/>
diff --git a/res/layout/search_inline_switch_item.xml b/res/layout/search_inline_switch_item.xml
index 75943c4..526f9fd 100644
--- a/res/layout/search_inline_switch_item.xml
+++ b/res/layout/search_inline_switch_item.xml
@@ -46,9 +46,8 @@
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceListItemSecondary"
- android:textColor="?android:attr/textColorSecondary"
- android:maxLines="10"/>
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceListItemSecondary"/>
<include layout="@layout/search_breadcrumb_view"/>
</LinearLayout>
diff --git a/res/layout/search_intent_item.xml b/res/layout/search_intent_item.xml
index 31f7f26..98e2a9b 100644
--- a/res/layout/search_intent_item.xml
+++ b/res/layout/search_intent_item.xml
@@ -46,9 +46,8 @@
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
- android:textColor="?android:attr/textColorSecondary"
- android:maxLines="3"
android:ellipsize="marquee"/>
<include layout="@layout/search_breadcrumb_view"/>
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 8173d8a..6495ab0 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -242,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 ae2eb0a..b255123 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2378,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 -->
@@ -4474,10 +4474,10 @@
<!-- Title for the cellular network in power use UI(i.e. Mobile network scanning: 30% of battery usage) [CHAR_LIMIT=40] -->
<string name="device_cellular_network">Mobile network scanning</string>
- <!-- Label for time since last full charge in power use UI, i.e. "7 h 20 min ago" [CHAR_LIMIT=60] -->
- <string name="power_last_full_charge_summary"><xliff:g id="time">%1$s</xliff:g> ago</string>
- <!-- Label for list of apps using battery in power use UI [CHAR_LIMIT=120] -->
- <string name="power_usage_list_summary">App usage since full charge (<xliff:g id="time">%1$s</xliff:g> ago)</string>
+ <!-- Label for time since last full charge in power use UI, i.e. "7 h 20 min ago". Note: ^1 should be used in all translations [CHAR_LIMIT=60] -->
+ <string name="power_last_full_charge_summary"><xliff:g id="time">^1</xliff:g> ago</string>
+ <!-- Label for list of apps using battery in power use UI. Note: ^1 should be used in all translations[CHAR_LIMIT=120] -->
+ <string name="power_usage_list_summary">App usage since full charge (<xliff:g id="time">^1</xliff:g> ago)</string>
<!-- Description for the screen usage item [CHAR_LIMIT=120] -->
<string name="screen_usage_summary">Amount of time screen has been on since full charge</string>
<!-- Label for list of different types using battery in power use UI [CHAR_LIMIT=60] -->
@@ -4539,8 +4539,8 @@
<string name="power_wifi">Wi\u2011Fi</string>
<!-- Label for power consumed by Bluetooth -->
<string name="power_bluetooth">Bluetooth</string>
- <!-- Label for power consumed by Cell idle -->
- <string name="power_cell">Cell standby</string>
+ <!-- Label for power consumed by Mobile network idle -->
+ <string name="power_cell">Mobile network standby</string>
<!-- Label for power consumed by Calling -->
<string name="power_phone">Voice calls</string>
<!-- Label for power consumed when Idle -->
@@ -4676,8 +4676,8 @@
<!-- Representation of a mAh value. [CHAR LIMIT=NONE] -->
<string name="mah"><xliff:g id="number" example="30">%d</xliff:g> mAh</string>
- <!-- Description for battery usage time for an app, i.e. Used for 30min. [CHAR LIMIT=60] -->
- <string name="battery_used_for">Used for %1$s</string>
+ <!-- Description for battery usage time for an app, i.e. Used for 30min. Note: ^1 should be used in all translations [CHAR LIMIT=60] -->
+ <string name="battery_used_for">Used for <xliff:g id="time">^1</xliff:g></string>
<!-- Description for battery usage info for an app, i.e. 60% used by facebook. [CHAR LIMIT=60] -->
<string name="battery_used_by"><xliff:g id="percent">%1$s</xliff:g> used by <xliff:g id="app">%2$s</xliff:g></string>
<!-- Description for percentage of battery usage for an app, i.e. Screen: 30% of overall battery. [CHAR LIMIT=60] -->
@@ -7678,11 +7678,11 @@
<!-- Summary of app not allowed to write system settings [CHAR LIMIT=45] -->
<string name="write_settings_off">No</string>
<!-- Summary of app trusted to install apps [CHAR LIMIT=45] -->
- <string name="external_source_trusted">Yes</string>
+ <string name="external_source_trusted">Allowed</string>
<!-- Summary of app not trusted to install apps [CHAR LIMIT=45] -->
- <string name="external_source_untrusted">No</string>
+ <string name="external_source_untrusted">Not allowed</string>
<!-- Title of switch preference that controls whether an external app source is trusted or not [CHAR LIMIT=50] -->
- <string name="external_source_switch_title">Allow app installs</string>
+ <string name="external_source_switch_title">Allow from this source</string>
<!-- Title of setting that controls gesture to open camera [CHAR LIMIT=40] -->
<string name="camera_gesture_title">Double twist for camera</string>
@@ -8171,8 +8171,11 @@
<!-- Summary for Bluetooth when disabled. [CHAR LIMIT=NONE] -->
<string name="bluetooth_disabled">Not visible to other devices</string>
- <!-- Summary for Bluetooth when connected. [CHAR LIMIT=NONE] -->
- <string name="bluetooth_connected_summary">Connected to </string>
+ <!-- Summary for Bluetooth when connected to one device. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_connected_summary">Connected to <xliff:g name="device">%1$s</xliff:g></string>
+
+ <!-- Summary for Bluetooth when connected to multiple devices. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_connected_multiple_devices_summary">Connected to multiple devices</string>
<!-- [CHAR LIMIT=60] Name of dev option called "System UI demo mode" -->
<string name="demo_mode">System UI demo mode</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 7ca109b..3dbaa8b 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -108,16 +108,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 795d35e..02b9949 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -57,11 +57,6 @@
android:title="@string/accessibility_screen_magnification_title"
android:icon="@mipmap/ic_accessibility_magnification" />
- <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_large_pointer_icon"
android:title="@string/accessibility_toggle_large_pointer_icon_title" />
@@ -118,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_and_notification.xml b/res/xml/app_and_notification.xml
index adbd402..627d3f8 100644
--- a/res/xml/app_and_notification.xml
+++ b/res/xml/app_and_notification.xml
@@ -23,7 +23,6 @@
<Preference
android:key="manage_perms"
android:title="@string/app_permissions"
- android:icon="@drawable/ic_apps"
android:order="-130"
settings:keywords="@string/keywords_app_permissions">
<intent android:action="android.intent.action.MANAGE_PERMISSIONS"/>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 54eb878..bec8863 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -80,11 +80,6 @@
android:fragment="com.android.settings.webview.WebViewAppPicker" />
<SwitchPreference
- android:key="enable_webview_multiprocess"
- android:title="@string/enable_webview_multiprocess"
- android:summary="@string/enable_webview_multiprocess_desc" />
-
- <SwitchPreference
android:key="color_temperature"
android:title="@string/color_temperature"
android:summary="@string/color_temperature_desc" />
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_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/src/com/android/settings/ApnEditor.java b/src/com/android/settings/ApnEditor.java
index f97811c..f668957 100644
--- a/src/com/android/settings/ApnEditor.java
+++ b/src/com/android/settings/ApnEditor.java
@@ -788,9 +788,14 @@
* Check the key fields' validity and save if valid.
* @param force save even if the fields are not valid, if the app is
* being suspended
- * @return true if the data was saved
+ * @return true if there's no error
*/
private boolean validateAndSave(boolean force) {
+ // nothing to do if it's a read only APN
+ if (mReadOnlyApn) {
+ return true;
+ }
+
String name = checkNotSet(mName.getText());
String apn = checkNotSet(mApn.getText());
String mcc = checkNotSet(mMcc.getText());
diff --git a/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java b/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java
index a2e9fe9..2c97e1a 100644
--- a/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java
+++ b/src/com/android/settings/ConfirmDeviceCredentialBaseFragment.java
@@ -68,8 +68,6 @@
PACKAGE + ".ConfirmCredentials.showWhenLocked";
private FingerprintUiHelper mFingerprintHelper;
- protected boolean mIsStrongAuthRequired;
- private boolean mAllowFpAuthentication;
protected boolean mReturnCredentials = false;
protected Button mCancelButton;
protected ImageView mFingerprintIcon;
@@ -83,8 +81,6 @@
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mAllowFpAuthentication = getActivity().getIntent().getBooleanExtra(
- ALLOW_FP_AUTHENTICATION, false);
mReturnCredentials = getActivity().getIntent().getBooleanExtra(
ChooseLockSettingsHelper.EXTRA_KEY_RETURN_CREDENTIALS, false);
// Only take this argument into account if it belongs to the current profile.
@@ -133,23 +129,26 @@
// credential. Otherwise, fingerprint can't unlock fbe/keystore through
// verifyTiedProfileChallenge. In such case, we also wanna show the user message that
// fingerprint is disabled due to device restart.
- private boolean isFingerprintDisallowedByStrongAuth() {
+ protected boolean isFingerprintDisallowedByStrongAuth() {
return !(mLockPatternUtils.isFingerprintAllowedForUser(mEffectiveUserId)
&& mUserManager.isUserUnlocked(mUserId));
}
+ private boolean isFingerprintAllowed() {
+ return !mReturnCredentials
+ && getActivity().getIntent().getBooleanExtra(ALLOW_FP_AUTHENTICATION, false)
+ && !isFingerprintDisallowedByStrongAuth()
+ && !isFingerprintDisabledByAdmin();
+ }
+
@Override
public void onResume() {
super.onResume();
- mIsStrongAuthRequired = isFingerprintDisallowedByStrongAuth();
- mAllowFpAuthentication = getActivity().getIntent().getBooleanExtra(
- ALLOW_FP_AUTHENTICATION, false)
- && !isFingerprintDisabledByAdmin() && !mReturnCredentials && !mIsStrongAuthRequired;
refreshLockScreen();
}
protected void refreshLockScreen() {
- if (mAllowFpAuthentication) {
+ if (isFingerprintAllowed()) {
mFingerprintHelper.startListening();
} else {
if (mFingerprintHelper.isListening()) {
diff --git a/src/com/android/settings/ConfirmLockPassword.java b/src/com/android/settings/ConfirmLockPassword.java
index 5c86dcd..9a285f2 100644
--- a/src/com/android/settings/ConfirmLockPassword.java
+++ b/src/com/android/settings/ConfirmLockPassword.java
@@ -191,9 +191,10 @@
}
private int getDefaultDetails() {
+ boolean isStrongAuthRequired = isFingerprintDisallowedByStrongAuth();
boolean isProfile = UserManager.get(getActivity()).isManagedProfile(mEffectiveUserId);
// Map boolean flags to an index by isStrongAuth << 2 + isProfile << 1 + isAlpha.
- int index = ((mIsStrongAuthRequired ? 1 : 0) << 2) + ((isProfile ? 1 : 0) << 1)
+ int index = ((isStrongAuthRequired ? 1 : 0) << 2) + ((isProfile ? 1 : 0) << 1)
+ (mIsAlpha ? 1 : 0);
return DETAIL_TEXTS[index];
}
@@ -443,6 +444,7 @@
checkForPendingIntent();
} else {
if (timeoutMs > 0) {
+ refreshLockScreen();
long deadline = mLockPatternUtils.setLockoutAttemptDeadline(
effectiveUserId, timeoutMs);
handleAttemptLockout(deadline);
diff --git a/src/com/android/settings/ConfirmLockPattern.java b/src/com/android/settings/ConfirmLockPattern.java
index 4b65163..56d92f1 100644
--- a/src/com/android/settings/ConfirmLockPattern.java
+++ b/src/com/android/settings/ConfirmLockPattern.java
@@ -236,12 +236,13 @@
}
private int getDefaultDetails() {
+ boolean isStrongAuthRequired = isFingerprintDisallowedByStrongAuth();
if (UserManager.get(getActivity()).isManagedProfile(mEffectiveUserId)) {
- return mIsStrongAuthRequired
+ return isStrongAuthRequired
? R.string.lockpassword_strong_auth_required_reason_restart_work_pattern
: R.string.lockpassword_confirm_your_pattern_generic_profile;
} else {
- return mIsStrongAuthRequired
+ return isStrongAuthRequired
? R.string.lockpassword_strong_auth_required_reason_restart_device_pattern
: R.string.lockpassword_confirm_your_pattern_generic;
}
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 1230ae5..951a26b 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";
+ private 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,7 +103,7 @@
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));
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index fa9410d..69f563e 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -284,11 +284,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/Utils.java b/src/com/android/settings/Utils.java
index d04ae8d..f6f980a 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -81,6 +81,8 @@
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableString;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.TtsSpan;
@@ -770,8 +772,9 @@
* @param withSeconds include seconds?
* @return the formatted elapsed time
*/
- public static String formatElapsedTime(Context context, double millis, boolean withSeconds) {
- StringBuilder sb = new StringBuilder();
+ public static CharSequence formatElapsedTime(Context context, double millis,
+ boolean withSeconds) {
+ SpannableStringBuilder sb = new SpannableStringBuilder();
int seconds = (int) Math.floor(millis / 1000);
if (!withSeconds) {
// Round up.
@@ -812,9 +815,15 @@
hours, minutes));
} else {
sb.append(context.getString(R.string.battery_history_minutes_no_seconds, minutes));
+
+ // Add ttsSpan if it only have minute value, because it will be read as "meters"
+ TtsSpan ttsSpan = new TtsSpan.MeasureBuilder().setNumber(minutes)
+ .setUnit("minute").build();
+ sb.setSpan(ttsSpan, 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
- return sb.toString();
+
+ return sb;
}
/**
@@ -1256,4 +1265,5 @@
return (volume != null) && (volume.getType() == VolumeInfo.TYPE_PRIVATE)
&& volume.isMountedReadable();
}
+
}
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 1d3e125..44dd353 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -550,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(),
@@ -601,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;
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index 6ed06da..21ead46 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() {
@@ -98,7 +95,7 @@
CharSequence serviceName = getServiceName(getContext());
mServicePreference.setSummary(serviceName);
mOnLockScreenSwitchPreference.setChecked(Settings.Secure.getInt(
- cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 1) == 1);
+ cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 0) == 1);
if (TextUtils.equals(serviceName, getString(R.string.accessibility_no_service_selected))) {
// If there's no service configured, enabling the shortcut will have no effect
// It should already be disabled, but force the switch to off just in case
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/AccountPreferenceBase.java b/src/com/android/settings/accounts/AccountPreferenceBase.java
index 2ad21d9..7c3b54c 100644
--- a/src/com/android/settings/accounts/AccountPreferenceBase.java
+++ b/src/com/android/settings/accounts/AccountPreferenceBase.java
@@ -17,14 +17,10 @@
package com.android.settings.accounts;
-import android.accounts.AuthenticatorDescription;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SyncStatusObserver;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.content.res.Resources.Theme;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
@@ -32,12 +28,10 @@
import android.os.UserManager;
import android.support.v7.preference.PreferenceScreen;
import android.text.format.DateFormat;
-import android.text.format.DateUtils;
import android.util.Log;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
-import com.android.settings.utils.LocalClassLoaderContextThemeWrapper;
import com.android.settingslib.accounts.AuthenticatorHelper;
import java.util.ArrayList;
diff --git a/src/com/android/settings/accounts/AccountSyncPreferenceController.java b/src/com/android/settings/accounts/AccountSyncPreferenceController.java
index 57d317b..0b095f7 100644
--- a/src/com/android/settings/accounts/AccountSyncPreferenceController.java
+++ b/src/com/android/settings/accounts/AccountSyncPreferenceController.java
@@ -25,6 +25,7 @@
import android.support.v7.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
@@ -53,8 +54,9 @@
final Bundle args = new Bundle();
args.putParcelable(AccountSyncSettings.ACCOUNT_KEY, mAccount);
args.putParcelable(EXTRA_USER, mUserHandle);
- Utils.startWithFragment(mContext, AccountSyncSettings.class.getName(), args, null, 0, -1,
- mAccount.name, MetricsProto.MetricsEvent.ACCOUNT);
+ Utils.startWithFragment(mContext, AccountSyncSettings.class.getName(), args, null, 0,
+ R.string.account_sync_title, null, MetricsProto.MetricsEvent.ACCOUNT);
+
return true;
}
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/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index 51225aa..9018d9b 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -25,7 +25,6 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -56,13 +55,7 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- return buildPreferenceControllers(context);
- }
-
- private static List<PreferenceController> buildPreferenceControllers(Context context) {
- final List<PreferenceController> controllers = new ArrayList<>();
- controllers.add(new SpecialAppAccessPreferenceController(context));
- return controllers;
+ return null;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -74,10 +67,5 @@
sir.xmlResId = R.xml.app_and_notification;
return Arrays.asList(sir);
}
-
- @Override
- public List<PreferenceController> getPreferenceControllers(Context context) {
- return buildPreferenceControllers(context);
- }
};
}
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index 29acaa4..804d645 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -25,6 +25,7 @@
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.support.annotation.IntDef;
@@ -51,18 +52,17 @@
@IntDef({ActionType.ACTION_NONE,
ActionType.ACTION_APP_INFO,
ActionType.ACTION_APP_PREFERENCE,
- ActionType.ACTION_STORE_DEEP_LINK,
ActionType.ACTION_NOTIF_PREFERENCE})
@Retention(RetentionPolicy.SOURCE)
public @interface ActionType {
int ACTION_NONE = 0;
int ACTION_APP_INFO = 1;
- int ACTION_STORE_DEEP_LINK = 2;
- int ACTION_APP_PREFERENCE = 3;
- int ACTION_NOTIF_PREFERENCE = 4;
+ int ACTION_APP_PREFERENCE = 2;
+ int ACTION_NOTIF_PREFERENCE = 3;
}
public static final String PREF_KEY_APP_HEADER = "pref_app_header";
+
private static final String TAG = "AppDetailFeature";
private final Context mContext;
@@ -179,10 +179,6 @@
ImageView iconView = mAppHeader.findViewById(R.id.app_detail_icon);
if (iconView != null) {
iconView.setImageDrawable(mIcon);
- 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);
@@ -220,9 +216,8 @@
Log.w(TAG, "No actionbar, cannot style actionbar.");
return this;
}
- final Drawable appHeaderBackground =
- mAppHeader.findViewById(R.id.app_snippet).getBackground();
- actionBar.setBackgroundDrawable(appHeaderBackground);
+ actionBar.setBackgroundDrawable(
+ new ColorDrawable(Utils.getColorAttr(activity, android.R.attr.colorSecondary)));
actionBar.setElevation(0);
return this;
@@ -257,20 +252,6 @@
}
return;
}
- case ActionType.ACTION_STORE_DEEP_LINK: {
- final Intent intent = new Intent(Intent.ACTION_SHOW_APP_INFO)
- .setPackage(getInstallerPackageName(mContext, mPackageName));
- final Intent result = resolveIntent(intent);
- if (result == null) {
- button.setVisibility(View.GONE);
- } else {
- result.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackageName);
- button.setImageResource(R.drawable.ic_sim_sd);
- button.setOnClickListener(v -> mFragment.startActivity(intent));
- button.setVisibility(View.VISIBLE);
- }
- return;
- }
case ActionType.ACTION_NOTIF_PREFERENCE: {
if (mAppNotifPrefIntent == null) {
button.setVisibility(View.GONE);
@@ -298,15 +279,6 @@
}
}
- private String getInstallerPackageName(Context context, String packageName) {
- try {
- return context.getPackageManager().getInstallerPackageName(packageName);
- } catch (IllegalArgumentException e) {
- Log.e(TAG, "Exception while retrieving the package installer of " + packageName, e);
- return null;
- }
- }
-
private Intent resolveIntent(Intent i) {
ResolveInfo result = mContext.getPackageManager().resolveActivity(i, 0);
if (result != null) {
diff --git a/src/com/android/settings/applications/AppInfoWithHeader.java b/src/com/android/settings/applications/AppInfoWithHeader.java
index 2c9599b..6b1ef67 100644
--- a/src/com/android/settings/applications/AppInfoWithHeader.java
+++ b/src/com/android/settings/applications/AppInfoWithHeader.java
@@ -21,6 +21,7 @@
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;
@@ -43,7 +44,8 @@
final Preference pref = FeatureFactory.getFactory(activity)
.getApplicationFeatureProvider(activity)
.newAppHeaderController(this, null /* appHeader */)
- .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
+ .setIcon(IconDrawableFactory.newInstance(activity)
+ .getBadgedIcon(mPackageInfo.applicationInfo))
.setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
.setSummary(mPackageInfo)
.setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
diff --git a/src/com/android/settings/applications/AppStorageSettings.java b/src/com/android/settings/applications/AppStorageSettings.java
index 0676f56..5ad5e48 100644
--- a/src/com/android/settings/applications/AppStorageSettings.java
+++ b/src/com/android/settings/applications/AppStorageSettings.java
@@ -99,6 +99,7 @@
private static final String KEY_CLEAR_URI = "clear_uri_button";
private static final String KEY_CACHE_CLEARED = "cache_cleared";
+ private static final String KEY_DATA_CLEARED = "data_cleared";
// Views related to cache info
private Preference mCacheSize;
@@ -115,6 +116,7 @@
private boolean mCanClearData = true;
private boolean mCacheCleared;
+ private boolean mDataCleared;
private AppStorageSizesController mSizeController;
@@ -130,6 +132,8 @@
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mCacheCleared = savedInstanceState.getBoolean(KEY_CACHE_CLEARED, false);
+ mDataCleared = savedInstanceState.getBoolean(KEY_DATA_CLEARED, false);
+ mCacheCleared = mCacheCleared || mDataCleared;
}
addPreferencesFromResource(R.xml.app_storage_settings);
@@ -147,6 +151,7 @@
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_CACHE_CLEARED, mCacheCleared);
+ outState.putBoolean(KEY_DATA_CLEARED, mDataCleared);
}
private void setupViews() {
@@ -527,6 +532,9 @@
if (mCacheCleared) {
mSizeController.setCacheCleared(true);
}
+ if (mDataCleared) {
+ mSizeController.setDataCleared(true);
+ }
mSizeController.updateUi(getContext());
@@ -538,7 +546,7 @@
long dataSize = result.getDataBytes();
long cacheSize = result.getCacheBytes();
- if (dataSize <= 0 || !mCanClearData) {
+ if (dataSize <= 0 || !mCanClearData || mDataCleared) {
mClearDataButton.setEnabled(false);
} else {
mClearDataButton.setEnabled(true);
@@ -564,6 +572,8 @@
}
switch (msg.what) {
case MSG_CLEAR_USER_DATA:
+ mDataCleared = true;
+ mCacheCleared = true;
processClearMsg(msg);
break;
case MSG_CLEAR_CACHE:
diff --git a/src/com/android/settings/applications/AppStorageSizesController.java b/src/com/android/settings/applications/AppStorageSizesController.java
index 23a3eb2..45ece6e 100644
--- a/src/com/android/settings/applications/AppStorageSizesController.java
+++ b/src/com/android/settings/applications/AppStorageSizesController.java
@@ -40,6 +40,7 @@
private StorageStatsSource.AppStorageStats mLastResult;
private boolean mLastResultFailed;
private boolean mCachedCleared;
+ private boolean mDataCleared;
private long mLastCodeSize = -1;
private long mLastDataSize = -1;
private long mLastCacheSize = -1;
@@ -69,7 +70,7 @@
mTotalSize.setSummary(errorRes);
} else {
long codeSize = mLastResult.getCodeBytes();
- long dataSize = mLastResult.getDataBytes();
+ long dataSize = mDataCleared ? 0 : mLastResult.getDataBytes();
if (mLastCodeSize != codeSize) {
mLastCodeSize = codeSize;
mAppSize.setSummary(getSizeStr(context, codeSize));
@@ -78,7 +79,7 @@
mLastDataSize = dataSize;
mDataSize.setSummary(getSizeStr(context, dataSize));
}
- long cacheSize = mCachedCleared ? 0 : mLastResult.getCacheBytes();
+ long cacheSize = (mDataCleared || mCachedCleared) ? 0 : mLastResult.getCacheBytes();
if (mLastCacheSize != cacheSize) {
mLastCacheSize = cacheSize;
mCacheSize.setSummary(getSizeStr(context, cacheSize));
@@ -111,6 +112,15 @@
}
/**
+ * Sets if we have cleared data and should zero the data bytes.
+ * When the data is cleared, the directory are recreated. Directories have some size, but are
+ * empty. We zero this out to best match user expectations.
+ */
+ public void setDataCleared(boolean isCleared) {
+ mDataCleared = isCleared;
+ }
+
+ /**
* Returns the last result calculated, if it exists. If it does not, returns null.
*/
public StorageStatsSource.AppStorageStats getLastResult() {
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 09771f2..c0d2dd8 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -415,8 +415,8 @@
.getApplicationFeatureProvider(activity)
.newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
.setPackageName(mPackageName)
- .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
- AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
+ AppHeaderController.ActionType.ACTION_NONE)
.styleActionBar(activity)
.bindAppHeaderButtons();
prepareUninstallAndStop();
@@ -454,6 +454,10 @@
@Override
public void onPackageSizeChanged(String packageName) {
+ if (!TextUtils.equals(packageName, mPackageName)) {
+ Log.d(LOG_TAG, "Package change irrelevant, skipping");
+ return;
+ }
refreshUi();
}
diff --git a/src/com/android/settings/applications/LayoutPreference.java b/src/com/android/settings/applications/LayoutPreference.java
index b958b3a..b823f8e 100644
--- a/src/com/android/settings/applications/LayoutPreference.java
+++ b/src/com/android/settings/applications/LayoutPreference.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.content.res.TypedArray;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
@@ -31,7 +32,10 @@
public class LayoutPreference extends Preference {
- private View mRootView;
+ private final View.OnClickListener mClickListener = v -> performClick(v);
+
+ @VisibleForTesting
+ View mRootView;
public LayoutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -59,7 +63,7 @@
private void setView(View view) {
setLayoutResource(R.layout.layout_preference_frame);
- final ViewGroup allDetails = (ViewGroup) view.findViewById(R.id.all_details);
+ final ViewGroup allDetails = view.findViewById(R.id.all_details);
if (allDetails != null) {
Utils.forceCustomPadding(allDetails, true /* additive padding */);
}
@@ -68,9 +72,14 @@
}
@Override
- public void onBindViewHolder(PreferenceViewHolder view) {
- super.onBindViewHolder(view);
- FrameLayout layout = (FrameLayout) view.itemView;
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ holder.itemView.setOnClickListener(mClickListener);
+
+ final boolean selectable = isSelectable();
+ holder.itemView.setFocusable(selectable);
+ holder.itemView.setClickable(selectable);
+
+ FrameLayout layout = (FrameLayout) holder.itemView;
layout.removeAllViews();
ViewGroup parent = (ViewGroup) mRootView.getParent();
if (parent != null) {
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/ProcessStatsDetail.java b/src/com/android/settings/applications/ProcessStatsDetail.java
index c23da04..6c0928c 100644
--- a/src/com/android/settings/applications/ProcessStatsDetail.java
+++ b/src/com/android/settings/applications/ProcessStatsDetail.java
@@ -39,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;
@@ -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)
diff --git a/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java b/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
deleted file mode 100644
index 5b05602..0000000
--- a/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
+++ /dev/null
@@ -1,49 +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.applications;
-
-import android.content.Context;
-import android.support.v7.preference.Preference;
-import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
-import com.android.settings.datausage.DataSaverBackend;
-
-public class SpecialAppAccessPreferenceController extends PreferenceController {
-
- private static final String KEY_SPECIAL_ACCESS = "special_access";
-
- private DataSaverBackend mDataSaverBackend;
-
- public SpecialAppAccessPreferenceController(Context context) {
- super(context);
- mDataSaverBackend = new DataSaverBackend(context);
- }
-
- @Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_SPECIAL_ACCESS;
- }
-
- @Override
- public void updateState(Preference preference) {
- final int count = mDataSaverBackend.getWhitelistedCount();
- preference.setSummary(mContext.getResources().getQuantityString(
- R.plurals.special_access_summary, count, count));
- }
-}
diff --git a/src/com/android/settings/applications/defaultapps/AutofillPickerActivity.java b/src/com/android/settings/applications/defaultapps/AutofillPickerActivity.java
new file mode 100644
index 0000000..a173909
--- /dev/null
+++ b/src/com/android/settings/applications/defaultapps/AutofillPickerActivity.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 com.android.settings.applications.defaultapps;
+
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+
+/**
+ * Standalone activity used to launch {@link DefaultAppPickerFragment} from a
+ * {@link android.provider.Settings#ACTION_REQUEST_SET_AUTOFILL_SERVICE} intent.
+ */
+public class AutofillPickerActivity extends SettingsActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ final Intent intent = getIntent();
+ final String packageName = intent.getData().getSchemeSpecificPart();
+ intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultAutofillPicker.class.getName());
+ intent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.autofill_app);
+ intent.putExtra(DefaultAutofillPicker.EXTRA_PACKAGE_NAME, packageName);
+
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected boolean isValidFragment(String fragmentName) {
+ return super.isValidFragment(fragmentName)
+ || DefaultAutofillPicker.class.getName().equals(fragmentName);
+ }
+}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
index 8eb1fc6..037cddf 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
@@ -16,6 +16,7 @@
package com.android.settings.applications.defaultapps;
+import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -38,6 +39,8 @@
static final String SETTING = Settings.Secure.AUTOFILL_SERVICE;
static final Intent AUTOFILL_PROBE = new Intent(AutofillService.SERVICE_INTERFACE);
+ static final String EXTRA_PACKAGE_NAME = "package_name";
+
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DEFAULT_AUTOFILL_PICKER;
@@ -79,11 +82,24 @@
@Override
protected boolean setDefaultKey(String key) {
Settings.Secure.putString(getContext().getContentResolver(), SETTING, key);
+
+ // Check if activity was launched from Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE
+ // intent, and set proper result if so...
+ final Activity activity = getActivity();
+ if (activity != null) {
+ final String packageName = activity.getIntent().getStringExtra(EXTRA_PACKAGE_NAME);
+ if (packageName != null) {
+ final int result = key != null && key.startsWith(packageName) ? Activity.RESULT_OK
+ : Activity.RESULT_CANCELED;
+ activity.setResult(result);
+ activity.finish();
+ }
+ }
return true;
}
/**
- * Provides Intent to setting activity for the specified auto-fill service.
+ * Provides Intent to setting activity for the specified autofill service.
*/
static final class AutofillSettingIntentProvider implements SettingIntentProvider {
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index 22b21e4..6c41f83 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -21,13 +21,16 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.os.UserManager;
import android.provider.Settings;
import android.widget.Switch;
import android.widget.Toast;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.widget.SwitchWidgetController;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.WirelessUtils;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -45,6 +48,7 @@
private boolean mValidListener;
private final LocalBluetoothAdapter mLocalAdapter;
private final IntentFilter mIntentFilter;
+ private final RestrictionUtils mRestrictionUtils;
private static final String EVENT_DATA_IS_BT_ON = "is_bluetooth_on";
private static final int EVENT_UPDATE_INDEX = 0;
@@ -63,6 +67,13 @@
public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
int metricsEvent) {
+ this(context, switchWidget, metricsFeatureProvider, manager, metricsEvent,
+ new RestrictionUtils());
+ }
+
+ public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+ MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
+ int metricsEvent, RestrictionUtils restrictionUtils) {
mContext = context;
mMetricsFeatureProvider = metricsFeatureProvider;
mSwitchWidget = switchWidget;
@@ -79,6 +90,7 @@
mLocalAdapter = manager.getBluetoothAdapter();
}
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
+ mRestrictionUtils = restrictionUtils;
}
public void setupSwitchController() {
@@ -90,15 +102,17 @@
}
public void resume(Context context) {
+ if (mContext != context) {
+ mContext = context;
+ }
+
+ maybeEnforceRestrictions();
+
if (mLocalAdapter == null) {
mSwitchWidget.setEnabled(false);
return;
}
- if (mContext != context) {
- mContext = context;
- }
-
// Bluetooth state is not sticky, so set it manually
handleStateChanged(mLocalAdapter.getBluetoothState());
@@ -156,6 +170,10 @@
@Override
public boolean onSwitchToggled(boolean isChecked) {
+ if (maybeEnforceRestrictions()) {
+ return true;
+ }
+
// Show toast message if Bluetooth is not allowed in airplane mode
if (isChecked &&
!WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_BLUETOOTH)) {
@@ -182,4 +200,29 @@
mSwitchWidget.setEnabled(false);
return true;
}
+
+ /**
+ * Enforces user restrictions disallowing Bluetooth (or its configuration) if there are any.
+ *
+ * @return if there was any user restriction to enforce.
+ */
+ @VisibleForTesting
+ boolean maybeEnforceRestrictions() {
+ EnforcedAdmin admin = mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_BLUETOOTH);
+ if (admin == null) {
+ admin = mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH);
+ }
+ mSwitchWidget.setDisabledByAdmin(admin);
+ if (admin != null) {
+ mSwitchWidget.setChecked(false);
+ if (mSwitch != null) {
+ mSwitch.setEnabled(false);
+ mSwitch.setChecked(false);
+ }
+ }
+ return admin != null;
+ }
+
}
diff --git a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
index f98a209..508d6c9 100644
--- a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.LifecycleObserver;
@@ -26,27 +27,35 @@
import com.android.settings.core.lifecycle.events.OnStart;
import com.android.settings.core.lifecycle.events.OnStop;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
-import com.android.settings.widget.MasterSwitchPreference;
import com.android.settings.widget.MasterSwitchController;
+import com.android.settings.widget.MasterSwitchPreference;
+import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
public class BluetoothMasterSwitchPreferenceController extends PreferenceController
implements OnSummaryChangeListener,
LifecycleObserver, OnResume, OnPause, OnStart, OnStop {
- private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
+ public static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
private LocalBluetoothManager mBluetoothManager;
private MasterSwitchPreference mBtPreference;
private BluetoothEnabler mBluetoothEnabler;
private BluetoothSummaryUpdater mSummaryUpdater;
+ private RestrictionUtils mRestrictionUtils;
public BluetoothMasterSwitchPreferenceController(Context context,
LocalBluetoothManager bluetoothManager) {
+ this(context, bluetoothManager, new RestrictionUtils());
+ }
+
+ @VisibleForTesting
+ public BluetoothMasterSwitchPreferenceController(Context context,
+ LocalBluetoothManager bluetoothManager, RestrictionUtils restrictionUtils) {
super(context);
mBluetoothManager = bluetoothManager;
mSummaryUpdater = new BluetoothSummaryUpdater(mContext, this, mBluetoothManager);
+ mRestrictionUtils = restrictionUtils;
}
@Override
@@ -56,7 +65,8 @@
mBluetoothEnabler = new BluetoothEnabler(mContext,
new MasterSwitchController(mBtPreference),
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager,
- MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE);
+ MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
+ mRestrictionUtils);
}
@Override
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingService.java b/src/com/android/settings/bluetooth/BluetoothPairingService.java
index 41a5cce..58df919 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingService.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingService.java
@@ -17,6 +17,8 @@
package com.android.settings.bluetooth;
import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
@@ -37,119 +39,147 @@
*/
public final class BluetoothPairingService extends Service {
- private static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;
+ private static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;
- private static final String TAG = "BluetoothPairingService";
+ private static final String ACTION_DISMISS_PAIRING =
+ "com.android.settings.bluetooth.ACTION_DISMISS_PAIRING";
- private BluetoothDevice mDevice;
+ private static final String BLUETOOTH_NOTIFICATION_CHANNEL =
+ "bluetooth_notification_channel";
- public static Intent getPairingDialogIntent(Context context, Intent intent) {
+ private static final String TAG = "BluetoothPairingService";
- BluetoothDevice device =
- intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
- BluetoothDevice.ERROR);
- Intent pairingIntent = new Intent();
- pairingIntent.setClass(context, BluetoothPairingDialog.class);
- pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
- pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
- if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION ||
- type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY ||
- type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
- int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
- BluetoothDevice.ERROR);
- pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
- }
- pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
- pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- return pairingIntent;
- }
+ private BluetoothDevice mDevice;
- private boolean mRegistered = false;
- private final BroadcastReceiver mCancelReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
- int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
- BluetoothDevice.ERROR);
- if ((bondState != BluetoothDevice.BOND_NONE) && (bondState != BluetoothDevice.BOND_BONDED)) {
- return;
+ public static Intent getPairingDialogIntent(Context context, Intent intent) {
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
+ BluetoothDevice.ERROR);
+ Intent pairingIntent = new Intent();
+ pairingIntent.setClass(context, BluetoothPairingDialog.class);
+ pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
+ pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
+ if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION ||
+ type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY ||
+ type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
+ int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
+ BluetoothDevice.ERROR);
+ pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
}
- Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" + mDevice.getName() + "), BondState: " + bondState);
- } else {
- Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" + mDevice.getName() + "), Cancelled.");
- }
- stopForeground(true);
- stopSelf();
- }
- };
-
- @Override
- public void onCreate() {
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- if (intent == null) {
- Log.e(TAG, "Can't start: null intent!");
- stopSelf();
- return START_NOT_STICKY;
+ pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
+ pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ return pairingIntent;
}
- Resources res = getResources();
- Notification.Builder builder = new Notification.Builder(this)
- .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
- .setTicker(res.getString(R.string.bluetooth_notif_ticker));
+ private boolean mRegistered = false;
+ private final BroadcastReceiver mCancelReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
+ int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
+ BluetoothDevice.ERROR);
+ if ((bondState != BluetoothDevice.BOND_NONE) && (bondState != BluetoothDevice.BOND_BONDED)) {
+ return;
+ }
+ } else if (action.equals(ACTION_DISMISS_PAIRING)) {
+ Log.d(TAG, "Notification cancel " + mDevice.getAddress() + " (" +
+ mDevice.getName() + ")");
+ mDevice.cancelPairingUserInput();
+ } else {
+ int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
+ BluetoothDevice.ERROR);
+ Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" +
+ mDevice.getName() + "), BondState: " + bondState);
+ }
+ stopForeground(true);
+ stopSelf();
+ }
+ };
- PendingIntent pending = PendingIntent.getActivity(this, 0,
- getPairingDialogIntent(this, intent), PendingIntent.FLAG_ONE_SHOT);
-
- mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
-
- if (mDevice.getBondState() != BluetoothDevice.BOND_BONDING) {
- Log.w(TAG, "Device " + mDevice + " not bonding: " + mDevice.getBondState());
- stopSelf();
- return START_NOT_STICKY;
+ @Override
+ public void onCreate() {
+ NotificationManager mgr = (NotificationManager)this
+ .getSystemService(Context.NOTIFICATION_SERVICE);
+ NotificationChannel notificationChannel = new NotificationChannel(
+ BLUETOOTH_NOTIFICATION_CHANNEL,
+ this.getString(R.string.bluetooth),
+ NotificationManager.IMPORTANCE_HIGH);
+ mgr.createNotificationChannel(notificationChannel);
}
- String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
- if (TextUtils.isEmpty(name)) {
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- name = device != null ? device.getAliasName() : getString(android.R.string.unknownName);
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent == null) {
+ Log.e(TAG, "Can't start: null intent!");
+ stopSelf();
+ return START_NOT_STICKY;
+ }
+
+ Resources res = getResources();
+ Notification.Builder builder = new Notification.Builder(this,
+ BLUETOOTH_NOTIFICATION_CHANNEL)
+ .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
+ .setTicker(res.getString(R.string.bluetooth_notif_ticker));
+
+ PendingIntent pairIntent = PendingIntent.getActivity(this, 0,
+ getPairingDialogIntent(this, intent), PendingIntent.FLAG_ONE_SHOT);
+
+ PendingIntent dismissIntent = PendingIntent.getBroadcast(this, 0,
+ new Intent(ACTION_DISMISS_PAIRING), PendingIntent.FLAG_ONE_SHOT);
+
+ mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+
+ if (mDevice != null && mDevice.getBondState() != BluetoothDevice.BOND_BONDING) {
+ Log.w(TAG, "Device " + mDevice + " not bonding: " + mDevice.getBondState());
+ stopSelf();
+ return START_NOT_STICKY;
+ }
+
+ String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
+ if (TextUtils.isEmpty(name)) {
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ name = device != null ? device.getAliasName() : res.getString(android.R.string.unknownName);
+ }
+
+ Log.d(TAG, "Show pairing notification for " + mDevice.getAddress() + " (" + name + ")");
+
+ Notification.Action pairAction = new Notification.Action.Builder(0,
+ res.getString(R.string.bluetooth_device_context_pair_connect), pairIntent).build();
+ Notification.Action dismissAction = new Notification.Action.Builder(0,
+ res.getString(android.R.string.cancel), dismissIntent).build();
+
+ builder.setContentTitle(res.getString(R.string.bluetooth_notif_title))
+ .setContentText(res.getString(R.string.bluetooth_notif_message, name))
+ .setContentIntent(pairIntent)
+ .setDefaults(Notification.DEFAULT_SOUND)
+ .setColor(getColor(com.android.internal.R.color.system_notification_accent_color))
+ .addAction(pairAction)
+ .addAction(dismissAction);
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
+ filter.addAction(BluetoothDevice.ACTION_PAIRING_CANCEL);
+ filter.addAction(ACTION_DISMISS_PAIRING);
+ registerReceiver(mCancelReceiver, filter);
+ mRegistered = true;
+
+ startForeground(NOTIFICATION_ID, builder.getNotification());
+ return START_REDELIVER_INTENT;
}
- Log.d(TAG, "Show pairing notification for " + mDevice.getAddress() + " (" + name + ")");
-
- builder.setContentTitle(res.getString(R.string.bluetooth_notif_title))
- .setContentText(res.getString(R.string.bluetooth_notif_message, name))
- .setContentIntent(pending)
- .setDefaults(Notification.DEFAULT_SOUND)
- .setColor(getColor(com.android.internal.R.color.system_notification_accent_color));
-
- IntentFilter filter = new IntentFilter();
- filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
- filter.addAction(BluetoothDevice.ACTION_PAIRING_CANCEL);
- registerReceiver(mCancelReceiver, filter);
- mRegistered = true;
-
- startForeground(NOTIFICATION_ID, builder.getNotification());
- return START_REDELIVER_INTENT;
- }
-
- @Override
- public void onDestroy() {
- if (mRegistered) {
- unregisterReceiver(mCancelReceiver);
- mRegistered = false;
+ @Override
+ public void onDestroy() {
+ if (mRegistered) {
+ unregisterReceiver(mCancelReceiver);
+ mRegistered = false;
+ }
+ stopForeground(true);
}
- stopForeground(true);
- }
- @Override
- public IBinder onBind(Intent intent) {
- // No binding.
- return null;
- }
-
+ @Override
+ public IBinder onBind(Intent intent) {
+ // No binding.
+ return null;
+ }
}
diff --git a/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java b/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
index 282f613..5a2dcb2 100644
--- a/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
@@ -17,14 +17,22 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
import android.content.Context;
+import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
+
import com.android.settings.R;
import com.android.settings.widget.SummaryUpdater;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
+
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
+import java.util.Set;
/**
* Helper class that listeners to bluetooth callback and notify client when there is update in
@@ -98,7 +106,7 @@
}
switch (mConnectionState) {
case BluetoothAdapter.STATE_CONNECTED:
- return mContext.getString(R.string.bluetooth_connected_summary);
+ return getConnectedDeviceSummary();
case BluetoothAdapter.STATE_CONNECTING:
return mContext.getString(R.string.bluetooth_connecting);
case BluetoothAdapter.STATE_DISCONNECTING:
@@ -145,4 +153,27 @@
: null;
}
+ @VisibleForTesting
+ String getConnectedDeviceSummary() {
+ String deviceName = null;
+ int count = 0;
+ final Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices();
+ if (devices == null || devices.isEmpty()) {
+ return null;
+ }
+
+ for (BluetoothDevice device : devices) {
+ if (device.isConnected()) {
+ deviceName = device.getName();
+ count++;
+ if (count > 1) {
+ break;
+ }
+ }
+ }
+
+ return count > 1 ? mContext.getString(R.string.bluetooth_connected_multiple_devices_summary)
+ : mContext.getString(R.string.bluetooth_connected_summary, deviceName);
+ }
+
}
diff --git a/src/com/android/settings/bluetooth/RestrictionUtils.java b/src/com/android/settings/bluetooth/RestrictionUtils.java
new file mode 100644
index 0000000..9c0c481
--- /dev/null
+++ b/src/com/android/settings/bluetooth/RestrictionUtils.java
@@ -0,0 +1,43 @@
+/*
+ * 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.bluetooth;
+
+import android.content.Context;
+import android.os.UserHandle;
+
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
+/**
+ * A utility class to aid testing.
+ */
+public class RestrictionUtils {
+
+ public RestrictionUtils() {}
+
+ /**
+ * Utility method to check if user restriction is enforced on the current user.
+ *
+ * <p> It helps with testing - override it to avoid calling static method which calls system
+ * API.
+ */
+ public EnforcedAdmin checkIfRestrictionEnforced(Context context, String restriction) {
+ return RestrictedLockUtils.checkIfRestrictionEnforced(
+ context, restriction, UserHandle.myUserId());
+ }
+
+}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index b12e849..aeb7efb 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.connecteddevice;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto;
@@ -85,5 +86,20 @@
sir.xmlResId = R.xml.connected_devices;
return Arrays.asList(sir);
}
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ PackageManager pm = context.getPackageManager();
+ final List<String> keys = new ArrayList<String>();
+
+ if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
+ keys.add(NfcPreferenceController.KEY_TOGGLE_NFC);
+ keys.add(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+ }
+ if (!pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
+ keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
+ }
+ return keys;
+ }
};
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java b/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java
index 9a92c93..bdd5c60 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java
@@ -17,19 +17,13 @@
package com.android.settings.dashboard.suggestions;
import android.app.AutomaticZenRule;
-import android.app.IWallpaperManager;
-import android.app.IWallpaperManager.Stub;
-import android.app.IWallpaperManagerCallback;
import android.app.KeyguardManager;
import android.app.NotificationManager;
import android.app.WallpaperManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.hardware.fingerprint.FingerprintManager;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.ServiceManager;
+import android.support.annotation.VisibleForTesting;
import com.android.ims.ImsManager;
import com.android.settings.Settings.FingerprintEnrollSuggestionActivity;
@@ -49,10 +43,14 @@
*/
public class SuggestionsChecks {
+ private static final String TAG = "SuggestionsChecks";
private final Context mContext;
+ private final WallpaperManagerWrapper mWallpaperManager;
+
public SuggestionsChecks(Context context) {
mContext = context.getApplicationContext();
+ mWallpaperManager = new WallpaperManagerWrapper(mContext);
}
public boolean isSuggestionComplete(Tile suggestion) {
@@ -68,11 +66,15 @@
} 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 =
- FeatureFactory.getFactory(mContext).getSuggestionFeatureProvider(mContext);
+ FeatureFactory.getFactory(mContext).getSuggestionFeatureProvider(mContext);
if (provider != null && provider.isPresent(className)) {
return provider.isSuggestionCompleted(mContext);
}
@@ -110,16 +112,9 @@
return false;
}
- private boolean hasWallpaperSet() {
- IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
- IWallpaperManager service = Stub.asInterface(b);
- try {
- return !service.isSetWallpaperAllowed(mContext.getOpPackageName()) ||
- service.getWallpaper(mCallback, WallpaperManager.FLAG_SYSTEM,
- new Bundle(), mContext.getUserId()) != null;
- } catch (RemoteException e) {
- }
- return false;
+ @VisibleForTesting
+ boolean hasWallpaperSet() {
+ return mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
}
private boolean isFingerprintEnabled() {
@@ -129,11 +124,4 @@
mContext.getUserId());
return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) == 0;
}
-
- private final IWallpaperManagerCallback mCallback = new IWallpaperManagerCallback.Stub() {
- @Override
- public void onWallpaperChanged() throws RemoteException {
- // Don't care.
- }
- };
}
diff --git a/tests/robotests/src/android/util/LauncherIcons.java b/src/com/android/settings/dashboard/suggestions/WallpaperManagerWrapper.java
similarity index 60%
rename from tests/robotests/src/android/util/LauncherIcons.java
rename to src/com/android/settings/dashboard/suggestions/WallpaperManagerWrapper.java
index a18cfae..9efe4fe 100644
--- a/tests/robotests/src/android/util/LauncherIcons.java
+++ b/src/com/android/settings/dashboard/suggestions/WallpaperManagerWrapper.java
@@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package android.util;
+package com.android.settings.dashboard.suggestions;
+
+import android.app.WallpaperManager;
import android.content.Context;
-import android.graphics.drawable.Drawable;
-/**
- * This class is only needed to get around RoboElectric issue.
- */
-public final class LauncherIcons {
+public class WallpaperManagerWrapper {
- public LauncherIcons(Context context) {
+ private final WallpaperManager mWallpaperManager;
+
+ public WallpaperManagerWrapper(Context context) {
+ mWallpaperManager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
}
- public Drawable wrapIconDrawableWithShadow(Drawable drawable) {
- return drawable;
+ public int getWallpaperId(int which) {
+ return mWallpaperManager.getWallpaperId(which);
}
}
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index e98ca20..a448b5c 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -40,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;
@@ -158,7 +159,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) {
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/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index adf2938..a2fe07d 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -123,9 +123,6 @@
boolean isStorageManagerChecked =
Settings.Secure.getInt(getContentResolver(),
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
- // Using the setCheckedInternal means the checked status won't propagate through the
- // listeners -- this will prevent us from accidentally causing a metrics event on resume.
- mSwitchBar.setCheckedInternal(isStorageManagerChecked);
mDaysToRetain.setEnabled(isStorageManagerChecked);
}
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
index a648102..8ab1a07 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
@@ -52,6 +52,17 @@
mDaysToRetainPreference = Preconditions.checkNotNull(daysToRetainPreference);
mFragmentManager = Preconditions.checkNotNull(fragmentManager);
+ initializeCheckedStatus();
+ }
+
+ private void initializeCheckedStatus() {
+ boolean isStorageManagerChecked =
+ Settings.Secure.getInt(
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
+ 0)
+ != 0;
+ mSwitchBar.setChecked(isStorageManagerChecked);
mSwitchBar.addOnSwitchChangeListener(this);
}
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index bfb9f0f..583a5eb 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -127,7 +127,6 @@
private static final String ENABLE_TERMINAL = "enable_terminal";
private static final String KEEP_SCREEN_ON = "keep_screen_on";
private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
- private static final String WEBVIEW_MULTIPROCESS_KEY = "enable_webview_multiprocess";
private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
private static final String HDCP_CHECKING_KEY = "hdcp_checking";
private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
@@ -319,7 +318,6 @@
private ListPreference mOverlayDisplayDevices;
private WebViewAppPreferenceController mWebViewAppPrefController;
- private SwitchPreference mWebViewMultiprocess;
private ListPreference mSimulateColorSpace;
@@ -497,7 +495,6 @@
mLogpersist = null;
}
mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
- mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
mBluetoothEnableInbandRinging = findAndInitSwitchPref(BLUETOOTH_ENABLE_INBAND_RINGING_KEY);
if (!BluetoothHeadset.isInbandRingingSupported(getContext())) {
@@ -814,7 +811,6 @@
updateForceResizableOptions();
Preference webViewAppPref = findPreference(mWebViewAppPrefController.getPreferenceKey());
mWebViewAppPrefController.updateState(webViewAppPref);
- updateWebViewMultiprocessOptions();
updateOemUnlockOptions();
if (mColorTemperaturePreference != null) {
updateColorTemperature();
@@ -852,21 +848,6 @@
pokeSystemProperties();
}
- private void updateWebViewMultiprocessOptions() {
- try {
- updateSwitchPreference(mWebViewMultiprocess,
- mWebViewUpdateService.isMultiProcessEnabled());
- } catch (RemoteException e) {
- }
- }
-
- private void writeWebViewMultiprocessOptions() {
- try {
- mWebViewUpdateService.enableMultiProcess(mWebViewMultiprocess.isChecked());
- } catch (RemoteException e) {
- }
- }
-
private void updateHdcpValues() {
ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
if (hdcpChecking != null) {
@@ -2551,8 +2532,6 @@
writeBluetoothDisableAbsVolumeOptions();
} else if (preference == mBluetoothEnableInbandRinging) {
writeBluetoothEnableInbandRingingOptions();
- } else if (preference == mWebViewMultiprocess) {
- writeWebViewMultiprocessOptions();
} else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
resetShortcutManagerThrottling();
} else {
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeForget.java b/src/com/android/settings/deviceinfo/PrivateVolumeForget.java
index a8e119d..b6d50ce 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeForget.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeForget.java
@@ -53,8 +53,18 @@
Bundle savedInstanceState) {
final StorageManager storage = getActivity().getSystemService(StorageManager.class);
final String fsUuid = getArguments().getString(VolumeRecord.EXTRA_FS_UUID);
+ // Passing null will crash the StorageManager, so let's early exit.
+ if (fsUuid == null) {
+ getActivity().finish();
+ return null;
+ }
mRecord = storage.findRecordByUuid(fsUuid);
+ if (mRecord == null) {
+ getActivity().finish();
+ return null;
+ }
+
final View view = inflater.inflate(R.layout.storage_internal_forget, container, false);
final TextView body = (TextView) view.findViewById(R.id.body);
final Button confirm = (Button) view.findViewById(R.id.confirm);
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index f7bb95d..2a5ac17 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -19,7 +19,6 @@
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;
@@ -29,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;
@@ -58,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>> {
@@ -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);
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 36694f0..31ca148 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) {
@@ -263,6 +275,7 @@
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
intent.setType(IMAGE_MIME_TYPE);
+ intent.putExtra(Intent.EXTRA_FROM_STORAGE, true);
return intent;
}
diff --git a/src/com/android/settings/display/AutoBrightnessPreferenceController.java b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
index 83304c2..6f9a302 100644
--- a/src/com/android/settings/display/AutoBrightnessPreferenceController.java
+++ b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
@@ -33,10 +33,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 +48,7 @@
@Override
public String getPreferenceKey() {
- return KEY_AUTO_BRIGHTNESS;
+ return mAutoBrightnessKey;
}
@Override
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 0c798a6..0cbfd54 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -28,6 +28,7 @@
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
+import android.text.TextUtils;
import android.view.View;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -40,6 +41,7 @@
import com.android.settings.applications.AppHeaderController;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.PreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.enterprise.DevicePolicyManagerWrapper;
import com.android.settings.enterprise.DevicePolicyManagerWrapperImpl;
import com.android.settings.overlay.FeatureFactory;
@@ -55,7 +57,7 @@
* 2. Battery related controls for app(i.e uninstall, force stop)
*
*/
-public class AdvancedPowerUsageDetail extends PowerUsageBase implements
+public class AdvancedPowerUsageDetail extends DashboardFragment implements
ButtonActionDialogFragment.AppButtonsDialogListener {
public static final String TAG = "AdvancedPowerUsageDetail";
@@ -82,6 +84,8 @@
ApplicationsState mState;
@VisibleForTesting
ApplicationsState.AppEntry mAppEntry;
+ @VisibleForTesting
+ BatteryUtils mBatteryUtils;
private Preference mForegroundPreference;
private Preference mBackgroundPreference;
@@ -101,11 +105,12 @@
final BatterySipper sipper = entry.sipper;
final BatteryStats.Uid uid = sipper.uidObj;
final BatteryUtils batteryUtils = BatteryUtils.getInstance(caller);
+ final boolean isTypeApp = sipper.drainType == BatterySipper.DrainType.APP;
- final long backgroundTimeMs = batteryUtils.getProcessTimeMs(
- BatteryUtils.StatusType.BACKGROUND, uid, which);
- final long foregroundTimeMs = batteryUtils.getProcessTimeMs(
- BatteryUtils.StatusType.FOREGROUND, uid, which);
+ final long foregroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(
+ BatteryUtils.StatusType.FOREGROUND, uid, which) : sipper.usageTimeMs;
+ final long backgroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(
+ BatteryUtils.StatusType.BACKGROUND, uid, which) : 0;
if (ArrayUtils.isEmpty(sipper.mPackages)) {
// populate data for system app
@@ -136,6 +141,7 @@
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE));
mUserManager = (UserManager) activity.getSystemService(Context.USER_SERVICE);
mPackageManager = activity.getPackageManager();
+ mBatteryUtils = BatteryUtils.getInstance(getContext());
}
@Override
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/BatteryStatsHelperLoader.java b/src/com/android/settings/fuelgauge/BatteryStatsHelperLoader.java
new file mode 100644
index 0000000..b99519b
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryStatsHelperLoader.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.fuelgauge;
+
+import android.content.Context;
+import android.os.BatteryStats;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.utils.AsyncLoader;
+
+/**
+ * Loader to get new {@link BatteryStatsHelper} in the background
+ */
+public class BatteryStatsHelperLoader extends AsyncLoader<BatteryStatsHelper> {
+ @VisibleForTesting
+ UserManager mUserManager;
+ private Bundle mBundle;
+
+ public BatteryStatsHelperLoader(Context context, Bundle bundle) {
+ super(context);
+ mBundle = bundle;
+ mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ }
+
+ @Override
+ public BatteryStatsHelper loadInBackground() {
+ final BatteryStatsHelper statsHelper = new BatteryStatsHelper(getContext(), true);
+
+ initBatteryStatsHelper(statsHelper);
+ return statsHelper;
+ }
+
+ @Override
+ protected void onDiscardResult(BatteryStatsHelper result) {
+
+ }
+
+ @VisibleForTesting
+ void initBatteryStatsHelper(BatteryStatsHelper statsHelper) {
+ statsHelper.create(mBundle);
+ statsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, mUserManager.getUserProfiles());
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 48e2421..dad7b59 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -15,14 +15,13 @@
*/
package com.android.settings.fuelgauge;
-import android.annotation.IntDef;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.BatteryStats;
import android.os.SystemClock;
+import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
-import android.text.format.DateUtils;
import android.util.Log;
import com.android.internal.os.BatterySipper;
@@ -64,7 +63,8 @@
return sInstance;
}
- private BatteryUtils(Context context) {
+ @VisibleForTesting
+ BatteryUtils(Context context) {
mPackageManager = context.getPackageManager();
mPowerUsageFeatureProvider = FeatureFactory.getFactory(
context).getPowerUsageFeatureProvider(context);
@@ -102,7 +102,6 @@
final long rawRealTimeUs = convertMsToUs(SystemClock.elapsedRealtime());
final int foregroundTypes[] = {BatteryStats.Uid.PROCESS_STATE_TOP,
BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE,
- BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING,
BatteryStats.Uid.PROCESS_STATE_FOREGROUND};
Log.v(TAG, "package: " + mPackageManager.getNameForUid(uid.getUid()));
@@ -129,9 +128,8 @@
final BatterySipper sipper = sippers.get(i);
if (shouldHideSipper(sipper)) {
sippers.remove(i);
- if (sipper.drainType != BatterySipper.DrainType.OVERCOUNTED
- && sipper.drainType != BatterySipper.DrainType.UNACCOUNTED) {
- // Don't add it if it is overcounted or unaccounted
+ if (sipper.drainType != BatterySipper.DrainType.OVERCOUNTED) {
+ // Don't add it if it is overcounted
totalPowerMah += sipper.totalPowerMah;
}
}
diff --git a/src/com/android/settings/fuelgauge/PowerGaugePreference.java b/src/com/android/settings/fuelgauge/PowerGaugePreference.java
index bdadf4c..b124c81 100644
--- a/src/com/android/settings/fuelgauge/PowerGaugePreference.java
+++ b/src/com/android/settings/fuelgauge/PowerGaugePreference.java
@@ -79,11 +79,15 @@
return mProgress.toString();
}
- public void setSubtitle(String subtitle) {
+ public void setSubtitle(CharSequence subtitle) {
mProgress = subtitle;
notifyChanged();
}
+ public CharSequence getSubtitle() {
+ return mProgress;
+ }
+
BatteryEntry getInfo() {
return mInfo;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index 722f4ad..4ebff34 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -29,6 +29,7 @@
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
+import android.text.TextUtils;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.os.BatterySipper;
@@ -60,7 +61,6 @@
final int[] mUsageTypes = {
UsageType.WIFI,
UsageType.CELL,
- UsageType.SERVICE,
UsageType.SYSTEM,
UsageType.BLUETOOTH,
UsageType.USER,
@@ -68,13 +68,14 @@
UsageType.APP,
UsageType.UNACCOUNTED,
UsageType.OVERCOUNTED};
+
+ private BatteryUtils mBatteryUtils;
private BatteryHistoryPreference mHistPref;
private PreferenceGroup mUsageListGroup;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
private PackageManager mPackageManager;
private UserManager mUserManager;
private Map<Integer, PowerUsageData> mBatteryDataMap;
- private BatteryUtils mBatteryUtils;
Handler mHandler = new Handler() {
@@ -124,7 +125,6 @@
@Override
public void onResume() {
super.onResume();
- refreshStats();
}
@Override
@@ -163,8 +163,11 @@
}
@Override
- protected void refreshStats() {
- super.refreshStats();
+ protected void refreshUi() {
+ final Context context = getContext();
+ if (context == null) {
+ return;
+ }
updatePreference(mHistPref);
@@ -207,10 +210,9 @@
return UsageType.UNACCOUNTED;
} else if (drainType == DrainType.OVERCOUNTED) {
return UsageType.OVERCOUNTED;
- } else if (mPowerUsageFeatureProvider.isTypeSystem(sipper)) {
+ } else if (mPowerUsageFeatureProvider.isTypeSystem(sipper)
+ || mPowerUsageFeatureProvider.isTypeService(sipper)) {
return UsageType.SYSTEM;
- } else if (mPowerUsageFeatureProvider.isTypeService(sipper)) {
- return UsageType.SERVICE;
} else {
return UsageType.APP;
}
@@ -255,8 +257,10 @@
final List<PowerUsageData> batteryDataList = new ArrayList<>(batteryDataMap.values());
final int dischargeAmount = statusHelper.getStats().getDischargeAmount(STATUS_TYPE);
final double totalPower = statusHelper.getTotalPower();
+ final double hiddenPower = calculateHiddenPower(batteryDataList);
for (final PowerUsageData usageData : batteryDataList) {
- usageData.percentage = (usageData.totalPowerMah / totalPower) * dischargeAmount;
+ usageData.percentage = mBatteryUtils.calculateBatteryPercent(usageData.totalPowerMah,
+ totalPower, hiddenPower, dischargeAmount);
updateUsageDataSummary(usageData, totalPower, dischargeAmount);
}
@@ -267,13 +271,26 @@
}
@VisibleForTesting
+ double calculateHiddenPower(List<PowerUsageData> batteryDataList) {
+ for (final PowerUsageData usageData : batteryDataList) {
+ if (usageData.usageType == UsageType.UNACCOUNTED) {
+ return usageData.totalPowerMah;
+ }
+ }
+
+ return 0;
+ }
+
+ @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));
+ CharSequence timeSequence = Utils.formatElapsedTime(getContext(),
+ usageData.totalUsageTimeMs, false);
+ usageData.summary = TextUtils.expandTemplate(getText(R.string.battery_used_for),
+ timeSequence);
} else {
BatterySipper sipper = findBatterySipperWithMaxBatteryUsage(usageData.usageList);
BatteryEntry batteryEntry = new BatteryEntry(getContext(), mHandler, mUserManager,
@@ -317,6 +334,10 @@
void setUserManager(UserManager userManager) {
mUserManager = userManager;
}
+ @VisibleForTesting
+ void setBatteryUtils(BatteryUtils batteryUtils) {
+ mBatteryUtils = batteryUtils;
+ }
/**
* Class that contains data used in {@link PowerGaugePreference}.
@@ -328,7 +349,6 @@
@IntDef({UsageType.APP,
UsageType.WIFI,
UsageType.CELL,
- UsageType.SERVICE,
UsageType.SYSTEM,
UsageType.BLUETOOTH,
UsageType.USER,
@@ -339,18 +359,17 @@
int APP = 0;
int WIFI = 1;
int CELL = 2;
- int SERVICE = 3;
- int SYSTEM = 4;
- int BLUETOOTH = 5;
- int USER = 6;
- int IDLE = 7;
- int UNACCOUNTED = 8;
- int OVERCOUNTED = 9;
+ int SYSTEM = 3;
+ int BLUETOOTH = 4;
+ int USER = 5;
+ int IDLE = 6;
+ int UNACCOUNTED = 7;
+ int OVERCOUNTED = 8;
}
@StringRes
public int titleResId;
- public String summary;
+ public CharSequence summary;
public double percentage;
public double totalPowerMah;
public long totalUsageTimeMs;
@@ -379,8 +398,6 @@
return R.string.power_wifi;
case UsageType.CELL:
return R.string.power_cell;
- case UsageType.SERVICE:
- return R.string.power_service;
case UsageType.SYSTEM:
return R.string.power_system;
case UsageType.BLUETOOTH:
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 1d9a228..aee55d6 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -16,28 +16,23 @@
package com.android.settings.fuelgauge;
import android.app.Activity;
-import android.content.BroadcastReceiver;
+import android.app.LoaderManager;
import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.BatteryStats;
+import android.content.Loader;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import com.android.internal.os.BatteryStatsHelper;
-import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.utils.AsyncLoader;
/**
* Common base class for things that need to show the battery usage graph.
*/
-public abstract class PowerUsageBase extends DashboardFragment {
+public abstract class PowerUsageBase extends DashboardFragment
+ implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> {
// +1 to allow ordering for PowerUsageSummary.
@VisibleForTesting
@@ -62,27 +57,23 @@
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
- if (!mHandler.hasMessages(MSG_REFRESH_STATS)) {
- mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500);
- }
+ getLoaderManager().restartLoader(0, null, this);
});
+
+ getLoaderManager().initLoader(0, icicle, this);
}
@Override
public void onStart() {
super.onStart();
- mStatsHelper.clearStats();
}
@Override
public void onResume() {
super.onResume();
+
BatteryStatsHelper.dropFile(getActivity(), BatteryHistoryDetail.BATTERY_HISTORY_FILE);
mBatteryBroadcastReceiver.register();
- if (mHandler.hasMessages(MSG_REFRESH_STATS)) {
- mHandler.removeMessages(MSG_REFRESH_STATS);
- mStatsHelper.clearStats();
- }
}
@Override
@@ -94,7 +85,6 @@
@Override
public void onStop() {
super.onStop();
- mHandler.removeMessages(MSG_REFRESH_STATS);
}
@Override
@@ -105,26 +95,27 @@
}
}
- protected void refreshStats() {
- mStatsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, mUm.getUserProfiles());
- }
+ protected abstract void refreshUi();
protected void updatePreference(BatteryHistoryPreference historyPref) {
historyPref.setStats(mStatsHelper);
}
- static final int MSG_REFRESH_STATS = 100;
+ @Override
+ public Loader<BatteryStatsHelper> onCreateLoader(int id,
+ Bundle args) {
+ return new BatteryStatsHelperLoader(getContext(), args);
+ }
- private final Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_REFRESH_STATS:
- mStatsHelper.clearStats();
- refreshStats();
- break;
- }
- }
- };
+ @Override
+ public void onLoadFinished(Loader<BatteryStatsHelper> loader,
+ BatteryStatsHelper statsHelper) {
+ mStatsHelper = statsHelper;
+ refreshUi();
+ }
+ @Override
+ public void onLoaderReset(Loader<BatteryStatsHelper> loader) {
+
+ }
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 5f12d7c..bcf830b 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -18,6 +18,8 @@
import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.BatteryStats;
import android.os.Build;
@@ -86,6 +88,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
@@ -139,7 +144,6 @@
@Override
public void onResume() {
super.onResume();
- refreshStats();
}
@Override
@@ -185,8 +189,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;
@@ -233,7 +237,7 @@
} else {
mStatsType = BatteryStats.STATS_SINCE_CHARGED;
}
- refreshStats();
+ refreshUi();
return true;
case MENU_HIGH_POWER_APPS:
Bundle args = new Bundle();
@@ -256,7 +260,7 @@
item.setTitle(mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps);
metricsFeatureProvider.action(context,
MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE, mShowAllApps);
- refreshStats();
+ refreshUi();
return true;
default:
return super.onOptionsItemSelected(item);
@@ -393,15 +397,11 @@
return results;
}
- protected void refreshStats() {
- super.refreshStats();
-
- BatteryInfo.getBatteryInfo(getContext(), new BatteryInfo.Callback() {
- @Override
- public void onBatteryInfoLoaded(BatteryInfo info) {
- updateHeaderPreference(info);
- }
- });
+ protected void refreshUi() {
+ final Context context = getContext();
+ if (context == null) {
+ return;
+ }
cacheRemoveAllPrefs(mAppListGroup);
mAppListGroup.setOrderingAsAdded(false);
@@ -410,20 +410,27 @@
final PowerProfile powerProfile = mStatsHelper.getPowerProfile();
final BatteryStats stats = mStatsHelper.getStats();
final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
- final Context context = getContext();
+
+ final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
+ Intent batteryBroadcast = context.registerReceiver(null,
+ new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ BatteryInfo batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast,
+ mStatsHelper.getStats(), elapsedRealtimeUs, false);
+ updateHeaderPreference(batteryInfo);
final TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.colorControlNormal, value, true);
final int colorControl = context.getColor(value.resourceId);
- final String usedTime = context.getString(R.string.battery_used_for);
final int dischargeAmount = USE_FAKE_DATA ? 5000
: stats != null ? stats.getDischargeAmount(mStatsType) : 0;
final long runningTime = calculateRunningTimeBasedOnStatsType();
updateScreenPreference();
updateLastFullChargePreference(runningTime);
- mAppListGroup.setTitle(getString(R.string.power_usage_list_summary,
- Utils.formatElapsedTime(context, runningTime, false)));
+
+ final CharSequence timeSequence = Utils.formatElapsedTime(context, runningTime, false);
+ mAppListGroup.setTitle(
+ TextUtils.expandTemplate(getText(R.string.power_usage_list_summary), timeSequence));
if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
final List<BatterySipper> usageList = getCoalescedUsageList(
@@ -494,7 +501,7 @@
sipper.usageTimeMs = mBatteryUtils.getProcessTimeMs(
BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, mStatsType);
}
- setUsageSummary(pref, usedTime, sipper.usageTimeMs);
+ setUsageSummary(pref, sipper.usageTimeMs);
if ((sipper.drainType != DrainType.APP
|| sipper.uidObj.getUid() == Process.ROOT_UID)
&& sipper.drainType != DrainType.USER) {
@@ -531,16 +538,17 @@
void updateScreenPreference() {
final BatterySipper sipper = findBatterySipperByType(
mStatsHelper.getUsageList(), DrainType.SCREEN);
- final Context context = getContext();
final long usageTimeMs = sipper != null ? sipper.usageTimeMs : 0;
- mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(context, usageTimeMs, false));
+ mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(getContext(), usageTimeMs, false));
}
@VisibleForTesting
void updateLastFullChargePreference(long timeMs) {
- mLastFullChargePref.setSubtitle(getString(R.string.power_last_full_charge_summary,
- Utils.formatElapsedTime(getContext(), timeMs, false)));
+ final CharSequence timeSequence = Utils.formatElapsedTime(getContext(), timeMs, false);
+ mLastFullChargePref.setSubtitle(
+ TextUtils.expandTemplate(getText(R.string.power_last_full_charge_summary),
+ timeSequence));
}
@VisibleForTesting
@@ -580,11 +588,13 @@
}
@VisibleForTesting
- void setUsageSummary(Preference preference, String usedTimePrefix, long usageTimeMs) {
+ void setUsageSummary(Preference preference, long usageTimeMs) {
// Only show summary when usage time is longer than one minute
if (usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
- preference.setSummary(String.format(usedTimePrefix,
- Utils.formatElapsedTime(getContext(), usageTimeMs, false)));
+ final CharSequence timeSequence = Utils.formatElapsedTime(getContext(), usageTimeMs,
+ false);
+ preference.setSummary(
+ TextUtils.expandTemplate(getText(R.string.battery_used_for), timeSequence));
}
}
@@ -718,6 +728,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/inputmethod/VirtualKeyboardPreferenceController.java b/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceController.java
index b7bf3dc..5436901 100644
--- a/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceController.java
+++ b/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceController.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v7.preference.Preference;
+import android.text.BidiFormatter;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -76,12 +77,15 @@
return;
}
+ final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
+
String summary = null;
for (String label : labels) {
if (summary == null) {
- summary = label;
+ summary = bidiFormatter.unicodeWrap(label);
} else {
- summary = mContext.getString(R.string.join_many_items_middle, summary, label);
+ summary = mContext.getString(R.string.join_many_items_middle, summary,
+ bidiFormatter.unicodeWrap(label));
}
}
preference.setSummary(summary);
diff --git a/src/com/android/settings/nfc/NfcPreferenceController.java b/src/com/android/settings/nfc/NfcPreferenceController.java
index 11e3e09..7164b5b 100644
--- a/src/com/android/settings/nfc/NfcPreferenceController.java
+++ b/src/com/android/settings/nfc/NfcPreferenceController.java
@@ -39,8 +39,8 @@
public class NfcPreferenceController extends PreferenceController
implements LifecycleObserver, OnResume, OnPause {
- private static final String KEY_TOGGLE_NFC = "toggle_nfc";
- private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
+ public static final String KEY_TOGGLE_NFC = "toggle_nfc";
+ public static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
private NfcEnabler mNfcEnabler;
private NfcAdapter mNfcAdapter;
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 4b060cb..db5cf2f 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -16,8 +16,10 @@
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;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import android.app.Activity;
import android.app.NotificationChannel;
@@ -56,9 +58,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() {
@@ -139,6 +145,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 +174,7 @@
int N = channels.size();
for (int i = 0; i < N; i++) {
final NotificationChannel channel = channels.get(i);
- 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);
+ populateSingleChannelPrefs(groupCategory, channel);
}
}
@@ -215,6 +198,76 @@
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
+ || mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
+ mImportanceToggle.setOnPreferenceChangeListener(
+ new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final int importance =
+ ((Boolean) newValue ? IMPORTANCE_UNSPECIFIED : 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 +307,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 8ba5b8b..f6a7b42 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -22,16 +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.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;
@@ -44,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;
@@ -53,9 +49,6 @@
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";
@@ -63,9 +56,6 @@
protected RestrictedSwitchPreference mLights;
protected RestrictedSwitchPreference mVibrate;
protected NotificationSoundPreference mRingtone;
- protected RestrictedDropDownPreference mImportance;
- protected RestrictedSwitchPreference mPriority;
- protected RestrictedDropDownPreference mVisibilityOverride;
@Override
public int getMetricsCategory() {
@@ -224,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));
@@ -256,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/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/search2/DatabaseIndexingManager.java b/src/com/android/settings/search2/DatabaseIndexingManager.java
index 533884d..ccc5283 100644
--- a/src/com/android/settings/search2/DatabaseIndexingManager.java
+++ b/src/com/android/settings/search2/DatabaseIndexingManager.java
@@ -515,7 +515,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 +560,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);
@@ -749,7 +749,6 @@
.setEntries(null)
.setClassName(fragmentName)
.setScreenTitle(screenTitle)
- .setIconResId(iconResId)
.setRank(rank)
.setIntentAction(intentAction)
.setIntentTargetPackage(intentTargetPackage)
diff --git a/src/com/android/settings/search2/SearchFragment.java b/src/com/android/settings/search2/SearchFragment.java
index 8e1e1b4..c5db08d 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();
@@ -252,7 +262,13 @@
return;
}
final int resultCount = mSearchAdapter.displaySearchResults();
- 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..ecc41b6 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 obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof SearchResult)) {
+ return false;
+ }
+ return this.stableId == ((SearchResult) obj).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 6ff68b1..60f2f7c 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;
public SearchResultsAdapter(SearchFragment fragment) {
@@ -128,7 +130,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;
@@ -136,23 +138,25 @@
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++));
}
- mSearchResults.addAll(results);
- notifyDataSetChanged();
+ final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(
+ new SearchResultDiffCallback(mSearchResults, newResults), false /* detectMoves */);
+ mSearchResults = newResults;
+ diffResult.dispatchUpdatesTo(this);
return mSearchResults.size();
}
diff --git a/src/com/android/settings/search2/SearchViewHolder.java b/src/com/android/settings/search2/SearchViewHolder.java
index 123a602..fef9367 100644
--- a/src/com/android/settings/search2/SearchViewHolder.java
+++ b/src/com/android/settings/search2/SearchViewHolder.java
@@ -66,9 +66,11 @@
iconView.setImageDrawable(appResult.info.loadIcon(pm));
} else if (result.icon != null) {
iconView.setImageDrawable(result.icon);
+ // TODO set color of icon
} else {
iconView.setBackgroundResource(R.drawable.empty_icon);
}
+
bindBreadcrumbView(result);
}
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 01551da..66e8c54 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -191,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 =
@@ -204,9 +206,6 @@
mConfigureWifiSettingsPreference = findPreference(PREF_KEY_CONFIGURE_WIFI_SETTINGS);
mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS);
- // Hide additional settings until access points are shown during onStart
- showAdditionalSettings(false);
-
Context prefContext = getPrefContext();
mAddPreference = new Preference(prefContext);
mAddPreference.setIcon(R.drawable.ic_menu_add_inset);
@@ -224,17 +223,6 @@
mBgThread.start();
}
- // TODO(b/37429702): Figure out how to temporarily disable animations during startup and remove
- // this method.
- private void showAdditionalSettings(boolean visible) {
- mAdditionalSettingsPreferenceCategory.setVisible(visible);
- mAdditionalSettingsPreferenceCategory.removeAll();
- if (visible) {
- mAdditionalSettingsPreferenceCategory.addPreference(mConfigureWifiSettingsPreference);
- mAdditionalSettingsPreferenceCategory.addPreference(mSavedNetworksPreference);
- }
- }
-
@Override
public void onDestroy() {
mBgThread.quit();
@@ -359,8 +347,6 @@
getView().removeCallbacks(mUpdateAccessPointsRunnable);
updateAccessPointPreferences();
}
-
- showAdditionalSettings(true);
}
/**
@@ -394,7 +380,6 @@
mWifiTracker.stopTracking();
getView().removeCallbacks(mUpdateAccessPointsRunnable);
getView().removeCallbacks(mHideProgressBarRunnable);
- showAdditionalSettings(false);
super.onStop();
}
diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
index e8bca37..21fda30 100644
--- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
+++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
@@ -301,6 +301,7 @@
Preference pref = new Preference(mPrefContext);
pref.setKey(ip);
pref.setTitle(ip);
+ pref.setSelectable(false);
mIpv6AddressCategory.addPreference(pref);
mIpv6AddressCategory.setVisible(true);
}
diff --git a/tests/robotests/assets/whitelist_duplicate_index_key b/tests/robotests/assets/whitelist_duplicate_index_key
new file mode 100644
index 0000000..5b5153c
--- /dev/null
+++ b/tests/robotests/assets/whitelist_duplicate_index_key
@@ -0,0 +1,12 @@
+add_users_when_locked
+additional_system_update_settings
+dashboard_tile_placeholder
+gesture_assist
+gesture_double_tap_power
+gesture_double_tap_screen
+gesture_double_twist
+gesture_pick_up
+gesture_swipe_down_fingerprint
+lock_screen_notifications
+screen_zoom
+usage_access
\ No newline at end of file
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/com/android/settings/UtilsTest.java b/tests/robotests/src/com/android/settings/UtilsTest.java
index 8b7605c..8dfd32a 100644
--- a/tests/robotests/src/com/android/settings/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/UtilsTest.java
@@ -19,7 +19,10 @@
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
+import android.text.SpannableString;
+import android.text.SpannableStringBuilder;
import android.text.format.DateUtils;
+import android.text.style.TtsSpan;
import org.junit.Before;
import org.junit.Test;
@@ -35,10 +38,14 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UtilsTest {
+ private static final String TIME_DESCRIPTION = "1 day 20 hours 30 minutes";
private Context mContext;
- @Mock private WifiManager wifiManager;
- @Mock private Network network;
- @Mock private ConnectivityManager connectivityManager;
+ @Mock
+ private WifiManager wifiManager;
+ @Mock
+ private Network network;
+ @Mock
+ private ConnectivityManager connectivityManager;
@Before
public void setUp() {
@@ -47,7 +54,7 @@
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(WifiManager.class)).thenReturn(wifiManager);
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
- .thenReturn(connectivityManager);
+ .thenReturn(connectivityManager);
}
@Test
@@ -89,7 +96,8 @@
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS;
final String expectedTime = "5m 0s";
- assertThat(Utils.formatElapsedTime(mContext, testMillis, true)).isEqualTo(expectedTime);
+ assertThat(Utils.formatElapsedTime(mContext, testMillis, true).toString()).isEqualTo(
+ expectedTime);
}
@Test
@@ -97,7 +105,8 @@
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS;
final String expectedTime = "5m";
- assertThat(Utils.formatElapsedTime(mContext, testMillis, false)).isEqualTo(expectedTime);
+ assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
+ expectedTime);
}
@Test
@@ -106,7 +115,23 @@
+ 4 * DateUtils.HOUR_IN_MILLIS + 15 * DateUtils.MINUTE_IN_MILLIS;
final String expectedTime = "2d 4h 15m";
- assertThat(Utils.formatElapsedTime(mContext, testMillis, false)).isEqualTo(expectedTime);
+ assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
+ expectedTime);
+ }
+
+ @Test
+ public void testFormatElapsedTime_onlyContainsMinute_hasTtsSpan() {
+ final double testMillis = 15 * DateUtils.MINUTE_IN_MILLIS;
+
+ final CharSequence charSequence = Utils.formatElapsedTime(mContext, testMillis, false);
+ assertThat(charSequence).isInstanceOf(SpannableStringBuilder.class);
+
+ final SpannableStringBuilder expectedString = (SpannableStringBuilder) charSequence;
+ final TtsSpan[] ttsSpans = expectedString.getSpans(0, expectedString.length(),
+ TtsSpan.class);
+
+ assertThat(ttsSpans).asList().hasSize(1);
+ assertThat(ttsSpans[0].getType()).isEqualTo(TtsSpan.TYPE_MEASURE);
}
@Test
@@ -119,13 +144,13 @@
}
@Test
- public void getInstallationStatus_notInstalled_shouldReturnUninstalled() {
+ public void testGetInstallationStatus_notInstalled_shouldReturnUninstalled() {
assertThat(Utils.getInstallationStatus(new ApplicationInfo()))
.isEqualTo(R.string.not_installed);
}
@Test
- public void getInstallationStatus_enabled_shouldReturnInstalled() {
+ public void testGetInstallationStatus_enabled_shouldReturnInstalled() {
final ApplicationInfo info = new ApplicationInfo();
info.flags = ApplicationInfo.FLAG_INSTALLED;
info.enabled = true;
@@ -134,7 +159,7 @@
}
@Test
- public void getInstallationStatus_disabled_shouldReturnDisabled() {
+ public void testGetInstallationStatus_disabled_shouldReturnDisabled() {
final ApplicationInfo info = new ApplicationInfo();
info.flags = ApplicationInfo.FLAG_INSTALLED;
info.enabled = false;
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
index 26c640d..c159a24 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
@@ -15,11 +15,16 @@
*/
package com.android.settings.accounts;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+
import android.accounts.Account;
import android.content.Context;
+import android.content.Intent;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -29,9 +34,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
-import static org.mockito.Mockito.mock;
-import static com.google.common.truth.Truth.assertThat;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccountSyncPreferenceControllerTest {
@@ -42,13 +44,18 @@
final Context context = application.getApplicationContext();
final Preference preference = new Preference(context);
preference.setKey("account_sync");
- AccountSyncPreferenceController controller = new AccountSyncPreferenceController(context);
- controller.init(new Account("acct1", "type1"), mock(UserHandle.class));
+ final AccountSyncPreferenceController controller =
+ new AccountSyncPreferenceController(context);
+ controller.init(new Account("acct1", "type1"), mock(UserHandle.class));
controller.handlePreferenceTreeClick(preference);
- assertThat(application.getNextStartedActivity().getStringExtra(
- SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(AccountSyncSettings.class.getName());
+ final Intent nextActivity = application.getNextStartedActivity();
+
+ assertThat(nextActivity.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
+ .isEqualTo(AccountSyncSettings.class.getName());
+ assertThat(nextActivity.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
+ .isEqualTo(R.string.account_sync_title);
}
}
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 030978f..8b9b4b4 100644
--- a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
@@ -33,12 +33,11 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
-import android.graphics.drawable.Drawable;
+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;
@@ -172,25 +171,6 @@
}
@Test
- public void bindButton_noStoreLink_shouldNotShowButton() {
- final View appLinks = mLayoutInflater
- .inflate(R.layout.app_details, null /* root */);
- when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
- .thenReturn(null);
-
- mController = new AppHeaderController(mContext, mFragment, appLinks);
- mController.setButtonActions(
- AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
- AppHeaderController.ActionType.ACTION_NONE);
- mController.done(mActivity);
-
- assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
- .isEqualTo(View.GONE);
- assertThat(appLinks.findViewById(R.id.right_button).getVisibility())
- .isEqualTo(View.GONE);
- }
-
- @Test
public void bindButton_noAppInfo_shouldNotShowButton() {
final View appLinks = mLayoutInflater
.inflate(R.layout.app_details, null /* root */);
@@ -276,17 +256,6 @@
.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(mActivity);
- 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() {
@@ -295,8 +264,6 @@
mController.setIsInstantApp(true);
mController.done(mActivity);
TextView label = appHeader.findViewById(R.id.install_type);
- ImageView badgeView = appHeader.findViewById(R.id.app_icon_instant_apps_badge);
- assertThat(badgeView.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(label.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(label.getText()).isEqualTo(
appHeader.getResources().getString(R.string.install_type_instant));
@@ -323,10 +290,11 @@
mController.styleActionBar(mActivity);
verify(actionBar).setElevation(0);
- verify(actionBar).setBackgroundDrawable(any(Drawable.class));
+ // 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/AppStorageSizesControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
index 127100f..36d78c1 100644
--- a/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
@@ -110,4 +110,22 @@
assertThat(mDataPreference.getSummary()).isEqualTo("100B");
assertThat(mTotalPreference.getSummary()).isEqualTo("101B");
}
+
+ @Test
+ public void fakeDataFlagSetsDataAndCacheToZero() {
+ AppStorageStats result = mock(AppStorageStats.class);
+ when(result.getCodeBytes()).thenReturn(1L);
+ when(result.getCacheBytes()).thenReturn(10L);
+ when(result.getDataBytes()).thenReturn(100L);
+ when(result.getTotalBytes()).thenReturn(111L);
+
+ mController.setResult(result);
+ mController.setDataCleared(true);
+ mController.updateUi(mContext);
+
+ assertThat(mAppPreference.getSummary()).isEqualTo("1.00B");
+ assertThat(mCachePreference.getSummary()).isEqualTo("0.00B");
+ assertThat(mDataPreference.getSummary()).isEqualTo("0.00B");
+ assertThat(mTotalPreference.getSummary()).isEqualTo("1.00B");
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index f372836..6cf4a59 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -18,7 +18,6 @@
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;
@@ -69,6 +68,9 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class InstalledAppDetailsTest {
+
+ private static final String PACKAGE_NAME = "test_package_name";
+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
@@ -87,6 +89,8 @@
private BatteryStatsHelper mBatteryStatsHelper;
@Mock
private BatteryStats.Uid mUid;
+ @Mock
+ private PackageManager mPackageManager;
private InstalledAppDetails mAppDetail;
private Context mShadowContext;
@@ -94,14 +98,15 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mShadowContext = RuntimeEnvironment.application;
+ mShadowContext = RuntimeEnvironment.application;
mAppDetail = spy(new InstalledAppDetails());
mBatterySipper.drainType = BatterySipper.DrainType.IDLE;
mBatterySipper.uidObj = mUid;
doReturn(mActivity).when(mAppDetail).getActivity();
doReturn(mShadowContext).when(mAppDetail).getContext();
+ doReturn(mPackageManager).when(mActivity).getPackageManager();
// Default to not considering any apps to be instant (individual tests can override this).
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
@@ -179,6 +184,24 @@
}
@Test
+ public void packageSizeChange_isOtherPackage_shouldNotRefreshUi() {
+ ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
+ mAppDetail.onPackageSizeChanged("Not_" + PACKAGE_NAME);
+
+ verify(mAppDetail, never()).refreshUi();
+ }
+
+ @Test
+ public void packageSizeChange_isOwnPackage_shouldRefreshUi() {
+ doReturn(Boolean.TRUE).when(mAppDetail).refreshUi();
+ ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
+
+ mAppDetail.onPackageSizeChanged(PACKAGE_NAME);
+
+ verify(mAppDetail).refreshUi();
+ }
+
+ @Test
public void launchPowerUsageDetailFragment_shouldNotCrash() {
mAppDetail.mBatteryPreference = mBatteryPreference;
mAppDetail.mSipper = mBatterySipper;
diff --git a/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java b/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java
new file mode 100644
index 0000000..04d4342
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.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.applications;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.support.v7.preference.Preference.OnPreferenceClickListener;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.view.View;
+
+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.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LayoutPreferenceTest {
+
+ private Context mContext;
+ private LayoutPreference mPreference;
+ private View mRootView;
+ private PreferenceViewHolder mHolder;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mPreference = new LayoutPreference(mContext, R.layout.app_action_buttons);
+ mRootView = mPreference.mRootView;
+ mHolder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext)
+ .inflate(R.layout.layout_preference_frame, null, false));
+ }
+
+ @Test
+ public void setOnClickListener_shouldAttachToRootView() {
+ final OnPreferenceClickListener listener = mock(OnPreferenceClickListener.class);
+
+ mPreference.setOnPreferenceClickListener(listener);
+ mPreference.onBindViewHolder(mHolder);
+
+ mHolder.itemView.callOnClick();
+
+ verify(listener).onPreferenceClick(mPreference);
+ assertThat(mHolder.itemView.isFocusable()).isTrue();
+ assertThat(mHolder.itemView.isClickable()).isTrue();
+ }
+
+ @Test
+ public void setNonSelectable_viewShouldNotBeSelectable() {
+ mPreference.setSelectable(false);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mHolder.itemView.isFocusable()).isFalse();
+ assertThat(mHolder.itemView.isClickable()).isFalse();
+ }
+
+ @Test
+ public void disableSomeView_shouldMaintainStateAfterBind() {
+ mPreference.findViewById(R.id.left_button).setEnabled(false);
+ mPreference.findViewById(R.id.right_button).setEnabled(true);
+
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mPreference.findViewById(R.id.left_button).isEnabled()).isFalse();
+ assertThat(mPreference.findViewById(R.id.right_button).isEnabled()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
deleted file mode 100644
index 44ca9f7..0000000
--- a/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
+++ /dev/null
@@ -1,78 +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.applications;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.support.v7.preference.Preference;
-import com.android.settings.R;
-import com.android.settings.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.datausage.DataSaverBackend;
-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.util.ReflectionHelpers;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class SpecialAppAccessPreferenceControllerTest {
- private Context mContext;
- @Mock
- private DataSaverBackend mBackend;
- @Mock
- private Preference mPreference;
-
- private SpecialAppAccessPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mController = new SpecialAppAccessPreferenceController(mContext);
- ReflectionHelpers.setField(mController, "mDataSaverBackend", mBackend);
- }
-
- @Test
- public void isAvailable_shouldAlwaysReturnTrue() {
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
- public void updateState_shouldSetSummary() {
- when(mBackend.getWhitelistedCount()).thenReturn(0);
-
- mController.updateState(mPreference);
-
- verify(mPreference).setSummary(mContext.getResources().getQuantityString(
- R.plurals.special_access_summary, 0, 0));
-
- when(mBackend.getWhitelistedCount()).thenReturn(1);
-
- mController.updateState(mPreference);
-
- verify(mPreference).setSummary(mContext.getResources().getQuantityString(
- R.plurals.special_access_summary, 1, 1));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
index 7761afc..074bef2 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -15,12 +15,15 @@
*/
package com.android.settings.bluetooth;
+import android.content.ComponentName;
import android.content.Context;
+import android.os.UserManager;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.widget.MasterSwitchController;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
@@ -30,30 +33,108 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import static com.google.common.truth.Truth.assertThat;
+import static junit.framework.TestCase.assertNotNull;
+import static junit.framework.TestCase.assertEquals;
import static org.mockito.Mockito.mock;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BluetoothEnablerTest {
+ private static final EnforcedAdmin FAKE_ENFORCED_ADMIN =
+ new EnforcedAdmin(new ComponentName("test.package", "test.Class"), 10);
+
@Mock
private MetricsFeatureProvider mMetricsFeatureProvider;
@Mock
private Context mContext;
+ @Mock
+ private MasterSwitchController mMasterSwitchController;
+ @Mock
+ private RestrictionUtils mRestrictionUtils;
+
+ private BluetoothEnabler mBluetoothEnabler;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mBluetoothEnabler = new BluetoothEnabler(
+ mContext,
+ mMasterSwitchController,
+ mMetricsFeatureProvider,
+ mock(LocalBluetoothManager.class),
+ 123,
+ mRestrictionUtils);
}
@Test
public void onSwitchToggled_shouldLogActionWithSuppliedEvent() {
- BluetoothEnabler bluetoothEnabler = new BluetoothEnabler(mContext,
- mock(MasterSwitchController.class), mMetricsFeatureProvider,
- mock(LocalBluetoothManager.class), 123);
- bluetoothEnabler.onSwitchToggled(false);
+ // WHEN the switch is toggled...
+ mBluetoothEnabler.onSwitchToggled(false);
+ // THEN the corresponding metrics action is logged.
verify(mMetricsFeatureProvider).action(mContext, 123, false);
}
+
+ @Test
+ public void maybeEnforceRestrictions_noRestrictions() {
+ // GIVEN there are no restrictions set...
+ when(mRestrictionUtils.checkIfRestrictionEnforced(any(Context.class), any(String.class)))
+ .thenReturn(null);
+
+ // WHEN the maybeEnforceRestrictions is called...
+ // THEN false is returned to indicate there was no restriction to enforce
+ assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isFalse();
+
+ // THEN a null EnfoceAdmin is set.
+ verify(mMasterSwitchController).setDisabledByAdmin(null);
+ // THEN the state of the switch isn't changed.
+ verify(mMasterSwitchController, never()).setChecked(anyBoolean());
+ }
+
+ @Test
+ public void maybeEnforceRestrictions_disallowBluetoothRestrictionSet() {
+ // GIVEN Bluetooth has been disallowed...
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(null);
+
+ // WHEN the maybeEnforceRestrictions is called...
+ // THEN true is returned to indicate there was a restriction to enforce.
+ assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isTrue();
+
+ // THEN the expected EnfoceAdmin is set.
+ verify(mMasterSwitchController).setDisabledByAdmin(FAKE_ENFORCED_ADMIN);
+
+ // THEN the switch is unchecked.
+ verify(mMasterSwitchController).setChecked(false);
+ }
+
+ @Test
+ public void maybeEnforceRestrictions_disallowConfigBluetoothRestrictionSet() {
+ // GIVEN configuring Bluetooth has been disallowed...
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(null);
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+
+ // WHEN the maybeEnforceRestrictions is called...
+ // THEN true is returned to indicate there was a restriction to enforce.
+ assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isTrue();
+
+ // THEN the expected EnfoceAdmin is set.
+ verify(mMasterSwitchController).setDisabledByAdmin(FAKE_ENFORCED_ADMIN);
+
+ // THEN the switch is unchecked.
+ verify(mMasterSwitchController).setChecked(false);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
index 0e39c5d..177130e 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
@@ -52,6 +52,8 @@
private PreferenceScreen mScreen;
@Mock
private MasterSwitchPreference mPreference;
+ @Mock
+ private RestrictionUtils mRestrictionUtils;
private Context mContext;
private BluetoothMasterSwitchPreferenceController mController;
@@ -60,7 +62,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application.getApplicationContext();
- mController = new BluetoothMasterSwitchPreferenceController(mContext, mBluetoothManager);
+ mController = new BluetoothMasterSwitchPreferenceController(
+ mContext, mBluetoothManager, mRestrictionUtils);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java
index cc059ad..79daa0e 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java
@@ -16,7 +16,10 @@
package com.android.settings.bluetooth;
+import static com.google.common.truth.Truth.assertThat;
+
import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
import android.content.Context;
import com.android.settings.R;
@@ -35,29 +38,38 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowBluetoothAdapter;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BluetoothSummaryUpdaterTest {
+ private static final String DEVICE_NAME = "Nightshade";
+ private static final String DEVICE_KEYBOARD_NAME = "Bluetooth Keyboard";
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private LocalBluetoothManager mBluetoothManager;
@Mock
private LocalBluetoothAdapter mBtAdapter;
-
- private BluetoothSummaryUpdater mSummaryUpdater;
+ @Mock
+ private BluetoothDevice mConnectedDevice;
+ @Mock
+ private BluetoothDevice mConnectedKeyBoardDevice;
@Mock
private SummaryListener mListener;
+ private BluetoothSummaryUpdater mSummaryUpdater;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -84,10 +96,12 @@
@Test
public void register_true_shouldSendSummaryChange() {
+ prepareConnectedDevice(false);
+
mSummaryUpdater.register(true);
verify(mListener).onSummaryChanged(
- mContext.getString(R.string.bluetooth_connected_summary));
+ mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME));
}
@Test
@@ -100,11 +114,13 @@
@Test
public void onBluetoothStateChanged_btEnabled_connected_shouldSendConnectedSummary() {
+ prepareConnectedDevice(false);
+
mSummaryUpdater.register(true);
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);
verify(mListener).onSummaryChanged(
- mContext.getString(R.string.bluetooth_connected_summary));
+ mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME));
}
@Test
@@ -114,7 +130,7 @@
mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_ON);
verify(mListener).onSummaryChanged(
- mContext.getString(R.string.disconnected));
+ mContext.getString(R.string.disconnected));
}
@Test
@@ -123,26 +139,28 @@
devices.add(mock(CachedBluetoothDevice.class));
when(devices.get(0).isConnected()).thenReturn(true);
when(mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy())
- .thenReturn(devices);
+ .thenReturn(devices);
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTED);
+ prepareConnectedDevice(false);
+
mSummaryUpdater.register(true);
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTED);
mSummaryUpdater.onConnectionStateChanged(null /* device */,
- BluetoothAdapter.STATE_CONNECTED);
+ BluetoothAdapter.STATE_CONNECTED);
verify(mListener).onSummaryChanged(
- mContext.getString(R.string.bluetooth_connected_summary));
+ mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME));
}
@Test
public void onConnectionStateChanged_inconsistentState_shouldSendDisconnectedMessage() {
mSummaryUpdater.register(true);
mSummaryUpdater.onConnectionStateChanged(null /* device */,
- BluetoothAdapter.STATE_CONNECTED);
+ BluetoothAdapter.STATE_CONNECTED);
verify(mListener).onSummaryChanged(
- mContext.getString(R.string.disconnected));
+ mContext.getString(R.string.disconnected));
}
@Test
@@ -150,7 +168,7 @@
mSummaryUpdater.register(true);
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTING);
mSummaryUpdater.onConnectionStateChanged(null /* device */,
- BluetoothAdapter.STATE_CONNECTING);
+ BluetoothAdapter.STATE_CONNECTING);
verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_connecting));
}
@@ -160,11 +178,44 @@
mSummaryUpdater.register(true);
when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTING);
mSummaryUpdater.onConnectionStateChanged(null /* device */,
- BluetoothAdapter.STATE_DISCONNECTING);
+ BluetoothAdapter.STATE_DISCONNECTING);
verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_disconnecting));
}
+ @Test
+ public void getConnectedDeviceSummary_hasConnectedDevice_returnOneDeviceSummary() {
+ prepareConnectedDevice(false);
+ final String expectedSummary = mContext.getString(R.string.bluetooth_connected_summary,
+ DEVICE_NAME);
+
+ assertThat(mSummaryUpdater.getConnectedDeviceSummary()).isEqualTo(expectedSummary);
+ }
+
+ @Test
+ public void getConnectedDeviceSummary_multipleDevices_returnMultipleDevicesSummary() {
+ prepareConnectedDevice(true);
+ final String expectedSummary = mContext.getString(
+ R.string.bluetooth_connected_multiple_devices_summary);
+
+ assertThat(mSummaryUpdater.getConnectedDeviceSummary()).isEqualTo(expectedSummary);
+ }
+
+ private void prepareConnectedDevice(boolean multipleDevices) {
+ final Set<BluetoothDevice> devices = new HashSet<>();
+ doReturn(DEVICE_NAME).when(mConnectedDevice).getName();
+ doReturn(true).when(mConnectedDevice).isConnected();
+ devices.add(mConnectedDevice);
+ if (multipleDevices) {
+ // Add one more device if we need to test multiple devices
+ doReturn(DEVICE_KEYBOARD_NAME).when(mConnectedKeyBoardDevice).getName();
+ doReturn(true).when(mConnectedKeyBoardDevice).isConnected();
+ devices.add(mConnectedKeyBoardDevice);
+ }
+
+ doReturn(devices).when(mBtAdapter).getBondedDevices();
+ }
+
private class SummaryListener implements OnSummaryChangeListener {
String summary;
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
index fc4b75f..a4b5c97 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
@@ -15,8 +15,12 @@
*/
package com.android.settings.connecteddevice;
+import android.content.Context;
+import android.content.pm.PackageManager;
import android.provider.SearchIndexableResource;
+import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
+import com.android.settings.nfc.NfcPreferenceController;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settingslib.drawer.CategoryKey;
@@ -24,22 +28,33 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ConnectedDeviceDashboardFragmentTest {
+ @Mock
+ Context mContext;
+
+ @Mock
+ private PackageManager mManager;
private ConnectedDeviceDashboardFragment mFragment;
@Before
public void setUp() {
+ MockitoAnnotations.initMocks(this);
mFragment = new ConnectedDeviceDashboardFragment();
+ when(mContext.getPackageManager()).thenReturn(mManager);
}
@Test
@@ -50,11 +65,47 @@
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
- ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
- ShadowApplication.getInstance().getApplicationContext(),
- true /* enabled */);
+ mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext, true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
}
+
+ @Test
+ public void testSearchIndexProvider_NoNfc_KeyAdded() {
+ when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
+ final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+
+ assertThat(keys).isNotNull();
+ assertThat(keys).contains(NfcPreferenceController.KEY_TOGGLE_NFC);
+ assertThat(keys).contains(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+ }
+
+ @Test
+ public void testSearchIndexProvider_NFC_KeyNotAdded() {
+ when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
+ final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+
+ assertThat(keys).isNotNull();
+ assertThat(keys).doesNotContain(NfcPreferenceController.KEY_TOGGLE_NFC);
+ assertThat(keys).doesNotContain(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
+ }
+
+ @Test
+ public void testSearchIndexProvider_NoBluetooth_KeyAdded() {
+ when(mManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)).thenReturn(false);
+ final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+
+ assertThat(keys).isNotNull();
+ assertThat(keys).contains(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
+ }
+
+ @Test
+ public void testSearchIndexProvider_Bluetooth_KeyNotAdded() {
+ when(mManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)).thenReturn(true);
+ final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+
+ assertThat(keys).isNotNull();
+ assertThat(keys).doesNotContain(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
+ }
}
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..accca2a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionsChecksTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.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.WallpaperManager;
+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;
+import org.robolectric.util.ReflectionHelpers;
+
+
+@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;
+ @Mock
+ private WallpaperManagerWrapper mWallpaperManager;
+ 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;
+ }
+
+ @Test
+ public void hasWallpaperSet_no_shouldReturnFalse() {
+ ReflectionHelpers.setField(mSuggestionsChecks, "mWallpaperManager", mWallpaperManager);
+ when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM))
+ .thenReturn(0);
+
+ assertThat(mSuggestionsChecks.hasWallpaperSet())
+ .isFalse();
+ }
+
+ @Test
+ public void hasWallpaperSet_yes_shouldReturnTrue() {
+ ReflectionHelpers.setField(mSuggestionsChecks, "mWallpaperManager", mWallpaperManager);
+ when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM))
+ .thenReturn(100);
+
+ assertThat(mSuggestionsChecks.hasWallpaperSet())
+ .isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
index b4f5f3d..be04eec 100644
--- a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
@@ -16,6 +16,8 @@
package com.android.settings.deletionhelper;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -27,6 +29,7 @@
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
+import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
@@ -121,4 +124,41 @@
verify(mFragmentManager.beginTransaction(), never())
.add(any(Fragment.class), eq(ActivationWarningFragment.TAG));
}
+
+ @Test
+ public void initializeSwitchOnConstruction() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
+ 1);
+
+ mController =
+ new AutomaticStorageManagerSwitchBarController(
+ mContext,
+ mSwitchBar,
+ mMetricsFeatureProvider,
+ mPreference,
+ mFragmentManager);
+
+ assertThat(mSwitchBar.isChecked()).isTrue();
+ }
+
+ @Test
+ public void initializingSwitchDoesNotTriggerView() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
+ 1);
+
+ mController =
+ new AutomaticStorageManagerSwitchBarController(
+ mContext,
+ mSwitchBar,
+ mMetricsFeatureProvider,
+ mPreference,
+ mFragmentManager);
+
+ verify(mFragmentManager.beginTransaction(), never())
+ .add(any(Fragment.class), eq(ActivationWarningFragment.TAG));
+ }
}
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..47d910d 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -114,6 +114,7 @@
Intent intent = argumentCaptor.getValue();
assertThat(intent.getType()).isEqualTo("image/*");
assertThat(intent.getAction()).isEqualTo(android.content.Intent.ACTION_VIEW);
+ assertThat(intent.getBooleanExtra(Intent.EXTRA_FROM_STORAGE, false)).isTrue();
}
@Test
@@ -242,21 +243,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 +263,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/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 801034c..4305dc7 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -57,6 +57,8 @@
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.robolectric.RuntimeEnvironment;
+
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@@ -73,6 +75,8 @@
private static final long FOREGROUND_TIME_US = 200 * 1000;
private static final long BACKGROUND_TIME_MS = 100;
private static final long FOREGROUND_TIME_MS = 200;
+ private static final long PHONE_FOREGROUND_TIME_MS = 250 * 1000;
+ private static final long PHONE_BACKGROUND_TIME_MS = 0;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@@ -137,9 +141,11 @@
ReflectionHelpers.setField(mBatteryEntry, "sipper", mBatterySipper);
mBatteryEntry.iconId = ICON_ID;
mBatterySipper.uidObj = mUid;
+ mBatterySipper.drainType = BatterySipper.DrainType.APP;
mFragment.mHeaderPreference = mHeaderPreference;
mFragment.mState = mState;
+ mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
mAppEntry.info = mock(ApplicationInfo.class);
mTestActivity = spy(new SettingsActivity());
@@ -191,6 +197,23 @@
}
@Test
+ public void testStartBatteryDetailPage_typeNotApp_hasBasicData() {
+ mBatterySipper.drainType = BatterySipper.DrainType.PHONE;
+ mBatterySipper.usageTimeMs = PHONE_FOREGROUND_TIME_MS;
+
+ AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
+ mBatteryEntry, USAGE_PERCENT);
+
+ assertThat(mBundle.getInt(AdvancedPowerUsageDetail.EXTRA_UID)).isEqualTo(UID);
+ assertThat(mBundle.getLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME)).isEqualTo(
+ PHONE_FOREGROUND_TIME_MS);
+ assertThat(mBundle.getLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME)).isEqualTo(
+ PHONE_BACKGROUND_TIME_MS);
+ assertThat(mBundle.getString(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_PERCENT)).isEqualTo(
+ USAGE_PERCENT);
+ }
+
+ @Test
public void testStartBatteryDetailPage_NormalApp() {
mBatterySipper.mPackages = PACKAGE_NAME;
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, mBatteryStatsHelper, 0,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java
new file mode 100644
index 0000000..d19a4b2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryStatsHelperLoaderTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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 static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.os.BatteryStats;
+import android.os.Bundle;
+import android.os.UserManager;
+
+import com.android.internal.os.BatteryStatsHelper;
+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 BatteryStatsHelperLoaderTest {
+ @Mock
+ private BatteryStatsHelper mBatteryStatsHelper;
+ @Mock
+ private Bundle mBundle;
+ @Mock
+ private Context mContext;
+ @Mock
+ private UserManager mUserManager;
+ private BatteryStatsHelperLoader mLoader;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mLoader = new BatteryStatsHelperLoader(mContext, mBundle);
+ mLoader.mUserManager = mUserManager;
+ }
+
+ @Test
+ public void testInitBatteryStatsHelper_init() {
+ mLoader.initBatteryStatsHelper(mBatteryStatsHelper);
+
+ verify(mBatteryStatsHelper).create(mBundle);
+ verify(mBatteryStatsHelper).refreshStats(BatteryStats.STATS_SINCE_CHARGED,
+ mUserManager.getUserProfiles());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index e5383c8..f9cc771 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -33,6 +33,9 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import java.util.ArrayList;
+import java.util.List;
+
import static android.os.BatteryStats.Uid.PROCESS_STATE_BACKGROUND;
import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND;
import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE;
@@ -47,9 +50,7 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.List;
+import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -63,12 +64,13 @@
private static final long TIME_STATE_BACKGROUND = 6000 * UNIT;
private static final int UID = 123;
- private static final long TIME_EXPECTED_FOREGROUND = 9000;
+ private static final long TIME_EXPECTED_FOREGROUND = 6500;
private static final long TIME_EXPECTED_BACKGROUND = 6000;
- private static final long TIME_EXPECTED_ALL = 15000;
+ private static final long TIME_EXPECTED_ALL = 12500;
private static final double BATTERY_SCREEN_USAGE = 300;
private static final double BATTERY_SYSTEM_USAGE = 600;
private static final double BATTERY_OVERACCOUNTED_USAGE = 500;
+ private static final double BATTERY_UNACCOUNTED_USAGE = 700;
private static final double TOTAL_BATTERY_USAGE = 1000;
private static final double HIDDEN_USAGE = 200;
private static final int DISCHARGE_AMOUNT = 80;
@@ -84,6 +86,8 @@
@Mock
private BatterySipper mOvercountedBatterySipper;
@Mock
+ private BatterySipper mUnaccountedBatterySipper;
+ @Mock
private BatterySipper mSystemBatterySipper;
@Mock
private BatterySipper mCellBatterySipper;
@@ -125,8 +129,13 @@
mOvercountedBatterySipper.drainType = BatterySipper.DrainType.OVERCOUNTED;
mOvercountedBatterySipper.totalPowerMah = BATTERY_OVERACCOUNTED_USAGE;
+ mUnaccountedBatterySipper.drainType = BatterySipper.DrainType.UNACCOUNTED;
+ mUnaccountedBatterySipper.totalPowerMah = BATTERY_UNACCOUNTED_USAGE;
+
mBatteryUtils = BatteryUtils.getInstance(RuntimeEnvironment.application);
mBatteryUtils.mPowerUsageFeatureProvider = mProvider;
+
+ mBatteryUtils = spy(new BatteryUtils(RuntimeEnvironment.application));
}
@Test
@@ -168,12 +177,14 @@
sippers.add(mScreenBatterySipper);
sippers.add(mSystemBatterySipper);
sippers.add(mOvercountedBatterySipper);
+ sippers.add(mUnaccountedBatterySipper);
when(mProvider.isTypeSystem(mSystemBatterySipper))
.thenReturn(true);
final double totalUsage = mBatteryUtils.removeHiddenBatterySippers(sippers);
assertThat(sippers).containsExactly(mNormalBatterySipper);
- assertThat(totalUsage).isWithin(PRECISION).of(BATTERY_SCREEN_USAGE + BATTERY_SYSTEM_USAGE);
+ assertThat(totalUsage).isWithin(PRECISION).of(
+ BATTERY_SCREEN_USAGE + BATTERY_SYSTEM_USAGE + BATTERY_UNACCOUNTED_USAGE);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 66d2c1a..d46baa1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserManager;
+import android.text.TextUtils;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatterySipper.DrainType;
@@ -105,9 +106,12 @@
when(mPowerUsageAdvanced.getContext()).thenReturn(mShadowContext);
doReturn(STUB_STRING).when(mPowerUsageAdvanced).getString(anyInt(), any(), any());
doReturn(STUB_STRING).when(mPowerUsageAdvanced).getString(anyInt(), any());
+ doReturn(mShadowContext.getText(R.string.battery_used_for)).when(
+ mPowerUsageAdvanced).getText(R.string.battery_used_for);
mPowerUsageAdvanced.setPackageManager(mPackageManager);
mPowerUsageAdvanced.setPowerUsageFeatureProvider(mPowerUsageFeatureProvider);
mPowerUsageAdvanced.setUserManager(mUserManager);
+ mPowerUsageAdvanced.setBatteryUtils(BatteryUtils.getInstance(mShadowContext));
mPowerUsageData = new PowerUsageData(UsageType.APP);
mMaxBatterySipper.totalPowerMah = TYPE_BLUETOOTH_USAGE;
@@ -140,13 +144,13 @@
}
@Test
- public void testExtractUsageType_TypeService_ReturnService() {
+ public void testExtractUsageType_TypeService_ReturnSystem() {
mNormalBatterySipper.drainType = DrainType.APP;
when(mNormalBatterySipper.getUid()).thenReturn(FAKE_UID_1);
when(mPowerUsageFeatureProvider.isTypeService(any())).thenReturn(true);
assertThat(mPowerUsageAdvanced.extractUsageType(mNormalBatterySipper))
- .isEqualTo(UsageType.SERVICE);
+ .isEqualTo(UsageType.SYSTEM);
}
@Test
@@ -176,10 +180,12 @@
@Test
public void testUpdateUsageDataSummary_onlyOneApp_showUsageTime() {
+ final String expectedSummary = "Used for 0m";
mPowerUsageData.usageList.add(mNormalBatterySipper);
+
mPowerUsageAdvanced.updateUsageDataSummary(mPowerUsageData, TOTAL_POWER, DISCHARGE_AMOUNT);
- verify(mPowerUsageAdvanced).getString(eq(R.string.battery_used_for), any());
+ assertThat(mPowerUsageData.summary.toString()).isEqualTo(expectedSummary);
}
@Test
@@ -210,8 +216,8 @@
final int[] usageTypeSet = mPowerUsageAdvanced.mUsageTypes;
assertThat(usageTypeSet).asList().containsExactly(UsageType.APP, UsageType.WIFI,
- UsageType.CELL, UsageType.BLUETOOTH, UsageType.IDLE, UsageType.SERVICE,
- UsageType.USER, UsageType.SYSTEM, UsageType.UNACCOUNTED, UsageType.OVERCOUNTED);
+ UsageType.CELL, UsageType.BLUETOOTH, UsageType.IDLE, UsageType.USER,
+ UsageType.SYSTEM, UsageType.UNACCOUNTED, UsageType.OVERCOUNTED);
}
@Test
@@ -293,4 +299,16 @@
assertThat(mPowerUsageAdvanced.shouldShowBatterySipper(mNormalBatterySipper)).isTrue();
}
+ @Test
+ public void testCalculateHiddenPower_returnCorrectPower() {
+ List<PowerUsageData> powerUsageDataList = new ArrayList<>();
+ final double unaccountedPower = 100;
+ final double normalPower = 150;
+ powerUsageDataList.add(new PowerUsageData(UsageType.UNACCOUNTED, unaccountedPower));
+ powerUsageDataList.add(new PowerUsageData(UsageType.APP, normalPower));
+ powerUsageDataList.add(new PowerUsageData(UsageType.CELL, normalPower));
+
+ assertThat(mPowerUsageAdvanced.calculateHiddenPower(powerUsageDataList)).isWithin(
+ PRECISION).of(unaccountedPower);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 39c386b..3556d09 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -36,9 +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;
@@ -86,15 +88,16 @@
public class PowerUsageSummaryTest {
private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"};
private static final String TIME_LEFT = "2h30min";
+ private static final String STUB_STRING = "stub_string";
private static final int BATTERY_LEVEL = 55;
private static final int UID = 123;
private static final int POWER_MAH = 100;
private static final long REMAINING_TIME_US = 100000;
- private static final long TIME_SINCE_LAST_FULL_CHARGE_MS = 25000;
+ private static final long TIME_SINCE_LAST_FULL_CHARGE_MS = 120 * 60 * 1000;
private static final long TIME_SINCE_LAST_FULL_CHARGE_US =
TIME_SINCE_LAST_FULL_CHARGE_MS * 1000;
private static final int DISCHARGE_AMOUNT = 100;
- private static final long USAGE_TIME_MS = 10000;
+ private static final long USAGE_TIME_MS = 65 * 60 * 1000;
private static final double TOTAL_POWER = 200;
private static final double BATTERY_SCREEN_USAGE = 300;
private static final double BATTERY_SYSTEM_USAGE = 600;
@@ -123,8 +126,6 @@
@Mock
private BatterySipper mCellBatterySipper;
@Mock
- private PowerGaugePreference mPreference;
- @Mock
private LayoutPreference mBatteryLayoutPref;
@Mock
private TextView mBatteryPercentText;
@@ -132,10 +133,6 @@
private TextView mSummary1;
@Mock
private BatteryInfo mBatteryInfo;
- @Mock
- private PowerGaugePreference mScreenUsagePref;
- @Mock
- private PowerGaugePreference mLastFullChargePref;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private BatteryStatsHelper mBatteryHelper;
@Mock
@@ -148,6 +145,9 @@
private TestFragment mFragment;
private FakeFeatureFactory mFeatureFactory;
private BatteryMeterView mBatteryMeterView;
+ private PowerGaugePreference mPreference;
+ private PowerGaugePreference mScreenUsagePref;
+ private PowerGaugePreference mLastFullChargePref;
@Before
public void setUp() {
@@ -158,6 +158,9 @@
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
when(mContext.getSystemService(Context.POWER_SERVICE)).thenReturn(mPowerManager);
+ mPreference = new PowerGaugePreference(mRealContext);
+ mScreenUsagePref = new PowerGaugePreference(mRealContext);
+ mLastFullChargePref = new PowerGaugePreference(mRealContext);
mFragment = spy(new TestFragment(mContext));
mFragment.initFeatureProvider();
mBatteryMeterView = new BatteryMeterView(mRealContext);
@@ -200,6 +203,7 @@
when(mBatteryHelper.getUsageList()).thenReturn(mUsageList);
mFragment.mScreenUsagePref = mScreenUsagePref;
mFragment.mLastFullChargePref = mLastFullChargePref;
+ mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext));
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
}
@@ -304,16 +308,21 @@
public void testSetUsageSummary_timeLessThanOneMinute_DoNotSetSummary() {
final long usageTimeMs = 59 * DateUtils.SECOND_IN_MILLIS;
- mFragment.setUsageSummary(mPreference, "", usageTimeMs);
- verify(mPreference, never()).setSummary(anyString());
+ mFragment.setUsageSummary(mPreference, usageTimeMs);
+ assertThat(mPreference.getSummary()).isNull();
}
@Test
public void testSetUsageSummary_timeMoreThanOneMinute_setSummary() {
final long usageTimeMs = 2 * DateUtils.MINUTE_IN_MILLIS;
+ doReturn(mRealContext.getText(R.string.battery_used_for)).when(mFragment).getText(
+ R.string.battery_used_for);
+ doReturn(mRealContext).when(mFragment).getContext();
+ final String expectedSummary = "Used for 2m";
- mFragment.setUsageSummary(mPreference, "", usageTimeMs);
- verify(mPreference).setSummary(anyString());
+ mFragment.setUsageSummary(mPreference, usageTimeMs);
+
+ assertThat(mPreference.getSummary().toString()).isEqualTo(expectedSummary);
}
@Test
@@ -380,32 +389,37 @@
@Test
public void testUpdateScreenPreference_showCorrectSummary() {
- final String expectedUsedTime = Utils.formatElapsedTime(mRealContext, USAGE_TIME_MS, false);
doReturn(mScreenBatterySipper).when(mFragment).findBatterySipperByType(any(), any());
doReturn(mRealContext).when(mFragment).getContext();
+ final CharSequence expectedSummary = Utils.formatElapsedTime(mRealContext, USAGE_TIME_MS,
+ false);
mFragment.updateScreenPreference();
- verify(mScreenUsagePref).setSubtitle(expectedUsedTime);
+ assertThat(mScreenUsagePref.getSubtitle()).isEqualTo(expectedSummary);
}
@Test
public void testUpdateLastFullChargePreference_showCorrectSummary() {
+ final CharSequence formattedString = mRealContext.getText(
+ R.string.power_last_full_charge_summary);
+ final CharSequence timeSequence = Utils.formatElapsedTime(mRealContext,
+ TIME_SINCE_LAST_FULL_CHARGE_MS, false);
+ final CharSequence expectedSummary = TextUtils.expandTemplate(
+ formattedString, timeSequence);
+ doReturn(formattedString).when(mFragment).getText(R.string.power_last_full_charge_summary);
doReturn(mRealContext).when(mFragment).getContext();
- final String expected = mRealContext.getString(R.string.power_last_full_charge_summary,
- Utils.formatElapsedTime(mRealContext, TIME_SINCE_LAST_FULL_CHARGE_MS, false));
- doReturn(expected).when(mFragment).getString(eq(R.string.power_last_full_charge_summary),
- any());
mFragment.updateLastFullChargePreference(TIME_SINCE_LAST_FULL_CHARGE_MS);
- verify(mLastFullChargePref).setSubtitle(expected);
+ assertThat(mLastFullChargePref.getSubtitle()).isEqualTo(expectedSummary);
}
@Test
public void testUpdatePreference_usageListEmpty_shouldNotCrash() {
when(mBatteryHelper.getUsageList()).thenReturn(new ArrayList<BatterySipper>());
- doReturn("").when(mFragment).getString(anyInt(), any());
+ doReturn(STUB_STRING).when(mFragment).getString(anyInt(), any());
+ doReturn(mRealContext).when(mFragment).getContext();
// Should not crash when update
mFragment.updateScreenPreference();
@@ -423,6 +437,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;
@@ -445,7 +486,7 @@
}
@Override
- protected void refreshStats() {
+ protected void refreshUi() {
// Leave it empty for toggle apps menu test
}
}
diff --git a/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
index 3256950..1332445 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
@@ -18,6 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -26,6 +28,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.support.v4.text.BidiFormatter;
import android.support.v7.preference.Preference;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -39,6 +42,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@@ -96,4 +100,35 @@
verify(mPreference).setSummary("label");
}
+
+ @Test
+ public void updateState_multiImeWithMixedLocale_setImeLabelToSummary() {
+ final BidiFormatter formatter = BidiFormatter.getInstance();
+ final ComponentName componentName = new ComponentName("pkg", "cls");
+ final List<InputMethodInfo> imis = new ArrayList<>();
+ final String label1 = "label";
+ final String label2 = "Keyboard מִקְלֶדֶת";
+ imis.add(mock(InputMethodInfo.class));
+ imis.add(mock(InputMethodInfo.class));
+
+ when(mDpm.getPermittedInputMethodsForCurrentUser()).thenReturn(null);
+ when(mImm.getEnabledInputMethodList()).thenReturn(imis);
+ when(imis.get(0).getPackageName()).thenReturn(componentName.getPackageName());
+ when(imis.get(0).loadLabel(mPm)).thenReturn(label1);
+ when(imis.get(1).getPackageName()).thenReturn(componentName.getPackageName());
+ when(imis.get(1).loadLabel(mPm)).thenReturn(label2);
+ when(mContext.getString(eq(R.string.join_many_items_middle), anyString(), anyString()))
+ .thenAnswer(invocation -> {
+ final Object[] args = invocation.getArguments();
+ final String str1 = (String) args[1];
+ final String str2 = (String) args[2];
+ return RuntimeEnvironment.application.getString(R.string.join_many_items_middle,
+ str1, str2);
+ });
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(
+ formatter.unicodeWrap(label1) + ", " + formatter.unicodeWrap(label2));
+ }
}
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/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/SearchResultsAdapterTest.java b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
index 647d68c..645dfe5 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
@@ -63,6 +63,8 @@
private Context mContext;
private String mLoaderClassName;
+ private String[] TITLES = {"alpha", "bravo", "charlie", "appAlpha", "appBravo", "appCharlie"};
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -72,13 +74,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();
@@ -88,7 +90,7 @@
}
@Test
- public void testCreateViewHolder_ReturnsIntentResult() {
+ public void testCreateViewHolder_returnsIntentResult() {
ViewGroup group = new FrameLayout(mContext);
SearchViewHolder view = mAdapter.onCreateViewHolder(group,
ResultPayload.PayloadType.INTENT);
@@ -96,7 +98,7 @@
}
@Test
- public void testCreateViewHolder_ReturnsInlineSwitchResult() {
+ public void testCreateViewHolder_returnsInlineSwitchResult() {
ViewGroup group = new FrameLayout(mContext);
SearchViewHolder view = mAdapter.onCreateViewHolder(group,
ResultPayload.PayloadType.INLINE_SWITCH);
@@ -104,21 +106,54 @@
}
@Test
- public void testEndToEndSearch_ProperResultsMerged() {
- mAdapter.addSearchResults(getDummyAppResults(),
+ public void testEndToEndSearch_properResultsMerged_correctOrder() {
+ mAdapter.addSearchResults(getDummyAppResults(), InstalledAppResultLoader.class.getName());
+ mAdapter.addSearchResults(getDummyDbResults(), DatabaseResultLoader.class.getName());
+ mAdapter.displaySearchResults();
+
+ List<SearchResult> results = mAdapter.getSearchResults();
+ List<SearchResult> sortedDummyResults = getSortedDummyResults();
+
+ assertThat(results).containsExactlyElementsIn(sortedDummyResults).inOrder();
+ }
+
+ @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(getDummyDbResults(),
- DatabaseResultLoader.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());
+ mAdapter.displaySearchResults();
+
+ List<SearchResult> results = mAdapter.getSearchResults();
+ List<SearchResult> sortedDummyResults = getSortedDummyResults();
+ assertThat(results).containsExactlyElementsIn(sortedDummyResults).inOrder();
+ }
+
+ @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("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(count).isEqualTo(6);
+ assertThat(results.get(0).title).isEqualTo(TITLES[0]);
+ assertThat(results.get(1).title).isEqualTo(TITLES[3]);
+ assertThat(count).isEqualTo(2);
}
private List<SearchResult> getDummyDbResults() {
@@ -127,15 +162,15 @@
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());
@@ -148,21 +183,35 @@
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());
return results;
}
+ private List<SearchResult> getSortedDummyResults() {
+ List<AppSearchResult> appResults = getDummyAppResults();
+ List<SearchResult> dbResults = getDummyDbResults();
+ List<SearchResult> sortedResults = new ArrayList<>(appResults.size() + dbResults.size());
+ sortedResults.add(dbResults.get(0)); // alpha
+ sortedResults.add(appResults.get(0)); // appAlpha
+ sortedResults.add(appResults.get(1)); // appBravo
+ sortedResults.add(dbResults.get(1)); // bravo
+ sortedResults.add(appResults.get(2)); // appCharlie
+ sortedResults.add(dbResults.get(2)); // Charlie
+
+ return sortedResults;
+ }
+
private ArrayList<SearchResult> getIntentSampleResults() {
ArrayList<SearchResult> sampleResults = new ArrayList<>();
ArrayList<String> breadcrumbs = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java b/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java
index aa4e4f9..047d867 100644
--- a/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java
+++ b/tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java
@@ -303,7 +303,7 @@
// Class Name
assertThat(cursor.getString(11)).isEqualTo(className);
// Icon
- assertThat(cursor.getInt(12)).isEqualTo(iconResId);
+ assertThat(cursor.getInt(12)).isEqualTo(0);
// Intent Action
assertThat(cursor.getString(13)).isEqualTo(action);
// Target Package
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/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/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/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index efe0c1c..8d28dee 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -54,11 +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 java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -73,6 +75,7 @@
private static final String SECURITY = "None";
private InetAddress mIpv4Address;
+ private Inet6Address mIpv6Address;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mockScreen;
@@ -113,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);
}
@@ -153,6 +162,8 @@
}
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))
@@ -420,4 +431,30 @@
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/deviceinfo/PrivateVolumeForgetTest.java b/tests/unit/src/com/android/settings/deviceinfo/PrivateVolumeForgetTest.java
new file mode 100644
index 0000000..be36e43
--- /dev/null
+++ b/tests/unit/src/com/android/settings/deviceinfo/PrivateVolumeForgetTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.deviceinfo;
+
+import android.content.Intent;
+import android.content.Context;
+
+import android.os.storage.VolumeRecord;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.settings.Settings;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class PrivateVolumeForgetTest {
+ @Rule
+ public ActivityTestRule<Settings.PrivateVolumeForgetActivity> mActivityRule =
+ new ActivityTestRule<>(Settings.PrivateVolumeForgetActivity.class, true, true);
+
+ @Test
+ public void test_invalidSetupDoesNotCrashSettings() {
+ Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ Intent intent = new Intent(targetContext, Settings.PrivateVolumeForgetActivity.class);
+ intent.putExtra(VolumeRecord.EXTRA_FS_UUID, "totally-fake-uuid-doesnt-even-fit-format");
+ mActivityRule.launchActivity(intent);
+
+ // Should exit gracefully without crashing.
+ }
+}
\ No newline at end of file