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 CONNECTION_RETRY_POLICY_H 17 #define CONNECTION_RETRY_POLICY_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "apn_item.h" 24 #include "cellular_data_constant.h" 25 26 namespace OHOS { 27 namespace Telephony { 28 namespace { 29 constexpr int32_t DEFAULT_DELAY_FOR_SETUP_FAIL = 3000; 30 constexpr int32_t DEFAULT_DELAY_FOR_MODEM_DEND = 1000; 31 } 32 33 class ConnectionRetryPolicy { 34 public: 35 ConnectionRetryPolicy(); 36 ~ConnectionRetryPolicy() = default; 37 sptr<ApnItem> GetNextRetryApnItem() const; 38 void SetMatchedApns(std::vector<sptr<ApnItem>> &apns); 39 void ClearRetryApns(); 40 void MarkBadApn(ApnItem &apn); 41 int64_t GetNextRetryDelay(std::string apnType, int32_t cause, int64_t suggestTime, RetryScene scene, 42 bool isDefaultApnRetrying); 43 void InitialRetryCountValue(); 44 std::vector<sptr<ApnItem>> GetMatchedApns() const; 45 static void OnPropChanged(const char *key, const char *value, void *context); 46 static DisConnectionReason ConvertPdpErrorToDisconnReason(int32_t reason); 47 bool IsAllBadApn() const; 48 static void RestartRadioIfRequired(int32_t failCause, int32_t slotId); 49 50 private: 51 int64_t GetRandomDelay(); 52 static bool ConvertStrToInt(const std::string& str, int32_t& value); 53 54 private: 55 static inline bool isPropOn_ = false; 56 std::vector<sptr<ApnItem>> matchedApns_; 57 static inline int32_t defaultSetupFailDelay_ = DEFAULT_DELAY_FOR_SETUP_FAIL; 58 static inline int32_t defaultModemDendDelay_ = DEFAULT_DELAY_FOR_MODEM_DEND; 59 mutable int32_t tryCount_ = 0; 60 int32_t maxCount_ = 5; 61 mutable int32_t currentApnIndex_ = 0; 62 }; 63 } // namespace Telephony 64 } // namespace OHOS 65 #endif // CONNECTION_RETRY_POLICY_H