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