Loading services/core/java/com/android/server/am/ActiveServices.java +3 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import android.os.Build; import android.os.DeadObjectException; import android.os.Handler; import android.os.Looper; Loading Loading @@ -590,6 +591,8 @@ public final class ActiveServices { r.cancelNotification(); r.foregroundId = 0; r.foregroundNoti = null; } else if (r.appInfo.targetSdkVersion >= Build.VERSION_CODES.L) { r.stripForegroundServiceFlagFromNotification(); } } } Loading services/core/java/com/android/server/am/ServiceRecord.java +25 −0 Original line number Diff line number Diff line Loading @@ -518,6 +518,31 @@ final class ServiceRecord extends Binder { } } public void stripForegroundServiceFlagFromNotification() { if (foregroundId == 0) { return; } final int localForegroundId = foregroundId; final int localUserId = userId; final String localPackageName = packageName; // Do asynchronous communication with notification manager to // avoid deadlocks. ams.mHandler.post(new Runnable() { @Override public void run() { NotificationManagerInternal nmi = LocalServices.getService( NotificationManagerInternal.class); if (nmi == null) { return; } nmi.removeForegroundServiceFlagFromNotification(localPackageName, localForegroundId, localUserId); } }); } public void clearDeliveredStartsLocked() { for (int i=deliveredStarts.size()-1; i>=0; i--) { deliveredStarts.get(i).removeUriPermissionsLocked(); Loading services/core/java/com/android/server/notification/NotificationManagerInternal.java +2 −0 Original line number Diff line number Diff line Loading @@ -21,4 +21,6 @@ import android.app.Notification; public interface NotificationManagerInternal { void enqueueNotification(String pkg, String basePkg, int callingUid, int callingPid, String tag, int id, Notification notification, int[] idReceived, int userId); void removeForegroundServiceFlagFromNotification(String pkg, int notificationId, int userId); } services/core/java/com/android/server/notification/NotificationManagerService.java +24 −0 Original line number Diff line number Diff line Loading @@ -1610,6 +1610,30 @@ public class NotificationManagerService extends SystemService { enqueueNotificationInternal(pkg, opPkg, callingUid, callingPid, tag, id, notification, idReceived, userId); } @Override public void removeForegroundServiceFlagFromNotification(String pkg, int notificationId, int userId) { checkCallerIsSystem(); synchronized (mNotificationList) { int i = indexOfNotificationLocked(pkg, null, notificationId, userId); if (i < 0) { Log.d(TAG, "stripForegroundServiceFlag: Could not find notification with " + "pkg=" + pkg + " / id=" + notificationId + " / userId=" + userId); return; } NotificationRecord r = mNotificationList.get(i); StatusBarNotification sbn = r.sbn; // NoMan adds flags FLAG_NO_CLEAR and FLAG_ONGOING_EVENT when it sees // FLAG_FOREGROUND_SERVICE. Hence it's not enough to remove FLAG_FOREGROUND_SERVICE, // we have to revert to the flags we received initially *and* force remove // FLAG_FOREGROUND_SERVICE. sbn.getNotification().flags = (r.mOriginalFlags & ~Notification.FLAG_FOREGROUND_SERVICE); mRankingHelper.sort(mNotificationList); mListeners.notifyPostedLocked(sbn, sbn /* oldSbn */); } } }; void enqueueNotificationInternal(final String pkg, final String opPkg, final int callingUid, Loading services/core/java/com/android/server/notification/NotificationRecord.java +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,8 @@ import java.util.Objects; */ public final class NotificationRecord { final StatusBarNotification sbn; final int mOriginalFlags; NotificationUsageStats.SingleNotificationStats stats; boolean isCanceled; int score; Loading Loading @@ -73,6 +75,7 @@ public final class NotificationRecord { { this.sbn = sbn; this.score = score; mOriginalFlags = sbn.getNotification().flags; mRankingTimeMs = calculateRankingTimeMs(0L); } Loading Loading
services/core/java/com/android/server/am/ActiveServices.java +3 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import android.os.Build; import android.os.DeadObjectException; import android.os.Handler; import android.os.Looper; Loading Loading @@ -590,6 +591,8 @@ public final class ActiveServices { r.cancelNotification(); r.foregroundId = 0; r.foregroundNoti = null; } else if (r.appInfo.targetSdkVersion >= Build.VERSION_CODES.L) { r.stripForegroundServiceFlagFromNotification(); } } } Loading
services/core/java/com/android/server/am/ServiceRecord.java +25 −0 Original line number Diff line number Diff line Loading @@ -518,6 +518,31 @@ final class ServiceRecord extends Binder { } } public void stripForegroundServiceFlagFromNotification() { if (foregroundId == 0) { return; } final int localForegroundId = foregroundId; final int localUserId = userId; final String localPackageName = packageName; // Do asynchronous communication with notification manager to // avoid deadlocks. ams.mHandler.post(new Runnable() { @Override public void run() { NotificationManagerInternal nmi = LocalServices.getService( NotificationManagerInternal.class); if (nmi == null) { return; } nmi.removeForegroundServiceFlagFromNotification(localPackageName, localForegroundId, localUserId); } }); } public void clearDeliveredStartsLocked() { for (int i=deliveredStarts.size()-1; i>=0; i--) { deliveredStarts.get(i).removeUriPermissionsLocked(); Loading
services/core/java/com/android/server/notification/NotificationManagerInternal.java +2 −0 Original line number Diff line number Diff line Loading @@ -21,4 +21,6 @@ import android.app.Notification; public interface NotificationManagerInternal { void enqueueNotification(String pkg, String basePkg, int callingUid, int callingPid, String tag, int id, Notification notification, int[] idReceived, int userId); void removeForegroundServiceFlagFromNotification(String pkg, int notificationId, int userId); }
services/core/java/com/android/server/notification/NotificationManagerService.java +24 −0 Original line number Diff line number Diff line Loading @@ -1610,6 +1610,30 @@ public class NotificationManagerService extends SystemService { enqueueNotificationInternal(pkg, opPkg, callingUid, callingPid, tag, id, notification, idReceived, userId); } @Override public void removeForegroundServiceFlagFromNotification(String pkg, int notificationId, int userId) { checkCallerIsSystem(); synchronized (mNotificationList) { int i = indexOfNotificationLocked(pkg, null, notificationId, userId); if (i < 0) { Log.d(TAG, "stripForegroundServiceFlag: Could not find notification with " + "pkg=" + pkg + " / id=" + notificationId + " / userId=" + userId); return; } NotificationRecord r = mNotificationList.get(i); StatusBarNotification sbn = r.sbn; // NoMan adds flags FLAG_NO_CLEAR and FLAG_ONGOING_EVENT when it sees // FLAG_FOREGROUND_SERVICE. Hence it's not enough to remove FLAG_FOREGROUND_SERVICE, // we have to revert to the flags we received initially *and* force remove // FLAG_FOREGROUND_SERVICE. sbn.getNotification().flags = (r.mOriginalFlags & ~Notification.FLAG_FOREGROUND_SERVICE); mRankingHelper.sort(mNotificationList); mListeners.notifyPostedLocked(sbn, sbn /* oldSbn */); } } }; void enqueueNotificationInternal(final String pkg, final String opPkg, final int callingUid, Loading
services/core/java/com/android/server/notification/NotificationRecord.java +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,8 @@ import java.util.Objects; */ public final class NotificationRecord { final StatusBarNotification sbn; final int mOriginalFlags; NotificationUsageStats.SingleNotificationStats stats; boolean isCanceled; int score; Loading Loading @@ -73,6 +75,7 @@ public final class NotificationRecord { { this.sbn = sbn; this.score = score; mOriginalFlags = sbn.getNotification().flags; mRankingTimeMs = calculateRankingTimeMs(0L); } Loading