Stop throwing exception when re-starting MediaProjection
MediaProjectionManager#getMediaProjection eventually calls start on a MediaProjection. Attempting to start an already started MediaProjection throws an exception. This makes it tricky to call a 'getter' multiple times with the same intent. Clients can try to cache the already gotten MediaProjection object but that is difficult to implement correctly especially as an already gotten MediaProjection could be stopped without notice to the client. Bug: 111131054 Test: gmscore running on an Android Q device without the capture_video permissions is able to use the MediaProjection APIs successfully. Change-Id: I8b1a5bfb5644f47924a39993a87b0ded5d554001
This commit is contained in:
@@ -90,6 +90,8 @@ public final class MediaProjectionManager {
|
||||
* int, android.content.Intent)}
|
||||
* @param resultData The resulting data from {@link android.app.Activity#onActivityResult(int,
|
||||
* int, android.content.Intent)}
|
||||
* @throws IllegalStateException on pre-Q devices if a previously gotten MediaProjection
|
||||
* from the same {@code resultData} has not yet been stopped
|
||||
*/
|
||||
public MediaProjection getMediaProjection(int resultCode, @NonNull Intent resultData) {
|
||||
if (resultCode != Activity.RESULT_OK || resultData == null) {
|
||||
|
||||
@@ -396,8 +396,9 @@ public final class MediaProjectionManagerService extends SystemService
|
||||
}
|
||||
synchronized (mLock) {
|
||||
if (isValidMediaProjection(asBinder())) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot start already started MediaProjection");
|
||||
Slog.w(TAG, "UID " + Binder.getCallingUid()
|
||||
+ " attempted to start already started MediaProjection");
|
||||
return;
|
||||
}
|
||||
mCallback = callback;
|
||||
registerCallback(mCallback);
|
||||
|
||||
Reference in New Issue
Block a user