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