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

Commit 98689f75 authored by Bryce Lee's avatar Bryce Lee
Browse files

Revert "Remove activity from task if not set properly."

This reverts commit 0f9bde84.

Reason for revert: causing b/35879503

Change-Id: I06402356ecdb559dcb8342f3a6cca755aea6533a
Fixes: 35879503
Bug: 35034729
Bug: 35035258
Bug: 34179495
Test: manual with repro steps
parent 0f9bde84
Loading
Loading
Loading
Loading
+9 −18
Original line number Diff line number Diff line
@@ -3023,18 +3023,10 @@ public class ActivityManagerService extends IActivityManager.Stub
            startRunningVoiceLocked(r.task.voiceSession, r.info.applicationInfo.uid);
        } else {
            finishRunningVoiceLocked();
            if (mLastResumedActivity != null) {
                final IVoiceInteractionSession session;
                if (mLastResumedActivity.task != null
                    && mLastResumedActivity.task.voiceSession != null) {
                    session = mLastResumedActivity.task.voiceSession;
                } else {
                    session = mLastResumedActivity.voiceSession;
                }
                if (session != null) {
            IVoiceInteractionSession session;
            if (mLastResumedActivity != null
                    && ((session = mLastResumedActivity.task.voiceSession) != null
                    || (session = mLastResumedActivity.voiceSession) != null)) {
                // We had been in a voice interaction session, but now focused has
                // move to something different.  Just finish the session, we can't
                // return to it and retain the proper state and synchronization with
@@ -3042,7 +3034,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                finishVoiceTask(session);
            }
        }
        }
        mWindowManager.setFocusedApp(r.appToken, true);
+4 −1
Original line number Diff line number Diff line
@@ -802,7 +802,10 @@ final class ActivityRecord implements AppWindowContainerListener {

        // Remove the activity from the old task and add it to the new task
        prevTask.removeActivity(this);

        // TODO(b/34179495): This should really be set to null in removeActivity() call above,
        // but really bad things that I can't track down right now happen when I do that.
        // So, setting it here now and will change later when there is time for investigation.
        task = null;
        newTask.addActivityAtIndex(position, this);
    }

+2 −1
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -4901,7 +4902,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
                setResizingDuringAnimation(task);
            }

            mService.mActivityStarter.postStartActivityProcessing(task.getTopActivity(),
            mService.mActivityStarter.postStartActivityUncheckedProcessing(task.getTopActivity(),
                    ActivityManager.START_TASK_TO_FRONT,
                    sourceRecord != null ? sourceRecord.task.getStackId() : INVALID_STACK_ID,
                    sourceRecord, task.getStack());
+23 −38
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.server.am;

import static android.app.Activity.RESULT_CANCELED;
import static android.app.ActivityManager.START_CANCELED;
import static android.app.ActivityManager.START_CLASS_NOT_FOUND;
import static android.app.ActivityManager.START_DELIVERED_TO_TOP;
import static android.app.ActivityManager.START_FLAG_ONLY_IF_NEEDED;
@@ -89,10 +88,12 @@ import android.app.ActivityOptions;
import android.app.AppGlobals;
import android.app.IActivityContainer;
import android.app.IApplicationThread;
import android.app.KeyguardManager;
import android.app.PendingIntent;
import android.app.ProfilerInfo;
import android.app.WaitResult;
import android.content.ComponentName;
import android.content.Context;
import android.content.IIntentSender;
import android.content.Intent;
import android.content.IntentSender;
@@ -508,8 +509,15 @@ class ActivityStarter {

        doPendingActivityLaunchesLocked(false);

        return startActivity(r, sourceRecord, voiceSession, voiceInteractor, startFlags, true,
            options, inTask);
        try {
            mService.mWindowManager.deferSurfaceLayout();
            err = startActivityUnchecked(r, sourceRecord, voiceSession, voiceInteractor, startFlags,
                    true, options, inTask);
        } finally {
            mService.mWindowManager.continueSurfaceLayout();
        }
        postStartActivityUncheckedProcessing(r, err, stack.mStackId, mSourceRecord, mTargetStack);
        return err;
    }

    /** Creates a launch intent for the given auxiliary resolution data. */
@@ -527,7 +535,7 @@ class ActivityStarter {
                auxiliaryResponse.token, auxiliaryResponse.needsPhaseTwo);
    }

    void postStartActivityProcessing(
    void postStartActivityUncheckedProcessing(
            ActivityRecord r, int result, int prevFocusedStackId, ActivityRecord sourceRecord,
            ActivityStack targetStack) {

@@ -929,32 +937,6 @@ class ActivityStarter {
        }
    }

    private int startActivity(final ActivityRecord r, ActivityRecord sourceRecord,
        IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
        int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask) {
        int result = START_CANCELED;
        try {
            mService.mWindowManager.deferSurfaceLayout();
            result = startActivityUnchecked(r, sourceRecord, voiceSession, voiceInteractor,
                startFlags,
                doResume, options, inTask);
        } finally {
            // If we are not able to proceed, disassociate the activity from the task. Leaving an
            // activity in an incomplete state can lead to issues, such as performing operations
            // without a window container.
            if (result != START_SUCCESS && mStartActivity.task != null) {
                mStartActivity.task.removeActivity(mStartActivity);
            }
            mService.mWindowManager.continueSurfaceLayout();
        }

        postStartActivityProcessing(r, result, mSupervisor.mFocusedStack.mStackId,
            mSourceRecord, mTargetStack);

        return result;
    }

    // Note: This method should only be called from {@link startActivity}.
    private int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord,
            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
            int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask) {
@@ -1861,8 +1843,11 @@ class ActivityStarter {
            final PendingActivityLaunch pal = mPendingActivityLaunches.remove(0);
            final boolean resume = doResume && mPendingActivityLaunches.isEmpty();
            try {
                startActivity(pal.r, pal.sourceRecord, null, null, pal.startFlags, resume, null,
                    null);
                final int result = startActivityUnchecked(
                        pal.r, pal.sourceRecord, null, null, pal.startFlags, resume, null, null);
                postStartActivityUncheckedProcessing(
                        pal.r, result, mSupervisor.mFocusedStack.mStackId, mSourceRecord,
                        mTargetStack);
            } catch (Exception e) {
                Slog.e(TAG, "Exception during pending activity launch pal=" + pal, e);
                pal.sendErrorResult(e.getMessage());
+0 −7
Original line number Diff line number Diff line
@@ -1083,13 +1083,6 @@ final class TaskRecord extends ConfigurationContainer implements TaskWindowConta

    /** @return true if this was the last activity in the task */
    boolean removeActivity(ActivityRecord r) {
        if (r.task != this) {
            throw new IllegalArgumentException(
                "Activity=" + r + " does not belong to task=" + this);
        }

        r.task = null;

        if (mActivities.remove(r) && r.fullscreen) {
            // Was previously in list.
            numFullscreen--;