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 #ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
17 #define OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
18 
19 #include <string>
20 
21 #include "device_auth.h"
22 #include "device_auth_defines.h"
23 #include "nlohmann/json.hpp"
24 #include "event_handler.h"
25 #include "single_instance.h"
26 
27 namespace OHOS {
28 namespace DeviceProfile {
29 struct GroupInfo {
30     std::string groupName;
31     std::string groupId;
32     std::string groupOwner;
33     int32_t groupType;
34     int32_t groupVisibility;
35 
GroupInfoGroupInfo36     GroupInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0) {}
37 };
38 
39 void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo);
40 
41 class TrustGroupManager {
42     DECLARE_SINGLE_INSTANCE(TrustGroupManager);
43 
44 public:
45     bool CheckTrustGroup(const std::string& deviceId);
46     bool InitHichainService();
47 private:
48     static void OnDeviceUnBoundAdapter(const char* peerUdid, const char* groupInfo);
49     static bool CheckDeviceId(const std::string udid);
50     static std::string GetDeviceUdid();
51     void InitDataChangeListener();
52     bool CheckGroupsInfo(const char* returnGroups, uint32_t groupNum);
53 
54 private:
55     const DeviceGroupManager* hichainGmInstance_ = nullptr;
56     DataChangeListener dataChangeListener_;
57 };
58 }  // namespace DeviceProfile
59 }  // namespace OHOS
60 #endif  // OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
61