2121import android .animation .TimeInterpolator ;
2222import android .app .ActivityManager ;
2323import android .app .ActivityManagerNative ;
24+ import android .app .ActivityThread ;
2425import android .app .Notification ;
2526import android .app .PendingIntent ;
2627import android .app .TaskStackBuilder ;
3031import android .content .Intent ;
3132import android .content .IntentFilter ;
3233import android .content .pm .ApplicationInfo ;
34+ import android .content .pm .IPackageManager ;
35+ import android .content .pm .PackageInfo ;
3336import android .content .pm .PackageManager ;
3437import android .content .pm .PackageManager .NameNotFoundException ;
3538import android .content .pm .UserInfo ;
@@ -585,31 +588,12 @@ public boolean isMediaNotification(NotificationData.Entry entry) {
585588 entry .expandedBig .findViewById (com .android .internal .R .id .media_action_area ) != null ;
586589 }
587590
588- private void startApplicationDetailsActivity (String packageName ) {
589- Intent intent = new Intent (Settings .ACTION_APPLICATION_DETAILS_SETTINGS ,
590- Uri .fromParts ("package" , packageName , null ));
591- intent .setComponent (intent .resolveActivity (mContext .getPackageManager ()));
592- TaskStackBuilder .create (mContext ).addNextIntentWithParentStack (intent ).startActivities (
593- null , UserHandle .CURRENT );
594- }
595-
596- private static final int max (int ...args ) {
597- switch (args .length ) {
598- case 0 :
599- return 0 ;
600- case 1 :
601- return args [0 ];
602- case 2 :
603- return args [1 ] > args [0 ] ? args [1 ] : args [0 ];
604- default :
605- int m = args [0 ];
606- for (int i = 0 ; i < args .length ; i ++) {
607- if (args [i ] > m ) {
608- m = args [i ];
609- }
610- }
611- return m ;
612- }
591+ private void startAppNotificationSettingsActivity (String packageName , int appUid ) {
592+ Intent intent = new Intent (Settings .ACTION_APP_NOTIFICATION_SETTINGS );
593+ intent .putExtra (Settings .EXTRA_APP_PACKAGE , packageName );
594+ intent .putExtra (Settings .EXTRA_APP_UID , appUid );
595+ TaskStackBuilder .create (mContext ).addNextIntentWithParentStack (intent )
596+ .startActivities (null , new UserHandle (UserHandle .getUserId (appUid )));
613597 }
614598
615599 protected SwipeHelper .LongPressListener getNotificationLongClicker () {
@@ -618,8 +602,6 @@ protected SwipeHelper.LongPressListener getNotificationLongClicker() {
618602 public boolean onLongPress (View v , int x , int y ) {
619603 dismissPopups ();
620604
621- final String packageNameF = (String ) v .getTag ();
622- if (packageNameF == null ) return false ;
623605 if (v .getWindowToken () == null ) return false ;
624606
625607 // Assume we are a status_bar_notification_row
@@ -629,14 +611,6 @@ public boolean onLongPress(View v, int x, int y) {
629611 // Already showing?
630612 if (guts .getVisibility () == View .VISIBLE ) return false ;
631613
632- final View button = guts .findViewById (R .id .notification_inspect_item );
633- button .setOnClickListener (new View .OnClickListener () {
634- public void onClick (View v ) {
635- startApplicationDetailsActivity (packageNameF );
636- animateCollapsePanels (CommandQueue .FLAG_EXCLUDE_NONE );
637- }
638- });
639-
640614 guts .setVisibility (View .VISIBLE );
641615 final double horz = Math .max (v .getWidth () - x , x );
642616 final double vert = Math .max (v .getHeight () - y , y );
@@ -959,28 +933,10 @@ protected boolean inflateViewsForHeadsUp(NotificationData.Entry entry, ViewGroup
959933 return inflateViews (entry , parent , true );
960934 }
961935
962- private Drawable loadPackageIconDrawable (String pkg , int userId ) {
963- Drawable icon = null ;
964- try {
965- icon = mContext .getPackageManager ().getApplicationIcon (pkg );
966- } catch (PackageManager .NameNotFoundException e ) {
967- }
968-
969- return icon ;
970- }
971-
972- private CharSequence loadPackageName (String pkg ) {
973- final PackageManager pm = mContext .getPackageManager ();
974- try {
975- ApplicationInfo info = pm .getApplicationInfo (pkg ,
976- PackageManager .GET_UNINSTALLED_PACKAGES );
977- if (info != null ) return pm .getApplicationLabel (info );
978- } catch (PackageManager .NameNotFoundException e ) {
979- }
980- return pkg ;
981- }
982-
983936 private boolean inflateViews (NotificationData .Entry entry , ViewGroup parent , boolean isHeadsUp ) {
937+ PackageManager pmUser = getPackageManagerForUser (
938+ entry .notification .getUser ().getIdentifier ());
939+
984940 int maxHeight = mRowMaxHeight ;
985941 StatusBarNotification sbn = entry .notification ;
986942 RemoteViews contentView = sbn .getNotification ().contentView ;
@@ -1031,12 +987,43 @@ private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent, boo
1031987 // the notification inspector (see SwipeHelper.setLongPressListener)
1032988 row .setTag (sbn .getPackageName ());
1033989 final View guts = row .findViewById (R .id .notification_guts );
1034- final Drawable pkgicon = loadPackageIconDrawable (entry .notification .getPackageName (),
1035- entry .notification .getUserId ());
1036- final String pkgname = loadPackageName (entry .notification .getPackageName ()).toString ();
990+ final String pkg = entry .notification .getPackageName ();
991+ String appname = pkg ;
992+ Drawable pkgicon = null ;
993+ int appUid = -1 ;
994+ try {
995+ final ApplicationInfo info = pmUser .getApplicationInfo (pkg ,
996+ PackageManager .GET_UNINSTALLED_PACKAGES | PackageManager .GET_DISABLED_COMPONENTS );
997+ if (info != null ) {
998+ appname = String .valueOf (pmUser .getApplicationLabel (info ));
999+ pkgicon = pmUser .getApplicationIcon (info );
1000+ appUid = info .uid ;
1001+ }
1002+ } catch (NameNotFoundException e ) {
1003+ // app is gone, just show package name and generic icon
1004+ pkgicon = pmUser .getDefaultActivityIcon ();
1005+ }
10371006 ((ImageView ) row .findViewById (android .R .id .icon )).setImageDrawable (pkgicon );
10381007 ((DateTimeView ) row .findViewById (R .id .timestamp )).setTime (entry .notification .getPostTime ());
1039- ((TextView ) row .findViewById (R .id .pkgname )).setText (pkgname );
1008+ ((TextView ) row .findViewById (R .id .pkgname )).setText (appname );
1009+ final View settingsButton = guts .findViewById (R .id .notification_inspect_item );
1010+ if (appUid >= 0 ) {
1011+ final int appUidF = appUid ;
1012+ settingsButton .setOnClickListener (new View .OnClickListener () {
1013+ public void onClick (View v ) {
1014+ dismissKeyguardThenExecute (new OnDismissAction () {
1015+ public boolean onDismiss () {
1016+ startAppNotificationSettingsActivity (pkg , appUidF );
1017+ animateCollapsePanels (CommandQueue .FLAG_EXCLUDE_NONE );
1018+ visibilityChanged (false );
1019+ return DELAY_DISMISS_TO_ACTIVITY_LAUNCH ;
1020+ }
1021+ });
1022+ }
1023+ });
1024+ } else {
1025+ settingsButton .setVisibility (View .GONE );
1026+ }
10401027
10411028 workAroundBadLayerDrawableOpacity (row );
10421029 View vetoButton = updateNotificationVetoButton (row , sbn );
@@ -1108,18 +1095,15 @@ private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent, boo
11081095 }
11091096
11101097 if (publicViewLocal == null ) {
1111- PackageManager pm = getPackageManagerForUser (
1112- entry .notification .getUser ().getIdentifier ());
1113-
11141098 // Add a basic notification template
11151099 publicViewLocal = LayoutInflater .from (mContext ).inflate (
11161100 com .android .internal .R .layout .notification_template_material_base ,
11171101 expandedPublic , true );
11181102
11191103 final TextView title = (TextView ) publicViewLocal .findViewById (com .android .internal .R .id .title );
11201104 try {
1121- title .setText (pm .getApplicationLabel (
1122- pm .getApplicationInfo (entry .notification .getPackageName (), 0 )));
1105+ title .setText (pmUser .getApplicationLabel (
1106+ pmUser .getApplicationInfo (entry .notification .getPackageName (), 0 )));
11231107 } catch (NameNotFoundException e ) {
11241108 title .setText (entry .notification .getPackageName ());
11251109 }
0 commit comments