Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c12771af authored by Xin Li's avatar Xin Li
Browse files

DO NOT MERGE - Merge Android 10 into master

Bug: 139893257
Change-Id: I64a01331273216829533f69f4422036e5598a547
parents 24096bc9 071ab094
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
            android:theme="@style/Theme.Settings.NoActionBar">
            <intent-filter priority="-1">
                <action android:name="com.android.settings.action.SETTINGS_SEARCH" />
                <action android:name="android.settings.APP_SEARCH_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
+9 −7
Original line number Diff line number Diff line
# People who can approve changes
dhnishi@google.com
juanlang@google.com
mfritze@google.com
zhfan@google.com
## People who can approve changes

# Android auto
rlagos@google.com

# Emergency approvers in case the above are not available
miket@google.com
 No newline at end of file
# TV Settings
leifhendrik@google.com

# Mobile Settings
zhfan@google.com
 No newline at end of file
+16 −14
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.intelligence.search.indexing;

import static com.android.settings.intelligence.search.query.DatabaseResultTask.SELECT_COLUMNS;
import static com.android.settings.intelligence.search.indexing.IndexDatabaseHelper.IndexColumns.DATA_AUTHORITY;
import static com.android.settings.intelligence.search.indexing.IndexDatabaseHelper.IndexColumns.DATA_PACKAGE;
import static com.android.settings.intelligence.search.indexing.IndexDatabaseHelper.IndexColumns.CLASS_NAME;
import static com.android.settings.intelligence.search.indexing.IndexDatabaseHelper.IndexColumns.DATA_ENTRIES;
@@ -220,6 +221,7 @@ public class DatabaseIndexingManager {
            values.put(DATA_ENTRIES, dataRow.entries);
            values.put(DATA_KEYWORDS, dataRow.spaceDelimitedKeywords);
            values.put(DATA_PACKAGE, dataRow.packageName);
            values.put(DATA_AUTHORITY, dataRow.authority);
            values.put(CLASS_NAME, dataRow.className);
            values.put(SCREEN_TITLE, dataRow.screenTitle);
            values.put(INTENT_ACTION, dataRow.intentAction);
@@ -241,7 +243,7 @@ public class DatabaseIndexingManager {
     * All rows which are disabled but no longer a non-indexable key will become enabled.
     *
     * @param database         The database to validate.
     * @param nonIndexableKeys A map between package name and the set of non-indexable keys for it.
     * @param nonIndexableKeys A map between authority and the set of non-indexable keys for it.
     */
    @VisibleForTesting
    void updateDataInDatabase(SQLiteDatabase database,
@@ -255,17 +257,17 @@ public class DatabaseIndexingManager {
        final ContentValues enabledToDisabledValue = new ContentValues();
        enabledToDisabledValue.put(ENABLED, 0);

        String packageName;
        String authority;
        // TODO Refactor: Move these two loops into one method.
        while (enabledResults.moveToNext()) {
            packageName = enabledResults.getString(enabledResults.getColumnIndexOrThrow(
                    IndexDatabaseHelper.IndexColumns.DATA_PACKAGE));
            authority = enabledResults.getString(enabledResults.getColumnIndexOrThrow(
                    DATA_AUTHORITY));
            final String key = enabledResults.getString(enabledResults.getColumnIndexOrThrow(
                    IndexDatabaseHelper.IndexColumns.DATA_KEY_REF));
            final Set<String> packageKeys = nonIndexableKeys.get(packageName);
                    DATA_KEY_REF));
            final Set<String> authorityKeys = nonIndexableKeys.get(authority);

            // The indexed item is set to Enabled but is now non-indexable
            if (packageKeys != null && packageKeys.contains(key)) {
            if (authorityKeys != null && authorityKeys.contains(key)) {
                final String whereClause = getKeyWhereClause(key);
                database.update(TABLE_PREFS_INDEX, enabledToDisabledValue, whereClause, null);
            }
@@ -279,17 +281,17 @@ public class DatabaseIndexingManager {
        disabledToEnabledValue.put(ENABLED, 1);

        while (disabledResults.moveToNext()) {
            packageName = disabledResults.getString(disabledResults.getColumnIndexOrThrow(
                    IndexDatabaseHelper.IndexColumns.DATA_PACKAGE));
            authority = disabledResults.getString(disabledResults.getColumnIndexOrThrow(
                    DATA_AUTHORITY));

            final String key = disabledResults.getString(disabledResults.getColumnIndexOrThrow(
                    IndexDatabaseHelper.IndexColumns.DATA_KEY_REF));
            final Set<String> packageKeys = nonIndexableKeys.get(packageName);
                    DATA_KEY_REF));
            final Set<String> authorityKeys = nonIndexableKeys.get(authority);

            // The indexed item is set to Disabled but is no longer non-indexable.
            // We do not enable keys when packageKeys is null because it means the keys came
            // from an unrecognized package and therefore should not be surfaced as results.
            if (packageKeys != null && !packageKeys.contains(key)) {
            // We do not enable keys when authorityKeys is null because it means the keys came
            // from an unrecognized authority and therefore should not be surfaced as results.
            if (authorityKeys != null && !authorityKeys.contains(key)) {
                final String whereClause = getKeyWhereClause(key);
                database.update(TABLE_PREFS_INDEX, disabledToEnabledValue, whereClause, null);
            }
+8 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class IndexData {
     * @see SearchIndexableData#iconResId
     */
    public final String packageName;
    public final String authority;
    public final String locale;
    public final String updatedTitle;
    public final String normalizedTitle;
@@ -87,6 +88,7 @@ public class IndexData {
        spaceDelimitedKeywords = normalizeKeywords(builder.mKeywords);
        intentAction = builder.mIntentAction;
        packageName = builder.mPackageName;
        authority = builder.mAuthority;
        intentTargetPackage = builder.mIntentTargetPackage;
        intentTargetClass = builder.mIntentTargetClass;
        enabled = builder.mEnabled;
@@ -155,6 +157,7 @@ public class IndexData {
        private String mChildClassName;
        private String mScreenTitle;
        private String mPackageName;
        private String mAuthority;
        private int mIconResId;
        private String mKeywords;
        private String mIntentAction;
@@ -213,6 +216,11 @@ public class IndexData {
            return this;
        }

        public Builder setAuthority(String authority) {
            mAuthority = authority;
            return this;
        }

        public Builder setIconResId(int iconResId) {
            mIconResId = iconResId;
            return this;
+32 −24
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@ package com.android.settings.intelligence.search.indexing;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.AsyncTask;
import android.provider.SearchIndexableData;
import android.provider.SearchIndexableResource;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.collection.ArraySet;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -42,7 +42,6 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -74,27 +73,34 @@ public class IndexDataConverter {
     */
    public List<IndexData> convertPreIndexDataToIndexData(PreIndexData preIndexData) {
        final long startConversion = System.currentTimeMillis();
        final List<SearchIndexableData> indexableData = preIndexData.getDataToUpdate();
        final Map<String, List<SearchIndexableData>> indexableDataMap =
                preIndexData.getDataToUpdate();
        final Map<String, Set<String>> nonIndexableKeys = preIndexData.getNonIndexableKeys();
        final List<IndexData> indexData = new ArrayList<>();

        for (Map.Entry<String, List<SearchIndexableData>> entry : indexableDataMap.entrySet()) {
            final String authority = entry.getKey();
            final List<SearchIndexableData> indexableData = entry.getValue();

            for (SearchIndexableData data : indexableData) {
                if (data instanceof SearchIndexableRaw) {
                    final SearchIndexableRaw rawData = (SearchIndexableRaw) data;
                final Set<String> rawNonIndexableKeys = nonIndexableKeys.get(
                        rawData.intentTargetPackage);
                final IndexData convertedRaw = convertRaw(mContext, rawData, rawNonIndexableKeys);
                    final Set<String> rawNonIndexableKeys = nonIndexableKeys.get(authority);
                    final IndexData convertedRaw = convertRaw(mContext, authority, rawData,
                            rawNonIndexableKeys);
                    if (convertedRaw != null) {
                        indexData.add(convertedRaw);
                    }
                } else if (data instanceof SearchIndexableResource) {
                    final SearchIndexableResource sir = (SearchIndexableResource) data;
                    final Set<String> resourceNonIndexableKeys =
                        getNonIndexableKeysForResource(nonIndexableKeys, sir.packageName);
                final List<IndexData> resourceData = convertResource(sir, resourceNonIndexableKeys);
                            getNonIndexableKeysForResource(nonIndexableKeys, authority);
                    final List<IndexData> resourceData = convertResource(sir, authority,
                            resourceNonIndexableKeys);
                    indexData.addAll(resourceData);
                }
            }
        }

        final long endConversion = System.currentTimeMillis();
        Log.d(TAG, "Converting pre-index data to index data took: "
@@ -150,10 +156,10 @@ public class IndexDataConverter {
     * and there is some data sanitization in the conversion.
     */
    @Nullable
    private IndexData convertRaw(Context context, SearchIndexableRaw raw,
    private IndexData convertRaw(Context context, String authority, SearchIndexableRaw raw,
            Set<String> nonIndexableKeys) {
        if (TextUtils.isEmpty(raw.key)) {
            Log.w(TAG, "Skipping null key for raw indexable " + raw.packageName + "/" + raw.title);
            Log.w(TAG, "Skipping null key for raw indexable " + authority + "/" + raw.title);
            return null;
        }
        // A row is enabled if it does not show up as an nonIndexableKey
@@ -172,6 +178,7 @@ public class IndexDataConverter {
                .setIntentTargetClass(raw.intentTargetClass)
                .setEnabled(enabled)
                .setPackageName(raw.packageName)
                .setAuthority(authority)
                .setKey(raw.key);

        return builder.build(context);
@@ -184,7 +191,7 @@ public class IndexDataConverter {
     *
     * TODO (b/33577327) simplify this method.
     */
    private List<IndexData> convertResource(SearchIndexableResource sir,
    private List<IndexData> convertResource(SearchIndexableResource sir, String authority,
            Set<String> nonIndexableKeys) {
        final Context context = sir.context;
        XmlResourceParser parser = null;
@@ -244,6 +251,7 @@ public class IndexDataConverter {
                    .setKeywords(headerKeywords)
                    .setClassName(sir.className)
                    .setPackageName(sir.packageName)
                    .setAuthority(authority)
                    .setIntentAction(sir.intentAction)
                    .setIntentTargetPackage(sir.intentTargetPackage)
                    .setIntentTargetClass(sir.intentTargetClass)
@@ -285,6 +293,7 @@ public class IndexDataConverter {
                        .setScreenTitle(screenTitle)
                        .setIconResId(iconResId)
                        .setPackageName(sir.packageName)
                        .setAuthority(authority)
                        .setIntentAction(sir.intentAction)
                        .setIntentTargetPackage(sir.intentTargetPackage)
                        .setIntentTargetClass(sir.intentTargetClass)
@@ -352,9 +361,8 @@ public class IndexDataConverter {
    }

    private Set<String> getNonIndexableKeysForResource(Map<String, Set<String>> nonIndexableKeys,
            String packageName) {
        return nonIndexableKeys.containsKey(packageName)
                ? nonIndexableKeys.get(packageName)
                : new HashSet<String>();
            String authority) {
        final Set<String> result = nonIndexableKeys.get(authority);
        return result != null ? result : new ArraySet<>();
    }
}
Loading