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

Commit 1602ec21 authored by Craig Mautner's avatar Craig Mautner
Browse files

Log stack issues and start resize effort.

- Modify Am.java to accept 'stack resize' command.

- Add logging for assigning home stack to non-home task to track down
bug. And maybe fix bug.

- Add template parameter to ArrayList.

Change-Id: Ia73182afc20e9e4430ddadebae034cecb3798eec
parent a5ca95a8
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class Am extends BaseCommand {
                "       am stop-user <USER_ID>\n" +
                "       am stack create <TASK_ID> <RELATIVE_STACK_ID> <POSITION> <WEIGHT>\n" +
                "       am stack movetask <STACK_ID> <TASK_ID> [true|false]\n" +
                "       am stack resize <STACK_ID> <WEIGHT>\n" +
                "       am stack dump\n" +
                "\n" +
                "am start: start an Activity.  Options are:\n" +
@@ -199,6 +200,8 @@ public class Am extends BaseCommand {
                "am stack movetask: move <TASK_ID> from its current stack to the top (true) or" +
                "   bottom (false) of <STACK_ID>.\n" +
                "\n" +
                "am stack resize: change <STACK_ID> relative size to new <WEIGHT>.\n" +
                "\n" +
                "am stack dump: list the hierarchy of stacks.\n" +
                "\n" +
                "<INTENT> specifications include these flags and arguments:\n" +
@@ -1481,6 +1484,8 @@ public class Am extends BaseCommand {
            runStackCreate();
        } else if (op.equals("movetask")) {
            runStackMoveTask();
        } else if (op.equals("resize")) {
            runStackResize();
        } else if (op.equals("dump")) {
            runStackDump();
        } else {
@@ -1528,6 +1533,18 @@ public class Am extends BaseCommand {
        }
    }

    private void runStackResize() throws Exception {
        String stackIdStr = nextArgRequired();
        int stackId = Integer.valueOf(stackIdStr);
        String weightStr = nextArgRequired();
        float weight = Float.valueOf(weightStr);

        try {
            mAm.resizeStack(stackId, weight);
        } catch (RemoteException e) {
        }
    }

    private void runStackDump() throws Exception {
        try {
            List<ActivityManager.StackInfo> stacks = mAm.getStacks();
+9 −7
Original line number Diff line number Diff line
@@ -6326,6 +6326,10 @@ public final class ActivityManagerService extends ActivityManagerNative
    @Override
    public void moveTaskToStack(int taskId, int stackId, boolean toTop) {
        if (stackId == HOME_STACK_ID) {
            Slog.e(TAG, "moveTaskToStack: Attempt to move task " + taskId + " to home stack",
                    new RuntimeException("here").fillInStackTrace());
        }
        synchronized (this) {
            mWindowManager.moveTaskToStack(taskId, stackId, toTop);
            mStackSupervisor.moveTaskToStack(taskId, stackId, toTop);
@@ -6388,8 +6392,8 @@ public final class ActivityManagerService extends ActivityManagerNative
    final void sendPendingThumbnail(ActivityRecord r, IBinder token,
            Bitmap thumbnail, CharSequence description, boolean always) {
        TaskRecord task = null;
        ArrayList receivers = null;
        TaskRecord task;
        ArrayList<PendingThumbnailsRecord> receivers = null;
        //System.out.println("Send pending thumbnail: " + r);
@@ -6415,12 +6419,11 @@ public final class ActivityManagerService extends ActivityManagerNative
            int N = mPendingThumbnails.size();
            int i=0;
            while (i<N) {
                PendingThumbnailsRecord pr =
                    (PendingThumbnailsRecord)mPendingThumbnails.get(i);
                PendingThumbnailsRecord pr = mPendingThumbnails.get(i);
                //System.out.println("Looking in " + pr.pendingRecords);
                if (pr.pendingRecords.remove(r)) {
                    if (receivers == null) {
                        receivers = new ArrayList();
                        receivers = new ArrayList<PendingThumbnailsRecord>();
                    }
                    receivers.add(pr);
                    if (pr.pendingRecords.size() == 0) {
@@ -6438,8 +6441,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            final int N = receivers.size();
            for (int i=0; i<N; i++) {
                try {
                    PendingThumbnailsRecord pr =
                        (PendingThumbnailsRecord)receivers.get(i);
                    PendingThumbnailsRecord pr = receivers.get(i);
                    pr.receiver.newThumbnail(
                        task != null ? task.taskId : -1, thumbnail, description);
                    if (pr.finished) {
+12 −15
Original line number Diff line number Diff line
@@ -305,6 +305,7 @@ public class ActivityStackSupervisor {
            final int nextStackId = mWindowManager.removeStack(stackId);
            // TODO: Perhaps we need to let the ActivityManager determine the next focus...
            if (mFocusedStack.mStackId == stackId) {
                // If this is the last app stack, set mFocusedStack to null.
                mFocusedStack = nextStackId == HOME_STACK_ID ? null : getStack(nextStackId);
            }
        }
@@ -455,19 +456,16 @@ public class ActivityStackSupervisor {
    }

    ActivityRecord topRunningActivityLocked() {
        ActivityRecord r = null;
        if (mFocusedStack != null) {
            r = mFocusedStack.topRunningActivityLocked(null);
        final ActivityStack focusedStack = getFocusedStack();
        ActivityRecord r = focusedStack.topRunningActivityLocked(null);
        if (r != null) {
            return r;
        }
        }

        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
            final ActivityStack stack = mStacks.get(stackNdx);
            if (stack.mCurrentUser != mCurrentUser) {
                continue;
            }
            if (stack != mFocusedStack && isFrontStack(stack)) {
            if (stack.mCurrentUser == mCurrentUser && stack != focusedStack &&
                    isFrontStack(stack)) {
                r = stack.topRunningActivityLocked(null);
                if (r != null) {
                    return r;
@@ -1162,7 +1160,7 @@ public class ActivityStackSupervisor {
    }

    ActivityStack getCorrectStack(ActivityRecord r) {
        if (!r.isHomeActivity) {
        if (!r.isHomeActivity || (r.task != null && !r.task.isHomeTask())) {
            int stackNdx;
            for (stackNdx = mStacks.size() - 1; stackNdx > 0; --stackNdx) {
                if (mStacks.get(stackNdx).mCurrentUser == mCurrentUser) {
@@ -1184,7 +1182,7 @@ public class ActivityStackSupervisor {
        if (r == null) {
            return;
        }
        if (r.isHomeActivity) {
        if (r.isHomeActivity || (r.task != null && r.task.isHomeTask())) {
            if (mStackState != STACK_STATE_HOME_IN_FRONT) {
                mStackState = STACK_STATE_HOME_TO_FRONT;
            }
@@ -1598,10 +1596,9 @@ public class ActivityStackSupervisor {
            // This not being started from an existing activity, and not part
            // of a new task...  just put it in the top task, though these days
            // this case should never happen.
            ActivityStack lastStack = getLastStack();
            targetStack = lastStack != null ? lastStack : mHomeStack;
            targetStack = getCorrectStack(r);
            moveHomeStack(targetStack.isHomeStack());
            ActivityRecord prev = lastStack == null ? null : targetStack.topActivity();
            ActivityRecord prev = targetStack.topActivity();
            r.setTask(prev != null ? prev.task
                    : targetStack.createTaskRecord(getNextTaskId(), r.info, intent, true),
                    null, true);
+17 −18
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ class TaskRecord extends ThumbnailHolder {
    /** Current stack */
    ActivityStack stack;

    private boolean mHomeTask;

    TaskRecord(int _taskId, ActivityInfo info, Intent _intent, ActivityStack _stack) {
        taskId = _taskId;
        affinity = info.taskAffinity;
@@ -153,19 +155,16 @@ class TaskRecord extends ThumbnailHolder {
    }

    void addActivityToTop(ActivityRecord r) {
        // Remove r first, and if it wasn't already in the list and it's fullscreen, count it.
        if (!mActivities.remove(r) && r.fullscreen) {
            // Was not previously in list.
            numFullscreen++;
        }
        mActivities.add(r);
        addActivityAtIndex(mActivities.size(), r);
    }

    void addActivityAtIndex(int index, ActivityRecord r) {
        // Remove r first, and if it wasn't already in the list and it's fullscreen, count it.
        if (!mActivities.remove(r) && r.fullscreen) {
            // Was not previously in list.
            numFullscreen++;
        }
        mHomeTask = r.isHomeActivity;
        mActivities.add(index, r);
    }

@@ -183,10 +182,9 @@ class TaskRecord extends ThumbnailHolder {
     * task starting at a specified index.
     */
    final void performClearTaskAtIndexLocked(int activityNdx) {
        final ArrayList<ActivityRecord> activities = mActivities;
        int numActivities = activities.size();
        int numActivities = mActivities.size();
        for ( ; activityNdx < numActivities; ++activityNdx) {
            final ActivityRecord r = activities.get(activityNdx);
            final ActivityRecord r = mActivities.get(activityNdx);
            if (r.finishing) {
                continue;
            }
@@ -216,19 +214,18 @@ class TaskRecord extends ThumbnailHolder {
     * or null if none was found.
     */
    final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
        final ArrayList<ActivityRecord> activities = mActivities;
        int numActivities = activities.size();
        int numActivities = mActivities.size();
        for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
            ActivityRecord r = activities.get(activityNdx);
            ActivityRecord r = mActivities.get(activityNdx);
            if (r.finishing) {
                continue;
            }
            if (r.realActivity.equals(newR.realActivity)) {
                // Here it is!  Now finish everything in front...
                ActivityRecord ret = r;
                final ActivityRecord ret = r;

                for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
                    r = activities.get(activityNdx);
                    r = mActivities.get(activityNdx);
                    if (r.finishing) {
                        continue;
                    }
@@ -249,10 +246,8 @@ class TaskRecord extends ThumbnailHolder {
                if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
                        && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
                    if (!ret.finishing) {
                        if (activities.contains(ret)) {
                        stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null,
                                "clear", false);
                        }
                        return null;
                    }
                }
@@ -321,6 +316,10 @@ class TaskRecord extends ThumbnailHolder {
        return subtask.activity;
    }

    boolean isHomeTask() {
        return mHomeTask;
    }

    public TaskAccessInfo getTaskAccessInfoLocked(boolean inclThumbs) {
        final TaskAccessInfo thumbs = new TaskAccessInfo();
        // How many different sub-thumbnails?