Merge "Move static search ranking from DatabaseResultLoader to Search Adapter."
diff --git a/res/drawable/ic_password.xml b/res/drawable/ic_password.xml
new file mode 100644
index 0000000..57591c2
--- /dev/null
+++ b/res/drawable/ic_password.xml
@@ -0,0 +1,34 @@
+<!--
+ 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:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M21.5,9.39l-1.63,0l0.81,-1.42l-0.86,-0.5l-0.82,1.42l-0.82,-1.42l-0.86,0.5l0.81,1.42l-1.63,0l0,1l1.63,0l-0.81,1.41l0.86,0.5l0.82,-1.41l0.82,1.41l0.86,-0.5l-0.81,-1.41l1.63,0z" />
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M13.68,7.97l-0.86,-0.5l-0.82,1.42l-0.82,-1.42l-0.86,0.5l0.81,1.42l-1.63,0l0,1l1.63,0l-0.81,1.41l0.86,0.5l0.82,-1.41l0.82,1.41l0.86,-0.5l-0.81,-1.41l1.63,0l0,-1l-1.63,0z" />
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M6.68,7.97l-0.86,-0.5l-0.82,1.42l-0.82,-1.42l-0.86,0.5l0.81,1.42l-1.63,0l0,1l1.63,0l-0.81,1.41l0.86,0.5l0.82,-1.41l0.82,1.41l0.86,-0.5l-0.81,-1.41l1.63,0l0,-1l-1.63,0z" />
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M21,17.89H3c-0.28,0 -0.5,-0.22 -0.5,-0.5v-1c0,-0.28 0.22,-0.5 0.5,-0.5h18c0.28,0 0.5,0.22 0.5,0.5v1C21.5,17.66 21.28,17.89 21,17.89z" />
+</vector>
diff --git a/res/drawable/ic_pattern.xml b/res/drawable/ic_pattern.xml
new file mode 100644
index 0000000..003111e
--- /dev/null
+++ b/res/drawable/ic_pattern.xml
@@ -0,0 +1,37 @@
+<!--
+ 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:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M4,4m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0" />
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M4,12m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0" />
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M12,4m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0" />
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M20,12m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0" />
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M20,18c-0.93,0 -1.7,0.64 -1.93,1.5h-4.14c-0.22,-0.86 -1,-1.5 -1.93,-1.5s-1.7,0.64 -1.93,1.5H5.93c-0.05,-0.18 -0.12,-0.35 -0.21,-0.51l5.28,-5.28C11.29,13.89 11.63,14 12,14c1.1,0 2,-0.9 2,-2c0,-0.37 -0.11,-0.71 -0.28,-1.01l5.28,-5.28C19.29,5.89 19.63,6 20,6c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2s-2,0.9 -2,2c0,0.37 0.11,0.71 0.28,1.01l-5.28,5.28C12.71,10.11 12.37,10 12,10c-1.1,0 -2,0.9 -2,2c0,0.37 0.11,0.71 0.28,1.01l-5.28,5.28C4.71,18.11 4.37,18 4,18c-1.1,0 -2,0.9 -2,2s0.9,2 2,2c0.93,0 1.7,-0.64 1.93,-1.5h4.14c0.22,0.86 1,1.5 1.93,1.5s1.7,-0.64 1.93,-1.5h4.14c0.22,0.86 1,1.5 1.93,1.5c1.1,0 2,-0.9 2,-2S21.1,18 20,18z" />
+</vector>
diff --git a/res/drawable/ic_pin.xml b/res/drawable/ic_pin.xml
new file mode 100644
index 0000000..0176019
--- /dev/null
+++ b/res/drawable/ic_pin.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="?attr/suwListItemIconColor"
+ android:pathData="M20,4L4,4A2,2 0,0 0,2 6L2,18a2,2 0,0 0,2 2L20,20a2,2 0,0 0,2 -2L22,6A2,2 0,0 0,20 4ZM7.1,15L5.9,15L5.9,10.2L4.7,10.2L4.7,9L7.1,9v6ZM13.2,11.4A1.2,1.2 0,0 1,12 12.6L10.8,12.6v1.2h2.4L13.2,15L9.6,15L9.6,12.6a1.2,1.2 0,0 1,1.2 -1.2L12,11.4L12,10.2L9.6,10.2L9.6,9L12,9a1.2,1.2 0,0 1,1.2 1.2v1.2ZM19.3,11.1a0.9,0.9 0,0 1,-0.9 0.9,0.9 0.9,0 0,1 0.9,0.9v0.9A1.2,1.2 0,0 1,18.1 15L15.7,15L15.7,13.8h2.4L18.1,12.6L16.9,12.6L16.9,11.4h1.2L18.1,10.2L15.7,10.2L15.7,9h2.4a1.2,1.2 0,0 1,1.2 1.2v0.9Z" />
+</vector>
diff --git a/res/layout/app_domains_dialog.xml b/res/layout/app_domains_dialog.xml
index f9c6b64..d006027 100644
--- a/res/layout/app_domains_dialog.xml
+++ b/res/layout/app_domains_dialog.xml
@@ -15,18 +15,12 @@
limitations under the License.
-->
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingStart="24dp"
- android:paddingTop="16dp"
- android:paddingEnd="24dp">
+<ListView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:divider="@null"
+ android:scrollbarStyle="insideOverlay"
+ android:padding="24dp" />
- <ListView
- android:id="@android:id/list"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:divider="@null"
- android:scrollbarStyle="insideOverlay" />
-
-</FrameLayout>
diff --git a/res/layout/app_domains_item.xml b/res/layout/app_domains_item.xml
index e2ccbd3..5aa9cfa 100644
--- a/res/layout/app_domains_item.xml
+++ b/res/layout/app_domains_item.xml
@@ -15,12 +15,12 @@
limitations under the License.
-->
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/domain_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="4dp"
android:paddingEnd="4dp"
- android:paddingTop="16dp"
- android:divider="@null"
- />
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp" />
diff --git a/res/layout/choose_lock_dialog_item.xml b/res/layout/choose_lock_dialog_item.xml
new file mode 100644
index 0000000..8e78f99
--- /dev/null
+++ b/res/layout/choose_lock_dialog_item.xml
@@ -0,0 +1,29 @@
+<?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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:drawablePadding="24dp"
+ android:ellipsize="marquee"
+ android:gravity="center_vertical"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:textAppearance="@android:style/TextAppearance.Material.Subhead"
+ android:textColor="?android:attr/textColorAlertDialogListItem" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 08d1b7c..9c1beaa 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1099,6 +1099,9 @@
<!-- Label for button in screen lock settings, allowing users to choose other types of screen locks. [CHAR LIMIT=40] -->
<string name="setup_lock_settings_options_button_label">Screen lock options</string>
+ <!-- Title for dialog in screen lock settings, allowing users to choose other types of screen locks. [CHAR LIMIT=40] -->
+ <string name="setup_lock_settings_options_dialog_title">Screen lock options</string>
+
<!-- Main Security lock settings --><skip />
<!-- Title for PreferenceScreen to launch picker for security method when there is none [CHAR LIMIT=22] -->
<string name="unlock_set_unlock_launch_picker_title">Screen lock</string>
@@ -1240,20 +1243,38 @@
<!-- Title shown on security settings to allow the user to change their lockscreen password [CHAR LIMIT=22]-->
<string name="unlock_change_lock_password_title">Change unlock password</string>
- <!-- Message shown when the user incorrectly enters their lock and it counts towards the max attempts before wiping the work profile. -->
- <string name="lock_profile_wipe_attempts">Try again. Attempt <xliff:g id="current_attempts">%1$d</xliff:g> of <xliff:g id="total_attempts">%2$d</xliff:g>.</string>
- <!-- Title of a dialog shown when the user only has one attempt left to provide the lock before the work profile is wiped. -->
- <string name="lock_profile_wipe_warning_title">Last try</string>
- <!-- Content of the dialog shown when the user only has one attempt left to provide the work pattern before the work profile is wiped. -->
- <string name="lock_profile_wipe_warning_content_pattern">If you enter an incorrect work pattern on this attempt, your work profile and associated data will be removed from this device.</string>
- <!-- Content of the dialog shown when the user only has one attempt left to provide the work PIN before the work profile is wiped. -->
- <string name="lock_profile_wipe_warning_content_pin">If you enter an incorrect work PIN on this attempt, your work profile and associated data will be removed from this device.</string>
- <!-- Content of the dialog shown when the user only has one attempt left to provide the work password before the work profile is wiped. -->
- <string name="lock_profile_wipe_warning_content_password">If you enter an incorrect work password on this attempt, your work profile and associated data will be removed from this device.</string>
- <!-- Content of the dialog shown when the user has failed to provide the work lock too many times and the work profile is wiped. -->
- <string name="lock_profile_wipe_content">Too many incorrect attempts. Your work profile and associated data will be removed from this device.</string>
+ <!-- Message shown on the lock screen when the user incorrectly enters their lock and it counts towards the max attempts before their data on the device is wiped. [CHAR LIMIT=NONE] -->
+ <string name="lock_failed_attempts_before_wipe">Try again. Attempt <xliff:g id="current_attempts">%1$d</xliff:g> of <xliff:g id="total_attempts">%2$d</xliff:g>.</string>
+
+ <!-- Title of a dialog shown when the user only has one attempt left to provide the lock before the device, one of its users, or a work profile is wiped. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_attempt_before_wipe_warning_title">Your data will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the device lock pattern before the device is wiped. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_pattern_attempt_before_wipe_device">If you enter an incorrect pattern on the next attempt, this device's data will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the device lock PIN before the device is wiped. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_pin_attempt_before_wipe_device">If you enter an incorrect PIN on the next attempt, this device's data will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the device lock password before the device is wiped. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_password_attempt_before_wipe_device">If you enter an incorrect password on the next attempt, this device's data will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the user lock pattern before the user is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_pattern_attempt_before_wipe_user">If you enter an incorrect pattern on the next attempt, this user will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the user lock PIN before the user is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_pin_attempt_before_wipe_user">If you enter an incorrect PIN on the next attempt, this user will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the user lock password before the user is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_password_attempt_before_wipe_user">If you enter an incorrect password on the next attempt, this user will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the work lock pattern before the work profile is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_pattern_attempt_before_wipe_profile">If you enter an incorrect pattern on the next attempt, your work profile and its data will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the work lock PIN before the work profile is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_pin_attempt_before_wipe_profile">If you enter an incorrect PIN on the next attempt, your work profile and its data will be deleted</string>
+ <!-- Content of the dialog shown when the user only has one attempt left to provide the work lock password before the work profile is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_last_password_attempt_before_wipe_profile">If you enter an incorrect password on the next attempt, your work profile and its data will be deleted</string>
+
+ <!-- Content of the dialog shown when the user has failed to provide the device lock too many times and the device is wiped. [CHAR LIMIT=NONE] -->
+ <string name="lock_failed_attempts_now_wiping_device">Too many incorrect attempts. This device's data will be deleted.</string>
+ <!-- Content of the dialog shown when the user has failed to provide the user lock too many times and the user is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_failed_attempts_now_wiping_user">Too many incorrect attempts. This user will be deleted.</string>
+ <!-- Content of the dialog shown when the user has failed to provide the work lock too many times and the work profile is removed. [CHAR LIMIT=NONE] -->
+ <string name="lock_failed_attempts_now_wiping_profile">Too many incorrect attempts. This work profile and its data will be deleted.</string>
<!-- Button label to dismiss the dialog telling the user the work profile has been wiped. [CHAR LIMIT=40] -->
- <string name="lock_profile_wipe_dismiss">Dismiss</string>
+ <string name="lock_failed_attempts_now_wiping_dialog_dismiss">Dismiss</string>
<!-- Hint shown in dialog screen when password is too short -->
<string name="lockpassword_password_too_short">Must be at least <xliff:g id="count" example="3">%d</xliff:g> characters</string>
@@ -4342,11 +4363,6 @@
can't verify user consent. [CHAR LIMIT=NONE] -->
<string name="touch_filtered_warning">Because an app is obscuring a permission request, Settings
can’t verify your response.</string>
- <!-- Warning shown when user input has been blocked due to another app overlaying screen
- content. Since we don't know what the app is showing on top of the input target, we
- can't verify user consent. [CHAR LIMIT=NONE] -->
- <string name="window_obscured_warning">Because another app is displaying on top of these options,
- Settings can\u2019t respond to your action.</string>
<!-- Warning that the device data will not be encrypted with password or PIN if
enabling an accessibility service and there is a secure lock setup. [CHAR LIMIT=NONE] -->
<string name="enable_service_encryption_warning">If you turn on <xliff:g id="service"
@@ -6575,8 +6591,8 @@
<!-- Configure Notifications: Work profile section header [CHAR LIMIT=30] -->
<string name="profile_section_header">Work notifications</string>
- <!-- Configure Notifications: Title for the notification badging option. [CHAR LIMIT=30] -->
- <string name="notification_badging_title">Allow icon badges</string>
+ <!-- Configure Notifications: Title for the notification badging option. [CHAR LIMIT=30 BACKUP_MESSAGE_ID=5125022693565388760] -->
+ <string name="notification_badging_title">Allow notification dots</string>
<!-- Configure Notifications: Title for the pulse notification light option. [CHAR LIMIT=30] -->
<string name="notification_pulse_title">Blink light</string>
@@ -6805,9 +6821,6 @@
<item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> categories deleted</item>
</plurals>
- <!-- [CHAR LIMIT=45\ Global notification badge setting -->
- <string name="notification_badges">Notification badges</string>
-
<!-- [CHAR LIMIT=NONE] App notification settings: notifications enabled-->
<string name="notification_toggle_on">On</string>
@@ -6826,8 +6839,11 @@
<!-- [CHAR LIMIT=NONE] Channel notification settings: Block option description-->
<string name="notification_content_block_summary">Never show notifications in the shade or on peripheral devices</string>
- <!-- [CHAR LIMIT=NONE] [BACKUP_MESSAGE_ID:7166470350070693657] Channel notification settings: Badging option title -->
- <string name="notification_badge_title">Allow icon badge</string>
+ <!-- [CHAR LIMIT=NONE BACKUP_MESSAGE_ID:7166470350070693657] App notification settings: Badging option title -->
+ <string name="notification_badge_title">Allow notification dot</string>
+
+ <!-- [CHAR LIMIT=NONE BACKUP_MESSAGE_ID:7166470350070693657] Channel notification settings: Badging option title -->
+ <string name="notification_channel_badge_title">Show notification dot</string>
<!-- [CHAR LIMIT=NONE] App notification settings: Override DND option title -->
<string name="app_notification_override_dnd_title">Override Do Not Disturb</string>
diff --git a/res/xml/security_lockscreen_settings.xml b/res/xml/security_lockscreen_settings.xml
index 2a4416e..d10440e 100644
--- a/res/xml/security_lockscreen_settings.xml
+++ b/res/xml/security_lockscreen_settings.xml
@@ -15,21 +15,32 @@
-->
<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/lockscreen_settings_title">
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/lockscreen_settings_title">
+
+ <com.android.settings.notification.RestrictedDropDownPreference
+ android:key="security_setting_lock_screen_notif"
+ android:title="@string/lock_screen_notifications_title"
+ android:summary="@string/summary_placeholder" />
+
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="add_users_when_locked"
+ android:title="@string/user_add_on_lockscreen_menu" />
+
+ <com.android.settingslib.RestrictedPreference
+ android:key="owner_info_settings"
+ android:title="@string/owner_info_settings_title"
+ android:summary="@string/owner_info_settings_summary" />
+
+ <PreferenceCategory
+ android:key="security_setting_lock_screen_notif_work_header"
+ android:title="@string/profile_section_header">
<com.android.settings.notification.RestrictedDropDownPreference
- android:key="lock_screen_notifications"
+ android:key="security_setting_lock_screen_notif_work"
android:title="@string/lock_screen_notifications_title"
- android:summary="@string/summary_placeholder"/>
+ android:summary="@string/summary_placeholder" />
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="add_users_when_locked"
- android:title="@string/user_add_on_lockscreen_menu"/>
-
- <com.android.settingslib.RestrictedPreference
- android:key="owner_info_settings"
- android:title="@string/owner_info_settings_title"
- android:summary="@string/owner_info_settings_summary"/>
+ </PreferenceCategory>
</PreferenceScreen>
diff --git a/res/xml/upgraded_channel_notification_settings.xml b/res/xml/upgraded_channel_notification_settings.xml
index 4cf171f..7925bb7 100644
--- a/res/xml/upgraded_channel_notification_settings.xml
+++ b/res/xml/upgraded_channel_notification_settings.xml
@@ -40,7 +40,7 @@
<!-- Show badge -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="badge"
- android:title="@string/notification_badge_title"
+ android:title="@string/notification_channel_badge_title"
settings:useAdditionalSummary="true"
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index 3bb82cf..fb2f29f 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -65,8 +65,6 @@
import com.android.settings.users.UserDialogs;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-import com.android.settingslib.SecureTouchListener;
-
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
@@ -352,8 +350,6 @@
final View restrictedAction = findViewById(R.id.restricted_action);
restrictedAction.setFilterTouchesWhenObscured(true);
- restrictedAction.setOnTouchListener(
- new SecureTouchListener(getString(R.string.window_obscured_warning)));
restrictedAction.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mAdding) {
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 3fc7964..5bcbc11 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -26,6 +26,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
import android.support.annotation.XmlRes;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
@@ -423,11 +424,28 @@
return -1;
}
- protected void removePreference(String key) {
- Preference pref = findPreference(key);
- if (pref != null) {
- getPreferenceScreen().removePreference(pref);
+ protected boolean removePreference(String key) {
+ return removePreference(getPreferenceScreen(), key);
+ }
+
+ @VisibleForTesting
+ boolean removePreference(PreferenceGroup group, String key) {
+ final int preferenceCount = group.getPreferenceCount();
+ for (int i = 0; i < preferenceCount; i++) {
+ final Preference preference = group.getPreference(i);
+ final String curKey = preference.getKey();
+
+ if (TextUtils.equals(curKey, key)) {
+ return group.removePreference(preference);
+ }
+
+ if (preference instanceof PreferenceGroup) {
+ if (removePreference((PreferenceGroup) preference, key)) {
+ return true;
+ }
+ }
}
+ return false;
}
/**
diff --git a/src/com/android/settings/applications/PackageManagerWrapper.java b/src/com/android/settings/applications/PackageManagerWrapper.java
index 0cfbdc5..580b578 100644
--- a/src/com/android/settings/applications/PackageManagerWrapper.java
+++ b/src/com/android/settings/applications/PackageManagerWrapper.java
@@ -111,4 +111,6 @@
*/
void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags,
int userId);
+
+ int getPackageUidAsUser(String pkg, int userId) throws PackageManager.NameNotFoundException;
}
diff --git a/src/com/android/settings/applications/PackageManagerWrapperImpl.java b/src/com/android/settings/applications/PackageManagerWrapperImpl.java
index 3a78e3c..a47137c 100644
--- a/src/com/android/settings/applications/PackageManagerWrapperImpl.java
+++ b/src/com/android/settings/applications/PackageManagerWrapperImpl.java
@@ -103,4 +103,10 @@
int userId) {
mPm.deletePackageAsUser(packageName, observer, flags, userId);
}
+
+ @Override
+ public int getPackageUidAsUser(String pkg, int userId)
+ throws PackageManager.NameNotFoundException {
+ return mPm.getPackageUidAsUser(pkg, userId);
+ }
}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
index 5c0f9a3..219ce0f 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
@@ -18,16 +18,20 @@
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
+import android.util.Log;
import java.util.List;
public class DefaultBrowserPreferenceController extends DefaultAppPreferenceController {
+ private static final String TAG = "BrowserPrefCtrl";
+
static final Intent BROWSE_PROBE = new Intent()
.setAction(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
@@ -60,9 +64,10 @@
@Override
protected DefaultAppInfo getDefaultAppInfo() {
try {
+ final String packageName = mPackageManager.getDefaultBrowserPackageNameAsUser(mUserId);
+ Log.d(TAG, "Get default browser package: " + packageName);
return new DefaultAppInfo(mPackageManager,
- mPackageManager.getPackageManager().getApplicationInfo(
- mPackageManager.getDefaultBrowserPackageNameAsUser(mUserId), 0));
+ mPackageManager.getPackageManager().getApplicationInfo(packageName, 0));
} catch (PackageManager.NameNotFoundException e) {
return null;
}
@@ -90,7 +95,12 @@
// Resolve that intent and check that the handleAllWebDataURI boolean is set
final List<ResolveInfo> list = getCandidates();
if (list != null && list.size() == 1) {
- return list.get(0).loadLabel(mPackageManager.getPackageManager()).toString();
+ final ResolveInfo info = list.get(0);
+ final String label = info.loadLabel(mPackageManager.getPackageManager()).toString();
+ final ComponentInfo cn = info.getComponentInfo();
+ final String packageName = cn == null ? null : cn.packageName;
+ Log.d(TAG, "Getting label for the only browser app: " + packageName + label);
+ return label;
}
return null;
}
diff --git a/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java b/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java
index 358223d..a6ae31c 100644
--- a/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java
+++ b/src/com/android/settings/bluetooth/BluetoothFeatureProvider.java
@@ -21,7 +21,12 @@
*/
public interface BluetoothFeatureProvider {
/**
- * Check whether additional pairing page is enabled
+ * @return whether additional pairing page is enabled
*/
boolean isPairingPageEnabled();
+
+ /**
+ * @return whether device details should be shown as a separate page (true) or a dialog (false)
+ */
+ boolean isDeviceDetailPageEnabled();
}
diff --git a/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java b/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java
index f5b65b7..8d9e1c4 100644
--- a/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java
+++ b/src/com/android/settings/bluetooth/BluetoothFeatureProviderImpl.java
@@ -9,4 +9,9 @@
public boolean isPairingPageEnabled() {
return false;
}
+
+ @Override
+ public boolean isDeviceDetailPageEnabled() {
+ return false;
+ }
}
diff --git a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
index 51102a6..b57ff6a 100644
--- a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
+++ b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
@@ -20,6 +20,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
+import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -145,12 +146,11 @@
}
}
- private void logPackageName(String key, String value) {
+ @VisibleForTesting
+ void logPackageName(String key, String value) {
final String prefKey = mTag + "/" + key;
- mMetricsFeature.action(mContext, MetricsEvent.ACTION_SETTINGS_PREFERENCE_CHANGE,
+ mMetricsFeature.action(mContext, MetricsEvent.ACTION_SETTINGS_PREFERENCE_CHANGE, value,
Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, prefKey));
- mMetricsFeature.action(mContext, MetricsEvent.ACTION_GENERIC_PACKAGE,
- prefKey + "|" + value);
}
private void safeLogValue(String key, String value) {
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index af6306d..d9643f2 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -36,12 +36,15 @@
import android.text.format.Formatter;
import android.util.ArraySet;
import android.util.IconDrawableFactory;
+import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.applications.AppInfoBase;
+import com.android.settings.applications.PackageManagerWrapper;
+import com.android.settings.applications.PackageManagerWrapperImpl;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.AppItem;
import com.android.settingslib.net.ChartData;
@@ -71,6 +74,7 @@
private static final int LOADER_CHART_DATA = 2;
private static final int LOADER_APP_PREF = 3;
+ private PackageManagerWrapper mPackageManagerWrapper;
private final ArraySet<String> mPackages = new ArraySet<>();
private Preference mTotalUsage;
private Preference mForegroundUsage;
@@ -99,6 +103,7 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ mPackageManagerWrapper = new PackageManagerWrapperImpl(getPackageManager());
final Bundle args = getArguments();
try {
@@ -142,11 +147,11 @@
if (mAppItem.key > 0) {
if (mPackages.size() != 0) {
- PackageManager pm = getPackageManager();
try {
- ApplicationInfo info = pm.getApplicationInfo(mPackages.valueAt(0), 0);
+ ApplicationInfo info = mPackageManagerWrapper.getApplicationInfoAsUser(
+ mPackages.valueAt(0), 0, UserHandle.getUserId(mAppItem.key));
mIcon = IconDrawableFactory.newInstance(getActivity()).getBadgedIcon(info);
- mLabel = info.loadLabel(pm);
+ mLabel = info.loadLabel(mPackageManagerWrapper.getPackageManager());
mPackageName = info.packageName;
} catch (PackageManager.NameNotFoundException e) {
}
@@ -317,9 +322,13 @@
String pkg = mPackages.size() != 0 ? mPackages.valueAt(0) : null;
int uid = 0;
- try {
- uid = pkg != null ? getPackageManager().getPackageUid(pkg, 0) : 0;
- } catch (PackageManager.NameNotFoundException e) {
+ if (pkg != null) {
+ try {
+ uid = mPackageManagerWrapper.getPackageUidAsUser(pkg,
+ UserHandle.getUserId(mAppItem.key));
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.w(TAG, "Skipping UID because cannot find package " + pkg);
+ }
}
final boolean showInfoButton = mAppItem.key > 0;
@@ -328,6 +337,7 @@
final Preference pref = EntityHeaderController
.newInstance(activity, this, null /* header */)
.setRecyclerView(getListView(), getLifecycle())
+ .setUid(uid)
.setButtonActions(showInfoButton
? EntityHeaderController.ActionType.ACTION_APP_INFO
: EntityHeaderController.ActionType.ACTION_NONE,
@@ -335,7 +345,6 @@
.setIcon(mIcon)
.setLabel(mLabel)
.setPackageName(pkg)
- .setUid(uid)
.done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
diff --git a/src/com/android/settings/fuelgauge/AppButtonsPreferenceController.java b/src/com/android/settings/fuelgauge/AppButtonsPreferenceController.java
index f4f6c36..6b4c8a9 100644
--- a/src/com/android/settings/fuelgauge/AppButtonsPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/AppButtonsPreferenceController.java
@@ -98,6 +98,8 @@
@VisibleForTesting
Button mUninstallButton;
@VisibleForTesting
+ String mPackageName;
+ @VisibleForTesting
boolean mDisableAfterUninstall = false;
private final int mRequestUninstall;
@@ -113,7 +115,6 @@
private MetricsFeatureProvider mMetricsFeatureProvider;
private LayoutPreference mButtonsPref;
- private String mPackageName;
private int mUserId;
private boolean mUpdatedSysApp = false;
private boolean mListeningToPackageRemove = false;
@@ -134,7 +135,6 @@
mMetricsFeatureProvider = FeatureFactory.getFactory(activity).getMetricsFeatureProvider();
mState = state;
- mSession = mState.newSession(this);
mDpm = dpm;
mUserManager = userManager;
mPm = packageManager;
@@ -145,10 +145,10 @@
mRequestUninstall = requestUninstall;
mRequestRemoveDeviceAdmin = requestRemoveDeviceAdmin;
- lifecycle.addObserver(this);
-
if (packageName != null) {
mAppEntry = mState.getEntry(packageName, mUserId);
+ mSession = mState.newSession(this);
+ lifecycle.addObserver(this);
} else {
mFinishing = true;
}
@@ -620,7 +620,11 @@
return false;
}
- private boolean refreshUi() {
+ @VisibleForTesting
+ boolean refreshUi() {
+ if (mPackageName == null) {
+ return false;
+ }
retrieveAppEntry();
if (mAppEntry == null || mPackageInfo == null) {
return false;
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 327d3a4..194b2fb 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -33,6 +33,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
/**
@@ -219,7 +221,7 @@
* Calculate the whole running time in the state {@code statsType}
*
* @param batteryStatsHelper utility class that contains the data
- * @param statsType state that we want to calculate the time for
+ * @param statsType state that we want to calculate the time for
* @return the running time in millis
*/
public long calculateRunningTimeBasedOnStatsType(BatteryStatsHelper batteryStatsHelper,
@@ -247,6 +249,18 @@
return ArrayUtils.isEmpty(packageNames) ? null : packageNames[0];
}
+ /**
+ * Sort the {@code usageList} based on {@link BatterySipper#totalPowerMah}
+ */
+ public void sortUsageList(List<BatterySipper> usageList) {
+ Collections.sort(usageList, new Comparator<BatterySipper>() {
+ @Override
+ public int compare(BatterySipper a, BatterySipper b) {
+ return Double.compare(b.totalPowerMah, a.totalPowerMah);
+ }
+ });
+ }
+
private long convertUsToMs(long timeUs) {
return timeUs / 1000;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index 2cc6899..5ef6fe5 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -80,12 +80,12 @@
@Override
public boolean isAdvancedUiEnabled() {
- return false;
+ return true;
}
@Override
public boolean isPowerAccountingToggleEnabled() {
- return false;
+ return true;
}
@Override
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index de80d3b..275b78c 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -77,8 +77,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
/**
@@ -399,7 +397,7 @@
*
* @return A sorted list of apps using power.
*/
- private static List<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
+ private List<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
final SparseArray<BatterySipper> uidList = new SparseArray<>();
final ArrayList<BatterySipper> results = new ArrayList<>();
@@ -474,12 +472,7 @@
}
// The sort order must have changed, so re-sort based on total power use.
- Collections.sort(results, new Comparator<BatterySipper>() {
- @Override
- public int compare(BatterySipper a, BatterySipper b) {
- return Double.compare(b.totalPowerMah, a.totalPowerMah);
- }
- });
+ mBatteryUtils.sortUsageList(results);
return results;
}
@@ -531,9 +524,9 @@
if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
final List<BatterySipper> usageList = getCoalescedUsageList(
USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
-
double hiddenPowerMah = mShowAllApps ? 0 :
mBatteryUtils.removeHiddenBatterySippers(usageList);
+ mBatteryUtils.sortUsageList(usageList);
final int numSippers = usageList.size();
for (int i = 0; i < numSippers; i++) {
diff --git a/src/com/android/settings/gestures/AssistGestureSettings.java b/src/com/android/settings/gestures/AssistGestureSettings.java
index a080bec..64187a3 100644
--- a/src/com/android/settings/gestures/AssistGestureSettings.java
+++ b/src/com/android/settings/gestures/AssistGestureSettings.java
@@ -38,7 +38,7 @@
@Override
public int getMetricsCategory() {
- return MetricsProto.MetricsEvent.VIEW_UNKNOWN;
+ return MetricsProto.MetricsEvent.SETTINGS_ASSIST_GESTURE;
}
@Override
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 58d45d6..31a8526 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -18,7 +18,10 @@
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.net.Uri;
@@ -67,6 +70,7 @@
private SettingObserver mAirplaneModeObserver;
private Preference mPreference;
+ private TetherBroadcastReceiver mTetherReceiver;
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
TetherPreferenceController() {
@@ -131,6 +135,11 @@
if (mAirplaneModeObserver == null) {
mAirplaneModeObserver = new SettingObserver();
}
+ if (mTetherReceiver == null) {
+ mTetherReceiver = new TetherBroadcastReceiver();
+ }
+ mContext.registerReceiver(
+ mTetherReceiver, new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
mContext.getContentResolver()
.registerContentObserver(mAirplaneModeObserver.uri, false, mAirplaneModeObserver);
}
@@ -140,6 +149,9 @@
if (mAirplaneModeObserver != null) {
mContext.getContentResolver().unregisterContentObserver(mAirplaneModeObserver);
}
+ if (mTetherReceiver != null) {
+ mContext.unregisterReceiver(mTetherReceiver);
+ }
}
@Override
@@ -238,4 +250,14 @@
}
}
}
+
+ @VisibleForTesting
+ class TetherBroadcastReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ updateSummary();
+ }
+
+ }
}
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index e7be62f..4cbe692 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -201,7 +201,8 @@
final NotificationChannel channel) {
MasterSwitchPreference channelPref = new MasterSwitchPreference(
getPrefContext());
- channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && !mAppRow.systemApp);
+ channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
+ && isChannelBlockable(mAppRow.systemApp, channel));
channelPref.setKey(channel.getId());
channelPref.setTitle(channel.getName());
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index f7bf1ca..6b4129c 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -228,7 +228,7 @@
mBlockBar.setKey(KEY_BLOCK);
getPreferenceScreen().addPreference(mBlockBar);
- if (mAppRow.systemApp && mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
+ if (!isChannelBlockable(mAppRow.systemApp, mChannel)) {
setVisible(mBlockBar, false);
}
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 3e363d7..26fc0a0 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -69,7 +69,10 @@
final PulseNotificationPreferenceController pulseController =
new PulseNotificationPreferenceController(context);
final LockScreenNotificationPreferenceController lockScreenNotificationController =
- new LockScreenNotificationPreferenceController(context);
+ new LockScreenNotificationPreferenceController(context,
+ "lock_screen_notifications",
+ "lock_screen_notifications_profile_header",
+ "lock_screen_notifications_profile");
if (lifecycle != null) {
lifecycle.addObserver(pulseController);
lifecycle.addObserver(lockScreenNotificationController);
diff --git a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
index b84d961..228e185 100644
--- a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
+++ b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
@@ -26,6 +26,7 @@
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
import android.util.Log;
import com.android.internal.widget.LockPatternUtils;
@@ -46,11 +47,10 @@
Preference.OnPreferenceChangeListener, LifecycleObserver, OnResume, OnPause {
private static final String TAG = "LockScreenNotifPref";
- private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "lock_screen_notifications";
- private static final String KEY_LOCK_SCREEN_PROFILE_HEADER =
- "lock_screen_notifications_profile_header";
- private static final String KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS =
- "lock_screen_notifications_profile";
+
+ private final String mSettingKey;
+ private final String mWorkSettingCategoryKey;
+ private final String mWorkSettingKey;
private RestrictedDropDownPreference mLockscreen;
private RestrictedDropDownPreference mLockscreenProfile;
@@ -64,7 +64,16 @@
private int mLockscreenSelectedValueProfile;
public LockScreenNotificationPreferenceController(Context context) {
+ this(context, null, null, null);
+ }
+
+ public LockScreenNotificationPreferenceController(Context context,
+ String settingKey, String workSettingCategoryKey, String workSettingKey) {
super(context);
+ mSettingKey = settingKey;
+ mWorkSettingCategoryKey = workSettingCategoryKey;
+ mWorkSettingKey = workSettingKey;
+
mProfileChallengeUserId = Utils.getManagedProfileId(
UserManager.get(context), UserHandle.myUserId());
final LockPatternUtils utils = new LockPatternUtils(context);
@@ -79,17 +88,17 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mLockscreen =
- (RestrictedDropDownPreference) screen.findPreference(KEY_LOCK_SCREEN_NOTIFICATIONS);
+ (RestrictedDropDownPreference) screen.findPreference(mSettingKey);
if (mLockscreen == null) {
- Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_NOTIFICATIONS);
+ Log.i(TAG, "Preference not found: " + mSettingKey);
return;
}
if (mProfileChallengeUserId != UserHandle.USER_NULL) {
mLockscreenProfile = (RestrictedDropDownPreference) screen.findPreference(
- KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
+ mWorkSettingKey);
} else {
- removePreference(screen, KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
- removePreference(screen, KEY_LOCK_SCREEN_PROFILE_HEADER);
+ removePreference(screen, mWorkSettingKey);
+ removePreference(screen, mWorkSettingCategoryKey);
}
mSettingObserver = new SettingObserver();
initLockScreenNotificationPrefDisplay();
@@ -136,7 +145,7 @@
private void initLockscreenNotificationPrefForProfile() {
if (mLockscreenProfile == null) {
- Log.i(TAG, "Preference not found: " + KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS);
+ Log.i(TAG, "Preference not found: " + mWorkSettingKey);
return;
}
ArrayList<CharSequence> entries = new ArrayList<>();
@@ -205,8 +214,8 @@
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- switch (preference.getKey()) {
- case KEY_LOCK_SCREEN_PROFILE_NOTIFICATIONS: {
+ final String key = preference.getKey();
+ if (TextUtils.equals(mWorkSettingKey, key)) {
final int val = Integer.parseInt((String) newValue);
if (val == mLockscreenSelectedValueProfile) {
return false;
@@ -223,8 +232,7 @@
enabled ? 1 : 0, mProfileChallengeUserId);
mLockscreenSelectedValueProfile = val;
return true;
- }
- case KEY_LOCK_SCREEN_NOTIFICATIONS: {
+ } else if (TextUtils.equals(mSettingKey, key)) {
final int val = Integer.parseInt((String) newValue);
if (val == mLockscreenSelectedValue) {
return false;
@@ -238,10 +246,8 @@
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0);
mLockscreenSelectedValue = val;
return true;
- }
- default:
- return false;
}
+ return false;
}
private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
@@ -295,6 +301,7 @@
final boolean enabled = getLockscreenNotificationsEnabled(mProfileChallengeUserId);
final boolean allowPrivate = !mSecureProfile
|| getLockscreenAllowPrivateNotifications(mProfileChallengeUserId);
+ mLockscreenProfile.setSummary("%s");
mLockscreenSelectedValueProfile = !enabled
? R.string.lock_screen_notifications_summary_disable_profile
: (allowPrivate ? R.string.lock_screen_notifications_summary_show_profile
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index e055133..fe426e7 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -443,4 +443,12 @@
return lockscreenSecure;
}
+
+ protected boolean isChannelBlockable(boolean systemApp, NotificationChannel channel) {
+ if (!mAppRow.systemApp) {
+ return true;
+ }
+ return channel.isBlockableSystem()
+ || channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
+ }
}
diff --git a/src/com/android/settings/password/ChooseLockTypeDialogFragment.java b/src/com/android/settings/password/ChooseLockTypeDialogFragment.java
index 2581483..ba69e64 100644
--- a/src/com/android/settings/password/ChooseLockTypeDialogFragment.java
+++ b/src/com/android/settings/password/ChooseLockTypeDialogFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.password;
+import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.Fragment;
@@ -23,6 +24,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -31,6 +33,7 @@
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import java.util.List;
@@ -99,7 +102,9 @@
}
mAdapter = new ScreenLockAdapter(context, locks, mController);
builder.setAdapter(mAdapter, this);
- return builder.create();
+ builder.setTitle(R.string.setup_lock_settings_options_dialog_title);
+ AlertDialog alertDialog = builder.create();
+ return alertDialog;
}
@Override
@@ -115,18 +120,39 @@
Context context,
List<ScreenLockType> locks,
ChooseLockGenericController controller) {
- super(context, android.R.layout.simple_list_item_1, locks);
+ super(context, R.layout.choose_lock_dialog_item, locks);
mController = controller;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
+ Context context = parent.getContext();
if (view == null) {
- view = LayoutInflater.from(parent.getContext())
- .inflate(android.R.layout.simple_list_item_1, parent, false);
+ view = LayoutInflater.from(context)
+ .inflate(R.layout.choose_lock_dialog_item, parent, false);
}
- ((TextView) view).setText(mController.getTitle(getItem(position)));
+ ScreenLockType lock = getItem(position);
+ TextView textView = (TextView) view;
+ textView.setText(mController.getTitle(lock));
+ textView.setCompoundDrawablesRelativeWithIntrinsicBounds(
+ getIconForScreenLock(context, lock), null, null, null);
return view;
}
+
+ private static Drawable getIconForScreenLock(Context context, ScreenLockType lock) {
+ switch (lock) {
+ case PATTERN:
+ return context.getDrawable(R.drawable.ic_pattern);
+ case PIN:
+ return context.getDrawable(R.drawable.ic_pin);
+ case PASSWORD:
+ return context.getDrawable(R.drawable.ic_password);
+ case NONE:
+ case SWIPE:
+ case MANAGED:
+ default:
+ return null;
+ }
+ }
}
}
diff --git a/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java b/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
index ae2dd42..0c36dba 100644
--- a/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
+++ b/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
@@ -31,6 +31,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
+import android.content.pm.UserInfo;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
@@ -70,6 +71,10 @@
public static final String SHOW_WHEN_LOCKED =
PACKAGE + ".ConfirmCredentials.showWhenLocked";
+ protected static final int USER_TYPE_PRIMARY = 1;
+ protected static final int USER_TYPE_MANAGED_PROFILE = 2;
+ protected static final int USER_TYPE_SECONDARY = 3;
+
private FingerprintUiHelper mFingerprintHelper;
protected boolean mReturnCredentials = false;
protected Button mCancelButton;
@@ -78,6 +83,7 @@
protected int mUserId;
protected UserManager mUserManager;
protected LockPatternUtils mLockPatternUtils;
+ protected DevicePolicyManager mDevicePolicyManager;
protected TextView mErrorTextView;
protected final Handler mHandler = new Handler();
@@ -92,6 +98,8 @@
mUserManager = UserManager.get(getActivity());
mEffectiveUserId = mUserManager.getCredentialOwnerProfile(mUserId);
mLockPatternUtils = new LockPatternUtils(getActivity());
+ mDevicePolicyManager = (DevicePolicyManager) getActivity().getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
}
@Override
@@ -122,9 +130,8 @@
}
private boolean isFingerprintDisabledByAdmin() {
- DevicePolicyManager dpm = (DevicePolicyManager) getActivity().getSystemService(
- Context.DEVICE_POLICY_SERVICE);
- final int disabledFeatures = dpm.getKeyguardDisabledFeatures(null, mEffectiveUserId);
+ final int disabledFeatures =
+ mDevicePolicyManager.getKeyguardDisabledFeatures(null, mEffectiveUserId);
return (disabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0;
}
@@ -158,10 +165,7 @@
mFingerprintHelper.stopListening();
}
}
- if (isProfileChallenge()) {
- updateErrorMessage(mLockPatternUtils.getCurrentFailedPasswordAttempts(
- mEffectiveUserId));
- }
+ updateErrorMessage(mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
}
protected void setAccessibilityTitle(CharSequence supplementalText) {
@@ -245,9 +249,8 @@
mainContent.setPadding(0, 0, 0, 0);
}
- DevicePolicyManager dpm = (DevicePolicyManager) getActivity().getSystemService(
- Context.DEVICE_POLICY_SERVICE);
- baseView.setBackground(new ColorDrawable(dpm.getOrganizationColorForUser(userId)));
+ baseView.setBackground(
+ new ColorDrawable(mDevicePolicyManager.getOrganizationColorForUser(userId)));
ImageView imageView = (ImageView) baseView.findViewById(R.id.background_image);
if (imageView != null) {
Drawable image = getResources().getDrawable(R.drawable.work_challenge_background);
@@ -263,13 +266,9 @@
}
}
- protected boolean isProfileChallenge() {
- return mUserManager.isManagedProfile(mEffectiveUserId);
- }
-
- protected void reportSuccessfullAttempt() {
- if (isProfileChallenge()) {
- mLockPatternUtils.reportSuccessfulPasswordAttempt(mEffectiveUserId);
+ protected void reportSuccessfulAttempt() {
+ mLockPatternUtils.reportSuccessfulPasswordAttempt(mEffectiveUserId);
+ if (mUserManager.isManagedProfile(mEffectiveUserId)) {
// Keyguard is responsible to disable StrongAuth for primary user. Disable StrongAuth
// for work challenge only here.
mLockPatternUtils.userPresent(mEffectiveUserId);
@@ -277,40 +276,73 @@
}
protected void reportFailedAttempt() {
- if (isProfileChallenge()) {
- // + 1 for this attempt.
- updateErrorMessage(
- mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId) + 1);
- mLockPatternUtils.reportFailedPasswordAttempt(mEffectiveUserId);
- }
+ updateErrorMessage(
+ mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId) + 1);
+ mLockPatternUtils.reportFailedPasswordAttempt(mEffectiveUserId);
}
protected void updateErrorMessage(int numAttempts) {
final int maxAttempts =
mLockPatternUtils.getMaximumFailedPasswordsForWipe(mEffectiveUserId);
- if (maxAttempts > 0 && numAttempts > 0) {
- int remainingAttempts = maxAttempts - numAttempts;
- if (remainingAttempts == 1) {
- // Last try
- final String title = getActivity().getString(
- R.string.lock_profile_wipe_warning_title);
- LastTryDialog.show(getFragmentManager(), title, getLastTryErrorMessage(),
- android.R.string.ok, false /* dismiss */);
- } else if (remainingAttempts <= 0) {
- // Profile is wiped
- LastTryDialog.show(getFragmentManager(), null /* title */,
- R.string.lock_profile_wipe_content, R.string.lock_profile_wipe_dismiss,
- true /* dismiss */);
- }
- if (mErrorTextView != null) {
- final String message = getActivity().getString(R.string.lock_profile_wipe_attempts,
- numAttempts, maxAttempts);
- showError(message, 0);
- }
+ if (maxAttempts <= 0 || numAttempts <= 0) {
+ return;
+ }
+
+ // Update the on-screen error string
+ if (mErrorTextView != null) {
+ final String message = getActivity().getString(
+ R.string.lock_failed_attempts_before_wipe, numAttempts, maxAttempts);
+ showError(message, 0);
+ }
+
+ // Only show popup dialog before the last attempt and before wipe
+ final int remainingAttempts = maxAttempts - numAttempts;
+ if (remainingAttempts > 1) {
+ return;
+ }
+ final FragmentManager fragmentManager = getChildFragmentManager();
+ final int userType = getUserTypeForWipe();
+ if (remainingAttempts == 1) {
+ // Last try
+ final String title = getActivity().getString(
+ R.string.lock_last_attempt_before_wipe_warning_title);
+ final int messageId = getLastTryErrorMessage(userType);
+ LastTryDialog.show(fragmentManager, title, messageId,
+ android.R.string.ok, false /* dismiss */);
+ } else {
+ // Device, profile, or secondary user is wiped
+ final int messageId = getWipeMessage(userType);
+ LastTryDialog.show(fragmentManager, null /* title */, messageId,
+ R.string.lock_failed_attempts_now_wiping_dialog_dismiss, true /* dismiss */);
}
}
- protected abstract int getLastTryErrorMessage();
+ private int getUserTypeForWipe() {
+ final UserInfo userToBeWiped = mUserManager.getUserInfo(
+ mDevicePolicyManager.getProfileWithMinimumFailedPasswordsForWipe(mEffectiveUserId));
+ if (userToBeWiped == null || userToBeWiped.isPrimary()) {
+ return USER_TYPE_PRIMARY;
+ } else if (userToBeWiped.isManagedProfile()) {
+ return USER_TYPE_MANAGED_PROFILE;
+ } else {
+ return USER_TYPE_SECONDARY;
+ }
+ }
+
+ protected abstract int getLastTryErrorMessage(int userType);
+
+ private int getWipeMessage(int userType) {
+ switch (userType) {
+ case USER_TYPE_PRIMARY:
+ return R.string.lock_failed_attempts_now_wiping_device;
+ case USER_TYPE_MANAGED_PROFILE:
+ return R.string.lock_failed_attempts_now_wiping_profile;
+ case USER_TYPE_SECONDARY:
+ return R.string.lock_failed_attempts_now_wiping_user;
+ default:
+ throw new IllegalArgumentException("Unrecognized user type:" + userType);
+ }
+ }
private final Runnable mResetErrorRunnable = new Runnable() {
@Override
@@ -357,6 +389,7 @@
DialogFragment dialog = new LastTryDialog();
dialog.setArguments(args);
dialog.show(from, TAG);
+ from.executePendingTransactions();
return true;
}
diff --git a/src/com/android/settings/password/ConfirmLockPassword.java b/src/com/android/settings/password/ConfirmLockPassword.java
index ef11521..a91f572 100644
--- a/src/com/android/settings/password/ConfirmLockPassword.java
+++ b/src/com/android/settings/password/ConfirmLockPassword.java
@@ -211,9 +211,20 @@
}
@Override
- protected int getLastTryErrorMessage() {
- return mIsAlpha ? R.string.lock_profile_wipe_warning_content_password
- : R.string.lock_profile_wipe_warning_content_pin;
+ protected int getLastTryErrorMessage(int userType) {
+ switch (userType) {
+ case USER_TYPE_PRIMARY:
+ return mIsAlpha ? R.string.lock_last_password_attempt_before_wipe_device
+ : R.string.lock_last_pin_attempt_before_wipe_device;
+ case USER_TYPE_MANAGED_PROFILE:
+ return mIsAlpha ? R.string.lock_last_password_attempt_before_wipe_profile
+ : R.string.lock_last_pin_attempt_before_wipe_profile;
+ case USER_TYPE_SECONDARY:
+ return mIsAlpha ? R.string.lock_last_password_attempt_before_wipe_user
+ : R.string.lock_last_pin_attempt_before_wipe_user;
+ default:
+ throw new IllegalArgumentException("Unrecognized user type:" + userType);
+ }
}
@Override
@@ -278,10 +289,8 @@
} else {
resetState();
mErrorTextView.setText("");
- if (isProfileChallenge()) {
- updateErrorMessage(mLockPatternUtils.getCurrentFailedPasswordAttempts(
- mEffectiveUserId));
- }
+ updateErrorMessage(
+ mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
}
mCredentialCheckResultTracker.setListener(this);
}
@@ -444,7 +453,7 @@
mPasswordEntryInputDisabler.setInputEnabled(true);
if (matched) {
if (newResult) {
- reportSuccessfullAttempt();
+ reportSuccessfulAttempt();
}
startDisappearAnimation(intent);
checkForPendingIntent();
@@ -493,10 +502,8 @@
public void onFinish() {
resetState();
mErrorTextView.setText("");
- if (isProfileChallenge()) {
- updateErrorMessage(mLockPatternUtils.getCurrentFailedPasswordAttempts(
- mEffectiveUserId));
- }
+ updateErrorMessage(
+ mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
}
}.start();
}
diff --git a/src/com/android/settings/password/ConfirmLockPattern.java b/src/com/android/settings/password/ConfirmLockPattern.java
index b66edfe..c16b55a 100644
--- a/src/com/android/settings/password/ConfirmLockPattern.java
+++ b/src/com/android/settings/password/ConfirmLockPattern.java
@@ -299,10 +299,8 @@
mDetailsTextView.setText(getDefaultDetails());
}
mErrorTextView.setText("");
- if (isProfileChallenge()) {
- updateErrorMessage(mLockPatternUtils.getCurrentFailedPasswordAttempts(
- mEffectiveUserId));
- }
+ updateErrorMessage(
+ mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
mLockPatternView.setEnabled(true);
mLockPatternView.enableInput();
@@ -497,7 +495,7 @@
mLockPatternView.setEnabled(true);
if (matched) {
if (newResult) {
- reportSuccessfullAttempt();
+ reportSuccessfulAttempt();
}
startDisappearAnimation(intent);
checkForPendingIntent();
@@ -524,8 +522,17 @@
}
@Override
- protected int getLastTryErrorMessage() {
- return R.string.lock_profile_wipe_warning_content_pattern;
+ protected int getLastTryErrorMessage(int userType) {
+ switch (userType) {
+ case USER_TYPE_PRIMARY:
+ return R.string.lock_last_pattern_attempt_before_wipe_device;
+ case USER_TYPE_MANAGED_PROFILE:
+ return R.string.lock_last_pattern_attempt_before_wipe_profile;
+ case USER_TYPE_SECONDARY:
+ return R.string.lock_last_pattern_attempt_before_wipe_user;
+ default:
+ throw new IllegalArgumentException("Unrecognized user type:" + userType);
+ }
}
private void handleAttemptLockout(long elapsedRealtimeDeadline) {
diff --git a/src/com/android/settings/security/LockscreenDashboardFragment.java b/src/com/android/settings/security/LockscreenDashboardFragment.java
index f3b18f2..92142a9 100644
--- a/src/com/android/settings/security/LockscreenDashboardFragment.java
+++ b/src/com/android/settings/security/LockscreenDashboardFragment.java
@@ -18,6 +18,8 @@
import android.content.Context;
import android.provider.SearchIndexableResource;
+import android.support.annotation.VisibleForTesting;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
@@ -26,6 +28,7 @@
import com.android.settings.notification.LockScreenNotificationPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -38,6 +41,15 @@
private static final String TAG = "LockscreenDashboardFragment";
+ @VisibleForTesting
+ static final String KEY_LOCK_SCREEN_NOTIFICATON = "security_setting_lock_screen_notif";
+ @VisibleForTesting
+ static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER =
+ "security_setting_lock_screen_notif_work_header";
+ @VisibleForTesting
+ static final String KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE =
+ "security_setting_lock_screen_notif_work";
+
private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
@Override
@@ -60,7 +72,10 @@
final List<PreferenceController> controllers = new ArrayList<>();
final Lifecycle lifecycle = getLifecycle();
final LockScreenNotificationPreferenceController notificationController =
- new LockScreenNotificationPreferenceController(context);
+ new LockScreenNotificationPreferenceController(context,
+ KEY_LOCK_SCREEN_NOTIFICATON,
+ KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER,
+ KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
lifecycle.addObserver(notificationController);
controllers.add(notificationController);
final AddUserWhenLockedPreferenceController addUserWhenLockedController =
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index 70d3ce5..c9e0805 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -78,6 +78,7 @@
private Lifecycle mLifecycle;
private RecyclerView mRecyclerView;
private Drawable mIcon;
+ private String mIconContentDescription;
private CharSequence mLabel;
private CharSequence mSummary;
private String mPackageName;
@@ -122,6 +123,10 @@
return this;
}
+ /**
+ * Set the icon in the header. Callers should also consider calling setIconContentDescription
+ * to provide a description of this icon for accessibility purposes.
+ */
public EntityHeaderController setIcon(Drawable icon) {
if (icon != null) {
mIcon = icon.getConstantState().newDrawable(mAppContext.getResources());
@@ -129,6 +134,11 @@
return this;
}
+ /**
+ * Convenience method to set the header icon from an ApplicationsState.AppEntry. Callers should
+ * also consider calling setIconContentDescription to provide a description of this icon for
+ * accessibility purposes.
+ */
public EntityHeaderController setIcon(ApplicationsState.AppEntry appEntry) {
if (appEntry.icon != null) {
mIcon = appEntry.icon.getConstantState().newDrawable(mAppContext.getResources());
@@ -136,6 +146,11 @@
return this;
}
+ public EntityHeaderController setIconContentDescription(String contentDescription) {
+ mIconContentDescription = contentDescription;
+ return this;
+ }
+
public EntityHeaderController setLabel(CharSequence label) {
mLabel = label;
return this;
@@ -204,6 +219,7 @@
ImageView iconView = mHeader.findViewById(R.id.entity_header_icon);
if (iconView != null) {
iconView.setImageDrawable(mIcon);
+ iconView.setContentDescription(mIconContentDescription);
}
setText(R.id.entity_header_title, mLabel);
setText(R.id.entity_header_summary, mSummary);
diff --git a/tests/robotests/Android.mk b/tests/robotests/Android.mk
index b448433..ae0102f 100644
--- a/tests/robotests/Android.mk
+++ b/tests/robotests/Android.mk
@@ -8,7 +8,7 @@
# Include the testing libraries (JUnit4 + Robolectric libs).
LOCAL_STATIC_JAVA_LIBRARIES := \
- platform-system-robolectric \
+ mockito-robolectric-prebuilt \
truth-prebuilt
LOCAL_JAVA_LIBRARIES := \
diff --git a/tests/robotests/assets/whitelist_duplicate_index_key b/tests/robotests/assets/whitelist_duplicate_index_key
index 0b8d675..a761f35 100644
--- a/tests/robotests/assets/whitelist_duplicate_index_key
+++ b/tests/robotests/assets/whitelist_duplicate_index_key
@@ -1,6 +1,5 @@
add_users_when_locked
additional_system_update_settings
-screen_zoom
dashboard_tile_placeholder
-lock_screen_notifications
-usage_access
\ No newline at end of file
+screen_zoom
+usage_access
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index 65e9708..2250090 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -16,6 +16,16 @@
package com.android.settings;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+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;
+
import android.app.Activity;
import android.app.ActivityManager;
import android.app.FragmentManager;
@@ -23,10 +33,11 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
-
import android.os.Bundle;
import android.view.Menu;
+
import com.android.settings.testutils.FakeFeatureFactory;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -37,15 +48,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsActivityTest {
@@ -89,7 +91,7 @@
public void testSetTaskDescription_IconChanged() {
mActivity.setTaskDescription(mTaskDescription);
- verify(mTaskDescription).setIcon(any());
+ verify(mTaskDescription).setIcon(nullable(Bitmap.class));
}
@Test
@@ -99,8 +101,8 @@
mActivity.mDisplaySearch = true;
mActivity.onCreateOptionsMenu(null);
- verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(any(Menu.class),
- any(Activity.class));
+ verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(nullable(Menu.class),
+ nullable(Activity.class));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
new file mode 100644
index 0000000..cd48da3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SettingsPreferenceFragmentTest {
+
+ @Mock
+ private PreferenceManager mPreferenceManager;
+ private Context mContext;
+ private TestFragment mFragment;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mFragment = new TestFragment();
+ }
+
+ @Test
+ public void removePreference_nested_shouldRemove() {
+ final String key = "test_key";
+ final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
+ when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+
+ final PreferenceCategory nestedCategory = new ProgressCategory(mContext);
+ final Preference preference = new Preference(mContext);
+ preference.setKey(key);
+ preference.setPersistent(false);
+
+ mScreen.addPreference(nestedCategory);
+ nestedCategory.addPreference(preference);
+
+ assertThat(mFragment.removePreference(mScreen, key)).isTrue();
+ assertThat(nestedCategory.getPreferenceCount()).isEqualTo(0);
+ }
+
+ @Test
+ public void removePreference_flat_shouldRemove() {
+ final String key = "test_key";
+ final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
+ when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+
+ final Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(key);
+
+ mScreen.addPreference(preference);
+
+ assertThat(mFragment.removePreference(mScreen, key)).isTrue();
+ assertThat(mScreen.getPreferenceCount()).isEqualTo(0);
+ }
+
+ @Test
+ public void removePreference_doNotExist_shouldNotRemove() {
+ final String key = "test_key";
+ final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
+ when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+
+ final Preference preference = mock(Preference.class);
+ when(preference.getKey()).thenReturn(key);
+
+ mScreen.addPreference(preference);
+
+ assertThat(mFragment.removePreference(mScreen, "not" + key)).isFalse();
+ assertThat(mScreen.getPreferenceCount()).isEqualTo(1);
+ }
+
+ public static final class TestFragment extends SettingsPreferenceFragment {
+
+ @Override
+ public int getMetricsCategory() {
+ return 0;
+ }
+ }
+
+
+}
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
index f1ad142..79ea4da 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
@@ -20,6 +20,8 @@
import android.accounts.AuthenticatorDescription;
import android.content.Context;
import android.content.pm.UserInfo;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v7.preference.Preference;
@@ -36,6 +38,7 @@
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.testutils.shadow.ShadowAccountManager;
import com.android.settings.testutils.shadow.ShadowContentResolver;
+import com.android.settingslib.accounts.AuthenticatorHelper;
import org.junit.Before;
import org.junit.Test;
@@ -44,6 +47,8 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@@ -211,12 +216,12 @@
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
- preferenceGroup);
+ preferenceGroup);
mController.onResume();
verify(preferenceGroup).setTitle(
- mContext.getString(R.string.account_for_section_header, "user 1"));
+ mContext.getString(R.string.account_for_section_header, "user 1"));
}
@@ -309,7 +314,7 @@
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
when(mAccountHelper.hasBaseUserRestriction(
eq(UserManager.DISALLOW_REMOVE_MANAGED_PROFILE), anyInt()))
- .thenReturn(true);
+ .thenReturn(true);
mController.updateRawDataToIndex(data);
@@ -324,7 +329,7 @@
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
when(mAccountHelper.hasBaseUserRestriction(
- eq(UserManager.DISALLOW_MODIFY_ACCOUNTS), anyInt())).thenReturn(true);
+ eq(UserManager.DISALLOW_MODIFY_ACCOUNTS), anyInt())).thenReturn(true);
mController.updateRawDataToIndex(data);
@@ -346,18 +351,18 @@
accountType1[0] = new Account("Account11", "com.acct1");
accountType1[1] = new Account("Account12", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
- .thenReturn(accountType1);
+ .thenReturn(accountType1);
AuthenticatorDescription[] authDescs = {
- new AuthenticatorDescription("com.acct1", "com.android.settings",
- R.string.account_settings_title, 0, 0, 0, false)
+ new AuthenticatorDescription("com.acct1", "com.android.settings",
+ R.string.account_settings_title, 0, 0, 0, false)
};
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
- preferenceGroup);
+ preferenceGroup);
mController.onResume();
@@ -366,7 +371,8 @@
}
@Test
- @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
+ @Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class,
+ ShadowAuthenticatorHelper.class})
public void onResume_twoAccountsOfSameName_shouldAddFivePreferences() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
@@ -425,25 +431,25 @@
accountType1[0] = new Account("Acct11", "com.acct1");
accountType1[1] = new Account("Acct12", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
- .thenReturn(accountType1);
+ .thenReturn(accountType1);
AuthenticatorDescription[] authDescs = {
- new AuthenticatorDescription("com.acct1", "com.android.settings",
- R.string.account_settings_title, 0, 0, 0, false)
+ new AuthenticatorDescription("com.acct1", "com.android.settings",
+ R.string.account_settings_title, 0, 0, 0, false)
};
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
- preferenceGroup);
+ preferenceGroup);
mController.onResume();
mController.onResume();
// each account should be added only once
- verify(preferenceGroup).addPreference(argThat(new PreferenceMatcher("Acct11")));
- verify(preferenceGroup).addPreference(argThat(new PreferenceMatcher("Acct12")));
+ verify(preferenceGroup).addPreference(argThat(titleMatches("Acct11")));
+ verify(preferenceGroup).addPreference(argThat(titleMatches("Acct12")));
}
@Test
@@ -460,18 +466,18 @@
accountType1[0] = new Account("Acct11", "com.acct1");
accountType1[1] = new Account("Acct12", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
- .thenReturn(accountType1);
+ .thenReturn(accountType1);
AuthenticatorDescription[] authDescs = {
- new AuthenticatorDescription("com.acct1", "com.android.settings",
- R.string.account_settings_title, 0, 0, 0, false)
+ new AuthenticatorDescription("com.acct1", "com.android.settings",
+ R.string.account_settings_title, 0, 0, 0, false)
};
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
- preferenceGroup);
+ preferenceGroup);
mController.onResume();
@@ -481,14 +487,14 @@
accountType1[1] = new Account("Acct12", "com.acct1");
accountType1[2] = new Account("Acct13", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
- .thenReturn(accountType1);
+ .thenReturn(accountType1);
mController.onResume();
// each account should be added only once
- verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct11")));
- verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct12")));
- verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct13")));
+ verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
+ verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
+ verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct13")));
}
@Test
@@ -504,7 +510,7 @@
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
- preferenceGroup);
+ preferenceGroup);
// First time resume will build the UI with no account
mController.onResume();
@@ -513,18 +519,18 @@
Account[] accounts = {new Account("Acct1", "com.acct1")};
when(mAccountManager.getAccountsAsUser(2)).thenReturn(accounts);
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
- .thenReturn(accounts);
+ .thenReturn(accounts);
AuthenticatorDescription[] authDescs = {
- new AuthenticatorDescription("com.acct1", "com.android.settings",
- R.string.account_settings_title, 0, 0, 0, false)
+ new AuthenticatorDescription("com.acct1", "com.android.settings",
+ R.string.account_settings_title, 0, 0, 0, false)
};
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
// Resume should show the newly added account
mController.onResume();
- verify(preferenceGroup).addPreference(argThat(new PreferenceMatcher("Acct1")));
+ verify(preferenceGroup).addPreference(argThat(titleMatches("Acct1")));
}
@Test
@@ -542,18 +548,18 @@
accountType1[0] = new Account("Acct11", "com.acct1");
accountType1[1] = new Account("Acct12", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
- .thenReturn(accountType1);
+ .thenReturn(accountType1);
AuthenticatorDescription[] authDescs = {
- new AuthenticatorDescription("com.acct1", "com.android.settings",
- R.string.account_settings_title, 0, 0, 0, false)
+ new AuthenticatorDescription("com.acct1", "com.android.settings",
+ R.string.account_settings_title, 0, 0, 0, false)
};
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(
- preferenceGroup);
+ preferenceGroup);
mController.onResume();
@@ -561,29 +567,24 @@
accountType1 = new Account[1];
accountType1[0] = new Account("Acct11", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class)))
- .thenReturn(accountType1);
+ .thenReturn(accountType1);
mController.onResume();
- verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct11")));
- verify(preferenceGroup, times(1)).addPreference(argThat(new PreferenceMatcher("Acct12")));
- verify(preferenceGroup, times(1)).removePreference(
- argThat(new PreferenceMatcher("Acct12")));
+ verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
+ verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
+ verify(preferenceGroup, times(1)).removePreference(argThat(titleMatches("Acct12")));
}
- private static class PreferenceMatcher extends ArgumentMatcher<Preference> {
-
- private final String mExpectedTitle;
-
- public PreferenceMatcher(String title) {
- mExpectedTitle = title;
- }
-
- @Override
- public boolean matches(Object arg) {
- final Preference preference = (Preference) arg;
- return TextUtils.equals(mExpectedTitle, preference.getTitle());
- }
+ private static ArgumentMatcher<Preference> titleMatches(String expected) {
+ return preference -> TextUtils.equals(expected, preference.getTitle());
}
+ @Implements(AuthenticatorHelper.class)
+ public static class ShadowAuthenticatorHelper {
+ @Implementation
+ public Drawable getDrawableForType(Context context, final String accountType) {
+ return new ColorDrawable();
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
index 033465b..76c560c 100644
--- a/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
@@ -15,6 +15,16 @@
*/
package com.android.settings.accounts;
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.ArgumentMatchers.nullable;
+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.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
@@ -26,17 +36,14 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
-import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.PreferenceFragment;
+import android.support.v7.preference.PreferenceScreen;
import android.widget.Button;
-import com.android.settings.AccessiblePreferenceCategory;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.LayoutPreference;
-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;
@@ -48,16 +55,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
-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.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;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RemoveAccountPreferenceControllerTest {
@@ -134,7 +131,7 @@
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), eq(userHandle));
+ verify(mAccountManager).removeAccountAsUser(eq(account), nullable(Activity.class),
+ nullable(AccountManagerCallback.class), nullable(Handler.class), eq(userHandle));
}
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java b/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java
index ef6351a..409a600 100644
--- a/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/DrawOverlayDetailsTest.java
@@ -16,6 +16,10 @@
package com.android.settings.applications;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.nullable;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -35,10 +39,6 @@
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DrawOverlayDetailsTest {
@@ -66,11 +66,11 @@
public void logSpecialPermissionChange() {
mFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
mFragment.logSpecialPermissionChange(true, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_APPDRAW_ALLOW), eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_APPDRAW_DENY), eq("app"));
}
diff --git a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
index 36116c0..a69ee6c 100644
--- a/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/applications/FetchPackageStorageAsyncLoaderTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
@@ -63,7 +64,8 @@
when(stats.getCodeBytes()).thenReturn(1L);
when(stats.getDataBytes()).thenReturn(2L);
when(stats.getCacheBytes()).thenReturn(3L);
- when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class)))
+ when(mSource.getStatsForPackage(nullable(String.class), nullable(String.class),
+ any(UserHandle.class)))
.thenReturn(stats);
ApplicationInfo info = new ApplicationInfo();
info.packageName = PACKAGE_NAME;
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java
index 37fa9d7..159d693 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppCounterTest.java
@@ -16,13 +16,25 @@
package com.android.settings.applications;
+import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
-import android.os.Build;
import android.os.UserHandle;
import android.os.UserManager;
@@ -41,20 +53,9 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import java.util.Collections;
import java.util.Set;
-import static com.android.settings.testutils.ApplicationTestUtils.buildInfo;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
/**
* Tests for {@link InstalledAppCounter}.
*/
@@ -113,11 +114,12 @@
private void expectQueryIntentActivities(int userId, String packageName, boolean launchable) {
when(mPackageManager.queryIntentActivitiesAsUser(
- argThat(new IsLaunchIntentFor(packageName)),
+ argThat(isLaunchIntentFor(packageName)),
eq(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE),
- eq(userId))).thenReturn(launchable ? Arrays.asList(new ResolveInfo())
- : new ArrayList<ResolveInfo>());
+ eq(userId))).thenReturn(launchable
+ ? Collections.singletonList(new ResolveInfo())
+ : new ArrayList<>());
}
private void testCountInstalledAppsAcrossAllUsers(boolean async) {
@@ -136,7 +138,7 @@
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(), eq(MAIN_USER_ID));
verify(mPackageManager).getInstalledApplicationsAsUser(anyInt(),
eq(MANAGED_PROFILE_ID));
- verify(mPackageManager, atLeast(0)).queryIntentActivitiesAsUser(anyObject(), anyInt(),
+ verify(mPackageManager, atLeast(0)).queryIntentActivitiesAsUser(any(Intent.class), anyInt(),
anyInt());
verifyNoMoreInteractions(mPackageManager);
@@ -251,16 +253,8 @@
}
}
- private static class IsLaunchIntentFor extends ArgumentMatcher<Intent> {
- private final String mPackageName;
-
- IsLaunchIntentFor(String packageName) {
- mPackageName = packageName;
- }
-
- @Override
- public boolean matches(Object i) {
- final Intent intent = (Intent) i;
+ private ArgumentMatcher<Intent> isLaunchIntentFor(String packageName) {
+ return intent -> {
if (intent == null) {
return false;
}
@@ -272,10 +266,10 @@
!categories.contains(Intent.CATEGORY_LAUNCHER)) {
return false;
}
- if (!mPackageName.equals(intent.getPackage())) {
+ if (!packageName.equals(intent.getPackage())) {
return false;
}
return true;
- }
+ };
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index f602236..f57bfe3 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -19,10 +19,9 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -32,6 +31,7 @@
import static org.mockito.Mockito.when;
import android.app.AlertDialog;
+import android.app.Fragment;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
@@ -53,6 +53,7 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.instantapps.InstantAppButtonsController;
+import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.applications.AppUtils;
@@ -137,7 +138,7 @@
@Test
public void shouldShowUninstallForAll_installForOneOtherUserOnly_shouldReturnTrue() {
- when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
+ when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
when(mUserManager.getUsers().size()).thenReturn(2);
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
@@ -153,7 +154,7 @@
@Test
public void shouldShowUninstallForAll_installForSelfOnly_shouldReturnFalse() {
- when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
+ when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
when(mUserManager.getUsers().size()).thenReturn(2);
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
@@ -239,7 +240,7 @@
// Make this app appear to be instant.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (i -> true));
- when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
+ when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
when(mUserManager.getUsers().size()).thenReturn(2);
final ApplicationInfo info = new ApplicationInfo();
@@ -349,16 +350,18 @@
final InstantAppButtonsController buttonsController =
mock(InstantAppButtonsController.class);
- when(buttonsController.setPackageName(anyString())).thenReturn(buttonsController);
+ when(buttonsController.setPackageName(nullable(String.class)))
+ .thenReturn(buttonsController);
FakeFeatureFactory.setupForTest(mContext);
FakeFeatureFactory factory =
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
when(factory.applicationFeatureProvider.newInstantAppButtonsController(
- any(), any(), any())).thenReturn(buttonsController);
+ nullable(Fragment.class), nullable(View.class), nullable(ShowDialogDelegate.class)))
+ .thenReturn(buttonsController);
fragment.maybeAddInstantAppButtons();
- verify(buttonsController).setPackageName(anyString());
+ verify(buttonsController).setPackageName(nullable(String.class));
verify(buttonsController).show();
}
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppListerTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppListerTest.java
index 76421c2..6baa8c9 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppListerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppListerTest.java
@@ -87,11 +87,12 @@
private void expectQueryIntentActivities(int userId, String packageName, boolean launchable) {
when(mPackageManager.queryIntentActivitiesAsUser(
- argThat(new IsLaunchIntentFor(packageName)),
+ argThat(isLaunchIntentFor(packageName)),
eq(PackageManager.GET_DISABLED_COMPONENTS | PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE),
- eq(userId))).thenReturn(launchable ? Arrays.asList(new ResolveInfo())
- : new ArrayList<ResolveInfo>());
+ eq(userId))).thenReturn(launchable
+ ? Collections.singletonList(new ResolveInfo())
+ : Collections.emptyList());
}
@Test
@@ -203,16 +204,8 @@
}
}
- private static class IsLaunchIntentFor extends ArgumentMatcher<Intent> {
- private final String mPackageName;
-
- IsLaunchIntentFor(String packageName) {
- mPackageName = packageName;
- }
-
- @Override
- public boolean matches(Object i) {
- final Intent intent = (Intent) i;
+ private static ArgumentMatcher<Intent> isLaunchIntentFor(String packageName) {
+ return intent -> {
if (intent == null) {
return false;
}
@@ -224,10 +217,10 @@
!categories.contains(Intent.CATEGORY_LAUNCHER)) {
return false;
}
- if (!mPackageName.equals(intent.getPackage())) {
+ if (!packageName.equals(intent.getPackage())) {
return false;
}
return true;
- }
+ };
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
index 6440141..9143365 100644
--- a/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/MusicViewHolderControllerTest.java
@@ -18,7 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.nullable;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -32,8 +32,8 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settingslib.deviceinfo.StorageVolumeProvider;
import com.android.settingslib.applications.StorageStatsSource;
+import com.android.settingslib.deviceinfo.StorageVolumeProvider;
import org.junit.Before;
import org.junit.Test;
@@ -82,7 +82,7 @@
@Test
public void storageShouldRepresentStorageStatsQuery() throws Exception {
- when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
+ when(mSource.getExternalStorageStats(nullable(String.class), nullable(UserHandle.class))).thenReturn(
new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
mController.queryStats();
diff --git a/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java b/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
index 96a10f1..3c2589d 100644
--- a/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/PictureInPictureDetailsTest.java
@@ -16,6 +16,12 @@
package com.android.settings.applications;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -30,12 +36,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -83,11 +83,11 @@
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(true, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ALLOW), eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_DENY), eq("app"));
}
diff --git a/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java b/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java
index d9c88ff..6474e09 100644
--- a/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java
+++ b/tests/robotests/src/com/android/settings/applications/PremiumSmsAccessTest.java
@@ -16,6 +16,10 @@
package com.android.settings.applications;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -33,10 +37,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PremiumSmsAccessTest {
@@ -60,17 +60,17 @@
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ASK_USER,
"app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_ASK), eq("app"));
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_NEVER_ALLOW,
"app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_DENY), eq("app"));
mFragment.logSpecialPermissionChange(SmsUsageMonitor.PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW,
"app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_PREMIUM_SMS_ALWAYS_ALLOW),
eq("app"));
}
diff --git a/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java b/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
index 532a923..5b381fc 100644
--- a/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/UsageAccessDetailsTest.java
@@ -16,6 +16,10 @@
package com.android.settings.applications;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -32,10 +36,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UsageAccessDetailsTest {
@@ -58,11 +58,11 @@
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(true, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_USAGE_VIEW_ALLOW), eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_USAGE_VIEW_DENY), eq("app"));
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java b/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java
index 3abe3f4..f1655d5 100644
--- a/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/VrListenerSettingsTest.java
@@ -16,6 +16,10 @@
package com.android.settings.applications;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -31,10 +35,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class VrListenerSettingsTest {
@@ -56,11 +56,11 @@
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(true, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_VRHELPER_ALLOW), eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_VRHELPER_DENY), eq("app"));
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java b/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java
index a632118..3297dbf 100644
--- a/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/WriteSettingsDetailsTest.java
@@ -16,6 +16,10 @@
package com.android.settings.applications;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -31,10 +35,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class WriteSettingsDetailsTest {
@@ -56,12 +56,12 @@
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(true, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_SETTINGS_CHANGE_ALLOW),
eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_SETTINGS_CHANGE_DENY),
eq("app"));
}
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 3e24fcf..216026a 100644
--- a/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
+++ b/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
@@ -35,6 +35,8 @@
import org.robolectric.annotation.Config;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
+ .ACTION_SETTINGS_PREFERENCE_CHANGE;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
.FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
.FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE;
@@ -43,6 +45,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -56,7 +59,7 @@
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
- private PairMatcher mNamePairMatcher;
+ private ArgumentMatcher<Pair<Integer, Object>> mNamePairMatcher;
private FakeFeatureFactory mFactory;
private MetricsFeatureProvider mMetricsFeature;
private SharedPreferencesLogger mSharedPrefLogger;
@@ -69,7 +72,7 @@
mMetricsFeature = mFactory.metricsFeatureProvider;
mSharedPrefLogger = new SharedPreferencesLogger(mContext, TEST_TAG);
- mNamePairMatcher = new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, String.class);
+ mNamePairMatcher = pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, String.class);
}
@Test
@@ -83,11 +86,9 @@
editor.putInt(TEST_KEY, 2);
editor.putInt(TEST_KEY, 2);
- final PairMatcher longMatcher =
- new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class);
-
verify(mMetricsFeature, times(6)).action(any(Context.class), anyInt(),
- argThat(mNamePairMatcher), argThat(longMatcher));
+ argThat(mNamePairMatcher),
+ argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class)));
}
@Test
@@ -100,15 +101,12 @@
editor.putBoolean(TEST_KEY, false);
- final PairMatcher trueMatcher =
- new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, true);
- final PairMatcher falseMatcher =
- new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, false);
-
verify(mMetricsFeature).action(any(Context.class), anyInt(),
- argThat(mNamePairMatcher), argThat(trueMatcher));
+ argThat(mNamePairMatcher),
+ argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, true)));
verify(mMetricsFeature, times(3)).action(any(Context.class), anyInt(),
- argThat(mNamePairMatcher), argThat(falseMatcher));
+ argThat(mNamePairMatcher),
+ argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, false)));
}
@Test
@@ -120,11 +118,9 @@
editor.putLong(TEST_KEY, 1);
editor.putLong(TEST_KEY, 2);
- final PairMatcher longMatcher =
- new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class);
-
verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
- argThat(mNamePairMatcher), argThat(longMatcher));
+ argThat(mNamePairMatcher),
+ argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_LONG_VALUE, Long.class)));
}
@Test
@@ -136,40 +132,27 @@
editor.putFloat(TEST_KEY, 1);
editor.putFloat(TEST_KEY, 2);
- final PairMatcher floatMatcher =
- new PairMatcher(FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE, Float.class);
-
verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
- argThat(mNamePairMatcher), argThat(floatMatcher));
+ argThat(mNamePairMatcher),
+ argThat(pairMatches(FIELD_SETTINGS_PREFERENCE_CHANGE_FLOAT_VALUE, Float.class)));
}
- private static class PairMatcher extends ArgumentMatcher<Pair<Integer, Object>> {
+ @Test
+ public void logPackage_shouldUseLogPackageApi() {
+ mSharedPrefLogger.logPackageName("key", "com.android.settings");
+ verify(mMetricsFeature).action(any(Context.class),
+ eq(ACTION_SETTINGS_PREFERENCE_CHANGE),
+ eq("com.android.settings"),
+ any(Pair.class));
+ }
- private final int mExpectedTag;
- private final Class mExpectedClass;
- private final Long mExpectedBoolean;
+ private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag, Class clazz) {
+ return pair -> pair.first == tag && Platform.isInstanceOfType(pair.second, clazz);
+ }
-
- public PairMatcher(int tag, Class clazz) {
- mExpectedTag = tag;
- mExpectedClass = clazz;
- mExpectedBoolean = null;
- }
-
- public PairMatcher(int tag, boolean bool) {
- mExpectedTag = tag;
- mExpectedClass = Long.class;
- mExpectedBoolean = bool ? 1L : 0L;
- }
-
- @Override
- public boolean matches(Object arg) {
- final Pair<Integer, Object> pair = (Pair) arg;
- boolean booleanMatch = mExpectedBoolean == null
- || mExpectedBoolean == pair.second;
- return pair.first == mExpectedTag
- && Platform.isInstanceOfType(pair.second, mExpectedClass)
- && booleanMatch;
- }
+ private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag, boolean bool) {
+ return pair -> pair.first == tag
+ && Platform.isInstanceOfType(pair.second, Long.class)
+ && pair.second.equals((bool ? 1L : 0L));
}
}
diff --git a/tests/robotests/src/com/android/settings/core/instrumentation/VisibilityLoggerMixinTest.java b/tests/robotests/src/com/android/settings/core/instrumentation/VisibilityLoggerMixinTest.java
index 8a555a8..06b1d06 100644
--- a/tests/robotests/src/com/android/settings/core/instrumentation/VisibilityLoggerMixinTest.java
+++ b/tests/robotests/src/com/android/settings/core/instrumentation/VisibilityLoggerMixinTest.java
@@ -15,6 +15,17 @@
*/
package com.android.settings.core.instrumentation;
+import static com.android.settings.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
+
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.anyInt;
+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.Activity;
import android.content.Context;
import android.content.Intent;
@@ -31,16 +42,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
-import static com.android.settings.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
-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.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -62,7 +63,7 @@
mMixin.onResume();
verify(mMetricsFeature, times(1))
- .visible(any(Context.class), eq(MetricsProto.MetricsEvent.VIEW_UNKNOWN),
+ .visible(nullable(Context.class), eq(MetricsProto.MetricsEvent.VIEW_UNKNOWN),
eq(TestInstrumentable.TEST_METRIC));
}
@@ -77,7 +78,7 @@
mMixin.onResume();
verify(mMetricsFeature, times(1))
- .visible(any(Context.class), eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES),
+ .visible(nullable(Context.class), eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES),
eq(TestInstrumentable.TEST_METRIC));
}
@@ -86,7 +87,7 @@
mMixin.onPause();
verify(mMetricsFeature, times(1))
- .hidden(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
+ .hidden(nullable(Context.class), eq(TestInstrumentable.TEST_METRIC));
}
@Test
@@ -96,7 +97,7 @@
mMixin.onPause();
verify(mMetricsFeature, never())
- .hidden(any(Context.class), anyInt());
+ .hidden(nullable(Context.class), anyInt());
}
@Test
@@ -107,7 +108,7 @@
mMixin.onPause();
verify(mMetricsFeature, never())
- .hidden(any(Context.class), anyInt());
+ .hidden(nullable(Context.class), anyInt());
}
private final class TestInstrumentable implements Instrumentable {
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index e35fa33..c981d2d 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -15,6 +15,15 @@
*/
package com.android.settings.dashboard;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
import android.os.Bundle;
import android.support.v7.preference.Preference;
@@ -43,15 +52,6 @@
import java.util.ArrayList;
import java.util.List;
-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.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DashboardFragmentTest {
@@ -75,9 +75,10 @@
mDashboardCategory.tiles.add(new Tile());
mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
when(mFakeFeatureFactory.dashboardFeatureProvider.getProgressiveDisclosureMixin(
- any(Context.class), eq(mTestFragment), any(Bundle.class)))
+ nullable(Context.class), eq(mTestFragment), nullable(Bundle.class)))
.thenReturn(mDisclosureMixin);
- when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString()))
+ when(mFakeFeatureFactory.dashboardFeatureProvider
+ .getTilesForCategory(nullable(String.class)))
.thenReturn(mDashboardCategory);
mTestFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
when(mContext.getPackageName()).thenReturn("TestPackage");
@@ -96,21 +97,23 @@
@Test
public void displayTilesAsPreference_shouldAddTilesWithIntent() {
- when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString()))
+ when(mFakeFeatureFactory.dashboardFeatureProvider
+ .getTilesForCategory(nullable(String.class)))
.thenReturn(mDashboardCategory);
- when(mFakeFeatureFactory.dashboardFeatureProvider.getDashboardKeyForTile(any(Tile.class)))
+ when(mFakeFeatureFactory.dashboardFeatureProvider
+ .getDashboardKeyForTile(nullable(Tile.class)))
.thenReturn("test_key");
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
- verify(mDisclosureMixin).addPreference(any(PreferenceScreen.class),
- any(Preference.class));
+ verify(mDisclosureMixin).addPreference(nullable(PreferenceScreen.class),
+ nullable(Preference.class));
}
@Test
public void displayTilesAsPreference_shouldNotAddTilesWithoutIntent() {
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
- verify(mTestFragment.mScreen, never()).addPreference(any(Preference.class));
+ verify(mTestFragment.mScreen, never()).addPreference(nullable(Preference.class));
}
@Test
@@ -118,7 +121,7 @@
mDashboardCategory.tiles = null;
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
- verify(mTestFragment.mScreen, never()).addPreference(any(Preference.class));
+ verify(mTestFragment.mScreen, never()).addPreference(nullable(Preference.class));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java b/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java
index a3b9bf8..55c275b 100644
--- a/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/ProgressiveDisclosureTest.java
@@ -40,6 +40,8 @@
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -118,7 +120,7 @@
@Test
public void findPreference_prefInCollapsedList_shouldFindIt() {
- when(mScreen.findPreference(anyString())).thenReturn(null);
+ when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
mMixin.addToCollapsedList(mPreference);
Preference pref = mMixin.findPreference(mScreen, mPreference.getKey());
@@ -139,7 +141,7 @@
@Test
public void findPreference_prefNotInCollapsedListOrScreen_shouldNotFindIt() {
- when(mScreen.findPreference(anyString())).thenReturn(null);
+ when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
Preference pref = mMixin.findPreference(mScreen, mPreference.getKey());
assertThat(pref).isNull();
@@ -147,7 +149,7 @@
@Test
public void findPreference_prefRemovedFromCollapsedList_shouldNotFindIt() {
- when(mScreen.findPreference(anyString())).thenReturn(null);
+ when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
mMixin.addToCollapsedList(mPreference);
mMixin.removePreference(mPreferenceFragment.getPreferenceScreen(), mPreference.getKey());
@@ -158,7 +160,7 @@
@Test
public void findPreference_nestedPrefInCollapsedList_shouldFindIt() {
- when(mScreen.findPreference(anyString())).thenReturn(null);
+ when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
final PreferenceScreen prefGroup = spy(new PreferenceScreen(mAppContext, null));
when(prefGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
final Preference preference = mock(Preference.class);
@@ -183,7 +185,7 @@
@Test
public void removeLastPreference_shouldRemoveExpandButtonToo() {
- when(mScreen.findPreference(anyString())).thenReturn(null);
+ when(mScreen.findPreference(nullable(String.class))).thenReturn(null);
mMixin.addToCollapsedList(mPreference);
// Collapsed
assertThat(mMixin.isCollapsed()).isTrue();
@@ -204,7 +206,7 @@
mMixin.collapse(screen);
assertThat(mMixin.isCollapsed()).isFalse();
- verify(mExpandButton, never()).setSummary(anyString());
+ verify(mExpandButton, never()).setSummary(nullable(String.class));
verify(screen, never()).addPreference(any(Preference.class));
verify(screen, never()).removePreference(any(Preference.class));
}
@@ -219,7 +221,7 @@
mMixin.collapse(screen);
assertThat(mMixin.isCollapsed()).isTrue();
- verify(mExpandButton, atLeastOnce()).setSummary(anyString());
+ verify(mExpandButton, atLeastOnce()).setSummary(nullable(String.class));
verify(screen).addPreference(any(ExpandPreference.class));
verify(screen, times(3)).removePreference(any(Preference.class));
}
@@ -264,7 +266,7 @@
lastPref.setOrder(100);
// Add something to collapsed list so we are in collapsed state.
mMixin.addToCollapsedList(new Preference(mAppContext));
- verify(mExpandButton).setSummary(anyString());
+ verify(mExpandButton).setSummary(nullable(String.class));
assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(1);
// 3 prefs on screen, 2 are real and the last one is more button.
@@ -286,7 +288,7 @@
lastPref.setOrder(100);
// Add something to collapsed list so we are in collapsed state.
mMixin.addToCollapsedList(new Preference(mAppContext));
- verify(mExpandButton).setSummary(anyString());
+ verify(mExpandButton).setSummary(nullable(String.class));
assertThat(mMixin.getCollapsedPrefs().size()).isEqualTo(1);
// 3 prefs on screen, 2 are real and the last one is more button.
@@ -299,7 +301,7 @@
verify(mScreen, never()).removePreference(any(Preference.class));
verify(mScreen, never()).addPreference(any(Preference.class));
- verify(mExpandButton, times(2)).setSummary(anyString());
+ verify(mExpandButton, times(2)).setSummary(nullable(String.class));
assertThat(mMixin.getCollapsedPrefs().get(0)).isSameAs(toBeAdded);
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
index 4d9c1ec..92bc915 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionDismissControllerTest.java
@@ -16,6 +16,15 @@
package com.android.settings.dashboard.suggestions;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+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.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
@@ -35,14 +44,6 @@
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.Matchers.anyInt;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SuggestionDismissControllerTest {
@@ -110,7 +111,7 @@
mController.onSwiped(vh, ItemTouchHelper.START);
verify(mFactory.suggestionsFeatureProvider).dismissSuggestion(
- eq(mContext), eq(mSuggestionParser), any(Tile.class));
- verify(mCallback).onSuggestionDismissed(any(Tile.class));
+ eq(mContext), eq(mSuggestionParser), nullable(Tile.class));
+ verify(mCallback).onSuggestionDismissed(nullable(Tile.class));
}
}
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
index 8cbe947..a9b4d78 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
@@ -18,13 +18,16 @@
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
+import android.util.ArraySet;
import android.view.View;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.applications.PackageManagerWrapper;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
@@ -43,6 +46,8 @@
import org.robolectric.util.ReflectionHelpers;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -59,6 +64,8 @@
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private EntityHeaderController mHeaderController;
+ @Mock
+ private PackageManagerWrapper mPackageManagerWrapper;
private AppDataUsage mFragment;
@@ -77,6 +84,7 @@
public void bindAppHeader_allWorkApps_shouldNotShowAppInfoLink() {
ShadowEntityHeaderController.setUseMock(mHeaderController);
when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
+ when(mHeaderController.setUid(anyInt())).thenReturn(mHeaderController);
mFragment = spy(new AppDataUsage());
@@ -90,4 +98,38 @@
verify(mHeaderController).setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE);
}
+
+ @Test
+ public void bindAppHeader_workApp_shouldSetWorkAppUid() throws
+ PackageManager.NameNotFoundException {
+ final int fakeUserId = 100;
+
+ mFragment = spy(new AppDataUsage());
+ final ArraySet<String> packages = new ArraySet<>();
+ packages.add("pkg");
+ final AppItem appItem = new AppItem(123456789);
+
+ ReflectionHelpers.setField(mFragment, "mPackageManagerWrapper", mPackageManagerWrapper);
+ ReflectionHelpers.setField(mFragment, "mAppItem", appItem);
+ ReflectionHelpers.setField(mFragment, "mPackages", packages);
+
+ when(mPackageManagerWrapper.getPackageUidAsUser(anyString(), anyInt()))
+ .thenReturn(fakeUserId);
+
+ ShadowEntityHeaderController.setUseMock(mHeaderController);
+ when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
+ when(mHeaderController.setUid(fakeUserId)).thenReturn(mHeaderController);
+
+ doReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS))
+ .when(mFragment)
+ .getPreferenceManager();
+ doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
+
+ mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
+
+ verify(mHeaderController)
+ .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE);
+ verify(mHeaderController)
+ .setUid(fakeUserId);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java b/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java
index d674c77..899894b 100644
--- a/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessTest.java
@@ -15,14 +15,22 @@
*/
package com.android.settings.datausage;
-import com.android.internal.logging.nano.MetricsProto;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Process;
+
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.applications.ApplicationsState;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,11 +39,6 @@
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.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UnrestrictedDataAccessTest {
@@ -75,11 +78,11 @@
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(true, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_UNL_DATA_ALLOW), eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_UNL_DATA_DENY), eq("app"));
}
diff --git a/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java b/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java
index 4acac70..a964cb3 100644
--- a/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/ZonePickerTest.java
@@ -16,6 +16,11 @@
package com.android.settings.datetime;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -33,11 +38,6 @@
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 {
@@ -64,8 +64,8 @@
// Should render
verify(mZonePicker).onCreateView(
- any(LayoutInflater.class),
- any(ViewGroup.class),
- any(Bundle.class));
+ nullable(LayoutInflater.class),
+ nullable(ViewGroup.class),
+ nullable(Bundle.class));
}
}
diff --git a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
index be04eec..1bc859f 100644
--- a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
@@ -71,6 +71,7 @@
mSwitchBar = new SwitchBar(mContext);
Context fakeContextForFakeProvider = mock(Context.class, RETURNS_DEEP_STUBS);
+ FakeFeatureFactory.setupForTest(fakeContextForFakeProvider);
FeatureFactory featureFactory = FakeFeatureFactory.getFactory(fakeContextForFakeProvider);
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
mPreference = new Preference(mContext);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
index 17abab1..89328e4 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
@@ -17,6 +17,12 @@
package com.android.settings.deviceinfo;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.app.Activity;
import android.app.usage.StorageStatsManager;
import android.icu.text.NumberFormat;
@@ -41,12 +47,6 @@
import java.util.ArrayList;
import java.util.List;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-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 StorageSettingsTest {
@@ -78,10 +78,10 @@
when(volumeInfo.isMountedReadable()).thenReturn(true);
when(volumeInfo.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
when(mStorageManagerVolumeProvider.getTotalBytes(
- any(StorageStatsManager.class), any(VolumeInfo.class)))
+ nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
.thenReturn(500L);
when(mStorageManagerVolumeProvider.getFreeBytes(
- any(StorageStatsManager.class), any(VolumeInfo.class)))
+ nullable(StorageStatsManager.class), nullable(VolumeInfo.class)))
.thenReturn(0L);
ReflectionHelpers.setField(
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/UsbBackendTest.java b/tests/robotests/src/com/android/settings/deviceinfo/UsbBackendTest.java
index 8529c5d..af05c7f 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/UsbBackendTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/UsbBackendTest.java
@@ -16,8 +16,13 @@
package com.android.settings.deviceinfo;
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
-import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.hardware.usb.UsbManager;
@@ -27,17 +32,10 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
-import static org.mockito.Answers.RETURNS_DEEP_STUBS;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.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 UsbBackendTest {
@@ -70,13 +68,7 @@
usbBackend.getCurrentMode();
verify(mContext).registerReceiver(eq(null),
- argThat(new ArgumentMatcher<IntentFilter>() {
- @Override
- public boolean matches(Object i) {
- final IntentFilter intentFilter = (IntentFilter) i;
- return intentFilter != null &&
- UsbManager.ACTION_USB_STATE.equals(intentFilter.getAction(0));
- }
- }));
+ argThat(intentFilter -> intentFilter != null &&
+ UsbManager.ACTION_USB_STATE.equals(intentFilter.getAction(0))));
}
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index e8057a6..bdbe908 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -16,11 +16,12 @@
package com.android.settings.deviceinfo.storage;
-import static com.google.common.truth.Truth.assertThat;
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
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.spy;
@@ -28,7 +29,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
@@ -119,7 +119,7 @@
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
- any(UserHandle.class));
+ nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getType()).isEqualTo("image/*");
@@ -134,7 +134,7 @@
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
- any(UserHandle.class));
+ nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -161,7 +161,7 @@
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
- any(UserHandle.class));
+ nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -182,20 +182,20 @@
@Test
public void testClickFiles() {
- when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
+ when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
mPreference.setKey("pref_files");
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
- any(UserHandle.class));
+ nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
Intent browseIntent = mVolume.buildBrowseIntent();
assertThat(intent.getAction()).isEqualTo(browseIntent.getAction());
assertThat(intent.getData()).isEqualTo(browseIntent.getData());
verify(mMetricsFeatureProvider, times(1)).action(
- any(Context.class), eq(MetricsEvent.STORAGE_FILES));
+ nullable(Context.class), eq(MetricsEvent.STORAGE_FILES));
}
@Test
@@ -205,7 +205,7 @@
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
- any(UserHandle.class));
+ nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -223,7 +223,7 @@
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
- any(UserHandle.class));
+ nullable(UserHandle.class));
Intent intent = argumentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
@@ -240,7 +240,7 @@
assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
verify(mFragment.getFragmentManager().beginTransaction()).add(
- any(PrivateVolumeSettings.SystemInfoFragment.class), anyString());
+ nullable(PrivateVolumeSettings.SystemInfoFragment.class), nullable(String.class));
}
@Test
@@ -329,13 +329,13 @@
mController.setUserId(new UserHandle(10));
- verify(audio, times(2)).setIcon(any(Drawable.class));
- verify(video, times(2)).setIcon(any(Drawable.class));
- verify(image, times(2)).setIcon(any(Drawable.class));
- verify(games, times(2)).setIcon(any(Drawable.class));
- verify(apps, times(2)).setIcon(any(Drawable.class));
- verify(system, times(2)).setIcon(any(Drawable.class));
- verify(files, times(2)).setIcon(any(Drawable.class));
+ verify(audio, times(2)).setIcon(nullable(Drawable.class));
+ verify(video, times(2)).setIcon(nullable(Drawable.class));
+ verify(image, times(2)).setIcon(nullable(Drawable.class));
+ verify(games, times(2)).setIcon(nullable(Drawable.class));
+ verify(apps, times(2)).setIcon(nullable(Drawable.class));
+ verify(system, times(2)).setIcon(nullable(Drawable.class));
+ verify(files, times(2)).setIcon(nullable(Drawable.class));
}
@Test
@@ -359,7 +359,7 @@
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
.thenReturn(files);
- when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
+ when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(true);
mController.displayPreference(screen);
@@ -388,7 +388,7 @@
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
.thenReturn(files);
- when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
+ when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(false);
mController.displayPreference(screen);
@@ -417,7 +417,7 @@
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
.thenReturn(files);
- when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
+ when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(null);
mController.displayPreference(screen);
@@ -445,11 +445,11 @@
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
.thenReturn(files);
- when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
+ when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(true);
mController.displayPreference(screen);
- when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
+ when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(null);
mController.setVolume(mVolume);
verify(screen).removePreference(files);
@@ -480,7 +480,7 @@
// This will hide it initially.
mController.displayPreference(screen);
- when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
+ when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(true);
// And we bring it back.
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
index 34d9b24..862116f 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterpriseSetDefaultAppsPreferenceControllerTest.java
@@ -16,6 +16,14 @@
package com.android.settings.enterprise;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -43,13 +51,6 @@
import java.util.ArrayList;
import java.util.List;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.anyObject;
-import static org.mockito.Mockito.when;
-
/**
* Tests for {@link EnterpriseSetDefaultAppsPreferenceController}.
*/
@@ -81,7 +82,7 @@
final List<UserAppInfo> apps = new ArrayList<>(number);
apps.add(new UserAppInfo(new UserInfo(i, "user." + i, UserInfo.FLAG_ADMIN), appInfo));
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(eq(i),
- argThat(new MatchesIntents(intents)))).thenReturn(apps);
+ argThat(matchesIntents(intents)))).thenReturn(apps);
}
}
@@ -116,7 +117,7 @@
@Test
public void testIsAvailable() {
when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(anyInt(),
- anyObject())).thenReturn(new ArrayList<UserAppInfo>());
+ any(Intent[].class))).thenReturn(new ArrayList<>());
assertThat(mController.isAvailable()).isFalse();
setEnterpriseSetDefaultApps(EnterpriseDefaultApps.BROWSER.getIntents(), 1);
@@ -136,28 +137,20 @@
.isEqualTo("number_enterprise_set_default_apps");
}
- private static class MatchesIntents extends ArgumentMatcher<Intent[]> {
- private final Intent[] mExpectedIntents;
-
- MatchesIntents(Intent[] intents) {
- mExpectedIntents = intents;
- }
-
- @Override
- public boolean matches(Object object) {
- final Intent[] actualIntents = (Intent[]) object;
+ private ArgumentMatcher<Intent[]> matchesIntents(Intent[] intents) {
+ return (Intent[] actualIntents) -> {
if (actualIntents == null) {
return false;
}
- if (actualIntents.length != mExpectedIntents.length) {
+ if (actualIntents.length != intents.length) {
return false;
}
- for (int i = 0; i < mExpectedIntents.length; i++) {
- if (!mExpectedIntents[i].filterEquals(actualIntents[i])) {
+ for (int i = 0; i < intents.length; i++) {
+ if (!intents[i].filterEquals(actualIntents[i])) {
return false;
}
}
return true;
- }
+ };
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 40db72c..cb91d41 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -18,10 +18,9 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
@@ -30,6 +29,7 @@
import static org.mockito.Mockito.verify;
import android.app.Activity;
+import android.app.Fragment;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -61,7 +61,6 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -122,22 +121,26 @@
doReturn(mContext).when(mFragment).getContext();
doReturn(mActivity).when(mFragment).getActivity();
doReturn(SUMMARY).when(mFragment).getString(anyInt());
- doReturn(APP_LABEL).when(mBundle).getString(anyString());
+ doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
doReturn(mBundle).when(mFragment).getArguments();
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
doReturn(mEntityHeaderController).when(mEntityHeaderController)
- .setRecyclerView(any(RecyclerView.class), any(Lifecycle.class));
+ .setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController)
.setButtonActions(anyInt(), anyInt());
doReturn(mEntityHeaderController).when(mEntityHeaderController)
- .setIcon(any(Drawable.class));
- doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(any(
+ .setIcon(nullable(Drawable.class));
+ doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(
ApplicationsState.AppEntry.class));
- doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(anyString());
doReturn(mEntityHeaderController).when(mEntityHeaderController)
- .setLabel(any(ApplicationsState.AppEntry.class));
- doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(anyString());
+ .setLabel(nullable(String.class));
+ doReturn(mEntityHeaderController).when(mEntityHeaderController)
+ .setLabel(nullable(String.class));
+ doReturn(mEntityHeaderController).when(mEntityHeaderController)
+ .setLabel(nullable(ApplicationsState.AppEntry.class));
+ doReturn(mEntityHeaderController).when(mEntityHeaderController)
+ .setSummary(nullable(String.class));
doReturn(UID).when(mBatterySipper).getUid();
doReturn(APP_LABEL).when(mBatteryEntry).getLabel();
@@ -160,15 +163,13 @@
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
- Answer<Void> callable = new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) throws Exception {
- mBundle = captor.getValue();
- return null;
- }
+ Answer<Void> callable = invocation -> {
+ mBundle = captor.getValue();
+ return null;
};
- doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(any(), anyString(),
- captor.capture(), anyInt(), any(), any());
+ doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(
+ nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(),
+ nullable(CharSequence.class), nullable(UserHandle.class));
}
@After
@@ -181,7 +182,7 @@
mFragment.mAppEntry = null;
mFragment.initHeader();
- verify(mEntityHeaderController).setIcon(any(Drawable.class));
+ verify(mEntityHeaderController).setIcon(nullable(Drawable.class));
verify(mEntityHeaderController).setLabel(APP_LABEL);
}
@@ -281,21 +282,20 @@
mBatteryEntry, USAGE_PERCENT);
verify(mTestActivity).startPreferencePanelAsUser(
- any(), anyString(), any(), anyInt(), any(), eq(new UserHandle(10)));
+ nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
+ nullable(CharSequence.class), eq(new UserHandle(10)));
}
@Test
public void testStartBatteryDetailPage_noBatteryUsage_hasBasicData() {
final ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
- Answer<Void> callable = new Answer<Void>() {
- @Override
- public Void answer(InvocationOnMock invocation) throws Exception {
- mBundle = captor.getValue();
- return null;
- }
+ Answer<Void> callable = invocation -> {
+ mBundle = captor.getValue();
+ return null;
};
- doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(any(), anyString(),
- captor.capture(), anyInt(), any(), any());
+ doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(nullable(Fragment.class),
+ nullable(String.class), captor.capture(), anyInt(), nullable(CharSequence.class),
+ nullable(UserHandle.class));
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, PACKAGE_NAME[0]);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
index 2008afd..92df48e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AppButtonsPreferenceControllerTest.java
@@ -344,6 +344,14 @@
assertThat(controllable).isTrue();
}
+ @Test
+ public void testRefreshUi_packageNull_shouldNotCrash() {
+ mController.mPackageName = null;
+
+ // Should not crash in this method
+ assertThat(mController.refreshUi()).isFalse();
+ }
+
/**
* The test fragment which implements
* {@link ButtonActionDialogFragment.AppButtonsDialogListener}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
index 221408d..bd6ae6a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
@@ -15,8 +15,13 @@
*/
package com.android.settings.fuelgauge;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
-import android.os.PowerManager;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater;
import android.view.View;
@@ -35,16 +40,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
-
-import static org.mockito.AdditionalMatchers.not;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -84,7 +79,7 @@
mBatteryHistoryPreference.onBindViewHolder(mViewHolder);
verify(mViewHolder).findViewById(R.id.battery_usage);
- verify(mTextView).setText(anyString());
+ verify(mTextView).setText(nullable(String.class));
verify(mBatteryInfo).bindHistory(mUsageView);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
index b3afbb4..77e3198 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryOptimizationPreferenceControllerTest.java
@@ -18,10 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -84,9 +82,9 @@
final boolean handled = mController.handlePreferenceTreeClick(mPreference);
assertThat(handled).isTrue();
- verify(mSettingsActivity).startPreferencePanel(any(Fragment.class),
- anyString(), any(Bundle.class), anyInt(), any(CharSequence.class),
- any(Fragment.class), anyInt());
+ verify(mSettingsActivity).startPreferencePanel(nullable(Fragment.class),
+ nullable(String.class), nullable(Bundle.class), anyInt(),
+ nullable(CharSequence.class), nullable(Fragment.class), anyInt());
}
@Test
@@ -96,9 +94,9 @@
final boolean handled = mController.handlePreferenceTreeClick(mPreference);
assertThat(handled).isFalse();
- verify(mSettingsActivity, never()).startPreferencePanel(any(Fragment.class),
- anyString(), any(Bundle.class), anyInt(), any(CharSequence.class),
- any(Fragment.class), anyInt());
+ verify(mSettingsActivity, never()).startPreferencePanel(nullable(Fragment.class),
+ nullable(String.class), nullable(Bundle.class), anyInt(),
+ nullable(CharSequence.class), nullable(Fragment.class), anyInt());
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index 395d36d..45836ad 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -292,6 +292,19 @@
BatteryStats.STATS_SINCE_CHARGED)).isEqualTo(TIME_SINCE_LAST_FULL_CHARGE_MS);
}
+ @Test
+ public void testSortUsageList() {
+ final List<BatterySipper> sippers = new ArrayList<>();
+ sippers.add(mNormalBatterySipper);
+ sippers.add(mScreenBatterySipper);
+ sippers.add(mSystemBatterySipper);
+
+ mBatteryUtils.sortUsageList(sippers);
+
+ assertThat(sippers).containsExactly(mNormalBatterySipper, mSystemBatterySipper,
+ mScreenBatterySipper);
+ }
+
private BatterySipper createTestSmearBatterySipper(long activityTime, double totalPowerMah,
int uidCode, boolean isUidNull) {
final BatterySipper sipper = mock(BatterySipper.class);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index f32ea7a..8e9febe 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -125,4 +125,14 @@
assertThat(mPowerFeatureProvider.isTypeSystem(mBatterySipper)).isFalse();
}
+
+ @Test
+ public void testIsAdvancedUiEnabled_returnTrue() {
+ assertThat(mPowerFeatureProvider.isAdvancedUiEnabled()).isTrue();
+ }
+
+ @Test
+ public void testIsPowerAccountingToggleEnabled_returnTrue() {
+ assertThat(mPowerFeatureProvider.isPowerAccountingToggleEnabled()).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
index b5a4def..b0b0b99 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/anomaly/checker/WakeLockAnomalyDetectorTest.java
@@ -18,10 +18,9 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -101,9 +100,10 @@
mContext = spy(RuntimeEnvironment.application);
ReflectionHelpers.setField(mPolicy, "wakeLockThreshold", WAKELOCK_THRESHOLD_MS);
- doReturn(false).when(mBatteryUtils).shouldHideSipper(any());
+ doReturn(false).when(mBatteryUtils).shouldHideSipper(nullable(BatterySipper.class));
doReturn(mPackageManager).when(mContext).getPackageManager();
- doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(anyString(), anyInt());
+ doReturn(mApplicationInfo).when(mPackageManager)
+ .getApplicationInfo(nullable(String.class), anyInt());
mAnomalySipper.uidObj = mAnomalyUid;
mAnomalyWakelocks = new ArrayMap<>();
diff --git a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
index f87f18b..d6b133b 100644
--- a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
@@ -15,6 +15,13 @@
*/
package com.android.settings.location;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -37,13 +44,6 @@
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.Matchers.anyString;
-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 LocationPreferenceControllerTest {
@@ -75,7 +75,7 @@
public void updateState_shouldSetSummary() {
mController.updateState(mPreference);
- verify(mPreference).setSummary(anyString());
+ verify(mPreference).setSummary(nullable(String.class));
}
@Test
@@ -83,7 +83,7 @@
mController.displayPreference(mScreen);
mController.updateSummary();
- verify(mPreference).setSummary(anyString());
+ verify(mPreference).setSummary(nullable(String.class));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
index e7f4968..358f12f 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
@@ -39,6 +39,8 @@
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -85,7 +87,7 @@
mFragment.onCreateOptionsMenu(null, null);
- verify(resetController).buildMenuItem(any(Menu.class));
+ verify(resetController).buildMenuItem(nullable(Menu.class));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index 7e92bc5..cecc910 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -20,7 +20,10 @@
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
+import android.content.ContentResolver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.provider.Settings;
@@ -41,6 +44,7 @@
import java.util.concurrent.atomic.AtomicReference;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -150,4 +154,36 @@
verify(mPreference).setSummary(R.string.switch_off_text);
}
+ @Test
+ public void onResume_shouldRegisterTetherReceiver() {
+ when(mContext.getContentResolver()).thenReturn(mock(ContentResolver.class));
+
+ mController.onResume();
+
+ verify(mContext).registerReceiver(
+ any(TetherPreferenceController.TetherBroadcastReceiver.class), any(IntentFilter.class));
+ }
+
+ @Test
+ public void onPause_shouldUnregisterTetherReceiver() {
+ when(mContext.getContentResolver()).thenReturn(mock(ContentResolver.class));
+ mController.onResume();
+
+ mController.onPause();
+
+ verify(mContext).unregisterReceiver(
+ any(TetherPreferenceController.TetherBroadcastReceiver.class));
+ }
+
+ @Test
+ public void tetherStatesChanged_shouldUpdateSummary() {
+ final Context context = RuntimeEnvironment.application;
+ ReflectionHelpers.setField(mController, "mContext", context);
+ mController.onResume();
+
+ context.sendBroadcast(new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
+
+ verify(mController).updateSummary();
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
index b0aa856..756f1d0 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
@@ -16,6 +16,10 @@
package com.android.settings.notification;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto;
@@ -31,10 +35,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationAccessSettingsTest {
@@ -56,12 +56,12 @@
@Test
public void logSpecialPermissionChange() {
mFragment.logSpecialPermissionChange(true, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_NOTIVIEW_ALLOW),
eq("app"));
mFragment.logSpecialPermissionChange(false, "app");
- verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
+ verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_NOTIVIEW_DENY),
eq("app"));
}
diff --git a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
index 581ed47..657739f 100644
--- a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
@@ -16,8 +16,14 @@
package com.android.settings.notification;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
-import android.preference.SeekBarVolumizer;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -31,13 +37,6 @@
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.Matchers.anyString;
-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 VolumeSeekBarPreferenceControllerTest {
@@ -56,7 +55,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- when(mScreen.findPreference(anyString())).thenReturn(mPreference);
+ when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
mController =
new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback);
}
diff --git a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
index 520e1f0..44aaf04 100644
--- a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
@@ -16,6 +16,16 @@
package com.android.settings.notification;
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
@@ -38,16 +48,6 @@
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.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.times;
-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 WorkSoundPreferenceControllerTest {
@@ -94,9 +94,9 @@
@Test
public void isAvailable_managedProfileAndNotSingleVolume_shouldReturnTrue() {
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
assertThat(mController.isAvailable()).isTrue();
@@ -104,9 +104,9 @@
@Test
public void isAvailable_noManagedProfile_shouldReturnFalse() {
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
@@ -114,9 +114,9 @@
@Test
public void isAvailable_singleVolume_shouldReturnFalse() {
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(true);
assertThat(mController.isAvailable()).isFalse();
@@ -128,7 +128,7 @@
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
// When the fragment first displays, the category should not appear.
@@ -137,7 +137,7 @@
// However, when a managed profile is added later, the category should appear.
mController.onResume();
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
mController.onManagedProfileAdded(UserHandle.myUserId());
@@ -150,9 +150,9 @@
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
// Which is in resumed state:
mController.displayPreference(mScreen);
@@ -161,7 +161,7 @@
verify(mWorkCategory, times(2)).setVisible(true);
// When a managed profile is removed, the category should be hidden.
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
mController.onManagedProfileRemoved(UserHandle.myUserId());
@@ -171,9 +171,9 @@
@Test
public void displayPreference_isAvailable_shouldShowPreferenceCategory() {
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
@@ -184,7 +184,7 @@
@Test
public void displayPreference_notAvailable_shouldHidePreferenceCategory() {
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.USER_NULL);
when(mAudioHelper.isSingleVolume()).thenReturn(true);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
@@ -200,7 +200,7 @@
mController.onPreferenceChange(preference, "hello");
- verify(preference).setSummary(anyString());
+ verify(preference).setSummary(nullable(String.class));
}
@Test
@@ -208,9 +208,9 @@
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
mController = new WorkSoundPreferenceController(mContext, mFragment, null, mAudioHelper);
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
@@ -234,9 +234,9 @@
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(UserHandle.myUserId());
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(false);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(false);
// When resumed:
mController.displayPreference(mScreen);
@@ -256,9 +256,9 @@
@Test
public void onResume_shouldSetUserIdToPreference() {
final int managedProfileUserId = 10;
- when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+ when(mAudioHelper.getManagedProfileId(nullable(UserManager.class)))
.thenReturn(managedProfileUserId);
- when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+ when(mAudioHelper.isUserUnlocked(nullable(UserManager.class), anyInt())).thenReturn(true);
when(mAudioHelper.isSingleVolume()).thenReturn(false);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
index 589e2df..198273b 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
@@ -209,7 +210,8 @@
@Test
public void upgradeQuality_noDpmRequirement_shouldReturnQuality() {
doReturn(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED)
- .when(mDevicePolicyManager).getPasswordQuality(any(ComponentName.class), anyInt());
+ .when(mDevicePolicyManager)
+ .getPasswordQuality(nullable(ComponentName.class), anyInt());
int upgradedQuality = mController.upgradeQuality(
DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC);
@@ -220,7 +222,8 @@
@Test
public void upgradeQuality_dpmRequirement_shouldReturnRequiredQuality() {
doReturn(DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC)
- .when(mDevicePolicyManager).getPasswordQuality(any(ComponentName.class), anyInt());
+ .when(mDevicePolicyManager)
+ .getPasswordQuality(nullable(ComponentName.class), anyInt());
int upgradedQuality = mController.upgradeQuality(
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
index 6927be7..967864d 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
@@ -17,6 +17,10 @@
package com.android.settings.search;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
@@ -36,10 +40,6 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import static org.mockito.Matchers.any;
-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 SavedQueryViewHolderTest {
@@ -71,7 +71,7 @@
mTitleView.performClick();
mRemoveButton.performClick();
- verify(mSearchFragment).onSavedQueryClicked(any(CharSequence.class));
- verify(mSearchFragment).onRemoveSavedQueryClicked(any(CharSequence.class));
+ verify(mSearchFragment).onSavedQueryClicked(nullable(CharSequence.class));
+ verify(mSearchFragment).onRemoveSavedQueryClicked(nullable(CharSequence.class));
}
}
diff --git a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
new file mode 100644
index 0000000..c6a0e53
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.security;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.XmlTestUtils;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LockscreenDashboardFragmentTest {
+
+ private LockscreenDashboardFragment mFragment;
+
+ @Test
+ public void containsNotificationSettingsForPrimaryUserAndWorkProfile() {
+ mFragment = new LockscreenDashboardFragment();
+
+ List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(RuntimeEnvironment.application,
+ mFragment.getPreferenceScreenResId());
+
+ assertThat(keys).containsAllOf(LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON,
+ LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE,
+ LockscreenDashboardFragment.KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE_HEADER);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index e386282..c29068f 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -234,6 +234,33 @@
}
@Test
+ public void iconContentDescription_shouldWorkWithSetIcon() {
+ final View view = mLayoutInflater
+ .inflate(R.layout.settings_entity_header, null /* root */);
+ when(mFragment.getActivity()).thenReturn(mock(Activity.class));
+ mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
+ String description = "Fake Description";
+ mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
+ mController.setIconContentDescription(description);
+ mController.done(mActivity);
+ assertThat(view.findViewById(R.id.entity_header_icon).getContentDescription().toString())
+ .isEqualTo(description);
+ }
+
+ @Test
+ public void iconContentDescription_shouldWorkWithoutSetIcon() {
+ final View view = mLayoutInflater
+ .inflate(R.layout.settings_entity_header, null /* root */);
+ when(mFragment.getActivity()).thenReturn(mock(Activity.class));
+ mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
+ String description = "Fake Description";
+ mController.setIconContentDescription(description);
+ mController.done(mActivity);
+ assertThat(view.findViewById(R.id.entity_header_icon).getContentDescription().toString())
+ .isEqualTo(description);
+ }
+
+ @Test
public void bindButton_hasAppNotifIntent_shouldShowButton() {
final View appLinks = mLayoutInflater
.inflate(R.layout.settings_entity_header, null /* root */);
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index 9601c49..0b374d5 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -17,6 +17,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.inOrder;
@@ -158,7 +159,7 @@
when(mockConnectivityManager.getNetworkInfo(any(Network.class)))
.thenReturn(mockNetworkInfo);
doNothing().when(mockConnectivityManagerWrapper).registerNetworkCallback(
- any(NetworkRequest.class), mCallbackCaptor.capture(), any(Handler.class));
+ nullable(NetworkRequest.class), mCallbackCaptor.capture(), nullable(Handler.class));
doNothing().when(mockForgetButton).setOnClickListener(mForgetClickListener.capture());
when(mockWifiInfo.getLinkSpeed()).thenReturn(LINK_SPEED);
@@ -254,7 +255,7 @@
mController.onResume();
verify(mockConnectivityManagerWrapper, times(1)).registerNetworkCallback(
- any(NetworkRequest.class), mCallbackCaptor.capture(), any(Handler.class));
+ nullable(NetworkRequest.class), mCallbackCaptor.capture(), nullable(Handler.class));
}
@Test