diff options
author | Mike Lockwood <lockwood@android.com> | 2011-03-14 21:56:33 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-03-15 16:50:18 -0400 |
commit | 638d7cb3ee0bb3596b01dc19eca9456fa72a36e0 (patch) | |
tree | ff1b7ca2724da9b62c1b6a0c2dced0d4f11b76e7 /libs/usb | |
parent | bf079216c607b660a0ad219df6c4752906a7fc61 (diff) | |
download | frameworks_base-638d7cb3ee0bb3596b01dc19eca9456fa72a36e0.zip frameworks_base-638d7cb3ee0bb3596b01dc19eca9456fa72a36e0.tar.gz frameworks_base-638d7cb3ee0bb3596b01dc19eca9456fa72a36e0.tar.bz2 |
DO NOT MERGE: Backport more USB accessory changes from honeycomb
Change-Id: I8459c5ab9fbf0b3cad752041484a5de44ca9badd
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'libs/usb')
6 files changed, 45 insertions, 12 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..802b715 100644 --- a/libs/usb/tests/AccessoryChat/AndroidManifest.xml +++ b/libs/usb/tests/AccessoryChat/AndroidManifest.xml @@ -17,10 +17,10 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.accessorychat"> - <application> + <application android:label="Accessory Chat"> <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..85b52dd 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) { @@ -143,9 +155,10 @@ static int usb_device_added(const char *devname, void* client_data) { send_string(device, ACCESSORY_STRING_MANUFACTURER, "Google, Inc."); send_string(device, ACCESSORY_STRING_MODEL, "AccessoryChat"); - send_string(device, ACCESSORY_STRING_DESCRIPTION, "Sample Program"); + send_string(device, ACCESSORY_STRING_DESCRIPTION, "Accessory Chat"); 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); |