1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.projection; 18 19 import android.media.projection.IMediaProjection; 20 import android.media.projection.IMediaProjectionCallback; 21 import android.media.projection.IMediaProjectionWatcherCallback; 22 import android.media.projection.MediaProjectionInfo; 23 import android.media.projection.ReviewGrantedConsentResult; 24 import android.os.IBinder; 25 import android.view.ContentRecordingSession; 26 27 /** {@hide} */ 28 interface IMediaProjectionManager { 29 /** 30 * Intent extra indicating if user must review access to the consent token already granted. 31 */ 32 const String EXTRA_USER_REVIEW_GRANTED_CONSENT = "extra_media_projection_user_consent_required"; 33 34 /** 35 * Intent extra indicating the package attempting to re-use granted consent. 36 */ 37 const String EXTRA_PACKAGE_REUSING_GRANTED_CONSENT = 38 "extra_media_projection_package_reusing_consent"; 39 40 @UnsupportedAppUsage hasProjectionPermission(int uid, String packageName)41 boolean hasProjectionPermission(int uid, String packageName); 42 43 /** 44 * Returns a new {@link IMediaProjection} instance associated with the given package. 45 */ 46 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 47 + ".permission.MANAGE_MEDIA_PROJECTION)") createProjection(int uid, String packageName, int type, boolean permanentGrant)48 IMediaProjection createProjection(int uid, String packageName, int type, 49 boolean permanentGrant); 50 51 /** 52 * Returns the current {@link IMediaProjection} instance associated with the given 53 * package, or {@code null} if it is not possible to re-use the current projection. 54 * 55 * <p>Should only be invoked when the user has reviewed consent for a re-used projection token. 56 * Requires that there is a prior session waiting for the user to review consent, and the given 57 * package details match those on the current projection. 58 * 59 * @see {@link #isCurrentProjection} 60 */ 61 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 62 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 63 + ".permission.MANAGE_MEDIA_PROJECTION)") getProjection(int uid, String packageName)64 IMediaProjection getProjection(int uid, String packageName); 65 66 /** 67 * Returns {@code true} if the given {@link IMediaProjection} corresponds to the current 68 * projection, or {@code false} otherwise. 69 */ 70 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 71 + ".permission.MANAGE_MEDIA_PROJECTION)") isCurrentProjection(IMediaProjection projection)72 boolean isCurrentProjection(IMediaProjection projection); 73 74 /** 75 * Reshows the permisison dialog for the user to review consent they've already granted in 76 * the given projection instance. 77 * 78 * <p>Preconditions: 79 * <ul> 80 * <li>{@link IMediaProjection#isValid} returned false, rather than throwing an exception</li> 81 * <li>Given projection instance is the current projection instance.</li> 82 * <ul> 83 * 84 * <p>Returns immediately but waits to start recording until user has reviewed their consent. 85 */ 86 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 87 + ".permission.MANAGE_MEDIA_PROJECTION)") requestConsentForInvalidProjection(in IMediaProjection projection)88 void requestConsentForInvalidProjection(in IMediaProjection projection); 89 90 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 91 + ".permission.MANAGE_MEDIA_PROJECTION)") getActiveProjectionInfo()92 MediaProjectionInfo getActiveProjectionInfo(); 93 94 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 95 + ".permission.MANAGE_MEDIA_PROJECTION)") stopActiveProjection()96 void stopActiveProjection(); 97 98 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 99 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyActiveProjectionCapturedContentResized(int width, int height)100 void notifyActiveProjectionCapturedContentResized(int width, int height); 101 102 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 103 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyActiveProjectionCapturedContentVisibilityChanged(boolean isVisible)104 void notifyActiveProjectionCapturedContentVisibilityChanged(boolean isVisible); 105 106 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 107 + ".permission.MANAGE_MEDIA_PROJECTION)") addCallback(IMediaProjectionWatcherCallback callback)108 void addCallback(IMediaProjectionWatcherCallback callback); 109 110 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 111 + ".permission.MANAGE_MEDIA_PROJECTION)") removeCallback(IMediaProjectionWatcherCallback callback)112 void removeCallback(IMediaProjectionWatcherCallback callback); 113 114 /** 115 * Returns {@code true} if it successfully updates the content recording session. Returns 116 * {@code false} otherwise, and stops the current projection. 117 * 118 * <p>If a different session is already in progress, then the pre-existing session is stopped, 119 * and the new incoming session takes over. Only updates the session if the given projection is 120 * valid. 121 * 122 * @param incomingSession the nullable incoming content recording session 123 * @param projection the non-null projection the session describes 124 * @throws SecurityException If the provided projection is not current. 125 */ 126 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 127 + ".permission.MANAGE_MEDIA_PROJECTION)") setContentRecordingSession(in ContentRecordingSession incomingSession, in IMediaProjection projection)128 boolean setContentRecordingSession(in ContentRecordingSession incomingSession, 129 in IMediaProjection projection); 130 131 /** 132 * Sets the result of the user reviewing the recording permission, when the host app is re-using 133 * the consent token. 134 * 135 * <p>Ignores the provided result if the given projection is not the current projection. 136 * 137 * <p>Based on the given result: 138 * <ul> 139 * <li>If UNKNOWN or RECORD_CANCEL, then tear down the recording.</li> 140 * <li>If RECORD_CONTENT_DISPLAY, then record the default display.</li> 141 * <li>If RECORD_CONTENT_TASK, record the task indicated by 142 * {@link IMediaProjection#getLaunchCookie}.</li> 143 * </ul> 144 * @param projection The projection associated with the consent result. Must be the current 145 * projection instance, unless the given result is RECORD_CANCEL. 146 */ 147 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 148 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 149 + ".permission.MANAGE_MEDIA_PROJECTION)") setUserReviewGrantedConsentResult(ReviewGrantedConsentResult consentResult, in @nullable IMediaProjection projection)150 void setUserReviewGrantedConsentResult(ReviewGrantedConsentResult consentResult, 151 in @nullable IMediaProjection projection); 152 } 153