Snap for 4415813 from c60a52b9aa to pi-release

Change-Id: I91ed33272a2ac02ce4ccc93b5814fae00c968bfe
This commit is contained in:
android-build-team Robot
2017-10-25 08:04:54 +00:00
25 changed files with 726 additions and 413 deletions

View File

@@ -76,7 +76,7 @@
android:id="@+id/no_results_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="96dp"
android:paddingTop="35dp"
android:orientation="vertical"
android:visibility="gone">

View File

@@ -64,9 +64,11 @@
android:key="auto_rotate"
android:title="@string/accelerometer_title" />
<SwitchPreference
<Preference
android:key="color_mode"
android:title="@string/color_mode_title" />
android:title="@string/color_mode_title"
android:fragment="com.android.settings.display.ColorModePreferenceFragment"
settings:keywords="@string/keywords_color_mode" />
<Preference
android:key="font_size"

View File

@@ -67,6 +67,7 @@ public class OwnerInfoSettings extends InstrumentedDialogFragment implements OnC
mOwnerInfo = (EditText) mView.findViewById(R.id.owner_info_edit_text);
if (!TextUtils.isEmpty(info)) {
mOwnerInfo.setText(info);
mOwnerInfo.setSelection(info.length());
}
}

View File

@@ -27,7 +27,6 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
@@ -44,14 +43,12 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.net.DataUsageController;
import java.util.ArrayList;
import java.util.List;
public class DataPlanUsageSummary extends DataUsageBase implements Indexable {
public class DataPlanUsageSummary extends DataUsageBase {
public static final String KEY_DATA_PLAN_USAGE = "data_plan_usage";
@@ -353,50 +350,5 @@ public class DataPlanUsageSummary extends DataUsageBase implements Indexable {
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
= SummaryProvider::new;
/**
* For search
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
List<SearchIndexableResource> resources = new ArrayList<>();
SearchIndexableResource resource = new SearchIndexableResource(context);
resource.xmlResId = R.xml.data_usage;
resources.add(resource);
resource = new SearchIndexableResource(context);
resource.xmlResId = R.xml.data_plan_usage_cell_data_preference_screen;
resources.add(resource);
resource = new SearchIndexableResource(context);
resource.xmlResId = R.xml.data_usage_wifi;
resources.add(resource);
return resources;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
List<String> keys = super.getNonIndexableKeys(context);
if (!DataUsageUtils.hasMobileData(context)) {
keys.add(KEY_MOBILE_USAGE_TITLE);
keys.add(KEY_MOBILE_DATA_USAGE_TOGGLE);
}
if (!DataUsageUtils.hasWifiRadio(context)) {
keys.add(KEY_WIFI_DATA_USAGE);
keys.add(KEY_NETWORK_RESTRICTIONS);
}
keys.add(KEY_WIFI_USAGE_TITLE);
return keys;
}
};
}

View File

@@ -29,7 +29,7 @@ import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class CameraHalHdrPlusPreferenceControllerV2 extends
public class CameraHalHdrplusPreferenceControllerV2 extends
DeveloperOptionsPreferenceController implements
Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
@@ -45,7 +45,7 @@ public class CameraHalHdrPlusPreferenceControllerV2 extends
private SwitchPreference mPreference;
public CameraHalHdrPlusPreferenceControllerV2(Context context) {
public CameraHalHdrplusPreferenceControllerV2(Context context) {
super(context);
}

View File

@@ -376,7 +376,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new LogPersistPreferenceControllerV2(context, fragment, lifecycle));
controllers.add(new ConnectivityMonitorPreferenceControllerV2(context));
controllers.add(new CameraLaserSensorPreferenceControllerV2(context));
controllers.add(new CameraHalHdrPlusPreferenceControllerV2(context));
controllers.add(new CameraHalHdrplusPreferenceControllerV2(context));
controllers.add(new WifiDisplayCertificationPreferenceController(context));
controllers.add(new WifiVerboseLoggingPreferenceController(context));
controllers.add(new WifiAggressiveHandoverPreferenceController(context));

View File

@@ -18,36 +18,24 @@ import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.support.v7.preference.Preference;
import android.support.v7.preference.TwoStatePreference;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
public class ColorModePreferenceController extends AbstractPreferenceController implements
PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
PreferenceControllerMixin {
private static final String TAG = "ColorModePreference";
private static final String KEY_COLOR_MODE = "color_mode";
@VisibleForTesting
static final float COLOR_SATURATION_DEFAULT = 1.0f;
@VisibleForTesting
static final float COLOR_SATURATION_VIVID = 1.1f;
private static final int SURFACE_FLINGER_TRANSACTION_QUERY_WIDE_COLOR = 1024;
private static final int SURFACE_FLINGER_TRANSACTION_SATURATION = 1022;
@VisibleForTesting
static final String PERSISTENT_PROPERTY_SATURATION = "persist.sys.sf.color_saturation";
private final IBinder mSurfaceFlinger;
private final ConfigurationWrapper mConfigWrapper;
public ColorModePreferenceController(Context context) {
super(context);
mSurfaceFlinger = ServiceManager.getService("SurfaceFlinger");
mConfigWrapper = new ConfigurationWrapper(context);
mConfigWrapper = new ConfigurationWrapper();
}
@Override
@@ -55,65 +43,36 @@ public class ColorModePreferenceController extends AbstractPreferenceController
return KEY_COLOR_MODE;
}
@Override
public void updateState(Preference preference) {
TwoStatePreference colorMode = (TwoStatePreference) preference;
colorMode.setChecked(getSaturationValue() > 1.0f);
}
@Override
public boolean isAvailable() {
return mConfigWrapper.isScreenWideColorGamut();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
float saturation = (boolean) newValue
? COLOR_SATURATION_VIVID : COLOR_SATURATION_DEFAULT;
SystemProperties.set(PERSISTENT_PROPERTY_SATURATION, Float.toString(saturation));
applySaturation(saturation);
return true;
}
/**
* Propagates the provided saturation to the SurfaceFlinger.
*/
private void applySaturation(float saturation) {
if (mSurfaceFlinger != null) {
final Parcel data = Parcel.obtain();
data.writeInterfaceToken("android.ui.ISurfaceComposer");
data.writeFloat(saturation);
try {
mSurfaceFlinger.transact(SURFACE_FLINGER_TRANSACTION_SATURATION, data, null, 0);
} catch (RemoteException ex) {
Log.e(TAG, "Failed to set saturation", ex);
} finally {
data.recycle();
}
}
}
private static float getSaturationValue() {
try {
return Float.parseFloat(SystemProperties.get(
PERSISTENT_PROPERTY_SATURATION, Float.toString(COLOR_SATURATION_DEFAULT)));
} catch (NumberFormatException e) {
return COLOR_SATURATION_DEFAULT;
}
}
@VisibleForTesting
static class ConfigurationWrapper {
private final Context mContext;
private final IBinder mSurfaceFlinger;
ConfigurationWrapper(Context context) {
mContext = context;
ConfigurationWrapper() {
mSurfaceFlinger = ServiceManager.getService("SurfaceFlinger");
}
boolean isScreenWideColorGamut() {
return mContext.getResources().getConfiguration().isScreenWideColorGamut();
if (mSurfaceFlinger != null) {
final Parcel data = Parcel.obtain();
final Parcel reply = Parcel.obtain();
data.writeInterfaceToken("android.ui.ISurfaceComposer");
try {
mSurfaceFlinger.transact(SURFACE_FLINGER_TRANSACTION_QUERY_WIDE_COLOR,
data, reply, 0);
return reply.readBoolean();
} catch (RemoteException ex) {
Log.e(TAG, "Failed to query wide color support", ex);
} finally {
data.recycle();
reply.recycle();
}
}
return false;
}
}
}

View File

@@ -0,0 +1,207 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.android.settings.display;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.widget.RadioButtonPickerFragment;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("WeakerAccess")
public class ColorModePreferenceFragment extends RadioButtonPickerFragment {
private static final String TAG = "ColorModePreferenceFragment";
@VisibleForTesting
static final float COLOR_SATURATION_NATURAL = 1.0f;
@VisibleForTesting
static final float COLOR_SATURATION_BOOSTED = 1.1f;
private static final int SURFACE_FLINGER_TRANSACTION_SATURATION = 1022;
private static final int SURFACE_FLINGER_TRANSACTION_NATIVE_MODE = 1023;
@VisibleForTesting
static final String PERSISTENT_PROPERTY_SATURATION = "persist.sys.sf.color_saturation";
@VisibleForTesting
static final String PERSISTENT_PROPERTY_NATIVE_MODE = "persist.sys.sf.native_mode";
@VisibleForTesting
static final String KEY_COLOR_MODE_NATURAL = "color_mode_natural";
@VisibleForTesting
static final String KEY_COLOR_MODE_BOOSTED = "color_mode_boosted";
@VisibleForTesting
static final String KEY_COLOR_MODE_SATURATED = "color_mode_saturated";
private IBinder mSurfaceFlinger;
private IActivityManager mActivityManager;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mSurfaceFlinger = ServiceManager.getService("SurfaceFlinger");
mActivityManager = ActivityManager.getService();
}
@Override
protected List<? extends CandidateInfo> getCandidates() {
Context c = getContext();
return Arrays.asList(
new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_natural),
KEY_COLOR_MODE_NATURAL),
new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_boosted),
KEY_COLOR_MODE_BOOSTED),
new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_saturated),
KEY_COLOR_MODE_SATURATED)
);
}
@Override
protected String getDefaultKey() {
if (isNativeModeEnabled()) {
return KEY_COLOR_MODE_SATURATED;
}
if (getSaturationValue() > COLOR_SATURATION_NATURAL) {
return KEY_COLOR_MODE_BOOSTED;
}
return KEY_COLOR_MODE_NATURAL;
}
@Override
protected boolean setDefaultKey(String key) {
switch (key) {
case KEY_COLOR_MODE_NATURAL:
applySaturation(COLOR_SATURATION_NATURAL);
setNativeMode(false);
break;
case KEY_COLOR_MODE_BOOSTED:
applySaturation(COLOR_SATURATION_BOOSTED);
setNativeMode(false);
break;
case KEY_COLOR_MODE_SATURATED:
applySaturation(COLOR_SATURATION_NATURAL);
setNativeMode(true);
break;
}
updateConfiguration();
return true;
}
@VisibleForTesting
void updateConfiguration() {
try {
mActivityManager.updateConfiguration(null);
} catch (RemoteException e) {
Log.d(TAG, "Could not update configuration", e);
}
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.COLOR_MODE_SETTINGS;
}
/**
* Propagates the provided saturation to the SurfaceFlinger.
*/
private void applySaturation(float saturation) {
SystemProperties.set(PERSISTENT_PROPERTY_SATURATION, Float.toString(saturation));
if (mSurfaceFlinger != null) {
final Parcel data = Parcel.obtain();
data.writeInterfaceToken("android.ui.ISurfaceComposer");
data.writeFloat(saturation);
try {
mSurfaceFlinger.transact(SURFACE_FLINGER_TRANSACTION_SATURATION, data, null, 0);
} catch (RemoteException ex) {
Log.e(TAG, "Failed to set saturation", ex);
} finally {
data.recycle();
}
}
}
private static float getSaturationValue() {
try {
return Float.parseFloat(SystemProperties.get(
PERSISTENT_PROPERTY_SATURATION, Float.toString(COLOR_SATURATION_NATURAL)));
} catch (NumberFormatException e) {
return COLOR_SATURATION_NATURAL;
}
}
/**
* Toggles native mode on/off in SurfaceFlinger.
*/
private void setNativeMode(boolean enabled) {
SystemProperties.set(PERSISTENT_PROPERTY_NATIVE_MODE, enabled ? "1" : "0");
if (mSurfaceFlinger != null) {
final Parcel data = Parcel.obtain();
data.writeInterfaceToken("android.ui.ISurfaceComposer");
data.writeInt(enabled ? 1 : 0);
try {
mSurfaceFlinger.transact(SURFACE_FLINGER_TRANSACTION_NATIVE_MODE, data, null, 0);
} catch (RemoteException ex) {
Log.e(TAG, "Failed to set native mode", ex);
} finally {
data.recycle();
}
}
}
private static boolean isNativeModeEnabled() {
return SystemProperties.getBoolean(PERSISTENT_PROPERTY_NATIVE_MODE, false);
}
@VisibleForTesting
static class ColorModeCandidateInfo extends CandidateInfo {
private final CharSequence mLabel;
private final String mKey;
ColorModeCandidateInfo(CharSequence label, String key) {
super(true);
mLabel = label;
mKey = key;
}
@Override
public CharSequence loadLabel() {
return mLabel;
}
@Override
public Drawable loadIcon() {
return null;
}
@Override
public String getKey() {
return mKey;
}
}
}

View File

@@ -25,6 +25,7 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.provider.SearchIndexableResource;
import android.provider.Settings.Global;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
@@ -38,10 +39,16 @@ import com.android.settings.Utils;
import com.android.settings.dashboard.conditional.BatterySaverCondition;
import com.android.settings.dashboard.conditional.ConditionManager;
import com.android.settings.notification.SettingPref;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.widget.SwitchBar;
import java.util.Arrays;
import java.util.List;
public class BatterySaverSettings extends SettingsPreferenceFragment
implements SwitchBar.OnSwitchChangeListener, BatterySaverReceiver.BatterySaverListener {
implements SwitchBar.OnSwitchChangeListener, BatterySaverReceiver.BatterySaverListener,
Indexable {
private static final String TAG = "BatterySaverSettings";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private static final String KEY_TURN_ON_AUTOMATICALLY = "turn_on_automatically";
@@ -89,7 +96,7 @@ public class BatterySaverSettings extends SettingsPreferenceFragment
protected String getCaption(Resources res, int value) {
if (value > 0 && value < 100) {
return res.getString(R.string.battery_saver_turn_on_automatically_pct,
Utils.formatPercentage(value));
Utils.formatPercentage(value));
}
return res.getString(R.string.battery_saver_turn_on_automatically_never);
}
@@ -219,4 +226,18 @@ public class BatterySaverSettings extends SettingsPreferenceFragment
}
}
}
/**
* 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.battery_saver_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -27,6 +27,7 @@ import android.location.SettingInjectorService;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceGroup;
@@ -40,6 +41,8 @@ import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
@@ -47,6 +50,7 @@ import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.location.RecentLocationApps;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -77,7 +81,7 @@ import java.util.List;
* implementation.
*/
public class LocationSettings extends LocationSettingsBase
implements SwitchBar.OnSwitchChangeListener {
implements SwitchBar.OnSwitchChangeListener, Indexable {
private static final String TAG = "LocationSettings";
@@ -455,4 +459,18 @@ public class LocationSettings extends LocationSettingsBase
return new SummaryProvider(activity, summaryLoader);
}
};
/**
* 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_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -16,6 +16,8 @@
package com.android.settings.location;
import android.content.Context;
import android.provider.SearchIndexableResource;
import android.provider.Settings.Global;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
@@ -24,11 +26,16 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import java.util.Arrays;
import java.util.List;
/**
* A page that configures the background scanning settings for Wi-Fi and Bluetooth.
*/
public class ScanningSettings extends SettingsPreferenceFragment {
public class ScanningSettings extends SettingsPreferenceFragment implements Indexable {
private static final String KEY_WIFI_SCAN_ALWAYS_AVAILABLE = "wifi_always_scanning";
private static final String KEY_BLUETOOTH_SCAN_ALWAYS_AVAILABLE = "bluetooth_always_scanning";
@@ -56,13 +63,13 @@ public class ScanningSettings extends SettingsPreferenceFragment {
private void initPreferences() {
final SwitchPreference wifiScanAlwaysAvailable =
(SwitchPreference) findPreference(KEY_WIFI_SCAN_ALWAYS_AVAILABLE);
(SwitchPreference) findPreference(KEY_WIFI_SCAN_ALWAYS_AVAILABLE);
wifiScanAlwaysAvailable.setChecked(Global.getInt(getContentResolver(),
Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1);
Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1);
final SwitchPreference bleScanAlwaysAvailable =
(SwitchPreference) findPreference(KEY_BLUETOOTH_SCAN_ALWAYS_AVAILABLE);
(SwitchPreference) findPreference(KEY_BLUETOOTH_SCAN_ALWAYS_AVAILABLE);
bleScanAlwaysAvailable.setChecked(Global.getInt(getContentResolver(),
Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1);
Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1);
}
@Override
@@ -81,4 +88,18 @@ public class ScanningSettings extends SettingsPreferenceFragment {
}
return true;
}
/**
* 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_scanning;
return Arrays.asList(sir);
}
};
}

View File

@@ -18,7 +18,9 @@ package com.android.settings.notification;
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.content.Context;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.support.v14.preference.SwitchPreference;
@@ -30,8 +32,13 @@ import android.util.Log;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
public class ZenModeBehaviorSettings extends ZenModeSettingsBase {
import java.util.Arrays;
import java.util.List;
public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Indexable {
private static final String KEY_ALARMS = "zen_mode_alarms";
private static final String KEY_MEDIA = "zen_mode_media";
private static final String KEY_REMINDERS = "zen_mode_reminders";
@@ -303,4 +310,18 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase {
NotificationManager.from(mContext).setNotificationPolicy(mPolicy);
}
/**
* 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.zen_mode_behavior_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -29,6 +29,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.service.notification.ConditionProviderService;
import android.service.notification.ZenModeConfig;
@@ -41,6 +42,8 @@ import android.view.View;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.utils.ManagedServiceSettings;
import com.android.settings.utils.ZenServiceListing;
import com.android.settingslib.TwoTargetPreference;
@@ -52,7 +55,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class ZenModeSettings extends ZenModeSettingsBase {
public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
public static final String KEY_VISUAL_SETTINGS = "zen_mode_visual_interruptions_settings";
private static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
@@ -499,4 +502,17 @@ public class ZenModeSettings extends ZenModeSettingsBase {
return type + rule.getName().toString();
}
};
/**
* 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.zen_mode_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -18,7 +18,9 @@ package com.android.settings.notification;
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.content.Context;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -26,8 +28,13 @@ import android.util.Log;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase {
import java.util.Arrays;
import java.util.List;
public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase implements Indexable {
private static final String KEY_SCREEN_OFF = "screenOff";
private static final String KEY_SCREEN_ON = "screenOn";
@@ -122,4 +129,18 @@ public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase {
suppressedVisualEffects);
NotificationManager.from(mContext).setNotificationPolicy(mPolicy);
}
/**
* 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.zen_mode_visual_interruptions_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -26,7 +26,6 @@ import com.android.settings.DeviceInfoSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.EncryptionAndCredential;
import com.android.settings.LegalSettings;
import com.android.settings.R;
import com.android.settings.ScreenPinningSettings;
import com.android.settings.SecuritySettings;
import com.android.settings.accessibility.AccessibilitySettings;
@@ -41,7 +40,6 @@ import com.android.settings.backup.BackupSettingsActivity;
import com.android.settings.backup.BackupSettingsFragment;
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.datausage.DataPlanUsageSummary;
import com.android.settings.datausage.DataUsageMeteredSettings;
import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
@@ -109,15 +107,15 @@ public final class SearchIndexableResources {
static final HashMap<String, SearchIndexableResource> sResMap = new HashMap<>();
@VisibleForTesting
static void addIndex(Class<?> indexClass, @XmlRes int xmlResId) {
addIndex(indexClass, xmlResId, null /* targetAction */);
static void addIndex(Class<?> indexClass) {
addIndex(indexClass, null /* targetAction */);
}
@VisibleForTesting
static void addIndex(Class<?> indexClass, @XmlRes int xmlResId, String targetAction) {
static void addIndex(Class<?> indexClass, String targetAction) {
String className = indexClass.getName();
SearchIndexableResource resource = new SearchIndexableResource(0, xmlResId, className,
NO_RES_ID);
SearchIndexableResource resource = new SearchIndexableResource(
0 /* rank */, NO_RES_ID, className, NO_RES_ID);
if (!TextUtils.isEmpty(targetAction)) {
resource.intentAction = targetAction;
@@ -128,75 +126,73 @@ public final class SearchIndexableResources {
}
static {
addIndex(WifiSettings.class, NO_RES_ID);
addIndex(NetworkDashboardFragment.class, NO_RES_ID);
addIndex(ConfigureWifiSettings.class, NO_RES_ID);
addIndex(SavedAccessPointsWifiSettings.class, NO_RES_ID);
addIndex(BluetoothSettings.class, NO_RES_ID);
addIndex(SimSettings.class, NO_RES_ID);
addIndex(DataPlanUsageSummary.class, NO_RES_ID);
addIndex(DataUsageSummary.class, NO_RES_ID);
addIndex(DataUsageMeteredSettings.class, NO_RES_ID);
addIndex(ScreenZoomSettings.class, NO_RES_ID);
addIndex(DisplaySettings.class, NO_RES_ID, "android.settings.DISPLAY_SETTINGS");
addIndex(AmbientDisplaySettings.class, NO_RES_ID);
addIndex(WallpaperTypeSettings.class, NO_RES_ID);
addIndex(AppAndNotificationDashboardFragment.class, NO_RES_ID);
addIndex(SoundSettings.class, NO_RES_ID, "android.settings.SOUND_SETTINGS");
addIndex(ZenModeSettings.class, R.xml.zen_mode_settings);
addIndex(StorageSettings.class, NO_RES_ID);
addIndex(PowerUsageAdvanced.class, NO_RES_ID);
addIndex(DefaultAppSettings.class, NO_RES_ID);
addIndex(ManageAssist.class, NO_RES_ID);
addIndex(SpecialAccessSettings.class, NO_RES_ID);
addIndex(UserSettings.class, NO_RES_ID);
addIndex(AssistGestureSettings.class, NO_RES_ID);
addIndex(PickupGestureSettings.class, NO_RES_ID);
addIndex(DoubleTapScreenSettings.class, NO_RES_ID);
addIndex(DoubleTapPowerSettings.class, NO_RES_ID);
addIndex(DoubleTwistGestureSettings.class, NO_RES_ID);
addIndex(SwipeToNotificationSettings.class, NO_RES_ID);
addIndex(GestureSettings.class, NO_RES_ID);
addIndex(LanguageAndInputSettings.class, NO_RES_ID);
addIndex(LocationSettings.class, R.xml.location_settings);
addIndex(ScanningSettings.class, R.xml.location_scanning);
addIndex(SecuritySettings.class, NO_RES_ID);
addIndex(EncryptionAndCredential.class, NO_RES_ID);
addIndex(ScreenPinningSettings.class, NO_RES_ID);
addIndex(UserAndAccountDashboardFragment.class, NO_RES_ID);
addIndex(VirtualKeyboardFragment.class, NO_RES_ID);
addIndex(AvailableVirtualKeyboardFragment.class, NO_RES_ID);
addIndex(PhysicalKeyboardFragment.class, NO_RES_ID);
addIndex(BackupSettingsActivity.class, NO_RES_ID);
addIndex(BackupSettingsFragment.class, NO_RES_ID);
addIndex(DateTimeSettings.class, NO_RES_ID);
addIndex(AccessibilitySettings.class, NO_RES_ID);
addIndex(PrintSettingsFragment.class, NO_RES_ID);
addIndex(DevelopmentSettingsDashboardFragment.class, NO_RES_ID);
addIndex(DeviceInfoSettings.class, NO_RES_ID);
addIndex(Status.class, NO_RES_ID);
addIndex(LegalSettings.class, NO_RES_ID);
addIndex(SystemDashboardFragment.class, NO_RES_ID);
addIndex(ResetDashboardFragment.class, NO_RES_ID);
addIndex(StorageDashboardFragment.class, NO_RES_ID);
addIndex(ConnectedDeviceDashboardFragment.class, NO_RES_ID);
addIndex(EnterprisePrivacySettings.class, NO_RES_ID);
addIndex(PaymentSettings.class, NO_RES_ID);
addIndex(TextToSpeechSettings.class, NO_RES_ID);
addIndex(TtsEnginePreferenceFragment.class, NO_RES_ID);
addIndex(MagnificationPreferenceFragment.class, NO_RES_ID);
addIndex(AccessibilityShortcutPreferenceFragment.class, NO_RES_ID);
addIndex(ChannelImportanceSettings.class, NO_RES_ID);
addIndex(DreamSettings.class, NO_RES_ID);
addIndex(SupportDashboardActivity.class, NO_RES_ID);
addIndex(AutomaticStorageManagerSettings.class, NO_RES_ID);
addIndex(ConfigureNotificationSettings.class, R.xml.configure_notification_settings);
addIndex(ZenModeBehaviorSettings.class, R.xml.zen_mode_behavior_settings);
addIndex(PowerUsageSummary.class, R.xml.power_usage_summary);
addIndex(BatterySaverSettings.class, R.xml.battery_saver_settings);
addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings);
addIndex(ZenModeVisualInterruptionSettings.class,
R.xml.zen_mode_visual_interruptions_settings);
addIndex(WifiSettings.class);
addIndex(NetworkDashboardFragment.class);
addIndex(ConfigureWifiSettings.class);
addIndex(SavedAccessPointsWifiSettings.class);
addIndex(BluetoothSettings.class);
addIndex(SimSettings.class);
addIndex(DataUsageSummary.class);
addIndex(DataUsageMeteredSettings.class);
addIndex(ScreenZoomSettings.class);
addIndex(DisplaySettings.class, "android.settings.DISPLAY_SETTINGS");
addIndex(AmbientDisplaySettings.class);
addIndex(WallpaperTypeSettings.class);
addIndex(AppAndNotificationDashboardFragment.class);
addIndex(SoundSettings.class, "android.settings.SOUND_SETTINGS");
addIndex(ZenModeSettings.class);
addIndex(StorageSettings.class);
addIndex(PowerUsageAdvanced.class);
addIndex(DefaultAppSettings.class);
addIndex(ManageAssist.class);
addIndex(SpecialAccessSettings.class);
addIndex(UserSettings.class);
addIndex(AssistGestureSettings.class);
addIndex(PickupGestureSettings.class);
addIndex(DoubleTapScreenSettings.class);
addIndex(DoubleTapPowerSettings.class);
addIndex(DoubleTwistGestureSettings.class);
addIndex(SwipeToNotificationSettings.class);
addIndex(GestureSettings.class);
addIndex(LanguageAndInputSettings.class);
addIndex(LocationSettings.class);
addIndex(ScanningSettings.class);
addIndex(SecuritySettings.class);
addIndex(EncryptionAndCredential.class);
addIndex(ScreenPinningSettings.class);
addIndex(UserAndAccountDashboardFragment.class);
addIndex(VirtualKeyboardFragment.class);
addIndex(AvailableVirtualKeyboardFragment.class);
addIndex(PhysicalKeyboardFragment.class);
addIndex(BackupSettingsActivity.class);
addIndex(BackupSettingsFragment.class);
addIndex(DateTimeSettings.class);
addIndex(AccessibilitySettings.class);
addIndex(PrintSettingsFragment.class);
addIndex(DevelopmentSettingsDashboardFragment.class);
addIndex(DeviceInfoSettings.class);
addIndex(Status.class);
addIndex(LegalSettings.class);
addIndex(SystemDashboardFragment.class);
addIndex(ResetDashboardFragment.class);
addIndex(StorageDashboardFragment.class);
addIndex(ConnectedDeviceDashboardFragment.class);
addIndex(EnterprisePrivacySettings.class);
addIndex(PaymentSettings.class);
addIndex(TextToSpeechSettings.class);
addIndex(TtsEnginePreferenceFragment.class);
addIndex(MagnificationPreferenceFragment.class);
addIndex(AccessibilityShortcutPreferenceFragment.class);
addIndex(ChannelImportanceSettings.class);
addIndex(DreamSettings.class);
addIndex(SupportDashboardActivity.class);
addIndex(AutomaticStorageManagerSettings.class);
addIndex(ConfigureNotificationSettings.class);
addIndex(PowerUsageSummary.class);
addIndex(BatterySaverSettings.class);
addIndex(LockscreenDashboardFragment.class);
addIndex(ZenModeBehaviorSettings.class);
addIndex(ZenModeVisualInterruptionSettings.class);
}
private SearchIndexableResources() {

View File

@@ -30,7 +30,6 @@ import android.util.Log;
import android.util.Xml;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.Indexable;
import com.android.settings.search.ResultPayload;
@@ -44,7 +43,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -310,8 +308,8 @@ public class IndexDataConverter {
} catch (XmlPullParserException e) {
Log.w(LOG_TAG, "XML Error parsing PreferenceScreen: ", e);
} catch (IOException e) {
Log.w(LOG_TAG, "IO Error parsing PreferenceScreen: " , e);
} catch (Resources.NotFoundException e ) {
Log.w(LOG_TAG, "IO Error parsing PreferenceScreen: ", e);
} catch (Resources.NotFoundException e) {
Log.w(LOG_TAG, "Resoucre not found error parsing PreferenceScreen: ", e);
} finally {
if (parser != null) parser.close();

View File

@@ -1,5 +1,4 @@
com.android.settings.location.LocationMode
com.android.settings.notification.ZenModeVisualInterruptionSettings
com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment
com.android.settings.deviceinfo.SimStatus
com.android.settings.deviceinfo.PrivateVolumeForget
@@ -23,18 +22,16 @@ com.android.settings.datausage.DataSaverSummary
com.android.settings.notification.ChannelNotificationSettings
com.android.settings.notification.ChannelGroupNotificationSettings
com.android.settings.datausage.AppDataUsage
com.android.settings.datausage.DataPlanUsageSummary
com.android.settings.accessibility.FontSizePreferenceFragmentForSetupWizard
com.android.settings.applications.ManageDomainUrls
com.android.settings.applications.WriteSettingsDetails
com.android.settings.location.LocationSettings
com.android.settings.applications.ProcessStatsSummary
com.android.settings.users.RestrictedProfileSettings
com.android.settings.accounts.ChooseAccountActivity
com.android.settings.accounts.ManagedProfileSettings
com.android.settings.accessibility.ToggleAutoclickPreferenceFragment
com.android.settings.applications.AppLaunchSettings
com.android.settings.fuelgauge.BatterySaverSettings
com.android.settings.location.ScanningSettings
com.android.settings.applications.ProcessStatsUi
com.android.settings.notification.ZenModeScheduleRuleSettings
com.android.settings.datausage.BillingCycleSettings
@@ -68,8 +65,6 @@ com.android.settings.applications.PremiumSmsAccess
com.android.settings.applications.UsageAccessDetails
com.android.settings.applications.AppStorageSettings
com.android.settings.notification.NotificationAccessSettings
com.android.settings.notification.ZenModeSettings
com.android.settings.notification.ZenModeBehaviorSettings
com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment
com.android.settings.localepicker.LocaleListEditor
com.android.settings.applications.ExternalSourcesDetails

View File

@@ -33,17 +33,13 @@ import android.net.wifi.WifiManager;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
import com.android.settingslib.NetworkPolicyEditor;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@@ -128,53 +124,6 @@ public class DataPlanUsageSummaryTest {
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
}
@Test
@Config(shadows = ShadowDataUsageUtils.class)
public void testNonIndexableKeys_existInXmlLayout() {
final Context context = RuntimeEnvironment.application;
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
final List<String> niks = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(context);
final List<String> keys = new ArrayList<>();
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_wifi));
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage));
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context,
R.xml.data_plan_usage_cell_data_preference_screen));
assertThat(keys).containsAllIn(niks);
}
@Test
@Config(shadows = ShadowDataUsageUtils.class)
public void testNonIndexableKeys_hasMobileData_hasWifi_allNonIndexableKeysAdded() {
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = false;
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = false;
List<String> keys = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mContext);
// Mobile data keys
assertThat(keys).contains(DataPlanUsageSummary.KEY_MOBILE_USAGE_TITLE);
assertThat(keys).contains(DataPlanUsageSummary.KEY_MOBILE_DATA_USAGE_TOGGLE);
// Wifi keys
assertThat(keys).contains(DataPlanUsageSummary.KEY_WIFI_DATA_USAGE);
assertThat(keys).contains(DataPlanUsageSummary.KEY_NETWORK_RESTRICTIONS);
assertThat(keys).contains(DataPlanUsageSummary.KEY_WIFI_USAGE_TITLE);
}
@Test
@Config(shadows = ShadowDataUsageUtils.class)
public void testNonIndexableKeys_noMobile_noWifi_limitedNonIndexableKeys() {
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
List<String> keys = DataPlanUsageSummary.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mContext);
assertThat(keys).containsExactly(DataPlanUsageSummary.KEY_WIFI_USAGE_TITLE);
}
private void initTest() {
mDataUsageSummary = new DataPlanUsageSummary();
mPolicyEditor = mock(NetworkPolicyEditor.class);

View File

@@ -42,7 +42,7 @@ import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {SettingsShadowSystemProperties.class})
public class CameraHalHdrPlusPreferenceControllerV2Test {
public class CameraHalHdrplusPreferenceControllerV2Test {
@Mock
private PreferenceScreen mScreen;
@@ -50,7 +50,7 @@ public class CameraHalHdrPlusPreferenceControllerV2Test {
private SwitchPreference mPreference;
private Context mContext;
private CameraHalHdrPlusPreferenceControllerV2 mController;
private CameraHalHdrplusPreferenceControllerV2 mController;
static final String USERDEBUG_BUILD = "userdebug";
@@ -58,7 +58,7 @@ public class CameraHalHdrPlusPreferenceControllerV2Test {
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new CameraHalHdrPlusPreferenceControllerV2(mContext);
mController = new CameraHalHdrplusPreferenceControllerV2(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
mController.displayPreference(mScreen);
@@ -73,18 +73,18 @@ public class CameraHalHdrPlusPreferenceControllerV2Test {
@Config(qualifiers = "mcc999")
public void isAvailable_withConfigNoShowAndUserDebugBuild_shouldReturnFalse() {
SettingsShadowSystemProperties.set(
CameraHalHdrPlusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
CameraHalHdrplusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void updateState_cameraHalHdrPlusEnabled_shouldCheckedPreference() {
public void updateState_cameraHalHdrplusEnabled_shouldCheckedPreference() {
SettingsShadowSystemProperties.set(
CameraHalHdrPlusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrPlusPreferenceControllerV2.ENABLED);
CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrplusPreferenceControllerV2.ENABLED);
SettingsShadowSystemProperties.set(
CameraHalHdrPlusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
CameraHalHdrplusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mPreference);
@@ -92,12 +92,12 @@ public class CameraHalHdrPlusPreferenceControllerV2Test {
}
@Test
public void updateState_cameraHalHdrPlusEnabled_shouldUncheckedPreference() {
public void updateState_cameraHalHdrplusEnabled_shouldUncheckedPreference() {
SettingsShadowSystemProperties.set(
CameraHalHdrPlusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrPlusPreferenceControllerV2.DISABLED);
CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrplusPreferenceControllerV2.DISABLED);
SettingsShadowSystemProperties.set(
CameraHalHdrPlusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
CameraHalHdrplusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
mController.updateState(mPreference);
@@ -108,20 +108,20 @@ public class CameraHalHdrPlusPreferenceControllerV2Test {
public void onPreferenceChange_preferenceChecked_shouldEnableCameraHalHdrplus() {
mController.onPreferenceChange(mPreference, true /* new value */);
assertThat(CameraHalHdrPlusPreferenceControllerV2.ENABLED).isEqualTo(
assertThat(CameraHalHdrplusPreferenceControllerV2.ENABLED).isEqualTo(
SystemProperties.get(
CameraHalHdrPlusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrPlusPreferenceControllerV2.DISABLED));
CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrplusPreferenceControllerV2.DISABLED));
}
@Test
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableCameraHalHdrplus() {
mController.onPreferenceChange(mPreference, false /* new value */);
assertThat(CameraHalHdrPlusPreferenceControllerV2.DISABLED).isEqualTo(
assertThat(CameraHalHdrplusPreferenceControllerV2.DISABLED).isEqualTo(
SystemProperties.get(
CameraHalHdrPlusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrPlusPreferenceControllerV2.DISABLED));
CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrplusPreferenceControllerV2.DISABLED));
}
@Test
@@ -137,9 +137,9 @@ public class CameraHalHdrPlusPreferenceControllerV2Test {
verify(mPreference).setEnabled(false);
verify(mPreference).setChecked(false);
assertThat(CameraHalHdrPlusPreferenceControllerV2.DISABLED).isEqualTo(
assertThat(CameraHalHdrplusPreferenceControllerV2.DISABLED).isEqualTo(
SystemProperties.get(
CameraHalHdrPlusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrPlusPreferenceControllerV2.DISABLED));
CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
CameraHalHdrplusPreferenceControllerV2.DISABLED));
}
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.display;
import android.content.Context;
import android.os.IBinder;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ColorModePreferenceControllerTest {
@Mock
private ColorModePreferenceController.ConfigurationWrapper mConfigWrapper;
@Mock
private SwitchPreference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private Context mContext;
@Mock
private IBinder mSurfaceFlinger;
private ColorModePreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
SettingsShadowSystemProperties.clear();
mController = new ColorModePreferenceController(mContext);
ReflectionHelpers.setField(mController, "mSurfaceFlinger", mSurfaceFlinger);
ReflectionHelpers.setField(mController, "mConfigWrapper", mConfigWrapper);
when(mConfigWrapper.isScreenWideColorGamut()).thenReturn(true);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void shouldCheckPreference() {
SettingsShadowSystemProperties.set(
ColorModePreferenceController.PERSISTENT_PROPERTY_SATURATION,
Float.toString(ColorModePreferenceController.COLOR_SATURATION_VIVID));
mController.updateState(mPreference);
verify(mPreference).setChecked(true);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void shouldUncheckPreference() {
SettingsShadowSystemProperties.set(
ColorModePreferenceController.PERSISTENT_PROPERTY_SATURATION,
Float.toString(ColorModePreferenceController.COLOR_SATURATION_DEFAULT));
mController.updateState(mPreference);
verify(mPreference).setChecked(false);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void shouldBoostSaturationOnCheck() {
mController.onPreferenceChange(mPreference, true);
String saturation = SettingsShadowSystemProperties
.get(ColorModePreferenceController.PERSISTENT_PROPERTY_SATURATION);
assertThat(saturation)
.isEqualTo(Float.toString(ColorModePreferenceController.COLOR_SATURATION_VIVID));
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void shouldResetSaturationOnUncheck() {
mController.onPreferenceChange(mPreference, false);
String saturation = SettingsShadowSystemProperties
.get(ColorModePreferenceController.PERSISTENT_PROPERTY_SATURATION);
assertThat(saturation)
.isEqualTo(Float.toString(ColorModePreferenceController.COLOR_SATURATION_DEFAULT));
}
}

View File

@@ -0,0 +1,170 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.display;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.app.IActivityManager;
import android.content.res.Configuration;
import android.os.IBinder;
import android.os.RemoteException;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import com.android.settings.widget.RadioButtonPickerFragment;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ColorModePreferenceFragmentTest {
@Mock
private IBinder mSurfaceFlinger;
@Mock
private IActivityManager mActivityManager;
private ColorModePreferenceFragment mFragment;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
SettingsShadowSystemProperties.clear();
mFragment = spy(new ColorModePreferenceFragment());
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
doNothing().when(mFragment).updateConfiguration();
ReflectionHelpers.setField(mFragment, "mSurfaceFlinger", mSurfaceFlinger);
ReflectionHelpers.setField(mFragment, "mActivityManager", mActivityManager);
}
@Test
public void verifyMetricsConstant() {
assertThat(mFragment.getMetricsCategory())
.isEqualTo(MetricsProto.MetricsEvent.COLOR_MODE_SETTINGS);
}
@Test
public void getCandidates() {
List<? extends RadioButtonPickerFragment.CandidateInfo> candidates =
mFragment.getCandidates();
assertThat(candidates.size()).isEqualTo(3);
assertThat(candidates.get(0).getKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_NATURAL);
assertThat(candidates.get(1).getKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_BOOSTED);
assertThat(candidates.get(2).getKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_SATURATED);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void getKey_natural() {
SettingsShadowSystemProperties.set(
ColorModePreferenceFragment.PERSISTENT_PROPERTY_SATURATION,
Float.toString(ColorModePreferenceFragment.COLOR_SATURATION_NATURAL));
SettingsShadowSystemProperties.set(
ColorModePreferenceFragment.PERSISTENT_PROPERTY_NATIVE_MODE, "0");
assertThat(mFragment.getDefaultKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_NATURAL);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void getKey_boosted() {
SettingsShadowSystemProperties.set(
ColorModePreferenceFragment.PERSISTENT_PROPERTY_SATURATION,
Float.toString(ColorModePreferenceFragment.COLOR_SATURATION_BOOSTED));
SettingsShadowSystemProperties.set(
ColorModePreferenceFragment.PERSISTENT_PROPERTY_NATIVE_MODE, "0");
assertThat(mFragment.getDefaultKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_BOOSTED);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void getKey_saturated() {
SettingsShadowSystemProperties.set(
ColorModePreferenceFragment.PERSISTENT_PROPERTY_NATIVE_MODE, "1");
assertThat(mFragment.getDefaultKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_SATURATED);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void setKey_natural() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_NATURAL);
String saturation = SettingsShadowSystemProperties
.get(ColorModePreferenceFragment.PERSISTENT_PROPERTY_SATURATION);
assertThat(saturation)
.isEqualTo(Float.toString(ColorModePreferenceFragment.COLOR_SATURATION_NATURAL));
String nativeMode = SettingsShadowSystemProperties
.get(ColorModePreferenceFragment.PERSISTENT_PROPERTY_NATIVE_MODE);
assertThat(nativeMode).isEqualTo("0");
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void setKey_boosted() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_BOOSTED);
String saturation = SettingsShadowSystemProperties
.get(ColorModePreferenceFragment.PERSISTENT_PROPERTY_SATURATION);
assertThat(saturation)
.isEqualTo(Float.toString(ColorModePreferenceFragment.COLOR_SATURATION_BOOSTED));
String nativeMode = SettingsShadowSystemProperties
.get(ColorModePreferenceFragment.PERSISTENT_PROPERTY_NATIVE_MODE);
assertThat(nativeMode).isEqualTo("0");
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void setKey_saturated() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_SATURATED);
String saturation = SettingsShadowSystemProperties
.get(ColorModePreferenceFragment.PERSISTENT_PROPERTY_SATURATION);
assertThat(saturation)
.isEqualTo(Float.toString(ColorModePreferenceFragment.COLOR_SATURATION_NATURAL));
String nativeMode = SettingsShadowSystemProperties
.get(ColorModePreferenceFragment.PERSISTENT_PROPERTY_NATIVE_MODE);
assertThat(nativeMode).isEqualTo("1");
}
}

View File

@@ -18,7 +18,9 @@ package com.android.settings.fuelgauge;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.SwitchBar;
@@ -30,6 +32,8 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BatterySaverSettingsTest {
@@ -58,4 +62,13 @@ public class BatterySaverSettingsTest {
assertThat(mBatterySaverSettings.mSwitchBar.isEnabled()).isTrue();
}
@Test
public void searchProvider_shouldIndexDefaultXml() {
final List<SearchIndexableResource> sir = mBatterySaverSettings.SEARCH_INDEX_DATA_PROVIDER
.getXmlResourcesToIndex(mContext, true /* enabled */);
assertThat(sir).hasSize(1);
assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.battery_saver_settings);
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.SearchIndexableResource;
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.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ScanningSettingsTest {
private Context mContext;
private ScanningSettings mSettings;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mSettings = new ScanningSettings();
}
@Test
public void searchProvider_shouldIndexDefaultXml() {
final List<SearchIndexableResource> sir = mSettings.SEARCH_INDEX_DATA_PROVIDER
.getXmlResourcesToIndex(mContext, true /* enabled */);
assertThat(sir).hasSize(1);
assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.location_scanning);
}
}

View File

@@ -22,6 +22,7 @@ import static junit.framework.Assert.assertTrue;
import android.app.NotificationManager;
import android.content.Context;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import com.android.settings.R;
@@ -34,16 +35,20 @@ import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ZenModeSettingsTest {
private ZenModeSettings.SummaryBuilder mBuilder;
private Context mContext;
private ZenModeSettings mSettings;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application.getApplicationContext();
mSettings = new ZenModeSettings();
mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
}
@@ -72,4 +77,13 @@ public class ZenModeSettingsTest {
&& result.indexOf(reminders) < result.indexOf(events));
}
@Test
public void searchProvider_shouldIndexDefaultXml() {
final List<SearchIndexableResource> sir = mSettings.SEARCH_INDEX_DATA_PROVIDER
.getXmlResourcesToIndex(mContext, true /* enabled */);
assertThat(sir).hasSize(1);
assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.zen_mode_settings);
}
}

View File

@@ -18,18 +18,15 @@ package com.android.settings.search;
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
import static com.android.settings.search.SearchIndexableResources.NO_RES_ID;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.annotation.XmlRes;
import android.database.Cursor;
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wifi.WifiSettings;
import org.junit.After;
@@ -45,9 +42,6 @@ import java.util.Map;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SearchIndexableResourcesTest {
@XmlRes
private static final int XML_RES_ID = R.xml.physical_keyboard_settings;
Map<String, SearchIndexableResource> sResMapCopy;
@Before
@@ -69,13 +63,13 @@ public class SearchIndexableResourcesTest {
assertThat(SearchIndexableResources.getResourceByName("java.lang.String")).isNull();
final int beforeCount = SearchIndexableResources.values().size();
SearchIndexableResources.addIndex(java.lang.String.class, XML_RES_ID);
SearchIndexableResources.addIndex(java.lang.String.class);
final SearchIndexableResource index = SearchIndexableResources
.getResourceByName("java.lang.String");
assertThat(index).isNotNull();
assertThat(index.className).isEqualTo("java.lang.String");
assertThat(index.xmlResId).isEqualTo(XML_RES_ID);
assertThat(index.xmlResId).isEqualTo(NO_RES_ID);
assertThat(index.iconResId).isEqualTo(NO_RES_ID);
final int afterCount = SearchIndexableResources.values().size();
assertThat(afterCount).isEqualTo(beforeCount + 1);
@@ -95,13 +89,13 @@ public class SearchIndexableResourcesTest {
@Test
public void testNonIndexableKeys_GetsKeyFromProvider() {
SearchIndexableResources.sResMap.clear();
SearchIndexableResources.addIndex(FakeIndexProvider.class, 0);
SearchIndexableResources.addIndex(FakeIndexProvider.class);
SettingsSearchIndexablesProvider provider = spy(new SettingsSearchIndexablesProvider());
Cursor cursor = provider.queryNonIndexableKeys(null);
boolean hasTestKey = false;
while(cursor.moveToNext()) {
while (cursor.moveToNext()) {
String key = cursor.getString(COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE);
if (TextUtils.equals(key, FakeIndexProvider.KEY)) {
hasTestKey = true;