summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
authorWonsik Kim <wonsik@google.com>2014-07-18 02:19:12 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-07-17 21:11:29 +0000
commit61635036ac29012a45715effcf60b3c395f05f17 (patch)
treed7eb4a31cccf17cc2c98131f3ec5f22fe0810c27 /media/java
parentca58ddf7c82dd0857de0c3d49d7eb87a842ee4ce (diff)
parent187423c0bc4b27479bc8c23bd86969429094b296 (diff)
downloadframeworks_base-61635036ac29012a45715effcf60b3c395f05f17.zip
frameworks_base-61635036ac29012a45715effcf60b3c395f05f17.tar.gz
frameworks_base-61635036ac29012a45715effcf60b3c395f05f17.tar.bz2
Merge "TIF: one-to-many relationship for TvInputService to TvInputInfo" into lmp-dev
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/tv/ITvInputService.aidl8
-rw-r--r--media/java/android/media/tv/ITvInputServiceCallback.aidl9
-rw-r--r--media/java/android/media/tv/TvInputInfo.java78
-rw-r--r--media/java/android/media/tv/TvInputService.java100
4 files changed, 181 insertions, 14 deletions
diff --git a/media/java/android/media/tv/ITvInputService.aidl b/media/java/android/media/tv/ITvInputService.aidl
index 992e424..158223a 100644
--- a/media/java/android/media/tv/ITvInputService.aidl
+++ b/media/java/android/media/tv/ITvInputService.aidl
@@ -18,6 +18,7 @@ package android.media.tv;
import android.media.tv.ITvInputServiceCallback;
import android.media.tv.ITvInputSessionCallback;
+import android.media.tv.TvInputHardwareInfo;
import android.view.InputChannel;
/**
@@ -27,5 +28,10 @@ import android.view.InputChannel;
oneway interface ITvInputService {
void registerCallback(ITvInputServiceCallback callback);
void unregisterCallback(in ITvInputServiceCallback callback);
- void createSession(in InputChannel channel, ITvInputSessionCallback callback);
+ void createSession(in InputChannel channel, ITvInputSessionCallback callback,
+ in String inputId);
+
+ // For hardware TvInputService
+ void notifyHardwareAdded(in TvInputHardwareInfo info);
+ void notifyHardwareRemoved(int deviceId);
}
diff --git a/media/java/android/media/tv/ITvInputServiceCallback.aidl b/media/java/android/media/tv/ITvInputServiceCallback.aidl
index 1fdb8c5..287da71 100644
--- a/media/java/android/media/tv/ITvInputServiceCallback.aidl
+++ b/media/java/android/media/tv/ITvInputServiceCallback.aidl
@@ -16,13 +16,14 @@
package android.media.tv;
-import android.content.ComponentName;
+import android.media.tv.TvInputInfo;
/**
- * Helper interface for ITvInputService to allow the TV input to notify the client when its status
- * has been changed.
+ * Helper interface for ITvInputService to allow the service to notify the
+ * TvInputManagerService.
* @hide
*/
oneway interface ITvInputServiceCallback {
- void onInputStateChanged(int state);
+ void addTvInput(in TvInputInfo inputInfo);
+ void removeTvInput(in String inputId);
}
diff --git a/media/java/android/media/tv/TvInputInfo.java b/media/java/android/media/tv/TvInputInfo.java
index 37f166b..8cd2f9b1 100644
--- a/media/java/android/media/tv/TvInputInfo.java
+++ b/media/java/android/media/tv/TvInputInfo.java
@@ -27,6 +27,8 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
+import android.hardware.hdmi.HdmiCecDeviceInfo;
+import android.media.tv.TvInputHardwareInfo;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -88,9 +90,46 @@ public final class TvInputInfo implements Parcelable {
* instantiating it from the given Context and ResolveInfo.
*
* @param service The ResolveInfo returned from the package manager about this TV input service.
- * @hide */
+ * @hide
+ */
public static TvInputInfo createTvInputInfo(Context context, ResolveInfo service)
throws XmlPullParserException, IOException {
+ return createTvInputInfo(context, service, generateInputIdForComponentName(
+ new ComponentName(service.serviceInfo.packageName, service.serviceInfo.name)));
+ }
+
+ /**
+ * Create a new instance of the TvInputInfo class,
+ * instantiating it from the given Context, ResolveInfo, and HdmiCecDeviceInfo.
+ *
+ * @param service The ResolveInfo returned from the package manager about this TV input service.
+ * @param cecInfo The HdmiCecDeviceInfo for a HDMI CEC logical device.
+ * @hide
+ */
+ public static TvInputInfo createTvInputInfo(Context context, ResolveInfo service,
+ HdmiCecDeviceInfo cecInfo) throws XmlPullParserException, IOException {
+ return createTvInputInfo(context, service, generateInputIdForHdmiCec(
+ new ComponentName(service.serviceInfo.packageName, service.serviceInfo.name),
+ cecInfo));
+ }
+
+ /**
+ * Create a new instance of the TvInputInfo class,
+ * instantiating it from the given Context, ResolveInfo, and TvInputHardwareInfo.
+ *
+ * @param service The ResolveInfo returned from the package manager about this TV input service.
+ * @param hardwareInfo The TvInputHardwareInfo for a TV input hardware device.
+ * @hide
+ */
+ public static TvInputInfo createTvInputInfo(Context context, ResolveInfo service,
+ TvInputHardwareInfo hardwareInfo) throws XmlPullParserException, IOException {
+ return createTvInputInfo(context, service, generateInputIdForHardware(
+ new ComponentName(service.serviceInfo.packageName, service.serviceInfo.name),
+ hardwareInfo));
+ }
+
+ private static TvInputInfo createTvInputInfo(Context context, ResolveInfo service,
+ String id) throws XmlPullParserException, IOException {
ServiceInfo si = service.serviceInfo;
PackageManager pm = context.getPackageManager();
XmlResourceParser parser = null;
@@ -115,7 +154,7 @@ public final class TvInputInfo implements Parcelable {
"Meta-data does not start with tv-input-service tag in " + si.name);
}
- TvInputInfo input = new TvInputInfo(context, service, null);
+ TvInputInfo input = new TvInputInfo(context, service, id, null);
TypedArray sa = res.obtainAttributes(attrs,
com.android.internal.R.styleable.TvInputService);
input.mSetupActivity = sa.getString(
@@ -153,12 +192,13 @@ public final class TvInputInfo implements Parcelable {
* Constructor.
*
* @param service The ResolveInfo returned from the package manager about this TV input service.
- * @hide
+ * @param id ID of this TV input. Should be generated via generateInputId*().
+ * @param parentId ID of this TV input's parent input. {@code null} if none exists.
*/
- private TvInputInfo(Context context, ResolveInfo service, String parentId) {
+ private TvInputInfo(Context context, ResolveInfo service, String id, String parentId) {
mService = service;
ServiceInfo si = service.serviceInfo;
- mId = generateInputIdForComponentName(new ComponentName(si.packageName, si.name));
+ mId = id;
mParentId = parentId;
}
@@ -311,13 +351,37 @@ public final class TvInputInfo implements Parcelable {
*
* @param name the component name for generating an input id.
* @return the generated input id for the given {@code name}.
- * @hide
*/
- public static final String generateInputIdForComponentName(ComponentName name) {
+ private static final String generateInputIdForComponentName(ComponentName name) {
return name.flattenToShortString();
}
/**
+ * Used to generate an input id from a ComponentName and HdmiCecDeviceInfo.
+ *
+ * @param name the component name for generating an input id.
+ * @param cecInfo HdmiCecDeviceInfo describing this TV input.
+ * @return the generated input id for the given {@code name} and {@code cecInfo}.
+ */
+ private static final String generateInputIdForHdmiCec(
+ ComponentName name, HdmiCecDeviceInfo cecInfo) {
+ return name.flattenToShortString() + String.format("|CEC%08X%08X",
+ cecInfo.getPhysicalAddress(), cecInfo.getLogicalAddress());
+ }
+
+ /**
+ * Used to generate an input id from a ComponentName and TvInputHardwareInfo
+ *
+ * @param name the component name for generating an input id.
+ * @param hardwareInfo TvInputHardwareInfo describing this TV input.
+ * @return the generated input id for the given {@code name} and {@code hardwareInfo}.
+ */
+ private static final String generateInputIdForHardware(
+ ComponentName name, TvInputHardwareInfo hardwareInfo) {
+ return name.flattenToShortString() + String.format("|HW%d", hardwareInfo.getDeviceId());
+ }
+
+ /**
* Used to make this class parcelable.
*
* @hide
diff --git a/media/java/android/media/tv/TvInputService.java b/media/java/android/media/tv/TvInputService.java
index 3206320..32cf5da 100644
--- a/media/java/android/media/tv/TvInputService.java
+++ b/media/java/android/media/tv/TvInputService.java
@@ -17,6 +17,7 @@
package android.media.tv;
import android.annotation.SuppressLint;
+import android.annotation.SystemApi;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
@@ -104,7 +105,8 @@ public abstract class TvInputService extends Service {
}
@Override
- public void createSession(InputChannel channel, ITvInputSessionCallback cb) {
+ public void createSession(InputChannel channel, ITvInputSessionCallback cb,
+ String inputId) {
if (channel == null) {
Log.w(TAG, "Creating session without input channel");
}
@@ -114,8 +116,21 @@ public abstract class TvInputService extends Service {
SomeArgs args = SomeArgs.obtain();
args.arg1 = channel;
args.arg2 = cb;
+ args.arg3 = inputId;
mHandler.obtainMessage(ServiceHandler.DO_CREATE_SESSION, args).sendToTarget();
}
+
+ @Override
+ public void notifyHardwareAdded(TvInputHardwareInfo hardwareInfo) {
+ mHandler.obtainMessage(ServiceHandler.DO_ADD_TV_INPUT_FROM_HARDWARE,
+ hardwareInfo).sendToTarget();
+ }
+
+ @Override
+ public void notifyHardwareRemoved(int deviceId) {
+ mHandler.obtainMessage(ServiceHandler.DO_REMOVE_TV_INPUT_FROM_HARDWARE,
+ deviceId, 0).sendToTarget();
+ }
};
}
@@ -138,6 +153,44 @@ public abstract class TvInputService extends Service {
public abstract Session onCreateSession();
/**
+ * Returns a concrete implementation of {@link Session}.
+ * <p>
+ * May return {@code null} if this TV input service fails to create a session for some reason.
+ * </p>
+ * @param inputId The ID of the TV input associated with the session.
+ *
+ * @hide
+ */
+ @SystemApi
+ public Session onCreateSession(String inputId) {
+ return onCreateSession();
+ }
+
+ /**
+ * Returns a new TvInputInfo object if this service is responsible for {@code hardwareInfo};
+ * otherwise, return {@code null}. Override to modify default behavior of ignoring all input.
+ *
+ * @param hardwareInfo TvInputHardwareInfo object just added.
+ *
+ * @hide
+ */
+ @SystemApi
+ public TvInputInfo onHardwareAdded(TvInputHardwareInfo hardwareInfo) {
+ return null;
+ }
+
+ /**
+ * Returns the input ID for {@code deviceId} if it is handled by this service;
+ * otherwise, return {@code null}. Override to modify default behavior of ignoring all input.
+ *
+ * @hide
+ */
+ @SystemApi
+ public String onHardwareRemoved(int deviceId) {
+ return null;
+ }
+
+ /**
* Base class for derived classes to implement to provide a TV input session.
*/
public abstract class Session implements KeyEvent.Callback {
@@ -715,6 +768,32 @@ public abstract class TvInputService extends Service {
@SuppressLint("HandlerLeak")
private final class ServiceHandler extends Handler {
private static final int DO_CREATE_SESSION = 1;
+ private static final int DO_ADD_TV_INPUT_FROM_HARDWARE = 2;
+ private static final int DO_REMOVE_TV_INPUT_FROM_HARDWARE = 3;
+
+ private void broadcastAddTvInput(TvInputInfo inputInfo) {
+ int n = mCallbacks.beginBroadcast();
+ for (int i = 0; i < n; ++i) {
+ try {
+ mCallbacks.getBroadcastItem(i).addTvInput(inputInfo);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error while broadcasting: " + e);
+ }
+ }
+ mCallbacks.finishBroadcast();
+ }
+
+ private void broadcastRemoveTvInput(String inputId) {
+ int n = mCallbacks.beginBroadcast();
+ for (int i = 0; i < n; ++i) {
+ try {
+ mCallbacks.getBroadcastItem(i).removeTvInput(inputId);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error while broadcasting: " + e);
+ }
+ }
+ mCallbacks.finishBroadcast();
+ }
@Override
public final void handleMessage(Message msg) {
@@ -723,8 +802,9 @@ public abstract class TvInputService extends Service {
SomeArgs args = (SomeArgs) msg.obj;
InputChannel channel = (InputChannel) args.arg1;
ITvInputSessionCallback cb = (ITvInputSessionCallback) args.arg2;
+ String inputId = (String) args.arg3;
try {
- Session sessionImpl = onCreateSession();
+ Session sessionImpl = onCreateSession(inputId);
if (sessionImpl == null) {
// Failed to create a session.
cb.onSessionCreated(null);
@@ -740,6 +820,22 @@ public abstract class TvInputService extends Service {
args.recycle();
return;
}
+ case DO_ADD_TV_INPUT_FROM_HARDWARE: {
+ TvInputHardwareInfo hardwareInfo = (TvInputHardwareInfo) msg.obj;
+ TvInputInfo inputInfo = onHardwareAdded(hardwareInfo);
+ if (inputInfo != null) {
+ broadcastAddTvInput(inputInfo);
+ }
+ return;
+ }
+ case DO_REMOVE_TV_INPUT_FROM_HARDWARE: {
+ int deviceId = msg.arg1;
+ String inputId = onHardwareRemoved(deviceId);
+ if (inputId != null) {
+ broadcastRemoveTvInput(inputId);
+ }
+ return;
+ }
default: {
Log.w(TAG, "Unhandled message code: " + msg.what);
return;