1 /*
2  * Copyright (C) 2012 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.compat.annotation.UnsupportedAppUsage;
21 import android.os.Build;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import com.android.telephony.Rlog;
26 
27 import java.util.Objects;
28 
29 /**
30  * A {@link CellInfo} representing an LTE cell that provides identity and measurement info.
31  */
32 public final class CellInfoLte extends CellInfo implements Parcelable {
33 
34     private static final String LOG_TAG = "CellInfoLte";
35     private static final boolean DBG = false;
36 
37     private CellIdentityLte mCellIdentityLte;
38     private CellSignalStrengthLte mCellSignalStrengthLte;
39     private CellConfigLte mCellConfig;
40 
41     /** @hide */
42     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
CellInfoLte()43     public CellInfoLte() {
44         super();
45         mCellIdentityLte = new CellIdentityLte();
46         mCellSignalStrengthLte = new CellSignalStrengthLte();
47         mCellConfig = new CellConfigLte();
48     }
49 
50     /** @hide */
CellInfoLte(CellInfoLte ci)51     public CellInfoLte(CellInfoLte ci) {
52         super(ci);
53         this.mCellIdentityLte = ci.mCellIdentityLte.copy();
54         this.mCellSignalStrengthLte = ci.mCellSignalStrengthLte.copy();
55         this.mCellConfig = new CellConfigLte(ci.mCellConfig);
56     }
57 
58     /** @hide */
CellInfoLte(android.hardware.radio.V1_0.CellInfo ci)59     public CellInfoLte(android.hardware.radio.V1_0.CellInfo ci) {
60         super(ci);
61         final android.hardware.radio.V1_0.CellInfoLte cil = ci.lte.get(0);
62         mCellIdentityLte = new CellIdentityLte(cil.cellIdentityLte);
63         mCellSignalStrengthLte = new CellSignalStrengthLte(cil.signalStrengthLte);
64         mCellConfig = new CellConfigLte();
65     }
66 
67     /** @hide */
CellInfoLte(android.hardware.radio.V1_2.CellInfo ci)68     public CellInfoLte(android.hardware.radio.V1_2.CellInfo ci) {
69         super(ci);
70         final android.hardware.radio.V1_2.CellInfoLte cil = ci.lte.get(0);
71         mCellIdentityLte = new CellIdentityLte(cil.cellIdentityLte);
72         mCellSignalStrengthLte = new CellSignalStrengthLte(cil.signalStrengthLte);
73         mCellConfig = new CellConfigLte();
74     }
75 
76     /** @hide */
CellInfoLte(android.hardware.radio.V1_4.CellInfo ci, long timeStamp)77     public CellInfoLte(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) {
78         super(ci, timeStamp);
79         final android.hardware.radio.V1_4.CellInfoLte cil = ci.info.lte();
80         mCellIdentityLte = new CellIdentityLte(cil.base.cellIdentityLte);
81         mCellSignalStrengthLte = new CellSignalStrengthLte(cil.base.signalStrengthLte);
82         mCellConfig = new CellConfigLte(cil.cellConfig);
83     }
84 
85     /** @hide */
CellInfoLte(android.hardware.radio.V1_5.CellInfo ci, long timeStamp)86     public CellInfoLte(android.hardware.radio.V1_5.CellInfo ci, long timeStamp) {
87         super(ci, timeStamp);
88         final android.hardware.radio.V1_5.CellInfoLte cil = ci.ratSpecificInfo.lte();
89         mCellIdentityLte = new CellIdentityLte(cil.cellIdentityLte);
90         mCellSignalStrengthLte = new CellSignalStrengthLte(cil.signalStrengthLte);
91         mCellConfig = new CellConfigLte();
92     }
93 
94     /** @hide */
CellInfoLte(android.hardware.radio.V1_6.CellInfo ci, long timeStamp)95     public CellInfoLte(android.hardware.radio.V1_6.CellInfo ci, long timeStamp) {
96         super(ci, timeStamp);
97         final android.hardware.radio.V1_6.CellInfoLte cil = ci.ratSpecificInfo.lte();
98         mCellIdentityLte = new CellIdentityLte(cil.cellIdentityLte);
99         mCellSignalStrengthLte = new CellSignalStrengthLte(cil.signalStrengthLte);
100         mCellConfig = new CellConfigLte();
101     }
102 
103     /**
104      * @return a {@link CellIdentityLte} instance.
105      */
106     @Override
getCellIdentity()107     public @NonNull CellIdentityLte getCellIdentity() {
108         if (DBG) log("getCellIdentity: " + mCellIdentityLte);
109         return mCellIdentityLte;
110     }
111 
112     /** @hide */
113     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCellIdentity(CellIdentityLte cid)114     public void setCellIdentity(CellIdentityLte cid) {
115         if (DBG) log("setCellIdentity: " + cid);
116         mCellIdentityLte = cid;
117     }
118 
119     /**
120      * @return a {@link CellSignalStrengthLte} instance.
121      */
122     @Override
getCellSignalStrength()123     public @NonNull CellSignalStrengthLte getCellSignalStrength() {
124         if (DBG) log("getCellSignalStrength: " + mCellSignalStrengthLte);
125         return mCellSignalStrengthLte;
126     }
127 
128     /** @hide */
129     @Override
sanitizeLocationInfo()130     public CellInfo sanitizeLocationInfo() {
131         CellInfoLte result = new CellInfoLte(this);
132         result.mCellIdentityLte = mCellIdentityLte.sanitizeLocationInfo();
133         return result;
134     }
135 
136     /** @hide */
137     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCellSignalStrength(CellSignalStrengthLte css)138     public void setCellSignalStrength(CellSignalStrengthLte css) {
139         if (DBG) log("setCellSignalStrength: " + css);
140         mCellSignalStrengthLte = css;
141     }
142 
143     /** @hide */
setCellConfig(CellConfigLte cellConfig)144     public void setCellConfig(CellConfigLte cellConfig) {
145         if (DBG) log("setCellConfig: " + cellConfig);
146         mCellConfig = cellConfig;
147     }
148 
149     /** @hide */
getCellConfig()150     public CellConfigLte getCellConfig() {
151         if (DBG) log("getCellConfig: " + mCellConfig);
152         return mCellConfig;
153     }
154 
155     /**
156      * @return hash code
157      */
158     @Override
hashCode()159     public int hashCode() {
160         return Objects.hash(
161                 super.hashCode(),
162                 mCellIdentityLte.hashCode(),
163                 mCellSignalStrengthLte.hashCode(),
164                 mCellConfig.hashCode());
165     }
166 
167     @Override
equals(Object other)168     public boolean equals(Object other) {
169         if (!(other instanceof CellInfoLte)) return false;
170         CellInfoLte o = (CellInfoLte) other;
171         return super.equals(o) && mCellIdentityLte.equals(o.mCellIdentityLte)
172                 && mCellSignalStrengthLte.equals(o.mCellSignalStrengthLte)
173                 && mCellConfig.equals(o.mCellConfig);
174     }
175 
176     @Override
toString()177     public String toString() {
178         StringBuffer sb = new StringBuffer();
179 
180         sb.append("CellInfoLte:{");
181         sb.append(super.toString());
182         sb.append(" ").append(mCellIdentityLte);
183         sb.append(" ").append(mCellSignalStrengthLte);
184         sb.append(" ").append(mCellConfig);
185         sb.append("}");
186 
187         return sb.toString();
188     }
189 
190     /** Implement the Parcelable interface */
191     @Override
describeContents()192     public int describeContents() {
193         return 0;
194     }
195 
196     /** Implement the Parcelable interface */
197     @Override
writeToParcel(Parcel dest, int flags)198     public void writeToParcel(Parcel dest, int flags) {
199         if (DBG) log("writeToParcel(Parcel, int): " + toString());
200         super.writeToParcel(dest, flags, TYPE_LTE);
201         mCellIdentityLte.writeToParcel(dest, flags);
202         mCellSignalStrengthLte.writeToParcel(dest, flags);
203         mCellConfig.writeToParcel(dest, flags);
204     }
205 
206     /**
207      * Construct a CellInfoLte object from the given parcel
208      * where the TYPE_LTE token is already been processed.
209      */
CellInfoLte(Parcel in)210     private CellInfoLte(Parcel in) {
211         super(in);
212         mCellIdentityLte = CellIdentityLte.CREATOR.createFromParcel(in);
213         mCellSignalStrengthLte = CellSignalStrengthLte.CREATOR.createFromParcel(in);
214         mCellConfig = CellConfigLte.CREATOR.createFromParcel(in);
215         if (DBG) log("CellInfoLte(Parcel): " + toString());
216     }
217 
218     /** Implement the Parcelable interface */
219     public static final @android.annotation.NonNull Creator<CellInfoLte> CREATOR = new Creator<CellInfoLte>() {
220         @Override
221         public CellInfoLte createFromParcel(Parcel in) {
222             in.readInt(); // Skip past token, we know what it is
223             return createFromParcelBody(in);
224         }
225 
226         @Override
227         public CellInfoLte[] newArray(int size) {
228             return new CellInfoLte[size];
229         }
230     };
231 
232     /** @hide */
createFromParcelBody(Parcel in)233     protected static CellInfoLte createFromParcelBody(Parcel in) {
234         return new CellInfoLte(in);
235     }
236 
237     /**
238      * log
239      */
log(String s)240     private static void log(String s) {
241         Rlog.w(LOG_TAG, s);
242     }
243 }
244