Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.telephony; |
| 18 | |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
Meng Wang | 1dbea2f | 2020-01-30 12:25:08 -0800 | [diff] [blame] | 23 | import com.android.telephony.Rlog; |
| 24 | |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 25 | import java.util.Objects; |
| 26 | |
| 27 | /** |
| 28 | * A {@link CellInfo} representing a TD-SCDMA cell that provides identity and measurement info. |
| 29 | * |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 30 | * @see android.telephony.CellInfo |
| 31 | * @see android.telephony.CellSignalStrengthTdscdma |
| 32 | * @see android.telephony.CellIdentityTdscdma |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 33 | */ |
| 34 | public 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 Harold | 7ce5baf | 2018-12-10 13:39:40 -0800 | [diff] [blame] | 56 | /** @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 Meng | 629f116 | 2019-01-14 17:14:58 -0800 | [diff] [blame] | 72 | /** @hide */ |
Nathan Harold | 6e3d94b | 2019-03-04 15:15:24 -0800 | [diff] [blame] | 73 | public CellInfoTdscdma(android.hardware.radio.V1_4.CellInfo ci, long timeStamp) { |
| 74 | super(ci, timeStamp); |
Pengquan Meng | 629f116 | 2019-01-14 17:14:58 -0800 | [diff] [blame] | 75 | 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 Chin | e9ce2ea | 2020-03-17 17:48:36 -0700 | [diff] [blame] | 80 | /** @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 Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 88 | /** |
| 89 | * @return a {@link CellIdentityTdscdma} instance. |
| 90 | */ |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 91 | @Override |
| 92 | public @NonNull CellIdentityTdscdma getCellIdentity() { |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 93 | return mCellIdentityTdscdma; |
| 94 | } |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 95 | |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 96 | /** @hide */ |
| 97 | public void setCellIdentity(CellIdentityTdscdma cid) { |
| 98 | mCellIdentityTdscdma = cid; |
| 99 | } |
| 100 | |
Nathan Harold | 78cf8ac | 2019-04-08 19:21:02 -0700 | [diff] [blame] | 101 | /** |
| 102 | * @return a {@link CellSignalStrengthTdscdma} instance. |
| 103 | */ |
Nathan Harold | 7b3f7a4 | 2018-07-09 11:59:53 -0700 | [diff] [blame] | 104 | @Override |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 105 | public @NonNull CellSignalStrengthTdscdma getCellSignalStrength() { |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 106 | return mCellSignalStrengthTdscdma; |
| 107 | } |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 108 | |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 109 | /** @hide */ |
Hall Liu | c9d7430 | 2019-02-28 15:29:19 -0800 | [diff] [blame] | 110 | @Override |
| 111 | public CellInfo sanitizeLocationInfo() { |
| 112 | CellInfoTdscdma result = new CellInfoTdscdma(this); |
| 113 | result.mCellIdentityTdscdma = mCellIdentityTdscdma.sanitizeLocationInfo(); |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | /** @hide */ |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 118 | 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 Harold | 65c4b15 | 2018-07-30 16:10:50 -0700 | [diff] [blame] | 166 | super.writeToParcel(dest, flags, TYPE_TDSCDMA); |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 167 | 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 Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 182 | @NonNull |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 183 | public static final Creator<CellInfoTdscdma> CREATOR = new Creator<CellInfoTdscdma>() { |
| 184 | @Override |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 185 | public @NonNull CellInfoTdscdma createFromParcel(Parcel in) { |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 186 | in.readInt(); // Skip past token, we know what it is |
| 187 | return createFromParcelBody(in); |
| 188 | } |
| 189 | |
| 190 | @Override |
Nathan Harold | b2bfb29 | 2019-03-19 13:20:17 -0700 | [diff] [blame] | 191 | public @NonNull CellInfoTdscdma[] newArray(int size) { |
Nathan Harold | 054b79d | 2018-03-28 08:39:43 -0700 | [diff] [blame] | 192 | 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 | } |