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     void CreateAllApnItem();
38     std::vector<sptr<ApnItem>> FilterMatchedApns(const std::string &requestApnType, const int32_t slotId);
39     void InitApnHolders();
40     sptr<ApnHolder> FindApnHolderById(const int32_t id) const;
41     static int32_t FindApnIdByApnName(const std::string &type);
42     static std::string FindApnNameByApnId(const int32_t id);
43     static int32_t FindApnIdByCapability(const uint64_t capabilities);
44     static NetManagerStandard::NetCap FindBestCapability(const uint64_t capabilities);
45     bool IsDataConnectionNotUsed(const std::shared_ptr<CellularDataStateMachine> &stateMachine) const;
46     int32_t CreateAllApnItemByDatabase(int32_t slotId);
47     bool HasAnyConnectedState() const;
48     ApnProfileState GetOverallApnState() const;
49     ApnProfileState GetOverallDefaultApnState() const;
50     sptr<ApnItem> GetRilAttachApn();
51     sptr<ApnItem> GetApnItemById(const int32_t id);
52     bool ResetApns(int32_t slotId);
53     void FetchDunApns(std::vector<sptr<ApnItem>> &matchApnItemList, const int32_t slotId);
54     bool IsPreferredApnUserEdited();
55 
56 private:
57     void AddApnHolder(const std::string &apnType, const int32_t priority);
58     int32_t CreateMvnoApnItems(int32_t slotId, const std::string &mcc, const std::string &mnc);
59     int32_t MakeSpecificApnItem(std::vector<PdpProfile> &apnVec);
60     void GetCTOperator(int32_t slotId, std::string &numeric);
61 
62 private:
63     static const std::map<std::string, int32_t> apnIdApnNameMap_;
64     static const std::vector<ApnProfileState> apnStateArr_;
65     std::vector<sptr<ApnItem>> allApnItem_;
66     std::vector<sptr<ApnHolder>> apnHolders_;
67     std::map<int32_t, sptr<ApnHolder>> apnIdApnHolderMap_;
68     std::vector<sptr<ApnHolder>> sortedApnHolders_;
69     std::mutex mutex_;
70     int32_t preferId_ = INVALID_PROFILE_ID;
71 };
72 } // namespace Telephony
73 } // namespace OHOS
74 #endif // APN_MANAGER_H