Skip to content

Commit 42e620c

Browse files
author
Dianne Hackborn
committed
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
1 parent e9b4b3e commit 42e620c

File tree

2 files changed

+90
-33
lines changed

2 files changed

+90
-33
lines changed

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
279279
WindowManagerFuncs mWindowManagerFuncs;
280280
LocalPowerManager mPowerManager;
281281
IStatusBarService mStatusBarService;
282+
final Object mServiceAquireLock = new Object();
282283
Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
283284
SearchManager mSearchManager;
284285

@@ -597,6 +598,16 @@ public void onProposedRotationChanged(int rotation) {
597598
}
598599
MyOrientationListener mOrientationListener;
599600

601+
IStatusBarService getStatusBarService() {
602+
synchronized (mServiceAquireLock) {
603+
if (mStatusBarService == null) {
604+
mStatusBarService = IStatusBarService.Stub.asInterface(
605+
ServiceManager.getService("statusbar"));
606+
}
607+
return mStatusBarService;
608+
}
609+
}
610+
600611
/*
601612
* We always let the sensor be switched on by default except when
602613
* the user has explicitly disabled sensor based rotation or when the
@@ -790,9 +801,14 @@ private void handleLongPressOnHome() {
790801
showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
791802
} else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
792803
try {
793-
mStatusBarService.toggleRecentApps();
804+
IStatusBarService statusbar = getStatusBarService();
805+
if (statusbar != null) {
806+
statusbar.toggleRecentApps();
807+
}
794808
} catch (RemoteException e) {
795809
Slog.e(TAG, "RemoteException when showing recent apps", e);
810+
// re-acquire status bar service next time it is needed.
811+
mStatusBarService = null;
796812
}
797813
}
798814
}
@@ -1751,9 +1767,14 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
17511767
mHomeLongPressed = false;
17521768
if (!homeWasLongPressed) {
17531769
try {
1754-
mStatusBarService.cancelPreloadRecentApps();
1770+
IStatusBarService statusbar = getStatusBarService();
1771+
if (statusbar != null) {
1772+
statusbar.cancelPreloadRecentApps();
1773+
}
17551774
} catch (RemoteException e) {
17561775
Slog.e(TAG, "RemoteException when showing recent apps", e);
1776+
// re-acquire status bar service next time it is needed.
1777+
mStatusBarService = null;
17571778
}
17581779

17591780
mHomePressed = false;
@@ -1804,9 +1825,14 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
18041825
if (down) {
18051826
if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
18061827
try {
1807-
mStatusBarService.preloadRecentApps();
1828+
IStatusBarService statusbar = getStatusBarService();
1829+
if (statusbar != null) {
1830+
statusbar.preloadRecentApps();
1831+
}
18081832
} catch (RemoteException e) {
18091833
Slog.e(TAG, "RemoteException when preloading recent apps", e);
1834+
// re-acquire status bar service next time it is needed.
1835+
mStatusBarService = null;
18101836
}
18111837
}
18121838
if (repeatCount == 0) {
@@ -2901,10 +2927,14 @@ public int finishAnimationLw() {
29012927
changes |= FINISH_LAYOUT_REDO_LAYOUT;
29022928

29032929
mHandler.post(new Runnable() { public void run() {
2904-
if (mStatusBarService != null) {
2905-
try {
2906-
mStatusBarService.collapse();
2907-
} catch (RemoteException ex) {}
2930+
try {
2931+
IStatusBarService statusbar = getStatusBarService();
2932+
if (statusbar != null) {
2933+
statusbar.collapse();
2934+
}
2935+
} catch (RemoteException ex) {
2936+
// re-acquire status bar service next time it is needed.
2937+
mStatusBarService = null;
29082938
}
29092939
}});
29102940
} else if (DEBUG_LAYOUT) {
@@ -4342,18 +4372,15 @@ private int updateSystemUiVisibilityLw() {
43424372
mFocusedApp = mFocusedWindow.getAppToken();
43434373
mHandler.post(new Runnable() {
43444374
public void run() {
4345-
if (mStatusBarService == null) {
4346-
mStatusBarService = IStatusBarService.Stub.asInterface(
4347-
ServiceManager.getService("statusbar"));
4348-
}
4349-
if (mStatusBarService != null) {
4350-
try {
4351-
mStatusBarService.setSystemUiVisibility(visibility, 0xffffffff);
4352-
mStatusBarService.topAppWindowChanged(needsMenu);
4353-
} catch (RemoteException e) {
4354-
// not much to be done
4355-
mStatusBarService = null;
4375+
try {
4376+
IStatusBarService statusbar = getStatusBarService();
4377+
if (statusbar != null) {
4378+
statusbar.setSystemUiVisibility(visibility, 0xffffffff);
4379+
statusbar.topAppWindowChanged(needsMenu);
43564380
}
4381+
} catch (RemoteException e) {
4382+
// re-acquire status bar service next time it is needed.
4383+
mStatusBarService = null;
43574384
}
43584385
}
43594386
});

services/java/com/android/server/am/ActivityStack.java

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,11 @@ private final void completePauseLocked() {
11291129
resumeTopActivityLocked(prev);
11301130
} else {
11311131
checkReadyForSleepLocked();
1132+
if (topRunningActivityLocked(null) == null) {
1133+
// If there are no more activities available to run, then
1134+
// do resume anyway to start something.
1135+
resumeTopActivityLocked(null);
1136+
}
11321137
}
11331138

11341139
if (prev != null) {
@@ -3413,6 +3418,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
34133418
IApplicationThread sendThumbnail = null;
34143419
boolean booting = false;
34153420
boolean enableScreen = false;
3421+
boolean activityRemoved = false;
34163422

34173423
synchronized (mService) {
34183424
ActivityRecord r = ActivityRecord.forToken(token);
@@ -3519,7 +3525,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
35193525
for (i=0; i<NF; i++) {
35203526
ActivityRecord r = (ActivityRecord)finishes.get(i);
35213527
synchronized (mService) {
3522-
destroyActivityLocked(r, true, false, "finish-idle");
3528+
activityRemoved = destroyActivityLocked(r, true, false, "finish-idle");
35233529
}
35243530
}
35253531

@@ -3541,6 +3547,10 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
35413547
mService.enableScreenAfterBoot();
35423548
}
35433549

3550+
if (activityRemoved) {
3551+
resumeTopActivityLocked(null);
3552+
}
3553+
35443554
return res;
35453555
}
35463556

@@ -3780,7 +3790,11 @@ private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
37803790
|| prevState == ActivityState.INITIALIZING) {
37813791
// If this activity is already stopped, we can just finish
37823792
// it right now.
3783-
return destroyActivityLocked(r, true, true, "finish-imm") ? null : r;
3793+
boolean activityRemoved = destroyActivityLocked(r, true, true, "finish-imm");
3794+
if (activityRemoved) {
3795+
resumeTopActivityLocked(null);
3796+
}
3797+
return activityRemoved ? null : r;
37843798
} else {
37853799
// Need to go through the full pause cycle to get this
37863800
// activity into the stopped state and then finish it.
@@ -3844,6 +3858,10 @@ final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices,
38443858
}
38453859

38463860
// Get rid of any pending idle timeouts.
3861+
removeTimeoutsForActivityLocked(r);
3862+
}
3863+
3864+
private void removeTimeoutsForActivityLocked(ActivityRecord r) {
38473865
mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
38483866
mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
38493867
mHandler.removeMessages(IDLE_TIMEOUT_MSG, r);
@@ -3897,6 +3915,7 @@ final void scheduleDestroyActivities(ProcessRecord owner, boolean oomAdj, String
38973915

38983916
final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) {
38993917
boolean lastIsOpaque = false;
3918+
boolean activityRemoved = false;
39003919
for (int i=mHistory.size()-1; i>=0; i--) {
39013920
ActivityRecord r = mHistory.get(i);
39023921
if (r.finishing) {
@@ -3920,9 +3939,14 @@ final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String r
39203939
if (DEBUG_SWITCH) Slog.v(TAG, "Destroying " + r + " in state " + r.state
39213940
+ " resumed=" + mResumedActivity
39223941
+ " pausing=" + mPausingActivity);
3923-
destroyActivityLocked(r, true, oomAdj, reason);
3942+
if (destroyActivityLocked(r, true, oomAdj, reason)) {
3943+
activityRemoved = true;
3944+
}
39243945
}
39253946
}
3947+
if (activityRemoved) {
3948+
resumeTopActivityLocked(null);
3949+
}
39263950
}
39273951

39283952
/**
@@ -4027,23 +4051,28 @@ final boolean destroyActivityLocked(ActivityRecord r,
40274051

40284052
final void activityDestroyed(IBinder token) {
40294053
synchronized (mService) {
4030-
ActivityRecord r = ActivityRecord.forToken(token);
4031-
if (r != null) {
4032-
mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
4033-
}
4034-
4035-
int index = indexOfActivityLocked(r);
4036-
if (index >= 0) {
4037-
if (r.state == ActivityState.DESTROYING) {
4038-
final long origId = Binder.clearCallingIdentity();
4039-
removeActivityFromHistoryLocked(r);
4040-
Binder.restoreCallingIdentity(origId);
4054+
final long origId = Binder.clearCallingIdentity();
4055+
try {
4056+
ActivityRecord r = ActivityRecord.forToken(token);
4057+
if (r != null) {
4058+
mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
4059+
}
4060+
4061+
int index = indexOfActivityLocked(r);
4062+
if (index >= 0) {
4063+
if (r.state == ActivityState.DESTROYING) {
4064+
cleanUpActivityLocked(r, true, true);
4065+
removeActivityFromHistoryLocked(r);
4066+
}
40414067
}
4068+
resumeTopActivityLocked(null);
4069+
} finally {
4070+
Binder.restoreCallingIdentity(origId);
40424071
}
40434072
}
40444073
}
40454074

4046-
private static void removeHistoryRecordsForAppLocked(ArrayList list, ProcessRecord app) {
4075+
private void removeHistoryRecordsForAppLocked(ArrayList list, ProcessRecord app) {
40474076
int i = list.size();
40484077
if (localLOGV) Slog.v(
40494078
TAG, "Removing app " + app + " from list " + list
@@ -4056,6 +4085,7 @@ private static void removeHistoryRecordsForAppLocked(ArrayList list, ProcessReco
40564085
if (r.app == app) {
40574086
if (localLOGV) Slog.v(TAG, "Removing this entry!");
40584087
list.remove(i);
4088+
removeTimeoutsForActivityLocked(r);
40594089
}
40604090
}
40614091
}

0 commit comments

Comments
 (0)