From 02bbaaa470db646334f529631e25cf70bb955571 Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Wed, 1 May 2019 16:55:33 -0400 Subject: [PATCH] Allow specifying full component names in sysui plugin whitelist This allows for a more granular whitelist, where a single package could have multiple plugins available but only a subset are enabled. Bug: 123881720 Test: manual Change-Id: Ie9b2c31f08d9dac8a892501345e8ff85143f40f9 --- .../shared/plugins/PluginInstanceManager.java | 32 ++++++++++++++++--- .../globalactions/GlobalActionsDialog.java | 1 + 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java index 40d98c1c08e48..f384507d302c9 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstanceManager.java @@ -151,19 +151,34 @@ public class PluginInstanceManager { return plugins.size() != 0; } - private void disable(PluginInfo info, - @PluginEnabler.DisableReason int reason) { + private boolean isPluginWhitelisted(ComponentName pluginName) { + for (String componentNameOrPackage : mWhitelistedPlugins) { + ComponentName componentName = ComponentName.unflattenFromString(componentNameOrPackage); + if (componentName == null) { + if (componentNameOrPackage.equals(pluginName.getPackageName())) { + return true; + } + } else { + if (componentName.equals(pluginName)) { + return true; + } + } + } + return false; + } + + private void disable(PluginInfo info, @PluginEnabler.DisableReason int reason) { // Live by the sword, die by the sword. // Misbehaving plugins get disabled and won't come back until uninstall/reinstall. + ComponentName pluginComponent = new ComponentName(info.mPackage, info.mClass); // If a plugin is detected in the stack of a crash then this will be called for that // plugin, if the plugin causing a crash cannot be identified, they are all disabled // assuming one of them must be bad. - if (mWhitelistedPlugins.contains(info.mPackage)) { + if (isPluginWhitelisted(pluginComponent)) { // Don't disable whitelisted plugins as they are a part of the OS. return; } - ComponentName pluginComponent = new ComponentName(info.mPackage, info.mClass); Log.w(TAG, "Disabling plugin " + pluginComponent.flattenToShortString()); mManager.getPluginEnabler().setDisabled(pluginComponent, reason); } @@ -288,6 +303,13 @@ public class PluginInstanceManager { if (result.size() > 1 && !mAllowMultiple) { // TODO: Show warning. Log.w(TAG, "Multiple plugins found for " + mAction); + if (DEBUG) { + for (ResolveInfo info : result) { + ComponentName name = new ComponentName(info.serviceInfo.packageName, + info.serviceInfo.name); + Log.w(TAG, " " + name); + } + } return; } for (ResolveInfo info : result) { @@ -305,7 +327,7 @@ public class PluginInstanceManager { protected PluginInfo handleLoadPlugin(ComponentName component) { // This was already checked, but do it again here to make extra extra sure, we don't // use these on production builds. - if (!isDebuggable && !mWhitelistedPlugins.contains(component.getPackageName())) { + if (!isDebuggable && !isPluginWhitelisted(component)) { // Never ever ever allow these on production builds, they are only for prototyping. Log.w(TAG, "Plugin cannot be loaded on production build: " + component); return null; diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java index 68d792e16274d..d6c8971866285 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java @@ -413,6 +413,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener, }, mKeyguardManager.isDeviceLocked()) : null; + ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController); dialog.setCanceledOnTouchOutside(false); // Handled by the custom class. dialog.setKeyguardShowing(mKeyguardShowing);