diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 0ccbbf44aa0..e326dbe3caf 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -313,7 +313,8 @@ - 1 (Default) + Use System Default: %1$d + 1 2 3 4 @@ -321,7 +322,8 @@ - + + 1 2 3 diff --git a/res/values/strings.xml b/res/values/strings.xml index e7c7bba0c09..38a1f6f6e78 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3371,6 +3371,8 @@ App-level permissions Recent location requests + + See all No apps have requested location recently diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml index 84b80b8d419..9fc29c3e83f 100644 --- a/res/xml/app_and_notification.xml +++ b/res/xml/app_and_notification.xml @@ -55,7 +55,8 @@ android:key="manage_perms" android:title="@string/app_permissions" android:order="12" - settings:keywords="@string/keywords_app_permissions"> + settings:keywords="@string/keywords_app_permissions" + settings:controller="com.android.settings.applications.AppPermissionsPreferenceController"> @@ -76,4 +77,4 @@ android:title="@string/special_access" android:order="20" /> - \ No newline at end of file + diff --git a/res/xml/location_recent_requests_see_all.xml b/res/xml/location_recent_requests_see_all.xml new file mode 100644 index 00000000000..38db1426995 --- /dev/null +++ b/res/xml/location_recent_requests_see_all.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index 43affe66457..3f96c58d98d 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -24,6 +24,13 @@ android:key="recent_location_requests" android:title="@string/location_category_recent_location_requests"/> + + permissions = getAllPermissionsInGroups(); Set grantedPermissionGroups = getGrantedPermissionGroups(permissions); CharSequence summary = null; @@ -96,7 +81,7 @@ public class AppPermissionsPreferenceController extends AbstractPreferenceContro private Set getGrantedPermissionGroups(Set permissions) { ArraySet grantedPermissionGroups = new ArraySet<>(); List installedPackages = - mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS); + mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS); for (PackageInfo installedPackage : installedPackages) { if (installedPackage.permissions == null) { continue; @@ -134,12 +119,12 @@ public class AppPermissionsPreferenceController extends AbstractPreferenceContro for (String group : PERMISSION_GROUPS) { try { final List permissions = - mPackageManager.queryPermissionsByGroup(group, 0); + mPackageManager.queryPermissionsByGroup(group, 0); for (PermissionInfo permissionInfo : permissions) { result.add(permissionInfo.name); } } catch (NameNotFoundException e) { - Log.e(TAG, "Error getting permissions in group "+group, e); + Log.e(TAG, "Error getting permissions in group " + group, e); } } return result; diff --git a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java index 7d3f946a4a9..cf1731d31ac 100644 --- a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java +++ b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java @@ -50,14 +50,9 @@ public abstract class DefaultAppShortcutPreferenceControllerBase extends BasePre } @Override - public void updateState(Preference preference) { - preference.setSummary(getSummary()); - } - - @Override - public String getSummary() { + public CharSequence getSummary() { int summaryResId = isDefaultApp() ? R.string.yes : R.string.no; - return mContext.getString(summaryResId); + return mContext.getText(summaryResId); } @Override diff --git a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java index 02f52b60e31..ca63575f363 100644 --- a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java +++ b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java @@ -21,7 +21,6 @@ import static android.Manifest.permission.SYSTEM_ALERT_WINDOW; import android.content.Context; import android.content.pm.PackageInfo; import android.os.UserManager; -import android.support.v7.preference.Preference; import com.android.settings.SettingsPreferenceFragment; @@ -50,18 +49,13 @@ public class DrawOverlayDetailPreferenceController extends AppInfoPreferenceCont return DISABLED_FOR_USER; } - @Override - public void updateState(Preference preference) { - preference.setSummary(getSummary()); - } - @Override protected Class getDetailFragmentClass() { return DrawOverlayDetails.class; } @Override - public String getSummary() { - return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry()).toString(); + public CharSequence getSummary() { + return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry()); } } diff --git a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java index 73e76755206..71532eaa4a8 100644 --- a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java +++ b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java @@ -21,7 +21,6 @@ import static android.Manifest.permission.WRITE_SETTINGS; import android.content.Context; import android.content.pm.PackageInfo; import android.os.UserManager; -import android.support.v7.preference.Preference; import com.android.settings.SettingsPreferenceFragment; @@ -51,19 +50,14 @@ public class WriteSystemSettingsPreferenceController extends AppInfoPreferenceCo return DISABLED_FOR_USER; } - @Override - public void updateState(Preference preference) { - preference.setSummary(getSummary()); - } - @Override protected Class getDetailFragmentClass() { return WriteSettingsDetails.class; } @Override - public String getSummary() { - return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()).toString(); + public CharSequence getSummary() { + return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()); } } diff --git a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java index dccc3101569..183d13f0033 100644 --- a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java +++ b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java @@ -19,7 +19,6 @@ package com.android.settings.backup; import android.app.backup.BackupManager; import android.content.Context; import android.os.UserManager; -import android.support.v7.preference.Preference; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; @@ -46,16 +45,11 @@ public class BackupSettingsActivityPreferenceController extends BasePreferenceCo } @Override - public void updateState(Preference preference) { - preference.setSummary(getSummary()); - } - - @Override - public String getSummary() { + public CharSequence getSummary() { final boolean backupEnabled = mBackupManager.isBackupEnabled(); return backupEnabled - ? mContext.getString(R.string.accessibility_feature_state_on) - : mContext.getString(R.string.accessibility_feature_state_off); + ? mContext.getText(R.string.accessibility_feature_state_on) + : mContext.getText(R.string.accessibility_feature_state_off); } } \ No newline at end of file diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java index bf13e07b068..f2f220a3268 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java @@ -113,7 +113,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr } @Override - public String getSummary() { + public CharSequence getSummary() { String deviceName = getDeviceName(); if (TextUtils.isEmpty(deviceName)) { return super.getSummary(); diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java index cea0147cecf..262d6b3bf09 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java @@ -72,7 +72,7 @@ public class BluetoothDeviceRenamePreferenceController extends } @Override - public String getSummary() { + public CharSequence getSummary() { return getDeviceName(); } diff --git a/src/com/android/settings/core/PreferenceControllerListHelper.java b/src/com/android/settings/core/PreferenceControllerListHelper.java index d955301d175..bec7c094ea2 100644 --- a/src/com/android/settings/core/PreferenceControllerListHelper.java +++ b/src/com/android/settings/core/PreferenceControllerListHelper.java @@ -41,7 +41,7 @@ import java.util.TreeSet; */ public class PreferenceControllerListHelper { - private static final String TAG = "PrefCtrlListCreator"; + private static final String TAG = "PrefCtrlListHelper"; /** * Instantiates a list of controller based on xml definition. diff --git a/src/com/android/settings/core/SubSettingLauncher.java b/src/com/android/settings/core/SubSettingLauncher.java index 1ffe7f53e6e..91bd4525d7c 100644 --- a/src/com/android/settings/core/SubSettingLauncher.java +++ b/src/com/android/settings/core/SubSettingLauncher.java @@ -164,7 +164,7 @@ public class SubSettingLauncher { } private void launchForResult(Fragment listener, Intent intent, int requestCode) { - listener.getActivity().startActivityForResult(intent, requestCode); + listener.startActivityForResult(intent, requestCode); } /** diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java index 468bd3d31df..51e151ebeff 100644 --- a/src/com/android/settings/core/gateway/SettingsGateway.java +++ b/src/com/android/settings/core/gateway/SettingsGateway.java @@ -28,6 +28,7 @@ import com.android.settings.Settings; import com.android.settings.TestingSettings; import com.android.settings.TetherSettings; import com.android.settings.TrustedCredentialsSettings; +import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment; import com.android.settings.wifi.calling.WifiCallingSettings; import com.android.settings.accessibility.AccessibilitySettings; import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard; @@ -154,6 +155,7 @@ public class SettingsGateway { UserDictionarySettings.class.getName(), DisplaySettings.class.getName(), DeviceInfoSettings.class.getName(), + MyDeviceInfoFragment.class.getName(), ManageApplications.class.getName(), ManageAssist.class.getName(), ProcessStatsUi.class.getName(), diff --git a/src/com/android/settings/dashboard/conditional/BackgroundDataCondition.java b/src/com/android/settings/dashboard/conditional/BackgroundDataCondition.java index cbac86f2393..34172c277ec 100644 --- a/src/com/android/settings/dashboard/conditional/BackgroundDataCondition.java +++ b/src/com/android/settings/dashboard/conditional/BackgroundDataCondition.java @@ -18,9 +18,12 @@ package com.android.settings.dashboard.conditional; import android.content.Intent; import android.graphics.drawable.Icon; import android.net.NetworkPolicyManager; +import android.util.FeatureFlagUtils; + import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.Settings; +import com.android.settings.core.FeatureFlags; public class BackgroundDataCondition extends Condition { @@ -55,8 +58,12 @@ public class BackgroundDataCondition extends Condition { @Override public void onPrimaryClick() { - mManager.getContext().startActivity(new Intent(mManager.getContext(), - Settings.DataUsageSummaryActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + final Class activityClass = FeatureFlagUtils.isEnabled(mManager.getContext(), + FeatureFlags.DATA_USAGE_SETTINGS_V2) + ? Settings.DataUsageSummaryActivity.class + : Settings.DataUsageSummaryLegacyActivity.class; + mManager.getContext().startActivity(new Intent(mManager.getContext(), activityClass) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } @Override diff --git a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java index 5512685a138..79187f52470 100644 --- a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java +++ b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java @@ -22,9 +22,7 @@ import android.support.annotation.VisibleForTesting; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; -import android.text.TextUtils; -import com.android.settings.R; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; @@ -32,58 +30,65 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { - private static final String BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_KEY = + private static final String MAX_CONNECTED_AUDIO_DEVICES_PREFERENCE_KEY = "bluetooth_max_connected_audio_devices"; @VisibleForTesting - static final String BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY = + static final String MAX_CONNECTED_AUDIO_DEVICES_PROPERTY = "persist.bluetooth.maxconnectedaudiodevices"; - private final String[] mListValues; - private final String[] mListSummaries; + private final int mDefaultMaxConnectedAudioDevices; private ListPreference mPreference; public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) { super(context); - - mListValues = context.getResources() - .getStringArray(R.array.bluetooth_max_connected_audio_devices_values); - mListSummaries = context.getResources() - .getStringArray(R.array.bluetooth_max_connected_audio_devices); + mDefaultMaxConnectedAudioDevices = mContext.getResources().getInteger( + com.android.internal.R.integer.config_bluetooth_max_connected_audio_devices); } @Override public String getPreferenceKey() { - return BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_KEY; + return MAX_CONNECTED_AUDIO_DEVICES_PREFERENCE_KEY; } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); - mPreference = (ListPreference) screen.findPreference(getPreferenceKey()); + final CharSequence[] entries = mPreference.getEntries(); + entries[0] = String.format(entries[0].toString(), mDefaultMaxConnectedAudioDevices); + mPreference.setEntries(entries); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString()); + String newValueString = newValue.toString(); + final ListPreference listPreference = (ListPreference) preference; + if (listPreference.findIndexOfValue(newValueString) <= 0) { + // Reset property value when default is chosen or when value is illegal + newValueString = ""; + } + SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValueString); updateState(preference); return true; } @Override public void updateState(Preference preference) { - final String currentValue = SystemProperties.get( - BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY); - int index = 0; // Defaults to 1 device - for (int i = 0; i < mListValues.length; i++) { - if (TextUtils.equals(currentValue, mListValues[i])) { - index = i; - break; + final ListPreference listPreference = (ListPreference) preference; + final CharSequence[] entries = listPreference.getEntries(); + final String currentValue = SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY); + int index = 0; + if (!currentValue.isEmpty()) { + index = listPreference.findIndexOfValue(currentValue); + if (index < 0) { + // Reset property value when value is illegal + SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, ""); + index = 0; } } - mPreference.setValue(mListValues[index]); - mPreference.setSummary(mListSummaries[index]); + listPreference.setValueIndex(index); + listPreference.setSummary(entries[index]); } @Override @@ -95,9 +100,8 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends @Override protected void onDeveloperOptionsSwitchDisabled() { mPreference.setEnabled(false); - SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, mListValues[0]); - mPreference.setValue(mListValues[0]); - mPreference.setSummary(mListSummaries[0]); + SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, ""); + updateState(mPreference); } } diff --git a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java index 0f1dea15369..6d0302fed18 100644 --- a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java +++ b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java @@ -67,7 +67,7 @@ public class DeviceNamePreferenceController extends BasePreferenceController } @Override - public String getSummary() { + public CharSequence getSummary() { return mDeviceName; } diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java index 05fe326fb15..8a2d5e360e5 100644 --- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java +++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java @@ -62,7 +62,7 @@ import java.util.Arrays; import java.util.List; public class MyDeviceInfoFragment extends DashboardFragment { - private static final String LOG_TAG = "MeCardFragment"; + private static final String LOG_TAG = "MyDeviceInfoFragment"; private static final String KEY_MY_DEVICE_INFO_HEADER = "my_device_info_header"; private static final String KEY_LEGAL_CONTAINER = "legal_container"; diff --git a/src/com/android/settings/display/ColorModePreferenceController.java b/src/com/android/settings/display/ColorModePreferenceController.java index 2ab2ec9e564..7fa978209d7 100644 --- a/src/com/android/settings/display/ColorModePreferenceController.java +++ b/src/com/android/settings/display/ColorModePreferenceController.java @@ -21,31 +21,47 @@ import android.os.ServiceManager; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; -import com.android.settings.core.PreferenceControllerMixin; -import com.android.settingslib.core.AbstractPreferenceController; +import com.android.internal.app.ColorDisplayController; +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; -public class ColorModePreferenceController extends AbstractPreferenceController implements - PreferenceControllerMixin { +public class ColorModePreferenceController extends BasePreferenceController { private static final String TAG = "ColorModePreference"; private static final String KEY_COLOR_MODE = "color_mode"; private static final int SURFACE_FLINGER_TRANSACTION_QUERY_WIDE_COLOR = 1024; private final ConfigurationWrapper mConfigWrapper; + private ColorDisplayController mColorDisplayController; public ColorModePreferenceController(Context context) { - super(context); + super(context, KEY_COLOR_MODE); mConfigWrapper = new ConfigurationWrapper(); } @Override - public String getPreferenceKey() { - return KEY_COLOR_MODE; + public int getAvailabilityStatus() { + return mConfigWrapper.isScreenWideColorGamut() ? AVAILABLE : DISABLED_FOR_USER; } @Override - public boolean isAvailable() { - return mConfigWrapper.isScreenWideColorGamut(); + public CharSequence getSummary() { + final int colorMode = getColorDisplayController().getColorMode(); + if (colorMode == ColorDisplayController.COLOR_MODE_SATURATED) { + return mContext.getText(R.string.color_mode_option_saturated); + } + if (colorMode == ColorDisplayController.COLOR_MODE_BOOSTED) { + return mContext.getText(R.string.color_mode_option_boosted); + } + return mContext.getText(R.string.color_mode_option_natural); + } + + @VisibleForTesting + ColorDisplayController getColorDisplayController() { + if (mColorDisplayController == null) { + mColorDisplayController = new ColorDisplayController(mContext); + } + return mColorDisplayController; } @VisibleForTesting diff --git a/src/com/android/settings/fuelgauge/BatterySaverController.java b/src/com/android/settings/fuelgauge/BatterySaverController.java index 83efefd84f9..f139f31c10b 100644 --- a/src/com/android/settings/fuelgauge/BatterySaverController.java +++ b/src/com/android/settings/fuelgauge/BatterySaverController.java @@ -103,7 +103,7 @@ public class BatterySaverController extends TogglePreferenceController } @Override - public String getSummary() { + public CharSequence getSummary() { final boolean mode = mPowerManager.isPowerSaveMode(); final int format = mode ? R.string.battery_saver_on_summary : R.string.battery_saver_off_summary; diff --git a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java index 8b2fcc084a7..1df5b900b53 100644 --- a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java +++ b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java @@ -19,7 +19,6 @@ package com.android.settings.gestures; import android.content.ContentResolver; import android.content.Context; import android.provider.Settings; -import android.support.v7.preference.Preference; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; @@ -56,12 +55,7 @@ public class GesturesSettingPreferenceController extends BasePreferenceControlle } @Override - public void updateState(Preference preference) { - preference.setSummary(getSummary()); - } - - @Override - public String getSummary() { + public CharSequence getSummary() { if (!mFeatureProvider.isSensorAvailable(mContext)) { return ""; } @@ -72,13 +66,13 @@ public class GesturesSettingPreferenceController extends BasePreferenceControlle contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; if (mFeatureProvider.isSupported(mContext) && assistGestureEnabled) { - return mContext.getString( + return mContext.getText( R.string.language_input_gesture_summary_on_with_assist); } if (assistGestureSilenceEnabled) { - return mContext.getString( + return mContext.getText( R.string.language_input_gesture_summary_on_non_assist); } - return mContext.getString(R.string.language_input_gesture_summary_off); + return mContext.getText(R.string.language_input_gesture_summary_off); } } \ No newline at end of file diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index 153403a31aa..a6feacc5c23 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -70,8 +70,10 @@ public class LocationSettings extends DashboardFragment { public int getInitialExpandedChildCount() { final RecentLocationApps recentLocationApps = new RecentLocationApps(getActivity()); final int locationRequestsApps = recentLocationApps.getAppList().size(); - final int locationRequestsPrefs = locationRequestsApps == 0 ? 1 : locationRequestsApps; - return locationRequestsPrefs + 2; + final int locationRequestsPrefs = + locationRequestsApps == 0 + ? 1 : (locationRequestsApps > 3 ? 4 : locationRequestsApps); + return locationRequestsPrefs + 1; } @Override diff --git a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java index 8238a9b4bc6..b017ec1f3ce 100644 --- a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java +++ b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java @@ -20,32 +20,33 @@ import android.support.annotation.VisibleForTesting; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceScreen; - import com.android.settings.R; import com.android.settings.applications.appinfo.AppInfoDashboardFragment; import com.android.settings.core.SubSettingLauncher; +import com.android.settings.dashboard.DashboardFragment; import com.android.settings.widget.AppPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.location.RecentLocationApps; - -import java.util.ArrayList; import java.util.List; public class RecentLocationRequestPreferenceController extends LocationBasePreferenceController { /** Key for preference category "Recent location requests" */ private static final String KEY_RECENT_LOCATION_REQUESTS = "recent_location_requests"; + @VisibleForTesting + static final String KEY_SEE_ALL = "recent_location_requests_see_all"; private final LocationSettings mFragment; private final RecentLocationApps mRecentLocationApps; private PreferenceCategory mCategoryRecentLocationRequests; + private Preference mSeeAllButton; - @VisibleForTesting + /** Used in this class and {@link RecentLocationRequestSeeAllPreferenceController}*/ static class PackageEntryClickedListener implements Preference.OnPreferenceClickListener { - private final LocationSettings mFragment; + private final DashboardFragment mFragment; private final String mPackage; private final UserHandle mUserHandle; - public PackageEntryClickedListener(LocationSettings fragment, String packageName, + public PackageEntryClickedListener(DashboardFragment fragment, String packageName, UserHandle userHandle) { mFragment = fragment; mPackage = packageName; @@ -92,24 +93,32 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe super.displayPreference(screen); mCategoryRecentLocationRequests = (PreferenceCategory) screen.findPreference(KEY_RECENT_LOCATION_REQUESTS); + mSeeAllButton = screen.findPreference(KEY_SEE_ALL); + } @Override public void updateState(Preference preference) { mCategoryRecentLocationRequests.removeAll(); + mSeeAllButton.setVisible(false); final Context prefContext = preference.getContext(); final List recentLocationRequests = mRecentLocationApps.getAppListSorted(); - final List recentLocationPrefs = new ArrayList<>(recentLocationRequests.size()); - for (final RecentLocationApps.Request request : recentLocationRequests) { - recentLocationPrefs.add(createAppPreference(prefContext, request)); - } - if (recentLocationRequests.size() > 0) { + if (recentLocationRequests.size() > 3) { + // Display the top 3 preferences to container in original order. + for (int i = 0; i < 3; i ++) { + mCategoryRecentLocationRequests.addPreference( + createAppPreference(prefContext, recentLocationRequests.get(i))); + } + // Display a button to list all requests + mSeeAllButton.setVisible(true); + } else if (recentLocationRequests.size() > 0) { // Add preferences to container in original order (already sorted by recency). - for (Preference entry : recentLocationPrefs) { - mCategoryRecentLocationRequests.addPreference(entry); + for (RecentLocationApps.Request request : recentLocationRequests) { + mCategoryRecentLocationRequests.addPreference( + createAppPreference(prefContext, request)); } } else { // If there's no item to display, add a "No recent apps" item. @@ -132,7 +141,7 @@ public class RecentLocationRequestPreferenceController extends LocationBasePrefe @VisibleForTesting AppPreference createAppPreference(Context prefContext, RecentLocationApps.Request request) { - final AppPreference pref = createAppPreference(prefContext); + final AppPreference pref = createAppPreference(prefContext); pref.setSummary(request.contentDescription); pref.setIcon(request.icon); pref.setTitle(request.label); diff --git a/src/com/android/settings/location/RecentLocationRequestSeeAllFragment.java b/src/com/android/settings/location/RecentLocationRequestSeeAllFragment.java new file mode 100644 index 00000000000..0b7614c22be --- /dev/null +++ b/src/com/android/settings/location/RecentLocationRequestSeeAllFragment.java @@ -0,0 +1,89 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.location; + + +import android.content.Context; +import android.provider.SearchIndexableResource; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.settings.R; +import com.android.settings.dashboard.DashboardFragment; +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; + +/** Dashboard Fragment to display all recent location requests, sorted by recency. */ +public class RecentLocationRequestSeeAllFragment extends DashboardFragment { + + private static final String TAG = "RecentLocationReqAll"; + + public static final String PATH = + "com.android.settings.location.RecentLocationRequestSeeAllFragment"; + + @Override + public int getMetricsCategory() { + return MetricsEvent.RECENT_LOCATION_REQUESTS_ALL; + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.location_recent_requests_see_all; + } + + @Override + protected String getLogTag() { + return TAG; + } + + @Override + protected List createPreferenceControllers(Context context) { + return buildPreferenceControllers(context, getLifecycle(), this); + } + + private static List buildPreferenceControllers( + Context context, Lifecycle lifecycle, RecentLocationRequestSeeAllFragment fragment) { + final List controllers = new ArrayList<>(); + controllers.add( + new RecentLocationRequestSeeAllPreferenceController(context, lifecycle, fragment)); + return controllers; + } + + /** + * For Search. + */ + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.location_recent_requests_see_all; + return Arrays.asList(sir); + } + + @Override + public List getPreferenceControllers(Context + context) { + return buildPreferenceControllers( + context, /* lifecycle = */ null, /* fragment = */ null); + } + }; +} diff --git a/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceController.java b/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceController.java new file mode 100644 index 00000000000..4b59df23821 --- /dev/null +++ b/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceController.java @@ -0,0 +1,95 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.location; + +import android.content.Context; +import android.support.annotation.VisibleForTesting; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceCategory; +import android.support.v7.preference.PreferenceScreen; +import com.android.settings.widget.AppPreference; +import com.android.settingslib.core.lifecycle.Lifecycle; +import com.android.settingslib.location.RecentLocationApps; +import java.util.List; + +/** Preference controller for preference category displaying all recent location requests. */ +public class RecentLocationRequestSeeAllPreferenceController + extends LocationBasePreferenceController { + + /** Key for preference category "All recent location requests" */ + private static final String KEY_ALL_RECENT_LOCATION_REQUESTS = "all_recent_location_requests"; + private final RecentLocationRequestSeeAllFragment mFragment; + private PreferenceCategory mCategoryAllRecentLocationRequests; + private RecentLocationApps mRecentLocationApps; + + public RecentLocationRequestSeeAllPreferenceController( + Context context, Lifecycle lifecycle, RecentLocationRequestSeeAllFragment fragment) { + this(context, lifecycle, fragment, new RecentLocationApps(context)); + } + + @VisibleForTesting + RecentLocationRequestSeeAllPreferenceController( + Context context, + Lifecycle lifecycle, + RecentLocationRequestSeeAllFragment fragment, + RecentLocationApps recentLocationApps) { + super(context, lifecycle); + mFragment = fragment; + mRecentLocationApps = recentLocationApps; + } + + @Override + public String getPreferenceKey() { + return KEY_ALL_RECENT_LOCATION_REQUESTS; + } + + @Override + public void onLocationModeChanged(int mode, boolean restricted) { + mCategoryAllRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode)); + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mCategoryAllRecentLocationRequests = + (PreferenceCategory) screen.findPreference(KEY_ALL_RECENT_LOCATION_REQUESTS); + + } + + @Override + public void updateState(Preference preference) { + mCategoryAllRecentLocationRequests.removeAll(); + List requests = mRecentLocationApps.getAppListSorted(); + for (RecentLocationApps.Request request : requests) { + Preference appPreference = createAppPreference(preference.getContext(), request); + mCategoryAllRecentLocationRequests.addPreference(appPreference); + } + } + + @VisibleForTesting + AppPreference createAppPreference( + Context prefContext, RecentLocationApps.Request request) { + final AppPreference pref = new AppPreference(prefContext); + pref.setSummary(request.contentDescription); + pref.setIcon(request.icon); + pref.setTitle(request.label); + pref.setOnPreferenceClickListener( + new RecentLocationRequestPreferenceController.PackageEntryClickedListener( + mFragment, request.packageName, request.userHandle)); + return pref; + } +} diff --git a/src/com/android/settings/network/MobileNetworkPreferenceController.java b/src/com/android/settings/network/MobileNetworkPreferenceController.java index 1670b0d185b..09f0f8b2440 100644 --- a/src/com/android/settings/network/MobileNetworkPreferenceController.java +++ b/src/com/android/settings/network/MobileNetworkPreferenceController.java @@ -32,11 +32,11 @@ import com.android.settings.wrapper.RestrictedLockUtilsWrapper; import com.android.settingslib.Utils; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.LifecycleObserver; -import com.android.settingslib.core.lifecycle.events.OnPause; -import com.android.settingslib.core.lifecycle.events.OnResume; +import com.android.settingslib.core.lifecycle.events.OnStart; +import com.android.settingslib.core.lifecycle.events.OnStop; public class MobileNetworkPreferenceController extends AbstractPreferenceController - implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause { + implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop { private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings"; @@ -71,9 +71,7 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); - if (isAvailable()) { - mPreference = screen.findPreference(getPreferenceKey()); - } + mPreference = screen.findPreference(getPreferenceKey()); } @Override @@ -82,15 +80,13 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl } @Override - public void onResume() { + public void onStart() { if (isAvailable()) { if (mPhoneStateListener == null) { mPhoneStateListener = new PhoneStateListener() { @Override public void onServiceStateChanged(ServiceState serviceState) { - if (mPreference != null) { - mPreference.setSummary(mTelephonyManager.getNetworkOperatorName()); - } + updateState(mPreference); } }; } @@ -99,9 +95,14 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl } @Override - public void onPause() { + public void onStop() { if (mPhoneStateListener != null) { mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); } } + + @Override + public CharSequence getSummary() { + return mTelephonyManager.getNetworkOperatorName(); + } } diff --git a/src/com/android/settings/notification/HeaderPreferenceController.java b/src/com/android/settings/notification/HeaderPreferenceController.java index 5ec60c2d93a..f30abf48ef0 100644 --- a/src/com/android/settings/notification/HeaderPreferenceController.java +++ b/src/com/android/settings/notification/HeaderPreferenceController.java @@ -51,6 +51,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController return mAppRow != null; } + @Override public void updateState(Preference preference) { if (mAppRow != null && mFragment != null) { LayoutPreference pref = (LayoutPreference) preference; @@ -78,7 +79,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController } @Override - public String getSummary() { + public CharSequence getSummary() { if (mChannel != null) { if (mChannelGroup != null && mChannelGroup.getGroup() != null && !TextUtils.isEmpty(mChannelGroup.getGroup().getName())) { diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java index a9c5c032769..38fdbcec003 100644 --- a/src/com/android/settings/password/ChooseLockPassword.java +++ b/src/com/android/settings/password/ChooseLockPassword.java @@ -279,7 +279,7 @@ public class ChooseLockPassword extends SettingsActivity { 0, 0, 0, - R.string.next_label); + R.string.lockpassword_confirm_label); Stage(int hintInAlpha, int hintInAlphaForFingerprint, int hintInNumeric, int hintInNumericForFingerprint, @@ -885,7 +885,7 @@ public class ChooseLockPassword extends SettingsActivity { // Hide password requirement view when we are just asking user to confirm the pw. mPasswordRestrictionView.setVisibility(View.GONE); setHeaderText(getString(mUiStage.getHint(mIsAlphaMode, mForFingerprint))); - setNextEnabled(canInput && length > 0); + setNextEnabled(canInput && length >= mPasswordMinLength); mClearButton.setEnabled(canInput && length > 0); } int message = mUiStage.getMessage(mIsAlphaMode, mForFingerprint); diff --git a/src/com/android/settings/print/PrintSettingPreferenceController.java b/src/com/android/settings/print/PrintSettingPreferenceController.java index 1f85c4cccbf..a589770a0ea 100644 --- a/src/com/android/settings/print/PrintSettingPreferenceController.java +++ b/src/com/android/settings/print/PrintSettingPreferenceController.java @@ -84,16 +84,13 @@ public class PrintSettingPreferenceController extends BasePreferenceController i @Override public void updateState(Preference preference) { - if (preference == null) { - return; - } - preference.setSummary(getSummary()); + super.updateState(preference); ((RestrictedPreference) preference).checkRestrictionAndSetDisabled( UserManager.DISALLOW_PRINTING); } @Override - public String getSummary() { + public CharSequence getSummary() { final List printJobs = mPrintManager.getPrintJobs(); int numActivePrintJobs = 0; @@ -112,7 +109,7 @@ public class PrintSettingPreferenceController extends BasePreferenceController i final List services = mPrintManager.getPrintServices(PrintManager.ENABLED_SERVICES); if (services == null || services.isEmpty()) { - return mContext.getString(R.string.print_settings_summary_no_service); + return mContext.getText(R.string.print_settings_summary_no_service); } else { final int count = services.size(); return mContext.getResources().getQuantityString( diff --git a/src/com/android/settings/search/SearchIndexableResourcesImpl.java b/src/com/android/settings/search/SearchIndexableResourcesImpl.java index f8da560eb4d..87c2a9107b7 100644 --- a/src/com/android/settings/search/SearchIndexableResourcesImpl.java +++ b/src/com/android/settings/search/SearchIndexableResourcesImpl.java @@ -65,6 +65,7 @@ import com.android.settings.inputmethod.PhysicalKeyboardFragment; import com.android.settings.inputmethod.VirtualKeyboardFragment; import com.android.settings.language.LanguageAndInputSettings; import com.android.settings.location.LocationSettings; +import com.android.settings.location.RecentLocationRequestSeeAllFragment; import com.android.settings.location.ScanningSettings; import com.android.settings.network.NetworkDashboardFragment; import com.android.settings.nfc.PaymentSettings; @@ -177,6 +178,7 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources { addIndex(SmartBatterySettings.class); addIndex(MyDeviceInfoFragment.class); addIndex(VibrationSettings.class); + addIndex(RecentLocationRequestSeeAllFragment.class); } @Override diff --git a/src/com/android/settings/security/ScreenPinningPreferenceController.java b/src/com/android/settings/security/ScreenPinningPreferenceController.java index 305d07699ba..a90746eb1e7 100644 --- a/src/com/android/settings/security/ScreenPinningPreferenceController.java +++ b/src/com/android/settings/security/ScreenPinningPreferenceController.java @@ -18,7 +18,6 @@ package com.android.settings.security; import android.content.Context; import android.provider.Settings; -import android.support.v7.preference.Preference; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; @@ -38,16 +37,10 @@ public class ScreenPinningPreferenceController extends BasePreferenceController } @Override - public String getSummary() { + public CharSequence getSummary() { return Settings.System.getInt(mContext.getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED, 0) != 0 - ? mContext.getString(R.string.switch_on_text) - : mContext.getString(R.string.switch_off_text); - } - - @Override - public void updateState(Preference preference) { - super.updateState(preference); - preference.setSummary(getSummary()); + ? mContext.getText(R.string.switch_on_text) + : mContext.getText(R.string.switch_off_text); } } diff --git a/src/com/android/settings/shortcut/CreateShortcut.java b/src/com/android/settings/shortcut/CreateShortcut.java index 2bd9b761255..b0787401f7b 100644 --- a/src/com/android/settings/shortcut/CreateShortcut.java +++ b/src/com/android/settings/shortcut/CreateShortcut.java @@ -71,7 +71,7 @@ public class CreateShortcut extends LauncherActivity { @VisibleForTesting Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) { - shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); ShortcutManager sm = getSystemService(ShortcutManager.class); ActivityInfo activityInfo = resolveInfo.activityInfo; diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java index a01ea1bd0ed..35bc07e3410 100644 --- a/src/com/android/settings/slices/SliceBuilderUtils.java +++ b/src/com/android/settings/slices/SliceBuilderUtils.java @@ -57,7 +57,7 @@ public class SliceBuilderUtils { final Icon icon = Icon.createWithResource(context, sliceData.getIconResource()); final BasePreferenceController controller = getPreferenceController(context, sliceData); - final String subtitleText = getSubtitleText(context, controller, sliceData); + final CharSequence subtitleText = getSubtitleText(context, controller, sliceData); final RowBuilder builder = new RowBuilder(context, sliceData.getUri()) .setTitle(sliceData.getTitle()) @@ -120,9 +120,9 @@ public class SliceBuilderUtils { } @VisibleForTesting - static String getSubtitleText(Context context, AbstractPreferenceController controller, + static CharSequence getSubtitleText(Context context, AbstractPreferenceController controller, SliceData sliceData) { - String summaryText = sliceData.getSummary(); + CharSequence summaryText = sliceData.getSummary(); if (isValidSummary(context, summaryText)) { return summaryText; } @@ -138,13 +138,14 @@ public class SliceBuilderUtils { return sliceData.getScreenTitle(); } - private static boolean isValidSummary(Context context, String summary) { - if (summary == null || TextUtils.isEmpty(summary.trim())) { + private static boolean isValidSummary(Context context, CharSequence summary) { + if (summary == null || TextUtils.isEmpty(summary.toString().trim())) { return false; } - final String placeHolder = context.getString(R.string.summary_placeholder); - final String doublePlaceHolder = context.getString(R.string.summary_two_lines_placeholder); + final CharSequence placeHolder = context.getText(R.string.summary_placeholder); + final CharSequence doublePlaceHolder = + context.getText(R.string.summary_two_lines_placeholder); return !(TextUtils.equals(summary, placeHolder) || TextUtils.equals(summary, doublePlaceHolder)); diff --git a/src/com/android/settings/system/SystemUpdatePreferenceController.java b/src/com/android/settings/system/SystemUpdatePreferenceController.java index 20f43ef0865..80d4ecb05df 100644 --- a/src/com/android/settings/system/SystemUpdatePreferenceController.java +++ b/src/com/android/settings/system/SystemUpdatePreferenceController.java @@ -83,21 +83,16 @@ public class SystemUpdatePreferenceController extends BasePreferenceController { } @Override - public void updateState(Preference preference) { - preference.setSummary(getSummary()); - } - - @Override - public String getSummary() { + public CharSequence getSummary() { final Bundle updateInfo = mUpdateManager.retrieveSystemUpdateInfo(); - String summary = mContext.getString(R.string.android_version_summary, + CharSequence summary = mContext.getString(R.string.android_version_summary, Build.VERSION.RELEASE); switch (updateInfo.getInt(SystemUpdateManager.KEY_STATUS)) { case SystemUpdateManager.STATUS_WAITING_DOWNLOAD: case SystemUpdateManager.STATUS_IN_PROGRESS: case SystemUpdateManager.STATUS_WAITING_INSTALL: case SystemUpdateManager.STATUS_WAITING_REBOOT: - summary = mContext.getString(R.string.android_version_pending_update_summary); + summary = mContext.getText(R.string.android_version_pending_update_summary); break; case SystemUpdateManager.STATUS_UNKNOWN: Log.d(TAG, "Update statue unknown"); diff --git a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry index 948b14ad70c..be3507c93ae 100644 --- a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry +++ b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry @@ -1 +1,2 @@ com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard +com.android.settings.search.indexing.FakeSettingsFragment diff --git a/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider b/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider index da541e21df2..b3290725c98 100644 --- a/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider +++ b/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider @@ -1,5 +1 @@ -com.android.settings.datausage.DataUsageSummaryLegacy com.android.settings.fuelgauge.PowerUsageSummary -com.android.settings.fuelgauge.PowerUsageAdvanced -com.android.settings.search.indexing.FakeSettingsFragment -com.android.settings.system.SystemDashboardFragment \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/accessibility/NotificationVibrationIntensityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/NotificationVibrationIntensityPreferenceControllerTest.java index 2f55e00d46e..32e17b92687 100644 --- a/tests/robotests/src/com/android/settings/accessibility/NotificationVibrationIntensityPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/NotificationVibrationIntensityPreferenceControllerTest.java @@ -86,25 +86,25 @@ public class NotificationVibrationIntensityPreferenceControllerTest { public void updateState_shouldRefreshSummary() { Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); - mController.updateState(null); + mController.updateState(mPreference); assertThat(mPreference.getSummary()) .isEqualTo(mContext.getString(R.string.accessibility_vibration_intensity_low)); Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); - mController.updateState(null); + mController.updateState(mPreference); assertThat(mPreference.getSummary()) .isEqualTo(mContext.getString(R.string.accessibility_vibration_intensity_high)); Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); - mController.updateState(null); + mController.updateState(mPreference); assertThat(mPreference.getSummary()) .isEqualTo(mContext.getString(R.string.accessibility_vibration_intensity_medium)); Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); - mController.updateState(null); + mController.updateState(mPreference); assertThat(mPreference.getSummary()) .isEqualTo(mContext.getString(R.string.accessibility_vibration_intensity_off)); } diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java index 01bfda6b28e..a9dc4720850 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java @@ -335,7 +335,6 @@ public final class AppInfoDashboardFragmentTest { public void startAppInfoFragment_includesNewAndOldArgs() { final SettingsPreferenceFragment caller = mock(SettingsPreferenceFragment.class); final SettingsActivity sa = mock (SettingsActivity.class); - when(caller.getActivity()).thenReturn(sa); when(caller.getContext()).thenReturn(sa); final AppEntry appEntry = mock(AppEntry.class); appEntry.info = mock(ApplicationInfo.class); @@ -348,7 +347,7 @@ public final class AppInfoDashboardFragmentTest { final ArgumentCaptor intent = ArgumentCaptor.forClass(Intent.class); - verify(sa).startActivityForResult(intent.capture(), any(Integer.class)); + verify(caller).startActivityForResult(intent.capture(), any(Integer.class)); assertThat(intent.getValue().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) .containsKey("test")) .isTrue(); diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBaseTest.java index 0715724ac29..aadcb3e2f07 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBaseTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoPreferenceControllerBaseTest.java @@ -93,7 +93,7 @@ public class AppInfoPreferenceControllerBaseTest { mController.handlePreferenceTreeClick(mPreference); final ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class); - verify(mActivity).startActivityForResult(intentCaptor.capture(), eq(SUB_INFO_FRAGMENT)); + verify(mFragment).startActivityForResult(intentCaptor.capture(), eq(SUB_INFO_FRAGMENT)); assertThat(intentCaptor.getValue().getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)) .isEqualTo(mController.getDetailFragmentClass().getName()); } diff --git a/tests/robotests/src/com/android/settings/core/SubSettingLauncherTest.java b/tests/robotests/src/com/android/settings/core/SubSettingLauncherTest.java index 4a1b2d8e7e6..3143381d681 100644 --- a/tests/robotests/src/com/android/settings/core/SubSettingLauncherTest.java +++ b/tests/robotests/src/com/android/settings/core/SubSettingLauncherTest.java @@ -121,7 +121,7 @@ public class SubSettingLauncherTest { .setResultListener(mFragment, requestCode) .launch(); - verify(mActivity).startActivityForResult(any(Intent.class), eq(requestCode)); + verify(mFragment).startActivityForResult(any(Intent.class), eq(requestCode)); } @Test diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentSearchIndexProviderInspector.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentSearchIndexProviderInspector.java index 80083ed1919..83579b4252c 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentSearchIndexProviderInspector.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentSearchIndexProviderInspector.java @@ -19,6 +19,8 @@ package com.android.settings.dashboard; import android.app.Fragment; import android.content.Context; +import com.android.settings.core.BasePreferenceController; +import com.android.settings.core.PreferenceControllerListHelper; import com.android.settings.search.DatabaseIndexingUtils; import com.android.settings.search.Indexable; import com.android.settingslib.core.AbstractPreferenceController; @@ -58,6 +60,14 @@ public class DashboardFragmentSearchIndexProviderInspector { try { controllersFromFragment = ((DashboardFragment) fragment).createPreferenceControllers(context); + List controllersFromXml = PreferenceControllerListHelper + .getPreferenceControllersFromXml(context, + ((DashboardFragment) fragment).getPreferenceScreenResId()); + final List uniqueControllerFromXml = + PreferenceControllerListHelper.filterControllers( + controllersFromXml, controllersFromFragment); + controllersFromFragment.addAll(uniqueControllerFromXml); + } catch (Throwable e) { // Can't do much with exception, assume the test passed. return true; diff --git a/tests/robotests/src/com/android/settings/dashboard/conditional/BackgroundDataConditionTest.java b/tests/robotests/src/com/android/settings/dashboard/conditional/BackgroundDataConditionTest.java new file mode 100644 index 00000000000..be0da83f368 --- /dev/null +++ b/tests/robotests/src/com/android/settings/dashboard/conditional/BackgroundDataConditionTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.dashboard.conditional; + +import android.content.Context; +import android.content.Intent; +import android.util.FeatureFlagUtils; + +import com.android.settings.Settings; +import com.android.settings.TestConfig; +import com.android.settings.core.FeatureFlags; +import com.android.settings.testutils.SettingsRobolectricTestRunner; +import com.android.settings.testutils.shadow.SettingsShadowSystemProperties; +import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = + SettingsShadowSystemProperties.class) +public class BackgroundDataConditionTest { + @Mock + private ConditionManager mConditionManager; + + private Context mContext; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + when(mConditionManager.getContext()).thenReturn(mContext); + } + + @Test + public void onPrimaryClick_v2enabled_shouldReturnv2SummaryActivity() { + FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DATA_USAGE_SETTINGS_V2, true); + + final ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Intent.class); + BackgroundDataCondition backgroundDataCondition + = new BackgroundDataCondition(mConditionManager); + backgroundDataCondition.onPrimaryClick(); + verify(mContext).startActivity(argumentCaptor.capture()); + Intent intent = argumentCaptor.getValue(); + + assertThat(intent.getComponent().getClassName()).isEqualTo( + Settings.DataUsageSummaryActivity.class.getName()); + } + + @Test + public void onPrimaryClick_v2disabled_shouldReturnLegacySummaryActivity() { + FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DATA_USAGE_SETTINGS_V2, false); + + final ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Intent.class); + BackgroundDataCondition backgroundDataCondition + = new BackgroundDataCondition(mConditionManager); + backgroundDataCondition.onPrimaryClick(); + verify(mContext).startActivity(argumentCaptor.capture()); + Intent intent = argumentCaptor.getValue(); + + assertThat(intent.getComponent().getClassName()).isEqualTo( + Settings.DataUsageSummaryLegacyActivity.class.getName()); + } +} diff --git a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java index cf892f8c255..cd56b788000 100644 --- a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java @@ -17,13 +17,15 @@ package com.android.settings.development; import static com.android.settings.development.BluetoothMaxConnectedAudioDevicesPreferenceController - .BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY; + .MAX_CONNECTED_AUDIO_DEVICES_PROPERTY; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import android.content.Context; +import android.content.res.Resources; import android.os.SystemProperties; import android.support.v7.preference.ListPreference; import android.support.v7.preference.PreferenceScreen; @@ -39,6 +41,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.mockito.Spy; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @@ -47,37 +50,41 @@ import org.robolectric.annotation.Config; sdk = TestConfig.SDK_VERSION, shadows = {SettingsShadowSystemProperties.class}) public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest { + private static final int TEST_MAX_CONNECTED_AUDIO_DEVICES = 3; @Mock private PreferenceScreen mPreferenceScreen; + @Spy + private Context mSpyContext = RuntimeEnvironment.application; + @Spy + private Resources mSpyResources = RuntimeEnvironment.application.getResources(); - private Context mContext; private ListPreference mPreference; private BluetoothMaxConnectedAudioDevicesPreferenceController mController; - /** - * 0: 1 device maximum (Default) - * 1: 2 devices maximum - * 2: 3 devices maximum - * 3: 4 devices maximum - * 4: 5 devices maximum - */ - private String[] mListValues; - private String[] mListSummaries; + private CharSequence[] mListValues; + private CharSequence[] mListEntries; @Before public void setup() { MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; - mPreference = new ListPreference(mContext); - mListValues = mContext.getResources().getStringArray( - R.array.bluetooth_max_connected_audio_devices_values); - mListSummaries = mContext.getResources().getStringArray( - R.array.bluetooth_max_connected_audio_devices); - mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mContext); + doReturn(mSpyResources).when(mSpyContext).getResources(); + // Get XML values without mock + // Setup test list preference using XML values + mPreference = new ListPreference(mSpyContext); + mPreference.setEntries(R.array.bluetooth_max_connected_audio_devices); + mPreference.setEntryValues(R.array.bluetooth_max_connected_audio_devices_values); + // Stub default max connected audio devices to a test controlled value + doReturn(TEST_MAX_CONNECTED_AUDIO_DEVICES).when(mSpyResources).getInteger( + com.android.internal.R.integer.config_bluetooth_max_connected_audio_devices); + // Init the actual controller + mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mSpyContext); + // Construct preference in the controller via a mocked preference screen object when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn( mPreference); mController.displayPreference(mPreferenceScreen); + mListValues = mPreference.getEntryValues(); + mListEntries = mPreference.getEntries(); } @After @@ -85,40 +92,68 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest { SettingsShadowSystemProperties.clear(); } + @Test + public void verifyResourceSizeAndRange() { + // Verify normal list entries and default preference entries have the same size + assertThat(mListEntries.length).isEqualTo(mListValues.length); + // Verify that list entries are formatted correctly + final String defaultEntry = String.format(mListEntries[0].toString(), + TEST_MAX_CONNECTED_AUDIO_DEVICES); + assertThat(mListEntries[0]).isEqualTo(defaultEntry); + // Update the preference + mController.updateState(mPreference); + // Verify default preference value, entry and summary + assertThat(mPreference.getValue()).isEqualTo(mListValues[0]); + assertThat(mPreference.getEntry()).isEqualTo(mListEntries[0]); + assertThat(mPreference.getSummary()).isEqualTo(mListEntries[0]); + // Verify that default system property is empty + assertThat(SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY)).isEmpty(); + // Verify default property integer value + assertThat(SystemProperties.getInt(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, + TEST_MAX_CONNECTED_AUDIO_DEVICES)).isEqualTo(TEST_MAX_CONNECTED_AUDIO_DEVICES); + } + @Test public void onPreferenceChange_setNumberOfDevices() { - for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) { - mController.onPreferenceChange(mPreference, mListValues[numberOfDevices]); - - final String currentValue = SystemProperties.get( - BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY); - - assertThat(currentValue).isEqualTo(mListValues[numberOfDevices]); - assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]); - assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]); + for (final CharSequence newValue : mListValues) { + // Change preference using a list value + mController.onPreferenceChange(mPreference, newValue); + // Verify that value is set on the preference + assertThat(mPreference.getValue()).isEqualTo(newValue); + int index = mPreference.findIndexOfValue(newValue.toString()); + assertThat(mPreference.getEntry()).isEqualTo(mListEntries[index]); + // Verify that system property is set correctly after the change + final String currentValue = SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY); + assertThat(currentValue).isEqualTo(mListValues[index]); } } @Test public void updateState_NumberOfDevicesUpdated_shouldSetPreference() { - for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) { - SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, - mListValues[numberOfDevices]); - + for (int i = 0; i < mListValues.length; ++i) { + final String propertyValue = mListValues[i].toString(); + SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, propertyValue); + // Verify that value is set on the preference mController.updateState(mPreference); - - assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]); - assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]); + assertThat(mPreference.getValue()).isEqualTo(mListValues[i]); + assertThat(mPreference.getEntry()).isEqualTo(mListEntries[i]); + assertThat(mPreference.getSummary()).isEqualTo(mListEntries[i]); + // Verify that property value remain unchanged + assertThat(SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY)) + .isEqualTo(propertyValue); } } @Test public void updateState_noValueSet_shouldSetDefaultTo1device() { - SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, "garbage"); + SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, "garbage"); mController.updateState(mPreference); + // Verify that preference is reset back to default and property is reset to default assertThat(mPreference.getValue()).isEqualTo(mListValues[0]); - assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]); + assertThat(mPreference.getEntry()).isEqualTo(mListEntries[0]); + assertThat(mPreference.getSummary()).isEqualTo(mListEntries[0]); + assertThat(SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY)).isEmpty(); } @Test @@ -126,26 +161,30 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest { mController.onDeveloperOptionsSwitchDisabled(); assertThat(mPreference.isEnabled()).isFalse(); + // Verify that preference is reset back to default and property is reset to default assertThat(mPreference.getValue()).isEqualTo(mListValues[0]); - assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]); - final String currentValue = SystemProperties.get( - BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY); - assertThat(currentValue).isEqualTo(mListValues[0]); + assertThat(mPreference.getEntry()).isEqualTo(mListEntries[0]); + assertThat(mPreference.getSummary()).isEqualTo(mListEntries[0]); + assertThat(SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY)).isEmpty(); } @Test public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() { - for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) { + for (int i = 0; i < mListValues.length; ++i) { + final String initialValue = mListValues[i].toString(); mController.onDeveloperOptionsSwitchDisabled(); assertThat(mPreference.isEnabled()).isFalse(); - SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, - mListValues[numberOfDevices]); + SystemProperties.set(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, initialValue); mController.onDeveloperOptionsSwitchEnabled(); assertThat(mPreference.isEnabled()).isTrue(); - assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]); - assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]); + assertThat(mPreference.getValue()).isEqualTo(mListValues[i]); + assertThat(mPreference.getEntry()).isEqualTo(mListEntries[i]); + assertThat(mPreference.getSummary()).isEqualTo(mListEntries[i]); + // Verify that property value remain unchanged + assertThat(SystemProperties.get(MAX_CONNECTED_AUDIO_DEVICES_PROPERTY)) + .isEqualTo(initialValue); } } } diff --git a/tests/robotests/src/com/android/settings/display/ColorModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ColorModePreferenceControllerTest.java new file mode 100644 index 00000000000..567b20052f7 --- /dev/null +++ b/tests/robotests/src/com/android/settings/display/ColorModePreferenceControllerTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.display; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.support.v7.preference.Preference; + +import com.android.internal.app.ColorDisplayController; +import com.android.settings.R; +import com.android.settings.TestConfig; +import com.android.settings.testutils.SettingsRobolectricTestRunner; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.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) +public class ColorModePreferenceControllerTest { + + @Mock + private Preference mPreference; + @Mock + private ColorDisplayController mColorDisplayController; + + private Context mContext; + private ColorModePreferenceController mController; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mController = spy(new ColorModePreferenceController(mContext)); + doReturn(mColorDisplayController).when(mController).getColorDisplayController(); + } + + @Test + public void updateState_colorModeSaturated_shouldSetSummaryToSaturated() { + when(mColorDisplayController.getColorMode()) + .thenReturn(ColorDisplayController.COLOR_MODE_SATURATED); + + mController.updateState(mPreference); + + verify(mPreference).setSummary(mContext.getString(R.string.color_mode_option_saturated)); + } + + @Test + public void updateState_colorModeBoosted_shouldSetSummaryToBoosted() { + when(mColorDisplayController.getColorMode()) + .thenReturn(ColorDisplayController.COLOR_MODE_BOOSTED); + + mController.updateState(mPreference); + + verify(mPreference).setSummary(mContext.getString(R.string.color_mode_option_boosted)); + } + + @Test + public void updateState_colorModeNatural_shouldSetSummaryToNatural() { + when(mColorDisplayController.getColorMode()) + .thenReturn(ColorDisplayController.COLOR_MODE_NATURAL); + + mController.updateState(mPreference); + + verify(mPreference).setSummary(mContext.getString(R.string.color_mode_option_natural)); + } + +} diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java index 45edb472e1a..b613bb3caaa 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java @@ -71,7 +71,7 @@ public class BatteryInfoTest { private static final int PLUGGED_IN = 1; private static final long REMAINING_TIME_NULL = -1; private static final long REMAINING_TIME = 2; - public static final String ENHANCED_STRING_SUFFIX = "left based on your usage"; + public static final String ENHANCED_STRING_SUFFIX = "based on your usage"; public static final long TEST_CHARGE_TIME_REMAINING = TimeUnit.MINUTES.toMicros(1); public static final String TEST_CHARGE_TIME_REMAINING_STRINGIFIED = "1m left until fully charged"; @@ -183,7 +183,7 @@ public class BatteryInfoTest { // Check that strings are showing less than 15 minutes remaining regardless of exact time. assertThat(info.chargeLabel.toString()).isEqualTo( mContext.getString(R.string.power_remaining_less_than_duration, - TEST_BATTERY_LEVEL_10, FIFTEEN_MIN_FORMATTED)); + FIFTEEN_MIN_FORMATTED, TEST_BATTERY_LEVEL_10)); assertThat(info.remainingLabel.toString()).isEqualTo( mContext.getString(R.string.power_remaining_less_than_duration_only, FIFTEEN_MIN_FORMATTED)); diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java index c4b6aeabbd2..329665b259c 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java @@ -445,19 +445,6 @@ public class PowerUsageSummaryLegacyTest { eq(Bundle.EMPTY), any()); } - @Ignore("b/73892008") - @Test - public void testShowBothEstimates_summariesAreBothModified() { - doReturn(new TextView(mRealContext)).when(mBatteryLayoutPref).findViewById(R.id.summary2); - doReturn(new TextView(mRealContext)).when(mBatteryLayoutPref).findViewById(R.id.summary1); - mFragment.onLongClick(new View(mRealContext)); - TextView summary1 = mFragment.mBatteryLayoutPref.findViewById(R.id.summary1); - TextView summary2 = mFragment.mBatteryLayoutPref.findViewById(R.id.summary2); - Robolectric.flushBackgroundThreadScheduler(); - assertThat(summary2.getText().toString()).contains(NEW_ML_EST_SUFFIX); - assertThat(summary1.getText().toString()).contains(OLD_EST_SUFFIX); - } - @Test public void testSaveInstanceState_showAllAppsRestored() { Bundle bundle = new Bundle(); diff --git a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java index d2333babf53..5fc787b3da7 100644 --- a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java @@ -106,17 +106,17 @@ public class GesturesSettingsPreferenceControllerTest { Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 0); Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0); mController.updateState(mPreference); - verify(mActivity).getString(R.string.language_input_gesture_summary_off); + verify(mActivity).getText(R.string.language_input_gesture_summary_off); Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 1); Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0); mController.updateState(mPreference); - verify(mActivity).getString(R.string.language_input_gesture_summary_on_with_assist); + verify(mActivity).getText(R.string.language_input_gesture_summary_on_with_assist); Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_ENABLED, 0); Settings.Secure.putInt(cr, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1); mController.updateState(mPreference); - verify(mActivity).getString(R.string.language_input_gesture_summary_on_non_assist); + verify(mActivity).getText(R.string.language_input_gesture_summary_on_non_assist); } @Test diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java index a33945128ff..1bacd5b49d2 100644 --- a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java @@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -34,7 +35,6 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceScreen; import android.text.TextUtils; - import com.android.settings.R; import com.android.settings.TestConfig; import com.android.settings.applications.appinfo.AppInfoDashboardFragment; @@ -43,7 +43,8 @@ import com.android.settings.widget.AppPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.location.RecentLocationApps; import com.android.settingslib.location.RecentLocationApps.Request; - +import java.util.ArrayList; +import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -56,9 +57,6 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import java.util.ArrayList; -import java.util.List; - @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class RecentLocationRequestPreferenceControllerTest { @@ -71,6 +69,8 @@ public class RecentLocationRequestPreferenceControllerTest { private PreferenceScreen mScreen; @Mock private RecentLocationApps mRecentLocationApps; + @Mock + private Preference mSeeAllButton; private Context mContext; private RecentLocationRequestPreferenceController mController; @@ -86,6 +86,7 @@ public class RecentLocationRequestPreferenceControllerTest { mController = spy(new RecentLocationRequestPreferenceController( mContext, mFragment, mLifecycle, mRecentLocationApps)); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mCategory); + when(mScreen.findPreference(mController.KEY_SEE_ALL)).thenReturn(mSeeAllButton); final String key = mController.getPreferenceKey(); when(mCategory.getKey()).thenReturn(key); when(mCategory.getContext()).thenReturn(mContext); @@ -123,38 +124,43 @@ public class RecentLocationRequestPreferenceControllerTest { @Test public void updateState_hasRecentRequest_shouldRemoveAllAndAddInjectedSettings() { - final List requests = new ArrayList<>(); - final Request req1 = mock(Request.class); - final Request req2 = mock(Request.class); - requests.add(req1); - requests.add(req2); + List requests = createMockRequests(2); doReturn(requests).when(mRecentLocationApps).getAppListSorted(); - final String title1 = "testTitle1"; - final String title2 = "testTitle2"; - final AppPreference preference1 = mock(AppPreference.class); - final AppPreference preference2 = mock(AppPreference.class); - when(preference1.getTitle()).thenReturn(title1); - when(preference2.getTitle()).thenReturn(title2); - doReturn(preference1).when(mController) - .createAppPreference(any(Context.class), eq(req1)); - doReturn(preference2).when(mController) - .createAppPreference(any(Context.class), eq(req2)); + mController.displayPreference(mScreen); mController.updateState(mCategory); verify(mCategory).removeAll(); // Verifies two preferences are added in original order InOrder inOrder = Mockito.inOrder(mCategory); - inOrder.verify(mCategory).addPreference(argThat(titleMatches(title1))); - inOrder.verify(mCategory).addPreference(argThat(titleMatches(title2))); + inOrder.verify(mCategory).addPreference(argThat(titleMatches("appTitle0"))); + inOrder.verify(mCategory).addPreference(argThat(titleMatches("appTitle1"))); + } + + @Test + public void updateState_hasOverThreeRequests_shouldDisplaySeeAllButton() { + List requests = createMockRequests(6); + when(mRecentLocationApps.getAppListSorted()).thenReturn(requests); + + mController.displayPreference(mScreen); + mController.updateState(mCategory); + + verify(mCategory).removeAll(); + // Verifies the first three preferences are added + InOrder inOrder = Mockito.inOrder(mCategory); + inOrder.verify(mCategory).addPreference(argThat(titleMatches("appTitle0"))); + inOrder.verify(mCategory).addPreference(argThat(titleMatches("appTitle1"))); + inOrder.verify(mCategory).addPreference(argThat(titleMatches("appTitle2"))); + verify(mCategory, never()).addPreference(argThat(titleMatches("appTitle3"))); + // Verifies the "See all" preference is visible + verify(mSeeAllButton).setVisible(true); } @Test public void createAppPreference_shouldAddClickListener() { final Request request = mock(Request.class); final AppPreference preference = mock(AppPreference.class); - doReturn(preference).when(mController) - .createAppPreference(any(Context.class)); + doReturn(preference).when(mController).createAppPreference(any(Context.class)); mController.createAppPreference(mContext, request); @@ -190,4 +196,19 @@ public class RecentLocationRequestPreferenceControllerTest { return preference -> TextUtils.equals(expected, preference.getTitle()); } -} + private List createMockRequests(int count) { + List requests = new ArrayList<>(); + for (int i = 0; i < count; i++) { + // Add mock requests + Request req = mock(Request.class, "request" + i); + requests.add(req); + // Map mock AppPreferences with mock requests + String title = "appTitle" + i; + AppPreference appPreference = mock(AppPreference.class, "AppPreference" + i); + doReturn(title).when(appPreference).getTitle(); + doReturn(appPreference) + .when(mController).createAppPreference(any(Context.class), eq(req)); + } + return requests; + } +} \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceControllerTest.java new file mode 100644 index 00000000000..2b64dbc1850 --- /dev/null +++ b/tests/robotests/src/com/android/settings/location/RecentLocationRequestSeeAllPreferenceControllerTest.java @@ -0,0 +1,126 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.location; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.arch.lifecycle.LifecycleOwner; +import android.content.Context; +import android.provider.Settings.Secure; +import android.support.v7.preference.PreferenceCategory; +import android.support.v7.preference.PreferenceScreen; +import com.android.settings.TestConfig; +import com.android.settings.testutils.SettingsRobolectricTestRunner; +import com.android.settings.widget.AppPreference; +import com.android.settingslib.core.lifecycle.Lifecycle; +import com.android.settingslib.location.RecentLocationApps; +import com.android.settingslib.location.RecentLocationApps.Request; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +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; + +/** Unit tests for {@link RecentLocationRequestSeeAllPreferenceController} */ +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class RecentLocationRequestSeeAllPreferenceControllerTest { + + @Mock + RecentLocationRequestSeeAllFragment mFragment; + @Mock + private PreferenceScreen mScreen; + @Mock + private PreferenceCategory mCategory; + @Mock + private RecentLocationApps mRecentLocationApps; + + private Context mContext; + private LifecycleOwner mLifecycleOwner; + private Lifecycle mLifecycle; + private RecentLocationRequestSeeAllPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + mLifecycleOwner = () -> mLifecycle; + mLifecycle = new Lifecycle(mLifecycleOwner); + mController = spy( + new RecentLocationRequestSeeAllPreferenceController( + mContext, mLifecycle, mFragment, mRecentLocationApps)); + when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mCategory); + final String key = mController.getPreferenceKey(); + when(mCategory.getKey()).thenReturn(key); + when(mCategory.getContext()).thenReturn(mContext); + } + + @Test + public void onLocationModeChanged_locationOn_shouldEnablePreference() { + mController.displayPreference(mScreen); + + mController.onLocationModeChanged(Secure.LOCATION_MODE_HIGH_ACCURACY, false); + + verify(mCategory).setEnabled(true); + } + + @Test + public void onLocationModeChanged_locationOff_shouldDisablePreference() { + mController.displayPreference(mScreen); + + mController.onLocationModeChanged(Secure.LOCATION_MODE_OFF, false); + + verify(mCategory).setEnabled(false); + } + + @Test + public void updateState_shouldRemoveAll() { + doReturn(Collections.EMPTY_LIST).when(mRecentLocationApps).getAppListSorted(); + + mController.displayPreference(mScreen); + mController.updateState(mCategory); + + verify(mCategory).removeAll(); + } + + @Test + public void updateState_hasRecentLocationRequest_shouldAddPreference() { + Request request = mock(Request.class); + AppPreference appPreference = mock(AppPreference.class); + doReturn(appPreference) + .when(mController).createAppPreference(any(Context.class), eq(request)); + when(mRecentLocationApps.getAppListSorted()) + .thenReturn(new ArrayList<>(Arrays.asList(request))); + + mController.displayPreference(mScreen); + mController.updateState(mCategory); + + verify(mCategory).removeAll(); + verify(mCategory).addPreference(appPreference); + } +} diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java index f070f7a5095..bd550510fd1 100644 --- a/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/MobileNetworkPreferenceControllerTest.java @@ -15,11 +15,9 @@ */ package com.android.settings.network; -import static android.arch.lifecycle.Lifecycle.Event.ON_PAUSE; -import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME; - +import static android.arch.lifecycle.Lifecycle.Event.ON_START; +import static android.arch.lifecycle.Lifecycle.Event.ON_STOP; import static com.google.common.truth.Truth.assertThat; - import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -53,10 +51,10 @@ import org.robolectric.annotation.Config; @RunWith(SettingsRobolectricTestRunner.class) @Config( - manifest = TestConfig.MANIFEST_PATH, - sdk = TestConfig.SDK_VERSION, - shadows = {ShadowRestrictedLockUtilsWrapper.class, ShadowConnectivityManager.class, - ShadowUserManager.class} + manifest = TestConfig.MANIFEST_PATH, + sdk = TestConfig.SDK_VERSION, + shadows = {ShadowRestrictedLockUtilsWrapper.class, ShadowConnectivityManager.class, + ShadowUserManager.class} ) public class MobileNetworkPreferenceControllerTest { @@ -110,11 +108,11 @@ public class MobileNetworkPreferenceControllerTest { mLifecycle.addObserver(mController); doReturn(true).when(mController).isAvailable(); - mLifecycle.handleLifecycleEvent(ON_RESUME); + mLifecycle.handleLifecycleEvent(ON_START); verify(mTelephonyManager).listen(mController.mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE); - mLifecycle.handleLifecycleEvent(ON_PAUSE); + mLifecycle.handleLifecycleEvent(ON_STOP); verify(mTelephonyManager).listen(mController.mPhoneStateListener, PhoneStateListener.LISTEN_NONE); } @@ -131,8 +129,8 @@ public class MobileNetworkPreferenceControllerTest { // Display pref and go through lifecycle to set up listener. mController.displayPreference(mScreen); - mLifecycle.handleLifecycleEvent(ON_RESUME); - verify(mController).onResume(); + mLifecycle.handleLifecycleEvent(ON_START); + verify(mController).onStart(); verify(mTelephonyManager).listen(mController.mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE); diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java index 88e46957be4..184be5f968e 100644 --- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java +++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java @@ -89,7 +89,7 @@ public class SliceBuilderUtilsTest { SliceData data = getDummyData(); FakePreferenceController controller = new FakePreferenceController(mContext, KEY); - String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); + CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); assertThat(summary).isEqualTo(data.getSummary()); } @@ -101,7 +101,7 @@ public class SliceBuilderUtilsTest { String controllerSummary = "new_Summary"; doReturn(controllerSummary).when(controller).getSummary(); - String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); + CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); assertThat(summary).isEqualTo(controllerSummary); } @@ -111,7 +111,7 @@ public class SliceBuilderUtilsTest { SliceData data = getDummyData((String) null); FakePreferenceController controller = new FakePreferenceController(mContext, KEY); - String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); + CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); assertThat(summary).isEqualTo(data.getScreenTitle()); } @@ -120,7 +120,7 @@ public class SliceBuilderUtilsTest { public void testDynamicSummary_placeHolderString_returnsScreenTitle() { SliceData data = getDummyData(mContext.getString(R.string.summary_placeholder)); FakePreferenceController controller = new FakePreferenceController(mContext, KEY); - String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); + CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); assertThat(summary).isEqualTo(data.getScreenTitle()); } @@ -132,7 +132,7 @@ public class SliceBuilderUtilsTest { FakePreferenceController controller = spy(new FakePreferenceController(mContext, KEY)); doReturn(summaryPlaceholder).when(controller).getSummary(); - String summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); + CharSequence summary = SliceBuilderUtils.getSubtitleText(mContext, controller, data); assertThat(summary).isEqualTo(data.getScreenTitle()); } diff --git a/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.java b/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.java index b92a70773f5..738d7103352 100644 --- a/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.java +++ b/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.java @@ -52,10 +52,8 @@ public class AboutPhoneSettingsTests { // TODO: retrieve using name/ids from com.android.settings package private static final String[] sResourceTexts = { "Phone number", - "SIM status", - "Model & hardware", - "MEID", - "Android version" + "Legal information", + "Regulatory labels" }; private UiDevice mDevice; @@ -94,11 +92,11 @@ public class AboutPhoneSettingsTests { } @Test - public void testAllMenuEntriesExist() throws Exception { + public void testAllMenuEntriesExist() { searchForItemsAndTakeAction(mDevice, sResourceTexts); } - private void launchAboutPhoneSettings(String aboutSetting) throws Exception { + private void launchAboutPhoneSettings(String aboutSetting) { Intent aboutIntent = new Intent(aboutSetting); aboutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); InstrumentationRegistry.getTargetContext().startActivity(aboutIntent); @@ -107,8 +105,7 @@ public class AboutPhoneSettingsTests { /** * Removes items found in the view and optionally takes some action. */ - private void removeItemsAndTakeAction(UiDevice device, ArrayList itemsLeftToFind) - throws Exception { + private void removeItemsAndTakeAction(UiDevice device, ArrayList itemsLeftToFind) { for (Iterator iterator = itemsLeftToFind.iterator(); iterator.hasNext(); ) { String itemText = iterator.next(); UiObject2 item = device.wait(Until.findObject(By.text(itemText)), TIMEOUT); @@ -124,8 +121,7 @@ public class AboutPhoneSettingsTests { *

Will scroll down the screen until it has found all elements or reached the bottom. * This allows elements to be found and acted on even if they change order. */ - private void searchForItemsAndTakeAction(UiDevice device, String[] itemsToFind) - throws Exception { + private void searchForItemsAndTakeAction(UiDevice device, String[] itemsToFind) { ArrayList itemsLeftToFind = new ArrayList<>(Arrays.asList(itemsToFind)); assertWithMessage("There must be at least one item to search for on the screen!") diff --git a/tests/unit/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerInstrumentationTest.java b/tests/unit/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerInstrumentationTest.java new file mode 100644 index 00000000000..ce8166787e6 --- /dev/null +++ b/tests/unit/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerInstrumentationTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.development; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import com.android.settings.R; + +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class BluetoothMaxConnectedAudioDevicesPreferenceControllerInstrumentationTest { + + private Context mTargetContext; + private String[] mListValues; + private String[] mListEntries; + private String mDefaultMaxConnectedAudioDevices; + + @Before + public void setUp() throws Exception { + mTargetContext = InstrumentationRegistry.getTargetContext(); + // Get XML values without mock + mListValues = mTargetContext.getResources() + .getStringArray(R.array.bluetooth_max_connected_audio_devices_values); + mListEntries = mTargetContext.getResources() + .getStringArray(R.array.bluetooth_max_connected_audio_devices); + mDefaultMaxConnectedAudioDevices = String.valueOf(mTargetContext.getResources() + .getInteger( + com.android.internal.R.integer + .config_bluetooth_max_connected_audio_devices)); + } + + @Test + public void verifyResource() { + // Verify normal list entries and default preference entries have the same size + Assert.assertEquals(mListEntries.length, mListValues.length); + Assert.assertThat(Arrays.asList(mListValues), + CoreMatchers.hasItem(mDefaultMaxConnectedAudioDevices)); + } +}