Merge "Delete deprecated controller"
diff --git a/res/layout/settings_main_dashboard.xml b/res/layout/settings_main_dashboard.xml
index 269bc3c..4f8c308 100644
--- a/res/layout/settings_main_dashboard.xml
+++ b/res/layout/settings_main_dashboard.xml
@@ -17,7 +17,8 @@
*/
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -43,13 +44,18 @@
android:contentInsetStartWithNavigation="64dp"
android:navigationIcon="@drawable/ic_search_24dp"
android:navigationContentDescription="@string/search_menu"
- android:title="@string/search_menu"
- android:titleTextAppearance="@style/TextAppearance.SearchBar"
- android:theme="?android:attr/actionBarTheme"/>
+ android:theme="?android:attr/actionBarTheme">
+ <TextView
+ android:id="@+id/search_action_bar_title"
+ style="@style/TextAppearance.SearchBar"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/search_menu" />
+ </Toolbar>
</android.support.v7.widget.CardView>
</FrameLayout>
<FrameLayout
android:id="@+id/main_content"
android:layout_height="match_parent"
- android:layout_width="match_parent"/>
+ android:layout_width="match_parent" />
</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3fb50e5..40152f7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -398,6 +398,12 @@
<string name="connected_device_connected_title">Currently connected</string>
<!-- Title for connected device group [CHAR LIMIT=none]-->
<string name="connected_device_saved_title">Saved devices</string>
+ <!-- Title for preference to add a device [CHAR LIMIT=none]-->
+ <string name="connected_device_add_device_title">Add device</string>
+ <!-- Summary for preference to add a device [CHAR LIMIT=none]-->
+ <string name="connected_device_add_device_summary">Bluetooth will turn on to enable pairing</string>
+ <!-- Title for other connection preferences [CHAR LIMIT=none]-->
+ <string name="connected_device_connections_title">Connection preferences</string>
<!-- Date & time settings screen title -->
<string name="date_and_time">Date & time</string>
diff --git a/res/xml/app_info_settings.xml b/res/xml/app_info_settings.xml
new file mode 100644
index 0000000..e2fb2e4
--- /dev/null
+++ b/res/xml/app_info_settings.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:key="installed_app_detail_settings_screen"
+ app:initialExpandedChildrenCount="6">
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="header_view"
+ android:layout="@layout/settings_entity_header"
+ android:selectable="false"
+ android:order="-10000"/>
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="instant_app_buttons"
+ android:layout="@layout/instant_app_buttons"
+ android:selectable="false"
+ android:order="-9999"/>
+
+ <com.android.settings.widget.ActionButtonPreference
+ android:key="action_buttons"
+ android:order="-9998" />
+
+ <Preference
+ android:key="notification_settings"
+ android:title="@string/notifications_label"/>
+
+ <com.android.settings.widget.FixedLineSummaryPreference
+ android:key="permission_settings"
+ android:title="@string/permissions_label"
+ android:summary="@string/summary_placeholder"
+ app:summaryLineCount="1" />
+
+ <Preference
+ android:key="storage_settings"
+ android:title="@string/storage_settings"
+ android:summary="@string/summary_placeholder"/>
+
+ <com.android.settings.applications.AppDomainsPreference
+ android:key="instant_app_launch_supported_domain_urls"
+ android:title="@string/app_launch_supported_domain_urls_title"
+ android:selectable="true" />
+
+ <Preference
+ android:key="data_settings"
+ android:title="@string/data_usage_summary_title"
+ android:summary="@string/summary_placeholder"/>
+
+ <Preference
+ android:key="battery"
+ android:title="@string/power_usage_summary_title"
+ android:summary="@string/summary_placeholder"/>
+
+ <Preference
+ android:key="preferred_settings"
+ android:title="@string/launch_by_default"
+ android:summary="@string/summary_placeholder"
+ android:selectable="true"/>
+
+ <Preference
+ android:key="memory"
+ android:title="@string/memory_settings_title"
+ android:summary="@string/summary_placeholder"
+ android:enabled="false"/>
+
+ <!-- Default apps shortcuts -->
+ <Preference
+ android:key="default_home"
+ android:title="@string/home_app"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="default_browser"
+ android:title="@string/default_browser_title"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="default_phone_app"
+ android:title="@string/default_phone_title"
+ android:summary="@string/default_phone_title" />
+
+ <Preference
+ android:key="default_emergency_app"
+ android:title="@string/default_emergency_app"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="default_sms_app"
+ android:title="@string/sms_application_title"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="app_version"
+ android:selectable="false"
+ android:order="9999"/>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index 497a485..5417051 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -16,6 +16,7 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="connected_devices_screen"
android:title="@string/connected_devices_dashboard_title">
@@ -26,4 +27,17 @@
<PreferenceCategory
android:key="saved_device_list"
android:title="@string/connected_device_saved_title"/>
+
+ <Preference
+ android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
+ android:key="add_bt_devices"
+ android:title="@string/connected_device_add_device_title"
+ android:icon="@drawable/ic_menu_add"
+ android:summary="@string/connected_device_add_device_summary"
+ settings:allowDividerAbove="true"/>
+
+ <Preference
+ android:key="connection_preferences"
+ android:title="@string/connected_device_connections_title"
+ settings:allowDividerAbove="true"/>
</PreferenceScreen>
diff --git a/res/xml/night_display_settings.xml b/res/xml/night_display_settings.xml
index dc4fecd..8f2bb97 100644
--- a/res/xml/night_display_settings.xml
+++ b/res/xml/night_display_settings.xml
@@ -16,7 +16,8 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/night_display_title">
+ android:title="@string/night_display_title"
+ android:key="night_display_title">
<DropDownPreference
android:key="night_display_auto_mode"
diff --git a/res/xml/notification_settings.xml b/res/xml/notification_settings.xml
index 85952e9..144bef6 100644
--- a/res/xml/notification_settings.xml
+++ b/res/xml/notification_settings.xml
@@ -15,6 +15,7 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto">
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="@string/app_notifications_title">
</PreferenceScreen>
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 82bef4d..dbd1d42 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -33,7 +33,8 @@
<!-- Turn on DND button -->
<!-- Layout preference doesn't obey allowDividerAbove, so put it in a PreferenceCategory -->
- <PreferenceCategory>
+ <PreferenceCategory
+ android:key="zen_mode_settings_button_category">
<com.android.settings.applications.LayoutPreference
android:key="zen_mode_settings_button_container"
android:selectable="false"
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index c791775..a5f7c45 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -76,7 +76,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_about;
}
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index d67758a..e726c63 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -56,6 +56,8 @@
private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
private static final String KEY_AMBIENT_DISPLAY = "ambient_display";
+ private static final String KEY_NIGHT_DISPLAY = "night_display";
+
@Override
public int getMetricsCategory() {
return MetricsEvent.DISPLAY;
@@ -77,7 +79,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_display;
}
@@ -126,6 +128,7 @@
keys.add(KEY_DISPLAY_SIZE);
keys.add(WallpaperPreferenceController.KEY_WALLPAPER);
keys.add(KEY_AMBIENT_DISPLAY);
+ keys.add(KEY_NIGHT_DISPLAY);
return keys;
}
diff --git a/src/com/android/settings/IccLockSettings.java b/src/com/android/settings/IccLockSettings.java
index 0517b13..b9f3b10 100644
--- a/src/com/android/settings/IccLockSettings.java
+++ b/src/com/android/settings/IccLockSettings.java
@@ -295,7 +295,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_icc_lock;
}
diff --git a/src/com/android/settings/PrivacySettings.java b/src/com/android/settings/PrivacySettings.java
index e547570..24774e0 100644
--- a/src/com/android/settings/PrivacySettings.java
+++ b/src/com/android/settings/PrivacySettings.java
@@ -220,7 +220,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_backup_reset;
}
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 193c2b3..dc961be 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -340,6 +340,7 @@
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
+ actionBar.setDisplayShowTitleEnabled(!mIsShowingDashboard);
}
mSwitchBar = findViewById(R.id.switch_bar);
if (mSwitchBar != null) {
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 5d3bf00..d9e264b 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -39,8 +39,6 @@
import android.util.ArrayMap;
import android.util.Log;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@@ -49,10 +47,12 @@
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.instrumentation.Instrumentable;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.search.actionbar.SearchMenuController;
+import com.android.settings.support.actionbar.HelpMenuController;
+import com.android.settings.support.actionbar.HelpResourceProvider;
import com.android.settings.widget.LoadingViewController;
import com.android.settingslib.CustomDialogPreference;
import com.android.settingslib.CustomEditTextPreference;
-import com.android.settingslib.HelpUtils;
import com.android.settingslib.widget.FooterPreferenceMixin;
import java.util.UUID;
@@ -61,13 +61,7 @@
* Base class for Settings fragments, with some helper functions and dialog management.
*/
public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceFragment
- implements DialogCreatable {
-
- /**
- * The Help Uri Resource key. This can be passed as an extra argument when creating the
- * Fragment.
- **/
- public static final String HELP_URI_RESOURCE_KEY = "help_uri_resource";
+ implements DialogCreatable, HelpResourceProvider {
private static final String TAG = "SettingsPreference";
@@ -79,13 +73,11 @@
protected final FooterPreferenceMixin mFooterPreferenceMixin =
new FooterPreferenceMixin(this, getLifecycle());
- private SettingsDialogFragment mDialogFragment;
-
- private String mHelpUri;
private static final int ORDER_FIRST = -1;
private static final int ORDER_LAST = Integer.MAX_VALUE -1;
+ private SettingsDialogFragment mDialogFragment;
// Cache the content resolver for async callbacks
private ContentResolver mContentResolver;
@@ -144,22 +136,13 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ SearchMenuController.init(this /* host */);
+ HelpMenuController.init(this /* host */);
if (icicle != null) {
mPreferenceHighlighted = icicle.getBoolean(SAVE_HIGHLIGHTED_KEY);
}
-
- // Prepare help url and enable menu if necessary
final Bundle arguments = getArguments();
- final int helpResource;
- if (arguments != null && arguments.containsKey(HELP_URI_RESOURCE_KEY)) {
- helpResource = arguments.getInt(HELP_URI_RESOURCE_KEY);
- } else {
- helpResource = getHelpResource();
- }
- if (helpResource != 0) {
- mHelpUri = getResources().getString(helpResource);
- }
// Check if we should keep the preferences expanded.
if (arguments != null) {
@@ -177,8 +160,8 @@
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View root = super.onCreateView(inflater, container, savedInstanceState);
- mPinnedHeaderFrameLayout = (ViewGroup) root.findViewById(R.id.pinned_header);
- mButtonBar = (ViewGroup) root.findViewById(R.id.button_bar);
+ mPinnedHeaderFrameLayout = root.findViewById(R.id.pinned_header);
+ mButtonBar = root.findViewById(R.id.button_bar);
return root;
}
@@ -465,22 +448,6 @@
return false;
}
- /**
- * Override this if you want to show a help item in the menu, by returning the resource id.
- * @return the resource id for the help url
- */
- protected int getHelpResource() {
- return R.string.help_uri_default;
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
- if (mHelpUri != null && getActivity() != null) {
- HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
- }
- }
-
/*
* The name is intentionally made different from Activity#finish(), so that
* users won't misunderstand its meaning.
diff --git a/src/com/android/settings/WifiCallingSettingsForSub.java b/src/com/android/settings/WifiCallingSettingsForSub.java
index 57a4ab2..ba5ba84 100644
--- a/src/com/android/settings/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/WifiCallingSettingsForSub.java
@@ -131,7 +131,7 @@
};
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
// Helper resource is already defined in the container fragment.
return 0;
}
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 877894b..0611b09 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -230,7 +230,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_accessibility;
}
diff --git a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardActivity.java b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardActivity.java
index b820cc2..f6e044e 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardActivity.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardActivity.java
@@ -17,22 +17,14 @@
package com.android.settings.accessibility;
import android.app.Fragment;
-import android.app.FragmentTransaction;
import android.os.Bundle;
import android.text.TextUtils;
-import android.view.accessibility.AccessibilityEvent;
-import android.view.LayoutInflater;
import android.view.Menu;
-import android.view.View;
-import android.view.WindowInsets;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
+import android.view.accessibility.AccessibilityEvent;
-import com.android.settings.R;
import com.android.settings.SettingsActivity;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.setupwizardlib.util.SystemBarHelper;
-import com.android.setupwizardlib.view.NavigationBar;
+import com.android.settings.search.actionbar.SearchMenuController;
+import com.android.settings.support.actionbar.HelpResourceProvider;
public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivity {
@@ -94,7 +86,8 @@
}
// Start the new Fragment.
- args.putInt(SettingsPreferenceFragment.HELP_URI_RESOURCE_KEY, 0);
+ args.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 0);
+ args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false);
startPreferenceFragment(Fragment.instantiate(this, fragmentClass, args), true);
mSendExtraWindowStateChanged = true;
}
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index c437a16..db121e2 100644
--- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
@@ -51,7 +51,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_accessibility_shortcut;
}
diff --git a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
index d0197cf..24e87fc 100644
--- a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
@@ -66,7 +66,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_magnification;
}
diff --git a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
index a94b72c..acb918c 100644
--- a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
@@ -103,7 +103,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_autoclick;
}
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 8e76e48..146f697 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -41,7 +41,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_color_correction;
}
diff --git a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
index 53664f5..9239b8e 100644
--- a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
@@ -99,7 +99,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_account_detail;
}
diff --git a/src/com/android/settings/accounts/AccountSyncSettings.java b/src/com/android/settings/accounts/AccountSyncSettings.java
index 675de0e..d83694d 100644
--- a/src/com/android/settings/accounts/AccountSyncSettings.java
+++ b/src/com/android/settings/accounts/AccountSyncSettings.java
@@ -573,7 +573,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_accounts;
}
}
diff --git a/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java b/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
index de200cb..37584fc 100644
--- a/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
+++ b/src/com/android/settings/accounts/UserAndAccountDashboardFragment.java
@@ -56,7 +56,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_user_and_account_dashboard;
}
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index 5eccd44..7d6bdbb 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -48,7 +48,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_apps_and_notifications;
}
diff --git a/src/com/android/settings/applications/AppInfoDashboardFragment.java b/src/com/android/settings/applications/AppInfoDashboardFragment.java
index 0e73ad7..a725781 100755
--- a/src/com/android/settings/applications/AppInfoDashboardFragment.java
+++ b/src/com/android/settings/applications/AppInfoDashboardFragment.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
@@ -25,35 +25,22 @@
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
-import android.app.LoaderManager;
-import android.app.LoaderManager.LoaderCallbacks;
import android.app.admin.DevicePolicyManager;
-import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.Loader;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
-import android.content.res.Resources;
-import android.hardware.usb.IUsbManager;
-import android.icu.text.ListFormatter;
-import android.net.INetworkStatsService;
-import android.net.INetworkStatsSession;
-import android.net.NetworkTemplate;
-import android.net.TrafficStats;
import android.net.Uri;
import android.os.AsyncTask;
-import android.os.BatteryStats;
import android.os.Bundle;
-import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
@@ -63,10 +50,7 @@
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen;
-import android.text.BidiFormatter;
import android.text.TextUtils;
-import android.text.format.DateUtils;
-import android.text.format.Formatter;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -76,13 +60,24 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.internal.os.BatterySipper;
-import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.DeviceAdminAdd;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
+import com.android.settings.applications.appinfo.AppBatteryPreferenceController;
+import com.android.settings.applications.appinfo.AppDataUsagePreferenceController;
+import com.android.settings.applications.appinfo.AppMemoryPreferenceController;
+import com.android.settings.applications.appinfo.AppNotificationPreferenceController;
+import com.android.settings.applications.appinfo.AppOpenByDefaultPreferenceController;
+import com.android.settings.applications.appinfo.AppPermissionPreferenceController;
+import com.android.settings.applications.appinfo.AppStoragePreferenceController;
+import com.android.settings.applications.appinfo.AppVersionPreferenceController;
+import com.android.settings.applications.appinfo.DefaultBrowserShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultEmergencyShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultHomeShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultPhoneShortcutPreferenceController;
+import com.android.settings.applications.appinfo.DefaultSmsShortcutPreferenceController;
import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
@@ -91,32 +86,17 @@
import com.android.settings.applications.instantapps.InstantAppButtonsController;
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.datausage.AppDataUsage;
-import com.android.settings.datausage.DataUsageList;
-import com.android.settings.datausage.DataUsageUtils;
-import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
-import com.android.settings.fuelgauge.BatteryEntry;
-import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
-import com.android.settings.fuelgauge.BatteryUtils;
-import com.android.settings.notification.AppNotificationSettings;
-import com.android.settings.notification.NotificationBackend;
-import com.android.settings.notification.NotificationBackend.AppRow;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.ActionButtonPreference;
import com.android.settings.widget.EntityHeaderController;
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
-import com.android.settingslib.AppItem;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
-import com.android.settingslib.applications.PermissionsSummaryHelper;
-import com.android.settingslib.applications.PermissionsSummaryHelper.PermissionsResultCallback;
-import com.android.settingslib.applications.StorageStatsSource;
-import com.android.settingslib.applications.StorageStatsSource.AppStorageStats;
-import com.android.settingslib.development.DevelopmentSettingsEnabler;
-import com.android.settingslib.net.ChartData;
-import com.android.settingslib.net.ChartDataLoader;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.wrapper.PackageManagerWrapper;
import java.lang.ref.WeakReference;
@@ -134,11 +114,10 @@
* For non-system applications, there is no option to clear data. Instead there is an option to
* uninstall the application.
*/
-public class AppInfoDashboardFragment extends SettingsPreferenceFragment
- implements ApplicationsState.Callbacks, OnPreferenceClickListener,
- LoaderCallbacks<AppStorageStats> {
+public class AppInfoDashboardFragment extends DashboardFragment
+ implements ApplicationsState.Callbacks {
- private static final String LOG_TAG = "AppInfoDashboardFragment";
+ private static final String TAG = "AppInfoDashboard";
// Menu identifiers
public static final int UNINSTALL_ALL_USERS_MENU = 1;
@@ -148,37 +127,27 @@
public static final int REQUEST_UNINSTALL = 0;
private static final int REQUEST_REMOVE_DEVICE_ADMIN = 1;
- private static final int SUB_INFO_FRAGMENT = 1;
+ public static final int SUB_INFO_FRAGMENT = 1;
- private static final int LOADER_CHART_DATA = 2;
- private static final int LOADER_STORAGE = 3;
+ public static final int LOADER_CHART_DATA = 2;
+ public static final int LOADER_STORAGE = 3;
@VisibleForTesting
- static final int LOADER_BATTERY = 4;
+ public static final int LOADER_BATTERY = 4;
// Dialog identifiers used in showDialog
private static final int DLG_BASE = 0;
private static final int DLG_FORCE_STOP = DLG_BASE + 1;
private static final int DLG_DISABLE = DLG_BASE + 2;
private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3;
- private static final String EXTRA_HIDE_INFO_BUTTON = "hideInfoButton";
private static final String KEY_HEADER = "header_view";
private static final String KEY_INSTANT_APP_BUTTONS = "instant_app_buttons";
private static final String KEY_ACTION_BUTTONS = "action_buttons";
- private static final String KEY_NOTIFICATION = "notification_settings";
- private static final String KEY_STORAGE = "storage_settings";
- private static final String KEY_PERMISSION = "permission_settings";
- private static final String KEY_DATA = "data_settings";
- private static final String KEY_LAUNCH = "preferred_settings";
- private static final String KEY_BATTERY = "battery";
- private static final String KEY_MEMORY = "memory";
- private static final String KEY_VERSION = "app_version";
private static final String KEY_INSTANT_APP_SUPPORTED_LINKS =
"instant_app_launch_supported_domain_urls";
- // The following copied from AppInfoBase
+
public static final String ARG_PACKAGE_NAME = "package";
public static final String ARG_PACKAGE_UID = "uid";
- protected static final String TAG = AppInfoBase.class.getSimpleName();
protected static final boolean localLOGV = false;
private EnforcedAdmin mAppsControlDisallowedAdmin;
@@ -192,7 +161,6 @@
private int mUserId;
private String mPackageName;
- private IUsbManager mUsbManager;
private DevicePolicyManagerWrapper mDpm;
private UserManager mUserManager;
private PackageManager mPm;
@@ -207,66 +175,22 @@
private boolean mShowUninstalled;
private LayoutPreference mHeader;
private boolean mUpdatedSysApp = false;
- private Preference mNotificationPreference;
- private Preference mStoragePreference;
- private Preference mPermissionsPreference;
- private Preference mLaunchPreference;
- private Preference mDataPreference;
- private Preference mMemoryPreference;
- private Preference mVersionPreference;
private AppDomainsPreference mInstantAppDomainsPreference;
private boolean mDisableAfterUninstall;
- // Used for updating notification preference.
- private final NotificationBackend mBackend = new NotificationBackend();
-
- private ChartData mChartData;
- private INetworkStatsSession mStatsSession;
+ private List<Callback> mCallbacks = new ArrayList<>();
@VisibleForTesting
ActionButtonPreference mActionButtons;
- @VisibleForTesting
- Preference mBatteryPreference;
- @VisibleForTesting
- BatterySipper mSipper;
- @VisibleForTesting
- BatteryStatsHelper mBatteryHelper;
- @VisibleForTesting
- BatteryUtils mBatteryUtils;
-
- protected ProcStatsData mStatsManager;
- protected ProcStatsPackageEntry mStats;
private InstantAppButtonsController mInstantAppButtonsController;
- private AppStorageStats mLastResult;
- private String mBatteryPercent;
-
- @VisibleForTesting
- final LoaderCallbacks<BatteryStatsHelper> mBatteryCallbacks =
- new LoaderCallbacks<BatteryStatsHelper>() {
-
- @Override
- public Loader<BatteryStatsHelper> onCreateLoader(int id, Bundle args) {
- return new BatteryStatsHelperLoader(getContext());
- }
-
- @Override
- public void onLoadFinished(Loader<BatteryStatsHelper> loader,
- BatteryStatsHelper batteryHelper) {
- mBatteryHelper = batteryHelper;
- if (mPackageInfo != null) {
- mSipper = findTargetSipper(batteryHelper, mPackageInfo.applicationInfo.uid);
- if (getActivity() != null) {
- updateBattery();
- }
- }
- }
-
- @Override
- public void onLoaderReset(Loader<BatteryStatsHelper> loader) {
- }
- };
+ /**
+ * Callback to invoke when app info has been changed.
+ */
+ public interface Callback {
+ void refreshUi();
+ }
@VisibleForTesting
boolean handleDisableable() {
@@ -401,14 +325,10 @@
final Activity activity = getActivity();
mApplicationFeatureProvider = FeatureFactory.getFactory(activity)
.getApplicationFeatureProvider(activity);
- mState = ApplicationsState.getInstance(activity.getApplication());
- mSession = mState.newSession(this, getLifecycle());
mDpm = new DevicePolicyManagerWrapper(
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE));
mUserManager = (UserManager) activity.getSystemService(Context.USER_SERVICE);
mPm = activity.getPackageManager();
- IBinder b = ServiceManager.getService(Context.USB_SERVICE);
- mUsbManager = IUsbManager.Stub.asInterface(b);
retrieveAppEntry();
startListeningToPackageRemove();
@@ -418,21 +338,8 @@
}
setHasOptionsMenu(true);
- addPreferencesFromResource(R.xml.installed_app_details);
addDynamicPrefs();
- if (Utils.isBandwidthControlEnabled()) {
- INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
- ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
- try {
- mStatsSession = statsService.openSession();
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- } else {
- removePreference(KEY_DATA);
- }
- mBatteryUtils = BatteryUtils.getInstance(getContext());
}
@Override
@@ -455,31 +362,60 @@
if (mFinishing) {
return;
}
- AppItem app = new AppItem(mAppEntry.info.uid);
- app.addUid(mAppEntry.info.uid);
- if (mStatsSession != null) {
- LoaderManager loaderManager = getLoaderManager();
- loaderManager.restartLoader(LOADER_CHART_DATA,
- ChartDataLoader.buildArgs(getTemplate(getContext()), app),
- mDataCallbacks);
- loaderManager.restartLoader(LOADER_STORAGE, Bundle.EMPTY, this);
- }
- restartBatteryStatsLoader();
- if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
- new MemoryUpdater().execute();
- }
updateDynamicPrefs();
}
- @VisibleForTesting
- public void restartBatteryStatsLoader() {
- getLoaderManager().restartLoader(LOADER_BATTERY, Bundle.EMPTY, mBatteryCallbacks);
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.app_info_settings;
}
@Override
- public void onPause() {
- getLoaderManager().destroyLoader(LOADER_CHART_DATA);
- super.onPause();
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ final String packageName = getPackageName();
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ final Lifecycle lifecycle = getLifecycle();
+
+ // The following are controllers for preferences that needs to refresh the preference state
+ // when app state changes.
+ controllers.add(new AppStoragePreferenceController(context, this, lifecycle));
+ controllers.add(new AppDataUsagePreferenceController(context, this, lifecycle));
+ controllers.add(new AppNotificationPreferenceController(context, this));
+ controllers.add(new AppOpenByDefaultPreferenceController(context, this));
+ controllers.add(new AppPermissionPreferenceController(context, this, packageName));
+ controllers.add(new AppVersionPreferenceController(context, this));
+
+ for (AbstractPreferenceController controller : controllers) {
+ mCallbacks.add((Callback) controller);
+ }
+
+ // The following are controllers for preferences that don't need to refresh the preference
+ // state when app state changes.
+ controllers.add(new AppBatteryPreferenceController(context, this, packageName, lifecycle));
+ controllers.add(new AppMemoryPreferenceController(context, this, lifecycle));
+ controllers.add(new DefaultHomeShortcutPreferenceController(context, packageName));
+ controllers.add(new DefaultBrowserShortcutPreferenceController(context, packageName));
+ controllers.add(new DefaultPhoneShortcutPreferenceController(context, packageName));
+ controllers.add(new DefaultEmergencyShortcutPreferenceController(context, packageName));
+ controllers.add(new DefaultSmsShortcutPreferenceController(context, packageName));
+
+ return controllers;
+ }
+
+ public ApplicationsState.AppEntry getAppEntry() {
+ if (mAppEntry == null) {
+ retrieveAppEntry();
+ }
+ return mAppEntry;
+ }
+
+ public PackageInfo getPackageInfo() {
+ return mPackageInfo;
}
public void onActivityCreated(Bundle savedInstanceState) {
@@ -502,43 +438,14 @@
.styleActionBar(activity)
.bindHeaderButtons();
- mNotificationPreference = findPreference(KEY_NOTIFICATION);
- mNotificationPreference.setOnPreferenceClickListener(this);
- mStoragePreference = findPreference(KEY_STORAGE);
- mStoragePreference.setOnPreferenceClickListener(this);
- mPermissionsPreference = findPreference(KEY_PERMISSION);
- mPermissionsPreference.setOnPreferenceClickListener(this);
- mDataPreference = findPreference(KEY_DATA);
- if (mDataPreference != null) {
- mDataPreference.setOnPreferenceClickListener(this);
- }
- mBatteryPreference = findPreference(KEY_BATTERY);
- mBatteryPreference.setEnabled(false);
- mBatteryPreference.setOnPreferenceClickListener(this);
- mMemoryPreference = findPreference(KEY_MEMORY);
- mMemoryPreference.setOnPreferenceClickListener(this);
- mMemoryPreference.setVisible(
- DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext()));
- mVersionPreference = findPreference(KEY_VERSION);
mInstantAppDomainsPreference =
(AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
- mLaunchPreference = findPreference(KEY_LAUNCH);
- if (mAppEntry != null && mAppEntry.info != null) {
- if ((mAppEntry.info.flags&ApplicationInfo.FLAG_INSTALLED) == 0 ||
- !mAppEntry.info.enabled) {
- mLaunchPreference.setEnabled(false);
- } else {
- mLaunchPreference.setOnPreferenceClickListener(this);
- }
- } else {
- mLaunchPreference.setEnabled(false);
- }
}
@Override
public void onPackageSizeChanged(String packageName) {
if (!TextUtils.equals(packageName, mPackageName)) {
- Log.d(LOG_TAG, "Package change irrelevant, skipping");
+ Log.d(TAG, "Package change irrelevant, skipping");
return;
}
refreshUi();
@@ -554,7 +461,7 @@
boolean ensurePackageInfoAvailable(Activity activity) {
if (mPackageInfo == null) {
mFinishing = true;
- Log.w(LOG_TAG, "Package info not available. Is this package already uninstalled?");
+ Log.w(TAG, "Package info not available. Is this package already uninstalled?");
activity.finishAndRemoveTask();
return false;
}
@@ -563,6 +470,7 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ super.onCreateOptionsMenu(menu, inflater);
menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, UNINSTALL_ALL_USERS_MENU, 1, R.string.uninstall_all_users_text)
@@ -622,23 +530,6 @@
}
}
- @Override
- public Loader<AppStorageStats> onCreateLoader(int id, Bundle args) {
- Context context = getContext();
- return new FetchPackageStorageAsyncLoader(
- context, new StorageStatsSource(context), mAppEntry.info, UserHandle.of(mUserId));
- }
-
- @Override
- public void onLoadFinished(Loader<AppStorageStats> loader, AppStorageStats result) {
- mLastResult = result;
- refreshUi();
- }
-
- @Override
- public void onLoaderReset(Loader<AppStorageStats> loader) {
- }
-
/**
* Utility method to hide and show specific preferences based on whether the app being displayed
* is an Instant App or an installed app.
@@ -652,7 +543,6 @@
mInstantAppDomainsPreference.setTitles(handledDomains);
// Dummy values, unused in the implementation
mInstantAppDomainsPreference.setValues(new int[handledDomains.length]);
- getPreferenceScreen().removePreference(mLaunchPreference);
} else {
getPreferenceScreen().removePreference(mInstantAppDomainsPreference);
}
@@ -672,8 +562,6 @@
.setSummary(summary)
.setIsInstantApp(isInstantApp)
.done(activity, false /* rebindActions */);
- mVersionPreference.setSummary(getString(R.string.version_text,
- BidiFormatter.getInstance().unicodeWrap(pkgInfo.versionName)));
}
@VisibleForTesting
@@ -700,19 +588,6 @@
return showIt;
}
- @VisibleForTesting
- BatterySipper findTargetSipper(BatteryStatsHelper batteryHelper, int uid) {
- List<BatterySipper> usageList = batteryHelper.getUsageList();
- for (int i = 0, size = usageList.size(); i < size; i++) {
- BatterySipper sipper = usageList.get(i);
- if (sipper.getUid() == uid) {
- return sipper;
- }
- }
-
- return null;
- }
-
private boolean signaturesMatch(String pkg1, String pkg2) {
if (pkg1 != null && pkg2 != null) {
try {
@@ -764,17 +639,8 @@
// Update the preference summaries.
Activity context = getActivity();
- boolean isExternal = ((mAppEntry.info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
- mStoragePreference.setSummary(getStorageSummary(context, mLastResult, isExternal));
-
- PermissionsSummaryHelper.getPermissionSummary(getContext(),
- mPackageName, mPermissionCallback);
- mLaunchPreference.setSummary(AppUtils.getLaunchByDefaultSummary(mAppEntry, mUsbManager,
- mPm, context));
- mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context,
- mBackend));
- if (mDataPreference != null) {
- mDataPreference.setSummary(getDataSummary());
+ for (Callback callback : mCallbacks) {
+ callback.refreshUi();
}
if (!mInitialized) {
@@ -803,63 +669,6 @@
return true;
}
- @VisibleForTesting
- void updateBattery() {
- mBatteryPreference.setEnabled(true);
- if (isBatteryStatsAvailable()) {
- final int dischargeAmount = mBatteryHelper.getStats().getDischargeAmount(
- BatteryStats.STATS_SINCE_CHARGED);
-
- final List<BatterySipper> usageList = new ArrayList<>(mBatteryHelper.getUsageList());
- final double hiddenAmount = mBatteryUtils.removeHiddenBatterySippers(usageList);
- final int percentOfMax = (int) mBatteryUtils.calculateBatteryPercent(
- mSipper.totalPowerMah, mBatteryHelper.getTotalPower(), hiddenAmount,
- dischargeAmount);
- mBatteryPercent = Utils.formatPercentage(percentOfMax);
- mBatteryPreference.setSummary(getString(R.string.battery_summary, mBatteryPercent));
- } else {
- mBatteryPreference.setSummary(getString(R.string.no_battery_summary));
- }
- }
-
- private CharSequence getDataSummary() {
- if (mChartData != null) {
- long totalBytes = mChartData.detail.getTotalBytes();
- if (totalBytes == 0) {
- return getString(R.string.no_data_usage);
- }
- Context context = getActivity();
- return getString(R.string.data_summary_format,
- Formatter.formatFileSize(context, totalBytes),
- DateUtils.formatDateTime(context, mChartData.detail.getStart(),
- DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH));
- }
- return getString(R.string.computing_size);
- }
-
- @VisibleForTesting
- static CharSequence getStorageSummary(
- Context context, AppStorageStats stats, boolean isExternal) {
- if (stats == null) {
- return context.getText(R.string.computing_size);
- } else {
- CharSequence storageType = context.getString(isExternal
- ? R.string.storage_type_external
- : R.string.storage_type_internal);
- return context.getString(R.string.storage_summary_format,
- getSize(context, stats), storageType.toString().toLowerCase());
- }
- }
-
- @VisibleForTesting
- boolean isBatteryStatsAvailable() {
- return mBatteryHelper != null && mSipper != null;
- }
-
- private static CharSequence getSize(Context context, AppStorageStats stats) {
- return Formatter.formatFileSize(context, stats.getTotalBytes());
- }
-
protected AlertDialog createDialog(int id, int errorCode) {
switch (id) {
case DLG_DISABLE:
@@ -928,7 +737,7 @@
mMetricsFeatureProvider.action(getContext(), MetricsEvent.ACTION_APP_FORCE_STOP, pkgName);
ActivityManager am = (ActivityManager) getActivity().getSystemService(
Context.ACTIVITY_SERVICE);
- Log.d(LOG_TAG, "Stopping package " + pkgName);
+ Log.d(TAG, "Stopping package " + pkgName);
am.forceStopPackage(pkgName);
int userId = UserHandle.getUserId(mAppEntry.info.uid);
mState.invalidatePackage(pkgName, userId);
@@ -950,7 +759,7 @@
void checkForceStop() {
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
// User can't force stop device admin.
- Log.w(LOG_TAG, "User can't force stop device admin");
+ Log.w(TAG, "User can't force stop device admin");
updateForceStopButton(false);
} else if (AppUtils.isInstant(mPackageInfo.applicationInfo)) {
updateForceStopButton(false);
@@ -958,7 +767,7 @@
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
// If the app isn't explicitly stopped, then always show the
// force stop button.
- Log.w(LOG_TAG, "App is not explicitly stopped");
+ Log.w(TAG, "App is not explicitly stopped");
updateForceStopButton(true);
} else {
Intent intent = new Intent(Intent.ACTION_QUERY_PACKAGE_RESTART,
@@ -966,25 +775,13 @@
intent.putExtra(Intent.EXTRA_PACKAGES, new String[] { mAppEntry.info.packageName });
intent.putExtra(Intent.EXTRA_UID, mAppEntry.info.uid);
intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(mAppEntry.info.uid));
- Log.d(LOG_TAG, "Sending broadcast to query restart status for "
+ Log.d(TAG, "Sending broadcast to query restart status for "
+ mAppEntry.info.packageName);
getActivity().sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
mCheckKillProcessesReceiver, null, Activity.RESULT_CANCELED, null, null);
}
}
- private void startManagePermissionsActivity() {
- // start new activity to manage app permissions
- Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
- intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
- intent.putExtra(EXTRA_HIDE_INFO_BUTTON, true);
- try {
- getActivity().startActivityForResult(intent, SUB_INFO_FRAGMENT);
- } catch (ActivityNotFoundException e) {
- Log.w(LOG_TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
- }
- }
-
private void startAppInfoFragment(Class<?> fragment, int title) {
startAppInfoFragment(fragment, title, this, mAppEntry);
}
@@ -1070,69 +867,12 @@
|| (mUserManager.isSplitSystemUser() && userCount == 2);
}
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (preference == mStoragePreference) {
- startAppInfoFragment(AppStorageSettings.class, R.string.storage_settings);
- } else if (preference == mNotificationPreference) {
- startAppInfoFragment(AppNotificationSettings.class, R.string.app_notifications_title);
- } else if (preference == mPermissionsPreference) {
- startManagePermissionsActivity();
- } else if (preference == mLaunchPreference) {
- startAppInfoFragment(AppLaunchSettings.class, R.string.launch_by_default);
- } else if (preference == mMemoryPreference) {
- ProcessStatsBase.launchMemoryDetail((SettingsActivity) getActivity(),
- mStatsManager.getMemInfo(), mStats, false);
- } else if (preference == mDataPreference) {
- startAppInfoFragment(AppDataUsage.class, R.string.app_data_usage);
- } else if (preference == mBatteryPreference) {
- if (isBatteryStatsAvailable()) {
- BatteryEntry entry = new BatteryEntry(getContext(), null, mUserManager, mSipper);
- entry.defaultPackageName = mPackageName;
- AdvancedPowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(),
- this, mBatteryHelper, BatteryStats.STATS_SINCE_CHARGED, entry,
- mBatteryPercent, null /* mAnomalies */);
- } else {
- AdvancedPowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(),
- this, mPackageName);
- }
- } else {
- return false;
- }
- return true;
- }
-
private void addDynamicPrefs() {
if (UserManager.get(getContext()).isManagedProfile()) {
return;
}
final PreferenceScreen screen = getPreferenceScreen();
final Context context = getContext();
- if (DefaultHomePreferenceController.hasHomePreference(mPackageName, context)) {
- screen.addPreference(new ShortcutPreference(getPrefContext(),
- DefaultAppSettings.class, "default_home", R.string.home_app,
- R.string.configure_apps));
- }
- if (DefaultBrowserPreferenceController.hasBrowserPreference(mPackageName, context)) {
- screen.addPreference(new ShortcutPreference(getPrefContext(),
- DefaultAppSettings.class, "default_browser", R.string.default_browser_title,
- R.string.configure_apps));
- }
- if (DefaultPhonePreferenceController.hasPhonePreference(mPackageName, context)) {
- screen.addPreference(new ShortcutPreference(getPrefContext(),
- DefaultAppSettings.class, "default_phone_app", R.string.default_phone_title,
- R.string.configure_apps));
- }
- if (DefaultEmergencyPreferenceController.hasEmergencyPreference(mPackageName, context)) {
- screen.addPreference(new ShortcutPreference(getPrefContext(),
- DefaultAppSettings.class, "default_emergency_app",
- R.string.default_emergency_app, R.string.configure_apps));
- }
- if (DefaultSmsPreferenceController.hasSmsPreference(mPackageName, context)) {
- screen.addPreference(new ShortcutPreference(getPrefContext(),
- DefaultAppSettings.class, "default_sms_app", R.string.sms_application_title,
- R.string.configure_apps));
- }
// Get the package info with the activities
PackageInfo packageInfoWithActivities = null;
@@ -1282,36 +1022,7 @@
private void updateDynamicPrefs() {
final Context context = getContext();
- Preference pref = findPreference("default_home");
-
- if (pref != null) {
- pref.setSummary(DefaultHomePreferenceController.isHomeDefault(mPackageName,
- new PackageManagerWrapper(context.getPackageManager()))
- ? R.string.yes : R.string.no);
- }
- pref = findPreference("default_browser");
- if (pref != null) {
- pref.setSummary(new DefaultBrowserPreferenceController(context)
- .isBrowserDefault(mPackageName, mUserId)
- ? R.string.yes : R.string.no);
- }
- pref = findPreference("default_phone_app");
- if (pref != null) {
- pref.setSummary(
- DefaultPhonePreferenceController.isPhoneDefault(mPackageName, context)
- ? R.string.yes : R.string.no);
- }
- pref = findPreference("default_emergency_app");
- if (pref != null) {
- pref.setSummary(DefaultEmergencyPreferenceController.isEmergencyDefault(mPackageName,
- getContext()) ? R.string.yes : R.string.no);
- }
- pref = findPreference("default_sms_app");
- if (pref != null) {
- pref.setSummary(DefaultSmsPreferenceController.isSmsDefault(mPackageName, context)
- ? R.string.yes : R.string.no);
- }
- pref = findPreference("system_alert_window");
+ Preference pref = findPreference("system_alert_window");
if (pref != null) {
pref.setSummary(DrawOverlayDetails.getSummary(getContext(), mAppEntry));
}
@@ -1330,78 +1041,11 @@
}
}
- public static NetworkTemplate getTemplate(Context context) {
- if (DataUsageList.hasReadyMobileRadio(context)) {
- return NetworkTemplate.buildTemplateMobileWildcard();
- }
- if (DataUsageUtils.hasWifiRadio(context)) {
- return NetworkTemplate.buildTemplateWifiWildcard();
- }
- return NetworkTemplate.buildTemplateEthernet();
- }
-
- public static CharSequence getNotificationSummary(AppEntry appEntry, Context context,
- NotificationBackend backend) {
- AppRow appRow = backend.loadAppRow(context, context.getPackageManager(), appEntry.info);
- return getNotificationSummary(appRow, context);
- }
-
- public static CharSequence getNotificationSummary(AppRow appRow, Context context) {
- // TODO: implement summary when it is known what it should say
- return "";
- }
-
private void onPackageRemoved() {
getActivity().finishActivity(SUB_INFO_FRAGMENT);
getActivity().finishAndRemoveTask();
}
- private class MemoryUpdater extends AsyncTask<Void, Void, ProcStatsPackageEntry> {
-
- @Override
- protected ProcStatsPackageEntry doInBackground(Void... params) {
- if (getActivity() == null) {
- return null;
- }
- if (mPackageInfo == null) {
- return null;
- }
- if (mStatsManager == null) {
- mStatsManager = new ProcStatsData(getActivity(), false);
- mStatsManager.setDuration(ProcessStatsBase.sDurations[0]);
- }
- mStatsManager.refreshStats(true);
- for (ProcStatsPackageEntry pkgEntry : mStatsManager.getEntries()) {
- for (ProcStatsEntry entry : pkgEntry.mEntries) {
- if (entry.mUid == mPackageInfo.applicationInfo.uid) {
- pkgEntry.updateMetrics();
- return pkgEntry;
- }
- }
- }
- return null;
- }
-
- @Override
- protected void onPostExecute(ProcStatsPackageEntry entry) {
- if (getActivity() == null) {
- return;
- }
- if (entry != null) {
- mStats = entry;
- mMemoryPreference.setEnabled(true);
- double amount = Math.max(entry.mRunWeight, entry.mBgWeight)
- * mStatsManager.getMemInfo().weightToRam;
- mMemoryPreference.setSummary(getString(R.string.memory_use_summary,
- Formatter.formatShortFileSize(getContext(), (long) amount)));
- } else {
- mMemoryPreference.setEnabled(false);
- mMemoryPreference.setSummary(getString(R.string.no_memory_use_summary));
- }
- }
-
- }
-
/**
* Elicit this class for testing. Test cannot be done in robolectric because it
* invokes the new API.
@@ -1453,76 +1097,22 @@
}
}
- private final LoaderCallbacks<ChartData> mDataCallbacks = new LoaderCallbacks<ChartData>() {
-
- @Override
- public Loader<ChartData> onCreateLoader(int id, Bundle args) {
- return new ChartDataLoader(getActivity(), mStatsSession, args);
- }
-
- @Override
- public void onLoadFinished(Loader<ChartData> loader, ChartData data) {
- mChartData = data;
- mDataPreference.setSummary(getDataSummary());
- }
-
- @Override
- public void onLoaderReset(Loader<ChartData> loader) {
- // Leave last result.
- }
- };
-
private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final boolean enabled = getResultCode() != Activity.RESULT_CANCELED;
- Log.d(LOG_TAG, "Got broadcast response: Restart status for "
+ Log.d(TAG, "Got broadcast response: Restart status for "
+ mAppEntry.info.packageName + " " + enabled);
updateForceStopButton(enabled);
}
};
- private final PermissionsResultCallback mPermissionCallback
- = new PermissionsResultCallback() {
- @Override
- public void onPermissionSummaryResult(int standardGrantedPermissionCount,
- int requestedPermissionCount, int additionalGrantedPermissionCount,
- List<CharSequence> grantedGroupLabels) {
- if (getActivity() == null) {
- return;
- }
- final Resources res = getResources();
- CharSequence summary = null;
-
- if (requestedPermissionCount == 0) {
- summary = res.getString(
- R.string.runtime_permissions_summary_no_permissions_requested);
- mPermissionsPreference.setOnPreferenceClickListener(null);
- mPermissionsPreference.setEnabled(false);
- } else {
- final ArrayList<CharSequence> list = new ArrayList<>(grantedGroupLabels);
- if (additionalGrantedPermissionCount > 0) {
- // N additional permissions.
- list.add(res.getQuantityString(
- R.plurals.runtime_permissions_additional_count,
- additionalGrantedPermissionCount, additionalGrantedPermissionCount));
- }
- if (list.size() == 0) {
- summary = res.getString(
- R.string.runtime_permissions_summary_no_permissions_granted);
- } else {
- summary = ListFormatter.getInstance().format(list);
- }
- mPermissionsPreference.setOnPreferenceClickListener(AppInfoDashboardFragment.this);
- mPermissionsPreference.setEnabled(true);
- }
- mPermissionsPreference.setSummary(summary);
+ private String getPackageName() {
+ if (mPackageName != null) {
+ return mPackageName;
}
- };
-
- private String retrieveAppEntry() {
final Bundle args = getArguments();
- mPackageName = (args != null) ? args.getString(ARG_PACKAGE_NAME) : null;
+ String mPackageName = (args != null) ? args.getString(ARG_PACKAGE_NAME) : null;
if (mPackageName == null) {
Intent intent = (args == null) ?
getActivity().getIntent() : (Intent) args.getParcelable("intent");
@@ -1530,12 +1120,25 @@
mPackageName = intent.getData().getSchemeSpecificPart();
}
}
+ return mPackageName;
+ }
+
+ private void retrieveAppEntry() {
+ final Activity activity = getActivity();
+ if (activity == null) {
+ return;
+ }
+ if (mState == null) {
+ mState = ApplicationsState.getInstance(activity.getApplication());
+ mSession = mState.newSession(this, getLifecycle());
+ }
mUserId = UserHandle.myUserId();
- mAppEntry = mState.getEntry(mPackageName, mUserId);
+ mAppEntry = mState.getEntry(getPackageName(), UserHandle.myUserId());
if (mAppEntry != null) {
// Get application info again to refresh changed properties of application
try {
- mPackageInfo = mPm.getPackageInfo(mAppEntry.info.packageName,
+ mPackageInfo = activity.getPackageManager().getPackageInfo(
+ mAppEntry.info.packageName,
PackageManager.MATCH_DISABLED_COMPONENTS |
PackageManager.MATCH_ANY_USER |
PackageManager.GET_SIGNATURES |
@@ -1547,8 +1150,6 @@
Log.w(TAG, "Missing AppEntry; maybe reinstalling?");
mPackageInfo = null;
}
-
- return mPackageName;
}
private void setIntentAndFinish(boolean finish, boolean appChanged) {
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 91d1cb3..6f94015 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -508,6 +508,7 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ super.onCreateOptionsMenu(menu, inflater);
menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, UNINSTALL_ALL_USERS_MENU, 1, R.string.uninstall_all_users_text)
diff --git a/src/com/android/settings/applications/ProcStatsData.java b/src/com/android/settings/applications/ProcStatsData.java
index dd85dd2..c1ec070 100644
--- a/src/com/android/settings/applications/ProcStatsData.java
+++ b/src/com/android/settings/applications/ProcStatsData.java
@@ -372,6 +372,10 @@
double totalScale;
long memTotalTime;
+ public double getWeightToRam() {
+ return weightToRam;
+ }
+
private MemInfo(Context context, ProcessStats.TotalMemoryUseCollection totalMem,
long memTotalTime) {
this.memTotalTime = memTotalTime;
diff --git a/src/com/android/settings/applications/ProcStatsEntry.java b/src/com/android/settings/applications/ProcStatsEntry.java
index 90ef5d7..2388a04 100644
--- a/src/com/android/settings/applications/ProcStatsEntry.java
+++ b/src/com/android/settings/applications/ProcStatsEntry.java
@@ -297,6 +297,10 @@
}
}
+ public int getUid() {
+ return mUid;
+ }
+
public static final Parcelable.Creator<ProcStatsEntry> CREATOR
= new Parcelable.Creator<ProcStatsEntry>() {
public ProcStatsEntry createFromParcel(Parcel in) {
diff --git a/src/com/android/settings/applications/ProcStatsPackageEntry.java b/src/com/android/settings/applications/ProcStatsPackageEntry.java
index 39a0042..88d5bd6 100644
--- a/src/com/android/settings/applications/ProcStatsPackageEntry.java
+++ b/src/com/android/settings/applications/ProcStatsPackageEntry.java
@@ -175,4 +175,17 @@
Utils.formatPercentage((int) (amount * 100)));
}
}
+
+ public double getRunWeight() {
+ return mRunWeight;
+ }
+
+ public double getBgWeight() {
+ return mBgWeight;
+ }
+
+ public ArrayList<ProcStatsEntry> getEntries() {
+ return mEntries;
+ }
+
}
diff --git a/src/com/android/settings/applications/ProcessStatsSummary.java b/src/com/android/settings/applications/ProcessStatsSummary.java
index cdb8a4c..75f8ba6 100644
--- a/src/com/android/settings/applications/ProcessStatsSummary.java
+++ b/src/com/android/settings/applications/ProcessStatsSummary.java
@@ -103,7 +103,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_process_stats_summary;
}
diff --git a/src/com/android/settings/applications/ProcessStatsUi.java b/src/com/android/settings/applications/ProcessStatsUi.java
index 9f76fb2..cb2a1eb 100644
--- a/src/com/android/settings/applications/ProcessStatsUi.java
+++ b/src/com/android/settings/applications/ProcessStatsUi.java
@@ -96,7 +96,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_process_stats_apps;
}
diff --git a/src/com/android/settings/applications/ShortcutPreference.java b/src/com/android/settings/applications/ShortcutPreference.java
index 91b41b7..9505e89 100644
--- a/src/com/android/settings/applications/ShortcutPreference.java
+++ b/src/com/android/settings/applications/ShortcutPreference.java
@@ -21,7 +21,12 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
+import com.android.settings.applications.appinfo.DefaultAppShortcutPreferenceControllerBase;
+/**
+ * deprecated in favor of {@link DefaultAppShortcutPreferenceControllerBase}
+ */
+@Deprecated
public class ShortcutPreference extends Preference {
private final Class mTarget;
diff --git a/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java b/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java
new file mode 100644
index 0000000..d341d53
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.app.LoaderManager;
+import android.app.slice.Slice;
+import android.content.Context;
+import android.content.Loader;
+import android.content.pm.PackageInfo;
+import android.os.BatteryStats;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.os.BatterySipper;
+import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.Utils;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
+import com.android.settings.fuelgauge.BatteryEntry;
+import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnPause;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AppBatteryPreferenceController extends BasePreferenceController
+ implements LoaderManager.LoaderCallbacks<BatteryStatsHelper>,
+ LifecycleObserver, OnResume, OnPause {
+
+ private static final String KEY_BATTERY = "battery";
+
+ @VisibleForTesting
+ BatterySipper mSipper;
+ @VisibleForTesting
+ BatteryStatsHelper mBatteryHelper;
+ @VisibleForTesting
+ BatteryUtils mBatteryUtils;
+
+ private Preference mPreference;
+ private final AppInfoDashboardFragment mParent;
+ private String mBatteryPercent;
+ private final String mPackageName;
+
+ public AppBatteryPreferenceController(Context context, AppInfoDashboardFragment parent,
+ String packageName, Lifecycle lifecycle) {
+ super(context, KEY_BATTERY);
+ mParent = parent;
+ mBatteryUtils = BatteryUtils.getInstance(mContext);
+ mPackageName = packageName;
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public Slice getSettingSlice() {
+ return null;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ mPreference.setEnabled(false);
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!KEY_BATTERY.equals(preference.getKey())) {
+ return false;
+ }
+ if (isBatteryStatsAvailable()) {
+ final UserManager userManager =
+ (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ final BatteryEntry entry = new BatteryEntry(mContext, null, userManager, mSipper);
+ entry.defaultPackageName = mPackageName;
+ AdvancedPowerUsageDetail.startBatteryDetailPage(
+ (SettingsActivity) mParent.getActivity(), mParent, mBatteryHelper,
+ BatteryStats.STATS_SINCE_CHARGED, entry, mBatteryPercent,
+ null /* mAnomalies */);
+ } else {
+ AdvancedPowerUsageDetail.startBatteryDetailPage(
+ (SettingsActivity) mParent.getActivity(), mParent, mPackageName);
+ }
+ return true;
+ }
+
+ @Override
+ public void onResume() {
+ mParent.getLoaderManager().restartLoader(
+ mParent.LOADER_BATTERY, Bundle.EMPTY, this);
+ }
+
+ @Override
+ public void onPause() {
+ mParent.getLoaderManager().destroyLoader(mParent.LOADER_BATTERY);
+ }
+
+ @Override
+ public Loader<BatteryStatsHelper> onCreateLoader(int id, Bundle args) {
+ return new BatteryStatsHelperLoader(mContext);
+ }
+
+ @Override
+ public void onLoadFinished(Loader<BatteryStatsHelper> loader,
+ BatteryStatsHelper batteryHelper) {
+ mBatteryHelper = batteryHelper;
+ final PackageInfo packageInfo = mParent.getPackageInfo();
+ if (packageInfo != null) {
+ mSipper = findTargetSipper(batteryHelper, packageInfo.applicationInfo.uid);
+ if (mParent.getActivity() != null) {
+ updateBattery();
+ }
+ }
+ }
+
+ @Override
+ public void onLoaderReset(Loader<BatteryStatsHelper> loader) {
+ }
+
+ @VisibleForTesting
+ void updateBattery() {
+ mPreference.setEnabled(true);
+ if (isBatteryStatsAvailable()) {
+ final int dischargeAmount = mBatteryHelper.getStats().getDischargeAmount(
+ BatteryStats.STATS_SINCE_CHARGED);
+
+ final List<BatterySipper> usageList = new ArrayList<>(mBatteryHelper.getUsageList());
+ final double hiddenAmount = mBatteryUtils.removeHiddenBatterySippers(usageList);
+ final int percentOfMax = (int) mBatteryUtils.calculateBatteryPercent(
+ mSipper.totalPowerMah, mBatteryHelper.getTotalPower(), hiddenAmount,
+ dischargeAmount);
+ mBatteryPercent = Utils.formatPercentage(percentOfMax);
+ mPreference.setSummary(mContext.getString(R.string.battery_summary, mBatteryPercent));
+ } else {
+ mPreference.setSummary(mContext.getString(R.string.no_battery_summary));
+ }
+ }
+
+ @VisibleForTesting
+ boolean isBatteryStatsAvailable() {
+ return mBatteryHelper != null && mSipper != null;
+ }
+
+ @VisibleForTesting
+ BatterySipper findTargetSipper(BatteryStatsHelper batteryHelper, int uid) {
+ final List<BatterySipper> usageList = batteryHelper.getUsageList();
+ for (int i = 0, size = usageList.size(); i < size; i++) {
+ final BatterySipper sipper = usageList.get(i);
+ if (sipper.getUid() == uid) {
+ return sipper;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceController.java b/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceController.java
new file mode 100644
index 0000000..61f3e46
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceController.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.app.LoaderManager;
+import android.content.Context;
+import android.content.Loader;
+import android.net.INetworkStatsService;
+import android.net.INetworkStatsSession;
+import android.net.NetworkTemplate;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.format.DateUtils;
+import android.text.format.Formatter;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.datausage.AppDataUsage;
+import com.android.settings.datausage.DataUsageList;
+import com.android.settings.datausage.DataUsageUtils;
+import com.android.settingslib.AppItem;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnPause;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+import com.android.settingslib.net.ChartData;
+import com.android.settingslib.net.ChartDataLoader;
+
+public class AppDataUsagePreferenceController extends AppInfoPreferenceControllerBase
+ implements LoaderManager.LoaderCallbacks<ChartData>, LifecycleObserver, OnResume, OnPause {
+
+ private static final String KEY_DATA = "data_settings";
+ private ChartData mChartData;
+ private INetworkStatsSession mStatsSession;
+
+ public AppDataUsagePreferenceController(Context context, AppInfoDashboardFragment parent,
+ Lifecycle lifecycle) {
+ super(context, parent, KEY_DATA);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return isBandwidthControlEnabled() ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ if (isAvailable()) {
+ final INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
+ ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
+ try {
+ mStatsSession = statsService.openSession();
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setSummary(getDataSummary());
+ }
+
+ @Override
+ public void onResume() {
+ if (mStatsSession != null) {
+ final int uid = mParent.getAppEntry().info.uid;
+ final AppItem app = new AppItem(uid);
+ app.addUid(uid);
+ mParent.getLoaderManager().restartLoader(mParent.LOADER_CHART_DATA,
+ ChartDataLoader.buildArgs(getTemplate(mContext), app),
+ this);
+ }
+ }
+
+ @Override
+ public void onPause() {
+ mParent.getLoaderManager().destroyLoader(mParent.LOADER_CHART_DATA);
+ }
+
+ @Override
+ public Loader<ChartData> onCreateLoader(int id, Bundle args) {
+ return new ChartDataLoader(mContext, mStatsSession, args);
+ }
+
+ @Override
+ public void onLoadFinished(Loader<ChartData> loader, ChartData data) {
+ mChartData = data;
+ updateState(mPreference);
+ }
+
+ @Override
+ public void onLoaderReset(Loader<ChartData> loader) {
+ // Leave last result.
+ }
+
+ @Override
+ protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
+ return AppDataUsage.class;
+ }
+
+ private CharSequence getDataSummary() {
+ if (mChartData != null) {
+ final long totalBytes = mChartData.detail.getTotalBytes();
+ if (totalBytes == 0) {
+ return mContext.getString(R.string.no_data_usage);
+ }
+ return mContext.getString(R.string.data_summary_format,
+ Formatter.formatFileSize(mContext, totalBytes),
+ DateUtils.formatDateTime(mContext, mChartData.detail.getStart(),
+ DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH));
+ }
+ return mContext.getString(R.string.computing_size);
+ }
+
+ private static NetworkTemplate getTemplate(Context context) {
+ if (DataUsageList.hasReadyMobileRadio(context)) {
+ return NetworkTemplate.buildTemplateMobileWildcard();
+ }
+ if (DataUsageUtils.hasWifiRadio(context)) {
+ return NetworkTemplate.buildTemplateWifiWildcard();
+ }
+ return NetworkTemplate.buildTemplateEthernet();
+ }
+
+ @VisibleForTesting
+ boolean isBandwidthControlEnabled() {
+ return Utils.isBandwidthControlEnabled();
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBase.java b/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBase.java
new file mode 100644
index 0000000..0d6c038
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBase.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.app.slice.Slice;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.core.BasePreferenceController;
+
+/*
+ * Abstract base controller for the app detail preferences that refresh the state when the app state
+ * changes and launch a specific detail fragment when the preference is clicked.
+ */
+public abstract class AppInfoPreferenceControllerBase extends BasePreferenceController
+ implements AppInfoDashboardFragment.Callback {
+
+ protected final AppInfoDashboardFragment mParent;
+ private final Class<? extends SettingsPreferenceFragment> mDetailFragmenClass;
+
+ protected Preference mPreference;
+
+ public AppInfoPreferenceControllerBase(Context context, AppInfoDashboardFragment parent,
+ String preferenceKey) {
+ super(context, preferenceKey);
+ mParent = parent;
+ mDetailFragmenClass = getDetailFragmentClass();
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public Slice getSettingSlice() {
+ return null;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (TextUtils.equals(preference.getKey(), mPreferenceKey) && mDetailFragmenClass != null) {
+ AppInfoDashboardFragment.startAppInfoFragment(
+ mDetailFragmenClass, -1, mParent, mParent.getAppEntry());
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void refreshUi() {
+ updateState(mPreference);
+ }
+
+ /**
+ * Gets the fragment class to be launched when the preference is clicked.
+ * @return the fragment to launch
+ */
+ protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
+ return null;
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppMemoryPreferenceController.java b/src/com/android/settings/applications/appinfo/AppMemoryPreferenceController.java
new file mode 100644
index 0000000..2a20f80
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppMemoryPreferenceController.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.app.Activity;
+import android.app.slice.Slice;
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.os.AsyncTask;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.format.Formatter;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.ProcStatsData;
+import com.android.settings.applications.ProcStatsEntry;
+import com.android.settings.applications.ProcStatsPackageEntry;
+import com.android.settings.applications.ProcessStatsBase;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
+
+public class AppMemoryPreferenceController extends BasePreferenceController
+ implements LifecycleObserver, OnResume {
+
+ private static final String KEY_MEMORY = "memory";
+
+ private Preference mPreference;
+ private final AppInfoDashboardFragment mParent;
+ private ProcStatsData mStatsManager;
+ private ProcStatsPackageEntry mStats;
+
+ private class MemoryUpdater extends AsyncTask<Void, Void, ProcStatsPackageEntry> {
+
+ @Override
+ protected ProcStatsPackageEntry doInBackground(Void... params) {
+ final Activity activity = mParent.getActivity();
+ if (activity == null) {
+ return null;
+ }
+ PackageInfo packageInfo = mParent.getPackageInfo();
+ if (packageInfo == null) {
+ return null;
+ }
+ if (mStatsManager == null) {
+ mStatsManager = new ProcStatsData(activity, false);
+ mStatsManager.setDuration(ProcessStatsBase.sDurations[0]);
+ }
+ mStatsManager.refreshStats(true);
+ for (ProcStatsPackageEntry pkgEntry : mStatsManager.getEntries()) {
+ for (ProcStatsEntry entry : pkgEntry.getEntries()) {
+ if (entry.getUid() == packageInfo.applicationInfo.uid) {
+ pkgEntry.updateMetrics();
+ return pkgEntry;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(ProcStatsPackageEntry entry) {
+ if (mParent.getActivity() == null) {
+ return;
+ }
+ if (entry != null) {
+ mStats = entry;
+ mPreference.setEnabled(true);
+ double amount = Math.max(entry.getRunWeight(), entry.getBgWeight())
+ * mStatsManager.getMemInfo().getWeightToRam();
+ mPreference.setSummary(mContext.getString(R.string.memory_use_summary,
+ Formatter.formatShortFileSize(mContext, (long) amount)));
+ } else {
+ mPreference.setEnabled(false);
+ mPreference.setSummary(mContext.getString(R.string.no_memory_use_summary));
+ }
+ }
+ }
+
+ public AppMemoryPreferenceController(Context context, AppInfoDashboardFragment parent,
+ Lifecycle lifecycle) {
+ super(context, KEY_MEMORY);
+ mParent = parent;
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
+ ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
+ }
+
+ @Override
+ public Slice getSettingSlice() {
+ return null;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (KEY_MEMORY.equals(preference.getKey())) {
+ ProcessStatsBase.launchMemoryDetail((SettingsActivity) mParent.getActivity(),
+ mStatsManager.getMemInfo(), mStats, false);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onResume() {
+ if (isAvailable()) {
+ new MemoryUpdater().execute();
+ }
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
new file mode 100644
index 0000000..7eef370
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.notification.AppNotificationSettings;
+import com.android.settings.notification.NotificationBackend;
+import com.android.settingslib.applications.ApplicationsState;
+
+public class AppNotificationPreferenceController extends AppInfoPreferenceControllerBase {
+
+ private static final String KEY_NOTIFICATION = "notification_settings";
+
+ // Used for updating notification preference.
+ private final NotificationBackend mBackend = new NotificationBackend();
+
+ public AppNotificationPreferenceController(Context context, AppInfoDashboardFragment parent) {
+ super(context, parent, KEY_NOTIFICATION);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setSummary(getNotificationSummary(mParent.getAppEntry(), mContext, mBackend));
+ }
+
+ @Override
+ protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
+ return AppNotificationSettings.class;
+ }
+
+ private CharSequence getNotificationSummary(ApplicationsState.AppEntry appEntry,
+ Context context, NotificationBackend backend) {
+ NotificationBackend.AppRow appRow =
+ backend.loadAppRow(context, context.getPackageManager(), appEntry.info);
+ return getNotificationSummary(appRow, context);
+ }
+
+ public static CharSequence getNotificationSummary(NotificationBackend.AppRow appRow,
+ Context context) {
+ // TODO: implement summary when it is known what it should say
+ return "";
+ }
+}
diff --git a/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceController.java b/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceController.java
new file mode 100644
index 0000000..a56e3fb
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceController.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.hardware.usb.IUsbManager;
+import android.os.ServiceManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.AppLaunchSettings;
+import com.android.settingslib.applications.AppUtils;
+import com.android.settingslib.applications.ApplicationsState;
+
+public class AppOpenByDefaultPreferenceController extends AppInfoPreferenceControllerBase {
+
+ private static final String KEY_LAUNCH = "preferred_settings";
+
+ private IUsbManager mUsbManager;
+ private PackageManager mPackageManager;
+
+ public AppOpenByDefaultPreferenceController(Context context, AppInfoDashboardFragment parent) {
+ super(context, parent, KEY_LAUNCH);
+ mUsbManager = IUsbManager.Stub.asInterface(ServiceManager.getService(Context.USB_SERVICE));
+ mPackageManager = context.getPackageManager();
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ final ApplicationsState.AppEntry appEntry = mParent.getAppEntry();
+ if (appEntry == null || appEntry.info == null) {
+ mPreference.setEnabled(false);
+ } else if ((appEntry.info.flags& ApplicationInfo.FLAG_INSTALLED) == 0
+ || !appEntry.info.enabled) {
+ mPreference.setEnabled(false);
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final PackageInfo packageInfo = mParent.getPackageInfo();
+ if (packageInfo != null && !AppUtils.isInstant(packageInfo.applicationInfo)) {
+ preference.setVisible(true);
+ preference.setSummary(AppUtils.getLaunchByDefaultSummary(mParent.getAppEntry(),
+ mUsbManager, mPackageManager, mContext));
+ } else {
+ preference.setVisible(false);
+ }
+ }
+
+ @Override
+ protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
+ return AppLaunchSettings.class;
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppPermissionPreferenceController.java b/src/com/android/settings/applications/appinfo/AppPermissionPreferenceController.java
new file mode 100644
index 0000000..bd309c6
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppPermissionPreferenceController.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.icu.text.ListFormatter;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.util.Log;
+
+import com.android.settings.R;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settingslib.applications.PermissionsSummaryHelper;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AppPermissionPreferenceController extends AppInfoPreferenceControllerBase {
+
+ private static final String TAG = "PermissionPrefControl";
+ private static final String KEY_PERMISSION = "permission_settings";
+ private static final String EXTRA_HIDE_INFO_BUTTON = "hideInfoButton";
+
+ private final String mPackageName;
+
+ @VisibleForTesting
+ final PermissionsSummaryHelper.PermissionsResultCallback mPermissionCallback
+ = new PermissionsSummaryHelper.PermissionsResultCallback() {
+ @Override
+ public void onPermissionSummaryResult(int standardGrantedPermissionCount,
+ int requestedPermissionCount, int additionalGrantedPermissionCount,
+ List<CharSequence> grantedGroupLabels) {
+ if (mParent.getActivity() == null) {
+ return;
+ }
+ final Resources res = mContext.getResources();
+ CharSequence summary = null;
+
+ if (requestedPermissionCount == 0) {
+ summary = res.getString(
+ R.string.runtime_permissions_summary_no_permissions_requested);
+ mPreference.setEnabled(false);
+ } else {
+ final ArrayList<CharSequence> list = new ArrayList<>(grantedGroupLabels);
+ if (additionalGrantedPermissionCount > 0) {
+ // N additional permissions.
+ list.add(res.getQuantityString(
+ R.plurals.runtime_permissions_additional_count,
+ additionalGrantedPermissionCount, additionalGrantedPermissionCount));
+ }
+ if (list.size() == 0) {
+ summary = res.getString(
+ R.string.runtime_permissions_summary_no_permissions_granted);
+ } else {
+ summary = ListFormatter.getInstance().format(list);
+ }
+ mPreference.setEnabled(true);
+ }
+ mPreference.setSummary(summary);
+ }
+ };
+
+ public AppPermissionPreferenceController(Context context, AppInfoDashboardFragment parent,
+ String packageName) {
+ super(context, parent, KEY_PERMISSION);
+ mPackageName = packageName;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ PermissionsSummaryHelper.getPermissionSummary(mContext, mPackageName, mPermissionCallback);
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (KEY_PERMISSION.equals(preference.getKey())) {
+ startManagePermissionsActivity();
+ return true;
+ }
+ return false;
+ }
+
+ private void startManagePermissionsActivity() {
+ // start new activity to manage app permissions
+ final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
+ intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mParent.getAppEntry().info.packageName);
+ intent.putExtra(EXTRA_HIDE_INFO_BUTTON, true);
+ try {
+ mParent.getActivity().startActivityForResult(intent, mParent.SUB_INFO_FRAGMENT);
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
+ }
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppStoragePreferenceController.java b/src/com/android/settings/applications/appinfo/AppStoragePreferenceController.java
new file mode 100644
index 0000000..d737288
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppStoragePreferenceController.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.app.LoaderManager;
+import android.content.Context;
+import android.content.Loader;
+import android.content.pm.ApplicationInfo;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.text.format.Formatter;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.AppStorageSettings;
+import com.android.settings.applications.FetchPackageStorageAsyncLoader;
+import com.android.settingslib.applications.StorageStatsSource;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnPause;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class AppStoragePreferenceController extends AppInfoPreferenceControllerBase
+ implements LoaderManager.LoaderCallbacks<StorageStatsSource.AppStorageStats>,
+ LifecycleObserver, OnResume, OnPause {
+
+ private static final String KEY_STORAGE = "storage_settings";
+ private StorageStatsSource.AppStorageStats mLastResult;
+
+ public AppStoragePreferenceController(Context context, AppInfoDashboardFragment parent,
+ Lifecycle lifecycle) {
+ super(context, parent, KEY_STORAGE);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final boolean isExternal =
+ (mParent.getAppEntry().info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
+ preference.setSummary(getStorageSummary(mLastResult, isExternal));
+ }
+
+ @Override
+ public void onResume() {
+ mParent.getLoaderManager().restartLoader(mParent.LOADER_STORAGE, Bundle.EMPTY, this);
+ }
+
+ @Override
+ public void onPause() {
+ mParent.getLoaderManager().destroyLoader(mParent.LOADER_STORAGE);
+ }
+
+ @Override
+ protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
+ return AppStorageSettings.class;
+ }
+
+ @VisibleForTesting
+ CharSequence getStorageSummary(
+ StorageStatsSource.AppStorageStats stats, boolean isExternal) {
+ if (stats == null) {
+ return mContext.getText(R.string.computing_size);
+ }
+ final CharSequence storageType = mContext.getString(isExternal
+ ? R.string.storage_type_external
+ : R.string.storage_type_internal);
+ return mContext.getString(R.string.storage_summary_format,
+ Formatter.formatFileSize(mContext, stats.getTotalBytes()),
+ storageType.toString().toLowerCase());
+ }
+
+ @Override
+ public Loader<StorageStatsSource.AppStorageStats> onCreateLoader(int id, Bundle args) {
+ return new FetchPackageStorageAsyncLoader(mContext, new StorageStatsSource(mContext),
+ mParent.getAppEntry().info, UserHandle.of(UserHandle.myUserId()));
+ }
+
+ @Override
+ public void onLoadFinished(Loader<StorageStatsSource.AppStorageStats> loader,
+ StorageStatsSource.AppStorageStats result) {
+ mLastResult = result;
+ updateState(mPreference);
+ }
+
+ @Override
+ public void onLoaderReset(Loader<StorageStatsSource.AppStorageStats> loader) {
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppVersionPreferenceController.java b/src/com/android/settings/applications/appinfo/AppVersionPreferenceController.java
new file mode 100644
index 0000000..82719f7
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/AppVersionPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.text.BidiFormatter;
+
+import com.android.settings.R;
+import com.android.settings.applications.AppInfoDashboardFragment;
+
+public class AppVersionPreferenceController extends AppInfoPreferenceControllerBase {
+
+ private static final String KEY_VERSION = "app_version";
+
+ public AppVersionPreferenceController(Context context, AppInfoDashboardFragment parent) {
+ super(context, parent, KEY_VERSION);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setSummary(mContext.getString(R.string.version_text,
+ BidiFormatter.getInstance().unicodeWrap(mParent.getPackageInfo().versionName)));
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
new file mode 100644
index 0000000..3311daa
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.app.slice.Slice;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.text.TextUtils;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.Utils;
+import com.android.settings.applications.DefaultAppSettings;
+import com.android.settings.core.BasePreferenceController;
+
+/*
+ * Abstract base controller for the default app shortcut preferences that launches the default app
+ * settings with the corresponding default app highlighted.
+ */
+public abstract class DefaultAppShortcutPreferenceControllerBase extends BasePreferenceController {
+
+ protected final String mPackageName;
+
+ public DefaultAppShortcutPreferenceControllerBase(Context context, String preferenceKey,
+ String packageName) {
+ super(context, preferenceKey);
+ mPackageName = packageName;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (UserManager.get(mContext).isManagedProfile()) {
+ return DISABLED_FOR_USER;
+ }
+ return hasAppCapability() ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ @Override
+ public Slice getSettingSlice() {
+ return null;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setSummary(isDefaultApp() ? R.string.yes : R.string.no);
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (TextUtils.equals(mPreferenceKey, preference.getKey())) {
+ Bundle bundle = new Bundle();
+ bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mPreferenceKey);
+ Utils.startWithFragment(mContext, DefaultAppSettings.class.getName(), bundle, null, 0,
+ R.string.configure_apps, null, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Check whether the app has the default app capability
+ * @return true if the app has the default app capability
+ */
+ protected abstract boolean hasAppCapability();
+
+ /**
+ * Check whether the app is the default app
+ * @return true if the app is the default app
+ */
+ protected abstract boolean isDefaultApp();
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java
new file mode 100644
index 0000000..64af3c2
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+import android.os.UserHandle;
+
+import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
+
+public class DefaultBrowserShortcutPreferenceController
+ extends DefaultAppShortcutPreferenceControllerBase {
+
+ private static final String KEY = "default_browser";
+
+ public DefaultBrowserShortcutPreferenceController(Context context, String packageName) {
+ super(context, KEY, packageName);
+ }
+
+ @Override
+ protected boolean hasAppCapability() {
+ return DefaultBrowserPreferenceController.hasBrowserPreference(mPackageName, mContext);
+ }
+
+ @Override
+ protected boolean isDefaultApp() {
+ return new DefaultBrowserPreferenceController(mContext)
+ .isBrowserDefault(mPackageName, UserHandle.myUserId());
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceController.java
new file mode 100644
index 0000000..f0c1b8a
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
+
+public class DefaultEmergencyShortcutPreferenceController
+ extends DefaultAppShortcutPreferenceControllerBase {
+
+ private static final String KEY = "default_emergency_app";
+
+ public DefaultEmergencyShortcutPreferenceController(Context context, String packageName) {
+ super(context, KEY, packageName);
+ }
+
+ @Override
+ protected boolean hasAppCapability() {
+ return DefaultEmergencyPreferenceController.hasEmergencyPreference(mPackageName, mContext);
+ }
+
+ @Override
+ protected boolean isDefaultApp() {
+ return DefaultEmergencyPreferenceController.isEmergencyDefault(mPackageName, mContext);
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceController.java
new file mode 100644
index 0000000..4ae9083
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceController.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
+import com.android.settingslib.wrapper.PackageManagerWrapper;
+
+public class DefaultHomeShortcutPreferenceController
+ extends DefaultAppShortcutPreferenceControllerBase {
+
+ private static final String KEY = "default_home";
+
+ public DefaultHomeShortcutPreferenceController(Context context, String packageName) {
+ super(context, KEY, packageName);
+ }
+
+ @Override
+ protected boolean hasAppCapability() {
+ return DefaultHomePreferenceController.hasHomePreference(mPackageName, mContext);
+ }
+
+ @Override
+ protected boolean isDefaultApp() {
+ return DefaultHomePreferenceController.isHomeDefault(mPackageName,
+ new PackageManagerWrapper(mContext.getPackageManager()));
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceController.java
new file mode 100644
index 0000000..c968d55
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
+
+public class DefaultPhoneShortcutPreferenceController
+ extends DefaultAppShortcutPreferenceControllerBase {
+
+ private static final String KEY = "default_phone_app";
+
+ public DefaultPhoneShortcutPreferenceController(Context context, String packageName) {
+ super(context, KEY, packageName);
+ }
+
+ @Override
+ protected boolean hasAppCapability() {
+ return DefaultPhonePreferenceController.hasPhonePreference(mPackageName, mContext);
+ }
+
+ @Override
+ protected boolean isDefaultApp() {
+ return DefaultPhonePreferenceController.isPhoneDefault(mPackageName, mContext);
+ }
+
+}
diff --git a/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceController.java
new file mode 100644
index 0000000..cf8b446
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceController.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import android.content.Context;
+
+import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
+
+public class DefaultSmsShortcutPreferenceController
+ extends DefaultAppShortcutPreferenceControllerBase {
+
+ private static final String KEY = "default_sms_app";
+
+ public DefaultSmsShortcutPreferenceController(Context context, String packageName) {
+ super(context, KEY, packageName);
+ }
+
+ @Override
+ protected boolean hasAppCapability() {
+ return DefaultSmsPreferenceController.hasSmsPreference(mPackageName, mContext);
+ }
+
+ @Override
+ protected boolean isDefaultApp() {
+ return DefaultSmsPreferenceController.isSmsDefault(mPackageName, mContext);
+ }
+
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index f95145d..87fa43d 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -23,7 +23,6 @@
import android.content.IntentFilter;
import android.os.UserManager;
import android.provider.Settings;
-import android.widget.Switch;
import android.widget.Toast;
import com.android.internal.annotations.VisibleForTesting;
@@ -41,8 +40,7 @@
* preference reflects the current state.
*/
public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchChangeListener {
- private final Switch mSwitch;
- private final SwitchWidgetController mSwitchWidget;
+ private final SwitchWidgetController mSwitchController;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private Context mContext;
private boolean mValidListener;
@@ -64,28 +62,27 @@
}
};
- public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+ public BluetoothEnabler(Context context, SwitchWidgetController switchController,
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
int metricsEvent) {
- this(context, switchWidget, metricsFeatureProvider, manager, metricsEvent,
+ this(context, switchController, metricsFeatureProvider, manager, metricsEvent,
new RestrictionUtils());
}
- public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+ public BluetoothEnabler(Context context, SwitchWidgetController switchController,
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
int metricsEvent, RestrictionUtils restrictionUtils) {
mContext = context;
mMetricsFeatureProvider = metricsFeatureProvider;
- mSwitchWidget = switchWidget;
- mSwitch = mSwitchWidget.getSwitch();
- mSwitchWidget.setListener(this);
+ mSwitchController = switchController;
+ mSwitchController.setListener(this);
mValidListener = false;
mMetricsEvent = metricsEvent;
if (manager == null) {
// Bluetooth is not supported
mLocalAdapter = null;
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
} else {
mLocalAdapter = manager.getBluetoothAdapter();
}
@@ -94,11 +91,11 @@
}
public void setupSwitchController() {
- mSwitchWidget.setupView();
+ mSwitchController.setupView();
}
public void teardownSwitchController() {
- mSwitchWidget.teardownView();
+ mSwitchController.teardownView();
}
public void resume(Context context) {
@@ -109,7 +106,7 @@
final boolean restricted = maybeEnforceRestrictions();
if (mLocalAdapter == null) {
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
return;
}
@@ -118,7 +115,7 @@
handleStateChanged(mLocalAdapter.getBluetoothState());
}
- mSwitchWidget.startListening();
+ mSwitchController.startListening();
mContext.registerReceiver(mReceiver, mIntentFilter);
mValidListener = true;
}
@@ -128,7 +125,7 @@
return;
}
if (mValidListener) {
- mSwitchWidget.stopListening();
+ mSwitchController.stopListening();
mContext.unregisterReceiver(mReceiver);
mValidListener = false;
}
@@ -137,37 +134,35 @@
void handleStateChanged(int state) {
switch (state) {
case BluetoothAdapter.STATE_TURNING_ON:
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
break;
case BluetoothAdapter.STATE_ON:
setChecked(true);
- mSwitchWidget.setEnabled(true);
+ mSwitchController.setEnabled(true);
break;
case BluetoothAdapter.STATE_TURNING_OFF:
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
break;
case BluetoothAdapter.STATE_OFF:
setChecked(false);
- mSwitchWidget.setEnabled(true);
+ mSwitchController.setEnabled(true);
break;
default:
setChecked(false);
- mSwitchWidget.setEnabled(true);
+ mSwitchController.setEnabled(true);
}
}
private void setChecked(boolean isChecked) {
- final boolean currentState =
- (mSwitchWidget.getSwitch() != null) && mSwitchWidget.getSwitch().isChecked();
- if (isChecked != currentState) {
+ if (isChecked != mSwitchController.isChecked()) {
// set listener to null, so onCheckedChanged won't be called
// if the checked status on Switch isn't changed by user click
if (mValidListener) {
- mSwitchWidget.stopListening();
+ mSwitchController.stopListening();
}
- mSwitchWidget.setChecked(isChecked);
+ mSwitchController.setChecked(isChecked);
if (mValidListener) {
- mSwitchWidget.startListening();
+ mSwitchController.startListening();
}
}
}
@@ -183,7 +178,7 @@
!WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_BLUETOOTH)) {
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
// Reset switch to off
- mSwitch.setChecked(false);
+ mSwitchController.setChecked(false);
return false;
}
@@ -195,13 +190,13 @@
// a) The switch should be OFF but it should still be togglable (enabled = True)
// b) The switch bar should have OFF text.
if (isChecked && !status) {
- mSwitch.setChecked(false);
- mSwitch.setEnabled(true);
- mSwitchWidget.updateTitle(false);
+ mSwitchController.setChecked(false);
+ mSwitchController.setEnabled(true);
+ mSwitchController.updateTitle(false);
return false;
}
}
- mSwitchWidget.setEnabled(false);
+ mSwitchController.setEnabled(false);
return true;
}
@@ -213,13 +208,10 @@
@VisibleForTesting
boolean maybeEnforceRestrictions() {
EnforcedAdmin admin = getEnforcedAdmin(mRestrictionUtils, mContext);
- mSwitchWidget.setDisabledByAdmin(admin);
+ mSwitchController.setDisabledByAdmin(admin);
if (admin != null) {
- mSwitchWidget.setChecked(false);
- if (mSwitch != null) {
- mSwitch.setEnabled(false);
- mSwitch.setChecked(false);
- }
+ mSwitchController.setChecked(false);
+ mSwitchController.setEnabled(false);
}
return admin != null;
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingController.java b/src/com/android/settings/bluetooth/BluetoothPairingController.java
index ce82612..7d2d7b4 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingController.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingController.java
@@ -172,6 +172,22 @@
}
/**
+ * Update Phone book permission
+ *
+ */
+ public void setContactSharingState() {
+ if ((mDevice.getPhonebookAccessPermission() != BluetoothDevice.ACCESS_ALLOWED)
+ && (mDevice.getPhonebookAccessPermission() != BluetoothDevice.ACCESS_REJECTED)) {
+ if (mDevice.getBluetoothClass().getDeviceClass()
+ == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) {
+ onCheckedChanged(null, true);
+ } else {
+ onCheckedChanged(null, false);
+ }
+ }
+ }
+
+ /**
* A method for querying if the provided editable is a valid passkey/pin format for this device.
*
* @param s - The passkey/pin
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDetail.java b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
index 60011f9..a9756a6 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
@@ -73,10 +73,20 @@
public void onStart() {
super.onStart();
- updateContent(mLocalAdapter.getBluetoothState());
+ updateBluetooth();
mAvailableDevicesCategory.setProgress(mLocalAdapter.isDiscovering());
}
+ @VisibleForTesting
+ void updateBluetooth() {
+ if (mLocalAdapter.isEnabled()) {
+ updateContent(mLocalAdapter.getBluetoothState());
+ } else {
+ // Turn on bluetooth if it is disabled
+ mLocalAdapter.enable();
+ }
+ }
+
@Override
public void onStop() {
super.onStop();
@@ -169,7 +179,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_bluetooth;
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
index 1aac0ff..18839dc 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
@@ -241,6 +241,7 @@
contactSharing.setVisibility(mPairingController.isProfileReady()
? View.GONE : View.VISIBLE);
+ mPairingController.setContactSharingState();
contactSharing.setOnCheckedChangeListener(mPairingController);
contactSharing.setChecked(mPairingController.getContactSharingState());
@@ -331,6 +332,7 @@
contactSharing.setVisibility(
mPairingController.isProfileReady() ? View.GONE : View.VISIBLE);
+ mPairingController.setContactSharingState();
contactSharing.setChecked(mPairingController.getContactSharingState());
contactSharing.setOnCheckedChangeListener(mPairingController);
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 9789310..72d8023 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -345,7 +345,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_bluetooth;
}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 8b0e568..e9ae11e 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -48,7 +48,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_connected_devices;
}
@@ -64,8 +64,8 @@
controllers.add(new ConnectedDeviceGroupController(this, lifecycle));
controllers.add(new SavedDeviceGroupController(this, lifecycle));
- return controllers;
+ return controllers;
}
@VisibleForTesting
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentOld.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentOld.java
index 6a8f26d..7097b36 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentOld.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentOld.java
@@ -62,7 +62,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_connected_devices;
}
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index 444cbe9..b3d9878 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -70,7 +70,7 @@
*/
public static final int UNAVAILABLE_UNKNOWN = 4;
- private final String mPreferenceKey;
+ protected final String mPreferenceKey;
public BasePreferenceController(Context context, String preferenceKey) {
super(context);
diff --git a/src/com/android/settings/datausage/DataPlanUsageSummary.java b/src/com/android/settings/datausage/DataPlanUsageSummary.java
index 912db0a..a56bfa1 100644
--- a/src/com/android/settings/datausage/DataPlanUsageSummary.java
+++ b/src/com/android/settings/datausage/DataPlanUsageSummary.java
@@ -74,7 +74,7 @@
private NetworkPolicyEditor mPolicyEditor;
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_data_usage;
}
diff --git a/src/com/android/settings/datausage/DataSaverSummary.java b/src/com/android/settings/datausage/DataSaverSummary.java
index c623395..4ada3af 100644
--- a/src/com/android/settings/datausage/DataSaverSummary.java
+++ b/src/com/android/settings/datausage/DataSaverSummary.java
@@ -105,7 +105,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_data_saver;
}
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 6fddb2b..fe22022 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -91,7 +91,7 @@
private NetworkPolicyEditor mPolicyEditor;
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_data_usage;
}
diff --git a/src/com/android/settings/datausage/UnrestrictedDataAccess.java b/src/com/android/settings/datausage/UnrestrictedDataAccess.java
index b382b8c..5b55ada 100644
--- a/src/com/android/settings/datausage/UnrestrictedDataAccess.java
+++ b/src/com/android/settings/datausage/UnrestrictedDataAccess.java
@@ -133,7 +133,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_unrestricted_data_access;
}
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index e38317a..cb9e750 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -137,7 +137,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_storage;
}
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 237f9ba..8f114fc 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -292,7 +292,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return 0;
}
diff --git a/src/com/android/settings/development/featureflags/FeatureFlagsDashboard.java b/src/com/android/settings/development/featureflags/FeatureFlagsDashboard.java
index c482d87..8f37c67 100644
--- a/src/com/android/settings/development/featureflags/FeatureFlagsDashboard.java
+++ b/src/com/android/settings/development/featureflags/FeatureFlagsDashboard.java
@@ -46,7 +46,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return 0;
}
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 5b9b375..341c76f 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -117,7 +117,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_storage_dashboard;
}
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index e9d3c85..0f88b4a 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -100,7 +100,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_storage;
}
diff --git a/src/com/android/settings/display/NightDisplayPreferenceController.java b/src/com/android/settings/display/NightDisplayPreferenceController.java
index 643f1d4..2761eca 100644
--- a/src/com/android/settings/display/NightDisplayPreferenceController.java
+++ b/src/com/android/settings/display/NightDisplayPreferenceController.java
@@ -37,4 +37,4 @@
public String getPreferenceKey() {
return KEY_NIGHT_DISPLAY;
}
-}
+}
\ No newline at end of file
diff --git a/src/com/android/settings/display/NightDisplaySettings.java b/src/com/android/settings/display/NightDisplaySettings.java
index ab94720..4e0ebcd 100644
--- a/src/com/android/settings/display/NightDisplaySettings.java
+++ b/src/com/android/settings/display/NightDisplaySettings.java
@@ -20,27 +20,34 @@
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
+import android.provider.SearchIndexableResource;
import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.TwoStatePreference;
-import android.widget.TimePicker;
import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
import com.android.settings.widget.SeekBarPreference;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settingslib.core.AbstractPreferenceController;
import java.text.DateFormat;
import java.time.LocalTime;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.List;
import java.util.TimeZone;
/**
* Settings screen for Night display.
+ * TODO (b/69912911) Upgrade to Dashboard fragment
*/
public class NightDisplaySettings extends SettingsPreferenceFragment
- implements ColorDisplayController.Callback, Preference.OnPreferenceChangeListener {
+ implements ColorDisplayController.Callback, Preference.OnPreferenceChangeListener,
+ Indexable {
private static final String KEY_NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode";
private static final String KEY_NIGHT_DISPLAY_START_TIME = "night_display_start_time";
@@ -75,7 +82,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_night_display;
}
@@ -92,12 +99,12 @@
mActivatedPreference = (TwoStatePreference) findPreference(KEY_NIGHT_DISPLAY_ACTIVATED);
mTemperaturePreference = (SeekBarPreference) findPreference(KEY_NIGHT_DISPLAY_TEMPERATURE);
- mAutoModePreference.setEntries(new CharSequence[] {
+ mAutoModePreference.setEntries(new CharSequence[]{
getString(R.string.night_display_auto_mode_never),
getString(R.string.night_display_auto_mode_custom),
getString(R.string.night_display_auto_mode_twilight)
});
- mAutoModePreference.setEntryValues(new CharSequence[] {
+ mAutoModePreference.setEntryValues(new CharSequence[]{
String.valueOf(ColorDisplayController.AUTO_MODE_DISABLED),
String.valueOf(ColorDisplayController.AUTO_MODE_CUSTOM),
String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT)
@@ -155,15 +162,12 @@
final Context context = getContext();
final boolean use24HourFormat = android.text.format.DateFormat.is24HourFormat(context);
- return new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
- @Override
- public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
- final LocalTime time = LocalTime.of(hourOfDay, minute);
- if (dialogId == DIALOG_START_TIME) {
- mController.setCustomStartTime(time);
- } else {
- mController.setCustomEndTime(time);
- }
+ return new TimePickerDialog(context, (view, hourOfDay, minute) -> {
+ final LocalTime time = LocalTime.of(hourOfDay, minute);
+ if (dialogId == DIALOG_START_TIME) {
+ mController.setCustomStartTime(time);
+ } else {
+ mController.setCustomEndTime(time);
}
}, initialTime.getHour(), initialTime.getMinute(), use24HourFormat);
}
@@ -247,4 +251,23 @@
public int getMetricsCategory() {
return MetricsEvent.NIGHT_DISPLAY_SETTINGS;
}
+
+ public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.night_display_settings;
+ result.add(sir);
+ return result;
+ }
+
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ return ColorDisplayController.isAvailable(context);
+ }
+ };
}
diff --git a/src/com/android/settings/dream/DreamSettings.java b/src/com/android/settings/dream/DreamSettings.java
index 94ec149..c3eaa7f 100644
--- a/src/com/android/settings/dream/DreamSettings.java
+++ b/src/com/android/settings/dream/DreamSettings.java
@@ -99,7 +99,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_screen_saver;
}
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index fb09f7a..ad7f83a 100644
--- a/src/com/android/settings/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/fingerprint/FingerprintSettings.java
@@ -545,7 +545,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_fingerprint;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index dd8c169..bf3cc64 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -340,7 +340,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_battery;
}
diff --git a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
index deffa97..5412f36 100644
--- a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
+++ b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java
@@ -22,6 +22,7 @@
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.v7.preference.Preference;
+import android.support.annotation.VisibleForTesting;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.R;
@@ -55,8 +56,13 @@
}
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
- AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context);
- return !ambientConfig.pulseOnDoubleTapAvailable()
+ return isSuggestionComplete(new AmbientDisplayConfiguration(context), prefs);
+ }
+
+ @VisibleForTesting
+ static boolean isSuggestionComplete(AmbientDisplayConfiguration config,
+ SharedPreferences prefs) {
+ return !config.pulseOnDoubleTapAvailable()
|| prefs.getBoolean(DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, false);
}
diff --git a/src/com/android/settings/gestures/DoubleTapScreenSettings.java b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
index c0cd453e..f2148b4 100644
--- a/src/com/android/settings/gestures/DoubleTapScreenSettings.java
+++ b/src/com/android/settings/gestures/DoubleTapScreenSettings.java
@@ -68,7 +68,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_double_tap_screen;
}
diff --git a/src/com/android/settings/gestures/PickupGesturePreferenceController.java b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
index 314cbc3..02107c1 100644
--- a/src/com/android/settings/gestures/PickupGesturePreferenceController.java
+++ b/src/com/android/settings/gestures/PickupGesturePreferenceController.java
@@ -24,6 +24,7 @@
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.v7.preference.Preference;
+import android.support.annotation.VisibleForTesting;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.R;
@@ -90,7 +91,7 @@
@Override
public boolean canHandleClicks() {
- return mAmbientConfig.pulseOnPickupCanBeModified(mUserId);
+ return pulseOnPickupCanBeModified();
}
@Override
@@ -102,4 +103,9 @@
return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE,
ON /* onValue */, intent, isAvailable(), ON /* defaultValue */);
}
+
+ @VisibleForTesting
+ boolean pulseOnPickupCanBeModified() {
+ return mAmbientConfig.pulseOnPickupCanBeModified(mUserId);
+ }
}
diff --git a/src/com/android/settings/gestures/PickupGestureSettings.java b/src/com/android/settings/gestures/PickupGestureSettings.java
index a4f1776..1762ba8 100644
--- a/src/com/android/settings/gestures/PickupGestureSettings.java
+++ b/src/com/android/settings/gestures/PickupGestureSettings.java
@@ -68,7 +68,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_pickup_gesture;
}
diff --git a/src/com/android/settings/network/AirplaneModePreferenceController.java b/src/com/android/settings/network/AirplaneModePreferenceController.java
index 0620f14..d86f7f7 100644
--- a/src/com/android/settings/network/AirplaneModePreferenceController.java
+++ b/src/com/android/settings/network/AirplaneModePreferenceController.java
@@ -100,12 +100,16 @@
}
public void onResume() {
- mAirplaneModeEnabler.resume();
+ if (mAirplaneModeEnabler != null) {
+ mAirplaneModeEnabler.resume();
+ }
}
@Override
public void onPause() {
- mAirplaneModeEnabler.pause();
+ if (mAirplaneModeEnabler != null) {
+ mAirplaneModeEnabler.pause();
+ }
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 2a04d27..4b1da31 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -78,7 +78,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_network_dashboard;
}
diff --git a/src/com/android/settings/notification/AbstractZenModePreferenceController.java b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
index ec275b2..de2e8fd 100644
--- a/src/com/android/settings/notification/AbstractZenModePreferenceController.java
+++ b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
@@ -22,10 +22,12 @@
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
+import android.os.UserHandle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -37,7 +39,8 @@
AbstractPreferenceController implements PreferenceControllerMixin, LifecycleObserver,
OnResume, OnPause {
- private SettingObserver mSettingObserver;
+ @VisibleForTesting
+ protected SettingObserver mSettingObserver;
private final String KEY;
final private NotificationManager mNotificationManager;
@@ -94,8 +97,8 @@
}
public void register(ContentResolver cr) {
- cr.registerContentObserver(ZEN_MODE_URI, false, this);
- cr.registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this);
+ cr.registerContentObserver(ZEN_MODE_URI, false, this, UserHandle.USER_ALL);
+ cr.registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this, UserHandle.USER_ALL);
}
public void unregister(ContentResolver cr) {
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index a724338..6e998f6 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -71,7 +71,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_sound;
}
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index fbc9f7d..22d6fca 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -54,7 +54,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_interruptions;
}
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index a694603..e5ba200 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -753,7 +753,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_choose_lockscreen;
}
diff --git a/src/com/android/settings/print/PrintSettingsFragment.java b/src/com/android/settings/print/PrintSettingsFragment.java
index 6bdce48..56bebcc 100644
--- a/src/com/android/settings/print/PrintSettingsFragment.java
+++ b/src/com/android/settings/print/PrintSettingsFragment.java
@@ -98,7 +98,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_printing;
}
diff --git a/src/com/android/settings/search/IndexDatabaseHelper.java b/src/com/android/settings/search/IndexDatabaseHelper.java
index 19e3419..7073545 100644
--- a/src/com/android/settings/search/IndexDatabaseHelper.java
+++ b/src/com/android/settings/search/IndexDatabaseHelper.java
@@ -293,7 +293,8 @@
}
static void setBuildIndexed(Context context, String buildNo) {
- context.getSharedPreferences(SHARED_PREFS_TAG, 0).edit().putBoolean(buildNo, true).commit();
+ // Use #apply() instead of #commit() since #commit() Robolectric loop indefinitely in sdk 26
+ context.getSharedPreferences(SHARED_PREFS_TAG, 0).edit().putBoolean(buildNo, true).apply();
}
private void dropTables(SQLiteDatabase db) {
diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java
index d0c0cd9..437fc86 100644
--- a/src/com/android/settings/search/SearchFeatureProvider.java
+++ b/src/com/android/settings/search/SearchFeatureProvider.java
@@ -38,6 +38,8 @@
*/
public interface SearchFeatureProvider {
+ Intent SEARCH_UI_INTENT = new Intent("com.android.settings.action.SETTINGS_SEARCH");
+
/**
* Ensures the caller has necessary privilege to launch search result page.
*
@@ -165,6 +167,10 @@
return null;
}
+ default boolean isSearchV2Enabled(Context context) {
+ return FeatureFlagUtils.isEnabled(context, FeatureFlags.SEARCH_V2);
+ }
+
/**
* Initializes the search toolbar.
*/
@@ -174,8 +180,8 @@
}
toolbar.setOnClickListener(tb -> {
final Intent intent;
- if (FeatureFlagUtils.isEnabled(activity, FeatureFlags.SEARCH_V2)) {
- intent = new Intent("com.android.settings.action.SETTINGS_SEARCH");
+ if (isSearchV2Enabled(activity)) {
+ intent = SEARCH_UI_INTENT;
} else {
intent = new Intent(activity, SearchActivity.class);
}
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 82ab020..1f88872 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -42,6 +42,7 @@
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.display.AmbientDisplaySettings;
+import com.android.settings.display.NightDisplaySettings;
import com.android.settings.display.ScreenZoomSettings;
import com.android.settings.dream.DreamSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings;
@@ -170,6 +171,7 @@
addIndex(WifiDisplaySettings.class);
addIndex(ZenModeBehaviorSettings.class);
addIndex(ZenModeAutomationSettings.class);
+ addIndex(NightDisplaySettings.class);
}
private SearchIndexableResources() {
diff --git a/src/com/android/settings/search/SearchViewHolder.java b/src/com/android/settings/search/SearchViewHolder.java
index ed72940..7667a06 100644
--- a/src/com/android/settings/search/SearchViewHolder.java
+++ b/src/com/android/settings/search/SearchViewHolder.java
@@ -17,6 +17,7 @@
package com.android.settings.search;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
@@ -26,6 +27,7 @@
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
+import android.support.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
@@ -84,8 +86,7 @@
AppSearchResult appResult = (AppSearchResult) result;
PackageManager pm = fragment.getActivity().getPackageManager();
UserHandle userHandle = appResult.getAppUserHandle();
- Drawable badgedIcon =
- mIconDrawableFactory.getBadgedIcon(appResult.info, userHandle.getIdentifier());
+ Drawable badgedIcon = getBadgedIcon(appResult.info, userHandle.getIdentifier());
iconView.setImageDrawable(badgedIcon);
titleView.setContentDescription(
pm.getUserBadgedLabel(appResult.info.loadLabel(pm), userHandle));
@@ -112,4 +113,9 @@
breadcrumbView.setText(breadcrumb);
breadcrumbView.setVisibility(View.VISIBLE);
}
+
+ @VisibleForTesting
+ Drawable getBadgedIcon(ApplicationInfo info, int userId) {
+ return mIconDrawableFactory.getBadgedIcon(info, userId);
+ }
}
\ No newline at end of file
diff --git a/src/com/android/settings/search/actionbar/SearchMenuController.java b/src/com/android/settings/search/actionbar/SearchMenuController.java
new file mode 100644
index 0000000..28bde33
--- /dev/null
+++ b/src/com/android/settings/search/actionbar/SearchMenuController.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.search.actionbar;
+
+import android.annotation.NonNull;
+import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+import com.android.settings.R;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.search.SearchFeatureProvider;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
+import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu;
+
+public class SearchMenuController implements LifecycleObserver, OnCreateOptionsMenu {
+
+ public static final String NEED_SEARCH_ICON_IN_ACTION_BAR = "need_search_icon_in_action_bar";
+
+ private final Fragment mHost;
+
+ public static void init(@NonNull ObservablePreferenceFragment host) {
+ final Context context = host.getContext();
+ final boolean isSearchV2Enabled = FeatureFactory.getFactory(context)
+ .getSearchFeatureProvider()
+ .isSearchV2Enabled(context);
+
+ if (isSearchV2Enabled) {
+ host.getLifecycle().addObserver(new SearchMenuController(host));
+ }
+ }
+
+ private SearchMenuController(@NonNull Fragment host) {
+ mHost = host;
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ if (menu == null) {
+ return;
+ }
+ final Bundle arguments = mHost.getArguments();
+ if (arguments != null && !arguments.getBoolean(NEED_SEARCH_ICON_IN_ACTION_BAR, true)) {
+ return;
+ }
+ final MenuItem searchItem = menu.add(Menu.NONE, Menu.NONE, 0 /* order */,
+ R.string.search_menu);
+ searchItem.setIcon(R.drawable.ic_search_24dp);
+ searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+
+ searchItem.setOnMenuItemClickListener(target -> {
+ mHost.startActivityForResult(
+ SearchFeatureProvider.SEARCH_UI_INTENT, 0 /* requestCode */);
+ return true;
+ });
+ }
+}
diff --git a/src/com/android/settings/security/EncryptionAndCredential.java b/src/com/android/settings/security/EncryptionAndCredential.java
index 301742b..62f5a0c 100644
--- a/src/com/android/settings/security/EncryptionAndCredential.java
+++ b/src/com/android/settings/security/EncryptionAndCredential.java
@@ -76,7 +76,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_encryption;
}
diff --git a/src/com/android/settings/security/LockscreenDashboardFragment.java b/src/com/android/settings/security/LockscreenDashboardFragment.java
index 6ff2ca1..df4ca30 100644
--- a/src/com/android/settings/security/LockscreenDashboardFragment.java
+++ b/src/com/android/settings/security/LockscreenDashboardFragment.java
@@ -71,7 +71,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_lockscreen;
}
diff --git a/src/com/android/settings/security/ScreenPinningSettings.java b/src/com/android/settings/security/ScreenPinningSettings.java
index 488e0c8..6e4856e 100644
--- a/src/com/android/settings/security/ScreenPinningSettings.java
+++ b/src/com/android/settings/security/ScreenPinningSettings.java
@@ -78,7 +78,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_screen_pinning;
}
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index 01c138a..31f1ec6 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -749,7 +749,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_security;
}
diff --git a/src/com/android/settings/security/trustagent/TrustAgentSettings.java b/src/com/android/settings/security/trustagent/TrustAgentSettings.java
index c7001a0..b7f89ba 100644
--- a/src/com/android/settings/security/trustagent/TrustAgentSettings.java
+++ b/src/com/android/settings/security/trustagent/TrustAgentSettings.java
@@ -79,7 +79,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_trust_agent;
}
diff --git a/src/com/android/settings/support/actionbar/HelpMenuController.java b/src/com/android/settings/support/actionbar/HelpMenuController.java
new file mode 100644
index 0000000..a95d44e
--- /dev/null
+++ b/src/com/android/settings/support/actionbar/HelpMenuController.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.support.actionbar;
+
+import static com.android.settings.support.actionbar.HelpResourceProvider.HELP_URI_RESOURCE_KEY;
+
+import android.annotation.NonNull;
+import android.app.Activity;
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+
+import com.android.settingslib.HelpUtils;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
+import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu;
+
+/**
+ * A controller that adds help menu to any Settings page.
+ */
+public class HelpMenuController implements LifecycleObserver, OnCreateOptionsMenu {
+
+ private final Fragment mHost;
+
+ public static void init(@NonNull ObservablePreferenceFragment host) {
+ host.getLifecycle().addObserver(new HelpMenuController(host));
+ }
+
+ private HelpMenuController(@NonNull Fragment host) {
+ mHost = host;
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ final Bundle arguments = mHost.getArguments();
+ int helpResourceId = 0;
+ if (arguments != null && arguments.containsKey(HELP_URI_RESOURCE_KEY)) {
+ helpResourceId = arguments.getInt(HELP_URI_RESOURCE_KEY);
+ } else if (mHost instanceof HelpResourceProvider) {
+ helpResourceId = ((HelpResourceProvider) mHost).getHelpResource();
+ }
+
+ String helpUri = null;
+ if (helpResourceId != 0) {
+ helpUri = mHost.getContext().getString(helpResourceId);
+ }
+ final Activity activity = mHost.getActivity();
+ if (helpUri != null && activity != null) {
+ HelpUtils.prepareHelpMenuItem(activity, menu, helpUri, mHost.getClass().getName());
+ }
+ }
+}
diff --git a/src/com/android/settings/support/actionbar/HelpResourceProvider.java b/src/com/android/settings/support/actionbar/HelpResourceProvider.java
new file mode 100644
index 0000000..2898986
--- /dev/null
+++ b/src/com/android/settings/support/actionbar/HelpResourceProvider.java
@@ -0,0 +1,36 @@
+/*
+ * 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.support.actionbar;
+
+import com.android.settings.R;
+
+public interface HelpResourceProvider {
+ /**
+ * The Help Uri Resource key. This can be passed as an extra argument when creating the
+ * Fragment.
+ **/
+ String HELP_URI_RESOURCE_KEY = "help_uri_resource";
+
+ /**
+ * Override this if you want to show a help item in the menu, by returning the resource id.
+ *
+ * @return the resource id for the help url
+ */
+ default int getHelpResource() {
+ return R.string.help_uri_default;
+ }
+}
diff --git a/src/com/android/settings/system/SystemDashboardFragment.java b/src/com/android/settings/system/SystemDashboardFragment.java
index 2485cce..c01bfcc 100644
--- a/src/com/android/settings/system/SystemDashboardFragment.java
+++ b/src/com/android/settings/system/SystemDashboardFragment.java
@@ -56,7 +56,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_system_dashboard;
}
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index d40441f..0a3bfe6 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -401,7 +401,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_vpn;
}
diff --git a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
index a87249e..1ff1faa 100644
--- a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
+++ b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
@@ -43,7 +43,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_uri_wallpaper;
}
diff --git a/src/com/android/settings/wfd/WifiDisplaySettings.java b/src/com/android/settings/wfd/WifiDisplaySettings.java
index 5707e3e..7a9fc39 100755
--- a/src/com/android/settings/wfd/WifiDisplaySettings.java
+++ b/src/com/android/settings/wfd/WifiDisplaySettings.java
@@ -141,7 +141,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_remote_display;
}
diff --git a/src/com/android/settings/widget/MasterSwitchController.java b/src/com/android/settings/widget/MasterSwitchController.java
index f7253fd..a22640c 100644
--- a/src/com/android/settings/widget/MasterSwitchController.java
+++ b/src/com/android/settings/widget/MasterSwitchController.java
@@ -74,9 +74,4 @@
public void setDisabledByAdmin(EnforcedAdmin admin) {
mPreference.setDisabledByAdmin(admin);
}
-
- @Override
- public Switch getSwitch() {
- return mPreference.getSwitch();
- }
}
diff --git a/src/com/android/settings/widget/MasterSwitchPreference.java b/src/com/android/settings/widget/MasterSwitchPreference.java
index 29bc17b..d47de88 100644
--- a/src/com/android/settings/widget/MasterSwitchPreference.java
+++ b/src/com/android/settings/widget/MasterSwitchPreference.java
@@ -90,7 +90,7 @@
}
public boolean isChecked() {
- return mSwitch != null && mSwitch.isEnabled() && mChecked;
+ return mSwitch != null && mChecked;
}
public void setChecked(boolean checked) {
diff --git a/src/com/android/settings/widget/SwitchBarController.java b/src/com/android/settings/widget/SwitchBarController.java
index 624db2a..cc4c8dc 100644
--- a/src/com/android/settings/widget/SwitchBarController.java
+++ b/src/com/android/settings/widget/SwitchBarController.java
@@ -82,10 +82,4 @@
public void setDisabledByAdmin(EnforcedAdmin admin) {
mSwitchBar.setDisabledByAdmin(admin);
}
-
- @Override
- public Switch getSwitch() {
- return mSwitchBar.getSwitch();
- }
-
}
diff --git a/src/com/android/settings/widget/SwitchWidgetController.java b/src/com/android/settings/widget/SwitchWidgetController.java
index 325a093..6c4f40a 100644
--- a/src/com/android/settings/widget/SwitchWidgetController.java
+++ b/src/com/android/settings/widget/SwitchWidgetController.java
@@ -16,7 +16,6 @@
package com.android.settings.widget;
-import android.widget.Switch;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
/*
@@ -108,12 +107,4 @@
* is {@code null}, then this preference will be enabled. Otherwise, it will be disabled.
*/
public abstract void setDisabledByAdmin(EnforcedAdmin admin);
-
- /**
- * Get the underlying switch widget.
- *
- * @return the switch widget.
- */
- public abstract Switch getSwitch();
-
}
\ No newline at end of file
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index cc48064..30b6d96 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -1071,7 +1071,7 @@
}
@Override
- protected int getHelpResource() {
+ public int getHelpResource() {
return R.string.help_url_wifi;
}
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index ab1a2af..4d5b256 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -1,3 +1,4 @@
+com.android.settings.applications.AppInfoDashboardFragment
com.android.settings.bluetooth.DevicePickerFragment
com.android.settings.bluetooth.BluetoothDeviceDetailsFragment
com.android.settings.bluetooth.BluetoothPairingDetail
diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable
index 681e8f6..245d321 100644
--- a/tests/robotests/assets/grandfather_not_implementing_indexable
+++ b/tests/robotests/assets/grandfather_not_implementing_indexable
@@ -9,7 +9,6 @@
com.android.settings.deviceinfo.ImeiInformation
com.android.settings.datausage.DataUsageList
com.android.settings.vpn2.AppManagementFragment
-com.android.settings.display.NightDisplaySettings
com.android.settings.vpn2.VpnSettings
com.android.settings.fingerprint.FingerprintSettings$FingerprintSettingsFragment
com.android.settings.applications.ProcessStatsDetail
@@ -47,7 +46,6 @@
com.android.settings.applications.ConfirmConvertToFbe
com.android.settings.deviceinfo.PublicVolumeSettings
com.android.settings.applications.InstalledAppDetails
-com.android.settings.applications.AppInfoDashboardFragment
com.android.settings.accessibility.ToggleAccessibilityServicePreferenceFragment
com.android.settings.print.PrintServiceSettingsFragment
com.android.settings.deviceinfo.PrivateVolumeSettings
diff --git a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java b/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
index 56343e2..0bd8933 100644
--- a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
@@ -18,9 +18,7 @@
import static com.android.settings.DeviceInfoSettings.NON_SIM_PREFERENCES_COUNT;
import static com.android.settings.DeviceInfoSettings.SIM_PREFERENCES_COUNT;
-
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -34,10 +32,10 @@
import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
import android.util.FeatureFlagUtils;
-import android.view.View;
import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@@ -54,7 +52,6 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
import java.util.List;
@@ -81,6 +78,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest();
mContext = RuntimeEnvironment.application;
mSettings = spy(new DeviceInfoSettings());
diff --git a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
index c84c1c6..788d185 100644
--- a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
@@ -42,6 +42,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@@ -64,6 +65,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest();
mContext = RuntimeEnvironment.application;
mFragment = spy(new TestFragment());
doReturn(mActivity).when(mFragment).getActivity();
diff --git a/tests/robotests/src/com/android/settings/applications/AppInfoDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/AppInfoDashboardFragmentTest.java
new file mode 100644
index 0000000..97c4df0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/AppInfoDashboardFragmentTest.java
@@ -0,0 +1,460 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.AlertDialog;
+import android.app.AppOpsManager;
+import android.app.Fragment;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
+import android.view.View;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.instantapps.InstantAppButtonsController;
+import com.android.settings.applications.instantapps.InstantAppButtonsController.ShowDialogDelegate;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.widget.ActionButtonPreferenceTest;
+import com.android.settings.wrapper.DevicePolicyManagerWrapper;
+import com.android.settingslib.Utils;
+import com.android.settingslib.applications.AppUtils;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.HashSet;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(
+ manifest = TestConfig.MANIFEST_PATH,
+ sdk = TestConfig.SDK_VERSION_O
+)
+public final class AppInfoDashboardFragmentTest {
+
+ private static final String PACKAGE_NAME = "test_package_name";
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private UserManager mUserManager;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private SettingsActivity mActivity;
+ @Mock
+ private DevicePolicyManagerWrapper mDevicePolicyManager;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private AppOpsManager mAppOpsManager;
+
+ private FakeFeatureFactory mFeatureFactory;
+ private AppInfoDashboardFragment mAppDetail;
+ private Context mShadowContext;
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
+ mShadowContext = RuntimeEnvironment.application;
+ mAppDetail = spy(new AppInfoDashboardFragment());
+ doReturn(mActivity).when(mAppDetail).getActivity();
+ doReturn(mShadowContext).when(mAppDetail).getContext();
+ doReturn(mPackageManager).when(mActivity).getPackageManager();
+ doReturn(mAppOpsManager).when(mActivity).getSystemService(Context.APP_OPS_SERVICE);
+ mAppDetail.mActionButtons = ActionButtonPreferenceTest.createMock();
+
+ // Default to not considering any apps to be instant (individual tests can override this).
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> false));
+ }
+
+ @Test
+ public void shouldShowUninstallForAll_installForOneOtherUserOnly_shouldReturnTrue() {
+ when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
+ when(mUserManager.getUsers().size()).thenReturn(2);
+ ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
+ ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
+ final ApplicationInfo info = new ApplicationInfo();
+ info.enabled = true;
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+
+ assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isTrue();
+ }
+
+ @Test
+ public void shouldShowUninstallForAll_installForSelfOnly_shouldReturnFalse() {
+ when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
+ when(mUserManager.getUsers().size()).thenReturn(2);
+ ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
+ ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
+ final ApplicationInfo info = new ApplicationInfo();
+ info.flags = ApplicationInfo.FLAG_INSTALLED;
+ info.enabled = true;
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+
+ assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isFalse();
+ }
+
+ @Test
+ public void launchFragment_hasNoPackageInfo_shouldFinish() {
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", null);
+
+ assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isFalse();
+ verify(mActivity).finishAndRemoveTask();
+ }
+
+ @Test
+ public void launchFragment_hasPackageInfo_shouldReturnTrue() {
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+
+ assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isTrue();
+ verify(mActivity, never()).finishAndRemoveTask();
+ }
+
+ @Test
+ public void packageSizeChange_isOtherPackage_shouldNotRefreshUi() {
+ ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
+ mAppDetail.onPackageSizeChanged("Not_" + PACKAGE_NAME);
+
+ verify(mAppDetail, never()).refreshUi();
+ }
+
+ @Test
+ public void packageSizeChange_isOwnPackage_shouldRefreshUi() {
+ doReturn(Boolean.TRUE).when(mAppDetail).refreshUi();
+ ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
+
+ mAppDetail.onPackageSizeChanged(PACKAGE_NAME);
+
+ verify(mAppDetail).refreshUi();
+ }
+
+ // Tests that we don't show the "uninstall for all users" button for instant apps.
+ @Test
+ public void instantApps_noUninstallForAllButton() {
+ // Make this app appear to be instant.
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+ when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
+ when(mUserManager.getUsers().size()).thenReturn(2);
+
+ final ApplicationInfo info = new ApplicationInfo();
+ info.enabled = true;
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+
+ ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
+ ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+
+ assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isFalse();
+ }
+
+ // Tests that we don't show the uninstall button for instant apps"
+ @Test
+ public void instantApps_noUninstallButton() {
+ // Make this app appear to be instant.
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+ final ApplicationInfo info = new ApplicationInfo();
+ info.flags = ApplicationInfo.FLAG_INSTALLED;
+ info.enabled = true;
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ packageInfo.applicationInfo = info;
+
+ ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
+ ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+
+ mAppDetail.initUninstallButtonForUserApp();
+ verify(mAppDetail.mActionButtons).setButton1Visible(false);
+ }
+
+ // Tests that we don't show the force stop button for instant apps (they aren't allowed to run
+ // when they aren't in the foreground).
+ @Test
+ public void instantApps_noForceStop() {
+ // Make this app appear to be instant.
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ final AppEntry appEntry = mock(AppEntry.class);
+ final ApplicationInfo info = new ApplicationInfo();
+ appEntry.info = info;
+
+ ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+ ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
+
+ mAppDetail.checkForceStop();
+ verify(mAppDetail.mActionButtons).setButton2Visible(false);
+ }
+
+ @Test
+ public void instantApps_buttonControllerHandlesDialog() {
+ InstantAppButtonsController mockController = mock(InstantAppButtonsController.class);
+ ReflectionHelpers.setField(
+ mAppDetail, "mInstantAppButtonsController", mockController);
+ // Make sure first that button controller is not called for supported dialog id
+ AlertDialog mockDialog = mock(AlertDialog.class);
+ when(mockController.createDialog(InstantAppButtonsController.DLG_CLEAR_APP))
+ .thenReturn(mockDialog);
+ assertThat(mAppDetail.createDialog(InstantAppButtonsController.DLG_CLEAR_APP, 0))
+ .isEqualTo(mockDialog);
+ verify(mockController).createDialog(InstantAppButtonsController.DLG_CLEAR_APP);
+ }
+
+ // A helper class for testing the InstantAppButtonsController - it lets us look up the
+ // preference associated with a key for instant app buttons and get back a mock
+ // LayoutPreference (to avoid a null pointer exception).
+ public static class InstalledAppDetailsWithMockInstantButtons extends InstalledAppDetails {
+ @Mock
+ private LayoutPreference mInstantButtons;
+
+ public InstalledAppDetailsWithMockInstantButtons() {
+ super();
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Override
+ public Preference findPreference(CharSequence key) {
+ if (key == "instant_app_buttons") {
+ return mInstantButtons;
+ }
+ return super.findPreference(key);
+ }
+ }
+
+ @Test
+ public void instantApps_instantSpecificButtons() {
+ // Make this app appear to be instant.
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+
+ final InstalledAppDetailsWithMockInstantButtons
+ fragment = new InstalledAppDetailsWithMockInstantButtons();
+ ReflectionHelpers.setField(fragment, "mPackageInfo", packageInfo);
+ ReflectionHelpers.setField(fragment, "mApplicationFeatureProvider",
+ mFeatureFactory.applicationFeatureProvider);
+
+ final InstantAppButtonsController buttonsController =
+ mock(InstantAppButtonsController.class);
+ when(buttonsController.setPackageName(nullable(String.class)))
+ .thenReturn(buttonsController);
+ when(mFeatureFactory.applicationFeatureProvider.newInstantAppButtonsController(
+ nullable(Fragment.class), nullable(View.class), nullable(ShowDialogDelegate.class)))
+ .thenReturn(buttonsController);
+
+ fragment.maybeAddInstantAppButtons();
+ verify(buttonsController).setPackageName(nullable(String.class));
+ verify(buttonsController).show();
+ }
+
+ @Test
+ public void instantApps_removeCorrectPref() {
+ PreferenceScreen mockPreferenceScreen = mock(PreferenceScreen.class);
+ PreferenceManager mockPreferenceManager = mock(PreferenceManager.class);
+ AppDomainsPreference mockAppDomainsPref = mock(AppDomainsPreference.class);
+ PackageInfo mockPackageInfo = mock(PackageInfo.class);
+ PackageManager mockPackageManager = mock(PackageManager.class);
+ ReflectionHelpers.setField(
+ mAppDetail, "mInstantAppDomainsPreference", mockAppDomainsPref);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPreferenceManager", mockPreferenceManager);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPackageInfo", mockPackageInfo);
+ ReflectionHelpers.setField(
+ mAppDetail, "mPm", mockPackageManager);
+ when(mockPreferenceManager.getPreferenceScreen()).thenReturn(mockPreferenceScreen);
+
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> false));
+ mAppDetail.prepareInstantAppPrefs();
+
+ // For the non instant case we remove the app domain pref, and leave the launch pref
+ verify(mockPreferenceScreen).removePreference(mockAppDomainsPref);
+
+ // For the instant app case we remove the launch preff, and leave the app domain pref
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+
+ mAppDetail.prepareInstantAppPrefs();
+ // Will be 1 still due to above call
+ verify(mockPreferenceScreen, times(1))
+ .removePreference(mockAppDomainsPref);
+ }
+
+ @Test
+ public void onActivityResult_uninstalledUpdates_shouldInvalidateOptionsMenu() {
+ doReturn(true).when(mAppDetail).refreshUi();
+
+ mAppDetail.onActivityResult(InstalledAppDetails.REQUEST_UNINSTALL, 0, mock(Intent.class));
+
+ verify(mActivity).invalidateOptionsMenu();
+ }
+
+ @Test
+ public void handleDisableable_appIsHomeApp_buttonShouldNotWork() {
+ final ApplicationInfo info = new ApplicationInfo();
+ info.packageName = "pkg";
+ info.enabled = true;
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ final HashSet<String> homePackages = new HashSet<>();
+ homePackages.add(info.packageName);
+
+ ReflectionHelpers.setField(mAppDetail, "mHomePackages", homePackages);
+ ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
+
+ assertThat(mAppDetail.handleDisableable()).isFalse();
+ verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
+ }
+
+ @Test
+ @Config(shadows = ShadowUtils.class)
+ public void handleDisableable_appIsEnabled_buttonShouldWork() {
+ final ApplicationInfo info = new ApplicationInfo();
+ info.packageName = "pkg";
+ info.enabled = true;
+ info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
+ new HashSet<>());
+
+ ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
+ mFeatureFactory.applicationFeatureProvider);
+ ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
+
+ assertThat(mAppDetail.handleDisableable()).isTrue();
+ verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
+ }
+
+ @Test
+ @Config(shadows = ShadowUtils.class)
+ public void handleDisableable_appIsDisabled_buttonShouldShowEnable() {
+ final ApplicationInfo info = new ApplicationInfo();
+ info.packageName = "pkg";
+ info.enabled = false;
+ info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
+ new HashSet<>());
+
+ ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
+ mFeatureFactory.applicationFeatureProvider);
+ ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
+
+ assertThat(mAppDetail.handleDisableable()).isTrue();
+ verify(mAppDetail.mActionButtons).setButton1Text(R.string.enable_text);
+ verify(mAppDetail.mActionButtons).setButton1Positive(true);
+ }
+
+ @Test
+ @Config(shadows = ShadowUtils.class)
+ public void handleDisableable_appIsEnabledAndInKeepEnabledWhitelist_buttonShouldNotWork() {
+ final ApplicationInfo info = new ApplicationInfo();
+ info.packageName = "pkg";
+ info.enabled = true;
+ info.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+
+ final HashSet<String> packages = new HashSet<>();
+ packages.add(info.packageName);
+ when(mFeatureFactory.applicationFeatureProvider.getKeepEnabledPackages()).thenReturn(
+ packages);
+
+ ReflectionHelpers.setField(mAppDetail, "mApplicationFeatureProvider",
+ mFeatureFactory.applicationFeatureProvider);
+ ReflectionHelpers.setField(mAppDetail, "mAppEntry", appEntry);
+
+ assertThat(mAppDetail.handleDisableable()).isFalse();
+ verify(mAppDetail.mActionButtons).setButton1Text(R.string.disable_text);
+ }
+
+ @Test
+ public void initUninstallButtonForUserApp_shouldSetNegativeButton() {
+ final ApplicationInfo info = new ApplicationInfo();
+ info.flags = ApplicationInfo.FLAG_INSTALLED;
+ info.enabled = true;
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ packageInfo.applicationInfo = info;
+ ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+
+ mAppDetail.initUninstallButtonForUserApp();
+
+ verify(mAppDetail.mActionButtons).setButton1Positive(false);
+ }
+
+ @Implements(Utils.class)
+ public static class ShadowUtils {
+ @Implementation
+ public static boolean isSystemPackage(Resources resources, PackageManager pm,
+ PackageInfo pkg) {
+ return false;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppBatteryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppBatteryPreferenceControllerTest.java
new file mode 100644
index 0000000..065fe2b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppBatteryPreferenceControllerTest.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyDouble;
+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.AppOpsManager;
+import android.app.LoaderManager;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.BatteryStats;
+import android.os.Bundle;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.os.BatterySipper;
+import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppBatteryPreferenceControllerTest {
+
+ private static final int TARGET_UID = 111;
+ private static final int OTHER_UID = 222;
+ private static final double BATTERY_LEVEL = 60;
+
+ @Mock
+ private SettingsActivity mActivity;
+ @Mock
+ private BatteryUtils mBatteryUtils;
+ @Mock
+ private BatterySipper mBatterySipper;
+ @Mock
+ private BatterySipper mOtherBatterySipper;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private BatteryStatsHelper mBatteryStatsHelper;
+ @Mock
+ private BatteryStats.Uid mUid;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private LoaderManager mLoaderManager;
+
+ private Context mContext;
+ private AppInfoDashboardFragment mFragment;
+ private AppBatteryPreferenceController mController;
+ private Preference mBatteryPreference;
+
+ @Before
+ public void setUp() throws NameNotFoundException {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+
+ mFragment = spy(new AppInfoDashboardFragment());
+
+ mBatteryPreference = spy(new Preference(mContext));
+
+ mBatterySipper.drainType = BatterySipper.DrainType.IDLE;
+ mBatterySipper.uidObj = mUid;
+ doReturn(TARGET_UID).when(mBatterySipper).getUid();
+ doReturn(OTHER_UID).when(mOtherBatterySipper).getUid();
+
+ mController = spy(new AppBatteryPreferenceController(
+ mContext, mFragment, "package1", null /* lifecycle */));
+ mController.mBatteryUtils = mBatteryUtils;
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mBatteryPreference);
+ }
+
+ @Test
+ public void getAvailabilityStatus_shouldAlwaysReturnAvailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
+ }
+
+ @Test
+ public void findTargetSipper_findCorrectSipper() {
+ final List<BatterySipper> usageList = new ArrayList<>();
+ usageList.add(mBatterySipper);
+ usageList.add(mOtherBatterySipper);
+ doReturn(usageList).when(mBatteryStatsHelper).getUsageList();
+
+ assertThat(mController.findTargetSipper(mBatteryStatsHelper, TARGET_UID)).isEqualTo(
+ mBatterySipper);
+ }
+
+ @Test
+ public void updateBattery_noBatteryStats_summaryNo() {
+ mController.displayPreference(mScreen);
+
+ mController.updateBattery();
+
+ assertThat(mBatteryPreference.getSummary()).isEqualTo(
+ "No battery use since last full charge");
+ }
+
+ @Test
+ public void updateBattery_hasBatteryStats_summaryPercent() {
+ mController.mBatteryHelper = mBatteryStatsHelper;
+ mController.mSipper = mBatterySipper;
+ doReturn(BATTERY_LEVEL).when(mBatteryUtils).calculateBatteryPercent(anyDouble(),
+ anyDouble(), anyDouble(), anyInt());
+ doReturn(new ArrayList<>()).when(mBatteryStatsHelper).getUsageList();
+ mController.displayPreference(mScreen);
+
+ mController.updateBattery();
+
+ assertThat(mBatteryPreference.getSummary()).isEqualTo("60% use since last full charge");
+ }
+
+ @Test
+ public void isBatteryStatsAvailable_hasBatteryStatsHelperAndSipper_returnTrue() {
+ mController.mBatteryHelper = mBatteryStatsHelper;
+ mController.mSipper = mBatterySipper;
+
+ assertThat(mController.isBatteryStatsAvailable()).isTrue();
+ }
+
+ @Test
+ public void isBatteryStatsAvailable_parametersNull_returnFalse() {
+ assertThat(mController.isBatteryStatsAvailable()).isFalse();
+ }
+
+ @Test
+ public void launchPowerUsageDetailFragment_shouldNotCrash() {
+ when(mActivity.getSystemService(Context.APP_OPS_SERVICE))
+ .thenReturn(mock(AppOpsManager.class));
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ final String key = mController.getPreferenceKey();
+ when(mBatteryPreference.getKey()).thenReturn(key);
+ mController.mSipper = mBatterySipper;
+ mController.mBatteryHelper = mBatteryStatsHelper;
+
+ // Should not crash
+ mController.handlePreferenceTreeClick(mBatteryPreference);
+ }
+
+ @Test
+ public void onResume_shouldRestartBatteryStatsLoader() {
+ doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+
+ mController.onResume();
+
+ verify(mLoaderManager).restartLoader(AppInfoDashboardFragment.LOADER_BATTERY, Bundle.EMPTY,
+ mController);
+ }
+
+ @Test
+ public void onPause_shouldDestroyBatteryStatsLoader() {
+ doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+
+ mController.onPause();
+
+ verify(mLoaderManager).destroyLoader(AppInfoDashboardFragment.LOADER_BATTERY);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceControllerTest.java
new file mode 100644
index 0000000..40f095c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceControllerTest.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.LoaderManager;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.net.ConnectivityManager;
+import android.net.INetworkStatsSession;
+import android.os.Bundle;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.datausage.AppDataUsage;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppDataUsagePreferenceControllerTest {
+
+ @Mock
+ private LoaderManager mLoaderManager;
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+
+ private Context mContext;
+ private AppDataUsagePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+ mController = spy(
+ new AppDataUsagePreferenceController(mContext, mFragment, null /* lifecycle */));
+ }
+
+ @Test
+ public void getAvailabilityStatus_bandwidthControlEnabled_shouldReturnAvailable() {
+ doReturn(true).when(mController).isBandwidthControlEnabled();
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_bandwidthControlDisabled_shouldReturnDisabled() {
+ doReturn(false).when(mController).isBandwidthControlEnabled();
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_UNSUPPORTED);
+ }
+
+ @Test
+ public void onResume_noSession_shouldNotRestartDataLoader() {
+ doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+
+ mController.onResume();
+
+ verify(mLoaderManager, never()).restartLoader(
+ AppInfoDashboardFragment.LOADER_CHART_DATA, Bundle.EMPTY, mController);
+ }
+
+ @Test
+ public void onResume_hasSession_shouldRestartDataLoader() {
+ final ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
+ when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
+ .thenReturn(connectivityManager);
+ when(connectivityManager.isNetworkSupported(anyInt())).thenReturn(true);
+ doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+ ReflectionHelpers.setField(mController, "mStatsSession", mock(INetworkStatsSession.class));
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+
+ mController.onResume();
+
+ verify(mLoaderManager).restartLoader(
+ eq(AppInfoDashboardFragment.LOADER_CHART_DATA), any(Bundle.class), eq(mController));
+ }
+
+ @Test
+ public void onPause_shouldDestroyDataLoader() {
+ doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+
+ mController.onPause();
+
+ verify(mLoaderManager).destroyLoader(AppInfoDashboardFragment.LOADER_CHART_DATA);
+ }
+
+ @Test
+ public void getDetailFragmentClass_shouldReturnAppDataUsage() {
+ assertThat(mController.getDetailFragmentClass()).isEqualTo(AppDataUsage.class);
+ }
+
+ @Test
+ public void updateState_shouldUpdatePreferenceSummary() {
+ final Preference preference = mock(Preference.class);
+
+ mController.updateState(preference);
+
+ verify(preference).setSummary(any());
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBaseTest.java
new file mode 100644
index 0000000..0803c93
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBaseTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.pm.ApplicationInfo;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.notification.AppNotificationSettings;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.applications.ApplicationsState;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppInfoPreferenceControllerBaseTest {
+
+ @Mock
+ private SettingsActivity mActivity;
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private Preference mPreference;
+
+ private TestPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mController = new TestPreferenceController(mFragment);
+ final String key = mController.getPreferenceKey();
+ when(mScreen.findPreference(key)).thenReturn(mPreference);
+ when(mPreference.getKey()).thenReturn(key);
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ }
+
+ @Test
+ public void getAvailabilityStatus_shouldReturnAvailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
+ }
+
+ @Test
+ public void refreshUi_shouldUpdatePreference() {
+ mController.displayPreference(mScreen);
+ mController.refreshUi();
+
+ assertThat(mController.preferenceUpdated).isTrue();
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_shouldStartDetailFragmentClass() {
+ final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+
+ mController.handlePreferenceTreeClick(mPreference);
+
+ verify(mActivity).startPreferencePanel(any(),
+ eq(mController.getDetailFragmentClass().getName()), any(), anyInt(), any(), any(),
+ anyInt());
+ }
+
+ private class TestPreferenceController extends AppInfoPreferenceControllerBase {
+
+ private boolean preferenceUpdated;
+
+ public TestPreferenceController(AppInfoDashboardFragment parent) {
+ super(RuntimeEnvironment.application, parent, "TestKey");
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preferenceUpdated = true;
+ }
+
+ @Override
+ public Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
+ return AppNotificationSettings.class;
+ }
+
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
new file mode 100644
index 0000000..39bb875
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.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.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.ProcStatsData;
+import com.android.settings.applications.ProcessStatsDetail;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppMemoryPreferenceControllerTest {
+
+ @Mock
+ private SettingsActivity mActivity;
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private Preference mPreference;
+
+ private Context mContext;
+ private AppMemoryPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController =
+ spy(new AppMemoryPreferenceController(mContext, mFragment, null /* lifecycle */));
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ final String key = mController.getPreferenceKey();
+ when(mPreference.getKey()).thenReturn(key);
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ }
+
+ @Test
+ public void getAvailabilityStatus_developmentSettingsEnabled_shouldReturnAvailable() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_developmentSettingsDisabled_shouldReturnDisabled() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(mController.DISABLED_DEPENDENT_SETTING);
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_shouldStartProcessStatsDetail() {
+ final ProcStatsData data = mock(ProcStatsData.class);
+ when(data.getMemInfo()).thenReturn(mock(ProcStatsData.MemInfo.class));
+ ReflectionHelpers.setField(mController, "mStatsManager", data);
+
+ mController.handlePreferenceTreeClick(mPreference);
+
+ verify(mActivity).startPreferencePanel(any(), eq(ProcessStatsDetail.class.getName()), any(),
+ eq(R.string.memory_usage), any(), any(), anyInt());
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
new file mode 100644
index 0000000..0d42fc2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.notification.AppNotificationSettings;
+import com.android.settings.notification.NotificationBackend;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.applications.ApplicationsState;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppNotificationPreferenceControllerTest {
+
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private Preference mPreference;
+
+ private Context mContext;
+ private AppNotificationPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController =
+ spy(new AppNotificationPreferenceController(mContext, mFragment));
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ final String key = mController.getPreferenceKey();
+ when(mPreference.getKey()).thenReturn(key);
+ }
+
+ @Test
+ public void getDetailFragmentClass_shouldReturnAppNotificationSettings() {
+ assertThat(mController.getDetailFragmentClass()).isEqualTo(AppNotificationSettings.class);
+ }
+
+ @Test
+ public void updateState_shouldSetSummary() {
+ final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+ ReflectionHelpers.setField(mController, "mBackend", new NotificationBackend());
+ mController.displayPreference(mScreen);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(any());
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceControllerTest.java
new file mode 100644
index 0000000..d4f0179
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppOpenByDefaultPreferenceControllerTest.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.AppLaunchSettings;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.applications.AppUtils;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppOpenByDefaultPreferenceControllerTest {
+
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private Preference mPreference;
+
+ private Context mContext;
+ private AppOpenByDefaultPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application.getApplicationContext();
+ mController = spy(new AppOpenByDefaultPreferenceController(mContext, mFragment));
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void getDetailFragmentClass_shouldReturnAppLaunchSettings() {
+ assertThat(mController.getDetailFragmentClass()).isEqualTo(AppLaunchSettings.class);
+ }
+
+ @Test
+ public void displayPreference_noAppEntry_shouldDisablePreference() {
+ mController.displayPreference(mScreen);
+
+ verify(mPreference).setEnabled(false);
+ }
+
+ @Test
+ public void displayPreference_noAppInfo_shouldDisablePreference() {
+ final AppEntry appEntry = mock(AppEntry.class);
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+
+ mController.displayPreference(mScreen);
+
+ verify(mPreference).setEnabled(false);
+ }
+
+ @Test
+ public void displayPreference_appNotInstalled_shouldDisablePreference() {
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+
+ mController.displayPreference(mScreen);
+
+ verify(mPreference).setEnabled(false);
+ }
+
+ @Test
+ public void displayPreference_appDisabled_shouldDisablePreference() {
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ appEntry.info.flags &= ApplicationInfo.FLAG_INSTALLED;
+ appEntry.info.enabled = false;
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+
+ mController.displayPreference(mScreen);
+
+ verify(mPreference).setEnabled(false);
+ }
+
+ @Test
+ public void displayPreference_appEnabled_shouldNotDisablePreference() {
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ appEntry.info.flags |= ApplicationInfo.FLAG_INSTALLED;
+ appEntry.info.enabled = true;
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+
+ mController.displayPreference(mScreen);
+
+ verify(mPreference, never()).setEnabled(false);
+ }
+
+ @Test
+ public void updateState_noPackageInfo_shouldNotShowPreference() {
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(false);
+ }
+
+ @Test
+ public void updateState_isInstantApp_shouldNotShowPreference() {
+ when(mFragment.getPackageInfo()).thenReturn(new PackageInfo());
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> true));
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(false);
+ }
+
+ @Test
+ public void updateState_notInstantApp_shouldShowPreferenceAndSetSummary() {
+ when(mFragment.getPackageInfo()).thenReturn(new PackageInfo());
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+ ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+ (InstantAppDataProvider) (i -> false));
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setVisible(true);
+ verify(mPreference).setSummary(any());
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppPermissionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppPermissionPreferenceControllerTest.java
new file mode 100644
index 0000000..3ddfaf0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppPermissionPreferenceControllerTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.applications.ApplicationsState;
+
+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 java.util.ArrayList;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppPermissionPreferenceControllerTest {
+
+ @Mock
+ private SettingsActivity mActivity;
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private Preference mPreference;
+
+ private Context mContext;
+ private AppPermissionPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new AppPermissionPreferenceController(mContext, mFragment, "Package1");
+ when(mScreen.findPreference(any())).thenReturn(mPreference);
+ final String key = mController.getPreferenceKey();
+ when(mPreference.getKey()).thenReturn(key);
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ }
+
+ @Test
+ public void getAvailabilityStatus_isAlwaysAvailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
+ }
+
+ @Test
+ public void onPermissionSummaryResult_noRequestedPermission_shouldDisablePreference() {
+ mController.displayPreference(mScreen);
+
+ mController.mPermissionCallback.onPermissionSummaryResult(
+ 1, 0, 1, new ArrayList<CharSequence>());
+
+ verify(mPreference).setEnabled(false);
+ verify(mPreference).setSummary(mContext.getString(
+ R.string.runtime_permissions_summary_no_permissions_requested));
+ }
+
+ @Test
+ public void onPermissionSummaryResult_noGrantedPermission_shouldSetNoPermissionSummary() {
+ mController.displayPreference(mScreen);
+
+ mController.mPermissionCallback.onPermissionSummaryResult(
+ 1, 5, 0, new ArrayList<CharSequence>());
+
+ verify(mPreference).setEnabled(true);
+ verify(mPreference).setSummary(mContext.getString(
+ R.string.runtime_permissions_summary_no_permissions_granted));
+ }
+
+ @Test
+ public void onPermissionSummaryResult_hasRuntimePermission_shouldSetPermissionAsSummary() {
+ mController.displayPreference(mScreen);
+ final String permission = "Storage";
+ final ArrayList<CharSequence> labels = new ArrayList<>();
+ labels.add(permission);
+
+ mController.mPermissionCallback.onPermissionSummaryResult(1, 5, 0, labels);
+
+ verify(mPreference).setEnabled(true);
+ verify(mPreference).setSummary(permission);
+ }
+
+ @Test
+ public void onPermissionSummaryResult_hasAdditionalPermission_shouldSetAdditionalSummary() {
+ mController.displayPreference(mScreen);
+ final String permission = "Storage";
+ final ArrayList<CharSequence> labels = new ArrayList<>();
+ labels.add(permission);
+
+ mController.mPermissionCallback.onPermissionSummaryResult(1, 5, 2, labels);
+
+ verify(mPreference).setEnabled(true);
+ verify(mPreference).setSummary("Storage and 2 additional permissions");
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_shouldStartManagePermissionsActivity() {
+ final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+
+ mController.handlePreferenceTreeClick(mPreference);
+
+ verify(mActivity).startActivityForResult(argThat(intent-> intent != null &&
+ Intent.ACTION_MANAGE_APP_PERMISSIONS.equals(intent.getAction())), anyInt());
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppStoragePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppStoragePreferenceControllerTest.java
new file mode 100644
index 0000000..1b6b3c0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppStoragePreferenceControllerTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+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.LoaderManager;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.os.Bundle;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.AppStorageSettings;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.applications.StorageStatsSource;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppStoragePreferenceControllerTest {
+
+ @Mock
+ private LoaderManager mLoaderManager;
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+
+ private Context mContext;
+ private AppStoragePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application.getApplicationContext();
+ mController =
+ spy(new AppStoragePreferenceController(mContext, mFragment, null /* lifecycle */));
+ }
+
+ @Test
+ public void onResume_shouldRestartStorageLoader() {
+ doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+
+ mController.onResume();
+
+ verify(mLoaderManager).restartLoader(AppInfoDashboardFragment.LOADER_STORAGE, Bundle.EMPTY,
+ mController);
+ }
+
+ @Test
+ public void onPause_shouldDestroyStorageLoader() {
+ doReturn(mLoaderManager).when(mFragment).getLoaderManager();
+
+ mController.onPause();
+
+ verify(mLoaderManager).destroyLoader(AppInfoDashboardFragment.LOADER_STORAGE);
+ }
+
+ @Test
+ public void getDetailFragmentClass_shouldReturnAppStorageSettings() {
+ assertThat(mController.getDetailFragmentClass()).isEqualTo(AppStorageSettings.class);
+ }
+
+ @Test
+ public void updateState_shouldUpdatePreferenceSummary() {
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = new ApplicationInfo();
+ when(mFragment.getAppEntry()).thenReturn(appEntry);
+ Preference preference = mock(Preference.class);
+
+ mController.updateState(preference);
+
+ verify(preference).setSummary(any());
+ }
+
+ @Test
+ public void getStorageSummary_shouldWorkForExternal() {
+ final StorageStatsSource.AppStorageStats stats =
+ mock(StorageStatsSource.AppStorageStats.class);
+ when(stats.getTotalBytes()).thenReturn(1L);
+
+ assertThat(mController.getStorageSummary(stats, true))
+ .isEqualTo("1 B used in external storage");
+ }
+
+ @Test
+ public void getStorageSummary_shouldWorkForInternal() {
+ final StorageStatsSource.AppStorageStats stats =
+ mock(StorageStatsSource.AppStorageStats.class);
+ when(stats.getTotalBytes()).thenReturn(1L);
+
+ assertThat(mController.getStorageSummary(stats, false))
+ .isEqualTo("1 B used in internal storage");
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppVersionPreferenceControllerTest.java
new file mode 100644
index 0000000..838b442
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppVersionPreferenceControllerTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class AppVersionPreferenceControllerTest {
+
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+ @Mock
+ private Preference mPreference;
+
+ private Context mContext;
+ private AppVersionPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new AppVersionPreferenceController(mContext, mFragment);
+ }
+
+ @Test
+ public void updateState_shouldUpdatePreferenceSummary() {
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ packageInfo.versionName = "test1234";
+ when(mFragment.getPackageInfo()).thenReturn(packageInfo);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary("version test1234");
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java
new file mode 100644
index 0000000..1a06f3b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.argThat;
+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.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.AppInfoDashboardFragment;
+import com.android.settings.applications.DefaultAppSettings;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultAppShortcutPreferenceControllerBaseTest {
+
+ @Mock
+ private UserManager mUserManager;
+ @Mock
+ private AppInfoDashboardFragment mFragment;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private Preference mPreference;
+
+ private Context mContext;
+ private TestPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+ mController = new TestPreferenceController(mContext, mFragment);
+ final String key = mController.getPreferenceKey();
+ when(mPreference.getKey()).thenReturn(key);
+ }
+
+ @Test
+ public void getAvailabilityStatus_managedProfile_shouldReturnDisabled() {
+ when(mUserManager.isManagedProfile()).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
+ }
+
+ @Test
+ public void getAvailabilityStatus_hasAppCapability_shouldReturnAvailable() {
+ mController.capable = true;
+ when(mUserManager.isManagedProfile()).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noAppCapability_shouldReturnDisabled() {
+ mController.capable = false;
+ when(mUserManager.isManagedProfile()).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_UNSUPPORTED);
+ }
+
+ @Test
+ public void updateState_isDefaultApp_shouldSetSummaryToYes() {
+ mController.isDefault = true;
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(R.string.yes);
+ }
+
+ @Test
+ public void updateState_notDefaultApp_shouldSetSummaryToNo() {
+ mController.isDefault = false;
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(R.string.no);
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_shouldStartDefaultAppSettings() {
+ mController.handlePreferenceTreeClick(mPreference);
+
+ verify(mContext).startActivity(argThat(intent-> intent != null
+ && intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT).equals(
+ DefaultAppSettings.class.getName())
+ && intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)
+ .getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY).equals("TestKey")));
+ }
+
+ private class TestPreferenceController extends DefaultAppShortcutPreferenceControllerBase {
+
+ private boolean isDefault;
+ private boolean capable;
+
+ public TestPreferenceController(Context context, AppInfoDashboardFragment parent) {
+ super(context, "TestKey", "TestPackage");
+ }
+
+ @Override
+ protected boolean hasAppCapability() {
+ return capable;
+ }
+
+ @Override
+ protected boolean isDefaultApp() {
+ return isDefault;
+ }
+
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..0a18722
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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 java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultBrowserShortcutPreferenceControllerTest {
+
+ @Mock
+ private PackageManager mPackageManager;
+
+ private Context mContext;
+ private DefaultBrowserShortcutPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ mController = new DefaultBrowserShortcutPreferenceController(mContext, "Package1");
+ }
+
+ @Test
+ public void getPreferenceKey_shouldReturnDefaultBrowser() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("default_browser");
+ }
+
+ @Test
+ public void hasAppCapability_hasBrowserCapability_shouldReturnTrue() {
+ List<ResolveInfo> resolveInfos = new ArrayList<>();
+ resolveInfos.add(new ResolveInfo());
+ when(mPackageManager.queryIntentActivities(argThat(intent-> intent != null
+ && intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)), anyInt()))
+ .thenReturn(resolveInfos);
+
+ assertThat(mController.hasAppCapability()).isTrue();
+ }
+
+ @Test
+ public void hasAppCapability_noBrowserCapability_shouldReturnFalse() {
+ assertThat(mController.hasAppCapability()).isFalse();
+ }
+
+ @Test
+ public void isDefaultApp_isDefaultBrowser_shouldReturnTrue() {
+ when(mPackageManager.getDefaultBrowserPackageNameAsUser(anyInt())).thenReturn("Package1");
+
+ assertThat(mController.isDefaultApp()).isTrue();
+ }
+
+ @Test
+ public void isDefaultApp_notDefaultBrowser_shouldReturnFalse() {
+ assertThat(mController.isDefaultApp()).isFalse();
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..414ef70
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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 java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultEmergencyShortcutPreferenceControllerTest {
+
+ @Mock
+ private PackageManager mPackageManager;
+
+ private Context mContext;
+ private DefaultEmergencyShortcutPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ mController = new DefaultEmergencyShortcutPreferenceController(mContext, "Package1");
+ }
+
+ @Test
+ public void getPreferenceKey_shouldReturnDefaultEmergency() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("default_emergency_app");
+ }
+
+ @Test
+ public void hasAppCapability_hasEmergencyCapability_shouldReturnTrue() {
+ List<ResolveInfo> resolveInfos = new ArrayList<>();
+ resolveInfos.add(new ResolveInfo());
+ when(mPackageManager.queryIntentActivities(argThat(intent-> intent != null
+ && intent.getAction().equals(TelephonyManager.ACTION_EMERGENCY_ASSISTANCE)),
+ anyInt())).thenReturn(resolveInfos);
+
+ assertThat(mController.hasAppCapability()).isTrue();
+ }
+
+ @Test
+ public void hasAppCapability_noEmergencyCapability_shouldReturnFalse() {
+ assertThat(mController.hasAppCapability()).isFalse();
+ }
+
+ @Test
+ public void isDefaultApp_isDefaultEmergency_shouldReturnTrue() {
+ Settings.Secure.putString(mContext.getContentResolver(),
+ Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION, "Package1");
+
+ assertThat(mController.isDefaultApp()).isTrue();
+ }
+
+ @Test
+ public void isDefaultApp_notDefaultEmergency_shouldReturnFalse() {
+ assertThat(mController.isDefaultApp()).isFalse();
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..a0a57f6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultHomeShortcutPreferenceControllerTest {
+
+ @Mock
+ private PackageManager mPackageManager;
+
+ private Context mContext;
+ private DefaultHomeShortcutPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ mController = new DefaultHomeShortcutPreferenceController(mContext, "Package1");
+ }
+
+ @Test
+ public void getPreferenceKey_shouldReturnDefaultHome() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("default_home");
+ }
+
+ @Test
+ @Config(shadows = ShadowDefaultHomePreferenceController.class)
+ public void hasAppCapability_hasHomeCapability_shouldReturnTrue() {
+ assertThat(mController.hasAppCapability()).isTrue();
+ }
+
+ @Test
+ public void hasAppCapability_noHomeCapability_shouldReturnFalse() {
+ assertThat(mController.hasAppCapability()).isFalse();
+ }
+
+ @Test
+ public void isDefaultApp_isDefaultHome_shouldReturnTrue() {
+ when(mPackageManager.getHomeActivities(anyList()))
+ .thenReturn(new ComponentName("Package1", "cls1"));
+ assertThat(mController.isDefaultApp()).isTrue();
+ }
+
+ @Test
+ public void isDefaultApp_notDefaultHome_shouldReturnFalse() {
+ when(mPackageManager.getHomeActivities(anyList()))
+ .thenReturn(new ComponentName("pkg2", "cls1"));
+ assertThat(mController.isDefaultApp()).isFalse();
+ }
+
+ @Implements(DefaultHomePreferenceController.class)
+ public static class ShadowDefaultHomePreferenceController {
+ @Implementation
+ public static boolean hasHomePreference(String pkg, Context context) {
+ return true;
+ }
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..d04b114
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultPhoneShortcutPreferenceControllerTest {
+
+ @Mock
+ private PackageManager mPackageManager;
+
+ private Context mContext;
+ private DefaultPhoneShortcutPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ mController = new DefaultPhoneShortcutPreferenceController(mContext, "Package1");
+ }
+
+ @Test
+ public void getPreferenceKey_shouldReturnDefaultPhone() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("default_phone_app");
+ }
+
+ @Test
+ @Config(shadows = ShadowDefaultPhonePreferenceController.class)
+ public void hasAppCapability_hasPhoneCapability_shouldReturnTrue() {
+ assertThat(mController.hasAppCapability()).isTrue();
+ }
+
+ @Test
+ public void hasAppCapability_noPhoneCapability_shouldReturnFalse() {
+ assertThat(mController.hasAppCapability()).isFalse();
+ }
+
+ @Test
+ @Config(shadows = ShadowDefaultPhonePreferenceController.class)
+ public void isDefaultApp_isDefaultPhone_shouldReturnTrue() {
+ assertThat(mController.isDefaultApp()).isTrue();
+ }
+
+ @Test
+ public void isDefaultApp_notDefaultPhone_shouldReturnFalse() {
+ assertThat(mController.isDefaultApp()).isFalse();
+ }
+
+ @Implements(DefaultPhonePreferenceController.class)
+ public static class ShadowDefaultPhonePreferenceController {
+ @Implementation
+ public static boolean hasPhonePreference(String pkg, Context context) {
+ return true;
+ }
+
+ @Implementation
+ public static boolean isPhoneDefault(String pkg, Context context) {
+ return true;
+ }
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java
new file mode 100644
index 0000000..4abaa6a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class DefaultSmsShortcutPreferenceControllerTest {
+
+ @Mock
+ private PackageManager mPackageManager;
+
+ private Context mContext;
+ private DefaultSmsShortcutPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ mController = new DefaultSmsShortcutPreferenceController(mContext, "Package1");
+ }
+
+ @Test
+ public void getPreferenceKey_shouldReturnDefaultSms() {
+ assertThat(mController.getPreferenceKey()).isEqualTo("default_sms_app");
+ }
+
+ @Test
+ @Config(shadows = ShadowDefaultSmsPreferenceController.class)
+ public void hasAppCapability_hasSmsCapability_shouldReturnTrue() {
+ assertThat(mController.hasAppCapability()).isTrue();
+ }
+
+ @Test
+ public void hasAppCapability_noSmsCapability_shouldReturnFalse() {
+ assertThat(mController.hasAppCapability()).isFalse();
+ }
+
+ @Test
+ @Config(shadows = ShadowDefaultSmsPreferenceController.class)
+ public void isDefaultApp_isDefaultSms_shouldReturnTrue() {
+ assertThat(mController.isDefaultApp()).isTrue();
+ }
+
+ @Test
+ public void isDefaultApp_notDefaultSms_shouldReturnFalse() {
+ assertThat(mController.isDefaultApp()).isFalse();
+ }
+
+ @Implements(DefaultSmsPreferenceController.class)
+ public static class ShadowDefaultSmsPreferenceController {
+ @Implementation
+ public static boolean hasSmsPreference(String pkg, Context context) {
+ return true;
+ }
+
+ @Implementation
+ public static boolean isSmsDefault(String pkg, Context context) {
+ return true;
+ }
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
index 2b30ae4..f434186 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDetailTest.java
@@ -31,7 +31,6 @@
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.res.Resources;
-import android.os.UserManager;
import android.support.v7.preference.PreferenceGroup;
import com.android.settings.R;
@@ -56,8 +55,6 @@
public class BluetoothPairingDetailTest {
@Mock
- private UserManager mUserManager;
- @Mock
private Resources mResource;
@Mock
private LocalBluetoothAdapter mLocalAdapter;
@@ -134,6 +131,25 @@
}
@Test
+ public void testUpdateBluetooth_bluetoothOff_turnOnBluetooth() {
+ doReturn(false).when(mLocalAdapter).isEnabled();
+
+ mFragment.updateBluetooth();
+
+ verify(mLocalAdapter).enable();
+ }
+
+ @Test
+ public void testUpdateBluetooth_bluetoothOn_updateState() {
+ doReturn(true).when(mLocalAdapter).isEnabled();
+ doNothing().when(mFragment).updateContent(anyInt());
+
+ mFragment.updateBluetooth();
+
+ verify(mFragment).updateContent(anyInt());
+ }
+
+ @Test
public void testOnScanningStateChanged_restartScanAfterInitialScanning() {
mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
mFragment.mFooterPreference = mFooterPreference;
@@ -181,6 +197,4 @@
verify(mAvailableDevicesCategory, times(1)).removeAll();
}
-
-
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
index 25a24d4..e598ec1 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
@@ -290,7 +290,6 @@
CheckBox sharingCheckbox = (CheckBox) frag.getmDialog()
.findViewById(R.id.phonebook_sharing_message_confirm_pin);
assertThat(sharingCheckbox.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(sharingCheckbox.getText().toString().contains(FAKE_DEVICE_NAME)).isTrue();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/display/NightDisplaySettingsTest.java
new file mode 100644
index 0000000..113e7ec
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/NightDisplaySettingsTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.display;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class NightDisplaySettingsTest {
+
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ }
+
+ @Test
+ public void testNightDisplayIndexing_containsResource() {
+ List<SearchIndexableResource> resources =
+ NightDisplaySettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext,
+ true /* enabled */);
+
+ List<Integer> indexedXml = new ArrayList<>();
+ for (SearchIndexableResource resource : resources) {
+ indexedXml.add(resource.xmlResId);
+ }
+
+ assertThat(indexedXml).contains(R.xml.night_display_settings);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
index 7633ce9..40c4af3 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsPreferenceControllerTest.java
@@ -45,7 +45,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = ShadowSecureSettings.class
)
public class AssistGestureSettingsPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
index 041b7e0..b2bd27e 100644
--- a/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/AssistGestureSettingsTest.java
@@ -41,7 +41,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AssistGestureSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
index 1f5ca20..12ecc90 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerPreferenceControllerTest.java
@@ -48,7 +48,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
SettingsShadowResources.class
})
public class DoubleTapPowerPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java
index b9635a7..e322b07 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapPowerSettingsTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DoubleTapPowerSettingsTest {
private DoubleTapPowerSettings mSettings;
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
index 2565dc8..72a77b0 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java
@@ -17,6 +17,7 @@
package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.when;
@@ -46,9 +47,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
- SettingsShadowResources.class
-})
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DoubleTapScreenPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -139,25 +138,19 @@
@Test
public void isSuggestionCompleted_ambientDisplay_falseWhenNotVisited() {
- SettingsShadowResources.overrideResource(
- com.android.internal.R.string.config_dozeComponent, "foo");
- SettingsShadowResources.overrideResource(
- com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar");
+ when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true);
// No stored value in shared preferences if not visited yet.
final Context context = RuntimeEnvironment.application;
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
.getSharedPrefs(context);
- assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs))
- .isFalse();
+ assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(
+ mAmbientDisplayConfiguration, prefs)).isFalse();
}
@Test
public void isSuggestionCompleted_ambientDisplay_trueWhenVisited() {
- SettingsShadowResources.overrideResource(
- com.android.internal.R.string.config_dozeComponent, "foo");
- SettingsShadowResources.overrideResource(
- com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar");
+ when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(false);
final Context context = RuntimeEnvironment.application;
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
.getSharedPrefs(context);
@@ -165,7 +158,7 @@
prefs.edit().putBoolean(
DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
- assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs))
- .isTrue();
+ assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(
+ mAmbientDisplayConfiguration, prefs)).isTrue();
}
}
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java
index 3d56d71..e29bf79 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenSettingsTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DoubleTapScreenSettingsTest {
private DoubleTapScreenSettings mSettings;
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java
index 236896a..081ff79 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTwistGestureSettingsTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DoubleTwistGestureSettingsTest {
private DoubleTwistGestureSettings mSettings;
diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
index a7516fc..b48889f 100644
--- a/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/DoubleTwistPreferenceControllerTest.java
@@ -51,7 +51,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
SettingsShadowResources.class
})
public class DoubleTwistPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
index b12b373..dcc06af 100644
--- a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
@@ -48,7 +48,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class GesturesSettingsPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
index 8757a65..ffd4928 100644
--- a/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java
@@ -18,6 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
@@ -46,7 +48,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
SettingsShadowResources.class
})
public class PickupGesturePreferenceControllerTest {
@@ -105,14 +107,16 @@
@Test
public void testCanHandleClicks_configIsSet_shouldReturnTrue() {
- when(mAmbientDisplayConfiguration.pulseOnPickupCanBeModified(anyInt())).thenReturn(true);
+ mController = spy(mController);
+ doReturn(true).when(mController).pulseOnPickupCanBeModified();
assertThat(mController.canHandleClicks()).isTrue();
}
@Test
public void testCanHandleClicks_configIsNotSet_shouldReturnFalse() {
- when(mAmbientDisplayConfiguration.pulseOnPickupCanBeModified(anyInt())).thenReturn(false);
+ mController = spy(mController);
+ doReturn(false).when(mController).pulseOnPickupCanBeModified();
assertThat(mController.canHandleClicks()).isFalse();
}
diff --git a/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java
index 2c4a1c4..05c88ba 100644
--- a/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PickupGestureSettingsTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PickupGestureSettingsTest {
private PickupGestureSettings mSettings;
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
index f3cc2ca..f535a99 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
@@ -41,7 +41,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SwipeToNotificationPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
index 0b329d3..7e3b90e 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationSettingsTest.java
@@ -37,7 +37,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SwipeToNotificationSettingsTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/graph/BottomLabelLayoutTest.java b/tests/robotests/src/com/android/settings/graph/BottomLabelLayoutTest.java
index c9804d6..eef6921 100644
--- a/tests/robotests/src/com/android/settings/graph/BottomLabelLayoutTest.java
+++ b/tests/robotests/src/com/android/settings/graph/BottomLabelLayoutTest.java
@@ -35,7 +35,7 @@
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BottomLabelLayoutTest {
private BottomLabelLayout mBottomLabelLayout;
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/graph/UsageGraphTest.java b/tests/robotests/src/com/android/settings/graph/UsageGraphTest.java
index fbd6fd4..4ab3381 100644
--- a/tests/robotests/src/com/android/settings/graph/UsageGraphTest.java
+++ b/tests/robotests/src/com/android/settings/graph/UsageGraphTest.java
@@ -37,7 +37,7 @@
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UsageGraphTest {
private UsageGraph mGraph;
diff --git a/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java
index 2716fc3..b8a63e4 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java
@@ -41,7 +41,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class GameControllerPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/inputmethod/PhysicalKeyboardPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/PhysicalKeyboardPreferenceControllerTest.java
index 8f9b2c5..5684f17 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/PhysicalKeyboardPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/PhysicalKeyboardPreferenceControllerTest.java
@@ -40,7 +40,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PhysicalKeyboardPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/inputmethod/SpellCheckerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/SpellCheckerPreferenceControllerTest.java
index 4457cc0..1991460 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/SpellCheckerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/SpellCheckerPreferenceControllerTest.java
@@ -39,7 +39,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SpellCheckerPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
index 7b149f3..c21cc76 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
@@ -38,7 +38,7 @@
import org.robolectric.shadows.ShadowContentResolver;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserDictionaryCursorLoaderTest {
private ContentProvider mContentProvider;
diff --git a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java
index 91fcaae..b220dd5 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListTest.java
@@ -37,7 +37,7 @@
import org.robolectric.shadows.ShadowContentResolver;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserDictionaryListTest {
private FakeProvider mContentProvider;
diff --git a/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
index fe2b0df..5913f7e 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
@@ -49,7 +49,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class VirtualKeyboardPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
index 141d59d..da996e8 100644
--- a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
@@ -64,7 +64,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class LanguageAndInputSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -159,12 +159,15 @@
final Context context = spy(RuntimeEnvironment.application);
final Resources res = spy(RuntimeEnvironment.application.getResources());
//(InputManager) context.getSystemService(Context.INPUT_SERVICE);
- InputManager manager = mock(InputManager.class);
- when(manager.getInputDeviceIds()).thenReturn(new int[]{});
- doReturn(manager).when(context).getSystemService(Context.INPUT_SERVICE);
+ final InputManager inputManager = mock(InputManager.class);
+ final TextServicesManager textServicesManager = mock(TextServicesManager.class);
+ when(inputManager.getInputDeviceIds()).thenReturn(new int[]{});
+ doReturn(inputManager).when(context).getSystemService(Context.INPUT_SERVICE);
+ doReturn(textServicesManager).when(context).getSystemService(
+ Context.TEXT_SERVICES_MANAGER_SERVICE);
doReturn(res).when(context).getResources();
doReturn(false).when(res)
- .getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys);
+ .getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys);
final List<String> niks = LanguageAndInputSettings.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(context);
LanguageAndInputSettings settings = new LanguageAndInputSettings();
@@ -177,7 +180,10 @@
@Test
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
- final Context context = RuntimeEnvironment.application;
+ final Context context = spy(RuntimeEnvironment.application);
+ final TextServicesManager textServicesManager = mock(TextServicesManager.class);
+ doReturn(textServicesManager).when(context).getSystemService(
+ Context.TEXT_SERVICES_MANAGER_SERVICE);
final LanguageAndInputSettings fragment = new LanguageAndInputSettings();
final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context,
fragment.getPreferenceScreenResId());
diff --git a/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java
index 7b315aa..485efbe 100644
--- a/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/language/PhoneLanguagePreferenceControllerTest.java
@@ -39,7 +39,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PhoneLanguagePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
index 26a160d..77d60cb 100644
--- a/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
@@ -39,7 +39,7 @@
import java.util.TreeSet;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserDictionaryPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
index 1ee52ca..40a42b5 100644
--- a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
@@ -33,7 +33,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = { ShadowSettingsPreferenceFragment.class })
public class LocaleListEditorTest {
diff --git a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
index fe45a93..01ca899 100644
--- a/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationPreferenceControllerTest.java
@@ -55,7 +55,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class LocationPreferenceControllerTest {
@Mock
private Preference mPreference;
diff --git a/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
new file mode 100644
index 0000000..48c26f3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AirplaneModePreferenceControllerTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+
+ @Mock
+ private Resources mResources;
+
+ @Mock
+ private PreferenceScreen mScreen;
+
+ @Mock
+ private PackageManager mPackageManager;
+
+ private AirplaneModePreferenceController mController;
+ private Lifecycle mLifecycle;
+ private FakeFeatureFactory mFactory;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mFactory = FakeFeatureFactory.setupForTest(mContext);
+ doReturn(mResources).when(mContext).getResources();
+ doReturn(mPackageManager).when(mContext).getPackageManager();
+ mController = spy(new AirplaneModePreferenceController(mContext, null));
+ mLifecycle = new Lifecycle(() -> mLifecycle);
+ mLifecycle.addObserver(mController);
+ }
+
+ @Test
+ public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() {
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true);
+ assertFalse(mController.isAvailable());
+
+ mController.displayPreference(mScreen);
+
+ // This should not crash
+ mController.onResume();
+ mController.onPause();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
index d593b58..4dd890d 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java
@@ -53,7 +53,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowRestrictedLockUtilsWrapper.class, ShadowConnectivityManager.class,
ShadowUserManager.class}
)
diff --git a/tests/robotests/src/com/android/settings/network/MobilePlanPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/MobilePlanPreferenceControllerTest.java
index a84179d..01d578f 100644
--- a/tests/robotests/src/com/android/settings/network/MobilePlanPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobilePlanPreferenceControllerTest.java
@@ -30,7 +30,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class MobilePlanPreferenceControllerTest {
@Test
diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
index 548d144..76ade7b 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
@@ -46,7 +46,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NetworkDashboardFragmentTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
index 896e802..087c0ff 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetActionMenuControllerTest.java
@@ -40,7 +40,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NetworkResetActionMenuControllerTest {
private static final int MENU_ID = Menu.FIRST;
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetPreferenceControllerTest.java
index 4d8c626..5cbba61 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkResetPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetPreferenceControllerTest.java
@@ -37,7 +37,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NetworkResetPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java
index 792bdd3..87bf812 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkResetRestrictionCheckerTest.java
@@ -36,7 +36,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NetworkResetRestrictionCheckerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java
index 7ed7f3f..5794820 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerPreferenceControllerTest.java
@@ -43,7 +43,7 @@
import java.util.Collections;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NetworkScorerPickerPreferenceControllerTest {
private static final String TEST_SCORER_PACKAGE = "Test Package";
diff --git a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java
index 7cfced8..773b311 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkScorerPickerTest.java
@@ -48,7 +48,7 @@
import java.util.ArrayList;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NetworkScorerPickerTest {
private static final String TEST_SCORER_PACKAGE_1 = "Test Package 1";
diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsMenuControllerTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsMenuControllerTest.java
index 0be66e0..4e37d56 100644
--- a/tests/robotests/src/com/android/settings/network/PrivateDnsMenuControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/PrivateDnsMenuControllerTest.java
@@ -37,7 +37,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PrivateDnsMenuControllerTest {
private static final int MENU_ID = 0;
diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
index f1d7a73..2dcfdc8 100644
--- a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
@@ -41,7 +41,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PrivateDnsModeDialogFragmentTest {
private static final String HOST_NAME = "192.168.1.1";
private static final String INVALID_HOST_NAME = "...,";
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index b8a6d28..33fd36b 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -52,7 +52,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class TetherPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
index c35f1cf..96a29c2 100644
--- a/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/VpnPreferenceControllerTest.java
@@ -48,7 +48,7 @@
import org.robolectric.shadows.ShadowServiceManager;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class VpnPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/network/WifiCallingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/WifiCallingPreferenceControllerTest.java
index 172508d..4d6a0be 100644
--- a/tests/robotests/src/com/android/settings/network/WifiCallingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/WifiCallingPreferenceControllerTest.java
@@ -39,7 +39,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WifiCallingPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java b/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java
index a82daf3..d4c74ed 100644
--- a/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java
@@ -36,7 +36,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PaymentSettingsTest {
@Mock
Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/AdjustVolumeRestrictedPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AdjustVolumeRestrictedPreferenceControllerTest.java
index d33d734..cc27649 100644
--- a/tests/robotests/src/com/android/settings/notification/AdjustVolumeRestrictedPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/AdjustVolumeRestrictedPreferenceControllerTest.java
@@ -43,7 +43,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AdjustVolumeRestrictedPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/AlarmRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AlarmRingtonePreferenceControllerTest.java
index f4bd522..85a3027 100644
--- a/tests/robotests/src/com/android/settings/notification/AlarmRingtonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/AlarmRingtonePreferenceControllerTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AlarmRingtonePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
index 7b0b033..f070421 100644
--- a/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
@@ -33,7 +33,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AlarmVolumePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java
index 9ba8706..c14e4aa 100644
--- a/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java
@@ -57,7 +57,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AllowSoundPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/AppLinkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AppLinkPreferenceControllerTest.java
index b440704..7198993 100644
--- a/tests/robotests/src/com/android/settings/notification/AppLinkPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/AppLinkPreferenceControllerTest.java
@@ -49,7 +49,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AppLinkPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java
index 6052478..55dbd3c 100644
--- a/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java
@@ -61,7 +61,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BadgePreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java
index 9014f4e..aca814a 100644
--- a/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java
@@ -59,7 +59,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BlockPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/BootSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BootSoundPreferenceControllerTest.java
index 58ba46b..3157d31 100644
--- a/tests/robotests/src/com/android/settings/notification/BootSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/BootSoundPreferenceControllerTest.java
@@ -38,7 +38,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BootSoundPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java
index ed9cc98..faace1b 100644
--- a/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java
@@ -36,7 +36,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class CastPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
index 2b2d024..e8d945b 100644
--- a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
@@ -39,7 +39,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ChargingSoundPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java
index 8cf8f83..afdc355 100644
--- a/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ConfigureNotificationSettingsTest.java
@@ -40,7 +40,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ConfigureNotificationSettingsTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
index fd903f9..2742d0d 100644
--- a/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
@@ -46,7 +46,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DeletedChannelsPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/DescriptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DescriptionPreferenceControllerTest.java
index 1776a9b..7f695f3 100644
--- a/tests/robotests/src/com/android/settings/notification/DescriptionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/DescriptionPreferenceControllerTest.java
@@ -51,7 +51,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DescriptionPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/DialPadTonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DialPadTonePreferenceControllerTest.java
index 4ec67e6..3400181 100644
--- a/tests/robotests/src/com/android/settings/notification/DialPadTonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/DialPadTonePreferenceControllerTest.java
@@ -40,7 +40,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DialPadTonePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java
index 241e279..428f536 100644
--- a/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java
@@ -61,7 +61,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DndPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/DockAudioMediaPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DockAudioMediaPreferenceControllerTest.java
index 58e5636..0634cef 100644
--- a/tests/robotests/src/com/android/settings/notification/DockAudioMediaPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/DockAudioMediaPreferenceControllerTest.java
@@ -41,7 +41,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DockAudioMediaPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/DockingSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DockingSoundPreferenceControllerTest.java
index d6a277f..517b722 100644
--- a/tests/robotests/src/com/android/settings/notification/DockingSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/DockingSoundPreferenceControllerTest.java
@@ -40,7 +40,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DockingSoundPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/EmergencyBroadcastPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/EmergencyBroadcastPreferenceControllerTest.java
index 24f4b6c..6a7be85 100644
--- a/tests/robotests/src/com/android/settings/notification/EmergencyBroadcastPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/EmergencyBroadcastPreferenceControllerTest.java
@@ -41,7 +41,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class EmergencyBroadcastPreferenceControllerTest {
private static final String PREF_TEST_KEY = "test_key";
diff --git a/tests/robotests/src/com/android/settings/notification/EmergencyTonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/EmergencyTonePreferenceControllerTest.java
index c3e887f..9e35ad9 100644
--- a/tests/robotests/src/com/android/settings/notification/EmergencyTonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/EmergencyTonePreferenceControllerTest.java
@@ -40,7 +40,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class EmergencyTonePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
index 385376f..f6b7e00 100644
--- a/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
@@ -54,7 +54,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class HeaderPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
index aebd6c9..d04a4c6 100644
--- a/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
@@ -52,7 +52,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ImportancePreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java
index 017cb88..0f3a37d 100644
--- a/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java
@@ -59,7 +59,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
SettingsShadowResources.class,
})
public class LightsPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
index ca7fc44..30cb158 100644
--- a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class MediaVolumePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
index d3f66b9..8e74e79 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAccessSettingsTest.java
@@ -36,7 +36,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NotificationAccessSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
index 089e330..0fb2e5c 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
@@ -31,7 +31,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NotificationBackendTest {
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java
index 1f49ff2..f4a5924 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java
@@ -57,7 +57,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NotificationPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
index 940a948..ab26226 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NotificationRingtonePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
index f919e7b..3e0fd7b 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
@@ -35,7 +35,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NotificationVolumePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
index e1f9eb7..aacccf4 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
@@ -48,7 +48,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NotificationsOffPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java
index 57ab4d3..614de6f 100644
--- a/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java
@@ -35,7 +35,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PhoneRingtonePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java
index 1a6d3d7..48edcf7 100644
--- a/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RingVolumePreferenceControllerTest.java
@@ -38,7 +38,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RingVolumePreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java
index e72ef53..82f4dab 100644
--- a/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java
@@ -36,7 +36,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RingtonePreferenceControllerBaseTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
index f94f8bf..4e77793 100644
--- a/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
@@ -39,7 +39,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ScreenLockSoundPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/SettingPrefControllerTest.java b/tests/robotests/src/com/android/settings/notification/SettingPrefControllerTest.java
index 307536d..ef7ee04 100644
--- a/tests/robotests/src/com/android/settings/notification/SettingPrefControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SettingPrefControllerTest.java
@@ -47,7 +47,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SettingPrefControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
index 1d5a791..3d6bc92 100644
--- a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
@@ -65,7 +65,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SoundPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
index ec0b6ea..5b816d4 100644
--- a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
@@ -41,7 +41,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SoundSettingsTest {
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java b/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java
index 74c41f3..5efad20 100644
--- a/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java
@@ -33,7 +33,7 @@
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SuppressorHelperTest {
private static final String SUPPRESSOR_NAME = "wear";
diff --git a/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
index eaf9bb5..ad9eb8f 100644
--- a/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
@@ -41,7 +41,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class TouchSoundPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/VibrateOnTouchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VibrateOnTouchPreferenceControllerTest.java
index b0ab54b..b469f9b 100644
--- a/tests/robotests/src/com/android/settings/notification/VibrateOnTouchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VibrateOnTouchPreferenceControllerTest.java
@@ -41,7 +41,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class VibrateOnTouchPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java
index 4695590..ea2c058 100644
--- a/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java
@@ -57,7 +57,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class VibrationPreferenceControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java
index ed658fe..cd8cdad 100644
--- a/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java
@@ -68,7 +68,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O, shadows = {
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, shadows = {
ShadowRestrictionUtils.class,
})
public class VisibilityPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
index a1d9205..f659e82 100644
--- a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
@@ -38,7 +38,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class VolumeSeekBarPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
index b091cd3..df98cff 100644
--- a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
@@ -35,7 +35,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class VolumeSeekBarPreferenceTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
index 0c826ed..a9abdce 100644
--- a/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
@@ -49,7 +49,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WorkSoundPreferenceControllerTest {
private static final String KEY_WORK_CATEGORY = "sound_work_settings_section";
diff --git a/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java
index 591378f..f65752f 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenAccessSettingsTest.java
@@ -36,7 +36,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ZenAccessSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java
index a1b4dab..a6f7b2b 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeButtonPreferenceControllerTest.java
@@ -130,4 +130,21 @@
verify(mZenButtonOn).setVisibility(View.VISIBLE);
verify(mZenButtonOff).setVisibility(View.GONE);
}
+
+ @Test
+ public void updateState_otherUserChangedZen() {
+ final Preference mockPref = mock(Preference.class);
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
+ mController.updateState(mockPref);
+ verify(mZenButtonOn).setVisibility(View.VISIBLE);
+ verify(mZenButtonOff).setVisibility(View.GONE);
+
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ final int GUEST_USER_ID = 10;
+ mController.mSettingObserver.onChange(false,
+ Settings.Global.getUriFor(Settings.Global.ZEN_MODE), GUEST_USER_ID);
+
+ verify(mZenButtonOn).setVisibility(View.GONE);
+ verify(mZenButtonOff).setVisibility(View.VISIBLE);
+ }
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
index 3cc87a8..c495759 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeCallsTest.java
@@ -41,7 +41,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ZenModeCallsTest {
private ZenModeCallsSettings mCalls;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
index fe92570..03226f9 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesTest.java
@@ -41,7 +41,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ZenModeMessagesTest {
private ZenModeMessagesSettings mMessages;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeScheduleRuleSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeScheduleRuleSettingsTest.java
index 89b3f2a..e45847d 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeScheduleRuleSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeScheduleRuleSettingsTest.java
@@ -47,7 +47,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
index fa2c6b9..966c927 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -38,7 +38,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ZenModeSettingsTest {
private ZenModeSettings.SummaryBuilder mBuilder;
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
index 28b0264..5b86374 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
@@ -47,7 +47,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class
})
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
index b8f0679..12c6b99 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
@@ -31,6 +31,7 @@
import com.android.settings.password.ChooseLockPassword.IntentBuilder;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.setupwizardlib.GlifLayout;
@@ -47,9 +48,10 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
+ SettingsShadowResourcesImpl.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowEventLogWriter.class,
ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
index c74448b..da3a157 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
@@ -29,6 +29,7 @@
import com.android.settings.password.ChooseLockPattern.IntentBuilder;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.setupwizardlib.GlifLayout;
@@ -43,9 +44,10 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
+ SettingsShadowResourcesImpl.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowEventLogWriter.class,
ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
index 20a05e3..55e60e5 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockSettingsHelperTest.java
@@ -33,7 +33,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
ShadowUserManager.class,
ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
index 0a0734f..2d82e0e 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
@@ -49,7 +49,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
ShadowEventLogWriter.class,
ShadowUserManager.class,
diff --git a/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java b/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
index d76968e..1568f19 100644
--- a/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
+++ b/tests/robotests/src/com/android/settings/password/ConfirmCredentialTest.java
@@ -35,7 +35,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java b/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java
index 8beefa8..f8792a8 100644
--- a/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java
+++ b/tests/robotests/src/com/android/settings/password/ScreenLockTypeTest.java
@@ -30,7 +30,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION)
+ sdk = TestConfig.SDK_VERSION_O)
public class ScreenLockTypeTest {
@Test
diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
index cb863a0..06086fc 100644
--- a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
@@ -38,7 +38,7 @@
import org.robolectric.shadows.ShadowActivity;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SetNewPasswordActivityTest {
private int mProvisioned;
diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
index 52678fb..a3f1787 100644
--- a/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
@@ -57,7 +57,7 @@
* Tests for {@link SetNewPasswordController}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public final class SetNewPasswordControllerTest {
private static final int CURRENT_USER_ID = 101;
private static final long FINGERPRINT_CHALLENGE = -9876512313131L;
diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
index 1195a2c..97fffd5 100644
--- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
@@ -34,6 +34,7 @@
import com.android.settings.password.SetupChooseLockPassword.SetupChooseLockPasswordFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -57,9 +58,10 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
+ SettingsShadowResourcesImpl.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowEventLogWriter.class,
ShadowUtils.class
diff --git a/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java b/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java
index 0e6f28a..6cd4244 100644
--- a/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupSkipDialogTest.java
@@ -40,7 +40,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/print/PrintSettingsFragmentTest.java b/tests/robotests/src/com/android/settings/print/PrintSettingsFragmentTest.java
index cf34f45..717fe88 100644
--- a/tests/robotests/src/com/android/settings/print/PrintSettingsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/print/PrintSettingsFragmentTest.java
@@ -45,7 +45,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PrintSettingsFragmentTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
index 0e4abe1..456f820 100644
--- a/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/AccessibilityServiceResultFutureTaskTest.java
@@ -28,6 +28,7 @@
import android.content.pm.ServiceInfo;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
+import android.os.UserManager;
import android.view.accessibility.AccessibilityManager;
import com.android.settings.TestConfig;
@@ -46,7 +47,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccessibilityServiceResultFutureTaskTest {
private static final String QUERY = "test_query";
@@ -59,6 +60,8 @@
private AccessibilityManager mAccessibilityManager;
@Mock
private SiteMapManager mSiteMapManager;
+ @Mock
+ private UserManager mUserManager;
private AccessibilityServiceResultLoader.AccessibilityServiceResultCallable mCallable;
@@ -67,6 +70,7 @@
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.ACCESSIBILITY_SERVICE))
.thenReturn(mAccessibilityManager);
+ when((Object)mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
mCallable = new AccessibilityServiceResultLoader.AccessibilityServiceResultCallable(
diff --git a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
index 6c6d7ab..4c19220 100644
--- a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
@@ -45,7 +45,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BaseSearchIndexProviderTest {
private static final String TEST_PREF_KEY = "test_pref_key";
diff --git a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
index cd62c15..f862529 100644
--- a/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/CursorToSearchResultConverterTest.java
@@ -52,7 +52,7 @@
import java.util.Set;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class CursorToSearchResultConverterTest {
private static final List<String> TITLES = Arrays.asList("title1", "title2", "title3");
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
index 20f58ad..7b5f474 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
@@ -70,7 +70,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
ShadowRunnableAsyncTask.class,
}
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
index 94ce487..4b662b6 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
@@ -35,7 +35,7 @@
import java.util.Map;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DatabaseIndexingUtilsTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java b/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
index fc15205..8194b12 100644
--- a/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineListPayloadTest.java
@@ -14,7 +14,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class InlineListPayloadTest {
private static final String DUMMY_SETTING = "inline_list_key";
diff --git a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
index 8bb558f..180e6a0 100644
--- a/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlinePayloadTest.java
@@ -17,7 +17,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class InlinePayloadTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
index 64778a0..895bf9c 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchPayloadTest.java
@@ -37,7 +37,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class InlineSwitchPayloadTest {
private static final String DUMMY_SETTING = "inline_test";
diff --git a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
index 86aee6f..a2319f3 100644
--- a/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/InlineSwitchViewHolderTest.java
@@ -43,7 +43,7 @@
import java.util.ArrayList;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class InlineSwitchViewHolderTest {
private static final String TITLE = "title";
diff --git a/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
index e31b3d7..73fe52c 100644
--- a/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/InputDeviceResultFutureTaskTest.java
@@ -56,7 +56,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
ShadowInputDevice.class
})
diff --git a/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java b/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
index 0e84dc7..1ed483d 100644
--- a/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/search/InstalledAppResultLoaderTest.java
@@ -65,7 +65,7 @@
import java.util.stream.Collectors;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class InstalledAppResultLoaderTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java b/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
index 4ec080c..14fe63a 100644
--- a/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/IntentSearchViewHolderTest.java
@@ -18,6 +18,8 @@
package com.android.settings.search;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -32,8 +34,10 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
+import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.View;
@@ -58,7 +62,7 @@
import java.util.Objects;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class IntentSearchViewHolderTest {
private static final String TITLE = "title";
@@ -72,6 +76,8 @@
private SearchFragment mFragment;
@Mock
private PackageManager mPackageManager;
+ @Mock
+ private UserManager mUserManager;
private FakeFeatureFactory mFeatureFactory;
private IntentSearchViewHolder mHolder;
private Drawable mIcon;
@@ -189,6 +195,9 @@
@Test
public void testBindViewElements_appSearchResult() {
+ mHolder = spy(mHolder);
+ doReturn(new ColorDrawable(0)).when(mHolder).getBadgedIcon(any(ApplicationInfo.class),
+ anyInt());
when(mPackageManager.getUserBadgedLabel(any(CharSequence.class),
eq(new UserHandle(USER_ID)))).thenReturn(BADGED_LABEL);
diff --git a/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java b/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
index 0bb43c5..2d9d4aa 100644
--- a/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/ResultPayloadTest.java
@@ -30,7 +30,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ResultPayloadTest {
private ResultPayload mPayload;
diff --git a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java b/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
index 50bdb84..a86089e 100644
--- a/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/ResultPayloadUtilsTest.java
@@ -30,7 +30,7 @@
import static junit.framework.Assert.fail;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ResultPayloadUtilsTest {
private ResultPayload payload;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
index 780a8a5d..4142111 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryLoaderTest.java
@@ -38,7 +38,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SavedQueryLoaderTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
index 7421d1a..0845aa6 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryPayloadTest.java
@@ -28,7 +28,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SavedQueryPayloadTest {
private SavedQueryPayload mPayload;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
index af8cfe4..5e1de45 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryRecorderAndRemoverTest.java
@@ -36,7 +36,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SavedQueryRecorderAndRemoverTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
index bb8f6d1..0bb30e9 100644
--- a/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SavedQueryViewHolderTest.java
@@ -38,7 +38,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SavedQueryViewHolderTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
index a3f3334..f1f633c 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFragmentTest.java
@@ -68,7 +68,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
index eedb324..90dba29 100644
--- a/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchIndexableResourcesTest.java
@@ -40,7 +40,7 @@
import java.util.Set;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SearchIndexableResourcesTest {
Set<Class> sProviderClassCopy;
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java b/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
index 286d7cf9..4dc0589 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultAggregatorTest.java
@@ -31,7 +31,7 @@
import java.util.concurrent.TimeUnit;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SearchResultAggregatorTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
index cd77b25..6d38aa8 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultBuilderTest.java
@@ -37,7 +37,7 @@
import java.util.ArrayList;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SearchResultBuilderTest {
private static final String TITLE = "title";
diff --git a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
index 4baf8d2..1dad447 100644
--- a/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchResultsAdapterTest.java
@@ -46,7 +46,7 @@
import java.util.Objects;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SearchResultsAdapterTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java b/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
index efeaed7..ac70a63 100644
--- a/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/SettingsSearchIndexablesProviderTest.java
@@ -27,7 +27,7 @@
import java.util.Set;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SettingsSearchIndexablesProviderTest {
private final String BASE_AUTHORITY = "com.android.settings";
diff --git a/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java b/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
index e285555..31026fc 100644
--- a/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
+++ b/tests/robotests/src/com/android/settings/search/StaticSearchResultFutureTaskTest.java
@@ -63,7 +63,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class StaticSearchResultFutureTaskTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
index 6050b32..4a9baa1 100644
--- a/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
+++ b/tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
@@ -43,7 +43,7 @@
* with another preference with a matchin replacement attribute.
*/
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class XmlParserUtilTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java b/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
new file mode 100644
index 0000000..52918fb
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.search.actionbar;
+
+import static org.mockito.Matchers.nullable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class SearchMenuControllerTest {
+
+ @Mock
+ private Menu mMenu;
+ private TestFragment mHost;
+ private FakeFeatureFactory mFeatureFactory;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mHost = new TestFragment();
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ }
+
+ @Test
+ public void init_searchV2Disabled_shouldNotAddMenu() {
+ when(mFeatureFactory.searchFeatureProvider.isSearchV2Enabled(nullable(Context.class)))
+ .thenReturn(false);
+
+ SearchMenuController.init(mHost);
+ mHost.getLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
+
+ verifyZeroInteractions(mMenu);
+ }
+
+ @Test
+ public void init_searchV2Enabled_shouldAddMenu() {
+ when(mFeatureFactory.searchFeatureProvider.isSearchV2Enabled(nullable(Context.class)))
+ .thenReturn(true);
+ when(mMenu.add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu))
+ .thenReturn(mock(MenuItem.class));
+
+ SearchMenuController.init(mHost);
+ mHost.getLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
+
+ verify(mMenu).add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu);
+ }
+
+ public static class TestFragment extends ObservablePreferenceFragment {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java b/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
index 0f2ab56..58003c4 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/IndexDataConverterTest.java
@@ -46,7 +46,7 @@
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, qualifiers = "mcc999")
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O, qualifiers = "mcc999")
public class IndexDataConverterTest {
private final String localeStr = "en_US";
diff --git a/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java b/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
index 1a05a2b..9fe647a 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/IndexDataTest.java
@@ -36,7 +36,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class IndexDataTest {
private IndexData.Builder mBuilder;
diff --git a/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java b/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
index 2bb03cb..ef16a37 100644
--- a/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
+++ b/tests/robotests/src/com/android/settings/search/indexing/PreIndexDataCollectorTest.java
@@ -46,7 +46,7 @@
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PreIndexDataCollectorTest {
private final String AUTHORITY_ONE = "authority";
diff --git a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
index ab7512f..df0cc2e 100644
--- a/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
+++ b/tests/robotests/src/com/android/settings/security/ConfigureKeyGuardDialogTest.java
@@ -36,7 +36,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = ShadowEventLogWriter.class
)
public class ConfigureKeyGuardDialogTest {
diff --git a/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java b/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
index 60e7dee..f5f0bb3 100644
--- a/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
+++ b/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
@@ -42,7 +42,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class EncryptionAndCredentialTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
index bb667f2..1a41c2d 100644
--- a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
@@ -30,7 +30,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class LockscreenDashboardFragmentTest {
private LockscreenDashboardFragment mFragment;
diff --git a/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java
index 71e2d8b..9bf8606 100644
--- a/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/OwnerInfoPreferenceControllerTest.java
@@ -16,13 +16,14 @@
package com.android.settings.security;
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.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -30,6 +31,7 @@
import android.app.FragmentTransaction;
import android.content.Context;
import android.support.v14.preference.PreferenceFragment;
+import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.widget.LockPatternUtils;
@@ -49,14 +51,16 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class OwnerInfoPreferenceControllerTest {
- @Mock(answer = RETURNS_DEEP_STUBS)
+ @Mock
private PreferenceFragment mFragment;
@Mock
private PreferenceScreen mScreen;
@Mock
+ private PreferenceManager mPreferenceManager;
+ @Mock
private FragmentManager mFragmentManager;
@Mock
private FragmentTransaction mFragmentTransaction;
@@ -76,7 +80,8 @@
when(mFragment.isAdded()).thenReturn(true);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
- when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
+ when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
+ when(mPreference.getContext()).thenReturn(mContext);
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
@@ -187,7 +192,8 @@
preference.performClick();
- verify(mFragment).getFragmentManager();
+ // Called once in setTargetFragment, and a second time to display the fragment.
+ verify(mFragment, times(2)).getFragmentManager();
verify(mFragment.getFragmentManager().beginTransaction())
.add(any(OwnerInfoSettings.class), anyString());
}
diff --git a/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
index 627ecf5..62ed3ab 100644
--- a/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/security/SecurityFeatureProviderImplTest.java
@@ -53,7 +53,7 @@
import org.robolectric.shadows.ShadowLooper;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SecurityFeatureProviderImplTest {
private static final String MOCK_KEY = "key";
diff --git a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
index 677bf41..4f0bee2 100644
--- a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
+++ b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
@@ -41,7 +41,7 @@
import java.util.Map;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SettingsSuggestionsTest {
private static final String CATEGORY_FIRST_IMPRESSION =
diff --git a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
index 5ad8500..19d6aa9 100644
--- a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java
@@ -52,7 +52,7 @@
import org.robolectric.shadows.ShadowPackageManager;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class NewDeviceIntroSuggestionActivityTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/support/SupportConfigTest.java b/tests/robotests/src/com/android/settings/support/SupportConfigTest.java
index 28b0a9d..ae4fcff 100644
--- a/tests/robotests/src/com/android/settings/support/SupportConfigTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportConfigTest.java
@@ -28,7 +28,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SupportConfigTest {
@Test
diff --git a/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java b/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
index 178e4ec..e7de81c 100644
--- a/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportDashboardActivityTest.java
@@ -40,7 +40,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SupportDashboardActivityTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java b/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
index 31c654c..cc025fb 100644
--- a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
@@ -40,7 +40,7 @@
import static org.robolectric.shadow.api.Shadow.directlyOn;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {SupportDisclaimerShadowResources.class})
public class SupportDisclaimerDialogFragmentTest {
diff --git a/tests/robotests/src/com/android/settings/support/actionbar/HelpMenuControllerTest.java b/tests/robotests/src/com/android/settings/support/actionbar/HelpMenuControllerTest.java
new file mode 100644
index 0000000..24e7d81
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/support/actionbar/HelpMenuControllerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.support.actionbar;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.os.Bundle;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class HelpMenuControllerTest {
+
+ @Mock
+ private Context mContext;
+ private TestFragment mHost;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mHost = spy(new TestFragment());
+ doReturn(mContext).when(mHost).getContext();
+ }
+
+ @Test
+ public void onCreateOptionsMenu_withArgumentOverride_shouldPrepareHelpUsingOverride() {
+ final Bundle bundle = new Bundle();
+ bundle.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 123);
+ mHost.setArguments(bundle);
+
+ HelpMenuController.init(mHost);
+
+ mHost.getLifecycle().onCreateOptionsMenu(null /* menu */, null /* inflater */);
+
+ verify(mContext).getString(123);
+
+ }
+
+ @Test
+ public void onCreateOptionsMenu_noArgumentOverride_shouldPrepareHelpUsingProvider() {
+ HelpMenuController.init(mHost);
+
+ mHost.getLifecycle().onCreateOptionsMenu(null /* menu */, null /* inflater */);
+
+ verify(mContext).getString(mHost.getHelpResource());
+ }
+
+
+ public static class TestFragment extends ObservablePreferenceFragment
+ implements HelpResourceProvider {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
index 116b63c..3dbd1e6 100644
--- a/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
+++ b/tests/robotests/src/com/android/settings/survey/SurveyMixinTest.java
@@ -32,7 +32,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SurveyMixinTest {
private static final String FAKE_KEY = "fake_key";
diff --git a/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
index b986e4f..7ae6cdb 100644
--- a/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/system/FactoryResetPreferenceControllerTest.java
@@ -39,7 +39,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowSecureSettings.class, ShadowUtils.class}
)
public class FactoryResetPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
index cd25953..8a1951a 100644
--- a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java
@@ -41,7 +41,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {
ShadowUserManager.class,
SettingsShadowResources.class,
diff --git a/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
index e1bc157..8c10c31 100644
--- a/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserFeatureProviderImplTest.java
@@ -37,7 +37,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserFeatureProviderImplTest {
public static final int FIRST_USER_ID = 0;
public static final int SECOND_USER_ID = 4;
diff --git a/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java b/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
index 5b31a82..242604a 100644
--- a/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserPreferenceTest.java
@@ -38,7 +38,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserPreferenceTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
index 56f3949..28b8c86 100644
--- a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
@@ -40,7 +40,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserSettingsTest {
@Mock private UserManager mUserManager;
diff --git a/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java b/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
index 690c292..ac6dc02 100644
--- a/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
+++ b/tests/robotests/src/com/android/settings/utils/LocalClassLoaderContextThemeWrapperTest.java
@@ -32,7 +32,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class LocalClassLoaderContextThemeWrapperTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java b/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
index 4b4f3fb..587a82a 100644
--- a/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/vpn2/AppDialogFragmentTest.java
@@ -33,7 +33,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AppDialogFragmentTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java b/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
index 9442892..5a029c7 100644
--- a/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/vpn2/VpnUtilsTest.java
@@ -32,7 +32,7 @@
* Tests for {@link VpnUtils}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public final class VpnUtilsTest {
@Test
public void testIsAlwaysOnVpnSet() {
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
index 470b69c..d06980b 100644
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
+++ b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
@@ -17,7 +17,9 @@
package com.android.settings.webview;
import static android.provider.Settings.ACTION_WEBVIEW_SETTINGS;
+
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
@@ -43,7 +45,6 @@
import com.android.settings.TestConfig;
import com.android.settings.applications.defaultapps.DefaultAppInfo;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
-import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.RadioButtonPreference;
import com.android.settings.wrapper.UserPackageWrapper;
@@ -62,16 +63,16 @@
import java.util.Arrays;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WebViewAppPickerTest {
- private Context mContext = RuntimeEnvironment.application;
+ private Context mContext;
private UserInfo mFirstUser;
private UserInfo mSecondUser;
private final static String DEFAULT_PACKAGE_NAME = "DEFAULT_PACKAGE_NAME";
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ @Mock
private Activity mActivity;
@Mock
private UserManager mUserManager;
@@ -90,8 +91,8 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mActivity);
- when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
mFirstUser = new UserInfo(0, "FIRST_USER", 0);
mSecondUser = new UserInfo(0, "SECOND_USER", 0);
mPicker = new WebViewAppPicker();
@@ -168,7 +169,7 @@
@Test
public void testDisabledPackageShownAsDisabled() {
String disabledReason = "disabled";
- DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -183,7 +184,7 @@
@Test
public void testEnabledPackageShownAsEnabled() {
String disabledReason = "";
- DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -198,7 +199,7 @@
@Test
public void testDisabledPackageShowsDisabledReasonSummary() {
String disabledReason = "disabled";
- DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -214,7 +215,7 @@
@Test
public void testEnabledPackageShowsEmptySummary() {
String disabledReason = null;
- DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
createApplicationInfo(DEFAULT_PACKAGE_NAME), disabledReason);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
@@ -228,14 +229,14 @@
@Test
public void testFinishIfNotAdmin() {
doReturn(false).when(mUserManager).isAdminUser();
- mPicker.onAttach((Context) mActivity);
+ mPicker.onAttach(mContext);
verify(mActivity, times(1)).finish();
}
@Test
public void testNotFinishedIfAdmin() {
doReturn(true).when(mUserManager).isAdminUser();
- mPicker.onAttach((Context) mActivity);
+ mPicker.onAttach(mContext);
verify(mActivity, never()).finish();
}
@@ -348,7 +349,7 @@
PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
- DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mActivity, mPackageManager,
+ DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mContext, mPackageManager,
mockPackageItemInfo, "" /* disabledReason */);
PackageInfo packageInfo = new PackageInfo();
diff --git a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
index 7d8ee52..a65bd3b 100644
--- a/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wfd/WifiDisplaySettingsTest.java
@@ -42,7 +42,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WifiDisplaySettingsTest {
@Mock
diff --git a/tests/unit/src/com/android/settings/core/PreferenceControllerContractTest.java b/tests/unit/src/com/android/settings/core/PreferenceControllerContractTest.java
index bc82125..86e8dc1 100644
--- a/tests/unit/src/com/android/settings/core/PreferenceControllerContractTest.java
+++ b/tests/unit/src/com/android/settings/core/PreferenceControllerContractTest.java
@@ -54,7 +54,7 @@
public void controllersInSearchShouldImplementPreferenceControllerMixin() {
final Set<String> errorClasses = new ArraySet<>();
- for (Class clazz: SearchIndexableResources.providerValues()) {
+ for (Class clazz : SearchIndexableResources.providerValues()) {
final Indexable.SearchIndexProvider provider =
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
@@ -68,7 +68,8 @@
continue;
}
for (AbstractPreferenceController controller : controllers) {
- if (!(controller instanceof PreferenceControllerMixin)) {
+ if (!(controller instanceof PreferenceControllerMixin)
+ && !(controller instanceof BasePreferenceController)) {
errorClasses.add(controller.getClass().getName());
}
}
@@ -76,7 +77,8 @@
if (!errorClasses.isEmpty()) {
final StringBuilder errorMessage = new StringBuilder()
- .append("Each preference must implement PreferenceControllerMixin, ")
+ .append("Each preference must implement PreferenceControllerMixin ")
+ .append("or extend BasePreferenceController, ")
.append("the following classes don't:\n");
for (String c : errorClasses) {
errorMessage.append(c).append("\n");