Merge "Remove wrapper for ConnectionManager/IPackageManager" into pi-dev
diff --git a/res/xml/enterprise_privacy_settings.xml b/res/xml/enterprise_privacy_settings.xml
index 4fa50e7..0aa1415 100644
--- a/res/xml/enterprise_privacy_settings.xml
+++ b/res/xml/enterprise_privacy_settings.xml
@@ -83,6 +83,9 @@
<Preference android:key="ca_certs_managed_profile"
android:title="@string/enterprise_privacy_ca_certs_work"
android:selectable="false"/>
+ <Preference android:key="backups_enabled"
+ android:title="@string/enterprise_privacy_backups_enabled"
+ android:selectable="false"/>
</PreferenceCategory>
<PreferenceCategory android:key="device_access_category"
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index a28b1e6..ee99998 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -18,7 +18,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="network_and_internet_screen"
- android:title="@string/network_dashboard_title">
+ android:title="@string/network_dashboard_title"
+ settings:initialExpandedChildrenCount="5">
<com.android.settings.widget.MasterSwitchPreference
android:fragment="com.android.settings.wifi.WifiSettings"
@@ -59,19 +60,10 @@
settings:useAdminDisabledSummary="true" />
<com.android.settingslib.RestrictedPreference
- android:fragment="com.android.settings.vpn2.VpnSettings"
- android:key="vpn_settings"
- android:title="@string/vpn_settings_title"
- android:icon="@drawable/ic_vpn_key"
- android:order="0"
- android:summary="@string/summary_placeholder"
- settings:userRestriction="no_config_vpn"
- settings:useAdminDisabledSummary="true" />
-
- <com.android.settingslib.RestrictedPreference
android:key="manage_mobile_plan"
android:title="@string/manage_mobile_plan_title"
android:persistent="false"
+ android:order="0"
settings:userRestriction="no_config_mobile_networks"
settings:useAdminDisabledSummary="true" />
@@ -88,4 +80,22 @@
android:key="proxy_settings"
android:title="@string/proxy_settings_title" />
-</PreferenceScreen>
\ No newline at end of file
+ <com.android.settingslib.RestrictedPreference
+ android:fragment="com.android.settings.vpn2.VpnSettings"
+ android:key="vpn_settings"
+ android:title="@string/vpn_settings_title"
+ android:icon="@drawable/ic_vpn_key"
+ android:order="10"
+ android:summary="@string/summary_placeholder"
+ settings:userRestriction="no_config_vpn"
+ settings:useAdminDisabledSummary="true" />
+
+ <com.android.settings.network.PrivateDnsModeDialogPreference
+ android:key="private_dns_settings"
+ android:title="@string/select_private_dns_configuration_title"
+ android:order="15"
+ android:dialogTitle="@string/select_private_dns_configuration_dialog_title"
+ android:dialogLayout="@layout/private_dns_mode_dialog"
+ android:positiveButtonText="@string/save" />
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/applications/appinfo/AppMemoryPreferenceController.java b/src/com/android/settings/applications/appinfo/AppMemoryPreferenceController.java
index 265754c..daf3992 100644
--- a/src/com/android/settings/applications/appinfo/AppMemoryPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppMemoryPreferenceController.java
@@ -109,7 +109,7 @@
}
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
- ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
+ ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
diff --git a/src/com/android/settings/applications/appinfo/PictureInPictureSettings.java b/src/com/android/settings/applications/appinfo/PictureInPictureSettings.java
index e2caa41..ef2c7a9 100644
--- a/src/com/android/settings/applications/appinfo/PictureInPictureSettings.java
+++ b/src/com/android/settings/applications/appinfo/PictureInPictureSettings.java
@@ -40,7 +40,6 @@
import com.android.settings.applications.AppInfoBase;
import com.android.settings.notification.EmptyTextSettings;
import com.android.settings.widget.AppPreference;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.wrapper.PackageManagerWrapper;
import java.text.Collator;
@@ -88,7 +87,7 @@
private Context mContext;
private PackageManagerWrapper mPackageManager;
- private UserManagerWrapper mUserManager;
+ private UserManager mUserManager;
private IconDrawableFactory mIconDrawableFactory;
/**
@@ -119,7 +118,7 @@
// Do nothing
}
- public PictureInPictureSettings(PackageManagerWrapper pm, UserManagerWrapper um) {
+ public PictureInPictureSettings(PackageManagerWrapper pm, UserManager um) {
mPackageManager = pm;
mUserManager = um;
}
@@ -130,7 +129,7 @@
mContext = getActivity();
mPackageManager = new PackageManagerWrapper(mContext.getPackageManager());
- mUserManager = new UserManagerWrapper(mContext.getSystemService(UserManager.class));
+ mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
}
diff --git a/src/com/android/settings/connecteddevice/usb/UsbBackend.java b/src/com/android/settings/connecteddevice/usb/UsbBackend.java
index 333449f..54811c8 100644
--- a/src/com/android/settings/connecteddevice/usb/UsbBackend.java
+++ b/src/com/android/settings/connecteddevice/usb/UsbBackend.java
@@ -22,11 +22,10 @@
import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus;
import android.net.ConnectivityManager;
+import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
-import com.android.settings.wrapper.UserManagerWrapper;
-
/**
* Provides access to underlying system USB functionality.
*/
@@ -50,17 +49,17 @@
private UsbPortStatus mPortStatus;
public UsbBackend(Context context) {
- this(context, new UserManagerWrapper(UserManager.get(context)));
+ this(context, (UserManager) context.getSystemService(Context.USER_SERVICE));
}
@VisibleForTesting
- public UsbBackend(Context context, UserManagerWrapper userManagerWrapper) {
+ public UsbBackend(Context context, UserManager userManager) {
mUsbManager = context.getSystemService(UsbManager.class);
- mFileTransferRestricted = userManagerWrapper.isUsbFileTransferRestricted();
- mFileTransferRestrictedBySystem = userManagerWrapper.isUsbFileTransferRestrictedBySystem();
- mTetheringRestricted = userManagerWrapper.isUsbTetheringRestricted();
- mTetheringRestrictedBySystem = userManagerWrapper.isUsbTetheringRestrictedBySystem();
+ mFileTransferRestricted = isUsbFileTransferRestricted(userManager);
+ mFileTransferRestrictedBySystem = isUsbFileTransferRestrictedBySystem(userManager);
+ mTetheringRestricted = isUsbTetheringRestricted(userManager);
+ mTetheringRestrictedBySystem = isUsbTetheringRestrictedBySystem(userManager);
mMidiSupported = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
ConnectivityManager cm =
@@ -172,6 +171,24 @@
return Integer.parseInt(role);
}
+ private static boolean isUsbFileTransferRestricted(UserManager userManager) {
+ return userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);
+ }
+
+ private static boolean isUsbTetheringRestricted(UserManager userManager) {
+ return userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
+ }
+
+ private static boolean isUsbFileTransferRestrictedBySystem(UserManager userManager) {
+ return userManager.hasBaseUserRestriction(
+ UserManager.DISALLOW_USB_FILE_TRANSFER, UserHandle.of(UserHandle.myUserId()));
+ }
+
+ private static boolean isUsbTetheringRestrictedBySystem(UserManager userManager) {
+ return userManager.hasBaseUserRestriction(
+ UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(UserHandle.myUserId()));
+ }
+
private boolean areFunctionDisallowed(long functions) {
return (mFileTransferRestricted && ((functions & UsbManager.FUNCTION_MTP) != 0
|| (functions & UsbManager.FUNCTION_PTP) != 0))
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index fd17012..44305dd 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -22,7 +22,6 @@
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.slices.SliceData;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -30,6 +29,10 @@
import java.lang.reflect.InvocationTargetException;
import java.util.List;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+
/**
* Abstract class to consolidate utility between preference controllers and act as an interface
* for Slices. The abstract classes that inherit from this class will act as the direct interfaces
@@ -39,6 +42,12 @@
private static final String TAG = "SettingsPrefController";
+ /**
+ * Denotes the availability of the Setting.
+ * <p>
+ * Used both explicitly and by the convenience methods {@link #isAvailable()} and
+ * {@link #isSupported()}.
+ */
@Retention(RetentionPolicy.SOURCE)
@IntDef({AVAILABLE, DISABLED_UNSUPPORTED, DISABLED_FOR_USER, DISABLED_DEPENDENT_SETTING,
UNAVAILABLE_UNKNOWN})
@@ -52,21 +61,42 @@
/**
* The setting is not supported by the device.
+ * <p>
+ * There is no guarantee that the setting page exists, and any links to the Setting should take
+ * you to the home page of Settings.
*/
public static final int DISABLED_UNSUPPORTED = 1;
/**
* The setting cannot be changed by the current user.
+ * <p>
+ * Links to the Setting should take you to the page of the Setting, even if it cannot be
+ * changed.
*/
public static final int DISABLED_FOR_USER = 2;
/**
* The setting has a dependency in the Settings App which is currently blocking access.
+ * <p>
+ * It must be possible for the Setting to be enabled by changing the configuration of the device
+ * settings. That is, a setting that cannot be changed because of the state of another setting.
+ * This should not be used for a setting that would be hidden from the UI entirely.
+ * <p>
+ * Correct use: Intensity of night display should be {@link #DISABLED_DEPENDENT_SETTING} when
+ * night display is off.
+ * Incorrect use: Mobile Data is {@link #DISABLED_DEPENDENT_SETTING} when there is no
+ * data-enabled sim.
+ * <p>
+ * Links to the Setting should take you to the page of the Setting, even if it cannot be
+ * changed.
*/
public static final int DISABLED_DEPENDENT_SETTING = 3;
/**
* A catch-all case for internal errors and inexplicable unavailability.
+ * <p>
+ * There is no guarantee that the setting page exists, and any links to the Setting should take
+ * you to the home page of Settings.
*/
public static final int UNAVAILABLE_UNKNOWN = 4;
@@ -134,9 +164,25 @@
return mPreferenceKey;
}
+ /**
+ * @return {@code true} when the controller can be changed on the device.
+ *
+ * <p>
+ * Will return true for {@link #AVAILABLE} and {@link #DISABLED_DEPENDENT_SETTING}.
+ * <p>
+ * When the availability status returned by {@link #getAvailabilityStatus()} is
+ * {@link #DISABLED_DEPENDENT_SETTING}, then the setting will be disabled by default in the
+ * DashboardFragment, and it is up to the {@link BasePreferenceController} to enable the
+ * preference at the right time.
+ *
+ * TODO (mfritze) Build a dependency mechanism to allow a controller to easily define the
+ * dependent setting.
+ */
@Override
public final boolean isAvailable() {
- return getAvailabilityStatus() == AVAILABLE;
+ final int availabilityStatus = getAvailabilityStatus();
+ return (availabilityStatus == AVAILABLE) ||
+ (availabilityStatus == DISABLED_DEPENDENT_SETTING);
}
/**
@@ -151,6 +197,21 @@
}
/**
+ * Displays preference in this controller.
+ */
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ if (getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
+ // Disable preference if it depends on another setting.
+ final Preference preference = screen.findPreference(getPreferenceKey());
+ if (preference != null) {
+ preference.setEnabled(false);
+ }
+ }
+ }
+
+ /**
* @return the UI type supported by the controller.
*/
@SliceData.SliceType
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index ead941f..8e56b12 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -47,7 +47,6 @@
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.widget.EntityHeaderController;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
@@ -185,8 +184,7 @@
mVolume, new StorageManagerVolumeProvider(sm));
controllers.add(mPreferenceController);
- UserManagerWrapper userManager =
- new UserManagerWrapper(context.getSystemService(UserManager.class));
+ final UserManager userManager = context.getSystemService(UserManager.class);
mSecondaryUsers = SecondaryUserController.getSecondaryUserControllers(context, userManager);
controllers.addAll(mSecondaryUsers);
@@ -235,8 +233,7 @@
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
final StorageManager sm = context.getSystemService(StorageManager.class);
- final UserManagerWrapper userManager =
- new UserManagerWrapper(context.getSystemService(UserManager.class));
+ final UserManager userManager = context.getSystemService(UserManager.class);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new StorageSummaryDonutPreferenceController(context));
controllers.add(new StorageItemPreferenceController(context, null /* host */,
@@ -251,9 +248,8 @@
@Override
public Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> onCreateLoader(int id,
Bundle args) {
- Context context = getContext();
- return new StorageAsyncLoader(context,
- new UserManagerWrapper(context.getSystemService(UserManager.class)),
+ final Context context = getContext();
+ return new StorageAsyncLoader(context, context.getSystemService(UserManager.class),
mVolume.fsUuid,
new StorageStatsSource(context),
new PackageManagerWrapper(context.getPackageManager()));
diff --git a/src/com/android/settings/deviceinfo/StorageProfileFragment.java b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
index 3f75f5c..a312a81 100644
--- a/src/com/android/settings/deviceinfo/StorageProfileFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
@@ -34,7 +34,6 @@
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader.AppsStorageResult;
import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
@@ -114,9 +113,9 @@
@Override
public Loader<SparseArray<AppsStorageResult>> onCreateLoader(int id, Bundle args) {
- Context context = getContext();
+ final Context context = getContext();
return new StorageAsyncLoader(context,
- new UserManagerWrapper(context.getSystemService(UserManager.class)),
+ context.getSystemService(UserManager.class),
mVolume.fsUuid,
new StorageStatsSource(context),
new PackageManagerWrapper(context.getPackageManager()));
diff --git a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
index 4aeb782..d63436f 100644
--- a/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
+++ b/src/com/android/settings/deviceinfo/storage/SecondaryUserController.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable;
+import android.os.UserManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
@@ -29,7 +30,6 @@
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.deviceinfo.StorageItemPreference;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
@@ -61,7 +61,7 @@
* @param userManager UserManagerWrapper for figuring out which controllers to add.
*/
public static List<AbstractPreferenceController> getSecondaryUserControllers(
- Context context, UserManagerWrapper userManager) {
+ Context context, UserManager userManager) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
UserInfo primaryUser = userManager.getPrimaryUser();
boolean addedUser = false;
@@ -74,8 +74,7 @@
if (info == null || Utils.isProfileOf(primaryUser, info)) {
controllers.add(
- new UserProfileController(
- context, info, userManager, USER_PROFILE_INSERTION_LOCATION));
+ new UserProfileController(context, info, USER_PROFILE_INSERTION_LOCATION));
continue;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
index 0b9b697..affcbc9 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -26,11 +26,11 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
import android.os.UserHandle;
+import android.os.UserManager;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.utils.AsyncLoader;
import com.android.settingslib.wrapper.PackageManagerWrapper;
@@ -46,7 +46,7 @@
*/
public class StorageAsyncLoader
extends AsyncLoader<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
- private UserManagerWrapper mUserManager;
+ private UserManager mUserManager;
private static final String TAG = "StorageAsyncLoader";
private String mUuid;
@@ -54,7 +54,7 @@
private PackageManagerWrapper mPackageManager;
private ArraySet<String> mSeenPackages;
- public StorageAsyncLoader(Context context, UserManagerWrapper userManager,
+ public StorageAsyncLoader(Context context, UserManager userManager,
String uuid, StorageStatsSource source, PackageManagerWrapper pm) {
super(context);
mUserManager = userManager;
diff --git a/src/com/android/settings/deviceinfo/storage/UserProfileController.java b/src/com/android/settings/deviceinfo/storage/UserProfileController.java
index 081a0be..510b0c0 100644
--- a/src/com/android/settings/deviceinfo/storage/UserProfileController.java
+++ b/src/com/android/settings/deviceinfo/storage/UserProfileController.java
@@ -32,7 +32,6 @@
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.deviceinfo.StorageProfileFragment;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.core.AbstractPreferenceController;
/**
@@ -44,16 +43,13 @@
UserIconLoader.UserIconHandler {
private static final String PREFERENCE_KEY_BASE = "pref_profile_";
private StorageItemPreference mStoragePreference;
- private UserManagerWrapper mUserManager;
private UserInfo mUser;
private long mTotalSizeBytes;
private final int mPreferenceOrder;
- public UserProfileController(
- Context context, UserInfo info, UserManagerWrapper userManager, int preferenceOrder) {
+ public UserProfileController(Context context, UserInfo info, int preferenceOrder) {
super(context);
mUser = Preconditions.checkNotNull(info);
- mUserManager = userManager;
mPreferenceOrder = preferenceOrder;
}
diff --git a/src/com/android/settings/enterprise/BackupsEnabledPreferenceController.java b/src/com/android/settings/enterprise/BackupsEnabledPreferenceController.java
new file mode 100644
index 0000000..b24f8dc
--- /dev/null
+++ b/src/com/android/settings/enterprise/BackupsEnabledPreferenceController.java
@@ -0,0 +1,37 @@
+/*
+ * 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.enterprise;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+public class BackupsEnabledPreferenceController extends BasePreferenceController {
+
+ private static final String KEY_BACKUPS_ENABLED = "backups_enabled";
+ private final EnterprisePrivacyFeatureProvider mFeatureProvider;
+
+ public BackupsEnabledPreferenceController(Context context) {
+ super(context, KEY_BACKUPS_ENABLED);
+ mFeatureProvider = FeatureFactory.getFactory(context)
+ .getEnterprisePrivacyFeatureProvider(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mFeatureProvider.areBackupsMandatory() ? AVAILABLE : DISABLED_FOR_USER;
+ }
+}
+
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
index 048782e..51d125d 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProvider.java
@@ -124,4 +124,9 @@
* profile (if any).
*/
int getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile();
+
+ /*
+ * Returns whether backups are mandatory.
+ */
+ boolean areBackupsMandatory();
}
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index 2146598..eead69f 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -235,6 +235,11 @@
return activeAdmins;
}
+ @Override
+ public boolean areBackupsMandatory() {
+ return null != mDpm.getMandatoryBackupTransport();
+ }
+
protected static class EnterprisePrivacySpan extends ClickableSpan {
private final Context mContext;
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
index b426d28..92ae38d 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacySettings.java
@@ -82,6 +82,7 @@
exposureChangesCategoryControllers.add(new CaCertsCurrentUserPreferenceController(context));
exposureChangesCategoryControllers.add(new CaCertsManagedProfilePreferenceController(
context));
+ exposureChangesCategoryControllers.add(new BackupsEnabledPreferenceController(context));
controllers.addAll(exposureChangesCategoryControllers);
controllers.add(new PreferenceCategoryController(context, "exposure_changes_category")
.setChildren(exposureChangesCategoryControllers));
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
index fd150e4..1b6e2f0 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.os.BatteryStats;
import android.support.annotation.VisibleForTesting;
+import android.text.format.DateUtils;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
@@ -72,18 +73,20 @@
final long foregroundTimeMs = mBatteryUtils.getProcessTimeMs(
BatteryUtils.StatusType.FOREGROUND, batterySipper.uidObj,
BatteryStats.STATS_SINCE_CHARGED);
- mHighUsageAppList.add(new AppInfo.Builder()
- .setUid(batterySipper.getUid())
- .setPackageName(
- mBatteryUtils.getPackageName(batterySipper.getUid()))
- .setScreenOnTimeMs(foregroundTimeMs)
- .build());
+ if (foregroundTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
+ mHighUsageAppList.add(new AppInfo.Builder()
+ .setUid(batterySipper.getUid())
+ .setPackageName(
+ mBatteryUtils.getPackageName(batterySipper.getUid()))
+ .setScreenOnTimeMs(foregroundTimeMs)
+ .build());
+ }
}
}
+ Collections.sort(mHighUsageAppList, Collections.reverseOrder());
mHighUsageAppList = mHighUsageAppList.subList(0,
Math.min(mPolicy.highUsageAppCount, mHighUsageAppList.size()));
- Collections.sort(mHighUsageAppList, Collections.reverseOrder());
}
}
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 7d8ea18..955c503 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -49,10 +49,8 @@
private static final String TAG = "NetworkDashboardFrag";
private static final int MENU_NETWORK_RESET = Menu.FIRST;
- private static final int MENU_PRIVATE_DNS = Menu.FIRST + 1;
private NetworkResetActionMenuController mNetworkResetController;
- private PrivateDnsMenuController mPrivateDnsMenuController;
@Override
public int getMetricsCategory() {
@@ -73,8 +71,6 @@
public void onAttach(Context context) {
super.onAttach(context);
mNetworkResetController = new NetworkResetActionMenuController(context, MENU_NETWORK_RESET);
- mPrivateDnsMenuController = new PrivateDnsMenuController(getFragmentManager(),
- MENU_PRIVATE_DNS);
}
@Override
@@ -86,7 +82,6 @@
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
mNetworkResetController.buildMenuItem(menu);
- mPrivateDnsMenuController.buildMenuItem(menu);
}
@Override
@@ -109,6 +104,8 @@
new MobileNetworkPreferenceController(context);
final VpnPreferenceController vpnPreferenceController =
new VpnPreferenceController(context);
+ final PrivateDnsPreferenceController privateDnsPreferenceController =
+ new PrivateDnsPreferenceController(context);
if (lifecycle != null) {
lifecycle.addObserver(airplaneModePreferenceController);
@@ -116,6 +113,7 @@
lifecycle.addObserver(wifiPreferenceController);
lifecycle.addObserver(mobileNetworkPreferenceController);
lifecycle.addObserver(vpnPreferenceController);
+ lifecycle.addObserver(privateDnsPreferenceController);
}
final List<AbstractPreferenceController> controllers = new ArrayList<>();
@@ -126,6 +124,7 @@
controllers.add(new ProxyPreferenceController(context));
controllers.add(mobilePlanPreferenceController);
controllers.add(wifiPreferenceController);
+ controllers.add(privateDnsPreferenceController);
return controllers;
}
diff --git a/src/com/android/settings/network/PrivateDnsMenuController.java b/src/com/android/settings/network/PrivateDnsMenuController.java
deleted file mode 100644
index a811775..0000000
--- a/src/com/android/settings/network/PrivateDnsMenuController.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import android.app.FragmentManager;
-import android.view.Menu;
-import android.view.MenuItem;
-
-import com.android.settings.R;
-
-public class PrivateDnsMenuController {
- private final FragmentManager mFragmentManager;
- private final int mMenuId;
-
- public PrivateDnsMenuController(FragmentManager fragmentManager, int menuId) {
- mFragmentManager = fragmentManager;
- mMenuId = menuId;
- }
-
- public void buildMenuItem(Menu menu) {
- if (menu != null) {
- MenuItem item = menu.add(0 /* groupId */, mMenuId, 0 /* order */,
- R.string.select_private_dns_configuration_title);
- item.setOnMenuItemClickListener(target -> {
- PrivateDnsModeDialogFragment.show(mFragmentManager);
- return true;
- });
- }
- }
-}
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogFragment.java b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
similarity index 71%
rename from src/com/android/settings/network/PrivateDnsModeDialogFragment.java
rename to src/com/android/settings/network/PrivateDnsModeDialogPreference.java
index 00950c3..3b09cc2 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogFragment.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogPreference.java
@@ -20,19 +20,18 @@
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.FragmentManager;
+import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
-import android.view.LayoutInflater;
+import android.util.AttributeSet;
+import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@@ -41,8 +40,9 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settings.utils.AnnotationSpan;
+import com.android.settingslib.CustomDialogPreference;
import com.android.settingslib.HelpUtils;
import java.util.HashMap;
@@ -51,7 +51,7 @@
/**
* Dialog to set the private dns
*/
-public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment implements
+public class PrivateDnsModeDialogPreference extends CustomDialogPreference implements
DialogInterface.OnClickListener, RadioGroup.OnCheckedChangeListener, TextWatcher {
public static final String ANNOTATION_URL = "url";
@@ -77,41 +77,44 @@
@VisibleForTesting
RadioGroup mRadioGroup;
@VisibleForTesting
- Button mSaveButton;
- @VisibleForTesting
String mMode;
- public static void show(FragmentManager fragmentManager) {
- if (fragmentManager.findFragmentByTag(TAG) == null) {
- final PrivateDnsModeDialogFragment fragment = new PrivateDnsModeDialogFragment();
- fragment.show(fragmentManager, TAG);
- }
+ public PrivateDnsModeDialogPreference(Context context) {
+ super(context);
}
+ public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public PrivateDnsModeDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ private final AnnotationSpan.LinkInfo mUrlLinkInfo = new AnnotationSpan.LinkInfo(
+ ANNOTATION_URL, (widget) -> {
+ final Context context = widget.getContext();
+ final Intent intent = HelpUtils.getHelpIntent(context,
+ context.getString(R.string.help_uri_private_dns),
+ context.getClass().getName());
+ if (intent != null) {
+ try {
+ widget.startActivityForResult(intent, 0);
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "Activity was not found for intent, " + intent.toString());
+ }
+ }
+ });
+
@Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
+ protected void onBindDialogView(View view) {
final Context context = getContext();
-
- final AlertDialog dialog = new AlertDialog.Builder(context)
- .setTitle(R.string.select_private_dns_configuration_title)
- .setView(buildPrivateDnsView(context))
- .setPositiveButton(R.string.save, this)
- .setNegativeButton(R.string.dlg_cancel, null)
- .create();
-
- dialog.setOnShowListener(dialogInterface -> {
- mSaveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
- updateDialogInfo();
- });
- return dialog;
- }
-
- private View buildPrivateDnsView(final Context context) {
final ContentResolver contentResolver = context.getContentResolver();
- mMode = Settings.Global.getString(contentResolver, MODE_KEY);
- final View view = LayoutInflater.from(context).inflate(R.layout.private_dns_mode_dialog,
- null);
-
mEditText = view.findViewById(R.id.private_dns_mode_provider_hostname);
mEditText.addTextChangedListener(this);
mEditText.setText(Settings.Global.getString(contentResolver, HOSTNAME_KEY));
@@ -131,26 +134,20 @@
helpTextView.setText(AnnotationSpan.linkify(
context.getText(R.string.private_dns_help_message), linkInfo));
}
-
- return view;
}
@Override
public void onClick(DialogInterface dialog, int which) {
+ final Context context = getContext();
if (mMode.equals(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME)) {
// Only clickable if hostname is valid, so we could save it safely
- Settings.Global.putString(getContext().getContentResolver(), HOSTNAME_KEY,
+ Settings.Global.putString(context.getContentResolver(), HOSTNAME_KEY,
mEditText.getText().toString());
}
- mMetricsFeatureProvider.action(getContext(),
+ FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
MetricsProto.MetricsEvent.ACTION_PRIVATE_DNS_MODE, mMode);
- Settings.Global.putString(getContext().getContentResolver(), MODE_KEY, mMode);
- }
-
- @Override
- public int getMetricsCategory() {
- return MetricsProto.MetricsEvent.DIALOG_PRIVATE_DNS;
+ Settings.Global.putString(context.getContentResolver(), MODE_KEY, mMode);
}
@Override
@@ -179,9 +176,7 @@
@Override
public void afterTextChanged(Editable s) {
- if (mSaveButton != null) {
- mSaveButton.setEnabled(isWeaklyValidatedHostname(mEditText.getText().toString()));
- }
+ updateDialogInfo();
}
private boolean isWeaklyValidatedHostname(String hostname) {
@@ -193,17 +188,24 @@
return hostname.matches(WEAK_HOSTNAME_REGEX);
}
+ private Button getSaveButton() {
+ final AlertDialog dialog = (AlertDialog) getDialog();
+ if (dialog == null) {
+ return null;
+ }
+ return dialog.getButton(DialogInterface.BUTTON_POSITIVE);
+ }
+
private void updateDialogInfo() {
final boolean modeProvider = PRIVATE_DNS_MODE_PROVIDER_HOSTNAME.equals(mMode);
if (mEditText != null) {
mEditText.setEnabled(modeProvider);
}
- if (mSaveButton != null) {
- mSaveButton.setEnabled(
- modeProvider
- ? isWeaklyValidatedHostname(mEditText.getText().toString())
- : true);
+ final Button saveButton = getSaveButton();
+ if (saveButton != null) {
+ saveButton.setEnabled(modeProvider
+ ? isWeaklyValidatedHostname(mEditText.getText().toString())
+ : true);
}
}
-
}
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
new file mode 100644
index 0000000..e317530
--- /dev/null
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+
+public class PrivateDnsPreferenceController extends BasePreferenceController
+ implements PreferenceControllerMixin, LifecycleObserver {
+ private static final String KEY_PRIVATE_DNS_SETTINGS = "private_dns_settings";
+
+ public PrivateDnsPreferenceController(Context context) {
+ super(context, KEY_PRIVATE_DNS_SETTINGS);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_PRIVATE_DNS_SETTINGS;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+}
diff --git a/src/com/android/settings/network/VpnPreferenceController.java b/src/com/android/settings/network/VpnPreferenceController.java
index 95513e0..c4ecf4f 100644
--- a/src/com/android/settings/network/VpnPreferenceController.java
+++ b/src/com/android/settings/network/VpnPreferenceController.java
@@ -180,13 +180,11 @@
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
- Log.d(TAG, "onAvailable " + network.netId);
updateSummary();
}
@Override
public void onLost(Network network) {
- Log.d(TAG, "onLost " + network.netId);
updateSummary();
}
};
diff --git a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
index 0874cea..22835f3 100644
--- a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
+++ b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
@@ -27,7 +27,6 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.wrapper.WallpaperManagerWrapper;
public class WallpaperSuggestionActivity extends Activity {
@@ -61,9 +60,16 @@
@VisibleForTesting
public static boolean isSuggestionComplete(Context context) {
- final WallpaperManagerWrapper manager = new WallpaperManagerWrapper(context);
- return manager.isWallpaperServiceEnabled() ? manager.getWallpaperId(
- WallpaperManager.FLAG_SYSTEM) > 0 : false;
+ if (!isWallpaperServiceEnabled(context)) {
+ return true;
+ }
+ final WallpaperManager manager = (WallpaperManager) context.getSystemService(
+ WALLPAPER_SERVICE);
+ return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
}
+ private static boolean isWallpaperServiceEnabled(Context context) {
+ return context.getResources().getBoolean(
+ com.android.internal.R.bool.config_enableWallpaperService);
+ }
}
diff --git a/src/com/android/settings/widget/PreferenceCategoryController.java b/src/com/android/settings/widget/PreferenceCategoryController.java
index cdd814c..c6477f3 100644
--- a/src/com/android/settings/widget/PreferenceCategoryController.java
+++ b/src/com/android/settings/widget/PreferenceCategoryController.java
@@ -43,7 +43,7 @@
@Override
public int getAvailabilityStatus() {
if (mChildren == null || mChildren.isEmpty()) {
- return DISABLED_DEPENDENT_SETTING;
+ return DISABLED_UNSUPPORTED;
}
// Category is available if any child is available
for (AbstractPreferenceController controller : mChildren) {
@@ -51,7 +51,7 @@
return AVAILABLE;
}
}
- return DISABLED_DEPENDENT_SETTING;
+ return DISABLED_UNSUPPORTED;
}
@Override
diff --git a/src/com/android/settings/wrapper/UserManagerWrapper.java b/src/com/android/settings/wrapper/UserManagerWrapper.java
deleted file mode 100644
index 8c3a01d..0000000
--- a/src/com/android/settings/wrapper/UserManagerWrapper.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.wrapper;
-
-import android.content.pm.UserInfo;
-import android.os.UserHandle;
-import android.os.UserManager;
-
-import java.util.List;
-
-/**
- * This class replicates a subset of the android.os.UserManager. The class
- * exists so that we can use a thin wrapper around the UserManager in production code and a mock in
- * tests. We cannot directly mock or shadow the UserManager, because some of the methods we rely on
- * are newer than the API version supported by Robolectric or are hidden.
- */
-public class UserManagerWrapper {
- private UserManager mUserManager;
-
- public UserManagerWrapper(UserManager userManager) {
- mUserManager = userManager;
- }
-
- public UserInfo getPrimaryUser() {
- return mUserManager.getPrimaryUser();
- }
-
- public List<UserInfo> getUsers() {
- return mUserManager.getUsers();
- }
-
- public List<UserInfo> getProfiles(int userHandle) {
- return mUserManager.getProfiles(userHandle);
- }
-
- public boolean isUsbFileTransferRestricted() {
- return mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);
- }
-
- public boolean isUsbTetheringRestricted() {
- return mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
- }
-
- public boolean isUsbFileTransferRestrictedBySystem() {
- return mUserManager.hasBaseUserRestriction(
- UserManager.DISALLOW_USB_FILE_TRANSFER, UserHandle.of(UserHandle.myUserId()));
- }
-
- public boolean isUsbTetheringRestrictedBySystem() {
- return mUserManager.hasBaseUserRestriction(
- UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(UserHandle.myUserId()));
- }
-}
diff --git a/src/com/android/settings/wrapper/WallpaperManagerWrapper.java b/src/com/android/settings/wrapper/WallpaperManagerWrapper.java
deleted file mode 100644
index eabc5bb..0000000
--- a/src/com/android/settings/wrapper/WallpaperManagerWrapper.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.wrapper;
-
-import android.app.WallpaperManager;
-import android.content.Context;
-
-public class WallpaperManagerWrapper {
-
- private final WallpaperManager mWallpaperManager;
- private final boolean mWallpaperServiceEnabled;
-
- public WallpaperManagerWrapper(Context context) {
- mWallpaperServiceEnabled = context.getResources().getBoolean(
- com.android.internal.R.bool.config_enableWallpaperService);
- mWallpaperManager = mWallpaperServiceEnabled ? (WallpaperManager) context.getSystemService(
- Context.WALLPAPER_SERVICE) : null;
- }
-
- public boolean isWallpaperServiceEnabled() {
- return mWallpaperServiceEnabled;
- }
-
- public int getWallpaperId(int which) {
- if (!mWallpaperServiceEnabled) {
- throw new RuntimeException("This device does not have wallpaper service enabled.");
- }
- return mWallpaperManager.getWallpaperId(which);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
index 6a586d19..64ad32b 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
@@ -110,7 +110,7 @@
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
assertThat(mController.getAvailabilityStatus())
- .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
+ .isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/PictureInPictureSettingsTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/PictureInPictureSettingsTest.java
index 3ea2a16..87dedad 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/PictureInPictureSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/PictureInPictureSettingsTest.java
@@ -25,12 +25,13 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.UserInfo;
+import android.os.UserManager;
import android.util.Pair;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.wrapper.PackageManagerWrapper;
+
import com.google.common.collect.ImmutableList;
import org.junit.Before;
@@ -52,7 +53,7 @@
@Mock
private PackageManagerWrapper mPackageManager;
@Mock
- private UserManagerWrapper mUserManager;
+ private UserManager mUserManager;
private ArrayList<PackageInfo> mPrimaryUserPackages;
private ArrayList<PackageInfo> mProfileUserPackages;
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbBackendTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbBackendTest.java
index 0823fe0..567b072 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbBackendTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbBackendTest.java
@@ -18,6 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,9 +29,10 @@
import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus;
import android.net.ConnectivityManager;
+import android.os.UserHandle;
+import android.os.UserManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.wrapper.UserManagerWrapper;
import org.junit.Before;
import org.junit.Test;
@@ -45,7 +48,7 @@
@Mock
private UsbManager mUsbManager;
@Mock
- private UserManagerWrapper mUserManagerWrapper;
+ private UserManager mUserManager;
@Mock
private ConnectivityManager mConnectivityManager;
@Mock
@@ -68,7 +71,7 @@
@Test
public void setDataRole_allRolesSupported_shouldSetDataRole() {
- final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
+ final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -91,7 +94,7 @@
@Test
public void setDataRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
- final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
+ final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -109,7 +112,7 @@
@Test
public void setPowerRole_allRolesSupported_shouldSetPowerRole() {
- final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
+ final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -133,7 +136,7 @@
@Test
public void setPowerRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
- final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
+ final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -151,20 +154,26 @@
@Test
public void areFunctionsSupported_fileTransferDisallowed_shouldReturnFalse() {
- when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(true);
- when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(true);
+ when(mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER))
+ .thenReturn(true);
+ when(mUserManager.hasBaseUserRestriction(
+ eq(UserManager.DISALLOW_USB_FILE_TRANSFER), any(UserHandle.class)))
+ .thenReturn(true);
- final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
+ final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isFalse();
}
@Test
public void areFunctionsSupported_fileTransferAllowed_shouldReturnTrue() {
- when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(false);
- when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(false);
+ when(mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER))
+ .thenReturn(false);
+ when(mUserManager.hasBaseUserRestriction(
+ eq(UserManager.DISALLOW_USB_FILE_TRANSFER), any(UserHandle.class)))
+ .thenReturn(false);
- final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
+ final UsbBackend usbBackend = new UsbBackend(mContext, mUserManager);
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java
index 34fbb01..3074d9e 100644
--- a/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java
@@ -21,27 +21,37 @@
import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
import static com.android.settings.core.BasePreferenceController.UNAVAILABLE_UNKNOWN;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import android.content.Context;
+
import com.android.settings.slices.SliceData;
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 android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+
@RunWith(SettingsRobolectricTestRunner.class)
public class BasePreferenceControllerTest {
- @Mock
- private BasePreferenceController mPreferenceController;
+ private final String KEY = "fake_key";
+
+ private Context mContext;
+ private FakeBasePreferenceController mPreferenceController;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mPreferenceController = new FakeBasePreferenceController(mContext, KEY);
}
@@ -57,70 +67,70 @@
@Test
public void isAvailable_availableStatusAvailable_returnsTrue() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(AVAILABLE);
+ mPreferenceController.setAvailability(AVAILABLE);
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void isAvailable_availableStatusUnsupported_returnsFalse() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_UNSUPPORTED);
+ mPreferenceController.setAvailability(DISABLED_UNSUPPORTED);
assertThat(mPreferenceController.isAvailable()).isFalse();
}
@Test
- public void isAvailable_availableStatusDisabled_returnsFalse() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_FOR_USER);
+ public void isAvailable_availableStatusDisabledForUser_returnsFalse() {
+ mPreferenceController.setAvailability(DISABLED_FOR_USER);
assertThat(mPreferenceController.isAvailable()).isFalse();
}
@Test
public void isAvailable_availableStatusBlockedDependent_returnsFalse() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_DEPENDENT_SETTING);
+ mPreferenceController.setAvailability(DISABLED_DEPENDENT_SETTING);
- assertThat(mPreferenceController.isAvailable()).isFalse();
+ assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void isAvailable_availableStatusUnavailable_returnsFalse() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(UNAVAILABLE_UNKNOWN);
+ mPreferenceController.setAvailability(UNAVAILABLE_UNKNOWN);
assertThat(mPreferenceController.isAvailable()).isFalse();
}
@Test
public void isSupported_availableStatusAvailable_returnsTrue() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(AVAILABLE);
+ mPreferenceController.setAvailability(AVAILABLE);
assertThat(mPreferenceController.isSupported()).isTrue();
}
@Test
public void isSupported_availableStatusUnsupported_returnsFalse() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_UNSUPPORTED);
+ mPreferenceController.setAvailability(DISABLED_UNSUPPORTED);
assertThat(mPreferenceController.isSupported()).isFalse();
}
@Test
- public void isSupported_availableStatusDisabled_returnsTrue() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_FOR_USER);
+ public void isSupported_availableStatusDisabledForUser_returnsTrue() {
+ mPreferenceController.setAvailability(DISABLED_FOR_USER);
assertThat(mPreferenceController.isSupported()).isTrue();
}
@Test
public void isSupported_availableStatusDependentSetting_returnsTrue() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(DISABLED_DEPENDENT_SETTING);
+ mPreferenceController.setAvailability(DISABLED_DEPENDENT_SETTING);
assertThat(mPreferenceController.isSupported()).isTrue();
}
@Test
public void isSupported_availableStatusUnavailable_returnsTrue() {
- when(mPreferenceController.getAvailabilityStatus()).thenReturn(UNAVAILABLE_UNKNOWN);
+ mPreferenceController.setAvailability(UNAVAILABLE_UNKNOWN);
assertThat(mPreferenceController.isSupported()).isTrue();
}
@@ -129,4 +139,48 @@
public void getSliceType_shouldReturnIntent() {
assertThat(mPreferenceController.getSliceType()).isEqualTo(SliceData.SliceType.INTENT);
}
+
+ @Test
+ public void settingAvailable_disabledOnDisplayPreference_preferenceEnabled() {
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ final Preference preference = new Preference(mContext);
+ preference.setEnabled(true);
+ when(screen.findPreference(anyString())).thenReturn(preference);
+
+ mPreferenceController.displayPreference(screen);
+
+ assertThat(preference.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void disabledDependentSetting_disabledOnDisplayPreference_preferenceDisabled() {
+ final PreferenceScreen screen = mock(PreferenceScreen.class);
+ final Preference preference = new Preference(mContext);
+ preference.setEnabled(true);
+ when(screen.findPreference(anyString())).thenReturn(preference);
+ mPreferenceController.setAvailability(DISABLED_DEPENDENT_SETTING);
+
+ mPreferenceController.displayPreference(screen);
+
+ assertThat(preference.isEnabled()).isFalse();
+ }
+
+ private class FakeBasePreferenceController extends BasePreferenceController {
+
+ public int mAvailable;
+
+ public FakeBasePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mAvailable = AVAILABLE;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mAvailable;
+ }
+
+ public void setAvailability(int availability) {
+ mAvailable = availability;
+ }
+ }
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
index 49f0312..bbe92ad 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
@@ -26,13 +26,13 @@
import android.content.Context;
import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable;
+import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.util.SparseArray;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.drawable.UserIconDrawable;
@@ -54,7 +54,7 @@
private static final String TEST_NAME = "Fred";
private static final String TARGET_PREFERENCE_GROUP_KEY = "pref_secondary_users";
@Mock
- private UserManagerWrapper mUserManager;
+ private UserManager mUserManager;
@Mock
private PreferenceScreen mScreen;
@Mock
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
index 84456ec..7ee6216 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
@@ -35,7 +35,6 @@
import com.android.settings.SubSettings;
import com.android.settings.deviceinfo.StorageProfileFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.drawable.UserIconDrawable;
@@ -53,8 +52,6 @@
private static final String TEST_NAME = "Fred";
@Mock
- private UserManagerWrapper mUserManager;
- @Mock
private PreferenceScreen mScreen;
private Context mContext;
@@ -66,7 +63,7 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mPrimaryProfile = new UserInfo();
- mController = new UserProfileController(mContext, mPrimaryProfile, mUserManager, 0);
+ mController = new UserProfileController(mContext, mPrimaryProfile, 0);
when(mScreen.getContext()).thenReturn(mContext);
mPrimaryProfile.name = TEST_NAME;
mPrimaryProfile.id = 10;
@@ -96,7 +93,7 @@
final Intent intent = intentCaptor.getValue();
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
- .isEqualTo(StorageProfileFragment.class.getName());
+ .isEqualTo(StorageProfileFragment.class.getName());
}
@Test
diff --git a/tests/robotests/src/com/android/settings/enterprise/BackupsEnabledPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/BackupsEnabledPreferenceControllerTest.java
new file mode 100644
index 0000000..a836fa2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/enterprise/BackupsEnabledPreferenceControllerTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.enterprise;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class BackupsEnabledPreferenceControllerTest {
+
+ private static final String KEY_BACKUPS_ENABLED = "backups_enabled";
+
+ private Context mContext;
+ private FakeFeatureFactory mFeatureFactory;
+
+ private BackupsEnabledPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ mController = new BackupsEnabledPreferenceController(mContext);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider.areBackupsMandatory())
+ .thenReturn(false);
+ assertThat(mController.isAvailable()).isFalse();
+
+ when(mFeatureFactory.enterprisePrivacyFeatureProvider.areBackupsMandatory())
+ .thenReturn(true);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void testHandlePreferenceTreeClick() {
+ assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
+ .isFalse();
+ }
+
+ @Test
+ public void testGetPreferenceKey() {
+ assertThat(mController.getPreferenceKey()).isEqualTo(KEY_BACKUPS_ENABLED);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index b4fc6d8..40371d7 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -347,6 +347,15 @@
.isEqualTo(3);
}
+ @Test
+ public void testAreBackupsMandatory() {
+ assertThat(mProvider.areBackupsMandatory()).isFalse();
+ ComponentName transportComponent = new ComponentName("test", "test");
+ when(mDevicePolicyManager.getMandatoryBackupTransport())
+ .thenReturn(transportComponent);
+ assertThat(mProvider.areBackupsMandatory()).isTrue();
+ }
+
private void resetAndInitializePackageManagerWrapper() {
reset(mPackageManagerWrapper);
when(mPackageManagerWrapper.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
index 5266fde..7bbe9bc 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacySettingsTest.java
@@ -98,7 +98,7 @@
private void verifyPreferenceControllers(List<AbstractPreferenceController> controllers) {
assertThat(controllers).isNotNull();
- assertThat(controllers.size()).isEqualTo(17);
+ assertThat(controllers.size()).isEqualTo(18);
int position = 0;
assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class);
@@ -126,6 +126,8 @@
assertThat(controllers.get(position++)).isInstanceOf(
CaCertsManagedProfilePreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf(
+ BackupsEnabledPreferenceController.class);
+ assertThat(controllers.get(position++)).isInstanceOf(
PreferenceCategoryController.class);
assertThat(controllers.get(position++)).isInstanceOf(
FailedPasswordWipeCurrentUserPreferenceController.class);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
index 14627c5..d983dfc 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
@@ -17,8 +17,10 @@
package com.android.settings.fuelgauge.batterytip.detectors;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -48,7 +50,8 @@
@RunWith(SettingsRobolectricTestRunner.class)
public class HighUsageDetectorTest {
- private static final int UID = 123;
+ private static final int UID_HIGH = 123;
+ private static final int UID_ZERO = 345;
private static final long SCREEN_ON_TIME_MS = DateUtils.HOUR_IN_MILLIS;
private Context mContext;
@Mock
@@ -56,7 +59,9 @@
@Mock
private BatteryUtils mBatteryUtils;
@Mock
- private BatterySipper mBatterySipper;
+ private BatterySipper mHighBatterySipper;
+ @Mock
+ private BatterySipper mZeroBatterySipper;
@Mock
private HighUsageDataParser mDataParser;
@@ -75,14 +80,25 @@
mHighUsageDetector.mBatteryUtils = mBatteryUtils;
mHighUsageDetector.mDataParser = mDataParser;
doNothing().when(mHighUsageDetector).parseBatteryData();
- doReturn(UID).when(mBatterySipper).getUid();
+ doReturn(UID_HIGH).when(mHighBatterySipper).getUid();
+ mHighBatterySipper.uidObj = mock(BatteryStats.Uid.class);
+ mZeroBatterySipper.uidObj = mock(BatteryStats.Uid.class);
+ doReturn(UID_ZERO).when(mZeroBatterySipper).getUid();
mAppInfo = new AppInfo.Builder()
- .setUid(UID)
+ .setUid(UID_HIGH)
.setScreenOnTimeMs(SCREEN_ON_TIME_MS)
.build();
+ doReturn(SCREEN_ON_TIME_MS).when(mBatteryUtils).getProcessTimeMs(
+ BatteryUtils.StatusType.FOREGROUND, mHighBatterySipper.uidObj,
+ BatteryStats.STATS_SINCE_CHARGED);
+ doReturn(0L).when(mBatteryUtils).getProcessTimeMs(
+ BatteryUtils.StatusType.FOREGROUND, mZeroBatterySipper.uidObj,
+ BatteryStats.STATS_SINCE_CHARGED);
+
mUsageList = new ArrayList<>();
- mUsageList.add(mBatterySipper);
+ mUsageList.add(mHighBatterySipper);
+ when(mBatteryStatsHelper.getUsageList()).thenReturn(mUsageList);
}
@Test
@@ -95,10 +111,16 @@
@Test
public void testDetect_containsHighUsageApp_tipVisible() {
doReturn(true).when(mDataParser).isDeviceHeavilyUsed();
- when(mBatteryStatsHelper.getUsageList()).thenReturn(mUsageList);
- doReturn(SCREEN_ON_TIME_MS).when(mBatteryUtils).getProcessTimeMs(
- BatteryUtils.StatusType.FOREGROUND, mBatterySipper.uidObj,
- BatteryStats.STATS_SINCE_CHARGED);
+
+ final HighUsageTip highUsageTip = (HighUsageTip) mHighUsageDetector.detect();
+ assertThat(highUsageTip.isVisible()).isTrue();
+ assertThat(highUsageTip.getHighUsageAppList()).containsExactly(mAppInfo);
+ }
+
+ @Test
+ public void testDetect_containsHighUsageApp_removeZeroOne() {
+ doReturn(true).when(mDataParser).isDeviceHeavilyUsed();
+ mUsageList.add(mZeroBatterySipper);
final HighUsageTip highUsageTip = (HighUsageTip) mHighUsageDetector.detect();
assertThat(highUsageTip.isVisible()).isTrue();
diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
index 19c9f87..51722e5 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
@@ -76,9 +76,7 @@
public void testPrepareActionBar_networkResetShouldBeCreated() {
final NetworkResetActionMenuController resetController =
mock(NetworkResetActionMenuController.class);
- final PrivateDnsMenuController privateDnsController = mock(PrivateDnsMenuController.class);
ReflectionHelpers.setField(mFragment, "mNetworkResetController", resetController);
- ReflectionHelpers.setField(mFragment, "mPrivateDnsMenuController", privateDnsController);
mFragment.onCreateOptionsMenu(null, null);
diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsMenuControllerTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsMenuControllerTest.java
deleted file mode 100644
index fa824d6..0000000
--- a/tests/robotests/src/com/android/settings/network/PrivateDnsMenuControllerTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.FragmentManager;
-import android.view.Menu;
-import android.view.MenuItem;
-
-import com.android.settings.R;
-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;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-public class PrivateDnsMenuControllerTest {
- private static final int MENU_ID = 0;
-
- private PrivateDnsMenuController mController;
- @Mock
- private Menu mMenu;
- @Mock
- private MenuItem mMenuItem;
- @Mock
- private FragmentManager mFragmentManager;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mController = new PrivateDnsMenuController(mFragmentManager, MENU_ID);
- when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);
- }
-
- @Test
- public void buildMenuItem_available_shouldAddToMenu() {
- mController.buildMenuItem(mMenu);
-
- verify(mMenu).add(0 /* groupId */, MENU_ID, 0 /* order */,
- R.string.select_private_dns_configuration_title);
- verify(mMenuItem).setOnMenuItemClickListener(any(MenuItem.OnMenuItemClickListener.class));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
deleted file mode 100644
index d490968..0000000
--- a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
-import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
-import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-
-import android.content.Context;
-import android.provider.Settings;
-import android.widget.Button;
-
-import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.shadow.ShadowHelpUtils;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(shadows = ShadowHelpUtils.class)
-public class PrivateDnsModeDialogFragmentTest {
-
- private static final String HOST_NAME = "192.168.1.1";
- private static final String INVALID_HOST_NAME = "...,";
-
- private Context mContext;
- private PrivateDnsModeDialogFragment mFragment;
- private Button mSaveButton;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = RuntimeEnvironment.application;
- mSaveButton = new Button(mContext);
-
- mFragment = spy(new PrivateDnsModeDialogFragment());
- doReturn(mContext).when(mFragment).getContext();
- mFragment.onCreateDialog(null);
- mFragment.mSaveButton = mSaveButton;
- }
-
- @Test
- public void testOnCheckedChanged_dnsModeOff_disableEditText() {
- mFragment.onCheckedChanged(null, R.id.private_dns_mode_off);
-
- assertThat(mFragment.mMode).isEqualTo(PRIVATE_DNS_MODE_OFF);
- assertThat(mFragment.mEditText.isEnabled()).isFalse();
- }
-
- @Test
- public void testOnCheckedChanged_dnsModeOpportunistic_disableEditText() {
- mFragment.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
-
- assertThat(mFragment.mMode).isEqualTo(PRIVATE_DNS_MODE_OPPORTUNISTIC);
- assertThat(mFragment.mEditText.isEnabled()).isFalse();
- }
-
- @Test
- public void testOnCheckedChanged_dnsModeProvider_enableEditText() {
- mFragment.onCheckedChanged(null, R.id.private_dns_mode_provider);
-
- assertThat(mFragment.mMode).isEqualTo(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME);
- assertThat(mFragment.mEditText.isEnabled()).isTrue();
- }
-
- @Test
- public void testOnCreateDialog_containsCorrectData() {
- Settings.Global.putString(mContext.getContentResolver(),
- PrivateDnsModeDialogFragment.MODE_KEY, PRIVATE_DNS_MODE_OPPORTUNISTIC);
- Settings.Global.putString(mContext.getContentResolver(),
- PrivateDnsModeDialogFragment.HOSTNAME_KEY, HOST_NAME);
-
- mFragment.onCreateDialog(null);
-
- assertThat(mFragment.mEditText.getText().toString()).isEqualTo(HOST_NAME);
- assertThat(mFragment.mRadioGroup.getCheckedRadioButtonId()).isEqualTo(
- R.id.private_dns_mode_opportunistic);
- }
-
- @Test
- public void testOnCheckedChanged_switchMode_saveButtonHasCorrectState() {
- // Set invalid hostname
- mFragment.mEditText.setText(INVALID_HOST_NAME);
-
- mFragment.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
- assertThat(mSaveButton.isEnabled()).isTrue();
-
- mFragment.onCheckedChanged(null, R.id.private_dns_mode_provider);
- assertThat(mSaveButton.isEnabled()).isFalse();
-
- mFragment.onCheckedChanged(null, R.id.private_dns_mode_off);
- assertThat(mSaveButton.isEnabled()).isTrue();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogPreferenceTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogPreferenceTest.java
new file mode 100644
index 0000000..8a60cf3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogPreferenceTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OPPORTUNISTIC;
+import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.AlertDialog;
+import android.app.Fragment;
+import android.content.Context;
+import android.provider.Settings;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+import android.widget.LinearLayout;
+
+import com.android.settings.R;
+import com.android.settingslib.CustomDialogPreference.CustomPreferenceDialogFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class PrivateDnsModeDialogPreferenceTest {
+
+ private static final String HOST_NAME = "dns.example.com";
+ private static final String INVALID_HOST_NAME = "...,";
+
+ private PrivateDnsModeDialogPreference mPreference;
+
+ private Context mContext;
+ private Button mSaveButton;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mSaveButton = new Button(mContext);
+
+ final CustomPreferenceDialogFragment fragment = mock(CustomPreferenceDialogFragment.class);
+ final AlertDialog dialog = mock(AlertDialog.class);
+ when(fragment.getDialog()).thenReturn(dialog);
+ when(dialog.getButton(anyInt())).thenReturn(mSaveButton);
+
+ mPreference = new PrivateDnsModeDialogPreference(mContext);
+ ReflectionHelpers.setField(mPreference, "mFragment", fragment);
+
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final View view = inflater.inflate(R.layout.private_dns_mode_dialog,
+ new LinearLayout(mContext), false);
+
+ mPreference.onBindDialogView(view);
+ }
+
+ @Test
+ public void testOnCheckedChanged_dnsModeOff_disableEditText() {
+ mPreference.onCheckedChanged(null, R.id.private_dns_mode_off);
+
+ assertThat(mPreference.mMode).isEqualTo(PRIVATE_DNS_MODE_OFF);
+ assertThat(mPreference.mEditText.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void testOnCheckedChanged_dnsModeOpportunistic_disableEditText() {
+ mPreference.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
+
+ assertThat(mPreference.mMode).isEqualTo(PRIVATE_DNS_MODE_OPPORTUNISTIC);
+ assertThat(mPreference.mEditText.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void testOnCheckedChanged_dnsModeProvider_enableEditText() {
+ mPreference.onCheckedChanged(null, R.id.private_dns_mode_provider);
+
+ assertThat(mPreference.mMode).isEqualTo(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME);
+ assertThat(mPreference.mEditText.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void testOnBindDialogView_containsCorrectData() {
+ Settings.Global.putString(mContext.getContentResolver(),
+ PrivateDnsModeDialogPreference.MODE_KEY, PRIVATE_DNS_MODE_OPPORTUNISTIC);
+ Settings.Global.putString(mContext.getContentResolver(),
+ PrivateDnsModeDialogPreference.HOSTNAME_KEY, HOST_NAME);
+
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final View view = inflater.inflate(R.layout.private_dns_mode_dialog,
+ new LinearLayout(mContext), false);
+ mPreference.onBindDialogView(view);
+
+ assertThat(mPreference.mEditText.getText().toString()).isEqualTo(HOST_NAME);
+ assertThat(mPreference.mRadioGroup.getCheckedRadioButtonId()).isEqualTo(
+ R.id.private_dns_mode_opportunistic);
+ }
+
+ @Test
+ public void testOnCheckedChanged_switchMode_saveButtonHasCorrectState() {
+ // Set invalid hostname
+ mPreference.mEditText.setText(INVALID_HOST_NAME);
+
+ mPreference.onCheckedChanged(null, R.id.private_dns_mode_opportunistic);
+ assertThat(mSaveButton.isEnabled()).isTrue();
+
+ mPreference.onCheckedChanged(null, R.id.private_dns_mode_provider);
+ assertThat(mSaveButton.isEnabled()).isFalse();
+
+ mPreference.onCheckedChanged(null, R.id.private_dns_mode_off);
+ assertThat(mSaveButton.isEnabled()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
index 6ebbef3..fc708ef 100644
--- a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
@@ -20,15 +20,15 @@
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
+import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.content.res.Resources;
import com.android.settings.SubSettings;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.wrapper.WallpaperManagerWrapper;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,6 +40,7 @@
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
+import org.robolectric.annotation.Resetter;
import org.robolectric.shadows.ShadowActivity;
import org.robolectric.shadows.ShadowPackageManager;
@@ -59,10 +60,15 @@
mController = Robolectric.buildActivity(WallpaperSuggestionActivity.class);
}
+ @After
+ public void tearDown() {
+ ShadowWallpaperManager.reset();
+ }
+
@Test
public void launch_primarySuggestionActivityDoesNotExist_shouldFallback() {
ShadowPackageManager packageManager =
- shadowOf(RuntimeEnvironment.application.getPackageManager());
+ shadowOf(RuntimeEnvironment.application.getPackageManager());
packageManager.removePackage("com.android.settings");
ShadowActivity activity = shadowOf(mController.setup().get());
@@ -74,32 +80,34 @@
}
@Test
- public void wallpaperServiceEnabled_no_shouldReturnFalse() {
+ public void wallpaperServiceEnabled_no_shouldReturnTrue() {
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService))
- .thenReturn(false);
-
- assertThat(WallpaperSuggestionActivity.isSuggestionComplete(mContext)).isFalse();
- }
-
- @Test
- @Config(shadows = WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class)
- public void hasWallpaperSet_no_shouldReturnFalse() {
- ShadowWallpaperManagerWrapper.setWallpaperId(0);
-
- assertThat(WallpaperSuggestionActivity.isSuggestionComplete(mContext)).isFalse();
- }
-
- @Test
- @Config(shadows = WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class)
- public void hasWallpaperSet_yes_shouldReturnTrue() {
- ShadowWallpaperManagerWrapper.setWallpaperId(100);
+ .thenReturn(false);
assertThat(WallpaperSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
}
- @Implements(WallpaperManagerWrapper.class)
- public static class ShadowWallpaperManagerWrapper {
+ @Test
+ @Config(shadows = ShadowWallpaperManager.class)
+ public void hasWallpaperSet_no_shouldReturnFalse() {
+ ShadowWallpaperManager.setWallpaperId(0);
+
+ assertThat(WallpaperSuggestionActivity.isSuggestionComplete(RuntimeEnvironment.application))
+ .isFalse();
+ }
+
+ @Test
+ @Config(shadows = ShadowWallpaperManager.class)
+ public void hasWallpaperSet_yes_shouldReturnTrue() {
+ ShadowWallpaperManager.setWallpaperId(100);
+
+ assertThat(WallpaperSuggestionActivity.isSuggestionComplete(RuntimeEnvironment.application))
+ .isTrue();
+ }
+
+ @Implements(WallpaperManager.class)
+ public static class ShadowWallpaperManager {
private static int sWallpaperId;
@@ -107,13 +115,11 @@
sWallpaperId = id;
}
+ @Resetter
public static void reset() {
sWallpaperId = 0;
}
- public void __constructor__(Context context) {
- }
-
@Implementation
public boolean isWallpaperServiceEnabled() {
return true;
diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
index f622804..d1d2b04 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
@@ -17,7 +17,6 @@
package com.android.settings.deviceinfo.storage;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -31,11 +30,11 @@
import android.content.pm.UserInfo;
import android.net.TrafficStats;
import android.os.UserHandle;
+import android.os.UserManager;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.util.SparseArray;
-import com.android.settings.wrapper.UserManagerWrapper;
import com.android.settingslib.applications.StorageStatsSource;
import com.android.settingslib.wrapper.PackageManagerWrapper;
@@ -65,7 +64,7 @@
@Mock
private PackageManagerWrapper mPackageManager;
@Mock
- private UserManagerWrapper mUserManager;
+ private UserManager mUserManager;
private List<ApplicationInfo> mInfo = new ArrayList<>();
private List<UserInfo> mUsers;