blob: b48388ecd168b88a1c1c3b9dda80e47beb2b7c99 [file] [log] [blame]
Pengquan Mengf922b8e2018-10-29 17:59:26 -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
19import android.os.Parcel;
20import android.telephony.gsm.GsmCellLocation;
21
22import java.util.Objects;
23
24/**
25 * Information to represent a unique 5G NR cell.
26 */
27public 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 Harolde13c5932019-02-08 17:34:43 -080033 private final long mNci;
Pengquan Mengf922b8e2018-10-29 17:59:26 -070034
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 Harolde13c5932019-02-08 17:34:43 -080048 long nci, String alphal, String alphas) {
Pengquan Mengf922b8e2018-10-29 17:59:26 -070049 super(TAG, CellInfo.TYPE_NR, mccStr, mncStr, alphal, alphas);
50 mPci = pci;
51 mTac = tac;
52 mNrArfcn = nrArfcn;
Nathan Harolde13c5932019-02-08 17:34:43 -080053 mNci = nci;
Pengquan Mengf922b8e2018-10-29 17:59:26 -070054 }
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 Harolde13c5932019-02-08 17:34:43 -080067 return Objects.hash(super.hashCode(), mPci, mTac, mNrArfcn, mNci);
Pengquan Mengf922b8e2018-10-29 17:59:26 -070068 }
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 Harolde13c5932019-02-08 17:34:43 -080077 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 Harolde28230072019-02-22 13:22:46 -080084 * @return The 36-bit NR Cell Identity in range [0, 68719476735] or
85 * {@link CellInfo#UNAVAILABLE_LONG} if unknown.
Nathan Harolde13c5932019-02-08 17:34:43 -080086 */
87 public long getNci() {
88 return mNci;
Pengquan Mengf922b8e2018-10-29 17:59:26 -070089 }
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 Harolde13c5932019-02-08 17:34:43 -0800138 .append(" mNci = ").append(mNci)
Pengquan Mengf922b8e2018-10-29 17:59:26 -0700139 .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 Harolde13c5932019-02-08 17:34:43 -0800151 dest.writeLong(mNci);
Pengquan Mengf922b8e2018-10-29 17:59:26 -0700152 }
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 Harolde13c5932019-02-08 17:34:43 -0800160 mNci = in.readLong();
Pengquan Mengf922b8e2018-10-29 17:59:26 -0700161 }
162
163 /** Implement the Parcelable interface */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700164 public static final @android.annotation.NonNull Creator<CellIdentityNr> CREATOR =
Pengquan Mengf922b8e2018-10-29 17:59:26 -0700165 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}