am 221830b9: Merge "Add support for USB accessory serial numbers" into honeycomb-mr1
* commit '221830b93d6f35bcf20db2d34978392b43f44221': Add support for USB accessory serial numbers
This commit is contained in:
@@ -94481,6 +94481,17 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</method>
|
</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"
|
<method name="getUri"
|
||||||
return="java.lang.String"
|
return="java.lang.String"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
@@ -267064,7 +267075,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="arg0" type="T">
|
<parameter name="t" type="T">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
@@ -33,18 +33,20 @@ public class UsbAccessory implements Parcelable {
|
|||||||
private final String mDescription;
|
private final String mDescription;
|
||||||
private final String mVersion;
|
private final String mVersion;
|
||||||
private final String mUri;
|
private final String mUri;
|
||||||
|
private final String mSerial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UsbAccessory should only be instantiated by UsbService implementation
|
* UsbAccessory should only be instantiated by UsbService implementation
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public UsbAccessory(String manufacturer, String model, String description,
|
public UsbAccessory(String manufacturer, String model, String description,
|
||||||
String version, String uri) {
|
String version, String uri, String serial) {
|
||||||
mManufacturer = manufacturer;
|
mManufacturer = manufacturer;
|
||||||
mModel = model;
|
mModel = model;
|
||||||
mDescription = description;
|
mDescription = description;
|
||||||
mVersion = version;
|
mVersion = version;
|
||||||
mUri = uri;
|
mUri = uri;
|
||||||
|
mSerial = serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,6 +59,7 @@ public class UsbAccessory implements Parcelable {
|
|||||||
mDescription = strings[2];
|
mDescription = strings[2];
|
||||||
mVersion = strings[3];
|
mVersion = strings[3];
|
||||||
mUri = strings[4];
|
mUri = strings[4];
|
||||||
|
mSerial = strings[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,6 +109,17 @@ public class UsbAccessory implements Parcelable {
|
|||||||
return mUri;
|
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) {
|
private static boolean compare(String s1, String s2) {
|
||||||
if (s1 == null) return (s2 == null);
|
if (s1 == null) return (s2 == null);
|
||||||
return s1.equals(s2);
|
return s1.equals(s2);
|
||||||
@@ -119,7 +133,8 @@ public class UsbAccessory implements Parcelable {
|
|||||||
compare(mModel, accessory.getModel()) &&
|
compare(mModel, accessory.getModel()) &&
|
||||||
compare(mDescription, accessory.getDescription()) &&
|
compare(mDescription, accessory.getDescription()) &&
|
||||||
compare(mVersion, accessory.getVersion()) &&
|
compare(mVersion, accessory.getVersion()) &&
|
||||||
compare(mUri, accessory.getUri()));
|
compare(mUri, accessory.getUri()) &&
|
||||||
|
compare(mSerial, accessory.getSerial()));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -130,7 +145,8 @@ public class UsbAccessory implements Parcelable {
|
|||||||
(mModel == null ? 0 : mModel.hashCode()) ^
|
(mModel == null ? 0 : mModel.hashCode()) ^
|
||||||
(mDescription == null ? 0 : mDescription.hashCode()) ^
|
(mDescription == null ? 0 : mDescription.hashCode()) ^
|
||||||
(mVersion == null ? 0 : mVersion.hashCode()) ^
|
(mVersion == null ? 0 : mVersion.hashCode()) ^
|
||||||
(mUri == null ? 0 : mUri.hashCode()));
|
(mUri == null ? 0 : mUri.hashCode()) ^
|
||||||
|
(mSerial == null ? 0 : mSerial.hashCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,7 +155,8 @@ public class UsbAccessory implements Parcelable {
|
|||||||
", mModel=" + mModel +
|
", mModel=" + mModel +
|
||||||
", mDescription=" + mDescription +
|
", mDescription=" + mDescription +
|
||||||
", mVersion=" + mVersion +
|
", mVersion=" + mVersion +
|
||||||
", mUri=" + mUri + "]";
|
", mUri=" + mUri +
|
||||||
|
", mSerial=" + mSerial + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<UsbAccessory> CREATOR =
|
public static final Parcelable.Creator<UsbAccessory> CREATOR =
|
||||||
@@ -150,7 +167,8 @@ public class UsbAccessory implements Parcelable {
|
|||||||
String description = in.readString();
|
String description = in.readString();
|
||||||
String version = in.readString();
|
String version = in.readString();
|
||||||
String uri = 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) {
|
public UsbAccessory[] newArray(int size) {
|
||||||
@@ -168,5 +186,6 @@ public class UsbAccessory implements Parcelable {
|
|||||||
parcel.writeString(mDescription);
|
parcel.writeString(mDescription);
|
||||||
parcel.writeString(mVersion);
|
parcel.writeString(mVersion);
|
||||||
parcel.writeString(mUri);
|
parcel.writeString(mUri);
|
||||||
|
parcel.writeString(mSerial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,14 @@ package com.android.future.usb;
|
|||||||
/**
|
/**
|
||||||
* A class representing a USB accessory.
|
* A class representing a USB accessory.
|
||||||
*/
|
*/
|
||||||
public final class UsbAccessory {
|
public class UsbAccessory {
|
||||||
|
|
||||||
private final String mManufacturer;
|
private final String mManufacturer;
|
||||||
private final String mModel;
|
private final String mModel;
|
||||||
private final String mDescription;
|
private final String mDescription;
|
||||||
private final String mVersion;
|
private final String mVersion;
|
||||||
private final String mUri;
|
private final String mUri;
|
||||||
|
private final String mSerial;
|
||||||
|
|
||||||
/* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) {
|
/* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) {
|
||||||
mManufacturer = accessory.getManufacturer();
|
mManufacturer = accessory.getManufacturer();
|
||||||
@@ -33,6 +34,7 @@ public final class UsbAccessory {
|
|||||||
mDescription = accessory.getDescription();
|
mDescription = accessory.getDescription();
|
||||||
mVersion = accessory.getVersion();
|
mVersion = accessory.getVersion();
|
||||||
mUri = accessory.getUri();
|
mUri = accessory.getUri();
|
||||||
|
mSerial = accessory.getSerial();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,6 +84,17 @@ public final class UsbAccessory {
|
|||||||
return mUri;
|
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) {
|
private static boolean compare(String s1, String s2) {
|
||||||
if (s1 == null) return (s2 == null);
|
if (s1 == null) return (s2 == null);
|
||||||
return s1.equals(s2);
|
return s1.equals(s2);
|
||||||
@@ -95,7 +108,8 @@ public final class UsbAccessory {
|
|||||||
compare(mModel, accessory.getModel()) &&
|
compare(mModel, accessory.getModel()) &&
|
||||||
compare(mDescription, accessory.getDescription()) &&
|
compare(mDescription, accessory.getDescription()) &&
|
||||||
compare(mVersion, accessory.getVersion()) &&
|
compare(mVersion, accessory.getVersion()) &&
|
||||||
compare(mUri, accessory.getUri()));
|
compare(mUri, accessory.getUri()) &&
|
||||||
|
compare(mSerial, accessory.getSerial()));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -106,7 +120,8 @@ public final class UsbAccessory {
|
|||||||
(mModel == null ? 0 : mModel.hashCode()) ^
|
(mModel == null ? 0 : mModel.hashCode()) ^
|
||||||
(mDescription == null ? 0 : mDescription.hashCode()) ^
|
(mDescription == null ? 0 : mDescription.hashCode()) ^
|
||||||
(mVersion == null ? 0 : mVersion.hashCode()) ^
|
(mVersion == null ? 0 : mVersion.hashCode()) ^
|
||||||
(mUri == null ? 0 : mUri.hashCode()));
|
(mUri == null ? 0 : mUri.hashCode()) ^
|
||||||
|
(mSerial == null ? 0 : mSerial.hashCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -115,6 +130,7 @@ public final class UsbAccessory {
|
|||||||
", mModel=" + mModel +
|
", mModel=" + mModel +
|
||||||
", mDescription=" + mDescription +
|
", mDescription=" + mDescription +
|
||||||
", mVersion=" + mVersion +
|
", mVersion=" + mVersion +
|
||||||
", mUri=" + mUri + "]";
|
", mUri=" + mUri +
|
||||||
|
", mSerial=" + mSerial + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,8 @@ public class UsbManager {
|
|||||||
try {
|
try {
|
||||||
return mService.openAccessory(new android.hardware.usb.UsbAccessory(
|
return mService.openAccessory(new android.hardware.usb.UsbAccessory(
|
||||||
accessory.getManufacturer(),accessory.getModel(),
|
accessory.getManufacturer(),accessory.getModel(),
|
||||||
accessory.getDescription(), accessory.getVersion(), accessory.getUri()));
|
accessory.getDescription(), accessory.getVersion(),
|
||||||
|
accessory.getUri(), accessory.getSerial()));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException in openAccessory" , e);
|
Log.e(TAG, "RemoteException in openAccessory" , e);
|
||||||
return null;
|
return null;
|
||||||
@@ -150,7 +151,8 @@ public class UsbManager {
|
|||||||
try {
|
try {
|
||||||
return mService.hasAccessoryPermission(new android.hardware.usb.UsbAccessory(
|
return mService.hasAccessoryPermission(new android.hardware.usb.UsbAccessory(
|
||||||
accessory.getManufacturer(),accessory.getModel(),
|
accessory.getManufacturer(),accessory.getModel(),
|
||||||
accessory.getDescription(), accessory.getVersion(), accessory.getUri()));
|
accessory.getDescription(), accessory.getVersion(),
|
||||||
|
accessory.getUri(), accessory.getSerial()));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException in hasPermission", e);
|
Log.e(TAG, "RemoteException in hasPermission", e);
|
||||||
return false;
|
return false;
|
||||||
@@ -174,7 +176,8 @@ public class UsbManager {
|
|||||||
try {
|
try {
|
||||||
mService.requestAccessoryPermission(new android.hardware.usb.UsbAccessory(
|
mService.requestAccessoryPermission(new android.hardware.usb.UsbAccessory(
|
||||||
accessory.getManufacturer(),accessory.getModel(),
|
accessory.getManufacturer(),accessory.getModel(),
|
||||||
accessory.getDescription(), accessory.getVersion(), accessory.getUri()),
|
accessory.getDescription(), accessory.getVersion(),
|
||||||
|
accessory.getUri(), accessory.getSerial()),
|
||||||
mContext.getPackageName(), pi);
|
mContext.getPackageName(), pi);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException in requestPermission", e);
|
Log.e(TAG, "RemoteException in requestPermission", e);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ LOCAL_MODULE_TAGS := tests
|
|||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := AccessoryChatGB
|
LOCAL_PACKAGE_NAME := AccessoryChat
|
||||||
|
|
||||||
LOCAL_JAVA_LIBRARIES := com.android.future.usb.accessory
|
LOCAL_JAVA_LIBRARIES := com.android.future.usb.accessory
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<application>
|
<application>
|
||||||
<uses-library android:name="com.android.future.usb.accessory" />
|
<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>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <usbhost/usbhost.h>
|
#include <usbhost/usbhost.h>
|
||||||
#include <linux/usb/f_accessory.h>
|
#include <linux/usb/f_accessory.h>
|
||||||
@@ -65,9 +66,20 @@ static void* write_thread(void* arg) {
|
|||||||
return NULL;
|
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) {
|
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,
|
int ret = usb_device_control_transfer(device, USB_DIR_OUT | USB_TYPE_VENDOR,
|
||||||
ACCESSORY_SEND_STRING, 0, index, (void *)string, strlen(string) + 1, 0);
|
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) {
|
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_DESCRIPTION, "Sample Program");
|
||||||
send_string(device, ACCESSORY_STRING_VERSION, "1.0");
|
send_string(device, ACCESSORY_STRING_VERSION, "1.0");
|
||||||
send_string(device, ACCESSORY_STRING_URI, "http://www.android.com");
|
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,
|
ret = usb_device_control_transfer(device, USB_DIR_OUT | USB_TYPE_VENDOR,
|
||||||
ACCESSORY_START, 0, 0, 0, 0, 0);
|
ACCESSORY_START, 0, 0, 0, 0, 0);
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ public class AccessoryChat extends Activity implements Runnable, TextView.OnEdit
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openAccessory(UsbAccessory accessory) {
|
private void openAccessory(UsbAccessory accessory) {
|
||||||
mFileDescriptor = mUsbManager.openAccessory(accessory);
|
Log.d(TAG, "openAccessory: " + accessory);
|
||||||
|
mFileDescriptor = mUsbManager.openAccessory(accessory);
|
||||||
if (mFileDescriptor != null) {
|
if (mFileDescriptor != null) {
|
||||||
FileDescriptor fd = mFileDescriptor.getFileDescriptor();
|
FileDescriptor fd = mFileDescriptor.getFileDescriptor();
|
||||||
mInputStream = new FileInputStream(fd);
|
mInputStream = new FileInputStream(fd);
|
||||||
|
|||||||
@@ -193,13 +193,14 @@ static jobjectArray android_server_UsbService_getAccessoryStrings(JNIEnv *env, j
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
jclass stringClass = env->FindClass("java/lang/String");
|
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;
|
if (!strArray) goto out;
|
||||||
set_accessory_string(env, fd, ACCESSORY_GET_STRING_MANUFACTURER, strArray, 0);
|
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_MODEL, strArray, 1);
|
||||||
set_accessory_string(env, fd, ACCESSORY_GET_STRING_DESCRIPTION, strArray, 2);
|
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_VERSION, strArray, 3);
|
||||||
set_accessory_string(env, fd, ACCESSORY_GET_STRING_URI, strArray, 4);
|
set_accessory_string(env, fd, ACCESSORY_GET_STRING_URI, strArray, 4);
|
||||||
|
set_accessory_string(env, fd, ACCESSORY_GET_STRING_SERIAL, strArray, 5);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user