Instantiate pref controllers from xml if it's defined.
- If a <preference> tag also defines a controller, we will try to instantiate it before displaying the UI. The same logic is shared by BaseSearchIndexProvider so it also drives search suppression. - If user also defines a list of controllers programatically, the programatically created ones takes precedence. Bug: 73668763 Test: WIP Change-Id: I7aecec270bcd3af261e012ef1f6995d2a523cfa1
This commit is contained in:
@@ -4,6 +4,15 @@
|
|||||||
# Keep all Fragments in this package, which are used by reflection.
|
# Keep all Fragments in this package, which are used by reflection.
|
||||||
-keep public class com.android.settings.** extends android.app.Fragment
|
-keep public class com.android.settings.** extends android.app.Fragment
|
||||||
|
|
||||||
|
# Keep all preference controllers needed by slice and DashboardFragment.
|
||||||
|
-keep class * extends com.android.settings.core.BasePreferenceController {
|
||||||
|
*;
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class * extends com.android.settings.core.TogglePreferenceController {
|
||||||
|
*;
|
||||||
|
}
|
||||||
|
|
||||||
# We want to keep methods in Activity that could be used in the XML attribute onClick.
|
# We want to keep methods in Activity that could be used in the XML attribute onClick.
|
||||||
-keepclassmembers class * extends android.app.Activity {
|
-keepclassmembers class * extends android.app.Activity {
|
||||||
public void *(android.view.View);
|
public void *(android.view.View);
|
||||||
|
@@ -45,14 +45,18 @@ public class BluetoothDetailsMacAddressController extends BluetoothDetailsContro
|
|||||||
protected void init(PreferenceScreen screen) {
|
protected void init(PreferenceScreen screen) {
|
||||||
mFooterPreference = mFooterPreferenceMixin.createFooterPreference();
|
mFooterPreference = mFooterPreferenceMixin.createFooterPreference();
|
||||||
mFooterPreference.setTitle(mContext.getString(
|
mFooterPreference.setTitle(mContext.getString(
|
||||||
R.string.bluetooth_device_mac_address, mCachedDevice.getAddress()));
|
R.string.bluetooth_device_mac_address, mCachedDevice.getAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refresh() {}
|
protected void refresh() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
|
if (mFooterPreference == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return mFooterPreference.getKey();
|
return mFooterPreference.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -119,15 +119,7 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AbstractPreferenceController> getPreferenceControllers(
|
|
||||||
Context context) {
|
|
||||||
//TODO(b/69333961): update the index for controllers
|
|
||||||
return super.getPreferenceControllers(context);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -116,6 +116,9 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
|||||||
public BasePreferenceController(Context context, String preferenceKey) {
|
public BasePreferenceController(Context context, String preferenceKey) {
|
||||||
super(context);
|
super(context);
|
||||||
mPreferenceKey = preferenceKey;
|
mPreferenceKey = preferenceKey;
|
||||||
|
if (TextUtils.isEmpty(mPreferenceKey)) {
|
||||||
|
throw new IllegalArgumentException("Preference key must be set");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* 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.core;
|
||||||
|
|
||||||
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_CONTROLLER;
|
||||||
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.XmlRes;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to load {@link BasePreferenceController} lists from Xml.
|
||||||
|
*/
|
||||||
|
public class PreferenceControllerListHelper {
|
||||||
|
|
||||||
|
private static final String TAG = "PrefCtrlListCreator";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a list of controller based on xml definition.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public static List<BasePreferenceController> getPreferenceControllersFromXml(Context context,
|
||||||
|
@XmlRes int xmlResId) {
|
||||||
|
final List<BasePreferenceController> controllers = new ArrayList<>();
|
||||||
|
List<Bundle> preferenceMetadata;
|
||||||
|
try {
|
||||||
|
preferenceMetadata = PreferenceXmlParserUtils.extractMetadata(context, xmlResId);
|
||||||
|
} catch (IOException | XmlPullParserException e) {
|
||||||
|
Log.e(TAG, "Failed to parse preference xml for getting controllers");
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Bundle metadata : preferenceMetadata) {
|
||||||
|
final String controllerName = metadata.getString(METADATA_CONTROLLER);
|
||||||
|
if (TextUtils.isEmpty(controllerName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BasePreferenceController controller;
|
||||||
|
try {
|
||||||
|
controller = BasePreferenceController.createInstance(context, controllerName);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
final String key = metadata.getString(METADATA_KEY);
|
||||||
|
if (TextUtils.isEmpty(key)) {
|
||||||
|
Log.w(TAG, "Controller requires key but it's not defined in xml: "
|
||||||
|
+ controllerName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Log.d(TAG, "Could not find Context-only controller for pref: " + key);
|
||||||
|
controller = BasePreferenceController.createInstance(context, controllerName, key);
|
||||||
|
}
|
||||||
|
controllers.add(controller);
|
||||||
|
}
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a sub list of {@link AbstractPreferenceController} to only contain controller that
|
||||||
|
* doesn't exist in filter.
|
||||||
|
*
|
||||||
|
* @param filter The filter. This list will be unchanged.
|
||||||
|
* @param input This list will be filtered into a sublist and element is kept
|
||||||
|
* IFF the controller key is not used by anything from {@param filter}.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public static List<BasePreferenceController> filterControllers(
|
||||||
|
@NonNull List<BasePreferenceController> input,
|
||||||
|
List<AbstractPreferenceController> filter) {
|
||||||
|
if (input == null || filter == null) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
final Set<String> keys = new TreeSet<>();
|
||||||
|
final List<BasePreferenceController> filteredList = new ArrayList<>();
|
||||||
|
for (AbstractPreferenceController controller : filter) {
|
||||||
|
final String key = controller.getPreferenceKey();
|
||||||
|
if (key != null) {
|
||||||
|
keys.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (BasePreferenceController controller : input) {
|
||||||
|
if (keys.contains(controller.getPreferenceKey())) {
|
||||||
|
Log.w(TAG, controller.getPreferenceKey() + " already has a controller");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
filteredList.add(controller);
|
||||||
|
}
|
||||||
|
return filteredList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -16,18 +16,40 @@
|
|||||||
|
|
||||||
package com.android.settings.core;
|
package com.android.settings.core;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.content.res.XmlResourceParser;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.util.Xml;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class to parse elements of XML preferences
|
* Utility class to parse elements of XML preferences
|
||||||
*/
|
*/
|
||||||
public class PreferenceXmlParserUtils {
|
public class PreferenceXmlParserUtils {
|
||||||
|
|
||||||
|
private static final String TAG = "PreferenceXmlParserUtil";
|
||||||
|
|
||||||
|
private static final List<String> SUPPORTED_PREF_TYPES = Arrays.asList(
|
||||||
|
"Preference", "PreferenceCategory", "PreferenceScreen");
|
||||||
|
|
||||||
|
public static final String METADATA_KEY = "key";
|
||||||
|
public static final String METADATA_CONTROLLER = "controller";
|
||||||
|
|
||||||
private static final String ENTRIES_SEPARATOR = "|";
|
private static final String ENTRIES_SEPARATOR = "|";
|
||||||
|
|
||||||
public static String getDataKey(Context context, AttributeSet attrs) {
|
public static String getDataKey(Context context, AttributeSet attrs) {
|
||||||
@@ -82,6 +104,47 @@ public class PreferenceXmlParserUtils {
|
|||||||
return dataIcon;
|
return dataIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts metadata from preference xml and put them into a {@link Bundle}.
|
||||||
|
*
|
||||||
|
* TODO(zhfan): Similar logic exists in {@link SliceBuilderUtils} and
|
||||||
|
* {@link UniquePreferenceTest}. Need refactoring to consolidate them all.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public static List<Bundle> extractMetadata(Context context, int xmlResId)
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
final List<Bundle> metadata = new ArrayList<>();
|
||||||
|
if (xmlResId <= 0) {
|
||||||
|
Log.d(TAG, xmlResId + " is invalid.");
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
final XmlResourceParser parser = context.getResources().getXml(xmlResId);
|
||||||
|
|
||||||
|
int type;
|
||||||
|
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||||
|
&& type != XmlPullParser.START_TAG) {
|
||||||
|
// Parse next until start tag is found
|
||||||
|
}
|
||||||
|
final int outerDepth = parser.getDepth();
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (type != XmlPullParser.START_TAG) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final String nodeName = parser.getName();
|
||||||
|
if (!SUPPORTED_PREF_TYPES.contains(nodeName) && !nodeName.endsWith("Preference")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final Bundle preferenceMetadata = new Bundle();
|
||||||
|
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||||
|
preferenceMetadata.putString(METADATA_KEY, getDataKey(context, attrs));
|
||||||
|
preferenceMetadata.putString(METADATA_CONTROLLER, getController(context, attrs));
|
||||||
|
metadata.add(preferenceMetadata);
|
||||||
|
} while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||||
|
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the fragment name if this preference launches a child fragment.
|
* Returns the fragment name if this preference launches a child fragment.
|
||||||
*/
|
*/
|
||||||
@@ -98,7 +161,8 @@ public class PreferenceXmlParserUtils {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getDataEntries(Context context, AttributeSet set, int[] attrs, int resId) {
|
private static String getDataEntries(Context context, AttributeSet set, int[] attrs,
|
||||||
|
int resId) {
|
||||||
final TypedArray sa = context.obtainStyledAttributes(set, attrs);
|
final TypedArray sa = context.obtainStyledAttributes(set, attrs);
|
||||||
final TypedValue tv = sa.peekValue(resId);
|
final TypedValue tv = sa.peekValue(resId);
|
||||||
sa.recycle();
|
sa.recycle();
|
||||||
@@ -108,7 +172,7 @@ public class PreferenceXmlParserUtils {
|
|||||||
data = context.getResources().getStringArray(tv.resourceId);
|
data = context.getResources().getStringArray(tv.resourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final int count = (data == null ) ? 0 : data.length;
|
final int count = (data == null) ? 0 : data.length;
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -29,9 +29,13 @@ import android.util.ArraySet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.core.PreferenceControllerListHelper;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
@@ -63,13 +67,34 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mDashboardFeatureProvider =
|
mDashboardFeatureProvider = FeatureFactory.getFactory(context).
|
||||||
FeatureFactory.getFactory(context).getDashboardFeatureProvider(context);
|
getDashboardFeatureProvider(context);
|
||||||
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
// Load preference controllers from code
|
||||||
|
final List<AbstractPreferenceController> controllersFromCode =
|
||||||
|
getPreferenceControllers(context);
|
||||||
|
// Load preference controllers from xml definition
|
||||||
|
final List<BasePreferenceController> controllersFromXml = PreferenceControllerListHelper
|
||||||
|
.getPreferenceControllersFromXml(context, getPreferenceScreenResId());
|
||||||
|
// Filter xml-based controllers in case a similar controller is created from code already.
|
||||||
|
final List<BasePreferenceController> uniqueControllerFromXml =
|
||||||
|
PreferenceControllerListHelper.filterControllers(
|
||||||
|
controllersFromXml, controllersFromCode);
|
||||||
|
|
||||||
List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
|
// Add unique controllers to list.
|
||||||
if (controllers == null) {
|
if (controllersFromCode != null) {
|
||||||
controllers = new ArrayList<>();
|
controllers.addAll(controllersFromCode);
|
||||||
}
|
}
|
||||||
|
controllers.addAll(uniqueControllerFromXml);
|
||||||
|
|
||||||
|
// And wire up with lifecycle.
|
||||||
|
final Lifecycle lifecycle = getLifecycle();
|
||||||
|
uniqueControllerFromXml
|
||||||
|
.stream()
|
||||||
|
.filter(controller -> controller instanceof LifecycleObserver)
|
||||||
|
.forEach(
|
||||||
|
controller -> lifecycle.addObserver((LifecycleObserver) controller));
|
||||||
|
|
||||||
mPlaceholderPreferenceController =
|
mPlaceholderPreferenceController =
|
||||||
new DashboardTilePlaceholderPreferenceController(context);
|
new DashboardTilePlaceholderPreferenceController(context);
|
||||||
controllers.add(mPlaceholderPreferenceController);
|
controllers.add(mPlaceholderPreferenceController);
|
||||||
@@ -217,7 +242,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
/**
|
/**
|
||||||
* Get a list of {@link AbstractPreferenceController} for this fragment.
|
* Get a list of {@link AbstractPreferenceController} for this fragment.
|
||||||
*/
|
*/
|
||||||
protected abstract List<AbstractPreferenceController> getPreferenceControllers(Context context);
|
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this tile should be displayed
|
* Returns true if this tile should be displayed
|
||||||
@@ -327,7 +354,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
|
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
|
||||||
mSummaryLoader.setSummaryConsumer(this);
|
mSummaryLoader.setSummaryConsumer(this);
|
||||||
final TypedArray a = context.obtainStyledAttributes(new int[]{
|
final TypedArray a = context.obtainStyledAttributes(new int[] {
|
||||||
android.R.attr.colorControlNormal});
|
android.R.attr.colorControlNormal});
|
||||||
final int tintColor = a.getColor(0, context.getColor(android.R.color.white));
|
final int tintColor = a.getColor(0, context.getColor(android.R.color.white));
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
@@ -28,6 +28,7 @@ import android.util.Log;
|
|||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.core.PreferenceControllerListHelper;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.core.PreferenceXmlParserUtils;
|
import com.android.settings.core.PreferenceXmlParserUtils;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
@@ -66,7 +67,7 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
|||||||
// Entire page should be suppressed, mark all keys from this page as non-indexable.
|
// Entire page should be suppressed, mark all keys from this page as non-indexable.
|
||||||
return getNonIndexableKeysFromXml(context);
|
return getNonIndexableKeysFromXml(context);
|
||||||
}
|
}
|
||||||
final List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
|
final List<AbstractPreferenceController> controllers = getAllPreferenceControllers(context);
|
||||||
if (controllers != null && !controllers.isEmpty()) {
|
if (controllers != null && !controllers.isEmpty()) {
|
||||||
final List<String> nonIndexableKeys = new ArrayList<>();
|
final List<String> nonIndexableKeys = new ArrayList<>();
|
||||||
for (AbstractPreferenceController controller : controllers) {
|
for (AbstractPreferenceController controller : controllers) {
|
||||||
@@ -88,6 +89,28 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public List<AbstractPreferenceController> getAllPreferenceControllers(Context context) {
|
||||||
|
final List<AbstractPreferenceController> controllersFromCode =
|
||||||
|
getPreferenceControllers(context);
|
||||||
|
final List<SearchIndexableResource> res = getXmlResourcesToIndex(context, true);
|
||||||
|
if (res == null || res.isEmpty()) {
|
||||||
|
return controllersFromCode;
|
||||||
|
}
|
||||||
|
List<BasePreferenceController> controllersFromXml = new ArrayList<>();
|
||||||
|
for (SearchIndexableResource sir : res) {
|
||||||
|
controllersFromXml.addAll(PreferenceControllerListHelper
|
||||||
|
.getPreferenceControllersFromXml(context, sir.xmlResId));
|
||||||
|
}
|
||||||
|
controllersFromXml = PreferenceControllerListHelper.filterControllers(controllersFromXml,
|
||||||
|
controllersFromCode);
|
||||||
|
final List<AbstractPreferenceController> allControllers = new ArrayList<>();
|
||||||
|
if (controllersFromCode != null) {
|
||||||
|
allControllers.addAll(controllersFromCode);
|
||||||
|
}
|
||||||
|
allControllers.addAll(controllersFromXml);
|
||||||
|
return allControllers;
|
||||||
|
}
|
||||||
|
|
||||||
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -77,8 +77,7 @@ public class DatabaseIndexingUtils {
|
|||||||
* @return A map between {@link Uri}s and {@link PreferenceControllerMixin}s to get the payload
|
* @return A map between {@link Uri}s and {@link PreferenceControllerMixin}s to get the payload
|
||||||
* types for Settings.
|
* types for Settings.
|
||||||
*/
|
*/
|
||||||
public static Map<String, ResultPayload> getPayloadKeyMap(
|
public static Map<String, ResultPayload> getPayloadKeyMap(String className, Context context) {
|
||||||
String className, Context context) {
|
|
||||||
ArrayMap<String, ResultPayload> map = new ArrayMap<>();
|
ArrayMap<String, ResultPayload> map = new ArrayMap<>();
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
return map;
|
return map;
|
||||||
@@ -96,8 +95,8 @@ public class DatabaseIndexingUtils {
|
|||||||
// SEARCH_INDEX_DATA_PROVIDER field
|
// SEARCH_INDEX_DATA_PROVIDER field
|
||||||
final Indexable.SearchIndexProvider provider = getSearchIndexProvider(clazz);
|
final Indexable.SearchIndexProvider provider = getSearchIndexProvider(clazz);
|
||||||
|
|
||||||
List<AbstractPreferenceController> controllers =
|
final List<AbstractPreferenceController> controllers =
|
||||||
provider.getPreferenceControllers(context);
|
provider.getAllPreferenceControllers(context);
|
||||||
|
|
||||||
if (controllers == null) {
|
if (controllers == null) {
|
||||||
return map;
|
return map;
|
||||||
|
@@ -18,7 +18,7 @@ package com.android.settings.search;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -72,7 +72,9 @@ public interface Indexable {
|
|||||||
* @param context
|
* @param context
|
||||||
* @return a list of {@link AbstractPreferenceController} for ResultPayload data during
|
* @return a list of {@link AbstractPreferenceController} for ResultPayload data during
|
||||||
* Indexing.
|
* Indexing.
|
||||||
|
*
|
||||||
|
* TODO(zhfan): name is confusing(too similar to getPreferenceControllers). Rename both.
|
||||||
*/
|
*/
|
||||||
List<AbstractPreferenceController> getPreferenceControllers(Context context);
|
List<AbstractPreferenceController> getAllPreferenceControllers(Context context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,12 +26,9 @@ import com.android.internal.logging.nano.MetricsProto;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.backup.BackupSettingsActivityPreferenceController;
|
import com.android.settings.backup.BackupSettingsActivityPreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.gestures.GesturesSettingPreferenceController;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -72,20 +69,6 @@ public class SystemDashboardFragment extends DashboardFragment {
|
|||||||
return R.string.help_url_system_dashboard;
|
return R.string.help_url_system_dashboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
|
||||||
return buildPreferenceControllers(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
|
||||||
controllers.add(new SystemUpdatePreferenceController(context));
|
|
||||||
controllers.add(new AdditionalSystemUpdatePreferenceController(context));
|
|
||||||
controllers.add(new BackupSettingsActivityPreferenceController(context));
|
|
||||||
controllers.add(new GesturesSettingPreferenceController(context));
|
|
||||||
return controllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getVisiblePreferenceCount(PreferenceGroup group) {
|
private int getVisiblePreferenceCount(PreferenceGroup group) {
|
||||||
int visibleCount = 0;
|
int visibleCount = 0;
|
||||||
for (int i = 0; i < group.getPreferenceCount(); i++) {
|
for (int i = 0; i < group.getPreferenceCount(); i++) {
|
||||||
@@ -112,12 +95,6 @@ public class SystemDashboardFragment extends DashboardFragment {
|
|||||||
return Arrays.asList(sir);
|
return Arrays.asList(sir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AbstractPreferenceController> getPreferenceControllers(
|
|
||||||
Context context) {
|
|
||||||
return buildPreferenceControllers(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
List<String> keys = super.getNonIndexableKeys(context);
|
List<String> keys = super.getNonIndexableKeys(context);
|
||||||
|
@@ -1,2 +1 @@
|
|||||||
com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard
|
com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard
|
||||||
com.android.settings.search.indexing.FakeSettingsFragment
|
|
@@ -1 +1,5 @@
|
|||||||
com.android.settings.fuelgauge.PowerUsageSummary
|
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
|
@@ -17,7 +17,8 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:key="fake_title_key"
|
android:key="fake_title_key"
|
||||||
android:title="screen_title">
|
android:title="screen_title"
|
||||||
|
settings:controller="com.android.settings.slices.FakePreferenceController">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="key"
|
android:key="key"
|
||||||
|
@@ -16,10 +16,8 @@
|
|||||||
package com.android.settings.connecteddevice;
|
package com.android.settings.connecteddevice;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
@@ -30,8 +28,6 @@ import com.android.settingslib.drawer.CategoryKey;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
@@ -41,13 +37,6 @@ import java.util.List;
|
|||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class AdvancedConnectedDeviceDashboardFragmentTest {
|
public class AdvancedConnectedDeviceDashboardFragmentTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private PackageManager mManager;
|
|
||||||
|
|
||||||
private AdvancedConnectedDeviceDashboardFragment mFragment;
|
private AdvancedConnectedDeviceDashboardFragment mFragment;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -55,7 +44,6 @@ public class AdvancedConnectedDeviceDashboardFragmentTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mFragment = new AdvancedConnectedDeviceDashboardFragment();
|
mFragment = new AdvancedConnectedDeviceDashboardFragment();
|
||||||
when(mContext.getApplicationContext().getPackageManager()).thenReturn(mManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -66,7 +54,8 @@ public class AdvancedConnectedDeviceDashboardFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSearchIndexProvider_shouldIndexResource() {
|
public void testSearchIndexProvider_shouldIndexResource() {
|
||||||
final List<SearchIndexableResource> indexRes =
|
final List<SearchIndexableResource> indexRes =
|
||||||
mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext,
|
mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||||
|
RuntimeEnvironment.application,
|
||||||
true /* enabled */);
|
true /* enabled */);
|
||||||
|
|
||||||
assertThat(indexRes).isNotNull();
|
assertThat(indexRes).isNotNull();
|
||||||
@@ -81,9 +70,8 @@ public class AdvancedConnectedDeviceDashboardFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNonIndexableKeys_existInXmlLayout() {
|
public void testNonIndexableKeys_existInXmlLayout() {
|
||||||
final Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
|
|
||||||
final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||||
.getNonIndexableKeys(mContext);
|
.getNonIndexableKeys(context);
|
||||||
final int xmlId = (new ConnectedDeviceDashboardFragment()).getPreferenceScreenResId();
|
final int xmlId = (new ConnectedDeviceDashboardFragment()).getPreferenceScreenResId();
|
||||||
|
|
||||||
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
|
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
|
||||||
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License
|
|
||||||
*/
|
|
||||||
package com.android.settings.connecteddevice;
|
|
||||||
|
|
||||||
import static android.content.Context.NFC_SERVICE;
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.nfc.NfcManager;
|
|
||||||
import android.provider.SearchIndexableResource;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
|
||||||
import com.android.settings.nfc.NfcPreferenceController;
|
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.testutils.XmlTestUtils;
|
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class ConnectedDeviceDashboardFragment2Test {
|
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
Context mContext;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private PackageManager mManager;
|
|
||||||
|
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
|
||||||
private ConnectedDeviceDashboardFragmentOld mFragment;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
|
||||||
|
|
||||||
mFragment = new ConnectedDeviceDashboardFragmentOld();
|
|
||||||
when(mContext.getPackageManager()).thenReturn(mManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchIndexProvider_shouldIndexResource() {
|
|
||||||
final List<SearchIndexableResource> indexRes =
|
|
||||||
mFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(mContext,
|
|
||||||
true /* enabled */);
|
|
||||||
|
|
||||||
assertThat(indexRes).isNotNull();
|
|
||||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchIndexProvider_NoNfc_KeyAdded() {
|
|
||||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
|
|
||||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
|
||||||
mContext);
|
|
||||||
|
|
||||||
assertThat(keys).isNotNull();
|
|
||||||
assertThat(keys).contains(NfcPreferenceController.KEY_TOGGLE_NFC);
|
|
||||||
assertThat(keys).contains(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchIndexProvider_NFC_KeyNotAdded() {
|
|
||||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
|
|
||||||
final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
|
||||||
mContext);
|
|
||||||
|
|
||||||
assertThat(keys).isNotNull();
|
|
||||||
assertThat(keys).doesNotContain(NfcPreferenceController.KEY_TOGGLE_NFC);
|
|
||||||
assertThat(keys).doesNotContain(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNonIndexableKeys_existInXmlLayout() {
|
|
||||||
final Context context = RuntimeEnvironment.application;
|
|
||||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
|
|
||||||
final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
|
||||||
.getNonIndexableKeys(mContext);
|
|
||||||
final int xmlId = (new ConnectedDeviceDashboardFragment()).getPreferenceScreenResId();
|
|
||||||
|
|
||||||
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
|
|
||||||
|
|
||||||
assertThat(keys).containsAllIn(niks);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSummaryProvider_hasNfc_shouldReturnNfcSummary() {
|
|
||||||
final NfcManager nfcManager = mock(NfcManager.class);
|
|
||||||
final SummaryLoader summaryLoader = mock(SummaryLoader.class);
|
|
||||||
|
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
|
||||||
when(mContext.getSystemService(NFC_SERVICE)).thenReturn(nfcManager);
|
|
||||||
when(nfcManager.getDefaultAdapter()).thenReturn(mock(NfcAdapter.class));
|
|
||||||
|
|
||||||
SummaryLoader.SummaryProvider provider =
|
|
||||||
new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
|
|
||||||
|
|
||||||
provider.setListening(false);
|
|
||||||
|
|
||||||
verifyZeroInteractions(summaryLoader);
|
|
||||||
|
|
||||||
provider.setListening(true);
|
|
||||||
|
|
||||||
verify(mContext).getString(R.string.connected_devices_dashboard_summary);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSummaryProvider_noNfc_shouldReturnNoNfcSummary() {
|
|
||||||
final SummaryLoader summaryLoader = mock(SummaryLoader.class);
|
|
||||||
|
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
|
||||||
when(mContext.getSystemService(NFC_SERVICE)).thenReturn(null);
|
|
||||||
|
|
||||||
SummaryLoader.SummaryProvider provider =
|
|
||||||
new ConnectedDeviceDashboardFragment.SummaryProvider(mContext, summaryLoader);
|
|
||||||
|
|
||||||
provider.setListening(false);
|
|
||||||
|
|
||||||
verifyZeroInteractions(summaryLoader);
|
|
||||||
|
|
||||||
provider.setListening(true);
|
|
||||||
|
|
||||||
verify(mContext).getString(R.string.connected_devices_dashboard_no_nfc_summary);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -31,6 +31,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@@ -45,6 +46,17 @@ public class BasePreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void newController_noKey_shouldCrash() {
|
||||||
|
new BasePreferenceController(RuntimeEnvironment.application, null /* key */) {
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_availableStatusAvailable_returnsTrue() {
|
public void isAvailable_availableStatusAvailable_returnsTrue() {
|
||||||
when(mPreferenceController.getAvailabilityStatus()).thenReturn(AVAILABLE);
|
when(mPreferenceController.getAvailabilityStatus()).thenReturn(AVAILABLE);
|
||||||
|
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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.core;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.slices.FakePreferenceController;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
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.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class PreferenceControllerListHelperTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void getControllers_shouldReturnAList() {
|
||||||
|
final List<BasePreferenceController> controllers =
|
||||||
|
PreferenceControllerListHelper.getPreferenceControllersFromXml(mContext,
|
||||||
|
R.xml.location_settings);
|
||||||
|
|
||||||
|
assertThat(controllers).isNotEmpty();
|
||||||
|
for (BasePreferenceController controller : controllers) {
|
||||||
|
assertThat(controller).isInstanceOf(FakePreferenceController.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void filterControllers_noFilter_shouldReturnSameList() {
|
||||||
|
final List<BasePreferenceController> controllers = new ArrayList<>();
|
||||||
|
controllers.add(new BasePreferenceController(mContext, "key") {
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final List<BasePreferenceController> result = PreferenceControllerListHelper
|
||||||
|
.filterControllers(controllers, null /* filter */);
|
||||||
|
assertThat(result).containsExactlyElementsIn(controllers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void filterControllers_noDuplicationFromFilter_shouldReturnSameList() {
|
||||||
|
final List<BasePreferenceController> controllers = new ArrayList<>();
|
||||||
|
controllers.add(new BasePreferenceController(mContext, "key") {
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final List<AbstractPreferenceController> filter = new ArrayList<>();
|
||||||
|
filter.add(new BasePreferenceController(mContext, "key2") {
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final List<BasePreferenceController> result = PreferenceControllerListHelper
|
||||||
|
.filterControllers(controllers, filter);
|
||||||
|
assertThat(result).containsExactlyElementsIn(controllers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void filterControllers_hasDuplicationFromFilter_shouldReturnSameList() {
|
||||||
|
final List<BasePreferenceController> controllers = new ArrayList<>();
|
||||||
|
controllers.add(new BasePreferenceController(mContext, "key") {
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final List<AbstractPreferenceController> filter = new ArrayList<>();
|
||||||
|
filter.add(new BasePreferenceController(mContext, "key") {
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final List<BasePreferenceController> result = PreferenceControllerListHelper
|
||||||
|
.filterControllers(controllers, filter);
|
||||||
|
assertThat(result).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -50,7 +50,7 @@ public class DashboardFragmentSearchIndexProviderInspector {
|
|||||||
final List<AbstractPreferenceController> controllersFromSearchIndexProvider;
|
final List<AbstractPreferenceController> controllersFromSearchIndexProvider;
|
||||||
final List<AbstractPreferenceController> controllersFromFragment;
|
final List<AbstractPreferenceController> controllersFromFragment;
|
||||||
try {
|
try {
|
||||||
controllersFromSearchIndexProvider = provider.getPreferenceControllers(context);
|
controllersFromSearchIndexProvider = provider.getAllPreferenceControllers(context);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
// Can't do much with exception, assume the test passed.
|
// Can't do much with exception, assume the test passed.
|
||||||
return true;
|
return true;
|
||||||
|
@@ -19,6 +19,8 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.nullable;
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -44,11 +46,10 @@ import com.android.settingslib.drawer.TileUtils;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -58,24 +59,25 @@ import java.util.List;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class DashboardFragmentTest {
|
public class DashboardFragmentTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
@Mock
|
||||||
private FakeFeatureFactory mFakeFeatureFactory;
|
private FakeFeatureFactory mFakeFeatureFactory;
|
||||||
private DashboardCategory mDashboardCategory;
|
private DashboardCategory mDashboardCategory;
|
||||||
|
private Context mContext;
|
||||||
private TestFragment mTestFragment;
|
private TestFragment mTestFragment;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mDashboardCategory = new DashboardCategory();
|
mDashboardCategory = new DashboardCategory();
|
||||||
mDashboardCategory.addTile(new Tile());
|
mDashboardCategory.addTile(new Tile());
|
||||||
mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
|
mTestFragment = new TestFragment(mContext);
|
||||||
when(mFakeFeatureFactory.dashboardFeatureProvider
|
when(mFakeFeatureFactory.dashboardFeatureProvider
|
||||||
.getTilesForCategory(nullable(String.class)))
|
.getTilesForCategory(nullable(String.class)))
|
||||||
.thenReturn(mDashboardCategory);
|
.thenReturn(mDashboardCategory);
|
||||||
mTestFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
|
mTestFragment.onAttach(mContext);
|
||||||
when(mContext.getPackageName()).thenReturn("TestPackage");
|
when(mContext.getPackageName()).thenReturn("TestPackage");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,16 +148,18 @@ public class DashboardFragmentTest {
|
|||||||
mock(AbstractPreferenceController.class);
|
mock(AbstractPreferenceController.class);
|
||||||
final AbstractPreferenceController mockController2 =
|
final AbstractPreferenceController mockController2 =
|
||||||
mock(AbstractPreferenceController.class);
|
mock(AbstractPreferenceController.class);
|
||||||
|
when(mockController1.getPreferenceKey()).thenReturn("key1");
|
||||||
|
when(mockController2.getPreferenceKey()).thenReturn("key2");
|
||||||
preferenceControllers.add(mockController1);
|
preferenceControllers.add(mockController1);
|
||||||
preferenceControllers.add(mockController2);
|
preferenceControllers.add(mockController2);
|
||||||
when(mockController1.isAvailable()).thenReturn(false);
|
when(mockController1.isAvailable()).thenReturn(false);
|
||||||
when(mockController2.isAvailable()).thenReturn(true);
|
when(mockController2.isAvailable()).thenReturn(true);
|
||||||
|
|
||||||
mTestFragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
|
mTestFragment.onAttach(mContext);
|
||||||
mTestFragment.onResume();
|
mTestFragment.onResume();
|
||||||
|
|
||||||
verify(mockController1, never()).getPreferenceKey();
|
verify(mockController1).getPreferenceKey();
|
||||||
verify(mockController2).getPreferenceKey();
|
verify(mockController2, times(2)).getPreferenceKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -205,9 +209,7 @@ public class DashboardFragmentTest {
|
|||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
tile.intent = intent;
|
tile.intent = intent;
|
||||||
|
|
||||||
intent.setComponent(new ComponentName(
|
intent.setComponent(new ComponentName(mContext.getPackageName(), "TestClass"));
|
||||||
ShadowApplication.getInstance().getApplicationContext().getPackageName(),
|
|
||||||
"TestClass"));
|
|
||||||
assertThat(mTestFragment.tintTileIcon(tile)).isFalse();
|
assertThat(mTestFragment.tintTileIcon(tile)).isFalse();
|
||||||
|
|
||||||
intent.setComponent(new ComponentName("OtherPackage", "TestClass"));
|
intent.setComponent(new ComponentName("OtherPackage", "TestClass"));
|
||||||
|
@@ -98,7 +98,7 @@ public final class EnterprisePrivacySettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getSearchIndexProviderPreferenceControllers() throws Exception {
|
public void getSearchIndexProviderPreferenceControllers() throws Exception {
|
||||||
final List<AbstractPreferenceController> controllers
|
final List<AbstractPreferenceController> controllers
|
||||||
= EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(
|
= EnterprisePrivacySettings.SEARCH_INDEX_DATA_PROVIDER.getAllPreferenceControllers(
|
||||||
ShadowApplication.getInstance().getApplicationContext());
|
ShadowApplication.getInstance().getApplicationContext());
|
||||||
verifyPreferenceControllers(controllers);
|
verifyPreferenceControllers(controllers);
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,6 @@ package com.android.settings.search;
|
|||||||
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
@@ -26,15 +25,15 @@ import android.content.Context;
|
|||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
@@ -50,13 +49,13 @@ public class BaseSearchIndexProviderTest {
|
|||||||
|
|
||||||
private static final String TEST_PREF_KEY = "test_pref_key";
|
private static final String TEST_PREF_KEY = "test_pref_key";
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BaseSearchIndexProvider mIndexProvider;
|
private BaseSearchIndexProvider mIndexProvider;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
mIndexProvider = spy(BaseSearchIndexProvider.class);
|
mIndexProvider = spy(BaseSearchIndexProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +90,38 @@ public class BaseSearchIndexProviderTest {
|
|||||||
assertThat(mIndexProvider.getNonIndexableKeys(mContext)).isEqualTo(Collections.EMPTY_LIST);
|
assertThat(mIndexProvider.getNonIndexableKeys(mContext)).isEqualTo(Collections.EMPTY_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void getAllPreferenceControllers_shouldCreateControllerFromCodeAndXml() {
|
||||||
|
|
||||||
|
final BaseSearchIndexProvider 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
final List<AbstractPreferenceController> controllersFromCode = new ArrayList<>();
|
||||||
|
controllersFromCode.add(new BasePreferenceController(mContext, "TEST_KEY") {
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return controllersFromCode;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final List<AbstractPreferenceController> controllers =
|
||||||
|
provider.getAllPreferenceControllers(mContext);
|
||||||
|
|
||||||
|
assertThat(controllers).hasSize(3);
|
||||||
|
}
|
||||||
|
|
||||||
public static class NotAvailablePreferenceController extends AbstractPreferenceController
|
public static class NotAvailablePreferenceController extends AbstractPreferenceController
|
||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin {
|
||||||
public NotAvailablePreferenceController(Context context) {
|
public NotAvailablePreferenceController(Context context) {
|
||||||
|
@@ -21,7 +21,6 @@ import android.content.Context;
|
|||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -48,12 +47,6 @@ public class FakeIndexProvider implements Indexable {
|
|||||||
result.add(KEY);
|
result.add(KEY);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AbstractPreferenceController> getPreferenceControllers(
|
|
||||||
Context context) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
@@ -32,9 +33,13 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These tests use a series of preferences that have specific attributes which are sometimes
|
* These tests use a series of preferences that have specific attributes which are sometimes
|
||||||
@@ -45,13 +50,13 @@ import org.xmlpull.v1.XmlPullParser;
|
|||||||
*/
|
*/
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class XmlParserUtilTest {
|
public class PreferenceXmlParserUtilTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = ShadowApplication.getInstance().getApplicationContext();
|
mContext = RuntimeEnvironment.application;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -91,7 +96,6 @@ public class XmlParserUtilTest {
|
|||||||
String summary = PreferenceXmlParserUtils.getDataSummary(mContext, attrs);
|
String summary = PreferenceXmlParserUtils.getDataSummary(mContext, attrs);
|
||||||
String expSummary = mContext.getString(R.string.summary_placeholder);
|
String expSummary = mContext.getString(R.string.summary_placeholder);
|
||||||
assertThat(summary).isEqualTo(expSummary);
|
assertThat(summary).isEqualTo(expSummary);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -163,6 +167,20 @@ public class XmlParserUtilTest {
|
|||||||
assertThat(entries).isNull();
|
assertThat(entries).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void extractMetadata_shouldContainKeyAndControllerName()
|
||||||
|
throws IOException, XmlPullParserException {
|
||||||
|
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||||
|
R.xml.location_settings);
|
||||||
|
|
||||||
|
assertThat(metadata).isNotEmpty();
|
||||||
|
for (Bundle bundle : metadata) {
|
||||||
|
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_KEY)).isNotNull();
|
||||||
|
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_CONTROLLER)).isNotNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param resId the ID for the XML preference
|
* @param resId the ID for the XML preference
|
||||||
* @return an XML resource parser that points to the start tag
|
* @return an XML resource parser that points to the start tag
|
@@ -18,9 +18,8 @@ package com.android.settings.search;
|
|||||||
|
|
||||||
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
|
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static junit.framework.Assert.fail;
|
import static junit.framework.Assert.fail;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
@@ -36,6 +35,7 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@@ -67,7 +67,7 @@ public class SearchIndexableResourcesTest {
|
|||||||
final int beforeCount =
|
final int beforeCount =
|
||||||
mSearchProvider.getSearchIndexableResources().getProviderValues().size();
|
mSearchProvider.getSearchIndexableResources().getProviderValues().size();
|
||||||
|
|
||||||
( (SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
|
((SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
|
||||||
.addIndex(java.lang.String.class);
|
.addIndex(java.lang.String.class);
|
||||||
|
|
||||||
assertThat(mSearchProvider.getSearchIndexableResources().getProviderValues())
|
assertThat(mSearchProvider.getSearchIndexableResources().getProviderValues())
|
||||||
@@ -86,11 +86,13 @@ public class SearchIndexableResourcesTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNonIndexableKeys_GetsKeyFromProvider() {
|
public void testNonIndexableKeys_GetsKeyFromProvider() {
|
||||||
mSearchProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
( (SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
|
((SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
|
||||||
.addIndex(FakeIndexProvider.class);
|
.addIndex(FakeIndexProvider.class);
|
||||||
|
|
||||||
SettingsSearchIndexablesProvider provider = spy(new SettingsSearchIndexablesProvider());
|
SettingsSearchIndexablesProvider provider = spy(new SettingsSearchIndexablesProvider());
|
||||||
|
|
||||||
|
doReturn(RuntimeEnvironment.application).when(provider).getContext();
|
||||||
|
|
||||||
Cursor cursor = provider.queryNonIndexableKeys(null);
|
Cursor cursor = provider.queryNonIndexableKeys(null);
|
||||||
boolean hasTestKey = false;
|
boolean hasTestKey = false;
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
@@ -106,8 +108,8 @@ public class SearchIndexableResourcesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllClassNamesHaveProviders() {
|
public void testAllClassNamesHaveProviders() {
|
||||||
for (Class clazz: mSearchProvider.getSearchIndexableResources().getProviderValues()) {
|
for (Class clazz : mSearchProvider.getSearchIndexableResources().getProviderValues()) {
|
||||||
if(DatabaseIndexingUtils.getSearchIndexProvider(clazz) == null) {
|
if (DatabaseIndexingUtils.getSearchIndexProvider(clazz) == null) {
|
||||||
fail(clazz.getName() + "is not an index provider");
|
fail(clazz.getName() + "is not an index provider");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -104,6 +104,7 @@ public class SettingsSearchIndexablesProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
public void testNonIndexablesColumnFetched() {
|
public void testNonIndexablesColumnFetched() {
|
||||||
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
Uri rawUri = Uri.parse("content://" + BASE_AUTHORITY + "/" +
|
||||||
SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
|
SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
|
||||||
|
@@ -16,15 +16,14 @@
|
|||||||
package com.android.settings.system;
|
package com.android.settings.system;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||||
|
|
||||||
@@ -34,7 +33,9 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(
|
@Config(
|
||||||
@@ -46,20 +47,20 @@ public class FactoryResetPreferenceControllerTest {
|
|||||||
|
|
||||||
private static final String FACTORY_RESET_KEY = "factory_reset";
|
private static final String FACTORY_RESET_KEY = "factory_reset";
|
||||||
|
|
||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
@Mock
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock
|
@Mock
|
||||||
private AccountManager mAccountManager;
|
private AccountManager mAccountManager;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private FactoryResetPreferenceController mController;
|
private FactoryResetPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
mContext = RuntimeEnvironment.application;
|
||||||
when(mContext.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
|
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUserManager);
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.ACCOUNT_SERVICE, mAccountManager);
|
||||||
mController = new FactoryResetPreferenceController(mContext);
|
mController = new FactoryResetPreferenceController(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -67,7 +67,7 @@ public class PreferenceControllerContractTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final List<AbstractPreferenceController> controllers =
|
final List<AbstractPreferenceController> controllers =
|
||||||
provider.getPreferenceControllers(mContext);
|
provider.getAllPreferenceControllers(mContext);
|
||||||
if (controllers == null) {
|
if (controllers == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user