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.telephony;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 
22 import dalvik.annotation.codegen.CovariantReturnType;
23 
24 import java.util.Objects;
25 
26 /**
27  * A {@link CellInfo} representing an 5G NR cell that provides identity and measurement info.
28  */
29 public final class CellInfoNr extends CellInfo {
30     private static final String TAG = "CellInfoNr";
31 
32     private CellIdentityNr mCellIdentity;
33     private final CellSignalStrengthNr mCellSignalStrength;
34 
35     /** @hide */
CellInfoNr()36     public CellInfoNr() {
37         super();
38         mCellIdentity = new CellIdentityNr();
39         mCellSignalStrength = new CellSignalStrengthNr();
40     }
41 
CellInfoNr(Parcel in)42     private CellInfoNr(Parcel in) {
43         super(in);
44         mCellIdentity = CellIdentityNr.CREATOR.createFromParcel(in);
45         mCellSignalStrength = CellSignalStrengthNr.CREATOR.createFromParcel(in);
46     }
47 
CellInfoNr(CellInfoNr other, boolean sanitizeLocationInfo)48     private CellInfoNr(CellInfoNr other, boolean sanitizeLocationInfo) {
49         super(other);
50         mCellIdentity = sanitizeLocationInfo ? other.mCellIdentity.sanitizeLocationInfo()
51                 : other.mCellIdentity;
52         mCellSignalStrength = other.mCellSignalStrength;
53     }
54 
55     /** @hide */
CellInfoNr(int connectionStatus, boolean registered, long timeStamp, CellIdentityNr cellIdentityNr, CellSignalStrengthNr cellSignalStrengthNr)56     public CellInfoNr(int connectionStatus, boolean registered, long timeStamp,
57             CellIdentityNr cellIdentityNr, CellSignalStrengthNr cellSignalStrengthNr) {
58         super(connectionStatus, registered, timeStamp);
59         mCellIdentity = cellIdentityNr;
60         mCellSignalStrength = cellSignalStrengthNr;
61     }
62 
63     /**
64      * @return a {@link CellIdentityNr} instance.
65      */
66     @CovariantReturnType(returnType = CellIdentityNr.class, presentAfter = 29)
67     @Override
68     @NonNull
getCellIdentity()69     public CellIdentity getCellIdentity() {
70         return mCellIdentity;
71     }
72 
73     /** @hide */
setCellIdentity(CellIdentityNr cid)74     public void setCellIdentity(CellIdentityNr cid) {
75         mCellIdentity = cid;
76     }
77 
78     /**
79      * @return a {@link CellSignalStrengthNr} instance.
80      */
81     @CovariantReturnType(returnType = CellSignalStrengthNr.class, presentAfter = 29)
82     @Override
83     @NonNull
getCellSignalStrength()84     public CellSignalStrength getCellSignalStrength() {
85         return mCellSignalStrength;
86     }
87 
88     /** @hide */
89     @Override
sanitizeLocationInfo()90     public CellInfo sanitizeLocationInfo() {
91         return new CellInfoNr(this, true);
92     }
93 
94     @Override
hashCode()95     public int hashCode() {
96         return Objects.hash(super.hashCode(), mCellIdentity, mCellSignalStrength);
97     }
98 
99     @Override
equals(Object other)100     public boolean equals(Object other) {
101         if (!(other instanceof CellInfoNr)) {
102             return false;
103         }
104 
105         CellInfoNr o = (CellInfoNr) other;
106         return super.equals(o) && mCellIdentity.equals(o.mCellIdentity)
107                 && mCellSignalStrength.equals(o.mCellSignalStrength);
108     }
109 
110     @Override
toString()111     public String toString() {
112         return new StringBuilder()
113                 .append(TAG + ":{")
114                 .append(" " + super.toString())
115                 .append(" " + mCellIdentity)
116                 .append(" " + mCellSignalStrength)
117                 .append(" }")
118                 .toString();
119     }
120 
121     @Override
writeToParcel(Parcel dest, int flags)122     public void writeToParcel(Parcel dest, int flags) {
123         super.writeToParcel(dest, flags, TYPE_NR);
124         mCellIdentity.writeToParcel(dest, flags);
125         mCellSignalStrength.writeToParcel(dest, flags);
126     }
127 
128     public static final @android.annotation.NonNull Creator<CellInfoNr> CREATOR = new Creator<CellInfoNr>() {
129         @Override
130         public CellInfoNr createFromParcel(Parcel in) {
131             // Skip the type info.
132             in.readInt();
133             return new CellInfoNr(in);
134         }
135 
136         @Override
137         public CellInfoNr[] newArray(int size) {
138             return new CellInfoNr[size];
139         }
140     };
141 
142     /** @hide */
createFromParcelBody(Parcel in)143     protected static CellInfoNr createFromParcelBody(Parcel in) {
144         return new CellInfoNr(in);
145     }
146 }
147