Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 188d00b0 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

UsbManager: Remove redundant Intent extras from USB device and accessory broadcasts



These extras are also accessable via the UsbDevice and UsbAccessory classes,
which are also included as extras.
Since you can't filter Intents based on extras there is no point in duplicating
this information as separate extras.

Change-Id: I4c8d1e70d66023a1800b3f8f06118898da6b37af
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 16dc3073
Loading
Loading
Loading
Loading
+0 −110
Original line number Diff line number Diff line
@@ -95368,50 +95368,6 @@
 visibility="public"
>
</field>
<field name="EXTRA_ACCESSORY_MANUFACTURER"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;accessory-manufacturer&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_ACCESSORY_PRODUCT"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;accessory-product&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_ACCESSORY_TYPE"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;accessory-type&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_ACCESSORY_VERSION"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;accessory-version&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_DEVICE"
 type="java.lang.String"
 transient="false"
@@ -95423,72 +95379,6 @@
 visibility="public"
>
</field>
<field name="EXTRA_DEVICE_CLASS"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;device_class&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_DEVICE_NAME"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;device_name&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_DEVICE_PROTOCOL"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;device_protocol&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_DEVICE_SUBCLASS"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;device_subclass&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_PRODUCT_ID"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;product_id&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_VENDOR_ID"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;vendor_id&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="USB_CONFIGURATION"
 type="java.lang.String"
 transient="false"
+3 −72
Original line number Diff line number Diff line
@@ -62,12 +62,6 @@ public class UsbManager {
     *
     * This intent is sent when a USB device is attached to the USB bus when in host mode.
     * <ul>
     * <li> {@link #EXTRA_DEVICE_NAME} containing the device's name (String)
     * <li> {@link #EXTRA_VENDOR_ID} containing the device's vendor ID (Integer)
     * <li> {@link #EXTRA_PRODUCT_ID} containing the device's product ID (Integer)
     * <li> {@link #EXTRA_DEVICE_CLASS} } containing the device class (Integer)
     * <li> {@link #EXTRA_DEVICE_SUBCLASS} containing the device subclass (Integer)
     * <li> {@link #EXTRA_DEVICE_PROTOCOL} containing the device protocol (Integer)
     * <li> {@link #EXTRA_DEVICE} containing the {@link android.hardware.UsbDevice}
     * for the attached device
     * </ul>
@@ -80,7 +74,8 @@ public class UsbManager {
     *
     * This intent is sent when a USB device is detached from the USB bus when in host mode.
     * <ul>
     * <li> {@link #EXTRA_DEVICE_NAME} containing the device's name (String)
     * <li> {@link #EXTRA_DEVICE} containing the {@link android.hardware.UsbDevice}
     * for the detached device
     * </ul>
     */
    public static final String ACTION_USB_DEVICE_DETACHED =
@@ -91,10 +86,6 @@ public class UsbManager {
     *
     * This intent is sent when a USB accessory is attached.
     * <ul>
     * <li> {@link #EXTRA_ACCESSORY_MANUFACTURER} containing the accessory's manufacturer (String)
     * <li> {@link #EXTRA_ACCESSORY_PRODUCT} containing the accessory's product name (String)
     * <li> {@link #EXTRA_ACCESSORY_TYPE} containing the accessory's type (String)
     * <li> {@link #EXTRA_ACCESSORY_VERSION} containing the accessory's version (String)
     * <li> {@link #EXTRA_ACCESSORY} containing the {@link android.hardware.UsbAccessory}
     * for the attached accessory
     * </ul>
@@ -172,43 +163,7 @@ public class UsbManager {

    /**
     * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} and
     * {@link #ACTION_USB_DEVICE_DETACHED} broadcasts
     * containing the device's ID (String).
     */
    public static final String EXTRA_DEVICE_NAME = "device_name";

    /**
     * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} broadcast
     * containing the device's vendor ID (int).
     */
    public static final String EXTRA_VENDOR_ID = "vendor_id";

    /**
     * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} broadcast
     * containing the device's product ID (int).
     */
    public static final String EXTRA_PRODUCT_ID = "product_id";

    /**
     * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} broadcast
     * containing the device's class (int).
     */
    public static final String EXTRA_DEVICE_CLASS = "device_class";

    /**
     * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} broadcast
     * containing the device's class (int).
     */
    public static final String EXTRA_DEVICE_SUBCLASS = "device_subclass";

    /**
     * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} broadcast
     * containing the device's class (int).
     */
    public static final String EXTRA_DEVICE_PROTOCOL = "device_protocol";

    /**
     * Name of extra for {@link #ACTION_USB_DEVICE_ATTACHED} broadcast
     * {@link #ACTION_USB_DEVICE_DETACHED} broadcasts.
     * containing the UsbDevice object for the device.
     */

@@ -220,30 +175,6 @@ public class UsbManager {
     */
    public static final String EXTRA_ACCESSORY = "accessory";

    /**
     * Name of extra for {@link #ACTION_USB_ACCESSORY_ATTACHED} broadcast
     * containing the accessory's manufacturer name.
     */
    public static final String EXTRA_ACCESSORY_MANUFACTURER = "accessory-manufacturer";

    /**
     * Name of extra for {@link #ACTION_USB_ACCESSORY_ATTACHED} broadcast
     * containing the accessory's product name.
     */
    public static final String EXTRA_ACCESSORY_PRODUCT = "accessory-product";

    /**
     * Name of extra for {@link #ACTION_USB_ACCESSORY_ATTACHED} broadcast
     * containing the accessory's type.
     */
    public static final String EXTRA_ACCESSORY_TYPE = "accessory-type";

    /**
     * Name of extra for {@link #ACTION_USB_ACCESSORY_ATTACHED} broadcast
     * containing the accessory's version.
     */
    public static final String EXTRA_ACCESSORY_VERSION = "accessory-version";

    private IUsbManager mService;

    /**
+2 −3
Original line number Diff line number Diff line
@@ -48,15 +48,14 @@ public class MtpClient {
    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String deviceName = intent.getStringExtra(UsbManager.EXTRA_DEVICE_NAME);
            UsbDevice usbDevice = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
            String deviceName = usbDevice.getDeviceName();

            synchronized (mDeviceList) {
                MtpDevice mtpDevice = getDeviceLocked(deviceName);

                if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
                    if (mtpDevice == null) {
                        UsbDevice usbDevice =
                                (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
                        mtpDevice = openDevice(usbDevice);
                    }
                    if (mtpDevice != null) {
+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.UsbDevice;
import android.hardware.UsbManager;
import android.util.Log;

@@ -41,7 +42,8 @@ public class DeviceDisconnectedReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String deviceName = intent.getStringExtra(UsbManager.EXTRA_DEVICE_NAME);
        UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        String deviceName = device.getDeviceName();
        Log.d(TAG, "ACTION_USB_DEVICE_DETACHED " + deviceName);

        // close our activity if the device it is displaying is disconnected
+1 −20
Original line number Diff line number Diff line
@@ -143,19 +143,6 @@ class UsbService extends IUsbManager.Stub {
                mCurrentAccessory = new UsbAccessory(strings);
                Intent intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
                intent.putExtra(UsbManager.EXTRA_ACCESSORY, mCurrentAccessory);
                // add strings as separate extras to allow filtering
                if (strings[0] != null) {
                    intent.putExtra(UsbManager.EXTRA_ACCESSORY_MANUFACTURER, strings[0]);
                }
                if (strings[1] != null) {
                    intent.putExtra(UsbManager.EXTRA_ACCESSORY_PRODUCT, strings[1]);
                }
                if (strings[2] != null) {
                    intent.putExtra(UsbManager.EXTRA_ACCESSORY_TYPE, strings[2]);
                }
                if (strings[3] != null) {
                    intent.putExtra(UsbManager.EXTRA_ACCESSORY_VERSION, strings[3]);
                }
                mContext.sendBroadcast(intent);
            } else {
                Log.e(TAG, "nativeGetAccessoryStrings failed");
@@ -360,12 +347,6 @@ class UsbService extends IUsbManager.Stub {
            mDevices.put(deviceName, device);

            Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
            intent.putExtra(UsbManager.EXTRA_DEVICE_NAME, deviceName);
            intent.putExtra(UsbManager.EXTRA_VENDOR_ID, vendorID);
            intent.putExtra(UsbManager.EXTRA_PRODUCT_ID, productID);
            intent.putExtra(UsbManager.EXTRA_DEVICE_CLASS, deviceClass);
            intent.putExtra(UsbManager.EXTRA_DEVICE_SUBCLASS, deviceSubclass);
            intent.putExtra(UsbManager.EXTRA_DEVICE_PROTOCOL, deviceProtocol);
            intent.putExtra(UsbManager.EXTRA_DEVICE, device);
            Log.d(TAG, "usbDeviceAdded, sending " + intent);
            mContext.sendBroadcast(intent);
@@ -378,7 +359,7 @@ class UsbService extends IUsbManager.Stub {
            UsbDevice device = mDevices.remove(deviceName);
            if (device != null) {
                Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED);
                intent.putExtra(UsbManager.EXTRA_DEVICE_NAME, deviceName);
                intent.putExtra(UsbManager.EXTRA_DEVICE, device);
                Log.d(TAG, "usbDeviceRemoved, sending " + intent);
                mContext.sendBroadcast(intent);
            }