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.net.shared;
18 
19 import android.annotation.Nullable;
20 import android.net.Layer2InformationParcelable;
21 import android.net.MacAddress;
22 
23 import java.util.Objects;
24 
25 /** @hide */
26 public class Layer2Information {
27     @Nullable
28     public final String mL2Key;
29     @Nullable
30     public final String mCluster;
31     @Nullable
32     public final MacAddress mBssid;
33 
34     /**
35      * Create a Layer2Information with the specified configuration.
36      */
Layer2Information(@ullable final String l2Key, @Nullable final String cluster, @Nullable final MacAddress bssid)37     public Layer2Information(@Nullable final String l2Key, @Nullable final String cluster,
38             @Nullable final MacAddress bssid) {
39         mL2Key = l2Key;
40         mCluster = cluster;
41         mBssid = bssid;
42     }
43 
44     @Override
toString()45     public String toString() {
46         StringBuffer str = new StringBuffer();
47         str.append("L2Key: ").append(mL2Key);
48         str.append(", Cluster: ").append(mCluster);
49         str.append(", bssid: ").append(mBssid);
50         return str.toString();
51     }
52 
53     /**
54      * Convert Layer2 Information to a {@link Layer2InformationParcelable}.
55      */
toStableParcelable()56     public Layer2InformationParcelable toStableParcelable() {
57         final Layer2InformationParcelable p = new Layer2InformationParcelable();
58         p.l2Key = mL2Key;
59         p.cluster = mCluster;
60         p.bssid = mBssid;
61         return p;
62     }
63 
64     /**
65      * Create an instance of {@link Layer2Information} based on the contents of the specified
66      * {@link Layer2InformationParcelable}.
67      */
fromStableParcelable(Layer2InformationParcelable p)68     public static Layer2Information fromStableParcelable(Layer2InformationParcelable p) {
69         if (p == null) return null;
70         return new Layer2Information(p.l2Key, p.cluster, p.bssid);
71     }
72 
73     @Override
equals(Object obj)74     public boolean equals(Object obj) {
75         if (!(obj instanceof Layer2Information)) return false;
76         final Layer2Information other = (Layer2Information) obj;
77         return Objects.equals(mL2Key, other.mL2Key)
78                 && Objects.equals(mCluster, other.mCluster)
79                 && Objects.equals(mBssid, other.mBssid);
80     }
81 
82     @Override
hashCode()83     public int hashCode() {
84         return Objects.hash(mL2Key, mCluster, mBssid);
85     }
86 }
87