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 /libs | |
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>
Diffstat (limited to 'libs')
6 files changed, 43 insertions, 10 deletions
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); |