use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by LineageOS.
the class DatabaseIndexingManager method indexFromResource.
@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr, SearchIndexableResource sir, List<String> nonIndexableKeys) {
final Context context = sir.context;
XmlResourceParser parser = null;
try {
parser = context.getResources().getXml(sir.xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
String nodeName = parser.getName();
if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
}
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
String summary;
String headerSummary;
String keywords;
String headerKeywords;
String childFragment;
@DrawableRes int iconResId;
ResultPayload payload;
boolean enabled;
final String fragmentName = sir.className;
final int rank = sir.rank;
final String intentAction = sir.intentAction;
final String intentTargetPackage = sir.intentTargetPackage;
final String intentTargetClass = sir.intentTargetClass;
Map<String, PreferenceControllerMixin> controllerUriMap = null;
if (fragmentName != null) {
controllerUriMap = DatabaseIndexingUtils.getPreferenceControllerUriMap(fragmentName, context);
}
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
// TODO: Set payload type for header results
DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
headerBuilder.setLocale(localeStr).setEntries(null).setClassName(fragmentName).setScreenTitle(screenTitle).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
// Flag for XML headers which a child element's title.
boolean isHeaderUnique = true;
DatabaseRow.Builder builder;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
nodeName = parser.getName();
title = XmlParserUtils.getDataTitle(context, attrs);
key = XmlParserUtils.getDataKey(context, attrs);
enabled = !nonIndexableKeys.contains(key);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
iconResId = XmlParserUtils.getDataIcon(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
}
builder = new DatabaseRow.Builder();
builder.setLocale(localeStr).setClassName(fragmentName).setScreenTitle(screenTitle).setIconResId(iconResId).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
summary = XmlParserUtils.getDataSummary(context, attrs);
String entries = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
entries = XmlParserUtils.getDataEntries(context, attrs);
}
// TODO (b/62254931) index primitives instead of payload
payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
builder.setEntries(entries).setChildClassName(childFragment).setPayload(payload);
// Insert rows for the child nodes of PreferenceScreen
updateOneRowWithFilteredData(database, builder, title, summary, null, /* summary off */
keywords);
} else {
String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
summaryOn = XmlParserUtils.getDataSummary(context, attrs);
}
updateOneRowWithFilteredData(database, builder, title, summaryOn, summaryOff, keywords);
}
}
// The xml header's title does not match the title of one of the child settings.
if (isHeaderUnique) {
updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary, null, /* summary off */
headerKeywords);
}
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} catch (IOException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} finally {
if (parser != null)
parser.close();
}
}
use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by omnirom.
the class DatabaseIndexingUtils method getPreferenceControllerUriMap.
/**
* @param className which wil provide the map between from {@link Uri}s to
* {@link PreferenceControllerMixin}
* @param context
* @return A map between {@link Uri}s and {@link PreferenceControllerMixin}s to get the payload
* types for Settings.
*/
public static Map<String, PreferenceControllerMixin> getPreferenceControllerUriMap(String className, Context context) {
if (context == null) {
return null;
}
final Class<?> clazz = getIndexableClass(className);
if (clazz == null) {
/*Log.d(TAG, "SearchIndexableResource '" + className +
"' should implement the " + Indexable.class.getName() + " interface!");*/
return null;
}
// Will be non null only for a Local provider implementing a
// SEARCH_INDEX_DATA_PROVIDER field
final Indexable.SearchIndexProvider provider = getSearchIndexProvider(clazz);
List<AbstractPreferenceController> controllers = provider.getPreferenceControllers(context);
if (controllers == null) {
return null;
}
ArrayMap<String, PreferenceControllerMixin> map = new ArrayMap<>();
for (AbstractPreferenceController controller : controllers) {
if (controller instanceof PreferenceControllerMixin) {
map.put(controller.getPreferenceKey(), (PreferenceControllerMixin) controller);
} else {
throw new IllegalStateException(controller.getClass().getName() + " must implement " + PreferenceControllerMixin.class.getName());
}
}
return map;
}
use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by crdroidandroid.
the class DatabaseIndexingUtilsTest method testGetPayloadFromMap_MatchingKey_ReturnsPayload.
@Test
public void testGetPayloadFromMap_MatchingKey_ReturnsPayload() {
final String key = "key";
PreferenceControllerMixin prefController = new PreferenceControllerMixin() {
@Override
public ResultPayload getResultPayload() {
return new ResultPayload(null);
}
};
ArrayMap<String, PreferenceControllerMixin> map = new ArrayMap<>();
map.put(key, prefController);
ResultPayload payload = DatabaseIndexingUtils.getPayloadFromUriMap(map, key);
assertThat(payload).isInstanceOf(ResultPayload.class);
}
use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by crdroidandroid.
the class DatabaseIndexingManager method indexFromResource.
@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr, SearchIndexableResource sir, List<String> nonIndexableKeys) {
final Context context = sir.context;
XmlResourceParser parser = null;
try {
parser = context.getResources().getXml(sir.xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
String nodeName = parser.getName();
if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
}
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
String summary;
String headerSummary;
String keywords;
String headerKeywords;
String childFragment;
@DrawableRes int iconResId;
ResultPayload payload;
boolean enabled;
final String fragmentName = sir.className;
final int rank = sir.rank;
final String intentAction = sir.intentAction;
final String intentTargetPackage = sir.intentTargetPackage;
final String intentTargetClass = sir.intentTargetClass;
Map<String, PreferenceControllerMixin> controllerUriMap = null;
if (fragmentName != null) {
controllerUriMap = DatabaseIndexingUtils.getPreferenceControllerUriMap(fragmentName, context);
}
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
// TODO: Set payload type for header results
DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
headerBuilder.setLocale(localeStr).setEntries(null).setClassName(fragmentName).setScreenTitle(screenTitle).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
// Flag for XML headers which a child element's title.
boolean isHeaderUnique = true;
DatabaseRow.Builder builder;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
nodeName = parser.getName();
title = XmlParserUtils.getDataTitle(context, attrs);
key = XmlParserUtils.getDataKey(context, attrs);
enabled = !nonIndexableKeys.contains(key);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
iconResId = XmlParserUtils.getDataIcon(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
}
builder = new DatabaseRow.Builder();
builder.setLocale(localeStr).setClassName(fragmentName).setScreenTitle(screenTitle).setIconResId(iconResId).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
summary = XmlParserUtils.getDataSummary(context, attrs);
String entries = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
entries = XmlParserUtils.getDataEntries(context, attrs);
}
// TODO (b/62254931) index primitives instead of payload
payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
builder.setEntries(entries).setChildClassName(childFragment).setPayload(payload);
// Insert rows for the child nodes of PreferenceScreen
updateOneRowWithFilteredData(database, builder, title, summary, null, /* summary off */
keywords);
} else {
String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
summaryOn = XmlParserUtils.getDataSummary(context, attrs);
}
updateOneRowWithFilteredData(database, builder, title, summaryOn, summaryOff, keywords);
}
}
// The xml header's title does not match the title of one of the child settings.
if (isHeaderUnique) {
updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary, null, /* summary off */
headerKeywords);
}
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} catch (IOException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} finally {
if (parser != null)
parser.close();
}
}
use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by SudaMod.
the class DatabaseIndexingManager method indexFromResource.
@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr, SearchIndexableResource sir, List<String> nonIndexableKeys) {
final Context context = sir.context;
XmlResourceParser parser = null;
try {
parser = context.getResources().getXml(sir.xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
String nodeName = parser.getName();
if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
}
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
String summary;
String headerSummary;
String keywords;
String headerKeywords;
String childFragment;
@DrawableRes int iconResId;
ResultPayload payload;
boolean enabled;
final String fragmentName = sir.className;
final int rank = sir.rank;
final String intentAction = sir.intentAction;
final String intentTargetPackage = sir.intentTargetPackage;
final String intentTargetClass = sir.intentTargetClass;
Map<String, PreferenceControllerMixin> controllerUriMap = null;
if (fragmentName != null) {
controllerUriMap = DatabaseIndexingUtils.getPreferenceControllerUriMap(fragmentName, context);
}
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
// TODO: Set payload type for header results
DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
headerBuilder.setLocale(localeStr).setEntries(null).setClassName(fragmentName).setScreenTitle(screenTitle).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
// Flag for XML headers which a child element's title.
boolean isHeaderUnique = true;
DatabaseRow.Builder builder;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
nodeName = parser.getName();
title = XmlParserUtils.getDataTitle(context, attrs);
key = XmlParserUtils.getDataKey(context, attrs);
enabled = !nonIndexableKeys.contains(key);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
iconResId = XmlParserUtils.getDataIcon(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
}
builder = new DatabaseRow.Builder();
builder.setLocale(localeStr).setClassName(fragmentName).setScreenTitle(screenTitle).setIconResId(iconResId).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
summary = XmlParserUtils.getDataSummary(context, attrs);
String entries = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
entries = XmlParserUtils.getDataEntries(context, attrs);
}
// TODO (b/62254931) index primitives instead of payload
payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
builder.setEntries(entries).setChildClassName(childFragment).setPayload(payload);
// Insert rows for the child nodes of PreferenceScreen
updateOneRowWithFilteredData(database, builder, title, summary, null, /* summary off */
keywords);
} else {
String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
summaryOn = XmlParserUtils.getDataSummary(context, attrs);
}
updateOneRowWithFilteredData(database, builder, title, summaryOn, summaryOff, keywords);
}
}
// The xml header's title does not match the title of one of the child settings.
if (isHeaderUnique) {
updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary, null, /* summary off */
headerKeywords);
}
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} catch (IOException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} finally {
if (parser != null)
parser.close();
}
}
Aggregations