Fix search results for backup settings.
Make BackupSettingsAcitivity searchable and remove PrivacySettings from the search index. Bug: 35720213 Test: make RunSettingsRoboTests -j40 Change-Id: Id2e091c978e4da078dcc6bc57760ec830e439c0c
This commit is contained in:
@@ -50,7 +50,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Gesture lock pattern settings.
|
||||
*/
|
||||
public class PrivacySettings extends SettingsPreferenceFragment implements Indexable {
|
||||
public class PrivacySettings extends SettingsPreferenceFragment {
|
||||
|
||||
// Vendor specific
|
||||
private static final String GSETTINGS_PROVIDER = "com.google.settings";
|
||||
@@ -225,49 +225,6 @@ public class PrivacySettings extends SettingsPreferenceFragment implements Index
|
||||
return R.string.help_url_backup_reset;
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new PrivacySearchIndexProvider();
|
||||
|
||||
private static class PrivacySearchIndexProvider extends BaseSearchIndexProvider {
|
||||
|
||||
boolean mIsPrimary;
|
||||
|
||||
public PrivacySearchIndexProvider() {
|
||||
super();
|
||||
|
||||
mIsPrimary = UserHandle.myUserId() == UserHandle.USER_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
|
||||
List<SearchIndexableResource> result = new ArrayList<SearchIndexableResource>();
|
||||
|
||||
// For non-primary user, no backup or reset is available
|
||||
// TODO: http://b/22388012
|
||||
if (!mIsPrimary) {
|
||||
return result;
|
||||
}
|
||||
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.privacy_settings;
|
||||
result.add(sir);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> nonVisibleKeys = new ArrayList<>();
|
||||
getNonVisibleKeys(context, nonVisibleKeys);
|
||||
return nonVisibleKeys;
|
||||
}
|
||||
}
|
||||
|
||||
private static void getNonVisibleKeys(Context context, Collection<String> nonVisibleKeys) {
|
||||
final IBackupManager backupManager = IBackupManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||
|
@@ -18,18 +18,29 @@ package com.android.settings.backup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* The activity used to launch the configured Backup activity or the preference screen
|
||||
* if the manufacturer provided their backup settings.
|
||||
*/
|
||||
public class BackupSettingsActivity extends Activity {
|
||||
public class BackupSettingsActivity extends Activity implements Indexable {
|
||||
private static final String TAG = "BackupSettingsActivity";
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
@@ -68,6 +79,52 @@ public class BackupSettingsActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
private static final String BACKUP_SEARCH_INDEX_KEY = "backup";
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
|
||||
boolean enabled) {
|
||||
|
||||
final List<SearchIndexableRaw> result = new ArrayList<>();
|
||||
|
||||
// Add the activity title
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.title = context.getResources().getString(R.string.privacy_settings_title);
|
||||
data.screenTitle = context.getResources().getString(
|
||||
R.string.privacy_settings_title);
|
||||
data.keywords = context.getResources().getString(
|
||||
R.string.keywords_backup);
|
||||
data.intentTargetPackage = context.getPackageName();
|
||||
data.intentTargetClass = BackupSettingsActivity.class.getName();
|
||||
data.intentAction = "android.intent.action.MAIN";
|
||||
data.key = BACKUP_SEARCH_INDEX_KEY;
|
||||
result.add(data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> keys = new ArrayList<String>();
|
||||
|
||||
// For non-primary user, no backup is available, so don't show it in search
|
||||
// TODO: http://b/22388012
|
||||
if (UserHandle.myUserId() != UserHandle.USER_SYSTEM) {
|
||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||
Log.d(TAG, "Not a system user, not indexing the screen");
|
||||
}
|
||||
keys.add(BACKUP_SEARCH_INDEX_KEY);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
void setFragmentManager(FragmentManager fragmentManager) {
|
||||
mFragmentManager = fragmentManager;
|
||||
|
@@ -18,11 +18,6 @@ package com.android.settings.backup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
@@ -32,7 +27,6 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -72,15 +66,10 @@ public class BackupSettingsFragment extends DashboardFragment {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
// The intention is to index {@link BackupSettingsActivity} instead of the fragments,
|
||||
// therefore leaving this index provider empty.
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.backup_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
|
@@ -38,6 +38,7 @@ import com.android.settings.applications.AdvancedAppSettings;
|
||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||
import com.android.settings.applications.SpecialAccessSettings;
|
||||
import com.android.settings.applications.assist.ManageAssist;
|
||||
import com.android.settings.backup.BackupSettingsActivity;
|
||||
import com.android.settings.backup.BackupSettingsFragment;
|
||||
import com.android.settings.bluetooth.BluetoothSettings;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||
@@ -162,7 +163,7 @@ public final class SearchIndexableResources {
|
||||
addIndex(AvailableVirtualKeyboardFragment.class,
|
||||
NO_DATA_RES_ID, R.drawable.ic_settings_language);
|
||||
addIndex(PhysicalKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
|
||||
addIndex(PrivacySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup);
|
||||
addIndex(BackupSettingsActivity.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup);
|
||||
addIndex(BackupSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup);
|
||||
addIndex(DateTimeSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_date_time);
|
||||
addIndex(AccessibilitySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility);
|
||||
|
Reference in New Issue
Block a user