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