Merge "(3/N)[MediaProjection] Fix NPE on IMediaProjection" into udc-dev

This commit is contained in:
Naomi Musgrave
2023-04-25 16:51:26 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 2 deletions

View File

@@ -395,8 +395,8 @@ public final class MediaProjectionManagerService extends SystemService
synchronized (mLock) {
final boolean consentGranted =
consentResult == RECORD_CONTENT_DISPLAY || consentResult == RECORD_CONTENT_TASK;
if (consentGranted && projection == null || !isCurrentProjection(
projection.asBinder())) {
if (consentGranted && !isCurrentProjection(
projection == null ? null : projection.asBinder())) {
Slog.v(TAG, "Reusing token: Ignore consent result of " + consentResult + " for a "
+ "token that isn't current");
return;

View File

@@ -445,6 +445,25 @@ public class MediaProjectionManagerServiceTest {
eq(mWaitingDisplaySession));
}
@Test
public void testSetUserReviewGrantedConsentResult_projectionNull_consentNotGranted()
throws Exception {
MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions();
projection.start(mIMediaProjectionCallback);
assertThat(mService.isCurrentProjection(projection)).isTrue();
doReturn(true).when(mWindowManagerInternal).setContentRecordingSession(
any(ContentRecordingSession.class));
// Some other token.
final IMediaProjection otherProjection = null;
// Waiting for user to review consent.
mService.setContentRecordingSession(mWaitingDisplaySession);
mService.setUserReviewGrantedConsentResult(RECORD_CANCEL, otherProjection);
// Display result is ignored; only the first session is set.
verify(mWindowManagerInternal, times(1)).setContentRecordingSession(
eq(mWaitingDisplaySession));
}
@Test
public void testSetUserReviewGrantedConsentResult_noVirtualDisplay() throws Exception {
MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions();