Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26fefde7 authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Set recording duration and file size limits

The recording will end and save automatically if the time exceeds one
hour or 5gb file size

Fixes: 149916370
Test: manual, verified recording ends and saves when limit is reached
Change-Id: Ifeba5a0834644b1ebdb3fb05961a38ca1c095ee8
parent 49cd3e5f
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ import javax.inject.Inject;
/**
 * A service which records the device screen and optionally microphone input.
 */
public class RecordingService extends Service {
public class RecordingService extends Service implements MediaRecorder.OnInfoListener {
    public static final int REQUEST_CODE = 2;

    private static final int NOTIFICATION_ID = 1;
@@ -85,6 +85,8 @@ public class RecordingService extends Service {
    private static final int VIDEO_FRAME_RATE = 30;
    private static final int AUDIO_BIT_RATE = 16;
    private static final int AUDIO_SAMPLE_RATE = 44100;
    private static final int MAX_DURATION_MS = 60 * 60 * 1000;
    private static final long MAX_FILESIZE_BYTES = 5000000000L;

    private final RecordingController mController;
    private MediaProjection mMediaProjection;
@@ -250,6 +252,8 @@ public class RecordingService extends Service {
            mMediaRecorder.setVideoSize(screenWidth, screenHeight);
            mMediaRecorder.setVideoFrameRate(VIDEO_FRAME_RATE);
            mMediaRecorder.setVideoEncodingBitRate(VIDEO_BIT_RATE);
            mMediaRecorder.setMaxDuration(MAX_DURATION_MS);
            mMediaRecorder.setMaxFileSize(MAX_FILESIZE_BYTES);

            // Set up audio
            if (mUseAudio) {
@@ -274,6 +278,7 @@ public class RecordingService extends Service {
                    null,
                    null);

            mMediaRecorder.setOnInfoListener(this);
            mMediaRecorder.start();
            mController.updateState(true);
        } catch (IOException e) {
@@ -454,4 +459,10 @@ public class RecordingService extends Service {
        return new Intent(context, RecordingService.class).setAction(ACTION_DELETE)
                .putExtra(EXTRA_PATH, path);
    }

    @Override
    public void onInfo(MediaRecorder mr, int what, int extra) {
        Log.d(TAG, "Media recorder info: " + what);
        onStartCommand(getStopIntent(this), 0, 0);
    }
}