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

Commit b1fd65c0 authored by Craig Mautner's avatar Craig Mautner
Browse files

Migrate AppWindowToken lists into DisplayContent.

In preparation for converting ActivityManager control to a task-based
interface the AppWindowTokens are being stored per-display.

Change-Id: Ie5e355219554523f5e56eaef138d382975cf1682
parent 93f770b5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    static final boolean DEBUG_POWER_QUICK = DEBUG_POWER || false;
    static final boolean DEBUG_MU = localLOGV || false;
    static final boolean DEBUG_IMMERSIVE = localLOGV || false;
    static final boolean VALIDATE_TOKENS = false;
    static final boolean VALIDATE_TOKENS = true;
    static final boolean SHOW_ACTIVITY_START_TIME = true;
    
    // Control over CPU and battery monitoring.
+12 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import com.android.internal.app.HeavyWeightSwitcherActivity;
import com.android.internal.os.BatteryStatsImpl;
import com.android.server.am.ActivityManagerService.PendingActivityLaunch;
import com.android.server.am.ActivityRecord.Token;
import com.android.server.wm.AppTransition;

import android.app.Activity;
@@ -157,7 +158,7 @@ final class ActivityStack {
    /**
     * Used for validating app tokens with window manager.
     */
    final ArrayList<IBinder> mValidateAppTokens = new ArrayList<IBinder>();
    final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<TaskGroup>();

    /**
     * List of running activities, sorted by recent usage.
@@ -1959,8 +1960,17 @@ final class ActivityStack {
    final void validateAppTokensLocked() {
        mValidateAppTokens.clear();
        mValidateAppTokens.ensureCapacity(mHistory.size());
        int taskId = Integer.MIN_VALUE;
        TaskGroup task = null;
        for (int i=0; i<mHistory.size(); i++) {
            mValidateAppTokens.add(mHistory.get(i).appToken);
            final ActivityRecord r = mHistory.get(i);
            if (taskId != r.task.taskId) {
                taskId = r.task.taskId;
                task = new TaskGroup();
                task.taskId = taskId;
                mValidateAppTokens.add(task);
            }
            task.tokens.add(r.appToken);
        }
        mService.mWindowManager.validateAppTokens(mValidateAppTokens);
    }
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.am;

import android.view.IApplicationToken;

import java.util.ArrayList;

public class TaskGroup {
    public int taskId = -1;
    public ArrayList<IApplicationToken> tokens = new ArrayList<IApplicationToken>();
}
+4 −0
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@ import android.view.View;
import android.view.WindowManager;

import java.io.PrintWriter;
import java.util.ArrayList;

class AppTokenList extends ArrayList<AppWindowToken> {
}

/**
 * Version of WindowToken that is specifically for a particular application (or
+141 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.wm;

import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayInfo;

@@ -33,6 +34,7 @@ class DisplayContentList extends ArrayList<DisplayContent> {
 * WindowManagerService.mWindowMap.
 */
class DisplayContent {
//    private final static String TAG = "DisplayContent";

    /** Unique identifier of this stack. */
    private final int mDisplayId;
@@ -66,6 +68,38 @@ class DisplayContent {
    int pendingLayoutChanges;
    final boolean isDefaultDisplay;

    /**
     * List controlling the ordering of windows in different applications which must
     * be kept in sync with ActivityManager.
     */
    final AppTokenList mAppTokens = new AppTokenList();

    /**
     * AppWindowTokens in the Z order they were in at the start of an animation. Between
     * animations this list is maintained in the exact order of mAppTokens. If tokens
     * are added to mAppTokens during an animation an attempt is made to insert them at the same
     * logical location in this list. Note that this list is always in sync with mWindows.
     */
    AppTokenList mAnimatingAppTokens = new AppTokenList();

    /**
     * Window tokens that are in the process of exiting, but still
     * on screen for animations.
     */
    final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();

    /**
     * Application tokens that are in the process of exiting, but still
     * on screen for animations.
     */
    final AppTokenList mExitingAppTokens = new AppTokenList();

    /**
     * Sorted most recent at top, oldest at [0].
     */
//    ArrayList<TaskList> mTaskLists = new ArrayList<TaskList>();
    SparseArray<TaskList> mTaskIdToTaskList = new SparseArray<TaskList>();

    /**
     * @param display May not be null.
     */
@@ -96,6 +130,71 @@ class DisplayContent {
        mDisplay.getDisplayInfo(mDisplayInfo);
    }

    /**
     *  Find the location to insert a new AppWindowToken into the window-ordered app token list.
     * @param addPos The location the token was inserted into in mAppTokens.
     * @param atoken The token to insert.
     */
    void addAppToken(final int addPos, final AppWindowToken atoken) {
        mAppTokens.add(addPos, atoken);

        if (addPos == 0 || addPos == mAnimatingAppTokens.size()) {
            // It was inserted into the beginning or end of mAppTokens. Honor that.
            mAnimatingAppTokens.add(addPos, atoken);
        } else {
            // Find the item immediately above the mAppTokens insertion point and put the token
            // immediately below that one in mAnimatingAppTokens.
            final AppWindowToken aboveAnchor = mAppTokens.get(addPos + 1);
            mAnimatingAppTokens.add(mAnimatingAppTokens.indexOf(aboveAnchor), atoken);
        }

        TaskList task = mTaskIdToTaskList.get(atoken.groupId);
        if (task == null) {
            mTaskIdToTaskList.put(atoken.groupId, new TaskList(atoken));
        }
    }

    void removeAppToken(final AppWindowToken wtoken) {
        mAppTokens.remove(wtoken);
        mAnimatingAppTokens.remove(wtoken);
        final int taskId = wtoken.groupId;
        final TaskList task = mTaskIdToTaskList.get(taskId);
        if (task != null) {
            AppTokenList appTokens = task.mAppTokens;
            appTokens.remove(wtoken);
            if (appTokens.size() == 0) {
                mTaskIdToTaskList.delete(taskId);
            }
        }
    }

    void refillAnimatingAppTokens() {
        mAnimatingAppTokens.clear();
        mAnimatingAppTokens.addAll(mAppTokens);
    }

    void setAppTaskId(AppWindowToken wtoken, int newTaskId) {
        final int taskId = wtoken.groupId;
        TaskList task = mTaskIdToTaskList.get(taskId);
        if (task != null) {
            AppTokenList appTokens = task.mAppTokens;
            appTokens.remove(wtoken);
            if (appTokens.size() == 0) {
                mTaskIdToTaskList.delete(taskId);
            }
        }

        task = mTaskIdToTaskList.get(newTaskId);
        if (task == null) {
            task = new TaskList(wtoken);
            mTaskIdToTaskList.put(newTaskId, task);
        } else {
            task.mAppTokens.add(wtoken);
        }

        wtoken.groupId = newTaskId;
    }

    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
        final String subPrefix = "  " + prefix;
@@ -119,7 +218,48 @@ class DisplayContent {
            pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
            pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
            pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
        pw.print(subPrefix); pw.print("layoutNeeded="); pw.print(layoutNeeded);
            if (mAppTokens.size() > 0) {
                pw.println();
                pw.println("  Application tokens in Z order:");
                for (int i=mAppTokens.size()-1; i>=0; i--) {
                    pw.print("  App #"); pw.print(i);
                            pw.print(' '); pw.print(mAppTokens.get(i)); pw.println(":");
                    mAppTokens.get(i).dump(pw, "    ");
                }
            }
            if (mExitingTokens.size() > 0) {
                pw.println();
                pw.println("  Exiting tokens:");
                for (int i=mExitingTokens.size()-1; i>=0; i--) {
                    WindowToken token = mExitingTokens.get(i);
                    pw.print("  Exiting #"); pw.print(i);
                    pw.print(' '); pw.print(token);
                    pw.println(':');
                    token.dump(pw, "    ");
                }
            }
            if (mExitingAppTokens.size() > 0) {
                pw.println();
                pw.println("  Exiting application tokens:");
                for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
                    WindowToken token = mExitingAppTokens.get(i);
                    pw.print("  Exiting App #"); pw.print(i);
                      pw.print(' '); pw.print(token);
                      pw.println(':');
                      token.dump(pw, "    ");
                }
            }
            if (mTaskIdToTaskList.size() > 0) {
                pw.println();
                for (int i = 0; i < mTaskIdToTaskList.size(); ++i) {
                    pw.print("  TaskList #"); pw.print(i);
                      pw.print(" taskId="); pw.println(mTaskIdToTaskList.keyAt(i));
                    pw.print("    mAppTokens=");
                      pw.println(mTaskIdToTaskList.valueAt(i).mAppTokens);
                    pw.println();
                }
            }
        pw.print(subPrefix); pw.print("layoutNeeded="); pw.println(layoutNeeded);
        pw.println();
    }
}
Loading