From b3192809643eff948d9457c8a7b36b968a7388a1 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 8 Feb 2022 06:22:47 +0000 Subject: [PATCH] Backport missing permission check for querying main activity intent - This was fixed in T in ag/16820166, but the original code was submitted in S. This ensures that the caller of this method is either holding the ACCESS_SHORTCUTS permission or is the default launcher. Bug: 229256049 Test: atest WMShellUnitTests Change-Id: Ib233ad754a6c6e3c4e0d0e10ed788ab8e055cccc Merged-In: Ib233ad754a6c6e3c4e0d0e10ed788ab8e055cccc (cherry picked from commit f4ed441e180d7113b5f6ebfe711e61a2dd3fd8b1) --- core/java/android/content/pm/ILauncherApps.aidl | 4 ++-- core/java/android/content/pm/LauncherApps.java | 3 ++- .../core/java/com/android/server/pm/LauncherAppsService.java | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/java/android/content/pm/ILauncherApps.aidl b/core/java/android/content/pm/ILauncherApps.aidl index 37fd3ffdeafa5..2eaadb05276c9 100644 --- a/core/java/android/content/pm/ILauncherApps.aidl +++ b/core/java/android/content/pm/ILauncherApps.aidl @@ -56,8 +56,8 @@ interface ILauncherApps { void startActivityAsUser(in IApplicationThread caller, String callingPackage, String callingFeatureId, in ComponentName component, in Rect sourceBounds, in Bundle opts, in UserHandle user); - PendingIntent getActivityLaunchIntent(in ComponentName component, in Bundle opts, - in UserHandle user); + PendingIntent getActivityLaunchIntent(String callingPackage, in ComponentName component, + in Bundle opts, in UserHandle user); void showAppDetailsAsUser(in IApplicationThread caller, String callingPackage, String callingFeatureId, in ComponentName component, in Rect sourceBounds, in Bundle opts, in UserHandle user); diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java index 0f9acadb11f98..4b6c586266a97 100644 --- a/core/java/android/content/pm/LauncherApps.java +++ b/core/java/android/content/pm/LauncherApps.java @@ -752,7 +752,8 @@ public class LauncherApps { } try { // due to b/209607104, startActivityOptions will be ignored - return mService.getActivityLaunchIntent(component, null /* opts */, user); + return mService.getActivityLaunchIntent(mContext.getPackageName(), component, + null /* opts */, user); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java index 24b9f48e71a64..a238593a96f87 100644 --- a/services/core/java/com/android/server/pm/LauncherAppsService.java +++ b/services/core/java/com/android/server/pm/LauncherAppsService.java @@ -1098,8 +1098,9 @@ public class LauncherAppsService extends SystemService { } @Override - public PendingIntent getActivityLaunchIntent(ComponentName component, Bundle opts, - UserHandle user) { + public PendingIntent getActivityLaunchIntent(String callingPackage, ComponentName component, + Bundle opts, UserHandle user) { + ensureShortcutPermission(callingPackage); if (!canAccessProfile(user.getIdentifier(), "Cannot start activity")) { throw new ActivityNotFoundException("Activity could not be found"); }