From 3c530ff514e9973a4218b51dcbdd6bde2a3baa65 Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Wed, 21 Aug 2019 15:57:56 -0700 Subject: [PATCH] allow error notification in plugin framework to be shown in external process, such as Launcher Bug: 139823632 Change-Id: Id0307e483e66bd3c396f5355a526e4c728e68335 Test: Manual --- .../systemui/shared/plugins/PluginInstanceManager.java | 8 +++----- .../systemui/shared/plugins/PluginManagerImpl.java | 9 ++++----- .../shared/plugins/PluginInstanceManagerTest.java | 4 +--- 3 files changed, 8 insertions(+), 13 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 f384507d302c9..a37861068e48f 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 @@ -32,7 +32,6 @@ import android.os.Build; import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.os.UserHandle; import android.util.ArraySet; import android.util.Log; import android.view.LayoutInflater; @@ -359,8 +358,8 @@ public class PluginInstanceManager { if (DEBUG) Log.d(TAG, "createPlugin"); return new PluginInfo(pkg, cls, plugin, pluginContext, version); } catch (InvalidVersionException e) { - final int icon = mContext.getResources().getIdentifier("tuner", "drawable", - mContext.getPackageName()); + final int icon = Resources.getSystem().getIdentifier( + "stat_sys_warning", "drawable", "android"); final int color = Resources.getSystem().getIdentifier( "system_notification_accent_color", "color", "android"); final Notification.Builder nb = new Notification.Builder(mContext, @@ -392,8 +391,7 @@ public class PluginInstanceManager { PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, 0); nb.addAction(new Action.Builder(null, "Disable plugin", pi).build()); mContext.getSystemService(NotificationManager.class) - .notifyAsUser(cls, SystemMessage.NOTE_PLUGIN, nb.build(), - UserHandle.ALL); + .notify(SystemMessage.NOTE_PLUGIN, nb.build()); // TODO: Warn user. Log.w(TAG, "Plugin has invalid interface version " + plugin.getVersion() + ", expected " + mVersion); diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java index a7e3c59ce72ec..4d1fb38329e9d 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginManagerImpl.java @@ -33,7 +33,6 @@ import android.os.Build; import android.os.Handler; import android.os.Looper; import android.os.SystemProperties; -import android.os.UserHandle; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; @@ -235,8 +234,8 @@ public class PluginManagerImpl extends BroadcastReceiver implements PluginManage String pkg = data.getEncodedSchemeSpecificPart(); ComponentName componentName = ComponentName.unflattenFromString(pkg); if (mOneShotPackages.contains(pkg)) { - int icon = mContext.getResources().getIdentifier("tuner", "drawable", - mContext.getPackageName()); + int icon = Resources.getSystem().getIdentifier( + "stat_sys_warning", "drawable", "android"); int color = Resources.getSystem().getIdentifier( "system_notification_accent_color", "color", "android"); String label = pkg; @@ -260,8 +259,8 @@ public class PluginManagerImpl extends BroadcastReceiver implements PluginManage Uri.parse("package://" + pkg)); PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, 0); nb.addAction(new Action.Builder(null, "Restart SysUI", pi).build()); - mContext.getSystemService(NotificationManager.class).notifyAsUser(pkg, - SystemMessage.NOTE_PLUGIN, nb.build(), UserHandle.ALL); + mContext.getSystemService(NotificationManager.class) + .notify(SystemMessage.NOTE_PLUGIN, nb.build()); } if (clearClassLoader(pkg)) { if (Build.IS_ENG) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java index 7d95563f2ff18..325d540ad7417 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceManagerTest.java @@ -40,7 +40,6 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.os.HandlerThread; -import android.os.UserHandle; import android.test.suitebuilder.annotation.SmallTest; import androidx.test.annotation.UiThreadTest; @@ -168,8 +167,7 @@ public class PluginInstanceManagerTest extends SysuiTestCase { // Plugin shouldn't be connected because it is the wrong version. verify(mMockListener, never()).onPluginConnected(any(), any()); - verify(nm).notifyAsUser(eq(TestPlugin.class.getName()), eq(SystemMessage.NOTE_PLUGIN), - any(), eq(UserHandle.ALL)); + verify(nm).notify(eq(SystemMessage.NOTE_PLUGIN), any()); } @Test