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_LOCATION_H 17 #define OHOS_CELL_LOCATION_H 18 19 #include "parcel.h" 20 #include "cell_information.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 class CellLocation : public Parcelable { 25 public: 26 enum class CellType { 27 CELL_TYPE_NONE = 0, 28 CELL_TYPE_GSM, 29 CELL_TYPE_CDMA, 30 }; 31 CellLocation() = default; 32 virtual ~CellLocation() = default; 33 virtual CellLocation::CellType GetCellLocationType() const = 0; 34 virtual bool Marshalling(Parcel &parcel) const = 0; 35 static CellLocation *Unmarshalling(Parcel &parcel); 36 virtual bool ReadFromParcel(Parcel &parcel) = 0; 37 38 virtual uint64_t GetTimeStamp() const; 39 protected: 40 uint64_t timeStamp_ = 0; 41 }; 42 43 class GsmCellLocation : public CellLocation { 44 public: 45 GsmCellLocation() = default; 46 virtual ~GsmCellLocation() = default; 47 bool Marshalling(Parcel &parcel) const override; 48 static GsmCellLocation *Unmarshalling(Parcel &parcel); 49 bool ReadFromParcel(Parcel &parcel) override; 50 CellLocation::CellType GetCellLocationType() const override; 51 void SetGsmParam(int32_t cellId, int32_t lac, int32_t psc = 0); 52 /** 53 * @brief Obtain gsm cell id 54 * 55 * @return GSM cell id, 0 if unknown, 0xffff max legal value 56 */ 57 int32_t GetCellId() const; 58 /** 59 * @brief Obtain gsm location area code 60 * 61 * @return GSM location area code, 0 if unknown, 0xffff max legal value 62 */ 63 int32_t GetLac() const; 64 /** 65 * @brief On a UMTS network, return the primary scrambling code cell 66 * 67 * @return Primary scrambling code for WCDMA, 0 if unknown or GSM 68 */ 69 int32_t GetPsc() const; 70 71 private: 72 int32_t cellId_ = 0; 73 int32_t lac_ = 0; 74 int32_t psc_ = 0; 75 }; 76 77 class CdmaCellLocation : public CellLocation { 78 public: 79 CdmaCellLocation() = default; 80 virtual ~CdmaCellLocation() = default; 81 bool Marshalling(Parcel &parcel) const override; 82 static CdmaCellLocation *Unmarshalling(Parcel &parcel); 83 bool ReadFromParcel(Parcel &parcel) override; 84 CellLocation::CellType GetCellLocationType() const override; 85 void SetCdmaParam(int32_t baseId, int32_t latitude, int32_t longitude, int32_t nid, int32_t sid); 86 87 /** 88 * @brief Obtain cdma base station identification number 89 * 90 * @return CDMA base station identification number 91 */ 92 int32_t GetBaseId() const; 93 /** 94 * @brief Obtain cdma base station latitude 95 * 96 * @return CDMA base station latitude 97 */ 98 int32_t GetLatitude() const; 99 /** 100 * @brief Obtain cdma base station longitude 101 * 102 * @return CDMA base station longitude 103 */ 104 int32_t GetLongitude() const; 105 /** 106 * @brief Obtain cdma network identification number 107 * 108 * @return CDMA network identification number 109 */ 110 int32_t GetNid() const; 111 /** 112 * @brief Obtain cdma system identification number 113 * 114 * @return CDMA system identification number 115 */ 116 int32_t GetSid() const; 117 private: 118 int32_t baseId_ = 0; 119 int32_t latitude_ = 0; 120 int32_t longitude_ = 0; 121 int32_t nid_ = 0; 122 int32_t sid_ = 0; 123 }; 124 } // namespace Telephony 125 } // namespace OHOS 126 #endif // OHOS_CELL_LOCATION_H