Merge "UsbDevice: Add support for retrieving version string for a USB device" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f105f61dd9
@@ -14025,6 +14025,7 @@ package android.hardware.usb {
|
||||
method public java.lang.String getProductName();
|
||||
method public java.lang.String getSerialNumber();
|
||||
method public int getVendorId();
|
||||
method public java.lang.String getVersion();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.hardware.usb.UsbDevice> CREATOR;
|
||||
}
|
||||
|
||||
@@ -14929,6 +14929,7 @@ package android.hardware.usb {
|
||||
method public java.lang.String getProductName();
|
||||
method public java.lang.String getSerialNumber();
|
||||
method public int getVendorId();
|
||||
method public java.lang.String getVersion();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.hardware.usb.UsbDevice> CREATOR;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class UsbDevice implements Parcelable {
|
||||
private final String mName;
|
||||
private final String mManufacturerName;
|
||||
private final String mProductName;
|
||||
private final String mVersion;
|
||||
private final String mSerialNumber;
|
||||
private final int mVendorId;
|
||||
private final int mProductId;
|
||||
@@ -62,7 +63,7 @@ public class UsbDevice implements Parcelable {
|
||||
*/
|
||||
public UsbDevice(String name, int vendorId, int productId,
|
||||
int Class, int subClass, int protocol,
|
||||
String manufacturerName, String productName, String serialNumber) {
|
||||
String manufacturerName, String productName, String version, String serialNumber) {
|
||||
mName = name;
|
||||
mVendorId = vendorId;
|
||||
mProductId = productId;
|
||||
@@ -71,6 +72,7 @@ public class UsbDevice implements Parcelable {
|
||||
mProtocol = protocol;
|
||||
mManufacturerName = manufacturerName;
|
||||
mProductName = productName;
|
||||
mVersion = version;
|
||||
mSerialNumber = serialNumber;
|
||||
}
|
||||
|
||||
@@ -103,6 +105,15 @@ public class UsbDevice implements Parcelable {
|
||||
return mProductName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version number of the device.
|
||||
*
|
||||
* @return the device version
|
||||
*/
|
||||
public String getVersion() {
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the serial number of the device.
|
||||
*
|
||||
@@ -263,7 +274,7 @@ public class UsbDevice implements Parcelable {
|
||||
",mVendorId=" + mVendorId + ",mProductId=" + mProductId +
|
||||
",mClass=" + mClass + ",mSubclass=" + mSubclass + ",mProtocol=" + mProtocol +
|
||||
",mManufacturerName=" + mManufacturerName + ",mProductName=" + mProductName +
|
||||
",mSerialNumber=" + mSerialNumber + ",mConfigurations=[");
|
||||
",mVersion=" + mVersion + ",mSerialNumber=" + mSerialNumber + ",mConfigurations=[");
|
||||
for (int i = 0; i < mConfigurations.length; i++) {
|
||||
builder.append("\n");
|
||||
builder.append(mConfigurations[i].toString());
|
||||
@@ -283,10 +294,11 @@ public class UsbDevice implements Parcelable {
|
||||
int protocol = in.readInt();
|
||||
String manufacturerName = in.readString();
|
||||
String productName = in.readString();
|
||||
String version = in.readString();
|
||||
String serialNumber = in.readString();
|
||||
Parcelable[] configurations = in.readParcelableArray(UsbInterface.class.getClassLoader());
|
||||
UsbDevice device = new UsbDevice(name, vendorId, productId, clasz, subClass, protocol,
|
||||
manufacturerName, productName, serialNumber);
|
||||
manufacturerName, productName, version, serialNumber);
|
||||
device.setConfigurations(configurations);
|
||||
return device;
|
||||
}
|
||||
@@ -309,6 +321,7 @@ public class UsbDevice implements Parcelable {
|
||||
parcel.writeInt(mProtocol);
|
||||
parcel.writeString(mManufacturerName);
|
||||
parcel.writeString(mProductName);
|
||||
parcel.writeString(mVersion);
|
||||
parcel.writeString(mSerialNumber);
|
||||
parcel.writeParcelableArray(mConfigurations, 0);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ static int usb_device_added(const char *devname, void* client_data) {
|
||||
|
||||
char *manufacturer = usb_device_get_manufacturer_name(device);
|
||||
char *product = usb_device_get_product_name(device);
|
||||
int version = usb_device_get_version(device);
|
||||
char *serial = usb_device_get_serial(device);
|
||||
|
||||
jstring deviceName = env->NewStringUTF(devname);
|
||||
@@ -81,7 +82,7 @@ static int usb_device_added(const char *devname, void* client_data) {
|
||||
jboolean result = env->CallBooleanMethod(thiz, method_beginUsbDeviceAdded,
|
||||
deviceName, usb_device_get_vendor_id(device), usb_device_get_product_id(device),
|
||||
deviceDesc->bDeviceClass, deviceDesc->bDeviceSubClass, deviceDesc->bDeviceProtocol,
|
||||
manufacturerName, productName, serialNumber);
|
||||
manufacturerName, productName, version, serialNumber);
|
||||
|
||||
env->DeleteLocalRef(serialNumber);
|
||||
env->DeleteLocalRef(productName);
|
||||
@@ -199,7 +200,7 @@ int register_android_server_UsbHostManager(JNIEnv *env)
|
||||
return -1;
|
||||
}
|
||||
method_beginUsbDeviceAdded = env->GetMethodID(clazz, "beginUsbDeviceAdded",
|
||||
"(Ljava/lang/String;IIIIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z");
|
||||
"(Ljava/lang/String;IIIIILjava/lang/String;Ljava/lang/String;ILjava/lang/String;)Z");
|
||||
if (method_beginUsbDeviceAdded == NULL) {
|
||||
ALOGE("Can't find beginUsbDeviceAdded");
|
||||
return -1;
|
||||
|
||||
@@ -112,7 +112,7 @@ public class UsbHostManager {
|
||||
*/
|
||||
private boolean beginUsbDeviceAdded(String deviceName, int vendorID, int productID,
|
||||
int deviceClass, int deviceSubclass, int deviceProtocol,
|
||||
String manufacturerName, String productName, String serialNumber) {
|
||||
String manufacturerName, String productName, int version, String serialNumber) {
|
||||
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "usb:UsbHostManager.beginUsbDeviceAdded(" + deviceName + ")");
|
||||
@@ -149,9 +149,12 @@ public class UsbHostManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create version string in "%.%" format
|
||||
String versionString = Integer.toString(version >> 8) + "." + (version & 0xFF);
|
||||
|
||||
mNewDevice = new UsbDevice(deviceName, vendorID, productID,
|
||||
deviceClass, deviceSubclass, deviceProtocol,
|
||||
manufacturerName, productName, serialNumber);
|
||||
manufacturerName, productName, versionString, serialNumber);
|
||||
|
||||
mNewConfigurations = new ArrayList<UsbConfiguration>();
|
||||
mNewInterfaces = new ArrayList<UsbInterface>();
|
||||
|
||||
Reference in New Issue
Block a user