Skip to content

Commit 69a1da4

Browse files
committed
Teach UiModeMgr about high-end and low-end desk docks.
Should fix dock mode on Stingray, since its docks advertise themselves as EXTRA_DOCK_STATE_LE_DESK and EXTRA_DOCK_STATE_HE_DESK but not EXTRA_DOCK_STATE_DESK. Bug: 5569662 Change-Id: I93197665c0df8dea06ca8fadae97ec267c751c85
1 parent 45a04db commit 69a1da4

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

services/java/com/android/server/UiModeManagerService.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ static Intent buildHomeIntent(String category) {
123123
@Override
124124
public void onReceive(Context context, Intent intent) {
125125
if (getResultCode() != Activity.RESULT_OK) {
126+
if (LOG) {
127+
Slog.v(TAG, "Handling broadcast result for action " + intent.getAction()
128+
+ ": canceled: " + getResultCode());
129+
}
126130
return;
127131
}
128132

@@ -151,6 +155,12 @@ public void onReceive(Context context, Intent intent) {
151155
category = Intent.CATEGORY_HOME;
152156
}
153157
}
158+
159+
if (LOG) {
160+
Slog.v(TAG, String.format(
161+
"Handling broadcast result for action %s: enable=0x%08x disable=0x%08x category=%s",
162+
intent.getAction(), enableFlags, disableFlags, category));
163+
}
154164

155165
if (category != null) {
156166
// This is the new activity that will serve as home while
@@ -424,11 +434,22 @@ void updateDockState(int newState) {
424434
}
425435
}
426436

437+
final static boolean isDeskDockState(int state) {
438+
switch (state) {
439+
case Intent.EXTRA_DOCK_STATE_DESK:
440+
case Intent.EXTRA_DOCK_STATE_LE_DESK:
441+
case Intent.EXTRA_DOCK_STATE_HE_DESK:
442+
return true;
443+
default:
444+
return false;
445+
}
446+
}
447+
427448
final void updateConfigurationLocked(boolean sendIt) {
428449
int uiMode = Configuration.UI_MODE_TYPE_NORMAL;
429450
if (mCarModeEnabled) {
430451
uiMode = Configuration.UI_MODE_TYPE_CAR;
431-
} else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK) {
452+
} else if (isDeskDockState(mDockState)) {
432453
uiMode = Configuration.UI_MODE_TYPE_DESK;
433454
}
434455
if (mCarModeEnabled) {
@@ -477,7 +498,7 @@ final void updateLocked(int enableFlags, int disableFlags) {
477498
if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
478499
adjustStatusBarCarModeLocked();
479500
oldAction = UiModeManager.ACTION_EXIT_CAR_MODE;
480-
} else if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_DESK) {
501+
} else if (isDeskDockState(mLastBroadcastState)) {
481502
oldAction = UiModeManager.ACTION_EXIT_DESK_MODE;
482503
}
483504

@@ -491,12 +512,12 @@ final void updateLocked(int enableFlags, int disableFlags) {
491512
mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR;
492513
action = UiModeManager.ACTION_ENTER_CAR_MODE;
493514
}
494-
} else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK) {
495-
if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_DESK) {
515+
} else if (isDeskDockState(mDockState)) {
516+
if (!isDeskDockState(mLastBroadcastState)) {
496517
if (oldAction != null) {
497518
mContext.sendBroadcast(new Intent(oldAction));
498519
}
499-
mLastBroadcastState = Intent.EXTRA_DOCK_STATE_DESK;
520+
mLastBroadcastState = mDockState;
500521
action = UiModeManager.ACTION_ENTER_DESK_MODE;
501522
}
502523
} else {
@@ -505,6 +526,12 @@ final void updateLocked(int enableFlags, int disableFlags) {
505526
}
506527

507528
if (action != null) {
529+
if (LOG) {
530+
Slog.v(TAG, String.format(
531+
"updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x",
532+
action, enableFlags, disableFlags));
533+
}
534+
508535
// Send the ordered broadcast; the result receiver will receive after all
509536
// broadcasts have been sent. If any broadcast receiver changes the result
510537
// code from the initial value of RESULT_OK, then the result receiver will
@@ -526,7 +553,7 @@ final void updateLocked(int enableFlags, int disableFlags) {
526553
if ((enableFlags&UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
527554
homeIntent = buildHomeIntent(Intent.CATEGORY_CAR_DOCK);
528555
}
529-
} else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK) {
556+
} else if (isDeskDockState(mDockState)) {
530557
if ((enableFlags&UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
531558
homeIntent = buildHomeIntent(Intent.CATEGORY_DESK_DOCK);
532559
}
@@ -535,6 +562,12 @@ final void updateLocked(int enableFlags, int disableFlags) {
535562
homeIntent = buildHomeIntent(Intent.CATEGORY_HOME);
536563
}
537564
}
565+
566+
if (LOG) {
567+
Slog.v(TAG, "updateLocked: null action, mDockState="
568+
+ mDockState +", firing homeIntent: " + homeIntent);
569+
}
570+
538571
if (homeIntent != null) {
539572
try {
540573
mContext.startActivity(homeIntent);

0 commit comments

Comments
 (0)