Merge "Use new OverlayManager categories"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5e4f1e8..1951afd 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -92,6 +92,7 @@
<uses-permission android:name="android.permission.NETWORK_SETTINGS" />
<uses-permission android:name="android.permission.TEST_BLACKLISTED_PASSWORD" />
<uses-permission android:name="android.permission.USE_RESERVED_DISK" />
+ <uses-permission android:name="android.permission.MANAGE_SCOPED_ACCESS_DIRECTORY_PERMISSIONS" />
<application android:label="@string/settings_label"
android:icon="@drawable/ic_launcher_settings"
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 0cf085f..f20b93c 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -173,4 +173,7 @@
<!-- Whether wifi_mac_address should be shown or not. -->
<bool name="config_show_wifi_mac_address">true</bool>
+
+ <!-- Whether to disable "Uninstall Updates" menu item for System apps or not.. -->
+ <bool name="config_disable_uninstall_update">false</bool>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7d4b3e9..ad11706 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2142,6 +2142,8 @@
<string name="wifi_hotspot_configure_ap_text_summary">AndroidAP WPA2 PSK hotspot</string>
<!-- Default access point SSID used for tethering -->
<string name="wifi_tether_configure_ssid_default">AndroidHotspot</string>
+ <!-- Summary text when hotspot is disabled because airplane mode is on [CHAR LIMIT=80]-->
+ <string name="wifi_tether_disabled_by_airplane">Unavailable because airplane mode is turned on</string>
<!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
Wi-Fi Testing on the diagnostic screen-->
@@ -6317,13 +6319,6 @@
<!-- Applicaitons with restrictions - settings button [CHAR LIMIT=30] -->
<string name="apps_with_restrictions_settings_button">Expand settings for application</string>
- <!-- Warning message when changing a global setting for a tablet.[CHAR LIMIT=none] -->
- <string name="global_change_warning" product="tablet">This setting affects all users on this tablet.</string>
- <!-- Warning message when changing a global setting for a phone.[CHAR LIMIT=none] -->
- <string name="global_change_warning" product="default">This setting affects all users on this phone.</string>
- <!-- Warning message title for global locale change [CHAR LIMIT=40] -->
- <string name="global_locale_change_title">Change language</string>
-
<!-- NFC payment settings --><skip/>
<string name="nfc_payment_settings_title">Tap & pay</string>
<!-- Caption for button linking to a page explaining how Tap and Pay works-->
@@ -9223,6 +9218,8 @@
<!-- Confirmation message displayed when the user taps Clear app, to ensure they want to remove
the instant app from the device. -->
<string name="clear_instant_app_confirmation">Do you want to remove this instant app?</string>
+ <!-- Label for button that allows user to launch the instant app. -->
+ <string name="launch_instant_app">Open</string>
<!-- Title of games app storage screen [CHAR LIMIT=30] -->
<string name="game_storage_settings">Games</string>
diff --git a/res/xml/accessibility_vibration_settings.xml b/res/xml/accessibility_vibration_settings.xml
index d61454d..17468ea 100644
--- a/res/xml/accessibility_vibration_settings.xml
+++ b/res/xml/accessibility_vibration_settings.xml
@@ -15,7 +15,7 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:key="accessibility_settings_screen"
+ android:key="accessibility_settings_vibration_screen"
android:title="@string/accessibility_vibration_settings_title"
android:persistent="true">
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 76b48d1..84b1071 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -59,6 +59,7 @@
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.backup.BackupSettingsActivity;
import com.android.settings.core.FeatureFlags;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.gateway.SettingsGateway;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.DashboardSummary;
@@ -612,11 +613,10 @@
* @param fragmentClass Full name of the class implementing the fragment.
* @param args Any desired arguments to supply to the fragment.
* @param titleRes Optional resource identifier of the title of this fragment.
- * @param titleText Optional text of the title of this fragment.
* @param userHandle The user for which the panel has to be started.
*/
public void startPreferencePanelAsUser(Fragment caller, String fragmentClass,
- Bundle args, int titleRes, CharSequence titleText, UserHandle userHandle) {
+ Bundle args, int titleRes, UserHandle userHandle) {
// This is a workaround.
//
// Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
@@ -628,19 +628,17 @@
// another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
// when we're calling it as the same user.
if (userHandle.getIdentifier() == UserHandle.myUserId()) {
- startPreferencePanel(caller, fragmentClass, args, titleRes, titleText, null, 0);
+ startPreferencePanel(caller, fragmentClass, args, titleRes, null /* titleText */,
+ null, 0);
} else {
- String title = null;
- if (titleRes < 0) {
- if (titleText != null) {
- title = titleText.toString();
- } else {
- // There not much we can do in that case
- title = "";
- }
- }
- Utils.startWithFragmentAsUser(this, fragmentClass, args, titleRes, title,
- mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller), userHandle);
+ new SubSettingLauncher(this)
+ .setDestination(fragmentClass)
+ .setArguments(args)
+ .setTitle(titleRes)
+ .setIsShortCut(mIsShortcut)
+ .setSourceMetricsCategory(mMetricsFeatureProvider.getMetricsCategory(caller))
+ .setUserHandle(userHandle)
+ .launch();
}
}
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 1a32127..3923da5 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -23,9 +23,7 @@
import android.annotation.Nullable;
import android.app.ActivityManager;
-import android.app.AlertDialog;
import android.app.AppGlobals;
-import android.app.Dialog;
import android.app.Fragment;
import android.app.IActivityManager;
import android.app.KeyguardManager;
@@ -34,7 +32,6 @@
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
@@ -52,9 +49,6 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.fingerprint.FingerprintManager;
-import android.icu.text.RelativeDateTimeFormatter;
-import android.icu.text.RelativeDateTimeFormatter.RelativeUnit;
-import android.icu.util.ULocale;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
@@ -107,7 +101,6 @@
import com.android.settings.wrapper.FingerprintManagerWrapper;
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
-import com.android.settingslib.utils.StringUtil;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Iterator;
@@ -237,16 +230,6 @@
return null;
}
- /**
- * Returns the default link's IP addresses, if any, taking into account IPv4 and IPv6 style
- * addresses.
- * @return the formatted and newline-separated IP addresses, or null if none.
- */
- public static String getDefaultIpAddresses(ConnectivityManager cm) {
- LinkProperties prop = cm.getActiveLinkProperties();
- return formatIpAddresses(prop);
- }
-
private static String formatIpAddresses(LinkProperties prop) {
if (prop == null) return null;
Iterator<InetAddress> iter = prop.getAllAddresses().iterator();
@@ -400,23 +383,6 @@
}
}
- /** Not global warming, it's global change warning. */
- public static Dialog buildGlobalChangeWarningDialog(final Context context, int titleResId,
- final Runnable positiveAction) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(titleResId);
- builder.setMessage(R.string.global_change_warning);
- builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- positiveAction.run();
- }
- });
- builder.setNegativeButton(android.R.string.cancel, null);
-
- return builder.create();
- }
-
public static boolean hasMultipleUsers(Context context) {
return ((UserManager) context.getSystemService(Context.USER_SERVICE))
.getUsers().size() > 1;
@@ -446,26 +412,6 @@
metricsCategory);
}
-
- /**
- * Start a new instance of the activity, showing only the given fragment.
- * When launched in this mode, the given preference fragment will be instantiated and fill the
- * entire activity.
- *
- * @param context The context.
- * @param fragmentName The name of the fragment to display.
- * @param titleResId resource id for the String to display for the title of this set
- * of preferences.
- * @param metricsCategory The current metricsCategory for logging source when fragment starts
- * @param intentFlags flag that should be added to the intent.
- */
- public static void startWithFragment(Context context, String fragmentName, int titleResId,
- int metricsCategory, int intentFlags) {
- startWithFragment(context, fragmentName, null, null, 0,
- null /* titleResPackageName */, titleResId, null, false /* not a shortcut */,
- metricsCategory, intentFlags);
- }
-
/**
* Start a new instance of the activity, showing only the given fragment.
* When launched in this mode, the given preference fragment will be instantiated and fill the
@@ -477,21 +423,12 @@
* @param resultTo Option fragment that should receive the result of the activity launch.
* @param resultRequestCode If resultTo is non-null, this is the request code in which
* to report the result.
- * @param titleResPackageName Optional package name for the resource id of the title.
* @param titleResId resource id for the String to display for the title of this set
* of preferences.
* @param title String to display for the title of this set of preferences.
* @param metricsCategory The current metricsCategory for logging source when fragment starts
*/
public static void startWithFragment(Context context, String fragmentName, Bundle args,
- Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
- CharSequence title, int metricsCategory) {
- startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
- titleResPackageName, titleResId, title, false /* not a shortcut */,
- metricsCategory);
- }
-
- public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, int titleResId,
CharSequence title, boolean isShortcut, int metricsCategory) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args,
@@ -506,18 +443,9 @@
public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
CharSequence title, boolean isShortcut, int metricsCategory) {
- startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
- titleResPackageName, titleResId, title, isShortcut, metricsCategory,
- Intent.FLAG_ACTIVITY_NEW_TASK);
- }
-
-
- public static void startWithFragment(Context context, String fragmentName, Bundle args,
- Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
- CharSequence title, boolean isShortcut, int metricsCategory, int flags) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName,
titleResId, title, isShortcut, metricsCategory);
- intent.addFlags(flags);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (resultTo == null) {
context.startActivity(intent);
} else {
@@ -525,22 +453,6 @@
}
}
- public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args,
- int titleResId, CharSequence title, boolean isShortcut, int metricsCategory,
- UserHandle userHandle) {
- // workaround to avoid crash in b/17523189
- if (userHandle.getIdentifier() == UserHandle.myUserId()) {
- startWithFragment(context, fragmentName, args, null, 0, titleResId, title, isShortcut,
- metricsCategory);
- } else {
- Intent intent = onBuildStartFragmentIntent(context, fragmentName, args,
- null /* titleResPackageName */, titleResId, title, isShortcut, metricsCategory);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- context.startActivityAsUser(intent, userHandle);
- }
- }
-
/**
* Build an Intent to launch a new activity showing the selected fragment.
* The implementation constructs an Intent that re-launches the current activity with the
diff --git a/src/com/android/settings/accounts/AccountDashboardFragment.java b/src/com/android/settings/accounts/AccountDashboardFragment.java
index 0a4c343..9702102 100644
--- a/src/com/android/settings/accounts/AccountDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDashboardFragment.java
@@ -22,6 +22,7 @@
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import android.text.BidiFormatter;
+import android.text.TextUtils;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -94,17 +95,21 @@
if (types == null || types.length == 0) {
summary = mContext.getString(R.string.account_dashboard_default_summary);
} else {
- // Show up to 3 account types
- final int size = Math.min(3, types.length);
+ // Show up to 3 account types, ignore any null value
+ int accountToAdd = Math.min(3, types.length);
- for (int i = 0; i < size; i++) {
+ for (int i = 0; i < types.length && accountToAdd > 0; i++) {
final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
+ if (TextUtils.isEmpty(label)) {
+ continue;
+ }
if (summary == null) {
summary = bidiFormatter.unicodeWrap(label);
} else {
summary = mContext.getString(R.string.join_many_items_middle, summary,
bidiFormatter.unicodeWrap(label));
}
+ accountToAdd--;
}
}
mSummaryLoader.setSummary(this, summary);
diff --git a/src/com/android/settings/accounts/AccountTypePreference.java b/src/com/android/settings/accounts/AccountTypePreference.java
index 574cbd5..e08f113 100644
--- a/src/com/android/settings/accounts/AccountTypePreference.java
+++ b/src/com/android/settings/accounts/AccountTypePreference.java
@@ -28,11 +28,13 @@
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import com.android.settings.Utils;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settings.widget.AppPreference;
public class AccountTypePreference extends AppPreference implements OnPreferenceClickListener {
/**
* Title of the tile that is shown to the user.
+ *
* @attr ref android.R.styleable#PreferenceHeader_title
*/
private final CharSequence mTitle;
@@ -56,6 +58,7 @@
/**
* Full class name of the fragment to display when this tile is
* selected.
+ *
* @attr ref android.R.styleable#PreferenceHeader_fragment
*/
private final String mFragment;
@@ -92,19 +95,21 @@
public boolean onPreferenceClick(Preference preference) {
if (mFragment != null) {
UserManager userManager =
- (UserManager) getContext().getSystemService(Context.USER_SERVICE);
+ (UserManager) getContext().getSystemService(Context.USER_SERVICE);
UserHandle user = mFragmentArguments.getParcelable(EXTRA_USER);
if (user != null && Utils.startQuietModeDialogIfNecessary(getContext(), userManager,
- user.getIdentifier())) {
+ user.getIdentifier())) {
return true;
} else if (user != null && Utils.unlockWorkProfileIfNecessary(getContext(),
- user.getIdentifier())) {
+ user.getIdentifier())) {
return true;
}
- Utils.startWithFragment(getContext(), mFragment, mFragmentArguments,
- null /* resultTo */, 0 /* resultRequestCode */, mTitleResPackageName,
- mTitleResId, null /* title */,false /* isShortCut */, mMetricsCategory,
- 0 /* flag */);
+ new SubSettingLauncher(getContext())
+ .setDestination(mFragment)
+ .setArguments(mFragmentArguments)
+ .setTitle(mTitleResPackageName, mTitleResId)
+ .setSourceMetricsCategory(mMetricsCategory)
+ .launch();
return true;
}
return false;
diff --git a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
index 5790d34..5e12503 100755
--- a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
+++ b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
@@ -82,8 +82,8 @@
private static final String TAG = "AppInfoDashboard";
// Menu identifiers
- private static final int UNINSTALL_ALL_USERS_MENU = 1;
- private static final int UNINSTALL_UPDATES = 2;
+ @VisibleForTesting static final int UNINSTALL_ALL_USERS_MENU = 1;
+ @VisibleForTesting static final int UNINSTALL_UPDATES = 2;
static final int FORCE_STOP_MENU = 3;
// Result code identifiers
@@ -330,7 +330,10 @@
menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(shouldShowUninstallForAll(mAppEntry));
mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
final MenuItem uninstallUpdatesItem = menu.findItem(UNINSTALL_UPDATES);
- uninstallUpdatesItem.setVisible(mUpdatedSysApp && !mAppsControlDisallowedBySystem);
+ final boolean uninstallUpdateDisabled = getContext().getResources().getBoolean(
+ R.bool.config_disable_uninstall_update);
+ uninstallUpdatesItem.setVisible(
+ mUpdatedSysApp && !mAppsControlDisallowedBySystem && !uninstallUpdateDisabled);
if (uninstallUpdatesItem.isVisible()) {
RestrictedLockUtils.setMenuItemAsDisabledByAdmin(getActivity(),
uninstallUpdatesItem, mAppsControlDisallowedAdmin);
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
index d116f91..30835fb 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
@@ -195,6 +195,14 @@
candidates.add(new DefaultAppInfo(context, mPm, mUserId, new ComponentName(
info.serviceInfo.packageName, info.serviceInfo.name)));
}
+ if (Manifest.permission.BIND_AUTOFILL.equals(permission)) {
+ // Let it go for now...
+ Log.w(TAG, "AutofillService from '" + info.serviceInfo.packageName
+ + "' uses unsupported permission " + Manifest.permission.BIND_AUTOFILL
+ + ". It works for now, but might not be supported on future releases");
+ candidates.add(new DefaultAppInfo(context, mPm, mUserId, new ComponentName(
+ info.serviceInfo.packageName, info.serviceInfo.name)));
+ }
}
return candidates;
}
diff --git a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
index 331907b..35b7c27 100644
--- a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
@@ -88,7 +88,7 @@
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY_TOGGLE_BLUETOOTH.equals(preference.getKey())) {
mActivity.startPreferencePanelAsUser(mFragment, BluetoothSettings.class.getName(), null,
- R.string.bluetooth, null, new UserHandle(UserHandle.myUserId()));
+ R.string.bluetooth, new UserHandle(UserHandle.myUserId()));
return true;
}
return super.handlePreferenceTreeClick(preference);
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java
index 8ac64e8..89826fe 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java
@@ -60,7 +60,7 @@
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY_PAIRING.equals(preference.getKey())) {
mActivity.startPreferencePanelAsUser(mFragment, BluetoothPairingDetail.class.getName(),
- null, R.string.bluetooth_pairing_page_title, null,
+ null, R.string.bluetooth_pairing_page_title,
new UserHandle(UserHandle.myUserId()));
return true;
}
diff --git a/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesController.java b/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesController.java
index 1375b4c..1f662c0 100644
--- a/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesController.java
+++ b/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesController.java
@@ -17,6 +17,8 @@
package com.android.settings.connecteddevice.usb;
import com.android.settings.R;
+import com.android.settings.Utils;
+
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.support.v14.preference.PreferenceFragment;
@@ -136,11 +138,18 @@
} else {
mode &= ~thisMode;
}
- mUsbBackend.setMode(mode);
+ if (!Utils.isMonkeyRunning()) {
+ mUsbBackend.setMode(mode);
+ }
return false;
}
@Override
+ public boolean isAvailable() {
+ return !Utils.isMonkeyRunning();
+ }
+
+ @Override
public String getPreferenceKey() {
return mKey;
}
diff --git a/src/com/android/settings/core/SubSettingLauncher.java b/src/com/android/settings/core/SubSettingLauncher.java
new file mode 100644
index 0000000..8e0f859
--- /dev/null
+++ b/src/com/android/settings/core/SubSettingLauncher.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.core;
+
+import android.annotation.StringRes;
+import android.app.Fragment;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
+
+import com.android.settings.SettingsActivity;
+import com.android.settings.SubSettings;
+import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
+
+public class SubSettingLauncher {
+
+ private final Context mContext;
+ private final LaunchRequest mLaunchRequest;
+ private boolean mLaunched;
+
+ public SubSettingLauncher(Context context) {
+ if (context == null) {
+ throw new IllegalArgumentException("Context must be non-null.");
+ }
+ mContext = context;
+ mLaunchRequest = new LaunchRequest();
+ }
+
+ public SubSettingLauncher setDestination(String fragmentName) {
+ mLaunchRequest.destinationName = fragmentName;
+ return this;
+ }
+
+ public SubSettingLauncher setTitle(@StringRes int titleResId) {
+ return setTitle(null /*titlePackageName*/, titleResId);
+ }
+
+ public SubSettingLauncher setTitle(String titlePackageName, @StringRes int titleResId) {
+ mLaunchRequest.titleResPackageName = titlePackageName;
+ mLaunchRequest.titleResId = titleResId;
+ mLaunchRequest.title = null;
+ return this;
+ }
+
+ public SubSettingLauncher setTitle(CharSequence title) {
+ mLaunchRequest.title = title;
+ return this;
+ }
+
+ public SubSettingLauncher setIsShortCut(boolean isShortCut) {
+ mLaunchRequest.isShortCut = isShortCut;
+ return this;
+ }
+
+ public SubSettingLauncher setArguments(Bundle arguments) {
+ mLaunchRequest.arguments = arguments;
+ return this;
+ }
+
+ public SubSettingLauncher setSourceMetricsCategory(int sourceMetricsCategory) {
+ mLaunchRequest.sourceMetricsCategory = sourceMetricsCategory;
+ return this;
+ }
+
+ public SubSettingLauncher setResultListener(Fragment listener, int resultRequestCode) {
+ mLaunchRequest.mRequestCode = resultRequestCode;
+ mLaunchRequest.mResultListener = listener;
+ return this;
+ }
+
+ public SubSettingLauncher addFlags(int flags) {
+ mLaunchRequest.flags |= flags;
+ return this;
+ }
+
+ public SubSettingLauncher setUserHandle(UserHandle userHandle) {
+ mLaunchRequest.userHandle = userHandle;
+ return this;
+ }
+
+ public void launch() {
+ if (mLaunched) {
+ throw new IllegalStateException(
+ "This launcher has already been executed. Do not reuse");
+ }
+ mLaunched = true;
+ final Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setClass(mContext, SubSettings.class);
+ if (TextUtils.isEmpty(mLaunchRequest.destinationName)) {
+ throw new IllegalArgumentException("Destination fragment must be set");
+ }
+ intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, mLaunchRequest.destinationName);
+
+ if (mLaunchRequest.sourceMetricsCategory <= 0) {
+ throw new IllegalArgumentException("Source metrics category must be set");
+ }
+ intent.putExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY,
+ mLaunchRequest.sourceMetricsCategory);
+
+ intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, mLaunchRequest.arguments);
+ intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME,
+ mLaunchRequest.titleResPackageName);
+ intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID,
+ mLaunchRequest.titleResId);
+ intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, mLaunchRequest.title);
+ intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT,
+ mLaunchRequest.isShortCut);
+ intent.addFlags(mLaunchRequest.flags);
+
+ if (mLaunchRequest.userHandle != null
+ && mLaunchRequest.userHandle.getIdentifier() != UserHandle.myUserId()) {
+ launchAsUser(mContext, intent, mLaunchRequest.userHandle);
+ } else if (mLaunchRequest.mResultListener != null) {
+ launchForResult(mLaunchRequest.mResultListener, intent, mLaunchRequest.mRequestCode);
+ } else {
+ launch(intent);
+ }
+ }
+
+ @VisibleForTesting
+ void launch(Intent intent) {
+ mContext.startActivity(intent);
+ }
+
+ private static void launchForResult(Fragment listener, Intent intent, int requestCode) {
+ listener.getActivity().startActivityForResult(intent, requestCode);
+ }
+
+ private static void launchAsUser(Context context, Intent intent, UserHandle userHandle) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ context.startActivityAsUser(intent, userHandle);
+ }
+
+ /**
+ * Simple container that has information about how to launch a subsetting.
+ */
+ static class LaunchRequest {
+ String destinationName;
+ int titleResId;
+ String titleResPackageName;
+ CharSequence title;
+ boolean isShortCut;
+ int sourceMetricsCategory = -100;
+ int flags;
+ Fragment mResultListener;
+ int mRequestCode;
+ UserHandle userHandle;
+ Bundle arguments;
+ }
+}
diff --git a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
index 275af3d..29d66bd 100644
--- a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
+++ b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
@@ -19,12 +19,11 @@
import android.util.ArrayMap;
import com.android.settings.DisplaySettings;
-import com.android.settings.accounts.AccountDetailDashboardFragment;
import com.android.settings.accounts.AccountDashboardFragment;
+import com.android.settings.accounts.AccountDetailDashboardFragment;
import com.android.settings.applications.AppAndNotificationDashboardFragment;
import com.android.settings.applications.DefaultAppSettings;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
-import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.fuelgauge.PowerUsageSummary;
@@ -60,9 +59,6 @@
PARENT_TO_CATEGORY_KEY_MAP = new ArrayMap<>();
PARENT_TO_CATEGORY_KEY_MAP.put(
NetworkDashboardFragment.class.getName(), CategoryKey.CATEGORY_NETWORK);
- //TODO(b/69471219): update ConnectedDeviceDashboardFragment once new feature is done.
- PARENT_TO_CATEGORY_KEY_MAP.put(ConnectedDeviceDashboardFragmentOld.class.getName(),
- CategoryKey.CATEGORY_DEVICE);
PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedConnectedDeviceDashboardFragment.class.getName(),
CategoryKey.CATEGORY_DEVICE);
PARENT_TO_CATEGORY_KEY_MAP.put(AppAndNotificationDashboardFragment.class.getName(),
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java
index 261f66c..23fc35b 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerDescriptionPreferenceController.java
@@ -23,6 +23,7 @@
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
/**
@@ -57,7 +58,7 @@
cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_BYTES_CLEARED, 0);
long lastRunMillis =
Settings.Secure.getLong(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_LAST_RUN, 0);
- if (freedBytes == 0 || lastRunMillis == 0 || !isStorageManagerEnabled(cr)) {
+ if (freedBytes == 0 || lastRunMillis == 0 || !Utils.isStorageManagerEnabled(context)) {
preference.setSummary(R.string.automatic_storage_manager_text);
} else {
preference.setSummary(
@@ -68,9 +69,4 @@
context, lastRunMillis, DateUtils.FORMAT_SHOW_DATE)));
}
}
-
- private boolean isStorageManagerEnabled(ContentResolver cr) {
- return Settings.Secure.getInt(cr, Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)
- != 0;
- }
}
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index 184c0c5..22ecb09 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -96,7 +96,7 @@
@Override
public void onResume() {
super.onResume();
- mDaysToRetain.setEnabled(isStorageManagerEnabled());
+ mDaysToRetain.setEnabled(Utils.isStorageManagerEnabled(getContext()));
}
@Override
@@ -153,12 +153,6 @@
return indices.length - 1;
}
- private boolean isStorageManagerEnabled() {
- return Settings.Secure.getInt(
- getContentResolver(), Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0)
- != 0;
- }
-
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new AutomaticStorageManagerDescriptionPreferenceController(context));
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
index a20afa1..c02fb10 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
@@ -27,6 +27,7 @@
import com.android.internal.util.Preconditions;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.Utils;
/** Handles the logic for flipping the storage management toggle on a {@link SwitchBar}. */
public class AutomaticStorageManagerSwitchBarController
@@ -56,13 +57,7 @@
}
private void initializeCheckedStatus() {
- boolean isStorageManagerChecked =
- Settings.Secure.getInt(
- mContext.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
- 0)
- != 0;
- mSwitchBar.setChecked(isStorageManagerChecked);
+ mSwitchBar.setChecked(Utils.isStorageManagerEnabled(mContext));
mSwitchBar.addOnSwitchChangeListener(this);
}
diff --git a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
index 8ab21b3..7724b00 100644
--- a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -23,12 +23,14 @@
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.PreferenceScreen;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.deletionhelper.ActivationWarningFragment;
import com.android.settings.widget.MasterSwitchController;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settings.widget.SwitchWidgetController;
+import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -74,9 +76,7 @@
if (!isAvailable()) {
return;
}
- boolean isStorageManagerEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
- mSwitch.setChecked(isStorageManagerEnabled);
+ mSwitch.setChecked(Utils.isStorageManagerEnabled(mContext));
if (mSwitch != null) {
mSwitchController = new MasterSwitchController(mSwitch);
@@ -97,9 +97,9 @@
SystemProperties.getBoolean(STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, false);
final boolean storageManagerDisabledByPolicy =
Settings.Secure.getInt(
- mContext.getContentResolver(),
- Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY,
- 0)
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY,
+ 0)
!= 0;
// Show warning if it is disabled by default and turning it on or if it was disabled by
// policy and we're turning it on.
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 981b0dc..6cf07a4 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -45,20 +45,20 @@
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.fuelgauge.anomaly.AnomalyUtils;
-import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
-import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
-import com.android.settings.wrapper.DevicePolicyManagerWrapper;
import com.android.settings.fuelgauge.anomaly.Anomaly;
import com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment;
import com.android.settings.fuelgauge.anomaly.AnomalyLoader;
import com.android.settings.fuelgauge.anomaly.AnomalySummaryPreferenceController;
+import com.android.settings.fuelgauge.anomaly.AnomalyUtils;
+import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.widget.EntityHeaderController;
+import com.android.settings.wrapper.DevicePolicyManagerWrapper;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.core.AbstractPreferenceController;
-
import com.android.settingslib.utils.StringUtil;
+
import java.util.ArrayList;
import java.util.List;
@@ -158,7 +158,7 @@
args.putParcelableList(EXTRA_ANOMALY_LIST, anomalies);
caller.startPreferencePanelAsUser(fragment, AdvancedPowerUsageDetail.class.getName(), args,
- R.string.battery_details_title, null,
+ R.string.battery_details_title,
new UserHandle(getUserIdToLaunchAdvancePowerUsageDetail(sipper)));
}
@@ -189,7 +189,7 @@
}
caller.startPreferencePanelAsUser(fragment, AdvancedPowerUsageDetail.class.getName(), args,
- R.string.battery_details_title, null, new UserHandle(UserHandle.myUserId()));
+ R.string.battery_details_title, new UserHandle(UserHandle.myUserId()));
}
@Override
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java b/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java
index 143733d..c7972e2 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java
@@ -17,7 +17,6 @@
package com.android.settings.fuelgauge;
import android.content.Context;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -69,8 +68,7 @@
args.putParcelableList(EXTRA_ANOMALY_LIST, anomalies);
caller.startPreferencePanelAsUser(fragment, PowerUsageAnomalyDetails.class.getName(), args,
- R.string.battery_abnormal_details_title, null,
- new UserHandle(UserHandle.myUserId()));
+ R.string.battery_abnormal_details_title, new UserHandle(UserHandle.myUserId()));
}
@Override
diff --git a/src/com/android/settings/fuelgauge/RestrictedAppDetails.java b/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
index e09a8a3..3045261 100644
--- a/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
+++ b/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
@@ -66,7 +66,7 @@
args.putParcelableList(EXTRA_PACKAGE_OPS_LIST, packageOpsList);
caller.startPreferencePanelAsUser(fragment, RestrictedAppDetails.class.getName(), args,
- R.string.restricted_app_title, null /* titleText */,
+ R.string.restricted_app_title,
new UserHandle(UserHandle.myUserId()));
}
diff --git a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java
index 1c787ab..1cc72a7 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java
@@ -20,6 +20,7 @@
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
+import android.os.Looper;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
@@ -46,7 +47,7 @@
public AutoBatterySeekBarPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_AUTO_BATTERY_SEEK_BAR);
- mContentObserver = new AutoBatterySaverSettingObserver(new Handler());
+ mContentObserver = new AutoBatterySaverSettingObserver(new Handler(Looper.getMainLooper()));
if (lifecycle != null) {
lifecycle.addObserver(this);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
index cbd1581..58a95ac 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
@@ -18,12 +18,10 @@
import android.app.Fragment;
import android.os.UserHandle;
-import android.support.v14.preference.PreferenceFragment;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.SmartBatterySettings;
-import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
public class SmartBatteryAction extends BatteryTipAction {
private SettingsActivity mSettingsActivity;
@@ -42,7 +40,7 @@
public void handlePositiveAction() {
mSettingsActivity.startPreferencePanelAsUser(mFragment,
SmartBatterySettings.class.getName(), null /* args */,
- R.string.smart_battery_manager_title, null /* titleText */,
+ R.string.smart_battery_manager_title,
new UserHandle(UserHandle.myUserId()));
}
}
diff --git a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
index b17d19e..afcdb64 100644
--- a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
@@ -60,7 +60,7 @@
((SettingsActivity) mFragment.getActivity()).startPreferencePanelAsUser(
mFragment,
AppInfoDashboardFragment.class.getName(), args,
- R.string.application_info_label, null, mUserHandle);
+ R.string.application_info_label, mUserHandle);
return true;
}
}
diff --git a/src/com/android/settings/vpn2/AppManagementFragment.java b/src/com/android/settings/vpn2/AppManagementFragment.java
index 9e215d1..b554c83 100644
--- a/src/com/android/settings/vpn2/AppManagementFragment.java
+++ b/src/com/android/settings/vpn2/AppManagementFragment.java
@@ -44,7 +44,7 @@
import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.Utils;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -100,10 +100,15 @@
};
public static void show(Context context, AppPreference pref, int sourceMetricsCategory) {
- Bundle args = new Bundle();
+ final Bundle args = new Bundle();
args.putString(ARG_PACKAGE_NAME, pref.getPackageName());
- Utils.startWithFragmentAsUser(context, AppManagementFragment.class.getName(), args, -1,
- pref.getLabel(), false, sourceMetricsCategory, new UserHandle(pref.getUserId()));
+ new SubSettingLauncher(context)
+ .setDestination(AppManagementFragment.class.getName())
+ .setArguments(args)
+ .setTitle(pref.getLabel())
+ .setSourceMetricsCategory(sourceMetricsCategory)
+ .setUserHandle(new UserHandle(pref.getUserId()))
+ .launch();
}
@Override
diff --git a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
index 8d798b1..0874cea 100644
--- a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
+++ b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
@@ -26,7 +26,7 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
-import com.android.settings.Utils;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settings.wrapper.WallpaperManagerWrapper;
public class WallpaperSuggestionActivity extends Activity {
@@ -51,9 +51,12 @@
@VisibleForTesting
void startFallbackSuggestion() {
// fall back to default wallpaper picker
- Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(),
- R.string.wallpaper_suggestion_title, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY,
- Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ new SubSettingLauncher(this)
+ .setDestination(WallpaperTypeSettings.class.getName())
+ .setTitle(R.string.wallpaper_suggestion_title)
+ .setSourceMetricsCategory(MetricsProto.MetricsEvent.DASHBOARD_SUMMARY)
+ .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
+ .launch();
}
@VisibleForTesting
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
index 826ed42..058ba5f 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
@@ -202,7 +202,7 @@
boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
if (isAirplaneMode) {
- mPreference.setSummary(R.string.summary_placeholder);
+ mPreference.setSummary(R.string.wifi_tether_disabled_by_airplane);
}
}
//
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index f43e39c..01bfa51 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -62,4 +62,5 @@
<bool name="config_show_device_model">false</bool>
<bool name="config_show_wifi_ip_address">false</bool>
<bool name="config_show_wifi_mac_address">false</bool>
+ <bool name="config_disable_uninstall_update">true</bool>
</resources>
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java
index 9371019..3ed9717 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java
@@ -17,6 +17,9 @@
import static com.android.settings.accounts.AccountDashboardFragmentTest
.ShadowAuthenticationHelper.LABELS;
+import static com.android.settings.accounts.AccountDashboardFragmentTest
+ .ShadowAuthenticationHelper.TYPES;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -75,7 +78,6 @@
ShadowAuthenticationHelper.class
})
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
- ShadowAuthenticationHelper.setHasAccount(true);
final SummaryLoader loader = mock(SummaryLoader.class);
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
@@ -91,7 +93,7 @@
ShadowAuthenticationHelper.class
})
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
- ShadowAuthenticationHelper.setHasAccount(false);
+ ShadowAuthenticationHelper.setEnabledAccount(null);
final SummaryLoader loader = mock(SummaryLoader.class);
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
@@ -104,6 +106,24 @@
}
@Test
+ @Config(shadows = {
+ ShadowAuthenticationHelper.class
+ })
+ public void updateSummary_noAccountTypeLabel_shouldNotDisplayNullEntry() {
+ final SummaryLoader loader = mock(SummaryLoader.class);
+ final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
+ final String[] enabledAccounts = {TYPES[0], "unlabled_account_type", TYPES[1]};
+ ShadowAuthenticationHelper.setEnabledAccount(enabledAccounts);
+
+ final SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
+ .createSummaryProvider(activity, loader);
+ provider.setListening(true);
+
+ // should only show the 2 accounts with labels
+ verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1]);
+ }
+
+ @Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
AccountDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
@@ -118,26 +138,25 @@
public static class ShadowAuthenticationHelper {
static final String[] TYPES = new String[] {"type1", "type2", "type3", "type4"};
- static final String[] LABELS = new String[] {"LABEL1", "LABEL2",
- "LABEL3", "LABEL4"};
- private static boolean sHasAccount = true;
+ static final String[] LABELS = new String[] {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
+ private static String[] sEnabledAccount = TYPES;
public void __constructor__(Context context, UserHandle userHandle,
AuthenticatorHelper.OnAccountsUpdateListener listener) {
}
- public static void setHasAccount(boolean hasAccount) {
- sHasAccount = hasAccount;
+ public static void setEnabledAccount(String[] enabledAccount) {
+ sEnabledAccount = enabledAccount;
}
@Resetter
public static void reset() {
- sHasAccount = true;
+ sEnabledAccount = TYPES;
}
@Implementation
public String[] getEnabledAccountTypes() {
- return sHasAccount ? TYPES : null;
+ return sEnabledAccount;
}
@Implementation
@@ -151,7 +170,7 @@
} else if (TextUtils.equals(accountType, TYPES[3])) {
return LABELS[3];
}
- return "no_label";
+ return null;
}
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
index b7e414c..d721e17 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
@@ -16,6 +16,10 @@
package com.android.settings.applications.appinfo;
+import static com.android.settings.applications.appinfo.AppInfoDashboardFragment
+ .UNINSTALL_ALL_USERS_MENU;
+import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.UNINSTALL_UPDATES;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -25,6 +29,7 @@
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;
@@ -36,6 +41,8 @@
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.UserManager;
+import android.view.Menu;
+import android.view.MenuItem;
import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
@@ -129,6 +136,42 @@
}
@Test
+ public void onPrepareOptionsMenu_setUpdateMenuVisible_byDefaultForSystemApps_shouldBeTrue() {
+ Menu menu = onPrepareOptionsMenuTestsSetup();
+ mFragment.onPrepareOptionsMenu(menu);
+
+ verify(menu.findItem(UNINSTALL_UPDATES), times(1)).setVisible(true);
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void onPrepareOptionsMenu_setUpdateMenuVisible_ifDisabledByDevice_shouldBeFalse() {
+ Menu menu = onPrepareOptionsMenuTestsSetup();
+ mFragment.onPrepareOptionsMenu(menu);
+
+ verify(menu.findItem(UNINSTALL_UPDATES), times(1)).setVisible(false);
+ }
+
+ private Menu onPrepareOptionsMenuTestsSetup() {
+ // Menu mocking
+ Menu menu = mock(Menu.class);
+ final MenuItem uninstallUpdatesMenuItem = mock(MenuItem.class);
+ final MenuItem uninstallForAllMenuItem = mock(MenuItem.class);
+ when(menu.findItem(UNINSTALL_UPDATES)).thenReturn(uninstallUpdatesMenuItem);
+ when(menu.findItem(UNINSTALL_ALL_USERS_MENU)).thenReturn(uninstallForAllMenuItem);
+
+ // Setup work to prevent NPE
+ final ApplicationInfo info = new ApplicationInfo();
+ info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
+ info.enabled = true;
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ mFragment.setAppEntry(appEntry);
+
+ return menu;
+ }
+
+ @Test
public void launchFragment_hasNoPackageInfo_shouldFinish() {
ReflectionHelpers.setField(mFragment, "mPackageInfo", null);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java
index 1deba78..61987bf 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingPreferenceControllerTest.java
@@ -101,6 +101,6 @@
mController.handlePreferenceTreeClick(mPreference);
verify(mSettingsActivity).startPreferencePanelAsUser(eq(mFragment), anyString(), any(),
- anyInt(), any(), any());
+ anyInt(), any());
}
}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java
index 3eacd7a..5aa3933 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment2Test.java
@@ -72,11 +72,6 @@
}
@Test
- public void testCategory_isConnectedDevice() {
- assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
- }
-
- @Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext,
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesControllerTest.java
index 557d836..c733078 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsProfilesControllerTest.java
@@ -36,6 +36,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.google.android.collect.Lists;
@@ -228,6 +229,13 @@
assertThat(!switches.get(0).isChecked());
}
+ @Test
+ @Config(shadows = ShadowUtils.class)
+ public void testIsAvailable_isMonkey_shouldReturnFalse() {
+ ShadowUtils.setIsUserAMonkey(true);
+ assertThat(mDetailsProfilesController.isAvailable()).isFalse();
+ }
+
private List<SwitchPreference> getProfileSwitches() {
ArrayList<SwitchPreference> result = new ArrayList<>();
for (int i = 0; i < mPreference.getPreferenceCount(); i++) {
diff --git a/tests/robotests/src/com/android/settings/core/SubSettingLauncherTest.java b/tests/robotests/src/com/android/settings/core/SubSettingLauncherTest.java
new file mode 100644
index 0000000..91d8f7b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/core/SubSettingLauncherTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.core;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.content.Intent;
+
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SubSettingLauncherTest {
+
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void cannotReuseLauncher() {
+ final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext))
+ .setDestination(SubSettingLauncherTest.class.getName())
+ .setSourceMetricsCategory(123);
+ doNothing().when(launcher).launch(any(Intent.class));
+ launcher.launch();
+ launcher.launch();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void launch_noSourceMetricsCategory_shouldCrash() {
+ final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext))
+ .setDestination(SubSettingLauncherTest.class.getName());
+ launcher.launch();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void launch_noDestination_shouldCrash() {
+ final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext))
+ .setSourceMetricsCategory(123);
+ launcher.launch();
+ }
+
+ @Test
+ public void launch_shouldIncludeAllParams() {
+ final ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
+ final SubSettingLauncher launcher = spy(new SubSettingLauncher(mContext));
+ launcher.setTitle("123")
+ .setDestination(SubSettingLauncherTest.class.getName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ .setSourceMetricsCategory(123)
+ .launch();
+ doNothing().when(launcher).launch(any(Intent.class));
+ verify(launcher).launch(intentArgumentCaptor.capture());
+ final Intent intent = intentArgumentCaptor.getValue();
+
+ assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE))
+ .isEqualTo("123");
+ assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
+ .isEqualTo(SubSettingLauncherTest.class.getName());
+ assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_NEW_TASK);
+ assertThat(intent.getIntExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY, -1))
+ .isEqualTo(123);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
index ea1d29b..41032bb 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
@@ -16,6 +16,9 @@
package com.android.settings.datausage;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.doReturn;
+
import android.content.Context;
import android.content.Intent;
import android.net.NetworkTemplate;
@@ -68,8 +71,10 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn("%1$s %2%s").when(mContext)
+ .getString(com.android.internal.R.string.fileSizeSuffix);
mController = new DataUsageSummaryPreferenceController(
mContext,
mDataUsageController,
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index af3a3a5..a188ce11 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -210,7 +210,7 @@
};
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(
nullable(Fragment.class), nullable(String.class), captor.capture(), anyInt(),
- nullable(CharSequence.class), nullable(UserHandle.class));
+ nullable(UserHandle.class));
mForegroundPreference = new Preference(mContext);
mBackgroundPreference = new Preference(mContext);
@@ -345,7 +345,7 @@
verify(mTestActivity).startPreferencePanelAsUser(
nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
- nullable(CharSequence.class), eq(new UserHandle(10)));
+ eq(new UserHandle(10)));
}
@Test
@@ -361,7 +361,7 @@
verify(mTestActivity).startPreferencePanelAsUser(
nullable(Fragment.class), nullable(String.class), nullable(Bundle.class), anyInt(),
- nullable(CharSequence.class), eq(new UserHandle(currentUser)));
+ eq(new UserHandle(currentUser)));
}
@Test
@@ -372,7 +372,7 @@
return null;
};
doAnswer(callable).when(mTestActivity).startPreferencePanelAsUser(nullable(Fragment.class),
- nullable(String.class), captor.capture(), anyInt(), nullable(CharSequence.class),
+ nullable(String.class), captor.capture(), anyInt(),
nullable(UserHandle.class));
AdvancedPowerUsageDetail.startBatteryDetailPage(mTestActivity, null, PACKAGE_NAME[0]);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
index 8aa0659..37b279e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
@@ -17,8 +17,6 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
-
-
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -26,7 +24,6 @@
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -40,9 +37,9 @@
import android.util.IconDrawableFactory;
import com.android.settings.SettingsActivity;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.fuelgauge.anomaly.Anomaly;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
@@ -188,8 +185,7 @@
}
};
doAnswer(bundleCallable).when(mSettingsActivity).startPreferencePanelAsUser(any(),
- anyString(),
- bundleCaptor.capture(), anyInt(), any(), any());
+ anyString(), bundleCaptor.capture(), anyInt(), any());
PowerUsageAnomalyDetails.startBatteryAbnormalPage(mSettingsActivity, mFragment,
mAnomalyList);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/RestrictAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/RestrictAppPreferenceControllerTest.java
index 5e43d1d..fbcedb7 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/RestrictAppPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/RestrictAppPreferenceControllerTest.java
@@ -17,7 +17,6 @@
package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -112,7 +111,7 @@
verify(mSettingsActivity).startPreferencePanelAsUser(eq(mFragment),
eq(RestrictedAppDetails.class.getName()), any(), eq(R.string.restricted_app_title),
- any(), any());
+ any());
}
}
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
index 7f495ab..a3c69c5 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
@@ -178,7 +178,7 @@
verify(activity).startPreferencePanelAsUser(any(),
eq(AppInfoDashboardFragment.class.getName()),
- any(Bundle.class), anyInt(), any(), any());
+ any(Bundle.class), anyInt(), any());
}
private static ArgumentMatcher<Preference> titleMatches(String expected) {
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
index 4b18fcf..92303e0 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -185,7 +185,7 @@
receiver.onReceive(RuntimeEnvironment.application, broadcast);
assertThat(mPreference.getSummary().toString()).isEqualTo(
- RuntimeEnvironment.application.getString(R.string.summary_placeholder));
+ "Unavailable because airplane mode is turned on");
}
@Test
diff --git a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
index aa1b55f..dd27591 100644
--- a/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
+++ b/tests/unit/src/com/android/settings/core/UniquePreferenceTest.java
@@ -90,7 +90,16 @@
"imei_info",
"wifi_ip_address",
"wifi_mac_address",
- "safety_info"
+ "safety_info",
+ // Dupe keys from data usage v2.
+ "data_usage_screen",
+ "cellular_data_usage",
+ "data_usage_wifi_screen",
+ "status_header",
+ "billing_preference",
+ "data_usage_cellular_screen",
+ "wifi_data_usage",
+ "data_usage_enable"
);
private Context mContext;