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 NETWORK_SEARCH_INCLUDE_CELL_INFO_H
17 #define NETWORK_SEARCH_INCLUDE_CELL_INFO_H
18 
19 #include "event_handler.h"
20 #include "tel_ril_network_parcel.h"
21 #include "cell_information.h"
22 #include "signal_information.h"
23 #include "network_state.h"
24 #include "cell_location.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class NetworkSearchManager;
29 class CellInfo {
30 public:
31     CellInfo(std::weak_ptr<NetworkSearchManager> networkSearchManager, int32_t slotId);
32     virtual ~CellInfo() = default;
33     static void InitCellSignalBar(const int32_t bar = 5);
34     void GetCellInfoList(std::vector<sptr<CellInformation>> &cellInfo);
35     void ProcessNeighboringCellInfo(const AppExecFwk::InnerEvent::Pointer &event);
36     void ProcessCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer &event);
37     void ClearCellInfoList();
38     void UpdateCellLocation(int32_t techType, int32_t cellId, int32_t lac);
39     sptr<CellLocation> GetCellLocation();
40 
41 private:
42     bool ProcessCellLocation(
43         sptr<CellInformation> &cell, CellInformation::CellType type, int32_t cellId, int32_t lac);
44     bool ProcessNeighboringCellGsm(CellNearbyInfo *cellInfo);
45     bool ProcessNeighboringCellLte(CellNearbyInfo *cellInfo);
46     bool ProcessNeighboringCellWcdma(CellNearbyInfo *cellInfo);
47     bool ProcessNeighboringCellCdma(CellNearbyInfo *cellInfo);
48     bool ProcessNeighboringCellTdscdma(CellNearbyInfo *cellInfo);
49     bool ProcessNeighboringCellNr(CellNearbyInfo *cellInfo);
50     bool ProcessCurrentCell(CurrentCellInformation *cellInfo);
51     bool ProcessCurrentCellWcdma(CurrentCellInformation *cellInfo);
52     bool ProcessCurrentCellLte(CurrentCellInformation *cellInfo);
53     bool ProcessCurrentCellGsm(CurrentCellInformation *cellInfo);
54     bool ProcessCurrentCellCdma(CurrentCellInformation *cellInfo);
55     bool ProcessCurrentCellTdscdma(CurrentCellInformation *cellInfo);
56     bool ProcessCurrentCellNr(CurrentCellInformation *cellInfo);
57     int32_t GetCurrentSignalLevelGsm(int32_t rxlev);
58     int32_t GetCurrentSignalLevelLte(int32_t rsrp);
59     int32_t GetCurrentSignalLevelWcdma(int32_t rscp);
60     int32_t GetCurrentSignalLevelCdma(int32_t pilotStrength);
61     int32_t GetCurrentSignalLevelTdscdma(int32_t rscp);
62     int32_t GetCurrentSignalLevelNr(int32_t rsrp);
63     void AddCellInformation(sptr<CellInformation> &cellInfo, std::vector<sptr<CellInformation>> &cellInfos);
64     void NotifyCellInfoUpdated() const;
65     void UpdateSignalLevel(sptr<CellInformation> &cell, CellInformation::CellType cellType);
66     CellInformation::CellType ConvertToCellType(SignalInformation::NetworkType signalType) const;
67     CellInformation::CellType ConvertTechToCellType(RadioTech techType) const;
68     CellInformation::CellType ConvertRatToCellType(int ratType) const;
69     sptr<CellLocation> GetCellLocationExt(CellInformation::CellType type);
70     std::mutex mutex_;
71     std::vector<sptr<CellInformation>> cellInfos_;
72     sptr<CellInformation> currentCellInfo_ = nullptr;
73     std::weak_ptr<NetworkSearchManager> networkSearchManager_;
74 
75     using CallInfoFunc = std::function<bool(CellInfo *, CellNearbyInfo *)>;
76     static const std::map<TelRilRatType, CallInfoFunc> memberFuncMap_;
77     int32_t slotId_ = 0;
78     static int32_t signalBar_;
79 };
80 } // namespace Telephony
81 } // namespace OHOS
82 #endif // NETWORK_SEARCH_INCLUDE_CELL_INFO_H