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

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

Refactor removeApp and removeTask for last removals.

Move app token removal to the AppWindowToken class so cleanup can
be done locally. Move task removal to the Task class so cleanup can
be done locally. Call task removal when the last app is removed.
Merge actions done prior to method calls into methods.

Fixes bug 18088522 item #12.

Change-Id: I5ce85d2bb309ceb82bd7404e27a56a7c31cd7359
parent d7211ef8
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.graphics.Canvas;
import android.hardware.display.DisplayManagerGlobal;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.Proxy;
import android.net.ProxyInfo;
@@ -87,8 +86,6 @@ import android.util.Slog;
import android.util.SuperNotCalledException;
import android.view.Display;
import android.view.HardwareRenderer;
import android.view.IWindowManager;
import android.view.IWindowSessionCallback;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewManager;
@@ -165,8 +162,8 @@ public final class ActivityThread {
    private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
    private static final Pattern PATTERN_SEMICOLON = Pattern.compile(";");
    private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003;
    private static final int LOG_ON_PAUSE_CALLED = 30021;
    private static final int LOG_ON_RESUME_CALLED = 30022;
    private static final int LOG_AM_ON_PAUSE_CALLED = 30021;
    private static final int LOG_AM_ON_RESUME_CALLED = 30022;

    private ContextImpl mSystemContext;

@@ -2993,7 +2990,7 @@ public final class ActivityThread {
                }
                r.activity.performResume();

                EventLog.writeEvent(LOG_ON_RESUME_CALLED,
                EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED,
                        UserHandle.myUserId(), r.activity.getComponentName().getClassName());

                r.paused = false;
@@ -3263,7 +3260,7 @@ public final class ActivityThread {
            // Now we are idle.
            r.activity.mCalled = false;
            mInstrumentation.callActivityOnPause(r.activity);
            EventLog.writeEvent(LOG_ON_PAUSE_CALLED, UserHandle.myUserId(),
            EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(),
                    r.activity.getComponentName().getClassName());
            if (!r.activity.mCalled) {
                throw new SuperNotCalledException(
@@ -3660,7 +3657,7 @@ public final class ActivityThread {
                try {
                    r.activity.mCalled = false;
                    mInstrumentation.callActivityOnPause(r.activity);
                    EventLog.writeEvent(LOG_ON_PAUSE_CALLED, UserHandle.myUserId(),
                    EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(),
                            r.activity.getComponentName().getClassName());
                    if (!r.activity.mCalled) {
                        throw new SuperNotCalledException(
+17 −1
Original line number Diff line number Diff line
@@ -252,6 +252,20 @@ class AppWindowToken extends WindowToken {
        return false;
    }

    void removeAppFromTaskLocked() {
        mIsExiting = false;
        removeAllWindows();

        final Task task = service.mTaskIdToTask.get(groupId);
        if (task != null) {
            if (!task.removeAppToken(this)) {
                Slog.e(WindowManagerService.TAG, "removeAppFromTaskLocked: token=" + this
                        + " not found.");
            }
            task.mStack.mExitingAppTokens.remove(this);
        }
    }

    @Override
    void removeAllWindows() {
        for (int winNdx = allAppWindows.size() - 1; winNdx >= 0;
@@ -266,8 +280,10 @@ class AppWindowToken extends WindowToken {
                Slog.w(WindowManagerService.TAG, "removeAllWindows: removing win=" + win);
            }

            win.mService.removeWindowLocked(win.mSession, win);
            service.removeWindowLocked(win.mSession, win);
        }
        allAppWindows.clear();
        windows.clear();
    }

    @Override
+1 −7
Original line number Diff line number Diff line
@@ -329,15 +329,9 @@ class DisplayContent {
                    for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
                        AppWindowToken wtoken = tokens.get(tokenNdx);
                        if (wtoken.mIsExiting) {
                            stack.mExitingAppTokens.remove(wtoken);
                            wtoken.mIsExiting = false;
                            mService.removeAppFromTaskLocked(wtoken);
                            wtoken.removeAppFromTaskLocked();
                        }
                    }
                    if (task.mDeferRemoval) {
                        task.mDeferRemoval = false;
                        mService.removeTaskLocked(task);
                    }
                }
            }
        }
+21 −1
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
package com.android.server.wm;

import static com.android.server.wm.WindowManagerService.TAG;
import static com.android.server.wm.WindowManagerService.DEBUG_STACK;

import android.util.EventLog;
import android.util.Slog;
import com.android.server.EventLogTags;

class Task {
    TaskStack mStack;
@@ -27,12 +29,14 @@ class Task {
    final int taskId;
    final int mUserId;
    boolean mDeferRemoval = false;
    final WindowManagerService mService;

    Task(AppWindowToken wtoken, TaskStack stack, int userId) {
    Task(AppWindowToken wtoken, TaskStack stack, int userId, WindowManagerService service) {
        taskId = wtoken.groupId;
        mAppTokens.add(wtoken);
        mStack = stack;
        mUserId = userId;
        mService = service;
    }

    DisplayContent getDisplayContent() {
@@ -51,11 +55,27 @@ class Task {
        mDeferRemoval = false;
    }

    void removeLocked() {
        if (!mAppTokens.isEmpty() && mStack.isAnimating()) {
            if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + taskId);
            mDeferRemoval = true;
            return;
        }
        if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + taskId);
        EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, taskId, "removeTask");
        mDeferRemoval = false;
        mStack.removeTask(this);
        mService.mTaskIdToTask.delete(taskId);
    }

    boolean removeAppToken(AppWindowToken wtoken) {
        boolean removed = mAppTokens.remove(wtoken);
        if (mAppTokens.size() == 0) {
            EventLog.writeEvent(com.android.server.EventLogTags.WM_TASK_REMOVED, taskId,
                    "removeAppToken: last token");
            if (mDeferRemoval) {
                removeLocked();
            }
        }
        return removed;
    }
+8 −0
Original line number Diff line number Diff line
@@ -224,6 +224,14 @@ public class TaskStack {
            }
            mDisplayContent.layoutNeeded = true;
        }
        final int taskId = task.taskId;
        for (int appNdx = mExitingAppTokens.size() - 1; appNdx >= 0; --appNdx) {
            final AppWindowToken wtoken = mExitingAppTokens.get(appNdx);
            if (wtoken.groupId == taskId) {
                wtoken.mIsExiting = false;
                mExitingAppTokens.remove(appNdx);
            }
        }
    }

    void attachDisplayContent(DisplayContent displayContent) {
Loading