• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     NetworkStatus::NetConnStatus newStatus = NetworkStatus::GetNetConnStatus();
41     if (oldStatus == newStatus) {
42         LOGI("net status is not change, status is %{public}d", static_cast<int32_t>(newStatus));
43         return E_OK;
44     }
45     if (newStatus == NetworkStatus::WIFI_CONNECT) {
46         LOGI("NetCapabilitiesChanged wifi connected");
47         dataSyncManager_->TriggerRecoverySync(triggerType_);
48         dataSyncManager_->DownloadThumb();
49         dataSyncManager_->CacheVideo();
50     } else if (newStatus == NetworkStatus::CELLULAR_CONNECT) {
51         LOGI("NetCapabilitiesChanged cellular connected");
52         dataSyncManager_->TriggerRecoverySync(triggerType_);
53         NetworkStatus::NetWorkChangeStopUploadTask();
54     } else {
55         LOGI("NetCapabilitiesChanged newStatus:%{public}d", newStatus);
56     }
57     return E_OK;
58 }
59 
NetConnectionPropertiesChange(sptr<NetHandle> & netHandle,const sptr<NetLinkInfo> & info)60 int32_t NetConnCallbackObserver::NetConnectionPropertiesChange(sptr<NetHandle> &netHandle,
61     const sptr<NetLinkInfo> &info)
62 {
63     return E_OK;
64 }
65 
NetLost(sptr<NetHandle> & netHandle)66 int32_t NetConnCallbackObserver::NetLost(sptr<NetHandle> &netHandle)
67 {
68     LOGI("NetConnCallbackObserver::NetLost");
69     NetworkStatus::SetNetConnStatus(NetworkStatus::NetConnStatus::NO_NETWORK);
70     return E_OK;
71 }
72 
NetUnavailable()73 int32_t NetConnCallbackObserver::NetUnavailable()
74 {
75     return E_OK;
76 }
77 
NetBlockStatusChange(sptr<NetHandle> & netHandle,bool blocked)78 int32_t NetConnCallbackObserver::NetBlockStatusChange(sptr<NetHandle> &netHandle, bool blocked)
79 {
80     return E_OK;
81 }
82 } // namespace OHOS::FileManagement::CloudSync