Merge "Move indexing into the Search Fragment"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5a2a8f8ad3
@@ -191,10 +191,12 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
|
||||||
if (action.equals(Intent.ACTION_USER_ADDED)
|
String action = intent.getAction();
|
||||||
|| action.equals(Intent.ACTION_USER_REMOVED)) {
|
if (action.equals(Intent.ACTION_USER_ADDED)
|
||||||
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
|| action.equals(Intent.ACTION_USER_REMOVED)) {
|
||||||
|
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -251,7 +253,9 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
if (!mSearchFeatureProvider.isEnabled(this)) {
|
||||||
|
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -400,7 +404,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
|
|
||||||
getFragmentManager().addOnBackStackChangedListener(this);
|
getFragmentManager().addOnBackStackChangedListener(this);
|
||||||
|
|
||||||
if (mIsShowingDashboard) {
|
if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
|
||||||
// Run the Index update only if we have some space
|
// Run the Index update only if we have some space
|
||||||
if (!Utils.isLowStorage(this)) {
|
if (!Utils.isLowStorage(this)) {
|
||||||
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
mSearchFeatureProvider.updateIndex(getApplicationContext());
|
||||||
@@ -642,8 +646,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
mDevelopmentPreferencesListener);
|
mDevelopmentPreferencesListener);
|
||||||
|
|
||||||
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
|
if (!mSearchFeatureProvider.isEnabled(this)) {
|
||||||
registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
|
registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
|
||||||
|
registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
|
||||||
|
}
|
||||||
if (mDynamicIndexableContentMonitor == null) {
|
if (mDynamicIndexableContentMonitor == null) {
|
||||||
mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
|
mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
|
||||||
}
|
}
|
||||||
@@ -659,7 +665,9 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
unregisterReceiver(mBatteryInfoReceiver);
|
unregisterReceiver(mBatteryInfoReceiver);
|
||||||
unregisterReceiver(mUserAddRemoveReceiver);
|
if (!mSearchFeatureProvider.isEnabled(this)) {
|
||||||
|
unregisterReceiver(mUserAddRemoveReceiver);
|
||||||
|
}
|
||||||
if (mDynamicIndexableContentMonitor != null) {
|
if (mDynamicIndexableContentMonitor != null) {
|
||||||
mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
|
mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
|
||||||
}
|
}
|
||||||
|
@@ -201,7 +201,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
reconstruct(db);
|
reconstruct(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reconstruct(SQLiteDatabase db) {
|
public void reconstruct(SQLiteDatabase db) {
|
||||||
dropTables(db);
|
dropTables(db);
|
||||||
bootstrapDB(db);
|
bootstrapDB(db);
|
||||||
}
|
}
|
||||||
|
@@ -152,7 +152,7 @@ public class DatabaseIndexingManager {
|
|||||||
return mIsAvailable.get();
|
return mIsAvailable.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void indexDatabase() {
|
||||||
AsyncTask.execute(new Runnable() {
|
AsyncTask.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@@ -85,10 +85,11 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
|||||||
public void updateIndex(Context context) {
|
public void updateIndex(Context context) {
|
||||||
long indexStartTime = System.currentTimeMillis();
|
long indexStartTime = System.currentTimeMillis();
|
||||||
if (isEnabled(context)) {
|
if (isEnabled(context)) {
|
||||||
getIndexingManager(context).update();
|
getIndexingManager(context).indexDatabase();
|
||||||
} else {
|
} else {
|
||||||
Index.getInstance(context).update();
|
Index.getInstance(context).update();
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Index.update() took " + (System.currentTimeMillis() - indexStartTime) + " ms");
|
Log.d(TAG, "IndexDatabase() took " +
|
||||||
|
(System.currentTimeMillis() - indexStartTime) + " ms");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ import android.support.annotation.VisibleForTesting;
|
|||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -34,6 +35,7 @@ import android.widget.SearchView;
|
|||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.InstrumentedFragment;
|
import com.android.settings.core.InstrumentedFragment;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
@@ -92,10 +94,19 @@ public class SearchFragment extends InstrumentedFragment implements
|
|||||||
loaderManager.initLoader(LOADER_ID_DATABASE, null, this);
|
loaderManager.initLoader(LOADER_ID_DATABASE, null, this);
|
||||||
loaderManager.initLoader(LOADER_ID_INSTALLED_APPS, null, this);
|
loaderManager.initLoader(LOADER_ID_INSTALLED_APPS, null, this);
|
||||||
}
|
}
|
||||||
final ActionBar actionBar = getActivity().getActionBar();
|
|
||||||
|
final Activity activity = getActivity();
|
||||||
|
final ActionBar actionBar = activity.getActionBar();
|
||||||
actionBar.setCustomView(makeSearchView(actionBar, mQuery));
|
actionBar.setCustomView(makeSearchView(actionBar, mQuery));
|
||||||
actionBar.setDisplayShowCustomEnabled(true);
|
actionBar.setDisplayShowCustomEnabled(true);
|
||||||
actionBar.setDisplayShowTitleEnabled(false);
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
|
|
||||||
|
// Run the Index update only if we have some space
|
||||||
|
if (!Utils.isLowStorage(activity)) {
|
||||||
|
mSearchFeatureProvider.updateIndex(activity);
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Cannot update the Indexer as we are running low on storage space!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -113,4 +113,16 @@ public class SearchFragmentTest {
|
|||||||
verify(mFeatureFactory.searchFeatureProvider)
|
verify(mFeatureFactory.searchFeatureProvider)
|
||||||
.getInstalledAppSearchLoader(any(Context.class), anyString());
|
.getInstalledAppSearchLoader(any(Context.class), anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateIndex_TriggerOnCreate() {
|
||||||
|
ActivityController<SearchActivity> activityController =
|
||||||
|
Robolectric.buildActivity(SearchActivity.class);
|
||||||
|
activityController.setup();
|
||||||
|
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||||
|
.findFragmentById(R.id.main_content);
|
||||||
|
|
||||||
|
fragment.onAttach(null);
|
||||||
|
verify(mFeatureFactory.searchFeatureProvider).updateIndex(any(Context.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user