summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2009-09-16 13:01:32 -0400
committerMike Lockwood <lockwood@android.com>2009-09-16 14:43:21 -0400
commit9092ab4d458ad60b459d5fad52368bde5d25f665 (patch)
tree3c96a0fe1bc09770934b18f15a4bc293e5d06572
parent764916d01b779ccc8064946c6ba2962fe063ed86 (diff)
downloadframeworks_base-9092ab4d458ad60b459d5fad52368bde5d25f665.zip
frameworks_base-9092ab4d458ad60b459d5fad52368bde5d25f665.tar.gz
frameworks_base-9092ab4d458ad60b459d5fad52368bde5d25f665.tar.bz2
Add support for launching activities when attaching to a car or desk dock.
Categories CATEGORY_CAR_DOCK and CATEGORY_DESK_DOCK can be assigned to activities to make them launchable on docked events. This is a better mechanism than listening for ACTION_DOCK_EVENT with a broadcast receiver. Change-Id: Ic5f3ab3555ce02ca922bc31ebba41978cefe8bda Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r--api/current.xml77
-rw-r--r--core/java/android/content/Intent.java25
-rw-r--r--services/java/com/android/server/DockObserver.java25
3 files changed, 122 insertions, 5 deletions
diff --git a/api/current.xml b/api/current.xml
index e438f6e..1713533 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -35178,6 +35178,17 @@
visibility="public"
>
</field>
+<field name="ACTION_DOCK_EVENT"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.intent.action.DOCK_EVENT&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="ACTION_EDIT"
type="java.lang.String"
transient="false"
@@ -35893,6 +35904,17 @@
visibility="public"
>
</field>
+<field name="CATEGORY_CAR_DOCK"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.intent.category.CAR_DOCK&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="CATEGORY_DEFAULT"
type="java.lang.String"
transient="false"
@@ -35904,6 +35926,17 @@
visibility="public"
>
</field>
+<field name="CATEGORY_DESK_DOCK"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.intent.category.DESK_DOCK&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="CATEGORY_DEVELOPMENT_PREFERENCE"
type="java.lang.String"
transient="false"
@@ -36123,6 +36156,50 @@
visibility="public"
>
</field>
+<field name="EXTRA_DOCK_STATE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.intent.extra.DOCK_STATE&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_DOCK_STATE_CAR"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="2"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_DOCK_STATE_DESK"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="EXTRA_DOCK_STATE_UNDOCKED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="EXTRA_DONT_KILL_APP"
type="java.lang.String"
transient="false"
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index c053ace..fc977c8 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -529,6 +529,8 @@ import java.util.Set;
* <li> {@link #CATEGORY_HOME}
* <li> {@link #CATEGORY_PREFERENCE}
* <li> {@link #CATEGORY_TEST}
+ * <li> {@link #CATEGORY_CAR_DOCK}
+ * <li> {@link #CATEGORY_DESK_DOCK}
* </ul>
*
* <h3>Standard Extra Data</h3>
@@ -1861,12 +1863,29 @@ public class Intent implements Parcelable {
*/
public static final String CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST =
"android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
+ /**
+ * An activity to run when device is inserted into a car dock.
+ * Used with {@link #ACTION_MAIN} to launch an activity.
+ * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
+ */
+ @SdkConstant(SdkConstantType.INTENT_CATEGORY)
+ public static final String CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
+ /**
+ * An activity to run when device is inserted into a car dock.
+ * Used with {@link #ACTION_MAIN} to launch an activity.
+ * To monitor dock state, use {@link #ACTION_DOCK_EVENT} instead.
+ */
+ @SdkConstant(SdkConstantType.INTENT_CATEGORY)
+ public static final String CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";
/**
* Broadcast Action: The phone was docked or undocked. Includes the extra
* field {@link #EXTRA_DOCK_STATE}, containing the current dock state.
- * @hide
+ * This is intended for monitoring the current dock state.
+ * To launch an activity from a dock state change, use {@link #CATEGORY_CAR_DOCK}
+ * or {@link #CATEGORY_DESK_DOCK} instead.
*/
+ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_DOCK_EVENT = "android.intent.action.DOCK_EVENT";
// ---------------------------------------------------------------------
@@ -2005,28 +2024,24 @@ public class Intent implements Parcelable {
* {@link android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED},
* {@link android.content.Intent#EXTRA_DOCK_STATE_DESK}, or
* {@link android.content.Intent#EXTRA_DOCK_STATE_CAR}.
- * @hide
*/
public static final String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
/**
* Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
* to represent that the phone is not in any dock.
- * @hide
*/
public static final int EXTRA_DOCK_STATE_UNDOCKED = 0;
/**
* Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
* to represent that the phone is in a desk dock.
- * @hide
*/
public static final int EXTRA_DOCK_STATE_DESK = 1;
/**
* Used as an int value for {@link android.content.Intent#EXTRA_DOCK_STATE}
* to represent that the phone is in a car dock.
- * @hide
*/
public static final int EXTRA_DOCK_STATE_CAR = 2;
diff --git a/services/java/com/android/server/DockObserver.java b/services/java/com/android/server/DockObserver.java
index 30c25e0..60195b9 100644
--- a/services/java/com/android/server/DockObserver.java
+++ b/services/java/com/android/server/DockObserver.java
@@ -16,6 +16,7 @@
package com.android.server;
+import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
@@ -111,6 +112,30 @@ class DockObserver extends UEventObserver {
Intent intent = new Intent(Intent.ACTION_DOCK_EVENT);
intent.putExtra(Intent.EXTRA_DOCK_STATE, mDockState);
mContext.sendStickyBroadcast(intent);
+
+ // Launch a dock activity
+ String category;
+ switch (mDockState) {
+ case Intent.EXTRA_DOCK_STATE_CAR:
+ category = Intent.CATEGORY_CAR_DOCK;
+ break;
+ case Intent.EXTRA_DOCK_STATE_DESK:
+ category = Intent.CATEGORY_DESK_DOCK;
+ break;
+ default:
+ category = null;
+ break;
+ }
+ if (category != null) {
+ intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(category);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ mContext.startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, e.getCause());
+ }
+ }
}
}
};