Skip to content

Commit 293f861

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Activate Dreams (screen saver) when desk-docked." into ics-mr1
2 parents d5decdc + 532a0bb commit 293f861

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

packages/SystemUI/AndroidManifest.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@
4646
</intent-filter>
4747
</receiver>
4848

49-
<!-- handle dock insertion, launch screensaver instead -->
49+
<!-- should you need to launch the screensaver, this is a good way to do it -->
5050
<activity android:name=".DreamsDockLauncher"
5151
android:theme="@android:style/Theme.Dialog"
5252
android:label="@string/dreams_dock_launcher">
5353
<intent-filter>
5454
<action android:name="android.intent.action.MAIN" />
5555
<category android:name="android.intent.category.DEFAULT" />
56-
<category android:name="android.intent.category.DESK_DOCK" />
5756
</intent-filter>
5857
</activity>
5958

59+
<!-- launch screensaver on (desk) dock event -->
60+
<receiver android:name=".DreamsDockLauncher$DockEventReceiver"
61+
android:exported="true"
62+
>
63+
<intent-filter>
64+
<action android:name="android.intent.action.DOCK_EVENT" />
65+
</intent-filter>
66+
</receiver>
67+
68+
6069
<activity android:name=".usb.UsbStorageActivity"
6170
android:excludeFromRecents="true">
6271
</activity>

packages/SystemUI/src/com/android/systemui/DreamsDockLauncher.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@
1212

1313
public class DreamsDockLauncher extends Activity {
1414
private static final String TAG = "DreamsDockLauncher";
15+
16+
// Launch the screen saver if started as an activity.
1517
@Override
1618
protected void onCreate (Bundle icicle) {
1719
super.onCreate(icicle);
20+
launchDream(this);
21+
finish();
22+
}
23+
24+
private static void launchDream(Context context) {
1825
try {
1926
String component = Settings.Secure.getString(
20-
getContentResolver(), Settings.Secure.DREAM_COMPONENT);
27+
context.getContentResolver(), Settings.Secure.DREAM_COMPONENT);
2128
if (component == null) {
22-
component = getResources().getString(com.android.internal.R.string.config_defaultDreamComponent);
29+
component = context.getResources().getString(
30+
com.android.internal.R.string.config_defaultDreamComponent);
2331
}
2432
if (component != null) {
2533
ComponentName cn = ComponentName.unflattenFromString(component);
@@ -29,14 +37,31 @@ protected void onCreate (Bundle icicle) {
2937
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
3038
| Intent.FLAG_ACTIVITY_NO_USER_ACTION
3139
);
32-
startActivity(zzz);
40+
Slog.v(TAG, "Starting screen saver on dock event: " + component);
41+
context.startActivity(zzz);
3342
} else {
3443
Slog.e(TAG, "Couldn't start screen saver: none selected");
3544
}
3645
} catch (android.content.ActivityNotFoundException exc) {
3746
// no screensaver? give up
3847
Slog.e(TAG, "Couldn't start screen saver: none installed");
3948
}
40-
finish();
49+
}
50+
51+
// Trap low-level dock events and launch the screensaver.
52+
public static class DockEventReceiver extends BroadcastReceiver {
53+
@Override
54+
public void onReceive(Context context, Intent intent) {
55+
if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
56+
Bundle extras = intent.getExtras();
57+
int state = extras
58+
.getInt(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
59+
if (state == Intent.EXTRA_DOCK_STATE_DESK
60+
|| state == Intent.EXTRA_DOCK_STATE_LE_DESK
61+
|| state == Intent.EXTRA_DOCK_STATE_HE_DESK) {
62+
launchDream(context);
63+
}
64+
}
65+
}
4166
}
4267
}

0 commit comments

Comments
 (0)