Skip to content

Commit 9e608c1

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #6381224: Initial emulator boot fails and shows a blank black screen." into jb-dev
2 parents 1799039 + 42e620c commit 9e608c1

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
}
@@ -1752,9 +1768,14 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
17521768
mHomeLongPressed = false;
17531769
if (!homeWasLongPressed) {
17541770
try {
1755-
mStatusBarService.cancelPreloadRecentApps();
1771+
IStatusBarService statusbar = getStatusBarService();
1772+
if (statusbar != null) {
1773+
statusbar.cancelPreloadRecentApps();
1774+
}
17561775
} catch (RemoteException e) {
17571776
Slog.e(TAG, "RemoteException when showing recent apps", e);
1777+
// re-acquire status bar service next time it is needed.
1778+
mStatusBarService = null;
17581779
}
17591780

17601781
mHomePressed = false;
@@ -1805,9 +1826,14 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
18051826
if (down) {
18061827
if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
18071828
try {
1808-
mStatusBarService.preloadRecentApps();
1829+
IStatusBarService statusbar = getStatusBarService();
1830+
if (statusbar != null) {
1831+
statusbar.preloadRecentApps();
1832+
}
18091833
} catch (RemoteException e) {
18101834
Slog.e(TAG, "RemoteException when preloading recent apps", e);
1835+
// re-acquire status bar service next time it is needed.
1836+
mStatusBarService = null;
18111837
}
18121838
}
18131839
if (repeatCount == 0) {
@@ -2902,10 +2928,14 @@ public int finishAnimationLw() {
29022928
changes |= FINISH_LAYOUT_REDO_LAYOUT;
29032929

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

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) {
@@ -3409,6 +3414,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
34093414
IApplicationThread sendThumbnail = null;
34103415
boolean booting = false;
34113416
boolean enableScreen = false;
3417+
boolean activityRemoved = false;
34123418

34133419
synchronized (mService) {
34143420
ActivityRecord r = ActivityRecord.forToken(token);
@@ -3515,7 +3521,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
35153521
for (i=0; i<NF; i++) {
35163522
ActivityRecord r = (ActivityRecord)finishes.get(i);
35173523
synchronized (mService) {
3518-
destroyActivityLocked(r, true, false, "finish-idle");
3524+
activityRemoved = destroyActivityLocked(r, true, false, "finish-idle");
35193525
}
35203526
}
35213527

@@ -3537,6 +3543,10 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
35373543
mService.enableScreenAfterBoot();
35383544
}
35393545

3546+
if (activityRemoved) {
3547+
resumeTopActivityLocked(null);
3548+
}
3549+
35403550
return res;
35413551
}
35423552

@@ -3776,7 +3786,11 @@ private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
37763786
|| prevState == ActivityState.INITIALIZING) {
37773787
// If this activity is already stopped, we can just finish
37783788
// it right now.
3779-
return destroyActivityLocked(r, true, true, "finish-imm") ? null : r;
3789+
boolean activityRemoved = destroyActivityLocked(r, true, true, "finish-imm");
3790+
if (activityRemoved) {
3791+
resumeTopActivityLocked(null);
3792+
}
3793+
return activityRemoved ? null : r;
37803794
} else {
37813795
// Need to go through the full pause cycle to get this
37823796
// activity into the stopped state and then finish it.
@@ -3840,6 +3854,10 @@ final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices,
38403854
}
38413855

38423856
// Get rid of any pending idle timeouts.
3857+
removeTimeoutsForActivityLocked(r);
3858+
}
3859+
3860+
private void removeTimeoutsForActivityLocked(ActivityRecord r) {
38433861
mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
38443862
mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
38453863
mHandler.removeMessages(IDLE_TIMEOUT_MSG, r);
@@ -3893,6 +3911,7 @@ final void scheduleDestroyActivities(ProcessRecord owner, boolean oomAdj, String
38933911

38943912
final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) {
38953913
boolean lastIsOpaque = false;
3914+
boolean activityRemoved = false;
38963915
for (int i=mHistory.size()-1; i>=0; i--) {
38973916
ActivityRecord r = mHistory.get(i);
38983917
if (r.finishing) {
@@ -3916,9 +3935,14 @@ final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String r
39163935
if (DEBUG_SWITCH) Slog.v(TAG, "Destroying " + r + " in state " + r.state
39173936
+ " resumed=" + mResumedActivity
39183937
+ " pausing=" + mPausingActivity);
3919-
destroyActivityLocked(r, true, oomAdj, reason);
3938+
if (destroyActivityLocked(r, true, oomAdj, reason)) {
3939+
activityRemoved = true;
3940+
}
39203941
}
39213942
}
3943+
if (activityRemoved) {
3944+
resumeTopActivityLocked(null);
3945+
}
39223946
}
39233947

39243948
/**
@@ -4023,23 +4047,28 @@ final boolean destroyActivityLocked(ActivityRecord r,
40234047

40244048
final void activityDestroyed(IBinder token) {
40254049
synchronized (mService) {
4026-
ActivityRecord r = ActivityRecord.forToken(token);
4027-
if (r != null) {
4028-
mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
4029-
}
4030-
4031-
int index = indexOfActivityLocked(r);
4032-
if (index >= 0) {
4033-
if (r.state == ActivityState.DESTROYING) {
4034-
final long origId = Binder.clearCallingIdentity();
4035-
removeActivityFromHistoryLocked(r);
4036-
Binder.restoreCallingIdentity(origId);
4050+
final long origId = Binder.clearCallingIdentity();
4051+
try {
4052+
ActivityRecord r = ActivityRecord.forToken(token);
4053+
if (r != null) {
4054+
mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
4055+
}
4056+
4057+
int index = indexOfActivityLocked(r);
4058+
if (index >= 0) {
4059+
if (r.state == ActivityState.DESTROYING) {
4060+
cleanUpActivityLocked(r, true, true);
4061+
removeActivityFromHistoryLocked(r);
4062+
}
40374063
}
4064+
resumeTopActivityLocked(null);
4065+
} finally {
4066+
Binder.restoreCallingIdentity(origId);
40384067
}
40394068
}
40404069
}
40414070

4042-
private static void removeHistoryRecordsForAppLocked(ArrayList list, ProcessRecord app) {
4071+
private void removeHistoryRecordsForAppLocked(ArrayList list, ProcessRecord app) {
40434072
int i = list.size();
40444073
if (localLOGV) Slog.v(
40454074
TAG, "Removing app " + app + " from list " + list
@@ -4052,6 +4081,7 @@ private static void removeHistoryRecordsForAppLocked(ArrayList list, ProcessReco
40524081
if (r.app == app) {
40534082
if (localLOGV) Slog.v(TAG, "Removing this entry!");
40544083
list.remove(i);
4084+
removeTimeoutsForActivityLocked(r);
40554085
}
40564086
}
40574087
}

0 commit comments

Comments
 (0)