From 588bfe051b45743701304a94d63b1eb43fdf8fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Go=CC=88llner?= Date: Wed, 31 May 2023 14:34:43 +0200 Subject: [PATCH] Partial screen sharing: show error notif when screen recording fails When starting a screen recording of a specific app, and the app is then removed from recents, there would be an error toast shown, but the "recording" notification was still showing, and interacting with it would do nothing. With this fix, we show an error notification for that case, which replaces the "recording" notification. Fixes: 250033241 Test: RecordingServiceTest.java Test: Manually - 1. Enable partial screen sharing 2. Start recording a specific app 3. Remove the app from recents before the recording starts Change-Id: Ic2dc8e6c40ba13d5feccc3deface0f62edabd6c8 --- .../systemui/screenrecord/RecordingService.java | 1 + .../systemui/screenrecord/RecordingServiceTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java index e1ac0fd1fd169..2c4555a2378a4 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java @@ -427,6 +427,7 @@ public class RecordingService extends Service implements ScreenMediaRecorderList Log.e(TAG, "stopRecording called, but there was an error when ending" + "recording"); exception.printStackTrace(); + createErrorNotification(); } catch (Throwable throwable) { // Something unexpected happen, SystemUI will crash but let's delete // the temporary files anyway diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingServiceTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingServiceTest.java index 3def6ba1fc583..8744aa346f8d0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingServiceTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingServiceTest.java @@ -203,6 +203,17 @@ public class RecordingServiceTest extends SysuiTestCase { verify(mScreenMediaRecorder).release(); } + @Test + public void testOnSystemRequestedStop_recorderEndThrowsRuntimeException_showsErrorNotification() + throws IOException { + doReturn(true).when(mController).isRecording(); + doThrow(new RuntimeException()).when(mScreenMediaRecorder).end(); + + mRecordingService.onStopped(); + + verify(mRecordingService).createErrorNotification(); + } + @Test public void testOnSystemRequestedStop_recorderEndThrowsOOMError_releasesRecording() throws IOException {