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_HOLDER_H 17 #define APN_HOLDER_H 18 19 #include <map> 20 #include <memory> 21 #include "apn_item.h" 22 #include "cellular_data_constant.h" 23 #include "connection_retry_policy.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 void ReleaseAllCellularData(); 29 30 #ifdef __cplusplus 31 } 32 #endif 33 34 namespace OHOS { 35 namespace Telephony { 36 class CellularDataStateMachine; 37 38 class ApnHolder : public RefBase { 39 public: 40 ApnHolder(const std::string &apnType, const int32_t priority); 41 ~ApnHolder(); 42 sptr<ApnItem> GetNextRetryApn() const; 43 void SetAllMatchedApns(std::vector<sptr<ApnItem>> &matchedApns); 44 int64_t GetRetryDelay() const; 45 void SetCurrentApn(sptr<ApnItem> &apnItem); 46 sptr<ApnItem> GetCurrentApn() const; 47 void SetApnState(ApnProfileState state); 48 ApnProfileState GetApnState() const; 49 bool IsDataCallEnabled() const; 50 std::string GetApnType() const; 51 void ReleaseDataConnection(); 52 int32_t GetProfileId(const std::string &apnType) const; 53 void SetCellularDataStateMachine(const std::shared_ptr<CellularDataStateMachine> &stateMachine); 54 std::shared_ptr<CellularDataStateMachine> GetCellularDataStateMachine() const; 55 uint64_t GetCapability() const; 56 int32_t GetPriority() const; 57 void RequestCellularData(const NetRequest &netRequest); 58 void ReleaseCellularData(const NetRequest &netRequest); 59 void ReleaseAllCellularData(); 60 bool IsEmergencyType() const; 61 bool IsMmsType() const; 62 void InitialApnRetryCount(); 63 bool IsSameMatchedApns(std::vector<sptr<ApnItem>> newMatchedApns, bool roamingState); 64 bool IsSameApnItem(const sptr<ApnItem> &newApnItem, const sptr<ApnItem> &oldApnItem, bool roamingState); 65 bool IsCompatibleApnItem(const sptr<ApnItem> &newApnItem, const sptr<ApnItem> &oldApnItem, bool roamingState); 66 67 private: 68 ApnHolder(ApnHolder &apnHolder) = default; 69 ApnHolder &operator=(ApnHolder &apnHolder) = default; 70 71 private: 72 static const std::map<std::string, int32_t> apnTypeDataProfileMap_; 73 bool dataCallEnabled_ = false; 74 uint64_t capability_ = 0; 75 ConnectionRetryPolicy retryPolicy_; 76 ApnProfileState apnState_ = ApnProfileState::PROFILE_STATE_IDLE; 77 sptr<ApnItem> apnItem_; 78 std::string apnType_; 79 int32_t priority_; 80 std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_; 81 std::vector<NetRequest> netRequests_; 82 }; 83 } // namespace Telephony 84 } // namespace OHOS 85 #endif // APN_HOLDER_H 86