Skip to content

Commit 010bb27

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge changes I0da0f04f,I93197665 into ics-mr1
* changes: Offer the user an option to launch Dreams when docked. Teach UiModeMgr about high-end and low-end desk docks.
2 parents 064975c + 221733a commit 010bb27

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

packages/SystemUI/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
</intent-filter>
4747
</receiver>
4848

49+
<!-- handle dock insertion, launch screensaver instead -->
50+
<activity android:name=".DreamsDockLauncher"
51+
android:label="@string/dreams_dock_launcher">
52+
<intent-filter>
53+
<action android:name="android.intent.action.MAIN" />
54+
<category android:name="android.intent.category.DEFAULT" />
55+
<category android:name="android.intent.category.DESK_DOCK" />
56+
</intent-filter>
57+
</activity>
58+
4959
<activity android:name=".usb.UsbStorageActivity"
5060
android:excludeFromRecents="true">
5161
</activity>

packages/SystemUI/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,7 @@
351351

352352
<!-- Content description of the clear button in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
353353
<string name="accessibility_clear_all">Clear all notifications.</string>
354+
355+
<!-- Description of the desk dock action that invokes the Android Dreams screen saver feature -->
356+
<string name="dreams_dock_launcher">Activate screen saver</string>
354357
</resources>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.android.systemui;
2+
3+
import android.app.Activity;
4+
import android.content.BroadcastReceiver;
5+
import android.content.ComponentName;
6+
import android.content.ContentResolver;
7+
import android.content.Context;
8+
import android.content.Intent;
9+
import android.os.Bundle;
10+
import android.provider.Settings;
11+
import android.util.Slog;
12+
13+
public class DreamsDockLauncher extends Activity {
14+
private static final String TAG = "DreamsDockLauncher";
15+
@Override
16+
protected void onCreate (Bundle icicle) {
17+
super.onCreate(icicle);
18+
try {
19+
String component = Settings.Secure.getString(
20+
getContentResolver(), Settings.Secure.DREAM_COMPONENT);
21+
if (component != null) {
22+
ComponentName cn = ComponentName.unflattenFromString(component);
23+
Intent zzz = new Intent(Intent.ACTION_MAIN)
24+
.setComponent(cn)
25+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
26+
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
27+
| Intent.FLAG_ACTIVITY_NO_USER_ACTION
28+
);
29+
startActivity(zzz);
30+
} else {
31+
Slog.e(TAG, "Couldn't start screen saver: none selected");
32+
}
33+
} catch (android.content.ActivityNotFoundException exc) {
34+
// no screensaver? give up
35+
Slog.e(TAG, "Couldn't start screen saver: none installed");
36+
}
37+
finish();
38+
}
39+
}

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)