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

Commit 64258367 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Removed references to ActivityRecord and TaskRecord in AM (24/n)

Once ActivityRecord and TaskRecord are moved to the WM package they
can no longer be accessed by classes in the AM package. This CL fixes
up some of the access before the move.
- Moved activity relaunch reasons to ActivityTaskManagerService and made
them public to allow access from the AM side in the future.
- Use task id to reference task in AppErrorDialog and AppErrors vs. the
TaskRecord object.
- Also, removed out-of-date code that tries to re-start a task if it
can't start in through recents. The reent start also looks for the task
in the stacks now so if the task exists it will be started through that
channel and we no longer need this fallback.

Test: Existing test pass
Bug: 80414790
Change-Id: I8df76a4f107fa526d726d7522eb5fcee6958b45d
parent 51cc98ad
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST;
import static android.Manifest.permission.FILTER_EVENTS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS;
import static android.Manifest.permission.REMOVE_TASKS;
import static android.app.ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
import static android.app.ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
@@ -29,9 +28,7 @@ import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY;
import static android.app.ActivityManagerInternal.ALLOW_NON_FULL;
import static android.app.ActivityThread.PROC_START_SEQ_IDENT;
import static android.app.AppOpsManager.OP_NONE;
import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.pm.ApplicationInfo.HIDDEN_API_ENFORCEMENT_DEFAULT;
import static android.content.pm.PackageManager.GET_PROVIDERS;
import static android.content.pm.PackageManager.MATCH_ANY_USER;
@@ -150,6 +147,8 @@ import static com.android.server.am.ActivityTaskManagerService.DUMP_RECENTS_CMD;
import static com.android.server.am.ActivityTaskManagerService.DUMP_RECENTS_SHORT_CMD;
import static com.android.server.am.ActivityTaskManagerService.DUMP_STARTER_CMD;
import static com.android.server.am.ActivityTaskManagerService.KEY_DISPATCHING_TIMEOUT_MS;
import static com.android.server.am.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
import static com.android.server.am.ActivityTaskManagerService.relaunchReasonToString;
import static com.android.server.am.MemoryStatUtil.hasMemcg;
import static com.android.server.am.MemoryStatUtil.readCmdlineFromProcfs;
import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem;
@@ -166,7 +165,6 @@ import android.app.ActivityManager.RunningTaskInfo;
import android.app.ActivityManager.StackInfo;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerProto;
import android.app.ActivityOptions;
import android.app.ActivityThread;
import android.app.AppGlobals;
import android.app.AppOpsManager;
@@ -369,18 +367,15 @@ import dalvik.system.VMRuntime;
import libcore.util.EmptyArray;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -9783,9 +9778,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                        : StatsLog.APP_CRASH_OCCURRED__FOREGROUND_STATE__UNKNOWN
        );
        final int relaunchReason = r == null ? ActivityRecord.RELAUNCH_REASON_NONE
        final int relaunchReason = r == null ? RELAUNCH_REASON_NONE
                        : r.getWindowProcessController().computeRelaunchReason();
        final String relaunchReasonString = ActivityRecord.relaunchReasonToString(relaunchReason);
        final String relaunchReasonString = relaunchReasonToString(relaunchReason);
        if (crashInfo.crashTag == null) {
            crashInfo.crashTag = relaunchReasonString;
        } else {
+3 −17
Original line number Diff line number Diff line
@@ -114,6 +114,9 @@ import static com.android.server.am.ActivityStack.LAUNCH_TICK;
import static com.android.server.am.ActivityStack.LAUNCH_TICK_MSG;
import static com.android.server.am.ActivityStack.PAUSE_TIMEOUT_MSG;
import static com.android.server.am.ActivityStack.STOP_TIMEOUT_MSG;
import static com.android.server.am.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE;
import static com.android.server.am.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
import static com.android.server.am.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
import static com.android.server.am.EventLogTags.AM_RELAUNCH_ACTIVITY;
import static com.android.server.am.EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY;
import static com.android.server.am.TaskPersister.DEBUG;
@@ -338,12 +341,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
    int mStartingWindowState = STARTING_WINDOW_NOT_SHOWN;
    boolean mTaskOverlay = false; // Task is always on-top of other activities in the task.

    // This activity is not being relaunched, or being relaunched for a non-resize reason.
    static final int RELAUNCH_REASON_NONE = 0;
    // This activity is being relaunched due to windowing mode change.
    static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1;
    // This activity is being relaunched due to a free-resize operation.
    static final int RELAUNCH_REASON_FREE_RESIZE = 2;
    // Marking the reason why this activity is being relaunched. Mainly used to track that this
    // activity is being relaunched to fulfill a resize request due to compatibility issues, e.g. in
    // pre-NYC apps that don't have a sense of being resized.
@@ -3010,17 +3007,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        mWindowContainerController.registerRemoteAnimations(definition);
    }

    static String relaunchReasonToString(int relaunchReason) {
        switch (relaunchReason) {
            case RELAUNCH_REASON_WINDOWING_MODE_RESIZE:
                return "window_resize";
            case RELAUNCH_REASON_FREE_RESIZE:
                return "free_resize";
            default:
                return null;
        }
    }

    @Override
    public String toString() {
        if (stringName != null) {
+2 −2
Original line number Diff line number Diff line
@@ -81,8 +81,8 @@ import static com.android.server.am.ActivityTaskManagerDebugConfig.POSTFIX_USER_
import static com.android.server.am.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY;
import static com.android.server.am.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.am.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ActivityRecord.RELAUNCH_REASON_FREE_RESIZE;
import static com.android.server.am.ActivityRecord.RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
import static com.android.server.am.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE;
import static com.android.server.am.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
import static com.android.server.am.ActivityStack.ActivityState.FINISHING;
+4 −4
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ import static com.android.server.am.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.am.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ActivityTaskManagerService.ANIMATE;
import static com.android.server.am.ActivityTaskManagerService.H.FIRST_SUPERVISOR_STACK_MSG;
import static com.android.server.am.ActivityRecord.RELAUNCH_REASON_NONE;
import static com.android.server.am.ActivityTaskManagerService.RELAUNCH_REASON_NONE;
import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
@@ -2258,9 +2258,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
     * Finish the topmost activities in all stacks that belong to the crashed app.
     * @param app The app that crashed.
     * @param reason Reason to perform this action.
     * @return The task that was finished in this stack, {@code null} if haven't found any.
     * @return The task id that was finished in this stack, or INVALID_TASK_ID if none was finished.
     */
    TaskRecord finishTopCrashedActivitiesLocked(WindowProcessController app, String reason) {
    int finishTopCrashedActivitiesLocked(WindowProcessController app, String reason) {
        TaskRecord finishedTask = null;
        ActivityStack focusedStack = getTopDisplayFocusedStack();
        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
@@ -2275,7 +2275,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
                }
            }
        }
        return finishedTask;
        return finishedTask != null ? finishedTask.taskId : INVALID_TASK_ID;
    }

    void finishVoiceTask(IVoiceInteractionSession session) {
+27 −2
Original line number Diff line number Diff line
@@ -277,7 +277,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;

/**
 * System service for managing activities and their containers (task, stacks, displays,... ).
@@ -314,7 +313,15 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    public static final String DUMP_RECENTS_CMD = "recents" ;
    public static final String DUMP_RECENTS_SHORT_CMD = "r" ;

    /** This activity is not being relaunched, or being relaunched for a non-resize reason. */
    public static final int RELAUNCH_REASON_NONE = 0;
    /** This activity is being relaunched due to windowing mode change. */
    public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1;
    /** This activity is being relaunched due to a free-resize operation. */
    public static final int RELAUNCH_REASON_FREE_RESIZE = 2;

    Context mContext;

    /**
     * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can
     * change at runtime. Use mContext for non-UI purposes.
@@ -1362,7 +1369,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                        Slog.i(TAG, "Removing task failed to finish activity");
                    }
                    // Explicitly dismissing the activity so reset its relaunch flag.
                    r.mRelaunchReason = ActivityRecord.RELAUNCH_REASON_NONE;
                    r.mRelaunchReason = RELAUNCH_REASON_NONE;
                } else {
                    res = tr.getStack().requestFinishActivityLocked(token, resultCode,
                            resultData, "app-request", true);
@@ -4325,6 +4332,17 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    public static String relaunchReasonToString(int relaunchReason) {
        switch (relaunchReason) {
            case RELAUNCH_REASON_WINDOWING_MODE_RESIZE:
                return "window_resize";
            case RELAUNCH_REASON_FREE_RESIZE:
                return "free_resize";
            default:
                return null;
        }
    }

    ActivityStack getTopDisplayFocusedStack() {
        return mStackSupervisor.getTopDisplayFocusedStack();
    }
@@ -6642,5 +6660,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                mStackSupervisor.handleAppCrashLocked(wpc);
            }
        }

        @Override
        public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) {
            synchronized (mGlobalLock) {
                return mStackSupervisor.finishTopCrashedActivitiesLocked(crashedApp, reason);
            }
        }
    }
}
Loading