Loading core/java/android/app/ActivityManagerInternal.java +5 −4 Original line number Diff line number Diff line Loading @@ -165,9 +165,10 @@ public abstract class ActivityManagerInternal { int userId); /** * Create an {@link IIntentSender} to start an activity, as if {@code packageName} on * user {@code userId} created it. * Start an activity {@code intent} as if {@code packageName} on user {@code userId} did it. * * @return error codes used by {@link IActivityManager#startActivity} and its siblings. */ public abstract IIntentSender getActivityIntentSenderAsPackage(String packageName, int userId, int requestCode, Intent intent, int flags, Bundle bOptions); public abstract int startActivityAsPackage(String packageName, int userId, Intent intent, Bundle bOptions); } core/java/android/content/pm/ILauncherApps.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ interface ILauncherApps { in List shortcutIds, in ComponentName componentName, int flags, in UserHandle user); void pinShortcuts(String callingPackage, String packageName, in List<String> shortcutIds, in UserHandle user); void startShortcut(String callingPackage, String packageName, String id, boolean startShortcut(String callingPackage, String packageName, String id, in Rect sourceBounds, in Bundle startActivityOptions, int userId); int getShortcutIconResId(String callingPackage, String packageName, String id, Loading core/java/android/content/pm/LauncherApps.java +12 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -688,6 +689,9 @@ public class LauncherApps { * @param sourceBounds The Rect containing the source bounds of the clicked icon. * @param startActivityOptions Options to pass to startActivity. * @param user The UserHandle of the profile. * * @throws android.content.ActivityNotFoundException failed to start shortcut. (e.g. * the shortcut no longer exists, is disabled, the intent receiver activity doesn't exist, etc) */ public void startShortcut(@NonNull String packageName, @NonNull String shortcutId, @Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions, Loading @@ -705,6 +709,9 @@ public class LauncherApps { * @param shortcut The target shortcut. * @param sourceBounds The Rect containing the source bounds of the clicked icon. * @param startActivityOptions Options to pass to startActivity. * * @throws android.content.ActivityNotFoundException failed to start shortcut. (e.g. * the shortcut no longer exists, is disabled, the intent receiver activity doesn't exist, etc) */ public void startShortcut(@NonNull ShortcutInfo shortcut, @Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions) { Loading @@ -717,8 +724,12 @@ public class LauncherApps { @Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions, int userId) { try { final boolean success = mService.startShortcut(mContext.getPackageName(), packageName, shortcutId, sourceBounds, startActivityOptions, userId); if (!success) { throw new ActivityNotFoundException("Shortcut could not be started"); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading services/core/java/com/android/server/am/ActivityManagerService.java +7 −10 Original line number Diff line number Diff line Loading @@ -21788,11 +21788,10 @@ public final class ActivityManagerService extends ActivityManagerNative } @Override public IIntentSender getActivityIntentSenderAsPackage( String packageName, int userId, int requestCode, Intent intent, int flags, Bundle bOptions) { String resolvedType = intent != null ? intent.resolveTypeIfNeeded( mContext.getContentResolver()) : null; public int startActivityAsPackage(String packageName, int userId, Intent intent, Bundle bOptions) { Preconditions.checkNotNull(intent, "intent"); final String resolvedType = intent.resolveTypeIfNeeded(mContext.getContentResolver()); // UID of the package on user userId. // "= 0" is needed because otherwise catch(RemoteException) would make it look like Loading @@ -21806,11 +21805,9 @@ public final class ActivityManagerService extends ActivityManagerNative } synchronized (ActivityManagerService.this) { return getIntentSenderLocked( ActivityManager.INTENT_SENDER_ACTIVITY, packageName, packageUid, UserHandle.getUserId(packageUid), /*token*/ null, /*resultWho*/ null, requestCode, new Intent[] {intent}, new String[]{resolvedType}, flags, bOptions); return startActivityInPackage(packageUid, packageName, intent, resolvedType, /*resultTo*/ null, /*resultWho*/ null, /*requestCode*/ 0, /*startFlags*/ 0, bOptions, userId, /*container*/ null, /*inTask*/ null); } } } services/core/java/com/android/server/pm/LauncherAppsService.java +22 −26 Original line number Diff line number Diff line Loading @@ -19,19 +19,18 @@ package com.android.server.pm; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.ActivityManagerInternal; import android.app.ActivityManagerNative; import android.app.AppGlobals; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.IIntentSender; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ILauncherApps; import android.content.pm.IOnAppsChangedListener; import android.content.pm.IPackageManager; import android.content.pm.LauncherApps; import android.content.pm.LauncherApps.ShortcutQuery; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; Loading Loading @@ -439,7 +438,7 @@ public class LauncherAppsService extends SystemService { } @Override public void startShortcut(String callingPackage, String packageName, String shortcutId, public boolean startShortcut(String callingPackage, String packageName, String shortcutId, Rect sourceBounds, Bundle startActivityOptions, int userId) { verifyCallingPackage(callingPackage); ensureInUserProfiles(userId, "Cannot start activity for unrelated profile " + userId); Loading @@ -458,39 +457,36 @@ public class LauncherAppsService extends SystemService { final Intent intent = mShortcutServiceInternal.createShortcutIntent(getCallingUserId(), callingPackage, packageName, shortcutId, userId); if (intent == null) { return; return false; } // Note the target activity doesn't have to be exported. prepareIntentForLaunch(intent, sourceBounds); startShortcutIntentAsPublisher( return startShortcutIntentAsPublisher( intent, packageName, startActivityOptions, userId); } @VisibleForTesting protected void startShortcutIntentAsPublisher(@NonNull Intent intent, private boolean startShortcutIntentAsPublisher(@NonNull Intent intent, @NonNull String publisherPackage, Bundle startActivityOptions, int userId) { final int code; final long ident = injectClearCallingIdentity(); try { final IIntentSender intentSender; final long ident = Binder.clearCallingIdentity(); try { intentSender = mActivityManagerInternal.getActivityIntentSenderAsPackage( publisherPackage, userId, /* requestCode= */ 0, intent, PendingIntent.FLAG_ONE_SHOT, /* options= */ startActivityOptions); } finally { Binder.restoreCallingIdentity(ident); code = mActivityManagerInternal.startActivityAsPackage(publisherPackage, userId, intent, startActivityOptions); if (code >= ActivityManager.START_SUCCESS) { return true; // Success } else { Log.e(TAG, "Couldn't start activity, code=" + code); } // Negative result means a failure. ActivityManagerNative.getDefault().sendIntentSender( intentSender, 0, null, null, null, null, null); } catch (RemoteException e) { return; return code >= ActivityManager.START_SUCCESS; } catch (SecurityException e) { if (DEBUG) { Slog.d(TAG, "SecurityException while launching intent", e); } return false; } finally { injectRestoreCallingIdentity(ident); } } Loading Loading
core/java/android/app/ActivityManagerInternal.java +5 −4 Original line number Diff line number Diff line Loading @@ -165,9 +165,10 @@ public abstract class ActivityManagerInternal { int userId); /** * Create an {@link IIntentSender} to start an activity, as if {@code packageName} on * user {@code userId} created it. * Start an activity {@code intent} as if {@code packageName} on user {@code userId} did it. * * @return error codes used by {@link IActivityManager#startActivity} and its siblings. */ public abstract IIntentSender getActivityIntentSenderAsPackage(String packageName, int userId, int requestCode, Intent intent, int flags, Bundle bOptions); public abstract int startActivityAsPackage(String packageName, int userId, Intent intent, Bundle bOptions); }
core/java/android/content/pm/ILauncherApps.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ interface ILauncherApps { in List shortcutIds, in ComponentName componentName, int flags, in UserHandle user); void pinShortcuts(String callingPackage, String packageName, in List<String> shortcutIds, in UserHandle user); void startShortcut(String callingPackage, String packageName, String id, boolean startShortcut(String callingPackage, String packageName, String id, in Rect sourceBounds, in Bundle startActivityOptions, int userId); int getShortcutIconResId(String callingPackage, String packageName, String id, Loading
core/java/android/content/pm/LauncherApps.java +12 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading Loading @@ -688,6 +689,9 @@ public class LauncherApps { * @param sourceBounds The Rect containing the source bounds of the clicked icon. * @param startActivityOptions Options to pass to startActivity. * @param user The UserHandle of the profile. * * @throws android.content.ActivityNotFoundException failed to start shortcut. (e.g. * the shortcut no longer exists, is disabled, the intent receiver activity doesn't exist, etc) */ public void startShortcut(@NonNull String packageName, @NonNull String shortcutId, @Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions, Loading @@ -705,6 +709,9 @@ public class LauncherApps { * @param shortcut The target shortcut. * @param sourceBounds The Rect containing the source bounds of the clicked icon. * @param startActivityOptions Options to pass to startActivity. * * @throws android.content.ActivityNotFoundException failed to start shortcut. (e.g. * the shortcut no longer exists, is disabled, the intent receiver activity doesn't exist, etc) */ public void startShortcut(@NonNull ShortcutInfo shortcut, @Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions) { Loading @@ -717,8 +724,12 @@ public class LauncherApps { @Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions, int userId) { try { final boolean success = mService.startShortcut(mContext.getPackageName(), packageName, shortcutId, sourceBounds, startActivityOptions, userId); if (!success) { throw new ActivityNotFoundException("Shortcut could not be started"); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
services/core/java/com/android/server/am/ActivityManagerService.java +7 −10 Original line number Diff line number Diff line Loading @@ -21788,11 +21788,10 @@ public final class ActivityManagerService extends ActivityManagerNative } @Override public IIntentSender getActivityIntentSenderAsPackage( String packageName, int userId, int requestCode, Intent intent, int flags, Bundle bOptions) { String resolvedType = intent != null ? intent.resolveTypeIfNeeded( mContext.getContentResolver()) : null; public int startActivityAsPackage(String packageName, int userId, Intent intent, Bundle bOptions) { Preconditions.checkNotNull(intent, "intent"); final String resolvedType = intent.resolveTypeIfNeeded(mContext.getContentResolver()); // UID of the package on user userId. // "= 0" is needed because otherwise catch(RemoteException) would make it look like Loading @@ -21806,11 +21805,9 @@ public final class ActivityManagerService extends ActivityManagerNative } synchronized (ActivityManagerService.this) { return getIntentSenderLocked( ActivityManager.INTENT_SENDER_ACTIVITY, packageName, packageUid, UserHandle.getUserId(packageUid), /*token*/ null, /*resultWho*/ null, requestCode, new Intent[] {intent}, new String[]{resolvedType}, flags, bOptions); return startActivityInPackage(packageUid, packageName, intent, resolvedType, /*resultTo*/ null, /*resultWho*/ null, /*requestCode*/ 0, /*startFlags*/ 0, bOptions, userId, /*container*/ null, /*inTask*/ null); } } }
services/core/java/com/android/server/pm/LauncherAppsService.java +22 −26 Original line number Diff line number Diff line Loading @@ -19,19 +19,18 @@ package com.android.server.pm; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.ActivityManagerInternal; import android.app.ActivityManagerNative; import android.app.AppGlobals; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.IIntentSender; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ILauncherApps; import android.content.pm.IOnAppsChangedListener; import android.content.pm.IPackageManager; import android.content.pm.LauncherApps; import android.content.pm.LauncherApps.ShortcutQuery; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; Loading Loading @@ -439,7 +438,7 @@ public class LauncherAppsService extends SystemService { } @Override public void startShortcut(String callingPackage, String packageName, String shortcutId, public boolean startShortcut(String callingPackage, String packageName, String shortcutId, Rect sourceBounds, Bundle startActivityOptions, int userId) { verifyCallingPackage(callingPackage); ensureInUserProfiles(userId, "Cannot start activity for unrelated profile " + userId); Loading @@ -458,39 +457,36 @@ public class LauncherAppsService extends SystemService { final Intent intent = mShortcutServiceInternal.createShortcutIntent(getCallingUserId(), callingPackage, packageName, shortcutId, userId); if (intent == null) { return; return false; } // Note the target activity doesn't have to be exported. prepareIntentForLaunch(intent, sourceBounds); startShortcutIntentAsPublisher( return startShortcutIntentAsPublisher( intent, packageName, startActivityOptions, userId); } @VisibleForTesting protected void startShortcutIntentAsPublisher(@NonNull Intent intent, private boolean startShortcutIntentAsPublisher(@NonNull Intent intent, @NonNull String publisherPackage, Bundle startActivityOptions, int userId) { final int code; final long ident = injectClearCallingIdentity(); try { final IIntentSender intentSender; final long ident = Binder.clearCallingIdentity(); try { intentSender = mActivityManagerInternal.getActivityIntentSenderAsPackage( publisherPackage, userId, /* requestCode= */ 0, intent, PendingIntent.FLAG_ONE_SHOT, /* options= */ startActivityOptions); } finally { Binder.restoreCallingIdentity(ident); code = mActivityManagerInternal.startActivityAsPackage(publisherPackage, userId, intent, startActivityOptions); if (code >= ActivityManager.START_SUCCESS) { return true; // Success } else { Log.e(TAG, "Couldn't start activity, code=" + code); } // Negative result means a failure. ActivityManagerNative.getDefault().sendIntentSender( intentSender, 0, null, null, null, null, null); } catch (RemoteException e) { return; return code >= ActivityManager.START_SUCCESS; } catch (SecurityException e) { if (DEBUG) { Slog.d(TAG, "SecurityException while launching intent", e); } return false; } finally { injectRestoreCallingIdentity(ident); } } Loading