Add synchronous indexing api to SearchFeatureProvider
- Opens the database indexing to be synchronous for the external settings api. - Adds logging to track synchronous and async indexing times. Bug: 62826872 Test: make RunSettingsRoboTests Change-Id: I28b69f3952946c0ae5dd7ea7da66f7a5fd485637
This commit is contained in:
@@ -39,11 +39,14 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
@@ -115,6 +118,9 @@ import static com.android.settings.search.IndexDatabaseHelper.Tables.TABLE_PREFS
|
||||
public class DatabaseIndexingManager {
|
||||
private static final String LOG_TAG = "DatabaseIndexingManager";
|
||||
|
||||
private static final String METRICS_ACTION_SETTINGS_ASYNC_INDEX =
|
||||
"search_asynchronous_indexing";
|
||||
|
||||
public static final String FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER =
|
||||
"SEARCH_INDEX_DATA_PROVIDER";
|
||||
|
||||
@@ -156,8 +162,7 @@ public class DatabaseIndexingManager {
|
||||
* Only the first indexing for the default language gets static search results - subsequent
|
||||
* calls will only gather non-indexable keys.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void performIndexing() {
|
||||
public void performIndexing() {
|
||||
final Intent intent = new Intent(SearchIndexablesContract.PROVIDER_INTERFACE);
|
||||
final List<ResolveInfo> list =
|
||||
mContext.getPackageManager().queryIntentContentProviders(intent, 0);
|
||||
@@ -1262,6 +1267,7 @@ public class DatabaseIndexingManager {
|
||||
|
||||
@VisibleForTesting
|
||||
IndexingCallback mCallback;
|
||||
private long mIndexStartTime;
|
||||
|
||||
public IndexingTask(IndexingCallback callback) {
|
||||
mCallback = callback;
|
||||
@@ -1269,6 +1275,7 @@ public class DatabaseIndexingManager {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
mIndexStartTime = System.currentTimeMillis();
|
||||
mIsIndexingComplete.set(false);
|
||||
}
|
||||
|
||||
@@ -1280,6 +1287,10 @@ public class DatabaseIndexingManager {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
int indexingTime = (int) (System.currentTimeMillis() - mIndexStartTime);
|
||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
|
||||
.histogram(mContext, METRICS_ACTION_SETTINGS_ASYNC_INDEX, indexingTime);
|
||||
|
||||
mIsIndexingComplete.set(true);
|
||||
if (mCallback != null) {
|
||||
mCallback.onIndexingFinished();
|
||||
|
@@ -62,9 +62,15 @@ public interface SearchFeatureProvider {
|
||||
SiteMapManager getSiteMapManager();
|
||||
|
||||
/**
|
||||
* Updates the Settings indexes
|
||||
* Updates the Settings indexes and calls {@link IndexingCallback#onIndexingFinished()} on
|
||||
* {@param callback} when indexing is complete.
|
||||
*/
|
||||
void updateIndex(Context context, IndexingCallback callback);
|
||||
void updateIndexAsync(Context context, IndexingCallback callback);
|
||||
|
||||
/**
|
||||
* Synchronously updates the Settings database.
|
||||
*/
|
||||
void updateIndex(Context context);
|
||||
|
||||
/**
|
||||
* @returns true when indexing is complete.
|
||||
|
@@ -19,10 +19,9 @@ package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.applications.PackageManagerWrapperImpl;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* FeatureProvider for the refactored search code.
|
||||
@@ -31,6 +30,8 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
||||
|
||||
private static final String TAG = "SearchFeatureProvider";
|
||||
|
||||
private static final String METRICS_ACTION_SETTINGS_INDEX = "search_synchronous_indexing";
|
||||
|
||||
private DatabaseIndexingManager mDatabaseIndexingManager;
|
||||
private SiteMapManager mSiteMapManager;
|
||||
|
||||
@@ -78,11 +79,17 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIndex(Context context, IndexingCallback callback) {
|
||||
long indexStartTime = System.currentTimeMillis();
|
||||
public void updateIndexAsync(Context context, IndexingCallback callback) {
|
||||
getIndexingManager(context).indexDatabase(callback);
|
||||
Log.d(TAG, "IndexDatabase() took " +
|
||||
(System.currentTimeMillis() - indexStartTime) + " ms");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIndex(Context context) {
|
||||
long indexStartTime = System.currentTimeMillis();
|
||||
getIndexingManager(context).performIndexing();
|
||||
int indexingTime = (int) (System.currentTimeMillis() - indexStartTime);
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
|
||||
.histogram(context, METRICS_ACTION_SETTINGS_INDEX, indexingTime);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -156,7 +156,7 @@ public class SearchFragment extends InstrumentedFragment implements SearchView.O
|
||||
final Activity activity = getActivity();
|
||||
// Run the Index update only if we have some space
|
||||
if (!Utils.isLowStorage(activity)) {
|
||||
mSearchFeatureProvider.updateIndex(activity, this /* indexingCallback */);
|
||||
mSearchFeatureProvider.updateIndexAsync(activity, this /* indexingCallback */);
|
||||
} else {
|
||||
Log.w(TAG, "Cannot update the Indexer as we are running low on storage space!");
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import android.provider.SearchIndexableResource;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
@@ -131,6 +132,7 @@ public class DatabaseIndexingManagerTest {
|
||||
mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
}
|
||||
|
||||
@After
|
||||
|
@@ -268,7 +268,7 @@ public class SearchFragmentTest {
|
||||
.thenReturn(true);
|
||||
|
||||
fragment.onAttach(null);
|
||||
verify(mFeatureFactory.searchFeatureProvider).updateIndex(any(Context.class),
|
||||
verify(mFeatureFactory.searchFeatureProvider).updateIndexAsync(any(Context.class),
|
||||
any(IndexingCallback.class));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user