Merge "Reserve full indexing for SearchFragment" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1261a679bf
@@ -362,7 +362,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
// smarter in the future.
|
||||
final Activity activity = getActivity();
|
||||
FeatureFactory.getFactory(activity).getSearchFeatureProvider().getIndexingManager(activity)
|
||||
.updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
|
||||
.updateFromClassNameResource(SecuritySettings.class.getName(),
|
||||
true /* includeInSearchResults */);
|
||||
|
||||
PreferenceGroup securityStatusPreferenceGroup =
|
||||
(PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
|
||||
|
@@ -30,7 +30,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -86,7 +85,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
// Constants for state save/restore
|
||||
private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
|
||||
private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
|
||||
private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
|
||||
|
||||
/**
|
||||
* When starting this activity, the invoking Intent can contain this extra
|
||||
@@ -188,19 +186,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(Intent.ACTION_USER_ADDED)
|
||||
|| action.equals(Intent.ACTION_USER_REMOVED)) {
|
||||
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
|
||||
|
||||
private ActionBar mActionBar;
|
||||
@@ -241,14 +226,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
if (!mSearchFeatureProvider.isEnabled(this)) {
|
||||
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
if (!mDisplaySearch) {
|
||||
@@ -346,15 +323,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
|
||||
getFragmentManager().addOnBackStackChangedListener(this);
|
||||
|
||||
if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
|
||||
// Run the Index update only if we have some space
|
||||
if (!Utils.isLowStorage(this)) {
|
||||
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
||||
} else {
|
||||
Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
|
||||
}
|
||||
}
|
||||
|
||||
if (savedState != null) {
|
||||
// We are restarting from a previous saved state; used that to initialize, instead
|
||||
// of starting fresh.
|
||||
@@ -568,10 +536,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
mDevelopmentPreferencesListener);
|
||||
|
||||
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
if (!mSearchFeatureProvider.isEnabled(this)) {
|
||||
registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
|
||||
registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
|
||||
}
|
||||
if (mDynamicIndexableContentMonitor == null) {
|
||||
mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
|
||||
}
|
||||
@@ -587,9 +551,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
mDevelopmentPreferencesListener);
|
||||
mDevelopmentPreferencesListener = null;
|
||||
unregisterReceiver(mBatteryInfoReceiver);
|
||||
if (!mSearchFeatureProvider.isEnabled(this)) {
|
||||
unregisterReceiver(mUserAddRemoveReceiver);
|
||||
}
|
||||
if (mDynamicIndexableContentMonitor != null) {
|
||||
mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
|
||||
}
|
||||
|
@@ -318,7 +318,7 @@ public class AccountPreferenceController extends PreferenceController
|
||||
}
|
||||
mProfiles.put(userInfo.id, profileData);
|
||||
new SearchFeatureProviderImpl().getIndexingManager(mContext).updateFromClassNameResource(
|
||||
UserAndAccountDashboardFragment.class.getName(), true, true);
|
||||
UserAndAccountDashboardFragment.class.getName(), true /* includeInSearchResults */);
|
||||
}
|
||||
|
||||
private DimmableIconPreference newAddAccountPreference(Context context) {
|
||||
|
@@ -221,6 +221,7 @@ public class BuildNumberPreferenceController extends PreferenceController
|
||||
mDevHitToast.show();
|
||||
// This is good time to index the Developer Options
|
||||
FeatureFactory.getFactory(mContext).getSearchFeatureProvider().getIndexingManager(mContext)
|
||||
.updateFromClassNameResource(DevelopmentSettings.class.getName(), true, true);
|
||||
.updateFromClassNameResource(DevelopmentSettings.class.getName(),
|
||||
true /* includeInSearchResults */);
|
||||
}
|
||||
}
|
||||
|
@@ -176,7 +176,7 @@ public final class DynamicIndexableContentMonitor implements
|
||||
public void onLoadFinished(Loader<List<PrintServiceInfo>> loader,
|
||||
List<PrintServiceInfo> services) {
|
||||
mIndexManager.updateFromClassNameResource(PrintSettingsFragment.class.getName(),
|
||||
false /* rebuild */, true /* includeInSearchResult */);
|
||||
true /* includeInSearchResults */);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,30 +213,30 @@ public final class DynamicIndexableContentMonitor implements
|
||||
if (mIndexManager != null) return;
|
||||
mIndexManager = indexManager;
|
||||
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
||||
buildIndex(true /* rebuild */);
|
||||
buildIndex();
|
||||
|
||||
// Watch for input device changes.
|
||||
mInputManager.registerInputDeviceListener(this /* listener */, null /* handler */);
|
||||
}
|
||||
|
||||
private void buildIndex(boolean rebuild) {
|
||||
private void buildIndex() {
|
||||
mIndexManager.updateFromClassNameResource(PhysicalKeyboardFragment.class.getName(),
|
||||
rebuild, true /* includeInSearchResult */);
|
||||
true /* includeInSearchResults */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
buildIndex(false /* rebuild */);
|
||||
buildIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
buildIndex(true /* rebuild */);
|
||||
buildIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
buildIndex(true /* rebuild */);
|
||||
buildIndex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ public final class DynamicIndexableContentMonitor implements
|
||||
mIndexManager = index;
|
||||
mPackageManager = context.getPackageManager();
|
||||
mAccessibilityServices.clear();
|
||||
buildIndex(true /* rebuild */);
|
||||
buildIndex();
|
||||
|
||||
// Cache accessibility service packages to know when they go away.
|
||||
AccessibilityManager accessibilityManager = (AccessibilityManager) context
|
||||
@@ -358,9 +358,9 @@ public final class DynamicIndexableContentMonitor implements
|
||||
}
|
||||
}
|
||||
|
||||
private void buildIndex(boolean rebuild) {
|
||||
private void buildIndex() {
|
||||
mIndexManager.updateFromClassNameResource(AccessibilitySettings.class.getName(),
|
||||
rebuild, true /* includeInSearchResult */);
|
||||
true /* includeInSearchResults */);
|
||||
}
|
||||
|
||||
synchronized void onPackageAvailable(String packageName) {
|
||||
@@ -372,13 +372,13 @@ public final class DynamicIndexableContentMonitor implements
|
||||
.queryIntentServices(intent, 0 /* flags */);
|
||||
if (services == null || services.isEmpty()) return;
|
||||
mAccessibilityServices.add(packageName);
|
||||
buildIndex(false /* rebuild */);
|
||||
buildIndex();
|
||||
}
|
||||
|
||||
synchronized void onPackageUnavailable(String packageName) {
|
||||
if (mIndexManager == null) return;
|
||||
if (!mAccessibilityServices.remove(packageName)) return;
|
||||
buildIndex(true /* rebuild */);
|
||||
buildIndex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,10 +428,10 @@ public final class DynamicIndexableContentMonitor implements
|
||||
mContentResolver = context.getContentResolver();
|
||||
mInputMethodServices.clear();
|
||||
// Build index of {@link UserDictionary}.
|
||||
buildIndex(LanguageAndInputSettings.class, true /* rebuild */);
|
||||
buildIndex(LanguageAndInputSettings.class);
|
||||
// Build index of IMEs.
|
||||
buildIndex(VirtualKeyboardFragment.class, true /* rebuild */);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class, true /* rebuild */);
|
||||
buildIndex(VirtualKeyboardFragment.class);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class);
|
||||
|
||||
// Cache IME service packages to know when they go away.
|
||||
final InputMethodManager inputMethodManager = (InputMethodManager) context
|
||||
@@ -452,9 +452,9 @@ public final class DynamicIndexableContentMonitor implements
|
||||
false /* notifyForDescendants */, this /* observer */);
|
||||
}
|
||||
|
||||
private void buildIndex(Class<?> indexClass, boolean rebuild) {
|
||||
mIndexManager.updateFromClassNameResource(indexClass.getName(), rebuild,
|
||||
true /* includeInSearchResult */);
|
||||
private void buildIndex(Class<?> indexClass) {
|
||||
mIndexManager.updateFromClassNameResource(indexClass.getName(),
|
||||
true /* includeInSearchResults */);
|
||||
}
|
||||
|
||||
synchronized void onPackageAvailable(String packageName) {
|
||||
@@ -466,24 +466,24 @@ public final class DynamicIndexableContentMonitor implements
|
||||
.queryIntentServices(intent, 0 /* flags */);
|
||||
if (services == null || services.isEmpty()) return;
|
||||
mInputMethodServices.add(packageName);
|
||||
buildIndex(VirtualKeyboardFragment.class, false /* rebuild */);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class, false /* rebuild */);
|
||||
buildIndex(VirtualKeyboardFragment.class);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class);
|
||||
}
|
||||
|
||||
synchronized void onPackageUnavailable(String packageName) {
|
||||
if (mIndexManager == null) return;
|
||||
if (!mInputMethodServices.remove(packageName)) return;
|
||||
buildIndex(VirtualKeyboardFragment.class, true /* rebuild */);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class, true /* rebuild */);
|
||||
buildIndex(VirtualKeyboardFragment.class);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (ENABLED_INPUT_METHODS_CONTENT_URI.equals(uri)) {
|
||||
buildIndex(VirtualKeyboardFragment.class, true /* rebuild */);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class, true /* rebuild */);
|
||||
buildIndex(VirtualKeyboardFragment.class);
|
||||
buildIndex(AvailableVirtualKeyboardFragment.class);
|
||||
} else if (UserDictionary.Words.CONTENT_URI.equals(uri)) {
|
||||
buildIndex(LanguageAndInputSettings.class, true /* rebuild */);
|
||||
buildIndex(LanguageAndInputSettings.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -187,6 +187,8 @@ public class DatabaseIndexingManager {
|
||||
|
||||
final String localeStr = Locale.getDefault().toString();
|
||||
updateDatabase(isLocaleIndexed, localeStr);
|
||||
|
||||
IndexDatabaseHelper.setLocaleIndexed(mContext, localeStr);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -242,8 +244,6 @@ public class DatabaseIndexingManager {
|
||||
} finally {
|
||||
database.endTransaction();
|
||||
}
|
||||
// TODO Refactor: move the locale out of the helper class
|
||||
IndexDatabaseHelper.setLocaleIndexed(mContext, localeStr);
|
||||
|
||||
mIsAvailable.set(true);
|
||||
}
|
||||
@@ -432,12 +432,10 @@ public class DatabaseIndexingManager {
|
||||
* Update the Index for a specific class name resources
|
||||
*
|
||||
* @param className the class name (typically a fragment name).
|
||||
* @param rebuild true means that you want to delete the data from the Index first.
|
||||
* @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, final boolean rebuild,
|
||||
boolean includeInSearchResults) {
|
||||
public void updateFromClassNameResource(String className, boolean includeInSearchResults) {
|
||||
if (className == null) {
|
||||
throw new IllegalArgumentException("class name cannot be null!");
|
||||
}
|
||||
@@ -452,26 +450,12 @@ public class DatabaseIndexingManager {
|
||||
@Override
|
||||
public void run() {
|
||||
addIndexableData(res);
|
||||
performIndexing();
|
||||
updateDatabase(false, Locale.getDefault().toString());
|
||||
res.enabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateFromSearchIndexableData(final SearchIndexableData data) {
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addIndexableData(data);
|
||||
performIndexing();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private SQLiteDatabase getReadableDatabase() {
|
||||
return IndexDatabaseHelper.getInstance(mContext).getReadableDatabase();
|
||||
}
|
||||
|
||||
private SQLiteDatabase getWritableDatabase() {
|
||||
try {
|
||||
return IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
|
Reference in New Issue
Block a user