OSDN Git Service

Fix issue #8436951 JB-MR2: Compatibility: Audible, Pandora, ...
authorDianne Hackborn <hackbod@google.com>
Thu, 21 Mar 2013 21:23:46 +0000 (14:23 -0700)
committerDianne Hackborn <hackbod@google.com>
Thu, 21 Mar 2013 21:23:46 +0000 (14:23 -0700)
...Tune-In does not work since JWQ77

Instead of crashing the app for it being bad, just go ahead and
show a notification for it anyway that we make up.

You get what you deserve. :p

Change-Id: I92e32b9ff8835dabde63f8e08e991f72de0d0a92

core/res/res/values/strings.xml
core/res/res/values/symbols.xml
services/java/com/android/server/am/ServiceRecord.java

index 447d94c..54447e3 100644 (file)
     <!-- If the device is getting low on internal storage, a notification is shown to the user.  This is the message of that notification. -->
     <string name="low_internal_storage_view_text">Some system functions may not work</string>
 
+    <!-- [CHAR LIMIT=NONE] Stub notification title for an app running a service that has provided
+         a bad bad notification for itself. -->
+    <string name="app_running_notification_title"><xliff:g id="app_name">%1$s</xliff:g>
+        running</string>
+    <!-- [CHAR LIMIT=NONE] Stub notification text for an app running a service that has provided
+         a bad bad notification for itself. -->
+    <string name="app_running_notification_text"><xliff:g id="app_name">%1$s</xliff:g>
+        is currently running</string>
+
     <!-- Preference framework strings. -->
     <string name="ok">OK</string>
     <!-- Preference framework strings. -->
index d57d56a..0f396e0 100644 (file)
   <java-symbol type="string" name="addToDictionary" />
   <java-symbol type="string" name="action_bar_home_description" />
   <java-symbol type="string" name="action_bar_up_description" />
+  <java-symbol type="string" name="app_running_notification_title" />
+  <java-symbol type="string" name="app_running_notification_text" />
   <java-symbol type="string" name="delete" />
   <java-symbol type="string" name="deleteText" />
   <java-symbol type="string" name="ellipsis_two_dots" />
index 1ac6bdf..8ff1c7d 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.android.server.am;
 
+import android.app.PendingIntent;
+import android.net.Uri;
+import android.provider.Settings;
 import com.android.internal.os.BatteryStatsImpl;
 import com.android.server.NotificationManagerService;
 
@@ -369,6 +372,44 @@ class ServiceRecord extends Binder {
                     }
                     try {
                         if (foregroundNoti.icon == 0) {
+                            // It is not correct for the caller to supply a notification
+                            // icon, but this used to be able to slip through, so for
+                            // those dirty apps give it the app's icon.
+                            foregroundNoti.icon = appInfo.icon;
+                            if (foregroundNoti.contentView == null) {
+                                // In this case the app may not have specified a
+                                // content view...  so we'll give them something to show.
+                                CharSequence appName = appInfo.loadLabel(
+                                        ams.mContext.getPackageManager());
+                                if (appName == null) {
+                                    appName = appInfo.packageName;
+                                }
+                                Context ctx = null;
+                                try {
+                                    ctx = ams.mContext.createPackageContext(
+                                            appInfo.packageName, 0);
+                                    Intent runningIntent = new Intent(
+                                            Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+                                    runningIntent.setData(Uri.fromParts("package",
+                                            appInfo.packageName, null));
+                                    PendingIntent pi = PendingIntent.getActivity(ams.mContext, 0,
+                                            runningIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+                                    foregroundNoti.setLatestEventInfo(ctx,
+                                            ams.mContext.getString(
+                                                    com.android.internal.R.string
+                                                            .app_running_notification_title,
+                                                    appName),
+                                            ams.mContext.getString(
+                                                    com.android.internal.R.string
+                                                            .app_running_notification_text,
+                                                    appName),
+                                            pi);
+                                } catch (PackageManager.NameNotFoundException e) {
+                                    foregroundNoti.icon = 0;
+                                }
+                            }
+                        }
+                        if (foregroundNoti.icon == 0) {
                             // Notifications whose icon is 0 are defined to not show
                             // a notification, silently ignoring it.  We don't want to
                             // just ignore it, we want to prevent the service from