diff options
| author | Andrii Kulian <akulian@google.com> | 2018-12-13 18:18:54 -0800 |
|---|---|---|
| committer | Andrii Kulian <akulian@google.com> | 2018-12-18 15:07:04 -0800 |
| commit | 2eb84b28779b35da8e410564db33a8aab1f3fbcb (patch) | |
| tree | 9a02c1fcbae1ea3cfe38dde1a901b5e6726f30ee /core/java/android | |
| parent | 009bd1bfe357418d993a93f3b28adb56d8ea01e5 (diff) | |
Add API to check if activity can be started on a display
Some activity launch restrictions apply to virtual displays, which
are not communicated to apps. Currently there is no way to check
this in advance before starting an activity. This means that an app
get an unexpected SecurityException after calling startActivity and
therefore cannot know when to show in their UI a possible option to
launch on a secondary display.
This CL gives adds a public API to check the possibility of launch
on a specific display.
Test: ActivityManagerMultiDisplayTests
Bug: 119575501
Change-Id: Ieb70f0bb79b1a88b7284a19af2efeeb1fcb90f75
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 26 | ||||
| -rw-r--r-- | core/java/android/app/IActivityTaskManager.aidl | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 84c778502393..d42326020323 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -1976,6 +1976,32 @@ public class ActivityManager { } /** + * Check if the context is allowed to start an activity on specified display. Some launch + * restrictions may apply to secondary displays that are private, virtual, or owned by the + * system, in which case an activity start may throw a {@link SecurityException}. Call this + * method prior to starting an activity on a secondary display to check if the current context + * has access to it. + * + * @see ActivityOptions#setLaunchDisplayId(int) + * @see android.view.Display.FLAG_PRIVATE + * @see android.view.Display.TYPE_VIRTUAL + * + * @param context Source context, from which an activity will be started. + * @param displayId Target display id. + * @param intent Intent used to launch an activity. + * @return {@code true} if a call to start an activity on the target display is allowed for the + * provided context and no {@link SecurityException} will be thrown, {@code false} otherwise. + */ + public boolean isActivityStartAllowedOnDisplay(Context context, int displayId, Intent intent) { + try { + return getTaskService().isActivityStartAllowedOnDisplay(displayId, intent, + intent.resolveTypeIfNeeded(context.getContentResolver()), context.getUserId()); + } catch (RemoteException e) { + throw new RuntimeException("Failure from system", e); + } + } + + /** * Information you can retrieve about a particular Service that is * currently running in the system. */ diff --git a/core/java/android/app/IActivityTaskManager.aidl b/core/java/android/app/IActivityTaskManager.aidl index 777a4949a132..f549e1890b5e 100644 --- a/core/java/android/app/IActivityTaskManager.aidl +++ b/core/java/android/app/IActivityTaskManager.aidl @@ -119,6 +119,8 @@ interface IActivityTaskManager { in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, IBinder permissionToken, boolean ignoreTargetSecurity, int userId); + boolean isActivityStartAllowedOnDisplay(int displayId, in Intent intent, in String resolvedType, + int userId); void unhandledBack(); boolean finishActivity(in IBinder token, int code, in Intent data, int finishTask); |
