• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 APN_MANAGER_H
17 #define APN_MANAGER_H
18 
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "apn_holder.h"
24 #include "apn_item.h"
25 #include "cellular_data_rdb_helper.h"
26 #include "net_all_capabilities.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 class ApnManager : public RefBase {
31 public:
32     ApnManager();
33     ~ApnManager();
34     sptr<ApnHolder> GetApnHolder(const std::string &apnType) const;
35     std::vector<sptr<ApnHolder>> GetAllApnHolder() const;
36     std::vector<sptr<ApnHolder>> GetSortApnHolder() const;
37     std::vector<sptr<ApnItem>> FilterMatchedApns(const std::string &requestApnType, const int32_t slotId);
38     void InitApnHolders();
39     sptr<ApnHolder> FindApnHolderById(const int32_t id) const;
40     static int32_t FindApnIdByApnName(const std::string &type);
41     static std::string FindApnNameByApnId(const int32_t id);
42     static int32_t FindApnIdByCapability(const uint64_t capabilities);
43     static NetManagerStandard::NetCap FindBestCapability(const uint64_t capabilities);
44     bool IsDataConnectionNotUsed(const std::shared_ptr<CellularDataStateMachine> &stateMachine) const;
45     int32_t CreateAllApnItemByDatabase(int32_t slotId);
46     bool HasAnyConnectedState() const;
47     ApnProfileState GetOverallApnState() const;
48     ApnProfileState GetOverallDefaultApnState() const;
49     sptr<ApnItem> GetRilAttachApn();
50     sptr<ApnItem> GetApnItemById(const int32_t id);
51     bool ResetApns(int32_t slotId);
52     void FetchDunApns(std::vector<sptr<ApnItem>> &matchApnItemList, const int32_t slotId);
53     void FetchBipApns(std::vector<sptr<ApnItem>> &matchApnItemList);
54     bool IsPreferredApnUserEdited();
55     static int32_t FindApnTypeByApnName(const std::string &apnName);
56     void ClearAllApnBad();
57     static uint64_t FindCapabilityByApnId(int32_t apnId);
58     void GetBipApnItem(sptr<ApnItem> &bipApn);
59 
60 private:
61     void ReportApnInfo(int32_t slotId, PdpProfile &apnData);
62     void AddApnHolder(const std::string &apnType, const int32_t priority);
63     int32_t CreateMvnoApnItems(int32_t slotId, const std::string &mcc, const std::string &mnc);
64     int32_t MakeSpecificApnItem(std::vector<PdpProfile> &apnVec, int32_t slotId);
65     void GetCTOperator(int32_t slotId, std::string &numeric);
66     void TryMergeSimilarPdpProfile(std::vector<PdpProfile> &apnVec);
67     void MergePdpProfile(PdpProfile &newProfile, PdpProfile &oldProfile);
68     bool GetPreferId(int32_t slotId);
69     int32_t PushApnItem(int32_t count, sptr<ApnItem> extraApnItem);
70 
71 private:
72     static const std::map<std::string, int32_t> apnIdApnNameMap_;
73     static const std::map<std::string, ApnTypes> apnNameApnTypeMap_;
74     static const std::vector<ApnProfileState> apnStateArr_;
75     std::vector<sptr<ApnItem>> allApnItem_;
76     std::vector<sptr<ApnHolder>> apnHolders_;
77     std::map<int32_t, sptr<ApnHolder>> apnIdApnHolderMap_;
78     std::vector<sptr<ApnHolder>> sortedApnHolders_;
79     std::mutex mutex_;
80     int32_t preferId_ = -1;
81 };
82 } // namespace Telephony
83 } // namespace OHOS
84 #endif // APN_MANAGER_H