OSDN Git Service

Foreground service notis must be correctly formed.
authorJulia Reynolds <juliacr@google.com>
Fri, 29 Sep 2017 19:52:37 +0000 (15:52 -0400)
committerJulia Reynolds <juliacr@google.com>
Fri, 29 Sep 2017 19:52:37 +0000 (15:52 -0400)
If an app targets api 26, it needs a notification channel, even for
foreground service notifications.

Change-Id: Id3131d4bb2748e9d23f66dd4f5570842bc50a44f
Fixes: 66905243
Test: manual

services/core/java/com/android/server/am/ServiceRecord.java
services/core/java/com/android/server/notification/NotificationManagerInternal.java
services/core/java/com/android/server/notification/NotificationManagerService.java

index 027dc08..ac85e6b 100644 (file)
@@ -517,11 +517,14 @@ final class ServiceRecord extends Binder {
                             } catch (PackageManager.NameNotFoundException e) {
                             }
                         }
-                        if (localForegroundNoti.getSmallIcon() == null) {
+                        if (localForegroundNoti.getSmallIcon() == null
+                                || nm.getNotificationChannel(localPackageName, appUid,
+                                localForegroundNoti.getChannelId()) == null) {
                             // 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
                             // being foreground.
+                            // Also every notification needs a channel.
                             throw new RuntimeException("invalid service notification: "
                                     + foregroundNoti);
                         }
index 4923b06..f1476b3 100644 (file)
 package com.android.server.notification;
 
 import android.app.Notification;
+import android.app.NotificationChannel;
 
 public interface NotificationManagerInternal {
+    NotificationChannel getNotificationChannel(String pkg, int uid, String channelId);
     void enqueueNotification(String pkg, String basePkg, int callingUid, int callingPid,
             String tag, int id, Notification notification, int userId);
 
index c6f2e8a..73017a4 100644 (file)
@@ -3373,6 +3373,12 @@ public class NotificationManagerService extends SystemService {
      */
     private final NotificationManagerInternal mInternalService = new NotificationManagerInternal() {
         @Override
+        public NotificationChannel getNotificationChannel(String pkg, int uid, String
+                channelId) {
+            return mRankingHelper.getNotificationChannel(pkg, uid, channelId, false);
+        }
+
+        @Override
         public void enqueueNotification(String pkg, String opPkg, int callingUid, int callingPid,
                 String tag, int id, Notification notification, int userId) {
             enqueueNotificationInternal(pkg, opPkg, callingUid, callingPid, tag, id, notification,