blob: 19655edf9fb2f6e97e217d8d01583372158886c4 [file] [log] [blame]
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -07001/*
2 * Copyright (C) 2018 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
17package android.hardware.usb;
18
19import android.annotation.NonNull;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import com.android.internal.annotations.Immutable;
24
25/**
26 * A parcelable wrapper to send UsbPorts over binders.
27 *
28 * @hide
29 */
30@Immutable
31public final class ParcelableUsbPort implements Parcelable {
32 private final @NonNull String mId;
33 private final int mSupportedModes;
Badhri Jagan Sridharane966a382018-12-09 14:49:38 -080034 private final int mSupportedContaminantProtectionModes;
35 private final boolean mSupportsEnableContaminantPresenceProtection;
36 private final boolean mSupportsEnableContaminantPresenceDetection;
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -070037
Badhri Jagan Sridharane966a382018-12-09 14:49:38 -080038 private ParcelableUsbPort(@NonNull String id, int supportedModes,
39 int supportedContaminantProtectionModes,
40 boolean supportsEnableContaminantPresenceProtection,
41 boolean supportsEnableContaminantPresenceDetection) {
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -070042 mId = id;
43 mSupportedModes = supportedModes;
Badhri Jagan Sridharane966a382018-12-09 14:49:38 -080044 mSupportedContaminantProtectionModes = supportedContaminantProtectionModes;
45 mSupportsEnableContaminantPresenceProtection =
46 supportsEnableContaminantPresenceProtection;
47 mSupportsEnableContaminantPresenceDetection =
48 supportsEnableContaminantPresenceDetection;
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -070049 }
50
51 /**
52 * Create the parcelable version of a {@link UsbPort}.
53 *
54 * @param port The port to create a parcealable version of
55 *
56 * @return The parcelable version of the port
57 */
58 public static @NonNull ParcelableUsbPort of(@NonNull UsbPort port) {
Badhri Jagan Sridharane966a382018-12-09 14:49:38 -080059 return new ParcelableUsbPort(port.getId(), port.getSupportedModes(),
60 port.getSupportedContaminantProtectionModes(),
61 port.supportsEnableContaminantPresenceProtection(),
62 port.supportsEnableContaminantPresenceDetection());
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -070063 }
64
65 /**
66 * Create a {@link UsbPort} from this object.
67 *
68 * @param usbManager A link to the usbManager in the current context
69 *
70 * @return The UsbPort for this object
71 */
72 public @NonNull UsbPort getUsbPort(@NonNull UsbManager usbManager) {
Badhri Jagan Sridharane966a382018-12-09 14:49:38 -080073 return new UsbPort(usbManager, mId, mSupportedModes, mSupportedContaminantProtectionModes,
74 mSupportsEnableContaminantPresenceProtection,
75 mSupportsEnableContaminantPresenceDetection);
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -070076 }
77
78 @Override
79 public int describeContents() {
80 return 0;
81 }
82
83 @Override
84 public void writeToParcel(Parcel dest, int flags) {
85 dest.writeString(mId);
86 dest.writeInt(mSupportedModes);
Badhri Jagan Sridharane966a382018-12-09 14:49:38 -080087 dest.writeInt(mSupportedContaminantProtectionModes);
88 dest.writeBoolean(mSupportsEnableContaminantPresenceProtection);
89 dest.writeBoolean(mSupportsEnableContaminantPresenceDetection);
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -070090 }
91
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070092 public static final @android.annotation.NonNull Creator<ParcelableUsbPort> CREATOR =
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -070093 new Creator<ParcelableUsbPort>() {
94 @Override
95 public ParcelableUsbPort createFromParcel(Parcel in) {
96 String id = in.readString();
97 int supportedModes = in.readInt();
Badhri Jagan Sridharane966a382018-12-09 14:49:38 -080098 int supportedContaminantProtectionModes = in.readInt();
99 boolean supportsEnableContaminantPresenceProtection = in.readBoolean();
100 boolean supportsEnableContaminantPresenceDetection = in.readBoolean();
101
102 return new ParcelableUsbPort(id, supportedModes,
103 supportedContaminantProtectionModes,
104 supportsEnableContaminantPresenceProtection,
105 supportsEnableContaminantPresenceDetection);
Philip P. Moltmann0ee6ee02018-09-21 10:00:29 -0700106 }
107
108 @Override
109 public ParcelableUsbPort[] newArray(int size) {
110 return new ParcelableUsbPort[size];
111 }
112 };
113}