Snap for 4628106 from e00a14b14c to pi-release

Change-Id: Ic6cf6a44c4f7196ae176336b2b1441db88d74dd6
This commit is contained in:
android-build-team Robot
2018-03-01 08:26:13 +00:00
58 changed files with 942 additions and 330 deletions

View File

@@ -313,7 +313,8 @@
<!-- Bluetooth developer settings: Titles for maximum number of connected audio devices -->
<string-array name="bluetooth_max_connected_audio_devices">
<item>1 (Default)</item>
<item>Use System Default: <xliff:g id="default_bluetooth_max_connected_audio_devices">%1$d</xliff:g></item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
@@ -321,7 +322,8 @@
</string-array>
<!-- Bluetooth developer settings: Values for maximum number of connected audio devices -->
<string-array name="bluetooth_max_connected_audio_devices_values">
<string-array translatable="false" name="bluetooth_max_connected_audio_devices_values">
<item></item>
<item>1</item>
<item>2</item>
<item>3</item>

View File

@@ -3371,6 +3371,8 @@
<string name="location_app_level_permissions">App-level permissions</string>
<!-- [CHAR LIMIT=42] Location settings screen, sub category for recent location requests -->
<string name="location_category_recent_location_requests">Recent location requests</string>
<!-- Location settings screen, displayed when there're more than three recent location requests -->
<string name="location_recent_location_requests_see_all">See all</string>
<!-- Location settings screen, displayed when there's no recent app accessing location -->
<string name="location_no_recent_apps">No apps have requested location recently</string>
<!-- [CHAR LIMIT=30] Location settings screen, sub category for location services -->

View File

@@ -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">
<intent android:action="android.intent.action.MANAGE_PERMISSIONS" />
</Preference>
@@ -76,4 +77,4 @@
android:title="@string/special_access"
android:order="20" />
</PreferenceScreen>
</PreferenceScreen>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/location_category_recent_location_requests"
android:key="recent_location_requests_see_all">
<PreferenceCategory
android:key="all_recent_location_requests"/>
</PreferenceScreen>

View File

@@ -24,6 +24,13 @@
android:key="recent_location_requests"
android:title="@string/location_category_recent_location_requests"/>
<Preference
android:key="recent_location_requests_see_all"
android:title="@string/location_recent_location_requests_see_all"
android:icon="@drawable/ic_chevron_right_24dp"
android:selectable="true"
android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"/>
<!-- This preference category gets removed if new_recent_location_ui is disabled -->
<Preference
android:key="app_level_permissions"

View File

@@ -702,16 +702,16 @@ public class SettingsActivity extends SettingsDrawerActivity
|| somethingChanged;
// Enable/disable the Me Card page.
final boolean isMeCardEnabled = featureFactory
final boolean aboutPhoneV2Enabled = featureFactory
.getAccountFeatureProvider()
.isMeCardEnabled(this);
.isAboutPhoneV2Enabled(this);
somethingChanged = setTileEnabled(new ComponentName(packageName,
Settings.MyDeviceInfoActivity.class.getName()),
isMeCardEnabled, isAdmin)
aboutPhoneV2Enabled, isAdmin)
|| somethingChanged;
somethingChanged = setTileEnabled(new ComponentName(packageName,
Settings.DeviceInfoSettingsActivity.class.getName()),
!isMeCardEnabled, isAdmin)
!aboutPhoneV2Enabled, isAdmin)
|| somethingChanged;
if (UserHandle.MU_ENABLED && !isAdmin) {

View File

@@ -49,7 +49,7 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
mSettingsContentObserver = new SettingObserver(settingKey) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateState(null);
updateState(mPreference);
}
};
}
@@ -74,27 +74,19 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
}
@Override
public void updateState(Preference preference) {
if (mPreference == null) {
return;
}
mPreference.setSummary(getSummary());
}
@Override
public String getSummary() {
public CharSequence getSummary() {
final int intensity = Settings.System.getInt(mContext.getContentResolver(),
mSettingKey, getDefaultIntensity());
switch (intensity) {
case Vibrator.VIBRATION_INTENSITY_OFF:
return mContext.getString(R.string.accessibility_vibration_intensity_off);
return mContext.getText(R.string.accessibility_vibration_intensity_off);
case Vibrator.VIBRATION_INTENSITY_LOW:
return mContext.getString(R.string.accessibility_vibration_intensity_low);
return mContext.getText(R.string.accessibility_vibration_intensity_low);
case Vibrator.VIBRATION_INTENSITY_MEDIUM:
return mContext.getString(R.string.accessibility_vibration_intensity_medium);
return mContext.getText(R.string.accessibility_vibration_intensity_medium);
case Vibrator.VIBRATION_INTENSITY_HIGH:
return mContext.getString(R.string.accessibility_vibration_intensity_high);
return mContext.getText(R.string.accessibility_vibration_intensity_high);
default:
return "";
}

View File

@@ -28,7 +28,7 @@ public interface AccountFeatureProvider {
/**
* Checks whether or not to display the new About Phone page.
*/
default boolean isMeCardEnabled(Context context) {
default boolean isAboutPhoneV2Enabled(Context context) {
return FeatureFlagUtils.isEnabled(context, FeatureFlags.ABOUT_PHONE_V2);
}
}

View File

@@ -75,7 +75,6 @@ public class AppAndNotificationDashboardFragment extends DashboardFragment {
controllers.add(new EmergencyBroadcastPreferenceController(context,
"app_and_notif_cell_broadcast_settings"));
controllers.add(new SpecialAppAccessPreferenceController(context));
controllers.add(new AppPermissionsPreferenceController(context));
controllers.add(new RecentAppsPreferenceController(context, app, host));
return controllers;
}

View File

@@ -19,55 +19,40 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.core.BasePreferenceController;
import java.util.List;
import java.util.Set;
public class AppPermissionsPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin {
public class AppPermissionsPreferenceController extends BasePreferenceController {
private static final String TAG = "AppPermissionPrefCtrl";
private static final String KEY_APP_PERMISSION_GROUPS = "manage_perms";
private static final String[] PERMISSION_GROUPS = new String[] {
"android.permission-group.LOCATION",
"android.permission-group.MICROPHONE",
"android.permission-group.CAMERA",
"android.permission-group.SMS",
"android.permission-group.CONTACTS",
"android.permission-group.PHONE"};
"android.permission-group.LOCATION",
"android.permission-group.MICROPHONE",
"android.permission-group.CAMERA",
"android.permission-group.SMS",
"android.permission-group.CONTACTS",
"android.permission-group.PHONE"};
private static final int NUM_PERMISSION_TO_USE = 3;
private final PackageManager mPackageManager;
public AppPermissionsPreferenceController(Context context) {
super(context);
super(context, KEY_APP_PERMISSION_GROUPS);
mPackageManager = context.getPackageManager();
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return KEY_APP_PERMISSION_GROUPS;
}
@Override
public void updateState(Preference preference) {
final String summary = getSummary();
if (summary != null) {
preference.setSummary(summary);
}
public int getAvailabilityStatus() {
return AVAILABLE;
}
/*
@@ -76,7 +61,7 @@ public class AppPermissionsPreferenceController extends AbstractPreferenceContro
Location, Microphone, Camera, Sms, Contacts, and Phone
*/
@Override
public String getSummary() {
public CharSequence getSummary() {
final Set<String> permissions = getAllPermissionsInGroups();
Set<String> grantedPermissionGroups = getGrantedPermissionGroups(permissions);
CharSequence summary = null;
@@ -96,7 +81,7 @@ public class AppPermissionsPreferenceController extends AbstractPreferenceContro
private Set<String> getGrantedPermissionGroups(Set<String> permissions) {
ArraySet<String> grantedPermissionGroups = new ArraySet<>();
List<PackageInfo> 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<PermissionInfo> 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;

View File

@@ -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

View File

@@ -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<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
return DrawOverlayDetails.class;
}
@Override
public String getSummary() {
return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry()).toString();
public CharSequence getSummary() {
return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry());
}
}

View File

@@ -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<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
return WriteSettingsDetails.class;
}
@Override
public String getSummary() {
return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()).toString();
public CharSequence getSummary() {
return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry());
}
}

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -72,7 +72,7 @@ public class BluetoothDeviceRenamePreferenceController extends
}
@Override
public String getSummary() {
public CharSequence getSummary() {
return getDeviceName();
}

View File

@@ -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.

View File

@@ -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);
}
/**

View File

@@ -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(),

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -67,7 +67,7 @@ public class DeviceNamePreferenceController extends BasePreferenceController
}
@Override
public String getSummary() {
public CharSequence getSummary() {
return mDeviceName;
}

View File

@@ -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";

View File

@@ -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

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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<RecentLocationApps.Request> recentLocationRequests =
mRecentLocationApps.getAppListSorted();
final List<Preference> 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);

View File

@@ -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<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle(), this);
}
private static List<AbstractPreferenceController> buildPreferenceControllers(
Context context, Lifecycle lifecycle, RecentLocationRequestSeeAllFragment fragment) {
final List<AbstractPreferenceController> 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<SearchIndexableResource> 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<AbstractPreferenceController> getPreferenceControllers(Context
context) {
return buildPreferenceControllers(
context, /* lifecycle = */ null, /* fragment = */ null);
}
};
}

View File

@@ -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<RecentLocationApps.Request> 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;
}
}

View File

@@ -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();
}
}

View File

@@ -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())) {

View File

@@ -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);

View File

@@ -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<PrintJob> printJobs = mPrintManager.getPrintJobs();
int numActivePrintJobs = 0;
@@ -112,7 +109,7 @@ public class PrintSettingPreferenceController extends BasePreferenceController i
final List<PrintServiceInfo> 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(

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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));

View File

@@ -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");

View File

@@ -1 +1,2 @@
com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard
com.android.settings.search.indexing.FakeSettingsFragment

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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> 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();

View File

@@ -93,7 +93,7 @@ public class AppInfoPreferenceControllerBaseTest {
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> 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());
}

View File

@@ -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

View File

@@ -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<BasePreferenceController> controllersFromXml = PreferenceControllerListHelper
.getPreferenceControllersFromXml(context,
((DashboardFragment) fragment).getPreferenceScreenResId());
final List<BasePreferenceController> uniqueControllerFromXml =
PreferenceControllerListHelper.filterControllers(
controllersFromXml, controllersFromFragment);
controllersFromFragment.addAll(uniqueControllerFromXml);
} catch (Throwable e) {
// Can't do much with exception, assume the test passed.
return true;

View File

@@ -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<Intent> 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<Intent> 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());
}
}

View File

@@ -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);
}
}
}

View File

@@ -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));
}
}

View File

@@ -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));

View File

@@ -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();

View File

@@ -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

View File

@@ -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<RecentLocationApps.Request> requests = new ArrayList<>();
final Request req1 = mock(Request.class);
final Request req2 = mock(Request.class);
requests.add(req1);
requests.add(req2);
List<Request> 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<Request> 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<RecentLocationApps.Request> createMockRequests(int count) {
List<RecentLocationApps.Request> 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;
}
}

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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<String> itemsLeftToFind)
throws Exception {
private void removeItemsAndTakeAction(UiDevice device, ArrayList<String> itemsLeftToFind) {
for (Iterator<String> 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 {
* <p>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<String> itemsLeftToFind = new ArrayList<>(Arrays.asList(itemsToFind));
assertWithMessage("There must be at least one item to search for on the screen!")

View File

@@ -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));
}
}