Merge "Revert "Accessibility settings refresh.""
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5ef5caf..23dc206 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -122,38 +122,6 @@
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
</activity-alias>
- <activity android:name=".Settings$WirelessSettings"
- android:label="@string/header_category_wireless_networks">
- <intent-filter android:priority="4">
- <action android:name="com.android.settings.category.wireless" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
-
- <activity android:name=".Settings$DeviceSettings"
- android:label="@string/header_category_device">
- <intent-filter android:priority="3">
- <action android:name="com.android.settings.category.device" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
-
- <activity android:name=".Settings$PersonalSettings"
- android:label="@string/header_category_personal">
- <intent-filter android:priority="2">
- <action android:name="com.android.settings.category.personal" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
-
- <activity android:name=".SystemSettings"
- android:label="@string/header_category_system">
- <intent-filter android:priority="1">
- <action android:name="com.android.settings.category.system" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
-
<receiver android:name=".SettingsInitialize">
<intent-filter>
<action android:name="android.intent.action.USER_INITIALIZE"/>
@@ -179,7 +147,7 @@
<activity android:name=".Settings$NetworkDashboardActivity"
android:taskAffinity="com.android.settings"
android:label="@string/network_dashboard_title"
- android:icon="@drawable/ic_dashboard_network"
+ android:icon="@drawable/ic_settings_wireless"
android:parentActivityName="Settings">
<intent-filter android:priority="1">
<action android:name="android.settings.WIRELESS_SETTINGS" />
@@ -265,11 +233,6 @@
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
- <intent-filter android:priority="4">
- <action android:name="com.android.settings.action.SETTINGS" />
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.wireless" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.wifi.WifiSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -440,11 +403,6 @@
<category android:name="com.android.settings.SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter android:priority="3">
- <action android:name="com.android.settings.action.SETTINGS" />
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.wireless" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.bluetooth.BluetoothSettings" />
</activity>
@@ -916,7 +874,7 @@
<activity android:name="Settings$DisplaySettingsActivity"
android:label="@string/display_settings"
- android:icon="@drawable/ic_dashboard_display"
+ android:icon="@drawable/ic_settings_display"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="com.android.settings.DISPLAY_SETTINGS" />
@@ -1020,11 +978,11 @@
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
- <intent-filter android:priority="6">
+ <intent-filter android:priority="200">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
+ android:value="com.android.settings.category.ia.apps" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.ManageApplications" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1039,8 +997,6 @@
<action android:name="android.settings.MANAGE_DOMAIN_URLS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.ManageDomainUrls" />
</activity>
@@ -1069,8 +1025,6 @@
<action android:name="android.settings.APP_MEMORY_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.ProcessStatsUi" />
</activity>
@@ -1285,11 +1239,6 @@
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
- <intent-filter android:priority="3">
- <action android:name="com.android.settings.action.SETTINGS" />
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.personal" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.location.LocationSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1298,7 +1247,7 @@
<activity android:name="Settings$SecuritySettingsActivity"
android:label="@string/security_settings_title"
- android:icon="@drawable/ic_dashboard_security"
+ android:icon="@drawable/ic_settings_security"
android:configChanges="orientation|keyboardHidden|screenSize"
android:taskAffinity=""
android:parentActivityName="Settings">
@@ -1500,8 +1449,6 @@
<action android:name="android.settings.ACCESSIBILITY_SETTINGS_FOR_SUW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.system" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.accessibility.AccessibilitySettingsForSetupWizard" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1559,19 +1506,13 @@
</activity>
<activity android:name="Settings$EnterprisePrivacySettingsActivity"
- android:label="@string/enterprise_privacy_settings_title"
- android:icon="@drawable/ic_settings_about"
- android:taskAffinity="com.android.settings"
- android:parentActivityName="Settings">
+ android:label="@string/enterprise_privacy_settings_title"
+ android:taskAffinity="com.android.settings"
+ android:parentActivityName="Settings$SecuritySettingsActivity">
<intent-filter>
<action android:name="android.settings.ENTERPRISE_PRIVACY_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter android:priority="-1">
- <action android:name="com.android.settings.action.SETTINGS" />
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.system" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.enterprise.EnterprisePrivacySettings" />
</activity>
@@ -1814,8 +1755,8 @@
android:value="com.android.settings.deviceinfo.ImeiInformation" />
</activity>
- <activity android:name="Settings$StorageSettingsActivity"
- android:label="@string/storage_settings_title"
+ <activity android:name=".Settings$StorageDashboardActivity"
+ android:label="@string/storage_settings"
android:icon="@drawable/ic_settings_storage"
android:taskAffinity="com.android.settings"
android:parentActivityName="Settings">
@@ -1833,7 +1774,7 @@
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
+ android:value="com.android.settings.category.ia.homepage" />
<meta-data android:name="com.android.settings.title"
android:resource="@string/storage_usb_settings" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
@@ -1845,7 +1786,7 @@
<activity android:name="Settings$PrivateVolumeSettingsActivity"
android:label="@string/storage_settings_title"
android:taskAffinity="com.android.settings"
- android:parentActivityName="Settings$StorageSettingsActivity">
+ android:parentActivityName="Settings$StorageDashboardActivity">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.deviceinfo.PrivateVolumeSettings" />
</activity>
@@ -1853,7 +1794,7 @@
<activity android:name="Settings$PublicVolumeSettingsActivity"
android:label="@string/storage_settings_title"
android:taskAffinity="com.android.settings"
- android:parentActivityName="Settings$StorageSettingsActivity">
+ android:parentActivityName="Settings$StorageDashboardActivity">
<intent-filter>
<action android:name="android.provider.action.DOCUMENT_ROOT_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
@@ -1869,7 +1810,7 @@
<activity android:name="Settings$PrivateVolumeForgetActivity"
android:label="@string/storage_settings_title"
android:taskAffinity="com.android.settings"
- android:parentActivityName="Settings$StorageSettingsActivity"
+ android:parentActivityName="Settings$StorageDashboardActivity"
android:exported="true"
android:permission="android.permission.MOUNT_UNMOUNT_FILESYSTEMS">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
@@ -2443,11 +2384,11 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter android:priority="2">
+ <intent-filter android:priority="8">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
+ android:value="com.android.settings.category.ia.accounts" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.users.UserSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -2466,11 +2407,11 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter android:priority="1">
+ <intent-filter android:priority="10">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
+ android:value="com.android.settings.category.ia.apps.default" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.nfc.PaymentSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -2631,14 +2572,14 @@
<!-- Show apps for which application-level notification settings are applicable -->
<activity android:name="Settings$NotificationAppListActivity"
android:label="@string/app_notifications_title"
- android:icon="@drawable/ic_settings_notifications"
+ android:icon="@drawable/ic_notifications"
android:exported="true"
android:taskAffinity="">
- <intent-filter android:priority="8">
+ <intent-filter android:priority="150">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.device" />
+ android:value="com.android.settings.category.ia.apps" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.NotificationApps" />
</activity>
@@ -2885,6 +2826,19 @@
android:value="com.android.settings.applications.ManageApplications" />
</activity>
+
+ <activity android:name="Settings$AppWriteSettingsActivity"
+ android:label="@string/write_settings_title"
+ android:taskAffinity="">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.action.MANAGE_WRITE_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:scheme="package" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.applications.WriteSettingsDetails" />
+ </activity>
+
<activity android:name="Settings$ManageExternalSourcesActivity"
android:label="@string/install_other_apps"
android:taskAffinity="">
@@ -2896,16 +2850,16 @@
android:value="com.android.settings.applications.ManageApplications" />
</activity>
- <activity android:name="Settings$AppWriteSettingsActivity"
- android:label="@string/write_settings_title"
- android:taskAffinity="">
+ <activity android:name="Settings$ManageAppExternalSourcesActivity"
+ android:label="@string/install_other_apps"
+ android:taskAffinity="">
<intent-filter android:priority="1">
- <action android:name="android.settings.action.MANAGE_WRITE_SETTINGS" />
+ <action android:name="android.settings.action.MANAGE_EXTERNAL_SOURCES" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.applications.WriteSettingsDetails" />
+ android:value="com.android.settings.applications.ExternalSourcesDetails" />
</activity>
<activity android:name="ShowAdminSupportDetailsDialog"
@@ -2989,7 +2943,7 @@
<!-- Alias for battery settings in new IA. Remove and merge metadata into TargetActivity -->
<activity android:name=".Settings$AppAndNotificationDashboardActivity"
android:label="@string/app_and_notification_dashboard_title"
- android:icon="@drawable/ic_dashboard_apps">
+ android:icon="@drawable/ic_apps">
<intent-filter android:priority="9">
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
@@ -3001,23 +2955,9 @@
android:value="@string/app_and_notification_dashboard_summary"/>
</activity>
- <activity android:name=".Settings$StorageDashboardActivity"
- android:label="@string/storage_settings"
- android:icon="@drawable/ic_dashboard_storage">
- <intent-filter android:priority="5">
- <action android:name="com.android.settings.action.SETTINGS" />
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.homepage" />
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.deviceinfo.StorageSettings" />
- <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
- android:value="true" />
- </activity>
-
<activity android:name=".Settings$UserAndAccountDashboardActivity"
android:label="@string/account_dashboard_title"
- android:icon="@drawable/ic_dashboard_user">
+ android:icon="@drawable/ic_settings_accounts">
<intent-filter android:priority="3">
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
@@ -3035,7 +2975,7 @@
<activity android:name=".Settings$SystemDashboardActivity"
android:label="@string/header_category_system"
- android:icon="@drawable/ic_dashboard_system">
+ android:icon="@drawable/ic_settings_about">
<intent-filter android:priority="1">
<action android:name="com.android.settings.action.SETTINGS"/>
</intent-filter>
@@ -3062,32 +3002,6 @@
android:resource="@string/support_summary"/>
</activity>
- <activity-alias android:name="ManageApplicationsDashboardAlias"
- android:targetActivity="Settings$ManageApplicationsActivity">
- <intent-filter android:priority="200">
- <action android:name="com.android.settings.action.SETTINGS" />
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.apps" />
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.applications.ManageApplications" />
- <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
- android:value="true" />
- </activity-alias>
-
- <activity-alias android:name="AppNotificationDashboardAlias"
- android:targetActivity="Settings$NotificationAppListActivity"
- android:icon="@drawable/ic_notifications">
- <intent-filter android:priority="150">
- <action android:name="com.android.settings.action.SETTINGS"/>
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.apps"/>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.applications.NotificationApps"/>
-
- </activity-alias>
-
<activity-alias android:name="ConfigureNotificationDashboardAlias"
android:targetActivity="Settings$ConfigureNotificationSettingsActivity">
<intent-filter android:priority="120">
@@ -3101,19 +3015,6 @@
android:value="true" />
</activity-alias>
- <activity-alias android:name="UsersDashboardAlias"
- android:targetActivity="Settings$UserSettingsActivity">
- <intent-filter android:priority="8">
- <action android:name="com.android.settings.action.SETTINGS"/>
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.users.UserSettings" />
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.accounts" />
- <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
- android:value="true" />
- </activity-alias>
-
<activity-alias android:name="AppDefaultDashboardAlias"
android:targetActivity="Settings$AdvancedAppsActivity"
android:label="@string/app_default_dashboard_title"
@@ -3129,19 +3030,6 @@
android:value="true" />
</activity-alias>
- <activity-alias android:name="PaymentSettingsDashboardAlias"
- android:targetActivity="Settings$PaymentSettingsActivity">
- <intent-filter android:priority="10">
- <action android:name="com.android.settings.action.SETTINGS"/>
- </intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.apps.default"/>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.nfc.PaymentSettings"/>
- <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
- android:value="true"/>
- </activity-alias>
-
<!-- End of information architecture host activities -->
<service
diff --git a/res/drawable/ic_dashboard_apps.xml b/res/drawable/ic_dashboard_apps.xml
deleted file mode 100644
index c0083a6..0000000
--- a/res/drawable/ic_dashboard_apps.xml
+++ /dev/null
@@ -1,25 +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="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z"
- android:fillColor="#ec8122"/>
-</vector>
diff --git a/res/drawable/ic_dashboard_display.xml b/res/drawable/ic_dashboard_display.xml
deleted file mode 100644
index ae367cf..0000000
--- a/res/drawable/ic_dashboard_display.xml
+++ /dev/null
@@ -1,26 +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="24.0dp"
- android:height="24.0dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="#4184f3"
- android:pathData="M20.0,15.31L23.31,12.0 20.0,8.69L20.0,4.0l-4.69,0.0L12.0,0.69 8.69,4.0L4.0,4.0l0.0,4.69L0.69,12.0 4.0,15.31L4.0,20.0l4.69,0.0L12.0,23.31 15.31,20.0L20.0,20.0l0.0,-4.69zM12.0,18.0L12.0,6.0c3.31,0.0 6.0,2.69 6.0,6.0s-2.69,6.0 -6.0,6.0z"/>
-</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_dashboard_security.xml b/res/drawable/ic_dashboard_security.xml
deleted file mode 100644
index 1e6a1e8..0000000
--- a/res/drawable/ic_dashboard_security.xml
+++ /dev/null
@@ -1,26 +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="24.0dp"
- android:height="24.0dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="#7a1ea1"
- android:pathData="M18.0,8.0l-1.0,0.0L17.0,6.0c0.0,-2.76 -2.24,-5.0 -5.0,-5.0S7.0,3.24 7.0,6.0l0.0,2.0L6.0,8.0c-1.1,0.0 -2.0,0.9 -2.0,2.0l0.0,10.0c0.0,1.0 0.9,2.0 2.0,2.0l12.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0L20.0,10.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0zm-6.0,9.0c-1.1,0.0 -2.0,-0.9 -2.0,-2.0s0.9,-2.0 2.0,-2.0 2.0,0.9 2.0,2.0 -0.9,2.0 -2.0,2.0zm3.1,-9.0L8.9,8.0L8.9,6.0c0.0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0.0 3.1,1.39 3.1,3.1l0.0,2.0z"/>
-</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_dashboard_sound.xml b/res/drawable/ic_dashboard_sound.xml
deleted file mode 100644
index 0cd3b04..0000000
--- a/res/drawable/ic_dashboard_sound.xml
+++ /dev/null
@@ -1,26 +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="24.0dp"
- android:height="24.0dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="#4184f3"
- android:pathData="M3.0,9.0l0.0,6.0l4.0,0.0l5.0,5.0L12.0,4.0L7.0,9.0L3.0,9.0zm13.5,3.0c0.0,-1.77 -1.02,-3.29 -2.5,-4.03l0.0,8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14.0,3.23l0.0,2.06c2.8,0.86 5.0,3.54 5.0,6.71s-2.11,5.85 -5.0,6.71l0.0,2.06c4.01,-0.91 7.0,-4.49 7.0,-8.77s-2.99,-7.86 -7.0,-8.77z"/>
-</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_dashboard_storage.xml b/res/drawable/ic_dashboard_storage.xml
deleted file mode 100644
index 2b6160e..0000000
--- a/res/drawable/ic_dashboard_storage.xml
+++ /dev/null
@@ -1,26 +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="24.0dp"
- android:height="24.0dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="#4184f3"
- android:pathData="M2.0,20.0l20.0,0.0l0.0,-4.0L2.0,16.0l0.0,4.0zm2.0,-3.0l2.0,0.0l0.0,2.0L4.0,19.0l0.0,-2.0zM2.0,4.0l0.0,4.0l20.0,0.0L22.0,4.0L2.0,4.0zm4.0,3.0L4.0,7.0L4.0,5.0l2.0,0.0l0.0,2.0zm-4.0,7.0l20.0,0.0l0.0,-4.0L2.0,10.0l0.0,4.0zm2.0,-3.0l2.0,0.0l0.0,2.0L4.0,13.0l0.0,-2.0z"/>
-</vector>
diff --git a/res/drawable/ic_dashboard_system.xml b/res/drawable/ic_dashboard_system.xml
deleted file mode 100644
index fdd9214..0000000
--- a/res/drawable/ic_dashboard_system.xml
+++ /dev/null
@@ -1,26 +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="24.0dp"
- android:height="24.0dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="#606060"
- android:pathData="M11.0,17.0l2.0,0.0l0.0,-6.0l-2.0,0.0l0.0,6.0zm1.0,-15.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0zm0.0,18.0c-4.41,0.0 -8.0,-3.59 -8.0,-8.0s3.59,-8.0 8.0,-8.0 8.0,3.59 8.0,8.0 -3.59,8.0 -8.0,8.0zM11.0,9.0l2.0,0.0L13.0,7.0l-2.0,0.0l0.0,2.0z"/>
-</vector>
diff --git a/res/drawable/ic_dashboard_user.xml b/res/drawable/ic_dashboard_user.xml
deleted file mode 100644
index 302d33e..0000000
--- a/res/drawable/ic_dashboard_user.xml
+++ /dev/null
@@ -1,30 +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="24.0dp"
- android:height="24.0dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="#aeb32a"
- android:pathData="M3.0,5.0
- l0.0,14.0c0.0,1.0 0.89,2.0 2.0,2.0l14.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0
- L21.0,5.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0
- L5.0,3.0c-1.11,0.0 -2.0,0.9 -2.0,2.0zm12.0,4.0c0.0,1.66 -1.34,3.0 -3.0,3.0s-3.0,-1.34 -3.0,-3.0 1.34,-3.0 3.0,-3.0 3.0,1.34 3.0,3.0zm-9.0,8.0c0.0,-2.0 4.0,-3.1 6.0,-3.1s6.0,1.1 6.0,3.1l0.0,1.0
- l-12.0,0l0.0,-1.0z"/>
-</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_devices_other.xml b/res/drawable/ic_devices_other.xml
index 73407a3..20639a3 100644
--- a/res/drawable/ic_devices_other.xml
+++ b/res/drawable/ic_devices_other.xml
@@ -17,8 +17,9 @@
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
- android:viewportHeight="24.0">
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
<path
android:pathData="M3,6h18L21,4L3,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h4v-2L3,18L3,6zM13,12L9,12v1.78c-0.61,0.55 -1,1.33 -1,2.22s0.39,1.67 1,2.22L9,20h4v-1.78c0.61,-0.55 1,-1.34 1,-2.22s-0.39,-1.67 -1,-2.22L13,12zM11,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM22,8h-6c-0.5,0 -1,0.5 -1,1v10c0,0.5 0.5,1 1,1h6c0.5,0 1,-0.5 1,-1L23,9c0,-0.5 -0.5,-1 -1,-1zM21,18h-4v-8h4v8z"
- android:fillColor="#0b9c57"/>
+ android:fillColor="#FFFFFFFF"/>
</vector>
diff --git a/res/drawable/ic_help.xml b/res/drawable/ic_help.xml
index 5b056e7..7a225e5 100644
--- a/res/drawable/ic_help.xml
+++ b/res/drawable/ic_help.xml
@@ -17,8 +17,9 @@
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
- android:viewportHeight="24.0">
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
<path
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"
- android:fillColor="#f3501d"/>
+ android:fillColor="#FFFFFFFF"/>
</vector>
diff --git a/res/drawable/ic_settings_accessibility.xml b/res/drawable/ic_settings_accessibility.xml
index a689c4a..34c0bdd 100644
--- a/res/drawable/ic_settings_accessibility.xml
+++ b/res/drawable/ic_settings_accessibility.xml
@@ -17,8 +17,9 @@
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
- android:viewportHeight="24.0">
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
<path
- android:fillColor="#3e50b4"
+ android:fillColor="#FFFFFFFF"
android:pathData="M12.0,2.0c1.1,0.0 2.0,0.9 2.0,2.0s-0.9,2.0 -2.0,2.0 -2.0,-0.9 -2.0,-2.0 0.9,-2.0 2.0,-2.0zm9.0,7.0l-6.0,0.0l0.0,13.0l-2.0,0.0l0.0,-6.0l-2.0,0.0l0.0,6.0L9.0,22.0L9.0,9.0L3.0,9.0L3.0,7.0l18.0,0.0l0.0,2.0z"/>
</vector>
diff --git a/res/drawable/ic_settings_battery.xml b/res/drawable/ic_settings_battery.xml
index f1e56d8..c8e053d 100644
--- a/res/drawable/ic_settings_battery.xml
+++ b/res/drawable/ic_settings_battery.xml
@@ -17,9 +17,10 @@
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
- android:viewportHeight="24.0">
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
<path
- android:fillColor="#4184f3"
+ android:fillColor="#FFFFFFFF"
android:pathData="M15.67,4.0L14.0,4.0L14.0,2.0l-4.0,0.0l0.0,2.0L8.33,4.0C7.6,4.0 7.0,4.6 7.0,5.33l0.0,15.33C7.0,21.4 7.6,22.0 8.33,22.0l7.33,0.0c0.74,0.0 1.34,-0.6 1.34,-1.33L17.0,5.33C17.0,4.6 16.4,4.0 15.67,4.0z
M16,5l0,5.5l-8,0l0,-5.5l3,0l0,-2l2,0l0,2l3,0z"/>
</vector>
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 00d4cca..15cb38a 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -18,7 +18,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/app_snippet"
- style="@style/EntityHeader"
+ style="@style/AppInfoHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
@@ -79,7 +79,7 @@
<TextView
android:id="@+id/app_detail_title"
- style="@style/TextAppearance.EntityHeaderTitle"
+ style="@style/TextAppearance.AppInfoTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"
@@ -89,24 +89,22 @@
<TextView
android:id="@+id/install_type"
+ style="@style/TextAppearance.AppInfoSummary"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondary"/>
+ android:ellipsize="marquee"/>
<TextView
android:id="@+id/app_detail_summary"
+ style="@style/TextAppearance.AppInfoSummary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:singleLine="true"
- android:ellipsize="marquee"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondary"/>
+ android:ellipsize="marquee"/>
</LinearLayout>
diff --git a/res/layout/app_preferred_settings.xml b/res/layout/app_preferred_settings.xml
index d0041a1..1f3b497 100644
--- a/res/layout/app_preferred_settings.xml
+++ b/res/layout/app_preferred_settings.xml
@@ -14,36 +14,27 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<ScrollView
+<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:clipToPadding="false"
- android:scrollbarStyle="@integer/preference_scrollbar_style">
+ android:layout_height="wrap_content"
+ android:paddingStart="@dimen/preference_no_icon_padding_start"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingBottom="5dip"
+ android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
+ <TextView android:id="@+id/auto_launch"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:layout_alignParentStart="true"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="6dip" />
+
+ <Button
+ android:id="@+id/clear_activities_button"
+ android:layout_marginStart="-4dip"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:paddingBottom="5dip"
- android:orientation="vertical">
+ android:text="@string/clear_activities" />
- <TextView android:id="@+id/auto_launch"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_alignParentStart="true"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="6dip" />
-
- <Button
- android:id="@+id/clear_activities_button"
- android:layout_marginStart="-4dip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/clear_activities" />
-
- </LinearLayout>
-
-</ScrollView>
+</LinearLayout>
diff --git a/res/layout/date_time_custom_list_item_2.xml b/res/layout/date_time_custom_list_item_2.xml
index ed32fb7..4902758 100644
--- a/res/layout/date_time_custom_list_item_2.xml
+++ b/res/layout/date_time_custom_list_item_2.xml
@@ -15,29 +15,28 @@
-->
<!-- Based on simple_list_item_2.xml in framework -->
-<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:mode="twoLine"
+ android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
->
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:orientation="vertical"
+ android:paddingStart="@dimen/preference_no_icon_padding_start"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
- <TextView android:id="@android:id/text1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="16dip"
- android:layout_marginStart="10dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- />
+ <TextView
+ android:id="@android:id/text1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceListItem" />
- <TextView android:id="@android:id/text2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="10dip"
- android:layout_below="@android:id/text1"
- android:layout_alignStart="@android:id/text1"
- android:textAppearance="?android:attr/textAppearanceSmall"
- />
+ <TextView
+ android:id="@android:id/text2"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+ android:textColor="?android:attr/textColorSecondary" />
-</TwoLineListItem>
+</LinearLayout>
diff --git a/res/layout/dialog_hardware_info.xml b/res/layout/dialog_hardware_info.xml
new file mode 100644
index 0000000..f9d52b8
--- /dev/null
+++ b/res/layout/dialog_hardware_info.xml
@@ -0,0 +1,57 @@
+<?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.
+ -->
+
+<ScrollView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:padding="24dp">
+
+ <TextView
+ android:id="@+id/model_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.Material.Body1"
+ android:textColor="?android:attr/textColorSecondary"
+ android:text="@string/model_info" />
+ <TextView
+ android:id="@+id/model_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingBottom="24dp"
+ android:textAppearance="@android:style/TextAppearance.Material.Body2" />
+
+ <TextView
+ android:id="@+id/hardware_rev_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.Material.Body1"
+ android:textColor="?android:attr/textColorSecondary"
+ android:text="@string/hardware_revision" />
+ <TextView
+ android:id="@+id/hardware_rev_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingBottom="24dp"
+ android:textAppearance="@android:style/TextAppearance.Material.Body2" />
+
+ </LinearLayout>
+</ScrollView>
\ No newline at end of file
diff --git a/res/layout/expand_preference.xml b/res/layout/expand_preference.xml
index 1392d65..d5fe031 100644
--- a/res/layout/expand_preference.xml
+++ b/res/layout/expand_preference.xml
@@ -56,9 +56,7 @@
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
- android:textColor="?android:attr/colorAccent"
android:ellipsize="marquee"/>
<TextView
diff --git a/res/layout/installed_app_details.xml b/res/layout/installed_app_details.xml
deleted file mode 100644
index c84936a..0000000
--- a/res/layout/installed_app_details.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 2008, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/all_details"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:orientation="vertical">
-
- <!-- App snippet with buttons -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:paddingTop="5dip"
- android:paddingBottom="10dip"
- android:orientation="vertical">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <FrameLayout
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- <!-- Application snippet label, version and icon -->
- <include
- layout="@layout/app_item"
- android:id="@+id/app_snippet" />
- </FrameLayout>
-
- <ImageView
- android:id="@+id/gear"
- android:layout_width="48dp"
- android:layout_height="48dp"
- android:layout_gravity="center_vertical"
- android:padding="12dp"
- android:src="@drawable/ic_settings_24dp"
- android:tint="?android:attr/colorAccent"
- android:clickable="true"
- android:background="?android:attr/selectableItemBackground" />
-
- </LinearLayout>
-
- <Space
- android:layout_width="match_parent"
- android:layout_height="5dp" />
-
- <!-- Force stop and uninstall buttons -->
- <include
- layout="@layout/two_buttons_panel"
- android:id="@+id/control_buttons_panel"/>
-
- </LinearLayout>
-</LinearLayout>
-
diff --git a/res/layout/preference_footer.xml b/res/layout/preference_footer.xml
index e336ac1..1df4f70 100644
--- a/res/layout/preference_footer.xml
+++ b/res/layout/preference_footer.xml
@@ -20,7 +20,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
- android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/selectableItemBackground"
@@ -31,15 +30,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="60dp"
- android:gravity="start|center_vertical"
+ android:gravity="start|top"
android:orientation="horizontal"
android:paddingEnd="12dp"
- android:paddingTop="4dp"
+ android:paddingTop="20dp"
android:paddingBottom="4dp">
- <com.android.internal.widget.PreferenceImageView
+ <ImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
+ android:layout_height="wrap_content" />
</LinearLayout>
<com.android.settingslib.widget.LinkTextView
@@ -50,6 +49,6 @@
android:paddingTop="16dp"
android:maxLines="10"
android:textColor="?android:attr/textColorSecondary"
- android:ellipsize="marquee"/>
+ android:ellipsize="marquee" />
</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/storage_summary_donut.xml b/res/layout/storage_summary_donut.xml
index eadb6e5..9fd4860 100644
--- a/res/layout/storage_summary_donut.xml
+++ b/res/layout/storage_summary_donut.xml
@@ -56,15 +56,6 @@
android:textAlignment="viewStart"
android:textAppearance="@android:style/TextAppearance.Material.Body1" />
- <TextView
- android:id="@+id/storage_manager_indicator"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginStart="4dp"
- android:layout_marginEnd="4dp"
- android:textAlignment="viewStart"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"/>
-
<Button
android:id="@+id/deletion_helper_button"
android:layout_width="wrap_content"
diff --git a/res/layout/vpn_dialog.xml b/res/layout/vpn_dialog.xml
index 6822e95..61b0861 100644
--- a/res/layout/vpn_dialog.xml
+++ b/res/layout/vpn_dialog.xml
@@ -20,7 +20,7 @@
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:padding="8dp">
+ android:padding="24dp">
<LinearLayout android:id="@+id/editor"
android:layout_width="match_parent"
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index d099cdc..d4f9d90 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -92,6 +92,8 @@
<attr name="apnPreferenceStyle" format="reference" />
+ <attr name="footerPreferenceStyle" format="reference" />
+
<!-- For Search -->
<declare-styleable name="Preference">
<attr name="keywords" format="string" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1e1304e..1a2957e1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2364,6 +2364,10 @@
<string name="security_patch">Android security patch level</string>
<!-- About phone screen, status item label [CHAR LIMIT=40] -->
<string name="model_info">Model</string>
+ <!-- About phone screen, dialog title for showing hardware information such as model, serial number, etc.[CHAR LIMIT=60] -->
+ <string name="hardware_info">Model & hardware</string>
+ <!-- Label for device's hardware revision value [CHAR LIMIT=40] -->
+ <string name="hardware_revision">Hardware version</string>
<!-- About phone screen, fcc equipment id label [CHAR LIMIT=40] -->
<string name="fcc_equipment_id">Equipment ID</string>
<!-- About phone screen, setting option name [CHAR LIMIT=40] -->
@@ -3013,6 +3017,10 @@
<string name="sms_change_default_dialog_text" translatable="true">Use <xliff:g id="new_app">%1$s</xliff:g> instead of <xliff:g id="current_app">%2$s</xliff:g> as your SMS app?</string>
<string name="sms_change_default_no_previous_dialog_text" translatable="true">Use <xliff:g id="new_app">%s</xliff:g> as your SMS app?</string>
+ <!-- Network Scorer Picker title [CHAR LIMIT=40]-->
+ <string name="network_scorer_picker_title">Network Scorer</string>
+ <string name="network_scorer_picker_none_preference">None</string>
+
<!-- Wifi Assistant change wi-fi assistant title. [CHAR LIMIT=40] -->
<string name="network_scorer_change_active_dialog_title">Change Wi\u2011Fi assistant?</string>
<!-- Wifi Assistant request message. This message asks the user if it is okay for an app to become the Wifi Assistant instead of the current Wifi Assistant app. [CHAR LIMIT=100] -->
@@ -3751,7 +3759,9 @@
<!-- On Text & language settings screen, setting summary for the Auto-punctuate setting. -->
<string name="auto_punctuate_summary">Press Space key twice to insert \u0022.\u0022</string>
<!-- On Security & location settings screen, setting check box name. Title of the checkbox to set whether password edit fields will show the most recent character typed and then hide it, or just hide it right away. By hide, I mean mask it out. -->
- <string name="show_password">Make passwords visible</string>
+ <string name="show_password">Show passwords</string>
+ <!-- On Security & location settings screen. This is a short summary text describing what "Show passwords" setting does -->
+ <string name="show_password_summary">Display characters briefly as you type</string>
<!-- Warning message about security implications of enabling an input method, displayed as a dialog
message when the user selects to enable an IME. -->
<string name="ime_security_warning">This input method may be able to collect
@@ -4285,6 +4295,11 @@
<!-- Display time remaining until battery is charged [CHAR_LIMIT=60] -->
<string name="power_charge_remaining"><xliff:g id="until_charged">%1$s</xliff:g> to charge</string>
+ <!-- Title for the background activity setting, which allows a user to control whether an app can run in the background [CHAR_LIMIT=40] -->
+ <string name="background_activity_title">Background activity</string>
+ <!-- Summary for the background activity [CHAR_LIMIT=120] -->
+ <string name="background_activity_summary">Allow the app to run in the background</string>
+
<!-- Title for the screen usage in power use UI [CHAR_LIMIT=40] -->
<string name="device_screen_usage">Screen usage</string>
<!-- Title for the screen consumption in power use UI(i.e. Screen consumption: 30% of battery usage) [CHAR_LIMIT=40] -->
@@ -8052,6 +8067,9 @@
<!-- Summary text for the assist gesture [CHAR LIMIT=160]-->
<string name="assist_gesture_summary"></string>
+ <!-- Title text for the assist gesture sensitivity setting [CHAR LIMIT=NONE]-->
+ <string name="assist_gesture_sensitivity_title">Sensitivity</string>
+
<!-- Switch text for each gesture setting state -->
<string name="gesture_setting_on">On</string>
<string name="gesture_setting_off">Off</string>
@@ -8100,62 +8118,58 @@
<!-- Enterprise Privacy --> <skip />
- <!-- Title of setting on main settings screen. This will take the user to a screen with information about his/her privacy on a managed device. Shown on enterprise-managed devices only. -->
- <string name="enterprise_privacy_settings">Privacy</string>
+ <!-- Title of setting on security settings screen. This will take the user to a screen with information about admin powers and their impact on the user's privacy on a managed device. Shown on enterprise-managed devices only. -->
+ <string name="enterprise_privacy_settings">Device management</string>
+ <!-- Summary for Enterprise Privacy settings, explaining what the user can expect to find under it [CHAR LIMIT=NONE]-->
+ <string name="enterprise_privacy_settings_summary">View all settings applied by your admin</string>
<!-- Enterprise Privacy settings activity title -->
- <string name="enterprise_privacy_settings_title">Privacy</string>
- <!-- Enterprise Privacy settings activity header, summarizing the powers that the admin has. [CHAR LIMIT=NONE] -->
- <string name="enterprise_privacy_header">To provide access to your work data, your organization may change settings and install software on your device, which could cause some of your personal content to be visible to your admin. Contact your organization\'s admin for more details.</string>
- <!-- Title for the 'What types of information can your organization see?' preference category. [CHAR LIMIT=60] -->
- <string name="enterprise_privacy_exposure_category">What types of information can your organization see?</string>
- <!-- Title for the 'What changes affect what your organization can see?' preference category. [CHAR LIMIT=60] -->
- <string name="enterprise_privacy_exposure_changes_category">What changes affect what your organization can see?</string>
- <!-- Title for the 'What actions may impact your access to this device?' preference category. [CHAR LIMIT=60] -->
- <string name="enterprise_privacy_device_access_category">What actions may impact your access to this device?</string>
+ <string name="enterprise_privacy_settings_title">Device management</string>
+ <!-- Enterprise Privacy settings activity footer, summarizing the powers that the admin has. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_footer">To provide access to your work data, your organization may change settings and install software on your device. \n\nFor more details, contact your organization\'s admin.</string>
+ <!-- Title for the 'Types of information your organization can see' preference category. [CHAR LIMIT=60] -->
+ <string name="enterprise_privacy_exposure_category">Types of information your organization can see</string>
+ <!-- Title for the 'Changes made by your organization’s admin' preference category. [CHAR LIMIT=60] -->
+ <string name="enterprise_privacy_exposure_changes_category">Changes made by your organization\'s admin</string>
+ <!-- Title for the 'Your access to this device' preference category. [CHAR LIMIT=60] -->
+ <string name="enterprise_privacy_device_access_category">Your access to this device</string>
<!-- Label explaining that the admin can see data associated with his/her work account. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_enterprise_data">Data associated with your work account, such as email and calendar</string>
- <!-- Label explaining that the admin can see all apps installed on the device. [CHAR LIMIT=NONE] -->
- <string name="enterprise_privacy_number_installed_packages_default">List of all apps on your device</string>
- <!-- Label explaining that the admin can see all apps installed on the device. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_number_installed_packages">
- <item quantity="one">List of all <xliff:g id="count">%d</xliff:g> app on your device</item>
- <item quantity="other">List of all <xliff:g id="count">%d</xliff:g> apps on your device</item>
+ <!-- Label explaining that the admin can see apps installed on the device. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_installed_packages">List of apps on your device</string>
+ <!-- Summary indicating the number of apps that a label (e.g. installed apps or apps granted a particular permission) refers to. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_number_packages">
+ <item quantity="one"><xliff:g id="count">%d</xliff:g> app</item>
+ <item quantity="other"><xliff:g id="count">%d</xliff:g> apps</item>
+ </plurals>
+ <!-- Summary indicating the number of apps that a label (e.g. installed apps or apps granted a particular permission) refers to. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_number_packages_actionable">
+ <item quantity="one"><xliff:g id="count">%d</xliff:g> app. Tap to view.</item>
+ <item quantity="other"><xliff:g id="count">%d</xliff:g> apps. Tap to view.</item>
</plurals>
<!-- Label explaining that the admin can see app usage statistics. [CHAR LIMIT=NONE] -->
- <string name="enterprise_privacy_usage_stats">Usage (time spent and amount of data used) of each app on your device</string>
+ <string name="enterprise_privacy_usage_stats">Time and data spent in each app on your device</string>
<!-- Label explaining that the admin can retrieve network logs on the device. [CHAR LIMIT=NONE] -->
- <string name="enterprise_privacy_network_logs">Traffic logs on your device</string>
+ <string name="enterprise_privacy_network_logs">Network traffic logs on your device</string>
<!-- Label explaining that the admin can request bug reports on the device. [CHAR LIMIT=NONE] -->
- <string name="enterprise_privacy_bug_reports">Your most recent bug report</string>
+ <string name="enterprise_privacy_bug_reports">Most recent bug report</string>
<!-- Label explaining that the admin can retrieve security on from the device. [CHAR LIMIT=NONE] -->
- <string name="enterprise_privacy_security_logs">Your most recent security log</string>
- <!-- Label indicating that the date at which the admin last took a particular action was "never" (i.e. the admin never took the action so far). -->
- <string name="enterprise_privacy_never">Never</string>
- <!-- Label indicating how many apps were installed on the device by the admin. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_number_enterprise_installed_packages">
- <item quantity="one"><xliff:g id="count">%d</xliff:g> app installed by your admin</item>
- <item quantity="other"><xliff:g id="count">%d</xliff:g> apps installed by your admin</item>
- </plurals>
- <!-- Label indicating how many apps were granted permission to access the device's location by the admin. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_number_location_access_packages">
- <item quantity="one"><xliff:g id="count">%d</xliff:g> app allowed access to your location by your admin</item>
- <item quantity="other"><xliff:g id="count">%d</xliff:g> apps allowed access to your location by your admin</item>
- </plurals>
- <!-- Label indicating how many apps were granted permission to access the microphone by the admin. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_number_microphone_access_packages">
- <item quantity="one"><xliff:g id="count">%d</xliff:g> app allowed access to your microphone by your admin</item>
- <item quantity="other"><xliff:g id="count">%d</xliff:g> apps allowed access to your microphone by your admin</item>
- </plurals>
- <!-- Label indicating how many apps were granted permission to access the camera by the admin. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_number_camera_access_packages">
- <item quantity="one"><xliff:g id="count">%d</xliff:g> app allowed access to your camera by your admin</item>
- <item quantity="other"><xliff:g id="count">%d</xliff:g> apps allowed access to your camera by your admin</item>
- </plurals>
- <!-- Label indicating how many apps were set as default defaults for common actions (e.g. open browser, send e-mail) by the admin. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_number_enterprise_set_default_apps">
- <item quantity="one"><xliff:g id="count">%d</xliff:g> default app set by your admin</item>
- <item quantity="other"><xliff:g id="count">%d</xliff:g> default apps set by your admin</item>
- </plurals>
+ <string name="enterprise_privacy_security_logs">Most recent security log</string>
+ <!-- Label indicating that the the admin never took a given action so far (e.g. did not retrieve security logs or request bug reports). -->
+ <string name="enterprise_privacy_none">None</string>
+ <!-- Label indicating that the admin installed one or more apps on the device. -->
+ <string name="enterprise_privacy_enterprise_installed_packages">Apps installed</string>
+ <!-- Label indicating that the admin granted one or more apps access to the device's location. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_location_access">Apps allowed to access your location</string>
+ <!-- Label indicating that the admin granted one or more apps access to the microphone. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_microphone_access">Apps allowed to access your microphone</string>
+ <!-- Label indicating that the admin granted one or more apps access to the camera. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_camera_access">Apps allowed to access your camera</string>
+ <!-- Label indicating that the admin set one or more apps as defaults for common actions (e.g. open browser, send e-mail). [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_enterprise_set_default_apps">Default apps set</string>
+ <!-- Label explaining that the current input method was set by the admin. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_input_method">Default keyboard</string>
+ <!-- Summary indicating the input method set by the admin. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_input_method_name">Set to <xliff:g id="app_label" example="Example Keyboard">%s</xliff:g></string>
<!-- Label explaining that an always-on VPN was set by the admin for the entire device. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_always_on_vpn_device">Always-on VPN turned on</string>
<!-- Label explaining that an always-on VPN was set by the admin in the personal profile. [CHAR LIMIT=NONE] -->
@@ -8164,22 +8178,46 @@
<string name="enterprise_privacy_always_on_vpn_work">Always-on VPN turned on in your work profile</string>
<!-- Label explaining that a global HTTP proxy was set by the admin. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_global_http_proxy">Global HTTP proxy set</string>
+ <!-- Label explaining that the admin installed trusted CA certificates for the current user. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_ca_certs_user">
+ <item quantity="one">Trusted CA Certificate installed</item>
+ <item quantity="other">Trusted CA Certificates installed</item>
+ </plurals>
+ <!-- Label explaining that the admin installed trusted CA certificates for the personal profile. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_ca_certs_personal">
+ <item quantity="one">Trusted CA Certificate installed in the personal profile</item>
+ <item quantity="other">Trusted CA Certificates installed in the personal profile</item>
+ </plurals>
+ <!-- Summary indicating the number of trusted CA certificates installed by the admin. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_number_ca_certs">
+ <item quantity="one"><xliff:g id="count">%d</xliff:g> certificate</item>
+ <item quantity="other"><xliff:g id="count">%d</xliff:g> certificates</item>
+ </plurals>
+ <!-- Summary indicating the number of trusted CA certificates installed by the admin. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_number_ca_certs_actionable">
+ <item quantity="one"><xliff:g id="count">%d</xliff:g> certificate. Tap to view.</item>
+ <item quantity="other"><xliff:g id="count">%d</xliff:g> certificates. Tap to view.</item>
+ </plurals>
+ <!-- Label explaining that the admin installed trusted CA certificates for the work profile. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_ca_certs_work">
+ <item quantity="one">Trusted CA Certificate installed in the work profile</item>
+ <item quantity="other">Trusted CA Certificates installed in the work profile</item>
+ </plurals>
<!-- Label explaining that the admin can lock the device and change the user's password. [CHAR LIMIT=NONE] -->
- <string name="enterprise_privacy_lock_device">Admin can lock device and reset password</string>
+ <string name="enterprise_privacy_lock_device">Admin can lock the device and reset password</string>
<!-- Label explaining that the admin can wipe the device remotely. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_wipe_device">Admin can delete all device data</string>
- <!-- Label explaining that the admin configured the device to wipe itself when the password is mistyped this many times. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_failed_password_wipe_device">
- <item quantity="one">Admin set maximum password attempts to <xliff:g id="count">%d</xliff:g> before deleting all device data</item>
- <item quantity="other">Admin set maximum password attempts to <xliff:g id="count">%d</xliff:g> before deleting all device data</item>
- </plurals>
- <!-- Label explaining that the admin configured the work profile to wipe itself when the password is mistyped this many times. [CHAR LIMIT=NONE] -->
- <plurals name="enterprise_privacy_failed_password_wipe_work">
- <item quantity="one">Admin set maximum password attempts to <xliff:g id="count">%d</xliff:g> before deleting work profile data</item>
- <item quantity="other">Admin set maximum password attempts to <xliff:g id="count">%d</xliff:g> before deleting work profile data</item>
+ <!-- Label explaining that the admin configured the device to wipe itself when the password is mistyped too many times. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_failed_password_wipe_device">Failed password attempts before deleting all device data</string>
+ <!-- Label explaining that the admin configured the work profile to wipe itself when the password is mistyped too many times. [CHAR LIMIT=NONE] -->
+ <string name="enterprise_privacy_failed_password_wipe_work">Failed password attempts before deleting work profile data</string>
+ <!-- Summary indicating the number of mistyped passwords after which the device or work profile wipes itself. [CHAR LIMIT=NONE] -->
+ <plurals name="enterprise_privacy_number_failed_password_wipe">
+ <item quantity="one"><xliff:g id="count">%d</xliff:g> attempt</item>
+ <item quantity="other"><xliff:g id="count">%d</xliff:g> attempts</item>
</plurals>
<!-- Message indicating that the device is enterprise-managed by a Device Owner [CHAR LIMIT=NONE] -->
- <string name="do_disclosure_generic">This device is managed.</string>
+ <string name="do_disclosure_generic">This device is managed by your organization.</string>
<!-- Message indicating that the device is enterprise-managed by a Device Owner [CHAR LIMIT=NONE] -->
<string name="do_disclosure_with_name">This device is managed by <xliff:g id="organization_name" example="Foo, Inc.">%s</xliff:g>.</string>
<!-- Message indicating that the device is enterprise-managed: Space that separates the main text and the "learn more" link that follows it. [CHAR LIMIT=NONE] -->
@@ -8203,7 +8241,7 @@
<string name="storage_files">Files</string>
<!-- Main settings screen item's title to go into the storage settings screen [CHAR LIMIT=25] -->
- <string name="storage_settings_2" >Phone Storage</string>
+ <string name="storage_settings_2">Phone storage</string>
<!-- Summary of a single storage volume used space. [CHAR LIMIT=24] -->
<string name="storage_size_large_alternate"><xliff:g id="number" example="128">^1</xliff:g><small> <xliff:g id="unit" example="KB">^2</xliff:g></small></string>
@@ -8212,18 +8250,6 @@
<!-- The percent of storage used by a storage volume. Exposed inside of a donut graph. [CHAR LIMIT=4]-->
<string name="storage_percent_used"><xliff:g id="percent" example="50%">%1$s</xliff:g>%%</string>
- <!-- Indicates if the automatic storage manager is enabled or not. [CHAR_LIMIT=40] -->
- <string name="storage_manager_indicator">Storage Manager: <xliff:g id="status" example="on">^1</xliff:g></string>
-
- <!-- Off status for the automatic storage manager. [CHAR_LIMIT=10] -->
- <string name="storage_manager_indicator_off">Off</string>
-
- <!-- On status for the automatic storage manager. [CHAR_LIMIT=10] -->
- <string name="storage_manager_indicator_on">On</string>
-
- <!-- Added as the value of a header field indicating this is an instant app (as opposed to installed normally) -->
- <string name="install_type_instant">Instant app</string>
-
<!-- Title of games app storage screen [CHAR LIMIT=30] -->
<string name="game_storage_settings">Games</string>
@@ -8252,4 +8278,16 @@
<!-- Temporary reboot string, will be removed -->
<string name="change_theme_reboot" translatable="false">Changing the theme requires a restart.</string>
+ <!-- Indicates if the automatic storage manager is enabled or not. [CHAR_LIMIT=40] -->
+ <string name="storage_manager_indicator">Storage Manager: <xliff:g id="status" example="on">^1</xliff:g></string>
+
+ <!-- Off status for the automatic storage manager. [CHAR_LIMIT=10] -->
+ <string name="storage_manager_indicator_off">Off</string>
+
+ <!-- On status for the automatic storage manager. [CHAR_LIMIT=10] -->
+ <string name="storage_manager_indicator_on">On</string>
+
+ <!-- Added as the value of a header field indicating this is an instant app (as opposed to installed normally) -->
+ <string name="install_type_instant">Instant app</string>
+
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 2692508..d193c30 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -428,6 +428,19 @@
<item name="android:textSize">24sp</item>
</style>
+ <style name="AppInfoHeader" parent="EntityHeader">
+ <item name="android:background">?android:attr/colorAccent</item>
+ </style>
+
+ <style name="TextAppearance.AppInfoTitle" parent="TextAppearance.EntityHeaderTitle">
+ <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
+ </style>
+
+ <style name="TextAppearance.AppInfoSummary"
+ parent="@android:style/TextAppearance.Material.Body1">
+ <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
+ </style>
+
<style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/>
<style name="LockPatternStyle">
diff --git a/res/values/styles_preference.xml b/res/values/styles_preference.xml
index e7c2852..8271df4 100644
--- a/res/values/styles_preference.xml
+++ b/res/values/styles_preference.xml
@@ -38,6 +38,11 @@
<item name="android:layout">@layout/apn_preference_layout</item>
</style>
+ <style name="FooterPreference" parent="SettingsPreference">
+ <item name="android:layout">@layout/preference_footer</item>
+ <item name="allowDividerAbove">true</item>
+ </style>
+
<style name="EditTextPreference"
parent="@style/Preference.DialogPreference.EditTextPreference.Material">
<item name="allowDividerAbove">false</item>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index c961cce..99e2133 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -81,6 +81,7 @@
<!-- Parent path frameworks/support/v14/preference/res/values/themes.xml -->
<item name="android:scrollbars">vertical</item>
<item name="apnPreferenceStyle">@style/ApnPreference</item>
+ <item name="footerPreferenceStyle">@style/FooterPreference</item>
<item name="dialogPreferenceStyle">@style/SettingsDialogPreference</item>
<item name="dropdownPreferenceStyle">@style/SettingsDropdownPreference</item>
<item name="editTextPreferenceStyle">@style/EditTextPreference</item>
@@ -102,8 +103,10 @@
<!-- 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="preferenceTheme">@style/PreferenceTheme</item>
<item name="switchBarTheme">@style/SetupWizardAccessibilitySwitchBarTheme</item>
</style>
@@ -216,7 +219,6 @@
</style>
<style name="Theme.ConfirmDeviceCredentials" parent="Theme.SubSettings">
- <item name="android:windowLightStatusBar">false</item>
<item name="confirmDeviceCredentialsSideMargin">@dimen/confirm_credentials_side_margin</item>
<item name="confirmDeviceCredentialsTopMargin">@dimen/confirm_credentials_top_margin</item>
</style>
diff --git a/res/xml/app_default_settings.xml b/res/xml/app_default_settings.xml
index a382bc9..e96c070 100644
--- a/res/xml/app_default_settings.xml
+++ b/res/xml/app_default_settings.xml
@@ -67,7 +67,7 @@
android:key="default_autofill"
android:title="@string/autofill_app"
android:summary="@string/app_list_preference_none"
- android:fragment="com.android.settings.applications.defaultapps.DefaultAutoFillPicker"
+ android:fragment="com.android.settings.applications.defaultapps.DefaultAutofillPicker"
settings:keywords="@string/autofill_keywords"
android:order="-14"/>
diff --git a/res/xml/app_storage_settings.xml b/res/xml/app_storage_settings.xml
index 0254b13..6bd8ae3 100644
--- a/res/xml/app_storage_settings.xml
+++ b/res/xml/app_storage_settings.xml
@@ -51,23 +51,11 @@
android:layout="@layout/horizontal_preference" />
<Preference
- android:key="external_code_size"
- android:title="@string/external_code_size_label"
- android:selectable="false"
- android:layout="@layout/horizontal_preference" />
-
- <Preference
android:key="data_size"
android:title="@string/data_size_label"
android:selectable="false"
android:layout="@layout/horizontal_preference" />
- <Preference
- android:key="external_data_size"
- android:title="@string/external_data_size_label"
- android:selectable="false"
- android:layout="@layout/horizontal_preference" />
-
<com.android.settings.applications.LayoutPreference
android:key="clear_data_button"
android:selectable="false"
diff --git a/res/xml/assist_gesture_settings.xml b/res/xml/assist_gesture_settings.xml
index c0a3810..52ee247 100644
--- a/res/xml/assist_gesture_settings.xml
+++ b/res/xml/assist_gesture_settings.xml
@@ -29,4 +29,10 @@
android:title="@string/assist_gesture_title"
android:summary="@string/assist_gesture_summary" />
+ <com.android.settings.SeekBarPreference
+ android:key="gesture_assist_sensitivity"
+ android:title="@string/assist_gesture_sensitivity_title"
+ android:defaultValue="2"
+ android:max="4" />
+
</PreferenceScreen>
diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index 34d48f1..7859119 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -44,7 +44,7 @@
/>
<Preference
- android:fragment="com.android.settings.ZonePicker"
+ android:fragment="com.android.settings.datetime.ZonePicker"
android:key="timezone"
android:title="@string/date_time_set_timezone"
android:summary="GMT-8:00"
diff --git a/res/xml/device_info_status.xml b/res/xml/device_info_status.xml
index 1b173f1..9a57af9 100644
--- a/res/xml/device_info_status.xml
+++ b/res/xml/device_info_status.xml
@@ -14,64 +14,76 @@
limitations under the License.
-->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/device_status_activity_title">
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/device_status_activity_title">
- <com.android.settings.CopyablePreference android:key="battery_status"
+ <Preference
+ android:key="battery_status"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/battery_status_title"
- android:summary="@string/device_info_not_available"
- android:persistent="false" />
- <com.android.settings.CopyablePreference android:key="battery_level"
+ android:summary="@string/device_info_not_available" />
+ <Preference
+ android:key="battery_level"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/battery_level_title"
android:summary="@string/device_info_not_available"
android:persistent="false" />
- <Preference android:key="sim_status"
+ <Preference
+ android:key="sim_status"
android:title="@string/sim_status_title"
android:persistent="false">
- <intent android:targetPackage="com.android.settings"
+ <intent
+ android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.Settings$SimStatusActivity" />
</Preference>
- <Preference android:key="imei_info"
+ <Preference
+ android:key="imei_info"
android:title="@string/imei_information_title"
android:persistent="false">
- <intent android:targetPackage="com.android.settings"
+ <intent
+ android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.Settings$ImeiInformationActivity" />
</Preference>
- <com.android.settings.CopyablePreference android:key="wifi_ip_address"
+ <Preference
+ android:key="wifi_ip_address"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/wifi_advanced_ip_address_title"
android:summary="@string/device_info_not_available"
android:persistent="false" />
- <com.android.settings.CopyablePreference android:key="wifi_mac_address"
+ <Preference
+ android:key="wifi_mac_address"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/status_wifi_mac_address"
android:summary="@string/device_info_not_available"
android:persistent="false" />
- <com.android.settings.CopyablePreference android:key="bt_address"
+ <Preference
+ android:key="bt_address"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/status_bt_address"
android:summary="@string/device_info_not_available"
android:persistent="false" />
- <com.android.settings.CopyablePreference android:key="serial_number"
+ <Preference
+ android:key="serial_number"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/status_serial_number"
android:summary="@string/device_info_not_available"
android:persistent="false" />
- <com.android.settings.CopyablePreference android:key="up_time"
+ <Preference
+ android:key="up_time"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/status_up_time"
android:summary="@string/device_info_not_available"
android:persistent="false" />
- <com.android.settings.CopyablePreference android:key="wimax_mac_address"
+ <Preference
+ android:key="wimax_mac_address"
android:enabled="false"
android:shouldDisableView="false"
android:title="@string/status_wimax_mac_address"
diff --git a/res/xml/enterprise_privacy_settings.xml b/res/xml/enterprise_privacy_settings.xml
index bfb1247..f08b9f2 100644
--- a/res/xml/enterprise_privacy_settings.xml
+++ b/res/xml/enterprise_privacy_settings.xml
@@ -19,79 +19,75 @@
android:key="enterprise_privacy_settings"
android:title="@string/enterprise_privacy_settings_title">
- <!-- Header -->
- <Preference android:key="enterprise_privacy_header"
- android:summary="@string/enterprise_privacy_header"
- android:selectable="false"/>
-
<PreferenceCategory android:title="@string/enterprise_privacy_exposure_category">
<com.android.settings.DividerPreference
android:key="enterprise_data"
android:layout_height="wrap_content"
android:title="@string/enterprise_privacy_enterprise_data"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
- android:key="number_installed_packages"
- android:title="@string/enterprise_privacy_number_installed_packages_default"
- settings:allowDividerBelow="true"
+ android:key="installed_packages"
+ android:title="@string/enterprise_privacy_installed_packages"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="usage_stats"
android:title="@string/enterprise_privacy_usage_stats"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="network_logs"
android:title="@string/enterprise_privacy_network_logs"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="bug_reports"
android:title="@string/enterprise_privacy_bug_reports"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="security_logs"
android:title="@string/enterprise_privacy_security_logs"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/enterprise_privacy_exposure_changes_category">
<com.android.settings.DividerPreference
android:key="number_enterprise_installed_packages"
- settings:allowDividerBelow="true"
+ android:title="@string/enterprise_privacy_enterprise_installed_packages"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="enterprise_privacy_number_location_access_packages"
- settings:allowDividerBelow="true"
+ android:title="@string/enterprise_privacy_location_access"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="enterprise_privacy_number_microphone_access_packages"
- settings:allowDividerBelow="true"
+ android:title="@string/enterprise_privacy_microphone_access"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="enterprise_privacy_number_camera_access_packages"
- settings:allowDividerBelow="true"
+ android:title="@string/enterprise_privacy_camera_access"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="number_enterprise_set_default_apps"
- settings:allowDividerBelow="true"
+ android:title="@string/enterprise_privacy_enterprise_set_default_apps"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="always_on_vpn_primary_user"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="always_on_vpn_managed_profile"
android:title="@string/enterprise_privacy_always_on_vpn_work"
- settings:allowDividerBelow="true"
+ settings:multiLine="true"/>
+ <com.android.settings.DividerPreference
+ android:key="input_method"
+ android:title="@string/enterprise_privacy_input_method"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="global_http_proxy"
android:title="@string/enterprise_privacy_global_http_proxy"
- settings:allowDividerBelow="true"
+ settings:multiLine="true"/>
+ <com.android.settings.DividerPreference
+ android:key="ca_certs_current_user"
+ settings:multiLine="true"/>
+ <com.android.settings.DividerPreference
+ android:key="ca_certs_managed_profile"
settings:multiLine="true"/>
</PreferenceCategory>
@@ -99,20 +95,20 @@
<com.android.settings.DividerPreference
android:key="lock_device"
android:title="@string/enterprise_privacy_lock_device"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="wipe_device"
android:title="@string/enterprise_privacy_wipe_device"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="failed_password_wipe_primary_user"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
<com.android.settings.DividerPreference
android:key="failed_password_wipe_managed_profile"
- settings:allowDividerBelow="true"
settings:multiLine="true"/>
</PreferenceCategory>
+
+ <com.android.settings.widget.FooterPreference
+ android:title="@string/enterprise_privacy_footer"
+ android:selectable="false"/>
</PreferenceScreen>
diff --git a/res/xml/ia_sound_settings.xml b/res/xml/ia_sound_settings.xml
index 27fcdda..a34d875 100644
--- a/res/xml/ia_sound_settings.xml
+++ b/res/xml/ia_sound_settings.xml
@@ -151,4 +151,41 @@
android:targetClass="com.android.cellbroadcastreceiver.CellBroadcastSettings" />
</com.android.settingslib.RestrictedPreference>
+ <com.android.settings.WorkOnlyCategory
+ android:key="sound_work_settings_section"
+ android:title="@string/sound_work_settings">
+
+ <!-- Use the same sounds of the work profile -->
+ <SwitchPreference
+ android:key="work_use_personal_sounds"
+ android:title="@string/work_use_personal_sounds_title"
+ android:summary="@string/work_use_personal_sounds_summary"
+ android:disableDependentsState="true" />
+
+ <!-- Work phone ringtone -->
+ <com.android.settings.DefaultRingtonePreference
+ android:key="work_ringtone"
+ android:title="@string/work_ringtone_title"
+ android:dialogTitle="@string/work_alarm_ringtone_title"
+ android:ringtoneType="ringtone"
+ android:dependency="work_use_personal_sounds" />
+
+ <!-- Default work notification ringtone -->
+ <com.android.settings.DefaultRingtonePreference
+ android:key="work_notification_ringtone"
+ android:title="@string/work_notification_ringtone_title"
+ android:dialogTitle="@string/work_alarm_ringtone_title"
+ android:ringtoneType="notification"
+ android:dependency="work_use_personal_sounds" />
+
+ <!-- Default work alarm ringtone -->
+ <com.android.settings.DefaultRingtonePreference
+ android:key="work_alarm_ringtone"
+ android:title="@string/work_alarm_ringtone_title"
+ android:dialogTitle="@string/work_alarm_ringtone_title"
+ android:persistent="false"
+ android:ringtoneType="alarm"
+ android:dependency="work_use_personal_sounds" />
+
+ </com.android.settings.WorkOnlyCategory>
</PreferenceScreen>
diff --git a/res/xml/installed_app_details.xml b/res/xml/installed_app_details.xml
deleted file mode 100644
index 7ebdaf7..0000000
--- a/res/xml/installed_app_details.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/application_info_label">
- <com.android.settings.applications.LayoutPreference
- android:key="header_view"
- android:layout="@layout/installed_app_details"
- android:selectable="false" />
-
- <Preference
- android:key="storage_settings"
- android:title="@string/storage_settings"
- android:selectable="true" />
-
- <Preference
- android:key="data_settings"
- android:title="@string/data_usage_summary_title"
- android:selectable="true" />
-
- <Preference
- android:key="permission_settings"
- android:title="@string/permissions_label"
- android:selectable="true" />
-
- <Preference
- android:key="notification_settings"
- android:title="@string/notifications_label"
- android:selectable="true" />
-
- <Preference
- android:key="preferred_settings"
- android:title="@string/launch_by_default"
- android:selectable="true" />
-
- <Preference
- android:key="battery"
- android:title="@string/power_usage_summary_title"
- android:selectable="true" />
-
- <Preference
- android:key="memory"
- android:title="@string/memory_settings_title"
- android:enabled="false"
- android:selectable="true" />
-
-</PreferenceScreen>
diff --git a/res/xml/installed_app_details_ia.xml b/res/xml/installed_app_details_ia.xml
index 5b9bdc7..3e06e39 100644
--- a/res/xml/installed_app_details_ia.xml
+++ b/res/xml/installed_app_details_ia.xml
@@ -23,6 +23,12 @@
android:selectable="false"
android:order="-10000"/>
+ <com.android.settings.applications.LayoutPreference
+ android:key="action_buttons"
+ android:layout="@layout/app_action_buttons"
+ android:selectable="false"
+ android:order="-9999"/>
+
<Preference
android:key="notification_settings"
android:title="@string/notifications_label"
diff --git a/res/xml/installed_app_launch_settings.xml b/res/xml/installed_app_launch_settings.xml
index 7342cc0..ac77be1 100644
--- a/res/xml/installed_app_launch_settings.xml
+++ b/res/xml/installed_app_launch_settings.xml
@@ -37,8 +37,7 @@
android:title="@string/app_launch_other_defaults_title">
<com.android.settings.applications.ClearDefaultsPreference
- android:key="app_launch_clear_defaults"
- />
+ android:key="app_launch_clear_defaults" />
</PreferenceCategory>
diff --git a/res/drawable/ic_dashboard_network.xml b/res/xml/network_scorer_picker_prefs.xml
similarity index 62%
rename from res/drawable/ic_dashboard_network.xml
rename to res/xml/network_scorer_picker_prefs.xml
index 6c7ee2e..fab69e7 100644
--- a/res/drawable/ic_dashboard_network.xml
+++ b/res/xml/network_scorer_picker_prefs.xml
@@ -15,12 +15,7 @@
limitations under the License.
-->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24.0dp"
- android:height="24.0dp"
- android:viewportWidth="18.0"
- android:viewportHeight="18.0">
- <path
- android:fillColor="#0b9c57"
- android:pathData="M9.01,15.99l8.8,-10.96C17.47,4.77 14.08,2.0 9.0,2.0S0.53,4.7 0.19,5.03l8.8,10.96l0.02,0.0z"/>
-</vector>
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/network_scorer_picker_title">
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/power_usage_details.xml b/res/xml/power_usage_details.xml
index 724aae8..86aa4f5 100644
--- a/res/xml/power_usage_details.xml
+++ b/res/xml/power_usage_details.xml
@@ -26,6 +26,11 @@
android:key="controls_parent"
android:title="@string/controls_subtitle">
+ <SwitchPreference
+ android:key="background_activity"
+ android:title="@string/background_activity_title"
+ android:summary="@string/background_activity_summary"/>
+
<Preference
android:key="high_power"
android:title="@string/high_power_apps" />
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index 544769d..155f21a 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -26,8 +26,10 @@
<intent android:action="android.settings.LOCATION_SOURCE_SETTINGS"/>
</Preference>
- <SwitchPreference android:key="show_password"
- android:title="@string/show_password"/>
+ <SwitchPreference
+ android:key="show_password"
+ android:title="@string/show_password"
+ android:summary="@string/show_password_summary"/>
</PreferenceCategory>
@@ -41,6 +43,12 @@
android:persistent="false"
android:fragment="com.android.settings.DeviceAdminSettings"/>
+ <Preference android:key="enterprise_privacy"
+ android:title="@string/enterprise_privacy_settings"
+ android:summary="@string/enterprise_privacy_settings_summary"
+ android:persistent="false"
+ android:fragment="com.android.settings.enterprise.EnterprisePrivacySettings"/>
+
</PreferenceCategory>
<Preference android:key="sim_lock_settings"
diff --git a/res/xml/sound_work_settings.xml b/res/xml/sound_work_settings.xml
deleted file mode 100644
index b63ec75..0000000
--- a/res/xml/sound_work_settings.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
- android:title="@string/sound_work_settings"
- android:key="sound_work_settings">
-
- <PreferenceCategory
- android:key="sound_work_settings_section"
- android:title="@string/sound_work_settings">
-
- <!-- Use the same sounds of the work profile -->
- <SwitchPreference
- android:key="work_use_personal_sounds"
- android:title="@string/work_use_personal_sounds_title"
- android:summary="@string/work_use_personal_sounds_summary"
- android:disableDependentsState="true" />
-
- <!-- Work phone ringtone -->
- <com.android.settings.DefaultRingtonePreference
- android:key="work_ringtone"
- android:title="@string/work_ringtone_title"
- android:dialogTitle="@string/work_alarm_ringtone_title"
- android:ringtoneType="ringtone"
- android:dependency="work_use_personal_sounds" />
-
- <!-- Default work notification ringtone -->
- <com.android.settings.DefaultRingtonePreference
- android:key="work_notification_ringtone"
- android:title="@string/work_notification_ringtone_title"
- android:dialogTitle="@string/work_alarm_ringtone_title"
- android:ringtoneType="notification"
- android:dependency="work_use_personal_sounds" />
-
- <!-- Default work alarm ringtone -->
- <com.android.settings.DefaultRingtonePreference
- android:key="work_alarm_ringtone"
- android:title="@string/work_alarm_ringtone_title"
- android:dialogTitle="@string/work_alarm_ringtone_title"
- android:persistent="false"
- android:ringtoneType="alarm"
- android:dependency="work_use_personal_sounds" />
-
- </PreferenceCategory>
-
-</PreferenceScreen>
diff --git a/res/xml/storage_dashboard_fragment.xml b/res/xml/storage_dashboard_fragment.xml
index fedc77f..78ccbbf 100644
--- a/res/xml/storage_dashboard_fragment.xml
+++ b/res/xml/storage_dashboard_fragment.xml
@@ -21,45 +21,38 @@
<com.android.settings.deviceinfo.storage.StorageSummaryDonutPreference
android:key="pref_summary"
android:order="0" />
+ <com.android.settings.widget.MasterSwitchPreference
+ android:fragment="com.android.settings.deletionhelper.AutomaticStorageManagerSettings"
+ android:key="toggle_asm"
+ android:title="@string/automatic_storage_manager_preference_title"
+ android:icon="@drawable/ic_settings_storage"
+ android:order="1" />
<com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
android:key="pref_photos_videos"
android:title="@string/storage_photos_videos"
- android:order="1" >
- </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
+ android:order="2" />
<com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
android:key="pref_music_audio"
android:title="@string/storage_music_audio"
- android:order="2" >
- </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
+ android:order="3" />
<com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
android:key="pref_games"
android:title="@string/storage_games"
- android:order="3" >
- </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
+ android:order="4" />
<com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
android:key="pref_other_apps"
android:title="@string/storage_other_apps"
- android:order="4" >
- </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
+ android:order="5" />
<com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
android:key="pref_files"
android:title="@string/storage_files"
- android:order="5" >
- </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
+ android:order="6" />
<com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate
android:key="pref_system"
android:title="@string/storage_detail_system"
- android:order="100" >
- </com.android.settings.deviceinfo.storage.StorageItemPreferenceAlternate>
+ android:order="100" />
<PreferenceCategory
android:key="pref_secondary_users"
android:title="@string/storage_other_users"
android:order="200" />
- <Preference
- android:key="manage_storage"
- android:title="@string/storage_menu_manage"
- android:icon="@drawable/ic_settings_storage"
- android:fragment="com.android.settings.deletionhelper.AutomaticStorageManagerSettings"
- android:order="300" >
- </Preference>
</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/user_and_accounts_settings.xml b/res/xml/user_and_accounts_settings.xml
index bc3ac6c..6280980 100644
--- a/res/xml/user_and_accounts_settings.xml
+++ b/res/xml/user_and_accounts_settings.xml
@@ -23,7 +23,8 @@
<Preference
android:key="emergency_info"
android:title="@string/emergency_info_title"
- android:order="100"/>
+ android:order="100"
+ settings:allowDividerAbove="true"/>
<PreferenceCategory
android:key="account_configuration_header"
diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml
index bf1dc75..8e51009 100644
--- a/res/xml/wifi_configure_settings.xml
+++ b/res/xml/wifi_configure_settings.xml
@@ -59,6 +59,11 @@
settings:keywords="@string/keywords_wifi_calling"/>
<Preference
+ android:key="network_scorer_picker"
+ android:title="@string/network_scorer_picker_title"
+ android:fragment="com.android.settings.network.NetworkScorerPicker"/>
+
+ <Preference
android:key="wifi_direct"
android:title="@string/wifi_menu_p2p">
<intent android:targetPackage="com.android.settings"
diff --git a/src/com/android/settings/AppHeader.java b/src/com/android/settings/AppHeader.java
index f5700b5..45902d8 100644
--- a/src/com/android/settings/AppHeader.java
+++ b/src/com/android/settings/AppHeader.java
@@ -16,21 +16,9 @@
package com.android.settings;
-import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
-import android.content.res.ColorStateList;
-import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.applications.AppInfoBase;
-import com.android.settings.applications.InstalledAppDetails;
public class AppHeader {
@@ -38,77 +26,6 @@
// constant value that can be used to check return code from sub activity.
private static final int INSTALLED_APP_DETAILS = 1;
- public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
- CharSequence label, String pkgName, int uid) {
- createAppHeader(fragment, icon, label, pkgName, uid, 0, null);
- }
-
- public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
- CharSequence label, String pkgName, int uid, Intent externalSettings) {
- createAppHeader(fragment, icon, label, pkgName, uid, 0, externalSettings);
- }
-
- public static void createAppHeader(Activity activity, Drawable icon, CharSequence label,
- String pkgName, int uid, ViewGroup pinnedHeader) {
- final View bar = activity.getLayoutInflater().inflate(R.layout.app_header,
- pinnedHeader, false);
- setupHeaderView(activity, icon, label, pkgName, uid, false, 0, bar, null);
- pinnedHeader.addView(bar);
- }
-
- public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
- CharSequence label, String pkgName, int uid, int tintColorRes) {
- createAppHeader(fragment, icon, label, pkgName, uid, tintColorRes, null);
- }
-
- public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
- CharSequence label, String pkgName, int uid, int tintColorRes,
- Intent externalSettings) {
- View bar = fragment.setPinnedHeaderView(R.layout.app_header);
- setupHeaderView(fragment.getActivity(), icon, label, pkgName, uid, includeAppInfo(fragment),
- tintColorRes, bar, externalSettings);
- }
-
- public static View setupHeaderView(final Activity activity, Drawable icon, CharSequence label,
- final String pkgName, final int uid, final boolean includeAppInfo, int tintColorRes,
- View bar, final Intent externalSettings) {
- final ImageView appIcon = (ImageView) bar.findViewById(R.id.app_icon);
- appIcon.setImageDrawable(icon);
- if (tintColorRes != 0) {
- appIcon.setImageTintList(ColorStateList.valueOf(activity.getColor(tintColorRes)));
- }
-
- final TextView appName = (TextView) bar.findViewById(R.id.app_name);
- appName.setText(label);
-
- if (pkgName != null && !pkgName.equals(Utils.OS_PKG)) {
- bar.setClickable(true);
- bar.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (includeAppInfo) {
- AppInfoBase.startAppInfoFragment(InstalledAppDetails.class,
- R.string.application_info_label, pkgName, uid, activity,
- INSTALLED_APP_DETAILS, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
- } else {
- activity.finish();
- }
- }
- });
- if (externalSettings != null) {
- final View appSettings = bar.findViewById(R.id.app_settings);
- appSettings.setVisibility(View.VISIBLE);
- appSettings.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- activity.startActivity(externalSettings);
- }
- });
- }
- }
- return bar;
- }
-
public static boolean includeAppInfo(final Fragment fragment) {
Bundle args = fragment.getArguments();
boolean showInfo = true;
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index 017a348..3e9304d 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -166,16 +166,6 @@
ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
- if (mIsSetNewPassword) {
- // In ACTION_SET_NEW_PARENT_PROFILE_PASSWORD or ACTION_SET_NEW_PASSWORD, the user
- // will be asked to confirm the password if one has been set.
- // On fingerprint supported device, fingerprint options are represented in the
- // options. If the user chooses to skip fingerprint setup, ChooseLockGeneric is
- // relaunched to only show options without fingerprint. In this case, we shouldn't
- // ask the user to confirm the password again.
- mPasswordConfirmed = getActivity().getIntent().getBooleanExtra(
- PASSWORD_CONFIRMED, false);
- }
if (savedInstanceState != null) {
mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED);
@@ -246,11 +236,12 @@
showFactoryResetProtectionWarningDialog(key);
return true;
} else if (KEY_SKIP_FINGERPRINT.equals(key)) {
- Intent chooseLockGenericIntent = new Intent(getActivity(), ChooseLockGeneric.class);
+ Intent chooseLockGenericIntent = new Intent(getActivity(),
+ ChooseLockGeneric.InternalActivity.class);
chooseLockGenericIntent.setAction(getIntent().getAction());
// Forward the target user id to ChooseLockGeneric.
chooseLockGenericIntent.putExtra(Intent.EXTRA_USER_ID, mUserId);
- chooseLockGenericIntent.putExtra(PASSWORD_CONFIRMED, mPasswordConfirmed);
+ chooseLockGenericIntent.putExtra(CONFIRM_CREDENTIALS, !mPasswordConfirmed);
startActivityForResult(chooseLockGenericIntent, SKIP_FINGERPRINT_REQUEST);
return true;
} else {
diff --git a/src/com/android/settings/CopyablePreference.java b/src/com/android/settings/CopyablePreference.java
deleted file mode 100644
index 03147c2..0000000
--- a/src/com/android/settings/CopyablePreference.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings;
-
-import android.content.ClipboardManager;
-import android.content.Context;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceViewHolder;
-import android.util.AttributeSet;
-import android.view.View;
-import android.view.View.OnLongClickListener;
-import android.widget.Toast;
-
-public class CopyablePreference extends Preference {
-
- public CopyablePreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public CopyablePreference(Context context) {
- this(context, null);
- }
-
- @Override
- public void onBindViewHolder(PreferenceViewHolder holder) {
- super.onBindViewHolder(holder);
- holder.setDividerAllowedAbove(true);
- holder.setDividerAllowedBelow(true);
- holder.itemView.setLongClickable(true);
- holder.itemView.setOnLongClickListener(new OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- copyPreference(getContext(), CopyablePreference.this);
- return true;
- }
- });
- }
-
- public CharSequence getCopyableText() {
- return getSummary();
- }
-
- public static void copyPreference(Context context, CopyablePreference pref) {
- ClipboardManager cm =
- (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
- cm.setText(pref.getCopyableText());
- Toast.makeText(context, com.android.internal.R.string.text_copied, Toast.LENGTH_SHORT)
- .show();
- }
-}
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index 89ba999..e9d3f86 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -128,7 +128,7 @@
controllers.add(new BasebandVersionPreferenceController(context));
controllers.add(new FirmwareVersionPreferenceController(context, lifecycle));
controllers.add(new RegulatoryInfoPreferenceController(context));
- controllers.add(new DeviceModelPreferenceController(context));
+ controllers.add(new DeviceModelPreferenceController(context, fragment));
controllers.add(new SecurityPatchPreferenceController(context));
controllers.add(new FccEquipmentIdPreferenceController(context));
controllers.add(new SELinuxStatusPreferenceController(context));
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 7417516..fb590cc 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -359,37 +359,33 @@
PreferenceGroup securityStatusPreferenceGroup =
(PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
- if (mDashboardFeatureProvider.isEnabled()) {
- final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
- getActivity(), getPrefContext(), getMetricsCategory(),
- CategoryKey.CATEGORY_SECURITY);
- int numSecurityStatusPrefs = 0;
- if (tilePrefs != null && !tilePrefs.isEmpty()) {
- for (Preference preference : tilePrefs) {
- if (!TextUtils.isEmpty(preference.getKey())
- && preference.getKey().startsWith(SECURITY_STATUS_KEY_PREFIX)) {
- // Injected security status settings are placed under the Security status
- // category.
- securityStatusPreferenceGroup.addPreference(preference);
- numSecurityStatusPrefs++;
- } else {
- // Other injected settings are placed under the Security preference screen.
- root.addPreference(preference);
- }
+ final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
+ getActivity(), getPrefContext(), getMetricsCategory(),
+ CategoryKey.CATEGORY_SECURITY);
+ int numSecurityStatusPrefs = 0;
+ if (tilePrefs != null && !tilePrefs.isEmpty()) {
+ for (Preference preference : tilePrefs) {
+ if (!TextUtils.isEmpty(preference.getKey())
+ && preference.getKey().startsWith(SECURITY_STATUS_KEY_PREFIX)) {
+ // Injected security status settings are placed under the Security status
+ // category.
+ securityStatusPreferenceGroup.addPreference(preference);
+ numSecurityStatusPrefs++;
+ } else {
+ // Other injected settings are placed under the Security preference screen.
+ root.addPreference(preference);
}
}
+ }
- if (numSecurityStatusPrefs == 0) {
- root.removePreference(securityStatusPreferenceGroup);
- } else if (numSecurityStatusPrefs > 0) {
- // Update preference data with tile data. Security feature provider only updates the
- // data if it actually needs to be changed.
- mSecurityFeatureProvider.updatePreferences(getActivity(), root,
- mDashboardFeatureProvider.getTilesForCategory(
- CategoryKey.CATEGORY_SECURITY));
- }
- } else {
- root.removePreference(root.findPreference(KEY_SECURITY_STATUS));
+ if (numSecurityStatusPrefs == 0) {
+ root.removePreference(securityStatusPreferenceGroup);
+ } else if (numSecurityStatusPrefs > 0) {
+ // Update preference data with tile data. Security feature provider only updates the
+ // data if it actually needs to be changed.
+ mSecurityFeatureProvider.updatePreferences(getActivity(), root,
+ mDashboardFeatureProvider.getTilesForCategory(
+ CategoryKey.CATEGORY_SECURITY));
}
for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
@@ -525,6 +521,14 @@
return result;
}
+ private static CharSequence getActiveTrustAgentLabel(Context context,
+ TrustAgentManager trustAgentManager, LockPatternUtils utils,
+ DevicePolicyManager dpm) {
+ ArrayList<TrustAgentComponentInfo> agents = getActiveTrustAgents(context,
+ trustAgentManager, utils, dpm);
+ return agents.isEmpty() ? null : agents.get(0).title;
+ }
+
@Override
public void onGearClick(GearPreference p) {
if (KEY_UNLOCK_SET_OR_CHANGE.equals(p.getKey())) {
@@ -912,6 +916,7 @@
private SwitchPreference mPowerButtonInstantlyLocks;
private RestrictedPreference mOwnerInfoPref;
+ private TrustAgentManager mTrustAgentManager;
private LockPatternUtils mLockPatternUtils;
private DevicePolicyManager mDPM;
@@ -923,6 +928,9 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ SecurityFeatureProvider securityFeatureProvider =
+ FeatureFactory.getFactory(getActivity()).getSecurityFeatureProvider();
+ mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
mLockPatternUtils = new LockPatternUtils(getContext());
mDPM = getContext().getSystemService(DevicePolicyManager.class);
createPreferenceHierarchy();
@@ -977,13 +985,12 @@
// lock instantly on power key press
mPowerButtonInstantlyLocks = (SwitchPreference) findPreference(
KEY_POWER_INSTANTLY_LOCKS);
- Preference trustAgentPreference = findPreference(KEY_TRUST_AGENT);
- if (mPowerButtonInstantlyLocks != null &&
- trustAgentPreference != null &&
- trustAgentPreference.getTitle().length() > 0) {
+ CharSequence trustAgentLabel = getActiveTrustAgentLabel(getContext(),
+ mTrustAgentManager, mLockPatternUtils, mDPM);
+ if (mPowerButtonInstantlyLocks != null && !TextUtils.isEmpty(trustAgentLabel)) {
mPowerButtonInstantlyLocks.setSummary(getString(
R.string.lockpattern_settings_power_button_instantly_locks_summary,
- trustAgentPreference.getTitle()));
+ trustAgentLabel));
}
mOwnerInfoPref = (RestrictedPreference) findPreference(KEY_OWNER_INFO_SETTINGS);
@@ -1052,14 +1059,15 @@
}
}
- Preference preference = findPreference(KEY_TRUST_AGENT);
- if (preference != null && preference.getTitle().length() > 0) {
+ CharSequence trustAgentLabel = getActiveTrustAgentLabel(getContext(),
+ mTrustAgentManager, mLockPatternUtils, mDPM);
+ if (!TextUtils.isEmpty(trustAgentLabel)) {
if (Long.valueOf(values[best].toString()) == 0) {
summary = getString(R.string.lock_immediately_summary_with_exception,
- preference.getTitle());
+ trustAgentLabel);
} else {
summary = getString(R.string.lock_after_timeout_summary_with_exception,
- entries[best], preference.getTitle());
+ entries[best], trustAgentLabel);
}
} else {
summary = getString(R.string.lock_after_timeout_summary, entries[best]);
@@ -1202,8 +1210,7 @@
Settings.Secure.PACKAGE_VERIFIER_STATE, 0);
DashboardFeatureProvider dashboardFeatureProvider =
FeatureFactory.getFactory(mContext).getDashboardFeatureProvider(mContext);
- if (dashboardFeatureProvider.isEnabled()
- && (packageVerifierState == PACKAGE_VERIFIER_STATE_ENABLED)) {
+ if (packageVerifierState == PACKAGE_VERIFIER_STATE_ENABLED) {
// Calling the feature provider could potentially be slow, so do this on a separate
// thread so as to not block the loading of Settings.
Executors.newSingleThreadExecutor().execute(new Runnable() {
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index a96fb1e..f2d6452 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -33,7 +33,6 @@
public static class TetherSettingsActivity extends SettingsActivity { /* empty */ }
public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
public static class DateTimeSettingsActivity extends SettingsActivity { /* empty */ }
- public static class StorageSettingsActivity extends SettingsActivity { /* empty */ }
public static class PrivateVolumeForgetActivity extends SettingsActivity { /* empty */ }
public static class PrivateVolumeSettingsActivity extends SettingsActivity { /* empty */ }
public static class PublicVolumeSettingsActivity extends SettingsActivity { /* empty */ }
@@ -132,6 +131,7 @@
public static class ManageExternalSourcesActivity extends SettingsActivity {
/* empty */ }
+ public static class ManageAppExternalSourcesActivity extends SettingsActivity { /* empty */ }
public static class WifiCallingSuggestionActivity extends SettingsActivity { /* empty */ }
public static class ZenModeAutomationSuggestionActivity extends SettingsActivity { /* empty */ }
@@ -156,12 +156,6 @@
public static class EnterprisePrivacySettingsActivity extends SettingsActivity { /* empty */ }
public static class WebViewAppPickerActivity extends SettingsActivity { /* empty */ }
- // Categories.
- public static class WirelessSettings extends SettingsActivity { /* empty */ }
- public static class DeviceSettings extends SettingsActivity { /* empty */ }
- public static class PersonalSettings extends SettingsActivity { /* empty */ }
- public static class SystemSettings extends SettingsActivity { /* empty */ }
-
// Top level categories for new IA
public static class NetworkDashboardActivity extends SettingsActivity {}
public static class ConnectedDeviceDashboardActivity extends SettingsActivity {}
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index d5e886f..7a4d5f8 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -32,7 +32,6 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.nfc.NfcAdapter;
@@ -68,6 +67,7 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DynamicIndexableContentMonitor;
import com.android.settings.search2.SearchFeatureProvider;
+import com.android.settings.wfd.WifiDisplaySettings;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.SettingsDrawerActivity;
@@ -383,11 +383,7 @@
final ComponentName cn = intent.getComponent();
final String className = cn.getClassName();
- mIsShowingDashboard = className.equals(Settings.class.getName())
- || className.equals(Settings.WirelessSettings.class.getName())
- || className.equals(Settings.DeviceSettings.class.getName())
- || className.equals(Settings.PersonalSettings.class.getName())
- || className.equals(Settings.WirelessSettings.class.getName());
+ mIsShowingDashboard = className.equals(Settings.class.getName());
// This is a "Sub Settings" when:
// - this is a real SubSettings
@@ -665,6 +661,9 @@
@Override
protected void onPause() {
super.onPause();
+ mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
+ mDevelopmentPreferencesListener);
+ mDevelopmentPreferencesListener = null;
unregisterReceiver(mBatteryInfoReceiver);
if (!mSearchFeatureProvider.isEnabled(this)) {
unregisterReceiver(mUserAddRemoveReceiver);
@@ -675,15 +674,6 @@
}
@Override
- public void onDestroy() {
- super.onDestroy();
-
- mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
- mDevelopmentPreferencesListener);
- mDevelopmentPreferencesListener = null;
- }
-
- @Override
public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings);
taskDescription.setIcon(icon);
@@ -899,32 +889,32 @@
pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.BluetoothSettingsActivity.class.getName()),
+ Settings.BluetoothSettingsActivity.class.getName()),
pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.DataUsageSummaryActivity.class.getName()),
+ Settings.DataUsageSummaryActivity.class.getName()),
Utils.isBandwidthControlEnabled(), isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.SimSettingsActivity.class.getName()),
+ Settings.SimSettingsActivity.class.getName()),
Utils.showSimCardTile(this), isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.PowerUsageSummaryActivity.class.getName()),
+ Settings.PowerUsageSummaryActivity.class.getName()),
mBatteryPresent, isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.UserSettingsActivity.class.getName()),
+ Settings.UserSettingsActivity.class.getName()),
UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
- && !Utils.isMonkeyRunning(), isAdmin);
+ && !Utils.isMonkeyRunning(), isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.NetworkDashboardActivity.class.getName()),
+ Settings.NetworkDashboardActivity.class.getName()),
!UserManager.isDeviceInDemoMode(this), isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.ConnectedDeviceDashboardActivity.class.getName()),
+ Settings.ConnectedDeviceDashboardActivity.class.getName()),
!UserManager.isDeviceInDemoMode(this), isAdmin);
setTileEnabled(new ComponentName(packageName,
@@ -936,49 +926,52 @@
pm.hasSystemFeature(PackageManager.FEATURE_NFC)
&& pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
&& adapter != null && adapter.isEnabled(), isAdmin);
- setTileEnabled(new ComponentName(packageName,
- "com.android.settings.PaymentSettingsDashboardAlias"),
- pm.hasSystemFeature(PackageManager.FEATURE_NFC)
- && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
- && adapter != null && adapter.isEnabled(), isAdmin);
setTileEnabled(new ComponentName(packageName,
- Settings.PrintSettingsActivity.class.getName()),
+ Settings.PrintSettingsActivity.class.getName()),
pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
final boolean showDev = mDevelopmentPreferences.getBoolean(
- DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
+ DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
&& !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
setTileEnabled(new ComponentName(packageName,
Settings.DevelopmentSettingsActivity.class.getName()),
showDev, isAdmin);
+ // Enable/disable backup settings depending on whether the user is admin.
+ setTileEnabled(new ComponentName(packageName,
+ BackupSettingsActivity.class.getName()), true,
+ isAdmin || Utils.isCarrierDemoUser(this));
+
+ setTileEnabled(new ComponentName(packageName,
+ Settings.EnterprisePrivacySettingsActivity.class.getName()),
+ FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
+ .hasDeviceOwner(), isAdmin);
+
+ setTileEnabled(new ComponentName(packageName,
+ Settings.WifiDisplaySettingsActivity.class.getName()),
+ WifiDisplaySettings.isAvailable(this), isAdmin);
+
if (UserHandle.MU_ENABLED && !isAdmin) {
+
// When on restricted users, disable all extra categories (but only the settings ones).
final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
-
- for (DashboardCategory category : categories) {
- for (Tile tile : category.tiles) {
- ComponentName component = tile.intent.getComponent();
- final String name = component.getClassName();
- final boolean isEnabledForRestricted = ArrayUtils.contains(
- SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
- if (packageName.equals(component.getPackageName()) && !isEnabledForRestricted) {
- setTileEnabled(component, false, isAdmin);
+ synchronized (categories) {
+ for (DashboardCategory category : categories) {
+ for (Tile tile : category.tiles) {
+ ComponentName component = tile.intent.getComponent();
+ final String name = component.getClassName();
+ final boolean isEnabledForRestricted = ArrayUtils.contains(
+ SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
+ if (packageName.equals(component.getPackageName())
+ && !isEnabledForRestricted) {
+ setTileEnabled(component, false, isAdmin);
+ }
}
}
}
}
- // Enable/disable backup settings depending on whether the user is admin.
- setTileEnabled(new ComponentName(packageName,
- BackupSettingsActivity.class.getName()), true,
- isAdmin || Utils.isCarrierDemoUser(this));
-
- setTileEnabled(new ComponentName(packageName,
- Settings.EnterprisePrivacySettingsActivity.class.getName()),
- FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
- .hasDeviceOwner(), isAdmin);
// Final step, refresh categories.
updateCategories();
}
@@ -1108,10 +1101,6 @@
return mResultIntentData;
}
- public void setResultIntentData(Intent resultIntentData) {
- mResultIntentData = resultIntentData;
- }
-
public void startSuggestion(Intent intent) {
if (intent == null || ActivityManager.isUserAMonkey()) {
return;
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 350ab9c..f267640 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -302,13 +302,6 @@
return formatPercentage(getBatteryLevel(batteryChangedIntent));
}
- public static void forcePrepareCustomPreferencesList(
- ViewGroup parent, View child, ListView list, boolean ignoreSidePadding) {
- list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
- list.setClipToPadding(false);
- prepareCustomPreferencesList(parent, child, list, ignoreSidePadding);
- }
-
/**
* Prepare a custom preferences layout, moving padding to {@link ListView}
* when outside scrollbars are requested. Usually used to display
diff --git a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
index 801a20b..65959b4 100644
--- a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
@@ -76,7 +76,7 @@
}
}
mAccountSynController.init(mAccount, userHandle);
- mRemoveAccountController.setAccount(mAccount);
+ mRemoveAccountController.init(mAccount, userHandle);
}
@Override
diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java
index c54a2d1..85e09d1 100644
--- a/src/com/android/settings/accounts/AccountPreferenceController.java
+++ b/src/com/android/settings/accounts/AccountPreferenceController.java
@@ -49,9 +49,7 @@
import com.android.settings.core.lifecycle.LifecycleObserver;
import com.android.settings.core.lifecycle.events.OnPause;
import com.android.settings.core.lifecycle.events.OnResume;
-import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.search.Index;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.search2.SearchFeatureProviderImpl;
import com.android.settingslib.RestrictedPreference;
@@ -89,7 +87,6 @@
private SettingsPreferenceFragment mParent;
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
private AccountRestrictionHelper mHelper;
- private DashboardFeatureProvider mDashboardFeatureProvider;
private MetricsFeatureProvider mMetricsFeatureProvider;
/**
@@ -138,7 +135,6 @@
mAuthoritiesCount = mAuthorities.length;
}
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
- mDashboardFeatureProvider = featureFactory.getDashboardFeatureProvider(mContext);
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
mHelper = helper;
}
diff --git a/src/com/android/settings/accounts/ChooseAccountActivity.java b/src/com/android/settings/accounts/ChooseAccountActivity.java
index 6f0c110..fce88aa 100644
--- a/src/com/android/settings/accounts/ChooseAccountActivity.java
+++ b/src/com/android/settings/accounts/ChooseAccountActivity.java
@@ -216,7 +216,7 @@
}
private void addEnterpriseDisclosure() {
- final CharSequence disclosure = mFeatureProvider.getDeviceOwnerDisclosure(getActivity());
+ final CharSequence disclosure = mFeatureProvider.getDeviceOwnerDisclosure();
if (disclosure == null) {
return;
}
diff --git a/src/com/android/settings/accounts/RemoveAccountPreferenceController.java b/src/com/android/settings/accounts/RemoveAccountPreferenceController.java
index c8dbe4c..f331144 100644
--- a/src/com/android/settings/accounts/RemoveAccountPreferenceController.java
+++ b/src/com/android/settings/accounts/RemoveAccountPreferenceController.java
@@ -27,8 +27,10 @@
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
+import android.os.UserHandle;
import android.support.v7.preference.PreferenceScreen;
import android.view.View;
import android.view.View.OnClickListener;
@@ -49,6 +51,7 @@
private Account mAccount;
private Fragment mParentFragment;
+ private UserHandle mUserHandle;
public RemoveAccountPreferenceController(Context context, Fragment parent) {
super(context);
@@ -76,11 +79,12 @@
@Override
public void onClick(View v) {
- ConfirmRemoveAccountDialog.show(mParentFragment, mAccount);
+ ConfirmRemoveAccountDialog.show(mParentFragment, mAccount, mUserHandle);
}
- public void setAccount(Account account) {
+ public void init(Account account, UserHandle userHandle) {
mAccount = account;
+ mUserHandle = userHandle;
}
/**
@@ -88,27 +92,37 @@
*/
public static class ConfirmRemoveAccountDialog extends InstrumentedDialogFragment implements
DialogInterface.OnClickListener {
- private static final String SAVE_ACCOUNT = "account";
+ private static final String KEY_ACCOUNT = "account";
private static final String REMOVE_ACCOUNT_DIALOG = "confirmRemoveAccount";
private Account mAccount;
+ private UserHandle mUserHandle;
- public static ConfirmRemoveAccountDialog show(Fragment parent, Account account) {
+ public static ConfirmRemoveAccountDialog show(
+ Fragment parent, Account account, UserHandle userHandle) {
if (!parent.isAdded()) {
return null;
}
final ConfirmRemoveAccountDialog dialog = new ConfirmRemoveAccountDialog();
- dialog.mAccount = account;
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY_ACCOUNT, account);
+ bundle.putParcelable(Intent.EXTRA_USER, userHandle);
+ dialog.setArguments(bundle);
dialog.setTargetFragment(parent, 0);
dialog.show(parent.getFragmentManager(), REMOVE_ACCOUNT_DIALOG);
return dialog;
}
@Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ final Bundle arguments = getArguments();
+ mAccount = arguments.getParcelable(KEY_ACCOUNT);
+ mUserHandle = arguments.getParcelable(Intent.EXTRA_USER);
+ }
+
+ @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
- if (savedInstanceState != null) {
- mAccount = (Account) savedInstanceState.getParcelable(SAVE_ACCOUNT);
- }
return new AlertDialog.Builder(context)
.setTitle(R.string.really_remove_account_title)
.setMessage(R.string.really_remove_account_message)
@@ -118,12 +132,6 @@
}
@Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putParcelable(SAVE_ACCOUNT, mAccount);
- }
-
- @Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DIALOG_ACCOUNT_SYNC_REMOVE;
}
@@ -159,7 +167,7 @@
activity.finish();
}
}
- }, null, Process.myUserHandle());
+ }, null, mUserHandle);
}
}
diff --git a/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java b/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
index 66fd85a..1b0282f 100644
--- a/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
+++ b/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
@@ -28,7 +28,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.drawer.Tile;
@@ -121,10 +120,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.user_and_accounts_settings;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/applications/AdvancedAppSettings.java b/src/com/android/settings/applications/AdvancedAppSettings.java
index c68e19f..b8ebeb4 100644
--- a/src/com/android/settings/applications/AdvancedAppSettings.java
+++ b/src/com/android/settings/applications/AdvancedAppSettings.java
@@ -20,7 +20,7 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.applications.defaultapps.DefaultAutoFillPreferenceController;
+import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
@@ -61,7 +61,7 @@
controllers.add(new DefaultSmsPreferenceController(context));
controllers.add(new DefaultEmergencyPreferenceController(context));
controllers.add(new DefaultHomePreferenceController(context));
- controllers.add(new DefaultAutoFillPreferenceController(context));
+ controllers.add(new DefaultAutofillPreferenceController(context));
return controllers;
}
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index 5dda9c1..bdf6cc4 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -23,7 +23,6 @@
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.Arrays;
@@ -58,10 +57,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.app_and_notification;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/applications/AppInfoWithHeader.java b/src/com/android/settings/applications/AppInfoWithHeader.java
index 4f3e8fa..768a726 100644
--- a/src/com/android/settings/applications/AppInfoWithHeader.java
+++ b/src/com/android/settings/applications/AppInfoWithHeader.java
@@ -21,7 +21,6 @@
import android.support.v7.preference.Preference;
import android.util.Log;
-import com.android.settings.AppHeader;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.AppUtils;
@@ -41,24 +40,17 @@
mCreated = true;
if (mPackageInfo == null) return;
final Activity activity = getActivity();
- if (!FeatureFactory.getFactory(activity)
- .getDashboardFeatureProvider(activity).isEnabled()) {
- AppHeader.createAppHeader(this, mPackageInfo.applicationInfo.loadIcon(mPm),
- mPackageInfo.applicationInfo.loadLabel(mPm), mPackageName,
- mPackageInfo.applicationInfo.uid, 0);
- } else {
- final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, null /* appHeader */)
- .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
- .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
- .setSummary(mPackageInfo)
- .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
- .setPackageName(mPackageName)
- .setUid(mPackageInfo.applicationInfo.uid)
- .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
- .done(getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, null /* appHeader */)
+ .setIcon(mPackageInfo.applicationInfo.loadIcon(mPm))
+ .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
+ .setSummary(mPackageInfo)
+ .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
+ .setPackageName(mPackageName)
+ .setUid(mPackageInfo.applicationInfo.uid)
+ .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+ .done(getPrefContext());
+ getPreferenceScreen().addPreference(pref);
}
}
diff --git a/src/com/android/settings/applications/AppStorageSettings.java b/src/com/android/settings/applications/AppStorageSettings.java
index b4d7526..0ea9515 100644
--- a/src/com/android/settings/applications/AppStorageSettings.java
+++ b/src/com/android/settings/applications/AppStorageSettings.java
@@ -105,12 +105,6 @@
private static final String KEY_URI_CATEGORY = "uri_category";
private static final String KEY_CLEAR_URI = "clear_uri_button";
- private Preference mTotalSize;
- private Preference mAppSize;
- private Preference mDataSize;
- private Preference mExternalCodeSize;
- private Preference mExternalDataSize;
-
// Views related to cache info
private Preference mCacheSize;
private Button mClearDataButton;
@@ -125,15 +119,9 @@
private PreferenceCategory mUri;
private boolean mCanClearData = true;
- private boolean mHaveSizes = false;
private AppStorageStats mLastResult;
- private long mLastCodeSize = -1;
- private long mLastDataSize = -1;
- private long mLastExternalCodeSize = -1;
- private long mLastExternalDataSize = -1;
- private long mLastCacheSize = -1;
- private long mLastTotalSize = -1;
+ private AppStorageSizesController mSizeController;
private ClearCacheObserver mClearCacheObserver;
private ClearUserDataObserver mClearDataObserver;
@@ -166,17 +154,15 @@
mInvalidSizeStr = getActivity().getText(R.string.invalid_size_value);
// Set default values on sizes
- mTotalSize = findPreference(KEY_TOTAL_SIZE);
- mAppSize = findPreference(KEY_APP_SIZE);
- mDataSize = findPreference(KEY_DATA_SIZE);
- mExternalCodeSize = findPreference(KEY_EXTERNAL_CODE_SIZE);
- mExternalDataSize = findPreference(KEY_EXTERNAL_DATA_SIZE);
+ mSizeController = new AppStorageSizesController.Builder()
+ .setTotalSizePreference(findPreference(KEY_TOTAL_SIZE))
+ .setAppSizePreference(findPreference(KEY_APP_SIZE))
+ .setDataSizePreference(findPreference(KEY_DATA_SIZE))
+ .setCacheSizePreference(findPreference(KEY_CACHE_SIZE))
+ .setComputingString(R.string.computing_size)
+ .setErrorString(R.string.invalid_size_value)
+ .build();
- if (Environment.isExternalStorageEmulated()) {
- PreferenceCategory category = (PreferenceCategory) findPreference(KEY_STORAGE_CATEGORY);
- category.removePreference(mExternalCodeSize);
- category.removePreference(mExternalDataSize);
- }
mClearDataButton = (Button) ((LayoutPreference) findPreference(KEY_CLEAR_DATA))
.findViewById(R.id.button);
@@ -265,13 +251,6 @@
dialog.dismiss();
}
- private String getSizeStr(long size) {
- if (size == SIZE_INVALID) {
- return mInvalidSizeStr.toString();
- }
- return Formatter.formatFileSize(getActivity(), size);
- }
-
@Override
protected boolean refreshUi() {
retrieveAppEntry();
@@ -521,7 +500,7 @@
@Override
public void onLoadFinished(Loader<AppStorageStats> loader, AppStorageStats result) {
- mLastResult = result;
+ mSizeController.setResult(result);
updateUiWithSize(result);
}
@@ -545,39 +524,15 @@
}
private void updateUiWithSize(AppStorageStats result) {
+ mSizeController.updateUi(getContext());
+
if (result == null) {
- mLastCodeSize = mLastDataSize = mLastCacheSize = mLastTotalSize = -1;
- if (!mHaveSizes) {
- mAppSize.setSummary(mComputingStr);
- mDataSize.setSummary(mComputingStr);
- mCacheSize.setSummary(mComputingStr);
- mTotalSize.setSummary(mComputingStr);
- }
mClearDataButton.setEnabled(false);
mClearCacheButton.setEnabled(false);
} else {
- mHaveSizes = true;
long codeSize = result.getCodeBytes();
long dataSize = result.getDataBytes();
- if (mLastCodeSize != codeSize) {
- mLastCodeSize = codeSize;
- mAppSize.setSummary(getSizeStr(codeSize));
- }
- if (mLastDataSize != dataSize) {
- mLastDataSize = dataSize;
- mDataSize.setSummary(getSizeStr(dataSize));
- }
long cacheSize = result.getCacheBytes();
- if (mLastCacheSize != cacheSize) {
- mLastCacheSize = cacheSize;
- mCacheSize.setSummary(getSizeStr(cacheSize));
- }
-
- long totalSize = codeSize + dataSize + cacheSize;
- if (mLastTotalSize != totalSize) {
- mLastTotalSize = totalSize;
- mTotalSize.setSummary(getSizeStr(totalSize));
- }
if (dataSize <= 0 || !mCanClearData) {
mClearDataButton.setEnabled(false);
@@ -615,28 +570,6 @@
}
};
- public static CharSequence getSummary(AppEntry appEntry, Context context) {
- if (appEntry.size == ApplicationsState.SIZE_INVALID
- || appEntry.size == ApplicationsState.SIZE_UNKNOWN) {
- return context.getText(R.string.computing_size);
- } else {
- CharSequence storageType = context.getString(
- (appEntry.info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0
- ? R.string.storage_type_external
- : R.string.storage_type_internal);
- return context.getString(R.string.storage_summary_format,
- getSize(appEntry, context), storageType);
- }
- }
-
- private static CharSequence getSize(AppEntry appEntry, Context context) {
- long size = appEntry.size;
- if (size == SIZE_INVALID) {
- return context.getText(R.string.invalid_size_value);
- }
- return Formatter.formatFileSize(context, size);
- }
-
@Override
public int getMetricsCategory() {
return MetricsEvent.APPLICATIONS_APP_STORAGE;
diff --git a/src/com/android/settings/applications/AppStorageSizesController.java b/src/com/android/settings/applications/AppStorageSizesController.java
new file mode 100644
index 0000000..bc8f680
--- /dev/null
+++ b/src/com/android/settings/applications/AppStorageSizesController.java
@@ -0,0 +1,155 @@
+/*
+ * 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.annotation.Nullable;
+import android.support.annotation.StringRes;
+import android.support.v7.preference.Preference;
+import android.text.format.Formatter;
+
+import com.android.internal.util.Preconditions;
+import com.android.settingslib.applications.StorageStatsSource;
+
+/**
+ * Handles setting the sizes for the app info screen.
+ */
+public class AppStorageSizesController {
+ private final Preference mTotalSize;
+ private final Preference mAppSize;
+ private final Preference mDataSize;
+ private final Preference mCacheSize;
+ private final @StringRes int mComputing;
+ private final @StringRes int mError;
+
+ @Nullable
+ private StorageStatsSource.AppStorageStats mLastResult;
+ private boolean mLastResultFailed;
+ private long mLastCodeSize = -1;
+ private long mLastDataSize = -1;
+ private long mLastCacheSize = -1;
+ private long mLastTotalSize = -1;
+
+ private AppStorageSizesController(Preference total, Preference app,
+ Preference data, Preference cache, @StringRes int computing, @StringRes int error) {
+ mTotalSize = total;
+ mAppSize = app;
+ mDataSize = data;
+ mCacheSize = cache;
+ mComputing = computing;
+ mError = error;
+ }
+
+ /**
+ * Updates the UI using storage stats.
+ * @param context Context to use to fetch strings
+ */
+ public void updateUi(Context context) {
+ if (mLastResult == null) {
+ int errorRes = mLastResultFailed ? mError : mComputing;
+
+ mAppSize.setSummary(errorRes);
+ mDataSize.setSummary(errorRes);
+ mCacheSize.setSummary(errorRes);
+ mTotalSize.setSummary(errorRes);
+ } else {
+ long codeSize = mLastResult.getCodeBytes();
+ long dataSize = mLastResult.getDataBytes();
+ if (mLastCodeSize != codeSize) {
+ mLastCodeSize = codeSize;
+ mAppSize.setSummary(getSizeStr(context, codeSize));
+ }
+ if (mLastDataSize != dataSize) {
+ mLastDataSize = dataSize;
+ mDataSize.setSummary(getSizeStr(context, dataSize));
+ }
+ long cacheSize = mLastResult.getCacheBytes();
+ if (mLastCacheSize != cacheSize) {
+ mLastCacheSize = cacheSize;
+ mCacheSize.setSummary(getSizeStr(context, cacheSize));
+ }
+
+ long totalSize = codeSize + dataSize + cacheSize;
+ if (mLastTotalSize != totalSize) {
+ mLastTotalSize = totalSize;
+ mTotalSize.setSummary(getSizeStr(context, totalSize));
+ }
+ }
+ }
+
+ /**
+ * Sets a result for the controller to use to update the UI.
+ * @param result A result for the UI. If null, count as a failed calculation.
+ */
+ public void setResult(StorageStatsSource.AppStorageStats result) {
+ mLastResult = result;
+ mLastResultFailed = result == null;
+ }
+
+ private String getSizeStr(Context context, long size) {
+ return Formatter.formatFileSize(context, size);
+ }
+
+ public static class Builder {
+ private Preference mTotalSize;
+ private Preference mAppSize;
+ private Preference mDataSize;
+ private Preference mCacheSize;
+ private @StringRes int mComputing;
+ private @StringRes int mError;
+
+ public Builder setAppSizePreference(Preference preference) {
+ mAppSize = preference;
+ return this;
+ }
+
+ public Builder setDataSizePreference(Preference preference) {
+ mDataSize = preference;
+ return this;
+ }
+
+ public Builder setCacheSizePreference(Preference preference) {
+ mCacheSize = preference;
+ return this;
+ }
+
+ public Builder setTotalSizePreference(Preference preference) {
+ mTotalSize = preference;
+ return this;
+ }
+
+ public Builder setComputingString(@StringRes int sequence) {
+ mComputing = sequence;
+ return this;
+ }
+
+ public Builder setErrorString(@StringRes int sequence) {
+ mError = sequence;
+ return this;
+ }
+
+ public AppStorageSizesController build() {
+ return new AppStorageSizesController(
+ Preconditions.checkNotNull(mTotalSize),
+ Preconditions.checkNotNull(mAppSize),
+ Preconditions.checkNotNull(mDataSize),
+ Preconditions.checkNotNull(mCacheSize),
+ mComputing,
+ mError);
+ }
+ }
+}
diff --git a/src/com/android/settings/applications/ClearDefaultsPreference.java b/src/com/android/settings/applications/ClearDefaultsPreference.java
index e9c5a0e..0de2676 100644
--- a/src/com/android/settings/applications/ClearDefaultsPreference.java
+++ b/src/com/android/settings/applications/ClearDefaultsPreference.java
@@ -24,6 +24,7 @@
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
+import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.SpannableString;
@@ -68,7 +69,9 @@
}
public ClearDefaultsPreference(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
+ this(context, attrs, TypedArrayUtils.getAttr(context,
+ android.support.v7.preference.R.attr.preferenceStyle,
+ android.R.attr.preferenceStyle));
}
public ClearDefaultsPreference(Context context) {
diff --git a/src/com/android/settings/applications/ExternalSourcesDetails.java b/src/com/android/settings/applications/ExternalSourcesDetails.java
index af9251c..6441437 100644
--- a/src/com/android/settings/applications/ExternalSourcesDetails.java
+++ b/src/com/android/settings/applications/ExternalSourcesDetails.java
@@ -15,6 +15,9 @@
*/
package com.android.settings.applications;
+import static android.app.Activity.RESULT_CANCELED;
+import static android.app.Activity.RESULT_OK;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import android.app.AlertDialog;
@@ -26,6 +29,7 @@
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import com.android.settings.R;
+import com.android.settings.Settings;
import com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -67,6 +71,10 @@
final boolean checked = (Boolean) newValue;
if (preference == mSwitchPref) {
if (mInstallAppsState != null && checked != mInstallAppsState.canInstallApps()) {
+ if (Settings.ManageAppExternalSourcesActivity.class.getName().equals(
+ getIntent().getComponent().getClassName())) {
+ setResult(checked ? RESULT_OK : RESULT_CANCELED);
+ }
setCanInstallApps(checked);
refreshUi();
}
@@ -97,9 +105,13 @@
protected boolean refreshUi() {
mInstallAppsState = mAppBridge.createInstallAppsStateFor(mPackageName,
mPackageInfo.applicationInfo.uid);
-
- final boolean canWrite = mInstallAppsState.canInstallApps();
- mSwitchPref.setChecked(canWrite);
+ if (!mInstallAppsState.isPotentialAppSource()) {
+ // Invalid app entry. Should not allow changing permission
+ mSwitchPref.setEnabled(false);
+ return true;
+ }
+ final boolean canInstallApps = mInstallAppsState.canInstallApps();
+ mSwitchPref.setChecked(canInstallApps);
return true;
}
diff --git a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
index 3477299..97e5b7b 100644
--- a/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
+++ b/src/com/android/settings/applications/FetchPackageStorageAsyncLoader.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.UserHandle;
+import android.util.Log;
import com.android.internal.util.Preconditions;
import com.android.settings.utils.AsyncLoader;
@@ -30,6 +31,7 @@
* Fetches the storage stats using the StorageStatsManager for a given package and user tuple.
*/
public class FetchPackageStorageAsyncLoader extends AsyncLoader<AppStorageStats> {
+ private static final String TAG = "FetchPackageStorage";
private final StorageStatsSource mSource;
private final ApplicationInfo mInfo;
private final UserHandle mUser;
@@ -44,7 +46,13 @@
@Override
public AppStorageStats loadInBackground() {
- return mSource.getStatsForPackage(mInfo.volumeUuid, mInfo.packageName, mUser);
+ AppStorageStats result = null;
+ try {
+ result = mSource.getStatsForPackage(mInfo.volumeUuid, mInfo.packageName, mUser);
+ } catch (IllegalStateException e) {
+ Log.w(TAG, "Package may have been removed during query, failing gracefully", e);
+ }
+ return result;
}
@Override
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 3427d9e..da6bbc0 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -20,6 +20,7 @@
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
+import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.app.admin.DevicePolicyManager;
import android.content.ActivityNotFoundException;
@@ -65,7 +66,6 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.IWebViewUpdateService;
import android.widget.Button;
@@ -86,7 +86,6 @@
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
-import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.datausage.AppDataUsage;
import com.android.settings.datausage.DataUsageList;
import com.android.settings.datausage.DataUsageSummary;
@@ -103,6 +102,8 @@
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.applications.PermissionsSummaryHelper;
import com.android.settingslib.applications.PermissionsSummaryHelper.PermissionsResultCallback;
+import com.android.settingslib.applications.StorageStatsSource;
+import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
import com.android.settingslib.net.ChartData;
import com.android.settingslib.net.ChartDataLoader;
@@ -123,7 +124,8 @@
* uninstall the application.
*/
public class InstalledAppDetails extends AppInfoBase
- implements View.OnClickListener, OnPreferenceClickListener {
+ implements View.OnClickListener, OnPreferenceClickListener,
+ LoaderManager.LoaderCallbacks<AppStorageStats> {
private static final String LOG_TAG = "InstalledAppDetails";
@@ -138,13 +140,14 @@
private static final int SUB_INFO_FRAGMENT = 1;
private static final int LOADER_CHART_DATA = 2;
+ private static final int LOADER_STORAGE = 3;
private static final int DLG_FORCE_STOP = DLG_BASE + 1;
private static final int DLG_DISABLE = DLG_BASE + 2;
private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3;
private static final String KEY_HEADER = "header_view";
- private static final String KEY_FOOTER = "header_footer";
+ private static final String KEY_ACTION_BUTTONS = "action_buttons";
private static final String KEY_NOTIFICATION = "notification_settings";
private static final String KEY_STORAGE = "storage_settings";
private static final String KEY_PERMISSION = "permission_settings";
@@ -158,12 +161,10 @@
private final HashSet<String> mHomePackages = new HashSet<>();
- private DashboardFeatureProvider mDashboardFeatureProvider;
-
private boolean mInitialized;
private boolean mShowUninstalled;
private LayoutPreference mHeader;
- private LayoutPreference mFooter;
+ private LayoutPreference mActionButtons;
private Button mUninstallButton;
private boolean mUpdatedSysApp = false;
private Button mForceStopButton;
@@ -191,6 +192,8 @@
protected ProcStatsData mStatsManager;
protected ProcStatsPackageEntry mStats;
+ private AppStorageStats mLastResult;
+
private boolean handleDisableable(Button button) {
boolean disableable = false;
// Try to prevent the user from bricking their phone
@@ -320,20 +323,14 @@
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Activity activity = getActivity();
- mDashboardFeatureProvider =
- FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
+
+ if (!ensurePackageInfoAvailable(activity)) {
+ return;
+ }
setHasOptionsMenu(true);
- addPreferencesFromResource(mDashboardFeatureProvider.isEnabled()
- ? R.xml.installed_app_details_ia
- : R.xml.installed_app_details);
+ addPreferencesFromResource(R.xml.installed_app_details_ia);
addDynamicPrefs();
- if (mDashboardFeatureProvider.isEnabled()) {
- mFooter = new LayoutPreference(getPrefContext(), R.layout.app_action_buttons);
- mFooter.setOrder(-9999);
- mFooter.setKey(KEY_FOOTER);
- getPreferenceScreen().addPreference(mFooter);
- }
if (Utils.isBandwidthControlEnabled()) {
INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
@@ -359,13 +356,14 @@
if (mFinishing) {
return;
}
- mState.requestSize(mPackageName, mUserId);
AppItem app = new AppItem(mAppEntry.info.uid);
app.addUid(mAppEntry.info.uid);
if (mStatsSession != null) {
- getLoaderManager().restartLoader(LOADER_CHART_DATA,
+ LoaderManager loaderManager = getLoaderManager();
+ loaderManager.restartLoader(LOADER_CHART_DATA,
ChartDataLoader.buildArgs(getTemplate(getContext()), app),
mDataCallbacks);
+ loaderManager.restartLoader(LOADER_STORAGE, Bundle.EMPTY, this);
}
new BatteryUpdater().execute();
new MemoryUpdater().execute();
@@ -389,20 +387,17 @@
if (mFinishing) {
return;
}
- if (!mDashboardFeatureProvider.isEnabled()) {
- handleHeader();
- } else {
- final Activity activity = getActivity();
- mHeader = (LayoutPreference) findPreference(KEY_HEADER);
- FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
- .setPackageName(mPackageName)
- .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
- AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
- .bindAppHeaderButtons();
- prepareUninstallAndStop();
- }
+ final Activity activity = getActivity();
+ mHeader = (LayoutPreference) findPreference(KEY_HEADER);
+ mActionButtons = (LayoutPreference) findPreference(KEY_ACTION_BUTTONS);
+ FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
+ .setPackageName(mPackageName)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
+ AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
+ .bindAppHeaderButtons();
+ prepareUninstallAndStop();
mNotificationPreference = findPreference(KEY_NOTIFICATION);
mNotificationPreference.setOnPreferenceClickListener(this);
@@ -439,36 +434,27 @@
refreshUi();
}
- private void handleHeader() {
- mHeader = (LayoutPreference) findPreference(KEY_HEADER);
- // Get Control button panel
- View btnPanel = mHeader.findViewById(R.id.control_buttons_panel);
- mForceStopButton = (Button) btnPanel.findViewById(R.id.right_button);
- mForceStopButton.setText(R.string.force_stop);
- mUninstallButton = (Button) btnPanel.findViewById(R.id.left_button);
- mForceStopButton.setEnabled(false);
-
- View gear = mHeader.findViewById(R.id.gear);
- Intent i = new Intent(Intent.ACTION_APPLICATION_PREFERENCES);
- i.setPackage(mPackageName);
- final Intent intent = resolveIntent(i);
- if (intent != null) {
- gear.setVisibility(View.VISIBLE);
- gear.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- startActivity(intent);
- }
- });
- } else {
- gear.setVisibility(View.GONE);
+ /**
+ * Ensures the {@link PackageInfo} is available to proceed. If it's not available, the fragment
+ * will finish.
+ *
+ * @return true if packageInfo is available.
+ */
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ boolean ensurePackageInfoAvailable(Activity activity) {
+ if (mPackageInfo == null) {
+ mFinishing = true;
+ Log.w(LOG_TAG, "Package info not available. Is this package already uninstalled?");
+ activity.finishAndRemoveTask();
+ return false;
}
+ return true;
}
private void prepareUninstallAndStop() {
- mForceStopButton = (Button) mFooter.findViewById(R.id.right_button);
+ mForceStopButton = (Button) mActionButtons.findViewById(R.id.right_button);
mForceStopButton.setText(R.string.force_stop);
- mUninstallButton = (Button) mFooter.findViewById(R.id.left_button);
+ mUninstallButton = (Button) mActionButtons.findViewById(R.id.left_button);
mForceStopButton.setEnabled(false);
}
@@ -536,25 +522,37 @@
}
}
+ @Override
+ public Loader<AppStorageStats> onCreateLoader(int id, Bundle args) {
+ Context context = getContext();
+ return new FetchPackageStorageAsyncLoader(
+ context, new StorageStatsSource(context), mAppEntry.info, UserHandle.of(mUserId));
+ }
+
+ @Override
+ public void onLoadFinished(Loader<AppStorageStats> loader, AppStorageStats result) {
+ mLastResult = result;
+ refreshUi();
+ }
+
+ @Override
+ public void onLoaderReset(Loader<AppStorageStats> loader) {
+ }
+
// Utility method to set application label and icon.
private void setAppLabelAndIcon(PackageInfo pkgInfo) {
final View appSnippet = mHeader.findViewById(R.id.app_snippet);
mState.ensureIcon(mAppEntry);
- if (mDashboardFeatureProvider.isEnabled()) {
- final Activity activity = getActivity();
- FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, appSnippet)
- .setLabel(mAppEntry)
- .setIcon(mAppEntry)
- .setSummary(getString(getInstallationStatus(mAppEntry.info)))
- .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
- .done(false /* rebindActions */);
- mVersionPreference.setSummary(getString(R.string.version_text, pkgInfo.versionName));
- } else {
- setupAppSnippet(appSnippet, mAppEntry.label, mAppEntry.icon,
- pkgInfo != null ? pkgInfo.versionName : null);
- }
+ final Activity activity = getActivity();
+ FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, appSnippet)
+ .setLabel(mAppEntry)
+ .setIcon(mAppEntry)
+ .setSummary(getString(getInstallationStatus(mAppEntry.info)))
+ .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
+ .done(false /* rebindActions */);
+ mVersionPreference.setSummary(getString(R.string.version_text, pkgInfo.versionName));
}
@VisibleForTesting
@@ -638,7 +636,8 @@
// Update the preference summaries.
Activity context = getActivity();
- mStoragePreference.setSummary(AppStorageSettings.getSummary(mAppEntry, context));
+ boolean isExternal = ((mAppEntry.info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
+ mStoragePreference.setSummary(getStorageSummary(context, mLastResult, isExternal));
PermissionsSummaryHelper.getPermissionSummary(getContext(),
mPackageName, mPermissionCallback);
@@ -707,6 +706,25 @@
return getString(R.string.computing_size);
}
+ @VisibleForTesting
+ static CharSequence getStorageSummary(
+ Context context, AppStorageStats stats, boolean isExternal) {
+ if (stats == null) {
+ return context.getText(R.string.computing_size);
+ } else {
+ CharSequence storageType = context.getString(isExternal
+ ? R.string.storage_type_external
+ : R.string.storage_type_internal);
+ return context.getString(R.string.storage_summary_format,
+ getSize(context, stats), storageType);
+ }
+ }
+
+ private static CharSequence getSize(Context context, AppStorageStats stats) {
+ return Formatter.formatFileSize(context, stats.getTotalBytes());
+ }
+
+
@Override
protected AlertDialog createDialog(int id, int errorCode) {
switch (id) {
@@ -1146,6 +1164,9 @@
}
}
+ /**
+ * @deprecated app info pages should use {@link AppHeaderController} to show the app header.
+ */
public static void setupAppSnippet(View appSnippet, CharSequence label, Drawable icon,
CharSequence versionName) {
LayoutInflater.from(appSnippet.getContext()).inflate(R.layout.widget_text_views,
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index ab99c9b..826e5db 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -56,7 +56,6 @@
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.Settings.AllApplicationsActivity;
import com.android.settings.Settings.GamesStorageActivity;
@@ -80,7 +79,6 @@
import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.NotificationBackend.AppRow;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -265,7 +263,6 @@
private NotificationBackend mNotifBackend;
private ResetAppsHelper mResetAppsHelper;
private String mVolumeUuid;
- private String mVolumeName;
private int mStorageType;
@Override
@@ -289,7 +286,6 @@
} else if (className.equals(StorageUseActivity.class.getName())) {
if (args != null && args.containsKey(EXTRA_VOLUME_UUID)) {
mVolumeUuid = args.getString(EXTRA_VOLUME_UUID);
- mVolumeName = args.getString(EXTRA_VOLUME_NAME);
mStorageType = args.getInt(EXTRA_STORAGE_TYPE, STORAGE_TYPE_DEFAULT);
mListType = LIST_TYPE_STORAGE;
} else {
@@ -423,22 +419,6 @@
}
}
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
- if (mListType == LIST_TYPE_STORAGE) {
- final Activity activity = getActivity();
- final boolean isNewIAEnabled = FeatureFactory.getFactory(activity)
- .getDashboardFeatureProvider(activity)
- .isEnabled();
- if (!isNewIAEnabled) {
- FrameLayout pinnedHeader = (FrameLayout) mRootView.findViewById(R.id.pinned_header);
- AppHeader.createAppHeader(getActivity(), null, mVolumeName, null, -1, pinnedHeader);
- }
- }
- }
-
private int getDefaultFilter() {
switch (mListType) {
case LIST_TYPE_USAGE_ACCESS:
@@ -627,12 +607,7 @@
return;
}
final Context context = getActivity();
- if (FeatureFactory.getFactory(context).getDashboardFeatureProvider(context).isEnabled()) {
- mOptionsMenu.findItem(R.id.advanced).setVisible(false);
- } else {
- mOptionsMenu.findItem(R.id.advanced).setVisible(
- mListType == LIST_TYPE_MAIN || mListType == LIST_TYPE_NOTIFICATION);
- }
+ mOptionsMenu.findItem(R.id.advanced).setVisible(false);
mOptionsMenu.findItem(R.id.sort_order_alpha).setVisible(mListType == LIST_TYPE_STORAGE
&& mSortOrder != R.id.sort_order_alpha);
diff --git a/src/com/android/settings/applications/ProcessStatsDetail.java b/src/com/android/settings/applications/ProcessStatsDetail.java
index 89c6ade..9b6f41e 100644
--- a/src/com/android/settings/applications/ProcessStatsDetail.java
+++ b/src/com/android/settings/applications/ProcessStatsDetail.java
@@ -44,7 +44,6 @@
import android.view.View;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.AppHeader;
import com.android.settings.CancellablePreference;
import com.android.settings.CancellablePreference.OnCancelListener;
import com.android.settings.R;
@@ -126,28 +125,20 @@
return;
}
final Activity activity = getActivity();
- if (!FeatureFactory.getFactory(activity)
- .getDashboardFeatureProvider(activity).isEnabled()) {
- AppHeader.createAppHeader(this, mApp.mUiTargetApp != null
- ? mApp.mUiTargetApp.loadIcon(mPm)
- : new ColorDrawable(0),
- mApp.mUiLabel, mApp.mPackage, mApp.mUiTargetApp.uid);
- } else {
- final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, null /* appHeader */)
- .setIcon(mApp.mUiTargetApp != null
- ? mApp.mUiTargetApp.loadIcon(mPm)
- : new ColorDrawable(0))
- .setLabel(mApp.mUiLabel)
- .setPackageName(mApp.mPackage)
- .setUid(mApp.mUiTargetApp != null
- ? mApp.mUiTargetApp.uid
- : UserHandle.USER_NULL)
- .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
- .done(getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, null /* appHeader */)
+ .setIcon(mApp.mUiTargetApp != null
+ ? mApp.mUiTargetApp.loadIcon(mPm)
+ : new ColorDrawable(0))
+ .setLabel(mApp.mUiLabel)
+ .setPackageName(mApp.mPackage)
+ .setUid(mApp.mUiTargetApp != null
+ ? mApp.mUiTargetApp.uid
+ : UserHandle.USER_NULL)
+ .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+ .done(getPrefContext());
+ getPreferenceScreen().addPreference(pref);
}
@Override
diff --git a/src/com/android/settings/applications/assist/GestureAssistPreferenceController.java b/src/com/android/settings/applications/assist/GestureAssistPreferenceController.java
deleted file mode 100644
index bd85a03..0000000
--- a/src/com/android/settings/applications/assist/GestureAssistPreferenceController.java
+++ /dev/null
@@ -1,46 +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.assist;
-
-import android.content.Context;
-
-import com.android.settings.core.PreferenceController;
-import com.android.settings.gestures.AssistGestureFeatureProvider;
-import com.android.settings.overlay.FeatureFactory;
-
-public class GestureAssistPreferenceController extends PreferenceController {
-
- private static final String KEY_ASSIST_GESTURE = "gesture_assist";
-
- private AssistGestureFeatureProvider mFeatureProvider;
-
- public GestureAssistPreferenceController(Context context) {
- super(context);
- mFeatureProvider = FeatureFactory.getFactory(context)
- .getAssistGestureFeatureProvider();
- }
-
- @Override
- public boolean isAvailable() {
- return mFeatureProvider.isSupported(mContext);
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_ASSIST_GESTURE;
- }
-}
diff --git a/src/com/android/settings/applications/assist/ManageAssist.java b/src/com/android/settings/applications/assist/ManageAssist.java
index a54f0ff..824c0b1 100644
--- a/src/com/android/settings/applications/assist/ManageAssist.java
+++ b/src/com/android/settings/applications/assist/ManageAssist.java
@@ -24,6 +24,7 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.gestures.AssistGesturePreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -70,7 +71,7 @@
Lifecycle lifecycle) {
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new DefaultAssistPreferenceController(context));
- controllers.add(new GestureAssistPreferenceController(context));
+ controllers.add(new AssistGesturePreferenceController(context, lifecycle));
controllers.add(new AssistContextPreferenceController(context, lifecycle));
controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java b/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java
index 96512f5..d276fd2 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java
@@ -35,8 +35,6 @@
public final ComponentName componentName;
public final PackageItemInfo packageItemInfo;
public final String summary;
- // Description for why this item is disabled, if null, the item is enabled.
- public final String disabledDescription;
public final boolean enabled;
public DefaultAppInfo(int uid, ComponentName cn) {
@@ -52,21 +50,19 @@
userId = uid;
componentName = cn;
this.summary = summary;
- this.disabledDescription = null;
this.enabled = enabled;
}
- public DefaultAppInfo(PackageItemInfo info, String description) {
+ public DefaultAppInfo(PackageItemInfo info, String summary, boolean enabled) {
userId = UserHandle.myUserId();
packageItemInfo = info;
componentName = null;
- summary = null;
- this.disabledDescription = description;
- enabled = true;
+ this.summary = summary;
+ this.enabled = enabled;
}
public DefaultAppInfo(PackageItemInfo info) {
- this(info, null);
+ this(info, null /* summary */, true /* enabled */);
}
public CharSequence loadLabel(PackageManager pm) {
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java b/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java
index e4bcf06..785f7ad 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java
@@ -116,26 +116,9 @@
screen.addPreference(nonePref);
}
for (Map.Entry<String, DefaultAppInfo> app : mCandidates.entrySet()) {
- final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
- final String appKey = app.getKey();
- final DefaultAppInfo info = app.getValue();
- pref.setTitle(info.loadLabel(mPm.getPackageManager()));
- pref.setIcon(info.loadIcon(mPm.getPackageManager()));
- pref.setKey(appKey);
- if (TextUtils.equals(defaultAppKey, appKey)) {
- pref.setChecked(true);
- }
- if (TextUtils.equals(systemDefaultAppKey, appKey)) {
- pref.setSummary(R.string.system_app);
- } else if (!TextUtils.isEmpty(info.summary)) {
- pref.setSummary(info.summary);
- }
- if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
- pref.setEnabled(false);
- pref.setSummary(app.getValue().disabledDescription);
- }
- pref.setEnabled(info.enabled);
- pref.setOnClickListener(this);
+ RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
+ configurePreferenceFromAppInfo(
+ pref, app.getKey(), app.getValue(), defaultAppKey, systemDefaultAppKey);
screen.addPreference(pref);
}
mayCheckOnlyRadioButton();
@@ -259,4 +242,22 @@
}
}
+ @VisibleForTesting
+ public RadioButtonPreference configurePreferenceFromAppInfo(RadioButtonPreference pref,
+ String appKey, DefaultAppInfo info, String defaultAppKey, String systemDefaultAppKey) {
+ pref.setTitle(info.loadLabel(mPm.getPackageManager()));
+ pref.setIcon(info.loadIcon(mPm.getPackageManager()));
+ pref.setKey(appKey);
+ if (TextUtils.equals(defaultAppKey, appKey)) {
+ pref.setChecked(true);
+ }
+ if (TextUtils.equals(systemDefaultAppKey, appKey)) {
+ pref.setSummary(R.string.system_app);
+ } else if (!TextUtils.isEmpty(info.summary)) {
+ pref.setSummary(info.summary);
+ }
+ pref.setEnabled(info.enabled);
+ pref.setOnClickListener(this);
+ return pref;
+ }
}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutoFillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
similarity index 62%
rename from src/com/android/settings/applications/defaultapps/DefaultAutoFillPicker.java
rename to src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
index b8190cd..e3a7a2b 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAutoFillPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
@@ -23,7 +23,8 @@
import android.content.pm.ServiceInfo;
import android.provider.Settings;
import android.service.autofill.AutoFillService;
-import android.service.autofill.AutoFillServiceInfo;
+import android.service.autofill.AutofillService;
+import android.service.autofill.AutofillServiceInfo;
import android.text.TextUtils;
import com.android.internal.logging.nano.MetricsProto;
@@ -32,10 +33,12 @@
import java.util.ArrayList;
import java.util.List;
-public class DefaultAutoFillPicker extends DefaultAppPickerFragment {
+public class DefaultAutofillPicker extends DefaultAppPickerFragment {
- static final String SETTING = Settings.Secure.AUTO_FILL_SERVICE;
- static final Intent AUTO_FILL_PROBE = new Intent(AutoFillService.SERVICE_INTERFACE);
+ static final String SETTING = Settings.Secure.AUTOFILL_SERVICE;
+ // TODO(b/35956626): remove once clients migrated
+ static final Intent OLD_AUTO_FILL_PROBE = new Intent(AutoFillService.OLD_SERVICE_INTERFACE);
+ static final Intent AUTOFILL_PROBE = new Intent(AutofillService.SERVICE_INTERFACE);
@Override
public int getMetricsCategory() {
@@ -51,11 +54,17 @@
protected List<DefaultAppInfo> getCandidates() {
final List<DefaultAppInfo> candidates = new ArrayList<>();
final List<ResolveInfo> resolveInfos = mPm.getPackageManager()
- .queryIntentServices(AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
+ .queryIntentServices(AUTOFILL_PROBE, PackageManager.GET_META_DATA);
for (ResolveInfo info : resolveInfos) {
candidates.add(new DefaultAppInfo(mUserId, new ComponentName(
info.serviceInfo.packageName, info.serviceInfo.name)));
}
+ final List<ResolveInfo> oldResolveInfos = mPm.getPackageManager()
+ .queryIntentServices(OLD_AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
+ for (ResolveInfo info : oldResolveInfos) {
+ candidates.add(new DefaultAppInfo(mUserId, new ComponentName(
+ info.serviceInfo.packageName, info.serviceInfo.name)));
+ }
return candidates;
}
@@ -82,13 +91,12 @@
/**
* Provides Intent to setting activity for the specified auto-fill service.
*/
- static final class AutoFillSettingIntentProvider
- implements SettingIntentProvider {
+ static final class AutofillSettingIntentProvider implements SettingIntentProvider {
private final String mSelectedKey;
private final PackageManager mPackageManager;
- public AutoFillSettingIntentProvider(PackageManager packageManager, String key) {
+ public AutofillSettingIntentProvider(PackageManager packageManager, String key) {
mSelectedKey = key;
mPackageManager = packageManager;
}
@@ -96,14 +104,33 @@
@Override
public Intent getIntent() {
final List<ResolveInfo> resolveInfos = mPackageManager.queryIntentServices(
- AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
+ AUTOFILL_PROBE, PackageManager.GET_META_DATA);
for (ResolveInfo resolveInfo : resolveInfos) {
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
final String flattenKey = new ComponentName(
serviceInfo.packageName, serviceInfo.name).flattenToString();
if (TextUtils.equals(mSelectedKey, flattenKey)) {
- final String settingsActivity = new AutoFillServiceInfo(
+ final String settingsActivity = new AutofillServiceInfo(
+ mPackageManager, serviceInfo)
+ .getSettingsActivity();
+ if (TextUtils.isEmpty(settingsActivity)) {
+ return null;
+ }
+ return new Intent(Intent.ACTION_MAIN).setComponent(
+ new ComponentName(serviceInfo.packageName, settingsActivity));
+ }
+ }
+
+ final List<ResolveInfo> oldResolveInfos = mPackageManager.queryIntentServices(
+ OLD_AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
+
+ for (ResolveInfo resolveInfo : oldResolveInfos) {
+ final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
+ final String flattenKey = new ComponentName(
+ serviceInfo.packageName, serviceInfo.name).flattenToString();
+ if (TextUtils.equals(mSelectedKey, flattenKey)) {
+ final String settingsActivity = new AutofillServiceInfo(
mPackageManager, serviceInfo)
.getSettingsActivity();
if (TextUtils.isEmpty(settingsActivity)) {
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutoFillPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java
similarity index 85%
rename from src/com/android/settings/applications/defaultapps/DefaultAutoFillPreferenceController.java
rename to src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java
index b7f3b77..c536dbb 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAutoFillPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java
@@ -22,9 +22,9 @@
import android.provider.Settings;
import android.text.TextUtils;
-public class DefaultAutoFillPreferenceController extends DefaultAppPreferenceController {
+public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
- public DefaultAutoFillPreferenceController(Context context) {
+ public DefaultAutofillPreferenceController(Context context) {
super(context);
}
@@ -43,8 +43,8 @@
if (info == null) {
return null;
}
- final DefaultAutoFillPicker.AutoFillSettingIntentProvider intentProvider =
- new DefaultAutoFillPicker.AutoFillSettingIntentProvider(
+ final DefaultAutofillPicker.AutofillSettingIntentProvider intentProvider =
+ new DefaultAutofillPicker.AutofillSettingIntentProvider(
mPackageManager.getPackageManager(), info.getKey());
return intentProvider.getIntent();
}
@@ -52,7 +52,7 @@
@Override
protected DefaultAppInfo getDefaultAppInfo() {
final String flattenComponent = Settings.Secure.getString(mContext.getContentResolver(),
- DefaultAutoFillPicker.SETTING);
+ DefaultAutofillPicker.SETTING);
if (!TextUtils.isEmpty(flattenComponent)) {
DefaultAppInfo appInfo = new DefaultAppInfo(
mUserId, ComponentName.unflattenFromString(flattenComponent));
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index 3fc0abf..e438cbf 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -34,7 +34,10 @@
import android.view.View.OnClickListener;
import android.widget.ImageView;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.Index;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -205,11 +208,20 @@
void onClicked() {
int bondState = mCachedDevice.getBondState();
+ final MetricsFeatureProvider metricsFeatureProvider =
+ FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
+
if (mCachedDevice.isConnected()) {
+ metricsFeatureProvider.action(getContext(),
+ MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
askDisconnect();
} else if (bondState == BluetoothDevice.BOND_BONDED) {
+ metricsFeatureProvider.action(getContext(),
+ MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
mCachedDevice.connect(true);
} else if (bondState == BluetoothDevice.BOND_NONE) {
+ metricsFeatureProvider.action(getContext(),
+ MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
pair();
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index 83c0560..6db51df 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -27,7 +27,6 @@
import android.widget.Switch;
import android.widget.Toast;
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.search.Index;
@@ -52,6 +51,7 @@
private static final String EVENT_DATA_IS_BT_ON = "is_bluetooth_on";
private static final int EVENT_UPDATE_INDEX = 0;
+ private final int mMetricsEvent;
private Handler mHandler = new Handler() {
@Override
@@ -77,13 +77,15 @@
};
public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
- MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager) {
+ MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
+ int metricsEvent) {
mContext = context;
mMetricsFeatureProvider = metricsFeatureProvider;
mSwitchWidget = switchWidget;
mSwitch = mSwitchWidget.getSwitch();
mSwitchWidget.setListener(this);
mValidListener = false;
+ mMetricsEvent = metricsEvent;
if (manager == null) {
// Bluetooth is not supported
@@ -191,7 +193,7 @@
return false;
}
- mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_BLUETOOTH_TOGGLE, isChecked);
+ mMetricsFeatureProvider.action(mContext, mMetricsEvent, isChecked);
if (mLocalAdapter != null) {
boolean status = mLocalAdapter.setBluetoothEnabled(isChecked);
diff --git a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
index d9b1bea..f98a209 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.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.LifecycleObserver;
import com.android.settings.core.lifecycle.events.OnPause;
@@ -54,7 +55,8 @@
mBtPreference = (MasterSwitchPreference) screen.findPreference(KEY_TOGGLE_BLUETOOTH);
mBluetoothEnabler = new BluetoothEnabler(mContext,
new MasterSwitchController(mBtPreference),
- FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager);
+ FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager,
+ MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE);
}
@Override
diff --git a/src/com/android/settings/bluetooth/BluetoothProgressCategory.java b/src/com/android/settings/bluetooth/BluetoothProgressCategory.java
index a36c98b..ec948e0 100644
--- a/src/com/android/settings/bluetooth/BluetoothProgressCategory.java
+++ b/src/com/android/settings/bluetooth/BluetoothProgressCategory.java
@@ -48,7 +48,6 @@
}
private void init() {
- setIcon(R.drawable.ic_settings_bluetooth);
setEmptyTextRes(R.string.bluetooth_no_devices_found);
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 99c46bf..5679f90 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -99,6 +99,8 @@
private final IntentFilter mIntentFilter;
+ // For Search
+ private static final String DATA_KEY_REFERENCE = "main_toggle_bluetooth";
// accessed from inner class (not private to avoid thunks)
FooterPreference mMyDevicePreference;
@@ -151,7 +153,8 @@
mSwitchBar = activity.getSwitchBar();
mBluetoothEnabler = new BluetoothEnabler(activity, new SwitchBarController(mSwitchBar),
- mMetricsFeatureProvider, Utils.getLocalBtManager(activity));
+ mMetricsFeatureProvider, Utils.getLocalBtManager(activity),
+ MetricsEvent.ACTION_BLUETOOTH_TOGGLE);
mBluetoothEnabler.setupSwitchController();
}
@@ -567,6 +570,7 @@
SearchIndexableRaw data = new SearchIndexableRaw(context);
data.title = res.getString(R.string.bluetooth_settings);
data.screenTitle = res.getString(R.string.bluetooth_settings);
+ data.key = DATA_KEY_REFERENCE;
result.add(data);
// Add cached paired BT devices
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 4fa44b4..037b381 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -21,9 +21,12 @@
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.DialogInterface;
+import android.support.annotation.VisibleForTesting;
import android.widget.Toast;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.Index;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -84,14 +87,25 @@
// TODO: wire this up to show connection errors...
static void showConnectingError(Context context, String name) {
- showError(context, name, R.string.bluetooth_connecting_error_message);
+ showConnectingError(context, name, getLocalBtManager(context));
+ }
+
+ @VisibleForTesting
+ static void showConnectingError(Context context, String name, LocalBluetoothManager manager) {
+ FeatureFactory.getFactory(context).getMetricsFeatureProvider().visible(context,
+ MetricsEvent.VIEW_UNKNOWN, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR);
+ showError(context, name, R.string.bluetooth_connecting_error_message, manager);
}
static void showError(Context context, String name, int messageResId) {
+ showError(context, name, messageResId, getLocalBtManager(context));
+ }
+
+ private static void showError(Context context, String name, int messageResId,
+ LocalBluetoothManager manager) {
String message = context.getString(messageResId, name);
- LocalBluetoothManager manager = getLocalBtManager(context);
Context activity = manager.getForegroundActivity();
- if(manager.isForegroundActivity()) {
+ if (manager.isForegroundActivity()) {
new AlertDialog.Builder(activity)
.setTitle(R.string.bluetooth_error_title)
.setMessage(message)
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 786b9d3..b12e849 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -27,7 +27,6 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.deviceinfo.UsbBackend;
import com.android.settings.nfc.NfcPreferenceController;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -82,10 +81,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.connected_devices;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/core/DynamicAvailabilityPreferenceController.java b/src/com/android/settings/core/DynamicAvailabilityPreferenceController.java
new file mode 100644
index 0000000..9323aa3
--- /dev/null
+++ b/src/com/android/settings/core/DynamicAvailabilityPreferenceController.java
@@ -0,0 +1,59 @@
+/*
+ * 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.core;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.core.lifecycle.Lifecycle;
+import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.core.lifecycle.events.OnResume;
+
+public abstract class DynamicAvailabilityPreferenceController extends PreferenceController
+ implements LifecycleObserver, OnResume {
+
+ private Preference mPreference;
+ private PreferenceScreen mScreen;
+
+ public DynamicAvailabilityPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ mScreen = screen;
+ mPreference = screen.findPreference(getPreferenceKey());
+ super.displayPreference(screen);
+ }
+
+ @Override
+ public void onResume() {
+ if (!isAvailable()) {
+ removePreference(mScreen, getPreferenceKey());
+ return;
+ }
+
+ updateState(mPreference);
+ if (mScreen.findPreference(getPreferenceKey()) == null) {
+ mScreen.addPreference(mPreference);
+ }
+ }
+}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 742f727..2a3c5d3 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -50,6 +50,7 @@
import com.android.settings.applications.AdvancedAppSettings;
import com.android.settings.applications.AppAndNotificationDashboardFragment;
import com.android.settings.applications.DrawOverlayDetails;
+import com.android.settings.applications.ExternalSourcesDetails;
import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.applications.ManageApplications;
import com.android.settings.applications.ManageDomainUrls;
@@ -214,6 +215,7 @@
ProcessStatsSummary.class.getName(),
DrawOverlayDetails.class.getName(),
WriteSettingsDetails.class.getName(),
+ ExternalSourcesDetails.class.getName(),
AdvancedAppSettings.class.getName(),
WallpaperTypeSettings.class.getName(),
VrListenerSettings.class.getName(),
@@ -243,47 +245,38 @@
};
public static final String[] SETTINGS_FOR_RESTRICTED = {
- //wireless_section
- Settings.WifiSettingsActivity.class.getName(),
- Settings.BluetoothSettingsActivity.class.getName(),
- Settings.SimSettingsActivity.class.getName(),
- //device_section
- Settings.SoundSettingsActivity.class.getName(),
- Settings.DisplaySettingsActivity.class.getName(),
- Settings.StorageSettingsActivity.class.getName(),
- Settings.ManageApplicationsActivity.class.getName(),
- Settings.PowerUsageSummaryActivity.class.getName(),
- //personal_section
- Settings.LocationSettingsActivity.class.getName(),
- Settings.SecuritySettingsActivity.class.getName(),
- Settings.UserSettingsActivity.class.getName(),
- //system_section
- Settings.DateTimeSettingsActivity.class.getName(),
- Settings.DeviceInfoSettingsActivity.class.getName(),
- Settings.AccessibilitySettingsActivity.class.getName(),
- Settings.PrintSettingsActivity.class.getName(),
- Settings.PaymentSettingsActivity.class.getName(),
-
-
// New IA
// Home page
Settings.NetworkDashboardActivity.class.getName(),
Settings.ConnectedDeviceDashboardActivity.class.getName(),
- Settings.WifiDisplaySettingsActivity.class.getName(),
Settings.AppAndNotificationDashboardActivity.class.getName(),
+ Settings.DisplaySettingsActivity.class.getName(),
+ Settings.SoundSettingsActivity.class.getName(),
Settings.StorageDashboardActivity.class.getName(),
- "com.android.settings.SoundDashboardAlias",
- "com.android.settings.UsersDashboardAlias",
+ Settings.PowerUsageSummaryActivity.class.getName(),
Settings.UserAndAccountDashboardActivity.class.getName(),
+ Settings.SecuritySettingsActivity.class.getName(),
+ Settings.AccessibilitySettingsActivity.class.getName(),
Settings.SystemDashboardActivity.class.getName(),
Settings.SupportDashboardActivity.class.getName(),
- // Home page > Apps & Notifications
- "com.android.settings.ManageApplicationsDashboardAlias",
- "com.android.settings.PaymentSettingsDashboardAlias",
// Home page > Network & Internet
+ Settings.WifiSettingsActivity.class.getName(),
Settings.DataUsageSummaryActivity.class.getName(),
+ Settings.SimSettingsActivity.class.getName(),
+ // Home page > Connected devices
+ Settings.BluetoothSettingsActivity.class.getName(),
+ Settings.WifiDisplaySettingsActivity.class.getName(),
+ Settings.PrintSettingsActivity.class.getName(),
+ // Home page > Apps & Notifications
+ Settings.UserSettingsActivity.class.getName(),
+ Settings.ManageApplicationsActivity.class.getName(),
+ Settings.PaymentSettingsActivity.class.getName(),
+ // Home page > Security & screen lock
+ Settings.LocationSettingsActivity.class.getName(),
// Home page > System
Settings.LanguageAndInputSettingsActivity.class.getName(),
+ Settings.DateTimeSettingsActivity.class.getName(),
+ Settings.DeviceInfoSettingsActivity.class.getName(),
Settings.EnterprisePrivacySettingsActivity.class.getName(),
};
}
diff --git a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
index a5efcc1..6c23b39 100644
--- a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
+++ b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
@@ -21,6 +21,7 @@
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.text.TextUtils;
+import android.util.Pair;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.overlay.FeatureFactory;
@@ -111,13 +112,17 @@
return;
}
// Pref key exists in set, log it's change in metrics.
- mMetricsFeature.count(mContext, prefKey + "|" + value, 1);
+ mMetricsFeature.action(mContext, MetricsEvent.ACTION_SETTINGS_PREFERENCE_CHANGE,
+ Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, prefKey),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_VALUE, value));
}
private void logPackageName(String key, String value) {
- mMetricsFeature.count(mContext, mTag + "/" + key, 1);
+ final String prefKey = mTag + "/" + key;
+ mMetricsFeature.action(mContext, MetricsEvent.ACTION_SETTINGS_PREFERENCE_CHANGE,
+ Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, prefKey));
mMetricsFeature.action(mContext, MetricsEvent.ACTION_GENERIC_PACKAGE,
- mTag + "/" + key + "|" + value);
+ prefKey + "|" + value);
}
private void safeLogValue(String key, String value) {
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index d9cef65..07d4806 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -146,8 +146,7 @@
List<Tile> suggestions) {
// TODO: Better place for tinting?
final TypedArray a = mContext.obtainStyledAttributes(new int[]{
- mDashboardFeatureProvider.isEnabled()
- ? android.R.attr.colorControlNormal : android.R.attr.colorAccent});
+ android.R.attr.colorControlNormal});
int tintColor = a.getColor(0, mContext.getColor(android.R.color.white));
a.recycle();
for (int i = 0; i < categories.size(); i++) {
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProvider.java b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
index 7845829..20bcd3d 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProvider.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
@@ -31,11 +31,6 @@
public interface DashboardFeatureProvider {
/**
- * Whether or not this feature is enabled.
- */
- boolean isEnabled();
-
- /**
* Get tiles (wrapped in {@link DashboardCategory}) for key defined in CategoryKey.
*/
DashboardCategory getTilesForCategory(String key);
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 1184e89..9c21720 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -69,11 +69,6 @@
}
@Override
- public boolean isEnabled() {
- return true;
- }
-
- @Override
public DashboardCategory getTilesForCategory(String key) {
return mCategoryManager.getTilesByCategory(mContext, key);
}
@@ -81,9 +76,6 @@
@Override
public List<Preference> getPreferencesForCategory(Activity activity, Context context,
int sourceMetricsCategory, String key) {
- if (!isEnabled()) {
- return null;
- }
final DashboardCategory category = getTilesForCategory(key);
if (category == null) {
Log.d(TAG, "NO dashboard tiles for " + TAG);
@@ -177,7 +169,7 @@
@Override
public ProgressiveDisclosureMixin getProgressiveDisclosureMixin(Context context,
DashboardFragment fragment) {
- return new ProgressiveDisclosureMixin(context, this, mMetricsFeatureProvider, fragment);
+ return new ProgressiveDisclosureMixin(context, mMetricsFeatureProvider, fragment);
}
@Override
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 29cee5e..e3845cd 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -309,8 +309,7 @@
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
mSummaryLoader.setSummaryConsumer(this);
final TypedArray a = context.obtainStyledAttributes(new int[]{
- mDashboardFeatureProvider.isEnabled() ? android.R.attr.colorControlNormal
- : android.R.attr.colorAccent});
+ android.R.attr.colorControlNormal});
final int tintColor = a.getColor(0, context.getColor(android.R.color.white));
a.recycle();
final String pkgName = context.getPackageName();
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index 5206336..6482672 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -30,7 +30,6 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.dashboard.conditional.Condition;
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
@@ -87,12 +86,7 @@
mSuggestionFeatureProvider = FeatureFactory.getFactory(activity)
.getSuggestionFeatureProvider(activity);
- if (mDashboardFeatureProvider.isEnabled()) {
- mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
- } else {
- mSummaryLoader = new SummaryLoader(activity,
- ((SettingsActivity) getActivity()).getDashboardCategories());
- }
+ mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
mConditionManager = ConditionManager.get(activity, false);
mSuggestionParser = new SuggestionParser(activity,
@@ -279,20 +273,15 @@
return;
}
- if (mDashboardFeatureProvider.isEnabled()) {
- // Temporary hack to wrap homepage category into a list. Soon we will create adapter
- // API that takes a single category.
- List<DashboardCategory> categories = new ArrayList<>();
- categories.add(mDashboardFeatureProvider.getTilesForCategory(
- CategoryKey.CATEGORY_HOMEPAGE));
- if (suggestions != null) {
- mAdapter.setCategoriesAndSuggestions(categories, suggestions);
- } else {
- mAdapter.setCategory(categories);
- }
+ // Temporary hack to wrap homepage category into a list. Soon we will create adapter
+ // API that takes a single category.
+ List<DashboardCategory> categories = new ArrayList<>();
+ categories.add(mDashboardFeatureProvider.getTilesForCategory(
+ CategoryKey.CATEGORY_HOMEPAGE));
+ if (suggestions != null) {
+ mAdapter.setCategoriesAndSuggestions(categories, suggestions);
} else {
- mAdapter.setCategoriesAndSuggestions(
- ((SettingsActivity) activity).getDashboardCategories(), suggestions);
+ mAdapter.setCategory(categories);
}
}
}
diff --git a/src/com/android/settings/dashboard/ProgressiveDisclosureMixin.java b/src/com/android/settings/dashboard/ProgressiveDisclosureMixin.java
index 90c3d25..be5e21b 100644
--- a/src/com/android/settings/dashboard/ProgressiveDisclosureMixin.java
+++ b/src/com/android/settings/dashboard/ProgressiveDisclosureMixin.java
@@ -46,7 +46,6 @@
private static final int DEFAULT_TILE_LIMIT = 300;
private final Context mContext;
- private final DashboardFeatureProvider mDashboardFeatureProvider;
// Collapsed preference sorted by order.
private final List<Preference> mCollapsedPrefs = new ArrayList<>();
private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -57,14 +56,12 @@
private boolean mUserExpanded;
public ProgressiveDisclosureMixin(Context context,
- DashboardFeatureProvider dashboardFeatureProvider,
MetricsFeatureProvider metricsFeatureProvider,
PreferenceFragment fragment) {
mContext = context;
mFragment = fragment;
mExpandButton = new ExpandPreference(context);
mExpandButton.setOnPreferenceClickListener(this);
- mDashboardFeatureProvider = dashboardFeatureProvider;
mMetricsFeatureProvider = metricsFeatureProvider;
}
@@ -122,8 +119,7 @@
* Whether the screen should be collapsed.
*/
public boolean shouldCollapse(PreferenceScreen screen) {
- return mDashboardFeatureProvider.isEnabled() && screen.getPreferenceCount() >= mTileLimit
- && !mUserExpanded;
+ return screen.getPreferenceCount() >= mTileLimit && !mUserExpanded;
}
/**
diff --git a/src/com/android/settings/dashboard/SummaryLoader.java b/src/com/android/settings/dashboard/SummaryLoader.java
index 2f0d8b6..df21168 100644
--- a/src/com/android/settings/dashboard/SummaryLoader.java
+++ b/src/com/android/settings/dashboard/SummaryLoader.java
@@ -116,23 +116,8 @@
@Override
public void run() {
- final Tile tile;
- if (mDashboardFeatureProvider.isEnabled()) {
- tile = getTileFromCategory(
- mDashboardFeatureProvider.getTilesForCategory(mCategoryKey), component);
- } else {
- // Since tiles are not always cached (like on locale change for instance),
- // we need to always get the latest one.
- if (!(mActivity instanceof SettingsDrawerActivity)) {
- if (DEBUG) {
- Log.d(TAG, "Can't get category list.");
- }
- return;
- }
- tile = getTileFromCategory(
- ((SettingsDrawerActivity) mActivity).getDashboardCategories(),
- component);
- }
+ final Tile tile = getTileFromCategory(
+ mDashboardFeatureProvider.getTilesForCategory(mCategoryKey), component);
if (tile == null) {
if (DEBUG) {
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 29bd509..0431ce5 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -42,7 +42,6 @@
import android.widget.AdapterView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.applications.AppHeaderController;
import com.android.settings.applications.AppInfoBase;
@@ -354,24 +353,17 @@
}
final Activity activity = getActivity();
- if (!FeatureFactory.getFactory(activity)
- .getDashboardFeatureProvider(activity).isEnabled()) {
- View header = setPinnedHeaderView(R.layout.app_header);
- AppHeader.setupHeaderView(getActivity(), mIcon, mLabel,
- pkg, uid, AppHeader.includeAppInfo(this), 0, header, null);
- } else {
- final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, null /* appHeader */)
- .setIcon(mIcon)
- .setLabel(mLabel)
- .setPackageName(pkg)
- .setUid(uid)
- .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
- AppHeaderController.ActionType.ACTION_NONE)
- .done(getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, null /* appHeader */)
+ .setIcon(mIcon)
+ .setLabel(mLabel)
+ .setPackageName(pkg)
+ .setUid(uid)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NONE)
+ .done(getPrefContext());
+ getPreferenceScreen().addPreference(pref);
}
@Override
diff --git a/src/com/android/settings/datausage/DataUsageMeteredSettings.java b/src/com/android/settings/datausage/DataUsageMeteredSettings.java
index 1982887..ce2bc8d 100644
--- a/src/com/android/settings/datausage/DataUsageMeteredSettings.java
+++ b/src/com/android/settings/datausage/DataUsageMeteredSettings.java
@@ -114,7 +114,8 @@
}
private Preference buildWifiPref(WifiConfiguration config) {
- final String networkId = config.SSID;
+ final String networkId = config.isPasspoint() ?
+ config.providerFriendlyName : config.SSID;
final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(networkId);
final MeteredPreference pref = new MeteredPreference(getPrefContext(), template);
pref.setTitle(removeDoubleQuotes(networkId));
diff --git a/src/com/android/settings/ZonePicker.java b/src/com/android/settings/datetime/ZonePicker.java
similarity index 89%
rename from src/com/android/settings/ZonePicker.java
rename to src/com/android/settings/datetime/ZonePicker.java
index f6d6a6c..2d58dd8 100644
--- a/src/com/android/settings/ZonePicker.java
+++ b/src/com/android/settings/datetime/ZonePicker.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings;
+package com.android.settings.datetime;
import android.annotation.NonNull;
import android.app.Activity;
@@ -33,8 +33,9 @@
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
+import com.android.settings.R;
import com.android.settings.core.instrumentation.Instrumentable;
+import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
import com.android.settingslib.datetime.ZoneGetter;
import java.util.Collections;
@@ -52,11 +53,6 @@
*/
public class ZonePicker extends ListFragment implements Instrumentable {
- public interface ZoneSelectionListener {
- // You can add any argument if you really need it...
- void onZoneSelected(TimeZone tz);
- }
-
private static final int MENU_TIMEZONE = Menu.FIRST+1;
private static final int MENU_ALPHABETICAL = Menu.FIRST;
private final VisibilityLoggerMixin mVisibilityLoggerMixin =
@@ -67,8 +63,6 @@
private SimpleAdapter mTimezoneSortedAdapter;
private SimpleAdapter mAlphabeticalAdapter;
- private ZoneSelectionListener mListener;
-
/**
* Constructs an adapter with TimeZone list. Sorted by TimeZone in default.
*
@@ -148,15 +142,6 @@
return -1;
}
- /**
- * @param item one of items in adapters. The adapter should be constructed by
- * {@link #constructTimezoneAdapter(Context, boolean)}.
- * @return TimeZone object corresponding to the item.
- */
- public static TimeZone obtainTimeZoneFromItem(Object item) {
- return TimeZone.getTimeZone((String)((Map<?, ?>)item).get(ZoneGetter.KEY_ID));
- }
-
@Override
public void onAttach(Context context) {
super.onAttach(context);
@@ -185,8 +170,8 @@
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = super.onCreateView(inflater, container, savedInstanceState);
- final ListView list = (ListView) view.findViewById(android.R.id.list);
- Utils.forcePrepareCustomPreferencesList(container, view, list, false);
+ final ListView list = view.findViewById(android.R.id.list);
+ prepareCustomPreferencesList(list);
return view;
}
@@ -233,8 +218,10 @@
}
}
- public void setZoneSelectionListener(ZoneSelectionListener listener) {
- mListener = listener;
+ static void prepareCustomPreferencesList(ListView list) {
+ list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
+ list.setClipToPadding(false);
+ list.setDivider(null);
}
private void setSorting(boolean sortByTimezone) {
@@ -259,12 +246,9 @@
final Activity activity = getActivity();
final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
alarm.setTimeZone(tzId);
- final TimeZone tz = TimeZone.getTimeZone(tzId);
- if (mListener != null) {
- mListener.onZoneSelected(tz);
- } else {
- getActivity().onBackPressed();
- }
+
+ getActivity().onBackPressed();
+
}
@Override
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index bff0882..4d4cfe8 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -18,6 +18,7 @@
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.FragmentManager;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
diff --git a/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java b/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
index 1b47561..a2c4302 100644
--- a/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
@@ -15,10 +15,12 @@
*/
package com.android.settings.deviceinfo;
+import android.app.Fragment;
import android.content.Context;
import android.os.Build;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
import com.android.settings.core.PreferenceController;
import com.android.settingslib.DeviceInfoUtils;
@@ -27,8 +29,11 @@
private static final String KEY_DEVICE_MODEL = "device_model";
- public DeviceModelPreferenceController(Context context) {
+ private final Fragment mHost;
+
+ public DeviceModelPreferenceController(Context context, Fragment host) {
super(context);
+ mHost = host;
}
@Override
@@ -49,4 +54,14 @@
public String getPreferenceKey() {
return KEY_DEVICE_MODEL;
}
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), KEY_DEVICE_MODEL)) {
+ return false;
+ }
+ final HardwareInfoDialogFragment fragment = HardwareInfoDialogFragment.newInstance();
+ fragment.show(mHost.getFragmentManager(), HardwareInfoDialogFragment.TAG);
+ return true;
+ }
}
diff --git a/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java b/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java
new file mode 100644
index 0000000..d68b47a
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java
@@ -0,0 +1,82 @@
+/*
+ * 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.app.AlertDialog;
+import android.app.Dialog;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.SystemProperties;
+import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settingslib.DeviceInfoUtils;
+
+public class HardwareInfoDialogFragment extends InstrumentedDialogFragment {
+
+ public static final String TAG = "HardwareInfo";
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.DIALOG_SETTINGS_HARDWARE_INFO;
+ }
+
+ public static HardwareInfoDialogFragment newInstance() {
+ final HardwareInfoDialogFragment fragment = new HardwareInfoDialogFragment();
+ return fragment;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.hardware_info)
+ .setPositiveButton(android.R.string.ok, null);
+ final View content = LayoutInflater.from(builder.getContext())
+ .inflate(R.layout.dialog_hardware_info, null /* parent */);
+ // Model
+ setText(content, R.id.model_label, R.id.model_value,
+ Build.MODEL + DeviceInfoUtils.getMsvSuffix());
+ // Hardware rev
+ setText(content, R.id.hardware_rev_label, R.id.hardware_rev_value,
+ SystemProperties.get("ro.boot.hardware.revision"));
+
+ return builder.setView(content).create();
+ }
+
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ void setText(View content, int labelViewId, int valueViewId, String value) {
+ if (content == null) {
+ return;
+ }
+ final View labelView = content.findViewById(labelViewId);
+ final TextView valueView = content.findViewById(valueViewId);
+ if (!TextUtils.isEmpty(value)) {
+ labelView.setVisibility(View.VISIBLE);
+ valueView.setVisibility(View.VISIBLE);
+ valueView.setText(value);
+ } else {
+ labelView.setVisibility(View.GONE);
+ valueView.setVisibility(View.GONE);
+ }
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/ManageStoragePreferenceController.java b/src/com/android/settings/deviceinfo/ManageStoragePreferenceController.java
deleted file mode 100644
index 769b69b..0000000
--- a/src/com/android/settings/deviceinfo/ManageStoragePreferenceController.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.deviceinfo;
-
-import android.content.Context;
-
-import com.android.settings.R;
-import com.android.settings.core.PreferenceController;
-
-public class ManageStoragePreferenceController extends PreferenceController {
-
- public static final String KEY_MANAGE_STORAGE = "manage_storage";
-
- public ManageStoragePreferenceController(Context context) {
- super(context);
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_MANAGE_STORAGE;
- }
-
- @Override
- public boolean isAvailable() {
- return mContext.getResources().getBoolean(R.bool.config_storage_manager_settings_enabled);
- }
-}
-
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 298a7ad..133c56c 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -35,11 +35,11 @@
import com.android.settings.applications.UserManagerWrapperImpl;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.deviceinfo.storage.AutomaticStorageManagementSwitchPreferenceController;
import com.android.settings.deviceinfo.storage.SecondaryUserController;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
import com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.applications.StorageStatsSource;
@@ -147,7 +147,11 @@
mSecondaryUsers = SecondaryUserController.getSecondaryUserControllers(context, userManager);
controllers.addAll(mSecondaryUsers);
- controllers.add(new ManageStoragePreferenceController(context));
+ final AutomaticStorageManagementSwitchPreferenceController asmController =
+ new AutomaticStorageManagementSwitchPreferenceController(
+ context, mMetricsFeatureProvider, getFragmentManager());
+ getLifecycle().addObserver(asmController);
+ controllers.add(asmController);
return controllers;
}
@@ -174,10 +178,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.storage_dashboard_fragment;
return Arrays.asList(sir);
@@ -194,7 +194,6 @@
null /* volume */, new StorageManagerVolumeProvider(sm)));
controllers.addAll(SecondaryUserController.getSecondaryUserControllers(
context, userManager));
- controllers.add(new ManageStoragePreferenceController(context));
return controllers;
}
diff --git a/src/com/android/settings/deviceinfo/StorageProfileFragment.java b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
index 6ae03da..d6071c7 100644
--- a/src/com/android/settings/deviceinfo/StorageProfileFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
@@ -24,6 +24,7 @@
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
+import android.support.annotation.VisibleForTesting;
import android.util.SparseArray;
import com.android.internal.logging.nano.MetricsProto;
@@ -119,10 +120,26 @@
@Override
public void onLoadFinished(Loader<SparseArray<AppsStorageResult>> loader,
SparseArray<AppsStorageResult> result) {
- mPreferenceController.onLoadFinished(result.get(mUserId));
+ mPreferenceController.onLoadFinished(scrubAppsFromResult(result.get(mUserId)));
}
@Override
public void onLoaderReset(Loader<SparseArray<AppsStorageResult>> loader) {
}
+
+ @VisibleForTesting
+ void setPreferenceController(StorageItemPreferenceController controller) {
+ mPreferenceController = controller;
+ }
+
+ private AppsStorageResult scrubAppsFromResult(AppsStorageResult result) {
+ if (result == null) {
+ return null;
+ }
+
+ result.gamesSize = 0;
+ result.musicAppsSize = 0;
+ result.otherAppsSize = 0;
+ return result;
+ }
}
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index c062a56..b2bad3a 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -234,8 +234,8 @@
final Bundle args = new Bundle();
args.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
Intent intent = Utils.onBuildStartFragmentIntent(getActivity(),
- StorageDashboardFragment.class.getName(), args, null, R.string.apps_storage,
- null, false, getMetricsCategory());
+ StorageDashboardFragment.class.getName(), args, null,
+ R.string.storage_settings_2, null, false, getMetricsCategory());
intent.putExtra(SettingsDrawerActivity.EXTRA_SHOW_MENU, true);
getActivity().startActivity(intent);
finish();
@@ -280,7 +280,7 @@
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
startFragment(this, StorageDashboardFragment.class.getCanonicalName(),
- -1, 0, args);
+ R.string.storage_settings_2, 0, args);
} else {
// TODO: Go to the StorageDashboardFragment once it fully handles all of the
// SD card cases and other private internal storage cases.
diff --git a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
new file mode 100644
index 0000000..a8ca5b9
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
@@ -0,0 +1,100 @@
+/**
+ * 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.storage;
+
+import android.app.FragmentManager;
+import android.content.Context;
+import android.os.SystemProperties;
+import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.core.lifecycle.events.OnResume;
+import com.android.settings.deletionhelper.ActivationWarningFragment;
+import com.android.settings.widget.MasterSwitchController;
+import com.android.settings.widget.MasterSwitchPreference;
+import com.android.settings.widget.SwitchWidgetController;
+
+public class AutomaticStorageManagementSwitchPreferenceController extends PreferenceController
+ implements LifecycleObserver, OnResume, SwitchWidgetController.OnSwitchChangeListener {
+ private static final String KEY_TOGGLE_ASM = "toggle_asm";
+ @VisibleForTesting
+ static final String STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY = "ro.storage_manager.enabled";
+
+ private MasterSwitchPreference mSwitch;
+ private MasterSwitchController mSwitchController;
+ private final MetricsFeatureProvider mMetricsFeatureProvider;
+ private final FragmentManager mFragmentManager;
+
+ public AutomaticStorageManagementSwitchPreferenceController(Context context,
+ MetricsFeatureProvider metricsFeatureProvider, FragmentManager fragmentManager) {
+ super(context);
+ mMetricsFeatureProvider = metricsFeatureProvider;
+ mFragmentManager = fragmentManager;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mSwitch = (MasterSwitchPreference) screen.findPreference(KEY_TOGGLE_ASM);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_TOGGLE_ASM;
+ }
+
+ @Override
+ public void onResume() {
+ boolean isStorageManagerEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
+ mSwitch.setChecked(isStorageManagerEnabled);
+
+ if (mSwitch != null) {
+ mSwitchController = new MasterSwitchController(mSwitch);
+ mSwitchController.setListener(this);
+ mSwitchController.startListening();
+ }
+ }
+
+ @Override
+ public boolean onSwitchToggled(boolean isChecked) {
+ mMetricsFeatureProvider.action(mContext,
+ MetricsEvent.ACTION_TOGGLE_STORAGE_MANAGER, isChecked);
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
+ isChecked ? 1 : 0);
+
+ boolean storageManagerEnabledByDefault = SystemProperties.getBoolean(
+ STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, false);
+ if (isChecked && !storageManagerEnabledByDefault) {
+ ActivationWarningFragment fragment = ActivationWarningFragment.newInstance();
+ fragment.show(mFragmentManager, ActivationWarningFragment.TAG);
+ }
+
+ return true;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
index a5e8373..41800a2 100644
--- a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
+++ b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
@@ -97,7 +97,7 @@
@Override
public void displayPreference(PreferenceScreen screen) {
if (mStoragePreference == null) {
- mStoragePreference = new StorageItemPreferenceAlternate(mContext);
+ mStoragePreference = new StorageItemPreferenceAlternate(screen.getContext());
PreferenceGroup group =
(PreferenceGroup) screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 7487b28..2fa1b18 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -173,6 +173,8 @@
}
public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) {
+ // TODO(b/35927909): Figure out how to split out apps which are only installed for work
+ // profiles in order to attribute those app's code bytes only to that profile.
mPhotoPreference.setStorageSize(
data.externalStats.imageBytes + data.externalStats.videoBytes);
mAudioPreference.setStorageSize(data.musicAppsSize + data.externalStats.audioBytes);
diff --git a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java
index 8b6bac0..44d3d44 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java
@@ -80,23 +80,6 @@
if (deletionHelperButton != null) {
deletionHelperButton.setOnClickListener(this);
}
-
- final TextView storageManagerText =
- (TextView) view.findViewById(R.id.storage_manager_indicator);
- if (storageManagerText != null) {
- Context context = getContext();
- final SpannableString templateSs = new SpannableString(
- context.getString(R.string.storage_manager_indicator));
- boolean isStorageManagerEnabled = Settings.Secure.getInt(context.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
- String value = isStorageManagerEnabled ?
- context.getString(R.string.storage_manager_indicator_on) :
- context.getString(R.string.storage_manager_indicator_off);
- Locale locale = storageManagerText.getTextLocale();
- final SpannableString ss = new SpannableString(value.toUpperCase(locale));
- ss.setSpan(new BoldLinkSpan(), 0, value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- storageManagerText.setText(TextUtils.expandTemplate(templateSs, ss));
- }
}
@Override
diff --git a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
index a962669..c4613ed 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
@@ -17,7 +17,6 @@
package com.android.settings.deviceinfo.storage;
import android.content.Context;
-import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -26,7 +25,6 @@
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
-import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
/**
diff --git a/src/com/android/settings/deviceinfo/storage/UserProfileController.java b/src/com/android/settings/deviceinfo/storage/UserProfileController.java
index 5da9fec..963784d 100644
--- a/src/com/android/settings/deviceinfo/storage/UserProfileController.java
+++ b/src/com/android/settings/deviceinfo/storage/UserProfileController.java
@@ -60,7 +60,7 @@
@Override
public void displayPreference(PreferenceScreen screen) {
- mStoragePreference = new StorageItemPreferenceAlternate(mContext);
+ mStoragePreference = new StorageItemPreferenceAlternate(screen.getContext());
mStoragePreference.setOrder(mPreferenceOrder);
mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
mStoragePreference.setTitle(mUser.name);
diff --git a/src/com/android/settings/display/ThemePreferenceController.java b/src/com/android/settings/display/ThemePreferenceController.java
index e66e7ce..a8d47d6 100644
--- a/src/com/android/settings/display/ThemePreferenceController.java
+++ b/src/com/android/settings/display/ThemePreferenceController.java
@@ -15,15 +15,19 @@
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_THEME;
-import android.app.AlertDialog;
-import android.app.UiModeManager;
import android.content.Context;
-import android.content.DialogInterface.OnClickListener;
+import android.content.om.IOverlayManager;
+import android.content.om.OverlayInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
-
import android.text.TextUtils;
+
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
@@ -31,17 +35,27 @@
import libcore.util.Objects;
+import java.util.List;
+
public class ThemePreferenceController extends PreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String KEY_THEME = "theme";
- private final UiModeManager mUiModeManager;
private final MetricsFeatureProvider mMetricsFeatureProvider;
+ private final OverlayManager mOverlayService;
+ private final PackageManager mPackageManager;
public ThemePreferenceController(Context context) {
+ this(context, ServiceManager.getService(Context.OVERLAY_SERVICE) != null
+ ? new OverlayManager() : null);
+ }
+
+ @VisibleForTesting
+ ThemePreferenceController(Context context, OverlayManager overlayManager) {
super(context);
- mUiModeManager = context.getSystemService(UiModeManager.class);
+ mOverlayService = overlayManager;
+ mPackageManager = context.getPackageManager();
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
@@ -61,12 +75,18 @@
@Override
public void updateState(Preference preference) {
ListPreference pref = (ListPreference) preference;
- String[] options = getAvailableThemes();
- for (int i = 0; i < options.length; i++) {
- options[i] = nullToDefault(options[i]);
+ String[] pkgs = getAvailableThemes();
+ CharSequence[] labels = new CharSequence[pkgs.length];
+ for (int i = 0; i < pkgs.length; i++) {
+ try {
+ labels[i] = mPackageManager.getApplicationInfo(pkgs[i], 0)
+ .loadLabel(mPackageManager);
+ } catch (NameNotFoundException e) {
+ labels[i] = pkgs[i];
+ }
}
- pref.setEntries(options);
- pref.setEntryValues(options);
+ pref.setEntries(labels);
+ pref.setEntryValues(pkgs);
String theme = getCurrentTheme();
if (TextUtils.isEmpty(theme)) {
theme = mContext.getString(R.string.default_theme);
@@ -77,49 +97,76 @@
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (Objects.equal(newValue, mUiModeManager.getTheme())) {
+ String current = getTheme();
+ if (Objects.equal(newValue, current)) {
return true;
}
- // TODO: STOPSHIP Don't require reboot and remove this prompt.
- OnClickListener onConfirm = (d, i) -> {
- mUiModeManager.setTheme(defaultToNull((String) newValue));
- ((ListPreference) preference).setValue((String) newValue);
- };
- new AlertDialog.Builder(mContext)
- .setTitle(R.string.change_theme_reboot)
- .setPositiveButton(com.android.internal.R.string.global_action_restart, onConfirm)
- .setNegativeButton(android.R.string.cancel, null)
- .show();
- return false;
+ try {
+ mOverlayService.setEnabledExclusive((String) newValue, true, UserHandle.myUserId());
+ } catch (RemoteException e) {
+ return false;
+ }
+ return true;
+ }
+
+ private String getTheme() {
+ try {
+ List<OverlayInfo> infos = mOverlayService.getOverlayInfosForTarget("android",
+ UserHandle.myUserId());
+ for (int i = 0, size = infos.size(); i < size; i++) {
+ if (infos.get(i).isEnabled()) {
+ return infos.get(i).packageName;
+ }
+ }
+ } catch (RemoteException e) {
+ }
+ return null;
}
@Override
public boolean isAvailable() {
+ if (mOverlayService == null) return false;
String[] themes = getAvailableThemes();
return themes != null && themes.length > 1;
}
+
@VisibleForTesting
String getCurrentTheme() {
- return mUiModeManager.getTheme();
+ return getTheme();
}
@VisibleForTesting
String[] getAvailableThemes() {
- return mUiModeManager.getAvailableThemes();
+ try {
+ List<OverlayInfo> infos = mOverlayService.getOverlayInfosForTarget("android",
+ UserHandle.myUserId());
+ String[] pkgs = new String[infos.size()];
+ for (int i = 0, size = infos.size(); i < size; i++) {
+ pkgs[i] = infos.get(i).packageName;
+ }
+ return pkgs;
+ } catch (RemoteException e) {
+ }
+ return new String[0];
}
- private String nullToDefault(String input) {
- if (TextUtils.isEmpty(input)) {
- return mContext.getString(R.string.default_theme);
- }
- return input;
- }
+ public static class OverlayManager {
+ private final IOverlayManager mService;
- private String defaultToNull(String input) {
- if (mContext.getString(R.string.default_theme).equals(input)) {
- return null;
+ public OverlayManager() {
+ mService = IOverlayManager.Stub.asInterface(
+ ServiceManager.getService(Context.OVERLAY_SERVICE));
}
- return input;
+
+ public void setEnabledExclusive(String pkg, boolean enabled, int userId)
+ throws RemoteException {
+ mService.setEnabledExclusive(pkg, enabled, userId);
+ }
+
+ public List<OverlayInfo> getOverlayInfosForTarget(String target, int userId)
+ throws RemoteException {
+ return mService.getOverlayInfosForTarget(target, userId);
+ }
}
}
diff --git a/src/com/android/settings/enterprise/AdminActionPreferenceControllerBase.java b/src/com/android/settings/enterprise/AdminActionPreferenceControllerBase.java
index 6b72573..f6bd4c1 100644
--- a/src/com/android/settings/enterprise/AdminActionPreferenceControllerBase.java
+++ b/src/com/android/settings/enterprise/AdminActionPreferenceControllerBase.java
@@ -40,7 +40,7 @@
public void updateState(Preference preference) {
final Date timestamp = getAdminActionTimestamp();
preference.setSummary(timestamp == null ?
- mContext.getString(R.string.enterprise_privacy_never) :
+ mContext.getString(R.string.enterprise_privacy_none) :
DateUtils.formatDateTime(mContext, timestamp.getTime(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE));
}
diff --git a/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java b/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java
index a2137ff..35648c8 100644
--- a/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java
+++ b/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceController.java
@@ -17,8 +17,6 @@
import android.Manifest;
import android.content.Context;
-import com.android.settings.R;
-
public class AdminGrantedCameraPermissionPreferenceController extends
AdminGrantedPermissionsPreferenceControllerBase {
@@ -26,8 +24,7 @@
= "enterprise_privacy_number_camera_access_packages";
public AdminGrantedCameraPermissionPreferenceController(Context context) {
- super(context, new String[] {Manifest.permission.CAMERA},
- R.plurals.enterprise_privacy_number_camera_access_packages);
+ super(context, new String[] {Manifest.permission.CAMERA});
}
@Override
diff --git a/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java b/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java
index 0453b53..f570558 100644
--- a/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java
+++ b/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceController.java
@@ -17,8 +17,6 @@
import android.Manifest;
import android.content.Context;
-import com.android.settings.R;
-
public class AdminGrantedLocationPermissionsPreferenceController extends
AdminGrantedPermissionsPreferenceControllerBase {
@@ -27,8 +25,7 @@
public AdminGrantedLocationPermissionsPreferenceController(Context context) {
super(context, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
- Manifest.permission.ACCESS_FINE_LOCATION},
- R.plurals.enterprise_privacy_number_location_access_packages);
+ Manifest.permission.ACCESS_FINE_LOCATION});
}
@Override
diff --git a/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java b/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java
index 3adde92..842235d 100644
--- a/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java
+++ b/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceController.java
@@ -17,8 +17,6 @@
import android.Manifest;
import android.content.Context;
-import com.android.settings.R;
-
public class AdminGrantedMicrophonePermissionPreferenceController extends
AdminGrantedPermissionsPreferenceControllerBase {
@@ -26,8 +24,7 @@
= "enterprise_privacy_number_microphone_access_packages";
public AdminGrantedMicrophonePermissionPreferenceController(Context context) {
- super(context, new String[] {Manifest.permission.RECORD_AUDIO},
- R.plurals.enterprise_privacy_number_microphone_access_packages);
+ super(context, new String[] {Manifest.permission.RECORD_AUDIO});
}
@Override
diff --git a/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java b/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java
index 2ca5451..2b972a5 100644
--- a/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java
+++ b/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBase.java
@@ -18,6 +18,7 @@
import android.content.res.Resources;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.core.PreferenceController;
import com.android.settings.overlay.FeatureFactory;
@@ -25,14 +26,11 @@
public abstract class AdminGrantedPermissionsPreferenceControllerBase extends PreferenceController {
private final String[] mPermissions;
- private final int mStringResourceId;
private final ApplicationFeatureProvider mFeatureProvider;
- public AdminGrantedPermissionsPreferenceControllerBase(Context context, String[] permissions,
- int stringResourceId) {
+ public AdminGrantedPermissionsPreferenceControllerBase(Context context, String[] permissions) {
super(context);
mPermissions = permissions;
- mStringResourceId = stringResourceId;
mFeatureProvider = FeatureFactory.getFactory(context)
.getApplicationFeatureProvider(context);
}
@@ -45,8 +43,8 @@
preference.setVisible(false);
} else {
preference.setVisible(true);
- preference.setTitle(mContext.getResources().getQuantityString(
- mStringResourceId, num, num));
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_packages, num, num));
}
});
}
diff --git a/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceController.java b/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceController.java
new file mode 100644
index 0000000..c8ea551
--- /dev/null
+++ b/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceController.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.enterprise;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+public class CaCertsCurrentUserPreferenceController extends PreferenceController {
+
+ private static final String CA_CERTS_CURRENT_USER = "ca_certs_current_user";
+ private final EnterprisePrivacyFeatureProvider mFeatureProvider;
+
+ public CaCertsCurrentUserPreferenceController(Context context) {
+ super(context);
+ mFeatureProvider = FeatureFactory.getFactory(context)
+ .getEnterprisePrivacyFeatureProvider(context);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final int certs = mFeatureProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser();
+ if (certs == 0) {
+ preference.setVisible(false);
+ return;
+ }
+ preference.setTitle(mContext.getResources().getQuantityString(
+ mFeatureProvider.isInCompMode() ? R.plurals.enterprise_privacy_ca_certs_personal :
+ R.plurals.enterprise_privacy_ca_certs_user, certs));
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_ca_certs, certs, certs));
+ preference.setVisible(true);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return CA_CERTS_CURRENT_USER;
+ }
+}
diff --git a/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceController.java b/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceController.java
new file mode 100644
index 0000000..33224ae
--- /dev/null
+++ b/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceController.java
@@ -0,0 +1,59 @@
+/*
+ * 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.enterprise;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+public class CaCertsManagedProfilePreferenceController extends PreferenceController {
+
+ private static final String KEY_CA_CERTS_MANAGED_PROFILE = "ca_certs_managed_profile";
+ private final EnterprisePrivacyFeatureProvider mFeatureProvider;
+
+ public CaCertsManagedProfilePreferenceController(Context context) {
+ super(context);
+ mFeatureProvider = FeatureFactory.getFactory(context)
+ .getEnterprisePrivacyFeatureProvider(context);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final int certs = mFeatureProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile();
+ if (certs == 0) {
+ preference.setVisible(false);
+ return;
+ }
+ preference.setTitle(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_ca_certs_work, certs));
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_ca_certs, certs, certs));
+ preference.setVisible(true);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_CA_CERTS_MANAGED_PROFILE;
+ }
+}
diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java
index 014092f..7fae8bb 100644
--- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java
+++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java
@@ -16,9 +16,13 @@
package com.android.settings.enterprise;
+import android.annotation.NonNull;
import android.content.ComponentName;
+import android.os.UserHandle;
import android.support.annotation.Nullable;
+import java.util.List;
+
/**
* This interface replicates a subset of the android.app.admin.DevicePolicyManager (DPM). The
* interface exists so that we can use a thin wrapper around the DPM in production code and a mock
@@ -89,4 +93,19 @@
* @see android.app.admin.DevicePolicyManager#getLastNetworkLogRetrievalTime
*/
long getLastNetworkLogRetrievalTime();
+
+ /**
+ * Calls {@code DevicePolicyManager.isCurrentInputMethodSetByOwner()}.
+ *
+ * @see android.app.admin.DevicePolicyManager#isCurrentInputMethodSetByOwner
+ */
+ boolean isCurrentInputMethodSetByOwner();
+
+
+ /**
+ * Calls {@code DevicePolicyManager.getOwnerInstalledCaCerts()}.
+ *
+ * @see android.app.admin.DevicePolicyManager#getOwnerInstalledCaCerts
+ */
+ List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user);
}
diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java
index 210faec..76264b4 100644
--- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java
+++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java
@@ -16,10 +16,14 @@
package com.android.settings.enterprise;
+import android.annotation.NonNull;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
+import android.os.UserHandle;
import android.support.annotation.Nullable;
+import java.util.List;
+
public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrapper {
private final DevicePolicyManager mDpm;
@@ -72,4 +76,14 @@
public long getLastNetworkLogRetrievalTime() {
return mDpm.getLastNetworkLogRetrievalTime();
}
+
+ @Override
+ public boolean isCurrentInputMethodSetByOwner() {
+ return mDpm.isCurrentInputMethodSetByOwner();
+ }
+
+ @Override
+ public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
+ return mDpm.getOwnerInstalledCaCerts(user);
+ }
}
diff --git a/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java b/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java
index 1fbb04a..9b4be3a 100644
--- a/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java
+++ b/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceController.java
@@ -44,9 +44,8 @@
preference.setVisible(false);
} else {
preference.setVisible(true);
- preference.setTitle(mContext.getResources().getQuantityString(
- R.plurals.enterprise_privacy_number_enterprise_installed_packages,
- num, num));
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_packages, num, num));
}
});
}
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
index 79b12e6..792c3ac 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
@@ -16,8 +16,6 @@
package com.android.settings.enterprise;
-import android.content.Context;
-
import java.util.Date;
public interface EnterprisePrivacyFeatureProvider {
@@ -37,10 +35,8 @@
* Returns a message informing the user that the device is managed by a Device Owner app. The
* message includes a Learn More link that takes the user to the enterprise privacy section of
* Settings. If the device is not managed by a Device Owner app, returns {@code null}.
- *
- * @param context The context in which to show the enterprise privacy section of Settings
*/
- CharSequence getDeviceOwnerDisclosure(Context context);
+ CharSequence getDeviceOwnerDisclosure();
/**
* Returns the time at which the Device Owner last retrieved security logs, or {@code null} if
@@ -86,4 +82,22 @@
* user's managed profile (if any) is wiped, or zero if no such limit is set.
*/
int getMaximumFailedPasswordsBeforeWipeInManagedProfile();
+
+ /**
+ * Returns the label of the current user's input method if that input method was set by a Device
+ * Owner or Profile Owner in that user. Otherwise, returns {@code null}.
+ */
+ String getImeLabelIfOwnerSet();
+
+ /**
+ * Returns the number of CA certificates that the Device Owner or Profile Owner installed in
+ * the current user.
+ */
+ int getNumberOfOwnerInstalledCaCertsInCurrentUser();
+
+ /**
+ * Returns the number of CA certificates that the Profile Owner installed in the current user's
+ * managed profile (if any).
+ */
+ int getNumberOfOwnerInstalledCaCertsInManagedProfile();
}
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index 645a1f5..3b8251c 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -17,8 +17,10 @@
package com.android.settings.enterprise;
import android.content.ComponentName;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
@@ -39,6 +41,7 @@
public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFeatureProvider {
+ private final Context mContext;
private final DevicePolicyManagerWrapper mDpm;
private final PackageManagerWrapper mPm;
private final UserManager mUm;
@@ -47,9 +50,10 @@
private static final int MY_USER_ID = UserHandle.myUserId();
- public EnterprisePrivacyFeatureProviderImpl(DevicePolicyManagerWrapper dpm,
+ public EnterprisePrivacyFeatureProviderImpl(Context context, DevicePolicyManagerWrapper dpm,
PackageManagerWrapper pm, UserManager um, ConnectivityManagerWrapper cm,
Resources resources) {
+ mContext = context.getApplicationContext();
mDpm = dpm;
mPm = pm;
mUm = um;
@@ -80,7 +84,7 @@
}
@Override
- public CharSequence getDeviceOwnerDisclosure(Context context) {
+ public CharSequence getDeviceOwnerDisclosure() {
if (!hasDeviceOwner()) {
return null;
}
@@ -95,7 +99,7 @@
}
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
- new EnterprisePrivacySpan(context), 0);
+ new EnterprisePrivacySpan(mContext), 0);
return disclosure;
}
@@ -156,6 +160,40 @@
return mDpm.getMaximumFailedPasswordsForWipe(profileOwner, userId);
}
+ @Override
+ public String getImeLabelIfOwnerSet() {
+ if (!mDpm.isCurrentInputMethodSetByOwner()) {
+ return null;
+ }
+ final String packageName = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+ Settings.Secure.DEFAULT_INPUT_METHOD, MY_USER_ID);
+ if (packageName == null) {
+ return null;
+ }
+ try {
+ return mPm.getApplicationInfoAsUser(packageName, 0 /* flags */, MY_USER_ID)
+ .loadLabel(mPm.getPackageManager()).toString();
+ } catch (PackageManager.NameNotFoundException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public int getNumberOfOwnerInstalledCaCertsInCurrentUser() {
+ final List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(MY_USER_ID));
+ return certs != null ? certs.size() : 0;
+ }
+
+ @Override
+ public int getNumberOfOwnerInstalledCaCertsInManagedProfile() {
+ final int userId = getManagedProfileUserId();
+ if (userId == UserHandle.USER_NULL) {
+ return 0;
+ }
+ final List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(userId));
+ return certs != null ? certs.size() : 0;
+ }
+
protected static class EnterprisePrivacySpan extends ClickableSpan {
private final Context mContext;
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
index 821b7ff..140a05c 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
@@ -63,8 +63,11 @@
controllers.add(new AlwaysOnVpnPrimaryUserPreferenceController(context));
controllers.add(new AlwaysOnVpnManagedProfilePreferenceController(context));
controllers.add(new GlobalHttpProxyPreferenceController(context));
+ controllers.add(new CaCertsCurrentUserPreferenceController(context));
+ controllers.add(new CaCertsManagedProfilePreferenceController(context));
controllers.add(new FailedPasswordWipePrimaryUserPreferenceController(context));
controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context));
+ controllers.add(new ImePreferenceController(context));
return controllers;
}
diff --git a/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java b/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java
index 23627cd..08a72e3 100644
--- a/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java
+++ b/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceController.java
@@ -68,9 +68,8 @@
preference.setVisible(false);
} else {
preference.setVisible(true);
- preference.setTitle(mContext.getResources().getQuantityString(
- R.plurals.enterprise_privacy_number_enterprise_set_default_apps,
- num, num));
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_packages, num, num));
}
}
diff --git a/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java b/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java
index 2eac0a9..5a0e7c8 100644
--- a/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java
+++ b/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceController.java
@@ -15,8 +15,6 @@
import android.content.Context;
-import com.android.settings.R;
-
public class FailedPasswordWipeManagedProfilePreferenceController
extends FailedPasswordWipePreferenceControllerBase {
@@ -24,7 +22,7 @@
= "failed_password_wipe_managed_profile";
public FailedPasswordWipeManagedProfilePreferenceController(Context context) {
- super(context, R.plurals.enterprise_privacy_failed_password_wipe_work);
+ super(context);
}
@Override
diff --git a/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java b/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java
index 7cdd8da..ee4aecf 100644
--- a/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java
+++ b/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBase.java
@@ -18,17 +18,16 @@
import android.content.res.Resources;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.overlay.FeatureFactory;
public abstract class FailedPasswordWipePreferenceControllerBase extends PreferenceController {
- private final int mStringResourceId;
protected final EnterprisePrivacyFeatureProvider mFeatureProvider;
- public FailedPasswordWipePreferenceControllerBase(Context context, int stringResourceId) {
+ public FailedPasswordWipePreferenceControllerBase(Context context) {
super(context);
- mStringResourceId = stringResourceId;
mFeatureProvider = FeatureFactory.getFactory(context)
.getEnterprisePrivacyFeatureProvider(context);
}
@@ -42,8 +41,9 @@
preference.setVisible(false);
} else {
preference.setVisible(true);
- preference.setTitle(mContext.getResources().getQuantityString(
- mStringResourceId, failedPasswordsBeforeWipe, failedPasswordsBeforeWipe));
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_failed_password_wipe,
+ failedPasswordsBeforeWipe, failedPasswordsBeforeWipe));
}
}
diff --git a/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java b/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java
index 91bdf9b..44c6383 100644
--- a/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java
+++ b/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceController.java
@@ -15,8 +15,6 @@
import android.content.Context;
-import com.android.settings.R;
-
public class FailedPasswordWipePrimaryUserPreferenceController
extends FailedPasswordWipePreferenceControllerBase {
@@ -24,7 +22,7 @@
= "failed_password_wipe_primary_user";
public FailedPasswordWipePrimaryUserPreferenceController(Context context) {
- super(context, R.plurals.enterprise_privacy_failed_password_wipe_device);
+ super(context);
}
@Override
diff --git a/src/com/android/settings/enterprise/ImePreferenceController.java b/src/com/android/settings/enterprise/ImePreferenceController.java
new file mode 100644
index 0000000..3c0cc26
--- /dev/null
+++ b/src/com/android/settings/enterprise/ImePreferenceController.java
@@ -0,0 +1,57 @@
+/*
+ * 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.enterprise;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+public class ImePreferenceController extends PreferenceController {
+
+ private static final String KEY_INPUT_METHOD = "input_method";
+ private final EnterprisePrivacyFeatureProvider mFeatureProvider;
+
+ public ImePreferenceController(Context context) {
+ super(context);
+ mFeatureProvider = FeatureFactory.getFactory(context)
+ .getEnterprisePrivacyFeatureProvider(context);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final String ownerSetIme = mFeatureProvider.getImeLabelIfOwnerSet();
+ if (ownerSetIme == null) {
+ preference.setVisible(false);
+ return;
+ }
+ preference.setSummary(mContext.getResources().getString(
+ R.string.enterprise_privacy_input_method_name, ownerSetIme));
+ preference.setVisible(true);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_INPUT_METHOD;
+ }
+}
diff --git a/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java b/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java
index 91ac4c2..4252429 100644
--- a/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java
+++ b/src/com/android/settings/enterprise/InstalledPackagesPreferenceController.java
@@ -24,7 +24,7 @@
public class InstalledPackagesPreferenceController extends PreferenceController {
- private static final String KEY_NUMBER_INSTALLED_PACKAGES = "number_installed_packages";
+ private static final String KEY_INSTALLED_PACKAGES = "installed_packages";
private final ApplicationFeatureProvider mFeatureProvider;
public InstalledPackagesPreferenceController(Context context) {
@@ -38,8 +38,12 @@
mFeatureProvider.calculateNumberOfInstalledApps(
ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
(num) -> {
- preference.setTitle(mContext.getResources().getQuantityString(
- R.plurals.enterprise_privacy_number_installed_packages, num, num));
+ if (num == 0) {
+ preference.setSummary("");
+ } else {
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_packages, num, num));
+ }
});
}
@@ -50,6 +54,6 @@
@Override
public String getPreferenceKey() {
- return KEY_NUMBER_INSTALLED_PACKAGES;
+ return KEY_INSTALLED_PACKAGES;
}
}
diff --git a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
new file mode 100644
index 0000000..0f08398
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * 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.app.AppOpsManager;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.support.annotation.VisibleForTesting;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.util.Log;
+import com.android.settings.core.PreferenceController;
+
+/**
+ * Controller to control whether an app can run in the background
+ */
+public class BackgroundActivityPreferenceController extends PreferenceController implements
+ Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "BgActivityPrefContr";
+ private static final String KEY_BACKGROUND_ACTIVITY = "background_activity";
+
+ private final PackageManager mPackageManager;
+ private final AppOpsManager mAppOpsManager;
+ private final String[] mPackages;
+ private final int mUid;
+
+ private String mTargetPackage;
+
+ public BackgroundActivityPreferenceController(Context context, int uid) {
+ super(context);
+ mPackageManager = context.getPackageManager();
+ mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
+ mUid = uid;
+ mPackages = mPackageManager.getPackagesForUid(mUid);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final int mode = mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid, mTargetPackage);
+
+ if (mode == AppOpsManager.MODE_ERRORED) {
+ preference.setEnabled(false);
+ } else {
+ ((SwitchPreference) preference).setChecked(mode != AppOpsManager.MODE_IGNORED);
+ }
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (mPackages == null) {
+ return false;
+ }
+ for (final String packageName : mPackages) {
+ if (isLegacyApp(packageName)) {
+ mTargetPackage = packageName;
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BACKGROUND_ACTIVITY;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ boolean switchOn = (Boolean) newValue;
+ mAppOpsManager.setUidMode(AppOpsManager.OP_RUN_IN_BACKGROUND, mUid,
+ switchOn ? AppOpsManager.MODE_DEFAULT : AppOpsManager.MODE_IGNORED);
+
+ return true;
+ }
+
+ @VisibleForTesting
+ boolean isLegacyApp(final String packageName) {
+ try {
+ ApplicationInfo info = mPackageManager.getApplicationInfo(packageName,
+ PackageManager.GET_META_DATA);
+
+ return info.targetSdkVersion < Build.VERSION_CODES.O;
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Cannot find package: " + packageName, e);
+ }
+
+ return false;
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index fc96340..96ac042 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -16,7 +16,6 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
-import android.os.Process;
import android.provider.SearchIndexableResource;
import android.support.annotation.ColorInt;
import android.support.annotation.IntDef;
@@ -40,10 +39,8 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
public class PowerUsageAdvanced extends PowerUsageBase {
private static final String TAG = "AdvancedBatteryUsage";
@@ -59,7 +56,8 @@
UsageType.BLUETOOTH,
UsageType.USER,
UsageType.IDLE,
- UsageType.APP};
+ UsageType.APP,
+ UsageType.UNACCOUNTED};
private BatteryHistoryPreference mHistPref;
private PreferenceGroup mUsageListGroup;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@@ -114,7 +112,7 @@
mUsageListGroup.removeAll();
for (int i = 0, size = dataList.size(); i < size; i++) {
final PowerUsageData batteryData = dataList.get(i);
- final PowerGaugePreference pref = new PowerGaugePreference(getContext());
+ final PowerGaugePreference pref = new PowerGaugePreference(getPrefContext());
pref.setTitle(batteryData.titleResId);
pref.setSummary(batteryData.summary);
@@ -139,6 +137,8 @@
return UsageType.USER;
} else if (drainType == DrainType.CELL) {
return UsageType.CELL;
+ } else if (drainType == DrainType.UNACCOUNTED) {
+ return UsageType.UNACCOUNTED;
} else if (mPowerUsageFeatureProvider.isTypeSystem(sipper)) {
return UsageType.SYSTEM;
} else if (mPowerUsageFeatureProvider.isTypeService(sipper)) {
@@ -200,7 +200,8 @@
UsageType.SYSTEM,
UsageType.BLUETOOTH,
UsageType.USER,
- UsageType.IDLE})
+ UsageType.IDLE,
+ UsageType.UNACCOUNTED})
public @interface UsageType {
int APP = 0;
int WIFI = 1;
@@ -210,6 +211,7 @@
int BLUETOOTH = 5;
int USER = 6;
int IDLE = 7;
+ int UNACCOUNTED = 8;
}
@StringRes
@@ -249,6 +251,8 @@
return R.string.power_user;
case UsageType.IDLE:
return R.string.power_idle;
+ case UsageType.UNACCOUNTED:
+ return R.string.power_unaccounted;
case UsageType.APP:
default:
return R.string.power_apps;
@@ -267,10 +271,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.power_usage_advanced;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
index 1598011..956b279 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java
@@ -34,7 +34,6 @@
import android.os.Bundle;
import android.os.Process;
import android.os.UserHandle;
-import android.provider.SearchIndexableResource;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
@@ -62,13 +61,12 @@
import com.android.settings.location.LocationSettings;
import com.android.settings.network.NetworkDashboardFragment;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.wifi.WifiSettings;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.List;
public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickListener {
@@ -327,13 +325,11 @@
private PackageManager mPm;
private DevicePolicyManager mDpm;
- private int mUsageSince;
private int[] mTypes;
private int mUid;
private double[] mValues;
private Button mForceStopButton;
private Button mReportButton;
- private long mStartTime;
private BatterySipper.DrainType mDrainType;
private double mNoCoverage; // Percentage of time that there was no coverage
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@@ -379,7 +375,6 @@
@Override
public void onResume() {
super.onResume();
- mStartTime = android.os.Process.getElapsedCpuTime();
checkForceStop();
if (mHighPower != null) {
mHighPower.setSummary(HighPowerDetail.getSummary(getActivity(), mApp.packageName));
@@ -400,7 +395,11 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- return null;
+ final List<PreferenceController> controllers = new ArrayList<>();
+ final int uid = getArguments().getInt(EXTRA_UID, 0);
+ controllers.add(new BackgroundActivityPreferenceController(context, uid));
+
+ return controllers;
}
@Override
@@ -414,7 +413,6 @@
private void createDetails() {
final Bundle args = getArguments();
Context context = getActivity();
- mUsageSince = args.getInt(EXTRA_USAGE_SINCE, USAGE_SINCE_UNPLUGGED);
mUid = args.getInt(EXTRA_UID, 0);
mPackages = context.getPackageManager().getPackagesForUid(mUid);
mDrainType = (BatterySipper.DrainType) args.getSerializable(EXTRA_DRAIN_TYPE);
@@ -514,29 +512,23 @@
if (pkg == null && mPackages != null) {
pkg = mPackages[0];
}
- if (!FeatureFactory.getFactory(activity)
- .getDashboardFeatureProvider(activity).isEnabled()) {
- AppHeader.createAppHeader(this, appIcon, title, pkg, uid,
- mDrainType != DrainType.APP ? android.R.color.white : 0);
- } else {
- final PreferenceScreen screen = getPreferenceScreen();
- final Preference appHeaderPref =
- findPreference(AppHeaderController.PREF_KEY_APP_HEADER);
- if (appHeaderPref != null) {
- return;
- }
- final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this, null /* appHeader */)
- .setIcon(appIcon)
- .setLabel(title)
- .setPackageName(pkg)
- .setUid(uid)
- .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
- AppHeaderController.ActionType.ACTION_NONE)
- .done(getPrefContext());
- screen.addPreference(pref);
+ final PreferenceScreen screen = getPreferenceScreen();
+ final Preference appHeaderPref =
+ findPreference(AppHeaderController.PREF_KEY_APP_HEADER);
+ if (appHeaderPref != null) {
+ return;
}
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, null /* appHeader */)
+ .setIcon(appIcon)
+ .setLabel(title)
+ .setPackageName(pkg)
+ .setUid(uid)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NONE)
+ .done(getPrefContext());
+ screen.addPreference(pref);
}
@Override
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 55fcaf8..44f61c1 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -733,10 +733,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.power_usage_summary;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/gestures/AssistGesturePreferenceController.java b/src/com/android/settings/gestures/AssistGesturePreferenceController.java
index 99d38b6..f0ba888 100644
--- a/src/com/android/settings/gestures/AssistGesturePreferenceController.java
+++ b/src/com/android/settings/gestures/AssistGesturePreferenceController.java
@@ -17,29 +17,90 @@
package com.android.settings.gestures;
import android.content.Context;
+import android.net.Uri;
import android.provider.Settings;
import android.support.v7.preference.Preference;
-import android.util.ArrayMap;
+import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.applications.assist.AssistSettingObserver;
import com.android.settings.core.lifecycle.Lifecycle;
+import com.android.settings.core.lifecycle.events.OnPause;
+import com.android.settings.core.lifecycle.events.OnResume;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.search2.InlineSwitchPayload;
-import com.android.settings.search2.ResultPayload;
-public class AssistGesturePreferenceController extends GesturePreferenceController {
+import java.util.Arrays;
+import java.util.List;
+
+public class AssistGesturePreferenceController extends GesturePreferenceController
+ implements OnPause, OnResume {
private static final String PREF_KEY_VIDEO = "gesture_assist_video";
private static final String PREF_KEY_ASSIST_GESTURE = "gesture_assist";
+ private final AssistGestureFeatureProvider mFeatureProvider;
+ private final SettingObserver mSettingObserver;
+ private boolean mWasAvailable;
+
+ private PreferenceScreen mScreen;
+ private Preference mPreference;
+
public AssistGesturePreferenceController(Context context, Lifecycle lifecycle) {
super(context, lifecycle);
+ mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
+ mSettingObserver = new SettingObserver();
+ mWasAvailable = isAvailable();
}
@Override
public boolean isAvailable() {
- AssistGestureFeatureProvider provider =
- FeatureFactory.getFactory(mContext).getAssistGestureFeatureProvider();
- return provider.isSupported(mContext);
+ return mFeatureProvider.isSupported(mContext);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ mScreen = screen;
+ mPreference = screen.findPreference(getPreferenceKey());
+ // Call super last or AbstractPreferenceController might remove the preference from the
+ // screen (if !isAvailable()) before we can save a reference to it.
+ super.displayPreference(screen);
+ }
+
+ @Override
+ public void onResume() {
+ mSettingObserver.register(mContext.getContentResolver(), true /* register */);
+ if (mWasAvailable != isAvailable()) {
+ // Only update the preference visibility if the availability has changed -- otherwise
+ // the preference may be incorrectly added to screens with collapsed sections.
+ updatePreference();
+ mWasAvailable = isAvailable();
+ }
+ }
+
+ @Override
+ public void onPause() {
+ mSettingObserver.register(mContext.getContentResolver(), false /* register */);
+ }
+
+ private void updatePreference() {
+ if (mPreference == null) {
+ return;
+ }
+
+ if (isAvailable()) {
+ if (mScreen.findPreference(getPreferenceKey()) == null) {
+ mScreen.addPreference(mPreference);
+ }
+ } else {
+ mScreen.removePreference(mPreference);
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean enabled = (boolean) newValue;
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_ENABLED, enabled ? 1 : 0);
+ return true;
}
@Override
@@ -53,17 +114,28 @@
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean enabled = (boolean) newValue;
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.ASSIST_GESTURE_ENABLED, enabled ? 1 : 0);
- return true;
- }
-
- @Override
protected boolean isSwitchPrefEnabled() {
final int assistGestureEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
return assistGestureEnabled != 0;
}
+
+ class SettingObserver extends AssistSettingObserver {
+
+ private final Uri ASSIST_GESTURE_ENABLED_URI =
+ Settings.Secure.getUriFor(Settings.Secure.ASSIST_GESTURE_ENABLED);
+
+ @Override
+ protected List<Uri> getSettingUris() {
+ return Arrays.asList(ASSIST_GESTURE_ENABLED_URI);
+ }
+
+ @Override
+ public void onSettingChange() {
+ if (mWasAvailable != isAvailable()) {
+ updatePreference();
+ mWasAvailable = isAvailable();
+ }
+ }
+ }
}
diff --git a/src/com/android/settings/gestures/AssistGestureSensitivityPreferenceController.java b/src/com/android/settings/gestures/AssistGestureSensitivityPreferenceController.java
new file mode 100644
index 0000000..5334e62
--- /dev/null
+++ b/src/com/android/settings/gestures/AssistGestureSensitivityPreferenceController.java
@@ -0,0 +1,151 @@
+/*
+ * 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.gestures;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.SeekBarPreference;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
+import com.android.settings.core.lifecycle.LifecycleObserver;
+import com.android.settings.core.lifecycle.events.OnPause;
+import com.android.settings.core.lifecycle.events.OnResume;
+import com.android.settings.overlay.FeatureFactory;
+
+public class AssistGestureSensitivityPreferenceController extends PreferenceController
+ implements Preference.OnPreferenceChangeListener, LifecycleObserver, OnPause, OnResume {
+
+ private static final String PREF_KEY_ASSIST_GESTURE_SENSITIVITY = "gesture_assist_sensitivity";
+
+ private final AssistGestureFeatureProvider mFeatureProvider;
+ private final SettingObserver mSettingObserver;
+
+ private PreferenceScreen mScreen;
+ private SeekBarPreference mPreference;
+
+ public AssistGestureSensitivityPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context);
+ mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
+ mSettingObserver = new SettingObserver();
+
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ mSettingObserver.register(mContext.getContentResolver(), true /* register */);
+ updatePreference();
+ }
+
+ @Override
+ public void onPause() {
+ mSettingObserver.register(mContext.getContentResolver(), false /* register */);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ // The sensitivity control is contingent on the assist gesture being supported and the
+ // gesture being enabled.
+ final int gestureEnabled = Settings.Secure.getInt(
+ mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_ENABLED,
+ 1);
+ return (gestureEnabled == 1) && mFeatureProvider.isSupported(mContext);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ mScreen = screen;
+ mPreference = (SeekBarPreference) screen.findPreference(getPreferenceKey());
+ // Call super last or AbstractPreferenceController might remove the preference from the
+ // screen (if !isAvailable()) before we can save a reference to it.
+ super.displayPreference(screen);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ updatePreference();
+ }
+
+ private void updatePreference() {
+ if (mPreference == null) {
+ return;
+ }
+
+ if (isAvailable()) {
+ if (mScreen.findPreference(getPreferenceKey()) == null) {
+ mScreen.addPreference(mPreference);
+ }
+ } else {
+ mScreen.removePreference(mPreference);
+ }
+
+ final int sensitivity = Settings.Secure.getInt(
+ mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_SENSITIVITY,
+ mPreference.getProgress());
+ mPreference.setProgress(sensitivity);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final int sensitivity = (int) newValue;
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_SENSITIVITY, sensitivity);
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_ASSIST_GESTURE_SENSITIVITY;
+ }
+
+ class SettingObserver extends ContentObserver {
+
+ private final Uri ASSIST_GESTURE_ENABLED_URI =
+ Settings.Secure.getUriFor(Settings.Secure.ASSIST_GESTURE_ENABLED);
+ private final Uri ASSIST_GESTURE_SENSITIVITY_URI =
+ Settings.Secure.getUriFor(Settings.Secure.ASSIST_GESTURE_SENSITIVITY);
+
+ public SettingObserver() {
+ super(null /* handler */);
+ }
+
+ public void register(ContentResolver cr, boolean register) {
+ if (register) {
+ cr.registerContentObserver(ASSIST_GESTURE_ENABLED_URI, false, this);
+ cr.registerContentObserver(ASSIST_GESTURE_SENSITIVITY_URI, false, this);
+ } else {
+ cr.unregisterContentObserver(this);
+ }
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ updatePreference();
+ }
+ }
+}
diff --git a/src/com/android/settings/gestures/AssistGestureSettings.java b/src/com/android/settings/gestures/AssistGestureSettings.java
index 1d82720..238b8b6 100644
--- a/src/com/android/settings/gestures/AssistGestureSettings.java
+++ b/src/com/android/settings/gestures/AssistGestureSettings.java
@@ -24,7 +24,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -59,6 +58,7 @@
Lifecycle lifecycle) {
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new AssistGesturePreferenceController(context, lifecycle));
+ controllers.add(new AssistGestureSensitivityPreferenceController(context, lifecycle));
return controllers;
}
@@ -67,10 +67,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.assist_gesture_settings;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/gestures/DoubleTapPowerSettings.java b/src/com/android/settings/gestures/DoubleTapPowerSettings.java
index b17341a..467cec8 100644
--- a/src/com/android/settings/gestures/DoubleTapPowerSettings.java
+++ b/src/com/android/settings/gestures/DoubleTapPowerSettings.java
@@ -24,7 +24,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -67,10 +66,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.double_tap_power_settings;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/gestures/DoubleTapScreenSettings.java b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
index a215dae..887ac80 100644
--- a/src/com/android/settings/gestures/DoubleTapScreenSettings.java
+++ b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
@@ -26,7 +26,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -70,10 +69,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.double_tap_screen_settings;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
index bee9474..46a8cbb 100644
--- a/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
+++ b/src/com/android/settings/gestures/DoubleTwistGestureSettings.java
@@ -24,7 +24,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -67,10 +66,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.double_twist_gesture_settings;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/gestures/PickupGestureSettings.java b/src/com/android/settings/gestures/PickupGestureSettings.java
index e4d12f2..0fe6097 100644
--- a/src/com/android/settings/gestures/PickupGestureSettings.java
+++ b/src/com/android/settings/gestures/PickupGestureSettings.java
@@ -26,7 +26,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -70,10 +69,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.pick_up_gesture_settings;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/gestures/SwipeToNotificationSettings.java b/src/com/android/settings/gestures/SwipeToNotificationSettings.java
index d948e55..6c136c2 100644
--- a/src/com/android/settings/gestures/SwipeToNotificationSettings.java
+++ b/src/com/android/settings/gestures/SwipeToNotificationSettings.java
@@ -24,7 +24,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -67,10 +66,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.swipe_to_notification_settings;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/language/LanguageAndInputSettings.java b/src/com/android/settings/language/LanguageAndInputSettings.java
index 3987252..ef9f84b 100644
--- a/src/com/android/settings/language/LanguageAndInputSettings.java
+++ b/src/com/android/settings/language/LanguageAndInputSettings.java
@@ -36,7 +36,6 @@
import com.android.settings.inputmethod.GameControllerPreferenceController;
import com.android.settings.inputmethod.SpellCheckerPreferenceController;
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -110,10 +109,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.language_and_input;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 6add786..a0ccf20 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -138,10 +138,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.network_and_internet;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/network/NetworkScoreManagerWrapper.java b/src/com/android/settings/network/NetworkScoreManagerWrapper.java
new file mode 100644
index 0000000..3489640
--- /dev/null
+++ b/src/com/android/settings/network/NetworkScoreManagerWrapper.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.network;
+
+import android.annotation.Nullable;
+import android.net.NetworkScoreManager;
+import android.net.NetworkScorerAppData;
+
+import java.util.List;
+
+/**
+ * Wrapper around {@link NetworkScoreManager} to facilitate unit testing.
+ *
+ * TODO: delete this class once robolectric supports Android O
+ */
+public class NetworkScoreManagerWrapper {
+ private final NetworkScoreManager mNetworkScoreManager;
+
+ public NetworkScoreManagerWrapper(NetworkScoreManager networkScoreManager) {
+ mNetworkScoreManager = networkScoreManager;
+ }
+
+ /**
+ * Returns the list of available scorer apps. The list will be empty if there are
+ * no valid scorers.
+ */
+ public List<NetworkScorerAppData> getAllValidScorers() {
+ return mNetworkScoreManager.getAllValidScorers();
+ }
+
+ /**
+ * Obtain the package name of the current active network scorer.
+ *
+ * <p>At any time, only one scorer application will receive {@link #ACTION_SCORE_NETWORKS}
+ * broadcasts and be allowed to call {@link #updateScores}. Applications may use this method to
+ * determine the current scorer and offer the user the ability to select a different scorer via
+ * the {@link #ACTION_CHANGE_ACTIVE} intent.
+ * @return the full package name of the current active scorer, or null if there is no active
+ * scorer.
+ */
+ @Nullable
+ public String getActiveScorerPackage() {
+ return mNetworkScoreManager.getActiveScorerPackage();
+ }
+
+ /**
+ * Returns metadata about the active scorer or <code>null</code> if there is no active scorer.
+ */
+ @Nullable
+ public NetworkScorerAppData getActiveScorer() {
+ return mNetworkScoreManager.getActiveScorer();
+ }
+
+ /**
+ * Set the active scorer to a new package and clear existing scores.
+ *
+ * <p>Should never be called directly without obtaining user consent. This can be done by using
+ * the {@link #ACTION_CHANGE_ACTIVE} broadcast, or using a custom configuration activity.
+ *
+ * @return true if the operation succeeded, or false if the new package is not a valid scorer.
+ * @throws SecurityException if the caller is not a system process or does not hold the
+ * {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission
+ */
+ public boolean setActiveScorer(String packageName) throws SecurityException {
+ return mNetworkScoreManager.setActiveScorer(packageName);
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/network/NetworkScorerPicker.java b/src/com/android/settings/network/NetworkScorerPicker.java
new file mode 100644
index 0000000..2d04e56
--- /dev/null
+++ b/src/com/android/settings/network/NetworkScorerPicker.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.network;
+
+import android.content.Context;
+import android.net.NetworkScoreManager;
+import android.net.NetworkScorerAppData;
+import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.InstrumentedPreferenceFragment;
+import com.android.settings.widget.RadioButtonPreference;
+
+import java.util.List;
+
+/**
+ * Fragment for choosing default network scorer.
+ */
+public class NetworkScorerPicker extends InstrumentedPreferenceFragment implements
+ RadioButtonPreference.OnClickListener {
+
+ private NetworkScoreManagerWrapper mNetworkScoreManager;
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.SETTINGS_NETWORK_SCORER;
+ }
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ super.onCreatePreferences(savedInstanceState, rootKey);
+ addPreferencesFromResource(R.xml.network_scorer_picker_prefs);
+ updateCandidates();
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ mNetworkScoreManager = createNetworkScorerManagerWrapper(context);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ final View view = super.onCreateView(inflater, container, savedInstanceState);
+ // this is needed so the back button goes back to previous fragment
+ setHasOptionsMenu(true);
+ return view;
+ }
+
+ @VisibleForTesting
+ public void updateCandidates() {
+ final PreferenceScreen screen = getPreferenceScreen();
+ screen.removeAll();
+
+ final List<NetworkScorerAppData> scorers = mNetworkScoreManager.getAllValidScorers();
+ if (scorers.isEmpty()) {
+ final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext());
+ nonePref.setTitle(R.string.network_scorer_picker_none_preference);
+ nonePref.setChecked(true);
+ screen.addPreference(nonePref);
+ return;
+ }
+ final String defaultAppKey = getActiveScorerPackage();
+ final int numScorers = scorers.size();
+ for (int i = 0; i < numScorers; i++) {
+ final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
+ final NetworkScorerAppData appData = scorers.get(i);
+ final String appKey = appData.getRecommendationServicePackageName();
+ pref.setTitle(appData.getRecommendationServiceLabel());
+ pref.setKey(appKey);
+ pref.setChecked(TextUtils.equals(defaultAppKey, appKey));
+ pref.setOnClickListener(this);
+ screen.addPreference(pref);
+ }
+ }
+
+ private String getActiveScorerPackage() {
+ return mNetworkScoreManager.getActiveScorerPackage();
+ }
+
+ private boolean setActiveScorer(String key) {
+ if (!TextUtils.equals(key, getActiveScorerPackage())) {
+ return mNetworkScoreManager.setActiveScorer(key);
+ }
+ return false;
+ }
+
+ @Override
+ public void onRadioButtonClicked(RadioButtonPreference selected) {
+ final String selectedKey = selected.getKey();
+ final boolean success = setActiveScorer(selectedKey);
+ if (success) {
+ updateCheckedState(selectedKey);
+ }
+ }
+
+ private void updateCheckedState(String selectedKey) {
+ final PreferenceScreen screen = getPreferenceScreen();
+ final int count = screen.getPreferenceCount();
+ for (int i = 0; i < count; i++) {
+ final Preference pref = screen.getPreference(i);
+ if (pref instanceof RadioButtonPreference) {
+ final RadioButtonPreference radioPref = (RadioButtonPreference) pref;
+ radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
+ }
+ }
+ }
+
+ @VisibleForTesting
+ NetworkScoreManagerWrapper createNetworkScorerManagerWrapper(Context context) {
+ return new NetworkScoreManagerWrapper(context.getSystemService(NetworkScoreManager.class));
+ }
+}
diff --git a/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java b/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java
new file mode 100644
index 0000000..6ff6edb
--- /dev/null
+++ b/src/com/android/settings/network/NetworkScorerPickerPreferenceController.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.network;
+
+import android.content.Context;
+import android.net.NetworkScorerAppData;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+
+/**
+ * {@link PreferenceController} that shows the active network scorer and toggles the preference
+ * based on {@link Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED}.
+ */
+public class NetworkScorerPickerPreferenceController extends PreferenceController {
+
+ private static final String KEY_NETWORK_SCORER_PICKER = "network_scorer_picker";
+
+ private final NetworkScoreManagerWrapper mNetworkScoreManager;
+
+ public NetworkScorerPickerPreferenceController(Context context,
+ NetworkScoreManagerWrapper networkScoreManager) {
+ super(context);
+ mNetworkScoreManager = networkScoreManager;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_NETWORK_SCORER_PICKER;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ boolean enabled = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
+ preference.setEnabled(enabled);
+ if (!enabled) {
+ preference.setSummary(null);
+ return;
+ }
+
+ NetworkScorerAppData scorer = mNetworkScoreManager.getActiveScorer();
+ if (scorer == null) {
+ preference.setSummary(mContext.getString(
+ R.string.network_scorer_picker_none_preference));
+ } else {
+ preference.setSummary(scorer.getRecommendationServiceLabel());
+ }
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+}
diff --git a/src/com/android/settings/nfc/NfcPreferenceController.java b/src/com/android/settings/nfc/NfcPreferenceController.java
index a5e5c3e..11e3e09 100644
--- a/src/com/android/settings/nfc/NfcPreferenceController.java
+++ b/src/com/android/settings/nfc/NfcPreferenceController.java
@@ -68,17 +68,10 @@
mNfcEnabler = new NfcEnabler(mContext, mNfcPreference, mBeamPreference);
String toggleable = Settings.Global.getString(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
- final boolean useNewIA = FeatureFactory.getFactory(mContext)
- .getDashboardFeatureProvider(mContext).isEnabled();
// Manually set dependencies for NFC when not toggleable.
if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
- if (useNewIA) {
- mAirplaneModeObserver = new AirplaneModeObserver();
- updateNfcPreference();
- } else {
- mNfcPreference.setDependency(AirplaneModePreferenceController.KEY_TOGGLE_AIRPLANE);
- mBeamPreference.setDependency(AirplaneModePreferenceController.KEY_TOGGLE_AIRPLANE);
- }
+ mAirplaneModeObserver = new AirplaneModeObserver();
+ updateNfcPreference();
}
}
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 34745a7..a451786 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -20,13 +20,9 @@
import static android.app.NotificationManager.IMPORTANCE_NONE;
import android.app.Activity;
-import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.ResolveInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
@@ -42,11 +38,9 @@
import com.android.settings.Utils;
import com.android.settings.applications.AppHeaderController;
import com.android.settings.applications.AppInfoBase;
-import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.notification.NotificationBackend.AppRow;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.MasterSwitchPreference;
-import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.RestrictedSwitchPreference;
import java.text.Collator;
@@ -63,21 +57,10 @@
private static final String KEY_BLOCK = "block";
- private DashboardFeatureProvider mDashboardFeatureProvider;
private List<NotificationChannelGroup> mChannelGroupList;
private List<PreferenceCategory> mChannelGroups = new ArrayList();
@Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if (mAppRow == null) return;
- if (!mDashboardFeatureProvider.isEnabled()) {
- AppHeader.createAppHeader(this, mAppRow.icon, mAppRow.label, mAppRow.pkg, mAppRow.uid,
- mAppRow.settingsIntent);
- }
- }
-
- @Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_APP_NOTIFICATION;
}
@@ -91,8 +74,6 @@
return;
}
final Activity activity = getActivity();
- mDashboardFeatureProvider =
- FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
addPreferencesFromResource(R.xml.app_notification_settings);
getPreferenceScreen().setOrderingAsAdded(true);
@@ -121,20 +102,18 @@
}
}.execute();
}
- if (mDashboardFeatureProvider.isEnabled()) {
- final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this /* fragment */, null /* appHeader */)
- .setIcon(mAppRow.icon)
- .setLabel(mAppRow.label)
- .setPackageName(mAppRow.pkg)
- .setUid(mAppRow.uid)
- .setAppNotifPrefIntent(mAppRow.settingsIntent)
- .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
- AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
- .done(getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this /* fragment */, null /* appHeader */)
+ .setIcon(mAppRow.icon)
+ .setLabel(mAppRow.label)
+ .setPackageName(mAppRow.pkg)
+ .setUid(mAppRow.uid)
+ .setAppNotifPrefIntent(mAppRow.settingsIntent)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
+ .done(getPrefContext());
+ getPreferenceScreen().addPreference(pref);
}
@Override
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index 7be98c1..1cb2154 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -40,11 +40,9 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
-import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.applications.AppHeaderController;
-import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -69,18 +67,6 @@
protected RestrictedSwitchPreference mPriority;
protected RestrictedDropDownPreference mVisibilityOverride;
- private DashboardFeatureProvider mDashboardFeatureProvider;
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if (mAppRow == null || mChannel == null) return;
- if (!mDashboardFeatureProvider.isEnabled()) {
- AppHeader.createAppHeader(
- this, mAppRow.icon, mChannel.getName(), mAppRow.pkg, mAppRow.uid);
- }
- }
-
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION;
@@ -95,8 +81,6 @@
return;
}
final Activity activity = getActivity();
- mDashboardFeatureProvider =
- FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
addPreferencesFromResource(R.xml.channel_notification_settings);
// load settings intent
@@ -125,21 +109,19 @@
setupBlockAndImportance();
updateDependents();
}
- if (mDashboardFeatureProvider.isEnabled()) {
- final Preference pref = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity)
- .newAppHeaderController(this /* fragment */, null /* appHeader */)
- .setIcon(mAppRow.icon)
- .setLabel(getNotificationChannelLabel(mChannel))
- .setSummary(mAppRow.label)
- .setPackageName(mAppRow.pkg)
- .setUid(mAppRow.uid)
- .setAppNotifPrefIntent(mAppRow.settingsIntent)
- .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
- AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
- .done(getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
+ final Preference pref = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this /* fragment */, null /* appHeader */)
+ .setIcon(mAppRow.icon)
+ .setLabel(getNotificationChannelLabel(mChannel))
+ .setSummary(mAppRow.label)
+ .setPackageName(mAppRow.pkg)
+ .setUid(mAppRow.uid)
+ .setAppNotifPrefIntent(mAppRow.settingsIntent)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
+ .done(getPrefContext());
+ getPreferenceScreen().addPreference(pref);
}
@Override
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 2a737d4..aee9dc2 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -17,14 +17,12 @@
package com.android.settings.notification;
import android.content.Context;
-import android.os.Bundle;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
-import com.android.settings.overlay.FeatureFactory;
import java.util.ArrayList;
import java.util.List;
@@ -62,16 +60,4 @@
controllers.add(mLockScreenNotificationController);
return controllers;
}
-
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- super.onCreatePreferences(savedInstanceState, rootKey);
- final Context context = getContext();
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context).isEnabled()) {
- final String prefKey = getPreferenceController(
- SwipeToNotificationPreferenceController.class)
- .getPreferenceKey();
- removePreference(prefKey);
- }
- }
}
diff --git a/src/com/android/settings/notification/NotificationStation.java b/src/com/android/settings/notification/NotificationStation.java
index 50bcd95..a357846 100644
--- a/src/com/android/settings/notification/NotificationStation.java
+++ b/src/com/android/settings/notification/NotificationStation.java
@@ -16,8 +16,11 @@
package com.android.settings.notification;
-import android.app.*;
+import android.app.Activity;
+import android.app.ActivityManager;
import android.app.INotificationManager;
+import android.app.Notification;
+import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.IntentSender;
@@ -26,7 +29,12 @@
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
-import android.os.*;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
@@ -45,13 +53,15 @@
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.CopyablePreference;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
-import java.lang.StringBuilder;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
public class NotificationStation extends SettingsPreferenceFragment {
private static final String TAG = NotificationStation.class.getSimpleName();
@@ -533,7 +543,7 @@
return null;
}
- private static class HistoricalNotificationPreference extends CopyablePreference {
+ private static class HistoricalNotificationPreference extends Preference {
private final HistoricalNotificationInfo mInfo;
public HistoricalNotificationPreference(Context context, HistoricalNotificationInfo info) {
@@ -574,14 +584,6 @@
}
@Override
- public CharSequence getCopyableText() {
- return new SpannableStringBuilder(mInfo.title)
- .append(" [").append(new Date(mInfo.timestamp).toString())
- .append("]\n").append(mInfo.pkgname)
- .append("\n").append(mInfo.extra);
- }
-
- @Override
public void performClick() {
// Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
// Uri.fromParts("package", mInfo.pkg, null));
diff --git a/src/com/android/settings/notification/WorkSoundPreferenceController.java b/src/com/android/settings/notification/WorkSoundPreferenceController.java
index 5ffb30b..a4d7b8d 100644
--- a/src/com/android/settings/notification/WorkSoundPreferenceController.java
+++ b/src/com/android/settings/notification/WorkSoundPreferenceController.java
@@ -25,7 +25,6 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
-import android.media.AudioSystem;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
@@ -38,7 +37,6 @@
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
-import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -53,7 +51,7 @@
import com.android.settings.core.lifecycle.events.OnResume;
public class WorkSoundPreferenceController extends PreferenceController implements
- OnPreferenceChangeListener, LifecycleObserver, OnResume, OnPause {
+ OnPreferenceChangeListener, LifecycleObserver, OnResume, OnPause {
private static final String TAG = "WorkSoundPrefController";
private static final String KEY_WORK_CATEGORY = "sound_work_settings_section";
@@ -62,27 +60,28 @@
private static final String KEY_WORK_NOTIFICATION_RINGTONE = "work_notification_ringtone";
private static final String KEY_WORK_ALARM_RINGTONE = "work_alarm_ringtone";
+ private final boolean mVoiceCapable;
+ private final UserManager mUserManager;
+ private final SoundSettings mParent;
+ private final AudioHelper mHelper;
+
private PreferenceGroup mWorkPreferenceCategory;
private TwoStatePreference mWorkUsePersonalSounds;
private Preference mWorkPhoneRingtonePreference;
private Preference mWorkNotificationRingtonePreference;
private Preference mWorkAlarmRingtonePreference;
- private boolean mVoiceCapable;
- private UserManager mUserManager;
- private SoundSettings mParent;
- private AudioHelper mHelper;
- private @UserIdInt
- int mManagedProfileId;
+ @UserIdInt
+ private int mManagedProfileId;
public WorkSoundPreferenceController(Context context, SoundSettings parent,
- Lifecycle lifecycle) {
+ Lifecycle lifecycle) {
this(context, parent, lifecycle, new AudioHelper(context));
}
@VisibleForTesting
WorkSoundPreferenceController(Context context, SoundSettings parent, Lifecycle lifecycle,
- AudioHelper helper) {
+ AudioHelper helper) {
super(context);
mUserManager = UserManager.get(context);
mVoiceCapable = Utils.isVoiceCapable(mContext);
@@ -95,7 +94,10 @@
@Override
public void displayPreference(PreferenceScreen screen) {
- // do nothing
+ mWorkPreferenceCategory = (PreferenceGroup) screen.findPreference(KEY_WORK_CATEGORY);
+ if (mWorkPreferenceCategory != null) {
+ mWorkPreferenceCategory.setVisible(isAvailable());
+ }
}
@Override
@@ -106,7 +108,7 @@
mContext.registerReceiver(mManagedProfileReceiver, managedProfileFilter);
mManagedProfileId = mHelper.getManagedProfileId(mUserManager);
- initWorkPreferences();
+ updateWorkPreferences();
}
@Override
@@ -165,7 +167,7 @@
}
Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, type);
return Ringtone.getTitle(context, ringtoneUri, false /* followSettingsUri */,
- true /* allowRemote */);
+ true /* allowRemote */);
}
private Context getManagedProfileContext() {
@@ -175,9 +177,9 @@
return mHelper.createPackageContextAsUser(mManagedProfileId);
}
- private DefaultRingtonePreference initWorkPreference(String key) {
+ private DefaultRingtonePreference initWorkPreference(PreferenceGroup root, String key) {
DefaultRingtonePreference pref =
- (DefaultRingtonePreference) mParent.getPreferenceScreen().findPreference(key);
+ (DefaultRingtonePreference) root.findPreference(key);
pref.setOnPreferenceChangeListener(this);
// Required so that RingtonePickerActivity lists the work profile ringtones
@@ -185,24 +187,18 @@
return pref;
}
- private void initWorkPreferences() {
- if (mManagedProfileId == UserHandle.USER_NULL || !isAvailable()) {
- maybeRemoveWorkPreferences();
+ private void updateWorkPreferences() {
+ if (mWorkPreferenceCategory == null) {
return;
}
-
- if (mWorkPreferenceCategory == null) {
- mParent.addPreferencesFromResource(R.xml.sound_work_settings);
- final PreferenceScreen screen = mParent.getPreferenceScreen();
-
- mWorkPreferenceCategory = (PreferenceGroup) screen.findPreference(KEY_WORK_CATEGORY);
+ final boolean isAvailable = isAvailable();
+ mWorkPreferenceCategory.setVisible(isAvailable);
+ if (!isAvailable) {
+ return;
+ }
+ if (mWorkUsePersonalSounds == null) {
mWorkUsePersonalSounds = (TwoStatePreference)
- screen.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS);
- mWorkPhoneRingtonePreference = initWorkPreference(KEY_WORK_PHONE_RINGTONE);
- mWorkNotificationRingtonePreference = initWorkPreference(
- KEY_WORK_NOTIFICATION_RINGTONE);
- mWorkAlarmRingtonePreference = initWorkPreference(KEY_WORK_ALARM_RINGTONE);
-
+ mWorkPreferenceCategory.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS);
mWorkUsePersonalSounds.setOnPreferenceChangeListener((Preference p, Object value) -> {
if ((boolean) value) {
UnifyWorkDialogFragment.show(mParent);
@@ -212,16 +208,27 @@
return true;
}
});
-
- if (!mVoiceCapable) {
- mWorkPreferenceCategory.removePreference(mWorkPhoneRingtonePreference);
- mWorkPhoneRingtonePreference = null;
- }
+ }
+ if (mWorkPhoneRingtonePreference == null) {
+ mWorkPhoneRingtonePreference = initWorkPreference(mWorkPreferenceCategory,
+ KEY_WORK_PHONE_RINGTONE);
+ }
+ if (mWorkNotificationRingtonePreference == null) {
+ mWorkNotificationRingtonePreference = initWorkPreference(mWorkPreferenceCategory,
+ KEY_WORK_NOTIFICATION_RINGTONE);
+ }
+ if (mWorkAlarmRingtonePreference == null) {
+ mWorkAlarmRingtonePreference = initWorkPreference(mWorkPreferenceCategory,
+ KEY_WORK_ALARM_RINGTONE);
+ }
+ if (!mVoiceCapable) {
+ mWorkPreferenceCategory.removePreference(mWorkPhoneRingtonePreference);
+ mWorkPhoneRingtonePreference = null;
}
- Context managedProfileContext = getManagedProfileContext();
+ final Context managedProfileContext = getManagedProfileContext();
if (Settings.Secure.getIntForUser(managedProfileContext.getContentResolver(),
- Settings.Secure.SYNC_PARENT_SOUNDS, 0, mManagedProfileId) == 1) {
+ Settings.Secure.SYNC_PARENT_SOUNDS, 0, mManagedProfileId) == 1) {
enableWorkSyncSettings();
} else {
disableWorkSyncSettings();
@@ -237,13 +244,10 @@
mWorkUsePersonalSounds.setChecked(true);
if (mWorkPhoneRingtonePreference != null) {
- mWorkPhoneRingtonePreference.setSummary(
- com.android.settings.R.string.work_sound_same_as_personal);
+ mWorkPhoneRingtonePreference.setSummary(R.string.work_sound_same_as_personal);
}
- mWorkNotificationRingtonePreference.setSummary(
- com.android.settings.R.string.work_sound_same_as_personal);
- mWorkAlarmRingtonePreference.setSummary(
- com.android.settings.R.string.work_sound_same_as_personal);
+ mWorkNotificationRingtonePreference.setSummary(R.string.work_sound_same_as_personal);
+ mWorkAlarmRingtonePreference.setSummary(R.string.work_sound_same_as_personal);
}
private void disableWorkSync() {
@@ -266,36 +270,25 @@
if (mWorkPhoneRingtonePreference != null) {
mWorkPhoneRingtonePreference.setSummary(
- updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_RINGTONE));
+ updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_RINGTONE));
}
mWorkNotificationRingtonePreference.setSummary(
- updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_NOTIFICATION));
+ updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_NOTIFICATION));
mWorkAlarmRingtonePreference.setSummary(
- updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_ALARM));
- }
-
- private void maybeRemoveWorkPreferences() {
- if (mWorkPreferenceCategory == null) {
- return;
- }
- mParent.getPreferenceScreen().removePreference(mWorkPreferenceCategory);
- mWorkPreferenceCategory = null;
- mWorkPhoneRingtonePreference = null;
- mWorkNotificationRingtonePreference = null;
- mWorkAlarmRingtonePreference = null;
+ updateRingtoneName(managedProfileContext, RingtoneManager.TYPE_ALARM));
}
public void onManagedProfileAdded(@UserIdInt int profileId) {
if (mManagedProfileId == UserHandle.USER_NULL) {
mManagedProfileId = profileId;
- initWorkPreferences();
+ updateWorkPreferences();
}
}
public void onManagedProfileRemoved(@UserIdInt int profileId) {
if (mManagedProfileId == profileId) {
mManagedProfileId = mHelper.getManagedProfileId(mUserManager);
- initWorkPreferences();
+ updateWorkPreferences();
}
}
@@ -317,7 +310,7 @@
};
public static class UnifyWorkDialogFragment extends InstrumentedDialogFragment
- implements DialogInterface.OnClickListener {
+ implements DialogInterface.OnClickListener {
private static final String TAG = "UnifyWorkDialogFragment";
private static final int REQUEST_CODE = 200;
@@ -329,12 +322,11 @@
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
- .setTitle(com.android.settings.R.string.work_sync_dialog_title)
- .setMessage(com.android.settings.R.string.work_sync_dialog_message)
- .setPositiveButton(com.android.settings.R.string.work_sync_dialog_yes,
- UnifyWorkDialogFragment.this)
- .setNegativeButton(android.R.string.no, null)
- .create();
+ .setTitle(R.string.work_sync_dialog_title)
+ .setMessage(R.string.work_sync_dialog_message)
+ .setPositiveButton(R.string.work_sync_dialog_yes, UnifyWorkDialogFragment.this)
+ .setNegativeButton(android.R.string.no, null)
+ .create();
}
public static void show(SoundSettings parent) {
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index e72ee03..5b039b2 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -116,7 +116,7 @@
@Override
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
if (mEnterprisePrivacyFeatureProvider == null) {
- mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(
+ mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context,
new DevicePolicyManagerWrapperImpl((DevicePolicyManager) context
.getSystemService(Context.DEVICE_POLICY_SERVICE)),
new PackageManagerWrapperImpl(context.getPackageManager()),
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 362a9c4..561c2c6 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -166,7 +166,7 @@
R.drawable.ic_settings_notifications);
addIndex(SystemDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(StorageDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage);
- addIndex(ConnectedDeviceDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_bt_laptop);
+ addIndex(ConnectedDeviceDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_devices_other);
addIndex(EnterprisePrivacySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(PaymentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_nfc_payment);
addIndex(
diff --git a/src/com/android/settings/search2/CursorToSearchResultConverter.java b/src/com/android/settings/search2/CursorToSearchResultConverter.java
index 880a65b..71d999e 100644
--- a/src/com/android/settings/search2/CursorToSearchResultConverter.java
+++ b/src/com/android/settings/search2/CursorToSearchResultConverter.java
@@ -35,6 +35,7 @@
import com.android.settings.dashboard.SiteMapManager;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -77,6 +78,22 @@
private final Set<String> mKeys;
+ private final int LONG_TITLE_LENGTH = 20;
+
+ private static final String[] whiteList = {
+ "main_toggle_wifi",
+ "main_toggle_bluetooth",
+ "toggle_airplane",
+ "tether_settings",
+ "battery_saver",
+ "toggle_nfc",
+ "restrict_background",
+ "data_usage_enable",
+ "button_roaming_key",
+ };
+ private static final Set<String> prioritySettings = new HashSet(Arrays.asList(whiteList));
+
+
public CursorToSearchResultConverter(Context context, String queryText) {
mContext = context;
mKeys = new HashSet<>();
@@ -135,7 +152,7 @@
}
final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor);
- final int rank = getRank(breadcrumbs, baseRank);
+ final int rank = getRank(title, breadcrumbs, baseRank, key);
final SearchResult.Builder builder = new SearchResult.Builder();
builder.addTitle(title)
@@ -225,18 +242,32 @@
}
/** Uses the breadcrumbs to determine the offset to the base rank.
- * There are two checks
- * A) If the query matches the highest level menu title
- * B) If the query matches a subsequent menu title
+ * There are three checks
+ * A) If the result is prioritized and the highest base level
+ * B) If the query matches the highest level menu title
+ * C) If the query matches a subsequent menu title
+ * D) Is the title longer than 20
*
- * If the query matches A and B, the offset is 0.
- * If the query matches A only, the offset is 1.
- * If the query matches neither A nor B, the offset is 2.
+ * If the query matches A, set it to TOP_RANK
+ * If the query matches B and C, the offset is 0.
+ * If the query matches C only, the offset is 1.
+ * If the query matches neither B nor C, the offset is 2.
+ * If the query matches D, the offset is 2
+
+ * @param title of the result.
* @param crumbs from the Information Architecture
* @param baseRank of the result. Lower if it's a better result.
* @return
*/
- private int getRank(List<String> crumbs, int baseRank) {
+ private int getRank(String title, List<String> crumbs, int baseRank, String key) {
+ // The result can only be prioritized if it is a top ranked result.
+ if (prioritySettings.contains(key) && baseRank < DatabaseResultLoader.BASE_RANKS[1]) {
+ return SearchResult.TOP_RANK;
+ }
+ if (title.length() > LONG_TITLE_LENGTH) {
+ return baseRank + 2;
+ }
return baseRank;
}
+
}
diff --git a/src/com/android/settings/search2/DatabaseResultLoader.java b/src/com/android/settings/search2/DatabaseResultLoader.java
index ad1e6a9..5892ebc 100644
--- a/src/com/android/settings/search2/DatabaseResultLoader.java
+++ b/src/com/android/settings/search2/DatabaseResultLoader.java
@@ -97,7 +97,7 @@
* If the query only matches keywords or entries, the best rank it can be is 9
*
*/
- private static final int[] BASE_RANKS = {1, 3, 7, 9};
+ public static final int[] BASE_RANKS = {1, 3, 7, 9};
private final String mQueryText;
private final Context mContext;
diff --git a/src/com/android/settings/search2/SearchFeatureProviderImpl.java b/src/com/android/settings/search2/SearchFeatureProviderImpl.java
index b161686..cd9c470 100644
--- a/src/com/android/settings/search2/SearchFeatureProviderImpl.java
+++ b/src/com/android/settings/search2/SearchFeatureProviderImpl.java
@@ -40,7 +40,7 @@
@Override
public boolean isEnabled(Context context) {
- return false;
+ return true;
}
@Override
diff --git a/src/com/android/settings/search2/SearchResult.java b/src/com/android/settings/search2/SearchResult.java
index a82c47f..6b27d89 100644
--- a/src/com/android/settings/search2/SearchResult.java
+++ b/src/com/android/settings/search2/SearchResult.java
@@ -27,10 +27,15 @@
public class SearchResult implements Comparable<SearchResult> {
/**
- * Defines the max rank for a search result to be considered as ranked. Results with ranks
+ * Defines the lowest rank for a search result to be considered as ranked. Results with ranks
* higher than this have no guarantee for sorting order.
*/
- public static final int MAX_RANK = 10;
+ public static final int BOTTOM_RANK = 10;
+
+ /**
+ * Defines the highest rank for a search result. Used for special search results only.
+ */
+ public static final int TOP_RANK = 0;
/**
* The title of the result and main text displayed.
diff --git a/src/com/android/settings/search2/SearchResultsAdapter.java b/src/com/android/settings/search2/SearchResultsAdapter.java
index afe432a..5151b64 100644
--- a/src/com/android/settings/search2/SearchResultsAdapter.java
+++ b/src/com/android/settings/search2/SearchResultsAdapter.java
@@ -32,7 +32,8 @@
import java.util.List;
import java.util.Map;
-import static com.android.settings.search2.SearchResult.MAX_RANK;
+import static com.android.settings.search2.SearchResult.TOP_RANK;
+import static com.android.settings.search2.SearchResult.BOTTOM_RANK;
public class SearchResultsAdapter extends Adapter<SearchViewHolder> {
@@ -117,9 +118,9 @@
int dbIndex = 0;
int appIndex = 0;
- int rank = 1;
+ int rank = TOP_RANK;
- while (rank <= MAX_RANK) {
+ while (rank <= BOTTOM_RANK) {
while ((dbIndex < dbSize) && (databaseResults.get(dbIndex).rank == rank)) {
results.add(databaseResults.get(dbIndex++));
}
diff --git a/src/com/android/settings/security/SecurityFeatureProviderImpl.java b/src/com/android/settings/security/SecurityFeatureProviderImpl.java
index 2d782a6..7be2d66 100644
--- a/src/com/android/settings/security/SecurityFeatureProviderImpl.java
+++ b/src/com/android/settings/security/SecurityFeatureProviderImpl.java
@@ -46,9 +46,24 @@
private TrustAgentManager mTrustAgentManager;
+ @VisibleForTesting
+ static final Drawable DEFAULT_ICON = null;
+ @VisibleForTesting
+ static final String DEFAULT_SUMMARY = " ";
+
/** Update preferences with data from associated tiles. */
public void updatePreferences(final Context context, final PreferenceScreen preferenceScreen,
final DashboardCategory dashboardCategory) {
+ if (preferenceScreen == null) {
+ return;
+ }
+ int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
+ if (tilesCount == 0) {
+ return;
+ }
+
+ initPreferences(context, preferenceScreen, dashboardCategory);
+
// Fetching the summary and icon from the provider introduces latency, so do this on a
// separate thread.
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -60,16 +75,33 @@
}
@VisibleForTesting
+ static void initPreferences(Context context, PreferenceScreen preferenceScreen,
+ DashboardCategory dashboardCategory) {
+ int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
+ for (int i = 0; i < tilesCount; i++) {
+ Tile tile = dashboardCategory.getTile(i);
+ // If the tile does not have a key or appropriate meta data, skip it.
+ if (TextUtils.isEmpty(tile.key) || (tile.metaData == null)) {
+ continue;
+ }
+ Preference matchingPref = preferenceScreen.findPreference(tile.key);
+ // If the tile does not have a matching preference, skip it.
+ if (matchingPref == null) {
+ continue;
+ }
+ // Remove any icons that may be loaded before we inject the final icon.
+ matchingPref.setIcon(DEFAULT_ICON);
+ // Reserve room for the summary. This prevents the title from having to shift when the
+ // final title is injected.
+ matchingPref.setSummary(DEFAULT_SUMMARY);
+ }
+ }
+
+ @VisibleForTesting
void updatePreferencesToRunOnWorkerThread(Context context, PreferenceScreen preferenceScreen,
DashboardCategory dashboardCategory) {
- if (preferenceScreen == null) {
- return;
- }
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
- if (tilesCount == 0) {
- return;
- }
Map<String, IContentProvider> providerMap = new ArrayMap<>();
for (int i = 0; i < tilesCount; i++) {
Tile tile = dashboardCategory.getTile(i);
diff --git a/src/com/android/settings/system/FactoryResetPreferenceController.java b/src/com/android/settings/system/FactoryResetPreferenceController.java
new file mode 100644
index 0000000..95a9e54
--- /dev/null
+++ b/src/com/android/settings/system/FactoryResetPreferenceController.java
@@ -0,0 +1,46 @@
+/*
+ * 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.system;
+
+import android.content.Context;
+
+import android.os.UserManager;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+
+public class FactoryResetPreferenceController extends PreferenceController {
+ /** Key of the "Factory reset" preference in {@link R.xml.system_dashboard_fragment}.*/
+ private static final String KEY_FACTORY_RESET = "factory_reset";
+
+ private final UserManager mUm;
+
+ public FactoryResetPreferenceController(Context context, UserManager um) {
+ super(context);
+ mUm = um;
+ }
+
+ /** Hide "Factory reset" settings for secondary users. */
+ @Override
+ public boolean isAvailable() {
+ return mUm.isAdminUser();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_FACTORY_RESET;
+ }
+}
diff --git a/src/com/android/settings/system/SystemDashboardFragment.java b/src/com/android/settings/system/SystemDashboardFragment.java
index c4bf0da..d4c63c2 100644
--- a/src/com/android/settings/system/SystemDashboardFragment.java
+++ b/src/com/android/settings/system/SystemDashboardFragment.java
@@ -25,7 +25,6 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -33,7 +32,6 @@
import java.util.Arrays;
import java.util.List;
-
public class SystemDashboardFragment extends DashboardFragment {
private static final String TAG = "SystemDashboardFrag";
@@ -62,6 +60,7 @@
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new SystemUpdatePreferenceController(context, UserManager.get(context)));
controllers.add(new AdditionalSystemUpdatePreferenceController(context));
+ controllers.add(new FactoryResetPreferenceController(context, UserManager.get(context)));
return controllers;
}
@@ -73,10 +72,6 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.system_dashboard_fragment;
return Arrays.asList(sir);
diff --git a/src/com/android/settings/vpn2/LegacyVpnPreference.java b/src/com/android/settings/vpn2/LegacyVpnPreference.java
index c1550e2..a4d7221 100644
--- a/src/com/android/settings/vpn2/LegacyVpnPreference.java
+++ b/src/com/android/settings/vpn2/LegacyVpnPreference.java
@@ -34,7 +34,7 @@
LegacyVpnPreference(Context context) {
super(context, null /* attrs */);
- setIcon(R.mipmap.ic_launcher_settings);
+ setIcon(R.drawable.ic_settings_24dp);
}
public VpnProfile getProfile() {
diff --git a/src/com/android/settings/webview/WebViewAppPicker.java b/src/com/android/settings/webview/WebViewAppPicker.java
index aa229ac..f1faf9b 100644
--- a/src/com/android/settings/webview/WebViewAppPicker.java
+++ b/src/com/android/settings/webview/WebViewAppPicker.java
@@ -21,9 +21,12 @@
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageItemInfo;
import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -58,9 +61,9 @@
List<ApplicationInfo> pkgs =
getWebViewUpdateServiceWrapper().getValidWebViewApplicationInfos(getContext());
for (ApplicationInfo ai : pkgs) {
- packageInfoList.add(new DefaultAppInfo(ai,
- getDisabledReason(getWebViewUpdateServiceWrapper(),
- getContext(), ai.packageName)));
+ packageInfoList.add(createDefaultAppInfo(ai,
+ getDisabledReason(getWebViewUpdateServiceWrapper(),
+ getContext(), ai.packageName)));
}
return packageInfoList;
}
@@ -92,7 +95,6 @@
}
}
-
private WebViewUpdateServiceWrapper createDefaultWebViewUpdateServiceWrapper() {
return new WebViewUpdateServiceWrapper();
}
@@ -107,6 +109,29 @@
return MetricsEvent.WEBVIEW_IMPLEMENTATION;
}
+ private static class WebViewAppInfo extends DefaultAppInfo {
+ public WebViewAppInfo(PackageItemInfo packageItemInfo, String summary, boolean enabled) {
+ super(packageItemInfo, summary, enabled);
+ }
+
+ @Override
+ public CharSequence loadLabel(PackageManager pm) {
+ String versionName = "";
+ try {
+ versionName = pm.getPackageInfo(packageItemInfo.packageName, 0).versionName;
+ } catch (PackageManager.NameNotFoundException e) {
+ }
+ return String.format("%s %s", super.loadLabel(pm), versionName);
+ }
+ }
+
+
+ @VisibleForTesting
+ DefaultAppInfo createDefaultAppInfo(PackageItemInfo packageItemInfo, String disabledReason) {
+ return new WebViewAppInfo(packageItemInfo, disabledReason,
+ TextUtils.isEmpty(disabledReason) /* enabled */);
+ }
+
/**
* Returns the reason why a package cannot be used as WebView implementation.
* This is either because of it being disabled, uninstalled, or hidden for any user.
diff --git a/src/com/android/settings/wfd/WifiDisplaySettings.java b/src/com/android/settings/wfd/WifiDisplaySettings.java
index f7c2f6e..0d6b4dc 100755
--- a/src/com/android/settings/wfd/WifiDisplaySettings.java
+++ b/src/com/android/settings/wfd/WifiDisplaySettings.java
@@ -125,9 +125,9 @@
super.onCreate(icicle);
final Context context = getActivity();
- mRouter = (MediaRouter)context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
- mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
- mWifiP2pManager = (WifiP2pManager)context.getSystemService(Context.WIFI_P2P_SERVICE);
+ mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
+ mDisplayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
+ mWifiP2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
mWifiP2pChannel = mWifiP2pManager.initialize(context, Looper.getMainLooper(), null);
addPreferencesFromResource(R.xml.wifi_display_settings);
@@ -211,6 +211,11 @@
return super.onOptionsItemSelected(item);
}
+ public static boolean isAvailable(Context context) {
+ return context.getSystemService(Context.DISPLAY_SERVICE) != null
+ && context.getSystemService(Context.WIFI_P2P_SERVICE) != null;
+ }
+
private void scheduleUpdate(int changes) {
if (mStarted) {
if (mPendingChanges == 0) {
@@ -237,7 +242,7 @@
mWifiDisplayCertificationOn = Settings.Global.getInt(getContentResolver(),
Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0;
mWpsConfig = Settings.Global.getInt(getContentResolver(),
- Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
+ Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
// The wifi display enabled setting may have changed.
invalidateOptions = true;
@@ -402,12 +407,12 @@
});
mWpsConfig = Settings.Global.getInt(getActivity().getContentResolver(),
Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
- String[] wpsEntries = { "Default", "PBC", "KEYPAD", "DISPLAY" };
+ String[] wpsEntries = {"Default", "PBC", "KEYPAD", "DISPLAY"};
String[] wpsValues = {
- "" + WpsInfo.INVALID,
- "" + WpsInfo.PBC,
- "" + WpsInfo.KEYPAD,
- "" + WpsInfo.DISPLAY };
+ "" + WpsInfo.INVALID,
+ "" + WpsInfo.PBC,
+ "" + WpsInfo.KEYPAD,
+ "" + WpsInfo.DISPLAY};
lp.setKey("wps");
lp.setTitle(R.string.wifi_display_wps_config);
lp.setEntries(wpsEntries);
@@ -430,8 +435,8 @@
return true;
}
});
- String[] lcEntries = { "Auto", "1", "6", "11" };
- String[] lcValues = { "0", "1", "6", "11" };
+ String[] lcEntries = {"Auto", "1", "6", "11"};
+ String[] lcValues = {"0", "1", "6", "11"};
lp.setKey("listening_channel");
lp.setTitle(R.string.wifi_display_listen_channel);
lp.setEntries(lcEntries);
@@ -454,8 +459,8 @@
return true;
}
});
- String[] ocEntries = { "Auto", "1", "6", "11", "36" };
- String[] ocValues = { "0", "1", "6", "11", "36" };
+ String[] ocEntries = {"Auto", "1", "6", "11", "36"};
+ String[] ocValues = {"0", "1", "6", "11", "36"};
lp.setKey("operating_channel");
lp.setTitle(R.string.wifi_display_operating_channel);
lp.setEntries(ocEntries);
@@ -512,14 +517,14 @@
public void onSuccess() {
if (DEBUG) {
Slog.d(TAG, "Successfully " + (enable ? "entered" : "exited")
- +" listen mode.");
+ + " listen mode.");
}
}
@Override
public void onFailure(int reason) {
Slog.e(TAG, "Failed to " + (enable ? "entered" : "exited")
- +" listen mode with reason " + reason + ".");
+ + " listen mode with reason " + reason + ".");
}
});
}
@@ -530,18 +535,18 @@
}
mWifiP2pManager.setWifiP2pChannels(mWifiP2pChannel,
lc, oc, new ActionListener() {
- @Override
- public void onSuccess() {
- if (DEBUG) {
- Slog.d(TAG, "Successfully set wifi p2p channels.");
- }
- }
+ @Override
+ public void onSuccess() {
+ if (DEBUG) {
+ Slog.d(TAG, "Successfully set wifi p2p channels.");
+ }
+ }
- @Override
- public void onFailure(int reason) {
- Slog.e(TAG, "Failed to set wifi p2p channels with reason " + reason + ".");
- }
- });
+ @Override
+ public void onFailure(int reason) {
+ Slog.e(TAG, "Failed to set wifi p2p channels with reason " + reason + ".");
+ }
+ });
}
private void toggleRoute(MediaRouter.RouteInfo route) {
@@ -561,7 +566,7 @@
private void showWifiDisplayOptionsDialog(final WifiDisplay display) {
View view = getActivity().getLayoutInflater().inflate(R.layout.wifi_display_options, null);
- final EditText nameEditText = (EditText)view.findViewById(R.id.name);
+ final EditText nameEditText = (EditText) view.findViewById(R.id.name);
nameEditText.setText(display.getFriendlyDisplayName());
DialogInterface.OnClickListener done = new DialogInterface.OnClickListener() {
@@ -707,7 +712,7 @@
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.disabledAlpha,
value, true);
- deviceDetails.setImageAlpha((int)(value.getFloat() * 255));
+ deviceDetails.setImageAlpha((int) (value.getFloat() * 255));
deviceDetails.setEnabled(true); // always allow button to be pressed
}
}
diff --git a/src/com/android/settings/widget/FooterPreference.java b/src/com/android/settings/widget/FooterPreference.java
index 4a0d128..9cb9e11 100644
--- a/src/com/android/settings/widget/FooterPreference.java
+++ b/src/com/android/settings/widget/FooterPreference.java
@@ -17,6 +17,7 @@
package com.android.settings.widget;
import android.content.Context;
+import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.method.LinkMovementMethod;
@@ -34,36 +35,24 @@
static final int ORDER_FOOTER = Integer.MAX_VALUE - 1;
static final String KEY_FOOTER = "footer_preference";
- public FooterPreference(Context context, AttributeSet attrs,
- int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- init();
- }
-
- public FooterPreference(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- init();
- }
-
public FooterPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
+ super(context, attrs, TypedArrayUtils.getAttr(
+ context, R.attr.footerPreferenceStyle, android.R.attr.preferenceStyle));
init();
}
public FooterPreference(Context context) {
- super(context);
- init();
+ this(context, null);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
- TextView title = (TextView) holder.itemView.findViewById(android.R.id.title);
+ TextView title = holder.itemView.findViewById(android.R.id.title);
title.setMovementMethod(new LinkMovementMethod());
}
private void init() {
- setLayoutResource(R.layout.preference_footer);
setIcon(R.drawable.ic_info_outline_24dp);
setKey(KEY_FOOTER);
setOrder(ORDER_FOOTER);
diff --git a/src/com/android/settings/widget/VideoPreference.java b/src/com/android/settings/widget/VideoPreference.java
index c8786dc..e06ef56 100644
--- a/src/com/android/settings/widget/VideoPreference.java
+++ b/src/com/android/settings/widget/VideoPreference.java
@@ -62,6 +62,7 @@
.build();
mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
if (mMediaPlayer != null && mMediaPlayer.getDuration() > 0) {
+ setVisible(true);
setLayoutResource(R.layout.video_preference);
mPreviewResource = attributes.getResourceId(
@@ -71,6 +72,8 @@
mMediaPlayer.setOnPreparedListener(mediaPlayer -> mediaPlayer.setLooping(true));
mAnimationAvailable = true;
+ } else {
+ setVisible(false);
}
} catch (Exception e) {
Log.w(TAG, "Animation resource not found. Will not show animation.");
diff --git a/src/com/android/settings/wifi/ConfigureWifiSettings.java b/src/com/android/settings/wifi/ConfigureWifiSettings.java
index 18cc28b..78e869b 100644
--- a/src/com/android/settings/wifi/ConfigureWifiSettings.java
+++ b/src/com/android/settings/wifi/ConfigureWifiSettings.java
@@ -15,16 +15,21 @@
*/
package com.android.settings.wifi;
+import static android.content.Context.NETWORK_SCORE_SERVICE;
import static android.content.Context.WIFI_SERVICE;
import android.content.Context;
+import android.net.NetworkScoreManager;
import android.net.wifi.WifiManager;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.network.NetworkScoreManagerWrapper;
+import com.android.settings.network.NetworkScorerPickerPreferenceController;
import com.android.settings.network.WifiCallingPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -54,6 +59,7 @@
public void onAttach(Context context) {
super.onAttach(context);
mProgressiveDisclosureMixin.setTileLimit(2);
+ ((SettingsActivity) getActivity()).setDisplaySearchMenu(true);
}
@Override
@@ -69,6 +75,9 @@
controllers.add(new CellularFallbackPreferenceController(context));
controllers.add(new NotifyOpenNetworksPreferenceController(context, getLifecycle()));
controllers.add(new WifiWakeupPreferenceController(context, getLifecycle()));
+ controllers.add(new NetworkScorerPickerPreferenceController(context,
+ new NetworkScoreManagerWrapper(
+ (NetworkScoreManager) getSystemService(NETWORK_SCORE_SERVICE))));
controllers.add(new WifiSleepPolicyPreferenceController(context));
controllers.add(new WifiP2pPreferenceController(context, getLifecycle(), mWifiManager));
controllers.add(new WifiCallingPreferenceController(context));
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index d652efa..8a3c8ac 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -48,7 +48,6 @@
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
-import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
@@ -93,7 +92,6 @@
/* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
- private static final int MENU_ID_SCAN = Menu.FIRST + 5;
private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
private static final int MENU_ID_FORGET = Menu.FIRST + 7;
private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
@@ -166,7 +164,8 @@
private Preference mSavedNetworksPreference;
private LinkablePreference mStatusMessagePreference;
- private MenuItem mScanMenuItem;
+ // For Search
+ private static final String DATA_KEY_REFERENCE = "main_toggle_wifi";
/* End of "used in Wifi Setup context" */
@@ -369,26 +368,6 @@
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- // If the user is not allowed to configure wifi, do not show the menu.
- if (isUiRestricted()) return;
-
- addOptionsMenuItems(menu);
- super.onCreateOptionsMenu(menu, inflater);
- }
-
- /**
- * @param menu
- */
- void addOptionsMenuItems(Menu menu) {
- final boolean wifiIsEnabled = mWifiTracker.isWifiEnabled();
- mScanMenuItem = menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.menu_stats_refresh)
- .setIcon(com.android.internal.R.drawable.ic_menu_refresh);
- mScanMenuItem.setEnabled(wifiIsEnabled)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
- }
-
- @Override
public int getMetricsCategory() {
return MetricsEvent.WIFI;
}
@@ -440,10 +419,6 @@
case MENU_ID_WPS_PIN:
showDialog(WPS_PIN_DIALOG_ID);
return true;
- case MENU_ID_SCAN:
- mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_WIFI_FORCE_SCAN);
- mWifiTracker.forceScan();
- return true;
}
return super.onOptionsItemSelected(item);
}
@@ -716,9 +691,6 @@
mAccessPointsPreferenceCategory.addPreference(mSeeAllNetworksPreference);
}
setConfigureWifiSettingsVisibility();
- if (mScanMenuItem != null) {
- mScanMenuItem.setEnabled(true);
- }
break;
case WifiManager.WIFI_STATE_ENABLING:
@@ -736,9 +708,6 @@
setOffMessage();
setConfigureWifiSettingsVisibility();
setProgressBarVisible(false);
- if (mScanMenuItem != null) {
- mScanMenuItem.setEnabled(false);
- }
break;
}
}
@@ -1028,6 +997,7 @@
data.title = res.getString(R.string.wifi_settings);
data.screenTitle = res.getString(R.string.wifi_settings);
data.keywords = res.getString(R.string.keywords_wifi);
+ data.key = DATA_KEY_REFERENCE;
result.add(data);
// Add saved Wi-Fi access points
diff --git a/tests/app/Android.mk b/tests/app/Android.mk
index 381006a..c0c0ccf 100644
--- a/tests/app/Android.mk
+++ b/tests/app/Android.mk
@@ -14,6 +14,7 @@
espresso-contrib-nodep \
espresso-intents-nodep \
ub-uiautomator \
+ truth-prebuilt \
legacy-android-test
# Include all test java files.
diff --git a/tests/app/AndroidManifest.xml b/tests/app/AndroidManifest.xml
index 1c50700..6659e5f 100644
--- a/tests/app/AndroidManifest.xml
+++ b/tests/app/AndroidManifest.xml
@@ -22,6 +22,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
+ <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+ <uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
<application>
<uses-library android:name="android.test.runner" />
diff --git a/tests/app/src/com/android/settings/ChooseLockGenericTest.java b/tests/app/src/com/android/settings/ChooseLockGenericTest.java
new file mode 100644
index 0000000..dee6697
--- /dev/null
+++ b/tests/app/src/com/android/settings/ChooseLockGenericTest.java
@@ -0,0 +1,235 @@
+/*
+ * 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 android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.support.test.filters.MediumTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
+import android.support.test.runner.lifecycle.Stage;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject;
+import android.support.test.uiautomator.UiSelector;
+
+import android.text.format.DateUtils;
+import android.view.KeyEvent;
+
+import com.android.settings.R;
+
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link ChooseLockGenericTest}
+ *
+ * m SettingsTests &&
+ * adb install \
+ * -r -g ${ANDROID_PRODUCT_OUT}/data/app/SettingsTests/SettingsTests.apk &&
+ * adb shell am instrument -e class com.android.settings.ChooseLockGenericTest \
+ * -w com.android.settings.tests/android.support.test.runner.AndroidJUnitRunner
+ */
+@RunWith(AndroidJUnit4.class)
+@MediumTest
+public class ChooseLockGenericTest {
+ private static final long TIMEOUT = 5 * DateUtils.SECOND_IN_MILLIS;
+ private static final Intent PHISHING_ATTACK_INTENT = new Intent()
+ .putExtra("confirm_credentials", false)
+ .putExtra("password_confirmed", true);
+
+ private UiDevice mDevice;
+ private Context mTargetContext;
+ private String mSettingPackage;
+ private PackageManager mPackageManager;
+ @Rule
+ public ActivityTestRule<ChooseLockGeneric> mChooseLockGenericActivityRule =
+ new ActivityTestRule<>(
+ ChooseLockGeneric.class,
+ true /* enable touch at launch */,
+ false /* don't launch at every test */);
+
+ @Before
+ public void setUp() throws Exception {
+ mDevice = UiDevice.getInstance(getInstrumentation());
+ mTargetContext = getInstrumentation().getTargetContext();
+ mSettingPackage = mTargetContext.getPackageName();
+ mPackageManager = mTargetContext.getPackageManager();
+
+ setPassword();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ clearPassword();
+ }
+
+ @Test
+ public void testConfirmLockPasswordShown_deviceWithPassword() throws Exception, Throwable {
+ // GIVEN a PIN password is set on this device at set up.
+ // WHEN ChooseLockGeneric is launched with no extras.
+ mChooseLockGenericActivityRule.launchActivity(null /* No extras */);
+ // THEN ConfirmLockPassword.InternalActivity is shown.
+ assertThat(getCurrentActivity()).isInstanceOf(ConfirmLockPassword.InternalActivity.class);
+ }
+
+ @Test
+ public void testConfirmLockPasswordShown_deviceWithPassword_phishingAttack()
+ throws Exception, Throwable {
+ // GIVEN a PIN password is set on this device at set up.
+ // WHEN ChooseLockGeneric is launched with extras to by-pass lock password confirmation.
+ mChooseLockGenericActivityRule.launchActivity(PHISHING_ATTACK_INTENT);
+ // THEN ConfirmLockPassword.InternalActivity is still shown.
+ assertThat(getCurrentActivity()).isInstanceOf(ConfirmLockPassword.InternalActivity.class);
+ }
+
+ private Activity getCurrentActivity() throws Throwable {
+ getInstrumentation().waitForIdleSync();
+ final Activity[] activity = new Activity[1];
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ Collection<Activity> activities = ActivityLifecycleMonitorRegistry.getInstance()
+ .getActivitiesInStage(Stage.RESUMED);
+ activity[0] = activities.iterator().next();
+ }
+ });
+ return activity[0];
+ }
+
+ private void launchNewPassword() throws Exception {
+ Intent newPasswordIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD)
+ .setPackage(mSettingPackage)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ getInstrumentation().getContext().startActivity(newPasswordIntent);
+ mDevice.waitForIdle();
+ }
+
+ /** Sets a PIN password, 12345, for testing. */
+ private void setPassword() throws Exception {
+ launchNewPassword();
+
+ if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
+ // Set "lock_none", but it actually means we don't want to enroll a fingerprint.
+ UiObject view = new UiObject(
+ new UiSelector().resourceId(mSettingPackage + ":id/lock_none"));
+ assertTrue("lock_none", view.waitForExists(TIMEOUT));
+ view.click();
+ mDevice.waitForIdle();
+ }
+
+ // Pick PIN from the option list
+ UiObject view = new UiObject(new UiSelector()
+ .resourceId(mSettingPackage + ":id/lock_pin"));
+ assertTrue("lock_pin", view.waitForExists(TIMEOUT));
+ view.click();
+ mDevice.waitForIdle();
+
+ // Ignore any interstitial options
+ view = new UiObject(new UiSelector()
+ .resourceId(mSettingPackage + ":id/encrypt_dont_require_password"));
+ if (view.waitForExists(TIMEOUT)) {
+ view.click();
+ mDevice.waitForIdle();
+ }
+
+ // Yes, we really want to
+ view = new UiObject(new UiSelector()
+ .resourceId(mSettingPackage + ":id/next_button"));
+ if (view.waitForExists(TIMEOUT)) {
+ view.click();
+ mDevice.waitForIdle();
+ }
+
+ // Set our PIN
+ view = new UiObject(new UiSelector()
+ .resourceId(mSettingPackage + ":id/password_entry"));
+ assertTrue("password_entry", view.waitForExists(TIMEOUT));
+
+ // Enter it twice to confirm
+ enterTestPin();
+ enterTestPin();
+
+ mDevice.pressBack();
+ }
+
+ /** Clears the previous set PIN password. */
+ private void clearPassword() throws Exception {
+ launchNewPassword();
+
+ // Enter current PIN
+ UiObject view = new UiObject(
+ new UiSelector().resourceId(mSettingPackage + ":id/password_entry"));
+ if (!view.waitForExists(TIMEOUT)) {
+ // Odd, maybe there is a crash dialog showing; try dismissing it
+ mDevice.pressBack();
+ mDevice.waitForIdle();
+
+ assertTrue("password_entry", view.waitForExists(TIMEOUT));
+ }
+
+ enterTestPin();
+
+ // Set back to "none"
+ view = new UiObject(new UiSelector().resourceId(mSettingPackage + ":id/lock_none"));
+ assertTrue("lock_none", view.waitForExists(TIMEOUT));
+ view.click();
+ mDevice.waitForIdle();
+
+ // Yes, we really want "none" if prompted again
+ view = new UiObject(new UiSelector().resourceId(mSettingPackage + ":id/lock_none"));
+ if (view.waitForExists(TIMEOUT)) {
+ view.click();
+ mDevice.waitForIdle();
+ }
+
+ // Yes, we really want to
+ view = new UiObject(new UiSelector()
+ .resourceId("android:id/button1"));
+ if (view.waitForExists(TIMEOUT)) {
+ view.click();
+ mDevice.waitForIdle();
+ }
+
+ mDevice.pressBack();
+ }
+
+ private void enterTestPin() throws Exception {
+ mDevice.waitForIdle();
+ mDevice.pressKeyCode(KeyEvent.KEYCODE_1);
+ mDevice.pressKeyCode(KeyEvent.KEYCODE_2);
+ mDevice.pressKeyCode(KeyEvent.KEYCODE_3);
+ mDevice.pressKeyCode(KeyEvent.KEYCODE_4);
+ mDevice.pressKeyCode(KeyEvent.KEYCODE_5);
+ mDevice.waitForIdle();
+ mDevice.pressEnter();
+ mDevice.waitForIdle();
+ }
+}
diff --git a/tests/app/src/com/android/settings/applications/ExternalSourcesSettingsTest.java b/tests/app/src/com/android/settings/applications/ExternalSourcesSettingsTest.java
new file mode 100644
index 0000000..9114c6f
--- /dev/null
+++ b/tests/app/src/com/android/settings/applications/ExternalSourcesSettingsTest.java
@@ -0,0 +1,200 @@
+/*
+ * 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 android.app.AppOpsManager.MODE_ALLOWED;
+import static android.app.AppOpsManager.MODE_DEFAULT;
+import static android.app.AppOpsManager.MODE_ERRORED;
+import static android.app.AppOpsManager.OP_REQUEST_INSTALL_PACKAGES;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import android.app.AppOpsManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.UserInfo;
+import android.net.Uri;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.LargeTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.BySelector;
+import android.support.test.uiautomator.Direction;
+
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.Until;
+import android.widget.ListView;
+import android.widget.Switch;
+import android.widget.TextView;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class ExternalSourcesSettingsTest {
+
+ private static final String TAG = ExternalSourcesSettingsTest.class.getSimpleName();
+ private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
+ private static final long START_ACTIVITY_TIMEOUT = 5000;
+
+ private Context mContext;
+ private UiDevice mUiDevice;
+ private PackageManager mPackageManager;
+ private AppOpsManager mAppOpsManager;
+ private List<UserInfo> mProfiles;
+ private String mPackageName;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext = InstrumentationRegistry.getTargetContext();
+ mPackageName = InstrumentationRegistry.getContext().getPackageName();
+ mPackageManager = mContext.getPackageManager();
+ mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
+ mProfiles = mContext.getSystemService(UserManager.class).getProfiles(UserHandle.myUserId());
+ resetAppOpModeForAllProfiles();
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mUiDevice.wakeUp();
+ mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+ }
+
+ private void resetAppOpModeForAllProfiles() throws Exception {
+ for (UserInfo user : mProfiles) {
+ final int uid = mPackageManager.getPackageUidAsUser(mPackageName, user.id);
+ mAppOpsManager.setMode(OP_REQUEST_INSTALL_PACKAGES, uid, mPackageName, MODE_DEFAULT);
+ }
+ }
+
+ private Intent createManageExternalSourcesListIntent() {
+ final Intent manageExternalSourcesIntent = new Intent();
+ manageExternalSourcesIntent.setAction(Settings.ACTION_MANAGE_EXTERNAL_SOURCES);
+ return manageExternalSourcesIntent;
+ }
+
+ private Intent createManageExternalSourcesAppIntent(String packageName) {
+ final Intent intent = createManageExternalSourcesListIntent();
+ intent.setData(Uri.parse("package:" + packageName));
+ return intent;
+ }
+
+ private String getApplicationLabel(String packageName) throws Exception {
+ final ApplicationInfo info = mPackageManager.getApplicationInfo(packageName, 0);
+ return mPackageManager.getApplicationLabel(info).toString();
+ }
+
+ private UiObject2 findAndVerifySwitchState(boolean checked) {
+ final BySelector switchSelector = By.clazz(Switch.class).res("android:id/switch_widget");
+ final UiObject2 switchPref = mUiDevice.wait(Until.findObject(switchSelector),
+ START_ACTIVITY_TIMEOUT);
+ assertNotNull("Switch not shown", switchPref);
+ assertTrue("Switch in invalid state", switchPref.isChecked() == checked);
+ return switchPref;
+ }
+
+ @Test
+ public void testManageExternalSourcesList() throws Exception {
+ final String testAppLabel = getApplicationLabel(mPackageName);
+
+ mContext.startActivity(createManageExternalSourcesListIntent());
+ final BySelector preferenceListSelector = By.clazz(ListView.class).res("android:id/list");
+ final UiObject2 preferenceList = mUiDevice.wait(Until.findObject(preferenceListSelector),
+ START_ACTIVITY_TIMEOUT);
+ assertNotNull("App list not shown", preferenceList);
+
+ final BySelector appLabelTextViewSelector = By.clazz(TextView.class)
+ .res("android:id/title")
+ .text(testAppLabel);
+ List<UiObject2> listOfMatchingTextViews;
+ do {
+ listOfMatchingTextViews = preferenceList.findObjects(appLabelTextViewSelector);
+ // assuming the number of profiles will be sufficiently small so that all the entries
+ // for the same package will fit in one screen at some time during the scroll.
+ } while (listOfMatchingTextViews.size() != mProfiles.size() &&
+ preferenceList.scroll(Direction.DOWN, 0.2f));
+ assertEquals("Test app not listed for each profile", mProfiles.size(),
+ listOfMatchingTextViews.size());
+
+ for (UiObject2 matchingObject : listOfMatchingTextViews) {
+ matchingObject.click();
+ findAndVerifySwitchState(true);
+ mUiDevice.pressBack();
+ }
+ }
+
+ private void testAppDetailScreenForAppOp(int appOpMode, int userId) throws Exception {
+ final String testAppLabel = getApplicationLabel(mPackageName);
+ final BySelector appDetailTitleSelector = By.clazz(TextView.class)
+ .res("com.android.settings:id/app_detail_title")
+ .text(testAppLabel);
+
+ mAppOpsManager.setMode(OP_REQUEST_INSTALL_PACKAGES,
+ mPackageManager.getPackageUidAsUser(mPackageName, userId), mPackageName, appOpMode);
+ mContext.startActivityAsUser(createManageExternalSourcesAppIntent(mPackageName),
+ UserHandle.of(userId));
+ mUiDevice.wait(Until.findObject(appDetailTitleSelector), START_ACTIVITY_TIMEOUT);
+ findAndVerifySwitchState(appOpMode == MODE_ALLOWED || appOpMode == MODE_DEFAULT);
+ mUiDevice.pressBack();
+ }
+
+ @Test
+ public void testManageExternalSourcesForApp() throws Exception {
+ // App op MODE_DEFAULT is already tested in #testManageExternalSourcesList
+ for (UserInfo user : mProfiles) {
+ testAppDetailScreenForAppOp(MODE_ALLOWED, user.id);
+ testAppDetailScreenForAppOp(MODE_ERRORED, user.id);
+ }
+ }
+
+ private void testSwitchToggle(int fromAppOp, int toAppOp) throws Exception {
+ final int packageUid = mPackageManager.getPackageUid(mPackageName, 0);
+ final boolean initialState = (fromAppOp == MODE_ALLOWED || fromAppOp == MODE_DEFAULT);
+
+ mAppOpsManager.setMode(OP_REQUEST_INSTALL_PACKAGES, packageUid, mPackageName, fromAppOp);
+ mContext.startActivity(createManageExternalSourcesAppIntent(mPackageName));
+ final UiObject2 switchPref = findAndVerifySwitchState(initialState);
+ switchPref.click();
+ Thread.sleep(1000);
+ assertEquals("Toggling switch did not change app op", toAppOp,
+ mAppOpsManager.checkOpNoThrow(OP_REQUEST_INSTALL_PACKAGES, packageUid,
+ mPackageName));
+ mUiDevice.pressBack();
+ }
+
+ @Test
+ public void testIfSwitchTogglesAppOp() throws Exception {
+ testSwitchToggle(MODE_ALLOWED, MODE_ERRORED);
+ testSwitchToggle(MODE_ERRORED, MODE_ALLOWED);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ mUiDevice.pressHome();
+ resetAppOpModeForAllProfiles();
+ }
+}
diff --git a/tests/robotests/src/android/content/om/IOverlayManager.java b/tests/robotests/src/android/content/om/IOverlayManager.java
new file mode 100644
index 0000000..d4f6d10
--- /dev/null
+++ b/tests/robotests/src/android/content/om/IOverlayManager.java
@@ -0,0 +1,26 @@
+/*
+ * 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.content.om;
+
+import android.os.IBinder;
+
+public class IOverlayManager {
+
+ public static class Stub {
+ public static IOverlayManager asInterface(IBinder b) {
+ return null;
+ }
+ }
+}
diff --git a/tests/robotests/src/android/content/om/OverlayInfo.java b/tests/robotests/src/android/content/om/OverlayInfo.java
new file mode 100644
index 0000000..cfd3adc
--- /dev/null
+++ b/tests/robotests/src/android/content/om/OverlayInfo.java
@@ -0,0 +1,18 @@
+/*
+ * 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.content.om;
+
+public class OverlayInfo {
+}
diff --git a/tests/robotests/src/android/net/NetworkScorerAppData.java b/tests/robotests/src/android/net/NetworkScorerAppData.java
new file mode 100644
index 0000000..1eaa8a7
--- /dev/null
+++ b/tests/robotests/src/android/net/NetworkScorerAppData.java
@@ -0,0 +1,112 @@
+package android.net;
+
+import android.annotation.Nullable;
+import android.content.ComponentName;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Objects;
+
+/**
+ * Holds metadata about a discovered network scorer/recommendation application.
+ *
+ * TODO: delete this class once robolectric supports Android O
+ */
+public final class NetworkScorerAppData implements Parcelable {
+ /** UID of the scorer app. */
+ public final int packageUid;
+ private final ComponentName mRecommendationService;
+ /** User visible label in Settings for the recommendation service. */
+ private final String mRecommendationServiceLabel;
+ /**
+ * The {@link ComponentName} of the Activity to start before enabling the "connect to open
+ * wifi networks automatically" feature.
+ */
+ private final ComponentName mEnableUseOpenWifiActivity;
+
+ public NetworkScorerAppData(int packageUid, ComponentName recommendationServiceComp,
+ String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity) {
+ this.packageUid = packageUid;
+ this.mRecommendationService = recommendationServiceComp;
+ this.mRecommendationServiceLabel = recommendationServiceLabel;
+ this.mEnableUseOpenWifiActivity = enableUseOpenWifiActivity;
+ }
+
+ protected NetworkScorerAppData(Parcel in) {
+ packageUid = in.readInt();
+ mRecommendationService = ComponentName.readFromParcel(in);
+ mRecommendationServiceLabel = in.readString();
+ mEnableUseOpenWifiActivity = ComponentName.readFromParcel(in);
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(packageUid);
+ ComponentName.writeToParcel(mRecommendationService, dest);
+ dest.writeString(mRecommendationServiceLabel);
+ ComponentName.writeToParcel(mEnableUseOpenWifiActivity, dest);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ public static final Creator<NetworkScorerAppData> CREATOR =
+ new Creator<NetworkScorerAppData>() {
+ @Override
+ public NetworkScorerAppData createFromParcel(Parcel in) {
+ return new NetworkScorerAppData(in);
+ }
+
+ @Override
+ public NetworkScorerAppData[] newArray(int size) {
+ return new NetworkScorerAppData[size];
+ }
+ };
+
+ public String getRecommendationServicePackageName() {
+ return mRecommendationService.getPackageName();
+ }
+
+ public ComponentName getRecommendationServiceComponent() {
+ return mRecommendationService;
+ }
+
+ @Nullable
+ public ComponentName getEnableUseOpenWifiActivity() {
+ return mEnableUseOpenWifiActivity;
+ }
+
+ @Nullable
+ public String getRecommendationServiceLabel() {
+ return mRecommendationServiceLabel;
+ }
+
+ @Override
+ public String toString() {
+ return "NetworkScorerAppData{" +
+ "packageUid=" + packageUid +
+ ", mRecommendationService=" + mRecommendationService +
+ ", mRecommendationServiceLabel=" + mRecommendationServiceLabel +
+ ", mEnableUseOpenWifiActivity=" + mEnableUseOpenWifiActivity +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ NetworkScorerAppData that = (NetworkScorerAppData) o;
+ return packageUid == that.packageUid &&
+ Objects.equals(mRecommendationService, that.mRecommendationService) &&
+ Objects.equals(mRecommendationServiceLabel, that.mRecommendationServiceLabel) &&
+ Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(packageUid, mRecommendationService, mRecommendationServiceLabel,
+ mEnableUseOpenWifiActivity);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index 6a5b935..7822d83 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -19,14 +19,12 @@
import android.app.ActivityManager;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
-import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
-import com.android.settings.testutils.FakeFeatureFactory;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@@ -45,8 +43,6 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsActivityTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
@Mock
private FragmentManager mFragmentManager;
@Mock
@@ -58,10 +54,6 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mActivity = spy(new SettingsActivity());
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
diff --git a/tests/robotests/src/com/android/settings/ZonePickerTest.java b/tests/robotests/src/com/android/settings/ZonePickerTest.java
index 344eea3..6ab0c2d 100644
--- a/tests/robotests/src/com/android/settings/ZonePickerTest.java
+++ b/tests/robotests/src/com/android/settings/ZonePickerTest.java
@@ -25,6 +25,7 @@
import android.widget.SimpleAdapter;
import android.widget.TextView;
+import com.android.settings.datetime.ZonePicker;
import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
import com.android.settings.testutils.shadow.ShadowTimeZoneNames;
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
index 2b861e2..d2ded86 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
@@ -33,7 +33,6 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.search.SearchIndexableRaw;
-import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowAccountManager;
import com.android.settings.testutils.shadow.ShadowContentResolver;
@@ -55,7 +54,6 @@
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -76,7 +74,6 @@
@Mock(answer = RETURNS_DEEP_STUBS)
private AccountRestrictionHelper mAccountHelper;
- private FakeFeatureFactory mFactory;
private Context mContext;
private AccountPreferenceController mController;
@@ -86,11 +83,8 @@
ShadowApplication shadowContext = ShadowApplication.getInstance();
shadowContext.setSystemService(Context.USER_SERVICE, mUserManager);
shadowContext.setSystemService(Context.ACCOUNT_SERVICE, mAccountManager);
- mContext = spy(shadowContext.getApplicationContext());
- FakeFeatureFactory.setupForTest(mContext);
- mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mContext = shadowContext.getApplicationContext();
- when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(
diff --git a/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
index 50f3ac6..033465b 100644
--- a/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
@@ -23,6 +23,7 @@
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
+import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
import android.support.v7.preference.PreferenceScreen;
@@ -127,11 +128,13 @@
when(mFragment.getActivity()).thenReturn(activity);
Account account = new Account("Account11", "com.acct1");
+ UserHandle userHandle = new UserHandle(10);
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog dialog =
- RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(mFragment, account);
-
+ RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(
+ mFragment, account, userHandle);
+ dialog.onCreate(new Bundle());
dialog.onClick(null, 0);
verify(mAccountManager).removeAccountAsUser(eq(account), any(Activity.class),
- any(AccountManagerCallback.class), any(Handler.class), any(UserHandle.class));
+ any(AccountManagerCallback.class), any(Handler.class), eq(userHandle));
}
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
index e1c2abf..39ffcf8 100644
--- a/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
@@ -16,7 +16,6 @@
package com.android.settings.accounts;
import android.app.Activity;
-import android.content.Context;
import android.content.pm.UserInfo;
import android.os.Bundle;
import android.os.UserManager;
@@ -25,14 +24,12 @@
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.Tile;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -54,8 +51,6 @@
private static final String METADATA_CATEGORY = "com.android.settings.category";
private static final String METADATA_ACCOUNT_TYPE = "com.android.settings.ia.account";
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
@Mock
private UserManager mUserManager;
private UserAndAccountDashboardFragment mFragment;
@@ -63,10 +58,6 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mFragment = new UserAndAccountDashboardFragment();
}
diff --git a/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java b/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
index 56d4a83..a717306 100644
--- a/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppInfoWithHeaderTest.java
@@ -72,7 +72,6 @@
ShadowApplication.getInstance().getApplicationContext(),
mAppInfoWithHeader,
null);
- when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
when(mFactory.applicationFeatureProvider.newAppHeaderController(mAppInfoWithHeader, null))
.thenReturn(appHeaderController);
mAppInfoWithHeader.onActivityCreated(null);
diff --git a/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
new file mode 100644
index 0000000..7204bd1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/AppStorageSizesControllerTest.java
@@ -0,0 +1,95 @@
+package com.android.settings.applications;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+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.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import com.android.settings.R;
+import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AppStorageSizesControllerTest {
+ private static final String COMPUTING = "Computing…";
+ private static final String INVALID_SIZE = "Couldn’t compute package size.";
+ private AppStorageSizesController mController;
+ private Context mContext;
+
+ private Preference mAppPreference;
+ private Preference mCachePreference;
+ private Preference mDataPreference;
+ private Preference mTotalPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mAppPreference = new Preference(mContext);
+ mCachePreference = new Preference(mContext);
+ mDataPreference = new Preference(mContext);
+ mTotalPreference = new Preference(mContext);
+
+ mController = new AppStorageSizesController.Builder()
+ .setAppSizePreference(mAppPreference)
+ .setCacheSizePreference(mCachePreference)
+ .setDataSizePreference(mDataPreference)
+ .setTotalSizePreference(mTotalPreference)
+ .setErrorString(R.string.invalid_size_value)
+ .setComputingString(R.string.computing_size)
+ .build();
+ }
+
+ @Test
+ public void requestingUpdateBeforeValuesSetIsComputing() {
+ mController.updateUi(mContext);
+
+ assertThat(mAppPreference.getSummary()).isEqualTo(COMPUTING);
+ assertThat(mCachePreference.getSummary()).isEqualTo(COMPUTING);
+ assertThat(mDataPreference.getSummary()).isEqualTo(COMPUTING);
+ assertThat(mTotalPreference.getSummary()).isEqualTo(COMPUTING);
+ }
+
+ @Test
+ public void requestingUpdateAfterFailureHasErrorText() {
+ mController.setResult(null);
+ mController.updateUi(mContext);
+
+ assertThat(mAppPreference.getSummary()).isEqualTo(INVALID_SIZE);
+ assertThat(mCachePreference.getSummary()).isEqualTo(INVALID_SIZE);
+ assertThat(mDataPreference.getSummary()).isEqualTo(INVALID_SIZE);
+ assertThat(mTotalPreference.getSummary()).isEqualTo(INVALID_SIZE);
+ }
+
+ @Test
+ public void properlyPopulatedAfterValidEntry() {
+ 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.updateUi(mContext);
+
+ assertThat(mAppPreference.getSummary()).isEqualTo("1.00B");
+ assertThat(mCachePreference.getSummary()).isEqualTo("10.00B");
+ assertThat(mDataPreference.getSummary()).isEqualTo("100B");
+ assertThat(mTotalPreference.getSummary()).isEqualTo("111B");
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
index 0b1d1aa..04eeb02 100644
--- a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
@@ -43,6 +43,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class FetchPackageStorageAsyncLoaderTest {
+ private static final String PACKAGE_NAME = "com.test.package";
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
@@ -63,10 +64,22 @@
when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class)))
.thenReturn(stats);
ApplicationInfo info = new ApplicationInfo();
- info.packageName = "com.test.package";
+ info.packageName = PACKAGE_NAME;
FetchPackageStorageAsyncLoader task = new FetchPackageStorageAsyncLoader(
mContext, mSource, info, new UserHandle(0));
assertThat(task.loadInBackground()).isEqualTo(stats);
}
+
+ @Test
+ public void installerExceptionHandledCleanly() {
+ when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class))).
+ thenThrow(new IllegalStateException("intentional failure"));
+ ApplicationInfo info = new ApplicationInfo();
+ info.packageName = PACKAGE_NAME;
+ FetchPackageStorageAsyncLoader task = new FetchPackageStorageAsyncLoader(
+ mContext, mSource, info, new UserHandle(0));
+
+ assertThat(task.loadInBackground()).isNull();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index 2a703ef..b0cd8d5 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -16,7 +16,10 @@
package com.android.settings.applications;
+
+import android.app.Activity;
import android.app.admin.DevicePolicyManager;
+import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.UserManager;
@@ -25,6 +28,7 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
import org.junit.Before;
import org.junit.Test;
@@ -32,14 +36,18 @@
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+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 final class InstalledAppDetailsTest {
@@ -47,24 +55,27 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private UserManager mUserManager;
@Mock
+ private Activity mActivity;
+ @Mock
private DevicePolicyManager mDevicePolicyManager;
+ private InstalledAppDetails mAppDetail;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mAppDetail = new InstalledAppDetails();
}
@Test
public void getInstallationStatus_notInstalled_shouldReturnUninstalled() {
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
assertThat(mAppDetail.getInstallationStatus(new ApplicationInfo()))
- .isEqualTo(R.string.not_installed);
+ .isEqualTo(R.string.not_installed);
}
@Test
public void getInstallationStatus_enabled_shouldReturnInstalled() {
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
final ApplicationInfo info = new ApplicationInfo();
info.flags = ApplicationInfo.FLAG_INSTALLED;
info.enabled = true;
@@ -74,7 +85,6 @@
@Test
public void getInstallationStatus_disabled_shouldReturnDisabled() {
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
final ApplicationInfo info = new ApplicationInfo();
info.flags = ApplicationInfo.FLAG_INSTALLED;
info.enabled = false;
@@ -86,7 +96,6 @@
public void shouldShowUninstallForAll_installForOneOtherUserOnly_shouldReturnTrue() {
when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
when(mUserManager.getUsers().size()).thenReturn(2);
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
final ApplicationInfo info = new ApplicationInfo();
@@ -103,7 +112,6 @@
public void shouldShowUninstallForAll_installForSelfOnly_shouldReturnFalse() {
when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
when(mUserManager.getUsers().size()).thenReturn(2);
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
final ApplicationInfo info = new ApplicationInfo();
@@ -117,4 +125,40 @@
assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isFalse();
}
+ @Test
+ public void getStorageSummary_shouldWorkForExternal() {
+ Context context = RuntimeEnvironment.application.getApplicationContext();
+ AppStorageStats stats = mock(AppStorageStats.class);
+ when(stats.getTotalBytes()).thenReturn(1L);
+
+ assertThat(InstalledAppDetails.getStorageSummary(context, stats, true))
+ .isEqualTo("1.00B used in External storage");
+ }
+
+ @Test
+ public void getStorageSummary_shouldWorkForInternal() {
+ Context context = RuntimeEnvironment.application.getApplicationContext();
+ AppStorageStats stats = mock(AppStorageStats.class);
+ when(stats.getTotalBytes()).thenReturn(1L);
+
+ assertThat(InstalledAppDetails.getStorageSummary(context, stats, false))
+ .isEqualTo("1.00B used in Internal storage");
+ }
+
+ @Test
+ public void launchFragment_hasNoPackageInfo_shouldFinish() {
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", null);
+
+ assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isFalse();
+ verify(mActivity).finishAndRemoveTask();
+ }
+
+ @Test
+ public void launchFragment_hasPackageInfo_shouldReturnTrue() {
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+
+ assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isTrue();
+ verify(mActivity, never()).finishAndRemoveTask();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/assist/GestureAssistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/GestureAssistPreferenceControllerTest.java
deleted file mode 100644
index 624a01f..0000000
--- a/tests/robotests/src/com/android/settings/applications/assist/GestureAssistPreferenceControllerTest.java
+++ /dev/null
@@ -1,64 +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.assist;
-
-import android.content.Context;
-
-import com.android.settings.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.when;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class GestureAssistPreferenceControllerTest {
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
- private FakeFeatureFactory mFeatureFactory;
- private GestureAssistPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- mController = new GestureAssistPreferenceController(mContext);
- }
-
- @Test
- public void isAvailable_shouldReturnFeatureProviderValue() {
- when(mFeatureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
- .thenReturn(true);
- assertThat(mController.isAvailable()).isTrue();
-
- when(mFeatureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
- .thenReturn(false);
- assertThat(mController.isAvailable()).isFalse();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutoFillPickerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
similarity index 91%
rename from tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutoFillPickerTest.java
rename to tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
index f2cf729..1bd611b 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutoFillPickerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPickerTest.java
@@ -24,6 +24,7 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.PackageManagerWrapper;
+import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
@@ -45,7 +46,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class DefaultAutoFillPickerTest {
+public class DefaultAutofillPickerTest {
private static final String TEST_APP_KEY = "123";
@@ -55,13 +56,14 @@
private UserManager mUserManager;
@Mock
private PackageManagerWrapper mPackageManager;
- private DefaultAutoFillPicker mPicker;
+ private DefaultAutofillPicker mPicker;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mActivity);
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mPicker = spy(new DefaultAutoFillPicker());
+ mPicker = spy(new DefaultAutofillPicker());
mPicker.onAttach((Context) mActivity);
ReflectionHelpers.setField(mPicker, "mPm", mPackageManager);
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutoFillPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
similarity index 90%
rename from tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutoFillPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
index 1c37368..7bcbcb0 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutoFillPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
@@ -45,7 +45,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class DefaultAutoFillPreferenceControllerTest {
+public class DefaultAutofillPreferenceControllerTest {
@Mock
private Context mContext;
@@ -54,14 +54,14 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PackageManagerWrapper mPackageManager;
- private DefaultAutoFillPreferenceController mController;
+ private DefaultAutofillPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mController = spy(new DefaultAutoFillPreferenceController(mContext));
+ mController = spy(new DefaultAutofillPreferenceController(mContext));
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
}
@@ -82,7 +82,7 @@
public void getDefaultAppInfo_shouldHaveSettingsProvider() {
ReflectionHelpers.setField(mController, "mContext", RuntimeEnvironment.application);
Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(),
- DefaultAutoFillPicker.SETTING, "com.android.settings/SettingsActivity.class");
+ DefaultAutofillPicker.SETTING, "com.android.settings/SettingsActivity.class");
final DefaultAppInfo info = mController.getDefaultAppInfo();
@@ -91,6 +91,6 @@
mController.getSettingIntent(info);
verify(mPackageManager.getPackageManager()).queryIntentServices(
- DefaultAutoFillPicker.AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
+ DefaultAutofillPicker.AUTOFILL_PROBE, PackageManager.GET_META_DATA);
}
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
new file mode 100644
index 0000000..5915118
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.bluetooth;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static 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 BluetoothDevicePreferenceTest {
+
+ private Context mContext;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDevice;
+
+ private FakeFeatureFactory mFakeFeatureFactory;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+ private BluetoothDevicePreference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+ FakeFeatureFactory.setupForTest(mContext);
+ mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
+ mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice);
+ }
+
+ @Test
+ public void onClicked_deviceConnected_shouldLogBluetoothDisconnectEvent() {
+ when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
+
+ mPreference.onClicked();
+
+ verify(mMetricsFeatureProvider).action(
+ mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
+ }
+
+ @Test
+ public void onClicked_deviceBonded_shouldLogBluetoothConnectEvent() {
+ when(mCachedBluetoothDevice.isConnected()).thenReturn(false);
+ when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
+
+ mPreference.onClicked();
+
+ verify(mMetricsFeatureProvider).action(
+ mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
+ }
+
+ @Test
+ public void onClicked_deviceNotBonded_shouldLogBluetoothPairEvent() {
+ when(mCachedBluetoothDevice.isConnected()).thenReturn(false);
+ when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
+ when(mCachedBluetoothDevice.startPairing()).thenReturn(true);
+
+ mPreference.onClicked();
+
+ verify(mMetricsFeatureProvider).action(
+ mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
new file mode 100644
index 0000000..7761afc
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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 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.bluetooth.LocalBluetoothManager;
+
+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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BluetoothEnablerTest {
+
+ @Mock
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+ @Mock
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void onSwitchToggled_shouldLogActionWithSuppliedEvent() {
+ BluetoothEnabler bluetoothEnabler = new BluetoothEnabler(mContext,
+ mock(MasterSwitchController.class), mMetricsFeatureProvider,
+ mock(LocalBluetoothManager.class), 123);
+ bluetoothEnabler.onSwitchToggled(false);
+
+ verify(mMetricsFeatureProvider).action(mContext, 123, false);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
new file mode 100644
index 0000000..5f4b101
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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 com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import static org.mockito.Matchers.anyInt;
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class UtilsTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private LocalBluetoothManager mLocalBluetoothManager;
+
+ private FakeFeatureFactory mFakeFeatureFactory;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mContext);
+ mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
+ }
+
+ @Test
+ public void showConnectingError_shouldLogBluetoothConnectError() {
+ when(mContext.getString(anyInt(), anyString())).thenReturn("testMessage");
+ Utils.showConnectingError(mContext, "testName", mock(LocalBluetoothManager.class));
+
+ verify(mMetricsFeatureProvider).visible(eq(mContext), anyInt(),
+ eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
index 83bae50..fc4b75f 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
@@ -15,44 +15,30 @@
*/
package com.android.settings.connecteddevice;
-import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ConnectedDeviceDashboardFragmentTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
-
private ConnectedDeviceDashboardFragment mFragment;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mFragment = new ConnectedDeviceDashboardFragment();
}
diff --git a/tests/robotests/src/com/android/settings/core/DynamicAvailabilityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/core/DynamicAvailabilityPreferenceControllerTest.java
new file mode 100644
index 0000000..38a8356
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/core/DynamicAvailabilityPreferenceControllerTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.core;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.lifecycle.Lifecycle;
+
+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 static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link DynamicAvailabilityPreferenceController}.
+ */
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class DynamicAvailabilityPreferenceControllerTest {
+
+ private final String PREFERENCE_KEY = "preference_key";
+
+ private @Mock Context mContext;
+ private @Mock Preference mPreference;
+ private @Mock PreferenceScreen mScreen;
+ private @Mock Lifecycle mLifecycle;
+
+ private boolean mIsAvailable;
+ private Preference mUpdatedPreference = null;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
+ when(mScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
+ when(mScreen.getPreferenceCount()).thenReturn(1);
+ when(mScreen.getPreference(0)).thenReturn(mPreference);
+ }
+
+ @Test
+ public void testAvailableToUnavailable() {
+ mIsAvailable = true;
+
+ final DynamicAvailabilityPreferenceController controller
+ = new DynamicAvailabilityPreferenceControllerTestable(mLifecycle);
+ verify(mLifecycle).addObserver(controller);
+
+ controller.displayPreference(mScreen);
+ verify(mScreen, never()).removePreference(mPreference);
+ verify(mScreen, never()).addPreference(mPreference);
+ assertThat(mUpdatedPreference).isNull();
+
+ controller.onResume();
+ verify(mScreen, never()).removePreference(mPreference);
+ verify(mScreen, never()).addPreference(mPreference);
+ assertThat(mUpdatedPreference).isEqualTo(mPreference);
+
+ mUpdatedPreference = null;
+ mIsAvailable = false;
+ controller.onResume();
+ verify(mScreen).removePreference(mPreference);
+ verify(mScreen, never()).addPreference(mPreference);
+ assertThat(mUpdatedPreference).isNull();
+ }
+
+ @Test
+ public void testUnavailableToAvailable() {
+ mIsAvailable = false;
+
+ final DynamicAvailabilityPreferenceController controller
+ = new DynamicAvailabilityPreferenceControllerTestable(mLifecycle);
+ verify(mLifecycle).addObserver(controller);
+
+ controller.displayPreference(mScreen);
+ verify(mScreen).removePreference(mPreference);
+ verify(mScreen, never()).addPreference(mPreference);
+ assertThat(mUpdatedPreference).isNull();
+
+ reset(mScreen);
+ controller.onResume();
+ verify(mScreen, never()).removePreference(mPreference);
+ verify(mScreen, never()).addPreference(mPreference);
+ assertThat(mUpdatedPreference).isNull();
+
+ mIsAvailable = true;
+ controller.onResume();
+ verify(mScreen, never()).removePreference(mPreference);
+ verify(mScreen).addPreference(mPreference);
+ assertThat(mUpdatedPreference).isEqualTo(mPreference);
+ }
+
+
+ private class DynamicAvailabilityPreferenceControllerTestable
+ extends DynamicAvailabilityPreferenceController {
+ public DynamicAvailabilityPreferenceControllerTestable(Lifecycle lifecycle) {
+ super(DynamicAvailabilityPreferenceControllerTest.this.mContext, lifecycle);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return mIsAvailable;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ mUpdatedPreference = preference;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREFERENCE_KEY;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java b/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
index eeaa175..763d6e3 100644
--- a/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
+++ b/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.content.SharedPreferences;
+import android.util.Pair;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -32,7 +33,6 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -71,7 +71,8 @@
editor.putInt(TEST_KEY, 2);
editor.putInt(TEST_KEY, 2);
- verify(mMetricsFeature, times(6)).count(any(Context.class), anyString(), anyInt());
+ verify(mMetricsFeature, times(6)).action(any(Context.class), anyInt(),
+ any(Pair.class), any(Pair.class));
}
@Test
@@ -83,7 +84,8 @@
editor.putBoolean(TEST_KEY, false);
editor.putBoolean(TEST_KEY, false);
- verify(mMetricsFeature, times(4)).count(any(Context.class), anyString(), anyInt());
+ verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
+ any(Pair.class), any(Pair.class));
}
@Test
@@ -95,7 +97,8 @@
editor.putLong(TEST_KEY, 1);
editor.putLong(TEST_KEY, 2);
- verify(mMetricsFeature, times(4)).count(any(Context.class), anyString(), anyInt());
+ verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
+ any(Pair.class), any(Pair.class));
}
@Test
@@ -107,7 +110,8 @@
editor.putFloat(TEST_KEY, 1);
editor.putFloat(TEST_KEY, 2);
- verify(mMetricsFeature, times(4)).count(any(Context.class), anyString(), anyInt());
+ verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
+ any(Pair.class), any(Pair.class));
}
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 5902ec0..4eea05e 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -57,7 +57,6 @@
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
@@ -268,24 +267,12 @@
}
@Test
- public void getPreferences_notEnabled_shouldReturnNull() {
- final DashboardFeatureProviderImpl mSpy = spy(mImpl);
- when(mSpy.isEnabled()).thenReturn(false);
-
- assertThat(mSpy.getPreferencesForCategory(null, null,
- MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
- .isNull();
- }
-
- @Test
public void getPreferences_noCategory_shouldReturnNull() {
mImpl = new DashboardFeatureProviderImpl(mActivity, mCategoryManager);
- final DashboardFeatureProviderImpl mSpy = spy(mImpl);
- when(mSpy.isEnabled()).thenReturn(true);
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
.thenReturn(null);
- assertThat(mSpy.getPreferencesForCategory(null, null,
+ assertThat(mImpl.getPreferencesForCategory(null, null,
MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
.isNull();
}
@@ -293,12 +280,10 @@
@Test
public void getPreferences_noTileForCategory_shouldReturnNull() {
mImpl = new DashboardFeatureProviderImpl(mActivity, mCategoryManager);
- final DashboardFeatureProviderImpl mSpy = spy(mImpl);
- when(mSpy.isEnabled()).thenReturn(true);
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
.thenReturn(new DashboardCategory());
- assertThat(mSpy.getPreferencesForCategory(null, null,
+ assertThat(mImpl.getPreferencesForCategory(null, null,
MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
.isNull();
}
@@ -306,15 +291,13 @@
@Test
public void getPreferences_hasTileForCategory_shouldReturnPrefList() {
mImpl = new DashboardFeatureProviderImpl(mActivity, mCategoryManager);
- final DashboardFeatureProviderImpl mSpy = spy(mImpl);
- when(mSpy.isEnabled()).thenReturn(true);
final DashboardCategory category = new DashboardCategory();
category.tiles.add(new Tile());
when(mCategoryManager
.getTilesByCategory(any(Context.class), eq(CategoryKey.CATEGORY_HOMEPAGE)))
.thenReturn(category);
- assertThat(mSpy.getPreferencesForCategory(mActivity,
+ assertThat(mImpl.getPreferencesForCategory(mActivity,
ShadowApplication.getInstance().getApplicationContext(),
MetricsProto.MetricsEvent.SETTINGS_GESTURES,
CategoryKey.CATEGORY_HOMEPAGE).isEmpty())
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
index b3f9fe0..a8e294c 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
@@ -75,7 +75,6 @@
@Test
public void updateCategoryAndSuggestion_shouldGetCategoryFromFeatureProvider() {
doReturn(mock(Activity.class)).when(mSummary).getActivity();
- when(mDashboardFeatureProvider.isEnabled()).thenReturn(true);
mSummary.updateCategoryAndSuggestion(null);
verify(mDashboardFeatureProvider).getTilesForCategory(CategoryKey.CATEGORY_HOMEPAGE);
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java b/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java
index e7f97c3..e872a09 100644
--- a/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java
@@ -77,13 +77,11 @@
mAppContext = ShadowApplication.getInstance().getApplicationContext();
mFakeFeatureFactory = (FakeFeatureFactory) FeatureFactory.getFactory(mContext);
mMixin = new ProgressiveDisclosureMixin(mAppContext,
- mFakeFeatureFactory.dashboardFeatureProvider,
mFakeFeatureFactory.metricsFeatureProvider,
mPreferenceFragment);
ReflectionHelpers.setField(mMixin, "mExpandButton", mExpandButton);
mPreference = new Preference(mAppContext);
mPreference.setKey("test");
- when(mFakeFeatureFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
}
@Test
@@ -97,7 +95,6 @@
@Test
public void shouldCollapse_morePreferenceThanLimit() {
- when(mFakeFeatureFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
when(mScreen.getPreferenceCount()).thenReturn(5);
mMixin.setTileLimit(3);
diff --git a/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java b/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java
new file mode 100644
index 0000000..4acac70
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.datetime;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
+import com.android.settings.testutils.shadow.ShadowZoneGetter;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ZonePickerTest {
+
+ private Activity mActivity;
+ private ZonePicker mZonePicker;
+
+ @Before
+ public void setUp() {
+ mActivity = Robolectric.setupActivity(Activity.class);
+ mZonePicker = spy(ZonePicker.class);
+ ReflectionHelpers.setField(mZonePicker, "mVisibilityLoggerMixin",
+ mock(VisibilityLoggerMixin.class));
+ }
+
+ @Test
+ @Config(shadows = ShadowZoneGetter.class)
+ public void testLaunch() {
+ // Shouldn't crash
+ mActivity.getFragmentManager()
+ .beginTransaction()
+ .add(mZonePicker, "test_tag")
+ .commit();
+
+ // Should render
+ verify(mZonePicker).onCreateView(
+ any(LayoutInflater.class),
+ any(ViewGroup.class),
+ any(Bundle.class));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java
index 06d81de..ea60e4c 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.deviceinfo;
+import android.app.Fragment;
import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -32,15 +33,20 @@
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
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 DeviceModelPreferenceControllerTest {
+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Fragment mFragment;
@Mock
private Preference mPreference;
@Mock
@@ -50,9 +56,10 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new DeviceModelPreferenceController(mContext);
+ mController = new DeviceModelPreferenceController(mContext, mFragment);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
+ when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
@@ -66,4 +73,13 @@
verify(mPreference).setSummary(anyString());
}
+
+ @Test
+ public void clickPreference_shouldLaunchHardwareInfoDialog() {
+ assertThat(mController.handlePreferenceTreeClick(mPreference))
+ .isTrue();
+ verify(mFragment).getFragmentManager();
+ verify(mFragment.getFragmentManager().beginTransaction())
+ .add(any(HardwareInfoDialogFragment.class), eq(HardwareInfoDialogFragment.TAG));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java
new file mode 100644
index 0000000..245d7d6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.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.deviceinfo;
+
+import android.app.Activity;
+import android.os.SystemProperties;
+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.Robolectric;
+import org.robolectric.annotation.Config;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class HardwareInfoDialogFragmentTest {
+
+ private Activity mActivity;
+
+ @Before
+ public void setUp() {
+ mActivity = Robolectric.setupActivity(Activity.class);
+ }
+
+ @Test
+ public void display_shouldShowHardwareRevision() {
+ final String TEST_HARDWARE_REV = "123";
+ SystemProperties.set("ro.boot.hardware.revision", TEST_HARDWARE_REV);
+
+ final HardwareInfoDialogFragment fragment = spy(HardwareInfoDialogFragment.newInstance());
+ fragment.show(mActivity.getFragmentManager(), HardwareInfoDialogFragment.TAG);
+
+ verify(fragment).setText(
+ any(View.class), eq(R.id.model_label), eq(R.id.model_value),
+ anyString());
+
+ verify(fragment).setText(
+ any(View.class), eq(R.id.hardware_rev_label), eq(R.id.hardware_rev_value),
+ anyString());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/ManageStoragePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/ManageStoragePreferenceControllerTest.java
deleted file mode 100644
index 14c6d72..0000000
--- a/tests/robotests/src/com/android/settings/deviceinfo/ManageStoragePreferenceControllerTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.deviceinfo;
-
-
-import android.content.Context;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import com.android.settings.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Answers.RETURNS_DEEP_STUBS;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-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 ManageStoragePreferenceControllerTest {
-
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
- @Mock(answer = RETURNS_DEEP_STUBS)
- private PreferenceScreen mScreen;
-
- private ManageStoragePreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mController = new ManageStoragePreferenceController(mContext);
- }
-
- @Test
- public void updateNonIndexableKey_prefUnavaiable_shouldUpdate() {
- final List<String> keys = new ArrayList<>();
- mController.updateNonIndexableKeys(keys);
-
- assertThat(keys).isNotEmpty();
- }
-
- @Test
- public void updateNonIndexableKey_prefAvaiable_shouldNotUpdate() {
- final List<String> keys = new ArrayList<>();
- when(mContext.getResources().getBoolean(
- com.android.settings.R.bool.config_storage_manager_settings_enabled))
- .thenReturn(true);
-
- mController.updateNonIndexableKeys(keys);
-
- assertThat(keys).isEmpty();
- }
-
- @Test
- public void displayPref_prefAvaiable_shouldDisplay() {
- when(mContext.getResources().getBoolean(
- com.android.settings.R.bool.config_storage_manager_settings_enabled))
- .thenReturn(true);
-
- mController.displayPreference(mScreen);
-
- verify(mScreen, never()).removePreference(any(Preference.class));
- }
-
- @Test
- public void displayPref_prefNotAvaiable_shouldNotDisplay() {
- final Preference preference = mock(Preference.class);
- when(mScreen.getPreferenceCount()).thenReturn(1);
- when(mScreen.getPreference(0)).thenReturn(preference);
- when(preference.getKey()).thenReturn(mController.getPreferenceKey());
-
- mController.displayPreference(mScreen);
-
- verify(mScreen).removePreference(any(Preference.class));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
index e2a46de..9baeda3 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
@@ -15,7 +15,6 @@
*/
package com.android.settings.deviceinfo;
-import android.content.Context;
import android.os.Bundle;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
@@ -24,7 +23,6 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
@@ -46,8 +44,6 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageDashboardFragmentTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private StorageManager mStorageManager;
@@ -57,10 +53,6 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mFragment = new StorageDashboardFragment();
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
new file mode 100644
index 0000000..8da2a9c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.settings.deviceinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.util.SparseArray;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
+import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
+import com.android.settingslib.applications.StorageStatsSource;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class StorageProfileFragmentTest {
+ @Test
+ public void verifyAppSizesAreZeroedOut() {
+ StorageItemPreferenceController controller = mock(StorageItemPreferenceController.class);
+ StorageProfileFragment fragment = new StorageProfileFragment();
+ StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
+ result.musicAppsSize = 100;
+ result.otherAppsSize = 200;
+ result.gamesSize = 300;
+ result.externalStats = new StorageStatsSource.ExternalStorageStats(6, 1, 2, 3);
+ SparseArray<StorageAsyncLoader.AppsStorageResult> resultsArray = new SparseArray<>();
+ resultsArray.put(0, result);
+ fragment.setPreferenceController(controller);
+
+ fragment.onLoadFinished(null, resultsArray);
+
+ ArgumentCaptor<StorageAsyncLoader.AppsStorageResult> resultCaptor = ArgumentCaptor.forClass(
+ StorageAsyncLoader.AppsStorageResult.class);
+ verify(controller).onLoadFinished(resultCaptor.capture());
+
+ StorageAsyncLoader.AppsStorageResult extractedResult = resultCaptor.getValue();
+ assertThat(extractedResult.musicAppsSize).isEqualTo(0);
+ assertThat(extractedResult.otherAppsSize).isEqualTo(0);
+ assertThat(extractedResult.gamesSize).isEqualTo(0);
+ assertThat(extractedResult.externalStats.audioBytes).isEqualTo(1);
+ assertThat(extractedResult.externalStats.videoBytes).isEqualTo(2);
+ assertThat(extractedResult.externalStats.imageBytes).isEqualTo(3);
+ assertThat(extractedResult.externalStats.totalBytes).isEqualTo(6);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
new file mode 100644
index 0000000..ee8e7d1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java
@@ -0,0 +1,172 @@
+/*
+ * 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.storage;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.deletionhelper.ActivationWarningFragment;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
+import com.android.settings.widget.MasterSwitchPreference;
+import com.android.settings.overlay.FeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AutomaticStorageManagementSwitchPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private MasterSwitchPreference mPreference;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mMockContext;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private FragmentManager mFragmentManager;
+
+ private Context mContext;
+ private AutomaticStorageManagementSwitchPreferenceController mController;
+ private MetricsFeatureProvider mMetricsFeature;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application.getApplicationContext();
+ FeatureFactory factory = FeatureFactory.getFactory(mContext);
+ mMetricsFeature = factory.getMetricsFeatureProvider();
+
+ mController = new AutomaticStorageManagementSwitchPreferenceController(
+ mContext, mMetricsFeature, mFragmentManager);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void isAvailable_shouldAlwaysReturnTrue() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void onResume_shouldReflectEnabledStatus() {
+ mController.displayPreference(mScreen);
+ ContentResolver resolver = mContext.getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);
+
+ mController.onResume();
+
+ verify(mPreference).setChecked(eq(true));
+ }
+
+ @Test
+ public void onResume_shouldRegisterCallback() {
+ mController.displayPreference(mScreen);
+ mController.onResume();
+
+ verify(mPreference).setOnPreferenceChangeListener(
+ any(Preference.OnPreferenceChangeListener.class));
+ }
+
+ @Test
+ public void togglingShouldCauseMetricsEvent() {
+ // FakeFeatureFactory uses mock contexts, so this test scaffolds itself rather than using
+ // the instance variables.
+ FakeFeatureFactory.setupForTest(mMockContext);
+ FakeFeatureFactory factory =
+ (FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
+ AutomaticStorageManagementSwitchPreferenceController controller =
+ new AutomaticStorageManagementSwitchPreferenceController(
+ mMockContext, factory.metricsFeatureProvider, mFragmentManager);
+
+ controller.onSwitchToggled(true);
+
+ verify(factory.metricsFeatureProvider, times(1)).action(
+ any(Context.class), eq(MetricsEvent.ACTION_TOGGLE_STORAGE_MANAGER), eq(true));
+ }
+
+ @Test
+ public void togglingShouldUpdateSettingsSecure() {
+ mController.onSwitchToggled(true);
+
+ ContentResolver resolver = mContext.getContentResolver();
+ assertThat(Settings.Secure.getInt(
+ resolver, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)).isNotEqualTo(0);
+ }
+
+ @Test
+ public void togglingOnShouldTriggerWarningFragment() {
+ FragmentTransaction transaction = mock(FragmentTransaction.class);
+ when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+
+ mController.onSwitchToggled(true);
+
+ verify(transaction).add(any(), eq(ActivationWarningFragment.TAG));
+ }
+
+ @Test
+ public void togglingOffShouldTriggerWarningFragment() {
+ FragmentTransaction transaction = mock(FragmentTransaction.class);
+ when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+
+ mController.onSwitchToggled(false);
+
+ verify(transaction, never()).add(any(), eq(ActivationWarningFragment.TAG));
+ }
+
+
+ @Config(shadows = {SettingsShadowSystemProperties.class})
+ @Test
+ public void togglingOnShouldNotTriggerWarningFragmentIfEnabledByDefault() {
+ FragmentTransaction transaction = mock(FragmentTransaction.class);
+ when (mFragmentManager.beginTransaction()).thenReturn(transaction);
+ SettingsShadowSystemProperties.set(
+ AutomaticStorageManagementSwitchPreferenceController
+ .STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, "true");
+
+ mController.onSwitchToggled(true);
+
+ verify(transaction, never()).add(any(), eq(ActivationWarningFragment.TAG));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
index 7222f53..c8f3069 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
@@ -55,6 +55,10 @@
private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users";
@Mock
private UserManagerWrapper mUserManager;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private PreferenceGroup mGroup;
private Context mContext;
private SecondaryUserController mController;
@@ -66,19 +70,19 @@
mContext = RuntimeEnvironment.application;
mPrimaryUser = new UserInfo();
mController = new SecondaryUserController(mContext, mPrimaryUser);
+
+ when(mScreen.getContext()).thenReturn(mContext);
+ when(mScreen.findPreference(anyString())).thenReturn(mGroup);
+ when(mGroup.getKey()).thenReturn(TARGET_PREFERENCE_GROUP_KEY);
}
@Test
public void controllerAddsSecondaryUser() throws Exception {
mPrimaryUser.name = TEST_NAME;
- PreferenceScreen screen = mock(PreferenceScreen.class);
- PreferenceGroup group = mock(PreferenceGroup.class);
- when(screen.findPreference(anyString())).thenReturn(group);
- when(group.getKey()).thenReturn(TARGET_PREFERENCE_GROUP_KEY);
- mController.displayPreference(screen);
+ mController.displayPreference(mScreen);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
- verify(group).addPreference(argumentCaptor.capture());
+ verify(mGroup).addPreference(argumentCaptor.capture());
Preference preference = argumentCaptor.getValue();
assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
}
@@ -86,15 +90,11 @@
@Test
public void controllerUpdatesSummaryOfNewPreference() throws Exception {
mPrimaryUser.name = TEST_NAME;
- PreferenceScreen screen = mock(PreferenceScreen.class);
- PreferenceGroup group = mock(PreferenceGroup.class);
- when(screen.findPreference(anyString())).thenReturn(group);
- when(group.getKey()).thenReturn(TARGET_PREFERENCE_GROUP_KEY);
- mController.displayPreference(screen);
+ mController.displayPreference(mScreen);
mController.setSize(10L);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
- verify(group).addPreference(argumentCaptor.capture());
+ verify(mGroup).addPreference(argumentCaptor.capture());
Preference preference = argumentCaptor.getValue();
assertThat(preference.getSummary()).isEqualTo("10.00B");
@@ -153,11 +153,7 @@
public void controllerUpdatesPreferenceOnAcceptingResult() throws Exception {
mPrimaryUser.name = TEST_NAME;
mPrimaryUser.id = 10;
- PreferenceScreen screen = mock(PreferenceScreen.class);
- PreferenceGroup group = mock(PreferenceGroup.class);
- when(screen.findPreference(anyString())).thenReturn(group);
- when(group.getKey()).thenReturn(TARGET_PREFERENCE_GROUP_KEY);
- mController.displayPreference(screen);
+ mController.displayPreference(mScreen);
StorageAsyncLoader.AppsStorageResult userResult =
new StorageAsyncLoader.AppsStorageResult();
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
@@ -166,7 +162,7 @@
mController.handleResult(result);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
- verify(group).addPreference(argumentCaptor.capture());
+ verify(mGroup).addPreference(argumentCaptor.capture());
Preference preference = argumentCaptor.getValue();
assertThat(preference.getSummary()).isEqualTo("99.00B");
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
index c12e515..cbf3414 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
@@ -114,13 +114,6 @@
}
@Test
- public void testAutomaticStorageManagerLabelOff() throws Exception {
- mPreference.onBindViewHolder(mHolder);
- TextView asmTextView = (TextView) mHolder.findViewById(R.id.storage_manager_indicator);
- assertThat(asmTextView.getText().toString()).isEqualTo("Storage Manager: OFF");
- }
-
- @Test
public void testFreeUpSpaceMetricIsTriggered() throws Exception {
mPreference.onBindViewHolder(mHolder);
Button button = (Button) mHolder.findViewById(R.id.deletion_helper_button);
@@ -130,15 +123,4 @@
verify(mMetricsFeatureProvider, times(1)).action(
any(Context.class), eq(MetricsEvent.STORAGE_FREE_UP_SPACE_NOW));
}
-
- @Test
- public void testAutomaticStorageManagerLabelOn() throws Exception {
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);
-
- mPreference.onBindViewHolder(mHolder);
-
- TextView asmTextView = (TextView) mHolder.findViewById(R.id.storage_manager_indicator);
- assertThat(asmTextView.getText().toString()).isEqualTo("Storage Manager: ON");
- }
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
index 2cd4f76..ed49da4 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
@@ -21,6 +21,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
@@ -53,6 +54,8 @@
@Mock
private UserManagerWrapper mUserManager;
+ @Mock
+ private PreferenceScreen mScreen;
private Context mContext;
private UserProfileController mController;
@@ -64,17 +67,17 @@
mContext = spy(RuntimeEnvironment.application);
mPrimaryProfile = new UserInfo();
mController = new UserProfileController(mContext, mPrimaryProfile, 0);
+ when(mScreen.getContext()).thenReturn(mContext);
}
@Test
public void controllerAddsPrimaryProfilePreference() throws Exception {
mPrimaryProfile.name = TEST_NAME;
mPrimaryProfile.id = 10;
- PreferenceScreen screen = mock(PreferenceScreen.class);
- mController.displayPreference(screen);
+ mController.displayPreference(mScreen);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
- verify(screen).addPreference(argumentCaptor.capture());
+ verify(mScreen).addPreference(argumentCaptor.capture());
Preference preference = argumentCaptor.getValue();
assertThat(preference.getTitle()).isEqualTo(TEST_NAME);
@@ -85,11 +88,10 @@
public void tappingProfilePreferenceSendsToStorageProfileFragment() throws Exception {
mPrimaryProfile.name = TEST_NAME;
mPrimaryProfile.id = 10;
- PreferenceScreen screen = mock(PreferenceScreen.class);
- mController.displayPreference(screen);
+ mController.displayPreference(mScreen);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
- verify(screen).addPreference(argumentCaptor.capture());
+ verify(mScreen).addPreference(argumentCaptor.capture());
Preference preference = argumentCaptor.getValue();
assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -105,8 +107,7 @@
public void acceptingResultUpdatesPreferenceSize() throws Exception {
mPrimaryProfile.name = TEST_NAME;
mPrimaryProfile.id = 10;
- PreferenceScreen screen = mock(PreferenceScreen.class);
- mController.displayPreference(screen);
+ mController.displayPreference(mScreen);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
StorageAsyncLoader.AppsStorageResult userResult =
new StorageAsyncLoader.AppsStorageResult();
@@ -115,7 +116,7 @@
mController.handleResult(result);
final ArgumentCaptor<Preference> argumentCaptor = ArgumentCaptor.forClass(Preference.class);
- verify(screen).addPreference(argumentCaptor.capture());
+ verify(mScreen).addPreference(argumentCaptor.capture());
Preference preference = argumentCaptor.getValue();
assertThat(preference.getSummary()).isEqualTo("99.00B");
diff --git a/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
index fe3e7fd..2c0f4a7 100644
--- a/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/ThemePreferenceControllerTest.java
@@ -17,10 +17,15 @@
package com.android.settings.display;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.support.v7.preference.ListPreference;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.display.ThemePreferenceController.OverlayManager;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,9 +33,13 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -40,24 +49,19 @@
private ListPreference mPreference;
@Mock
private Context mContext;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private ApplicationInfo mApplicationInfo;
private ThemePreferenceController mController;
@Before
- public void setUp() {
+ public void setUp() throws NameNotFoundException {
MockitoAnnotations.initMocks(this);
- mController = spy(new ThemePreferenceController(mContext));
- }
-
- @Test
- public void updateState_nullTheme_shouldSetSummaryToDefault() {
- final String[] themes = {"Theme1", "Theme2"};
- doReturn(null).when(mController).getCurrentTheme();
- doReturn(themes).when(mController).getAvailableThemes();
-
- mController.updateState(mPreference);
-
- verify(mPreference).setSummary(mContext.getString(R.string.default_theme));
+ when(mPackageManager.getApplicationInfo(any(), anyInt())).thenReturn(mApplicationInfo);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ mController = spy(new ThemePreferenceController(mContext, mock(OverlayManager.class)));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java
index 59043ed..e9b9d86 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerTestBase.java
@@ -59,12 +59,12 @@
@Test
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
- when(mContext.getString(R.string.enterprise_privacy_never)).thenReturn("Never");
+ when(mContext.getString(R.string.enterprise_privacy_none)).thenReturn("None");
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, "24");
setDate(null);
mController.updateState(preference);
- assertThat(preference.getSummary()).isEqualTo("Never");
+ assertThat(preference.getSummary()).isEqualTo("None");
final Date date = new GregorianCalendar(2011 /* year */, 10 /* month */, 9 /* dayOfMonth */,
8 /* hourOfDay */, 7 /* minute */, 6 /* second */).getTime();
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
index de24885..6efccfc 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedCameraPermissionPreferenceControllerTest.java
@@ -18,7 +18,6 @@
import android.Manifest;
-import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import org.junit.runner.RunWith;
@@ -34,8 +33,7 @@
public AdminGrantedCameraPermissionPreferenceControllerTest() {
super("enterprise_privacy_number_camera_access_packages",
- new String[] {Manifest.permission.CAMERA},
- R.plurals.enterprise_privacy_number_camera_access_packages);
+ new String[] {Manifest.permission.CAMERA});
}
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
index 1c6f91d..a23ad8b 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedLocationPermissionsPreferenceControllerTest.java
@@ -18,7 +18,6 @@
import android.Manifest;
-import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import org.junit.runner.RunWith;
@@ -35,8 +34,7 @@
public AdminGrantedLocationPermissionsPreferenceControllerTest() {
super("enterprise_privacy_number_location_access_packages",
new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
- Manifest.permission.ACCESS_FINE_LOCATION},
- R.plurals.enterprise_privacy_number_location_access_packages);
+ Manifest.permission.ACCESS_FINE_LOCATION});
}
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
index bcaf63f..39a715f 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedMicrophonePermissionPreferenceControllerTest.java
@@ -18,7 +18,6 @@
import android.Manifest;
-import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import org.junit.runner.RunWith;
@@ -34,8 +33,7 @@
public AdminGrantedMicrophonePermissionPreferenceControllerTest() {
super("enterprise_privacy_number_microphone_access_packages",
- new String[] {Manifest.permission.RECORD_AUDIO},
- R.plurals.enterprise_privacy_number_microphone_access_packages);
+ new String[] {Manifest.permission.RECORD_AUDIO});
}
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
index 2bebbf0..1f52b0e 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerBaseTest.java
@@ -30,7 +30,7 @@
AdminGrantedPermissionsPreferenceControllerTestBase {
public AdminGrantedPermissionsPreferenceControllerBaseTest() {
- super(null, new String[] {"some.permission"}, 123 /* resourceStringId */);
+ super(null, new String[] {"some.permission"});
}
@Override
@@ -43,8 +43,7 @@
AdminGrantedPermissionsPreferenceControllerBase {
AdminGrantedPermissionsPreferenceControllerBaseTestable() {
- super(AdminGrantedPermissionsPreferenceControllerBaseTest.this.mContext, mPermissions,
- mStringResourceId);
+ super(AdminGrantedPermissionsPreferenceControllerBaseTest.this.mContext, mPermissions);
}
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
index 68ded37..821fb34 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminGrantedPermissionsPreferenceControllerTestBase.java
@@ -20,6 +20,7 @@
import android.content.res.Resources;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -44,7 +45,6 @@
protected final String mKey;
protected final String[] mPermissions;
- protected final int mStringResourceId;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
protected Context mContext;
@@ -52,11 +52,9 @@
protected AdminGrantedPermissionsPreferenceControllerBase mController;
- public AdminGrantedPermissionsPreferenceControllerTestBase(String key, String[] permissions,
- int stringResourceId) {
+ public AdminGrantedPermissionsPreferenceControllerTestBase(String key, String[] permissions) {
mKey = key;
mPermissions = permissions;
- mStringResourceId = stringResourceId;
}
@Before
@@ -83,10 +81,10 @@
preference.setVisible(false);
setNumberOfPackagesWithAdminGrantedPermissions(20);
- when(mContext.getResources().getQuantityString(mStringResourceId, 20, 20))
- .thenReturn("20 packages");
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
+ 20, 20)).thenReturn("20 packages");
mController.updateState(preference);
- assertThat(preference.getTitle()).isEqualTo("20 packages");
+ assertThat(preference.getSummary()).isEqualTo("20 packages");
assertThat(preference.isVisible()).isTrue();
setNumberOfPackagesWithAdminGrantedPermissions(0);
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
new file mode 100644
index 0000000..3cd63bb
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.enterprise;
+
+import android.content.Context;
+import android.content.res.Resources;
+import com.android.settings.R;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link CaCertsCurrentUserPreferenceController}.
+ */
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class CaCertsCurrentUserPreferenceControllerTest {
+
+ private final String INSTALLED_CERTS_USER_1 = "cert installed";
+ private final String INSTALLED_CERTS_USER_10 = "certs installed";
+ private final String INSTALLED_CERTS_PERSONAL_1 = "cert installed in personal profile";
+ private final String INSTALLED_CERTS_PERSONAL_10 = "certs installed in personal profile";
+ private final String NUMBER_INSTALLED_CERTS_1 = "1 cert";
+ private final String NUMBER_INSTALLED_CERTS_10 = "10 certs";
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ private FakeFeatureFactory mFeatureFactory;
+
+ private CaCertsCurrentUserPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mContext);
+ mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mController = new CaCertsCurrentUserPreferenceController(mContext);
+
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_user,
+ 1)).thenReturn(INSTALLED_CERTS_USER_1);
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_user,
+ 10)).thenReturn(INSTALLED_CERTS_USER_10);
+ when(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_ca_certs_personal, 1))
+ .thenReturn(INSTALLED_CERTS_PERSONAL_1);
+ when(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_ca_certs_personal, 10))
+ .thenReturn(INSTALLED_CERTS_PERSONAL_10);
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
+ 1, 1)).thenReturn(NUMBER_INSTALLED_CERTS_1);
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
+ 10, 10)).thenReturn(NUMBER_INSTALLED_CERTS_10);
+ }
+
+ @Test
+ public void testUpdateState() {
+ final Preference preference = new Preference(mContext, null, 0, 0);
+ preference.setVisible(true);
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(0);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isFalse();
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(1);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_USER_1);
+ assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_1);
+
+ preference.setVisible(false);
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(10);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_USER_10);
+ assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_10);
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(true);
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(0);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isFalse();
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(1);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_PERSONAL_1);
+ assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_1);
+
+ preference.setVisible(false);
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInCurrentUser()).thenReturn(10);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_PERSONAL_10);
+ assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_10);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void testHandlePreferenceTreeClick() {
+ assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
+ .isFalse();
+ }
+
+ @Test
+ public void testGetPreferenceKey() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("ca_certs_current_user");
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java
new file mode 100644
index 0000000..c66128b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsManagedProfilePreferenceControllerTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.enterprise;
+
+import android.content.Context;
+import android.content.res.Resources;
+import com.android.settings.R;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link CaCertsManagedProfilePreferenceController}.
+ */
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class CaCertsManagedProfilePreferenceControllerTest {
+
+ private final String INSTALLED_CERTS_1 = "cert installed";
+ private final String INSTALLED_CERTS_10 = "certs installed";
+ private final String NUMBER_INSTALLED_CERTS_1 = "1 cert";
+ private final String NUMBER_INSTALLED_CERTS_10 = "10 certs";
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ private FakeFeatureFactory mFeatureFactory;
+
+ private CaCertsManagedProfilePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mContext);
+ mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mController = new CaCertsManagedProfilePreferenceController(mContext);
+
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_work,
+ 1)).thenReturn(INSTALLED_CERTS_1);
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_ca_certs_work,
+ 10)).thenReturn(INSTALLED_CERTS_10);
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
+ 1, 1)).thenReturn(NUMBER_INSTALLED_CERTS_1);
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
+ 10, 10)).thenReturn(NUMBER_INSTALLED_CERTS_10);
+ }
+
+ @Test
+ public void testUpdateState() {
+ final Preference preference = new Preference(mContext, null, 0, 0);
+ preference.setVisible(true);
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInManagedProfile()).thenReturn(0);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isFalse();
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInManagedProfile()).thenReturn(1);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_1);
+ assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_1);
+
+ preference.setVisible(false);
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider
+ .getNumberOfOwnerInstalledCaCertsInManagedProfile()).thenReturn(10);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getTitle()).isEqualTo(INSTALLED_CERTS_10);
+ assertThat(preference.getSummary()).isEqualTo(NUMBER_INSTALLED_CERTS_10);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void testHandlePreferenceTreeClick() {
+ assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
+ .isFalse();
+ }
+
+ @Test
+ public void testGetPreferenceKey() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("ca_certs_managed_profile");
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
index b55b512..46c29b2 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseInstalledPackagesPreferenceControllerTest.java
@@ -86,11 +86,10 @@
assertThat(preference.isVisible()).isFalse();
setNumberOfEnterpriseInstalledPackages(20);
- when(mContext.getResources().getQuantityString(
- R.plurals.enterprise_privacy_number_enterprise_installed_packages, 20, 20))
- .thenReturn("20 packages");
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
+ 20, 20)).thenReturn("20 packages");
mController.updateState(preference);
- assertThat(preference.getTitle()).isEqualTo("20 packages");
+ assertThat(preference.getSummary()).isEqualTo("20 packages");
assertThat(preference.isVisible()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index 9b955e4..38d9221 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -18,12 +18,14 @@
import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.net.ProxyInfo;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import android.text.SpannableStringBuilder;
import com.android.settings.R;
@@ -41,11 +43,13 @@
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
/**
@@ -61,11 +65,16 @@
private final int MY_USER_ID = UserHandle.myUserId();
private final int MANAGED_PROFILE_USER_ID = MY_USER_ID + 1;
private final String VPN_PACKAGE_ID = "com.example.vpn";
+ private final String IME_PACKAGE_ID = "com.example.ime";
+ private final String OTHER_PACKAGE_ID = "com.example.other";
+ private final String IME_PACKAGE_LABEL = "Test IME";
private List<UserInfo> mProfiles = new ArrayList();
+ private @Mock Context mContext;
private @Mock DevicePolicyManagerWrapper mDevicePolicyManager;
- private @Mock PackageManagerWrapper mPackageManager;
+ private @Mock PackageManagerWrapper mPackageManagerWrapper;
+ private @Mock PackageManager mPackageManager;
private @Mock UserManager mUserManager;
private @Mock ConnectivityManagerWrapper mConnectivityManger;
private Resources mResources;
@@ -76,14 +85,14 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
- when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
- .thenReturn(true);
+ when(mContext.getApplicationContext()).thenReturn(mContext);
+ resetAndInitializePackageManagerWrapper();
when(mUserManager.getProfiles(MY_USER_ID)).thenReturn(mProfiles);
mProfiles.add(new UserInfo(MY_USER_ID, "", "", 0 /* flags */));
mResources = ShadowApplication.getInstance().getApplicationContext().getResources();
- mProvider = new EnterprisePrivacyFeatureProviderImpl(mDevicePolicyManager, mPackageManager,
- mUserManager, mConnectivityManger, mResources);
+ mProvider = new EnterprisePrivacyFeatureProviderImpl(mContext, mDevicePolicyManager,
+ mPackageManagerWrapper, mUserManager, mConnectivityManger, mResources);
}
@Test
@@ -106,28 +115,26 @@
@Test
public void testGetDeviceOwnerDisclosure() {
- final Context context = mock(Context.class);
-
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
- assertThat(mProvider.getDeviceOwnerDisclosure(context)).isNull();
+ assertThat(mProvider.getDeviceOwnerDisclosure()).isNull();
SpannableStringBuilder disclosure = new SpannableStringBuilder();
disclosure.append(mResources.getString(R.string.do_disclosure_generic));
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
- new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(context), 0);
+ new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(mContext), 0);
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
- assertThat(mProvider.getDeviceOwnerDisclosure(context)).isEqualTo(disclosure);
+ assertThat(mProvider.getDeviceOwnerDisclosure()).isEqualTo(disclosure);
disclosure = new SpannableStringBuilder();
disclosure.append(mResources.getString(R.string.do_disclosure_with_name,
OWNER_ORGANIZATION));
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
- new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(context), 0);
+ new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(mContext), 0);
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(OWNER_ORGANIZATION);
- assertThat(mProvider.getDeviceOwnerDisclosure(context)).isEqualTo(disclosure);
+ assertThat(mProvider.getDeviceOwnerDisclosure()).isEqualTo(disclosure);
}
@Test
@@ -217,4 +224,78 @@
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(10);
}
+
+ @Test
+ public void testGetImeLabelIfOwnerSet() throws Exception {
+ final ApplicationInfo applicationInfo = mock(ApplicationInfo.class);
+ when(applicationInfo.loadLabel(mPackageManager)).thenReturn(IME_PACKAGE_LABEL);
+
+ Settings.Secure.putString(null, Settings.Secure.DEFAULT_INPUT_METHOD, IME_PACKAGE_ID);
+ when(mPackageManagerWrapper.getApplicationInfoAsUser(IME_PACKAGE_ID, 0, MY_USER_ID))
+ .thenReturn(applicationInfo);
+
+ // IME not set by Device Owner.
+ when(mDevicePolicyManager.isCurrentInputMethodSetByOwner()).thenReturn(false);
+ assertThat(mProvider.getImeLabelIfOwnerSet()).isNull();
+
+ // Device Owner set IME to empty string.
+ when(mDevicePolicyManager.isCurrentInputMethodSetByOwner()).thenReturn(true);
+ Settings.Secure.putString(null, Settings.Secure.DEFAULT_INPUT_METHOD, null);
+ assertThat(mProvider.getImeLabelIfOwnerSet()).isNull();
+
+ // Device Owner set IME to nonexistent package.
+ Settings.Secure.putString(null, Settings.Secure.DEFAULT_INPUT_METHOD, IME_PACKAGE_ID);
+ when(mPackageManagerWrapper.getApplicationInfoAsUser(IME_PACKAGE_ID, 0, MY_USER_ID))
+ .thenThrow(new PackageManager.NameNotFoundException());
+ assertThat(mProvider.getImeLabelIfOwnerSet()).isNull();
+
+ // Device Owner set IME to existent package.
+ resetAndInitializePackageManagerWrapper();
+ when(mPackageManagerWrapper.getApplicationInfoAsUser(IME_PACKAGE_ID, 0, MY_USER_ID))
+ .thenReturn(applicationInfo);
+ assertThat(mProvider.getImeLabelIfOwnerSet()).isEqualTo(IME_PACKAGE_LABEL);
+ }
+
+ @Test
+ public void testGetNumberOfOwnerInstalledCaCertsInCurrentUser() {
+ final UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM);
+
+ when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
+ .thenReturn(null);
+ assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser()).isEqualTo(0);
+ when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
+ .thenReturn(new ArrayList<String>());
+ assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser()).isEqualTo(0);
+ when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
+ .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
+ assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInCurrentUser()).isEqualTo(2);
+ }
+
+ @Test
+ public void testGetNumberOfOwnerInstalledCaCertsInManagedProfile() {
+ final UserHandle userHandle = new UserHandle(MANAGED_PROFILE_USER_ID);
+ final UserInfo managedProfile =
+ new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE);
+
+ mProfiles.add(managedProfile);
+ when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
+ .thenReturn(null);
+ assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
+ when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
+ .thenReturn(new ArrayList<String>());
+ assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
+ when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
+ .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
+ assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(2);
+
+ mProfiles.remove(managedProfile);
+ assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
+ }
+
+ private void resetAndInitializePackageManagerWrapper() {
+ reset(mPackageManagerWrapper);
+ when(mPackageManagerWrapper.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
+ .thenReturn(true);
+ when(mPackageManagerWrapper.getPackageManager()).thenReturn(mPackageManager);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
index 6c062ae..2690198 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
@@ -73,7 +73,7 @@
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
ShadowApplication.getInstance().getApplicationContext());
assertThat(controllers).isNotNull();
- assertThat(controllers.size()).isEqualTo(14);
+ assertThat(controllers.size()).isEqualTo(17);
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
assertThat(controllers.get(1)).isInstanceOf(NetworkLogsPreferenceController.class);
assertThat(controllers.get(2)).isInstanceOf(BugReportsPreferenceController.class);
@@ -93,7 +93,13 @@
assertThat(controllers.get(10)).isInstanceOf(
AlwaysOnVpnManagedProfilePreferenceController.class);
assertThat(controllers.get(11)).isInstanceOf(GlobalHttpProxyPreferenceController.class);
- assertThat(controllers.get(12)).isInstanceOf(FailedPasswordWipePrimaryUserPreferenceController.class);
- assertThat(controllers.get(13)).isInstanceOf(FailedPasswordWipeManagedProfilePreferenceController.class);
+ assertThat(controllers.get(12)).isInstanceOf(CaCertsCurrentUserPreferenceController.class);
+ assertThat(controllers.get(13)).isInstanceOf(
+ CaCertsManagedProfilePreferenceController.class);
+ assertThat(controllers.get(14)).isInstanceOf(
+ FailedPasswordWipePrimaryUserPreferenceController.class);
+ assertThat(controllers.get(15)).isInstanceOf(
+ FailedPasswordWipeManagedProfilePreferenceController.class);
+ assertThat(controllers.get(16)).isInstanceOf(ImePreferenceController.class);
}
}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
index 84520a5..093ce20 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
@@ -118,11 +118,10 @@
ContactsContract.Contacts.CONTENT_TYPE)}, 32);
setEnterpriseSetDefaultApps(new Intent[] {new Intent(Intent.ACTION_DIAL),
new Intent(Intent.ACTION_CALL)}, 64);
- when(mContext.getResources().getQuantityString(
- R.plurals.enterprise_privacy_number_enterprise_set_default_apps, 127, 127))
- .thenReturn("127 apps");
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
+ 127, 127)).thenReturn("127 apps");
mController.updateState(preference);
- assertThat(preference.getTitle()).isEqualTo("127 apps");
+ assertThat(preference.getSummary()).isEqualTo("127 apps");
assertThat(preference.isVisible()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
index 29952a7..c9981f9 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipeManagedProfilePreferenceControllerTest.java
@@ -18,7 +18,6 @@
import android.content.Context;
-import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -38,8 +37,7 @@
private int mMaximumFailedPasswordsBeforeWipe = 0;
public FailedPasswordWipeManagedProfilePreferenceControllerTest() {
- super("failed_password_wipe_managed_profile",
- R.plurals.enterprise_privacy_failed_password_wipe_work);
+ super("failed_password_wipe_managed_profile");
}
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
index 97d0d6d..1c7b448 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerBaseTest.java
@@ -33,7 +33,7 @@
private int mMaximumFailedPasswordsBeforeWipe = 0;
public FailedPasswordWipePreferenceControllerBaseTest() {
- super(null, 123 /* stringResourceId */);
+ super(null);
}
@Override
@@ -50,7 +50,7 @@
private class FailedPasswordWipePreferenceControllerBaseTestable extends
FailedPasswordWipePreferenceControllerBase {
FailedPasswordWipePreferenceControllerBaseTestable() {
- super(FailedPasswordWipePreferenceControllerBaseTest.this.mContext, mStringResourceId);
+ super(FailedPasswordWipePreferenceControllerBaseTest.this.mContext);
}
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
index 5a74fa5..aa189e2 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePreferenceControllerTestBase.java
@@ -20,6 +20,7 @@
import android.content.res.Resources;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -37,7 +38,6 @@
public abstract class FailedPasswordWipePreferenceControllerTestBase {
protected final String mKey;
- protected final int mStringResourceId;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
protected Context mContext;
@@ -45,9 +45,8 @@
protected FailedPasswordWipePreferenceControllerBase mController;
- public FailedPasswordWipePreferenceControllerTestBase(String key, int stringResourceId) {
+ public FailedPasswordWipePreferenceControllerTestBase(String key) {
mKey = key;
- mStringResourceId = stringResourceId;
}
@Before
@@ -65,11 +64,11 @@
preference.setVisible(false);
setMaximumFailedPasswordsBeforeWipe(10);
- when(mContext.getResources().getQuantityString(mStringResourceId, 10, 10))
+ when(mContext.getResources().getQuantityString(
+ R.plurals.enterprise_privacy_number_failed_password_wipe, 10, 10))
.thenReturn("10 attempts");
mController.updateState(preference);
- assertThat(preference.getTitle()).isEqualTo("10 attempts");
- assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getSummary()).isEqualTo("10 attempts");
setMaximumFailedPasswordsBeforeWipe(0);
mController.updateState(preference);
diff --git a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java
index ea6d977..65c9828 100644
--- a/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/FailedPasswordWipePrimaryUserPreferenceControllerTest.java
@@ -18,7 +18,6 @@
import android.content.Context;
-import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -38,8 +37,7 @@
private int mMaximumFailedPasswordsBeforeWipe = 0;
public FailedPasswordWipePrimaryUserPreferenceControllerTest() {
- super("failed_password_wipe_primary_user",
- R.plurals.enterprise_privacy_failed_password_wipe_device);
+ super("failed_password_wipe_primary_user");
}
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
new file mode 100644
index 0000000..547746c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.enterprise;
+
+import android.content.Context;
+import android.content.res.Resources;
+import com.android.settings.R;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link ImePreferenceController}.
+ */
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class ImePreferenceControllerTest {
+
+ private final String DEFAULT_IME_LABEL = "Test IME";
+ private final String DEFAULT_IME_TEXT = "Set to Test IME";
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ private FakeFeatureFactory mFeatureFactory;
+
+ private ImePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mContext);
+ mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mController = new ImePreferenceController(mContext);
+ when(mContext.getResources().getString(R.string.enterprise_privacy_input_method_name,
+ DEFAULT_IME_LABEL)).thenReturn(DEFAULT_IME_TEXT);
+ }
+
+ @Test
+ public void testUpdateState() {
+ final Preference preference = new Preference(mContext, null, 0, 0);
+ preference.setVisible(true);
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
+ .thenReturn(null);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isFalse();
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
+ .thenReturn(DEFAULT_IME_LABEL);
+ mController.updateState(preference);
+ assertThat(preference.isVisible()).isTrue();
+ assertThat(preference.getSummary()).isEqualTo(DEFAULT_IME_TEXT);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void testHandlePreferenceTreeClick() {
+ assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
+ .isFalse();
+ }
+
+ @Test
+ public void testGetPreferenceKey() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("input_method");
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java
index bf2c4ca..60ceed6 100644
--- a/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/InstalledPackagesPreferenceControllerTest.java
@@ -64,22 +64,30 @@
mController = new InstalledPackagesPreferenceController(mContext);
}
- @Test
- public void testUpdateState() {
- final Preference preference = new Preference(mContext, null, 0, 0);
+ private void setNumberOfInstalledPackages(int number) {
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
((ApplicationFeatureProvider.NumberOfAppsCallback)
- invocation.getArguments()[1]).onNumberOfAppsResult(20);
+ invocation.getArguments()[1]).onNumberOfAppsResult(number);
return null;
}}).when(mFeatureFactory.applicationFeatureProvider)
.calculateNumberOfInstalledApps(
eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), anyObject());
- when(mContext.getResources().getQuantityString(
- R.plurals.enterprise_privacy_number_installed_packages, 20, 20))
- .thenReturn("20 packages");
+ }
+
+ @Test
+ public void testUpdateState() {
+ final Preference preference = new Preference(mContext, null, 0, 0);
+
+ setNumberOfInstalledPackages(0);
mController.updateState(preference);
- assertThat(preference.getTitle()).isEqualTo("20 packages");
+ assertThat(preference.getSummary()).isEqualTo("");
+
+ setNumberOfInstalledPackages(20);
+ when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
+ 20, 20)).thenReturn("20 packages");
+ mController.updateState(preference);
+ assertThat(preference.getSummary()).isEqualTo("20 packages");
}
@Test
@@ -95,6 +103,6 @@
@Test
public void testGetPreferenceKey() {
- assertThat(mController.getPreferenceKey()).isEqualTo("number_installed_packages");
+ assertThat(mController.getPreferenceKey()).isEqualTo("installed_packages");
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
new file mode 100644
index 0000000..6d3607f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java
@@ -0,0 +1,149 @@
+/*
+ * 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.app.AppOpsManager;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.support.v14.preference.SwitchPreference;
+
+import com.android.settings.TestConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BackgroundActivityPreferenceControllerTest {
+ private static final int UID_NORMAL = 1234;
+ private static final int UID_SPECIAL = 2345;
+ private static final String HIGH_SDK_PACKAGE = "com.android.package.high";
+ private static final String LOW_SDK_PACKAGE = "com.android.package.low";
+ private static final String[] PACKAGES_NORMAL = {LOW_SDK_PACKAGE};
+ private static final String[] PACKAGES_SPECIAL = {HIGH_SDK_PACKAGE, LOW_SDK_PACKAGE};
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private AppOpsManager mAppOpsManager;
+ @Mock
+ private SwitchPreference mPreference;
+ @Mock
+ private ApplicationInfo mHighApplicationInfo;
+ @Mock
+ private ApplicationInfo mLowApplicationInfo;
+ private BackgroundActivityPreferenceController mController;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
+ when(mPackageManager.getPackagesForUid(UID_NORMAL)).thenReturn(PACKAGES_NORMAL);
+ when(mPackageManager.getPackagesForUid(UID_SPECIAL)).thenReturn(PACKAGES_SPECIAL);
+
+ when(mPackageManager.getApplicationInfo(HIGH_SDK_PACKAGE, PackageManager.GET_META_DATA))
+ .thenReturn(mHighApplicationInfo);
+ when(mPackageManager.getApplicationInfo(LOW_SDK_PACKAGE, PackageManager.GET_META_DATA))
+ .thenReturn(mLowApplicationInfo);
+ mHighApplicationInfo.targetSdkVersion = Build.VERSION_CODES.O;
+ mLowApplicationInfo.targetSdkVersion = Build.VERSION_CODES.L;
+
+ mController = new BackgroundActivityPreferenceController(mContext, UID_NORMAL);
+ mController.isAvailable();
+ }
+
+ @Test
+ public void testOnPreferenceChange_TurnOnCheck_MethodInvoked() {
+ mController.onPreferenceChange(mPreference, true);
+
+ verify(mAppOpsManager).setUidMode(AppOpsManager.OP_RUN_IN_BACKGROUND,
+ UID_NORMAL, AppOpsManager.MODE_DEFAULT);
+ }
+
+ @Test
+ public void testOnPreferenceChange_TurnOffCheck_MethodInvoked() {
+ mController.onPreferenceChange(null, false);
+
+ verify(mAppOpsManager).setUidMode(AppOpsManager.OP_RUN_IN_BACKGROUND,
+ UID_NORMAL, AppOpsManager.MODE_IGNORED);
+ }
+
+ @Test
+ public void testUpdateState_CheckOn_SetCheckedTrue() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_DEFAULT);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void testUpdateState_CheckOff_SetCheckedFalse() {
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_NORMAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_IGNORED);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void testIsPackageAvailable_SdkLowerThanO_ReturnTrue() {
+ assertThat(mController.isLegacyApp(LOW_SDK_PACKAGE)).isTrue();
+ }
+
+ @Test
+ public void testIsPackageAvailable_SdkLargerOrEqualThanO_ReturnFalse() {
+ assertThat(mController.isLegacyApp(HIGH_SDK_PACKAGE)).isFalse();
+ }
+
+ @Test
+ public void testMultiplePackages_ReturnStatusForTargetPackage() {
+ mController = new BackgroundActivityPreferenceController(mContext, UID_SPECIAL);
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_SPECIAL, LOW_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_DEFAULT);
+ when(mAppOpsManager
+ .checkOpNoThrow(AppOpsManager.OP_RUN_IN_BACKGROUND, UID_SPECIAL, HIGH_SDK_PACKAGE))
+ .thenReturn(AppOpsManager.MODE_IGNORED);
+
+ final boolean available = mController.isAvailable();
+ mController.updateState(mPreference);
+
+ assertThat(available).isTrue();
+ // Should get status from LOW_SDK_PACKAGE
+ verify(mPreference).setChecked(true);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index ed7e48b..494ac67 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -94,9 +94,9 @@
@Test
public void testExtractUsageType_TypeEqualsToDrainType_ReturnRelevantType() {
final DrainType drainTypes[] = {DrainType.WIFI, DrainType.BLUETOOTH, DrainType.IDLE,
- DrainType.USER, DrainType.CELL};
+ DrainType.USER, DrainType.CELL, DrainType.UNACCOUNTED};
final int usageTypes[] = {UsageType.WIFI, UsageType.BLUETOOTH, UsageType.IDLE,
- UsageType.USER, UsageType.CELL};
+ UsageType.USER, UsageType.CELL, UsageType.UNACCOUNTED};
assertThat(drainTypes.length).isEqualTo(usageTypes.length);
for (int i = 0, size = drainTypes.length; i < size; i++) {
@@ -147,7 +147,7 @@
assertThat(usageTypeSet).asList().containsExactly(UsageType.APP, UsageType.WIFI,
UsageType.CELL, UsageType.BLUETOOTH, UsageType.IDLE, UsageType.SERVICE,
- UsageType.USER, UsageType.SYSTEM);
+ UsageType.USER, UsageType.SYSTEM, UsageType.UNACCOUNTED);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSensitivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSensitivityPreferenceControllerTest.java
new file mode 100644
index 0000000..229ef49
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSensitivityPreferenceControllerTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.gestures;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import com.android.settings.search2.InlineSwitchPayload;
+import com.android.settings.search2.ResultPayload;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED;
+import static android.provider.Settings.Secure.ASSIST_GESTURE_SENSITIVITY;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyInt;
+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 AssistGestureSensitivityPreferenceControllerTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ private FakeFeatureFactory mFactory;
+ private AssistGestureSensitivityPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mContext);
+ mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mController = new AssistGestureSensitivityPreferenceController(mContext, null);
+ }
+
+ @Test
+ public void isAvailable_whenSupportedAndEnabled_shouldReturnTrue() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
+ when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_whenSupportedAndDisabled_shouldReturnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
+ when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_whenUnsupportedAndEnabled_shouldReturnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
+ when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_whenUnsupportedAndDisabled_shouldReturnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
+ when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+}
+
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
index 285a393..4efc822 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
@@ -23,12 +23,10 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
-import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@@ -42,17 +40,13 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AssistGestureSettingsTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ @Mock
private Context mContext;
private AssistGestureSettings mSettings;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mSettings = new AssistGestureSettings();
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java
index b5fdfea..f8c3367 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java
@@ -16,43 +16,29 @@
package com.android.settings.gestures;
-import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DoubleTapPowerSettingsTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
-
private DoubleTapPowerSettings mSettings;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mSettings = new DoubleTapPowerSettings();
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java
index c0aac43..433ba46 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java
@@ -16,43 +16,29 @@
package com.android.settings.gestures;
-import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DoubleTapScreenSettingsTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
-
private DoubleTapScreenSettings mSettings;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mSettings = new DoubleTapScreenSettings();
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java
index f2a56d7..35c48ec 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java
@@ -16,19 +16,14 @@
package com.android.settings.gestures;
-import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@@ -40,18 +35,11 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DoubleTwistGestureSettingsTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
private DoubleTwistGestureSettings mSettings;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mSettings = new DoubleTwistGestureSettings();
}
diff --git a/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java
index cf08836..921a1be 100644
--- a/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java
@@ -16,19 +16,14 @@
package com.android.settings.gestures;
-import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@@ -41,18 +36,10 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PickupGestureSettingsTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
-
private PickupGestureSettings mSettings;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mSettings = new PickupGestureSettings();
}
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
index b9f3bac..78dc27ac 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
@@ -23,12 +23,10 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
-import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@@ -43,17 +41,13 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SwipeToNotificationSettingsTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ @Mock
private Context mContext;
private SwipeToNotificationSettings mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mFragment = new SwipeToNotificationSettings();
}
diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
index 7626ec4..2201c68 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
@@ -15,21 +15,16 @@
*/
package com.android.settings.network;
-import android.content.Context;
import android.provider.SearchIndexableResource;
import android.view.Menu;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@@ -40,24 +35,15 @@
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NetworkDashboardFragmentTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
-
private NetworkDashboardFragment mFragment;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- final FakeFeatureFactory factory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mFragment = new NetworkDashboardFragment();
}
diff --git a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java
new file mode 100644
index 0000000..6bf47ac
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import static android.provider.Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.net.NetworkScorerAppData;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+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.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class NetworkScorerPickerPreferenceControllerTest {
+
+ private static final String TEST_SCORER_PACKAGE = "Test Package";
+ private static final String TEST_SCORER_CLASS = "Test Class";
+ private static final String TEST_SCORER_LABEL = "Test Label";
+
+ private Context mContext;
+ @Mock
+ private NetworkScoreManagerWrapper mNetworkScorer;
+ private NetworkScorerPickerPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new NetworkScorerPickerPreferenceController(mContext, mNetworkScorer);
+ }
+
+ @Test
+ public void testIsAvailable_shouldAlwaysReturnTrue() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void updateState_preferenceSetSummaryAsActiveScorerLabel() {
+ Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 1);
+ ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE, TEST_SCORER_CLASS);
+ NetworkScorerAppData scorerAppData = new NetworkScorerAppData(
+ 0, scorer, TEST_SCORER_LABEL, null /* enableUseOpenWifiActivity */);
+ when(mNetworkScorer.getActiveScorer()).thenReturn(scorerAppData);
+ Preference preference = mock(Preference.class);
+
+ mController.updateState(preference);
+
+ verify(preference).setSummary(TEST_SCORER_LABEL);
+ }
+
+ @Test
+ public void updateState_noActiveScorer_preferenceSetSummaryToNone() {
+ Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 1);
+ when(mNetworkScorer.getActiveScorer()).thenReturn(null);
+ Preference preference = mock(Preference.class);
+
+ mController.updateState(preference);
+
+ verify(preference).setSummary(mContext.getString(
+ R.string.network_scorer_picker_none_preference));
+ }
+
+ @Test
+ public void updateState_networkRecommendationsDisabled_preferenceDisabled() {
+ Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 0);
+ when(mNetworkScorer.getActiveScorer()).thenReturn(null);
+ Preference preference = mock(Preference.class);
+
+ mController.updateState(preference);
+
+ verify(preference).setEnabled(false);
+ verify(preference).setSummary(null);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java
new file mode 100644
index 0000000..fef6f85
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.network;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.net.NetworkScorerAppData;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.widget.RadioButtonPreference;
+import com.google.android.collect.Lists;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class NetworkScorerPickerTest {
+
+ private static final String TEST_SCORER_PACKAGE_1 = "Test Package 1";
+ private static final String TEST_SCORER_CLASS_1 = "Test Class 1";
+ private static final String TEST_SCORER_LABEL_1 = "Test Label 1";
+ private static final String TEST_SCORER_PACKAGE_2 = "Test Package 2";
+
+ private Context mContext;
+ @Mock
+ private NetworkScoreManagerWrapper mNetworkScoreManager;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
+ private TestFragment mFragment;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mFragment = new TestFragment(mContext, mPreferenceScreen, mNetworkScoreManager);
+ mFragment.onAttach(mContext);
+ }
+
+ @Test
+ public void testOnRadioButtonClicked_success() {
+ RadioButtonPreference pref = new RadioButtonPreference(mContext);
+ pref.setKey(TEST_SCORER_PACKAGE_1);
+ when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref);
+ when(mPreferenceScreen.getPreferenceCount()).thenReturn(1);
+ when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true);
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_2);
+
+ mFragment.onRadioButtonClicked(pref);
+
+ verify(mNetworkScoreManager).setActiveScorer(TEST_SCORER_PACKAGE_1);
+ assertThat(pref.isChecked()).isTrue();
+ }
+
+ @Test
+ public void testOnRadioButtonClicked_currentScorer_doNothing() {
+ RadioButtonPreference pref = new RadioButtonPreference(mContext);
+ pref.setKey(TEST_SCORER_PACKAGE_1);
+ pref.setChecked(true);
+ when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref);
+ when(mPreferenceScreen.getPreferenceCount()).thenReturn(1);
+ when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true);
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1);
+
+ mFragment.onRadioButtonClicked(pref);
+
+ verify(mNetworkScoreManager, never()).setActiveScorer(any());
+ assertThat(pref.isChecked()).isTrue();
+ }
+
+ @Test
+ public void testUpdateCandidates_noValidScorers_nonePreference() {
+ when(mNetworkScoreManager.getAllValidScorers()).thenReturn(new ArrayList<>());
+ ArgumentCaptor<RadioButtonPreference> arg =
+ ArgumentCaptor.forClass(RadioButtonPreference.class);
+
+ mFragment.updateCandidates();
+
+ verify(mPreferenceScreen).addPreference(arg.capture());
+ assertThat(arg.getValue().getTitle()).isEqualTo(
+ mContext.getString(R.string.network_scorer_picker_none_preference));
+ }
+
+ @Test
+ public void testUpdateCandidates_validScorer() {
+ ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE_1, TEST_SCORER_CLASS_1);
+ NetworkScorerAppData scorerAppData = new NetworkScorerAppData(
+ 0, scorer, TEST_SCORER_LABEL_1, null /* enableUseOpenWifiActivity */);
+ when(mNetworkScoreManager.getAllValidScorers()).thenReturn(
+ Lists.newArrayList(scorerAppData));
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1);
+ ArgumentCaptor<RadioButtonPreference> arg =
+ ArgumentCaptor.forClass(RadioButtonPreference.class);
+
+ mFragment.updateCandidates();
+
+ verify(mPreferenceScreen).addPreference(arg.capture());
+ RadioButtonPreference pref = arg.getValue();
+ assertThat(pref.getTitle()).isEqualTo(TEST_SCORER_LABEL_1);
+ assertThat(pref.isChecked()).isTrue();
+ }
+
+ public static class TestFragment extends NetworkScorerPicker {
+
+ private final Context mContext;
+ private final PreferenceScreen mScreen;
+ private final PreferenceManager mPrefManager;
+ private final NetworkScoreManagerWrapper mNetworkScoreManagerWrapper;
+
+ public TestFragment(Context context, PreferenceScreen preferenceScreen,
+ NetworkScoreManagerWrapper networkScoreManagerWrapper) {
+ mContext = context;
+ mScreen = preferenceScreen;
+ mNetworkScoreManagerWrapper = networkScoreManagerWrapper;
+ mPrefManager = mock(PreferenceManager.class);
+ when(mPrefManager.getContext()).thenReturn(context);
+ }
+
+ @Override
+ public Context getContext() {
+ return mContext;
+ }
+
+ @Override
+ public PreferenceManager getPreferenceManager() {
+ return mPrefManager;
+ }
+
+ @Override
+ public PreferenceScreen getPreferenceScreen() {
+ return mScreen;
+ }
+
+ @Override
+ NetworkScoreManagerWrapper createNetworkScorerManagerWrapper(Context context) {
+ return mNetworkScoreManagerWrapper;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
index acfd400..13abd97 100644
--- a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
@@ -17,11 +17,10 @@
package com.android.settings.notification;
import android.content.Context;
-import android.os.Build.VERSION_CODES;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import android.telephony.TelephonyManager;
@@ -36,17 +35,15 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -65,6 +62,8 @@
@Mock
private PreferenceScreen mScreen;
@Mock
+ private PreferenceCategory mWorkCategory;
+ @Mock
private TelephonyManager mTelephonyManager;
@Mock
private AudioHelper mAudioHelper;
@@ -78,6 +77,17 @@
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+ when(mScreen.findPreference(KEY_WORK_CATEGORY))
+ .thenReturn(mWorkCategory);
+ when(mWorkCategory.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS))
+ .thenReturn(mock(TwoStatePreference.class));
+ when(mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
+ .thenReturn(mock(DefaultRingtonePreference.class));
+ when(mWorkCategory.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
+ .thenReturn(mock(DefaultRingtonePreference.class));
+ when(mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
+ .thenReturn(mock(DefaultRingtonePreference.class));
+
mController = new WorkSoundPreferenceController(mContext, mFragment, null, mAudioHelper);
}
@@ -112,45 +122,30 @@
}
@Test
- public void onResume_available_shouldAddPreferenceCategory() {
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
- .thenReturn(UserHandle.myUserId());
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
- when(mAudioHelper.isSingleVolume()).thenReturn(false);
- when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
- when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
- mockWorkCategory();
-
- mController.onResume();
-
- verify(mFragment).addPreferencesFromResource(R.xml.sound_work_settings);
- }
-
- @Test
- public void onManagedProfileAdded_shouldAddPreferenceCategory() {
+ public void onManagedProfileAdded_shouldDisplayPreferenceCategory() {
// Given a device without any managed profiles:
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
- mockWorkCategory();
- // When the fragment first resumes, the category should not appear.
+ // When the fragment first displays, the category should not appear.
+ mController.displayPreference(mScreen);
+ verify(mWorkCategory).setVisible(false);
+
+
+ // However, when a managed profile is added later, the category should appear.
mController.onResume();
-
- verify(mFragment, never()).addPreferencesFromResource(R.xml.sound_work_settings);
-
- // However, when a managed profile is added after resuming, the category should appear.
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
.thenReturn(UserHandle.myUserId());
mController.onManagedProfileAdded(UserHandle.myUserId());
- verify(mFragment).addPreferencesFromResource(R.xml.sound_work_settings);
+ verify(mWorkCategory).setVisible(true);
}
@Test
- public void onManagedProfileRemoved_shouldRemovePreferenceCategory() {
+ public void onManagedProfileRemoved_shouldHidePreferenceCategory() {
// Given a device with a managed profile:
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
@@ -158,29 +153,44 @@
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
- mockWorkCategory();
// Which is in resumed state:
+ mController.displayPreference(mScreen);
mController.onResume();
- // When a managed profile is removed, the category should be removed.
+ verify(mWorkCategory, times(2)).setVisible(true);
+
+ // When a managed profile is removed, the category should be hidden.
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
mController.onManagedProfileRemoved(UserHandle.myUserId());
- verify(mScreen).removePreference(mScreen.findPreference(KEY_WORK_CATEGORY));
+ verify(mWorkCategory).setVisible(false);
+ }
+
+
+ @Test
+ public void displayPreference_isAvailable_shouldShowPreferenceCategory() {
+ when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ .thenReturn(UserHandle.myUserId());
+ when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isSingleVolume()).thenReturn(false);
+ when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
+ when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
+
+ mController.displayPreference(mScreen);
+ verify(mWorkCategory).setVisible(true);
}
@Test
- public void onResume_notAvailable_shouldNotAddPreferenceCategory() {
+ public void displayPreference_notAvailable_shouldHidePreferenceCategory() {
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
- .thenReturn(UserHandle.USER_NULL);
+ .thenReturn(UserHandle.USER_NULL);
when(mAudioHelper.isSingleVolume()).thenReturn(true);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
- mController.onResume();
-
- verify(mFragment, never()).addPreferencesFromResource(anyInt());
+ mController.displayPreference(mScreen);
+ verify(mWorkCategory).setVisible(false);
}
@Test
@@ -206,27 +216,19 @@
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
.thenReturn(UserHandle.myUserId());
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(false);
- mockWorkCategory();
// When resumed:
+ mController.displayPreference(mScreen);
mController.onResume();
- // Sound preferences should explain that the profile isn't available yet.
- verify(mScreen.findPreference(KEY_WORK_PHONE_RINGTONE)).setSummary(eq(notAvailable));
- verify(mScreen.findPreference(KEY_WORK_NOTIFICATION_RINGTONE)).setSummary(eq(notAvailable));
- verify(mScreen.findPreference(KEY_WORK_ALARM_RINGTONE)).setSummary(eq(notAvailable));
- }
+ verify(mWorkCategory, times(2)).setVisible(true);
- private void mockWorkCategory() {
- when(mScreen.findPreference(KEY_WORK_CATEGORY))
- .thenReturn(mock(PreferenceGroup.class));
- when(mScreen.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS))
- .thenReturn(mock(TwoStatePreference.class));
- when(mScreen.findPreference(KEY_WORK_PHONE_RINGTONE))
- .thenReturn(mock(DefaultRingtonePreference.class));
- when(mScreen.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
- .thenReturn(mock(DefaultRingtonePreference.class));
- when(mScreen.findPreference(KEY_WORK_ALARM_RINGTONE))
- .thenReturn(mock(DefaultRingtonePreference.class));
+ // Sound preferences should explain that the profile isn't available yet.
+ verify(mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
+ .setSummary(eq(notAvailable));
+ verify(mWorkCategory.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
+ .setSummary(eq(notAvailable));
+ verify(mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
+ .setSummary(eq(notAvailable));
}
}
diff --git a/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java b/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java
index 6f326ab..ab55605 100644
--- a/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search2/CursorToSearchResultConverterTest.java
@@ -24,6 +24,7 @@
import android.graphics.drawable.Drawable;
import android.util.ArrayMap;
+import com.android.settings.DisplaySettings;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.SubSettings;
@@ -32,6 +33,7 @@
import com.android.settings.gestures.SwipeToNotificationSettings;
import com.android.settings.search2.ResultPayload.PayloadType;
+import com.android.settings.wifi.WifiSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -147,6 +149,29 @@
}
@Test
+ public void testLongTitle_PenalizedInRank() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ "Longer than 20 characters", // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ DisplaySettings.class.getName(),
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ BLANK, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+ assertThat(results.get(0).rank).isEqualTo(BASE_RANK + 2);
+ }
+
+ @Test
public void testParseCursor_MatchesIntentForSubSettings() {
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
final String BLANK = "";
@@ -246,6 +271,245 @@
assertThat(newPayload.valueMap.get(0)).isFalse();
}
+ // The following tests are temporary, and should be removed when we replace the Search
+ // White-list solution for elevating ranking.
+
+ @Test
+ public void testWifiKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "main_toggle_wifi";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testBluetoothKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "main_toggle_bluetooth";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testAirplaneKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "toggle_airplane";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testHotspotKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "tether_settings";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testBatterySaverKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "battery_saver";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testNFCKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "toggle_nfc";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testDataSaverKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "restrict_background";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testDataUsageKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "data_usage_enable";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ @Test
+ public void testRoamingKey_PrioritizedResult() {
+ MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
+ final String BLANK = "";
+ final String key = "button_roaming_key";
+
+ cursor.addRow(new Object[]{
+ ID, // Doc ID
+ TITLES[0], // Title
+ SUMMARY, // Summary on
+ SUMMARY, // summary off
+ WifiSettings.class.getName(), // ClassName
+ BLANK, // screen title
+ null, // icon
+ BLANK, // action
+ null, // target package
+ BLANK, // target class
+ key, // Key
+ 0, // Payload Type
+ null // Payload
+ });
+ List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
+
+ assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
+ }
+
+ // End of temporary tests
+
private MatrixCursor getDummyCursor() {
return getDummyCursor(true /* hasIcon */);
}
diff --git a/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
index 49eb48b..50debb4 100644
--- a/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
@@ -171,6 +171,18 @@
verify(screen.findPreference(MOCK_KEY), never()).setSummary(anyString());
}
+ @Test
+ public void initPreferences_shouldLoadDefaults() {
+ PreferenceScreen screen = getPreferenceScreen();
+ DashboardCategory dashboardCategory = getDashboardCategory();
+ dashboardCategory.getTile(0).metaData = new Bundle();
+
+ mImpl.initPreferences(mContext, screen, dashboardCategory);
+ verify(screen.findPreference(MOCK_KEY)).setIcon(SecurityFeatureProviderImpl.DEFAULT_ICON);
+ verify(screen.findPreference(MOCK_KEY))
+ .setSummary(SecurityFeatureProviderImpl.DEFAULT_SUMMARY);
+ }
+
private PreferenceScreen getPreferenceScreen() {
final PreferenceScreen screen = mock(PreferenceScreen.class);
final Preference pref = mock(Preference.class);
diff --git a/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
new file mode 100644
index 0000000..f41870e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.system;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.UserManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class FactoryResetPreferenceControllerTest {
+
+ private static final String FACTORY_RESET_KEY = "factory_reset";
+
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private UserManager mUserManager;
+
+ private FactoryResetPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mController = new FactoryResetPreferenceController(mContext, mUserManager);
+ }
+
+ @Test
+ public void isAvailable_systemUser() {
+ when(mUserManager.isAdminUser()).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_nonSystemUser() {
+ when(mUserManager.isAdminUser()).thenReturn(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test public void getPreferenceKey() {
+ assertThat(mController.getPreferenceKey()).isEqualTo(FACTORY_RESET_KEY);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowZoneGetter.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowZoneGetter.java
new file mode 100644
index 0000000..655acf1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowZoneGetter.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.testutils.shadow;
+
+import android.content.Context;
+
+import com.android.settingslib.datetime.ZoneGetter;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+@Implements(ZoneGetter.class)
+public class ShadowZoneGetter {
+
+ @Implementation
+ public static List<Map<String, Object>> getZonesList(Context context) {
+ List<Map<String, Object>> zones = new ArrayList<>();
+ zones.add(createDisplayEntry(TimeZone.getDefault(), "gmt-1:00", "FakePlace", 10000));
+ return zones;
+ }
+
+ private static Map<String, Object> createDisplayEntry(
+ TimeZone tz, CharSequence gmtOffsetText, CharSequence displayName, int offsetMillis) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ZoneGetter.KEY_ID, tz.getID());
+ map.put(ZoneGetter.KEY_DISPLAYNAME, displayName.toString());
+ map.put(ZoneGetter.KEY_DISPLAY_LABEL, displayName);
+ map.put(ZoneGetter.KEY_GMT, gmtOffsetText.toString());
+ map.put(ZoneGetter.KEY_OFFSET_LABEL, gmtOffsetText);
+ map.put(ZoneGetter.KEY_OFFSET, offsetMillis);
+ return map;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
index 78839fa..728e357 100644
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
+++ b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
@@ -19,6 +19,7 @@
import static android.provider.Settings.ACTION_WEBVIEW_SETTINGS;
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.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -33,13 +34,17 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageItemInfo;
+import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.UserManager;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.widget.RadioButtonPreference;
import com.android.settings.applications.PackageManagerWrapper;
+import com.android.settings.applications.defaultapps.DefaultAppInfo;
+import com.android.settings.widget.RadioButtonPreference;
import java.util.Arrays;
@@ -51,6 +56,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -66,7 +72,7 @@
private Activity mActivity;
@Mock
private UserManager mUserManager;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PackageManagerWrapper mPackageManager;
private WebViewAppPicker mPicker;
@@ -89,6 +95,8 @@
doNothing().when(mPicker).updateCheckedState(any());
doReturn(mActivity).when(mPicker).getActivity();
+ ReflectionHelpers.setField(mPicker, "mPm", mPackageManager);
+
mWvusWrapper = mock(WebViewUpdateServiceWrapper.class);
mPicker.setWebViewUpdateServiceWrapper(mWvusWrapper);
}
@@ -152,6 +160,62 @@
}
@Test
+ public void testDisabledPackageShownAsDisabled() {
+ String disabledReason = "disabled";
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
+ createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
+
+ RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
+ mPicker.configurePreferenceFromAppInfo(mockPreference,
+ DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
+
+ verify(mockPreference, times(1)).setEnabled(eq(false));
+ verify(mockPreference, never()).setEnabled(eq(true));
+ }
+
+ @Test
+ public void testEnabledPackageShownAsEnabled() {
+ String disabledReason = "";
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
+ createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
+
+ RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
+ mPicker.configurePreferenceFromAppInfo(mockPreference,
+ DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
+
+ verify(mockPreference, times(1)).setEnabled(eq(true));
+ verify(mockPreference, never()).setEnabled(eq(false));
+ }
+
+ @Test
+ public void testDisabledPackageShowsDisabledReasonSummary() {
+ String disabledReason = "disabled";
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
+ createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
+
+ RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
+ mPicker.configurePreferenceFromAppInfo(mockPreference,
+ DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
+
+ verify(mockPreference, times(1)).setSummary(eq(disabledReason));
+ // Ensure we haven't called setSummary several times.
+ verify(mockPreference, times(1)).setSummary(any());
+ }
+
+ @Test
+ public void testEnabledPackageShowsEmptySummary() {
+ String disabledReason = null;
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
+ createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
+
+ RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
+ mPicker.configurePreferenceFromAppInfo(mockPreference,
+ DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
+
+ verify(mockPreference, never()).setSummary(any());
+ }
+
+ @Test
public void testFinishIfNotAdmin() {
doReturn(false).when(mUserManager).isAdminUser();
mPicker.onAttach((Context) mActivity);
@@ -264,4 +328,30 @@
assertThat(mPicker.getDisabledReason(wvusWrapper, mContext,
DEFAULT_PACKAGE_NAME)).isEqualTo(EXPECTED_DISABLED_REASON);
}
+
+ /**
+ * Ensure that the version name of a WebView package is displayed after its name in the
+ * preference title.
+ */
+ @Test
+ public void testWebViewVersionAddedAfterLabel() throws PackageManager.NameNotFoundException {
+ PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
+ mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
+ when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(
+ mockPackageItemInfo, "" /* disabledReason */);
+
+ PackageInfo packageInfo = new PackageInfo();
+ packageInfo.versionName = "myVersionName";
+ PackageManager pm = mock(PackageManager.class);
+ when(pm.getPackageInfo(eq(DEFAULT_PACKAGE_NAME), anyInt())).thenReturn(packageInfo);
+ when(mPackageManager.getPackageManager()).thenReturn(pm);
+
+ RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
+ mPicker.configurePreferenceFromAppInfo(mockPreference,
+ DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
+
+ verify(mockPreference, times(1)).setTitle(eq("myPackage myVersionName"));
+ verify(mockPreference, times(1)).setTitle(any());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
index c412d55..de097fc 100644
--- a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
@@ -18,7 +18,9 @@
import android.app.Activity;
import android.content.Context;
+import android.hardware.display.DisplayManager;
import android.media.MediaRouter;
+import android.net.wifi.p2p.WifiP2pManager;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
@@ -32,6 +34,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -82,4 +85,22 @@
verify(mActivity).getString(R.string.wifi_display_status_connected);
}
+ @Test
+ public void isAvailable_noService_shouldReturnFalse() {
+ assertThat(WifiDisplaySettings.isAvailable(mActivity))
+ .isFalse();
+
+ }
+
+ @Test
+ public void isAvailable_hasService_shouldReturnTrue() {
+ when(mActivity.getSystemService(Context.DISPLAY_SERVICE))
+ .thenReturn(mock(DisplayManager.class));
+ when(mActivity.getSystemService(Context.WIFI_P2P_SERVICE))
+ .thenReturn(mock(WifiP2pManager.class));
+
+ assertThat(WifiDisplaySettings.isAvailable(mActivity))
+ .isTrue();
+ }
+
}
diff --git a/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java b/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java
index 231787e..3137d59 100644
--- a/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java
@@ -14,95 +14,115 @@
* limitations under the License.
*/
-package com.android.settings.core;
-
-import static junit.framework.TestCase.assertNotNull;
+package com.android.settings.display;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.app.UiModeManager;
-import android.content.Context;
import android.content.ContextWrapper;
+import android.content.om.OverlayInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.v7.preference.ListPreference;
-import com.android.settings.R;
import com.android.settings.display.ThemePreferenceController;
+import com.android.settings.display.ThemePreferenceController.OverlayManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import java.util.ArrayList;
+
@SmallTest
@RunWith(AndroidJUnit4.class)
public class ThemePreferenceControllerTest {
- private UiModeManager mMockUiModeManager;
+ private OverlayManager mMockOverlayManager;
private ContextWrapper mContext;
private ThemePreferenceController mPreferenceController;
+ private PackageManager mMockPackageManager;
@Before
public void setup() {
- mMockUiModeManager = mock(UiModeManager.class);
- mContext = new ContextWrapper(InstrumentationRegistry.getTargetContext()) {
+ mMockOverlayManager = mock(OverlayManager.class);
+ mMockPackageManager = mock(PackageManager.class);
+ mContext = new ContextWrapper(InstrumentationRegistry.getContext()) {
@Override
- public Object getSystemService(String name) {
- if (Context.UI_MODE_SERVICE.equals(name)) {
- return mMockUiModeManager;
- }
- return super.getSystemService(name);
+ public PackageManager getPackageManager() {
+ return mMockPackageManager;
}
};
- mPreferenceController = new ThemePreferenceController(mContext);
+ mPreferenceController = new ThemePreferenceController(mContext, mMockOverlayManager);
}
@Test
- public void testUpdateState() {
- when(mMockUiModeManager.getAvailableThemes()).thenReturn(new String[] {
- null,
- "Theme1",
- "Theme2",
+ public void testUpdateState() throws Exception {
+ OverlayInfo info1 = new OverlayInfo("com.android.Theme1", "android",
+ "", OverlayInfo.STATE_ENABLED, 0);
+ OverlayInfo info2 = new OverlayInfo("com.android.Theme2", "android",
+ "", 0, 0);
+ when(mMockPackageManager.getApplicationInfo(any(), anyInt())).thenAnswer(inv -> {
+ ApplicationInfo info = mock(ApplicationInfo.class);
+ if ("com.android.Theme1".equals(inv.getArguments()[0])) {
+ when(info.loadLabel(any())).thenReturn("Theme1");
+ } else {
+ when(info.loadLabel(any())).thenReturn("Theme2");
+ }
+ return info;
});
- when(mMockUiModeManager.getTheme()).thenReturn("Theme1");
+ when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt())).thenReturn(
+ list(info1, info2));
ListPreference pref = mock(ListPreference.class);
mPreferenceController.updateState(pref);
ArgumentCaptor<String[]> arg = ArgumentCaptor.forClass(String[].class);
verify(pref).setEntries(arg.capture());
- String[] entries = arg.getValue();
- assertEquals(3, entries.length);
- assertNotNull(entries[0]);
- assertEquals("Theme1", entries[1]);
- assertEquals("Theme2", entries[2]);
+
+ CharSequence[] entries = arg.getValue();
+ assertEquals(2, entries.length);
+ assertEquals("Theme1", entries[0]);
+ assertEquals("Theme2", entries[1]);
verify(pref).setEntryValues(arg.capture());
- String[] entryValues = arg.getValue();
- assertEquals(3, entryValues.length);
- assertNotNull(entryValues[0]);
- assertEquals("Theme1", entryValues[1]);
- assertEquals("Theme2", entryValues[2]);
+ CharSequence[] entryValues = arg.getValue();
+ assertEquals("com.android.Theme1", entryValues[0]);
+ assertEquals("com.android.Theme2", entryValues[1]);
- verify(pref).setValue(eq("Theme1"));
+ verify(pref).setValue(eq("com.android.Theme1"));
}
@Test
- public void testAvailable_false() {
- when(mMockUiModeManager.getAvailableThemes()).thenReturn(new String[1]);
+ public void testAvailable_false() throws Exception {
+ when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt()))
+ .thenReturn(list(new OverlayInfo("", "", "", 0, 0)));
assertFalse(mPreferenceController.isAvailable());
}
@Test
- public void testAvailable_true() {
- when(mMockUiModeManager.getAvailableThemes()).thenReturn(new String[2]);
+ public void testAvailable_true() throws Exception {
+ when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt()))
+ .thenReturn(list(new OverlayInfo("", "", "", 0, 0),
+ new OverlayInfo("", "", "", 0, 0)));
assertTrue(mPreferenceController.isAvailable());
}
+
+ private ArrayList<OverlayInfo> list(OverlayInfo... infos) {
+ ArrayList<OverlayInfo> list = new ArrayList<>();
+ for (int i = 0; i < infos.length; i++) {
+ list.add(infos[i]);
+ }
+ return list;
+ }
}
diff --git a/tests/unit/src/com/android/settings/vpn2/PreferenceListTest.java b/tests/unit/src/com/android/settings/vpn2/PreferenceListTest.java
index 40958ba..4a62011 100644
--- a/tests/unit/src/com/android/settings/vpn2/PreferenceListTest.java
+++ b/tests/unit/src/com/android/settings/vpn2/PreferenceListTest.java
@@ -37,9 +37,9 @@
import java.util.Map;
import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.compat.ArgumentMatcher;
public class PreferenceListTest extends AndroidTestCase {
private static final String TAG = "PreferenceListTest";
@@ -138,7 +138,7 @@
final ArgumentMatcher<VpnProfile> equalsFake = new ArgumentMatcher<VpnProfile>() {
@Override
- public boolean matches(final Object arg) {
+ public boolean matchesObject(final Object arg) {
if (arg == vpnProfile) return true;
if (arg == null) return false;
return TextUtils.equals(((VpnProfile) arg).key, vpnProfile.key);