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

Commit ece03333 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

Fix messaging when screen recording stops without recording content.

If there's some sort of error when stopping a screen recording, the
toast and the notification should say "Error saving screen recording"
not "Error starting screen recording".

Bug: 356586297
Bug: 332662551
Flag: EXEMPT bugfix

Test: screen record a single app, but then go to home screen before
countdown finishes, then click on status bar chip and click "Stop" (or
click "Stop" on the notification) -> verify toast says "Error saving
screen recording" and verify notification says "Error saving screen
recording"
Test: atest RecordingServiceTest

Change-Id: I0c19ab9ee121fd7d47352653062fe8ecbe870f5c
parent b64d6c60
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -181,7 +181,7 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
                    mUiEventLogger.log(Events.ScreenRecordEvent.SCREEN_RECORD_START);
                } else {
                    updateState(false);
                    createErrorNotification();
                    createErrorStartingNotification();
                    stopForeground(STOP_FOREGROUND_DETACH);
                    stopSelf();
                    return Service.START_NOT_STICKY;
@@ -272,17 +272,30 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
    }

    /**
     * Simple error notification, needed since startForeground must be called to avoid errors
     * Simple "error starting" notification, needed since startForeground must be called to avoid
     * errors.
     */
    @VisibleForTesting
    protected void createErrorNotification() {
    protected void createErrorStartingNotification() {
        createErrorNotification(strings().getStartError());
    }

    /**
     * Simple "error saving" notification, needed since startForeground must be called to avoid
     * errors.
     */
    @VisibleForTesting
    protected void createErrorSavingNotification() {
        createErrorNotification(strings().getSaveError());
    }

    private void createErrorNotification(String notificationContentTitle) {
        Bundle extras = new Bundle();
        extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, strings().getTitle());
        String notificationTitle = strings().getStartError();

        Notification.Builder builder = new Notification.Builder(this, getChannelId())
                .setSmallIcon(R.drawable.ic_screenrecord)
                .setContentTitle(notificationTitle)
                .setContentTitle(notificationContentTitle)
                .addExtras(extras);
        startForeground(mNotificationId, builder.build());
    }
@@ -427,11 +440,11 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
                // let's release the recorder and delete all temporary files in this case
                getRecorder().release();
            }
            showErrorToast(R.string.screenrecord_start_error);
            showErrorToast(R.string.screenrecord_save_error);
            Log.e(getTag(), "stopRecording called, but there was an error when ending"
                    + "recording");
            exception.printStackTrace();
            createErrorNotification();
            createErrorSavingNotification();
        } catch (Throwable throwable) {
            if (getRecorder() != null) {
                // Something unexpected happen, SystemUI will crash but let's delete
+3 −2
Original line number Diff line number Diff line
@@ -126,7 +126,8 @@ public class RecordingServiceTest extends SysuiTestCase {
        doNothing().when(mRecordingService).createRecordingNotification();
        doReturn(mNotification).when(mRecordingService).createProcessingNotification();
        doReturn(mNotification).when(mRecordingService).createSaveNotification(any());
        doNothing().when(mRecordingService).createErrorNotification();
        doNothing().when(mRecordingService).createErrorStartingNotification();
        doNothing().when(mRecordingService).createErrorSavingNotification();
        doNothing().when(mRecordingService).showErrorToast(anyInt());
        doNothing().when(mRecordingService).stopForeground(anyInt());

@@ -234,7 +235,7 @@ public class RecordingServiceTest extends SysuiTestCase {

        mRecordingService.onStopped();

        verify(mRecordingService).createErrorNotification();
        verify(mRecordingService).createErrorSavingNotification();
    }

    @Test