Add support to hide developer tile based on a flag

Define new meta-data option for development tiles that can be used to
specify a sysprop flag.
If this meta-data is present, the value will be used as the flag name
that has to be enabled for the preference to show up.

Bug: 248363970
Test: atest SettingsRoboTests:DevelopmentTilePreferenceControllerTest
Change-Id: I66d56777a6290d7fee739492bd2871f637791d75
This commit is contained in:
Ats Jenk
2022-09-22 16:44:51 -07:00
parent 108b73d972
commit 618876c6c9
4 changed files with 84 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.service.quicksettings.TileService;
import android.util.Log;
@@ -61,9 +62,23 @@ public class DevelopmentTilePreferenceController extends BasePreferenceControlle
final Intent intent = new Intent(TileService.ACTION_QS_TILE)
.setPackage(context.getPackageName());
final List<ResolveInfo> resolveInfos = mPackageManager.queryIntentServices(intent,
PackageManager.MATCH_DISABLED_COMPONENTS);
PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.GET_META_DATA);
for (ResolveInfo info : resolveInfos) {
ServiceInfo sInfo = info.serviceInfo;
// 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(
DevelopmentTiles.META_DATA_REQUIRES_SYSTEM_PROPERTY);
if (flag != null) {
boolean enabled = SystemProperties.getBoolean(flag, false);
if (!enabled) {
// Flagged tile, flag is not enabled
continue;
}
}
}
final int enabledSetting = mPackageManager.getComponentEnabledSetting(
new ComponentName(sInfo.packageName, sInfo.name));
boolean checked = enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED

View File

@@ -58,6 +58,22 @@ import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.development.SystemPropPoker;
public abstract class DevelopmentTiles extends TileService {
/**
* Meta-data for a development tile to declare a sysprop flag that needs to be enabled for
* the tile to be available.
*
* To define the flag, set this meta-data on the tile's manifest declaration.
* <pre class="prettyprint">
* {@literal
* <meta-data android:name="com.android.settings.development.qstile.REQUIRES_SYSTEM_PROPERTY"
* android:value="persist.debug.flag_name_here" />
* }
* </pre>
*/
public static final String META_DATA_REQUIRES_SYSTEM_PROPERTY =
"com.android.settings.development.qstile.REQUIRES_SYSTEM_PROPERTY";
private static final String TAG = "DevelopmentTiles";
protected abstract boolean isEnabled();