Make Quick setttings developer tiles searchable
Bug: 286365859 Test: manual verify Change-Id: I2b3578d4aa80d48a4dcc29cfaac2f25089f0d4e8
This commit is contained in:
@@ -18,21 +18,26 @@ package com.android.settings.development.qstile;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SearchIndexable
|
||||
public class DevelopmentTileConfigFragment extends DashboardFragment {
|
||||
private static final String TAG = "DevelopmentTileConfig";
|
||||
private static final String QS_TILE_PERF = "develop_qs_tile";
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
@@ -56,5 +61,61 @@ public class DevelopmentTileConfigFragment extends DashboardFragment {
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
|
||||
boolean enabled) {
|
||||
List<SearchIndexableRaw> result = new ArrayList<>();
|
||||
// Save the query system property for getNonIndexableKeys to avoid
|
||||
// getTitleServiceList multiple times
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(QS_TILE_PERF,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
List<ServiceInfo> services =
|
||||
DevelopmentTilePreferenceController.getTileServiceList(context);
|
||||
PackageManager pm = context.getPackageManager();
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
for (ServiceInfo sInfo : services) {
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.title = sInfo.loadLabel(pm).toString();
|
||||
data.key = sInfo.name;
|
||||
result.add(data);
|
||||
|
||||
if (sInfo.metaData == null) {
|
||||
continue;
|
||||
}
|
||||
String flag = sInfo.metaData.getString(
|
||||
DevelopmentTiles.META_DATA_REQUIRES_SYSTEM_PROPERTY);
|
||||
if (flag == null) {
|
||||
continue;
|
||||
}
|
||||
editor.putString(sInfo.name, flag);
|
||||
}
|
||||
editor.apply();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
List<String> keys = super.getNonIndexableKeys(context);
|
||||
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(QS_TILE_PERF,
|
||||
Context.MODE_PRIVATE);
|
||||
Map<String, ?> map = sharedPref.getAll();
|
||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
||||
if (entry.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
String key = entry.getKey();
|
||||
String flag = entry.getValue().toString();
|
||||
|
||||
if (!SystemProperties.getBoolean(flag, false)) {
|
||||
keys.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import androidx.preference.SwitchPreference;
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DevelopmentTilePreferenceController extends BasePreferenceController {
|
||||
@@ -59,13 +60,9 @@ public class DevelopmentTilePreferenceController extends BasePreferenceControlle
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
final Context context = screen.getContext();
|
||||
final Intent intent = new Intent(TileService.ACTION_QS_TILE)
|
||||
.setPackage(context.getPackageName());
|
||||
final List<ResolveInfo> resolveInfos = mPackageManager.queryIntentServices(intent,
|
||||
PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.GET_META_DATA);
|
||||
for (ResolveInfo info : resolveInfos) {
|
||||
ServiceInfo sInfo = info.serviceInfo;
|
||||
List<ServiceInfo> serviceInfos = getTileServiceList(context);
|
||||
|
||||
for (ServiceInfo sInfo : serviceInfos) {
|
||||
// Check if the tile requires a flag. If it does, hide tile if flag is off.
|
||||
if (sInfo.metaData != null) {
|
||||
String flag = sInfo.metaData.getString(
|
||||
@@ -95,6 +92,24 @@ public class DevelopmentTilePreferenceController extends BasePreferenceControlle
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Quick Settings services from PackageManager
|
||||
*/
|
||||
public static List<ServiceInfo> getTileServiceList(Context context) {
|
||||
Intent intent = new Intent(TileService.ACTION_QS_TILE)
|
||||
.setPackage(context.getPackageName());
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
List<ResolveInfo> resolveInfos = packageManager.queryIntentServices(intent,
|
||||
PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.GET_META_DATA);
|
||||
|
||||
List<ServiceInfo> servicesInfos = new ArrayList<>();
|
||||
for (ResolveInfo info : resolveInfos) {
|
||||
ServiceInfo sInfo = info.serviceInfo;
|
||||
servicesInfos.add(sInfo);
|
||||
}
|
||||
return servicesInfos;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static class OnChangeHandler implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
|
Reference in New Issue
Block a user