Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e2ad37f9 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Add option to retrieve pending intent result

Used by SystemUI to check whether an activity start will
actually lead to something animating.

Also fixes an issue where we return MOVED_TO_FRONT instead of
DELIVERED_TO_TOP.

Test: go/wm-smoke
Test: Use PendingIntent.sendAndReturnResult
Change-Id: I2b6bfca0a53125635bc462f32ab7eaae366c0c8a
parent 4d8d32cb
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -867,19 +867,30 @@ public final class PendingIntent implements Parcelable {
            @Nullable OnFinished onFinished, @Nullable Handler handler,
            @Nullable String requiredPermission, @Nullable Bundle options)
            throws CanceledException {
        if (sendAndReturnResult(context, code, intent, onFinished, handler, requiredPermission,
                options) < 0) {
            throw new CanceledException();
        }
    }

    /**
     * Like {@link #send}, but returns the result
     * @hide
     */
    public int sendAndReturnResult(Context context, int code, @Nullable Intent intent,
            @Nullable OnFinished onFinished, @Nullable Handler handler,
            @Nullable String requiredPermission, @Nullable Bundle options)
            throws CanceledException {
        try {
            String resolvedType = intent != null ?
                    intent.resolveTypeIfNeeded(context.getContentResolver())
                    : null;
            int res = ActivityManager.getService().sendIntentSender(
            return ActivityManager.getService().sendIntentSender(
                    mTarget, mWhitelistToken, code, intent, resolvedType,
                    onFinished != null
                            ? new FinishedDispatcher(this, onFinished, handler)
                            : null,
                    requiredPermission, options);
            if (res < 0) {
                throw new CanceledException();
            }
        } catch (RemoteException e) {
            throw new CanceledException(e);
        }
+1 −1
Original line number Diff line number Diff line
@@ -1252,7 +1252,7 @@ class ActivityStarter {
                    outActivity[0] = reusedActivity;
                }

                return START_TASK_TO_FRONT;
                return START_DELIVERED_TO_TOP;
            }
        }

+6 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.am;

import static android.app.ActivityManager.START_SUCCESS;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;

@@ -311,7 +312,7 @@ final class PendingIntentRecord extends IIntentSender.Stub {
                if (userId == UserHandle.USER_CURRENT) {
                    userId = owner.mUserController.getCurrentOrTargetUserId();
                }
                int res = 0;
                int res = START_SUCCESS;
                switch (key.type) {
                    case ActivityManager.INTENT_SENDER_ACTIVITY:
                        try {
@@ -332,11 +333,11 @@ final class PendingIntentRecord extends IIntentSender.Stub {
                                }
                                allIntents[allIntents.length-1] = finalIntent;
                                allResolvedTypes[allResolvedTypes.length-1] = resolvedType;
                                owner.getActivityStartController().startActivitiesInPackage(uid,
                                        key.packageName, allIntents, allResolvedTypes, resultTo,
                                        mergedOptions, userId);
                                res = owner.getActivityStartController().startActivitiesInPackage(
                                        uid, key.packageName, allIntents, allResolvedTypes,
                                        resultTo, mergedOptions, userId);
                            } else {
                                owner.getActivityStartController().startActivityInPackage(uid,
                                res = owner.getActivityStartController().startActivityInPackage(uid,
                                        callingPid, callingUid, key.packageName, finalIntent,
                                        resolvedType, resultTo, resultWho, requestCode, 0,
                                        mergedOptions, userId, null, "PendingIntentRecord");