Loading core/java/android/hardware/usb/UsbAccessory.java +28 −30 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.hardware.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * A class representing a USB accessory, which is an external hardware component Loading Loading @@ -46,12 +49,12 @@ public class UsbAccessory implements Parcelable { private static final String TAG = "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; private final @NonNull String mManufacturer; private final @NonNull String mModel; private final @Nullable String mDescription; private final @Nullable String mVersion; private final @Nullable String mUri; private final @Nullable String mSerial; /** @hide */ public static final int MANUFACTURER_STRING = 0; Loading @@ -70,10 +73,11 @@ public class UsbAccessory implements Parcelable { * UsbAccessory should only be instantiated by UsbService implementation * @hide */ public UsbAccessory(String manufacturer, String model, String description, String version, String uri, String serial) { mManufacturer = manufacturer; mModel = model; public UsbAccessory(@NonNull String manufacturer, @NonNull String model, @Nullable String description, @Nullable String version, @Nullable String uri, @Nullable String serial) { mManufacturer = Preconditions.checkNotNull(manufacturer); mModel = Preconditions.checkNotNull(model); mDescription = description; mVersion = version; mUri = uri; Loading @@ -85,12 +89,8 @@ public class UsbAccessory implements Parcelable { * @hide */ public UsbAccessory(String[] strings) { mManufacturer = strings[MANUFACTURER_STRING]; mModel = strings[MODEL_STRING]; mDescription = strings[DESCRIPTION_STRING]; mVersion = strings[VERSION_STRING]; mUri = strings[URI_STRING]; mSerial = strings[SERIAL_STRING]; this(strings[MANUFACTURER_STRING], strings[MODEL_STRING], strings[DESCRIPTION_STRING], strings[VERSION_STRING], strings[URI_STRING], strings[SERIAL_STRING]); } /** Loading @@ -98,7 +98,7 @@ public class UsbAccessory implements Parcelable { * * @return the accessory manufacturer */ public String getManufacturer() { public @NonNull String getManufacturer() { return mManufacturer; } Loading @@ -107,25 +107,25 @@ public class UsbAccessory implements Parcelable { * * @return the accessory model */ public String getModel() { public @NonNull String getModel() { return mModel; } /** * Returns a user visible description of the accessory. * * @return the accessory description * @return the accessory description, or {@code null} if not set */ public String getDescription() { public @Nullable String getDescription() { return mDescription; } /** * Returns the version of the accessory. * * @return the accessory version * @return the accessory version, or {@code null} if not set */ public String getVersion() { public @Nullable String getVersion() { return mVersion; } Loading @@ -134,9 +134,9 @@ public class UsbAccessory implements Parcelable { * This is an optional URI that might show information about the accessory * or provide the option to download an application for the accessory * * @return the accessory URI * @return the accessory URI, or {@code null} if not set */ public String getUri() { public @Nullable String getUri() { return mUri; } Loading @@ -145,9 +145,9 @@ public class UsbAccessory implements Parcelable { * 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 * @return the unique serial number, or {@code null} if not set */ public String getSerial() { public @Nullable String getSerial() { return mSerial; } Loading @@ -172,12 +172,10 @@ public class UsbAccessory implements Parcelable { @Override public int hashCode() { return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ (mModel == null ? 0 : mModel.hashCode()) ^ return mManufacturer.hashCode() ^ mModel.hashCode() ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ (mUri == null ? 0 : mUri.hashCode()) ^ (mSerial == null ? 0 : mSerial.hashCode())); (mUri == null ? 0 : mUri.hashCode()) ^ (mSerial == null ? 0 : mSerial.hashCode()); } @Override Loading core/java/android/hardware/usb/UsbConfiguration.java +13 −10 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.hardware.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * A class representing a configuration on a {@link UsbDevice}. Loading @@ -35,20 +38,20 @@ import android.os.Parcelable; public class UsbConfiguration implements Parcelable { private final int mId; private final String mName; private final @Nullable String mName; private final int mAttributes; private final int mMaxPower; private Parcelable[] mInterfaces; /** All interfaces for this config, only null during creation */ private @Nullable Parcelable[] mInterfaces; /** * Mask for "self-powered" bit in the configuration's attributes. * @see #getAttributes */ private static final int ATTR_SELF_POWERED = 1 << 6; /** * Mask for "remote wakeup" bit in the configuration's attributes. * @see #getAttributes */ private static final int ATTR_REMOTE_WAKEUP = 1 << 5; Loading @@ -56,7 +59,7 @@ public class UsbConfiguration implements Parcelable { * UsbConfiguration should only be instantiated by UsbService implementation * @hide */ public UsbConfiguration(int id, String name, int attributes, int maxPower) { public UsbConfiguration(int id, @Nullable String name, int attributes, int maxPower) { mId = id; mName = name; mAttributes = attributes; Loading @@ -76,9 +79,9 @@ public class UsbConfiguration implements Parcelable { /** * Returns the configuration's name. * * @return the configuration's name * @return the configuration's name, or {@code null} if the property could not be read */ public String getName() { public @Nullable String getName() { return mName; } Loading Loading @@ -125,7 +128,7 @@ public class UsbConfiguration implements Parcelable { * * @return the interface */ public UsbInterface getInterface(int index) { public @NonNull UsbInterface getInterface(int index) { return (UsbInterface)mInterfaces[index]; } Loading @@ -133,8 +136,8 @@ public class UsbConfiguration implements Parcelable { * Only used by UsbService implementation * @hide */ public void setInterfaces(Parcelable[] interfaces) { mInterfaces = interfaces; public void setInterfaces(@NonNull Parcelable[] interfaces) { mInterfaces = Preconditions.checkArrayElementsNotNull(interfaces, "interfaces"); } @Override Loading core/java/android/hardware/usb/UsbDevice.java +31 −26 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.hardware.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * This class represents a USB device attached to the android device with the android device Loading @@ -42,29 +45,31 @@ public class UsbDevice implements Parcelable { private static final String TAG = "UsbDevice"; private static final boolean DEBUG = false; private final String mName; private final String mManufacturerName; private final String mProductName; private final String mVersion; private final String mSerialNumber; private final @NonNull String mName; private final @Nullable String mManufacturerName; private final @Nullable String mProductName; private final @NonNull String mVersion; private final @Nullable String mSerialNumber; private final int mVendorId; private final int mProductId; private final int mClass; private final int mSubclass; private final int mProtocol; private Parcelable[] mConfigurations; // list of all interfaces on the device private UsbInterface[] mInterfaces; /** All configurations for this device, only null during creation */ private @Nullable Parcelable[] mConfigurations; /** All interfaces on the device. Initialized on first call to getInterfaceList */ private @Nullable UsbInterface[] mInterfaces; /** * UsbDevice should only be instantiated by UsbService implementation * @hide */ public UsbDevice(String name, int vendorId, int productId, int Class, int subClass, int protocol, String manufacturerName, String productName, String version, String serialNumber) { mName = name; public UsbDevice(@NonNull String name, int vendorId, int productId, int Class, int subClass, int protocol, @Nullable String manufacturerName, @Nullable String productName, @NonNull String version, @Nullable String serialNumber) { mName = Preconditions.checkNotNull(name); mVendorId = vendorId; mProductId = productId; mClass = Class; Loading @@ -72,7 +77,7 @@ public class UsbDevice implements Parcelable { mProtocol = protocol; mManufacturerName = manufacturerName; mProductName = productName; mVersion = version; mVersion = Preconditions.checkStringNotEmpty(version); mSerialNumber = serialNumber; } Loading @@ -83,25 +88,25 @@ public class UsbDevice implements Parcelable { * * @return the device name */ public String getDeviceName() { public @NonNull String getDeviceName() { return mName; } /** * Returns the manufacturer name of the device. * * @return the manufacturer name * @return the manufacturer name, or {@code null} if the property could not be read */ public String getManufacturerName() { public @Nullable String getManufacturerName() { return mManufacturerName; } /** * Returns the product name of the device. * * @return the product name * @return the product name, or {@code null} if the property could not be read */ public String getProductName() { public @Nullable String getProductName() { return mProductName; } Loading @@ -110,16 +115,16 @@ public class UsbDevice implements Parcelable { * * @return the device version */ public String getVersion() { public @NonNull String getVersion() { return mVersion; } /** * Returns the serial number of the device. * * @return the serial number name * @return the serial number name, or {@code null} if the property could not be read */ public String getSerialNumber() { public @Nullable String getSerialNumber() { return mSerialNumber; } Loading Loading @@ -195,11 +200,11 @@ public class UsbDevice implements Parcelable { * * @return the configuration */ public UsbConfiguration getConfiguration(int index) { public @NonNull UsbConfiguration getConfiguration(int index) { return (UsbConfiguration)mConfigurations[index]; } private UsbInterface[] getInterfaceList() { private @Nullable UsbInterface[] getInterfaceList() { if (mInterfaces == null) { int configurationCount = mConfigurations.length; int interfaceCount = 0; Loading Loading @@ -240,7 +245,7 @@ public class UsbDevice implements Parcelable { * * @return the interface */ public UsbInterface getInterface(int index) { public @NonNull UsbInterface getInterface(int index) { return getInterfaceList()[index]; } Loading @@ -248,8 +253,8 @@ public class UsbDevice implements Parcelable { * Only used by UsbService implementation * @hide */ public void setConfigurations(Parcelable[] configuration) { mConfigurations = configuration; public void setConfigurations(@NonNull Parcelable[] configuration) { mConfigurations = Preconditions.checkArrayElementsNotNull(configuration, "configuration"); } @Override Loading core/java/android/hardware/usb/UsbInterface.java +9 −5 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package android.hardware.usb; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * A class representing an interface on a {@link UsbDevice}. Loading @@ -36,17 +38,19 @@ public class UsbInterface implements Parcelable { private final int mId; private final int mAlternateSetting; private final String mName; private @Nullable final String mName; private final int mClass; private final int mSubclass; private final int mProtocol; /** All endpoints of this interface, only null during creation */ private Parcelable[] mEndpoints; /** * UsbInterface should only be instantiated by UsbService implementation * @hide */ public UsbInterface(int id, int alternateSetting, String name, public UsbInterface(int id, int alternateSetting, @Nullable String name, int Class, int subClass, int protocol) { mId = id; mAlternateSetting = alternateSetting; Loading Loading @@ -83,9 +87,9 @@ public class UsbInterface implements Parcelable { /** * Returns the interface's name. * * @return the interface's name * @return the interface's name, or {@code null} if the property could not be read */ public String getName() { public @Nullable String getName() { return mName; } Loading Loading @@ -140,7 +144,7 @@ public class UsbInterface implements Parcelable { * @hide */ public void setEndpoints(Parcelable[] endpoints) { mEndpoints = endpoints; mEndpoints = Preconditions.checkArrayElementsNotNull(endpoints, "endpoints"); } @Override Loading services/usb/java/com/android/server/usb/UsbHostManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; Loading Loading
core/java/android/hardware/usb/UsbAccessory.java +28 −30 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.hardware.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * A class representing a USB accessory, which is an external hardware component Loading Loading @@ -46,12 +49,12 @@ public class UsbAccessory implements Parcelable { private static final String TAG = "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; private final @NonNull String mManufacturer; private final @NonNull String mModel; private final @Nullable String mDescription; private final @Nullable String mVersion; private final @Nullable String mUri; private final @Nullable String mSerial; /** @hide */ public static final int MANUFACTURER_STRING = 0; Loading @@ -70,10 +73,11 @@ public class UsbAccessory implements Parcelable { * UsbAccessory should only be instantiated by UsbService implementation * @hide */ public UsbAccessory(String manufacturer, String model, String description, String version, String uri, String serial) { mManufacturer = manufacturer; mModel = model; public UsbAccessory(@NonNull String manufacturer, @NonNull String model, @Nullable String description, @Nullable String version, @Nullable String uri, @Nullable String serial) { mManufacturer = Preconditions.checkNotNull(manufacturer); mModel = Preconditions.checkNotNull(model); mDescription = description; mVersion = version; mUri = uri; Loading @@ -85,12 +89,8 @@ public class UsbAccessory implements Parcelable { * @hide */ public UsbAccessory(String[] strings) { mManufacturer = strings[MANUFACTURER_STRING]; mModel = strings[MODEL_STRING]; mDescription = strings[DESCRIPTION_STRING]; mVersion = strings[VERSION_STRING]; mUri = strings[URI_STRING]; mSerial = strings[SERIAL_STRING]; this(strings[MANUFACTURER_STRING], strings[MODEL_STRING], strings[DESCRIPTION_STRING], strings[VERSION_STRING], strings[URI_STRING], strings[SERIAL_STRING]); } /** Loading @@ -98,7 +98,7 @@ public class UsbAccessory implements Parcelable { * * @return the accessory manufacturer */ public String getManufacturer() { public @NonNull String getManufacturer() { return mManufacturer; } Loading @@ -107,25 +107,25 @@ public class UsbAccessory implements Parcelable { * * @return the accessory model */ public String getModel() { public @NonNull String getModel() { return mModel; } /** * Returns a user visible description of the accessory. * * @return the accessory description * @return the accessory description, or {@code null} if not set */ public String getDescription() { public @Nullable String getDescription() { return mDescription; } /** * Returns the version of the accessory. * * @return the accessory version * @return the accessory version, or {@code null} if not set */ public String getVersion() { public @Nullable String getVersion() { return mVersion; } Loading @@ -134,9 +134,9 @@ public class UsbAccessory implements Parcelable { * This is an optional URI that might show information about the accessory * or provide the option to download an application for the accessory * * @return the accessory URI * @return the accessory URI, or {@code null} if not set */ public String getUri() { public @Nullable String getUri() { return mUri; } Loading @@ -145,9 +145,9 @@ public class UsbAccessory implements Parcelable { * 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 * @return the unique serial number, or {@code null} if not set */ public String getSerial() { public @Nullable String getSerial() { return mSerial; } Loading @@ -172,12 +172,10 @@ public class UsbAccessory implements Parcelable { @Override public int hashCode() { return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ (mModel == null ? 0 : mModel.hashCode()) ^ return mManufacturer.hashCode() ^ mModel.hashCode() ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ (mUri == null ? 0 : mUri.hashCode()) ^ (mSerial == null ? 0 : mSerial.hashCode())); (mUri == null ? 0 : mUri.hashCode()) ^ (mSerial == null ? 0 : mSerial.hashCode()); } @Override Loading
core/java/android/hardware/usb/UsbConfiguration.java +13 −10 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.hardware.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * A class representing a configuration on a {@link UsbDevice}. Loading @@ -35,20 +38,20 @@ import android.os.Parcelable; public class UsbConfiguration implements Parcelable { private final int mId; private final String mName; private final @Nullable String mName; private final int mAttributes; private final int mMaxPower; private Parcelable[] mInterfaces; /** All interfaces for this config, only null during creation */ private @Nullable Parcelable[] mInterfaces; /** * Mask for "self-powered" bit in the configuration's attributes. * @see #getAttributes */ private static final int ATTR_SELF_POWERED = 1 << 6; /** * Mask for "remote wakeup" bit in the configuration's attributes. * @see #getAttributes */ private static final int ATTR_REMOTE_WAKEUP = 1 << 5; Loading @@ -56,7 +59,7 @@ public class UsbConfiguration implements Parcelable { * UsbConfiguration should only be instantiated by UsbService implementation * @hide */ public UsbConfiguration(int id, String name, int attributes, int maxPower) { public UsbConfiguration(int id, @Nullable String name, int attributes, int maxPower) { mId = id; mName = name; mAttributes = attributes; Loading @@ -76,9 +79,9 @@ public class UsbConfiguration implements Parcelable { /** * Returns the configuration's name. * * @return the configuration's name * @return the configuration's name, or {@code null} if the property could not be read */ public String getName() { public @Nullable String getName() { return mName; } Loading Loading @@ -125,7 +128,7 @@ public class UsbConfiguration implements Parcelable { * * @return the interface */ public UsbInterface getInterface(int index) { public @NonNull UsbInterface getInterface(int index) { return (UsbInterface)mInterfaces[index]; } Loading @@ -133,8 +136,8 @@ public class UsbConfiguration implements Parcelable { * Only used by UsbService implementation * @hide */ public void setInterfaces(Parcelable[] interfaces) { mInterfaces = interfaces; public void setInterfaces(@NonNull Parcelable[] interfaces) { mInterfaces = Preconditions.checkArrayElementsNotNull(interfaces, "interfaces"); } @Override Loading
core/java/android/hardware/usb/UsbDevice.java +31 −26 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.hardware.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * This class represents a USB device attached to the android device with the android device Loading @@ -42,29 +45,31 @@ public class UsbDevice implements Parcelable { private static final String TAG = "UsbDevice"; private static final boolean DEBUG = false; private final String mName; private final String mManufacturerName; private final String mProductName; private final String mVersion; private final String mSerialNumber; private final @NonNull String mName; private final @Nullable String mManufacturerName; private final @Nullable String mProductName; private final @NonNull String mVersion; private final @Nullable String mSerialNumber; private final int mVendorId; private final int mProductId; private final int mClass; private final int mSubclass; private final int mProtocol; private Parcelable[] mConfigurations; // list of all interfaces on the device private UsbInterface[] mInterfaces; /** All configurations for this device, only null during creation */ private @Nullable Parcelable[] mConfigurations; /** All interfaces on the device. Initialized on first call to getInterfaceList */ private @Nullable UsbInterface[] mInterfaces; /** * UsbDevice should only be instantiated by UsbService implementation * @hide */ public UsbDevice(String name, int vendorId, int productId, int Class, int subClass, int protocol, String manufacturerName, String productName, String version, String serialNumber) { mName = name; public UsbDevice(@NonNull String name, int vendorId, int productId, int Class, int subClass, int protocol, @Nullable String manufacturerName, @Nullable String productName, @NonNull String version, @Nullable String serialNumber) { mName = Preconditions.checkNotNull(name); mVendorId = vendorId; mProductId = productId; mClass = Class; Loading @@ -72,7 +77,7 @@ public class UsbDevice implements Parcelable { mProtocol = protocol; mManufacturerName = manufacturerName; mProductName = productName; mVersion = version; mVersion = Preconditions.checkStringNotEmpty(version); mSerialNumber = serialNumber; } Loading @@ -83,25 +88,25 @@ public class UsbDevice implements Parcelable { * * @return the device name */ public String getDeviceName() { public @NonNull String getDeviceName() { return mName; } /** * Returns the manufacturer name of the device. * * @return the manufacturer name * @return the manufacturer name, or {@code null} if the property could not be read */ public String getManufacturerName() { public @Nullable String getManufacturerName() { return mManufacturerName; } /** * Returns the product name of the device. * * @return the product name * @return the product name, or {@code null} if the property could not be read */ public String getProductName() { public @Nullable String getProductName() { return mProductName; } Loading @@ -110,16 +115,16 @@ public class UsbDevice implements Parcelable { * * @return the device version */ public String getVersion() { public @NonNull String getVersion() { return mVersion; } /** * Returns the serial number of the device. * * @return the serial number name * @return the serial number name, or {@code null} if the property could not be read */ public String getSerialNumber() { public @Nullable String getSerialNumber() { return mSerialNumber; } Loading Loading @@ -195,11 +200,11 @@ public class UsbDevice implements Parcelable { * * @return the configuration */ public UsbConfiguration getConfiguration(int index) { public @NonNull UsbConfiguration getConfiguration(int index) { return (UsbConfiguration)mConfigurations[index]; } private UsbInterface[] getInterfaceList() { private @Nullable UsbInterface[] getInterfaceList() { if (mInterfaces == null) { int configurationCount = mConfigurations.length; int interfaceCount = 0; Loading Loading @@ -240,7 +245,7 @@ public class UsbDevice implements Parcelable { * * @return the interface */ public UsbInterface getInterface(int index) { public @NonNull UsbInterface getInterface(int index) { return getInterfaceList()[index]; } Loading @@ -248,8 +253,8 @@ public class UsbDevice implements Parcelable { * Only used by UsbService implementation * @hide */ public void setConfigurations(Parcelable[] configuration) { mConfigurations = configuration; public void setConfigurations(@NonNull Parcelable[] configuration) { mConfigurations = Preconditions.checkArrayElementsNotNull(configuration, "configuration"); } @Override Loading
core/java/android/hardware/usb/UsbInterface.java +9 −5 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package android.hardware.usb; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.Preconditions; /** * A class representing an interface on a {@link UsbDevice}. Loading @@ -36,17 +38,19 @@ public class UsbInterface implements Parcelable { private final int mId; private final int mAlternateSetting; private final String mName; private @Nullable final String mName; private final int mClass; private final int mSubclass; private final int mProtocol; /** All endpoints of this interface, only null during creation */ private Parcelable[] mEndpoints; /** * UsbInterface should only be instantiated by UsbService implementation * @hide */ public UsbInterface(int id, int alternateSetting, String name, public UsbInterface(int id, int alternateSetting, @Nullable String name, int Class, int subClass, int protocol) { mId = id; mAlternateSetting = alternateSetting; Loading Loading @@ -83,9 +87,9 @@ public class UsbInterface implements Parcelable { /** * Returns the interface's name. * * @return the interface's name * @return the interface's name, or {@code null} if the property could not be read */ public String getName() { public @Nullable String getName() { return mName; } Loading Loading @@ -140,7 +144,7 @@ public class UsbInterface implements Parcelable { * @hide */ public void setEndpoints(Parcelable[] endpoints) { mEndpoints = endpoints; mEndpoints = Preconditions.checkArrayElementsNotNull(endpoints, "endpoints"); } @Override Loading
services/usb/java/com/android/server/usb/UsbHostManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.usb; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; Loading