• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "devattest_network_callback.h"
17 
18 #include <securec.h>
19 #include "singleton.h"
20 #include "devattest_log.h"
21 #include "devattest_errno.h"
22 #include "attest_entry.h"
23 
24 namespace OHOS {
25 namespace DevAttest {
26 using namespace OHOS;
27 constexpr std::int32_t UNAVAILABLE_STATUS = 1;
28 constexpr std::int32_t AVAILABLE_STATUS = 2;
29 constexpr std::int32_t OTHER_STATUS = 3;
30 constexpr std::int32_t STATUS_MAX_COUNT = 30;
NetCapabilitiesChange(sptr<NetHandle> & netHandle,const sptr<NetAllCapabilities> & netAllCap)31 int32_t DevAttestNetworkCallback::NetCapabilitiesChange(
32     sptr<NetHandle> &netHandle, const sptr<NetAllCapabilities> &netAllCap)
33 {
34     if (netHandle == nullptr || netAllCap == nullptr) {
35         HILOGW("[NetCapabilitiesChange] invalid parameter");
36         return DEVATTEST_SUCCESS;
37     }
38     if (netStatus_ == AVAILABLE_STATUS) {
39         HILOGW("[NetCapabilitiesChange] No need to operate");
40         netStatus_ = OTHER_STATUS;
41         return DEVATTEST_SUCCESS;
42     }
43     int32_t netHandleId = netHandle->GetNetId();
44     if (netId_ == netHandleId) {
45         HILOGI("[NetCapabilitiesChange] Skip the same operation");
46         return DEVATTEST_SUCCESS;
47     }
48     netId_ = netHandleId;
49     for (auto netCap : netAllCap->netCaps_) {
50         switch (netCap) {
51             case NET_CAPABILITY_MMS:
52                 HILOGD("[NetCapabilitiesChange] NET_CAPABILITY_MMS start");
53                 break;
54             case NET_CAPABILITY_NOT_METERED:
55                 HILOGD("[NetCapabilitiesChange] NET_CAPABILITY_NOT_METERED start");
56                 break;
57             case NET_CAPABILITY_INTERNET:
58                 HILOGD("[NetCapabilitiesChange] NET_CAPABILITY_INTERNET start");
59                 break;
60             case NET_CAPABILITY_NOT_VPN:
61                 HILOGD("[NetCapabilitiesChange] NET_CAPABILITY_NOT_VPN start");
62                 break;
63             case NET_CAPABILITY_VALIDATED:
64                 HILOGD("[NetCapabilitiesChange] NET_CAPABILITY_VALIDATED start");
65                 (void)AttestTask();
66                 break;
67             case NET_CAPABILITY_CAPTIVE_PORTAL:
68                 HILOGD("[NetCapabilitiesChange] NET_CAPABILITY_CAPTIVE_PORTAL start");
69                 break;
70             default:
71                 HILOGD("[NetCapabilitiesChange] default start");
72                 break;
73         }
74     }
75     return DEVATTEST_SUCCESS;
76 }
77 
NetAvailable(sptr<NetHandle> & netHandle)78 int32_t DevAttestNetworkCallback::NetAvailable(sptr<NetHandle> &netHandle)
79 {
80     netStatus_ += AVAILABLE_STATUS;
81     if (netStatus_ > STATUS_MAX_COUNT) {
82         netStatus_ = OTHER_STATUS;
83     }
84     (void)AttestCreateTimerTask();
85     return DEVATTEST_SUCCESS;
86 }
87 
NetUnavailable(void)88 int32_t DevAttestNetworkCallback::NetUnavailable(void)
89 {
90     netStatus_ += UNAVAILABLE_STATUS;
91     if (netStatus_ > STATUS_MAX_COUNT) {
92         netStatus_ = OTHER_STATUS;
93     }
94     return DEVATTEST_SUCCESS;
95 }
96 } // DevAttest
97 } // OHOS
98 
99