blob: 1bef681619edecb45822bc7ff85651d29bb8fba2 [file] [log] [blame]
Wink Savilleb208a242012-07-25 14:08:09 -07001/*
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
17package android.telephony;
18
Nathan Harold78cf8ac2019-04-08 19:21:02 -070019import android.annotation.NonNull;
Artur Satayev74cb7192019-12-10 17:47:56 +000020import android.compat.annotation.UnsupportedAppUsage;
Mathew Inwood55418ea2018-12-20 15:30:45 +000021import android.os.Build;
Wink Savilleb208a242012-07-25 14:08:09 -070022import android.os.Parcel;
23import android.os.Parcelable;
Wink Savilleb208a242012-07-25 14:08:09 -070024
Meng Wang1dbea2f2020-01-30 12:25:08 -080025import com.android.telephony.Rlog;
26
Wink Savilleb208a242012-07-25 14:08:09 -070027/**
Nathan Harold054b79d2018-03-28 08:39:43 -070028 * A {@link CellInfo} representing a CDMA cell that provides identity and measurement info.
Wink Savilleb208a242012-07-25 14:08:09 -070029 */
30public 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 */
Mathew Inwooda8382062018-08-16 17:01:12 +010039 @UnsupportedAppUsage
Wink Savilleb208a242012-07-25 14:08:09 -070040 public CellInfoCdma() {
41 super();
42 mCellIdentityCdma = new CellIdentityCdma();
43 mCellSignalStrengthCdma = new CellSignalStrengthCdma();
44 }
45
46 /** @hide */
Mathew Inwood55418ea2018-12-20 15:30:45 +000047 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Wink Savilleb208a242012-07-25 14:08:09 -070048 public CellInfoCdma(CellInfoCdma ci) {
49 super(ci);
50 this.mCellIdentityCdma = ci.mCellIdentityCdma.copy();
51 this.mCellSignalStrengthCdma = ci.mCellSignalStrengthCdma.copy();
52 }
53
Nathan Harold7ce5baf2018-12-10 13:39:40 -080054 /** @hide */
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 */
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
Pengquan Meng629f1162019-01-14 17:14:58 -080072 /** @hide */
Nathan Harold6e3d94b2019-03-04 15:15:24 -080073 public CellInfoCdma(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) {
74 super(ci, timeStamp);
Pengquan Meng629f1162019-01-14 17:14:58 -080075 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
Sarah Chine9ce2ea2020-03-17 17:48:36 -070081 /** @hide */
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
Nathan Harold78cf8ac2019-04-08 19:21:02 -070090 /**
91 * @return a {@link CellIdentityCdma} instance.
92 */
Nathan Harold7b3f7a42018-07-09 11:59:53 -070093 @Override
Nathan Harold78cf8ac2019-04-08 19:21:02 -070094 public @NonNull CellIdentityCdma getCellIdentity() {
Wink Savilleb208a242012-07-25 14:08:09 -070095 return mCellIdentityCdma;
96 }
Nathan Harold78cf8ac2019-04-08 19:21:02 -070097
Wink Savilleb208a242012-07-25 14:08:09 -070098 /** @hide */
Mathew Inwooda8382062018-08-16 17:01:12 +010099 @UnsupportedAppUsage
Wink Savilleb208a242012-07-25 14:08:09 -0700100 public void setCellIdentity(CellIdentityCdma cid) {
101 mCellIdentityCdma = cid;
102 }
103
Nathan Harold78cf8ac2019-04-08 19:21:02 -0700104 /**
105 * @return a {@link CellSignalStrengthCdma} instance.
106 */
Nathan Harold7b3f7a42018-07-09 11:59:53 -0700107 @Override
Nathan Harold78cf8ac2019-04-08 19:21:02 -0700108 public @NonNull CellSignalStrengthCdma getCellSignalStrength() {
Wink Savilleb208a242012-07-25 14:08:09 -0700109 return mCellSignalStrengthCdma;
110 }
Hall Liuc9d74302019-02-28 15:29:19 -0800111
112 /** @hide */
113 @Override
114 public CellInfo sanitizeLocationInfo() {
115 CellInfoCdma result = new CellInfoCdma(this);
116 result.mCellIdentityCdma = mCellIdentityCdma.sanitizeLocationInfo();
117 return result;
118 }
119
Wink Savilleb208a242012-07-25 14:08:09 -0700120 /** @hide */
121 public void setCellSignalStrength(CellSignalStrengthCdma css) {
122 mCellSignalStrengthCdma = css;
123 }
124
125 /**
126 * @return hash code
127 */
128 @Override
129 public int hashCode() {
130 return super.hashCode() + mCellIdentityCdma.hashCode() + mCellSignalStrengthCdma.hashCode();
131 }
132
133 @Override
134 public boolean equals(Object other) {
135 if (!super.equals(other)) {
136 return false;
137 }
138 try {
139 CellInfoCdma o = (CellInfoCdma) other;
140 return mCellIdentityCdma.equals(o.mCellIdentityCdma)
141 && mCellSignalStrengthCdma.equals(o.mCellSignalStrengthCdma);
142 } catch (ClassCastException e) {
143 return false;
144 }
145 }
146
147 @Override
148 public String toString() {
149 StringBuffer sb = new StringBuffer();
150
Wink Saville094beec2013-04-05 15:03:31 -0700151 sb.append("CellInfoCdma:{");
Wink Savilleb208a242012-07-25 14:08:09 -0700152 sb.append(super.toString());
Wink Saville094beec2013-04-05 15:03:31 -0700153 sb.append(" ").append(mCellIdentityCdma);
154 sb.append(" ").append(mCellSignalStrengthCdma);
155 sb.append("}");
Wink Savilleb208a242012-07-25 14:08:09 -0700156
157 return sb.toString();
158 }
159
160 /** Implement the Parcelable interface */
161 @Override
162 public int describeContents() {
163 return 0;
164 }
165
166 /** Implement the Parcelable interface */
167 @Override
168 public void writeToParcel(Parcel dest, int flags) {
Wink Savillec6e4917a2012-09-21 13:54:05 -0700169 super.writeToParcel(dest, flags, TYPE_CDMA);
Wink Savilleb208a242012-07-25 14:08:09 -0700170 mCellIdentityCdma.writeToParcel(dest, flags);
171 mCellSignalStrengthCdma.writeToParcel(dest, flags);
172 }
173
174 /**
175 * Construct a CellInfoCdma object from the given parcel
176 * where the token is already been processed.
177 */
178 private CellInfoCdma(Parcel in) {
179 super(in);
180 mCellIdentityCdma = CellIdentityCdma.CREATOR.createFromParcel(in);
181 mCellSignalStrengthCdma = CellSignalStrengthCdma.CREATOR.createFromParcel(in);
182 if (DBG) log("CellInfoCdma(Parcel): " + toString());
183 }
184
185 /** Implement the Parcelable interface */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700186 public static final @android.annotation.NonNull Creator<CellInfoCdma> CREATOR = new Creator<CellInfoCdma>() {
Wink Savilleb208a242012-07-25 14:08:09 -0700187 @Override
188 public CellInfoCdma createFromParcel(Parcel in) {
189 in.readInt(); // Skip past token, we know what it is
190 return createFromParcelBody(in);
191 }
192
193 @Override
194 public CellInfoCdma[] newArray(int size) {
195 return new CellInfoCdma[size];
196 }
197 };
198
199 /** @hide */
200 protected static CellInfoCdma createFromParcelBody(Parcel in) {
201 return new CellInfoCdma(in);
202 }
203
204 /**
205 * log
206 */
207 private static void log(String s) {
Wink Saville599a90c2012-11-27 12:29:13 -0800208 Rlog.w(LOG_TAG, s);
Wink Savilleb208a242012-07-25 14:08:09 -0700209 }
210}