Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -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 | |
| 19 | import android.os.Parcel; |
| 20 | import android.telephony.gsm.GsmCellLocation; |
| 21 | |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Information to represent a unique 5G NR cell. |
| 26 | */ |
| 27 | public final class CellIdentityNr extends CellIdentity { |
| 28 | private static final String TAG = "CellIdentityNr"; |
| 29 | |
| 30 | private final int mNrArfcn; |
| 31 | private final int mPci; |
| 32 | private final int mTac; |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 33 | private final long mNci; |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * |
| 37 | * @param pci Physical Cell Id in range [0, 1007]. |
| 38 | * @param tac 16-bit Tracking Area Code. |
| 39 | * @param nrArfcn NR Absolute Radio Frequency Channel Number, in range [0, 3279165]. |
| 40 | * @param mccStr 3-digit Mobile Country Code in string format. |
| 41 | * @param mncStr 2 or 3-digit Mobile Network Code in string format. |
| 42 | * @param alphal long alpha Operator Name String or Enhanced Operator Name String. |
| 43 | * @param alphas short alpha Operator Name String or Enhanced Operator Name String. |
| 44 | * |
| 45 | * @hide |
| 46 | */ |
| 47 | public CellIdentityNr(int pci, int tac, int nrArfcn, String mccStr, String mncStr, |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 48 | long nci, String alphal, String alphas) { |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 49 | super(TAG, CellInfo.TYPE_NR, mccStr, mncStr, alphal, alphas); |
| 50 | mPci = pci; |
| 51 | mTac = tac; |
| 52 | mNrArfcn = nrArfcn; |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 53 | mNci = nci; |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @return a CellLocation object for this CellIdentity. |
| 58 | * @hide |
| 59 | */ |
| 60 | @Override |
| 61 | public CellLocation asCellLocation() { |
| 62 | return new GsmCellLocation(); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public int hashCode() { |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 67 | return Objects.hash(super.hashCode(), mPci, mTac, mNrArfcn, mNci); |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean equals(Object other) { |
| 72 | if (!(other instanceof CellIdentityNr)) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | CellIdentityNr o = (CellIdentityNr) other; |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 77 | return super.equals(o) && mPci == o.mPci && mTac == o.mTac && mNrArfcn == o.mNrArfcn |
| 78 | && mNci == o.mNci; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Get the NR Cell Identity. |
| 83 | * |
Nathan Harold | e2823007 | 2019-02-22 13:22:46 -0800 | [diff] [blame] | 84 | * @return The 36-bit NR Cell Identity in range [0, 68719476735] or |
| 85 | * {@link CellInfo#UNAVAILABLE_LONG} if unknown. |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 86 | */ |
| 87 | public long getNci() { |
| 88 | return mNci; |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the Absolute Radio Frequency Channel Number. |
| 93 | * @return Integer value in range [0, 3279165] or {@link CellInfo#UNAVAILABLE} if unknown. |
| 94 | */ |
| 95 | @Override |
| 96 | public int getChannelNumber() { |
| 97 | return mNrArfcn; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get the physical cell id. |
| 102 | * @return Integer value in range [0, 1007] or {@link CellInfo#UNAVAILABLE} if unknown. |
| 103 | */ |
| 104 | public int getPci() { |
| 105 | return mPci; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get the tracking area code. |
| 110 | * @return a 16 bit integer or {@link CellInfo#UNAVAILABLE} if unknown. |
| 111 | */ |
| 112 | public int getTac() { |
| 113 | return mTac; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @return Mobile Country Code in string format, or {@code null} if unknown. |
| 118 | */ |
| 119 | public String getMccString() { |
| 120 | return mMccStr; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @return Mobile Network Code in string fomrat, or {@code null} if unknown. |
| 125 | */ |
| 126 | public String getMncString() { |
| 127 | return mMncStr; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public String toString() { |
| 132 | return new StringBuilder(TAG + ":{") |
| 133 | .append(" mPci = ").append(mPci) |
| 134 | .append(" mTac = ").append(mTac) |
| 135 | .append(" mNrArfcn = ").append(mNrArfcn) |
| 136 | .append(" mMcc = ").append(mMccStr) |
| 137 | .append(" mMnc = ").append(mMncStr) |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 138 | .append(" mNci = ").append(mNci) |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 139 | .append(" mAlphaLong = ").append(mAlphaLong) |
| 140 | .append(" mAlphaShort = ").append(mAlphaShort) |
| 141 | .append(" }") |
| 142 | .toString(); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void writeToParcel(Parcel dest, int type) { |
| 147 | super.writeToParcel(dest, CellInfo.TYPE_NR); |
| 148 | dest.writeInt(mPci); |
| 149 | dest.writeInt(mTac); |
| 150 | dest.writeInt(mNrArfcn); |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 151 | dest.writeLong(mNci); |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** Construct from Parcel, type has already been processed */ |
| 155 | private CellIdentityNr(Parcel in) { |
| 156 | super(TAG, CellInfo.TYPE_NR, in); |
| 157 | mPci = in.readInt(); |
| 158 | mTac = in.readInt(); |
| 159 | mNrArfcn = in.readInt(); |
Nathan Harold | e13c593 | 2019-02-08 17:34:43 -0800 | [diff] [blame] | 160 | mNci = in.readLong(); |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** Implement the Parcelable interface */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 164 | public static final @android.annotation.NonNull Creator<CellIdentityNr> CREATOR = |
Pengquan Meng | f922b8e | 2018-10-29 17:59:26 -0700 | [diff] [blame] | 165 | new Creator<CellIdentityNr>() { |
| 166 | @Override |
| 167 | public CellIdentityNr createFromParcel(Parcel in) { |
| 168 | // Skip the type info. |
| 169 | in.readInt(); |
| 170 | return createFromParcelBody(in); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public CellIdentityNr[] newArray(int size) { |
| 175 | return new CellIdentityNr[size]; |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | /** @hide */ |
| 180 | protected static CellIdentityNr createFromParcelBody(Parcel in) { |
| 181 | return new CellIdentityNr(in); |
| 182 | } |
| 183 | } |