From f3de8aa2cd72a4acd24d26ca0f807fd9d3b528eb Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 29 Sep 2017 15:52:37 -0400 Subject: [PATCH] Foreground service notis must be correctly formed. 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 | 5 ++++- .../server/notification/NotificationManagerInternal.java | 2 ++ .../server/notification/NotificationManagerService.java | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index 027dc0862e9de..ac85e6b132bf1 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -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); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerInternal.java b/services/core/java/com/android/server/notification/NotificationManagerInternal.java index 4923b06e9595e..f1476b34388b9 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerInternal.java +++ b/services/core/java/com/android/server/notification/NotificationManagerInternal.java @@ -17,8 +17,10 @@ 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); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index c6f2e8a4f512d..73017a4bcf8e2 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3372,6 +3372,12 @@ public class NotificationManagerService extends SystemService { * The private API only accessible to the system process. */ 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) {