1 /*
2  * Copyright (C) 2024 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 #ifndef OHOS_WIFI_ASSET_MANAGER_H
16 #define OHOS_WIFI_ASSET_MANAGER_H
17 #ifdef SUPPORT_ClOUD_WIFI_ASSET
18 #include <string>
19 #include "asset_system_type.h"
20 #include "asset_system_api.h"
21 #include "wifi_msg.h"
22 #include "wifi_event_handler.h"
23 #include "sta_service_callback.h"
24 
25 namespace OHOS {
26 namespace Wifi {
27 constexpr uint32_t SIZE_OF_ITEM = 13;
28 constexpr int32_t USER_ID_DEFAULT = 100;
29 class WifiAssetManager {
30 public:
31     WifiAssetManager();
32 
33     ~WifiAssetManager();
34 
35     static WifiAssetManager &GetInstance();
36 
37     void InitUpLoadLocalDeviceSync();
38 
39     void CloudAssetSync();
40 
41     void WifiAssetTriggerSync();
42 
43     void WifiAssetAdd(const WifiDeviceConfig &config, int32_t userId = USER_ID_DEFAULT, bool flagSync = true);
44 
45     void WifiAssetQuery(int32_t userId = USER_ID_DEFAULT);
46 
47     void WifiAssetUpdate(const WifiDeviceConfig &config, int32_t userId = USER_ID_DEFAULT);
48 
49     void WifiAssetRemove(const WifiDeviceConfig &config,
50         int32_t userId = USER_ID_DEFAULT, bool flagSync = true);
51 
52     void WifiAssetAddPack(const std::vector<WifiDeviceConfig> &wifiDeviceConfigs,
53         int32_t userId = USER_ID_DEFAULT, bool flagSync = true, bool firstSync = false);
54 
55     void WifiAssetRemovePack(const std::vector<WifiDeviceConfig> &wifiDeviceConfigs,
56         int32_t userId = USER_ID_DEFAULT, bool flagSync = true);
57 
58     void WifiAssetRemoveAll(int32_t userId = USER_ID_DEFAULT, bool flagSync = true);
59 
60     void WifiAssetUpdatePack(const std::vector<WifiDeviceConfig> &wifiDeviceConfigs,
61         int32_t userId = USER_ID_DEFAULT);
62 
63     bool IsWifiConfigChanged(const WifiDeviceConfig &config, const WifiDeviceConfig &oriConfig);
64 
65     bool IsWifiConfigUpdated(const std::vector<WifiDeviceConfig> newWifiDeviceConfigs, WifiDeviceConfig &config);
66 
67     StaServiceCallback GetStaCallback() const;
68 
69     void DealStaConnChanged(OperateResState state, const WifiLinkedInfo &info, int instId);
70 private:
71     std::unique_ptr<WifiEventHandler> assetServiceThread_ = nullptr;
72 
73     std::atomic<bool> firstSync_ = false;
74 
75     StaServiceCallback staCallback_;
76 };
77 }  // namespace Wifi
78 }  // namespace OHOS
79 #endif
80 #endif