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

Commit 02b7a83b authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Make stack field private in TaskRecord

This is needed to enforce usage of setter - prerequisite
for ag/1499587.

Change-Id: I194008899d8320a213e82b9106f0589f499941b4
Test: Refactoring only. Manual and existing tests still pass.
parent 191a99bc
Loading
Loading
Loading
Loading
+26 −25
Original line number Diff line number Diff line
@@ -3101,7 +3101,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized (this) {
            ActivityRecord r = mStackSupervisor.isInAnyStackLocked(token);
            if (r != null) {
                r.task.stack.notifyActivityDrawnLocked(r);
                r.getStack().notifyActivityDrawnLocked(r);
            }
        }
    }
@@ -4749,7 +4749,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                return;
            }
            TaskRecord task = r.task;
            if (task != null && (!task.mFullscreen || !task.stack.mFullscreen)) {
            if (task != null && (!task.mFullscreen || !task.getStack().mFullscreen)) {
                // Fixed screen orientation isn't supported when activities aren't in full screen
                // mode.
                return;
@@ -4789,7 +4789,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            final long origId = Binder.clearCallingIdentity();
            try {
                r.forceNewConfig = true;
                r.task.stack.ensureActivityConfigurationLocked(r, 0, false);
                r.getStack().ensureActivityConfigurationLocked(r, 0, false);
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
@@ -4835,7 +4835,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            if (mController != null) {
                // Find the first activity that is not finishing.
                ActivityRecord next = r.task.stack.topRunningActivityLocked(token, 0);
                ActivityRecord next = r.getStack().topRunningActivityLocked(token, 0);
                if (next != null) {
                    // ask watcher if this is allowed
                    boolean resumeOK = true;
@@ -4869,7 +4869,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                        Slog.i(TAG, "Removing task failed to finish activity");
                    }
                } else {
                    res = tr.stack.requestFinishActivityLocked(token, resultCode,
                    res = tr.getStack().requestFinishActivityLocked(token, resultCode,
                            resultData, "app-request", true);
                    if (!res) {
                        Slog.i(TAG, "Failed to finish by app-request");
@@ -4903,7 +4903,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            for (int i = 0; i < activities.size(); i++) {
                ActivityRecord r = activities.get(i);
                if (!r.finishing && r.isInStackLocked()) {
                    r.task.stack.finishActivityLocked(r, Activity.RESULT_CANCELED,
                    r.getStack().finishActivityLocked(r, Activity.RESULT_CANCELED,
                            null, "finish-heavy", true);
                }
            }
@@ -4939,7 +4939,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            final long origId = Binder.clearCallingIdentity();
            ActivityRecord r = ActivityRecord.isInStackLocked(token);
            if (r != null) {
                r.task.stack.finishSubActivityLocked(r, resultWho, requestCode);
                r.getStack().finishSubActivityLocked(r, resultWho, requestCode);
            }
            Binder.restoreCallingIdentity(origId);
        }
@@ -4963,7 +4963,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    mStackSupervisor.showLockTaskToast();
                    return false;
                }
                return task.stack.finishActivityAffinityLocked(r);
                return task.getStack().finishActivityAffinityLocked(r);
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
@@ -4994,7 +4994,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                if (r == null) {
                    return false;
                }
                return r.task.stack.safelyDestroyActivityLocked(r, "app-req");
                return r.getStack().safelyDestroyActivityLocked(r, "app-req");
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
@@ -6930,9 +6930,9 @@ public final class ActivityManagerService extends ActivityManagerNative
        final long origId = Binder.clearCallingIdentity();
        synchronized (this) {
            ActivityRecord r = ActivityRecord.isInStackLocked(token);
            final ActivityRecord r = ActivityRecord.isInStackLocked(token);
            if (r != null) {
                r.task.stack.activityStoppedLocked(r, icicle, persistentState, description);
                r.getStack().activityStoppedLocked(r, icicle, persistentState, description);
            }
        }
@@ -9076,7 +9076,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        rti.origActivity = tr.origActivity;
        rti.realActivity = tr.realActivity;
        rti.description = tr.lastDescription;
        rti.stackId = tr.stack != null ? tr.stack.mStackId : -1;
        rti.stackId = tr.getStackId();
        rti.userId = tr.userId;
        rti.taskDescription = new ActivityManager.TaskDescription(tr.lastTaskDescription);
        rti.firstActiveTime = tr.firstActiveTime;
@@ -9205,15 +9205,15 @@ public final class ActivityManagerService extends ActivityManagerNative
                            continue;
                        }
                    }
                    final ActivityStack stack = tr.getStack();
                    if ((flags & ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS) != 0) {
                        if (tr.stack != null && tr.stack.isHomeStack()) {
                        if (stack != null && stack.isHomeStack()) {
                            if (DEBUG_RECENTS) Slog.d(TAG_RECENTS,
                                    "Skipping, home stack task: " + tr);
                            continue;
                        }
                    }
                    if ((flags & ActivityManager.RECENT_INGORE_DOCKED_STACK_TOP_TASK) != 0) {
                        final ActivityStack stack = tr.stack;
                        if (stack != null && stack.isDockedStack() && stack.topTask() == tr) {
                            if (DEBUG_RECENTS) Slog.d(TAG_RECENTS,
                                    "Skipping, top task in docked stack: " + tr);
@@ -9221,7 +9221,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                        }
                    }
                    if ((flags & ActivityManager.RECENT_INGORE_PINNED_STACK_TASKS) != 0) {
                        if (tr.stack != null && tr.stack.isPinnedStack()) {
                        if (stack != null && stack.isPinnedStack()) {
                            if (DEBUG_RECENTS) Slog.d(TAG_RECENTS,
                                    "Skipping, pinned stack task: " + tr);
                            continue;
@@ -9328,7 +9328,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                // Use the full screen as the context for the task thumbnail
                final Point displaySize = new Point();
                final TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
                r.task.stack.getDisplaySize(displaySize);
                r.getStack().getDisplaySize(displaySize);
                thumbnailInfo.taskWidth = displaySize.x;
                thumbnailInfo.taskHeight = displaySize.y;
                thumbnailInfo.screenOrientation = mGlobalConfiguration.orientation;
@@ -9352,7 +9352,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                task.inRecents = true;
                mRecentTasks.add(task);
                r.task.stack.addTask(task, false, "addAppTask");
                r.getStack().addTask(task, false, "addAppTask");
                task.setLastThumbnailLocked(thumbnail);
                task.freeLastThumbnail();
@@ -9418,7 +9418,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves
                //   that task to freeform
                // - otherwise the task is not moved
                int stackId = task.stack.mStackId;
                int stackId = task.getStackId();
                if (!StackId.isTaskResizeAllowed(stackId)) {
                    throw new IllegalArgumentException("resizeTask not allowed on task=" + task);
                }
@@ -9428,7 +9428,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    stackId = FREEFORM_WORKSPACE_STACK_ID;
                }
                boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0;
                if (stackId != task.stack.mStackId) {
                if (stackId != task.getStackId()) {
                    mStackSupervisor.moveTaskToStackUncheckedLocked(
                            task, stackId, ON_TOP, !FORCE_FOCUS, "resizeTask");
                    preserveWindow = false;
@@ -9455,7 +9455,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found");
                    return rect;
                }
                if (task.stack != null) {
                if (task.getStack() != null) {
                    // Return the bounds from window manager since it will be adjusted for various
                    // things like the presense of a docked stack for tasks that aren't resizeable.
                    mWindowManager.getTaskBounds(task.taskId, rect);
@@ -10113,7 +10113,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            synchronized (this) {
                final TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(
                        taskId, !RESTORE_FROM_RECENTS, INVALID_STACK_ID);
                return tr != null && tr.stack != null && tr.stack.isHomeStack();
                final ActivityStack stack = tr != null ? tr.getStack() : null;
                return stack != null && stack.isHomeStack();
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
@@ -12460,7 +12461,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
                final boolean translucentChanged = r.changeWindowTranslucency(true);
                if (translucentChanged) {
                    r.task.stack.releaseBackgroundResources(r);
                    r.getStack().releaseBackgroundResources(r);
                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                }
                mWindowManager.setAppFullscreen(token, true);
@@ -12487,7 +12488,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
                final boolean translucentChanged = r.changeWindowTranslucency(false);
                if (translucentChanged) {
                    r.task.stack.convertActivityToTranslucent(r);
                    r.getStack().convertActivityToTranslucent(r);
                }
                mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                mWindowManager.setAppFullscreen(token, false);
@@ -19161,7 +19162,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized (this) {
            ActivityRecord srec = ActivityRecord.forTokenLocked(token);
            if (srec != null) {
                return srec.task.stack.shouldUpRecreateTaskLocked(srec, destAffinity);
                return srec.getStack().shouldUpRecreateTaskLocked(srec, destAffinity);
            }
        }
        return false;
@@ -19173,7 +19174,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized (this) {
            final ActivityRecord r = ActivityRecord.forTokenLocked(token);
            if (r != null) {
                return r.task.stack.navigateUpToLocked(r, destIntent, resultCode, resultData);
                return r.getStack().navigateUpToLocked(r, destIntent, resultCode, resultData);
            }
            return false;
        }
+30 −21
Original line number Diff line number Diff line
@@ -464,7 +464,7 @@ final class ActivityRecord {
    }

    void scheduleMultiWindowModeChanged() {
        if (task == null || task.stack == null || app == null || app.thread == null) {
        if (task == null || task.getStack() == null || app == null || app.thread == null) {
            return;
        }
        try {
@@ -476,20 +476,19 @@ final class ActivityRecord {
    }

    void schedulePictureInPictureModeChanged() {
        if (task == null || task.stack == null || app == null || app.thread == null) {
        if (task == null || task.getStack() == null || app == null || app.thread == null) {
            return;
        }
        try {
            app.thread.schedulePictureInPictureModeChanged(
                    appToken, task.stack.mStackId == PINNED_STACK_ID);
                    appToken, task.getStackId() == PINNED_STACK_ID);
        } catch (Exception e) {
            // If process died, no one cares.
        }
    }

    boolean isFreeform() {
        return task != null && task.stack != null
                && task.stack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
        return task != null && task.getStackId() == FREEFORM_WORKSPACE_STACK_ID;
    }

    static class Token extends IApplicationToken.Stub {
@@ -566,7 +565,7 @@ final class ActivityRecord {
                return null;
            }
            ActivityRecord r = token.weakActivity.get();
            if (r == null || r.task == null || r.task.stack == null) {
            if (r == null || r.getStack() == null) {
                return null;
            }
            return r;
@@ -777,8 +776,9 @@ final class ActivityRecord {
    }

    void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) {
        if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) {
            task.stack.removeTask(task, "setTask");
        if (task != null && task.removeActivity(this) && task != newTask
                && task.getStack() != null) {
            task.getStack().removeTask(task, "setTask");
        }
        task = newTask;
        setTaskToAffiliateWith(taskToAffiliateWith);
@@ -792,6 +792,13 @@ final class ActivityRecord {
        }
    }

    /**
     * @return Stack value from current task, null if there is no task.
     */
    ActivityStack getStack() {
        return task != null ? task.getStack() : null;
    }

    boolean changeWindowTranslucency(boolean toOpaque) {
        if (fullscreen == toOpaque) {
            return false;
@@ -825,7 +832,8 @@ final class ActivityRecord {
    }

    boolean isInStackLocked() {
        return task != null && task.stack != null && task.stack.isInStackLocked(this) != null;
        final ActivityStack stack = getStack();
        return stack != null && stack.isInStackLocked(this) != null;
    }

    boolean isHomeActivity() {
@@ -848,7 +856,7 @@ final class ActivityRecord {
    }

    boolean isFocusable() {
        return StackId.canReceiveKeys(task.stack.mStackId) || isAlwaysFocusable();
        return StackId.canReceiveKeys(task.getStackId()) || isAlwaysFocusable();
    }

    boolean isResizeable() {
@@ -883,8 +891,8 @@ final class ActivityRecord {

    void makeFinishingLocked() {
        if (!finishing) {
            if (task != null && task.stack != null
                    && this == task.stack.getVisibleBehindActivity()) {
            final ActivityStack stack = getStack();
            if (stack != null && this == stack.getVisibleBehindActivity()) {
                // A finishing activity should not remain as visible in the background
                mStackSupervisor.requestVisibleBehindLocked(this, false);
            }
@@ -948,7 +956,7 @@ final class ActivityRecord {
                intent, getUriPermissionsLocked(), userId);
        final ReferrerIntent rintent = new ReferrerIntent(intent, referrer);
        boolean unsent = true;
        final ActivityStack stack = task.stack;
        final ActivityStack stack = getStack();
        final boolean isTopActivityInStack =
                stack != null && stack.topRunningActivityLocked() == this;
        final boolean isTopActivityWhileSleeping =
@@ -1133,7 +1141,7 @@ final class ActivityRecord {
            return false;
        }

        final ActivityStack stack = task.stack;
        final ActivityStack stack = getStack();
        if (stack == null) {
            return false;
        }
@@ -1146,7 +1154,7 @@ final class ActivityRecord {

    void finishLaunchTickingLocked() {
        launchTickTime = 0;
        final ActivityStack stack = task.stack;
        final ActivityStack stack = getStack();
        if (stack != null) {
            stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
        }
@@ -1180,7 +1188,7 @@ final class ActivityRecord {
        if (displayStartTime != 0) {
            reportLaunchTimeLocked(curTime);
        }
        final ActivityStack stack = task.stack;
        final ActivityStack stack = getStack();
        if (fullyDrawnStartTime != 0 && stack != null) {
            final long thisTime = curTime - fullyDrawnStartTime;
            final long totalTime = stack.mFullyDrawnStartTime != 0
@@ -1212,7 +1220,7 @@ final class ActivityRecord {
    }

    private void reportLaunchTimeLocked(final long curTime) {
        final ActivityStack stack = task.stack;
        final ActivityStack stack = getStack();
        if (stack == null) {
            return;
        }
@@ -1356,13 +1364,13 @@ final class ActivityRecord {

    static ActivityRecord isInStackLocked(IBinder token) {
        final ActivityRecord r = ActivityRecord.forTokenLocked(token);
        return (r != null) ? r.task.stack.isInStackLocked(r) : null;
        return (r != null) ? r.getStack().isInStackLocked(r) : null;
    }

    static ActivityStack getStackLocked(IBinder token) {
        final ActivityRecord r = ActivityRecord.isInStackLocked(token);
        if (r != null) {
            return r.task.stack;
            return r.getStack();
        }
        return null;
    }
@@ -1373,8 +1381,9 @@ final class ActivityRecord {
            // This would be redundant.
            return false;
        }
        if (task == null || task.stack == null || this == task.stack.mResumedActivity
                || this == task.stack.mPausingActivity || !haveState || !stopped) {
        final ActivityStack stack = getStack();
        if (stack == null || this == stack.mResumedActivity || this == stack.mPausingActivity
                || !haveState || !stopped) {
            // We're not ready for this kind of thing.
            return false;
        }
+14 −14
Original line number Diff line number Diff line
@@ -644,9 +644,9 @@ final class ActivityStack {
            return null;
        }
        final TaskRecord task = r.task;
        if (task != null && task.stack != null
                && task.mActivities.contains(r) && mTaskHistory.contains(task)) {
            if (task.stack != this) Slog.w(TAG,
        final ActivityStack stack = r.getStack();
        if (stack != null && task.mActivities.contains(r) && mTaskHistory.contains(task)) {
            if (stack != this) Slog.w(TAG,
                    "Illegal state! task does not point to stack it is in.");
            return r;
        }
@@ -1467,7 +1467,7 @@ final class ActivityStack {
    private void setVisible(ActivityRecord r, boolean visible) {
        r.visible = visible;
        if (!visible && r.mUpdateTaskThumbnailWhenHidden) {
            r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null);
            r.updateThumbnailLocked(r.task.getStack().screenshotActivitiesLocked(r), null);
            r.mUpdateTaskThumbnailWhenHidden = false;
        }
        mWindowManager.setAppVisibility(r.appToken, visible);
@@ -1487,7 +1487,7 @@ final class ActivityStack {
            return null;
        }

        ActivityStack stack = task.stack;
        final ActivityStack stack = task.getStack();
        if (stack == null) {
            return null;
        }
@@ -1531,7 +1531,7 @@ final class ActivityStack {
        ArrayList<ActivityStack> stacks = mStacks;
        final ActivityRecord parent = mActivityContainer.mParentActivity;
        if (parent != null) {
            stacks = parent.task.stack.mStacks;
            stacks = parent.getStack().mStacks;
        }
        if (stacks != null) {
            for (int i = stacks.size() - 1; i >= 0; --i) {
@@ -2276,7 +2276,7 @@ final class ActivityStack {
        }

        final TaskRecord nextTask = next.task;
        if (prevTask != null && prevTask.stack == this &&
        if (prevTask != null && prevTask.getStack() == this &&
                prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) {
            if (DEBUG_STACK)  mStackSupervisor.validateTopActivitiesLocked();
            if (prevTask == nextTask) {
@@ -3630,7 +3630,7 @@ final class ActivityStack {
        if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r);
        r.state = ActivityState.FINISHING;
        final boolean finishingActivityInNonFocusedStack
                = r.task.stack != mStackSupervisor.getFocusedStack()
                = r.getStack() != mStackSupervisor.getFocusedStack()
                && prevState == ActivityState.PAUSED && mode == FINISH_AFTER_VISIBLE;

        if (mode == FINISH_IMMEDIATELY
@@ -5228,7 +5228,7 @@ final class ActivityStack {
            }
        }

        task.stack = null;
        task.setStack(null);
    }

    TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent,
@@ -5261,7 +5261,7 @@ final class ActivityStack {
    void addTask(final TaskRecord task, final boolean toTop, String reason) {
        final ActivityStack prevStack = preAddTask(task, reason, toTop);

        task.stack = this;
        task.setStack(this);
        if (toTop) {
            insertTaskAtTop(task, null);
        } else {
@@ -5273,9 +5273,9 @@ final class ActivityStack {

    void positionTask(final TaskRecord task, int position) {
        final ActivityRecord topRunningActivity = task.topRunningActivityLocked();
        final boolean wasResumed = topRunningActivity == task.stack.mResumedActivity;
        final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity;
        final ActivityStack prevStack = preAddTask(task, "positionTask", !ON_TOP);
        task.stack = this;
        task.setStack(this);
        insertTaskAtPosition(task, position);
        postAddTask(task, prevStack);
        if (wasResumed) {
@@ -5289,7 +5289,7 @@ final class ActivityStack {
    }

    private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) {
        final ActivityStack prevStack = task.stack;
        final ActivityStack prevStack = task.getStack();
        if (prevStack != null && prevStack != this) {
            prevStack.removeTask(task, reason,
                    toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING);
@@ -5343,7 +5343,7 @@ final class ActivityStack {
     * created on this stack which the activity is added to.
     * */
    void moveActivityToStack(ActivityRecord r) {
        final ActivityStack prevStack = r.task.stack;
        final ActivityStack prevStack = r.getStack();
        if (prevStack.mStackId == mStackId) {
            // You are already in the right stack silly...
            return;
+37 −34

File changed.

Preview size limit exceeded, changes collapsed.

+33 −27

File changed.

Preview size limit exceeded, changes collapsed.

Loading