1 /*
2  * Copyright (C) 2020 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.debug;
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 import com.android.internal.util.Preconditions;
25 
26 /**
27  * Contains information about the client in an ADB connection.
28  * @hide
29  */
30 @Immutable
31 public class PairDevice implements Parcelable {
32     /**
33      * The human-readable name of the device.
34      */
35     @NonNull private final String mName;
36 
37     /**
38      * The device's guid.
39      */
40     @NonNull private final String mGuid;
41 
42     /**
43      * Indicates whether the device is currently connected to adbd.
44      */
45     private final boolean mConnected;
46 
PairDevice(@onNull String name, @NonNull String guid, boolean connected)47     public PairDevice(@NonNull String name, @NonNull String guid, boolean connected) {
48         Preconditions.checkStringNotEmpty(name);
49         Preconditions.checkStringNotEmpty(guid);
50         mName = name;
51         mGuid = guid;
52         mConnected = connected;
53     }
54 
55     /**
56      * @return the device name.
57      */
58     @NonNull
getDeviceName()59     public String getDeviceName() {
60         return mName;
61     }
62 
63     /**
64      * @return the device GUID.
65      */
66     @NonNull
getGuid()67     public String getGuid() {
68         return mGuid;
69     }
70 
71     /**
72      * @return the adb connection state of the device.
73      */
isConnected()74     public boolean isConnected() {
75         return mConnected;
76     }
77 
78     @Override
writeToParcel(@onNull Parcel dest, int flags)79     public void writeToParcel(@NonNull Parcel dest, int flags) {
80         dest.writeString(mName);
81         dest.writeString(mGuid);
82         dest.writeBoolean(mConnected);
83     }
84 
85     /**
86      * @return Human-readable info about the object.
87      */
88     @Override
toString()89     public String toString() {
90         return "\n" + mName + "\n" + mGuid + "\n" + mConnected;
91     }
92 
93     @Override
describeContents()94     public int describeContents() {
95         return 0;
96     }
97 
98     @NonNull
99     public static final Parcelable.Creator<PairDevice> CREATOR =
100             new Creator<PairDevice>() {
101                 @Override
102                 public PairDevice createFromParcel(Parcel source) {
103                     return new PairDevice(source.readString(), source.readString(),
104                             source.readBoolean());
105                 }
106 
107                 @Override
108                 public PairDevice[] newArray(int size) {
109                     return new PairDevice[size];
110                 }
111             };
112 }
113