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.graphics.Rect; 20 import android.media.projection.IMediaProjection; 21 import android.media.projection.IMediaProjectionCallback; 22 import android.media.projection.IMediaProjectionWatcherCallback; 23 import android.media.projection.MediaProjectionInfo; 24 import android.media.projection.ReviewGrantedConsentResult; 25 import android.media.projection.StopReason; 26 import android.os.IBinder; 27 import android.view.ContentRecordingSession; 28 29 /** {@hide} */ 30 interface IMediaProjectionManager { 31 /** 32 * Intent extra indicating if user must review access to the consent token already granted. 33 */ 34 const String EXTRA_USER_REVIEW_GRANTED_CONSENT = "extra_media_projection_user_consent_required"; 35 36 /** 37 * Intent extra indicating the package attempting to re-use granted consent. 38 */ 39 const String EXTRA_PACKAGE_REUSING_GRANTED_CONSENT = 40 "extra_media_projection_package_reusing_consent"; 41 42 /** 43 * Returns whether a combination of process UID and package has the projection permission. 44 * 45 * @param processUid the process UID as returned by {@link android.os.Process.myUid()}. 46 */ 47 @UnsupportedAppUsage hasProjectionPermission(int processUid, String packageName)48 boolean hasProjectionPermission(int processUid, String packageName); 49 50 /** 51 * Returns a new {@link IMediaProjection} instance associated with the given package for the 52 * given display id. 53 * 54 * @param processUid the process UID as returned by {@link android.os.Process.myUid()}. 55 */ 56 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 57 + ".permission.MANAGE_MEDIA_PROJECTION)") createProjection(int processUid, String packageName, int type, boolean permanentGrant, int displayId)58 IMediaProjection createProjection(int processUid, String packageName, int type, 59 boolean permanentGrant, int displayId); 60 61 /** 62 * Returns the current {@link IMediaProjection} instance associated with the given 63 * package and process UID, or {@code null} if it is not possible to re-use the current 64 * projection. 65 * 66 * <p>Should only be invoked when the user has reviewed consent for a re-used projection token. 67 * Requires that there is a prior session waiting for the user to review consent, and the given 68 * package details match those on the current projection. 69 * 70 * @see {@link #isCurrentProjection} 71 * 72 * @param processUid the process UID as returned by {@link android.os.Process.myUid()}. 73 */ 74 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 75 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 76 + ".permission.MANAGE_MEDIA_PROJECTION)") getProjection(int processUid, String packageName)77 IMediaProjection getProjection(int processUid, String packageName); 78 79 /** 80 * Returns {@code true} if the given {@link IMediaProjection} corresponds to the current 81 * projection, or {@code false} otherwise. 82 */ 83 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 84 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 85 + ".permission.MANAGE_MEDIA_PROJECTION)") isCurrentProjection(IMediaProjection projection)86 boolean isCurrentProjection(IMediaProjection projection); 87 88 /** 89 * Reshows the permisison dialog for the user to review consent they've already granted in 90 * the given projection instance. 91 * 92 * <p>Preconditions: 93 * <ul> 94 * <li>{@link IMediaProjection#isValid} returned false, rather than throwing an exception</li> 95 * <li>Given projection instance is the current projection instance.</li> 96 * <ul> 97 * 98 * <p>Returns immediately but waits to start recording until user has reviewed their consent. 99 */ 100 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 101 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 102 + ".permission.MANAGE_MEDIA_PROJECTION)") requestConsentForInvalidProjection(in IMediaProjection projection)103 void requestConsentForInvalidProjection(in IMediaProjection projection); 104 105 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 106 + ".permission.MANAGE_MEDIA_PROJECTION)") getActiveProjectionInfo()107 MediaProjectionInfo getActiveProjectionInfo(); 108 109 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 110 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 111 + ".permission.MANAGE_MEDIA_PROJECTION)") stopActiveProjection(in StopReason stopReason)112 void stopActiveProjection(in StopReason stopReason); 113 114 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 115 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 116 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyActiveProjectionCapturedContentVisibilityChanged(boolean isVisible)117 void notifyActiveProjectionCapturedContentVisibilityChanged(boolean isVisible); 118 119 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 120 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 121 + ".permission.MANAGE_MEDIA_PROJECTION)") addCallback(IMediaProjectionWatcherCallback callback)122 MediaProjectionInfo addCallback(IMediaProjectionWatcherCallback callback); 123 124 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 125 + ".permission.MANAGE_MEDIA_PROJECTION)") removeCallback(IMediaProjectionWatcherCallback callback)126 void removeCallback(IMediaProjectionWatcherCallback callback); 127 128 /** 129 * Returns {@code true} if it successfully updates the content recording session. Returns 130 * {@code false} otherwise, and stops the current projection. 131 * 132 * <p>If a different session is already in progress, then the pre-existing session is stopped, 133 * and the new incoming session takes over. Only updates the session if the given projection is 134 * valid. 135 * 136 * @param incomingSession the nullable incoming content recording session 137 * @param projection the non-null projection the session describes 138 * @throws SecurityException If the provided projection is not current. 139 */ 140 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 141 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 142 + ".permission.MANAGE_MEDIA_PROJECTION)") setContentRecordingSession(in ContentRecordingSession incomingSession, in IMediaProjection projection)143 boolean setContentRecordingSession(in ContentRecordingSession incomingSession, 144 in IMediaProjection projection); 145 146 /** 147 * Sets the result of the user reviewing the recording permission, when the host app is re-using 148 * the consent token. 149 * 150 * <p>Ignores the provided result if the given projection is not the current projection. 151 * 152 * <p>Based on the given result: 153 * <ul> 154 * <li>If UNKNOWN or RECORD_CANCEL, then tear down the recording.</li> 155 * <li>If RECORD_CONTENT_DISPLAY, then record the default display.</li> 156 * <li>If RECORD_CONTENT_TASK, record the task indicated by 157 * {@link IMediaProjection#getLaunchCookie}.</li> 158 * </ul> 159 * @param projection The projection associated with the consent result. Must be the current 160 * projection instance, unless the given result is RECORD_CANCEL. 161 */ 162 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 163 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 164 + ".permission.MANAGE_MEDIA_PROJECTION)") setUserReviewGrantedConsentResult(ReviewGrantedConsentResult consentResult, in @nullable IMediaProjection projection)165 void setUserReviewGrantedConsentResult(ReviewGrantedConsentResult consentResult, 166 in @nullable IMediaProjection projection); 167 168 /** 169 * Notifies system server that the permission request was initiated. 170 * 171 * <p>Only used for emitting atoms. 172 * 173 * @param hostProcessUid The uid of the process requesting consent to capture, may be an 174 * app or SystemUI. 175 * @param sessionCreationSource Only set if the state is MEDIA_PROJECTION_STATE_INITIATED. 176 * Indicates the entry point for requesting the permission. Must be 177 * a valid state defined 178 * in the SessionCreationSource enum. 179 */ 180 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 181 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 182 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyPermissionRequestInitiated(int hostProcessUid, int sessionCreationSource)183 oneway void notifyPermissionRequestInitiated(int hostProcessUid, int sessionCreationSource); 184 185 /** 186 * Notifies system server that the permission request was displayed. 187 * 188 * <p>Only used for emitting atoms. 189 * 190 * @param hostProcessUid The uid of the process requesting consent to capture, may be an app or 191 * SystemUI. 192 */ 193 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 194 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 195 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyPermissionRequestDisplayed(int hostProcessUid)196 oneway void notifyPermissionRequestDisplayed(int hostProcessUid); 197 198 /** 199 * Notifies system server that the permission request was cancelled. 200 * 201 * <p>Only used for emitting atoms. 202 * 203 * @param hostProcessUid The uid of the process requesting consent to capture, may be an app or 204 * SystemUI. 205 */ 206 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 207 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 208 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyPermissionRequestCancelled(int hostProcessUid)209 oneway void notifyPermissionRequestCancelled(int hostProcessUid); 210 211 /** 212 * Notifies system server that the app selector was displayed. 213 * 214 * <p>Only used for emitting atoms. 215 * 216 * @param hostProcessUid The uid of the process requesting consent to capture, may be an app or 217 * SystemUI. 218 */ 219 @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION") 220 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 221 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyAppSelectorDisplayed(int hostProcessUid)222 oneway void notifyAppSelectorDisplayed(int hostProcessUid); 223 224 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 225 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 226 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyWindowingModeChanged(int contentToRecord, int targetProcessUid, int windowingMode)227 oneway void notifyWindowingModeChanged(int contentToRecord, int targetProcessUid, int windowingMode); 228 229 @EnforcePermission("MANAGE_MEDIA_PROJECTION") 230 @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" 231 + ".permission.MANAGE_MEDIA_PROJECTION)") notifyCaptureBoundsChanged(int contentToRecord, int targetProcessUid, in Rect captureBounds)232 oneway void notifyCaptureBoundsChanged(int contentToRecord, int targetProcessUid, 233 in Rect captureBounds); 234 } 235