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 "cstdint" 19 20 #include "net_conn_client.h" 21 #include "net_conn_constants.h" 22 23 #include "devattest_log.h" 24 #include "devattest_errno.h" 25 #include "attest_entry.h" 26 27 namespace OHOS { 28 namespace DevAttest { 29 using namespace OHOS; NetCapabilitiesChange(sptr<NetHandle> & netHandle,const sptr<NetAllCapabilities> & netAllCap)30int32_t DevAttestNetworkCallback::NetCapabilitiesChange( 31 sptr<NetHandle> &netHandle, const sptr<NetAllCapabilities> &netAllCap) 32 { 33 if (netHandle == nullptr || netAllCap == nullptr) { 34 HILOGI("[NetCapabilitiesChange] invalid parameter"); 35 return DEVATTEST_SUCCESS; 36 } 37 int32_t ret = DEVATTEST_SUCCESS; 38 int32_t netHandleId = netHandle->GetNetId(); 39 if (netId_ == netHandleId) { 40 HILOGI("[NetCapabilitiesChange] Skip the same operation"); 41 return DEVATTEST_SUCCESS; 42 } 43 netId_ = netHandleId; 44 for (auto netCap : netAllCap->netCaps_) { 45 switch (netCap) { 46 case NET_CAPABILITY_MMS: 47 HILOGI("[NetCapabilitiesChange] NET_CAPABILITY_MMS start"); 48 break; 49 case NET_CAPABILITY_NOT_METERED: 50 HILOGI("[NetCapabilitiesChange] NET_CAPABILITY_NOT_METERED start"); 51 break; 52 case NET_CAPABILITY_INTERNET: 53 HILOGI("[NetCapabilitiesChange] NET_CAPABILITY_INTERNET start"); 54 ret = AttestTask(); 55 HILOGI("DevAttestService test success, ret = %{public}d", ret); 56 break; 57 case NET_CAPABILITY_NOT_VPN: 58 HILOGI("[NetCapabilitiesChange] NET_CAPABILITY_NOT_VPN start"); 59 break; 60 case NET_CAPABILITY_VALIDATED: 61 HILOGI("[NetCapabilitiesChange] NET_CAPABILITY_VALIDATED start"); 62 break; 63 case NET_CAPABILITY_CAPTIVE_PORTAL: 64 HILOGI("[NetCapabilitiesChange] NET_CAPABILITY_CAPTIVE_PORTAL start"); 65 break; 66 default: 67 HILOGI("[NetCapabilitiesChange] default start"); 68 break; 69 } 70 } 71 return DEVATTEST_SUCCESS; 72 } 73 } // DevAttest 74 } // OHOS 75 76