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

Commit 92c243bd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clean up unnecessary internal abstraction used by WMS"

parents 1e92f500 b31fe1da
Loading
Loading
Loading
Loading
+1 −28
Original line number Diff line number Diff line
@@ -293,9 +293,7 @@ import android.os.Trace;
import android.os.UserHandle;
import android.service.contentcapture.ActivityEvent;
import android.service.dreams.DreamActivity;
import android.service.dreams.DreamManagerInternal;
import android.service.voice.IVoiceInteractionSession;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.EventLog;
import android.util.Log;
@@ -2642,31 +2640,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return false;
    }

    static boolean canLaunchDreamActivity(String packageName) {
        if (packageName == null) {
            return false;
        }

        if (!LocalServices.getService(ActivityTaskManagerInternal.class).isDreaming()) {
            return false;
        }

        final DreamManagerInternal dreamManager =
                LocalServices.getService(DreamManagerInternal.class);

        // Verify that the package is the current active dream or doze component. The
        // getActiveDreamComponent() call path does not acquire the DreamManager lock and thus
        // is safe to use.
        final ComponentName activeDream = dreamManager.getActiveDreamComponent(false /* doze */);
        final ComponentName activeDoze = dreamManager.getActiveDreamComponent(true /* doze */);
        return TextUtils.equals(packageName, getPackageName(activeDream))
                || TextUtils.equals(packageName, getPackageName(activeDoze));
    }

    private static String getPackageName(ComponentName componentName) {
        return componentName != null ? componentName.getPackageName() : null;
    }

    private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent,
            ActivityOptions options, ActivityRecord sourceRecord) {
        int activityType = ACTIVITY_TYPE_UNDEFINED;
@@ -2687,7 +2660,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                && canLaunchAssistActivity(launchedFromPackage)) {
            activityType = ACTIVITY_TYPE_ASSISTANT;
        } else if (options != null && options.getLaunchActivityType() == ACTIVITY_TYPE_DREAM
                && canLaunchDreamActivity(launchedFromPackage)
                && mAtmService.canLaunchDreamActivity(launchedFromPackage)
                && DreamActivity.class.getName() == info.name) {
            activityType = ACTIVITY_TYPE_DREAM;
        }
+2 −2
Original line number Diff line number Diff line
@@ -1820,7 +1820,7 @@ class ActivityStarter {

        if (!mAvoidMoveToFront && mDoResume) {
            mTargetRootTask.getRootTask().moveToFront("reuseOrNewTask", targetTask);
            if (!mTargetRootTask.isTopRootTaskInDisplayArea() && mService.mInternal.isDreaming()
            if (!mTargetRootTask.isTopRootTaskInDisplayArea() && mService.isDreaming()
                    && !dreamStopping) {
                // Launching underneath dream activity (fullscreen, always-on-top). Run the launch-
                // -behind transition so the Activity gets created and starts in visible state.
@@ -2099,7 +2099,7 @@ class ActivityStarter {

        // At this point we are certain we want the task moved to the front. If we need to dismiss
        // any other always-on-top root tasks, now is the time to do it.
        if (targetTaskTop.canTurnScreenOn() && mService.mInternal.isDreaming()) {
        if (targetTaskTop.canTurnScreenOn() && mService.isDreaming()) {
            targetTaskTop.mTaskSupervisor.wakeUp("recycleTask#turnScreenOnFlag");
        }

+0 −10
Original line number Diff line number Diff line
@@ -316,7 +316,6 @@ public abstract class ActivityTaskManagerInternal {
    public abstract void clearHeavyWeightProcessIfEquals(WindowProcessController proc);
    public abstract void finishHeavyWeightApp();

    public abstract boolean isDreaming();
    public abstract boolean isSleeping();
    public abstract boolean isShuttingDown();
    public abstract boolean shuttingDown(boolean booted, int timeout);
@@ -456,15 +455,6 @@ public abstract class ActivityTaskManagerInternal {
    /** Writes current activity states to the proto stream. */
    public abstract void writeActivitiesToProto(ProtoOutputStream proto);

    /**
     * Saves the current activity manager state and includes the saved state in the next dump of
     * activity manager.
     */
    public abstract void saveANRState(String reason);

    /** Clears the previously saved activity manager ANR state. */
    public abstract void clearSavedANRState();

    /** Dump the current state based on the command. */
    public abstract void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args,
            int opti, boolean dumpAll, boolean dumpClient, String dumpPackage);
+55 −47
Original line number Diff line number Diff line
@@ -208,6 +208,7 @@ import android.os.storage.IStorageManager;
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.service.dreams.DreamActivity;
import android.service.dreams.DreamManagerInternal;
import android.service.voice.IVoiceInteractionSession;
import android.service.voice.VoiceInteractionManagerInternal;
import android.sysprop.DisplayProperties;
@@ -671,7 +672,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     * start/stop the dream. It is set to true shortly  before the {@link DreamService} is started.
     * It is set to false after the {@link DreamService} is stopped.
     */
    private boolean mDreaming = false;
    private volatile boolean mDreaming;

    /**
     * The process state used for processes that are running the top activities.
@@ -1399,10 +1400,34 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    boolean isDreaming() {
        return mDreaming;
    }

    boolean canLaunchDreamActivity(String packageName) {
        if (!mDreaming || packageName == null) {
            return false;
        }
        final DreamManagerInternal dreamManager =
                LocalServices.getService(DreamManagerInternal.class);
        // Verify that the package is the current active dream or doze component. The
        // getActiveDreamComponent() call path does not acquire the DreamManager lock and thus
        // is safe to use.
        final ComponentName activeDream = dreamManager.getActiveDreamComponent(false /* doze */);
        if (activeDream != null && packageName.equals(activeDream.getPackageName())) {
            return true;
        }
        final ComponentName activeDoze = dreamManager.getActiveDreamComponent(true /* doze */);
        if (activeDoze != null && packageName.equals(activeDoze.getPackageName())) {
            return true;
        }
        return false;
    }

    private void enforceCallerIsDream(String callerPackageName) {
        final long origId = Binder.clearCallingIdentity();
        try {
            if (!ActivityRecord.canLaunchDreamActivity(callerPackageName)) {
            if (!canLaunchDreamActivity(callerPackageName)) {
                throw new SecurityException("The dream activity can be started only when the device"
                        + " is dreaming and only by the active dream package.");
            }
@@ -3049,7 +3074,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     * SecurityException} or returns false with a logcat message depending on whether the app
     * targets SDK level {@link android.os.Build.VERSION_CODES#S} or not.
     */
    private boolean checkCanCloseSystemDialogs(int pid, int uid, @Nullable String packageName) {
    boolean checkCanCloseSystemDialogs(int pid, int uid, @Nullable String packageName) {
        final WindowProcessController process;
        synchronized (mGlobalLock) {
            process = mProcessMap.getProcess(pid);
@@ -3177,8 +3202,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                permission, pid, uid, owningUid, exported);
    }

    boolean isCallerRecents(int callingUid) {
        return mRecentTasks.isCallerRecents(callingUid);
    }

    boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) {
        if (getRecentTasks().isCallerRecents(callingUid)) {
        if (isCallerRecents(callingUid)) {
            // Always allow the recents component to get tasks
            return true;
        }
@@ -5127,11 +5156,28 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    }

    /**
     * @return allowlist tag for a uid from mPendingTempAllowlist, null if not currently on
     * the allowlist
     * Saves the current activity manager state and includes the saved state in the next dump of
     * activity manager.
     */
    String getPendingTempAllowlistTagForUidLocked(int uid) {
        return mPendingTempAllowlist.get(uid);
    void saveANRState(String reason) {
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new FastPrintWriter(sw, false, 1024);
        pw.println("  ANR time: " + DateFormat.getDateTimeInstance().format(new Date()));
        if (reason != null) {
            pw.println("  Reason: " + reason);
        }
        pw.println();
        getActivityStartController().dump(pw, "  ", null);
        pw.println();
        pw.println("-------------------------------------------------------------------"
                + "------------");
        dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */,
                true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */,
                "" /* header */);
        pw.println();
        pw.close();

        mLastANRState = sw.toString();
    }

    void logAppTooSlow(WindowProcessController app, long startTime, String msg) {
@@ -5514,7 +5560,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

        @Override
        public boolean isCallerRecents(int callingUid) {
            return getRecentTasks().isCallerRecents(callingUid);
            return ActivityTaskManagerService.this.isCallerRecents(callingUid);
        }

        @Override
@@ -5642,13 +5688,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
        }

        @Override
        public boolean isDreaming() {
            synchronized (mGlobalLock) {
                return mDreaming;
            }
        }

        @HotPath(caller = HotPath.OOM_ADJUSTMENT)
        @Override
        public boolean isSleeping() {
@@ -6148,37 +6187,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
        }

        @Override
        public void saveANRState(String reason) {
            synchronized (mGlobalLock) {
                final StringWriter sw = new StringWriter();
                final PrintWriter pw = new FastPrintWriter(sw, false, 1024);
                pw.println("  ANR time: " + DateFormat.getDateTimeInstance().format(new Date()));
                if (reason != null) {
                    pw.println("  Reason: " + reason);
                }
                pw.println();
                getActivityStartController().dump(pw, "  ", null);
                pw.println();
                pw.println("-------------------------------------------------------------------"
                        + "------------");
                dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */,
                        true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */,
                        "" /* header */);
                pw.println();
                pw.close();

                mLastANRState = sw.toString();
            }
        }

        @Override
        public void clearSavedANRState() {
            synchronized (mGlobalLock) {
                mLastANRState = null;
            }
        }

        @Override
        public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti,
                boolean dumpAll, boolean dumpClient, String dumpPackage) {
+1 −1
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ class AnrController {
    private void dumpAnrStateLocked(ActivityRecord activity, WindowState windowState,
                                    String reason) {
        mService.saveANRStateLocked(activity, windowState, reason);
        mService.mAtmInternal.saveANRState(reason);
        mService.mAtmService.saveANRState(reason);
    }

    private boolean isWindowAboveSystem(WindowState windowState) {
Loading