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