• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #ifndef DISTRIBUTED_INCLUDE_SOFTBUS_DISTRIBUTED_DEVICE_SERVICE_H
17 #define DISTRIBUTED_INCLUDE_SOFTBUS_DISTRIBUTED_DEVICE_SERVICE_H
18 
19 #include "distributed_device_data.h"
20 
21 #include <thread>
22 #include "match_box.h"
23 #include "ffrt.h"
24 
25 namespace OHOS {
26 namespace Notification {
27 class DistributedDeviceService {
28 public:
29     static constexpr int32_t STATE_TYPE_BOTH = 3;
30     static constexpr int32_t STATE_TYPE_SWITCH = 2;
31     static constexpr int32_t STATE_TYPE_LOCKSCREEN = 1;
32     static constexpr int32_t SYNC_BUNDLE_ICONS = 1;
33     static constexpr int32_t SYNC_LIVE_VIEW = 2;
34     static constexpr int32_t SYNC_INSTALLED_BUNDLE = 3;
35     static constexpr int32_t DEVICE_USAGE = 4;
36 
37     static DistributedDeviceService& GetInstance();
38     static std::string DeviceTypeToTypeString(uint16_t deviceType);
39 
40     bool IsLocalPadOrPC();
41     bool IsReportDataByHa();
42     void InitLocalDevice(const std::string &deviceId, uint16_t deviceType);
43     DistributedDeviceInfo GetLocalDevice();
44     void SetSubscribeAllConnect(bool subscribe);
45     bool IsSubscribeAllConnect();
46     bool CheckNeedSubscribeAllConnect();
47     bool IsSyncLiveView(const std::string& deviceId, bool forceSync);
48     bool IsSyncIcons(const std::string& deviceId, bool forceSync);
49     bool IsSyncInstalledBundle(const std::string& deviceId, bool forceSync);
50     bool GetDeviceInfoByUdid(const std::string& udid, DistributedDeviceInfo& device);
51     bool GetDeviceInfo(const std::string& deviceId, DistributedDeviceInfo& device);
52     void SetDeviceState(const std::string& deviceId, int32_t state);
53     void SetDeviceSyncData(const std::string& deviceId, int32_t type, bool syncData);
54     bool CheckDeviceExist(const std::string& deviceId);
55     bool CheckDeviceNeedSync(const std::string& deviceId);
56     void IncreaseDeviceSyncCount(const std::string& deviceId);
57     void AddDeviceInfo(DistributedDeviceInfo deviceItem);
58     void ResetDeviceInfo(const std::string& deviceId, int32_t peerState);
59     void DeleteDeviceInfo(const std::string& deviceId);
60     std::map<std::string, DistributedDeviceInfo>& GetDeviceList();
61     void GetDeviceList(std::map<std::string, DistributedDeviceInfo>& peerDevices);
62     void SyncDeviceMatch(const DistributedDeviceInfo peerDevice, MatchType type);
63 #ifdef DISTRIBUTED_FEATURE_MASTER
64     void SetDeviceStatus(const std::shared_ptr<TlvBox>& boxMessage);
65 #else
66     void InitCurrentDeviceStatus();
67     void SyncDeviceStatus(int32_t type, int32_t status, bool notificationEnable, bool liveViewEnable);
68 #endif
69 
70 private:
71     ffrt::mutex mapLock_;
72     bool subscribeAllConnect = false;
73     DistributedDeviceInfo localDevice_;
74     std::map<std::string, DistributedDeviceInfo> peerDevice_;
75 };
76 }
77 }
78 #endif // DISTRIBUTED_INCLUDE_SOFTBUS_DISTRIBUTED_DEVICE_SERVICE_H
79