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

Commit 0f44b427 authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Android (Google) Code Review
Browse files

Merge "Show stop error notification in the correct user" into main

parents 6b1695bd 8862119d
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ public class RecordingServiceTest extends SysuiTestCase {
    public void testOnSystemRequestedStop_recordingInProgress_endsRecording() throws IOException {
        doReturn(true).when(mController).isRecording();

        mRecordingService.onStopped(StopReason.STOP_UNKNOWN);
        mRecordingService.onStopped(mContext.getUserId(), StopReason.STOP_UNKNOWN);

        verify(mScreenMediaRecorder).end(eq(StopReason.STOP_UNKNOWN));
    }
@@ -209,7 +209,7 @@ public class RecordingServiceTest extends SysuiTestCase {
    public void testOnSystemRequestedStop_recordingInProgress_updatesState() {
        doReturn(true).when(mController).isRecording();

        mRecordingService.onStopped(StopReason.STOP_UNKNOWN);
        mRecordingService.onStopped(mContext.getUserId(), StopReason.STOP_UNKNOWN);

        assertUpdateState(false);
    }
@@ -219,7 +219,7 @@ public class RecordingServiceTest extends SysuiTestCase {
            throws IOException {
        doReturn(false).when(mController).isRecording();

        mRecordingService.onStopped(StopReason.STOP_UNKNOWN);
        mRecordingService.onStopped(mContext.getUserId(), StopReason.STOP_UNKNOWN);

        verify(mScreenMediaRecorder, never()).end(StopReason.STOP_UNKNOWN);
    }
@@ -230,7 +230,7 @@ public class RecordingServiceTest extends SysuiTestCase {
        doReturn(true).when(mController).isRecording();
        doThrow(new RuntimeException()).when(mScreenMediaRecorder).end(StopReason.STOP_UNKNOWN);

        mRecordingService.onStopped(StopReason.STOP_UNKNOWN);
        mRecordingService.onStopped(mContext.getUserId(), StopReason.STOP_UNKNOWN);

        verify(mScreenMediaRecorder).release();
    }
@@ -239,7 +239,7 @@ public class RecordingServiceTest extends SysuiTestCase {
    public void testOnSystemRequestedStop_whenRecordingInProgress_showsNotifications() {
        doReturn(true).when(mController).isRecording();

        mRecordingService.onStopped(StopReason.STOP_UNKNOWN);
        mRecordingService.onStopped(mContext.getUserId(), StopReason.STOP_UNKNOWN);

        // Processing notification
        ArgumentCaptor<Notification> notifCaptor = ArgumentCaptor.forClass(Notification.class);
@@ -274,7 +274,7 @@ public class RecordingServiceTest extends SysuiTestCase {
        doReturn(true).when(mController).isRecording();
        doThrow(new RuntimeException()).when(mScreenMediaRecorder).end(anyInt());

        mRecordingService.onStopped(StopReason.STOP_UNKNOWN);
        mRecordingService.onStopped(mContext.getUserId(), StopReason.STOP_UNKNOWN);

        verify(mRecordingService).createErrorSavingNotification(any());
        ArgumentCaptor<Notification> notifCaptor = ArgumentCaptor.forClass(Notification.class);
@@ -292,7 +292,8 @@ public class RecordingServiceTest extends SysuiTestCase {
        doReturn(true).when(mController).isRecording();
        doThrow(new OutOfMemoryError()).when(mScreenMediaRecorder).end(anyInt());

        assertThrows(Throwable.class, () -> mRecordingService.onStopped(StopReason.STOP_UNKNOWN));
        assertThrows(Throwable.class, () -> mRecordingService.onStopped(
                mContext.getUserId(), StopReason.STOP_UNKNOWN));

        verify(mScreenMediaRecorder).release();
    }
+6 −9
Original line number Diff line number Diff line
@@ -489,13 +489,10 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
                getTag(), notificationIdForGroup, groupNotif, currentUser);
    }

    private void stopService(@StopReason int stopReason) {
        stopService(USER_ID_NOT_SPECIFIED, stopReason);
    }

    private void stopService(int userId, @StopReason int stopReason) {
        if (userId == USER_ID_NOT_SPECIFIED) {
            userId = mUserContextTracker.getUserContext().getUserId();
            Log.w(getTag(), "Stopping service without specifying user! " + userId);
        }
        UserHandle currentUser = new UserHandle(userId);
        Log.d(getTag(), "notifying for user " + userId);
@@ -583,7 +580,6 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
        return new RecordingServiceStrings(getResources());
    }


    /**
     * Get an intent to stop the recording service.
     * @param context Context from the requesting activity
@@ -621,10 +617,11 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
    }

    @Override
    public void onStopped(@StopReason int stopReason) {
    public void onStopped(int userId, @StopReason int stopReason) {
        if (mController.isRecording()) {
            Log.d(getTag(), "Stopping recording because the system requested the stop");
            stopService(stopReason);
            Log.d(getTag(), "Stopping recording for user " + userId
                    + " because the system requested the stop");
            stopService(userId, stopReason);
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -334,7 +334,7 @@ public class ScreenMediaRecorder extends MediaProjection.Callback {
    @Override
    public void onStop() {
        Log.d(TAG, "The system notified about stopping the projection");
        mListener.onStopped(StopReason.STOP_UNKNOWN);
        mListener.onStopped(mContext.getUserId(), StopReason.STOP_UNKNOWN);
    }

    private void stopInternalAudioRecording() {
@@ -464,7 +464,7 @@ public class ScreenMediaRecorder extends MediaProjection.Callback {
         * For example, this might happen when doing partial screen sharing of an app
         * and the app that is being captured is closed.
         */
        void onStopped(@StopReason int stopReason);
        void onStopped(int userId, @StopReason int stopReason);
    }

    /**