Merge "Catch exception when muxing fails to start" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1e25b178ab
@@ -295,9 +295,8 @@
|
|||||||
<string name="screenrecord_save_title">Screen recording saved</string>
|
<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] -->
|
<!-- 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>
|
<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] -->
|
<!-- A toast message shown when there is an error saving a screen recording [CHAR LIMIT=NONE] -->
|
||||||
<string name="screenrecord_delete_error">Error deleting screen recording</string>
|
<string name="screenrecord_save_error">Error saving 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 the screen recording cannot be started due to a generic error [CHAR LIMIT=NONE] -->
|
<!-- 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>
|
<string name="screenrecord_start_error">Error starting screen recording</string>
|
||||||
|
|
||||||
|
|||||||
@@ -453,9 +453,9 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
|
|||||||
postGroupNotification(currentUser);
|
postGroupNotification(currentUser);
|
||||||
mNotificationManager.notifyAsUser(null, mNotificationId, notification,
|
mNotificationManager.notifyAsUser(null, mNotificationId, notification,
|
||||||
currentUser);
|
currentUser);
|
||||||
} catch (IOException e) {
|
} catch (IOException | IllegalStateException e) {
|
||||||
Log.e(TAG, "Error saving screen recording: " + e.getMessage());
|
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);
|
mNotificationManager.cancelAsUser(null, mNotificationId, currentUser);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,8 +52,9 @@ import android.view.Surface;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.android.systemui.media.MediaProjectionCaptureTarget;
|
import com.android.systemui.media.MediaProjectionCaptureTarget;
|
||||||
import java.io.File;
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -321,7 +322,7 @@ public class ScreenMediaRecorder extends MediaProjection.Callback {
|
|||||||
/**
|
/**
|
||||||
* Store recorded video
|
* Store recorded video
|
||||||
*/
|
*/
|
||||||
protected SavedRecording save() throws IOException {
|
protected SavedRecording save() throws IOException, IllegalStateException {
|
||||||
String fileName = new SimpleDateFormat("'screen-'yyyyMMdd-HHmmss'.mp4'")
|
String fileName = new SimpleDateFormat("'screen-'yyyyMMdd-HHmmss'.mp4'")
|
||||||
.format(new Date());
|
.format(new Date());
|
||||||
|
|
||||||
|
|||||||
@@ -52,9 +52,8 @@ public class ScreenRecordingMuxer {
|
|||||||
/**
|
/**
|
||||||
* RUN IN THE BACKGROUND THREAD!
|
* RUN IN THE BACKGROUND THREAD!
|
||||||
*/
|
*/
|
||||||
public void mux() throws IOException {
|
public void mux() throws IOException, IllegalStateException {
|
||||||
MediaMuxer muxer = null;
|
MediaMuxer muxer = new MediaMuxer(mOutFile, mFormat);
|
||||||
muxer = new MediaMuxer(mOutFile, mFormat);
|
|
||||||
// Add extractors
|
// Add extractors
|
||||||
for (String file: mFiles) {
|
for (String file: mFiles) {
|
||||||
MediaExtractor extractor = new MediaExtractor();
|
MediaExtractor extractor = new MediaExtractor();
|
||||||
@@ -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();
|
muxer.start();
|
||||||
|
|
||||||
for (Pair<MediaExtractor, Integer> pair: mExtractorIndexToMuxerIndex.keySet()) {
|
for (Pair<MediaExtractor, Integer> pair: mExtractorIndexToMuxerIndex.keySet()) {
|
||||||
MediaExtractor extractor = pair.first;
|
MediaExtractor extractor = pair.first;
|
||||||
extractor.selectTrack(pair.second);
|
extractor.selectTrack(pair.second);
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
@@ -73,6 +75,8 @@ public class RecordingServiceTest extends SysuiTestCase {
|
|||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
@Mock
|
@Mock
|
||||||
private UserContextProvider mUserContextTracker;
|
private UserContextProvider mUserContextTracker;
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<Runnable> mRunnableCaptor;
|
||||||
private KeyguardDismissUtil mKeyguardDismissUtil = new KeyguardDismissUtil() {
|
private KeyguardDismissUtil mKeyguardDismissUtil = new KeyguardDismissUtil() {
|
||||||
public void executeWhenUnlocked(ActivityStarter.OnDismissAction action,
|
public void executeWhenUnlocked(ActivityStarter.OnDismissAction action,
|
||||||
boolean requiresShadeOpen) {
|
boolean requiresShadeOpen) {
|
||||||
@@ -209,4 +213,19 @@ public class RecordingServiceTest extends SysuiTestCase {
|
|||||||
|
|
||||||
verify(mScreenMediaRecorder).release();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user