Merge "Make sure FP error text is visible in landscape"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9106a0a..05c5075 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -276,6 +276,8 @@
android:value="com.android.settings.wifi.WifiSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
+ <meta-data android:name="android.metadata.SLICE_URI"
+ android:value="content://com.android.settings.slices/wifi" />
</activity>
<!-- Keep compatibility with old shortcuts. -->
@@ -1918,7 +1920,8 @@
android:label="@string/development_settings_title"
android:icon="@drawable/ic_settings_development"
android:taskAffinity="com.android.settings"
- android:parentActivityName="Settings">
+ android:parentActivityName="Settings"
+ android:enabled="false">
<intent-filter android:priority="1">
<action android:name="android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
<action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
@@ -1987,15 +1990,6 @@
android:value="com.android.settings.print.PrintJobSettingsFragment" />
</activity>
- <!-- Keep compatibility with old shortcuts. -->
- <activity-alias android:name="DevelopmentSettings"
- android:exported="true"
- android:label="@string/development_settings_title"
- android:targetActivity="Settings$DevelopmentSettingsDashboardActivity">
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.development.DevelopmentSettingsDashboardFragment" />
- </activity-alias>
-
<activity android:name=".development.AppPicker"
android:label="@string/select_application"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog" />
@@ -2004,15 +1998,6 @@
android:label="@string/select_webview_provider_dialog_title">
</activity>
- <!-- Keep compatibility with old shortcuts. -->
- <activity-alias android:name="UsbSettings"
- android:exported="true"
- android:label="@string/storage_title_usb"
- android:targetActivity="Settings$DevelopmentSettingsDashboardActivity">
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.deviceinfo.UsbSettings" />
- </activity-alias>
-
<!-- Bluetooth stuff -->
<activity android:name=".bluetooth.BluetoothPairingDialog"
@@ -3308,6 +3293,18 @@
</intent-filter>
</activity>
+ <provider android:name=".SettingsSliceProvider"
+ android:authorities="com.android.settings.slices"
+ android:exported="true">
+ </provider>
+
+ <receiver
+ android:name=".SliceBroadcastReceiver" >
+ <intent-filter>
+ <action android:name="com.android.settings.slice.action.WIFI_CHANGED"/>
+ </intent-filter>
+ </receiver>
+
<!-- This is the longest AndroidManifest.xml ever. -->
</application>
</manifest>
diff --git a/res/layout/search_slice_item.xml b/res/layout/search_slice_item.xml
new file mode 100644
index 0000000..1607209
--- /dev/null
+++ b/res/layout/search_slice_item.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:background="?android:attr/selectableItemBackground"
+ android:clipToPadding="false">
+
+ <include layout="@layout/search_icon_view"/>
+
+ <android.app.slice.widget.SliceView
+ android:id="@android:id/content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/settings_main_dashboard.xml b/res/layout/settings_main_dashboard.xml
index 8e83cff..7c34803 100644
--- a/res/layout/settings_main_dashboard.xml
+++ b/res/layout/settings_main_dashboard.xml
@@ -32,7 +32,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/search_bar_margin"
- app:cardCornerRadius="2dp"
+ app:cardCornerRadius="@dimen/search_bar_half_height"
app:cardBackgroundColor="?android:attr/colorBackground"
app:cardElevation="2dp">
<Toolbar
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index 4d30969..1f78abd 100755
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -60,6 +60,7 @@
<dimen name="switchbar_subsettings_margin_end">24dp</dimen>
<dimen name="search_bar_height">64dp</dimen>
+ <dimen name="search_bar_half_height">32dp</dimen>
<!-- Dimensions for Wifi Assistant Card -->
<dimen name="wifi_assistant_padding_top_bottom">24dp</dimen>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 0d4289a..2f00297 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -121,6 +121,7 @@
<dimen name="search_bar_negative_margin">-8dp</dimen>
<dimen name="search_bar_height">48dp</dimen>
+ <dimen name="search_bar_half_height">24dp</dimen>
<dimen name="search_bar_text_size">16dp</dimen>
<!-- Dimensions for Wifi Assistant Card -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 43827e3..3fb50e5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -394,6 +394,11 @@
<!-- Title for pairing bluetooth device page [CHAR LIMIT=none] -->
<string name="bluetooth_pairing_page_title">Pair new device</string>
+ <!-- Title for connected device group [CHAR LIMIT=none]-->
+ <string name="connected_device_connected_title">Currently connected</string>
+ <!-- Title for connected device group [CHAR LIMIT=none]-->
+ <string name="connected_device_saved_title">Saved devices</string>
+
<!-- Date & time settings screen title -->
<string name="date_and_time">Date & time</string>
<!-- The title of the activity to pick a time zone. -->
@@ -2671,13 +2676,13 @@
<string name="status_imei_sv">IMEI SV</string>
<!-- Do not translate. About phone, status item title -->
<string name="status_iccid">ICCID</string>
- <!-- About tablet, status item title. The Mobile Directory Number [CHAR LIMIT=30] -->
+ <!-- About tablet, status item title. The Mobile Directory Number [CHAR LIMIT=40] -->
<string name="status_number" product="tablet">MDN</string>
- <!-- About phone, status item title. The phone number of the current device [CHAR LIMIT=30] -->
+ <!-- About phone, status item title. The phone number of the current device [CHAR LIMIT=40] -->
<string name="status_number" product="default">Phone number</string>
- <!-- About tablet, status item title for multi-sim devices. The Mobile Directory Number [CHAR LIMIT=30] -->
+ <!-- About tablet, status item title for multi-sim devices. The Mobile Directory Number [CHAR LIMIT=40] -->
<string name="status_number_sim_slot" product="tablet">MDN (sim slot %1$d)</string>
- <!-- About phone, status item title for multi-sim devices. The phone number of the current device [CHAR LIMIT=30] -->
+ <!-- About phone, status item title for multi-sim devices. The phone number of the current device [CHAR LIMIT=40] -->
<string name="status_number_sim_slot" product="default">Phone number (sim slot %1$d)</string>
<!-- About tablet, status item title. The Mobile Directory Number [CHAR LIMIT=30] -->
<string name="status_number_sim_status" product="tablet">MDN on SIM</string>
@@ -4970,7 +4975,7 @@
<string name="process_dex2oat_label">App optimization</string>
<!-- [CHAR_LIMIT=40] Battery saver: Label for feature, title + menu item -->
- <string name="battery_saver">Battery saver</string>
+ <string name="battery_saver">Battery Saver</string>
<!-- [CHAR_LIMIT=40] Battery saver: Title for automatic entry option -->
<string name="battery_saver_turn_on_automatically_title">Turn on automatically</string>
@@ -6578,7 +6583,7 @@
<string name="keywords_imei_info">imei, meid, min, prl version, imei sv</string>
<string name="keywords_sim_status">network, mobile network state, service state, signal strength, mobile network type, roaming, iccid</string>
<string name="keywords_model_and_hardware">serial number, hardware version</string>
- <string name="keywords_android_version">android security patch level, baseband version, kernel version, </string>
+ <string name="keywords_android_version">android security patch level, baseband version, kernel version</string>
<!-- NFC Wi-Fi pairing/setup strings-->
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index c7f7f48..d24dd51 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -19,4 +19,7 @@
android:key="connected_devices_screen"
android:title="@string/connected_devices_dashboard_title">
+ <PreferenceCategory
+ android:key="connected_device_list"
+ android:title="@string/connected_device_connected_title"/>
</PreferenceScreen>
diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index d74e8c2..5219caa 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -29,32 +29,37 @@
android:summaryOn="@string/date_time_auto_summaryOn"
android:summaryOff="@string/date_time_auto_summaryOff"
settings:useAdditionalSummary="true"
- settings:restrictedSwitchSummary="@string/enabled_by_admin" />
+ settings:restrictedSwitchSummary="@string/enabled_by_admin"
+ settings:userRestriction="no_config_date_time" />
- <Preference
+ <com.android.settingslib.RestrictedPreference
android:key="date"
android:title="@string/date_time_set_date"
- android:summary="@string/summary_placeholder" />
+ android:summary="@string/summary_placeholder"
+ settings:userRestriction="no_config_date_time" />
- <Preference
+ <com.android.settingslib.RestrictedPreference
android:key="time"
android:title="@string/date_time_set_time"
- android:summary="@string/summary_placeholder" />
+ android:summary="@string/summary_placeholder"
+ settings:userRestriction="no_config_date_time" />
</PreferenceCategory>
<PreferenceCategory
android:key="time_zone_preference_category">
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="auto_zone"
android:title="@string/zone_auto"
android:summaryOn="@string/zone_auto_summaryOn"
- android:summaryOff="@string/zone_auto_summaryOff" />
+ android:summaryOff="@string/zone_auto_summaryOff"
+ settings:userRestriction="no_config_date_time" />
- <Preference
+ <com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.datetime.ZonePicker"
android:key="timezone"
android:title="@string/date_time_set_timezone"
- android:summary="GMT-8:00" />
+ android:summary="GMT-8:00"
+ settings:userRestriction="no_config_date_time" />
</PreferenceCategory>
<PreferenceCategory
diff --git a/src/com/android/settings/CredentialStorage.java b/src/com/android/settings/CredentialStorage.java
index e5d40b7..ffbd2ce 100644
--- a/src/com/android/settings/CredentialStorage.java
+++ b/src/com/android/settings/CredentialStorage.java
@@ -275,6 +275,16 @@
Log.e(TAG, "Failed to install " + key + " as uid " + uid);
return;
}
+ // The key was prepended USER_PRIVATE_KEY by the CredentialHelper. However,
+ // KeyChain internally uses the raw alias name and only prepends USER_PRIVATE_KEY
+ // to the key name when interfacing with KeyStore.
+ // This is generally a symptom of CredentialStorage and CredentialHelper relying
+ // on internal implementation details of KeyChain and imitating its functionality
+ // rather than delegating to KeyChain for the certificate installation.
+ if (uid == Process.SYSTEM_UID || uid == KeyStore.UID_SELF) {
+ new MarkKeyAsUserSelectable(
+ key.replaceFirst("^" + Credentials.USER_PRIVATE_KEY, "")).execute();
+ }
}
int flags = KeyStore.FLAG_NONE;
@@ -391,6 +401,33 @@
}
/**
+ * Background task to mark a given key alias as user-selectable, so that
+ * it can be selected by users from the Certificate Selection prompt.
+ */
+ private class MarkKeyAsUserSelectable extends AsyncTask<Void, Void, Boolean> {
+ final String mAlias;
+
+ public MarkKeyAsUserSelectable(String alias) {
+ mAlias = alias;
+ }
+
+ @Override
+ protected Boolean doInBackground(Void... unused) {
+ try (KeyChainConnection keyChainConnection = KeyChain.bind(CredentialStorage.this)) {
+ keyChainConnection.getService().setUserSelectable(mAlias, true);
+ return true;
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to mark key " + mAlias + " as user-selectable.");
+ return false;
+ } catch (InterruptedException e) {
+ Log.w(TAG, "Failed to mark key " + mAlias + " as user-selectable.");
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+ }
+
+ /**
* Check that the caller is either certinstaller or Settings running in a profile of this user.
*/
private boolean checkCallerIsCertInstallerOrSelfInProfile() {
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 60d16ff..193c2b3 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -835,7 +835,8 @@
|| somethingChanged;
final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
- && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
+ && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)
+ && !Utils.isMonkeyRunning();
somethingChanged = setTileEnabled(new ComponentName(packageName,
Settings.DevelopmentSettingsDashboardActivity.class.getName()),
diff --git a/src/com/android/settings/SettingsSliceProvider.java b/src/com/android/settings/SettingsSliceProvider.java
new file mode 100644
index 0000000..845dacd
--- /dev/null
+++ b/src/com/android/settings/SettingsSliceProvider.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings;
+
+import android.app.PendingIntent;
+import android.app.slice.Slice;
+import android.app.slice.SliceProvider;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.Icon;
+import android.net.Uri;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+
+public class SettingsSliceProvider extends SliceProvider {
+ public static final String SLICE_AUTHORITY = "com.android.settings.slices";
+
+ public static final String PATH_WIFI = "wifi";
+ public static final String ACTION_WIFI_CHANGED =
+ "com.android.settings.slice.action.WIFI_CHANGED";
+ // TODO -- Associate slice URI with search result instead of separate hardcoded thing
+ public static final String[] WIFI_SEARCH_TERMS = {"wi-fi", "wifi", "internet"};
+
+ public static Uri getUri(String path) {
+ return new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SLICE_AUTHORITY)
+ .appendPath(path).build();
+ }
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Slice onBindSlice(Uri sliceUri) {
+ String path = sliceUri.getPath();
+ switch (path) {
+ case "/" + PATH_WIFI:
+ return createWifi(sliceUri);
+
+ }
+ throw new IllegalArgumentException("Unrecognized slice uri: " + sliceUri);
+ }
+
+ private Slice createWifi(Uri uri) {
+ // Get wifi state
+ String[] toggleHints;
+ WifiManager wifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+ int wifiState = wifiManager.getWifiState();
+ boolean wifiEnabled = false;
+ String state;
+ switch (wifiState) {
+ case WifiManager.WIFI_STATE_DISABLED:
+ case WifiManager.WIFI_STATE_DISABLING:
+ state = getContext().getString(R.string.disconnected);
+ break;
+ case WifiManager.WIFI_STATE_ENABLED:
+ case WifiManager.WIFI_STATE_ENABLING:
+ state = wifiManager.getConnectionInfo().getSSID();
+ WifiInfo.removeDoubleQuotes(state);
+ wifiEnabled = true;
+ break;
+ case WifiManager.WIFI_STATE_UNKNOWN:
+ default:
+ state = ""; // just don't show anything?
+ break;
+ }
+ if (wifiEnabled) {
+ toggleHints = new String[] {Slice.HINT_TOGGLE, Slice.HINT_SELECTED};
+ } else {
+ toggleHints = new String[] {Slice.HINT_TOGGLE};
+ }
+ // Construct the slice
+ Slice.Builder b = new Slice.Builder(uri);
+ b.addSubSlice(new Slice.Builder(b)
+ .addAction(getIntent("android.settings.WIFI_SETTINGS"),
+ new Slice.Builder(b)
+ .addText(getContext().getString(R.string.wifi_settings), null)
+ .addText(state, null)
+ .addIcon(Icon.createWithResource(getContext(),
+ R.drawable.ic_settings_wireless), null, Slice.HINT_HIDDEN)
+ .addHints(Slice.HINT_TITLE)
+ .build())
+ .addAction(getBroadcastIntent(ACTION_WIFI_CHANGED),
+ new Slice.Builder(b)
+ .addHints(toggleHints)
+ .build())
+ .build());
+ return b.build();
+ }
+
+ private PendingIntent getIntent(String action) {
+ Intent intent = new Intent(action);
+ PendingIntent pi = PendingIntent.getActivity(getContext(), 0, intent, 0);
+ return pi;
+ }
+
+ private PendingIntent getBroadcastIntent(String action) {
+ Intent intent = new Intent(action);
+ intent.setClass(getContext(), SliceBroadcastReceiver.class);
+ return PendingIntent.getBroadcast(getContext(), 0, intent,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ }
+}
diff --git a/src/com/android/settings/SliceBroadcastReceiver.java b/src/com/android/settings/SliceBroadcastReceiver.java
new file mode 100644
index 0000000..f43e3a3
--- /dev/null
+++ b/src/com/android/settings/SliceBroadcastReceiver.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings;
+
+import static com.android.settings.SettingsSliceProvider.ACTION_WIFI_CHANGED;
+
+import android.app.slice.Slice;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
+
+/**
+ * Responds to actions performed on slices and notifies slices of updates in state changes.
+ */
+public class SliceBroadcastReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent i) {
+ String action = i.getAction();
+ switch (action) {
+ case ACTION_WIFI_CHANGED:
+ WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ boolean newState = i.getBooleanExtra(Slice.EXTRA_TOGGLE_STATE, wm.isWifiEnabled());
+ wm.setWifiEnabled(newState);
+ // Wait a bit for wifi to update (TODO: is there a better way to do this?)
+ Handler h = new Handler();
+ h.postDelayed(() -> {
+ Uri uri = SettingsSliceProvider.getUri(SettingsSliceProvider.PATH_WIFI);
+ context.getContentResolver().notifyChange(uri, null);
+ }, 1000);
+ break;
+ }
+ }
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
new file mode 100644
index 0000000..e053bc9
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
@@ -0,0 +1,181 @@
+/*
+ * 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.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.SystemProperties;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.widget.GearPreference;
+import com.android.settingslib.bluetooth.BluetoothCallback;
+import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Update the bluetooth devices. It gets bluetooth event from {@link LocalBluetoothManager} using
+ * {@link BluetoothCallback}. It notifies the upper level whether to add/remove the preference
+ * through {@link DevicePreferenceCallback}
+ *
+ * In {@link BluetoothDeviceUpdater}, it uses {@link BluetoothDeviceFilter.Filter} to detect
+ * whether the {@link CachedBluetoothDevice} is relevant.
+ */
+public abstract class BluetoothDeviceUpdater implements BluetoothCallback {
+ private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY =
+ "persist.bluetooth.showdeviceswithoutnames";
+
+ protected final LocalBluetoothManager mLocalManager;
+ protected final DevicePreferenceCallback mDevicePreferenceCallback;
+ protected final Map<BluetoothDevice, Preference> mPreferenceMap;
+ protected Context mPrefContext;
+
+ private final boolean mShowDeviceWithoutNames;
+ private DashboardFragment mFragment;
+
+ @VisibleForTesting
+ final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
+ final CachedBluetoothDevice device =
+ ((BluetoothDevicePreference) pref).getBluetoothDevice();
+ if (device == null) {
+ return;
+ }
+ final Bundle args = new Bundle();
+ args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS,
+ device.getDevice().getAddress());
+ final SettingsActivity activity = (SettingsActivity) mFragment.getActivity();
+ activity.startPreferencePanel(mFragment,
+ BluetoothDeviceDetailsFragment.class.getName(), args,
+ R.string.device_details_title, null, null, 0);
+
+ };
+
+ public BluetoothDeviceUpdater(DashboardFragment fragment,
+ DevicePreferenceCallback devicePreferenceCallback) {
+ this(fragment, devicePreferenceCallback, Utils.getLocalBtManager(fragment.getContext()));
+ }
+
+ @VisibleForTesting
+ BluetoothDeviceUpdater(DashboardFragment fragment,
+ DevicePreferenceCallback devicePreferenceCallback, LocalBluetoothManager localManager) {
+ mFragment = fragment;
+ mDevicePreferenceCallback = devicePreferenceCallback;
+ mShowDeviceWithoutNames = SystemProperties.getBoolean(
+ BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false);
+ mPreferenceMap = new HashMap<>();
+ mLocalManager = localManager;
+ }
+
+ /**
+ * Register the bluetooth event callback and update the list
+ */
+ public void registerCallback() {
+ mLocalManager.setForegroundActivity(mFragment.getContext());
+ mLocalManager.getEventManager().registerCallback(this);
+ forceUpdate();
+ }
+
+ /**
+ * Unregister the bluetooth event callback
+ */
+ public void unregisterCallback() {
+ mLocalManager.setForegroundActivity(null);
+ mLocalManager.getEventManager().unregisterCallback(this);
+ }
+
+ /**
+ * Force to update the list of bluetooth devices
+ */
+ public void forceUpdate() {
+ Collection<CachedBluetoothDevice> cachedDevices =
+ mLocalManager.getCachedDeviceManager().getCachedDevicesCopy();
+ for (CachedBluetoothDevice cachedBluetoothDevice : cachedDevices) {
+ update(cachedBluetoothDevice);
+ }
+ }
+
+ @Override
+ public void onBluetoothStateChanged(int bluetoothState) {
+ forceUpdate();
+ }
+
+ @Override
+ public void onScanningStateChanged(boolean started) {}
+
+ @Override
+ public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
+ update(cachedDevice);
+ }
+
+ @Override
+ public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {}
+
+ @Override
+ public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
+ update(cachedDevice);
+ }
+
+ @Override
+ public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {}
+
+ /**
+ * Set the context to generate the {@link Preference}, so it could get the correct theme.
+ */
+ public void setPrefContext(Context context) {
+ mPrefContext = context;
+ }
+
+ /**
+ * Update whether to show {@cde cachedBluetoothDevice} in the list.
+ */
+ abstract public void update(CachedBluetoothDevice cachedBluetoothDevice);
+
+ /**
+ * Add the {@link Preference} that represents the {@code cachedDevice}
+ */
+ protected void addPreference(CachedBluetoothDevice cachedDevice) {
+ final BluetoothDevice device = cachedDevice.getDevice();
+ if (!mPreferenceMap.containsKey(device)) {
+ BluetoothDevicePreference btPreference =
+ new BluetoothDevicePreference(mPrefContext, cachedDevice,
+ mShowDeviceWithoutNames);
+ btPreference.setOnGearClickListener(mDeviceProfilesListener);
+ mPreferenceMap.put(device, btPreference);
+ mDevicePreferenceCallback.onDeviceAdded(btPreference);
+ }
+ }
+
+ /**
+ * Remove the {@link Preference} that represents the {@code cachedDevice}
+ */
+ protected void removePreference(CachedBluetoothDevice cachedDevice) {
+ final BluetoothDevice device = cachedDevice.getDevice();
+ if (mPreferenceMap.containsKey(device)) {
+ mDevicePreferenceCallback.onDeviceRemoved(mPreferenceMap.get(device));
+ mPreferenceMap.remove(device);
+ }
+ }
+}
diff --git a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
new file mode 100644
index 0000000..239e405
--- /dev/null
+++ b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
@@ -0,0 +1,66 @@
+/*
+ * 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.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+
+/**
+ * Controller to maintain connected bluetooth devices
+ */
+public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
+
+ public ConnectedBluetoothDeviceUpdater(DashboardFragment fragment,
+ DevicePreferenceCallback devicePreferenceCallback) {
+ super(fragment, devicePreferenceCallback);
+ }
+
+ @VisibleForTesting
+ ConnectedBluetoothDeviceUpdater(DashboardFragment fragment,
+ DevicePreferenceCallback devicePreferenceCallback,
+ LocalBluetoothManager localBluetoothManager) {
+ super(fragment, devicePreferenceCallback, localBluetoothManager);
+ }
+
+ @Override
+ public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
+ if (state == BluetoothAdapter.STATE_CONNECTED) {
+ addPreference(cachedDevice);
+ } else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
+ removePreference(cachedDevice);
+ }
+ }
+
+ @Override
+ public void update(CachedBluetoothDevice cachedDevice) {
+ final BluetoothDevice device = cachedDevice.getDevice();
+ final boolean filterMatch =
+ device.getBondState() == BluetoothDevice.BOND_BONDED && device.isConnected();
+
+ if (filterMatch) {
+ // Add the preference if it is new one
+ addPreference(cachedDevice);
+ } else {
+ removePreference(cachedDevice);
+ }
+ }
+}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 74f6ea2..14acd89 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -17,27 +17,20 @@
import android.app.Activity;
import android.content.Context;
-import android.content.pm.PackageManager;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
-import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
-import com.android.settings.bluetooth.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.deviceinfo.UsbBackend;
import com.android.settings.nfc.NfcPreferenceController;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
public class ConnectedDeviceDashboardFragment extends DashboardFragment {
@@ -66,7 +59,14 @@
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
- return null;
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ final Lifecycle lifecycle = getLifecycle();
+
+ final ConnectedDeviceGroupController connectedDeviceGroupController =
+ new ConnectedDeviceGroupController(this, lifecycle);
+ controllers.add(connectedDeviceGroupController);
+ return controllers;
+
}
@VisibleForTesting
@@ -109,19 +109,26 @@
/**
* For Search.
*/
+ //TODO(b/69333961): update the index for this new fragment
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- return new ArrayList<>();
+ return new ArrayList<>();
}
@Override
public List<String> getNonIndexableKeys(Context context) {
-
return new ArrayList<>();
}
+
+ @Override
+ public List<AbstractPreferenceController> getPreferenceControllers(
+ Context context) {
+ //TODO(b/69333961): update the index for controllers
+ return super.getPreferenceControllers(context);
+ }
};
}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceGroupController.java b/src/com/android/settings/connecteddevice/ConnectedDeviceGroupController.java
new file mode 100644
index 0000000..a0b5cb8
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceGroupController.java
@@ -0,0 +1,109 @@
+/*
+ * 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.connecteddevice;
+
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.bluetooth.BluetoothDeviceUpdater;
+import com.android.settings.bluetooth.ConnectedBluetoothDeviceUpdater;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+/**
+ * Controller to maintain the {@link android.support.v7.preference.PreferenceGroup} for all
+ * connected devices. It uses {@link DevicePreferenceCallback} to add/remove {@link Preference}
+ */
+public class ConnectedDeviceGroupController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
+ DevicePreferenceCallback {
+
+ private static final String KEY = "connected_device_list";
+
+ @VisibleForTesting
+ PreferenceGroup mPreferenceGroup;
+ private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+
+ public ConnectedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle) {
+ super(fragment.getContext());
+ init(lifecycle, new ConnectedBluetoothDeviceUpdater(fragment, this));
+ }
+
+ @VisibleForTesting
+ ConnectedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle,
+ BluetoothDeviceUpdater bluetoothDeviceUpdater) {
+ super(fragment.getContext());
+ init(lifecycle, bluetoothDeviceUpdater);
+ }
+
+ @Override
+ public void onStart() {
+ mBluetoothDeviceUpdater.registerCallback();
+ }
+
+ @Override
+ public void onStop() {
+ mBluetoothDeviceUpdater.unregisterCallback();
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreferenceGroup = (PreferenceGroup) screen.findPreference(KEY);
+ mPreferenceGroup.setVisible(false);
+ mBluetoothDeviceUpdater.setPrefContext(screen.getContext());
+ mBluetoothDeviceUpdater.forceUpdate();
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ public void onDeviceAdded(Preference preference) {
+ if (mPreferenceGroup.getPreferenceCount() == 0) {
+ mPreferenceGroup.setVisible(true);
+ }
+ mPreferenceGroup.addPreference(preference);
+ }
+
+ @Override
+ public void onDeviceRemoved(Preference preference) {
+ mPreferenceGroup.removePreference(preference);
+ if (mPreferenceGroup.getPreferenceCount() == 0) {
+ mPreferenceGroup.setVisible(false);
+ }
+ }
+
+ private void init(Lifecycle lifecycle, BluetoothDeviceUpdater bluetoothDeviceUpdater) {
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
+ }
+}
diff --git a/src/com/android/settings/connecteddevice/DevicePreferenceCallback.java b/src/com/android/settings/connecteddevice/DevicePreferenceCallback.java
new file mode 100644
index 0000000..5f04700
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/DevicePreferenceCallback.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.connecteddevice;
+
+import android.support.v7.preference.Preference;
+
+/**
+ * Callback to add or remove {@link Preference} in device group.
+ */
+public interface DevicePreferenceCallback {
+ /**
+ * Called when a device(i.e. bluetooth, usb) is added
+ * @param preference present the device
+ */
+ void onDeviceAdded(Preference preference);
+
+ /**
+ * Called when a device(i.e. bluetooth, usb) is removed
+ * @param preference present the device
+ */
+ void onDeviceRemoved(Preference preference);
+}
diff --git a/src/com/android/settings/datetime/AutoTimePreferenceController.java b/src/com/android/settings/datetime/AutoTimePreferenceController.java
index 0b70f45..3da712a 100644
--- a/src/com/android/settings/datetime/AutoTimePreferenceController.java
+++ b/src/com/android/settings/datetime/AutoTimePreferenceController.java
@@ -46,8 +46,10 @@
if (!(preference instanceof RestrictedSwitchPreference)) {
return;
}
- ((RestrictedSwitchPreference) preference).setDisabledByAdmin(
- getEnforcedAdminProperty());
+ if (!((RestrictedSwitchPreference) preference).isDisabledByAdmin()) {
+ ((RestrictedSwitchPreference) preference).setDisabledByAdmin(
+ getEnforcedAdminProperty());
+ }
((RestrictedSwitchPreference) preference).setChecked(isEnabled());
}
diff --git a/src/com/android/settings/datetime/DatePreferenceController.java b/src/com/android/settings/datetime/DatePreferenceController.java
index 9582e9e..d2a8686 100644
--- a/src/com/android/settings/datetime/DatePreferenceController.java
+++ b/src/com/android/settings/datetime/DatePreferenceController.java
@@ -27,6 +27,7 @@
import android.widget.DatePicker;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.Calendar;
@@ -59,9 +60,14 @@
@Override
public void updateState(Preference preference) {
+ if (!(preference instanceof RestrictedPreference)) {
+ return;
+ }
final Calendar now = Calendar.getInstance();
preference.setSummary(DateFormat.getLongDateFormat(mContext).format(now.getTime()));
- preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
+ if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
+ preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
+ }
}
@Override
diff --git a/src/com/android/settings/datetime/TimePreferenceController.java b/src/com/android/settings/datetime/TimePreferenceController.java
index 9bb5689..684ad0c 100644
--- a/src/com/android/settings/datetime/TimePreferenceController.java
+++ b/src/com/android/settings/datetime/TimePreferenceController.java
@@ -26,6 +26,7 @@
import android.widget.TimePicker;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.Calendar;
@@ -60,9 +61,14 @@
@Override
public void updateState(Preference preference) {
+ if (!(preference instanceof RestrictedPreference)) {
+ return;
+ }
final Calendar now = Calendar.getInstance();
preference.setSummary(DateFormat.getTimeFormat(mContext).format(now.getTime()));
- preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
+ if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
+ preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
+ }
}
@Override
diff --git a/src/com/android/settings/datetime/TimeZonePreferenceController.java b/src/com/android/settings/datetime/TimeZonePreferenceController.java
index 987132b..435b1fe 100644
--- a/src/com/android/settings/datetime/TimeZonePreferenceController.java
+++ b/src/com/android/settings/datetime/TimeZonePreferenceController.java
@@ -21,6 +21,7 @@
import android.support.v7.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.datetime.ZoneGetter;
@@ -41,8 +42,13 @@
@Override
public void updateState(Preference preference) {
+ if (!(preference instanceof RestrictedPreference)) {
+ return;
+ }
preference.setSummary(getTimeZoneOffsetAndName());
- preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled());
+ if( !((RestrictedPreference) preference).isDisabledByAdmin()) {
+ preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled());
+ }
}
@Override
diff --git a/src/com/android/settings/development/BugReportInPowerPreferenceControllerV2.java b/src/com/android/settings/development/BugReportInPowerPreferenceController.java
similarity index 96%
rename from src/com/android/settings/development/BugReportInPowerPreferenceControllerV2.java
rename to src/com/android/settings/development/BugReportInPowerPreferenceController.java
index 0ab826f..31b618b 100644
--- a/src/com/android/settings/development/BugReportInPowerPreferenceControllerV2.java
+++ b/src/com/android/settings/development/BugReportInPowerPreferenceController.java
@@ -30,7 +30,7 @@
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import com.android.settingslib.wrapper.PackageManagerWrapper;
-public class BugReportInPowerPreferenceControllerV2 extends
+public class BugReportInPowerPreferenceController extends
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin {
@@ -48,7 +48,7 @@
private final UserManager mUserManager;
private SwitchPreference mPreference;
- public BugReportInPowerPreferenceControllerV2(Context context) {
+ public BugReportInPowerPreferenceController(Context context) {
super(context);
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mPackageManager = new PackageManagerWrapper(context.getPackageManager());
diff --git a/src/com/android/settings/development/BugReportPreferenceControllerV2.java b/src/com/android/settings/development/BugReportPreferenceController.java
similarity index 89%
rename from src/com/android/settings/development/BugReportPreferenceControllerV2.java
rename to src/com/android/settings/development/BugReportPreferenceController.java
index 5876f84..ac2ae0d 100644
--- a/src/com/android/settings/development/BugReportPreferenceControllerV2.java
+++ b/src/com/android/settings/development/BugReportPreferenceController.java
@@ -22,14 +22,14 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-public class BugReportPreferenceControllerV2 extends DeveloperOptionsPreferenceController implements
+public class BugReportPreferenceController extends DeveloperOptionsPreferenceController implements
PreferenceControllerMixin {
private static final String KEY_BUGREPORT = "bugreport";
private final UserManager mUserManager;
- public BugReportPreferenceControllerV2(Context context) {
+ public BugReportPreferenceController(Context context) {
super(context);
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
diff --git a/src/com/android/settings/development/CameraLaserSensorPreferenceControllerV2.java b/src/com/android/settings/development/CameraLaserSensorPreferenceController.java
similarity index 96%
rename from src/com/android/settings/development/CameraLaserSensorPreferenceControllerV2.java
rename to src/com/android/settings/development/CameraLaserSensorPreferenceController.java
index 43943ac..41a7983 100644
--- a/src/com/android/settings/development/CameraLaserSensorPreferenceControllerV2.java
+++ b/src/com/android/settings/development/CameraLaserSensorPreferenceController.java
@@ -29,7 +29,7 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-public class CameraLaserSensorPreferenceControllerV2 extends
+public class CameraLaserSensorPreferenceController extends
DeveloperOptionsPreferenceController implements
Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
@@ -51,7 +51,7 @@
private SwitchPreference mPreference;
- public CameraLaserSensorPreferenceControllerV2(Context context) {
+ public CameraLaserSensorPreferenceController(Context context) {
super(context);
}
diff --git a/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2.java b/src/com/android/settings/development/ConnectivityMonitorPreferenceController.java
similarity index 96%
rename from src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2.java
rename to src/com/android/settings/development/ConnectivityMonitorPreferenceController.java
index fdcecfb..075af2b 100644
--- a/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2.java
+++ b/src/com/android/settings/development/ConnectivityMonitorPreferenceController.java
@@ -29,7 +29,7 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-public class ConnectivityMonitorPreferenceControllerV2 extends
+public class ConnectivityMonitorPreferenceController extends
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin {
@@ -55,7 +55,7 @@
private SwitchPreference mPreference;
- public ConnectivityMonitorPreferenceControllerV2(Context context) {
+ public ConnectivityMonitorPreferenceController(Context context) {
super(context);
}
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 72eb30a..237f9ba 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -257,15 +257,15 @@
@Override
public void onDisableLogPersistDialogConfirmed() {
- final LogPersistPreferenceControllerV2 controller = getDevelopmentOptionsController(
- LogPersistPreferenceControllerV2.class);
+ final LogPersistPreferenceController controller = getDevelopmentOptionsController(
+ LogPersistPreferenceController.class);
controller.onDisableLogPersistDialogConfirmed();
}
@Override
public void onDisableLogPersistDialogRejected() {
- final LogPersistPreferenceControllerV2 controller = getDevelopmentOptionsController(
- LogPersistPreferenceControllerV2.class);
+ final LogPersistPreferenceController controller = getDevelopmentOptionsController(
+ LogPersistPreferenceController.class);
controller.onDisableLogPersistDialogRejected();
}
@@ -298,12 +298,15 @@
@Override
protected int getPreferenceScreenResId() {
- Log.d(TAG, "Creating pref screen");
- return R.xml.development_settings;
+ return Utils.isMonkeyRunning()? R.xml.placeholder_prefs : R.xml.development_settings;
}
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ if (Utils.isMonkeyRunning()) {
+ mPreferenceControllers = new ArrayList<>();
+ return null;
+ }
mPreferenceControllers = buildPreferenceControllers(context, getActivity(), getLifecycle(),
this /* devOptionsDashboardFragment */,
new BluetoothA2dpConfigStore());
@@ -326,6 +329,9 @@
}
private void enableDeveloperOptions() {
+ if (Utils.isMonkeyRunning()) {
+ return;
+ }
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
for (AbstractPreferenceController controller : mPreferenceControllers) {
if (controller instanceof DeveloperOptionsPreferenceController) {
@@ -335,6 +341,9 @@
}
private void disableDeveloperOptions() {
+ if (Utils.isMonkeyRunning()) {
+ return;
+ }
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
final SystemPropPoker poker = SystemPropPoker.getInstance();
poker.blockPokes();
@@ -362,7 +371,7 @@
BluetoothA2dpConfigStore bluetoothA2dpConfigStore) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new MemoryUsagePreferenceController(context));
- controllers.add(new BugReportPreferenceControllerV2(context));
+ controllers.add(new BugReportPreferenceController(context));
controllers.add(new LocalBackupPasswordPreferenceController(context));
controllers.add(new StayAwakePreferenceController(context, lifecycle));
controllers.add(new HdcpCheckingPreferenceController(context));
@@ -370,23 +379,23 @@
controllers.add(new OemUnlockPreferenceController(context, activity, fragment));
controllers.add(new FileEncryptionPreferenceController(context));
controllers.add(new PictureColorModePreferenceController(context, lifecycle));
- controllers.add(new WebViewAppPreferenceControllerV2(context));
+ controllers.add(new WebViewAppPreferenceController(context));
controllers.add(new CoolColorTemperaturePreferenceController(context));
controllers.add(new DisableAutomaticUpdatesPreferenceController(context));
controllers.add(new AdbPreferenceController(context, fragment));
controllers.add(new ClearAdbKeysPreferenceController(context, fragment));
controllers.add(new LocalTerminalPreferenceController(context));
- controllers.add(new BugReportInPowerPreferenceControllerV2(context));
+ controllers.add(new BugReportInPowerPreferenceController(context));
controllers.add(new MockLocationAppPreferenceController(context, fragment));
controllers.add(new DebugViewAttributesPreferenceController(context));
controllers.add(new SelectDebugAppPreferenceController(context, fragment));
controllers.add(new WaitForDebuggerPreferenceController(context));
controllers.add(new EnableGpuDebugLayersPreferenceController(context));
- controllers.add(new VerifyAppsOverUsbPreferenceControllerV2(context));
- controllers.add(new LogdSizePreferenceControllerV2(context));
- controllers.add(new LogPersistPreferenceControllerV2(context, fragment, lifecycle));
- controllers.add(new ConnectivityMonitorPreferenceControllerV2(context));
- controllers.add(new CameraLaserSensorPreferenceControllerV2(context));
+ controllers.add(new VerifyAppsOverUsbPreferenceController(context));
+ controllers.add(new LogdSizePreferenceController(context));
+ controllers.add(new LogPersistPreferenceController(context, fragment, lifecycle));
+ controllers.add(new ConnectivityMonitorPreferenceController(context));
+ controllers.add(new CameraLaserSensorPreferenceController(context));
controllers.add(new WifiDisplayCertificationPreferenceController(context));
controllers.add(new WifiVerboseLoggingPreferenceController(context));
controllers.add(new WifiAggressiveHandoverPreferenceController(context));
diff --git a/src/com/android/settings/development/LogPersistPreferenceControllerV2.java b/src/com/android/settings/development/LogPersistPreferenceController.java
similarity index 95%
rename from src/com/android/settings/development/LogPersistPreferenceControllerV2.java
rename to src/com/android/settings/development/LogPersistPreferenceController.java
index 537b71b..a958379 100644
--- a/src/com/android/settings/development/LogPersistPreferenceControllerV2.java
+++ b/src/com/android/settings/development/LogPersistPreferenceController.java
@@ -26,14 +26,14 @@
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.development.AbstractLogpersistPreferenceController;
-public class LogPersistPreferenceControllerV2 extends
+public class LogPersistPreferenceController extends
AbstractLogpersistPreferenceController implements PreferenceControllerMixin {
private final DevelopmentSettingsDashboardFragment mFragment;
private ListPreference mPreference;
- public LogPersistPreferenceControllerV2(Context context,
+ public LogPersistPreferenceController(Context context,
DevelopmentSettingsDashboardFragment fragment, Lifecycle lifecycle) {
super(context, lifecycle);
diff --git a/src/com/android/settings/development/LogdSizePreferenceControllerV2.java b/src/com/android/settings/development/LogdSizePreferenceController.java
similarity index 91%
rename from src/com/android/settings/development/LogdSizePreferenceControllerV2.java
rename to src/com/android/settings/development/LogdSizePreferenceController.java
index 8194c48..6522800 100644
--- a/src/com/android/settings/development/LogdSizePreferenceControllerV2.java
+++ b/src/com/android/settings/development/LogdSizePreferenceController.java
@@ -24,12 +24,12 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.AbstractLogdSizePreferenceController;
-public class LogdSizePreferenceControllerV2 extends AbstractLogdSizePreferenceController implements
+public class LogdSizePreferenceController extends AbstractLogdSizePreferenceController implements
Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
private ListPreference mPreference;
- public LogdSizePreferenceControllerV2(Context context) {
+ public LogdSizePreferenceController(Context context) {
super(context);
}
diff --git a/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerV2.java b/src/com/android/settings/development/VerifyAppsOverUsbPreferenceController.java
similarity index 97%
rename from src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerV2.java
rename to src/com/android/settings/development/VerifyAppsOverUsbPreferenceController.java
index 6e3035e..f01da0d 100644
--- a/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerV2.java
+++ b/src/com/android/settings/development/VerifyAppsOverUsbPreferenceController.java
@@ -38,7 +38,7 @@
/**
* Controller to manage the state of "Verify apps over USB" toggle.
*/
-public class VerifyAppsOverUsbPreferenceControllerV2 extends
+public class VerifyAppsOverUsbPreferenceController extends
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
AdbOnChangeListener, PreferenceControllerMixin {
private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
@@ -70,7 +70,7 @@
// This field is accessed using reflection in the test, please keep name in sync.
private final PackageManagerWrapper mPackageManager;
- public VerifyAppsOverUsbPreferenceControllerV2(Context context) {
+ public VerifyAppsOverUsbPreferenceController(Context context) {
super(context);
mPackageManager = new PackageManagerWrapper(context.getPackageManager());
diff --git a/src/com/android/settings/development/WebViewAppPreferenceControllerV2.java b/src/com/android/settings/development/WebViewAppPreferenceController.java
similarity index 96%
rename from src/com/android/settings/development/WebViewAppPreferenceControllerV2.java
rename to src/com/android/settings/development/WebViewAppPreferenceController.java
index d061281..9ccb20b 100644
--- a/src/com/android/settings/development/WebViewAppPreferenceControllerV2.java
+++ b/src/com/android/settings/development/WebViewAppPreferenceController.java
@@ -31,7 +31,7 @@
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import com.android.settingslib.wrapper.PackageManagerWrapper;
-public class WebViewAppPreferenceControllerV2 extends
+public class WebViewAppPreferenceController extends
DeveloperOptionsPreferenceController implements PreferenceControllerMixin {
private static final String TAG = "WebViewAppPrefCtrl";
@@ -42,7 +42,7 @@
private Preference mPreference;
- public WebViewAppPreferenceControllerV2(Context context) {
+ public WebViewAppPreferenceController(Context context) {
super(context);
mPackageManager = new PackageManagerWrapper(context.getPackageManager());
diff --git a/src/com/android/settings/webview/WebViewAppPreferenceController.java b/src/com/android/settings/webview/WebViewAppPreferenceController.java
index 9410af7..18d874e 100644
--- a/src/com/android/settings/webview/WebViewAppPreferenceController.java
+++ b/src/com/android/settings/webview/WebViewAppPreferenceController.java
@@ -23,7 +23,7 @@
import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
/**
- * Deprecated in favor of {@link com.android.settings.development.WebViewAppPreferenceControllerV2}
+ * Deprecated in favor of {@link com.android.settings.development.WebViewAppPreferenceController}
*/
@Deprecated
public class WebViewAppPreferenceController extends DefaultAppPreferenceController {
diff --git a/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
index 206ba95..17d1021 100644
--- a/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
@@ -30,6 +30,7 @@
import com.android.settings.password.SetupChooseLockPattern;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -44,9 +45,10 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
+ SettingsShadowResourcesImpl.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowEventLogWriter.class,
ShadowUtils.class
@@ -62,7 +64,7 @@
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
- mActivity = Robolectric.buildActivity(
+ mActivity = Robolectric.buildActivity(
SetupChooseLockPattern.class,
SetupChooseLockPattern.modifyIntentForSetup(
application,
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index fb32da1..6616537 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -33,7 +33,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccessibilitySettingsTest {
@Test
diff --git a/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
index 66621a0..2e95c73 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ShortcutServicePickerFragmentTest.java
@@ -41,7 +41,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ShortcutServicePickerFragmentTest {
private static final String TEST_SERVICE_KEY_1 = "abc/123";
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
index 5ef5a12..8d1d174 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
@@ -38,7 +38,7 @@
import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index cfed83b..8924551 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -55,7 +55,7 @@
import static org.robolectric.Shadows.shadowOf;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccountDetailDashboardFragmentTest {
private static final String METADATA_CATEGORY = "com.android.settings.category";
@@ -63,8 +63,6 @@
private static final String METADATA_USER_HANDLE = "user_handle";
@Mock(answer = RETURNS_DEEP_STUBS)
- private Activity mActivity;
- @Mock(answer = RETURNS_DEEP_STUBS)
private AccountManager mAccountManager;
@Mock
private Preference mPreference;
@@ -129,11 +127,11 @@
@Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
- FakeFeatureFactory.setupForTest(mActivity);
+ FakeFeatureFactory.setupForTest(mContext);
final FakeFeatureFactory featureFactory =
- (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
+ (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
final DashboardFeatureProviderImpl dashboardFeatureProvider =
- new DashboardFeatureProviderImpl(mActivity);
+ new DashboardFeatureProviderImpl(mContext);
final PackageManager packageManager = mock(PackageManager.class);
ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
when(packageManager.resolveActivity(any(Intent.class), anyInt()))
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
index 4380e5c..1b20e96 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
@@ -56,7 +56,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
)
public class AccountHeaderPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
index 139bee7..6daaeca 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
@@ -68,7 +68,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public class AccountPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceTest.java
index 0778043..4399580 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceTest.java
@@ -35,7 +35,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccountPreferenceTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
index 5fbd3a7..dde68f5 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountSyncPreferenceControllerTest.java
@@ -47,7 +47,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public class AccountSyncPreferenceControllerTest {
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountTypePreferenceLoaderTest.java b/tests/robotests/src/com/android/settings/accounts/AccountTypePreferenceLoaderTest.java
index fff73b7..2e7f0fa 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountTypePreferenceLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountTypePreferenceLoaderTest.java
@@ -50,7 +50,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccountTypePreferenceLoaderTest {
@Mock(answer = RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/accounts/AddUserWhenLockedPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AddUserWhenLockedPreferenceControllerTest.java
index faaf7db..e00a0ae 100644
--- a/tests/robotests/src/com/android/settings/accounts/AddUserWhenLockedPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AddUserWhenLockedPreferenceControllerTest.java
@@ -41,7 +41,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AddUserWhenLockedPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/accounts/AutoSyncDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AutoSyncDataPreferenceControllerTest.java
index 4715f88..336de21 100644
--- a/tests/robotests/src/com/android/settings/accounts/AutoSyncDataPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AutoSyncDataPreferenceControllerTest.java
@@ -44,14 +44,14 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AutoSyncDataPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock(answer = RETURNS_DEEP_STUBS)
private UserManager mUserManager;
- @Mock(answer = RETURNS_DEEP_STUBS)
+ @Mock
private Fragment mFragment;
private Preference mPreference;
diff --git a/tests/robotests/src/com/android/settings/accounts/AutoSyncPersonalDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AutoSyncPersonalDataPreferenceControllerTest.java
index 597fbd4..50d4df8 100644
--- a/tests/robotests/src/com/android/settings/accounts/AutoSyncPersonalDataPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AutoSyncPersonalDataPreferenceControllerTest.java
@@ -42,7 +42,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AutoSyncPersonalDataPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java
index a25aa28..35a8bb6 100644
--- a/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AutoSyncWorkDataPreferenceControllerTest.java
@@ -42,7 +42,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AutoSyncWorkDataPreferenceControllerTest {
private static int MANAGED_PROFILE_ID = 10;
diff --git a/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java b/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java
index 4e4bb4f..4d1667f 100644
--- a/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/ProviderPreferenceTest.java
@@ -32,7 +32,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ProviderPreferenceTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
index d4e866f..8250340 100644
--- a/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/RemoveAccountPreferenceControllerTest.java
@@ -40,6 +40,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v14.preference.PreferenceFragment;
+import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
import android.widget.Button;
@@ -60,7 +61,7 @@
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RemoveAccountPreferenceControllerTest {
private static final String KEY_REMOVE_ACCOUNT = "remove_account";
@@ -70,9 +71,11 @@
private AccountManager mAccountManager;
@Mock
private DevicePolicyManagerWrapper mDevicePolicyManager;
- @Mock(answer = RETURNS_DEEP_STUBS)
+ @Mock
private PreferenceFragment mFragment;
@Mock
+ private PreferenceManager mPreferenceManager;
+ @Mock
private PreferenceScreen mScreen;
@Mock
private FragmentManager mFragmentManager;
@@ -92,7 +95,8 @@
mContext = spy(shadowContext.getApplicationContext());
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
- when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
+ when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
+ when(mPreferenceManager.getContext()).thenReturn(mContext);
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(
diff --git a/tests/robotests/src/com/android/settings/accounts/RemoveUserFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/RemoveUserFragmentTest.java
index cd73068..ef23d22 100644
--- a/tests/robotests/src/com/android/settings/accounts/RemoveUserFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/RemoveUserFragmentTest.java
@@ -28,7 +28,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RemoveUserFragmentTest {
@Test
diff --git a/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
index 8dba2f2..2383ed1 100644
--- a/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/UserAndAccountDashboardFragmentTest.java
@@ -43,7 +43,7 @@
import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserAndAccountDashboardFragmentTest {
private static final String METADATA_CATEGORY = "com.android.settings.category";
diff --git a/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java
index c59ac18..253d6ea 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/AssistContextPreferenceControllerTest.java
@@ -46,7 +46,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AssistContextPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java
index 1dec8d0..e062291 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/AssistFlashScreenPreferenceControllerTest.java
@@ -51,7 +51,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AssistFlashScreenPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/applications/assist/AssistSettingObserverTest.java b/tests/robotests/src/com/android/settings/applications/assist/AssistSettingObserverTest.java
index f0956c7..431cfba 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/AssistSettingObserverTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/AssistSettingObserverTest.java
@@ -29,7 +29,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AssistSettingObserverTest {
private AssistSettingObserver mObserver;
diff --git a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java
index 65f0b46..1018872 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPickerTest.java
@@ -40,7 +40,7 @@
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DefaultAssistPickerTest {
private static ComponentName sTestAssist;
diff --git a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
index 180abbb..199862f 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
@@ -56,7 +56,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DefaultAssistPreferenceControllerTest {
private static final String TEST_KEY = "test_pref_key";
diff --git a/tests/robotests/src/com/android/settings/applications/assist/ManageAssistTest.java b/tests/robotests/src/com/android/settings/applications/assist/ManageAssistTest.java
index 1b4fb09..6abf09d 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/ManageAssistTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/ManageAssistTest.java
@@ -29,7 +29,7 @@
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ManageAssistTest {
private ManageAssist mSettings;
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
new file mode 100644
index 0000000..525f70e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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 static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.TestConfig;
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class BluetoothDeviceUpdaterTest {
+ @Mock
+ private DashboardFragment mDashboardFragment;
+ @Mock
+ private DevicePreferenceCallback mDevicePreferenceCallback;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDevice;
+ @Mock
+ private BluetoothDevice mBluetoothDevice;
+ @Mock
+ private SettingsActivity mSettingsActivity;
+
+ private Context mContext;
+ private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+ private BluetoothDevicePreference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ doReturn(mContext).when(mDashboardFragment).getContext();
+ doReturn(mBluetoothDevice).when(mCachedBluetoothDevice).getDevice();
+
+ mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
+ mBluetoothDeviceUpdater = new BluetoothDeviceUpdater(mDashboardFragment,
+ mDevicePreferenceCallback, null) {
+ @Override
+ public void update(CachedBluetoothDevice cachedBluetoothDevice) {
+ // do nothing
+ }
+ };
+ mBluetoothDeviceUpdater.setPrefContext(mContext);
+ }
+
+ @Test
+ public void testAddPreference_deviceExist_doNothing() {
+ mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, mPreference);
+
+ mBluetoothDeviceUpdater.addPreference(mCachedBluetoothDevice);
+
+ verify(mDevicePreferenceCallback, never()).onDeviceAdded(any(Preference.class));
+ }
+
+ @Test
+ public void testAddPreference_deviceNotExist_addPreference() {
+ mBluetoothDeviceUpdater.addPreference(mCachedBluetoothDevice);
+
+ verify(mDevicePreferenceCallback).onDeviceAdded(any(Preference.class));
+ assertThat(mBluetoothDeviceUpdater.mPreferenceMap.containsKey(mBluetoothDevice)).isTrue();
+ }
+
+ @Test
+ public void testRemovePreference_deviceExist_removePreference() {
+ mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, mPreference);
+
+ mBluetoothDeviceUpdater.removePreference(mCachedBluetoothDevice);
+
+ verify(mDevicePreferenceCallback).onDeviceRemoved(mPreference);
+ assertThat(mBluetoothDeviceUpdater.mPreferenceMap.containsKey(mBluetoothDevice)).isFalse();
+ }
+
+ @Test
+ public void testRemovePreference_deviceNotExist_doNothing() {
+ mBluetoothDeviceUpdater.removePreference(mCachedBluetoothDevice);
+
+ verify(mDevicePreferenceCallback, never()).onDeviceRemoved(any(Preference.class));
+ }
+
+ @Test
+ public void testDeviceProfilesListener_click_startBluetoothDeviceDetailPage() {
+ doReturn(mSettingsActivity).when(mDashboardFragment).getActivity();
+
+ mBluetoothDeviceUpdater.mDeviceProfilesListener.onGearClick(mPreference);
+
+ verify(mSettingsActivity).startPreferencePanel(eq(mDashboardFragment),
+ eq(BluetoothDeviceDetailsFragment.class.getName()), any(),
+ eq(R.string.device_details_title), eq(null), eq(null), eq(0));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
new file mode 100644
index 0000000..c86664c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.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.bluetooth;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+
+import com.android.settings.TestConfig;
+import com.android.settings.connecteddevice.DevicePreferenceCallback;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class ConnectedBluetoothDeviceUpdaterTest {
+ @Mock
+ private DashboardFragment mDashboardFragment;
+ @Mock
+ private DevicePreferenceCallback mDevicePreferenceCallback;
+ @Mock
+ private CachedBluetoothDevice mCachedBluetoothDevice;
+ @Mock
+ private BluetoothDevice mBluetoothDevice;
+
+ private Context mContext;
+ private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ doReturn(mContext).when(mDashboardFragment).getContext();
+ doReturn(mBluetoothDevice).when(mCachedBluetoothDevice).getDevice();
+
+ mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mDashboardFragment,
+ mDevicePreferenceCallback, null));
+ mBluetoothDeviceUpdater.setPrefContext(mContext);
+ doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
+ doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
+ }
+
+ @Test
+ public void testUpdate_filterMatch_addPreference() {
+ doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
+ doReturn(true).when(mBluetoothDevice).isConnected();
+
+ mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+ verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
+ }
+
+ @Test
+ public void testUpdate_filterNotMatch_removePreference() {
+ doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState();
+ doReturn(false).when(mBluetoothDevice).isConnected();
+
+ mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+ verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
+ }
+
+ @Test
+ public void testOnConnectionStateChanged_deviceConnected_addPreference() {
+ mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothAdapter.STATE_CONNECTED);
+
+ verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
+ }
+
+ @Test
+ public void testOnConnectionStateChanged_deviceDisconnected_removePreference() {
+ mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothAdapter.STATE_DISCONNECTED);
+
+ verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceGroupControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceGroupControllerTest.java
new file mode 100644
index 0000000..e18115a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceGroupControllerTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.settings.connecteddevice;
+
+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.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.bluetooth.ConnectedBluetoothDeviceUpdater;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class ConnectedDeviceGroupControllerTest {
+ @Mock
+ private DashboardFragment mDashboardFragment;
+ @Mock
+ private ConnectedBluetoothDeviceUpdater mConnectedBluetoothDeviceUpdater;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+ @Mock
+ private PreferenceManager mPreferenceManager;
+
+ private PreferenceGroup mPreferenceGroup;
+ private Context mContext;
+ private Preference mPreference;
+ private ConnectedDeviceGroupController mConnectedDeviceGroupController;
+ private Lifecycle mLifecycle;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mPreference = new Preference(mContext);
+ mLifecycle = new Lifecycle(() -> mLifecycle);
+ mPreferenceGroup = spy(new PreferenceScreen(mContext, null));
+ doReturn(mPreferenceManager).when(mPreferenceGroup).getPreferenceManager();
+ doReturn(mContext).when(mDashboardFragment).getContext();
+
+ mConnectedDeviceGroupController = new ConnectedDeviceGroupController(mDashboardFragment,
+ mLifecycle, mConnectedBluetoothDeviceUpdater);
+ mConnectedDeviceGroupController.mPreferenceGroup = mPreferenceGroup;
+ }
+
+ @Test
+ public void testOnDeviceAdded_firstAdd_becomeVisible() {
+ mConnectedDeviceGroupController.onDeviceAdded(mPreference);
+
+ assertThat(mPreferenceGroup.isVisible()).isTrue();
+ }
+
+ @Test
+ public void testOnDeviceRemoved_lastRemove_becomeInvisible() {
+ mPreferenceGroup.addPreference(mPreference);
+
+ mConnectedDeviceGroupController.onDeviceRemoved(mPreference);
+
+ assertThat(mPreferenceGroup.isVisible()).isFalse();
+ }
+
+ @Test
+ public void testOnDeviceRemoved_notLastRemove_stillVisible() {
+ mPreferenceGroup.setVisible(true);
+ mPreferenceGroup.addPreference(mPreference);
+ mPreferenceGroup.addPreference(new Preference(mContext));
+
+ mConnectedDeviceGroupController.onDeviceRemoved(mPreference);
+
+ assertThat(mPreferenceGroup.isVisible()).isTrue();
+ }
+
+ @Test
+ public void testDisplayPreference_becomeInvisible() {
+ doReturn(mPreferenceGroup).when(mPreferenceScreen).findPreference(anyString());
+
+ mConnectedDeviceGroupController.displayPreference(mPreferenceScreen);
+
+ assertThat(mPreferenceGroup.isVisible()).isFalse();
+ }
+
+ @Test
+ public void testLifecycle() {
+ // register the callback in onStart()
+ mLifecycle.handleLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_START);
+ verify(mConnectedBluetoothDeviceUpdater).registerCallback();
+
+ // unregister the callback in onStop()
+ mLifecycle.handleLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_STOP);
+ verify(mConnectedBluetoothDeviceUpdater).unregisterCallback();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java
index e6a6dd8..f1d34f8 100644
--- a/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java
@@ -22,6 +22,7 @@
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settingslib.RestrictedPreference;
import org.junit.Before;
import org.junit.Test;
@@ -48,14 +49,15 @@
@Mock
private AutoTimePreferenceController mAutoTimePreferenceController;
- private Preference mPreference;
+ private RestrictedPreference mPreference;
private DatePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(mAlarmManager);
- mPreference = new Preference(ShadowApplication.getInstance().getApplicationContext());
+ mPreference = new RestrictedPreference(ShadowApplication.getInstance().
+ getApplicationContext());
mController = new DatePreferenceController(mContext, mHost, mAutoTimePreferenceController);
}
@@ -72,6 +74,9 @@
@Test
public void updateState_autoTimeEnabled_shouldDisablePref() {
+ // Make sure not disabled by admin.
+ mPreference.setDisabledByAdmin(null);
+
when(mAutoTimePreferenceController.isEnabled()).thenReturn(true);
mController.updateState(mPreference);
@@ -80,6 +85,9 @@
@Test
public void updateState_autoTimeDisabled_shouldEnablePref() {
+ // Make sure not disabled by admin.
+ mPreference.setDisabledByAdmin(null);
+
when(mAutoTimePreferenceController.isEnabled()).thenReturn(false);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java
index 15877e0..89c5f47 100644
--- a/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java
@@ -17,10 +17,11 @@
package com.android.settings.datetime;
import android.content.Context;
-import android.support.v7.preference.Preference;
+import android.os.UserManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settingslib.RestrictedPreference;
import org.junit.Before;
import org.junit.Test;
@@ -31,6 +32,7 @@
import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -46,12 +48,13 @@
private AutoTimePreferenceController mAutoTimePreferenceController;
private TimePreferenceController mController;
- private Preference mPreference;
+ private RestrictedPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mPreference = new Preference(ShadowApplication.getInstance().getApplicationContext());
+ mPreference = new RestrictedPreference(
+ ShadowApplication.getInstance().getApplicationContext());
mController = new TimePreferenceController(mContext, mHost, mAutoTimePreferenceController);
}
@@ -62,6 +65,9 @@
@Test
public void updateState_autoTimeEnabled_shouldDisablePref() {
+ // Make sure not disabled by admin.
+ mPreference.setDisabledByAdmin(null);
+
when(mAutoTimePreferenceController.isEnabled()).thenReturn(true);
mController.updateState(mPreference);
@@ -70,6 +76,9 @@
@Test
public void updateState_autoTimeDisabled_shouldEnablePref() {
+ // Make sure not disabled by admin.
+ mPreference.setDisabledByAdmin(null);
+
when(mAutoTimePreferenceController.isEnabled()).thenReturn(false);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java
index 2f96d65..ec26448 100644
--- a/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java
@@ -21,6 +21,7 @@
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settingslib.RestrictedPreference;
import org.junit.Before;
import org.junit.Test;
@@ -41,15 +42,16 @@
@Mock
private AutoTimeZonePreferenceController mAutoTimeZonePreferenceController;
+
private Context mContext;
private TimeZonePreferenceController mController;
- private Preference mPreference;
+ private RestrictedPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = ShadowApplication.getInstance().getApplicationContext();
- mPreference = new Preference(mContext);
+ mPreference = new RestrictedPreference(mContext);
mController = spy(new TimeZonePreferenceController(mContext,
mAutoTimeZonePreferenceController));
}
@@ -61,6 +63,9 @@
@Test
public void updateState_autoTimeZoneEnabled_shouldDisablePref() {
+ // Make sure not disabled by admin.
+ mPreference.setDisabledByAdmin(null);
+
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(true);
mController.updateState(mPreference);
@@ -70,6 +75,9 @@
@Test
public void updateState_autoTimeZoneDisabled_shouldEnablePref() {
+ // Make sure not disabled by admin.
+ mPreference.setDisabledByAdmin(null);
+
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(false);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java
similarity index 91%
rename from tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java
index 6fa1400..82086dd 100644
--- a/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java
@@ -16,12 +16,11 @@
package com.android.settings.development;
-import static com.android.settings.development
- .BugReportInPowerPreferenceControllerV2.COMPONENT_NAME;
-import static com.android.settings.development
- .BugReportInPowerPreferenceControllerV2.SETTING_VALUE_OFF;
-import static com.android.settings.development
- .BugReportInPowerPreferenceControllerV2.SETTING_VALUE_ON;
+import static com.android.settings.development.BugReportInPowerPreferenceController.COMPONENT_NAME;
+import static com.android.settings.development.BugReportInPowerPreferenceController
+ .SETTING_VALUE_OFF;
+import static com.android.settings.development.BugReportInPowerPreferenceController
+ .SETTING_VALUE_ON;
import static com.google.common.truth.Truth.assertThat;
@@ -53,7 +52,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class BugReportInPowerPreferenceControllerV2Test {
+public class BugReportInPowerPreferenceControllerTest {
@Mock
private PreferenceScreen mScreen;
@@ -67,7 +66,7 @@
private SwitchPreference mPreference;
private ContentResolver mContentResolver;
- private BugReportInPowerPreferenceControllerV2 mController;
+ private BugReportInPowerPreferenceController mController;
@Before
public void setUp() {
@@ -75,7 +74,7 @@
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mContext.getContentResolver()).thenReturn(mContentResolver);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mController = new BugReportInPowerPreferenceControllerV2(mContext);
+ mController = new BugReportInPowerPreferenceController(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
}
diff --git a/tests/robotests/src/com/android/settings/development/BugReportPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/BugReportPreferenceControllerTest.java
similarity index 91%
rename from tests/robotests/src/com/android/settings/development/BugReportPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/BugReportPreferenceControllerTest.java
index 9b4cde6..908c519 100644
--- a/tests/robotests/src/com/android/settings/development/BugReportPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/BugReportPreferenceControllerTest.java
@@ -36,20 +36,20 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class BugReportPreferenceControllerV2Test {
+public class BugReportPreferenceControllerTest {
@Mock
private Context mContext;
@Mock
private UserManager mUserManager;
- private BugReportPreferenceControllerV2 mController;
+ private BugReportPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mController = new BugReportPreferenceControllerV2(mContext);
+ mController = new BugReportPreferenceController(mContext);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
similarity index 75%
rename from tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
index 87967b9..1443d16 100644
--- a/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
@@ -16,18 +16,16 @@
package com.android.settings.development;
-import static com.android.settings.development.CameraLaserSensorPreferenceControllerV2.ENG_BUILD;
-import static com.android.settings.development
- .CameraLaserSensorPreferenceControllerV2.USERDEBUG_BUILD;
-import static com.android.settings.development.CameraLaserSensorPreferenceControllerV2.USER_BUILD;
+import static com.android.settings.development.CameraLaserSensorPreferenceController.ENG_BUILD;
+import static com.android.settings.development.CameraLaserSensorPreferenceController
+ .USERDEBUG_BUILD;
+import static com.android.settings.development.CameraLaserSensorPreferenceController.USER_BUILD;
import android.content.Context;
-import android.content.res.Resources;
import android.os.SystemProperties;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.PreferenceScreen;
-import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
@@ -36,7 +34,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@@ -50,7 +47,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {SettingsShadowSystemProperties.class})
-public class CameraLaserSensorPreferenceControllerV2Test {
+public class CameraLaserSensorPreferenceControllerTest {
@Mock
private PreferenceScreen mScreen;
@@ -59,13 +56,13 @@
private Context mContext;
- private CameraLaserSensorPreferenceControllerV2 mController;
+ private CameraLaserSensorPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mController = new CameraLaserSensorPreferenceControllerV2(mContext);
+ mController = new CameraLaserSensorPreferenceController(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
mController.displayPreference(mScreen);
@@ -85,7 +82,7 @@
@Test
public void isAvailable_withUserdebugBuild_shouldReturnTrue() {
SettingsShadowSystemProperties.set(
- CameraLaserSensorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
assertThat(mController.isAvailable()).isTrue();
}
@@ -93,7 +90,7 @@
@Test
public void isAvailable_withEngBuild_shouldReturnTrue() {
SettingsShadowSystemProperties.set(
- CameraLaserSensorPreferenceControllerV2.BUILD_TYPE, ENG_BUILD);
+ CameraLaserSensorPreferenceController.BUILD_TYPE, ENG_BUILD);
assertThat(mController.isAvailable()).isTrue();
}
@@ -101,7 +98,7 @@
@Test
public void isAvailable_withUserBuild_shouldReturnFalse() {
SettingsShadowSystemProperties.set(
- CameraLaserSensorPreferenceControllerV2.BUILD_TYPE, USER_BUILD);
+ CameraLaserSensorPreferenceController.BUILD_TYPE, USER_BUILD);
assertThat(mController.isAvailable()).isFalse();
}
@@ -109,10 +106,10 @@
@Test
public void updateState_cameraLaserSensorEnabled_shouldCheckedPreference() {
SettingsShadowSystemProperties.set(
- CameraLaserSensorPreferenceControllerV2.PROPERTY_CAMERA_LASER_SENSOR,
- Integer.toString(CameraLaserSensorPreferenceControllerV2.ENABLED));
+ CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
+ Integer.toString(CameraLaserSensorPreferenceController.ENABLED));
SettingsShadowSystemProperties.set(
- CameraLaserSensorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mScreen);
@@ -122,10 +119,10 @@
@Test
public void updateState_cameraLaserSensorEnabled_shouldUncheckedPreference() {
SettingsShadowSystemProperties.set(
- CameraLaserSensorPreferenceControllerV2.PROPERTY_CAMERA_LASER_SENSOR,
- Integer.toString(CameraLaserSensorPreferenceControllerV2.DISABLED));
+ CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
+ Integer.toString(CameraLaserSensorPreferenceController.DISABLED));
SettingsShadowSystemProperties.set(
- CameraLaserSensorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ CameraLaserSensorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mScreen);
@@ -136,20 +133,20 @@
public void onPreferenceChange_preferenceChecked_shouldEnableCameraLaserSensor() {
mController.onPreferenceChange(mPreference, true);
- assertThat(Integer.toString(CameraLaserSensorPreferenceControllerV2.ENABLED)).isEqualTo(
+ assertThat(Integer.toString(CameraLaserSensorPreferenceController.ENABLED)).isEqualTo(
SystemProperties.get(
- CameraLaserSensorPreferenceControllerV2.PROPERTY_CAMERA_LASER_SENSOR,
- Integer.toString(CameraLaserSensorPreferenceControllerV2.ENABLED)));
+ CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
+ Integer.toString(CameraLaserSensorPreferenceController.ENABLED)));
}
@Test
public void onPreferenceChange__preferenceUnchecked_shouldDisableCameraLaserSensor() {
mController.onPreferenceChange(mPreference, false);
- assertThat(Integer.toString(CameraLaserSensorPreferenceControllerV2.DISABLED)).isEqualTo(
+ assertThat(Integer.toString(CameraLaserSensorPreferenceController.DISABLED)).isEqualTo(
SystemProperties.get(
- CameraLaserSensorPreferenceControllerV2.PROPERTY_CAMERA_LASER_SENSOR,
- Integer.toString(CameraLaserSensorPreferenceControllerV2.ENABLED)));
+ CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
+ Integer.toString(CameraLaserSensorPreferenceController.ENABLED)));
}
@Test
@@ -165,9 +162,9 @@
verify(mPreference).setEnabled(false);
verify(mPreference).setChecked(false);
- assertThat(Integer.toString(CameraLaserSensorPreferenceControllerV2.DISABLED)).isEqualTo(
+ assertThat(Integer.toString(CameraLaserSensorPreferenceController.DISABLED)).isEqualTo(
SystemProperties.get(
- CameraLaserSensorPreferenceControllerV2.PROPERTY_CAMERA_LASER_SENSOR,
- Integer.toString(CameraLaserSensorPreferenceControllerV2.ENABLED)));
+ CameraLaserSensorPreferenceController.PROPERTY_CAMERA_LASER_SENSOR,
+ Integer.toString(CameraLaserSensorPreferenceController.ENABLED)));
}
}
diff --git a/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerTest.java
similarity index 66%
rename from tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerTest.java
index 5b4f594..5e99ec9 100644
--- a/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/ConnectivityMonitorPreferenceControllerTest.java
@@ -16,9 +16,9 @@
package com.android.settings.development;
-import static com.android.settings.development.ConnectivityMonitorPreferenceControllerV2.ENG_BUILD;
-import static com.android.settings.development
- .ConnectivityMonitorPreferenceControllerV2.USERDEBUG_BUILD;
+import static com.android.settings.development.ConnectivityMonitorPreferenceController.ENG_BUILD;
+import static com.android.settings.development.ConnectivityMonitorPreferenceController
+ .USERDEBUG_BUILD;
import static com.google.common.truth.Truth.assertThat;
@@ -45,7 +45,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows =
SettingsShadowSystemProperties.class)
-public class ConnectivityMonitorPreferenceControllerV2Test {
+public class ConnectivityMonitorPreferenceControllerTest {
private static final String USER_BUILD = "user";
@@ -55,14 +55,14 @@
private SwitchPreference mPreference;
private Context mContext;
- private ConnectivityMonitorPreferenceControllerV2 mController;
+ private ConnectivityMonitorPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SettingsShadowSystemProperties.clear();
mContext = RuntimeEnvironment.application;
- mController = new ConnectivityMonitorPreferenceControllerV2(mContext);
+ mController = new ConnectivityMonitorPreferenceController(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
@@ -70,7 +70,7 @@
@Test
public void isAvailable_trueShowFlagWithUserdebugBuild_shouldReturnTrue() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
assertThat(mController.isAvailable()).isTrue();
}
@@ -78,7 +78,7 @@
@Test
public void isAvailable_trueShowFlagWithEngBuild_shouldReturnTrue() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, ENG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, ENG_BUILD);
assertThat(mController.isAvailable()).isTrue();
}
@@ -86,7 +86,7 @@
@Test
public void isAvailable_trueShowFlagWithUserBuild_shouldReturnFalse() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USER_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USER_BUILD);
assertThat(mController.isAvailable()).isFalse();
}
@@ -95,7 +95,7 @@
@Config(qualifiers = "mcc999")
public void isAvailable_falseShowFlagWithUserdebugBuild_shouldReturnFalse() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
assertThat(mController.isAvailable()).isFalse();
}
@@ -104,7 +104,7 @@
@Config(qualifiers = "mcc999")
public void isAvailable_falseShowFlagWithEngBuild_shouldReturnFalse() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, ENG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, ENG_BUILD);
assertThat(mController.isAvailable()).isFalse();
}
@@ -113,7 +113,7 @@
@Config(qualifiers = "mcc999")
public void isAvailable_falseShowFlagWithUserBuild_shouldReturnFalse() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USER_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USER_BUILD);
assertThat(mController.isAvailable()).isFalse();
}
@@ -121,10 +121,10 @@
@Test
public void updateState_connectivityMonitorEnabled_shouldCheckedPreference() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.ENABLED_STATUS);
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.ENABLED_STATUS);
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mPreference);
@@ -134,10 +134,10 @@
@Test
public void updateState_connectivityMonitorUserEnabled_shouldCheckedPreference() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.USER_ENABLED_STATUS);
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.USER_ENABLED_STATUS);
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mPreference);
@@ -147,10 +147,10 @@
@Test
public void updateState_connectivityMonitorDisabled_shouldUncheckedPreference() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.DISABLED_STATUS);
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.DISABLED_STATUS);
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mPreference);
@@ -160,10 +160,10 @@
@Test
public void updateState_connectivityMonitorUserDisabled_shouldUncheckedPreference() {
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS);
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS);
SettingsShadowSystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
+ ConnectivityMonitorPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mPreference);
@@ -173,29 +173,29 @@
@Test
public void onPreferenceChange_preferenceChecked_shouldEnableConnectivityMonitor() {
SystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.USER_ENABLED_STATUS);
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.USER_ENABLED_STATUS);
mController.handlePreferenceTreeClick(mPreference);
- assertThat(ConnectivityMonitorPreferenceControllerV2.USER_ENABLED_STATUS).isEqualTo(
+ assertThat(ConnectivityMonitorPreferenceController.USER_ENABLED_STATUS).isEqualTo(
SystemProperties.get(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.DISABLED_STATUS));
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.DISABLED_STATUS));
}
@Test
public void onPreferenceChange_preferenceUnchecked_shouldDisableConnectivityMonitor() {
SystemProperties.set(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS);
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS);
mController.handlePreferenceTreeClick(mPreference);
- assertThat(ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS).isEqualTo(
+ assertThat(ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS).isEqualTo(
SystemProperties.get(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
- ConnectivityMonitorPreferenceControllerV2.DISABLED_STATUS));
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.DISABLED_STATUS));
}
@Test
@@ -210,10 +210,10 @@
mController.onDeveloperOptionsSwitchDisabled();
String mode = SystemProperties.get(
- ConnectivityMonitorPreferenceControllerV2.PROPERTY_CONNECTIVITY_MONITOR,
+ ConnectivityMonitorPreferenceController.PROPERTY_CONNECTIVITY_MONITOR,
null /* default */);
- assertThat(mode).isEqualTo(ConnectivityMonitorPreferenceControllerV2.USER_DISABLED_STATUS);
+ assertThat(mode).isEqualTo(ConnectivityMonitorPreferenceController.USER_DISABLED_STATUS);
verify(mPreference).setEnabled(false);
verify(mPreference).setChecked(false);
}
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
index 5449353..881ee84 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
@@ -223,10 +223,10 @@
@Test
public void onDisableLogPersistDialogConfirmed_shouldCallControllerDialogConfirmed() {
- final LogPersistPreferenceControllerV2 controller = mock(
- LogPersistPreferenceControllerV2.class);
+ final LogPersistPreferenceController controller = mock(
+ LogPersistPreferenceController.class);
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
- LogPersistPreferenceControllerV2.class);
+ LogPersistPreferenceController.class);
mDashboard.onDisableLogPersistDialogConfirmed();
verify(controller).onDisableLogPersistDialogConfirmed();
@@ -234,10 +234,10 @@
@Test
public void onDisableLogPersistDialogRejected_shouldCallControllerDialogRejected() {
- final LogPersistPreferenceControllerV2 controller = mock(
- LogPersistPreferenceControllerV2.class);
+ final LogPersistPreferenceController controller = mock(
+ LogPersistPreferenceController.class);
doReturn(controller).when(mDashboard).getDevelopmentOptionsController(
- LogPersistPreferenceControllerV2.class);
+ LogPersistPreferenceController.class);
mDashboard.onDisableLogPersistDialogRejected();
verify(controller).onDisableLogPersistDialogRejected();
diff --git a/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerTest.java
similarity index 92%
rename from tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerTest.java
index ddc0da5..1dc1255 100644
--- a/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/LogPersistPreferenceControllerTest.java
@@ -42,7 +42,7 @@
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {SettingsShadowSystemProperties.class})
-public class LogPersistPreferenceControllerV2Test {
+public class LogPersistPreferenceControllerTest {
@Mock
private ListPreference mPreference;
@@ -52,7 +52,7 @@
private DevelopmentSettingsDashboardFragment mFragment;
private Context mContext;
- private LogPersistPreferenceControllerV2 mController;
+ private LogPersistPreferenceController mController;
private Lifecycle mLifecycle;
@Before
@@ -60,7 +60,7 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mLifecycle = new Lifecycle(() -> mLifecycle);
- mController = new LogPersistPreferenceControllerV2(mContext, mFragment, mLifecycle);
+ mController = new LogPersistPreferenceController(mContext, mFragment, mLifecycle);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
SystemProperties.set("ro.debuggable", "1");
mController.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerTest.java
similarity index 94%
rename from tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerTest.java
index 71766c3..f7be653 100644
--- a/tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/LogdSizePreferenceControllerTest.java
@@ -41,7 +41,7 @@
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {SettingsShadowSystemProperties.class})
-public class LogdSizePreferenceControllerV2Test {
+public class LogdSizePreferenceControllerTest {
@Mock
private PreferenceScreen mScreen;
@@ -61,7 +61,7 @@
private String[] mListValues;
private String[] mListSummaries;
private Context mContext;
- private LogdSizePreferenceControllerV2 mController;
+ private LogdSizePreferenceController mController;
@Before
public void setup() {
@@ -69,7 +69,7 @@
mContext = RuntimeEnvironment.application;
mListValues = mContext.getResources().getStringArray(R.array.select_logd_size_values);
mListSummaries = mContext.getResources().getStringArray(R.array.select_logd_size_summaries);
- mController = new LogdSizePreferenceControllerV2(mContext);
+ mController = new LogdSizePreferenceController(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
diff --git a/tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerTest.java
similarity index 95%
rename from tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerTest.java
index 9e60295..e396ebe 100644
--- a/tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerTest.java
@@ -52,7 +52,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class VerifyAppsOverUsbPreferenceControllerV2Test {
+public class VerifyAppsOverUsbPreferenceControllerTest {
@Mock
private PackageManagerWrapper mPackageManager;
@@ -62,11 +62,11 @@
private RestrictedSwitchPreference mPreference;
@Mock
- private VerifyAppsOverUsbPreferenceControllerV2.RestrictedLockUtilsDelegate
+ private VerifyAppsOverUsbPreferenceController.RestrictedLockUtilsDelegate
mRestrictedLockUtilsDelegate;
private Context mContext;
- private VerifyAppsOverUsbPreferenceControllerV2 mController;
+ private VerifyAppsOverUsbPreferenceController mController;
/** Convenience class for setting global int settings. */
class GlobalSetter {
@@ -83,7 +83,7 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
- mController = new VerifyAppsOverUsbPreferenceControllerV2(mContext);
+ mController = new VerifyAppsOverUsbPreferenceController(mContext);
ReflectionHelpers.setField(
mController, "mRestrictedLockUtils", mRestrictedLockUtilsDelegate);
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
@@ -188,7 +188,7 @@
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, -1 /* default */);
- assertThat(mode).isEqualTo(VerifyAppsOverUsbPreferenceControllerV2.SETTING_VALUE_ON);
+ assertThat(mode).isEqualTo(VerifyAppsOverUsbPreferenceController.SETTING_VALUE_ON);
}
@Test
@@ -198,7 +198,7 @@
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, -1 /* default */);
- assertThat(mode).isEqualTo(VerifyAppsOverUsbPreferenceControllerV2.SETTING_VALUE_OFF);
+ assertThat(mode).isEqualTo(VerifyAppsOverUsbPreferenceController.SETTING_VALUE_OFF);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/WebViewAppPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/WebViewAppPreferenceControllerTest.java
similarity index 94%
rename from tests/robotests/src/com/android/settings/development/WebViewAppPreferenceControllerV2Test.java
rename to tests/robotests/src/com/android/settings/development/WebViewAppPreferenceControllerTest.java
index 4f9540f..59f6e35 100644
--- a/tests/robotests/src/com/android/settings/development/WebViewAppPreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/development/WebViewAppPreferenceControllerTest.java
@@ -43,7 +43,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class WebViewAppPreferenceControllerV2Test {
+public class WebViewAppPreferenceControllerTest {
@Mock
private PreferenceScreen mPreferenceScreen;
@@ -57,13 +57,13 @@
private DefaultAppInfo mAppInfo;
private Context mContext;
- private WebViewAppPreferenceControllerV2 mController;
+ private WebViewAppPreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mController = spy(new WebViewAppPreferenceControllerV2(mContext));
+ mController = spy(new WebViewAppPreferenceController(mContext));
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
ReflectionHelpers.setField(mController, "mWebViewUpdateServiceWrapper",
mWebViewUpdateServiceWrapper);
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
index 183f5ad..b0cd484 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
@@ -101,6 +101,13 @@
return directlyOn(realResources, Resources.class).getColorStateList(id, theme);
}
+ /**
+ * Deprecated because SDK 24+ uses
+ * {@link SettingsShadowResourcesImpl#loadDrawable(Resources, TypedValue, int, int, Theme)}
+ *
+ * TODO: Delete when all tests have been migrated to sdk 26
+ */
+ @Deprecated
@Implementation
public Drawable loadDrawable(TypedValue value, int id, Theme theme)
throws NotFoundException {
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResourcesImpl.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResourcesImpl.java
new file mode 100644
index 0000000..42b02f3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResourcesImpl.java
@@ -0,0 +1,57 @@
+/*
+ * 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.testutils.shadow;
+
+import android.content.res.Resources;
+import android.content.res.ResourcesImpl;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.util.TypedValue;
+
+import com.android.settings.R;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.shadows.ShadowResourcesImpl;
+
+@Implements(
+ value = ResourcesImpl.class,
+ isInAndroidSdk = false,
+ minSdk = 26
+)
+public class SettingsShadowResourcesImpl extends ShadowResourcesImpl {
+
+ @Implementation
+ public Drawable loadDrawable(Resources wrapper, TypedValue value, int id, int density,
+ Resources.Theme theme) {
+ // The drawable item in switchbar_background.xml refers to a very recent color attribute
+ // that Robolectric isn't yet aware of.
+ // TODO: Remove this once Robolectric is updated.
+ if (id == R.drawable.switchbar_background) {
+ return new ColorDrawable();
+ } else if (id == R.drawable.ic_launcher_settings) {
+ // ic_launcher_settings uses adaptive-icon, which is not supported by robolectric,
+ // change it to a normal drawable.
+ id = R.drawable.ic_settings_wireless;
+ } else if (id == R.drawable.app_filter_spinner_background) {
+ id = R.drawable.ic_expand_more_inverse;
+ } else if (id == R.drawable.selectable_card_grey) {
+ id = R.drawable.ic_expand_more_inverse;
+ }
+ return super.loadDrawable(wrapper, value, id, density, theme);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPreferenceControllerTest.java
index 08ecc9b..9404e53 100644
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/webview/WebViewAppPreferenceControllerTest.java
@@ -31,7 +31,7 @@
import org.robolectric.annotation.Config;
/**
- * Deprecated in favor of {@link com.android.settings.development.WebViewAppPreferenceControllerV2}
+ * Deprecated in favor of {@link com.android.settings.development.WebViewAppPreferenceController}
*/
@Deprecated
@RunWith(SettingsRobolectricTestRunner.class)
diff --git a/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java b/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
index 0f3eb31..f69012e 100644
--- a/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/ActionBarShadowControllerTest.java
@@ -45,7 +45,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ActionBarShadowControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/widget/ActionButtonPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/ActionButtonPreferenceTest.java
index a080bc6..a215967 100644
--- a/tests/robotests/src/com/android/settings/widget/ActionButtonPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/ActionButtonPreferenceTest.java
@@ -40,7 +40,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ActionButtonPreferenceTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/AppPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/AppPreferenceTest.java
index d489094..6481f8a 100644
--- a/tests/robotests/src/com/android/settings/widget/AppPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/AppPreferenceTest.java
@@ -33,7 +33,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AppPreferenceTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/AppSwitchPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/AppSwitchPreferenceTest.java
index a7c8d7c..81537a8 100644
--- a/tests/robotests/src/com/android/settings/widget/AppSwitchPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/AppSwitchPreferenceTest.java
@@ -33,7 +33,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AppSwitchPreferenceTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/AspectRatioFrameLayoutTest.java b/tests/robotests/src/com/android/settings/widget/AspectRatioFrameLayoutTest.java
index dd6138c..4a19258 100644
--- a/tests/robotests/src/com/android/settings/widget/AspectRatioFrameLayoutTest.java
+++ b/tests/robotests/src/com/android/settings/widget/AspectRatioFrameLayoutTest.java
@@ -32,7 +32,7 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AspectRatioFrameLayoutTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/DefaultIndicatorSeekBarTest.java b/tests/robotests/src/com/android/settings/widget/DefaultIndicatorSeekBarTest.java
index 7fcf328..47a9aa6 100644
--- a/tests/robotests/src/com/android/settings/widget/DefaultIndicatorSeekBarTest.java
+++ b/tests/robotests/src/com/android/settings/widget/DefaultIndicatorSeekBarTest.java
@@ -29,7 +29,7 @@
import static junit.framework.Assert.assertEquals;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DefaultIndicatorSeekBarTest {
private DefaultIndicatorSeekBar mDefaultIndicatorSeekBar;
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index 9c6ee45..af30e4f 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -58,7 +58,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class EntityHeaderControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
diff --git a/tests/robotests/src/com/android/settings/widget/FixedLineSummaryPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/FixedLineSummaryPreferenceTest.java
index 0d9a77b..5022ceb 100644
--- a/tests/robotests/src/com/android/settings/widget/FixedLineSummaryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/FixedLineSummaryPreferenceTest.java
@@ -38,7 +38,7 @@
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class FixedLineSummaryPreferenceTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/widget/LoadingViewControllerTest.java b/tests/robotests/src/com/android/settings/widget/LoadingViewControllerTest.java
index 09b52c8..6ab2b17 100644
--- a/tests/robotests/src/com/android/settings/widget/LoadingViewControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/LoadingViewControllerTest.java
@@ -37,7 +37,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class LoadingViewControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java
index 1c449cc..c80c7b4 100644
--- a/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/MasterSwitchPreferenceTest.java
@@ -40,7 +40,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class MasterSwitchPreferenceTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/PreferenceCategoryControllerTest.java b/tests/robotests/src/com/android/settings/widget/PreferenceCategoryControllerTest.java
index 23aa378..d8661bf 100644
--- a/tests/robotests/src/com/android/settings/widget/PreferenceCategoryControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/PreferenceCategoryControllerTest.java
@@ -36,7 +36,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PreferenceCategoryControllerTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java b/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
index 8ca68ae..9fc5b2e 100644
--- a/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
@@ -45,7 +45,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RadioButtonPickerFragmentTest {
diff --git a/tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java b/tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java
index a1a2f24..0226c22 100644
--- a/tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java
+++ b/tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java
@@ -31,7 +31,7 @@
import static junit.framework.Assert.assertEquals;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RingProgressBarTest {
private Context mContext = RuntimeEnvironment.application;
diff --git a/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java b/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
index 78afc43..1072152 100644
--- a/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
@@ -36,7 +36,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
+ sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowTextUtils.class}
)
public class RtlCompatibleViewPagerTest {
diff --git a/tests/robotests/src/com/android/settings/widget/ScrollToParentEditTextTest.java b/tests/robotests/src/com/android/settings/widget/ScrollToParentEditTextTest.java
index 5755015..8e91259 100644
--- a/tests/robotests/src/com/android/settings/widget/ScrollToParentEditTextTest.java
+++ b/tests/robotests/src/com/android/settings/widget/ScrollToParentEditTextTest.java
@@ -41,7 +41,7 @@
import org.robolectric.shadows.ShadowView;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ScrollToParentEditTextTest {
private static final int EDIT_TEXT_SIZE = 20;
diff --git a/tests/robotests/src/com/android/settings/widget/SummaryUpdaterTest.java b/tests/robotests/src/com/android/settings/widget/SummaryUpdaterTest.java
index 2f42550..8dbe552 100644
--- a/tests/robotests/src/com/android/settings/widget/SummaryUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/widget/SummaryUpdaterTest.java
@@ -34,7 +34,7 @@
import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SummaryUpdaterTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java
index 59be160..ff2332c 100644
--- a/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java
@@ -42,7 +42,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ValidatedEditTextPreferenceTest {
@Mock
diff --git a/tests/unit/src/com/android/settings/core/UserRestrictionTest.java b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
new file mode 100644
index 0000000..ad00bd7
--- /dev/null
+++ b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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.core;
+
+import static junit.framework.Assert.fail;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.os.UserManager;
+import android.platform.test.annotations.Presubmit;
+import android.provider.SearchIndexableResource;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.util.Xml;
+
+import com.android.settings.search.DatabaseIndexingUtils;
+import com.android.settings.search.Indexable;
+import com.android.settings.search.SearchIndexableResources;
+
+import com.google.android.collect.Sets;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+@RunWith(AndroidJUnit4.class)
+@MediumTest
+public class UserRestrictionTest {
+
+ private static final String TAG = "UserRestrictionTest";
+
+ private Context mContext;
+
+ private static final Set<String> USER_RESTRICTIONS = Sets.newHashSet(
+ UserManager.DISALLOW_CONFIG_DATE_TIME,
+ UserManager.DISALLOW_CONFIG_CREDENTIALS,
+ UserManager.DISALLOW_NETWORK_RESET,
+ UserManager.DISALLOW_FACTORY_RESET,
+ UserManager.DISALLOW_CONFIG_TETHERING,
+ UserManager.DISALLOW_CONFIG_VPN,
+ UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS
+ );
+
+ @Before
+ public void setUp() {
+ mContext = InstrumentationRegistry.getTargetContext();
+ }
+
+ /**
+ * Verity that userRestriction attributes are entered and parsed successfully.
+ */
+ @Test
+ public void userRestrictionAttributeShouldBeValid()
+ throws IOException, XmlPullParserException, Resources.NotFoundException {
+ for (Class<?> clazz : SearchIndexableResources.providerValues()) {
+ verifyUserRestriction(clazz);
+ }
+ }
+
+ private void verifyUserRestriction(Class<?> clazz)
+ throws IOException, XmlPullParserException, Resources.NotFoundException {
+ if (clazz == null) {
+ return;
+ }
+ final String className = clazz.getName();
+ final Indexable.SearchIndexProvider provider =
+ DatabaseIndexingUtils.getSearchIndexProvider(clazz);
+ final List<SearchIndexableResource> resourcesToIndex =
+ provider.getXmlResourcesToIndex(mContext, true);
+
+ if (resourcesToIndex == null) {
+ Log.d(TAG, className + "is not providing SearchIndexableResource, skipping");
+ return;
+ }
+
+ for (SearchIndexableResource sir : resourcesToIndex) {
+ if (sir.xmlResId <= 0) {
+ Log.d(TAG, className + " doesn't have a valid xml to index.");
+ continue;
+ }
+ final XmlResourceParser parser = mContext.getResources().getXml(sir.xmlResId);
+
+ int type;
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && type != XmlPullParser.START_TAG) {
+ // Parse next until start tag is found
+ }
+ final int outerDepth = parser.getDepth();
+
+ do {
+ if (type != XmlPullParser.START_TAG) {
+ continue;
+ }
+ final String nodeName = parser.getName();
+ if (!nodeName.endsWith("Preference")) {
+ continue;
+ }
+ final AttributeSet attrs = Xml.asAttributeSet(parser);
+ final String userRestriction = getDataUserRestrictions(mContext, attrs);
+ if (userRestriction != null) {
+ if(!isValidRestriction(userRestriction)) {
+ fail("userRestriction in " + className + " not valid.");
+ }
+ }
+ } while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
+ }
+ }
+
+ boolean isValidRestriction(String userRestriction) {
+ return USER_RESTRICTIONS.contains(userRestriction);
+ }
+
+ private String getDataUserRestrictions(Context context, AttributeSet attrs) {
+ return getData(context, attrs,
+ com.android.settingslib.R.styleable.RestrictedPreference,
+ com.android.settingslib.R.styleable.RestrictedPreference_userRestriction);
+ }
+
+ private String getData(Context context, AttributeSet set, int[] attrs, int resId) {
+ final TypedArray ta = context.obtainStyledAttributes(set, attrs);
+ String data = ta.getString(resId);
+ ta.recycle();
+ return data;
+ }
+}