1 /* 2 * Copyright (C) 2024-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 #ifndef OHOS_DEVICEPROFILE_CONNECTOR_MOCK_H 16 #define OHOS_DEVICEPROFILE_CONNECTOR_MOCK_H 17 18 #include <string> 19 #include <gmock/gmock.h> 20 21 #include "deviceprofile_connector.h" 22 #include "dm_device_info.h" 23 24 namespace OHOS { 25 namespace DistributedHardware { 26 class DmDeviceProfileConnector { 27 public: 28 virtual ~DmDeviceProfileConnector() = default; 29 public: 30 virtual std::vector<DistributedDeviceProfile::AccessControlProfile> GetAllAccessControlProfile() = 0; 31 virtual int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, 32 const std::string &localUdid, DmOfflineParam &offlineParam) = 0; 33 virtual int32_t HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, 34 const std::string &remoteUdid, const std::string &localUdid) = 0; 35 virtual uint32_t CheckBindType(std::string trustDeviceId, std::string requestDeviceId) = 0; 36 virtual std::map<int32_t, int32_t> GetUserIdAndBindLevel(const std::string &localUdid, 37 const std::string &peerUdid) = 0; 38 virtual bool DeleteAclForAccountLogOut(const DMAclQuadInfo &info, const std::string &accountId, 39 DmOfflineParam &offlineParam) = 0; 40 virtual DmOfflineParam HandleAppUnBindEvent(int32_t remoteUserId, 41 const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid) = 0; 42 virtual std::multimap<std::string, int32_t> GetDevIdAndUserIdByActHash(const std::string &localUdid, 43 const std::string &peerUdid, int32_t peerUserId, const std::string &peerAccountHash) = 0; 44 virtual std::vector<int32_t> SyncAclByBindType(std::string pkgName, std::vector<int32_t> bindTypeVec, 45 std::string localDeviceId, std::string targetDeviceId) = 0; 46 virtual std::vector<int32_t> GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId, 47 std::string trustUdid) = 0; 48 virtual DmOfflineParam DeleteAccessControlList(const std::string &pkgName, const std::string &localDeviceId, 49 const std::string &remoteDeviceId, int32_t bindLevel, const std::string &extra) = 0; 50 virtual void DeleteAclForRemoteUserRemoved(std::string peerUdid, int32_t peerUserId, 51 std::vector<int32_t> &userIds, DmOfflineParam &offlineParam) = 0; 52 virtual DmOfflineParam HandleAppUnBindEvent(int32_t remoteUserId, 53 const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId) = 0; 54 virtual std::unordered_map<std::string, DmAuthForm> GetAppTrustDeviceList(const std::string &pkgName, 55 const std::string &deviceId) = 0; 56 virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; 57 virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string& bundleName, 58 int32_t pinExchangeType, DistributedDeviceProfile::LocalServiceInfo &serviceInfo) = 0; 59 virtual int32_t PutSessionKey(int32_t userId, const std::vector<unsigned char> &sessionKeyArray, 60 int32_t &sessionKeyId) = 0; 61 virtual int32_t PutLocalServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo) = 0; 62 virtual int32_t DeleteLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) = 0; 63 virtual int32_t UpdateLocalServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo) = 0; 64 virtual bool CheckAclStatusAndForegroundNotMatch(const std::string &localUdid, 65 const std::vector<int32_t> &foregroundUserIds, const std::vector<int32_t> &backgroundUserIds) = 0; 66 virtual std::map<std::string, int32_t> GetDeviceIdAndBindLevel(std::vector<int32_t> userIds, 67 const std::string &localUdid) = 0; 68 virtual void DeleteAccessControlById(int64_t& accessControlId) = 0; 69 virtual std::vector<ProcessInfo> GetProcessInfoFromAclByUserId(const std::string &localDeviceId, 70 const std::string &targetDeviceId, int32_t userId) = 0; 71 virtual std::vector<DistributedDeviceProfile::AccessControlProfile> GetAccessControlProfile() = 0; 72 virtual std::vector<DistributedDeviceProfile::AccessControlProfile> GetAllAclIncludeLnnAcl() = 0; 73 virtual std::vector<std::string> GetDeviceIdAndUdidListByTokenId(const std::vector<int32_t> &userIds, 74 const std::string &localUdid, int32_t tokenId) = 0; 75 virtual void CacheAcerAclId(const DistributedDeviceProfile::AccessControlProfile &profile, 76 std::vector<DmAclIdParam> &aclInfos) = 0; 77 virtual bool IsLnnAcl(const DistributedDeviceProfile::AccessControlProfile &profile) = 0; 78 public: 79 static inline std::shared_ptr<DmDeviceProfileConnector> dmDeviceProfileConnector = nullptr; 80 }; 81 82 class DeviceProfileConnectorMock : public DmDeviceProfileConnector { 83 public: 84 MOCK_METHOD(std::vector<DistributedDeviceProfile::AccessControlProfile>, GetAllAccessControlProfile, ()); 85 MOCK_METHOD(int32_t, HandleDevUnBindEvent, (int32_t, const std::string &, const std::string &, DmOfflineParam &)); 86 MOCK_METHOD(int32_t, HandleAccountLogoutEvent, (int32_t, const std::string &, const std::string &, 87 const std::string &)); 88 MOCK_METHOD(uint32_t, CheckBindType, (std::string, std::string)); 89 MOCK_METHOD((std::map<int32_t, int32_t>), GetUserIdAndBindLevel, (const std::string &, const std::string &)); 90 MOCK_METHOD(bool, DeleteAclForAccountLogOut, (const DMAclQuadInfo &, const std::string &, 91 DmOfflineParam &)); 92 MOCK_METHOD((DmOfflineParam), HandleAppUnBindEvent, (int32_t, const std::string &, 93 int32_t, const std::string &)); 94 MOCK_METHOD((std::multimap<std::string, int32_t>), GetDevIdAndUserIdByActHash, (const std::string &, 95 const std::string &, int32_t, const std::string &)); 96 MOCK_METHOD((std::vector<int32_t>), SyncAclByBindType, (std::string, std::vector<int32_t>, std::string, 97 std::string)); 98 MOCK_METHOD((std::vector<int32_t>), GetBindTypeByPkgName, (std::string, std::string, std::string)); 99 MOCK_METHOD(DmOfflineParam, DeleteAccessControlList, (const std::string &, const std::string &, const std::string &, 100 int32_t, const std::string &)); 101 MOCK_METHOD(void, DeleteAclForRemoteUserRemoved, (std::string, int32_t, std::vector<int32_t> &, DmOfflineParam &)); 102 MOCK_METHOD((DmOfflineParam), HandleAppUnBindEvent, (int32_t, const std::string &, 103 int32_t, const std::string &, int32_t)); 104 MOCK_METHOD((std::unordered_map<std::string, DmAuthForm>), GetAppTrustDeviceList, 105 (const std::string &, const std::string &)); 106 MOCK_METHOD(int32_t, CheckDeviceInfoPermission, (const std::string &, const std::string &)); 107 MOCK_METHOD(int32_t, GetLocalServiceInfoByBundleNameAndPinExchangeType, (const std::string&, int32_t, 108 DistributedDeviceProfile::LocalServiceInfo &serviceInfo)); 109 MOCK_METHOD(int32_t, PutSessionKey, (int32_t, const std::vector<unsigned char> &, int32_t&)); 110 MOCK_METHOD(int32_t, PutLocalServiceInfo, (const DistributedDeviceProfile::LocalServiceInfo &)); 111 MOCK_METHOD(int32_t, DeleteLocalServiceInfo, (const std::string &, int32_t)); 112 MOCK_METHOD(int32_t, UpdateLocalServiceInfo, (const DistributedDeviceProfile::LocalServiceInfo &)); 113 MOCK_METHOD(bool, CheckAclStatusAndForegroundNotMatch, 114 (const std::string &, (const std::vector<int32_t> &), (const std::vector<int32_t> &))); 115 MOCK_METHOD((std::map<std::string, int32_t>), GetDeviceIdAndBindLevel, 116 ((std::vector<int32_t>), const std::string &)); 117 MOCK_METHOD(void, DeleteAccessControlById, (int64_t& accessControlId)); 118 MOCK_METHOD(std::vector<ProcessInfo>, GetProcessInfoFromAclByUserId, 119 (const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId)); 120 MOCK_METHOD(std::vector<DistributedDeviceProfile::AccessControlProfile>, GetAccessControlProfile, ()); 121 MOCK_METHOD(std::vector<DistributedDeviceProfile::AccessControlProfile>, GetAllAclIncludeLnnAcl, ()); 122 MOCK_METHOD(std::vector<std::string>, GetDeviceIdAndUdidListByTokenId, (const std::vector<int32_t> &userIds, 123 const std::string &localUdid, int32_t tokenId)); 124 MOCK_METHOD(void, CacheAcerAclId, (const DistributedDeviceProfile::AccessControlProfile &profile, 125 std::vector<DmAclIdParam> &aclInfos)); 126 MOCK_METHOD(bool, IsLnnAcl, (const DistributedDeviceProfile::AccessControlProfile &profile)); 127 }; 128 } 129 } 130 #endif 131