AccessoryChat: use platform APIs and support Galaxy Nexus

Change-Id: I171c2781f3d447bec46f0179351e1b18721b1b89
This commit is contained in:
Simon Wilson
2012-02-07 14:24:06 -08:00
parent dc210ade0a
commit c92e6f14f9
4 changed files with 11 additions and 13 deletions

View File

@@ -23,9 +23,4 @@ LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := AccessoryChat LOCAL_PACKAGE_NAME := AccessoryChat
LOCAL_JAVA_LIBRARIES := com.android.future.usb.accessory
# Force an old SDK version to make sure we aren't using newer UsbManager APIs
LOCAL_SDK_VERSION := 8
include $(BUILD_PACKAGE) include $(BUILD_PACKAGE)

View File

@@ -17,8 +17,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.accessorychat"> package="com.android.accessorychat">
<uses-feature android:name="android.hardware.usb.accessory" />
<application android:label="Accessory Chat"> <application android:label="Accessory Chat">
<uses-library android:name="com.android.future.usb.accessory" />
<activity android:name="AccessoryChat" android:label="Accessory Chat"> <activity android:name="AccessoryChat" android:label="Accessory Chat">
<intent-filter> <intent-filter>
@@ -35,5 +36,5 @@
android:resource="@xml/accessory_filter" /> android:resource="@xml/accessory_filter" />
</activity> </activity>
</application> </application>
<uses-sdk android:minSdkVersion="10" /> <uses-sdk android:minSdkVersion="12" />
</manifest> </manifest>

View File

@@ -98,7 +98,7 @@ static int usb_device_added(const char *devname, void* client_data) {
vendorId = usb_device_get_vendor_id(device); vendorId = usb_device_get_vendor_id(device);
productId = usb_device_get_product_id(device); productId = usb_device_get_product_id(device);
if (vendorId == 0x18D1 || vendorId == 0x22B8) { if (vendorId == 0x18D1 || vendorId == 0x22B8 || vendorId == 0x04e8) {
if (!sDevice && (productId == 0x2D00 || productId == 0x2D01)) { if (!sDevice && (productId == 0x2D00 || productId == 0x2D01)) {
struct usb_descriptor_header* desc; struct usb_descriptor_header* desc;
struct usb_descriptor_iter iter; struct usb_descriptor_iter iter;

View File

@@ -33,8 +33,8 @@ import android.util.Log;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import com.android.future.usb.UsbAccessory; import android.hardware.usb.UsbManager;
import com.android.future.usb.UsbManager; import android.hardware.usb.UsbAccessory;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -64,9 +64,11 @@ public class AccessoryChat extends Activity implements Runnable, TextView.OnEdit
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (ACTION_USB_PERMISSION.equals(intent.getAction())) { if (ACTION_USB_PERMISSION.equals(intent.getAction())) {
synchronized (this) { synchronized (this) {
UsbAccessory accessory = UsbManager.getAccessory(intent); UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
openAccessory(accessory); if (accessory != null) {
openAccessory(accessory);
}
} else { } else {
Log.d(TAG, "permission denied for accessory " + accessory); Log.d(TAG, "permission denied for accessory " + accessory);
} }
@@ -80,7 +82,7 @@ public class AccessoryChat extends Activity implements Runnable, TextView.OnEdit
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mUsbManager = UsbManager.getInstance(this); mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter); registerReceiver(mUsbReceiver, filter);