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

Commit 2219a1ba authored by Craig Mautner's avatar Craig Mautner
Browse files

Modify primary ActivityStack accessing.

- Move mHomeStack to ActivityStackSupervisor.
- Move mMainStack to ActivityStackSupervisor.

Change-Id: I43522c9505f066b379ea172dd63663e78a0feece
parent d5444c66
Loading
Loading
Loading
Loading
+20 −24
Original line number Diff line number Diff line
@@ -286,7 +286,6 @@ public final class ActivityManagerService extends ActivityManagerNative
    /** The current stack for manipulating */
    public ActivityStack mFocusedStack;
    public ActivityStack mHomeStack;
    private final boolean mHeadless;
@@ -317,7 +316,6 @@ public final class ActivityManagerService extends ActivityManagerNative
    final ArrayList<PendingActivityLaunch> mPendingActivityLaunches
            = new ArrayList<PendingActivityLaunch>();
    BroadcastQueue mFgBroadcastQueue;
    BroadcastQueue mBgBroadcastQueue;
    // Convenient for easy iteration over the queues. Foreground is first
@@ -1486,9 +1484,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        m.mFactoryTest = factoryTest;
        m.mLooper = thr.mLooper;
        m.mStackSupervisor = new ActivityStackSupervisor(m);
        m.mHomeStack = m.mFocusedStack = new ActivityStack(m, context, true, thr.mLooper,
                HOME_ACTIVITY_STACK, m.mStackSupervisor);
        m.mStackSupervisor = new ActivityStackSupervisor(m, context, thr.mLooper);
        m.mStackSupervisor.init();
        m.mStacks.add(m.mFocusedStack);
        m.mBatteryStatsService.publish(context);
@@ -2322,8 +2319,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    aInfo.applicationInfo.uid);
            if (app == null || app.instrumentationClass == null) {
                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                mHomeStack.startActivityLocked(null, intent, null, aInfo,
                        null, null, 0, 0, 0, null, 0, null, false, null);
                mStackSupervisor.startHomeActivity(intent, aInfo);
            }
        }
@@ -6147,7 +6143,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    break;
                }
            }
            mStacks.add(new ActivityStack(this, mContext, false, mLooper, mLastStackId,
            mStacks.add(new ActivityStack(this, mContext, mLooper, mLastStackId,
                    mStackSupervisor));
            mWindowManager.createStack(mLastStackId, position, relativeStackId, weight);
            return mLastStackId;
+21 −24
Original line number Diff line number Diff line
@@ -152,7 +152,6 @@ final class ActivityStack {
    }

    final ActivityManagerService mService;
    final boolean mMainStack;

    final Context mContext;

@@ -450,12 +449,11 @@ final class ActivityStack {
        return count;
    }

    ActivityStack(ActivityManagerService service, Context context, boolean mainStack, Looper looper,
            int stackId, ActivityStackSupervisor supervisor) {
    ActivityStack(ActivityManagerService service, Context context, Looper looper, int stackId,
            ActivityStackSupervisor supervisor) {
        mHandler = new ActivityStackHandler(looper);
        mService = service;
        mContext = context;
        mMainStack = mainStack;
        PowerManager pm =
            (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        mGoingToSleep = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep");
@@ -836,7 +834,7 @@ final class ActivityStack {
        // launching the initial activity (that is, home), so that it can have
        // a chance to initialize itself while in the background, making the
        // switch back to it faster and look better.
        if (mMainStack) {
        if (mStackSupervisor.isMainStack(this)) {
            mService.startSetupActivityLocked();
        }

@@ -1035,7 +1033,7 @@ final class ActivityStack {
                        prev.shortComponentName);
                prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing,
                        userLeaving, prev.configChangeFlags);
                if (mMainStack) {
                if (mStackSupervisor.isMainStack(this)) {
                    mService.updateUsageStats(prev, false);
                }
            } catch (Exception e) {
@@ -1273,11 +1271,11 @@ final class ActivityStack {
            mHandler.sendMessage(msg);
        }

        if (mMainStack) {
        if (mStackSupervisor.isMainStack(this)) {
            mService.reportResumedActivityLocked(next);
        }

        if (mMainStack) {
        if (mStackSupervisor.isMainStack(this)) {
            mService.setFocusedActivityLocked(next);
        }
        next.resumeKeyDispatchingLocked();
@@ -1462,7 +1460,7 @@ final class ActivityStack {
        if (next == null) {
            // There are no more activities!  Let's just start up the
            // Launcher...
            if (mMainStack) {
            if (mStackSupervisor.isMainStack(this)) {
                ActivityOptions.abort(options);
                return mService.startHomeActivityLocked(mCurrentUser);
            }
@@ -1703,7 +1701,7 @@ final class ActivityStack {
            // Have the window manager re-evaluate the orientation of
            // the screen based on the new activity order.
            boolean updated = false;
            if (mMainStack) {
            if (mStackSupervisor.isMainStack(this)) {
                synchronized (mService) {
                    Configuration config = mService.mWindowManager.updateOrientationFromAppTokens(
                            mService.mConfiguration,
@@ -1728,7 +1726,7 @@ final class ActivityStack {
                    // Do over!
                    mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG);
                }
                if (mMainStack) {
                if (mStackSupervisor.isMainStack(this)) {
                    mService.setFocusedActivityLocked(next);
                }
                ensureActivitiesVisibleLocked(null, 0);
@@ -1776,7 +1774,7 @@ final class ActivityStack {
                if (!next.hasBeenLaunched) {
                    next.hasBeenLaunched = true;
                } else {
                    if (SHOW_APP_STARTING_PREVIEW && mMainStack) {
                    if (SHOW_APP_STARTING_PREVIEW && mStackSupervisor.isMainStack(this)) {
                        mService.mWindowManager.setAppStartingWindow(
                                next.appToken, next.packageName, next.theme,
                                mService.compatibilityInfoForPackageLocked(
@@ -2549,7 +2547,7 @@ final class ActivityStack {
            throw new SecurityException(msg);
        }

        if (mMainStack) {
        if (mStackSupervisor.isMainStack(this)) {
            if (mService.mController != null) {
                boolean abort = false;
                try {
@@ -2584,7 +2582,7 @@ final class ActivityStack {
            outActivity[0] = r;
        }

        if (mMainStack) {
        if (mStackSupervisor.isMainStack(this)) {
            if (mResumedActivity == null
                    || mResumedActivity.info.applicationInfo.uid != callingUid) {
                if (!mService.checkAppSwitchAllowedLocked(callingPid, callingUid, "Activity start")) {
@@ -3086,7 +3084,7 @@ final class ActivityStack {

            final long origId = Binder.clearCallingIdentity();

            if (mMainStack && aInfo != null &&
            if (mStackSupervisor.isMainStack(this) && aInfo != null &&
                    (aInfo.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
                // This may be a heavy-weight process!  Check to see if we already
                // have another, different heavy-weight process running.
@@ -3160,7 +3158,7 @@ final class ActivityStack {
                    aInfo, resultTo, resultWho, requestCode, callingPid, callingUid,
                    callingPackage, startFlags, options, componentSpecified, null);

            if (mConfigWillChange && mMainStack) {
            if (mConfigWillChange && mStackSupervisor.isMainStack(this)) {
                // If the caller also wants to switch to a new configuration,
                // do so now.  This allows a clean switch, as we are waiting
                // for the current activity to pause (so we will not destroy
@@ -3259,7 +3257,7 @@ final class ActivityStack {
                    // TODO: New, check if this is correct
                    aInfo = mService.getActivityInfoForUser(aInfo, userId);

                    if (mMainStack && aInfo != null && (aInfo.applicationInfo.flags
                    if (mStackSupervisor.isMainStack(this) && aInfo != null && (aInfo.applicationInfo.flags
                            & ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
                        throw new IllegalArgumentException(
                                "FLAG_CANT_SAVE_STATE not supported here");
@@ -3361,7 +3359,7 @@ final class ActivityStack {
        }

        if (r.app != null && r.app.thread != null) {
            if (mMainStack) {
            if (mStackSupervisor.isMainStack(this)) {
                if (mService.mFocusedActivity == r) {
                    mService.setFocusedActivityLocked(topRunningActivityLocked(null));
                }
@@ -3512,13 +3510,12 @@ final class ActivityStack {
                ensureActivitiesVisibleLocked(null, 0);

                //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout);
                if (mMainStack) {
                if (mStackSupervisor.isMainStack(this)) {
                    if (!mService.mBooted) {
                        mService.mBooted = true;
                        enableScreen = true;
                    }
                }
                
            } else if (fromTimeout) {
                reportActivityLaunchedLocked(fromTimeout, null, -1, -1);
            }
@@ -3535,7 +3532,7 @@ final class ActivityStack {
                mCancelledThumbnails.clear();
            }

            if (mMainStack) {
            if (mStackSupervisor.isMainStack(this)) {
                booting = mService.mBooting;
                mService.mBooting = false;
            }
@@ -3763,7 +3760,7 @@ final class ActivityStack {
        }

        r.pauseKeyDispatchingLocked();
        if (mMainStack) {
        if (mStackSupervisor.isMainStack(this)) {
            if (mService.mFocusedActivity == r) {
                mService.setFocusedActivityLocked(topRunningActivityLocked(null));
            }
@@ -4429,7 +4426,7 @@ final class ActivityStack {
        // If we have a watcher, preflight the move before committing to it.  First check
        // for *other* available tasks, but if none are available, then try again allowing the
        // current task to be selected.
        if (mMainStack && mService.mController != null) {
        if (mStackSupervisor.isMainStack(this) && mService.mController != null) {
            ActivityRecord next = topRunningActivityLocked(null, task);
            if (next == null) {
                next = topRunningActivityLocked(null, 0);
@@ -4770,7 +4767,7 @@ final class ActivityStack {
        if (andResume) {
            r.results = null;
            r.newIntents = null;
            if (mMainStack) {
            if (mStackSupervisor.isMainStack(this)) {
                mService.reportResumedActivityLocked(r);
            }
            r.state = ActivityState.RESUMED;
+36 −1
Original line number Diff line number Diff line
@@ -16,17 +16,39 @@

package com.android.server.am;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Looper;

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

public class ActivityStackSupervisor {
    public static final int HOME_STACK_ID = 0;

    final ActivityManagerService mService;
    final Context mContext;
    final Looper mLooper;

    /** Dismiss the keyguard after the next activity is displayed? */
    private boolean mDismissKeyguardOnNextActivity = false;

    public ActivityStackSupervisor(ActivityManagerService service) {
    private ActivityStack mHomeStack;
    private ActivityStack mMainStack;
    private ArrayList<ActivityStack> mStacks = new ArrayList<ActivityStack>();

    public ActivityStackSupervisor(ActivityManagerService service, Context context,
            Looper looper) {
        mService = service;
        mContext = context;
        mLooper = looper;
    }

    void init() {
        mHomeStack = new ActivityStack(mService, mContext, mLooper, HOME_STACK_ID, this);
        setMainStack(mHomeStack);
        mService.mFocusedStack = mHomeStack;
    }

    void dismissKeyguard() {
@@ -36,10 +58,23 @@ public class ActivityStackSupervisor {
        }
    }

    boolean isMainStack(ActivityStack stack) {
        return stack == mMainStack;
    }

    void setMainStack(ActivityStack stack) {
        mMainStack = stack;
    }

    void setDismissKeyguard(boolean dismiss) {
        mDismissKeyguardOnNextActivity = dismiss;
    }

    void startHomeActivity(Intent intent, ActivityInfo aInfo) {
        mHomeStack.startActivityLocked(null, intent, null, aInfo, null, null, 0, 0, 0, null, 0,
                null, false, null);
    }

    public void dump(PrintWriter pw, String prefix) {
        pw.print(prefix); pw.print("mDismissKeyguardOnNextActivity:");
                pw.println(mDismissKeyguardOnNextActivity);