Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / android / CHIPTool / app / src / main / java / com / google / chip / chiptool / commissioner / thread / BorderAgentInfo.java
1 /*
2  *   Copyright (c) 2020 Project CHIP Authors
3  *   All rights reserved.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  */
18
19 package com.google.chip.chiptool.commissioner.thread;
20
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import androidx.annotation.NonNull;
24 import java.net.InetAddress;
25 import java.net.UnknownHostException;
26
27 public class BorderAgentInfo implements Parcelable {
28   public String discriminator;
29   public String networkName;
30   public byte[] extendedPanId;
31   public InetAddress host;
32   public int port;
33
34   public BorderAgentInfo(
35       @NonNull String discriminator,
36       @NonNull String networkName,
37       @NonNull byte[] extendedPanId,
38       @NonNull InetAddress host,
39       @NonNull int port) {
40     this.discriminator = discriminator;
41     this.networkName = networkName;
42     this.extendedPanId = extendedPanId;
43     this.host = host;
44     this.port = port;
45   }
46
47   protected BorderAgentInfo(Parcel in) {
48     discriminator = in.readString();
49     networkName = in.readString();
50     extendedPanId = in.createByteArray();
51     try {
52       host = InetAddress.getByAddress(in.createByteArray());
53     } catch (UnknownHostException e) {
54     }
55     port = in.readInt();
56   }
57
58   @Override
59   public void writeToParcel(Parcel dest, int flags) {
60     dest.writeString(discriminator);
61     dest.writeString(networkName);
62     dest.writeByteArray(extendedPanId);
63     dest.writeByteArray(host.getAddress());
64     dest.writeInt(port);
65   }
66
67   @Override
68   public int describeContents() {
69     return 0;
70   }
71
72   public boolean equals(BorderAgentInfo other) {
73     return this.discriminator.equals(other.discriminator);
74   }
75
76   public static final Creator<BorderAgentInfo> CREATOR =
77       new Creator<BorderAgentInfo>() {
78         @Override
79         public BorderAgentInfo createFromParcel(Parcel in) {
80           return new BorderAgentInfo(in);
81         }
82
83         @Override
84         public BorderAgentInfo[] newArray(int size) {
85           return new BorderAgentInfo[size];
86         }
87       };
88 }