Merge "Revert "Force update APs when enabling wifi in WifiSettings."" into oc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ae2eb0a..236ec29 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2378,7 +2378,7 @@
<!-- [CHAR LIMIT=40] Display settings screen, setting option name to change whether the device wakes up when a lift gesture is detected. -->
<string name="lift_to_wake_title">Lift to wake</string>
<!-- [CHAR LIMIT=30] Display settings screen, setting option name to change whether the ambient display feature is enabled. -->
- <string name="doze_title">Incoming notification screen</string>
+ <string name="doze_title">Ambient display</string>
<!-- [CHAR LIMIT=NONE] Display settings screen, setting description for the ambient display feature. -->
<string name="doze_summary">Wake screen when you receive notifications</string>
<!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size -->
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 54eb878..bec8863 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -80,11 +80,6 @@
android:fragment="com.android.settings.webview.WebViewAppPicker" />
<SwitchPreference
- android:key="enable_webview_multiprocess"
- android:title="@string/enable_webview_multiprocess"
- android:summary="@string/enable_webview_multiprocess_desc" />
-
- <SwitchPreference
android:key="color_temperature"
android:title="@string/color_temperature"
android:summary="@string/color_temperature_desc" />
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index 86e3b16..7946dd9 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -60,7 +60,7 @@
<Preference
android:key="encryption_and_credential"
android:title="@string/encryption_and_credential_settings_title"
- android:summary="@string/encryption_and_credential_settings_summary"/>
+ android:summary="@string/encryption_and_credential_settings_summary"
android:fragment="com.android.settings.EncryptionAndCredential"/>
<Preference android:key="manage_trust_agents"
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index b29f8a0..1230ae5 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -104,7 +104,7 @@
controllers.add(new VrDisplayPreferenceController(context));
controllers.add(new WallpaperPreferenceController(context));
controllers.add(new ThemePreferenceController(context));
- controllers.add(new BrightnessLevelPreferenceController(context, lifecycle));
+ controllers.add(new BrightnessLevelPreferenceController(context));
return controllers;
}
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index 6ed06da..21ead46 100644
--- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
@@ -42,12 +42,9 @@
public static final String SHORTCUT_SERVICE_KEY = "accessibility_shortcut_service";
public static final String ON_LOCK_SCREEN_KEY = "accessibility_shortcut_on_lock_screen";
- // ID for dialog that confirms shortcut capabilities
- private static final int DIALOG_ID_ADD_SHORTCUT_WARNING = 1;
private Preference mServicePreference;
private SwitchPreference mOnLockScreenSwitchPreference;
- private String mSelectedServiceComponentNameString;
@Override
public int getMetricsCategory() {
@@ -98,7 +95,7 @@
CharSequence serviceName = getServiceName(getContext());
mServicePreference.setSummary(serviceName);
mOnLockScreenSwitchPreference.setChecked(Settings.Secure.getInt(
- cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 1) == 1);
+ cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 0) == 1);
if (TextUtils.equals(serviceName, getString(R.string.accessibility_no_service_selected))) {
// If there's no service configured, enabling the shortcut will have no effect
// It should already be disabled, but force the switch to off just in case
diff --git a/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java b/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java
index 8b6d52a..3250521 100644
--- a/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java
+++ b/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.accessibility;
+import static android.content.DialogInterface.BUTTON_POSITIVE;
+
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Activity;
import android.app.AlertDialog;
@@ -147,7 +149,7 @@
@Override
public void onClick(DialogInterface dialog, int which) {
final Fragment fragment = getTargetFragment();
- if (fragment instanceof DefaultAppPickerFragment) {
+ if ((which == BUTTON_POSITIVE) && (fragment instanceof DefaultAppPickerFragment)) {
final Bundle bundle = getArguments();
((ShortcutServicePickerFragment) fragment).onServiceConfirmed(
bundle.getString(EXTRA_KEY));
diff --git a/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java b/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java
index 79776a0..f5d7b64 100644
--- a/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java
+++ b/src/com/android/settings/accounts/AutoSyncDataPreferenceController.java
@@ -28,8 +28,8 @@
import android.os.UserManager;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
-
import android.util.Log;
+
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
@@ -41,9 +41,10 @@
private static final String TAG_CONFIRM_AUTO_SYNC_CHANGE = "confirmAutoSyncChange";
private static final String KEY_AUTO_SYNC_ACCOUNT = "auto_sync_account_data";
- protected UserManager mUserManager;
- private UserHandle mUserHandle;
- private Fragment mParentFragment;
+ protected final UserManager mUserManager;
+ private final Fragment mParentFragment;
+
+ protected UserHandle mUserHandle;
public AutoSyncDataPreferenceController(Context context, Fragment parent) {
super(context);
diff --git a/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java b/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java
index 899f77d..1d08968 100644
--- a/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java
+++ b/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceController.java
@@ -18,6 +18,8 @@
import android.app.Fragment;
import android.content.Context;
+import com.android.settings.Utils;
+
public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPreferenceController {
private static final String TAG = "AutoSyncWorkData";
@@ -25,11 +27,11 @@
public AutoSyncWorkDataPreferenceController(Context context, Fragment parent) {
super(context, parent);
+ mUserHandle = Utils.getManagedProfile(mUserManager);
}
@Override
public String getPreferenceKey() {
return KEY_AUTO_SYNC_WORK_ACCOUNT;
}
-
}
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index af1127e..45938ae 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -25,6 +25,7 @@
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.support.annotation.IntDef;
@@ -217,9 +218,8 @@
Log.w(TAG, "No actionbar, cannot style actionbar.");
return this;
}
- final Drawable appHeaderBackground =
- mAppHeader.findViewById(R.id.app_snippet).getBackground();
- actionBar.setBackgroundDrawable(appHeaderBackground);
+ actionBar.setBackgroundDrawable(
+ new ColorDrawable(Utils.getColorAttr(activity, android.R.attr.colorSecondary)));
actionBar.setElevation(0);
return this;
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index 22b21e4..6c41f83 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -21,13 +21,16 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.os.UserManager;
import android.provider.Settings;
import android.widget.Switch;
import android.widget.Toast;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.widget.SwitchWidgetController;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.WirelessUtils;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -45,6 +48,7 @@
private boolean mValidListener;
private final LocalBluetoothAdapter mLocalAdapter;
private final IntentFilter mIntentFilter;
+ private final RestrictionUtils mRestrictionUtils;
private static final String EVENT_DATA_IS_BT_ON = "is_bluetooth_on";
private static final int EVENT_UPDATE_INDEX = 0;
@@ -63,6 +67,13 @@
public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
int metricsEvent) {
+ this(context, switchWidget, metricsFeatureProvider, manager, metricsEvent,
+ new RestrictionUtils());
+ }
+
+ public BluetoothEnabler(Context context, SwitchWidgetController switchWidget,
+ MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
+ int metricsEvent, RestrictionUtils restrictionUtils) {
mContext = context;
mMetricsFeatureProvider = metricsFeatureProvider;
mSwitchWidget = switchWidget;
@@ -79,6 +90,7 @@
mLocalAdapter = manager.getBluetoothAdapter();
}
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
+ mRestrictionUtils = restrictionUtils;
}
public void setupSwitchController() {
@@ -90,15 +102,17 @@
}
public void resume(Context context) {
+ if (mContext != context) {
+ mContext = context;
+ }
+
+ maybeEnforceRestrictions();
+
if (mLocalAdapter == null) {
mSwitchWidget.setEnabled(false);
return;
}
- if (mContext != context) {
- mContext = context;
- }
-
// Bluetooth state is not sticky, so set it manually
handleStateChanged(mLocalAdapter.getBluetoothState());
@@ -156,6 +170,10 @@
@Override
public boolean onSwitchToggled(boolean isChecked) {
+ if (maybeEnforceRestrictions()) {
+ return true;
+ }
+
// Show toast message if Bluetooth is not allowed in airplane mode
if (isChecked &&
!WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_BLUETOOTH)) {
@@ -182,4 +200,29 @@
mSwitchWidget.setEnabled(false);
return true;
}
+
+ /**
+ * Enforces user restrictions disallowing Bluetooth (or its configuration) if there are any.
+ *
+ * @return if there was any user restriction to enforce.
+ */
+ @VisibleForTesting
+ boolean maybeEnforceRestrictions() {
+ EnforcedAdmin admin = mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_BLUETOOTH);
+ if (admin == null) {
+ admin = mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH);
+ }
+ mSwitchWidget.setDisabledByAdmin(admin);
+ if (admin != null) {
+ mSwitchWidget.setChecked(false);
+ if (mSwitch != null) {
+ mSwitch.setEnabled(false);
+ mSwitch.setChecked(false);
+ }
+ }
+ return admin != null;
+ }
+
}
diff --git a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
index f98a209..c071570 100644
--- a/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceController.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.LifecycleObserver;
@@ -26,9 +27,9 @@
import com.android.settings.core.lifecycle.events.OnStart;
import com.android.settings.core.lifecycle.events.OnStop;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
-import com.android.settings.widget.MasterSwitchPreference;
import com.android.settings.widget.MasterSwitchController;
+import com.android.settings.widget.MasterSwitchPreference;
+import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
public class BluetoothMasterSwitchPreferenceController extends PreferenceController
@@ -41,12 +42,20 @@
private MasterSwitchPreference mBtPreference;
private BluetoothEnabler mBluetoothEnabler;
private BluetoothSummaryUpdater mSummaryUpdater;
+ private RestrictionUtils mRestrictionUtils;
public BluetoothMasterSwitchPreferenceController(Context context,
LocalBluetoothManager bluetoothManager) {
+ this(context, bluetoothManager, new RestrictionUtils());
+ }
+
+ @VisibleForTesting
+ public BluetoothMasterSwitchPreferenceController(Context context,
+ LocalBluetoothManager bluetoothManager, RestrictionUtils restrictionUtils) {
super(context);
mBluetoothManager = bluetoothManager;
mSummaryUpdater = new BluetoothSummaryUpdater(mContext, this, mBluetoothManager);
+ mRestrictionUtils = restrictionUtils;
}
@Override
@@ -56,7 +65,8 @@
mBluetoothEnabler = new BluetoothEnabler(mContext,
new MasterSwitchController(mBtPreference),
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager,
- MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE);
+ MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
+ mRestrictionUtils);
}
@Override
diff --git a/src/com/android/settings/bluetooth/RestrictionUtils.java b/src/com/android/settings/bluetooth/RestrictionUtils.java
new file mode 100644
index 0000000..9c0c481
--- /dev/null
+++ b/src/com/android/settings/bluetooth/RestrictionUtils.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.bluetooth;
+
+import android.content.Context;
+import android.os.UserHandle;
+
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
+/**
+ * A utility class to aid testing.
+ */
+public class RestrictionUtils {
+
+ public RestrictionUtils() {}
+
+ /**
+ * Utility method to check if user restriction is enforced on the current user.
+ *
+ * <p> It helps with testing - override it to avoid calling static method which calls system
+ * API.
+ */
+ public EnforcedAdmin checkIfRestrictionEnforced(Context context, String restriction) {
+ return RestrictedLockUtils.checkIfRestrictionEnforced(
+ context, restriction, UserHandle.myUserId());
+ }
+
+}
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index dda984b..aca4809 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -14,13 +14,16 @@
package com.android.settings.datausage;
+import static android.net.NetworkPolicy.LIMIT_DISABLED;
+import static android.net.NetworkPolicy.WARNING_DISABLED;
+
import android.app.AlertDialog;
import android.app.Dialog;
-import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
+import android.icu.text.NumberFormat;
import android.net.NetworkPolicy;
import android.net.NetworkTemplate;
import android.os.Bundle;
@@ -42,8 +45,7 @@
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.net.DataUsageController;
-import static android.net.NetworkPolicy.LIMIT_DISABLED;
-import static android.net.NetworkPolicy.WARNING_DISABLED;
+import java.text.ParseException;
public class BillingCycleSettings extends DataUsageBase implements
Preference.OnPreferenceChangeListener, DataUsageEditController {
@@ -246,7 +248,6 @@
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
final long bytes = isLimit ? editor.getPolicyLimitBytes(template)
: editor.getPolicyWarningBytes(template);
- final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;
if (bytes > 1.5f * GB_IN_BYTES) {
final String bytesText = formatText(bytes / (float) GB_IN_BYTES);
@@ -265,7 +266,7 @@
private String formatText(float v) {
v = Math.round(v * 100) / 100f;
- return String.valueOf(v);
+ return NumberFormat.getInstance().format(v);
}
@Override
@@ -278,15 +279,20 @@
final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE);
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
- EditText bytesField = (EditText) mView.findViewById(R.id.bytes);
- Spinner spinner = (Spinner) mView.findViewById(R.id.size_spinner);
+ EditText bytesField = mView.findViewById(R.id.bytes);
+ Spinner spinner = mView.findViewById(R.id.size_spinner);
String bytesString = bytesField.getText().toString();
- if (bytesString.isEmpty()) {
- bytesString = "0";
+
+ double input = 0;
+ try {
+ input = NumberFormat.getInstance().parse(bytesString).doubleValue();
+ } catch (ParseException e) {
+ Log.w(TAG, "Failed to parse byte value " + bytesString);
}
- final long bytes = (long) (Float.valueOf(bytesString)
- * (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
+
+ final long bytes = (long) (input
+ * (spinner.getSelectedItemPosition() == 0 ? MB_IN_BYTES : GB_IN_BYTES));
// to fix the overflow problem
final long correctedBytes = Math.min(MAX_DATA_LIMIT_BYTES, bytes);
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
index adf2938..a2fe07d 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSettings.java
@@ -123,9 +123,6 @@
boolean isStorageManagerChecked =
Settings.Secure.getInt(getContentResolver(),
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
- // Using the setCheckedInternal means the checked status won't propagate through the
- // listeners -- this will prevent us from accidentally causing a metrics event on resume.
- mSwitchBar.setCheckedInternal(isStorageManagerChecked);
mDaysToRetain.setEnabled(isStorageManagerChecked);
}
diff --git a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
index a648102..8ab1a07 100644
--- a/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
+++ b/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarController.java
@@ -52,6 +52,17 @@
mDaysToRetainPreference = Preconditions.checkNotNull(daysToRetainPreference);
mFragmentManager = Preconditions.checkNotNull(fragmentManager);
+ initializeCheckedStatus();
+ }
+
+ private void initializeCheckedStatus() {
+ boolean isStorageManagerChecked =
+ Settings.Secure.getInt(
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
+ 0)
+ != 0;
+ mSwitchBar.setChecked(isStorageManagerChecked);
mSwitchBar.addOnSwitchChangeListener(this);
}
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index bfb9f0f..583a5eb 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -127,7 +127,6 @@
private static final String ENABLE_TERMINAL = "enable_terminal";
private static final String KEEP_SCREEN_ON = "keep_screen_on";
private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
- private static final String WEBVIEW_MULTIPROCESS_KEY = "enable_webview_multiprocess";
private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
private static final String HDCP_CHECKING_KEY = "hdcp_checking";
private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
@@ -319,7 +318,6 @@
private ListPreference mOverlayDisplayDevices;
private WebViewAppPreferenceController mWebViewAppPrefController;
- private SwitchPreference mWebViewMultiprocess;
private ListPreference mSimulateColorSpace;
@@ -497,7 +495,6 @@
mLogpersist = null;
}
mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
- mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
mBluetoothEnableInbandRinging = findAndInitSwitchPref(BLUETOOTH_ENABLE_INBAND_RINGING_KEY);
if (!BluetoothHeadset.isInbandRingingSupported(getContext())) {
@@ -814,7 +811,6 @@
updateForceResizableOptions();
Preference webViewAppPref = findPreference(mWebViewAppPrefController.getPreferenceKey());
mWebViewAppPrefController.updateState(webViewAppPref);
- updateWebViewMultiprocessOptions();
updateOemUnlockOptions();
if (mColorTemperaturePreference != null) {
updateColorTemperature();
@@ -852,21 +848,6 @@
pokeSystemProperties();
}
- private void updateWebViewMultiprocessOptions() {
- try {
- updateSwitchPreference(mWebViewMultiprocess,
- mWebViewUpdateService.isMultiProcessEnabled());
- } catch (RemoteException e) {
- }
- }
-
- private void writeWebViewMultiprocessOptions() {
- try {
- mWebViewUpdateService.enableMultiProcess(mWebViewMultiprocess.isChecked());
- } catch (RemoteException e) {
- }
- }
-
private void updateHdcpValues() {
ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
if (hdcpChecking != null) {
@@ -2551,8 +2532,6 @@
writeBluetoothDisableAbsVolumeOptions();
} else if (preference == mBluetoothEnableInbandRinging) {
writeBluetoothEnableInbandRingingOptions();
- } else if (preference == mWebViewMultiprocess) {
- writeWebViewMultiprocessOptions();
} else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
resetShortcutManagerThrottling();
} else {
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeForget.java b/src/com/android/settings/deviceinfo/PrivateVolumeForget.java
index a8e119d..b6d50ce 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeForget.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeForget.java
@@ -53,8 +53,18 @@
Bundle savedInstanceState) {
final StorageManager storage = getActivity().getSystemService(StorageManager.class);
final String fsUuid = getArguments().getString(VolumeRecord.EXTRA_FS_UUID);
+ // Passing null will crash the StorageManager, so let's early exit.
+ if (fsUuid == null) {
+ getActivity().finish();
+ return null;
+ }
mRecord = storage.findRecordByUuid(fsUuid);
+ if (mRecord == null) {
+ getActivity().finish();
+ return null;
+ }
+
final View view = inflater.inflate(R.layout.storage_internal_forget, container, false);
final TextView body = (TextView) view.findViewById(R.id.body);
final Button confirm = (Button) view.findViewById(R.id.confirm);
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index f7bb95d..2a5ac17 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -19,7 +19,6 @@
import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
-import android.content.Intent;
import android.content.Loader;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -29,16 +28,11 @@
import android.os.storage.VolumeInfo;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
-import android.util.Log;
import android.util.SparseArray;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settings.applications.PackageManagerWrapper;
import com.android.settings.applications.PackageManagerWrapperImpl;
import com.android.settings.applications.UserManagerWrapper;
import com.android.settings.applications.UserManagerWrapperImpl;
@@ -58,7 +52,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Objects;
public class StorageDashboardFragment extends DashboardFragment
implements LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
@@ -101,8 +94,7 @@
final long usedBytes = totalSize - mVolume.getPath().getFreeSpace();
mSummaryController.updateBytes(usedBytes, totalSize);
mPreferenceController.setVolume(mVolume);
- mPreferenceController.setSystemSize(systemSize);
-
+ mPreferenceController.setUsedSize(usedBytes);
mPreferenceController.setTotalSize(totalSize);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
PreferenceController controller = mSecondaryUsers.get(i);
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 36694f0..5c4e354 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -78,7 +78,7 @@
private final StorageVolumeProvider mSvp;
private VolumeInfo mVolume;
private int mUserId;
- private long mSystemSize;
+ private long mUsedBytes;
private long mTotalSize;
private StorageItemPreference mPhotoPreference;
@@ -226,17 +226,29 @@
mGamePreference.setStorageSize(data.gamesSize, mTotalSize);
mMoviesPreference.setStorageSize(data.videoAppsSize, mTotalSize);
mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
- if (mSystemPreference != null) {
- mSystemPreference.setStorageSize(mSystemSize + data.systemSize, mTotalSize);
- }
- long unattributedBytes = data.externalStats.totalBytes - data.externalStats.audioBytes
- - data.externalStats.videoBytes - data.externalStats.imageBytes;
- mFilePreference.setStorageSize(unattributedBytes, mTotalSize);
+ long unattributedExternalBytes =
+ data.externalStats.totalBytes
+ - data.externalStats.audioBytes
+ - data.externalStats.videoBytes
+ - data.externalStats.imageBytes;
+ mFilePreference.setStorageSize(unattributedExternalBytes, mTotalSize);
+
+ // We define the system size as everything we can't classify.
+ if (mSystemPreference != null) {
+ mSystemPreference.setStorageSize(
+ mUsedBytes
+ - data.externalStats.totalBytes
+ - data.musicAppsSize
+ - data.gamesSize
+ - data.videoAppsSize
+ - data.otherAppsSize,
+ mTotalSize);
+ }
}
- public void setSystemSize(long systemSizeBytes) {
- mSystemSize = systemSizeBytes;
+ public void setUsedSize(long usedSizeBytes) {
+ mUsedBytes = usedSizeBytes;
}
public void setTotalSize(long totalSizeBytes) {
diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceController.java b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
index d012ac3..e0000d6 100644
--- a/src/com/android/settings/display/BrightnessLevelPreferenceController.java
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
@@ -13,79 +13,20 @@
*/
package com.android.settings.display;
-import android.content.ContentResolver;
+import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
+
import android.content.Context;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Handler;
-import android.os.PowerManager;
-import android.os.RemoteException;
-import android.os.ServiceManager;
import android.provider.Settings;
-import android.provider.Settings.System;
-import android.service.vr.IVrManager;
-import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.util.Log;
-
import com.android.settings.core.PreferenceController;
-import com.android.settings.core.lifecycle.Lifecycle;
-import com.android.settings.core.lifecycle.LifecycleObserver;
-import com.android.settings.core.lifecycle.events.OnPause;
-import com.android.settings.core.lifecycle.events.OnResume;
-
import java.text.NumberFormat;
-public class BrightnessLevelPreferenceController extends PreferenceController implements
- LifecycleObserver, OnResume, OnPause {
+public class BrightnessLevelPreferenceController extends PreferenceController {
- private static final String TAG = "BrightnessPrefCtrl";
private static final String KEY_BRIGHTNESS = "brightness";
- private static final Uri BRIGHTNESS_MODE_URI;
- private static final Uri BRIGHTNESS_URI;
- private static final Uri BRIGHTNESS_FOR_VR_URI;
- private static final Uri BRIGHTNESS_ADJ_URI;
- private final int mMinBrightness;
- private final int mMaxBrightness;
- private final int mMinVrBrightness;
- private final int mMaxVrBrightness;
- private final ContentResolver mContentResolver;
-
- private Preference mPreference;
-
- static {
- BRIGHTNESS_MODE_URI = System.getUriFor(System.SCREEN_BRIGHTNESS_MODE);
- BRIGHTNESS_URI = System.getUriFor(System.SCREEN_BRIGHTNESS);
- BRIGHTNESS_FOR_VR_URI = System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR);
- BRIGHTNESS_ADJ_URI = System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ);
- }
-
- private ContentObserver mBrightnessObserver = new ContentObserver(new Handler()) {
- @Override
- public void onChange(boolean selfChange) {
- updatedSummary(mPreference);
- }
- };
-
- public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
- this(context, lifecycle, new PowerManagerWrapper(
- (PowerManager) context.getSystemService(Context.POWER_SERVICE)));
- }
-
- @VisibleForTesting
- public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle,
- PowerManagerWrapper powerManagerWrapper) {
+ public BrightnessLevelPreferenceController(Context context) {
super(context);
- if (lifecycle != null) {
- lifecycle.addObserver(this);
- }
- mMinBrightness = powerManagerWrapper.getMinimumScreenBrightnessSetting();
- mMaxBrightness = powerManagerWrapper.getMaximumScreenBrightnessSetting();
- mMinVrBrightness = powerManagerWrapper.getMinimumScreenBrightnessForVrSetting();
- mMaxVrBrightness = powerManagerWrapper.getMaximumScreenBrightnessForVrSetting();
- mContentResolver = mContext.getContentResolver();
}
@Override
@@ -99,66 +40,10 @@
}
@Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = screen.findPreference(KEY_BRIGHTNESS);
- }
-
- @Override
public void updateState(Preference preference) {
- updatedSummary(preference);
+ final double brightness = Settings.System.getInt(mContext.getContentResolver(),
+ SCREEN_BRIGHTNESS, 0);
+ preference.setSummary(NumberFormat.getPercentInstance().format(brightness / 255));
}
- @Override
- public void onResume() {
- mContentResolver.registerContentObserver(BRIGHTNESS_MODE_URI, false, mBrightnessObserver);
- mContentResolver.registerContentObserver(BRIGHTNESS_URI, false, mBrightnessObserver);
- mContentResolver.registerContentObserver(BRIGHTNESS_FOR_VR_URI, false, mBrightnessObserver);
- mContentResolver.registerContentObserver(BRIGHTNESS_ADJ_URI, false, mBrightnessObserver);
- }
-
- @Override
- public void onPause() {
- mContentResolver.unregisterContentObserver(mBrightnessObserver);
- }
-
- private void updatedSummary(Preference preference) {
- if (preference != null) {
- preference.setSummary(NumberFormat.getPercentInstance().format(getCurrentBrightness()));
- }
- }
-
- private double getCurrentBrightness() {
- if (isInVrMode()) {
- final double value = System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR,
- mMaxBrightness);
- return getPercentage(value, mMinVrBrightness, mMaxVrBrightness);
- }
- final int brightnessMode = Settings.System.getInt(mContentResolver,
- System.SCREEN_BRIGHTNESS_MODE, System.SCREEN_BRIGHTNESS_MODE_MANUAL);
- if (brightnessMode == System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
- final float value = Settings.System.getFloat(mContentResolver,
- System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0);
- // auto brightness is between -1 and 1
- return ((value + 1)) / 2;
- }
- final double value = Settings.System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS,
- mMinBrightness);
- return getPercentage(value, mMinBrightness, mMaxBrightness);
- }
-
- private double getPercentage(double value, int min, int max) {
- return (value - min) / (max - min);
- }
-
- @VisibleForTesting
- boolean isInVrMode() {
- try {
- return IVrManager.Stub.asInterface(ServiceManager.getService(Context.VR_SERVICE))
- .getVrModeState();
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to check vr mode!", e);
- }
- return false;
- }
}
diff --git a/src/com/android/settings/display/PowerManagerWrapper.java b/src/com/android/settings/display/PowerManagerWrapper.java
deleted file mode 100644
index afa2f33..0000000
--- a/src/com/android/settings/display/PowerManagerWrapper.java
+++ /dev/null
@@ -1,49 +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.display;
-
-import android.os.PowerManager;
-
-/**
- * This class replicates a subset of the android.os.PowerManager. The class exists so that we can
- * use a thin wrapper around the PowerManager in production code and a mock in tests. We cannot
- * directly mock or shadow the PowerManager, because some of the methods we rely on are newer than
- * the API version supported by Robolectric or are hidden.
- */
-public class PowerManagerWrapper {
- private final PowerManager mPowerManager;
-
- public PowerManagerWrapper(PowerManager powerManager) {
- mPowerManager = powerManager;
- }
-
- public int getMinimumScreenBrightnessSetting() {
- return mPowerManager.getMinimumScreenBrightnessSetting();
- }
-
- public int getMaximumScreenBrightnessSetting() {
- return mPowerManager.getMaximumScreenBrightnessSetting();
- }
-
- public int getMinimumScreenBrightnessForVrSetting() {
- return mPowerManager.getMinimumScreenBrightnessForVrSetting();
- }
-
- public int getMaximumScreenBrightnessForVrSetting() {
- return mPowerManager.getMaximumScreenBrightnessForVrSetting();
- }
-}
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index 01670fe..fb59c59 100644
--- a/src/com/android/settings/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/fingerprint/FingerprintSettings.java
@@ -47,6 +47,7 @@
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.style.URLSpan;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@@ -604,7 +605,9 @@
private void renameFingerPrint(int fingerId, String newName) {
mFingerprintManager.rename(fingerId, mUserId, newName);
- mFingerprintsRenaming.put(fingerId, newName);
+ if (!TextUtils.isEmpty(newName)) {
+ mFingerprintsRenaming.put(fingerId, newName);
+ }
updatePreferences();
}
diff --git a/src/com/android/settings/wifi/LinkablePreference.java b/src/com/android/settings/wifi/LinkablePreference.java
index 5bf51ed..9a6b11a 100644
--- a/src/com/android/settings/wifi/LinkablePreference.java
+++ b/src/com/android/settings/wifi/LinkablePreference.java
@@ -21,6 +21,7 @@
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.Spannable;
+import android.text.method.LinkMovementMethod;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.widget.TextView;
@@ -81,6 +82,7 @@
mContentTitle.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(boldSpan);
+ textView.setMovementMethod(new LinkMovementMethod());
}
}
diff --git a/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java
new file mode 100644
index 0000000..d93d3a7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.accounts;
+
+
+import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.when;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AutoSyncWorkDataPreferenceControllerTest {
+
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private UserManager mUserManager;
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private Fragment mFragment;
+ @Mock
+ private Context mContext;
+
+ private AutoSyncWorkDataPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+
+ mController = new AutoSyncWorkDataPreferenceController(mContext, mFragment);
+ }
+
+ @Test
+ public void checkIsAvailable_managedProfile_shouldNotDisplay() {
+ when(mUserManager.isManagedProfile()).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void checkIsAvailable_linkedUser_shouldNotDisplay() {
+ when(mUserManager.isManagedProfile()).thenReturn(false);
+ when(mUserManager.isLinkedUser()).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void checkIsAvailable_singleUserProfile_shouldNotDisplay() {
+ final List<UserInfo> infos = new ArrayList<>();
+ infos.add(new UserInfo(1, "user 1", 0));
+ when(mUserManager.isManagedProfile()).thenReturn(false);
+ when(mUserManager.isLinkedUser()).thenReturn(false);
+ when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void multipleProfile_shouldInitWithWorkProfileUserHandle() {
+ final int id1 = 1;
+ final int id2 = 2;
+ final UserInfo managedUser = new UserInfo(id2, "user 2", FLAG_MANAGED_PROFILE);
+ final List<UserHandle> infos = new ArrayList<>();
+ infos.add(new UserHandle(id1));
+ infos.add(new UserHandle(id2));
+ when(mUserManager.getUserProfiles()).thenReturn(infos);
+ when(mUserManager.getUserHandle()).thenReturn(id1);
+ when(mUserManager.getUserInfo(id2)).thenReturn(managedUser);
+
+ mController = new AutoSyncWorkDataPreferenceController(mContext, mFragment);
+
+ assertThat(mController.mUserHandle.getIdentifier()).isEqualTo(id2);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
index eef2112..37a7521 100644
--- a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
@@ -34,7 +34,7 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
-import android.graphics.drawable.Drawable;
+import android.graphics.drawable.ColorDrawable;
import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.view.LayoutInflater;
@@ -310,10 +310,11 @@
mController.styleActionBar(mActivity);
verify(actionBar).setElevation(0);
- verify(actionBar).setBackgroundDrawable(any(Drawable.class));
+ // Enforce a color drawable as background here, as image based drawables might not be
+ // wide enough to cover entire action bar.
+ verify(actionBar).setBackgroundDrawable(any(ColorDrawable.class));
}
-
@Test
public void initAppHeaderController_appHeaderNull_useFragmentContext() {
mController = new AppHeaderController(mContext, mFragment, null);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
index 7761afc..074bef2 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -15,12 +15,15 @@
*/
package com.android.settings.bluetooth;
+import android.content.ComponentName;
import android.content.Context;
+import android.os.UserManager;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.widget.MasterSwitchController;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
@@ -30,30 +33,108 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import static com.google.common.truth.Truth.assertThat;
+import static junit.framework.TestCase.assertNotNull;
+import static junit.framework.TestCase.assertEquals;
import static org.mockito.Mockito.mock;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BluetoothEnablerTest {
+ private static final EnforcedAdmin FAKE_ENFORCED_ADMIN =
+ new EnforcedAdmin(new ComponentName("test.package", "test.Class"), 10);
+
@Mock
private MetricsFeatureProvider mMetricsFeatureProvider;
@Mock
private Context mContext;
+ @Mock
+ private MasterSwitchController mMasterSwitchController;
+ @Mock
+ private RestrictionUtils mRestrictionUtils;
+
+ private BluetoothEnabler mBluetoothEnabler;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mBluetoothEnabler = new BluetoothEnabler(
+ mContext,
+ mMasterSwitchController,
+ mMetricsFeatureProvider,
+ mock(LocalBluetoothManager.class),
+ 123,
+ mRestrictionUtils);
}
@Test
public void onSwitchToggled_shouldLogActionWithSuppliedEvent() {
- BluetoothEnabler bluetoothEnabler = new BluetoothEnabler(mContext,
- mock(MasterSwitchController.class), mMetricsFeatureProvider,
- mock(LocalBluetoothManager.class), 123);
- bluetoothEnabler.onSwitchToggled(false);
+ // WHEN the switch is toggled...
+ mBluetoothEnabler.onSwitchToggled(false);
+ // THEN the corresponding metrics action is logged.
verify(mMetricsFeatureProvider).action(mContext, 123, false);
}
+
+ @Test
+ public void maybeEnforceRestrictions_noRestrictions() {
+ // GIVEN there are no restrictions set...
+ when(mRestrictionUtils.checkIfRestrictionEnforced(any(Context.class), any(String.class)))
+ .thenReturn(null);
+
+ // WHEN the maybeEnforceRestrictions is called...
+ // THEN false is returned to indicate there was no restriction to enforce
+ assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isFalse();
+
+ // THEN a null EnfoceAdmin is set.
+ verify(mMasterSwitchController).setDisabledByAdmin(null);
+ // THEN the state of the switch isn't changed.
+ verify(mMasterSwitchController, never()).setChecked(anyBoolean());
+ }
+
+ @Test
+ public void maybeEnforceRestrictions_disallowBluetoothRestrictionSet() {
+ // GIVEN Bluetooth has been disallowed...
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(null);
+
+ // WHEN the maybeEnforceRestrictions is called...
+ // THEN true is returned to indicate there was a restriction to enforce.
+ assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isTrue();
+
+ // THEN the expected EnfoceAdmin is set.
+ verify(mMasterSwitchController).setDisabledByAdmin(FAKE_ENFORCED_ADMIN);
+
+ // THEN the switch is unchecked.
+ verify(mMasterSwitchController).setChecked(false);
+ }
+
+ @Test
+ public void maybeEnforceRestrictions_disallowConfigBluetoothRestrictionSet() {
+ // GIVEN configuring Bluetooth has been disallowed...
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(null);
+ when(mRestrictionUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+
+ // WHEN the maybeEnforceRestrictions is called...
+ // THEN true is returned to indicate there was a restriction to enforce.
+ assertThat(mBluetoothEnabler.maybeEnforceRestrictions()).isTrue();
+
+ // THEN the expected EnfoceAdmin is set.
+ verify(mMasterSwitchController).setDisabledByAdmin(FAKE_ENFORCED_ADMIN);
+
+ // THEN the switch is unchecked.
+ verify(mMasterSwitchController).setChecked(false);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
index 0e39c5d..177130e 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothMasterSwitchPreferenceControllerTest.java
@@ -52,6 +52,8 @@
private PreferenceScreen mScreen;
@Mock
private MasterSwitchPreference mPreference;
+ @Mock
+ private RestrictionUtils mRestrictionUtils;
private Context mContext;
private BluetoothMasterSwitchPreferenceController mController;
@@ -60,7 +62,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application.getApplicationContext();
- mController = new BluetoothMasterSwitchPreferenceController(mContext, mBluetoothManager);
+ mController = new BluetoothMasterSwitchPreferenceController(
+ mContext, mBluetoothManager, mRestrictionUtils);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
diff --git a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
index b4f5f3d..be04eec 100644
--- a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
@@ -16,6 +16,8 @@
package com.android.settings.deletionhelper;
+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.RETURNS_DEEP_STUBS;
@@ -27,6 +29,7 @@
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
+import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
@@ -121,4 +124,41 @@
verify(mFragmentManager.beginTransaction(), never())
.add(any(Fragment.class), eq(ActivationWarningFragment.TAG));
}
+
+ @Test
+ public void initializeSwitchOnConstruction() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
+ 1);
+
+ mController =
+ new AutomaticStorageManagerSwitchBarController(
+ mContext,
+ mSwitchBar,
+ mMetricsFeatureProvider,
+ mPreference,
+ mFragmentManager);
+
+ assertThat(mSwitchBar.isChecked()).isTrue();
+ }
+
+ @Test
+ public void initializingSwitchDoesNotTriggerView() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
+ 1);
+
+ mController =
+ new AutomaticStorageManagerSwitchBarController(
+ mContext,
+ mSwitchBar,
+ mMetricsFeatureProvider,
+ mPreference,
+ mFragmentManager);
+
+ verify(mFragmentManager.beginTransaction(), never())
+ .add(any(Fragment.class), eq(ActivationWarningFragment.TAG));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index 47faf92..2231c22 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -242,21 +242,19 @@
eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
mController.displayPreference(screen);
- mController.setSystemSize(KILOBYTE * 6);
+ mController.setUsedSize(KILOBYTE * 200); // There should 87kB attributed.
StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
result.gamesSize = KILOBYTE * 8;
result.videoAppsSize = KILOBYTE * 16;
result.musicAppsSize = KILOBYTE * 4;
result.otherAppsSize = KILOBYTE * 9;
- result.systemSize = KILOBYTE * 10;
+ result.systemSize = KILOBYTE * 10; // This value is ignored and overriden now.
result.externalStats = new StorageStatsSource.ExternalStorageStats(
KILOBYTE * 50, // total
KILOBYTE * 10, // audio
KILOBYTE * 15, // video
KILOBYTE * 20); // image
- result.gamesSize = KILOBYTE * 8;
- result.otherAppsSize = KILOBYTE * 9;
mController.onLoadFinished(result);
assertThat(audio.getSummary().toString()).isEqualTo("14.00KB"); // 4KB apps + 10KB files
@@ -264,7 +262,7 @@
assertThat(games.getSummary().toString()).isEqualTo("8.00KB");
assertThat(movies.getSummary().toString()).isEqualTo("16.00KB");
assertThat(apps.getSummary().toString()).isEqualTo("9.00KB");
- assertThat(system.getSummary().toString()).isEqualTo("16.00KB");
+ assertThat(system.getSummary().toString()).isEqualTo("113KB");
assertThat(files.getSummary().toString()).isEqualTo("5.00KB");
}
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
index 0b33089..025e1ae 100644
--- a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
@@ -16,31 +16,27 @@
package com.android.settings.display;
+import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
-import android.provider.Settings.System;
+import android.provider.Settings;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
+import java.text.NumberFormat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.internal.ShadowExtractor;
-import org.robolectric.shadows.ShadowContentResolver;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -50,10 +46,6 @@
@Mock
private ContentResolver mContentResolver;
@Mock
- private PowerManagerWrapper mPowerManager;
- @Mock
- private PreferenceScreen mScreen;
- @Mock
private Preference mPreference;
private BrightnessLevelPreferenceController mController;
@@ -61,15 +53,8 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- when(mContext.getContentResolver()).thenReturn(mContentResolver);
- when(mPowerManager.getMinimumScreenBrightnessSetting()).thenReturn(0);
- when(mPowerManager.getMaximumScreenBrightnessSetting()).thenReturn(100);
- when(mPowerManager.getMinimumScreenBrightnessForVrSetting()).thenReturn(0);
- when(mPowerManager.getMaximumScreenBrightnessForVrSetting()).thenReturn(100);
- when(mScreen.findPreference(anyString())).thenReturn(mPreference);
- mController = spy(new BrightnessLevelPreferenceController(mContext, null, mPowerManager));
- doReturn(false).when(mController).isInVrMode();
+ mController = new BrightnessLevelPreferenceController(mContext);
}
@Test
@@ -78,80 +63,14 @@
}
@Test
- public void onResume_shouldRegisterObserver() {
- Context context = RuntimeEnvironment.application;
- BrightnessLevelPreferenceController controller =
- new BrightnessLevelPreferenceController(context, null, mPowerManager);
- ShadowContentResolver shadowContentResolver =
- (ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
-
- controller.onResume();
-
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isNotEmpty();
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_BRIGHTNESS))).isNotEmpty();
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty();
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isNotEmpty();
- }
-
- @Test
- public void onPause_shouldUnregisterObserver() {
- Context context = RuntimeEnvironment.application;
- BrightnessLevelPreferenceController controller =
- new BrightnessLevelPreferenceController(context, null, mPowerManager);
- ShadowContentResolver shadowContentResolver =
- (ShadowContentResolver) ShadowExtractor.extract(context.getContentResolver());
-
- controller.displayPreference(mScreen);
- controller.onResume();
- controller.onPause();
-
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_BRIGHTNESS_MODE))).isEmpty();
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_BRIGHTNESS))).isEmpty();
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isEmpty();
- assertThat(shadowContentResolver.getContentObservers(
- System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isEmpty();
- }
-
- @Test
- public void updateState_inVrMode_shouldSetSummaryToVrBrightness() {
- doReturn(true).when(mController).isInVrMode();
- System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_FOR_VR, 85);
+ public void updateState_shouldSetSummary() {
+ final NumberFormat formatter = NumberFormat.getPercentInstance();
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ Settings.System.putInt(mContentResolver, SCREEN_BRIGHTNESS, 45);
mController.updateState(mPreference);
- verify(mPreference).setSummary("85%");
+ verify(mPreference).setSummary(formatter.format(45.0 / 255));
}
- @Test
- public void updateState_autoBrightness_shouldSetSummaryToVrBrightness() {
- doReturn(false).when(mController).isInVrMode();
- System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
- System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
-
- System.putFloat(mContentResolver, System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f);
-
- mController.updateState(mPreference);
-
- verify(mPreference).setSummary("50%");
- }
-
- @Test
- public void updateState_manualBrightness_shouldSetSummaryToVrBrightness() {
- doReturn(false).when(mController).isInVrMode();
- System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
- System.SCREEN_BRIGHTNESS_MODE_MANUAL);
-
- System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 45);
-
- mController.updateState(mPreference);
-
- verify(mPreference).setSummary("45%");
- }
}
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
index fa0170c..f4370fc 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingUtilsTest.java
@@ -17,30 +17,35 @@
package com.android.settings.search;
-import static com.google.common.truth.Truth.assertThat;
-
import android.content.Context;
-import android.util.ArrayMap;
+import android.util.ArrayMap;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
-import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
+import com.android.settings.display.AutoBrightnessPreferenceController;
+import com.android.settings.gestures.DoubleTapPowerPreferenceController;
+import com.android.settings.gestures.DoubleTapScreenPreferenceController;
+import com.android.settings.gestures.DoubleTwistPreferenceController;
+import com.android.settings.gestures.PickupGesturePreferenceController;
+import com.android.settings.gestures.SwipeToNotificationPreferenceController;
import com.android.settings.search2.DatabaseIndexingUtils;
+
import com.android.settings.search2.IntentPayload;
import com.android.settings.search2.ResultPayload;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
import java.util.Map;
+import static com.google.common.truth.Truth.assertThat;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DatabaseIndexingUtilsTest {
@@ -52,7 +57,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
+ mContext = ShadowApplication.getInstance().getApplicationContext();
}
@Test
@@ -69,11 +74,11 @@
@Test
public void testGetPreferenceControllerUriMap_CompatibleClass_ReturnsValidMap() {
- final String className = "com.android.settings.system.SystemDashboardFragment";
- final Map<String, PreferenceController> map =
- DatabaseIndexingUtils.getPreferenceControllerUriMap(className, mContext);
- assertThat(map.get("system_update_settings"))
- .isInstanceOf(SystemUpdatePreferenceController.class);
+ String className = "com.android.settings.DisplaySettings";
+
+ Map map = DatabaseIndexingUtils.getPreferenceControllerUriMap(className, mContext);
+ assertThat(map.get("auto_brightness"))
+ .isInstanceOf(AutoBrightnessPreferenceController.class);
}
@Test
@@ -101,7 +106,7 @@
return new IntentPayload(null);
}
};
- ArrayMap<String, PreferenceController> map = new ArrayMap<>();
+ ArrayMap<String,PreferenceController> map = new ArrayMap<>();
map.put(key, prefController);
ResultPayload payload = DatabaseIndexingUtils.getPayloadFromUriMap(map, key);
diff --git a/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java b/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java
index 4267ed1..4ee42e0 100644
--- a/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/utils/ThreadUtilsTest.java
@@ -16,16 +16,17 @@
package com.android.settings.utils;
-import com.android.settings.TestConfig;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
-@RunWith(RobolectricTestRunner.class)
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ThreadUtilsTest {
diff --git a/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
new file mode 100644
index 0000000..96cb217
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/LinkablePreferenceTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.settings.LinkifyUtils;
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LinkablePreferenceTest {
+
+ private static final String TITLE = "Title";
+
+ private Context mContext = RuntimeEnvironment.application;
+
+ private LinkablePreference mPreference;
+ private PreferenceViewHolder mHolder;
+ private View mView;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mPreference = new LinkablePreference(mContext);
+ final CharSequence linkableDescription =
+ mContext.getResources().getText(R.string.wifi_scan_notify_text);
+ final LinkifyUtils.OnClickListener clickListener = () -> {/* Do nothing */ };
+ mPreference.setText(TITLE, linkableDescription, clickListener);
+
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ mView = inflater.inflate(
+ mPreference.getLayoutResource(), new LinearLayout(mContext), false);
+ mHolder = PreferenceViewHolder.createInstanceForTests(mView);
+
+ mPreference.onBindViewHolder(mHolder);
+ }
+
+ @Test
+ public void prefWithLinkShouldHaveAccessibilityMovementMethodSet() {
+ TextView textView = mView.findViewById(android.R.id.title);
+ assertThat(textView.getMovementMethod()).isNotNull();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/deviceinfo/PrivateVolumeForgetTest.java b/tests/unit/src/com/android/settings/deviceinfo/PrivateVolumeForgetTest.java
new file mode 100644
index 0000000..be36e43
--- /dev/null
+++ b/tests/unit/src/com/android/settings/deviceinfo/PrivateVolumeForgetTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.deviceinfo;
+
+import android.content.Intent;
+import android.content.Context;
+
+import android.os.storage.VolumeRecord;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.settings.Settings;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class PrivateVolumeForgetTest {
+ @Rule
+ public ActivityTestRule<Settings.PrivateVolumeForgetActivity> mActivityRule =
+ new ActivityTestRule<>(Settings.PrivateVolumeForgetActivity.class, true, true);
+
+ @Test
+ public void test_invalidSetupDoesNotCrashSettings() {
+ Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ Intent intent = new Intent(targetContext, Settings.PrivateVolumeForgetActivity.class);
+ intent.putExtra(VolumeRecord.EXTRA_FS_UUID, "totally-fake-uuid-doesnt-even-fit-format");
+ mActivityRule.launchActivity(intent);
+
+ // Should exit gracefully without crashing.
+ }
+}
\ No newline at end of file