Loading packages/SystemUI/res/values/strings.xml +2 −3 Original line number Diff line number Diff line Loading @@ -295,9 +295,8 @@ <string name="screenrecord_save_title">Screen recording saved</string> <!-- Subtext for a notification shown after saving a screen recording to prompt the user to view it [CHAR_LIMIT=100] --> <string name="screenrecord_save_text">Tap to view</string> <!-- A toast message shown when there is an error deleting a screen recording [CHAR LIMIT=NONE] --> <string name="screenrecord_delete_error">Error deleting screen recording</string> <!-- A toast message shown when the screen recording cannot be started due to insufficient permissions [CHAR LIMIT=NONE] --> <!-- A toast message shown when there is an error saving a screen recording [CHAR LIMIT=NONE] --> <string name="screenrecord_save_error">Error saving screen recording</string> <!-- A toast message shown when the screen recording cannot be started due to a generic error [CHAR LIMIT=NONE] --> <string name="screenrecord_start_error">Error starting screen recording</string> Loading packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +2 −2 Original line number Diff line number Diff line Loading @@ -453,9 +453,9 @@ public class RecordingService extends Service implements ScreenMediaRecorderList postGroupNotification(currentUser); mNotificationManager.notifyAsUser(null, mNotificationId, notification, currentUser); } catch (IOException e) { } catch (IOException | IllegalStateException e) { Log.e(TAG, "Error saving screen recording: " + e.getMessage()); showErrorToast(R.string.screenrecord_delete_error); showErrorToast(R.string.screenrecord_save_error); mNotificationManager.cancelAsUser(null, mNotificationId, currentUser); } }); Loading packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java +3 −2 Original line number Diff line number Diff line Loading @@ -52,8 +52,9 @@ import android.view.Surface; import android.view.WindowManager; import com.android.systemui.media.MediaProjectionCaptureTarget; import java.io.File; import java.io.Closeable; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; Loading Loading @@ -321,7 +322,7 @@ public class ScreenMediaRecorder extends MediaProjection.Callback { /** * Store recorded video */ protected SavedRecording save() throws IOException { protected SavedRecording save() throws IOException, IllegalStateException { String fileName = new SimpleDateFormat("'screen-'yyyyMMdd-HHmmss'.mp4'") .format(new Date()); Loading packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordingMuxer.java +5 −3 Original line number Diff line number Diff line Loading @@ -52,9 +52,8 @@ public class ScreenRecordingMuxer { /** * RUN IN THE BACKGROUND THREAD! */ public void mux() throws IOException { MediaMuxer muxer = null; muxer = new MediaMuxer(mOutFile, mFormat); public void mux() throws IOException, IllegalStateException { MediaMuxer muxer = new MediaMuxer(mOutFile, mFormat); // Add extractors for (String file: mFiles) { MediaExtractor extractor = new MediaExtractor(); Loading @@ -74,7 +73,10 @@ public class ScreenRecordingMuxer { } } // This may throw IllegalStateException if no tracks were added above // Let the error propagate up so we can notify the user. muxer.start(); for (Pair<MediaExtractor, Integer> pair: mExtractorIndexToMuxerIndex.keySet()) { MediaExtractor extractor = pair.first; extractor.selectTrack(pair.second); Loading packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingServiceTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ import com.android.systemui.statusbar.phone.KeyguardDismissUtil; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; Loading Loading @@ -73,6 +75,8 @@ public class RecordingServiceTest extends SysuiTestCase { private Handler mHandler; @Mock private UserContextProvider mUserContextTracker; @Captor private ArgumentCaptor<Runnable> mRunnableCaptor; private KeyguardDismissUtil mKeyguardDismissUtil = new KeyguardDismissUtil() { public void executeWhenUnlocked(ActivityStarter.OnDismissAction action, boolean requiresShadeOpen) { Loading Loading @@ -209,4 +213,19 @@ public class RecordingServiceTest extends SysuiTestCase { verify(mScreenMediaRecorder).release(); } @Test public void testOnErrorSaving() throws IOException { // When the screen recording does not save properly doThrow(new IllegalStateException("fail")).when(mScreenMediaRecorder).save(); Intent startIntent = RecordingService.getStopIntent(mContext); mRecordingService.onStartCommand(startIntent, 0, 0); verify(mExecutor).execute(mRunnableCaptor.capture()); mRunnableCaptor.getValue().run(); // Then the state is set to not recording and we cancel the notification verify(mController).updateState(false); verify(mNotificationManager).cancelAsUser(any(), anyInt(), any()); } } Loading
packages/SystemUI/res/values/strings.xml +2 −3 Original line number Diff line number Diff line Loading @@ -295,9 +295,8 @@ <string name="screenrecord_save_title">Screen recording saved</string> <!-- Subtext for a notification shown after saving a screen recording to prompt the user to view it [CHAR_LIMIT=100] --> <string name="screenrecord_save_text">Tap to view</string> <!-- A toast message shown when there is an error deleting a screen recording [CHAR LIMIT=NONE] --> <string name="screenrecord_delete_error">Error deleting screen recording</string> <!-- A toast message shown when the screen recording cannot be started due to insufficient permissions [CHAR LIMIT=NONE] --> <!-- A toast message shown when there is an error saving a screen recording [CHAR LIMIT=NONE] --> <string name="screenrecord_save_error">Error saving screen recording</string> <!-- A toast message shown when the screen recording cannot be started due to a generic error [CHAR LIMIT=NONE] --> <string name="screenrecord_start_error">Error starting screen recording</string> Loading
packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +2 −2 Original line number Diff line number Diff line Loading @@ -453,9 +453,9 @@ public class RecordingService extends Service implements ScreenMediaRecorderList postGroupNotification(currentUser); mNotificationManager.notifyAsUser(null, mNotificationId, notification, currentUser); } catch (IOException e) { } catch (IOException | IllegalStateException e) { Log.e(TAG, "Error saving screen recording: " + e.getMessage()); showErrorToast(R.string.screenrecord_delete_error); showErrorToast(R.string.screenrecord_save_error); mNotificationManager.cancelAsUser(null, mNotificationId, currentUser); } }); Loading
packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java +3 −2 Original line number Diff line number Diff line Loading @@ -52,8 +52,9 @@ import android.view.Surface; import android.view.WindowManager; import com.android.systemui.media.MediaProjectionCaptureTarget; import java.io.File; import java.io.Closeable; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; Loading Loading @@ -321,7 +322,7 @@ public class ScreenMediaRecorder extends MediaProjection.Callback { /** * Store recorded video */ protected SavedRecording save() throws IOException { protected SavedRecording save() throws IOException, IllegalStateException { String fileName = new SimpleDateFormat("'screen-'yyyyMMdd-HHmmss'.mp4'") .format(new Date()); Loading
packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordingMuxer.java +5 −3 Original line number Diff line number Diff line Loading @@ -52,9 +52,8 @@ public class ScreenRecordingMuxer { /** * RUN IN THE BACKGROUND THREAD! */ public void mux() throws IOException { MediaMuxer muxer = null; muxer = new MediaMuxer(mOutFile, mFormat); public void mux() throws IOException, IllegalStateException { MediaMuxer muxer = new MediaMuxer(mOutFile, mFormat); // Add extractors for (String file: mFiles) { MediaExtractor extractor = new MediaExtractor(); Loading @@ -74,7 +73,10 @@ public class ScreenRecordingMuxer { } } // This may throw IllegalStateException if no tracks were added above // Let the error propagate up so we can notify the user. muxer.start(); for (Pair<MediaExtractor, Integer> pair: mExtractorIndexToMuxerIndex.keySet()) { MediaExtractor extractor = pair.first; extractor.selectTrack(pair.second); Loading
packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingServiceTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ import com.android.systemui.statusbar.phone.KeyguardDismissUtil; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; Loading Loading @@ -73,6 +75,8 @@ public class RecordingServiceTest extends SysuiTestCase { private Handler mHandler; @Mock private UserContextProvider mUserContextTracker; @Captor private ArgumentCaptor<Runnable> mRunnableCaptor; private KeyguardDismissUtil mKeyguardDismissUtil = new KeyguardDismissUtil() { public void executeWhenUnlocked(ActivityStarter.OnDismissAction action, boolean requiresShadeOpen) { Loading Loading @@ -209,4 +213,19 @@ public class RecordingServiceTest extends SysuiTestCase { verify(mScreenMediaRecorder).release(); } @Test public void testOnErrorSaving() throws IOException { // When the screen recording does not save properly doThrow(new IllegalStateException("fail")).when(mScreenMediaRecorder).save(); Intent startIntent = RecordingService.getStopIntent(mContext); mRecordingService.onStartCommand(startIntent, 0, 0); verify(mExecutor).execute(mRunnableCaptor.capture()); mRunnableCaptor.getValue().run(); // Then the state is set to not recording and we cancel the notification verify(mController).updateState(false); verify(mNotificationManager).cancelAsUser(any(), anyInt(), any()); } }