blob: c19521fdfa996acbc81044f676cb08cd09866333 [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;
Wink Savilleb208a242012-07-25 14:08:09 -070021import android.os.Parcel;
22import android.os.Parcelable;
Wink Savilleb208a242012-07-25 14:08:09 -070023
Meng Wang1dbea2f2020-01-30 12:25:08 -080024import com.android.telephony.Rlog;
25
Wink Savilleb208a242012-07-25 14:08:09 -070026/**
Nathan Harold054b79d2018-03-28 08:39:43 -070027 * A {@link CellInfo} representing a GSM cell that provides identity and measurement info.
Wink Savilleb208a242012-07-25 14:08:09 -070028 */
29public 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 */
Mathew Inwooda8382062018-08-16 17:01:12 +010038 @UnsupportedAppUsage
Wink Savilleb208a242012-07-25 14:08:09 -070039 public CellInfoGsm() {
40 super();
41 mCellIdentityGsm = new CellIdentityGsm();
42 mCellSignalStrengthGsm = new CellSignalStrengthGsm();
43 }
44
45 /** @hide */
46 public CellInfoGsm(CellInfoGsm ci) {
47 super(ci);
Nathan Harold7ce5baf2018-12-10 13:39:40 -080048 mCellIdentityGsm = ci.mCellIdentityGsm.copy();
49 mCellSignalStrengthGsm = ci.mCellSignalStrengthGsm.copy();
50 }
51
52 /** @hide */
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 */
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);
Wink Savilleb208a242012-07-25 14:08:09 -070066 }
67
Pengquan Meng629f1162019-01-14 17:14:58 -080068 /** @hide */
Nathan Harold6e3d94b2019-03-04 15:15:24 -080069 public CellInfoGsm(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) {
70 super(ci, timeStamp);
Pengquan Meng629f1162019-01-14 17:14:58 -080071 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
Sarah Chine9ce2ea2020-03-17 17:48:36 -070076 /** @hide */
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
Nathan Harold78cf8ac2019-04-08 19:21:02 -070084 /**
85 * @return a {@link CellIdentityGsm} instance.
86 */
Nathan Harold7b3f7a42018-07-09 11:59:53 -070087 @Override
Nathan Harold78cf8ac2019-04-08 19:21:02 -070088 public @NonNull CellIdentityGsm getCellIdentity() {
Wink Savilleb208a242012-07-25 14:08:09 -070089 return mCellIdentityGsm;
90 }
Nathan Harold78cf8ac2019-04-08 19:21:02 -070091
Wink Savilleb208a242012-07-25 14:08:09 -070092 /** @hide */
93 public void setCellIdentity(CellIdentityGsm cid) {
94 mCellIdentityGsm = cid;
95 }
96
Nathan Harold78cf8ac2019-04-08 19:21:02 -070097 /**
98 * @return a {@link CellSignalStrengthGsm} instance.
99 */
Nathan Harold7b3f7a42018-07-09 11:59:53 -0700100 @Override
Nathan Harold78cf8ac2019-04-08 19:21:02 -0700101 public @NonNull CellSignalStrengthGsm getCellSignalStrength() {
Wink Savilleb208a242012-07-25 14:08:09 -0700102 return mCellSignalStrengthGsm;
103 }
Hall Liuc9d74302019-02-28 15:29:19 -0800104
105 /** @hide */
106 @Override
107 public CellInfo sanitizeLocationInfo() {
108 CellInfoGsm result = new CellInfoGsm(this);
109 result.mCellIdentityGsm = mCellIdentityGsm.sanitizeLocationInfo();
110 return result;
111 }
112
Wink Savilleb208a242012-07-25 14:08:09 -0700113 /** @hide */
114 public void setCellSignalStrength(CellSignalStrengthGsm css) {
115 mCellSignalStrengthGsm = css;
116 }
117
118 /**
119 * @return hash code
120 */
121 @Override
122 public int hashCode() {
123 return super.hashCode() + mCellIdentityGsm.hashCode() + mCellSignalStrengthGsm.hashCode();
124 }
125
126 @Override
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
141 public String toString() {
142 StringBuffer sb = new StringBuffer();
143
Wink Saville094beec2013-04-05 15:03:31 -0700144 sb.append("CellInfoGsm:{");
Wink Savilleb208a242012-07-25 14:08:09 -0700145 sb.append(super.toString());
Wink Saville094beec2013-04-05 15:03:31 -0700146 sb.append(" ").append(mCellIdentityGsm);
147 sb.append(" ").append(mCellSignalStrengthGsm);
148 sb.append("}");
Wink Savilleb208a242012-07-25 14:08:09 -0700149
150 return sb.toString();
151 }
152
153 /** Implement the Parcelable interface */
154 @Override
155 public int describeContents() {
156 return 0;
157 }
158
159 /** Implement the Parcelable interface */
160 @Override
161 public void writeToParcel(Parcel dest, int flags) {
Wink Savillec6e4917a2012-09-21 13:54:05 -0700162 super.writeToParcel(dest, flags, TYPE_GSM);
Wink Savilleb208a242012-07-25 14:08:09 -0700163 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 */
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 */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700178 public static final @android.annotation.NonNull Creator<CellInfoGsm> CREATOR = new Creator<CellInfoGsm>() {
Wink Savilleb208a242012-07-25 14:08:09 -0700179 @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 */
192 protected static CellInfoGsm createFromParcelBody(Parcel in) {
193 return new CellInfoGsm(in);
194 }
195
196 /**
197 * log
198 */
199 private static void log(String s) {
Wink Saville599a90c2012-11-27 12:29:13 -0800200 Rlog.w(LOG_TAG, s);
Wink Savilleb208a242012-07-25 14:08:09 -0700201 }
202}