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

Commit fd7e534b authored by Craig Mautner's avatar Craig Mautner Committed by Android (Google) Code Review
Browse files

Merge "Implement separate stacks."

parents 0f6ba077 de4ef020
Loading
Loading
Loading
Loading
+32 −28
Original line number Diff line number Diff line
@@ -2610,7 +2610,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized (this) {
            // If this is coming from the currently resumed activity, it is
            // effectively saying that app switches are allowed at this point.
            final ActivityStack stack = getMainStack();
            final ActivityStack stack = getTopStack();
            if (stack.mResumedActivity != null &&
                    stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) {
                mAppSwitchesAllowedTime = 0;
@@ -5898,6 +5898,8 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    private void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
        mRecentTasks.remove(tr);
        mStackSupervisor.removeTask(tr);
        final boolean killProcesses = (flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
        Intent baseIntent = new Intent(
                tr.intent != null ? tr.intent : tr.affinityIntent);
@@ -5955,14 +5957,12 @@ public final class ActivityManagerService extends ActivityManagerNative
                if (tr != null) {
                    ActivityRecord r = tr.stack.removeTaskActivitiesLocked(taskId, -1, false);
                    if (r != null) {
                        mRecentTasks.remove(tr);
                        cleanUpRemovedTaskLocked(tr, flags);
                        return true;
                    }
                    if (tr.mActivities.size() == 0) {
                        // Caller is just removing a recent task that is
                        // not actively running.  That is easy!
                        mRecentTasks.remove(tr);
                        cleanUpRemovedTaskLocked(tr, flags);
                        return true;
                    }
@@ -6003,12 +6003,12 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    @Override
    public void moveTaskToBack(int task) {
    public void moveTaskToBack(int taskId) {
        enforceCallingPermission(android.Manifest.permission.REORDER_TASKS,
                "moveTaskToBack()");
        synchronized(this) {
            TaskRecord tr = recentTaskForIdLocked(task);
            TaskRecord tr = recentTaskForIdLocked(taskId);
            if (tr != null) {
                ActivityStack stack = tr.stack;
                if (stack.mResumedActivity != null && stack.mResumedActivity.task == tr) {
@@ -6018,7 +6018,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    }
                }
                final long origId = Binder.clearCallingIdentity();
                stack.moveTaskToBackLocked(task, null);
                stack.moveTaskToBackLocked(taskId, null);
                Binder.restoreCallingIdentity(origId);
            }
        }
@@ -6071,7 +6071,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    public int createStack(int relativeStackId, int position, float weight) {
        synchronized (this) {
            int stackId = mStackSupervisor.createStack(relativeStackId, position, weight);
            mWindowManager.createStack(stackId, position, relativeStackId, weight);
            mWindowManager.createStack(stackId, relativeStackId, position, weight);
            return stackId;
        }
    }
@@ -7003,7 +7003,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized(this) {
            final long origId = Binder.clearCallingIdentity();
            try {
                getMainStack().unhandledBackLocked();
                getTopStack().unhandledBackLocked();
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
@@ -7393,7 +7393,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        PendingActivityExtras pae;
        Bundle extras = new Bundle();
        synchronized (this) {
            ActivityRecord activity = getMainStack().mResumedActivity;
            ActivityRecord activity = getTopStack().mResumedActivity;
            if (activity == null) {
                Slog.w(TAG, "getTopActivityExtras failed: no resumed activity");
                return null;
@@ -7489,7 +7489,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    public boolean isTopActivityImmersive() {
        enforceNotIsolatedCaller("startActivity");
        synchronized (this) {
            ActivityRecord r = getMainStack().topRunningActivityLocked(null);
            ActivityRecord r = getTopStack().topRunningActivityLocked(null);
            return (r != null) ? r.immersive : false;
        }
    }
@@ -9391,7 +9391,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
        pw.println("  mConfiguration: " + mConfiguration);
        if (dumpAll) {
            pw.println("  mConfigWillChange: " + getMainStack().mConfigWillChange);
            pw.println("  mConfigWillChange: " + getTopStack().mConfigWillChange);
            if (mCompatModePackages.getPackages().size() > 0) {
                boolean printed = false;
                for (Map.Entry<String, Integer> entry
@@ -9451,8 +9451,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            pw.print("  mLastPowerCheckUptime=");
                    TimeUtils.formatDuration(mLastPowerCheckUptime, pw);
                    pw.println("");
            pw.println("  mGoingToSleep=" + getMainStack().mGoingToSleep);
            pw.println("  mLaunchingActivity=" + getMainStack().mLaunchingActivity);
            pw.println("  mGoingToSleep=" + getTopStack().mGoingToSleep);
            pw.println("  mLaunchingActivity=" + getTopStack().mLaunchingActivity);
            pw.println("  mAdjSeq=" + mAdjSeq + " mLruSeq=" + mLruSeq);
            pw.println("  mNumNonHiddenProcs=" + mNumNonHiddenProcs
                    + " mNumHiddenProcs=" + mNumHiddenProcs
@@ -12185,8 +12185,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        return config;
    }
    ActivityStack getMainStack() {
        return mStackSupervisor.getMainStack();
    ActivityStack getTopStack() {
        return mStackSupervisor.getTopStack();
    }
    public Configuration getConfiguration() {
@@ -12251,8 +12251,6 @@ public final class ActivityManagerService extends ActivityManagerNative
        int changes = 0;
        boolean kept = true;
        
        if (values != null) {
            Configuration newConfig = new Configuration(mConfiguration);
            changes = newConfig.updateFrom(values);
@@ -12331,7 +12329,21 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
        }
        kept = mStackSupervisor.updateConfigurationLocked(changes, starting);
        boolean kept = true;
        final ActivityStack mainStack = mStackSupervisor.getTopStack();
        if (changes != 0 && starting == null) {
            // If the configuration changed, and the caller is not already
            // in the process of starting an activity, then find the top
            // activity to check if its configuration needs to change.
            starting = mainStack.topRunningActivityLocked(null);
        }
        
        if (starting != null) {
            kept = mainStack.ensureActivityConfigurationLocked(starting, changes);
            // And we need to make sure at this point that all other activities
            // are made visible with the correct configuration.
            mStackSupervisor.ensureActivitiesVisibleLocked(starting, changes);
        }
        if (values != null && mWindowManager != null) {
            mWindowManager.setNewConfiguration(mConfiguration);
@@ -13409,15 +13421,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    private final ActivityRecord resumedAppLocked() {
        final ActivityStack stack = mStackSupervisor.getMainStack();
        ActivityRecord resumedActivity = stack.mResumedActivity;
        if (resumedActivity == null || resumedActivity.app == null) {
            resumedActivity = stack.mPausingActivity;
            if (resumedActivity == null || resumedActivity.app == null) {
                resumedActivity = stack.topRunningActivityLocked(null);
            }
        }
        return resumedActivity;
        return mStackSupervisor.resumedAppLocked();
    }
    final boolean updateOomAdjLocked(ProcessRecord app) {
+25 −11
Original line number Diff line number Diff line
@@ -129,6 +129,10 @@ final class ActivityRecord {
    String stringName;      // for caching of toString().

    private boolean inHistory;  // are we in the history stack?
    final ActivityStackSupervisor mStackSupervisor;

    /** Launch the home activity rather than the activity at the top of stack */
    boolean mLaunchHomeTaskNext;

    void dump(PrintWriter pw, String prefix) {
        final long now = SystemClock.uptimeMillis();
@@ -268,28 +272,28 @@ final class ActivityRecord {
            weakActivity = new WeakReference<ActivityRecord>(activity);
        }

        @Override public void windowsDrawn() throws RemoteException {
        @Override public void windowsDrawn() {
            ActivityRecord activity = weakActivity.get();
            if (activity != null) {
                activity.windowsDrawn();
            }
        }

        @Override public void windowsVisible() throws RemoteException {
        @Override public void windowsVisible() {
            ActivityRecord activity = weakActivity.get();
            if (activity != null) {
                activity.windowsVisible();
            }
        }

        @Override public void windowsGone() throws RemoteException {
        @Override public void windowsGone() {
            ActivityRecord activity = weakActivity.get();
            if (activity != null) {
                activity.windowsGone();
            }
        }

        @Override public boolean keyDispatchingTimedOut() throws RemoteException {
        @Override public boolean keyDispatchingTimedOut() {
            ActivityRecord activity = weakActivity.get();
            if (activity != null) {
                return activity.keyDispatchingTimedOut();
@@ -297,7 +301,7 @@ final class ActivityRecord {
            return false;
        }

        @Override public long getKeyDispatchingTimeout() throws RemoteException {
        @Override public long getKeyDispatchingTimeout() {
            ActivityRecord activity = weakActivity.get();
            if (activity != null) {
                return activity.getKeyDispatchingTimeout();
@@ -305,6 +309,7 @@ final class ActivityRecord {
            return 0;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder(128);
            sb.append("Token{");
@@ -329,7 +334,7 @@ final class ActivityRecord {
            int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
            ActivityInfo aInfo, Configuration _configuration,
            ActivityRecord _resultTo, String _resultWho, int _reqCode,
            boolean _componentSpecified) {
            boolean _componentSpecified, ActivityStackSupervisor supervisor) {
        service = _service;
        appToken = new Token(this);
        info = aInfo;
@@ -359,6 +364,7 @@ final class ActivityRecord {
        thumbnailNeeded = false;
        idle = false;
        hasBeenLaunched = false;
        mStackSupervisor = supervisor;

        // This starts out true, since the initial state of an activity
        // is that we have everything, and we shouldn't never consider it
@@ -466,6 +472,9 @@ final class ActivityRecord {
    }

    void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
        if (task != null && task.removeActivity(this)) {
            mStackSupervisor.removeTask(task);
        }
        if (inHistory && !finishing) {
            if (task != null) {
                task.numActivities--;
@@ -524,6 +533,11 @@ final class ActivityRecord {
        }
    }

    boolean isRootActivity() {
        ArrayList<ActivityRecord> activities = task.mActivities;
        return activities.size() == 0 || this == task.mActivities.get(0);
    }

    UriPermissionOwner getUriPermissionsLocked() {
        if (uriPermissions == null) {
            uriPermissions = new UriPermissionOwner(service, this);
@@ -814,23 +828,23 @@ final class ActivityRecord {
                    // Instead of doing the full stop routine here, let's just
                    // hide any activities we now can, and let them stop when
                    // the normal idle happens.
                    stack.processStoppingActivitiesLocked(false);
                    mStackSupervisor.processStoppingActivitiesLocked(false);
                } else {
                    // If this activity was already idle, then we now need to
                    // make sure we perform the full stop of any activities
                    // that are waiting to do so.  This is because we won't
                    // do that while they are still waiting for this one to
                    // become visible.
                    final int N = stack.mWaitingVisibleActivities.size();
                    final int N = mStackSupervisor.mWaitingVisibleActivities.size();
                    if (N > 0) {
                        for (int i=0; i<N; i++) {
                            ActivityRecord r = stack.mWaitingVisibleActivities.get(i);
                            ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
                            r.waitingVisible = false;
                            if (ActivityManagerService.DEBUG_SWITCH) Log.v(
                                    ActivityManagerService.TAG,
                                    "Was waiting for visible: " + r);
                        }
                        stack.mWaitingVisibleActivities.clear();
                        mStackSupervisor.mWaitingVisibleActivities.clear();
                        Message msg = Message.obtain();
                        msg.what = ActivityStack.IDLE_NOW_MSG;
                        stack.mHandler.sendMessage(msg);
+139 −251

File changed.

Preview size limit exceeded, changes collapsed.

+319 −100

File changed.

Preview size limit exceeded, changes collapsed.

+5 −5
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public class CompatModePackages {
    }

    public boolean getFrontActivityAskCompatModeLocked() {
        ActivityRecord r = mService.getMainStack().topRunningActivityLocked(null);
        ActivityRecord r = mService.getTopStack().topRunningActivityLocked(null);
        if (r == null) {
            return false;
        }
@@ -177,7 +177,7 @@ public class CompatModePackages {
    }

    public void setFrontActivityAskCompatModeLocked(boolean ask) {
        ActivityRecord r = mService.getMainStack().topRunningActivityLocked(null);
        ActivityRecord r = mService.getTopStack().topRunningActivityLocked(null);
        if (r != null) {
            setPackageAskCompatModeLocked(r.packageName, ask);
        }
@@ -199,7 +199,7 @@ public class CompatModePackages {
    }

    public int getFrontActivityScreenCompatModeLocked() {
        ActivityRecord r = mService.getMainStack().topRunningActivityLocked(null);
        ActivityRecord r = mService.getTopStack().topRunningActivityLocked(null);
        if (r == null) {
            return ActivityManager.COMPAT_MODE_UNKNOWN;
        }
@@ -207,7 +207,7 @@ public class CompatModePackages {
    }

    public void setFrontActivityScreenCompatModeLocked(int mode) {
        ActivityRecord r = mService.getMainStack().topRunningActivityLocked(null);
        ActivityRecord r = mService.getTopStack().topRunningActivityLocked(null);
        if (r == null) {
            Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity");
            return;
@@ -294,7 +294,7 @@ public class CompatModePackages {
            Message msg = mHandler.obtainMessage(MSG_WRITE);
            mHandler.sendMessageDelayed(msg, 10000);

            final ActivityStack stack = mService.getMainStack();
            final ActivityStack stack = mService.getTopStack();
            ActivityRecord starting = stack.restartPackage(packageName);

            // Tell all processes that loaded this package about the change.
Loading