1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_CELL_INFORMATION_H 17 #define OHOS_CELL_INFORMATION_H 18 19 #include "parcel.h" 20 21 namespace OHOS { 22 namespace Telephony { 23 class CellInformation : public Parcelable { 24 public: 25 static const int32_t MAX_CELL_NUM = 10; 26 /** 27 * @brief Cell type 28 */ 29 enum class CellType { 30 CELL_TYPE_NONE = 0, 31 /** 32 * Global System for Mobile Communications (GSM) cell type 33 */ 34 CELL_TYPE_GSM, 35 /** 36 * Code Division Multiple Access (CDMA) cell type 37 */ 38 CELL_TYPE_CDMA, 39 /** 40 * Wideband Code Division Multiple Access (WCDMA) cell type 41 */ 42 CELL_TYPE_WCDMA, 43 /** 44 * Time Division-Synchronous Code Division Multiple Access (TD-SCDMA) cell type 45 */ 46 CELL_TYPE_TDSCDMA, 47 /** 48 * Long Term Evolution (LTE) cell type 49 */ 50 CELL_TYPE_LTE, 51 /** 52 * 5G New Radio (NR) cell type 53 */ 54 CELL_TYPE_NR 55 }; 56 CellInformation() = default; 57 virtual ~CellInformation() = default; 58 virtual bool Marshalling(Parcel &parcel) const = 0; 59 static CellInformation *Unmarshalling(Parcel &parcel); 60 virtual bool ReadFromParcel(Parcel &parcel) = 0; 61 virtual CellInformation::CellType GetNetworkType() const = 0; 62 virtual std::string ToString() const = 0; 63 void Init(int32_t mcc, int32_t mnc, int32_t cellId); 64 65 /** 66 * @brief Obtain the cell Id 67 * 68 * @return Cell Id 69 */ 70 virtual int32_t GetCellId() const; 71 /** 72 * @brief Obtain the Mobile Country Code 73 * 74 * @return Mobile Country Code 75 */ 76 virtual std::string GetMcc() const; 77 /** 78 * @brief Obtain the Mobile Network Code 79 * 80 * @return Mobile Network Code 81 */ 82 virtual std::string GetMnc() const; 83 virtual uint64_t GetTimeStamp() const; 84 virtual int32_t GetSignalLevel() const; 85 virtual int32_t GetSignalIntensity() const; 86 virtual bool GetIsCamped() const; 87 virtual void SetIsCamped(bool isCamped); 88 virtual void SetSignalIntensity(int32_t signalIntensity); 89 virtual void SetSignalLevel(int32_t signalLevel); 90 91 protected: 92 std::string mcc_ = ""; 93 std::string mnc_ = ""; 94 int32_t cellId_ = 0; 95 uint64_t timeStamp_ = 0; 96 int32_t signalIntensity_ = 0; 97 int32_t signalLevel_ = 0; 98 bool isCamped_ = false; 99 }; 100 101 class GsmCellInformation : public CellInformation { 102 public: 103 GsmCellInformation() = default; 104 virtual ~GsmCellInformation() = default; 105 bool Marshalling(Parcel &parcel) const override; 106 static GsmCellInformation *Unmarshalling(Parcel &parcel); 107 bool ReadFromParcel(Parcel &parcel) override; 108 CellInformation::CellType GetNetworkType() const override; 109 std::string ToString() const override; 110 void SetGsmParam(int32_t bsic, int32_t lac, int32_t arfcn); 111 void UpdateLocation(int32_t cellId, int32_t lac); 112 GsmCellInformation(const GsmCellInformation &gsmCell); 113 GsmCellInformation &operator=(const GsmCellInformation &gsmCell); 114 bool operator==(const GsmCellInformation &other) const; 115 /** 116 * @brief Obtain the Location Area Code 117 * 118 * @return Location Area Code 119 */ 120 int32_t GetLac() const; 121 /** 122 * @brief Obtain the Base Station Identity Code 123 * 124 * @return Base Station Identity Code 125 */ 126 int32_t GetBsic() const; 127 /** 128 * @brief Obtain the Absolute RF Channel Number 129 * 130 * @return Absolute RF Channel Number 131 */ 132 int32_t GetArfcn() const; 133 134 private: 135 int32_t lac_ = 0; 136 int32_t bsic_ = 0; 137 int32_t arfcn_ = 0; 138 }; 139 140 class LteCellInformation : public CellInformation { 141 public: 142 LteCellInformation() = default; 143 virtual ~LteCellInformation() = default; 144 bool Marshalling(Parcel &parcel) const override; 145 static LteCellInformation *Unmarshalling(Parcel &parcel); 146 bool ReadFromParcel(Parcel &parcel) override; 147 CellInformation::CellType GetNetworkType() const override; 148 std::string ToString() const override; 149 void SetLteParam(int32_t pci, int32_t tac, int32_t arfcn); 150 LteCellInformation(const LteCellInformation <eCell); 151 LteCellInformation &operator=(const LteCellInformation <eCell); 152 bool operator==(const LteCellInformation &other) const; 153 void UpdateLocation(int32_t cellId, int32_t tac); 154 /** 155 * @brief Obtain the Physical Cell Id 156 * 157 * @return Physical Cell Id 158 */ 159 int32_t GetPci() const; 160 /** 161 * @brief Obtain the Tracking Area Code 162 * 163 * @return Tracking Area Code 164 */ 165 int32_t GetTac() const; 166 /** 167 * @brief Obtain the Absolute RF Channel Number 168 * 169 * @return Absolute RF Channel Number 170 */ 171 int32_t GetArfcn() const; 172 173 private: 174 int32_t pci_ = 0; 175 int32_t tac_ = 0; 176 int32_t earfcn_ = 0; 177 }; 178 179 class WcdmaCellInformation : public CellInformation { 180 public: 181 WcdmaCellInformation() = default; 182 virtual ~WcdmaCellInformation() = default; 183 bool Marshalling(Parcel &parcel) const override; 184 static WcdmaCellInformation *Unmarshalling(Parcel &parcel); 185 bool ReadFromParcel(Parcel &parcel) override; 186 CellInformation::CellType GetNetworkType() const override; 187 std::string ToString() const override; 188 void SetWcdmaParam(int32_t psc, int32_t lac, int32_t arfcn); 189 WcdmaCellInformation(const WcdmaCellInformation &wcdmaCell); 190 WcdmaCellInformation &operator=(const WcdmaCellInformation &wcdmaCell); 191 bool operator==(const WcdmaCellInformation &other) const; 192 void UpdateLocation(int32_t cellId, int32_t lac); 193 /** 194 * @brief Obtain the Primary Scrambling Code 195 * 196 * @return Primary Scrambling Code 197 */ 198 int32_t GetPsc() const; 199 /** 200 * @brief Obtain the Location Area Code 201 * 202 * @return Location Area Code 203 */ 204 int32_t GetLac() const; 205 /** 206 * @brief Obtain the Absolute RF Channel Number 207 * 208 * @return Absolute RF Channel Number 209 */ 210 int32_t GetArfcn() const; 211 212 private: 213 int32_t lac_ = 0; 214 int32_t psc_ = 0; 215 int32_t uarfcn_ = 0; 216 }; 217 218 class TdscdmaCellInformation : public CellInformation { 219 public: 220 TdscdmaCellInformation() = default; 221 virtual ~TdscdmaCellInformation() = default; 222 bool Marshalling(Parcel &parcel) const override; 223 static TdscdmaCellInformation *Unmarshalling(Parcel &parcel); 224 bool ReadFromParcel(Parcel &parcel) override; 225 CellInformation::CellType GetNetworkType() const override; 226 std::string ToString() const override; 227 void SetTdscdmaParam(int32_t psc, int32_t lac, int32_t arfcn); 228 TdscdmaCellInformation(const TdscdmaCellInformation &wcdmaCell); 229 TdscdmaCellInformation &operator=(const TdscdmaCellInformation &wcdmaCell); 230 bool operator==(const TdscdmaCellInformation &other) const; 231 void UpdateLocation(int32_t cellId, int32_t lac); 232 /** 233 * @brief Obtain the Cell Parameters ID 234 * 235 * @return Cell Parameters ID 236 */ 237 int32_t GetCpid() const; 238 /** 239 * @brief Obtain the Location Area Code 240 * 241 * @return Location Area Code 242 */ 243 int32_t GetLac() const; 244 /** 245 * @brief Obtain the Absolute RF Channel Number 246 * 247 * @return Absolute RF Channel Number 248 */ 249 int32_t GetArfcn() const; 250 251 private: 252 int32_t lac_ = 0; 253 int32_t cpid_ = 0; 254 int32_t uarfcn_ = 0; 255 }; 256 257 class CdmaCellInformation : public CellInformation { 258 public: 259 CdmaCellInformation() = default; 260 virtual ~CdmaCellInformation() = default; 261 bool Marshalling(Parcel &parcel) const override; 262 static CdmaCellInformation *Unmarshalling(Parcel &parcel); 263 bool ReadFromParcel(Parcel &parcel) override; 264 CellInformation::CellType GetNetworkType() const override; 265 std::string ToString() const override; 266 void SetCdmaParam(int32_t baseId, int32_t latitude, int32_t longitude, int32_t nid, int32_t sid); 267 CdmaCellInformation(const CdmaCellInformation &cdmaCell); 268 CdmaCellInformation &operator=(const CdmaCellInformation &cdmaCell); 269 bool operator==(const CdmaCellInformation &other) const; 270 void UpdateLocation(int32_t baseId, int32_t latitude, int32_t longitude); 271 /** 272 * @brief Obtain cdma base station identification number 273 * 274 * @return CDMA base station identification number 275 */ 276 int32_t GetBaseId() const; 277 /** 278 * @brief Obtain cdma base station latitude 279 * 280 * @return CDMA base station latitude 281 */ 282 int32_t GetLatitude() const; 283 /** 284 * @brief Obtain cdma base station longitude 285 * 286 * @return CDMA base station longitude 287 */ 288 int32_t GetLongitude() const; 289 /** 290 * @brief Obtain cdma network identification number 291 * 292 * @return CDMA network identification number 293 */ 294 int32_t GetNid() const; 295 /** 296 * @brief Obtain cdma system identification number 297 * 298 * @return CDMA system identification number 299 */ 300 int32_t GetSid() const; 301 302 private: 303 int32_t baseId_ = 0; 304 int32_t latitude_ = 0; 305 int32_t longitude_ = 0; 306 int32_t nid_ = 0; 307 int32_t sid_ = 0; 308 }; 309 310 class NrCellInformation : public CellInformation { 311 public: 312 NrCellInformation() = default; 313 virtual ~NrCellInformation() = default; 314 bool Marshalling(Parcel &parcel) const override; 315 static NrCellInformation *Unmarshalling(Parcel &parcel); 316 bool ReadFromParcel(Parcel &parcel) override; 317 CellInformation::CellType GetNetworkType() const override; 318 std::string ToString() const override; 319 void SetNrParam(int32_t nrArfcn, int32_t pci, int32_t tac, int64_t nci); 320 void SetNrSignalParam(int32_t rsrp, int32_t rsrq); 321 NrCellInformation(const NrCellInformation &nrCell); 322 NrCellInformation &operator=(const NrCellInformation &nrCell); 323 bool operator==(const NrCellInformation &other) const; 324 void UpdateLocation(int32_t pci, int32_t tac); 325 /** 326 * @return Absolute RF Channel Number 327 */ 328 int32_t GetArfcn() const; 329 /** 330 * @brief Obtain the Physical Cell Id 331 * 332 * @return Physical Cell Id 333 */ 334 int32_t GetPci() const; 335 /** 336 * @brief Obtain the Tracking Area Code 337 * 338 * @return Tracking Area Code 339 */ 340 int32_t GetTac() const; 341 /** 342 * @brief Obtain the NR(New Radio 5G) Cell Identity 343 * 344 * @return NR(New Radio 5G) Cell Identity 345 */ 346 int64_t GetNci() const; 347 348 private: 349 int32_t nrArfcn_ = 0; 350 int32_t pci_ = 0; 351 int32_t tac_ = 0; 352 int64_t nci_ = 0; 353 int32_t rsrp_ = 0; 354 int32_t rsrq_ = 0; 355 }; 356 } // namespace Telephony 357 } // namespace OHOS 358 #endif // OHOS_CELL_INFORMATION_H