Remove unneeded binder call Test: NotificationConversationInfoTest Test: NotificationInfoTest Test: manually long press on convo and normal notifs Fixes: 309461259 Change-Id: I7a896c8bf1e818823a91155b8761ba8c214bd059
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java index 14593cb..e141b7c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfo.java
@@ -16,6 +16,7 @@ package com.android.systemui.statusbar.notification.row; +import static android.app.Notification.EXTRA_BUILDER_APPLICATION_INFO; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; @@ -353,18 +354,15 @@ } private void bindPackage() { - ApplicationInfo info; - try { - info = mPm.getApplicationInfo( - mPackageName, - PackageManager.MATCH_UNINSTALLED_PACKAGES - | PackageManager.MATCH_DISABLED_COMPONENTS - | PackageManager.MATCH_DIRECT_BOOT_UNAWARE - | PackageManager.MATCH_DIRECT_BOOT_AWARE); - if (info != null) { + // filled in if missing during notification inflation, which must have happened if + // we have a notification to long press on + ApplicationInfo info = + mSbn.getNotification().extras.getParcelable(EXTRA_BUILDER_APPLICATION_INFO, + ApplicationInfo.class); + if (info != null) { + try { mAppName = String.valueOf(mPm.getApplicationLabel(info)); - } - } catch (PackageManager.NameNotFoundException e) { + } catch (Exception ignored) {} } ((TextView) findViewById(R.id.pkg_name)).setText(mAppName); }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java index d8ebd42..2012099 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java
@@ -16,6 +16,7 @@ package com.android.systemui.statusbar.notification.row; +import static android.app.Notification.EXTRA_BUILDER_APPLICATION_INFO; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; @@ -66,7 +67,6 @@ import java.lang.annotation.Retention; import java.util.List; -import java.util.Set; /** * The guts of a notification revealed when performing a long press. @@ -297,19 +297,18 @@ private void bindHeader() { // Package name mPkgIcon = null; - ApplicationInfo info; - try { - info = mPm.getApplicationInfo( - mPackageName, - PackageManager.MATCH_UNINSTALLED_PACKAGES - | PackageManager.MATCH_DISABLED_COMPONENTS - | PackageManager.MATCH_DIRECT_BOOT_UNAWARE - | PackageManager.MATCH_DIRECT_BOOT_AWARE); - if (info != null) { + // filled in if missing during notification inflation, which must have happened if + // we have a notification to long press on + ApplicationInfo info = + mSbn.getNotification().extras.getParcelable(EXTRA_BUILDER_APPLICATION_INFO, + ApplicationInfo.class); + if (info != null) { + try { mAppName = String.valueOf(mPm.getApplicationLabel(info)); mPkgIcon = mPm.getApplicationIcon(info); - } - } catch (PackageManager.NameNotFoundException e) { + } catch (Exception ignored) {} + } + if (mPkgIcon == null) { // app is gone, just show package name and generic icon mPkgIcon = mPm.getDefaultActivityIcon(); }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java index 1763d9b..3c1f559 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationConversationInfoTest.java
@@ -16,6 +16,7 @@ package com.android.systemui.statusbar.notification.row; +import static android.app.Notification.EXTRA_BUILDER_APPLICATION_INFO; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; @@ -183,8 +184,6 @@ .thenReturn(packageInfo); final ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.uid = TEST_UID; // non-zero - when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn( - applicationInfo); final PackageInfo systemPackageInfo = new PackageInfo(); systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) @@ -207,6 +206,7 @@ .addMessage(new Notification.MessagingStyle.Message( "hello!", 1000, new Person.Builder().setName("other").build()))) .build(); + notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, applicationInfo); mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, notification, UserHandle.CURRENT, null, 0); mEntry = new NotificationEntryBuilder().setSbn(mSbn).setShortcutInfo(mShortcutInfo).build();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java index b59385c..f31b1c4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java
@@ -16,6 +16,7 @@ package com.android.systemui.statusbar.notification.row; +import static android.app.Notification.EXTRA_BUILDER_APPLICATION_INFO; import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; @@ -143,8 +144,6 @@ .thenReturn(packageInfo); final ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.uid = TEST_UID; // non-zero - when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn( - applicationInfo); final PackageInfo systemPackageInfo = new PackageInfo(); systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) @@ -162,8 +161,10 @@ mDefaultNotificationChannel = new NotificationChannel( NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, IMPORTANCE_LOW); + Notification notification = new Notification(); + notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, applicationInfo); mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, - new Notification(), UserHandle.getUserHandleForUid(TEST_UID), null, 0); + notification, UserHandle.getUserHandleForUid(TEST_UID), null, 0); mEntry = new NotificationEntryBuilder().setSbn(mSbn).build(); when(mAssistantFeedbackController.isFeedbackEnabled()).thenReturn(false); when(mAssistantFeedbackController.getInlineDescriptionResource(any()))