Merge "[Media Projection] Require valid token to set session" into tm-dev am: 55ecb4ec82 am: 986c517b77 am: fa30ad6853 am: cb0d7f43a0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18356863

Change-Id: I518249d759ec459d13d8246bd15a1f71bd4bd43c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Naomi Musgrave
2022-05-20 16:32:18 +00:00
committed by Automerger Merge Worker
8 changed files with 71 additions and 30 deletions

View File

@@ -21,6 +21,7 @@ import android.media.projection.IMediaProjectionCallback;
import android.media.projection.IMediaProjectionWatcherCallback;
import android.media.projection.MediaProjectionInfo;
import android.os.IBinder;
import android.view.ContentRecordingSession;
/** {@hide} */
interface IMediaProjectionManager {
@@ -33,4 +34,15 @@ interface IMediaProjectionManager {
void stopActiveProjection();
void addCallback(IMediaProjectionWatcherCallback callback);
void removeCallback(IMediaProjectionWatcherCallback callback);
/**
* Updates the content recording session. If a different session is already in progress, then
* the pre-existing session is stopped, and the new incoming session takes over. Only updates
* the session if the given projection is valid.
*
* @param incomingSession the nullable incoming content recording session
* @param projection the non-null projection the session describes
*/
void setContentRecordingSession(in ContentRecordingSession incomingSession,
in IMediaProjection projection);
}

View File

@@ -26,12 +26,11 @@ import android.hardware.display.VirtualDisplay;
import android.hardware.display.VirtualDisplayConfig;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.ArrayMap;
import android.util.Log;
import android.view.ContentRecordingSession;
import android.view.IWindowManager;
import android.view.Surface;
import android.view.WindowManagerGlobal;
import android.window.WindowContainerToken;
import java.util.Map;
@@ -53,6 +52,7 @@ public final class MediaProjection {
private final IMediaProjection mImpl;
private final Context mContext;
private final Map<Callback, CallbackRecord> mCallbacks;
@Nullable private IMediaProjectionManager mProjectionService = null;
/** @hide */
public MediaProjection(Context context, IMediaProjection impl) {
@@ -172,7 +172,6 @@ public final class MediaProjection {
@NonNull VirtualDisplayConfig.Builder virtualDisplayConfig,
@Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) {
try {
final IWindowManager wmService = WindowManagerGlobal.getWindowManagerService();
final WindowContainerToken taskWindowContainerToken =
mImpl.getTaskRecordingWindowContainerToken();
Context windowContext = null;
@@ -199,7 +198,7 @@ public final class MediaProjection {
}
session.setDisplayId(virtualDisplay.getDisplay().getDisplayId());
// Successfully set up, so save the current session details.
wmService.setContentRecordingSession(session);
getProjectionService().setContentRecordingSession(session, mImpl);
return virtualDisplay;
} catch (RemoteException e) {
// Can not capture if WMS is not accessible, so bail out.
@@ -207,6 +206,14 @@ public final class MediaProjection {
}
}
private IMediaProjectionManager getProjectionService() {
if (mProjectionService == null) {
mProjectionService = IMediaProjectionManager.Stub.asInterface(
ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE));
}
return mProjectionService;
}
/**
* Stops projection.
*/