Philip P. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.hardware.usb; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import com.android.internal.annotations.Immutable; |
| 24 | |
| 25 | /** |
| 26 | * A parcelable wrapper to send UsbPorts over binders. |
| 27 | * |
| 28 | * @hide |
| 29 | */ |
| 30 | @Immutable |
| 31 | public final class ParcelableUsbPort implements Parcelable { |
| 32 | private final @NonNull String mId; |
| 33 | private final int mSupportedModes; |
Badhri Jagan Sridharan | e966a38 | 2018-12-09 14:49:38 -0800 | [diff] [blame] | 34 | private final int mSupportedContaminantProtectionModes; |
| 35 | private final boolean mSupportsEnableContaminantPresenceProtection; |
| 36 | private final boolean mSupportsEnableContaminantPresenceDetection; |
Philip P. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 37 | |
Badhri Jagan Sridharan | e966a38 | 2018-12-09 14:49:38 -0800 | [diff] [blame] | 38 | private ParcelableUsbPort(@NonNull String id, int supportedModes, |
| 39 | int supportedContaminantProtectionModes, |
| 40 | boolean supportsEnableContaminantPresenceProtection, |
| 41 | boolean supportsEnableContaminantPresenceDetection) { |
Philip P. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 42 | mId = id; |
| 43 | mSupportedModes = supportedModes; |
Badhri Jagan Sridharan | e966a38 | 2018-12-09 14:49:38 -0800 | [diff] [blame] | 44 | mSupportedContaminantProtectionModes = supportedContaminantProtectionModes; |
| 45 | mSupportsEnableContaminantPresenceProtection = |
| 46 | supportsEnableContaminantPresenceProtection; |
| 47 | mSupportsEnableContaminantPresenceDetection = |
| 48 | supportsEnableContaminantPresenceDetection; |
Philip P. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 49 | } |
| 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 Sridharan | e966a38 | 2018-12-09 14:49:38 -0800 | [diff] [blame] | 59 | return new ParcelableUsbPort(port.getId(), port.getSupportedModes(), |
| 60 | port.getSupportedContaminantProtectionModes(), |
| 61 | port.supportsEnableContaminantPresenceProtection(), |
| 62 | port.supportsEnableContaminantPresenceDetection()); |
Philip P. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 63 | } |
| 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 Sridharan | e966a38 | 2018-12-09 14:49:38 -0800 | [diff] [blame] | 73 | return new UsbPort(usbManager, mId, mSupportedModes, mSupportedContaminantProtectionModes, |
| 74 | mSupportsEnableContaminantPresenceProtection, |
| 75 | mSupportsEnableContaminantPresenceDetection); |
Philip P. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 76 | } |
| 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 Sridharan | e966a38 | 2018-12-09 14:49:38 -0800 | [diff] [blame] | 87 | dest.writeInt(mSupportedContaminantProtectionModes); |
| 88 | dest.writeBoolean(mSupportsEnableContaminantPresenceProtection); |
| 89 | dest.writeBoolean(mSupportsEnableContaminantPresenceDetection); |
Philip P. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | public static final Creator<ParcelableUsbPort> CREATOR = |
| 93 | new Creator<ParcelableUsbPort>() { |
| 94 | @Override |
| 95 | public ParcelableUsbPort createFromParcel(Parcel in) { |
| 96 | String id = in.readString(); |
| 97 | int supportedModes = in.readInt(); |
Badhri Jagan Sridharan | e966a38 | 2018-12-09 14:49:38 -0800 | [diff] [blame] | 98 | 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. Moltmann | 0ee6ee0 | 2018-09-21 10:00:29 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public ParcelableUsbPort[] newArray(int size) { |
| 110 | return new ParcelableUsbPort[size]; |
| 111 | } |
| 112 | }; |
| 113 | } |