blob: 038c49ac37ee26ea48015ed955ee32007d3ed309 [file] [log] [blame]
Nathan Harold054b79d2018-03-28 08:39:43 -07001/*
2 * Copyright (C) 2018 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 Haroldb2bfb292019-03-19 13:20:17 -070019import android.annotation.NonNull;
Nathan Harold054b79d2018-03-28 08:39:43 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
Meng Wang1dbea2f2020-01-30 12:25:08 -080023import com.android.telephony.Rlog;
24
Nathan Harold054b79d2018-03-28 08:39:43 -070025import java.util.Objects;
26
27/**
28 * A {@link CellInfo} representing a TD-SCDMA cell that provides identity and measurement info.
29 *
Nathan Haroldb2bfb292019-03-19 13:20:17 -070030 * @see android.telephony.CellInfo
31 * @see android.telephony.CellSignalStrengthTdscdma
32 * @see android.telephony.CellIdentityTdscdma
Nathan Harold054b79d2018-03-28 08:39:43 -070033 */
34public final class CellInfoTdscdma extends CellInfo implements Parcelable {
35
36 private static final String LOG_TAG = "CellInfoTdscdma";
37 private static final boolean DBG = false;
38
39 private CellIdentityTdscdma mCellIdentityTdscdma;
40 private CellSignalStrengthTdscdma mCellSignalStrengthTdscdma;
41
42 /** @hide */
43 public CellInfoTdscdma() {
44 super();
45 mCellIdentityTdscdma = new CellIdentityTdscdma();
46 mCellSignalStrengthTdscdma = new CellSignalStrengthTdscdma();
47 }
48
49 /** @hide */
50 public CellInfoTdscdma(CellInfoTdscdma ci) {
51 super(ci);
52 this.mCellIdentityTdscdma = ci.mCellIdentityTdscdma.copy();
53 this.mCellSignalStrengthTdscdma = ci.mCellSignalStrengthTdscdma.copy();
54 }
55
Nathan Harold7ce5baf2018-12-10 13:39:40 -080056 /** @hide */
57 public CellInfoTdscdma(android.hardware.radio.V1_0.CellInfo ci) {
58 super(ci);
59 final android.hardware.radio.V1_0.CellInfoTdscdma cit = ci.tdscdma.get(0);
60 mCellIdentityTdscdma = new CellIdentityTdscdma(cit.cellIdentityTdscdma);
61 mCellSignalStrengthTdscdma = new CellSignalStrengthTdscdma(cit.signalStrengthTdscdma);
62 }
63
64 /** @hide */
65 public CellInfoTdscdma(android.hardware.radio.V1_2.CellInfo ci) {
66 super(ci);
67 final android.hardware.radio.V1_2.CellInfoTdscdma cit = ci.tdscdma.get(0);
68 mCellIdentityTdscdma = new CellIdentityTdscdma(cit.cellIdentityTdscdma);
69 mCellSignalStrengthTdscdma = new CellSignalStrengthTdscdma(cit.signalStrengthTdscdma);
70 }
71
Pengquan Meng629f1162019-01-14 17:14:58 -080072 /** @hide */
Nathan Harold6e3d94b2019-03-04 15:15:24 -080073 public CellInfoTdscdma(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.CellInfoTdscdma cit = ci.info.tdscdma();
76 mCellIdentityTdscdma = new CellIdentityTdscdma(cit.cellIdentityTdscdma);
77 mCellSignalStrengthTdscdma = new CellSignalStrengthTdscdma(cit.signalStrengthTdscdma);
78 }
79
Sarah Chine9ce2ea2020-03-17 17:48:36 -070080 /** @hide */
81 public CellInfoTdscdma(android.hardware.radio.V1_5.CellInfo ci, long timeStamp) {
82 super(ci, timeStamp);
83 final android.hardware.radio.V1_5.CellInfoTdscdma cit = ci.ratSpecificInfo.tdscdma();
84 mCellIdentityTdscdma = new CellIdentityTdscdma(cit.cellIdentityTdscdma);
85 mCellSignalStrengthTdscdma = new CellSignalStrengthTdscdma(cit.signalStrengthTdscdma);
86 }
87
Nathan Harold78cf8ac2019-04-08 19:21:02 -070088 /**
89 * @return a {@link CellIdentityTdscdma} instance.
90 */
Nathan Haroldb2bfb292019-03-19 13:20:17 -070091 @Override
92 public @NonNull CellIdentityTdscdma getCellIdentity() {
Nathan Harold054b79d2018-03-28 08:39:43 -070093 return mCellIdentityTdscdma;
94 }
Nathan Haroldb2bfb292019-03-19 13:20:17 -070095
Nathan Harold054b79d2018-03-28 08:39:43 -070096 /** @hide */
97 public void setCellIdentity(CellIdentityTdscdma cid) {
98 mCellIdentityTdscdma = cid;
99 }
100
Nathan Harold78cf8ac2019-04-08 19:21:02 -0700101 /**
102 * @return a {@link CellSignalStrengthTdscdma} instance.
103 */
Nathan Harold7b3f7a42018-07-09 11:59:53 -0700104 @Override
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700105 public @NonNull CellSignalStrengthTdscdma getCellSignalStrength() {
Nathan Harold054b79d2018-03-28 08:39:43 -0700106 return mCellSignalStrengthTdscdma;
107 }
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700108
Nathan Harold054b79d2018-03-28 08:39:43 -0700109 /** @hide */
Hall Liuc9d74302019-02-28 15:29:19 -0800110 @Override
111 public CellInfo sanitizeLocationInfo() {
112 CellInfoTdscdma result = new CellInfoTdscdma(this);
113 result.mCellIdentityTdscdma = mCellIdentityTdscdma.sanitizeLocationInfo();
114 return result;
115 }
116
117 /** @hide */
Nathan Harold054b79d2018-03-28 08:39:43 -0700118 public void setCellSignalStrength(CellSignalStrengthTdscdma css) {
119 mCellSignalStrengthTdscdma = css;
120 }
121
122 /**
123 * @return hash code
124 */
125 @Override
126 public int hashCode() {
127 return Objects.hash(super.hashCode(), mCellIdentityTdscdma, mCellSignalStrengthTdscdma);
128 }
129
130 @Override
131 public boolean equals(Object other) {
132 if (!super.equals(other)) {
133 return false;
134 }
135 try {
136 CellInfoTdscdma o = (CellInfoTdscdma) other;
137 return mCellIdentityTdscdma.equals(o.mCellIdentityTdscdma)
138 && mCellSignalStrengthTdscdma.equals(o.mCellSignalStrengthTdscdma);
139 } catch (ClassCastException e) {
140 return false;
141 }
142 }
143
144 @Override
145 public String toString() {
146 StringBuffer sb = new StringBuffer();
147
148 sb.append("CellInfoTdscdma:{");
149 sb.append(super.toString());
150 sb.append(" ").append(mCellIdentityTdscdma);
151 sb.append(" ").append(mCellSignalStrengthTdscdma);
152 sb.append("}");
153
154 return sb.toString();
155 }
156
157 /** Implement the Parcelable interface */
158 @Override
159 public int describeContents() {
160 return 0;
161 }
162
163 /** Implement the Parcelable interface */
164 @Override
165 public void writeToParcel(Parcel dest, int flags) {
Nathan Harold65c4b152018-07-30 16:10:50 -0700166 super.writeToParcel(dest, flags, TYPE_TDSCDMA);
Nathan Harold054b79d2018-03-28 08:39:43 -0700167 mCellIdentityTdscdma.writeToParcel(dest, flags);
168 mCellSignalStrengthTdscdma.writeToParcel(dest, flags);
169 }
170
171 /**
172 * Construct a CellInfoTdscdma object from the given parcel
173 * where the token is already been processed.
174 */
175 private CellInfoTdscdma(Parcel in) {
176 super(in);
177 mCellIdentityTdscdma = CellIdentityTdscdma.CREATOR.createFromParcel(in);
178 mCellSignalStrengthTdscdma = CellSignalStrengthTdscdma.CREATOR.createFromParcel(in);
179 }
180
181 /** Implement the Parcelable interface */
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700182 @NonNull
Nathan Harold054b79d2018-03-28 08:39:43 -0700183 public static final Creator<CellInfoTdscdma> CREATOR = new Creator<CellInfoTdscdma>() {
184 @Override
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700185 public @NonNull CellInfoTdscdma createFromParcel(Parcel in) {
Nathan Harold054b79d2018-03-28 08:39:43 -0700186 in.readInt(); // Skip past token, we know what it is
187 return createFromParcelBody(in);
188 }
189
190 @Override
Nathan Haroldb2bfb292019-03-19 13:20:17 -0700191 public @NonNull CellInfoTdscdma[] newArray(int size) {
Nathan Harold054b79d2018-03-28 08:39:43 -0700192 return new CellInfoTdscdma[size];
193 }
194 };
195
196 /** @hide */
197 protected static CellInfoTdscdma createFromParcelBody(Parcel in) {
198 return new CellInfoTdscdma(in);
199 }
200
201 /**
202 * log
203 */
204 private static void log(String s) {
205 Rlog.w(LOG_TAG, s);
206 }
207}