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

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

Introduce ActivityStackSupervisor.

- New coordinating class to juggle multiple ActivityStacks.
- First job: take singleton Keyguard dismiss behavior out of
ActivityStack.

Change-Id: I68e4b44411d3ec9401e86ac23703d6540dcb12e8
parent 97bf092e
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -281,6 +281,9 @@ public final class ActivityManagerService extends ActivityManagerNative
    /** Identifier counter for all ActivityStacks */
    private int mLastStackId = 0;
    /** Run all ActivityStacks through this */
    ActivityStackSupervisor mStackSupervisor;
    /** The current stack for manipulating */
    public ActivityStack mFocusedStack;
    public ActivityStack mHomeStack;
@@ -1483,8 +1486,9 @@ public final class ActivityManagerService extends ActivityManagerNative
        m.mFactoryTest = factoryTest;
        m.mLooper = thr.mLooper;
        m.mHomeStack = m.mFocusedStack
                = new ActivityStack(m, context, true, thr.mLooper, HOME_ACTIVITY_STACK);
        m.mStackSupervisor = new ActivityStackSupervisor(m);
        m.mHomeStack = m.mFocusedStack = new ActivityStack(m, context, true, thr.mLooper,
                HOME_ACTIVITY_STACK, m.mStackSupervisor);
        m.mStacks.add(m.mFocusedStack);
        m.mBatteryStatsService.publish(context);
@@ -1680,6 +1684,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        Watchdog.getInstance().addMonitor(this);
        mProcessStatsThread = new Thread("ProcessStats") {
            @Override
            public void run() {
                while (true) {
                    try {
@@ -2046,13 +2051,13 @@ public final class ActivityManagerService extends ActivityManagerNative
                // If this is a new package in the process, add the package to the list
                app.addPackage(info.packageName);
                return app;
            } else {
            }
            // An application record is attached to a previous process,
            // clean it up now.
            if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG, "App died: " + app);
            handleAppDiedLocked(app, true, true);
        }
        }
        String hostingNameStr = hostingName != null
                ? hostingName.flattenToShortString() : null;
@@ -4432,11 +4437,13 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    @Override
    public void showBootMessage(final CharSequence msg, final boolean always) {
        enforceNotIsolatedCaller("showBootMessage");
        mWindowManager.showBootMessage(msg, always);
    }
    @Override
    public void dismissKeyguardOnNextActivity() {
        enforceNotIsolatedCaller("dismissKeyguardOnNextActivity");
        final long token = Binder.clearCallingIdentity();
@@ -4446,7 +4453,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    mLockScreenShown = false;
                    comeOutOfSleepIfNeededLocked();
                }
                mFocusedStack.dismissKeyguardOnNextActivityLocked();
                mStackSupervisor.setDismissKeyguard(true);
            }
        } finally {
            Binder.restoreCallingIdentity(token);
@@ -6140,7 +6147,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                    break;
                }
            }
            mStacks.add(new ActivityStack(this, mContext, false, mLooper, mLastStackId));
            mStacks.add(new ActivityStack(this, mContext, false, mLooper, mLastStackId,
                    mStackSupervisor));
            mWindowManager.createStack(mLastStackId, position, relativeStackId, weight);
            return mLastStackId;
        }
@@ -9289,11 +9297,11 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (dumpAll) {
                pw.println("  mLastPausedActivity: " + stack.mLastPausedActivity);
                pw.println("  mSleepTimeout: " + stack.mSleepTimeout);
                pw.println("  mDismissKeyguardOnNextActivity: "
                        + stack.mDismissKeyguardOnNextActivity);
            }
        }
        mStackSupervisor.dump(pw, "  ");
        if (mRecentTasks.size() > 0) {
            pw.println();
            pw.println("  Recent tasks:");
+23 −33
Original line number Diff line number Diff line
@@ -285,11 +285,6 @@ final class ActivityStack {
     */
    boolean mSleepTimeout = false;

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

    /**
     * Save the most recent screenshot for reuse. This keeps Recents from taking two identical
     * screenshots, one for the Recents thumbnail and one for the pauseActivity thumbnail.
@@ -310,6 +305,9 @@ final class ActivityStack {

    final int mStackId;

    /** Run all ActivityStacks through this */
    final ActivityStackSupervisor mStackSupervisor;

    static final int SLEEP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG;
    static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1;
    static final int IDLE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2;
@@ -453,7 +451,7 @@ final class ActivityStack {
    }

    ActivityStack(ActivityManagerService service, Context context, boolean mainStack, Looper looper,
            int stackId) {
            int stackId, ActivityStackSupervisor supervisor) {
        mHandler = new ActivityStackHandler(looper);
        mService = service;
        mContext = context;
@@ -464,6 +462,7 @@ final class ActivityStack {
        mLaunchingActivity = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Launch");
        mLaunchingActivity.setReferenceCounted(false);
        mStackId = stackId;
        mStackSupervisor = supervisor;
    }

    private boolean okToShow(ActivityRecord r) {
@@ -2518,7 +2517,7 @@ final class ActivityStack {
                    resultRecord, resultWho, requestCode,
                    Activity.RESULT_CANCELED, null);
            }
            mDismissKeyguardOnNextActivity = false;
            mStackSupervisor.setDismissKeyguard(false);
            ActivityOptions.abort(options);
            return err;
        }
@@ -2533,7 +2532,7 @@ final class ActivityStack {
                    resultRecord, resultWho, requestCode,
                    Activity.RESULT_CANCELED, null);
            }
            mDismissKeyguardOnNextActivity = false;
            mStackSupervisor.setDismissKeyguard(false);
            String msg;
            if (!aInfo.exported) {
                msg = "Permission Denial: starting " + intent.toString()
@@ -2571,7 +2570,7 @@ final class ActivityStack {
                    }
                    // We pretend to the caller that it was really started, but
                    // they will just get a cancel result.
                    mDismissKeyguardOnNextActivity = false;
                    mStackSupervisor.setDismissKeyguard(false);
                    ActivityOptions.abort(options);
                    return ActivityManager.START_SUCCESS;
                }
@@ -2592,7 +2591,7 @@ final class ActivityStack {
                    PendingActivityLaunch pal =
                            new PendingActivityLaunch(r, sourceRecord, startFlags, this);
                    mService.mPendingActivityLaunches.add(pal);
                    mDismissKeyguardOnNextActivity = false;
                    mStackSupervisor.setDismissKeyguard(false);
                    ActivityOptions.abort(options);
                    return ActivityManager.START_SWITCHES_CANCELED;
                }
@@ -2614,13 +2613,12 @@ final class ActivityStack {

        err = startActivityUncheckedLocked(r, sourceRecord,
                startFlags, true, options);
        if (mDismissKeyguardOnNextActivity && mPausingActivity == null) {
        if (mPausingActivity == null) {
            // Someone asked to have the keyguard dismissed on the next
            // activity start, but we are not actually doing an activity
            // switch...  just dismiss the keyguard now, because we
            // probably want to see whatever is behind it.
            mDismissKeyguardOnNextActivity = false;
            mService.mWindowManager.dismissKeyguard();
            mStackSupervisor.dismissKeyguard();
        }
        return err;
    }
@@ -3315,11 +3313,7 @@ final class ActivityStack {
            w.thisTime = w.totalTime;
        }
        mService.notifyAll();

        if (mDismissKeyguardOnNextActivity) {
            mDismissKeyguardOnNextActivity = false;
            mService.mWindowManager.dismissKeyguard();
        }
        mStackSupervisor.dismissKeyguard();
    }

    void sendActivityResultLocked(int callingUid, ActivityRecord r,
@@ -4788,10 +4782,6 @@ final class ActivityStack {
        return true;
    }

    public void dismissKeyguardOnNextActivityLocked() {
        mDismissKeyguardOnNextActivity = true;
    }

    boolean willActivityBeVisibleLocked(IBinder token) {
        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+47 −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 java.io.PrintWriter;

public class ActivityStackSupervisor {

    final ActivityManagerService mService;

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

    public ActivityStackSupervisor(ActivityManagerService service) {
        mService = service;
    }

    void dismissKeyguard() {
        if (mDismissKeyguardOnNextActivity) {
            mDismissKeyguardOnNextActivity = false;
            mService.mWindowManager.dismissKeyguard();
        }
    }

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

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