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
28namespace OHOS {
29namespace Telephony {
30class ApnManager : public RefBase {
31public:
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    bool ResetApns(int32_t slotId);
51    void FetchDunApns(std::vector<sptr<ApnItem>> &matchApnItemList, const int32_t slotId);
52    bool IsPreferredApnUserEdited();
53    static int32_t FindApnTypeByApnName(const std::string &apnName);
54    void ClearAllApnBad();
55
56private:
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
62private:
63    static const std::map<std::string, int32_t> apnIdApnNameMap_;
64    static const std::map<std::string, ApnTypes> apnNameApnTypeMap_;
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