Merge "Add synchronous indexing api to SearchFeatureProvider" into oc-dr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e2e54e17c7
@@ -39,11 +39,14 @@ import android.support.annotation.VisibleForTesting;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Pair;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
|
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
@@ -115,6 +118,9 @@ import static com.android.settings.search.IndexDatabaseHelper.Tables.TABLE_PREFS
|
|||||||
public class DatabaseIndexingManager {
|
public class DatabaseIndexingManager {
|
||||||
private static final String LOG_TAG = "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 =
|
public static final String FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER =
|
||||||
"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
|
* Only the first indexing for the default language gets static search results - subsequent
|
||||||
* calls will only gather non-indexable keys.
|
* calls will only gather non-indexable keys.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
public void performIndexing() {
|
||||||
void performIndexing() {
|
|
||||||
final Intent intent = new Intent(SearchIndexablesContract.PROVIDER_INTERFACE);
|
final Intent intent = new Intent(SearchIndexablesContract.PROVIDER_INTERFACE);
|
||||||
final List<ResolveInfo> list =
|
final List<ResolveInfo> list =
|
||||||
mContext.getPackageManager().queryIntentContentProviders(intent, 0);
|
mContext.getPackageManager().queryIntentContentProviders(intent, 0);
|
||||||
@@ -1262,6 +1267,7 @@ public class DatabaseIndexingManager {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
IndexingCallback mCallback;
|
IndexingCallback mCallback;
|
||||||
|
private long mIndexStartTime;
|
||||||
|
|
||||||
public IndexingTask(IndexingCallback callback) {
|
public IndexingTask(IndexingCallback callback) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
@@ -1269,6 +1275,7 @@ public class DatabaseIndexingManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
|
mIndexStartTime = System.currentTimeMillis();
|
||||||
mIsIndexingComplete.set(false);
|
mIsIndexingComplete.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1280,6 +1287,10 @@ public class DatabaseIndexingManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid) {
|
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);
|
mIsIndexingComplete.set(true);
|
||||||
if (mCallback != null) {
|
if (mCallback != null) {
|
||||||
mCallback.onIndexingFinished();
|
mCallback.onIndexingFinished();
|
||||||
|
@@ -62,9 +62,15 @@ public interface SearchFeatureProvider {
|
|||||||
SiteMapManager getSiteMapManager();
|
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.
|
* @returns true when indexing is complete.
|
||||||
|
@@ -19,10 +19,9 @@ package com.android.settings.search;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.android.settings.applications.PackageManagerWrapperImpl;
|
import com.android.settings.applications.PackageManagerWrapperImpl;
|
||||||
import com.android.settings.dashboard.SiteMapManager;
|
import com.android.settings.dashboard.SiteMapManager;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FeatureProvider for the refactored search code.
|
* 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 TAG = "SearchFeatureProvider";
|
||||||
|
|
||||||
|
private static final String METRICS_ACTION_SETTINGS_INDEX = "search_synchronous_indexing";
|
||||||
|
|
||||||
private DatabaseIndexingManager mDatabaseIndexingManager;
|
private DatabaseIndexingManager mDatabaseIndexingManager;
|
||||||
private SiteMapManager mSiteMapManager;
|
private SiteMapManager mSiteMapManager;
|
||||||
|
|
||||||
@@ -78,11 +79,17 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateIndex(Context context, IndexingCallback callback) {
|
public void updateIndexAsync(Context context, IndexingCallback callback) {
|
||||||
long indexStartTime = System.currentTimeMillis();
|
|
||||||
getIndexingManager(context).indexDatabase(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();
|
final Activity activity = getActivity();
|
||||||
// Run the Index update only if we have some space
|
// Run the Index update only if we have some space
|
||||||
if (!Utils.isLowStorage(activity)) {
|
if (!Utils.isLowStorage(activity)) {
|
||||||
mSearchFeatureProvider.updateIndex(activity, this /* indexingCallback */);
|
mSearchFeatureProvider.updateIndexAsync(activity, this /* indexingCallback */);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Cannot update the Indexer as we are running low on storage space!");
|
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 android.util.ArrayMap;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.DatabaseTestUtils;
|
import com.android.settings.testutils.DatabaseTestUtils;
|
||||||
@@ -131,6 +132,7 @@ public class DatabaseIndexingManagerTest {
|
|||||||
mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||||
|
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||||
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@@ -268,7 +268,7 @@ public class SearchFragmentTest {
|
|||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
|
|
||||||
fragment.onAttach(null);
|
fragment.onAttach(null);
|
||||||
verify(mFeatureFactory.searchFeatureProvider).updateIndex(any(Context.class),
|
verify(mFeatureFactory.searchFeatureProvider).updateIndexAsync(any(Context.class),
|
||||||
any(IndexingCallback.class));
|
any(IndexingCallback.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user