1 /*
2 * Copyright (c) 2023 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 "net_conn_callback_observer.h"
17 #include "dfs_error.h"
18 #include "network_status.h"
19 #include "utils_log.h"
20
21 using namespace OHOS::NetManagerStandard;
22
23 namespace OHOS::FileManagement::CloudSync {
NetConnCallbackObserver(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager)24 NetConnCallbackObserver::NetConnCallbackObserver(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager)
25 {
26 dataSyncManager_ = dataSyncManager;
27 }
28
NetAvailable(sptr<NetHandle> & netHandle)29 int32_t NetConnCallbackObserver::NetAvailable(sptr<NetHandle> &netHandle)
30 {
31 LOGI("network is available");
32 return E_OK;
33 }
34
NetCapabilitiesChange(sptr<NetHandle> & netHandle,const sptr<NetAllCapabilities> & netAllCap)35 int32_t NetConnCallbackObserver::NetCapabilitiesChange(sptr<NetHandle> &netHandle,
36 const sptr<NetAllCapabilities> &netAllCap)
37 {
38 NetworkStatus::NetConnStatus oldStatus = NetworkStatus::GetNetConnStatus();
39 NetworkStatus::SetNetConnStatus(*netAllCap);
40 if (oldStatus != NetworkStatus::NO_NETWORK) {
41 return E_OK;
42 }
43 NetworkStatus::NetConnStatus newStatus = NetworkStatus::GetNetConnStatus();
44 if (newStatus == NetworkStatus::WIFI_CONNECT) {
45 LOGI("NetCapabilitiesChanged wifi connected");
46 dataSyncManager_->TriggerRecoverySync(triggerType_);
47 dataSyncManager_->DownloadThumb();
48 dataSyncManager_->CacheVideo();
49 } else if (newStatus == NetworkStatus::CELLULAR_CONNECT) {
50 LOGI("NetCapabilitiesChanged cellular connected");
51 dataSyncManager_->TriggerRecoverySync(triggerType_);
52 } else {
53 LOGI("NetCapabilitiesChanged newStatus:%{public}d", newStatus);
54 }
55 return E_OK;
56 }
57
NetConnectionPropertiesChange(sptr<NetHandle> & netHandle,const sptr<NetLinkInfo> & info)58 int32_t NetConnCallbackObserver::NetConnectionPropertiesChange(sptr<NetHandle> &netHandle,
59 const sptr<NetLinkInfo> &info)
60 {
61 return E_OK;
62 }
63
NetLost(sptr<NetHandle> & netHandle)64 int32_t NetConnCallbackObserver::NetLost(sptr<NetHandle> &netHandle)
65 {
66 LOGI("NetConnCallbackObserver::NetLost");
67 NetworkStatus::SetNetConnStatus(NetworkStatus::NetConnStatus::NO_NETWORK);
68 return E_OK;
69 }
70
NetUnavailable()71 int32_t NetConnCallbackObserver::NetUnavailable()
72 {
73 return E_OK;
74 }
75
NetBlockStatusChange(sptr<NetHandle> & netHandle,bool blocked)76 int32_t NetConnCallbackObserver::NetBlockStatusChange(sptr<NetHandle> &netHandle, bool blocked)
77 {
78 return E_OK;
79 }
80 } // namespace OHOS::FileManagement::CloudSync