From f24850452900905daeb62886a07cbf4e6a890661 Mon Sep 17 00:00:00 2001 From: Beth Thibodeau Date: Fri, 18 Jun 2021 12:22:51 -0400 Subject: [PATCH] Use notification action to stop recording In S, contentIntent requires unlock. But since the stop action is a service intent, it can be sent by a Notification.Action without unlock Test: manual, atest RecordingServiceTest Fixes: 189654086 Change-Id: Ife5b039a8281fd0a74f495fbf8943943904e4792 --- .../systemui/screenrecord/RecordingService.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java index c6b5eb7508af0..5bb3413595ba8 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java @@ -291,19 +291,24 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis ? res.getString(R.string.screenrecord_ongoing_screen_only) : res.getString(R.string.screenrecord_ongoing_screen_and_audio); - Intent stopIntent = getNotificationIntent(this); + PendingIntent pendingIntent = PendingIntent.getService( + this, + REQUEST_CODE, + getNotificationIntent(this), + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); + Notification.Action stopAction = new Notification.Action.Builder( + Icon.createWithResource(this, R.drawable.ic_android), + getResources().getString(R.string.screenrecord_stop_label), + pendingIntent).build(); Notification.Builder builder = new Notification.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_screenrecord) .setContentTitle(notificationTitle) - .setContentText(getResources().getString(R.string.screenrecord_stop_text)) .setUsesChronometer(true) .setColorized(true) .setColor(getResources().getColor(R.color.GM2_red_700)) .setOngoing(true) .setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE) - .setContentIntent( - PendingIntent.getService(this, REQUEST_CODE, stopIntent, - PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)) + .addAction(stopAction) .addExtras(extras); startForeground(NOTIFICATION_RECORDING_ID, builder.build()); }