Misc clean up in search

- Remove updateFromClassNameResource() because it's just a no-op method.
- Simplify SearchIndexResources
- Update some pref pages to have unique keys.

Change-Id: I51e542d9947aafd046861ce7be0b4c7213fcd01d
Fixes: 64951285
Test: UniquePreferenceKeyTest
Test: robotest
Bug: 67852637
This commit is contained in:
Fan Zhang
2017-10-26 15:56:41 -07:00
parent 73bce67552
commit 823dde54c7
57 changed files with 124 additions and 127 deletions

View File

@@ -17,7 +17,6 @@
package com.android.settings;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.app.Activity;
@@ -382,14 +381,6 @@ public class SecuritySettings extends SettingsPreferenceFragment
// Advanced Security features
initTrustAgentPreference(root, numberOfTrustAgent);
// The above preferences come and go based on security state, so we need to update
// the index. This call is expected to be fairly cheap, but we may want to do something
// smarter in the future.
final Activity activity = getActivity();
FeatureFactory.getFactory(activity).getSearchFeatureProvider().getIndexingManager(activity)
.updateFromClassNameResource(SecuritySettings.class.getName(),
true /* includeInSearchResults */);
PreferenceGroup securityStatusPreferenceGroup =
(PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(

View File

@@ -54,7 +54,6 @@ import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.SearchFeatureProviderImpl;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.accounts.AuthenticatorHelper;
@@ -346,8 +345,6 @@ public class AccountPreferenceController extends AbstractPreferenceController
DISALLOW_MODIFY_ACCOUNTS, userInfo.id);
}
mProfiles.put(userInfo.id, profileData);
new SearchFeatureProviderImpl().getIndexingManager(mContext).updateFromClassNameResource(
UserAndAccountDashboardFragment.class.getName(), true /* includeInSearchResults */);
}
private DimmableIconPreference newAddAccountPreference(Context context) {

View File

@@ -20,7 +20,6 @@ import static android.provider.Settings.EXTRA_AUTHORITIES;
import android.app.Activity;
import android.content.Context;
import android.content.pm.UserInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
@@ -31,7 +30,6 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.drawer.Tile;
import java.util.ArrayList;
import java.util.Arrays;
@@ -40,7 +38,6 @@ import java.util.List;
public class UserAndAccountDashboardFragment extends DashboardFragment {
private static final String TAG = "UserAndAccountDashboard";
private static final String METADATA_IA_ACCOUNT = "com.android.settings.ia.account";
@Override
public int getMetricsCategory() {

View File

@@ -18,20 +18,18 @@
package com.android.settings.search;
import static com.android.settings.search.DatabaseResultLoader.COLUMN_INDEX_ID;
import static com.android.settings.search.DatabaseResultLoader
.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
import static com.android.settings.search.DatabaseResultLoader.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
import static com.android.settings.search.DatabaseResultLoader.COLUMN_INDEX_KEY;
import static com.android.settings.search.DatabaseResultLoader.SELECT_COLUMNS;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DOCID;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.CLASS_NAME;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_ENTRIES;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_KEY_REF;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns
.DATA_SUMMARY_ON_NORMALIZED;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_TITLE;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DOCID;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.ENABLED;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.ICON;
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.INTENT_ACTION;
@@ -53,14 +51,12 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.AsyncTask;
import android.os.Build;
import android.provider.SearchIndexableResource;
import android.provider.SearchIndexablesContract;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.indexing.IndexData;
import com.android.settings.search.indexing.IndexDataConverter;
import com.android.settings.search.indexing.PreIndexData;
@@ -365,36 +361,6 @@ public class DatabaseIndexingManager {
disabledResults.close();
}
/**
* TODO (b/64951285): Deprecate this method
*
* Update the Index for a specific class name resources
*
* @param className the class name (typically a fragment name).
* @param includeInSearchResults true means that you want the bit "enabled" set so that the
* data will be seen included into the search results
*/
public void updateFromClassNameResource(String className, boolean includeInSearchResults) {
if (className == null) {
throw new IllegalArgumentException("class name cannot be null!");
}
final SearchIndexableResource res = SearchIndexableResources.getResourceByName(className);
if (res == null) {
Log.e(LOG_TAG, "Cannot find SearchIndexableResources for class name: " + className);
return;
}
res.context = mContext;
res.enabled = includeInSearchResults;
AsyncTask.execute(new Runnable() {
@Override
public void run() {
// addIndexableData(res);
// updateDatabase(false, Locale.getDefault().toString());
// res.enabled = false;
}
});
}
private SQLiteDatabase getWritableDatabase() {
try {
return IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();

View File

@@ -19,7 +19,6 @@ package com.android.settings.search;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.XmlRes;
import android.text.TextUtils;
import com.android.settings.DateTimeSettings;
import com.android.settings.DeviceInfoSettings;
@@ -92,13 +91,6 @@ import java.util.Collection;
import java.util.HashMap;
public final class SearchIndexableResources {
/**
* Identifies subsettings which have an {@link SearchIndexableResource#intentAction} but
* whose intents should still be treated as subsettings inside of Settings.
*/
public static final String SUBSETTING_TARGET_PACKAGE = "subsetting_target_package";
@XmlRes
public static final int NO_RES_ID = 0;
@@ -107,20 +99,10 @@ public final class SearchIndexableResources {
@VisibleForTesting
static void addIndex(Class<?> indexClass) {
addIndex(indexClass, null /* targetAction */);
}
@VisibleForTesting
static void addIndex(Class<?> indexClass, String targetAction) {
String className = indexClass.getName();
SearchIndexableResource resource = new SearchIndexableResource(
0 /* rank */, NO_RES_ID, className, NO_RES_ID);
if (!TextUtils.isEmpty(targetAction)) {
resource.intentAction = targetAction;
resource.intentTargetPackage = SUBSETTING_TARGET_PACKAGE;
}
sResMap.put(className, resource);
}
@@ -133,11 +115,11 @@ public final class SearchIndexableResources {
addIndex(DataUsageSummary.class);
addIndex(DataUsageMeteredSettings.class);
addIndex(ScreenZoomSettings.class);
addIndex(DisplaySettings.class, "android.settings.DISPLAY_SETTINGS");
addIndex(DisplaySettings.class);
addIndex(AmbientDisplaySettings.class);
addIndex(WallpaperTypeSettings.class);
addIndex(AppAndNotificationDashboardFragment.class);
addIndex(SoundSettings.class, "android.settings.SOUND_SETTINGS");
addIndex(SoundSettings.class);
addIndex(ZenModeSettings.class);
addIndex(StorageSettings.class);
addIndex(PowerUsageAdvanced.class);

View File

@@ -26,7 +26,6 @@ import com.android.settings.SettingsActivity;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.ResultPayload;
import com.android.settings.search.ResultPayloadUtils;
import com.android.settings.search.SearchIndexableResources;
import java.text.Normalizer;
import java.util.Objects;
@@ -269,12 +268,10 @@ public class IndexData {
boolean isEmptyIntentAction = TextUtils.isEmpty(mIntentAction);
// No intent action is set, or the intent action is for a subsetting.
if (isEmptyIntentAction
|| TextUtils.equals(mIntentTargetPackage,
SearchIndexableResources.SUBSETTING_TARGET_PACKAGE)) {
if (isEmptyIntentAction) {
// Action is null, we will launch it as a sub-setting
intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context, mClassName, mKey,
mScreenTitle);
intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context, mClassName,
mKey, mScreenTitle);
} else {
intent = new Intent(mIntentAction);
final String targetClass = mIntentTargetClass;