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
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     /**
95      * @return a {@link CellIdentityLte} instance.
96      */
97     @Override
getCellIdentity()98     public @NonNull CellIdentityLte getCellIdentity() {
99         if (DBG) log("getCellIdentity: " + mCellIdentityLte);
100         return mCellIdentityLte;
101     }
102 
103     /** @hide */
104     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCellIdentity(CellIdentityLte cid)105     public void setCellIdentity(CellIdentityLte cid) {
106         if (DBG) log("setCellIdentity: " + cid);
107         mCellIdentityLte = cid;
108     }
109 
110     /**
111      * @return a {@link CellSignalStrengthLte} instance.
112      */
113     @Override
getCellSignalStrength()114     public @NonNull CellSignalStrengthLte getCellSignalStrength() {
115         if (DBG) log("getCellSignalStrength: " + mCellSignalStrengthLte);
116         return mCellSignalStrengthLte;
117     }
118 
119     /** @hide */
120     @Override
sanitizeLocationInfo()121     public CellInfo sanitizeLocationInfo() {
122         CellInfoLte result = new CellInfoLte(this);
123         result.mCellIdentityLte = mCellIdentityLte.sanitizeLocationInfo();
124         return result;
125     }
126 
127     /** @hide */
128     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
setCellSignalStrength(CellSignalStrengthLte css)129     public void setCellSignalStrength(CellSignalStrengthLte css) {
130         if (DBG) log("setCellSignalStrength: " + css);
131         mCellSignalStrengthLte = css;
132     }
133 
134     /** @hide */
setCellConfig(CellConfigLte cellConfig)135     public void setCellConfig(CellConfigLte cellConfig) {
136         if (DBG) log("setCellConfig: " + cellConfig);
137         mCellConfig = cellConfig;
138     }
139 
140     /** @hide */
getCellConfig()141     public CellConfigLte getCellConfig() {
142         if (DBG) log("getCellConfig: " + mCellConfig);
143         return mCellConfig;
144     }
145 
146     /**
147      * @return hash code
148      */
149     @Override
hashCode()150     public int hashCode() {
151         return Objects.hash(
152                 super.hashCode(),
153                 mCellIdentityLte.hashCode(),
154                 mCellSignalStrengthLte.hashCode(),
155                 mCellConfig.hashCode());
156     }
157 
158     @Override
equals(Object other)159     public boolean equals(Object other) {
160         if (!(other instanceof CellInfoLte)) return false;
161         CellInfoLte o = (CellInfoLte) other;
162         return super.equals(o) && mCellIdentityLte.equals(o.mCellIdentityLte)
163                 && mCellSignalStrengthLte.equals(o.mCellSignalStrengthLte)
164                 && mCellConfig.equals(o.mCellConfig);
165     }
166 
167     @Override
toString()168     public String toString() {
169         StringBuffer sb = new StringBuffer();
170 
171         sb.append("CellInfoLte:{");
172         sb.append(super.toString());
173         sb.append(" ").append(mCellIdentityLte);
174         sb.append(" ").append(mCellSignalStrengthLte);
175         sb.append(" ").append(mCellConfig);
176         sb.append("}");
177 
178         return sb.toString();
179     }
180 
181     /** Implement the Parcelable interface */
182     @Override
describeContents()183     public int describeContents() {
184         return 0;
185     }
186 
187     /** Implement the Parcelable interface */
188     @Override
writeToParcel(Parcel dest, int flags)189     public void writeToParcel(Parcel dest, int flags) {
190         if (DBG) log("writeToParcel(Parcel, int): " + toString());
191         super.writeToParcel(dest, flags, TYPE_LTE);
192         mCellIdentityLte.writeToParcel(dest, flags);
193         mCellSignalStrengthLte.writeToParcel(dest, flags);
194         mCellConfig.writeToParcel(dest, flags);
195     }
196 
197     /**
198      * Construct a CellInfoLte object from the given parcel
199      * where the TYPE_LTE token is already been processed.
200      */
CellInfoLte(Parcel in)201     private CellInfoLte(Parcel in) {
202         super(in);
203         mCellIdentityLte = CellIdentityLte.CREATOR.createFromParcel(in);
204         mCellSignalStrengthLte = CellSignalStrengthLte.CREATOR.createFromParcel(in);
205         mCellConfig = CellConfigLte.CREATOR.createFromParcel(in);
206         if (DBG) log("CellInfoLte(Parcel): " + toString());
207     }
208 
209     /** Implement the Parcelable interface */
210     public static final @android.annotation.NonNull Creator<CellInfoLte> CREATOR = new Creator<CellInfoLte>() {
211         @Override
212         public CellInfoLte createFromParcel(Parcel in) {
213             in.readInt(); // Skip past token, we know what it is
214             return createFromParcelBody(in);
215         }
216 
217         @Override
218         public CellInfoLte[] newArray(int size) {
219             return new CellInfoLte[size];
220         }
221     };
222 
223     /** @hide */
createFromParcelBody(Parcel in)224     protected static CellInfoLte createFromParcelBody(Parcel in) {
225         return new CellInfoLte(in);
226     }
227 
228     /**
229      * log
230      */
log(String s)231     private static void log(String s) {
232         Rlog.w(LOG_TAG, s);
233     }
234 }
235