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