1 /*
2 * Copyright (c) 2021-2024 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 "distributed_sched_stub.h"
17
18 #include "ability_info.h"
19 #include "adapter/dnetwork_adapter.h"
20 #include "bundle/bundle_manager_internal.h"
21 #include "caller_info.h"
22 #include "datetime_ex.h"
23 #include "dfx/dms_hisysevent_report.h"
24 #include "dfx/dms_hitrace_chain.h"
25 #include "dfx/dms_hitrace_constants.h"
26 #include "distributed_want.h"
27 #include "distributed_sched_permission.h"
28 #include "dtbschedmgr_log.h"
29 #include "dtbschedmgr_device_info_storage.h"
30 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
31 #include "image_source.h"
32 #include "mission/distributed_sched_mission_manager.h"
33 #include "mission/mission_info_converter.h"
34 #include "mission/snapshot_converter.h"
35 #include "napi_error_code.h"
36 #endif
37 #include "ipc_skeleton.h"
38 #include "message_parcel.h"
39 #include "parcel_helper.h"
40
41 namespace OHOS {
42 namespace DistributedSchedule {
43 using namespace std;
44 using namespace AAFwk;
45 using namespace AppExecFwk;
46
47 namespace {
48 constexpr int32_t HID_HAP = 10000; /* first hap user */
49 const std::string TAG = "DistributedSchedStub";
50 const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
51 const std::string EXTRO_INFO_JSON_KEY_ACCESS_TOKEN = "accessTokenID";
52 const std::string EXTRO_INFO_JSON_KEY_REQUEST_CODE = "requestCode";
53 const std::string PERMISSION_DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC";
54 const std::string PARAM_FREEINSTALL_APPID = "ohos.freeinstall.params.callingAppId";
55 const std::string PARAM_FREEINSTALL_BUNDLENAMES = "ohos.freeinstall.params.callingBundleNames";
56 const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
57 const std::string DMS_VERSION_ID = "dmsVersion";
58 const int DEFAULT_REQUEST_CODE = -1;
59 }
60
DistributedSchedStub()61 DistributedSchedStub::DistributedSchedStub()
62 {
63 InitExtendedLocalFuncsInner();
64 InitLocalFuncsInner();
65 InitRemoteFuncsInner();
66 }
67
~DistributedSchedStub()68 DistributedSchedStub::~DistributedSchedStub()
69 {
70 remoteFuncsMap_.clear();
71 localFuncsMap_.clear();
72 }
73
InitExtendedLocalFuncsInner()74 void DistributedSchedStub::InitExtendedLocalFuncsInner()
75 {
76 // request codes for mission manager
77 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
78 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_DSCHED_EVENT_LISTENER)] =
79 &DistributedSchedStub::RegisterDSchedEventListenerInner;
80 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_DSCHED_EVENT_LISTENER)] =
81 &DistributedSchedStub::UnRegisterDSchedEventListenerInner;
82 #endif
83 }
84
InitLocalFuncsInner()85 void DistributedSchedStub::InitLocalFuncsInner()
86 {
87 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY)] =
88 &DistributedSchedStub::StartRemoteAbilityInner;
89 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION)] =
90 &DistributedSchedStub::ContinueMissionInner;
91 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME)] =
92 &DistributedSchedStub::ContinueMissionOfBundleNameInner;
93 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_CONTINUATION)] =
94 &DistributedSchedStub::StartContinuationInner;
95 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_COMPLETE_CONTINUATION)] =
96 &DistributedSchedStub::NotifyCompleteContinuationInner;
97 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_REMOTE_ABILITY)] =
98 &DistributedSchedStub::ConnectRemoteAbilityInner;
99 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_REMOTE_ABILITY)] =
100 &DistributedSchedStub::DisconnectRemoteAbilityInner;
101 // request codes for mission manager
102 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
103 InitLocalMissionManagerInner();
104 #endif
105 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY_BY_CALL)] =
106 &DistributedSchedStub::StartRemoteAbilityByCallInner;
107 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_REMOTE_ABILITY)] =
108 &DistributedSchedStub::ReleaseRemoteAbilityInner;
109 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
110 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM)] =
111 &DistributedSchedStub::StartRemoteShareFormInner;
112 #endif
113 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::GET_DISTRIBUTED_COMPONENT_LIST)] =
114 &DistributedSchedStub::GetDistributedComponentListInner;
115 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_FREE_INSTALL)] =
116 &DistributedSchedStub::StartRemoteFreeInstallInner;
117 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::STOP_REMOTE_EXTERNSION_ABILITY)] =
118 &DistributedSchedStub::StopRemoteExtensionAbilityInner;
119 }
120
InitLocalMissionManagerInner()121 void DistributedSchedStub::InitLocalMissionManagerInner()
122 {
123 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::GET_REMOTE_MISSION_SNAPSHOT_INFO)] =
124 &DistributedSchedStub::GetRemoteMissionSnapshotInfoInner;
125 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_MISSION_LISTENER)] =
126 &DistributedSchedStub::RegisterMissionListenerInner;
127 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_ON_LISTENER)] =
128 &DistributedSchedStub::RegisterOnListenerInner;
129 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_OFF_LISTENER)] =
130 &DistributedSchedStub::RegisterOffListenerInner;
131 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_MISSION_LISTENER)] =
132 &DistributedSchedStub::UnRegisterMissionListenerInner;
133 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::GET_MISSION_INFOS)] =
134 &DistributedSchedStub::GetMissionInfosInner;
135 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS)] =
136 &DistributedSchedStub::StartSyncRemoteMissionsInner;
137 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS)] =
138 &DistributedSchedStub::StopSyncRemoteMissionsInner;
139 localFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::SET_MISSION_CONTINUE_STATE)] =
140 &DistributedSchedStub::SetMissionContinueStateInner;
141 }
142
InitRemoteFuncsInner()143 void DistributedSchedStub::InitRemoteFuncsInner()
144 {
145 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_ABILITY_FROM_REMOTE)] =
146 &DistributedSchedStub::StartAbilityFromRemoteInner;
147 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::SEND_RESULT_FROM_REMOTE)] =
148 &DistributedSchedStub::SendResultFromRemoteInner;
149 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_CONTINUATION_RESULT_FROM_REMOTE)] =
150 &DistributedSchedStub::NotifyContinuationResultFromRemoteInner;
151 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_DSCHED_EVENT_RESULT_FROM_REMOTE)] =
152 &DistributedSchedStub::NotifyDSchedEventResultFromRemoteInner;
153 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_ABILITY_FROM_REMOTE)] =
154 &DistributedSchedStub::ConnectAbilityFromRemoteInner;
155 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_ABILITY_FROM_REMOTE)] =
156 &DistributedSchedStub::DisconnectAbilityFromRemoteInner;
157 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_PROCESS_DIED_FROM_REMOTE)] =
158 &DistributedSchedStub::NotifyProcessDiedFromRemoteInner;
159 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
160 // request codes for mission manager
161 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS_FROM_REMOTE)] =
162 &DistributedSchedStub::StartSyncMissionsFromRemoteInner;
163 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS_FROM_REMOTE)] =
164 &DistributedSchedStub::StopSyncMissionsFromRemoteInner;
165 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_MISSIONS_CHANGED_FROM_REMOTE)] =
166 &DistributedSchedStub::NotifyMissionsChangedFromRemoteInner;
167 #endif
168 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION)] =
169 &DistributedSchedStub::ContinueMissionInner;
170 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME)] =
171 &DistributedSchedStub::ContinueMissionOfBundleNameInner;
172 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_ABILITY_BY_CALL_FROM_REMOTE)] =
173 &DistributedSchedStub::StartAbilityByCallFromRemoteInner;
174 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_ABILITY_FROM_REMOTE)] =
175 &DistributedSchedStub::ReleaseAbilityFromRemoteInner;
176 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_STATE_CHANGED_FROM_REMOTE)] =
177 &DistributedSchedStub::NotifyStateChangedFromRemoteInner;
178 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
179 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_SHARE_FORM_FROM_REMOTE)] =
180 &DistributedSchedStub::StartShareFormFromRemoteInner;
181 #endif
182 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::START_FREE_INSTALL_FROM_REMOTE)] =
183 &DistributedSchedStub::StartFreeInstallFromRemoteInner;
184 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE)] =
185 &DistributedSchedStub::NotifyCompleteFreeInstallFromRemoteInner;
186 remoteFuncsMap_[static_cast<uint32_t>(IDSchedInterfaceCode::STOP_EXTERNSION_ABILITY_FROM_REMOTE)] =
187 &DistributedSchedStub::StopExtensionAbilityFromRemoteInner;
188 }
189
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)190 int32_t DistributedSchedStub::OnRemoteRequest(uint32_t code,
191 MessageParcel& data, MessageParcel& reply, MessageOption& option)
192 {
193 bool IsLocalCalling = IPCSkeleton::IsLocalCalling();
194 HILOGI("OnRemoteRequest, code = %{public}u, flags = %{public}d, IsLocalCalling = %{public}d.",
195 code, option.GetFlags(), IsLocalCalling);
196
197 const auto& funcsMap = IsLocalCalling ? localFuncsMap_ : remoteFuncsMap_;
198 auto iter = funcsMap.find(code);
199 if (iter != funcsMap.end()) {
200 auto func = iter->second;
201 if (!EnforceInterfaceToken(data)) {
202 HILOGW("OnRemoteRequest interface token check failed!");
203 return DMS_PERMISSION_DENIED;
204 }
205 if (func != nullptr) {
206 return (this->*func)(data, reply);
207 }
208 }
209
210 HILOGW("OnRemoteRequest default case, need check.");
211 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
212 }
213
StartRemoteAbilityInner(MessageParcel & data,MessageParcel & reply)214 int32_t DistributedSchedStub::StartRemoteAbilityInner(MessageParcel& data, MessageParcel& reply)
215 {
216 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
217 return DMS_PERMISSION_DENIED;
218 }
219 DmsHiTraceChain hiTraceChain(TraceValue::START_REMOTE_ABILITY);
220 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::START_REMOTE_ABILITY);
221 shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
222 if (want == nullptr) {
223 HILOGW("START_ABILITY want readParcelable failed!");
224 return ERR_NULL_OBJECT;
225 }
226 int32_t callerUid = 0;
227 PARCEL_READ_HELPER(data, Int32, callerUid);
228 int32_t requestCode = 0;
229 PARCEL_READ_HELPER(data, Int32, requestCode);
230 uint32_t accessToken = 0;
231 PARCEL_READ_HELPER(data, Uint32, accessToken);
232 HILOGD("get callerUid = %d, AccessTokenID = %u", callerUid, accessToken);
233 if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
234 PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
235 HILOGE("check data_sync permission failed!");
236 return DMS_PERMISSION_DENIED;
237 }
238 DistributedSchedPermission::GetInstance().MarkUriPermission(*want, accessToken);
239 int32_t result = StartRemoteAbility(*want, callerUid, requestCode, accessToken);
240 ReportEvent(*want, BehaviorEvent::START_REMOTE_ABILITY, result, callerUid);
241 HILOGI("StartRemoteAbilityInner result = %{public}d", result);
242 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
243 }
244
ReportEvent(const OHOS::AAFwk::Want & want,const std::string & eventName,int32_t result,int32_t callerUid)245 void DistributedSchedStub::ReportEvent(const OHOS::AAFwk::Want& want, const std::string& eventName, int32_t result,
246 int32_t callerUid)
247 {
248 std::vector<std::string> bundleNames;
249 if (!BundleManagerInternal::GetBundleNameListFromBms(callerUid, bundleNames)) {
250 HILOGE("GetBundleNameListFromBms failed");
251 return;
252 }
253 std::string srcBundleName = bundleNames.empty() ? std::string() : bundleNames.front();
254 HILOGD("srcBundleName %{public}s", srcBundleName.c_str());
255 AppExecFwk::BundleInfo localBundleInfo;
256 if (BundleManagerInternal::GetLocalBundleInfo(srcBundleName, localBundleInfo) != ERR_OK) {
257 HILOGE("get local bundle info failed");
258 return;
259 }
260 HILOGD("version %{public}s", localBundleInfo.versionName.c_str());
261
262 BehaviorEventParam eventParam = { EventCallingType::LOCAL, eventName, result, want.GetElement().GetBundleName(),
263 want.GetElement().GetAbilityName(), callerUid, srcBundleName, localBundleInfo.versionName };
264 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
265 HILOGD("report event success!");
266 }
267
ReadDistributedWant(MessageParcel & data)268 shared_ptr<AAFwk::Want> DistributedSchedStub::ReadDistributedWant(MessageParcel& data)
269 {
270 shared_ptr<DistributedWant> dstbWant(data.ReadParcelable<DistributedWant>());
271 shared_ptr<AAFwk::Want> want = nullptr;
272 if (dstbWant != nullptr) {
273 want = dstbWant->ToWant();
274 }
275 return want;
276 }
277
StartAbilityFromRemoteInner(MessageParcel & data,MessageParcel & reply)278 int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
279 {
280 if (!CheckCallingUid()) {
281 HILOGW("request DENIED!");
282 return DMS_PERMISSION_DENIED;
283 }
284 shared_ptr<AAFwk::Want> want = ReadDistributedWant(data);
285 if (want == nullptr) {
286 HILOGW("want readParcelable failed!");
287 return ERR_NULL_OBJECT;
288 }
289 unique_ptr<CompatibleAbilityInfo> cmpAbilityInfo(data.ReadParcelable<CompatibleAbilityInfo>());
290 if (cmpAbilityInfo == nullptr) {
291 HILOGW("AbilityInfo readParcelable failed!");
292 return ERR_NULL_OBJECT;
293 }
294 AbilityInfo abilityInfo;
295 cmpAbilityInfo->ConvertToAbilityInfo(abilityInfo);
296 std::string package = abilityInfo.bundleName;
297 std::string deviceId = abilityInfo.deviceId;
298 int64_t begin = GetTickCount();
299 int32_t requestCode = 0;
300 PARCEL_READ_HELPER(data, Int32, requestCode);
301 CallerInfo callerInfo;
302 PARCEL_READ_HELPER(data, Int32, callerInfo.uid);
303 PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
304 callerInfo.callerType = CALLER_TYPE_HARMONY;
305 AccountInfo accountInfo;
306 accountInfo.accountType = data.ReadInt32();
307 PARCEL_READ_HELPER(data, StringVector, &accountInfo.groupIdList);
308 callerInfo.callerAppId = data.ReadString();
309 std::string extraInfo = data.ReadString();
310 if (!extraInfo.empty()) {
311 nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
312 if (!extraInfoJson.is_discarded()) {
313 SaveExtraInfo(extraInfoJson, callerInfo);
314 HILOGD("parse extra info");
315 }
316 }
317 int32_t result = StartAbilityFromRemote(*want, abilityInfo, requestCode, callerInfo, accountInfo);
318 BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::START_REMOTE_ABILITY, result,
319 want->GetElement().GetBundleName(), want->GetElement().GetAbilityName(), callerInfo.uid };
320 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
321 HILOGI("result = %{public}d", result);
322 PARCEL_WRITE_HELPER(reply, Int32, result);
323 int64_t end = GetTickCount();
324 PARCEL_WRITE_HELPER(reply, Int64, end - begin);
325 PARCEL_WRITE_HELPER(reply, String, package);
326 PARCEL_WRITE_HELPER(reply, String, deviceId);
327 return ERR_NONE;
328 }
329
SaveExtraInfo(const nlohmann::json & extraInfoJson,CallerInfo & callerInfo)330 void DistributedSchedStub::SaveExtraInfo(const nlohmann::json& extraInfoJson, CallerInfo& callerInfo)
331 {
332 if (extraInfoJson.find(EXTRO_INFO_JSON_KEY_ACCESS_TOKEN) != extraInfoJson.end() &&
333 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN].is_number_unsigned()) {
334 uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
335 callerInfo.accessToken = accessToken;
336 HILOGD("parse extra info, accessTokenID = %u", accessToken);
337 }
338 if (extraInfoJson.find(DMS_VERSION_ID) != extraInfoJson.end() && extraInfoJson[DMS_VERSION_ID].is_string()) {
339 std::string dmsVersion = extraInfoJson[DMS_VERSION_ID];
340 callerInfo.extraInfoJson[DMS_VERSION_ID] = dmsVersion;
341 HILOGD("save dms version");
342 }
343 }
344
SendResultFromRemoteInner(MessageParcel & data,MessageParcel & reply)345 int32_t DistributedSchedStub::SendResultFromRemoteInner(MessageParcel& data, MessageParcel& reply)
346 {
347 if (!CheckCallingUid()) {
348 HILOGW("request DENIED!");
349 return DMS_PERMISSION_DENIED;
350 }
351 shared_ptr<DistributedWant> dstbWant(data.ReadParcelable<DistributedWant>());
352 shared_ptr<AAFwk::Want> want = nullptr;
353 if (dstbWant != nullptr) {
354 want = dstbWant->ToWant();
355 }
356 if (want == nullptr) {
357 HILOGW("want readParcelable failed!");
358 return ERR_NULL_OBJECT;
359 }
360 int64_t begin = GetTickCount();
361 int32_t requestCode = 0;
362 PARCEL_READ_HELPER(data, Int32, requestCode);
363 CallerInfo callerInfo;
364 PARCEL_READ_HELPER(data, Int32, callerInfo.uid);
365 PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
366 callerInfo.callerType = CALLER_TYPE_HARMONY;
367 AccountInfo accountInfo;
368 accountInfo.accountType = data.ReadInt32();
369 PARCEL_READ_HELPER(data, StringVector, &accountInfo.groupIdList);
370 callerInfo.callerAppId = data.ReadString();
371 int32_t resultCode = 0;
372 PARCEL_READ_HELPER(data, Int32, resultCode);
373 std::string extraInfo = data.ReadString();
374 if (extraInfo.empty()) {
375 HILOGD("extra info is empty!");
376 }
377 callerInfo.extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
378 int32_t result = SendResultFromRemote(*want, requestCode, callerInfo, accountInfo, resultCode);
379 HILOGI("result = %{public}d", result);
380 PARCEL_WRITE_HELPER(reply, Int32, result);
381 int64_t end = GetTickCount();
382 PARCEL_WRITE_HELPER(reply, Int64, end - begin);
383 return ERR_NONE;
384 }
385
ContinueMissionInner(MessageParcel & data,MessageParcel & reply)386 int32_t DistributedSchedStub::ContinueMissionInner(MessageParcel& data, MessageParcel& reply)
387 {
388 bool isLocalCalling = IPCSkeleton::IsLocalCalling();
389 if ((isLocalCalling && !DistributedSchedPermission::GetInstance().IsFoundationCall()) ||
390 (!isLocalCalling && !CheckCallingUid())) {
391 HILOGE("check permission failed!");
392 return DMS_PERMISSION_DENIED;
393 }
394
395 std::string srcDevId;
396 std::string dstDevId;
397 PARCEL_READ_HELPER(data, String, srcDevId);
398 PARCEL_READ_HELPER(data, String, dstDevId);
399 int32_t missionId = 0;
400 PARCEL_READ_HELPER(data, Int32, missionId);
401 sptr<IRemoteObject> callback = data.ReadRemoteObject();
402 if (callback == nullptr) {
403 HILOGW("read callback failed!");
404 return ERR_NULL_OBJECT;
405 }
406 shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
407 if (wantParams == nullptr) {
408 HILOGW("wantParams readParcelable failed!");
409 return ERR_NULL_OBJECT;
410 }
411 int32_t result = ContinueMission(srcDevId, dstDevId, missionId, callback, *wantParams);
412 HILOGI("result = %{public}d", result);
413 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
414 }
415
ContinueMissionOfBundleNameInner(MessageParcel & data,MessageParcel & reply)416 int32_t DistributedSchedStub::ContinueMissionOfBundleNameInner(MessageParcel& data, MessageParcel& reply)
417 {
418 bool isLocalCalling = IPCSkeleton::IsLocalCalling();
419 if ((isLocalCalling && !DistributedSchedPermission::GetInstance().IsFoundationCall()) ||
420 (!isLocalCalling && !CheckCallingUid())) {
421 HILOGE("check permission failed!");
422 return DMS_PERMISSION_DENIED;
423 }
424
425 std::string srcDevId;
426 std::string dstDevId;
427 std::string bundleName;
428 PARCEL_READ_HELPER(data, String, srcDevId);
429 PARCEL_READ_HELPER(data, String, dstDevId);
430 PARCEL_READ_HELPER(data, String, bundleName);
431 sptr<IRemoteObject> callback = data.ReadRemoteObject();
432 if (callback == nullptr) {
433 HILOGW("read callback failed!");
434 return ERR_NULL_OBJECT;
435 }
436 shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
437 if (wantParams == nullptr) {
438 HILOGW("wantParams readParcelable failed!");
439 return ERR_NULL_OBJECT;
440 }
441 int32_t result = ContinueMission(srcDevId, dstDevId, bundleName, callback, *wantParams);
442 HILOGI("result = %{public}d", result);
443 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
444 }
445
StartContinuationInner(MessageParcel & data,MessageParcel & reply)446 int32_t DistributedSchedStub::StartContinuationInner(MessageParcel& data, MessageParcel& reply)
447 {
448 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
449 return DMS_PERMISSION_DENIED;
450 }
451 DmsHiTraceChain hiTraceChain(TraceValue::START_CONTINUATION);
452 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::START_CONTINUATION);
453 shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
454 if (want == nullptr) {
455 HILOGW("want readParcelable failed!");
456 return ERR_NULL_OBJECT;
457 }
458 int32_t missionId = data.ReadInt32();
459 int32_t callerUid = data.ReadInt32();
460 int32_t status = data.ReadInt32();
461 uint32_t accessToken = 0;
462 PARCEL_READ_HELPER(data, Uint32, accessToken);
463 HILOGI("get AccessTokenID = %{public}u", accessToken);
464 DistributedSchedPermission::GetInstance().MarkUriPermission(*want, accessToken);
465 int32_t result = StartContinuation(*want, missionId, callerUid, status, accessToken);
466 ReportEvent(*want, BehaviorEvent::START_CONTINUATION, result, callerUid);
467 HILOGI("result = %{public}d", result);
468 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
469 }
470
NotifyCompleteContinuationInner(MessageParcel & data,MessageParcel & reply)471 int32_t DistributedSchedStub::NotifyCompleteContinuationInner(MessageParcel& data,
472 [[maybe_unused]] MessageParcel& reply)
473 {
474 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
475 HILOGE("check permission failed!");
476 return DMS_PERMISSION_DENIED;
477 }
478
479 u16string devId = data.ReadString16();
480 if (devId.empty()) {
481 HILOGE("devId is empty!");
482 return INVALID_PARAMETERS_ERR;
483 }
484 int32_t sessionId = 0;
485 PARCEL_READ_HELPER(data, Int32, sessionId);
486 bool continuationResult = false;
487 PARCEL_READ_HELPER(data, Bool, continuationResult);
488 NotifyCompleteContinuation(devId, sessionId, continuationResult);
489 return ERR_OK;
490 }
491
NotifyDSchedEventResultFromRemoteInner(MessageParcel & data,MessageParcel & reply)492 int32_t DistributedSchedStub::NotifyDSchedEventResultFromRemoteInner(MessageParcel& data,
493 [[maybe_unused]] MessageParcel& reply)
494 {
495 if (!CheckCallingUid()) {
496 HILOGW("request DENIED!");
497 return DMS_PERMISSION_DENIED;
498 }
499
500 std::string type = "";
501 PARCEL_READ_HELPER(data, String, type);
502 int32_t dSchedEventResult = -1;
503 PARCEL_READ_HELPER(data, Int32, dSchedEventResult);
504 return NotifyDSchedEventResultFromRemote(type, dSchedEventResult);
505 }
506
NotifyContinuationResultFromRemoteInner(MessageParcel & data,MessageParcel & reply)507 int32_t DistributedSchedStub::NotifyContinuationResultFromRemoteInner(MessageParcel& data,
508 [[maybe_unused]] MessageParcel& reply)
509 {
510 if (!CheckCallingUid()) {
511 HILOGW("request DENIED!");
512 return DMS_PERMISSION_DENIED;
513 }
514
515 int32_t sessionId = 0;
516 PARCEL_READ_HELPER(data, Int32, sessionId);
517 bool continuationResult = false;
518 PARCEL_READ_HELPER(data, Bool, continuationResult);
519 return NotifyContinuationResultFromRemote(sessionId, continuationResult);
520 }
521
ConnectRemoteAbilityInner(MessageParcel & data,MessageParcel & reply)522 int32_t DistributedSchedStub::ConnectRemoteAbilityInner(MessageParcel& data, MessageParcel& reply)
523 {
524 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
525 return DMS_PERMISSION_DENIED;
526 }
527 DmsHiTraceChain hiTraceChain(TraceValue::CONNECT_REMOTE_ABILITY);
528 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::CONNECT_REMOTE_ABILITY);
529 shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
530 if (want == nullptr) {
531 HILOGW("want readParcelable failed!");
532 return ERR_NULL_OBJECT;
533 }
534 sptr<IRemoteObject> connect = data.ReadRemoteObject();
535 int32_t callerUid = 0;
536 PARCEL_READ_HELPER(data, Int32, callerUid);
537 int32_t callerPid = 0;
538 PARCEL_READ_HELPER(data, Int32, callerPid);
539 uint32_t accessToken = 0;
540 PARCEL_READ_HELPER(data, Uint32, accessToken);
541 HILOGD("get callerUid = %d, callerPid = %d, AccessTokenID = %u", callerUid, callerPid,
542 accessToken);
543 if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
544 PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
545 HILOGE("check data_sync permission failed!");
546 return DMS_PERMISSION_DENIED;
547 }
548 int32_t result = ConnectRemoteAbility(*want, connect, callerUid, callerPid, accessToken);
549 ReportEvent(*want, BehaviorEvent::CONNECT_REMOTE_ABILITY, result, callerUid);
550 HILOGI("result = %{public}d", result);
551 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
552 }
553
DisconnectRemoteAbilityInner(MessageParcel & data,MessageParcel & reply)554 int32_t DistributedSchedStub::DisconnectRemoteAbilityInner(MessageParcel& data, MessageParcel& reply)
555 {
556 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
557 return DMS_PERMISSION_DENIED;
558 }
559 DmsHiTraceChain hiTraceChain(TraceValue::DISCONNECT_REMOTE_ABILITY);
560 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::DISCONNECT_REMOTE_ABILITY);
561 sptr<IRemoteObject> connect = data.ReadRemoteObject();
562 int32_t callerUid = 0;
563 PARCEL_READ_HELPER(data, Int32, callerUid);
564 uint32_t accessToken = 0;
565 PARCEL_READ_HELPER(data, Uint32, accessToken);
566 HILOGD("get callerUid = %d, AccessTokenID = %u", callerUid, accessToken);
567 if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
568 PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
569 HILOGE("check data_sync permission failed!");
570 return DMS_PERMISSION_DENIED;
571 }
572 int32_t result = DisconnectRemoteAbility(connect, callerUid, accessToken);
573 BehaviorEventParam eventParam = { EventCallingType::LOCAL, BehaviorEvent::DISCONNECT_REMOTE_ABILITY, result };
574 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
575 HILOGI("result = %{public}d", result);
576 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
577 }
578
ReadDataForConnect(MessageParcel & data,CallerInfo & callerInfo,AccountInfo & accountInfo)579 int32_t DistributedSchedStub::ReadDataForConnect(MessageParcel& data, CallerInfo& callerInfo, AccountInfo& accountInfo)
580 {
581 PARCEL_READ_HELPER(data, Int32, callerInfo.uid);
582 PARCEL_READ_HELPER(data, Int32, callerInfo.pid);
583 PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
584 callerInfo.callerType = CALLER_TYPE_HARMONY;
585 accountInfo.accountType = data.ReadInt32();
586 PARCEL_READ_HELPER(data, StringVector, &accountInfo.groupIdList);
587 callerInfo.callerAppId = data.ReadString();
588 return ERR_NONE;
589 }
590
ConnectAbilityFromRemoteInner(MessageParcel & data,MessageParcel & reply)591 int32_t DistributedSchedStub::ConnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
592 {
593 if (!CheckCallingUid()) {
594 HILOGW("request DENIED!");
595 return DMS_PERMISSION_DENIED;
596 }
597 shared_ptr<AAFwk::Want> want = ReadDistributedWant(data);
598 if (want == nullptr) {
599 HILOGW("want readParcelable failed!");
600 return ERR_NULL_OBJECT;
601 }
602 unique_ptr<CompatibleAbilityInfo> cmpAbilityInfo(data.ReadParcelable<CompatibleAbilityInfo>());
603 if (cmpAbilityInfo == nullptr) {
604 HILOGW("abilityInfo readParcelable failed!");
605 return ERR_NULL_OBJECT;
606 }
607 AbilityInfo abilityInfo;
608 cmpAbilityInfo->ConvertToAbilityInfo(abilityInfo);
609 sptr<IRemoteObject> connect = data.ReadRemoteObject();
610 CallerInfo callerInfo;
611 AccountInfo accountInfo;
612 int32_t result = ReadDataForConnect(data, callerInfo, accountInfo);
613 if (result != ERR_NONE) {
614 return result;
615 }
616 std::string extraInfo = data.ReadString();
617 if (extraInfo.empty()) {
618 HILOGD("extra info is empty!");
619 }
620 nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
621 if (!extraInfoJson.is_discarded()) {
622 SaveExtraInfo(extraInfoJson, callerInfo);
623 HILOGD("parse extra info");
624 }
625 std::string package = abilityInfo.bundleName;
626 std::string deviceId = abilityInfo.deviceId;
627 int64_t begin = GetTickCount();
628 result = ConnectAbilityFromRemote(*want, abilityInfo, connect, callerInfo, accountInfo);
629 BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::CONNECT_REMOTE_ABILITY, result,
630 want->GetElement().GetBundleName(), want->GetElement().GetAbilityName(), callerInfo.uid };
631 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
632 HILOGW("result = %{public}d", result);
633 int64_t end = GetTickCount();
634 PARCEL_WRITE_HELPER(reply, Int32, result);
635 PARCEL_WRITE_HELPER(reply, Int64, end - begin);
636 PARCEL_WRITE_HELPER(reply, String, package);
637 PARCEL_WRITE_HELPER(reply, String, deviceId);
638 return ERR_NONE;
639 }
640
DisconnectAbilityFromRemoteInner(MessageParcel & data,MessageParcel & reply)641 int32_t DistributedSchedStub::DisconnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
642 {
643 if (!CheckCallingUid()) {
644 HILOGW("request DENIED!");
645 return DMS_PERMISSION_DENIED;
646 }
647
648 sptr<IRemoteObject> connect = data.ReadRemoteObject();
649 int32_t uid = 0;
650 PARCEL_READ_HELPER(data, Int32, uid);
651 string sourceDeviceId;
652 PARCEL_READ_HELPER(data, String, sourceDeviceId);
653 int32_t result = DisconnectAbilityFromRemote(connect, uid, sourceDeviceId);
654 BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::DISCONNECT_REMOTE_ABILITY, result };
655 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
656 HILOGI("result %{public}d", result);
657 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
658 }
659
NotifyProcessDiedFromRemoteInner(MessageParcel & data,MessageParcel & reply)660 int32_t DistributedSchedStub::NotifyProcessDiedFromRemoteInner(MessageParcel& data, MessageParcel& reply)
661 {
662 if (!CheckCallingUid()) {
663 HILOGW("request DENIED!");
664 return DMS_PERMISSION_DENIED;
665 }
666
667 int32_t uid = 0;
668 PARCEL_READ_HELPER(data, Int32, uid);
669 int32_t pid = 0;
670 PARCEL_READ_HELPER(data, Int32, pid);
671 string sourceDeviceId;
672 PARCEL_READ_HELPER(data, String, sourceDeviceId);
673 CallerInfo callerInfo;
674 callerInfo.uid = uid;
675 callerInfo.pid = pid;
676 callerInfo.sourceDeviceId = sourceDeviceId;
677 callerInfo.callerType = CALLER_TYPE_HARMONY;
678 int32_t result = NotifyProcessDiedFromRemote(callerInfo);
679 HILOGI("result %{public}d", result);
680 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
681 }
682
CheckCallingUid()683 bool DistributedSchedStub::CheckCallingUid()
684 {
685 // never allow non-system uid for distributed request
686 auto callingUid = IPCSkeleton::GetCallingUid();
687 return callingUid < HID_HAP;
688 }
689
EnforceInterfaceToken(MessageParcel & data)690 bool DistributedSchedStub::EnforceInterfaceToken(MessageParcel& data)
691 {
692 u16string interfaceToken = data.ReadInterfaceToken();
693 return interfaceToken == DMS_STUB_INTERFACE_TOKEN;
694 }
695
696 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
GetMissionInfosInner(MessageParcel & data,MessageParcel & reply)697 int32_t DistributedSchedStub::GetMissionInfosInner(MessageParcel& data, MessageParcel& reply)
698 {
699 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
700 if (!DistributedSchedPermission::GetInstance().IsFoundationCall() &&
701 !DistributedSchedPermission::GetInstance().IsSceneBoardCall()) {
702 return DMS_PERMISSION_DENIED;
703 }
704 std::u16string deviceId = data.ReadString16();
705 int32_t numMissions = 0;
706 PARCEL_READ_HELPER(data, Int32, numMissions);
707
708 std::vector<MissionInfo> missionInfos;
709 int32_t result = GetMissionInfos(Str16ToStr8(deviceId), numMissions, missionInfos);
710 HILOGI("result = %{public}d", result);
711 if (result == ERR_NONE) {
712 result = MissionInfoConverter::WriteMissionInfosToParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
713 }
714 return result;
715 }
716
GetRemoteMissionSnapshotInfoInner(MessageParcel & data,MessageParcel & reply)717 int32_t DistributedSchedStub::GetRemoteMissionSnapshotInfoInner(MessageParcel& data, MessageParcel& reply)
718 {
719 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
720 if (!DistributedSchedPermission::GetInstance().IsFoundationCall() &&
721 !DistributedSchedPermission::GetInstance().IsSceneBoardCall()) {
722 return DMS_PERMISSION_DENIED;
723 }
724 string networkId = data.ReadString();
725 if (networkId.empty()) {
726 HILOGE("networkId is empty!");
727 return ERR_FLATTEN_OBJECT;
728 }
729 int32_t missionId = 0;
730 PARCEL_READ_HELPER(data, Int32, missionId);
731 if (missionId < 0) {
732 HILOGE("missionId is invalid");
733 return INVALID_PARAMETERS_ERR;
734 }
735 std::unique_ptr<MissionSnapshot> missionSnapshotPtr = std::make_unique<MissionSnapshot>();
736 int32_t errCode = GetRemoteMissionSnapshotInfo(networkId, missionId, missionSnapshotPtr);
737 if (errCode != ERR_NONE) {
738 HILOGE("get mission snapshot failed!");
739 return ERR_NULL_OBJECT;
740 }
741 PARCEL_WRITE_HELPER(reply, Parcelable, missionSnapshotPtr.get());
742 std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
743 if (uuid.empty()) {
744 HILOGE("uuid is empty!");
745 return ERR_NULL_OBJECT;
746 }
747 std::unique_ptr<Snapshot> snapshotPtr = make_unique<Snapshot>();
748 SnapshotConverter::ConvertToSnapshot(*missionSnapshotPtr, snapshotPtr);
749 DistributedSchedMissionManager::GetInstance().EnqueueCachedSnapshotInfo(uuid,
750 missionId, std::move(snapshotPtr));
751 return ERR_NONE;
752 }
753
RegisterMissionListenerInner(MessageParcel & data,MessageParcel & reply)754 int32_t DistributedSchedStub::RegisterMissionListenerInner(MessageParcel& data, MessageParcel& reply)
755 {
756 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
757 return DMS_PERMISSION_DENIED;
758 }
759 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
760 u16string devId = data.ReadString16();
761 if (devId.empty()) {
762 HILOGW("read deviceId failed!");
763 return INVALID_PARAMETERS_ERR;
764 }
765 sptr<IRemoteObject> missionChangedListener = data.ReadRemoteObject();
766 if (missionChangedListener == nullptr) {
767 HILOGW("read IRemoteObject failed!");
768 return ERR_FLATTEN_OBJECT;
769 }
770 int32_t result = RegisterMissionListener(devId, missionChangedListener);
771 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
772 }
773
RegisterDSchedEventListenerInner(MessageParcel & data,MessageParcel & reply)774 int32_t DistributedSchedStub::RegisterDSchedEventListenerInner(MessageParcel& data, MessageParcel& reply)
775 {
776 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
777 string type = data.ReadString();
778 if (type.empty()) {
779 HILOGW("read type failed!");
780 return ERR_FLATTEN_OBJECT;
781 }
782 sptr<IRemoteObject> dSchedEventListener = data.ReadRemoteObject();
783 if (dSchedEventListener == nullptr) {
784 HILOGW("read IRemoteObject failed!");
785 return ERR_FLATTEN_OBJECT;
786 }
787 int32_t result = RegisterDSchedEventListener(type, dSchedEventListener);
788 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
789 }
790
UnRegisterDSchedEventListenerInner(MessageParcel & data,MessageParcel & reply)791 int32_t DistributedSchedStub::UnRegisterDSchedEventListenerInner(MessageParcel& data, MessageParcel& reply)
792 {
793 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
794 string type = data.ReadString();
795 if (type.empty()) {
796 HILOGW("read type failed!");
797 return ERR_FLATTEN_OBJECT;
798 }
799 sptr<IRemoteObject> dSchedEventListener = data.ReadRemoteObject();
800 if (dSchedEventListener == nullptr) {
801 HILOGW("read IRemoteObject failed!");
802 return ERR_FLATTEN_OBJECT;
803 }
804 int32_t result = UnRegisterDSchedEventListener(type, dSchedEventListener);
805 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
806 }
807
RegisterOnListenerInner(MessageParcel & data,MessageParcel & reply)808 int32_t DistributedSchedStub::RegisterOnListenerInner(MessageParcel& data, MessageParcel& reply)
809 {
810 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
811 return DMS_PERMISSION_DENIED;
812 }
813 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
814 string type = data.ReadString();
815 if (type.empty()) {
816 HILOGW("read type failed!");
817 return ERR_FLATTEN_OBJECT;
818 }
819 sptr<IRemoteObject> onListener = data.ReadRemoteObject();
820 if (onListener == nullptr) {
821 HILOGW("read IRemoteObject failed!");
822 return ERR_FLATTEN_OBJECT;
823 }
824 int32_t result = RegisterOnListener(type, onListener);
825 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
826 }
827
RegisterOffListenerInner(MessageParcel & data,MessageParcel & reply)828 int32_t DistributedSchedStub::RegisterOffListenerInner(MessageParcel& data, MessageParcel& reply)
829 {
830 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
831 return DMS_PERMISSION_DENIED;
832 }
833 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
834 string type = data.ReadString();
835 if (type.empty()) {
836 HILOGW("read type failed!");
837 return ERR_FLATTEN_OBJECT;
838 }
839 sptr<IRemoteObject> onListener = data.ReadRemoteObject();
840 if (onListener == nullptr) {
841 HILOGW("read IRemoteObject failed!");
842 return ERR_FLATTEN_OBJECT;
843 }
844 int32_t result = RegisterOffListener(type, onListener);
845 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
846 }
847
UnRegisterMissionListenerInner(MessageParcel & data,MessageParcel & reply)848 int32_t DistributedSchedStub::UnRegisterMissionListenerInner(MessageParcel& data, MessageParcel& reply)
849 {
850 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
851 return DMS_PERMISSION_DENIED;
852 }
853 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
854 u16string devId = data.ReadString16();
855 if (devId.empty()) {
856 HILOGW("read deviceId failed!");
857 return INVALID_PARAMETERS_ERR;
858 }
859 sptr<IRemoteObject> missionChangedListener = data.ReadRemoteObject();
860 if (missionChangedListener == nullptr) {
861 HILOGW("read IRemoteObject failed!");
862 return ERR_FLATTEN_OBJECT;
863 }
864 int32_t result = UnRegisterMissionListener(devId, missionChangedListener);
865 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
866 }
867
StartSyncMissionsFromRemoteInner(MessageParcel & data,MessageParcel & reply)868 int32_t DistributedSchedStub::StartSyncMissionsFromRemoteInner(MessageParcel& data, MessageParcel& reply)
869 {
870 if (!CheckCallingUid()) {
871 HILOGW("request DENIED!");
872 return DMS_PERMISSION_DENIED;
873 }
874 CallerInfo callerInfo;
875 if (!CallerInfoUnmarshalling(callerInfo, data)) {
876 HILOGW("read callerInfo failed!");
877 return ERR_FLATTEN_OBJECT;
878 }
879 std::vector<DstbMissionInfo> missionInfos;
880 if (StartSyncMissionsFromRemote(callerInfo, missionInfos) != ERR_NONE) {
881 return ERR_FLATTEN_OBJECT;
882 }
883 if (!reply.WriteInt32(VERSION)) {
884 return ERR_FLATTEN_OBJECT;
885 }
886 if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(reply, missionInfos)) {
887 HILOGE("write mission info failed!");
888 return ERR_FLATTEN_OBJECT;
889 }
890 return ERR_NONE;
891 }
892
StopSyncRemoteMissionsInner(MessageParcel & data,MessageParcel & reply)893 int32_t DistributedSchedStub::StopSyncRemoteMissionsInner(MessageParcel& data, MessageParcel& reply)
894 {
895 HILOGI("[PerformanceTest] called, IPC end = %{public}" PRId64, GetTickCount());
896 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
897 return DMS_PERMISSION_DENIED;
898 }
899 u16string devId = data.ReadString16();
900 if (devId.empty()) {
901 HILOGW("read deviceId failed!");
902 return INVALID_PARAMETERS_ERR;
903 }
904 int32_t result = StopSyncRemoteMissions(Str16ToStr8(devId));
905 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
906 }
907
StopSyncMissionsFromRemoteInner(MessageParcel & data,MessageParcel & reply)908 int32_t DistributedSchedStub::StopSyncMissionsFromRemoteInner(MessageParcel& data, MessageParcel& reply)
909 {
910 if (!CheckCallingUid()) {
911 HILOGW("request DENIED!");
912 return DMS_PERMISSION_DENIED;
913 }
914 CallerInfo callerInfo;
915 if (!CallerInfoUnmarshalling(callerInfo, data)) {
916 HILOGW("read callerInfo failed!");
917 return ERR_FLATTEN_OBJECT;
918 }
919 int32_t result = StopSyncMissionsFromRemote(callerInfo);
920 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
921 }
922
NotifyMissionsChangedFromRemoteInner(MessageParcel & data,MessageParcel & reply)923 int32_t DistributedSchedStub::NotifyMissionsChangedFromRemoteInner(MessageParcel& data, MessageParcel& reply)
924 {
925 if (!CheckCallingUid()) {
926 HILOGW("request DENIED!");
927 return DMS_PERMISSION_DENIED;
928 }
929 int32_t version = data.ReadInt32();
930 HILOGD("version is %{public}d", version);
931 std::vector<DstbMissionInfo> missionInfos;
932 if (!DstbMissionInfo::ReadDstbMissionInfosFromParcel(data, missionInfos)) {
933 return ERR_FLATTEN_OBJECT;
934 }
935 CallerInfo callerInfo;
936 callerInfo.sourceDeviceId = data.ReadString();
937 callerInfo.uid = data.ReadInt32();
938 callerInfo.pid = data.ReadInt32();
939 callerInfo.dmsVersion = data.ReadInt32();
940 int32_t result = NotifyMissionsChangedFromRemote(missionInfos, callerInfo);
941 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
942 }
943
StartSyncRemoteMissionsInner(MessageParcel & data,MessageParcel & reply)944 int32_t DistributedSchedStub::StartSyncRemoteMissionsInner(MessageParcel& data, MessageParcel& reply)
945 {
946 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
947 return DMS_PERMISSION_DENIED;
948 }
949 HILOGI("[PerformanceTest], IPC end = %{public}" PRId64, GetTickCount());
950 u16string devId = data.ReadString16();
951 if (devId.empty()) {
952 HILOGW("read deviceId failed!");
953 return INVALID_PARAMETERS_ERR;
954 }
955 string deviceId = Str16ToStr8(devId);
956 bool fixConflict = data.ReadBool();
957 int64_t tag = data.ReadInt64();
958 int32_t result = StartSyncRemoteMissions(deviceId, fixConflict, tag);
959 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
960 }
961
SetMissionContinueStateInner(MessageParcel & data,MessageParcel & reply)962 int32_t DistributedSchedStub::SetMissionContinueStateInner(MessageParcel& data, MessageParcel& reply)
963 {
964 if (!CheckCallingUid() && !DistributedSchedPermission::GetInstance().IsSceneBoardCall()) {
965 HILOGW("request DENIED!");
966 return DMS_PERMISSION_DENIED;
967 }
968
969 int32_t missionId = 0;
970 PARCEL_READ_HELPER(data, Int32, missionId);
971 int32_t state = 0;
972 PARCEL_READ_HELPER(data, Int32, state);
973
974 int32_t result = SetMissionContinueState(missionId, static_cast<AAFwk::ContinueState>(state));
975 HILOGI("result %{public}d", result);
976 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
977 }
978 #endif
979
CallerInfoUnmarshalling(CallerInfo & callerInfo,MessageParcel & data)980 bool DistributedSchedStub::CallerInfoUnmarshalling(CallerInfo& callerInfo, MessageParcel& data)
981 {
982 int32_t uid = -1;
983 PARCEL_READ_HELPER_RET(data, Int32, uid, false);
984 int32_t pid = -1;
985 PARCEL_READ_HELPER_RET(data, Int32, pid, false);
986 int32_t callerType = CALLER_TYPE_NONE;
987 PARCEL_READ_HELPER_RET(data, Int32, callerType, false);
988 std::string sourceDeviceId;
989 PARCEL_READ_HELPER_RET(data, String, sourceDeviceId, false);
990 HILOGI("sourceDeviceId = %{public}s",
991 DnetworkAdapter::AnonymizeNetworkId(sourceDeviceId).c_str());
992 int32_t duid = -1;
993 PARCEL_READ_HELPER_RET(data, Int32, duid, false);
994 std::string callerAppId;
995 PARCEL_READ_HELPER_RET(data, String, callerAppId, false);
996 int32_t version = -1;
997 PARCEL_READ_HELPER_RET(data, Int32, version, false);
998 callerInfo.uid = uid;
999 callerInfo.pid = pid;
1000 callerInfo.callerType = callerType;
1001 callerInfo.sourceDeviceId = sourceDeviceId;
1002 callerInfo.duid = duid;
1003 callerInfo.callerAppId = callerAppId;
1004 callerInfo.dmsVersion = version;
1005 return true;
1006 }
1007
StartRemoteAbilityByCallInner(MessageParcel & data,MessageParcel & reply)1008 int32_t DistributedSchedStub::StartRemoteAbilityByCallInner(MessageParcel& data, MessageParcel& reply)
1009 {
1010 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
1011 return DMS_PERMISSION_DENIED;
1012 }
1013 DmsHiTraceChain hiTraceChain(TraceValue::START_REMOTE_ABILITY_BYCALL);
1014 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::START_REMOTE_ABILITY_BYCALL);
1015 shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1016 if (want == nullptr) {
1017 HILOGW("want readParcelable failed!");
1018 return ERR_NULL_OBJECT;
1019 }
1020 sptr<IRemoteObject> connect = data.ReadRemoteObject();
1021 int32_t callerUid = 0;
1022 PARCEL_READ_HELPER(data, Int32, callerUid);
1023 int32_t callerPid = 0;
1024 PARCEL_READ_HELPER(data, Int32, callerPid);
1025 uint32_t accessToken = 0;
1026 PARCEL_READ_HELPER(data, Uint32, accessToken);
1027 if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
1028 PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
1029 HILOGE("check data_sync permission failed!");
1030 return DMS_PERMISSION_DENIED;
1031 }
1032 int32_t result = StartRemoteAbilityByCall(*want, connect, callerUid, callerPid, accessToken);
1033 ReportEvent(*want, BehaviorEvent::START_REMOTE_ABILITY_BYCALL, result, callerUid);
1034 HILOGI("result = %{public}d", result);
1035 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1036 }
1037
ReleaseRemoteAbilityInner(MessageParcel & data,MessageParcel & reply)1038 int32_t DistributedSchedStub::ReleaseRemoteAbilityInner(MessageParcel& data, MessageParcel& reply)
1039 {
1040 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
1041 return DMS_PERMISSION_DENIED;
1042 }
1043 DmsHiTraceChain hiTraceChain(TraceValue::RELEASE_REMOTE_ABILITY);
1044 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::RELEASE_REMOTE_ABILITY);
1045 sptr<IRemoteObject> connect = data.ReadRemoteObject();
1046 shared_ptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
1047 if (element == nullptr) {
1048 HILOGE("ReleaseRemoteAbilityInner receive element is nullptr");
1049 return ERR_INVALID_VALUE;
1050 }
1051 int32_t result = ReleaseRemoteAbility(connect, *element);
1052 BehaviorEventParam eventParam = { EventCallingType::LOCAL, BehaviorEvent::RELEASE_REMOTE_ABILITY, result,
1053 element->GetBundleName(), element->GetAbilityName() };
1054 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
1055 HILOGI("result = %{public}d", result);
1056 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1057 }
1058
StartAbilityByCallFromRemoteInner(MessageParcel & data,MessageParcel & reply)1059 int32_t DistributedSchedStub::StartAbilityByCallFromRemoteInner(MessageParcel& data, MessageParcel& reply)
1060 {
1061 if (!CheckCallingUid()) {
1062 HILOGW("request DENIED!");
1063 return DMS_PERMISSION_DENIED;
1064 }
1065
1066 sptr<IRemoteObject> connect = data.ReadRemoteObject();
1067 CallerInfo callerInfo;
1068 PARCEL_READ_HELPER(data, Int32, callerInfo.uid);
1069 PARCEL_READ_HELPER(data, Int32, callerInfo.pid);
1070 PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
1071 AccountInfo accountInfo;
1072 accountInfo.accountType = data.ReadInt32();
1073 PARCEL_READ_HELPER(data, StringVector, &accountInfo.groupIdList);
1074 callerInfo.callerAppId = data.ReadString();
1075 std::string extraInfo = data.ReadString();
1076 if (extraInfo.empty()) {
1077 HILOGW("read extraInfo failed!");
1078 return ERR_NULL_OBJECT;
1079 }
1080 nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
1081 if (!extraInfoJson.is_discarded()) {
1082 SaveExtraInfo(extraInfoJson, callerInfo);
1083 HILOGD("parse extra info");
1084 }
1085 shared_ptr<DistributedWant> dstbWant(data.ReadParcelable<DistributedWant>());
1086 shared_ptr<AAFwk::Want> want = nullptr;
1087 if (dstbWant != nullptr) {
1088 want = dstbWant->ToWant();
1089 }
1090 if (want == nullptr) {
1091 HILOGW("want readParcelable failed!");
1092 return ERR_NULL_OBJECT;
1093 }
1094 int32_t result = StartAbilityByCallFromRemote(*want, connect, callerInfo, accountInfo);
1095 BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::START_REMOTE_ABILITY_BYCALL, result,
1096 want->GetElement().GetBundleName(), want->GetElement().GetAbilityName(), callerInfo.uid };
1097 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
1098 HILOGI("result = %{public}d", result);
1099 PARCEL_WRITE_HELPER(reply, Int32, result);
1100 return ERR_NONE;
1101 }
1102
ReleaseAbilityFromRemoteInner(MessageParcel & data,MessageParcel & reply)1103 int32_t DistributedSchedStub::ReleaseAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
1104 {
1105 if (!CheckCallingUid()) {
1106 HILOGW("request DENIED!");
1107 return DMS_PERMISSION_DENIED;
1108 }
1109
1110 sptr<IRemoteObject> connect = data.ReadRemoteObject();
1111 shared_ptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
1112 if (element == nullptr) {
1113 HILOGE("ReleaseAbilityFromRemoteInner receive element is nullptr");
1114 return ERR_INVALID_VALUE;
1115 }
1116 CallerInfo callerInfo;
1117 PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
1118 std::string extraInfo;
1119 PARCEL_READ_HELPER(data, String, extraInfo);
1120 int32_t result = ReleaseAbilityFromRemote(connect, *element, callerInfo);
1121 BehaviorEventParam eventParam = { EventCallingType::REMOTE, BehaviorEvent::RELEASE_REMOTE_ABILITY, result,
1122 element->GetBundleName(), element->GetAbilityName() };
1123 DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
1124 HILOGI("result %{public}d", result);
1125 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1126 }
1127
1128 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
StartRemoteShareFormInner(MessageParcel & data,MessageParcel & reply)1129 int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel& data, MessageParcel& reply)
1130 {
1131 HILOGD("SHAREFORM:: func call");
1132 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
1133 return DMS_PERMISSION_DENIED;
1134 }
1135
1136 std::string deviceId = "";
1137 PARCEL_READ_HELPER(data, String, deviceId);
1138 shared_ptr<AppExecFwk::FormShareInfo> formShareInfo(data.ReadParcelable<AppExecFwk::FormShareInfo>());
1139 if (formShareInfo == nullptr) {
1140 HILOGW("SHARE_FORM readParcelable failed!");
1141 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast<int32_t>(ERR_FLATTEN_OBJECT));
1142 return ERR_FLATTEN_OBJECT;
1143 }
1144
1145 int32_t result = StartRemoteShareForm(deviceId, *formShareInfo);
1146 HILOGI("result = %{public}d", result);
1147 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1148 }
1149
StartShareFormFromRemoteInner(MessageParcel & data,MessageParcel & reply)1150 int32_t DistributedSchedStub::StartShareFormFromRemoteInner(MessageParcel& data, MessageParcel& reply)
1151 {
1152 HILOGD("SHAREFORM:: func call");
1153 if (!CheckCallingUid()) {
1154 HILOGW("request DENIED!");
1155 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast<int32_t>(DMS_PERMISSION_DENIED));
1156 return DMS_PERMISSION_DENIED;
1157 }
1158
1159 std::string deviceId = "";
1160 PARCEL_READ_HELPER(data, String, deviceId);
1161 shared_ptr<AppExecFwk::FormShareInfo> formShareInfo(data.ReadParcelable<AppExecFwk::FormShareInfo>());
1162 if (formShareInfo == nullptr) {
1163 HILOGW("SHARE_FORM readParcelable failed!");
1164 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast<int32_t>(ERR_FLATTEN_OBJECT));
1165 return ERR_FLATTEN_OBJECT;
1166 }
1167
1168 int32_t result = StartShareFormFromRemote(deviceId, *formShareInfo);
1169 HILOGI("result = %{public}d", result);
1170 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1171 }
1172 #endif
1173
GetDistributedComponentListInner(MessageParcel & data,MessageParcel & reply)1174 int32_t DistributedSchedStub::GetDistributedComponentListInner(MessageParcel& data, MessageParcel& reply)
1175 {
1176 if (!CheckCallingUid()) {
1177 HILOGW("request DENIED!");
1178 return DMS_PERMISSION_DENIED;
1179 }
1180 std::vector<std::string> distributedComponents;
1181 int32_t result = GetDistributedComponentList(distributedComponents);
1182 HILOGI("result = %{public}d", result);
1183 PARCEL_WRITE_HELPER(reply, Int32, result);
1184 PARCEL_WRITE_HELPER(reply, StringVector, distributedComponents);
1185 return ERR_NONE;
1186 }
1187
NotifyStateChangedFromRemoteInner(MessageParcel & data,MessageParcel & reply)1188 int32_t DistributedSchedStub::NotifyStateChangedFromRemoteInner(MessageParcel& data, MessageParcel& reply)
1189 {
1190 if (!CheckCallingUid()) {
1191 HILOGW("request DENIED!");
1192 return DMS_PERMISSION_DENIED;
1193 }
1194 int32_t abilityState = 0;
1195 PARCEL_READ_HELPER(data, Int32, abilityState);
1196 int32_t connectToken = 0;
1197 PARCEL_READ_HELPER(data, Int32, connectToken);
1198 shared_ptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
1199 if (element == nullptr) {
1200 HILOGE("NotifyStateChangedFromRemoteInner receive element is nullptr");
1201 return ERR_INVALID_VALUE;
1202 }
1203 int32_t result = NotifyStateChangedFromRemote(abilityState, connectToken, *element);
1204 HILOGI("result = %{public}d", result);
1205 PARCEL_WRITE_HELPER(reply, Int32, result);
1206 return ERR_NONE;
1207 }
1208
StartRemoteFreeInstallInner(MessageParcel & data,MessageParcel & reply)1209 int32_t DistributedSchedStub::StartRemoteFreeInstallInner(MessageParcel& data, MessageParcel& reply)
1210 {
1211 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
1212 return DMS_PERMISSION_DENIED;
1213 }
1214 shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1215 if (want == nullptr) {
1216 HILOGE("want readParcelable failed!");
1217 return ERR_NULL_OBJECT;
1218 }
1219 int32_t callerUid = 0;
1220 int32_t requestCode = 0;
1221 uint32_t accessToken = 0;
1222 PARCEL_READ_HELPER(data, Int32, callerUid);
1223 PARCEL_READ_HELPER(data, Int32, requestCode);
1224 PARCEL_READ_HELPER(data, Uint32, accessToken);
1225 sptr<IRemoteObject> callback = data.ReadRemoteObject();
1226 if (callback == nullptr) {
1227 HILOGE("read callback failed!");
1228 return ERR_NULL_OBJECT;
1229 }
1230 if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
1231 PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
1232 HILOGE("check data_sync permission failed!");
1233 return DMS_PERMISSION_DENIED;
1234 }
1235 int32_t result = StartRemoteFreeInstall(*want, callerUid, requestCode, accessToken, callback);
1236 HILOGI("result = %{public}d", result);
1237 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1238 return ERR_NONE;
1239 }
1240
ReadDataForFreeInstall(MessageParcel & data,CallerInfo & callerInfo,AccountInfo & accountInfo,int64_t & taskId)1241 int32_t DistributedSchedStub::ReadDataForFreeInstall(MessageParcel& data, CallerInfo &callerInfo,
1242 AccountInfo &accountInfo, int64_t &taskId)
1243 {
1244 callerInfo.callerType = CALLER_TYPE_HARMONY;
1245 PARCEL_READ_HELPER(data, Int32, callerInfo.uid);
1246 PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
1247 accountInfo.accountType = data.ReadInt32();
1248 PARCEL_READ_HELPER(data, StringVector, &accountInfo.groupIdList);
1249 callerInfo.callerAppId = data.ReadString();
1250 PARCEL_READ_HELPER(data, Int64, taskId);
1251 return ERR_NONE;
1252 }
1253
StartFreeInstallFromRemoteInner(MessageParcel & data,MessageParcel & reply)1254 int32_t DistributedSchedStub::StartFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply)
1255 {
1256 if (!CheckCallingUid()) {
1257 HILOGW("request DENIED!");
1258 return DMS_PERMISSION_DENIED;
1259 }
1260 shared_ptr<AAFwk::Want> want = ReadDistributedWant(data);
1261 if (want == nullptr) {
1262 HILOGE("want readParcelable failed!");
1263 return ERR_NULL_OBJECT;
1264 }
1265 int64_t begin = GetTickCount();
1266 CallerInfo callerInfo = {.accessToken = 0};
1267 AccountInfo accountInfo = {};
1268 int64_t taskId = 0;
1269 int32_t result = ReadDataForFreeInstall(data, callerInfo, accountInfo, taskId);
1270 if (result != ERR_NONE) {
1271 return result;
1272 }
1273 shared_ptr<DistributedWant> cmpDstbWant(data.ReadParcelable<DistributedWant>());
1274 shared_ptr<AAFwk::Want> cmpWant = nullptr;
1275 if (cmpDstbWant != nullptr) {
1276 cmpWant = cmpDstbWant->ToWant();
1277 }
1278 std::string extraInfo = data.ReadString();
1279 if (extraInfo.empty()) {
1280 HILOGD("extra info is empty!");
1281 }
1282 nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
1283 int32_t requestCode = DEFAULT_REQUEST_CODE;
1284 if (!extraInfoJson.is_discarded()) {
1285 SaveExtraInfo(extraInfoJson, callerInfo);
1286 if (extraInfoJson.find(EXTRO_INFO_JSON_KEY_REQUEST_CODE) != extraInfoJson.end() &&
1287 extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE].is_number_integer()) {
1288 requestCode = extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE];
1289 HILOGD("parse extra info, requestCode = %d", requestCode);
1290 }
1291 }
1292 FreeInstallInfo info = {
1293 .want = *want, .callerInfo = callerInfo, .accountInfo = accountInfo, .requestCode = requestCode};
1294 info.want.SetParam(PARAM_FREEINSTALL_APPID, callerInfo.callerAppId);
1295 info.want.SetParam(
1296 PARAM_FREEINSTALL_BUNDLENAMES, (*cmpWant).GetStringArrayParam(CMPT_PARAM_FREEINSTALL_BUNDLENAMES));
1297 result = StartFreeInstallFromRemote(info, taskId);
1298 HILOGI("result = %{public}d", result);
1299 PARCEL_WRITE_HELPER(reply, Int32, result);
1300 int64_t end = GetTickCount();
1301 PARCEL_WRITE_HELPER(reply, Int64, end - begin);
1302 return ERR_NONE;
1303 }
1304
NotifyCompleteFreeInstallFromRemoteInner(MessageParcel & data,MessageParcel & reply)1305 int32_t DistributedSchedStub::NotifyCompleteFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply)
1306 {
1307 if (!CheckCallingUid()) {
1308 HILOGW("request DENIED!");
1309 return DMS_PERMISSION_DENIED;
1310 }
1311 int64_t taskId = 0;
1312 int32_t resultCode = 0;
1313 PARCEL_READ_HELPER(data, Int64, taskId);
1314 PARCEL_READ_HELPER(data, Int32, resultCode);
1315 int32_t result = NotifyCompleteFreeInstallFromRemote(taskId, resultCode);
1316 HILOGI("result = %{public}d", result);
1317 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1318 }
1319
StopRemoteExtensionAbilityInner(MessageParcel & data,MessageParcel & reply)1320 int32_t DistributedSchedStub::StopRemoteExtensionAbilityInner(MessageParcel& data, MessageParcel& reply)
1321 {
1322 if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) {
1323 HILOGW("request DENIED!");
1324 return DMS_PERMISSION_DENIED;
1325 }
1326 shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1327 if (want == nullptr) {
1328 HILOGW("Stop reomte extension ability want readParcelable failed!");
1329 return ERR_NULL_OBJECT;
1330 }
1331 int32_t callerUid = 0;
1332 PARCEL_READ_HELPER(data, Int32, callerUid);
1333 uint32_t accessToken = 0;
1334 PARCEL_READ_HELPER(data, Uint32, accessToken);
1335 int32_t serviceType = 0;
1336 PARCEL_READ_HELPER(data, Int32, serviceType);
1337 HILOGD("get callerUid = %{private}d, AccessTokenID = %{private}u", callerUid, accessToken);
1338 if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
1339 PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
1340 HILOGE("check data_sync permission failed!");
1341 return DMS_PERMISSION_DENIED;
1342 }
1343 auto result = StopRemoteExtensionAbility(*want, callerUid, accessToken, serviceType);
1344 HILOGD("StartRemoteAbilityInner result = %{public}d", result);
1345 PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
1346 }
1347
StopExtensionAbilityFromRemoteInner(MessageParcel & data,MessageParcel & reply)1348 int32_t DistributedSchedStub::StopExtensionAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply)
1349 {
1350 if (!CheckCallingUid()) {
1351 HILOGW("request DENIED!");
1352 return DMS_PERMISSION_DENIED;
1353 }
1354 shared_ptr<DistributedWant> dstbWant(data.ReadParcelable<DistributedWant>());
1355 shared_ptr<AAFwk::Want> want = nullptr;
1356 if (dstbWant != nullptr) {
1357 want = dstbWant->ToWant();
1358 }
1359 if (want == nullptr) {
1360 HILOGW("want readParcelable failed!");
1361 return ERR_NULL_OBJECT;
1362 }
1363 int32_t serviceType = 0;
1364 PARCEL_READ_HELPER(data, Int32, serviceType);
1365 CallerInfo callerInfo;
1366 PARCEL_READ_HELPER(data, Int32, callerInfo.uid);
1367 PARCEL_READ_HELPER(data, String, callerInfo.sourceDeviceId);
1368 callerInfo.callerType = CALLER_TYPE_HARMONY;
1369 AccountInfo accountInfo;
1370 accountInfo.accountType = data.ReadInt32();
1371 PARCEL_READ_HELPER(data, StringVector, &accountInfo.groupIdList);
1372 callerInfo.callerAppId = data.ReadString();
1373 std::string extraInfo = data.ReadString();
1374 if (extraInfo.empty()) {
1375 HILOGD("extra info is empty!");
1376 }
1377 nlohmann::json extraInfoJson = nlohmann::json::parse(extraInfo, nullptr, false);
1378 if (!extraInfoJson.is_discarded() && extraInfoJson.find(EXTRO_INFO_JSON_KEY_ACCESS_TOKEN) != extraInfoJson.end() &&
1379 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN].is_number_unsigned()) {
1380 uint32_t accessToken = extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN];
1381 callerInfo.accessToken = accessToken;
1382 HILOGD("parse extra info, accessTokenID = %{private}u", accessToken);
1383 }
1384 auto result = StopExtensionAbilityFromRemote(*want, callerInfo, accountInfo, serviceType);
1385 HILOGD("result = %{public}d", result);
1386 PARCEL_WRITE_HELPER(reply, Int32, result);
1387 return ERR_NONE;
1388 }
1389 } // namespace DistributedSchedule
1390 } // namespace OHOS
1391