1 /*
2 * Copyright (c) 2022-2023 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 <gtest/gtest.h>
17 #include "ipc_skeleton.h"
18 #include "mock_distributed_sched.h"
19
20 namespace OHOS {
21 namespace DistributedSchedule {
22 using namespace std;
23 using namespace AAFwk;
24
25 namespace {
26 const std::string TAG = "MockDistributedSched";
27 const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
28 }
DistributedSchedStub()29 DistributedSchedStub::DistributedSchedStub()
30 {
31 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM)] =
32 &DistributedSchedStub::StartRemoteShareFormInner;
33 }
34
~DistributedSchedStub()35 DistributedSchedStub::~DistributedSchedStub()
36 {
37 localFuncsMap_.clear();
38 }
39
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)40 int32_t DistributedSchedStub::OnRemoteRequest(uint32_t code,
41 MessageParcel &data, MessageParcel &reply, MessageOption &option)
42 {
43 const auto &funcsMap = localFuncsMap_;
44 auto iter = funcsMap.find(code);
45 if (iter != funcsMap.end()) {
46 auto func = iter->second;
47 if (!EnforceInterfaceToken(data)) {
48 return 1;
49 }
50 if (func != nullptr) {
51 return (this->*func)(data, reply);
52 }
53 }
54
55 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57
EnforceInterfaceToken(MessageParcel & data)58 bool DistributedSchedStub::EnforceInterfaceToken(MessageParcel &data)
59 {
60 u16string interfaceToken = data.ReadInterfaceToken();
61 return interfaceToken == DMS_STUB_INTERFACE_TOKEN;
62 }
63
StartRemoteShareFormInner(MessageParcel & data,MessageParcel & reply)64 int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel &data, MessageParcel &reply)
65 {
66 std::string deviceId = data.ReadString();
67 shared_ptr<AppExecFwk::FormShareInfo> formShareInfo(data.ReadParcelable<AppExecFwk::FormShareInfo>());
68 if (formShareInfo == nullptr) {
69 return ERR_NULL_OBJECT;
70 }
71
72 int32_t result = StartRemoteShareForm(deviceId, *formShareInfo);
73 return result;
74 }
75
StopRemoteExtensionAbility(const OHOS::AAFwk::Want & want,int32_t callerUid,uint32_t accessToken,int32_t extensionType)76 int32_t DistributedSchedService::StopRemoteExtensionAbility(
77 const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType)
78 {
79 return ERR_NONE;
80 }
81
StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want & want,const CallerInfo & callerInfo,const DistributedSchedService::AccountInfo & accountInfo,int32_t extensionType)82 int32_t DistributedSchedService::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
83 const CallerInfo& callerInfo, const DistributedSchedService::AccountInfo& accountInfo, int32_t extensionType)
84 {
85 return ERR_NONE;
86 }
87 } // namespace DistributedSchedule
88 } // namespace OHOS