1 /*
2  * Copyright (C) 2016 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.wifi.nl80211;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import com.android.internal.annotations.VisibleForTesting;
25 
26 import java.util.Objects;
27 
28 /**
29  * A class representing the radio chains of the Wi-Fi modems. Use to provide raw information about
30  * signals received on different radio chains.
31  *
32  * @hide
33  */
34 @SystemApi
35 public final class RadioChainInfo implements Parcelable {
36     private static final String TAG = "RadioChainInfo";
37 
38     /** @hide */
39     @VisibleForTesting
40     public int chainId;
41     /** @hide */
42     @VisibleForTesting
43     public int level;
44 
45     /**
46      * Return an identifier for this radio chain. This is an arbitrary ID which is consistent for
47      * the same device.
48      *
49      * @return The radio chain ID.
50      */
getChainId()51     public int getChainId() {
52         return chainId;
53     }
54 
55     /**
56      * Returns the detected signal level on this radio chain in dBm (aka RSSI).
57      *
58      * @return A signal level in dBm.
59      */
getLevelDbm()60     public int getLevelDbm() {
61         return level;
62     }
63 
64     /**
65      * Construct a RadioChainInfo.
66      */
RadioChainInfo(int chainId, int level)67     public RadioChainInfo(int chainId, int level) {
68         this.chainId = chainId;
69         this.level = level;
70     }
71 
72     /** override comparator */
73     @Override
equals(Object rhs)74     public boolean equals(Object rhs) {
75         if (this == rhs) return true;
76         if (!(rhs instanceof RadioChainInfo)) {
77             return false;
78         }
79         RadioChainInfo chainInfo = (RadioChainInfo) rhs;
80         if (chainInfo == null) {
81             return false;
82         }
83         return chainId == chainInfo.chainId && level == chainInfo.level;
84     }
85 
86     /** override hash code */
87     @Override
hashCode()88     public int hashCode() {
89         return Objects.hash(chainId, level);
90     }
91 
92 
93     /** implement Parcelable interface */
94     @Override
describeContents()95     public int describeContents() {
96         return 0;
97     }
98 
99     /**
100      * implement Parcelable interface
101      * |flags| is ignored.
102      */
103     @Override
writeToParcel(@onNull Parcel out, int flags)104     public void writeToParcel(@NonNull Parcel out, int flags) {
105         out.writeInt(chainId);
106         out.writeInt(level);
107     }
108 
109     /** implement Parcelable interface */
110     @NonNull public static final Parcelable.Creator<RadioChainInfo> CREATOR =
111             new Parcelable.Creator<RadioChainInfo>() {
112         /**
113          * Caller is responsible for providing a valid parcel.
114          */
115         @Override
116         public RadioChainInfo createFromParcel(Parcel in) {
117             return new RadioChainInfo(in.readInt(), in.readInt());
118         }
119 
120         @Override
121         public RadioChainInfo[] newArray(int size) {
122             return new RadioChainInfo[size];
123         }
124     };
125 }
126