diff options
author | Mike Lockwood <lockwood@android.com> | 2011-03-14 18:24:35 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-03-14 20:10:47 -0400 |
commit | 015b1ecaec27b7cf5f1a78099d9ae34a0c3169f2 (patch) | |
tree | 3b7a7bca14b9579c6fe647696d4623ad8acb8c71 | |
parent | 9f3f36c95b87aab2c5f7cd6b6e18927f8ebfa9c4 (diff) | |
download | frameworks_base-015b1ecaec27b7cf5f1a78099d9ae34a0c3169f2.zip frameworks_base-015b1ecaec27b7cf5f1a78099d9ae34a0c3169f2.tar.gz frameworks_base-015b1ecaec27b7cf5f1a78099d9ae34a0c3169f2.tar.bz2 |
Add support for USB accessory serial numbers
Change-Id: I47b79f091b300ced60bfc61eff2f771139663aae
Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r-- | api/current.xml | 13 | ||||
-rw-r--r-- | core/java/android/hardware/usb/UsbAccessory.java | 29 | ||||
-rw-r--r-- | libs/usb/src/com/android/future/usb/UsbAccessory.java | 24 | ||||
-rw-r--r-- | libs/usb/src/com/android/future/usb/UsbManager.java | 9 | ||||
-rw-r--r-- | libs/usb/tests/AccessoryChat/Android.mk | 2 | ||||
-rw-r--r-- | libs/usb/tests/AccessoryChat/AndroidManifest.xml | 2 | ||||
-rw-r--r-- | libs/usb/tests/AccessoryChat/accessorychat/accessorychat.c | 13 | ||||
-rw-r--r-- | libs/usb/tests/AccessoryChat/src/com/android/accessorychat/AccessoryChat.java | 3 | ||||
-rw-r--r-- | services/jni/com_android_server_UsbService.cpp | 3 |
9 files changed, 81 insertions, 17 deletions
diff --git a/api/current.xml b/api/current.xml index 5bc2dd3..76185a6 100644 --- a/api/current.xml +++ b/api/current.xml @@ -94459,6 +94459,17 @@ visibility="public" > </method> +<method name="getSerial" + return="java.lang.String" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="getUri" return="java.lang.String" abstract="false" @@ -267042,7 +267053,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="arg0" type="T"> +<parameter name="t" type="T"> </parameter> </method> </interface> diff --git a/core/java/android/hardware/usb/UsbAccessory.java b/core/java/android/hardware/usb/UsbAccessory.java index cc174d4..5e9ead0 100644 --- a/core/java/android/hardware/usb/UsbAccessory.java +++ b/core/java/android/hardware/usb/UsbAccessory.java @@ -33,18 +33,20 @@ public class UsbAccessory implements Parcelable { private final String mDescription; private final String mVersion; private final String mUri; + private final String mSerial; /** * UsbAccessory should only be instantiated by UsbService implementation * @hide */ public UsbAccessory(String manufacturer, String model, String description, - String version, String uri) { + String version, String uri, String serial) { mManufacturer = manufacturer; mModel = model; mDescription = description; mVersion = version; mUri = uri; + mSerial = serial; } /** @@ -57,6 +59,7 @@ public class UsbAccessory implements Parcelable { mDescription = strings[2]; mVersion = strings[3]; mUri = strings[4]; + mSerial = strings[5]; } /** @@ -106,6 +109,17 @@ public class UsbAccessory implements Parcelable { return mUri; } + /** + * Returns the unique serial number for the accessory. + * This is an optional serial number that can be used to differentiate + * between individual accessories of the same model and manufacturer + * + * @return the unique serial number + */ + public String getSerial() { + return mSerial; + } + private static boolean compare(String s1, String s2) { if (s1 == null) return (s2 == null); return s1.equals(s2); @@ -119,7 +133,8 @@ public class UsbAccessory implements Parcelable { compare(mModel, accessory.getModel()) && compare(mDescription, accessory.getDescription()) && compare(mVersion, accessory.getVersion()) && - compare(mUri, accessory.getUri())); + compare(mUri, accessory.getUri()) && + compare(mSerial, accessory.getSerial())); } return false; } @@ -130,7 +145,8 @@ public class UsbAccessory implements Parcelable { (mModel == null ? 0 : mModel.hashCode()) ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ - (mUri == null ? 0 : mUri.hashCode())); + (mUri == null ? 0 : mUri.hashCode()) ^ + (mSerial == null ? 0 : mSerial.hashCode())); } @Override @@ -139,7 +155,8 @@ public class UsbAccessory implements Parcelable { ", mModel=" + mModel + ", mDescription=" + mDescription + ", mVersion=" + mVersion + - ", mUri=" + mUri + "]"; + ", mUri=" + mUri + + ", mSerial=" + mSerial + "]"; } public static final Parcelable.Creator<UsbAccessory> CREATOR = @@ -150,7 +167,8 @@ public class UsbAccessory implements Parcelable { String description = in.readString(); String version = in.readString(); String uri = in.readString(); - return new UsbAccessory(manufacturer, model, description, version, uri); + String serial = in.readString(); + return new UsbAccessory(manufacturer, model, description, version, uri, serial); } public UsbAccessory[] newArray(int size) { @@ -168,5 +186,6 @@ public class UsbAccessory implements Parcelable { parcel.writeString(mDescription); parcel.writeString(mVersion); parcel.writeString(mUri); + parcel.writeString(mSerial); } } diff --git a/libs/usb/src/com/android/future/usb/UsbAccessory.java b/libs/usb/src/com/android/future/usb/UsbAccessory.java index 3d0707f..0f965d7 100644 --- a/libs/usb/src/com/android/future/usb/UsbAccessory.java +++ b/libs/usb/src/com/android/future/usb/UsbAccessory.java @@ -19,13 +19,14 @@ package com.android.future.usb; /** * A class representing a USB accessory. */ -public final class UsbAccessory { +public class UsbAccessory { private final String mManufacturer; private final String mModel; private final String mDescription; private final String mVersion; private final String mUri; + private final String mSerial; /* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) { mManufacturer = accessory.getManufacturer(); @@ -33,6 +34,7 @@ public final class UsbAccessory { mDescription = accessory.getDescription(); mVersion = accessory.getVersion(); mUri = accessory.getUri(); + mSerial = accessory.getSerial(); } /** @@ -82,6 +84,17 @@ public final class UsbAccessory { return mUri; } + /** + * Returns the unique serial number for the accessory. + * This is an optional serial number that can be used to differentiate + * between individual accessories of the same model and manufacturer + * + * @return the unique serial number + */ + public String getSerial() { + return mSerial; + } + private static boolean compare(String s1, String s2) { if (s1 == null) return (s2 == null); return s1.equals(s2); @@ -95,7 +108,8 @@ public final class UsbAccessory { compare(mModel, accessory.getModel()) && compare(mDescription, accessory.getDescription()) && compare(mVersion, accessory.getVersion()) && - compare(mUri, accessory.getUri())); + compare(mUri, accessory.getUri()) && + compare(mSerial, accessory.getSerial())); } return false; } @@ -106,7 +120,8 @@ public final class UsbAccessory { (mModel == null ? 0 : mModel.hashCode()) ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ - (mUri == null ? 0 : mUri.hashCode())); + (mUri == null ? 0 : mUri.hashCode()) ^ + (mSerial == null ? 0 : mSerial.hashCode())); } @Override @@ -115,6 +130,7 @@ public final class UsbAccessory { ", mModel=" + mModel + ", mDescription=" + mDescription + ", mVersion=" + mVersion + - ", mUri=" + mUri + "]"; + ", mUri=" + mUri + + ", mSerial=" + mSerial + "]"; } } diff --git a/libs/usb/src/com/android/future/usb/UsbManager.java b/libs/usb/src/com/android/future/usb/UsbManager.java index 840e1e3..d424b63 100644 --- a/libs/usb/src/com/android/future/usb/UsbManager.java +++ b/libs/usb/src/com/android/future/usb/UsbManager.java @@ -130,7 +130,8 @@ public class UsbManager { try { return mService.openAccessory(new android.hardware.usb.UsbAccessory( accessory.getManufacturer(),accessory.getModel(), - accessory.getDescription(), accessory.getVersion(), accessory.getUri())); + accessory.getDescription(), accessory.getVersion(), + accessory.getUri(), accessory.getSerial())); } catch (RemoteException e) { Log.e(TAG, "RemoteException in openAccessory" , e); return null; @@ -150,7 +151,8 @@ public class UsbManager { try { return mService.hasAccessoryPermission(new android.hardware.usb.UsbAccessory( accessory.getManufacturer(),accessory.getModel(), - accessory.getDescription(), accessory.getVersion(), accessory.getUri())); + accessory.getDescription(), accessory.getVersion(), + accessory.getUri(), accessory.getSerial())); } catch (RemoteException e) { Log.e(TAG, "RemoteException in hasPermission", e); return false; @@ -174,7 +176,8 @@ public class UsbManager { try { mService.requestAccessoryPermission(new android.hardware.usb.UsbAccessory( accessory.getManufacturer(),accessory.getModel(), - accessory.getDescription(), accessory.getVersion(), accessory.getUri()), + accessory.getDescription(), accessory.getVersion(), + accessory.getUri(), accessory.getSerial()), mContext.getPackageName(), pi); } catch (RemoteException e) { Log.e(TAG, "RemoteException in requestPermission", e); diff --git a/libs/usb/tests/AccessoryChat/Android.mk b/libs/usb/tests/AccessoryChat/Android.mk index d555961..77b8424 100644 --- a/libs/usb/tests/AccessoryChat/Android.mk +++ b/libs/usb/tests/AccessoryChat/Android.mk @@ -21,7 +21,7 @@ LOCAL_MODULE_TAGS := tests LOCAL_SRC_FILES := $(call all-subdir-java-files) -LOCAL_PACKAGE_NAME := AccessoryChatGB +LOCAL_PACKAGE_NAME := AccessoryChat LOCAL_JAVA_LIBRARIES := com.android.future.usb.accessory diff --git a/libs/usb/tests/AccessoryChat/AndroidManifest.xml b/libs/usb/tests/AccessoryChat/AndroidManifest.xml index d6093ae..37ab29f 100644 --- a/libs/usb/tests/AccessoryChat/AndroidManifest.xml +++ b/libs/usb/tests/AccessoryChat/AndroidManifest.xml @@ -20,7 +20,7 @@ <application> <uses-library android:name="com.android.future.usb.accessory" /> - <activity android:name="AccessoryChat" android:label="Accessory Chat GB"> + <activity android:name="AccessoryChat" android:label="Accessory Chat"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> diff --git a/libs/usb/tests/AccessoryChat/accessorychat/accessorychat.c b/libs/usb/tests/AccessoryChat/accessorychat/accessorychat.c index 3c0de69..c80b7c4 100644 --- a/libs/usb/tests/AccessoryChat/accessorychat/accessorychat.c +++ b/libs/usb/tests/AccessoryChat/accessorychat/accessorychat.c @@ -24,6 +24,7 @@ #include <fcntl.h> #include <errno.h> #include <pthread.h> +#include <time.h> #include <usbhost/usbhost.h> #include <linux/usb/f_accessory.h> @@ -65,9 +66,20 @@ static void* write_thread(void* arg) { return NULL; } +static void milli_sleep(int millis) { + struct timespec tm; + + tm.tv_sec = 0; + tm.tv_nsec = millis * 1000000; + nanosleep(&tm, NULL); +} + static void send_string(struct usb_device *device, int index, const char* string) { int ret = usb_device_control_transfer(device, USB_DIR_OUT | USB_TYPE_VENDOR, ACCESSORY_SEND_STRING, 0, index, (void *)string, strlen(string) + 1, 0); + + // some devices can't handle back-to-back requests, so delay a bit + milli_sleep(10); } static int usb_device_added(const char *devname, void* client_data) { @@ -146,6 +158,7 @@ static int usb_device_added(const char *devname, void* client_data) { send_string(device, ACCESSORY_STRING_DESCRIPTION, "Sample Program"); send_string(device, ACCESSORY_STRING_VERSION, "1.0"); send_string(device, ACCESSORY_STRING_URI, "http://www.android.com"); + send_string(device, ACCESSORY_STRING_SERIAL, "1234567890"); ret = usb_device_control_transfer(device, USB_DIR_OUT | USB_TYPE_VENDOR, ACCESSORY_START, 0, 0, 0, 0, 0); diff --git a/libs/usb/tests/AccessoryChat/src/com/android/accessorychat/AccessoryChat.java b/libs/usb/tests/AccessoryChat/src/com/android/accessorychat/AccessoryChat.java index f9a5bf4..c3f4fa3 100644 --- a/libs/usb/tests/AccessoryChat/src/com/android/accessorychat/AccessoryChat.java +++ b/libs/usb/tests/AccessoryChat/src/com/android/accessorychat/AccessoryChat.java @@ -135,7 +135,8 @@ public class AccessoryChat extends Activity implements Runnable, TextView.OnEdit } private void openAccessory(UsbAccessory accessory) { - mFileDescriptor = mUsbManager.openAccessory(accessory); + Log.d(TAG, "openAccessory: " + accessory); + mFileDescriptor = mUsbManager.openAccessory(accessory); if (mFileDescriptor != null) { FileDescriptor fd = mFileDescriptor.getFileDescriptor(); mInputStream = new FileInputStream(fd); diff --git a/services/jni/com_android_server_UsbService.cpp b/services/jni/com_android_server_UsbService.cpp index c66f181..816f76f 100644 --- a/services/jni/com_android_server_UsbService.cpp +++ b/services/jni/com_android_server_UsbService.cpp @@ -193,13 +193,14 @@ static jobjectArray android_server_UsbService_getAccessoryStrings(JNIEnv *env, j return NULL; } jclass stringClass = env->FindClass("java/lang/String"); - jobjectArray strArray = env->NewObjectArray(5, stringClass, NULL); + jobjectArray strArray = env->NewObjectArray(6, stringClass, NULL); if (!strArray) goto out; set_accessory_string(env, fd, ACCESSORY_GET_STRING_MANUFACTURER, strArray, 0); set_accessory_string(env, fd, ACCESSORY_GET_STRING_MODEL, strArray, 1); set_accessory_string(env, fd, ACCESSORY_GET_STRING_DESCRIPTION, strArray, 2); set_accessory_string(env, fd, ACCESSORY_GET_STRING_VERSION, strArray, 3); set_accessory_string(env, fd, ACCESSORY_GET_STRING_URI, strArray, 4); + set_accessory_string(env, fd, ACCESSORY_GET_STRING_SERIAL, strArray, 5); out: close(fd); |