Debian Codegraph @

core/java/android/app/ActivityClient.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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.app;
18
19 import android.annotation.Nullable;
20 import android.annotation.RequiresPermission;
21 import android.content.ComponentName;
22 import android.content.Intent;
23 import android.content.res.Configuration;
24 import android.content.res.Resources;
25 import android.os.Bundle;
26 import android.os.IBinder;
27 import android.os.PersistableBundle;
28 import android.os.RemoteException;
29 import android.util.Singleton;
30 import android.view.RemoteAnimationDefinition;
31 import android.window.SizeConfigurationBuckets;
32
33 import com.android.internal.policy.IKeyguardDismissCallback;
34
35 /**
36 * Provides the activity associated operations that communicate with system.
37 *
38 * @hide
39 */
40 public class ActivityClient {
41 private ActivityClient() {}
42
43 /** Reports the main thread is idle after the activity is resumed. */
44 public void activityIdle(IBinder token, Configuration config, boolean stopProfiling) {
45 try {
46 getActivityClientController().activityIdle(token, config, stopProfiling);
47 } catch (RemoteException e) {
48 e.rethrowFromSystemServer();
49 }
50 }
51
52 /** Reports {@link Activity#onResume()} is done. */
53 public void activityResumed(IBinder token, boolean handleSplashScreenExit) {
54 try {
55 getActivityClientController().activityResumed(token, handleSplashScreenExit);
56 } catch (RemoteException e) {
57 e.rethrowFromSystemServer();
58 }
59 }
60
61 /** Reports {@link android.app.servertransaction.RefreshCallbackItem} is executed. */
62 public void activityRefreshed(IBinder token) {
63 try {
64 getActivityClientController().activityRefreshed(token);
65 } catch (RemoteException e) {
66 e.rethrowFromSystemServer();
67 }
68 }
69
70 /**
71 * Reports after {@link Activity#onTopResumedActivityChanged(boolean)} is called for losing the
72 * top most position.
73 */
74 public void activityTopResumedStateLost() {
75 try {
76 getActivityClientController().activityTopResumedStateLost();
77 } catch (RemoteException e) {
78 e.rethrowFromSystemServer();
79 }
80 }
81
82 /** Reports {@link Activity#onPause()} is done. */
83 public void activityPaused(IBinder token) {
84 try {
85 getActivityClientController().activityPaused(token);
86 } catch (RemoteException e) {
87 e.rethrowFromSystemServer();
88 }
89 }
90
91 /** Reports {@link Activity#onStop()} is done. */
92 public void activityStopped(IBinder token, Bundle state, PersistableBundle persistentState,
93 CharSequence description) {
94 try {
95 getActivityClientController().activityStopped(token, state, persistentState,
96 description);
97 } catch (RemoteException e) {
98 e.rethrowFromSystemServer();
99 }
100 }
101
102 /** Reports {@link Activity#onDestroy()} is done. */
103 public void activityDestroyed(IBinder token) {
104 try {
105 getActivityClientController().activityDestroyed(token);
106 } catch (RemoteException e) {
107 e.rethrowFromSystemServer();
108 }
109 }
110
111 /** Reports the activity starts local relaunch. */
112 public void activityLocalRelaunch(IBinder token) {
113 try {
114 getActivityClientController().activityLocalRelaunch(token);
115 } catch (RemoteException e) {
116 e.rethrowFromSystemServer();
117 }
118 }
119
120 /** Reports the activity has completed relaunched. */
121 public void activityRelaunched(IBinder token) {
122 try {
123 getActivityClientController().activityRelaunched(token);
124 } catch (RemoteException e) {
125 e.rethrowFromSystemServer();
126 }
127 }
128
129 void reportSizeConfigurations(IBinder token, SizeConfigurationBuckets sizeConfigurations) {
130 try {
131 getActivityClientController().reportSizeConfigurations(token, sizeConfigurations);
132 } catch (RemoteException e) {
133 e.rethrowFromSystemServer();
134 }
135 }
136
137 public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) {
138 try {
139 return getActivityClientController().moveActivityTaskToBack(token, nonRoot);
140 } catch (RemoteException e) {
141 throw e.rethrowFromSystemServer();
142 }
143 }
144
145 boolean shouldUpRecreateTask(IBinder token, String destAffinity) {
146 try {
147 return getActivityClientController().shouldUpRecreateTask(token, destAffinity);
148 } catch (RemoteException e) {
149 throw e.rethrowFromSystemServer();
150 }
151 }
152
153 boolean navigateUpTo(IBinder token, Intent destIntent, String resolvedType, int resultCode,
154 Intent resultData) {
155 try {
156 return getActivityClientController().navigateUpTo(token, destIntent, resolvedType,
157 resultCode, resultData);
158 } catch (RemoteException e) {
159 throw e.rethrowFromSystemServer();
160 }
161 }
162
163 boolean releaseActivityInstance(IBinder token) {
164 try {
165 return getActivityClientController().releaseActivityInstance(token);
166 } catch (RemoteException e) {
167 throw e.rethrowFromSystemServer();
168 }
169 }
170
171 public boolean finishActivity(IBinder token, int resultCode, Intent resultData,
172 int finishTask) {
173 try {
174 return getActivityClientController().finishActivity(token, resultCode, resultData,
175 finishTask);
176 } catch (RemoteException e) {
177 throw e.rethrowFromSystemServer();
178 }
179 }
180
181 boolean finishActivityAffinity(IBinder token) {
182 try {
183 return getActivityClientController().finishActivityAffinity(token);
184 } catch (RemoteException e) {
185 throw e.rethrowFromSystemServer();
186 }
187 }
188
189 void finishSubActivity(IBinder token, String resultWho, int requestCode) {
190 try {
191 getActivityClientController().finishSubActivity(token, resultWho, requestCode);
192 } catch (RemoteException e) {
193 e.rethrowFromSystemServer();
194 }
195 }
196
197 @RequiresPermission(android.Manifest.permission.MANAGE_MEDIA_PROJECTION)
198 void setForceSendResultForMediaProjection(IBinder token) {
199 try {
200 getActivityClientController().setForceSendResultForMediaProjection(token);
201 } catch (RemoteException e) {
202 throw e.rethrowFromSystemServer();
203 }
204 }
205
206 public boolean isTopOfTask(IBinder token) {
207 try {
208 return getActivityClientController().isTopOfTask(token);
209 } catch (RemoteException e) {
210 throw e.rethrowFromSystemServer();
211 }
212 }
213
214 boolean willActivityBeVisible(IBinder token) {
215 try {
216 return getActivityClientController().willActivityBeVisible(token);
217 } catch (RemoteException e) {
218 throw e.rethrowFromSystemServer();
219 }
220 }
221
222 public int getDisplayId(IBinder token) {
223 try {
224 return getActivityClientController().getDisplayId(token);
225 } catch (RemoteException e) {
226 throw e.rethrowFromSystemServer();
227 }
228 }
229
230 public int getTaskForActivity(IBinder token, boolean onlyRoot) {
231 try {
232 return getActivityClientController().getTaskForActivity(token, onlyRoot);
233 } catch (RemoteException e) {
234 throw e.rethrowFromSystemServer();
235 }
236 }
237
238 /**
239 * Returns the {@link Configuration} of the task which hosts the Activity, or {@code null} if
240 * the task {@link Configuration} cannot be obtained.
241 */
242 @Nullable
243 public Configuration getTaskConfiguration(IBinder activityToken) {
244 try {
245 return getActivityClientController().getTaskConfiguration(activityToken);
246 } catch (RemoteException e) {
247 throw e.rethrowFromSystemServer();
248 }
249 }
250
251 /**
252 * Returns the non-finishing activity token below in the same task if it belongs to the same
253 * process.
254 */
255 @Nullable
256 public IBinder getActivityTokenBelow(IBinder activityToken) {
257 try {
258 return getActivityClientController().getActivityTokenBelow(activityToken);
259 } catch (RemoteException e) {
260 throw e.rethrowFromSystemServer();
261 }
262 }
263
264 ComponentName getCallingActivity(IBinder token) {
265 try {
266 return getActivityClientController().getCallingActivity(token);
267 } catch (RemoteException e) {
268 throw e.rethrowFromSystemServer();
269 }
270 }
271
272 String getCallingPackage(IBinder token) {
273 try {
274 return getActivityClientController().getCallingPackage(token);
275 } catch (RemoteException e) {
276 throw e.rethrowFromSystemServer();
277 }
278 }
279
280 public int getLaunchedFromUid(IBinder token) {
281 try {
282 return getActivityClientController().getLaunchedFromUid(token);
283 } catch (RemoteException e) {
284 throw e.rethrowFromSystemServer();
285 }
286 }
287
288 public String getLaunchedFromPackage(IBinder token) {
289 try {
290 return getActivityClientController().getLaunchedFromPackage(token);
291 } catch (RemoteException e) {
292 throw e.rethrowFromSystemServer();
293 }
294 }
295
296 public void setRequestedOrientation(IBinder token, int requestedOrientation) {
297 try {
298 getActivityClientController().setRequestedOrientation(token, requestedOrientation);
299 } catch (RemoteException e) {
300 e.rethrowFromSystemServer();
301 }
302 }
303
304 int getRequestedOrientation(IBinder token) {
305 try {
306 return getActivityClientController().getRequestedOrientation(token);
307 } catch (RemoteException e) {
308 throw e.rethrowFromSystemServer();
309 }
310 }
311
312 boolean convertFromTranslucent(IBinder token) {
313 try {
314 return getActivityClientController().convertFromTranslucent(token);
315 } catch (RemoteException e) {
316 throw e.rethrowFromSystemServer();
317 }
318 }
319
320 boolean convertToTranslucent(IBinder token, Bundle options) {
321 try {
322 return getActivityClientController().convertToTranslucent(token, options);
323 } catch (RemoteException e) {
324 throw e.rethrowFromSystemServer();
325 }
326 }
327
328 void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) {
329 try {
330 getActivityClientController().reportActivityFullyDrawn(token, restoredFromBundle);
331 } catch (RemoteException e) {
332 e.rethrowFromSystemServer();
333 }
334 }
335
336 boolean isImmersive(IBinder token) {
337 try {
338 return getActivityClientController().isImmersive(token);
339 } catch (RemoteException e) {
340 throw e.rethrowFromSystemServer();
341 }
342 }
343
344 void setImmersive(IBinder token, boolean immersive) {
345 try {
346 getActivityClientController().setImmersive(token, immersive);
347 } catch (RemoteException e) {
348 e.rethrowFromSystemServer();
349 }
350 }
351
352 boolean enterPictureInPictureMode(IBinder token, PictureInPictureParams params) {
353 try {
354 return getActivityClientController().enterPictureInPictureMode(token, params);
355 } catch (RemoteException e) {
356 throw e.rethrowFromSystemServer();
357 }
358 }
359
360 void setPictureInPictureParams(IBinder token, PictureInPictureParams params) {
361 try {
362 getActivityClientController().setPictureInPictureParams(token, params);
363 } catch (RemoteException e) {
364 e.rethrowFromSystemServer();
365 }
366 }
367
368 void setShouldDockBigOverlays(IBinder token, boolean shouldDockBigOverlays) {
369 try {
370 getActivityClientController().setShouldDockBigOverlays(token, shouldDockBigOverlays);
371 } catch (RemoteException e) {
372 e.rethrowFromSystemServer();
373 }
374 }
375
376 void toggleFreeformWindowingMode(IBinder token) {
377 try {
378 getActivityClientController().toggleFreeformWindowingMode(token);
379 } catch (RemoteException e) {
380 e.rethrowFromSystemServer();
381 }
382 }
383
384 void startLockTaskModeByToken(IBinder token) {
385 try {
386 getActivityClientController().startLockTaskModeByToken(token);
387 } catch (RemoteException e) {
388 e.rethrowFromSystemServer();
389 }
390 }
391
392 void stopLockTaskModeByToken(IBinder token) {
393 try {
394 getActivityClientController().stopLockTaskModeByToken(token);
395 } catch (RemoteException e) {
396 e.rethrowFromSystemServer();
397 }
398 }
399
400 void showLockTaskEscapeMessage(IBinder token) {
401 try {
402 getActivityClientController().showLockTaskEscapeMessage(token);
403 } catch (RemoteException e) {
404 e.rethrowFromSystemServer();
405 }
406 }
407
408 void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) {
409 try {
410 getActivityClientController().setTaskDescription(token, td);
411 } catch (RemoteException e) {
412 e.rethrowFromSystemServer();
413 }
414 }
415
416 boolean showAssistFromActivity(IBinder token, Bundle args) {
417 try {
418 return getActivityClientController().showAssistFromActivity(token, args);
419 } catch (RemoteException e) {
420 throw e.rethrowFromSystemServer();
421 }
422 }
423
424 boolean isRootVoiceInteraction(IBinder token) {
425 try {
426 return getActivityClientController().isRootVoiceInteraction(token);
427 } catch (RemoteException e) {
428 throw e.rethrowFromSystemServer();
429 }
430 }
431
432 void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) {
433 try {
434 getActivityClientController().startLocalVoiceInteraction(callingActivity, options);
435 } catch (RemoteException e) {
436 e.rethrowFromSystemServer();
437 }
438 }
439
440 void stopLocalVoiceInteraction(IBinder callingActivity) {
441 try {
442 getActivityClientController().stopLocalVoiceInteraction(callingActivity);
443 } catch (RemoteException e) {
444 e.rethrowFromSystemServer();
445 }
446 }
447
448 void setShowWhenLocked(IBinder token, boolean showWhenLocked) {
449 try {
450 getActivityClientController().setShowWhenLocked(token, showWhenLocked);
451 } catch (RemoteException e) {
452 e.rethrowFromSystemServer();
453 }
454 }
455
456 void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) {
457 try {
458 getActivityClientController().setInheritShowWhenLocked(token, inheritShowWhenLocked);
459 } catch (RemoteException e) {
460 e.rethrowFromSystemServer();
461 }
462 }
463
464 void setTurnScreenOn(IBinder token, boolean turnScreenOn) {
465 try {
466 getActivityClientController().setTurnScreenOn(token, turnScreenOn);
467 } catch (RemoteException e) {
468 e.rethrowFromSystemServer();
469 }
470 }
471
472 int setVrMode(IBinder token, boolean enabled, ComponentName packageName) {
473 try {
474 return getActivityClientController().setVrMode(token, enabled, packageName);
475 } catch (RemoteException e) {
476 throw e.rethrowFromSystemServer();
477 }
478 }
479
480 void overridePendingTransition(IBinder token, String packageName, int enterAnim, int exitAnim,
481 int backgroundColor) {
482 try {
483 getActivityClientController().overridePendingTransition(token, packageName,
484 enterAnim, exitAnim, backgroundColor);
485 } catch (RemoteException e) {
486 e.rethrowFromSystemServer();
487 }
488 }
489
490 void setRecentsScreenshotEnabled(IBinder token, boolean enabled) {
491 try {
492 getActivityClientController().setRecentsScreenshotEnabled(token, enabled);
493 } catch (RemoteException e) {
494 e.rethrowFromSystemServer();
495 }
496 }
497
498 /**
499 * Removes the outdated snapshot of the home task.
500 *
501 * @param homeToken The token of the home task, or null if you have the
502 * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS} permission and
503 * want us to find the home task token for you.
504 */
505 public void invalidateHomeTaskSnapshot(IBinder homeToken) {
506 try {
507 getActivityClientController().invalidateHomeTaskSnapshot(homeToken);
508 } catch (RemoteException e) {
509 e.rethrowFromSystemServer();
510 }
511 }
512
513 void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback,
514 CharSequence message) {
515 try {
516 getActivityClientController().dismissKeyguard(token, callback, message);
517 } catch (RemoteException e) {
518 e.rethrowFromSystemServer();
519 }
520 }
521
522 void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) {
523 try {
524 getActivityClientController().registerRemoteAnimations(token, definition);
525 } catch (RemoteException e) {
526 e.rethrowFromSystemServer();
527 }
528 }
529
530 void unregisterRemoteAnimations(IBinder token) {
531 try {
532 getActivityClientController().unregisterRemoteAnimations(token);
533 } catch (RemoteException e) {
534 e.rethrowFromSystemServer();
535 }
536 }
537
538 void onBackPressed(IBinder token, IRequestFinishCallback callback) {
539 try {
540 getActivityClientController().onBackPressed(token, callback);
541 } catch (RemoteException e) {
542 e.rethrowFromSystemServer();
543 }
544 }
545
546 /**
547 * Reports the splash screen view has attached to client.
548 */
549 void reportSplashScreenAttached(IBinder token) {
550 try {
551 getActivityClientController().splashScreenAttached(token);
552 } catch (RemoteException e) {
553 e.rethrowFromSystemServer();
554 }
555 }
556
557 /**
558 * Shows or hides a Camera app compat toggle for stretched issues with the requested state.
559 *
560 * @param token The token for the window that needs a control.
561 * @param showControl Whether the control should be shown or hidden.
562 * @param transformationApplied Whether the treatment is already applied.
563 * @param callback The callback executed when the user clicks on a control.
564 */
565 void requestCompatCameraControl(Resources res, IBinder token, boolean showControl,
566 boolean transformationApplied, ICompatCameraControlCallback callback) {
567 if (!res.getBoolean(com.android.internal.R.bool
568 .config_isCameraCompatControlForStretchedIssuesEnabled)) {
569 return;
570 }
571 try {
572 getActivityClientController().requestCompatCameraControl(
573 token, showControl, transformationApplied, callback);
574 } catch (RemoteException e) {
575 e.rethrowFromSystemServer();
576 }
577 }
578
579 public static ActivityClient getInstance() {
580 return sInstance.get();
581 }
582
583 /**
584 * If system server has passed the controller interface, store it so the subsequent access can
585 * speed up.
586 */
587 public static IActivityClientController setActivityClientController(
588 IActivityClientController activityClientController) {
589 // No lock because it is no harm to encounter race condition. The thread safe Singleton#get
590 // will take over that case.
591 return INTERFACE_SINGLETON.mKnownInstance = activityClientController;
592 }
593
594 private static IActivityClientController getActivityClientController() {
595 final IActivityClientController controller = INTERFACE_SINGLETON.mKnownInstance;
596 return controller != null ? controller : INTERFACE_SINGLETON.get();
597 }
598
599 private static final Singleton<ActivityClient> sInstance = new Singleton<ActivityClient>() {
600 @Override
601 protected ActivityClient create() {
602 return new ActivityClient();
603 }
604 };
605
606 private static final ActivityClientControllerSingleton INTERFACE_SINGLETON =
607 new ActivityClientControllerSingleton();
608
609 private static class ActivityClientControllerSingleton
610 extends Singleton<IActivityClientController> {
611 /**
612 * A quick look up to reduce potential extra binder transactions. E.g. getting activity
613 * task manager from service manager and controller from activity task manager.
614 */
615 IActivityClientController mKnownInstance;
616
617 @Override
618 protected IActivityClientController create() {
619 try {
620 return ActivityTaskManager.getService().getActivityClientController();
621 } catch (RemoteException e) {
622 throw e.rethrowFromSystemServer();
623 }
624 }
625 }
626 }