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