Move indexing into the Search Fragment
Cold start latency for Settings increased drastically
from the indexing of the Search Database. Moving it into
the Search Fragment moves that latency to cases where
users are actually searching.
Change-Id: I11368af610ac9e80f9901654f980c2c1e26342a5
Fixes: 34142852
Test: make RunSettingsRoboTests
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 0751b81..13bc048 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -191,10 +191,12 @@
private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (action.equals(Intent.ACTION_USER_ADDED)
- || action.equals(Intent.ACTION_USER_REMOVED)) {
- mSearchFeatureProvider.updateIndex(getApplicationContext());
+ 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());
+ }
}
}
};
@@ -251,7 +253,9 @@
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- mSearchFeatureProvider.updateIndex(getApplicationContext());
+ if (!mSearchFeatureProvider.isEnabled(this)) {
+ mSearchFeatureProvider.updateIndex(getApplicationContext());
+ }
}
@Override
@@ -400,7 +404,7 @@
getFragmentManager().addOnBackStackChangedListener(this);
- if (mIsShowingDashboard) {
+ if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
// Run the Index update only if we have some space
if (!Utils.isLowStorage(this)) {
mSearchFeatureProvider.updateIndex(getApplicationContext());
@@ -642,8 +646,10 @@
mDevelopmentPreferencesListener);
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
- registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
- registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
+ 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();
}
@@ -659,7 +665,9 @@
protected void onPause() {
super.onPause();
unregisterReceiver(mBatteryInfoReceiver);
- unregisterReceiver(mUserAddRemoveReceiver);
+ if (!mSearchFeatureProvider.isEnabled(this)) {
+ unregisterReceiver(mUserAddRemoveReceiver);
+ }
if (mDynamicIndexableContentMonitor != null) {
mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
}