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