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

Commit 03cf6244 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Immediately deliver new intent to paused activity in docked stack" into nyc-mr1-dev

parents c4cea1e0 826c7061
Loading
Loading
Loading
Loading
+30 −16
Original line number Diff line number Diff line
@@ -433,8 +433,10 @@ public final class ActivityThread {
    static final class NewIntentData {
        List<ReferrerIntent> intents;
        IBinder token;
        boolean andPause;
        public String toString() {
            return "NewIntentData{intents=" + intents + " token=" + token + "}";
            return "NewIntentData{intents=" + intents + " token=" + token
                    + " andPause=" + andPause +"}";
        }
    }

@@ -751,10 +753,12 @@ public final class ActivityThread {
                    configChanges, notResumed, config, overrideConfig, true, preserveWindow);
        }

        public final void scheduleNewIntent(List<ReferrerIntent> intents, IBinder token) {
        public final void scheduleNewIntent(
                List<ReferrerIntent> intents, IBinder token, boolean andPause) {
            NewIntentData data = new NewIntentData();
            data.intents = intents;
            data.token = token;
            data.andPause = andPause;

            sendMessage(H.NEW_INTENT, data);
        }
@@ -2787,9 +2791,12 @@ public final class ActivityThread {
        }
    }

    public final void performNewIntents(IBinder token, List<ReferrerIntent> intents) {
        ActivityClientRecord r = mActivities.get(token);
        if (r != null) {
    void performNewIntents(IBinder token, List<ReferrerIntent> intents, boolean andPause) {
        final ActivityClientRecord r = mActivities.get(token);
        if (r == null) {
            return;
        }

        final boolean resumed = !r.paused;
        if (resumed) {
            r.activity.mTemporaryPause = true;
@@ -2800,11 +2807,18 @@ public final class ActivityThread {
            r.activity.performResume();
            r.activity.mTemporaryPause = false;
        }

        if (r.paused && andPause) {
            // In this case the activity was in the paused state when we delivered the intent,
            // to guarantee onResume gets called after onNewIntent we temporarily resume the
            // activity and pause again as the caller wanted.
            performResumeActivity(token, false, "performNewIntents");
            performPauseActivityIfNeeded(r, "performNewIntents");
        }
    }

    private void handleNewIntent(NewIntentData data) {
        performNewIntents(data.token, data.intents);
        performNewIntents(data.token, data.intents, data.andPause);
    }

    public void handleRequestAssistContextExtras(RequestAssistContextExtras cmd) {
+4 −2
Original line number Diff line number Diff line
@@ -190,7 +190,8 @@ public abstract class ApplicationThreadNative extends Binder
            data.enforceInterface(IApplicationThread.descriptor);
            List<ReferrerIntent> pi = data.createTypedArrayList(ReferrerIntent.CREATOR);
            IBinder b = data.readStrongBinder();
            scheduleNewIntent(pi, b);
            final boolean andPause = data.readInt() == 1;
            scheduleNewIntent(pi, b, andPause);
            return true;
        }

@@ -909,12 +910,13 @@ class ApplicationThreadProxy implements IApplicationThread {
        data.recycle();
    }

    public void scheduleNewIntent(List<ReferrerIntent> intents, IBinder token)
    public void scheduleNewIntent(List<ReferrerIntent> intents, IBinder token, boolean andPause)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
        data.writeTypedList(intents);
        data.writeStrongBinder(token);
        data.writeInt(andPause ? 1 : 0);
        mRemote.transact(SCHEDULE_NEW_INTENT_TRANSACTION, data, null,
                IBinder.FLAG_ONEWAY);
        data.recycle();
+2 −1
Original line number Diff line number Diff line
@@ -67,7 +67,8 @@ public interface IApplicationThread extends IInterface {
            List<ReferrerIntent> pendingNewIntents, int configChanges, boolean notResumed,
            Configuration config, Configuration overrideConfig, boolean preserveWindow)
            throws RemoteException;
    void scheduleNewIntent(List<ReferrerIntent> intent, IBinder token) throws RemoteException;
    void scheduleNewIntent(
            List<ReferrerIntent> intent, IBinder token, boolean andPause) throws RemoteException;
    void scheduleDestroyActivity(IBinder token, boolean finished,
            int configChanges) throws RemoteException;
    void scheduleReceiver(Intent intent, ActivityInfo info, CompatibilityInfo compatInfo,
+1 −1
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ public class LocalActivityManager {
                    ArrayList<ReferrerIntent> intents = new ArrayList<>(1);
                    intents.add(new ReferrerIntent(intent, mParent.getPackageName()));
                    if (localLOGV) Log.v(TAG, r.id + ": new intent");
                    mActivityThread.performNewIntents(r, intents);
                    mActivityThread.performNewIntents(r, intents, false /* andPause */);
                    r.intent = intent;
                    moveToState(r, mCurState);
                    if (mSingleMode) {
+19 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.am;

import static android.app.ActivityManager.StackId;
import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
@@ -946,21 +947,29 @@ final class ActivityRecord {
        // The activity now gets access to the data associated with this Intent.
        service.grantUriPermissionFromIntentLocked(callingUid, packageName,
                intent, getUriPermissionsLocked(), userId);
        // We want to immediately deliver the intent to the activity if
        // it is currently the top resumed activity...  however, if the
        // device is sleeping, then all activities are stopped, so in that
        // case we will deliver it if this is the current top activity on its
        // stack.
        final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
        boolean unsent = true;
        if ((state == ActivityState.RESUMED
                || (service.isSleepingLocked() && task.stack != null
                    && task.stack.topRunningActivityLocked() == this))
                && app != null && app.thread != null) {
        final ActivityStack stack = task.stack;
        final boolean isTopActivityInStack =
                stack != null && stack.topRunningActivityLocked() == this;
        final boolean isTopActivityWhileSleeping =
                service.isSleepingLocked() && isTopActivityInStack;
        final boolean isTopActivityInMinimizedDockedStack = isTopActivityInStack
                && stack.mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized
                && state == ActivityState.PAUSED;

        // We want to immediately deliver the intent to the activity if:
        // - It is the resumed activity.
        // - The device is sleeping and it is the top activity behind the lock screen (b/6700897).
        // - It is the top activity in a minimized docked stack. In this case the activity will be
        //   temporarily resumed then paused again on the client side.
        if ((state == ActivityState.RESUMED || isTopActivityWhileSleeping
                || isTopActivityInMinimizedDockedStack) && app != null && app.thread != null) {
            try {
                ArrayList<ReferrerIntent> ar = new ArrayList<>(1);
                ar.add(rintent);
                app.thread.scheduleNewIntent(ar, appToken);
                app.thread.scheduleNewIntent(
                        ar, appToken, isTopActivityInMinimizedDockedStack /* andPause */);
                unsent = false;
            } catch (RemoteException e) {
                Slog.w(TAG, "Exception thrown sending new intent to " + this, e);
Loading