• 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 ConnectionRetryPolicy::ConnectionRetryPolicy() = default;
23 
24 ConnectionRetryPolicy::~ConnectionRetryPolicy() = default;
25 
GetNextRetryApnItem() const26 sptr<ApnItem> ConnectionRetryPolicy::GetNextRetryApnItem() const
27 {
28     if (matchedApns_.empty()) {
29         TELEPHONY_LOGE("matchedApns is null");
30         return nullptr;
31     }
32     if (currentApnIndex_ >= static_cast<int32_t>(matchedApns_.size()) || currentApnIndex_ < 0) {
33         currentApnIndex_ = 0;
34         return matchedApns_[currentApnIndex_];
35     }
36     sptr<ApnItem> apnItem = matchedApns_[currentApnIndex_];
37     tryCount_++;
38     if ((apnItem != nullptr && apnItem->IsBadApn()) || (tryCount_ > maxCount_)) {
39         tryCount_ = 0;
40         currentApnIndex_++;
41         return GetNextRetryApnItem();
42     }
43     return apnItem;
44 }
45 
SetMatchedApns(std::vector<sptr<ApnItem>> & apns)46 void ConnectionRetryPolicy::SetMatchedApns(std::vector<sptr<ApnItem>> &apns)
47 {
48     matchedApns_ = apns;
49 }
50 
ClearRetryApns()51 void ConnectionRetryPolicy::ClearRetryApns()
52 {
53     matchedApns_.clear();
54 }
55 
MarkBadApn(ApnItem & apn)56 void ConnectionRetryPolicy::MarkBadApn(ApnItem &apn)
57 {
58     // The APN that fails after multiple retries is true
59     apn.MarkBadApn(true);
60 }
61 
GetNextRetryDelay() const62 int64_t ConnectionRetryPolicy::GetNextRetryDelay() const
63 {
64     return DEFAULT_DELAY_FOR_NEXT_APN;
65 }
66 
InitialRetryCountValue()67 void ConnectionRetryPolicy::InitialRetryCountValue()
68 {
69     tryCount_ = 0;
70     TELEPHONY_LOGI("tryCount_ is %{public}d", tryCount_);
71 }
72 } // namespace Telephony
73 } // namespace OHOS