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 #include "device_manager_impl.h"
17 #include "device_manager_impl_mock.h"
18 #include "dm_constants.h"
19
20 #include "gtest/gtest.h"
21
22 namespace OHOS {
23 namespace DistributedHardware {
24 #ifndef NORMAL_MOCK
25 const std::string NETWORKID_ONE = "45656596896323231";
26 const std::string NETWORKID_TWO = "45656596896323232";
27 const std::string NETWORKID_THREE = "45656596896323233";
28 constexpr int32_t NETWORKTYPE_WITH_WIFI = 2;
29 constexpr int32_t NETWORKTYPE_NONE_WIFI = 4;
30 #endif
31
InitDeviceManager(const std::string & pkgName,std::shared_ptr<DmInitCallback> dmInitCallback)32 int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback)
33 {
34 return DeviceManagerBase::deviceManager->InitDeviceManager(pkgName, dmInitCallback);
35 }
36
UnInitDeviceManager(const std::string & pkgName)37 int32_t DeviceManagerImpl::UnInitDeviceManager(const std::string &pkgName)
38 {
39 return DeviceManagerBase::deviceManager->UnInitDeviceManager(pkgName);
40 }
41
GetTrustedDeviceList(const std::string & pkgName,const std::string & extra,std::vector<DmDeviceInfo> & deviceList)42 int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName,
43 const std::string &extra,
44 std::vector<DmDeviceInfo> &deviceList)
45 {
46 return DeviceManagerBase::deviceManager->GetTrustedDeviceList(pkgName, extra, deviceList);
47 }
48
GetLocalDeviceInfo(const std::string & pkgName,DmDeviceInfo & info)49 int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info)
50 {
51 return DeviceManagerBase::deviceManager->GetLocalDeviceInfo(pkgName, info);
52 }
53
RegisterDevStateCallback(const std::string & pkgName,const std::string & extra,std::shared_ptr<DeviceStateCallback> callback)54 int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName,
55 const std::string &extra,
56 std::shared_ptr<DeviceStateCallback> callback)
57 {
58 return DeviceManagerBase::deviceManager->RegisterDevStateCallback(pkgName, extra, callback);
59 }
60
UnRegisterDevStateCallback(const std::string & pkgName)61 int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName)
62 {
63 return DeviceManagerBase::deviceManager->UnRegisterDevStateCallback(pkgName);
64 }
65
66 #ifdef NORMAL_MOCK
GetNetworkTypeByNetworkId(const std::string & pkgName,const std::string & netWorkId,int32_t & netWorkType)67 int32_t DeviceManagerImpl::GetNetworkTypeByNetworkId(const std::string &pkgName,
68 const std::string &netWorkId,
69 int32_t &netWorkType)
70 {
71 return DeviceManagerBase::deviceManager->GetNetworkTypeByNetworkId(pkgName, netWorkId, netWorkType);
72 }
73 #else
GetNetworkTypeByNetworkId(const std::string & pkgName,const std::string & netWorkId,int32_t & netWorkType)74 int32_t DeviceManagerImpl::GetNetworkTypeByNetworkId(const std::string &pkgName,
75 const std::string &netWorkId,
76 int32_t &netWorkType)
77 {
78 GTEST_LOG_(INFO) << "GetTrustedDeviceList start";
79 if (netWorkId == NETWORKID_ONE) {
80 return ERR_DM_INPUT_PARA_INVALID;
81 }
82
83 if (netWorkId == NETWORKID_TWO) {
84 netWorkType = NETWORKTYPE_WITH_WIFI;
85 return DM_OK;
86 }
87
88 netWorkType = NETWORKTYPE_NONE_WIFI;
89 return DM_OK;
90 }
91 #endif
92
CheckSrcAccessControl(const DmAccessCaller & caller,const DmAccessCallee & callee)93 bool DeviceManagerImpl::CheckSrcAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee)
94 {
95 return DeviceManagerBase::deviceManager->CheckSrcAccessControl(caller, callee);
96 }
97
CheckSinkAccessControl(const DmAccessCaller & caller,const DmAccessCallee & callee)98 bool DeviceManagerImpl::CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee)
99 {
100 return DeviceManagerBase::deviceManager->CheckSinkAccessControl(caller, callee);
101 }
102
CheckSrcIsSameAccount(const DmAccessCaller & caller,const DmAccessCallee & callee)103 bool DeviceManagerImpl::CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee)
104 {
105 return DeviceManagerBase::deviceManager->CheckSrcIsSameAccount(caller, callee);
106 }
107
CheckSinkIsSameAccount(const DmAccessCaller & caller,const DmAccessCallee & callee)108 bool DeviceManagerImpl::CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee)
109 {
110 return DeviceManagerBase::deviceManager->CheckSinkIsSameAccount(caller, callee);
111 }
112 } // namespace DistributedHardware
113 } // namespace OHOS
114