blob: a0f64cddfc7474cb0a3ed7427988b0ca64375ed8 [file] [log] [blame]
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mike Lockwoodc4308f02011-03-01 08:04:54 -080017package android.hardware.usb;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050018
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -070021import android.app.ActivityThread;
Artur Satayev26958002019-12-10 17:47:52 +000022import android.compat.annotation.UnsupportedAppUsage;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050023import android.os.Parcel;
24import android.os.Parcelable;
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -070025import android.os.RemoteException;
26
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -070027import com.android.internal.util.Preconditions;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050028
Daulet Zhanguzin0eb0a772019-12-30 17:13:24 +000029import java.util.Objects;
30
Mike Lockwoode7d511e2010-12-30 13:39:37 -050031/**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040032 * This class represents a USB device attached to the android device with the android device
33 * acting as the USB host.
34 * Each device contains one or more {@link UsbInterface}s, each of which contains a number of
35 * {@link UsbEndpoint}s (the channels via which data is transmitted over USB).
36 *
37 * <p> This class contains information (along with {@link UsbInterface} and {@link UsbEndpoint})
38 * that describes the capabilities of the USB device.
39 * To communicate with the device, you open a {@link UsbDeviceConnection} for the device
40 * and use {@link UsbRequest} to send and receive data on an endpoint.
41 * {@link UsbDeviceConnection#controlTransfer} is used for control requests on endpoint zero.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080042 *
43 * <div class="special reference">
44 * <h3>Developer Guides</h3>
45 * <p>For more information about communicating with USB hardware, read the
Dave Friedmandf0fd34d2017-04-10 14:50:24 -070046 * <a href="{@docRoot}guide/topics/connectivity/usb/index.html">USB</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080047 * </div>
Mike Lockwoode7d511e2010-12-30 13:39:37 -050048 */
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050049public class UsbDevice implements Parcelable {
Mike Lockwoode7d511e2010-12-30 13:39:37 -050050
51 private static final String TAG = "UsbDevice";
Paul McLean0a8f0692014-12-22 14:57:45 -070052 private static final boolean DEBUG = false;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050053
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -070054 private final @NonNull String mName;
55 private final @Nullable String mManufacturerName;
56 private final @Nullable String mProductName;
57 private final @NonNull String mVersion;
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -070058 private final @NonNull UsbConfiguration[] mConfigurations;
59 private final @NonNull IUsbSerialReader mSerialNumberReader;
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050060 private final int mVendorId;
61 private final int mProductId;
62 private final int mClass;
63 private final int mSubclass;
64 private final int mProtocol;
Paul McLeand3364532019-09-23 08:28:41 -060065 private final boolean mHasAudioPlayback;
66 private final boolean mHasAudioCapture;
Paul McLean9bd2f892019-10-04 20:15:33 -060067 private final boolean mHasMidi;
Paul McLeana7e7f942019-10-08 11:07:29 -060068 private final boolean mHasVideoPlayback;
69 private final boolean mHasVideoCapture;
Mike Lockwood7531aa22014-01-13 10:31:01 -080070
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -070071 /** All interfaces on the device. Initialized on first call to getInterfaceList */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010072 @UnsupportedAppUsage
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -070073 private @Nullable UsbInterface[] mInterfaces;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050074
75 /**
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -070076 * Create a new UsbDevice object. Only called by {@link Builder#build(IUsbSerialReader)}
77 *
Mike Lockwoode7d511e2010-12-30 13:39:37 -050078 * @hide
79 */
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -070080 private UsbDevice(@NonNull String name, int vendorId, int productId, int Class, int subClass,
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -070081 int protocol, @Nullable String manufacturerName, @Nullable String productName,
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -070082 @NonNull String version, @NonNull UsbConfiguration[] configurations,
Paul McLeand3364532019-09-23 08:28:41 -060083 @NonNull IUsbSerialReader serialNumberReader,
Paul McLeana7e7f942019-10-08 11:07:29 -060084 boolean hasAudioPlayback, boolean hasAudioCapture, boolean hasMidi,
85 boolean hasVideoPlayback, boolean hasVideoCapture) {
Daulet Zhanguzinfcc8d862019-12-18 14:42:04 +000086 mName = Objects.requireNonNull(name);
Mike Lockwoode7d511e2010-12-30 13:39:37 -050087 mVendorId = vendorId;
88 mProductId = productId;
89 mClass = Class;
90 mSubclass = subClass;
91 mProtocol = protocol;
Robin Cutshaw575ca852012-05-01 19:45:25 -040092 mManufacturerName = manufacturerName;
93 mProductName = productName;
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -070094 mVersion = Preconditions.checkStringNotEmpty(version);
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -070095 mConfigurations = Preconditions.checkArrayElementsNotNull(configurations, "configurations");
Daulet Zhanguzinfcc8d862019-12-18 14:42:04 +000096 mSerialNumberReader = Objects.requireNonNull(serialNumberReader);
Paul McLeand3364532019-09-23 08:28:41 -060097 mHasAudioPlayback = hasAudioPlayback;
98 mHasAudioCapture = hasAudioCapture;
Paul McLean9bd2f892019-10-04 20:15:33 -060099 mHasMidi = hasMidi;
Paul McLeana7e7f942019-10-08 11:07:29 -0600100 mHasVideoPlayback = hasVideoPlayback;
101 mHasVideoCapture = hasVideoCapture;
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700102
103 // Make sure the binder belongs to the system
104 if (ActivityThread.isSystem()) {
105 Preconditions.checkArgument(mSerialNumberReader instanceof IUsbSerialReader.Stub);
106 }
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500107 }
108
109 /**
110 * Returns the name of the device.
111 * In the standard implementation, this is the path of the device file
112 * for the device in the usbfs file system.
113 *
114 * @return the device name
115 */
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700116 public @NonNull String getDeviceName() {
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500117 return mName;
118 }
119
120 /**
Robin Cutshaw575ca852012-05-01 19:45:25 -0400121 * Returns the manufacturer name of the device.
122 *
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700123 * @return the manufacturer name, or {@code null} if the property could not be read
Robin Cutshaw575ca852012-05-01 19:45:25 -0400124 */
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700125 public @Nullable String getManufacturerName() {
Robin Cutshaw575ca852012-05-01 19:45:25 -0400126 return mManufacturerName;
127 }
128
129 /**
130 * Returns the product name of the device.
131 *
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700132 * @return the product name, or {@code null} if the property could not be read
Robin Cutshaw575ca852012-05-01 19:45:25 -0400133 */
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700134 public @Nullable String getProductName() {
Robin Cutshaw575ca852012-05-01 19:45:25 -0400135 return mProductName;
136 }
137
138 /**
Mike Lockwoodc9bb40e2015-04-29 13:05:55 -0700139 * Returns the version number of the device.
140 *
141 * @return the device version
142 */
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700143 public @NonNull String getVersion() {
Mike Lockwoodc9bb40e2015-04-29 13:05:55 -0700144 return mVersion;
145 }
146
147 /**
Robin Cutshaw575ca852012-05-01 19:45:25 -0400148 * Returns the serial number of the device.
149 *
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700150 * @return the serial number name, or {@code null} if the property could not be read
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700151 *
152 * @throws SecurityException if the app targets SDK >= {@value android.os.Build.VERSION_CODES#Q}
153 * and the app does not have permission to read from the device.
Robin Cutshaw575ca852012-05-01 19:45:25 -0400154 */
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700155 public @Nullable String getSerialNumber() {
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700156 try {
157 return mSerialNumberReader.getSerial(ActivityThread.currentPackageName());
158 } catch (RemoteException e) {
159 e.rethrowFromSystemServer();
160 return null;
161 }
Robin Cutshaw575ca852012-05-01 19:45:25 -0400162 }
163
164 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500165 * Returns a unique integer ID for the device.
166 * This is a convenience for clients that want to use an integer to represent
167 * the device, rather than the device name.
168 * IDs are not persistent across USB disconnects.
169 *
170 * @return the device ID
171 */
172 public int getDeviceId() {
173 return getDeviceId(mName);
174 }
175
176 /**
177 * Returns a vendor ID for the device.
178 *
179 * @return the device vendor ID
180 */
181 public int getVendorId() {
182 return mVendorId;
183 }
184
185 /**
186 * Returns a product ID for the device.
187 *
188 * @return the device product ID
189 */
190 public int getProductId() {
191 return mProductId;
192 }
193
194 /**
195 * Returns the devices's class field.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400196 * Some useful constants for USB device classes can be found in {@link UsbConstants}.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500197 *
198 * @return the devices's class
199 */
200 public int getDeviceClass() {
201 return mClass;
202 }
203
204 /**
205 * Returns the device's subclass field.
206 *
207 * @return the device's subclass
208 */
209 public int getDeviceSubclass() {
210 return mSubclass;
211 }
212
213 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400214 * Returns the device's protocol field.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500215 *
216 * @return the device's protocol
217 */
218 public int getDeviceProtocol() {
219 return mProtocol;
220 }
221
222 /**
Mike Lockwood7531aa22014-01-13 10:31:01 -0800223 * Returns the number of {@link UsbConfiguration}s this device contains.
224 *
225 * @return the number of configurations
226 */
227 public int getConfigurationCount() {
228 return mConfigurations.length;
229 }
230
Paul McLeand3364532019-09-23 08:28:41 -0600231 /** @hide */
232 public boolean getHasAudioPlayback() {
233 return mHasAudioPlayback;
234 }
235
236 /** @hide */
237 public boolean getHasAudioCapture() {
238 return mHasAudioCapture;
239 }
240
Paul McLean9bd2f892019-10-04 20:15:33 -0600241 /** @hide */
242 public boolean getHasMidi() {
243 return mHasMidi;
244 }
245
Paul McLeana7e7f942019-10-08 11:07:29 -0600246 /** @hide */
247 public boolean getHasVideoPlayback() {
248 return mHasVideoPlayback;
249 }
250
251 /** @hide */
252 public boolean getHasVideoCapture() {
253 return mHasVideoCapture;
254 }
255
Mike Lockwood7531aa22014-01-13 10:31:01 -0800256 /**
257 * Returns the {@link UsbConfiguration} at the given index.
258 *
259 * @return the configuration
260 */
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700261 public @NonNull UsbConfiguration getConfiguration(int index) {
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700262 return mConfigurations[index];
Mike Lockwood7531aa22014-01-13 10:31:01 -0800263 }
264
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700265 private @Nullable UsbInterface[] getInterfaceList() {
Mike Lockwood7531aa22014-01-13 10:31:01 -0800266 if (mInterfaces == null) {
267 int configurationCount = mConfigurations.length;
268 int interfaceCount = 0;
269 for (int i = 0; i < configurationCount; i++) {
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700270 UsbConfiguration configuration = mConfigurations[i];
Mike Lockwood7531aa22014-01-13 10:31:01 -0800271 interfaceCount += configuration.getInterfaceCount();
272 }
273
274 mInterfaces = new UsbInterface[interfaceCount];
275 int offset = 0;
276 for (int i = 0; i < configurationCount; i++) {
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700277 UsbConfiguration configuration = mConfigurations[i];
Mike Lockwood7531aa22014-01-13 10:31:01 -0800278 interfaceCount = configuration.getInterfaceCount();
279 for (int j = 0; j < interfaceCount; j++) {
280 mInterfaces[offset++] = configuration.getInterface(j);
281 }
282 }
283 }
284
285 return mInterfaces;
286 }
287
288 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400289 * Returns the number of {@link UsbInterface}s this device contains.
Mike Lockwood7531aa22014-01-13 10:31:01 -0800290 * For devices with multiple configurations, you will probably want to use
291 * {@link UsbConfiguration#getInterfaceCount} instead.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500292 *
293 * @return the number of interfaces
294 */
295 public int getInterfaceCount() {
Mike Lockwood7531aa22014-01-13 10:31:01 -0800296 return getInterfaceList().length;
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500297 }
298
299 /**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400300 * Returns the {@link UsbInterface} at the given index.
Mike Lockwood7531aa22014-01-13 10:31:01 -0800301 * For devices with multiple configurations, you will probably want to use
302 * {@link UsbConfiguration#getInterface} instead.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500303 *
304 * @return the interface
305 */
Philip P. Moltmannf2d83ed2016-10-17 12:14:41 -0700306 public @NonNull UsbInterface getInterface(int index) {
Mike Lockwood7531aa22014-01-13 10:31:01 -0800307 return getInterfaceList()[index];
308 }
309
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500310 @Override
311 public boolean equals(Object o) {
312 if (o instanceof UsbDevice) {
313 return ((UsbDevice)o).mName.equals(mName);
314 } else if (o instanceof String) {
315 return ((String)o).equals(mName);
316 } else {
317 return false;
318 }
319 }
320
321 @Override
Mike Lockwoodc6f23e82011-03-09 12:05:20 -0500322 public int hashCode() {
323 return mName.hashCode();
324 }
325
326 @Override
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500327 public String toString() {
Paul McLeand3364532019-09-23 08:28:41 -0600328 StringBuilder builder = new StringBuilder("UsbDevice[mName=" + mName
329 + ",mVendorId=" + mVendorId + ",mProductId=" + mProductId
330 + ",mClass=" + mClass + ",mSubclass=" + mSubclass + ",mProtocol=" + mProtocol
331 + ",mManufacturerName=" + mManufacturerName + ",mProductName=" + mProductName
332 + ",mVersion=" + mVersion + ",mSerialNumberReader=" + mSerialNumberReader
333 + ", mHasAudioPlayback=" + mHasAudioPlayback
334 + ", mHasAudioCapture=" + mHasAudioCapture
Paul McLean9bd2f892019-10-04 20:15:33 -0600335 + ", mHasMidi=" + mHasMidi
Paul McLeana7e7f942019-10-08 11:07:29 -0600336 + ", mHasVideoCapture=" + mHasVideoCapture
337 + ", mHasVideoPlayback=" + mHasVideoPlayback
Paul McLeand3364532019-09-23 08:28:41 -0600338 + ", mConfigurations=[");
Mike Lockwood7531aa22014-01-13 10:31:01 -0800339 for (int i = 0; i < mConfigurations.length; i++) {
340 builder.append("\n");
341 builder.append(mConfigurations[i].toString());
342 }
343 builder.append("]");
344 return builder.toString();
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500345 }
346
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700347 public static final @android.annotation.NonNull Parcelable.Creator<UsbDevice> CREATOR =
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500348 new Parcelable.Creator<UsbDevice>() {
349 public UsbDevice createFromParcel(Parcel in) {
350 String name = in.readString();
351 int vendorId = in.readInt();
352 int productId = in.readInt();
353 int clasz = in.readInt();
354 int subClass = in.readInt();
355 int protocol = in.readInt();
Robin Cutshaw575ca852012-05-01 19:45:25 -0400356 String manufacturerName = in.readString();
357 String productName = in.readString();
Mike Lockwoodc9bb40e2015-04-29 13:05:55 -0700358 String version = in.readString();
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700359 IUsbSerialReader serialNumberReader =
360 IUsbSerialReader.Stub.asInterface(in.readStrongBinder());
361 UsbConfiguration[] configurations = in.readParcelableArray(
362 UsbConfiguration.class.getClassLoader(), UsbConfiguration.class);
Paul McLeand3364532019-09-23 08:28:41 -0600363 // Capabilities
364 boolean hasAudioPlayback = in.readInt() == 1;
365 boolean hasAudioCapture = in.readInt() == 1;
Paul McLean9bd2f892019-10-04 20:15:33 -0600366 boolean hasMidi = in.readInt() == 1;
Paul McLeana7e7f942019-10-08 11:07:29 -0600367 boolean hasVideoPlayback = in.readInt() == 1;
368 boolean hasVideoCapture = in.readInt() == 1;
Mike Lockwood7531aa22014-01-13 10:31:01 -0800369 UsbDevice device = new UsbDevice(name, vendorId, productId, clasz, subClass, protocol,
Paul McLeand3364532019-09-23 08:28:41 -0600370 manufacturerName, productName, version, configurations, serialNumberReader,
Paul McLeana7e7f942019-10-08 11:07:29 -0600371 hasAudioPlayback, hasAudioCapture, hasMidi,
372 hasVideoPlayback, hasVideoCapture);
Paul McLeand3364532019-09-23 08:28:41 -0600373
Mike Lockwood7531aa22014-01-13 10:31:01 -0800374 return device;
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500375 }
376
377 public UsbDevice[] newArray(int size) {
378 return new UsbDevice[size];
379 }
380 };
381
382 public int describeContents() {
383 return 0;
384 }
385
386 public void writeToParcel(Parcel parcel, int flags) {
387 parcel.writeString(mName);
388 parcel.writeInt(mVendorId);
389 parcel.writeInt(mProductId);
390 parcel.writeInt(mClass);
391 parcel.writeInt(mSubclass);
392 parcel.writeInt(mProtocol);
Robin Cutshaw575ca852012-05-01 19:45:25 -0400393 parcel.writeString(mManufacturerName);
394 parcel.writeString(mProductName);
Mike Lockwoodc9bb40e2015-04-29 13:05:55 -0700395 parcel.writeString(mVersion);
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700396 parcel.writeStrongBinder(mSerialNumberReader.asBinder());
Mike Lockwood7531aa22014-01-13 10:31:01 -0800397 parcel.writeParcelableArray(mConfigurations, 0);
Paul McLeand3364532019-09-23 08:28:41 -0600398 parcel.writeInt(mHasAudioPlayback ? 1 : 0);
399 parcel.writeInt(mHasAudioCapture ? 1 : 0);
Paul McLean9bd2f892019-10-04 20:15:33 -0600400 parcel.writeInt(mHasMidi ? 1 : 0);
Paul McLeana7e7f942019-10-08 11:07:29 -0600401 parcel.writeInt(mHasVideoPlayback ? 1 : 0);
402 parcel.writeInt(mHasVideoCapture ? 1 : 0);
Paul McLean9bd2f892019-10-04 20:15:33 -0600403 }
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500404
405 public static int getDeviceId(String name) {
406 return native_get_device_id(name);
407 }
408
409 public static String getDeviceName(int id) {
410 return native_get_device_name(id);
411 }
412
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500413 private static native int native_get_device_id(String name);
414 private static native String native_get_device_name(int id);
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700415
416 /**
417 * @hide
418 */
419 public static class Builder {
420 private final @NonNull String mName;
421 private final int mVendorId;
422 private final int mProductId;
423 private final int mClass;
424 private final int mSubclass;
425 private final int mProtocol;
426 private final @Nullable String mManufacturerName;
427 private final @Nullable String mProductName;
428 private final @NonNull String mVersion;
429 private final @NonNull UsbConfiguration[] mConfigurations;
Paul McLeand3364532019-09-23 08:28:41 -0600430 private final boolean mHasAudioPlayback;
431 private final boolean mHasAudioCapture;
Paul McLean9bd2f892019-10-04 20:15:33 -0600432 private final boolean mHasMidi;
Paul McLeana7e7f942019-10-08 11:07:29 -0600433 private final boolean mHasVideoPlayback;
434 private final boolean mHasVideoCapture;
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700435
436 // Temporary storage for serial number. Serial number reader need to be wrapped in a
437 // IUsbSerialReader as they might be used as PII.
438 public final @Nullable String serialNumber;
439
440 public Builder(@NonNull String name, int vendorId, int productId, int Class, int subClass,
441 int protocol, @Nullable String manufacturerName, @Nullable String productName,
442 @NonNull String version, @NonNull UsbConfiguration[] configurations,
Paul McLeand3364532019-09-23 08:28:41 -0600443 @Nullable String serialNumber,
Paul McLeana7e7f942019-10-08 11:07:29 -0600444 boolean hasAudioPlayback, boolean hasAudioCapture, boolean hasMidi,
445 boolean hasVideoPlayback, boolean hasVideoCapture) {
Daulet Zhanguzinfcc8d862019-12-18 14:42:04 +0000446 mName = Objects.requireNonNull(name);
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700447 mVendorId = vendorId;
448 mProductId = productId;
449 mClass = Class;
450 mSubclass = subClass;
451 mProtocol = protocol;
452 mManufacturerName = manufacturerName;
453 mProductName = productName;
454 mVersion = Preconditions.checkStringNotEmpty(version);
455 mConfigurations = configurations;
456 this.serialNumber = serialNumber;
Paul McLeand3364532019-09-23 08:28:41 -0600457 mHasAudioPlayback = hasAudioPlayback;
458 mHasAudioCapture = hasAudioCapture;
Paul McLean9bd2f892019-10-04 20:15:33 -0600459 mHasMidi = hasMidi;
Paul McLeana7e7f942019-10-08 11:07:29 -0600460 mHasVideoPlayback = hasVideoPlayback;
461 mHasVideoCapture = hasVideoCapture;
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700462 }
463
464 /**
465 * Create a new {@link UsbDevice}
466 *
467 * @param serialReader The method to read the serial number.
468 *
469 * @return The usb device
470 */
471 public UsbDevice build(@NonNull IUsbSerialReader serialReader) {
472 return new UsbDevice(mName, mVendorId, mProductId, mClass, mSubclass, mProtocol,
Paul McLeand3364532019-09-23 08:28:41 -0600473 mManufacturerName, mProductName, mVersion, mConfigurations, serialReader,
Paul McLeana7e7f942019-10-08 11:07:29 -0600474 mHasAudioPlayback, mHasAudioCapture, mHasMidi,
475 mHasVideoPlayback, mHasVideoCapture);
Philip P. Moltmanna2c6eea2018-08-24 09:50:40 -0700476 }
477 }
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500478}