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

Commit 7622a0f8 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Maybe fix issue #17700474: manta: high occurrence of device booted...

...but dev.bootcomplete flag is not set

Rework things to address a few issues I found:

- When the activity goes idle, the way we were handling finishing the
  boot there was calling finishBooting() with the lock held, but it
  shouldn't.  We now dispatch that and turning on the screen together
  in a separate message.

- Make sure we don't try to start the home activity until we have
  reached the point of the system being ready and mBooting being set.
  This ensures we don't do any work prematurely.

Change-Id: If30c1f287af73bc2164e7aadbe98022ae42cc5e7
parent 38646c19
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1468,6 +1468,7 @@ public final class ActiveServices {
                app.services.remove(r);
                r.app = null;
                scheduleServiceRestartLocked(r, false);
                return;
            }
        }

+18 −8
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static com.android.internal.util.XmlUtils.writeBooleanAttribute;
import static com.android.internal.util.XmlUtils.writeIntAttribute;
import static com.android.internal.util.XmlUtils.writeLongAttribute;
import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
@@ -1192,7 +1193,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    static final int SYSTEM_USER_START_MSG = 42;
    static final int SYSTEM_USER_CURRENT_MSG = 43;
    static final int ENTER_ANIMATION_COMPLETE_MSG = 44;
    static final int ENABLE_SCREEN_AFTER_BOOT_MSG = 45;
    static final int FINISH_BOOTING_MSG = 45;
    static final int START_USER_SWITCH_MSG = 46;
    static final int SEND_LOCALE_TO_MOUNT_DAEMON_MSG = 47;
@@ -1877,8 +1878,13 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
                break;
            }
            case ENABLE_SCREEN_AFTER_BOOT_MSG: {
            case FINISH_BOOTING_MSG: {
                if (msg.arg1 != 0) {
                    finishBooting();
                }
                if (msg.arg2 != 0) {
                    enableScreenAfterBoot();
                }
                break;
            }
            case SEND_LOCALE_TO_MOUNT_DAEMON_MSG: {
@@ -6258,8 +6264,9 @@ public final class ActivityManagerService extends ActivityManagerNative
        Binder.restoreCallingIdentity(origId);
    }
    void postEnableScreenAfterBootLocked() {
        mHandler.sendEmptyMessage(ENABLE_SCREEN_AFTER_BOOT_MSG);
    void postFinishBooting(boolean finishBooting, boolean enableScreen) {
        mHandler.sendMessage(mHandler.obtainMessage(FINISH_BOOTING_MSG,
                finishBooting? 1 : 0, enableScreen ? 1 : 0));
    }
    void enableScreenAfterBoot() {
@@ -11272,6 +11279,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            // Start up initial activity.
            mBooting = true;
            startHomeActivityLocked(mCurrentUserId);
            try {
                if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
@@ -12505,7 +12513,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        boolean printedAnything = false;
        if (mRecentTasks.size() > 0) {
        if (mRecentTasks != null && mRecentTasks.size() > 0) {
            boolean printedHeader = false;
            final int N = mRecentTasks.size();
@@ -12904,10 +12912,12 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (dumpAll) {
                pw.println("  Total persistent processes: " + numPers);
                pw.println("  mProcessesReady=" + mProcessesReady
                        + " mSystemReady=" + mSystemReady);
                pw.println("  mBooting=" + mBooting
                        + " mSystemReady=" + mSystemReady
                        + " mBooted=" + mBooted
                        + " mFactoryTest=" + mFactoryTest);
                pw.println("  mBooting=" + mBooting
                        + " mCallFinishBooting=" + mCallFinishBooting
                        + " mBootAnimationComplete=" + mBootAnimationComplete);
                pw.print("  mLastPowerCheckRealtime=");
                        TimeUtils.formatDuration(mLastPowerCheckRealtime, pw);
                        pw.println("");
+9 −0
Original line number Diff line number Diff line
@@ -1482,6 +1482,11 @@ final class ActivityStack {
    final boolean resumeTopActivityInnerLocked(ActivityRecord prev, Bundle options) {
        if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");

        if (!mService.mBooting && !mService.mBooted) {
            // Not ready yet!
            return false;
        }

        ActivityRecord parent = mActivityContainer.mParentActivity;
        if ((parent != null && parent.state != ActivityState.RESUMED) ||
                !mActivityContainer.isAttachedLocked()) {
@@ -3606,6 +3611,10 @@ final class ActivityStack {

        final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null;
        if (task == tr && tr.isOverHomeStack() || numTasks <= 1 && isOnHomeDisplay()) {
            if (!mService.mBooting && !mService.mBooted) {
                // Not ready yet!
                return false;
            }
            final int taskToReturnTo = tr.getTaskToReturnTo();
            tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
            return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null);
+8 −6
Original line number Diff line number Diff line
@@ -421,6 +421,11 @@ public final class ActivityStackSupervisor implements DisplayListener {
    }

    boolean resumeHomeStackTask(int homeStackTaskType, ActivityRecord prev) {
        if (!mService.mBooting && !mService.mBooted) {
            // Not ready yet!
            return false;
        }

        if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) {
            mWindowManager.showRecentApps();
            return false;
@@ -2295,9 +2300,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
            activityRemoved |= r.task.stack.destroyActivityLocked(r, true, "finish-idle");
        }

        if (booting) {
            mService.finishBooting();
        } else {
        if (!booting) {
            // Complete user switch
            if (startingUsers != null) {
                for (int i = 0; i < startingUsers.size(); i++) {
@@ -2318,8 +2321,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
        //dump();
        //mWindowManager.dump();

        if (enableScreen) {
            mService.postEnableScreenAfterBootLocked();
        if (booting || enableScreen) {
            mService.postFinishBooting(booting, enableScreen);
        }

        if (activityRemoved) {
@@ -2584,7 +2587,6 @@ public final class ActivityStackSupervisor implements DisplayListener {
                        r.mLaunchTaskBehind);
            }
        }
        resumeHomeStackTask(HOME_ACTIVITY_TYPE, null);
    }

    void moveTaskToStack(int taskId, int stackId, boolean toTop) {