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 f4ed441e18)
This commit is contained in:
Winson Chung
2022-02-08 06:22:47 +00:00
parent 9142d8c936
commit b319280964
3 changed files with 7 additions and 5 deletions

View File

@@ -56,8 +56,8 @@ interface ILauncherApps {
void startActivityAsUser(in IApplicationThread caller, String callingPackage, void startActivityAsUser(in IApplicationThread caller, String callingPackage,
String callingFeatureId, in ComponentName component, in Rect sourceBounds, String callingFeatureId, in ComponentName component, in Rect sourceBounds,
in Bundle opts, in UserHandle user); in Bundle opts, in UserHandle user);
PendingIntent getActivityLaunchIntent(in ComponentName component, in Bundle opts, PendingIntent getActivityLaunchIntent(String callingPackage, in ComponentName component,
in UserHandle user); in Bundle opts, in UserHandle user);
void showAppDetailsAsUser(in IApplicationThread caller, String callingPackage, void showAppDetailsAsUser(in IApplicationThread caller, String callingPackage,
String callingFeatureId, in ComponentName component, in Rect sourceBounds, String callingFeatureId, in ComponentName component, in Rect sourceBounds,
in Bundle opts, in UserHandle user); in Bundle opts, in UserHandle user);

View File

@@ -752,7 +752,8 @@ public class LauncherApps {
} }
try { try {
// due to b/209607104, startActivityOptions will be ignored // 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) { } catch (RemoteException re) {
throw re.rethrowFromSystemServer(); throw re.rethrowFromSystemServer();
} }

View File

@@ -1098,8 +1098,9 @@ public class LauncherAppsService extends SystemService {
} }
@Override @Override
public PendingIntent getActivityLaunchIntent(ComponentName component, Bundle opts, public PendingIntent getActivityLaunchIntent(String callingPackage, ComponentName component,
UserHandle user) { Bundle opts, UserHandle user) {
ensureShortcutPermission(callingPackage);
if (!canAccessProfile(user.getIdentifier(), "Cannot start activity")) { if (!canAccessProfile(user.getIdentifier(), "Cannot start activity")) {
throw new ActivityNotFoundException("Activity could not be found"); throw new ActivityNotFoundException("Activity could not be found");
} }