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