Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 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 | |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Artur Satayev | 74cb719 | 2019-12-10 17:47:56 +0000 | [diff] [blame] | 20 | import android.compat.annotation.UnsupportedAppUsage; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 23 | |
Meng Wang | 1dbea2f | 2020-01-30 12:25:08 -0800 | [diff] [blame] | 24 | import com.android.telephony.Rlog; |
| 25 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 26 | /** |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 27 | * A {@link CellInfo} representing a GSM cell that provides identity and measurement info. |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 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 */ |
Mathew Inwood | a838206 | 2018-08-16 17:01:12 +0100 | [diff] [blame] | 38 | @UnsupportedAppUsage |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 39 | 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 Harold | 7ce5baf | 2018-12-10 13:39:40 -0800 | [diff] [blame] | 48 | 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 Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Pengquan Meng | 629f116 | 2019-01-14 17:14:58 -0800 | [diff] [blame] | 68 | /** @hide */ |
Nathan Harold | 6e3d94b | 2019-03-04 15:15:24 -0800 | [diff] [blame] | 69 | public CellInfoGsm(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) { |
| 70 | super(ci, timeStamp); |
Pengquan Meng | 629f116 | 2019-01-14 17:14:58 -0800 | [diff] [blame] | 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 | |
Sarah Chin | e9ce2ea | 2020-03-17 17:48:36 -0700 | [diff] [blame] | 76 | /** @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 Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 84 | /** |
| 85 | * @return a {@link CellIdentityGsm} instance. |
| 86 | */ |
Nathan Harold | 7b3f7a4 | 2018-07-09 11:59:53 -0700 | [diff] [blame] | 87 | @Override |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 88 | public @NonNull CellIdentityGsm getCellIdentity() { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 89 | return mCellIdentityGsm; |
| 90 | } |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 91 | |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 92 | /** @hide */ |
| 93 | public void setCellIdentity(CellIdentityGsm cid) { |
| 94 | mCellIdentityGsm = cid; |
| 95 | } |
| 96 | |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 97 | /** |
| 98 | * @return a {@link CellSignalStrengthGsm} instance. |
| 99 | */ |
Nathan Harold | 7b3f7a4 | 2018-07-09 11:59:53 -0700 | [diff] [blame] | 100 | @Override |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 101 | public @NonNull CellSignalStrengthGsm getCellSignalStrength() { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 102 | return mCellSignalStrengthGsm; |
| 103 | } |
Hall Liu | c9d7430 | 2019-02-28 15:29:19 -0800 | [diff] [blame] | 104 | |
| 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 Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 113 | /** @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 Saville | 094beec | 2013-04-05 15:03:31 -0700 | [diff] [blame] | 144 | sb.append("CellInfoGsm:{"); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 145 | sb.append(super.toString()); |
Wink Saville | 094beec | 2013-04-05 15:03:31 -0700 | [diff] [blame] | 146 | sb.append(" ").append(mCellIdentityGsm); |
| 147 | sb.append(" ").append(mCellSignalStrengthGsm); |
| 148 | sb.append("}"); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 149 | |
| 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 Saville | c6e4917a | 2012-09-21 13:54:05 -0700 | [diff] [blame] | 162 | super.writeToParcel(dest, flags, TYPE_GSM); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 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 | */ |
| 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 Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 178 | public static final @android.annotation.NonNull Creator<CellInfoGsm> CREATOR = new Creator<CellInfoGsm>() { |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 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 */ |
| 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 Saville | 599a90c | 2012-11-27 12:29:13 -0800 | [diff] [blame] | 200 | Rlog.w(LOG_TAG, s); |
Wink Saville | b208a24 | 2012-07-25 14:08:09 -0700 | [diff] [blame] | 201 | } |
| 202 | } |