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

Commit 42e620ca authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #6381224: Initial emulator boot fails and shows a blank black screen.

Make sure that all cases where we remove an activity from the history
stack, we call resumeTopActivityLocked() to cause the home activity
to be launched if the stack is now empty.

Also fixed a problem where some timeouts would not be removed when destroying
an activity, and a race condition in boot that would cause the
PhoneWindowManager to initially start out with the home key not working.

Bug: 6381224
Change-Id: If046bb01aed624b0d9ee3bbaaba68ed6b98fd1d0
parent e9b4b3e9
Loading
Loading
Loading
Loading
+45 −18
Original line number Diff line number Diff line
@@ -279,6 +279,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    WindowManagerFuncs mWindowManagerFuncs;
    LocalPowerManager mPowerManager;
    IStatusBarService mStatusBarService;
    final Object mServiceAquireLock = new Object();
    Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
    SearchManager mSearchManager;

@@ -597,6 +598,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }
    MyOrientationListener mOrientationListener;

    IStatusBarService getStatusBarService() {
        synchronized (mServiceAquireLock) {
            if (mStatusBarService == null) {
                mStatusBarService = IStatusBarService.Stub.asInterface(
                        ServiceManager.getService("statusbar"));
            }
            return mStatusBarService;
        }
    }

    /*
     * We always let the sensor be switched on by default except when
     * the user has explicitly disabled sensor based rotation or when the
@@ -790,9 +801,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
        } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
            try {
                mStatusBarService.toggleRecentApps();
                IStatusBarService statusbar = getStatusBarService();
                if (statusbar != null) {
                    statusbar.toggleRecentApps();
                }
            } catch (RemoteException e) {
                Slog.e(TAG, "RemoteException when showing recent apps", e);
                // re-acquire status bar service next time it is needed.
                mStatusBarService = null;
            }
        }
    }
@@ -1751,9 +1767,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                mHomeLongPressed = false;
                if (!homeWasLongPressed) {
                    try {
                        mStatusBarService.cancelPreloadRecentApps();
                        IStatusBarService statusbar = getStatusBarService();
                        if (statusbar != null) {
                            statusbar.cancelPreloadRecentApps();
                        }
                    } catch (RemoteException e) {
                        Slog.e(TAG, "RemoteException when showing recent apps", e);
                        // re-acquire status bar service next time it is needed.
                        mStatusBarService = null;
                    }

                    mHomePressed = false;
@@ -1804,9 +1825,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            if (down) {
                if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
                    try {
                        mStatusBarService.preloadRecentApps();
                        IStatusBarService statusbar = getStatusBarService();
                        if (statusbar != null) {
                            statusbar.preloadRecentApps();
                        }
                    } catch (RemoteException e) {
                        Slog.e(TAG, "RemoteException when preloading recent apps", e);
                        // re-acquire status bar service next time it is needed.
                        mStatusBarService = null;
                    }
                }
                if (repeatCount == 0) {
@@ -2901,10 +2927,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        changes |= FINISH_LAYOUT_REDO_LAYOUT;

                        mHandler.post(new Runnable() { public void run() {
                            if (mStatusBarService != null) {
                            try {
                                    mStatusBarService.collapse();
                                } catch (RemoteException ex) {}
                                IStatusBarService statusbar = getStatusBarService();
                                if (statusbar != null) {
                                    statusbar.collapse();
                                }
                            } catch (RemoteException ex) {
                                // re-acquire status bar service next time it is needed.
                                mStatusBarService = null;
                            }
                        }});
                    } else if (DEBUG_LAYOUT) {
@@ -4342,20 +4372,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mFocusedApp = mFocusedWindow.getAppToken();
        mHandler.post(new Runnable() {
                public void run() {
                    if (mStatusBarService == null) {
                        mStatusBarService = IStatusBarService.Stub.asInterface(
                                ServiceManager.getService("statusbar"));
                    }
                    if (mStatusBarService != null) {
                    try {
                            mStatusBarService.setSystemUiVisibility(visibility, 0xffffffff);
                            mStatusBarService.topAppWindowChanged(needsMenu);
                        IStatusBarService statusbar = getStatusBarService();
                        if (statusbar != null) {
                            statusbar.setSystemUiVisibility(visibility, 0xffffffff);
                            statusbar.topAppWindowChanged(needsMenu);
                        }
                    } catch (RemoteException e) {
                            // not much to be done
                        // re-acquire status bar service next time it is needed.
                        mStatusBarService = null;
                    }
                }
                }
            });
        return diff;
    }
+45 −15
Original line number Diff line number Diff line
@@ -1129,6 +1129,11 @@ final class ActivityStack {
            resumeTopActivityLocked(prev);
        } else {
            checkReadyForSleepLocked();
            if (topRunningActivityLocked(null) == null) {
                // If there are no more activities available to run, then
                // do resume anyway to start something.
                resumeTopActivityLocked(null);
            }
        }
        
        if (prev != null) {
@@ -3413,6 +3418,7 @@ final class ActivityStack {
        IApplicationThread sendThumbnail = null;
        boolean booting = false;
        boolean enableScreen = false;
        boolean activityRemoved = false;

        synchronized (mService) {
            ActivityRecord r = ActivityRecord.forToken(token);
@@ -3519,7 +3525,7 @@ final class ActivityStack {
        for (i=0; i<NF; i++) {
            ActivityRecord r = (ActivityRecord)finishes.get(i);
            synchronized (mService) {
                destroyActivityLocked(r, true, false, "finish-idle");
                activityRemoved = destroyActivityLocked(r, true, false, "finish-idle");
            }
        }

@@ -3541,6 +3547,10 @@ final class ActivityStack {
            mService.enableScreenAfterBoot();
        }

        if (activityRemoved) {
            resumeTopActivityLocked(null);
        }

        return res;
    }

@@ -3780,7 +3790,11 @@ final class ActivityStack {
                || prevState == ActivityState.INITIALIZING) {
            // If this activity is already stopped, we can just finish
            // it right now.
            return destroyActivityLocked(r, true, true, "finish-imm") ? null : r;
            boolean activityRemoved = destroyActivityLocked(r, true, true, "finish-imm");
            if (activityRemoved) {
                resumeTopActivityLocked(null);
            }
            return activityRemoved ? null : r;
        } else {
            // Need to go through the full pause cycle to get this
            // activity into the stopped state and then finish it.
@@ -3844,6 +3858,10 @@ final class ActivityStack {
        }

        // Get rid of any pending idle timeouts.
        removeTimeoutsForActivityLocked(r);
    }

    private void removeTimeoutsForActivityLocked(ActivityRecord r) {
        mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
        mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
        mHandler.removeMessages(IDLE_TIMEOUT_MSG, r);
@@ -3897,6 +3915,7 @@ final class ActivityStack {

    final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) {
        boolean lastIsOpaque = false;
        boolean activityRemoved = false;
        for (int i=mHistory.size()-1; i>=0; i--) {
            ActivityRecord r = mHistory.get(i);
            if (r.finishing) {
@@ -3920,9 +3939,14 @@ final class ActivityStack {
                if (DEBUG_SWITCH) Slog.v(TAG, "Destroying " + r + " in state " + r.state
                        + " resumed=" + mResumedActivity
                        + " pausing=" + mPausingActivity);
                destroyActivityLocked(r, true, oomAdj, reason);
                if (destroyActivityLocked(r, true, oomAdj, reason)) {
                    activityRemoved = true;
                }
            }
        }
        if (activityRemoved) {
            resumeTopActivityLocked(null);
        }
    }

    /**
@@ -4027,6 +4051,8 @@ final class ActivityStack {

    final void activityDestroyed(IBinder token) {
        synchronized (mService) {
            final long origId = Binder.clearCallingIdentity();
            try {
                ActivityRecord r = ActivityRecord.forToken(token);
                if (r != null) {
                    mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
@@ -4035,15 +4061,18 @@ final class ActivityStack {
                int index = indexOfActivityLocked(r);
                if (index >= 0) {
                    if (r.state == ActivityState.DESTROYING) {
                    final long origId = Binder.clearCallingIdentity();
                        cleanUpActivityLocked(r, true, true);
                        removeActivityFromHistoryLocked(r);
                    Binder.restoreCallingIdentity(origId);
                    }
                }
                resumeTopActivityLocked(null);
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
        }
    }
    
    private static void removeHistoryRecordsForAppLocked(ArrayList list, ProcessRecord app) {
    private void removeHistoryRecordsForAppLocked(ArrayList list, ProcessRecord app) {
        int i = list.size();
        if (localLOGV) Slog.v(
            TAG, "Removing app " + app + " from list " + list
@@ -4056,6 +4085,7 @@ final class ActivityStack {
            if (r.app == app) {
                if (localLOGV) Slog.v(TAG, "Removing this entry!");
                list.remove(i);
                removeTimeoutsForActivityLocked(r);
            }
        }
    }