From 01a964d7fbba63c670062ffca9a0ebe30cdcb1ff Mon Sep 17 00:00:00 2001 From: yueg Date: Tue, 3 Oct 2017 15:25:41 -0700 Subject: Make incoming and ongoing call notification foreground and highest priority. Use startForeground()/stopForeground() for posting notification instead of NotificationManager.notify()/cancel(). It makes incoming and ongoing notification foreground and not able to snooze. It also colorize ongoing call notification for Android O, since we already setColorized(). Use setPriority(Notification.PRIORITY_MAX) for pre-O, and NotificationManager.IMPORTANCE_MAX for O. It makes incoming and ongoing notification stay on the top. Test: StatusBarNotifierTest*2 PiperOrigin-RevId: 170924163 Change-Id: Iab1415b0161a4623a1ccf52d3948f32b6f93eeb2 --- java/com/android/incallui/call/TelecomAdapter.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'java/com/android/incallui/call/TelecomAdapter.java') diff --git a/java/com/android/incallui/call/TelecomAdapter.java b/java/com/android/incallui/call/TelecomAdapter.java index 005278bff..0c0bbd473 100644 --- a/java/com/android/incallui/call/TelecomAdapter.java +++ b/java/com/android/incallui/call/TelecomAdapter.java @@ -16,12 +16,14 @@ package com.android.incallui.call; +import android.app.Notification; import android.content.ActivityNotFoundException; import android.content.Intent; import android.os.Looper; import android.support.annotation.MainThread; import android.support.annotation.VisibleForTesting; import android.telecom.InCallService; +import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import java.util.List; @@ -167,4 +169,24 @@ public class TelecomAdapter implements InCallServiceListener { } return false; } + + /** + * Start a foreground notification. Calling it multiple times with the same id only updates the + * existing notification. Whoever called this function are responsible for calling {@link + * #stopForegroundNotification()} to remove the notification. + */ + public void startForegroundNotification(int id, Notification notification) { + Assert.isNotNull( + mInCallService, "No inCallService available for starting foreground notification"); + mInCallService.startForeground(id, notification); + } + + /** + * Stop a started foreground notification. This does not stop {@code mInCallService} from running. + */ + public void stopForegroundNotification() { + Assert.isNotNull( + mInCallService, "No inCallService available for stopping foreground notification"); + mInCallService.stopForeground(true /*removeNotification*/); + } } -- cgit v1.2.3