diff --git a/api/current.xml b/api/current.xml index fe48625d7d853..bb4a0561e03dc 100644 --- a/api/current.xml +++ b/api/current.xml @@ -35178,6 +35178,17 @@ visibility="public" > + + + + + + + + + + + + + + {@link #CATEGORY_HOME} *
  • {@link #CATEGORY_PREFERENCE} *
  • {@link #CATEGORY_TEST} + *
  • {@link #CATEGORY_CAR_DOCK} + *
  • {@link #CATEGORY_DESK_DOCK} * * *

    Standard Extra Data

    @@ -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 30c25e0ba8672..60195b9e577ba 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()); + } + } } } };