• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "connection_retry_policy.h"
17 
18 #include "telephony_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Telephony {
22 constexpr static const int64_t DEFAULT_DELAY_FOR_NEXT_APN = 2 * 1000;
23 
24 ConnectionRetryPolicy::ConnectionRetryPolicy() = default;
25 
26 ConnectionRetryPolicy::~ConnectionRetryPolicy() = default;
27 
GetNextRetryApnItem() const28 sptr<ApnItem> ConnectionRetryPolicy::GetNextRetryApnItem() const
29 {
30     if (matchedApns_.empty()) {
31         TELEPHONY_LOGE("matchedApns is null");
32         return nullptr;
33     }
34     if (currentApnIndex_ >= static_cast<int32_t>(matchedApns_.size()) || currentApnIndex_ < 0) {
35         currentApnIndex_ = 0;
36         return matchedApns_[currentApnIndex_];
37     }
38     sptr<ApnItem> apnItem = matchedApns_[currentApnIndex_];
39     tryCount_++;
40     if ((apnItem != nullptr && apnItem->IsBadApn()) || (tryCount_ > maxCount_)) {
41         tryCount_ = 0;
42         currentApnIndex_++;
43         return GetNextRetryApnItem();
44     }
45     return apnItem;
46 }
47 
SetMatchedApns(std::vector<sptr<ApnItem>> & apns)48 void ConnectionRetryPolicy::SetMatchedApns(std::vector<sptr<ApnItem>> &apns)
49 {
50     matchedApns_ = apns;
51 }
52 
ClearRetryApns()53 void ConnectionRetryPolicy::ClearRetryApns()
54 {
55     matchedApns_.clear();
56 }
57 
MarkBadApn(ApnItem & apn)58 void ConnectionRetryPolicy::MarkBadApn(ApnItem &apn)
59 {
60     // The APN that fails after multiple retries is true
61     apn.MarkBadApn(true);
62 }
63 
GetNextRetryDelay() const64 int64_t ConnectionRetryPolicy::GetNextRetryDelay() const
65 {
66     return DEFAULT_DELAY_FOR_NEXT_APN;
67 }
68 
InitialRetryCountValue()69 void ConnectionRetryPolicy::InitialRetryCountValue()
70 {
71     tryCount_ = 0;
72     TELEPHONY_LOGI("tryCount_ is %{public}d", tryCount_);
73 }
74 } // namespace Telephony
75 } // namespace OHOS