1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "distributed_sched_proxy.h"
17 #include "dfx/dms_hitrace_constants.h"
18 #include "distributed_want.h"
19 #include "dtbschedmgr_log.h"
20 #include "ipc_types.h"
21 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
22 #include "mission/mission_info_converter.h"
23 #include "pixel_map.h"
24 #endif
25 #include "parcel_helper.h"
26 #include "string_ex.h"
27
28 namespace OHOS {
29 namespace DistributedSchedule {
30 using namespace std;
31 using namespace AAFwk;
32
33 namespace {
34 const std::string TAG = "DistributedSchedProxy";
35 const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
36 const std::string EXTRO_INFO_JSON_KEY_ACCESS_TOKEN = "accessTokenID";
37 const std::string EXTRO_INFO_JSON_KEY_REQUEST_CODE = "requestCode";
38 const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
39 const std::string DMS_VERSION_ID = "dmsVersion";
40 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
41 constexpr int32_t WAIT_TIME = 15;
42 #endif
43 }
44
StartRemoteAbility(const OHOS::AAFwk::Want & want,int32_t callerUid,int32_t requestCode,uint32_t accessToken)45 int32_t DistributedSchedProxy::StartRemoteAbility(const OHOS::AAFwk::Want& want,
46 int32_t callerUid, int32_t requestCode, uint32_t accessToken)
47 {
48 sptr<IRemoteObject> remote = Remote();
49 if (remote == nullptr) {
50 return ERR_NULL_OBJECT;
51 }
52 MessageParcel data;
53 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
54 return ERR_FLATTEN_OBJECT;
55 }
56 PARCEL_WRITE_HELPER(data, Parcelable, &want);
57 PARCEL_WRITE_HELPER(data, Int32, callerUid);
58 PARCEL_WRITE_HELPER(data, Int32, requestCode);
59 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
60 MessageParcel reply;
61 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY),
62 data, reply);
63 }
64
StartAbilityFromRemote(const OHOS::AAFwk::Want & want,const OHOS::AppExecFwk::AbilityInfo & abilityInfo,int32_t requestCode,const CallerInfo & callerInfo,const AccountInfo & accountInfo)65 int32_t DistributedSchedProxy::StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
66 const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode,
67 const CallerInfo& callerInfo, const AccountInfo& accountInfo)
68 {
69 sptr<IRemoteObject> remote = Remote();
70 if (remote == nullptr) {
71 HILOGE("StartAbilityFromRemote remote service null");
72 return ERR_NULL_OBJECT;
73 }
74 MessageParcel data;
75 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
76 return ERR_FLATTEN_OBJECT;
77 }
78 DistributedWant dstbWant(want);
79 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
80 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
81 abilityInfo.ConvertToCompatiableAbilityInfo(compatibleAbilityInfo);
82 PARCEL_WRITE_HELPER(data, Parcelable, &compatibleAbilityInfo);
83 PARCEL_WRITE_HELPER(data, Int32, requestCode);
84 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
85 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
86 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
87 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
88 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
89 nlohmann::json extraInfoJson;
90 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
91 if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
92 extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
93 }
94 std::string extraInfo = extraInfoJson.dump();
95 PARCEL_WRITE_HELPER(data, String, extraInfo);
96 MessageParcel reply;
97 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
98 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_ABILITY_FROM_REMOTE),
99 data, reply);
100 }
101
SendResultFromRemote(OHOS::AAFwk::Want & want,int32_t requestCode,const CallerInfo & callerInfo,const AccountInfo & accountInfo,int32_t resultCode)102 int32_t DistributedSchedProxy::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode,
103 const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode)
104 {
105 sptr<IRemoteObject> remote = Remote();
106 if (remote == nullptr) {
107 HILOGE("SendResultFromRemote remote service null");
108 return ERR_NULL_OBJECT;
109 }
110 MessageParcel data;
111 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
112 return ERR_FLATTEN_OBJECT;
113 }
114 DistributedWant dstbWant(want);
115 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
116 PARCEL_WRITE_HELPER(data, Int32, requestCode);
117 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
118 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
119 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
120 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
121 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
122 PARCEL_WRITE_HELPER(data, Int32, resultCode);
123 std::string extraInfo = callerInfo.extraInfoJson.dump();
124 PARCEL_WRITE_HELPER(data, String, extraInfo);
125 MessageParcel reply;
126 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::SEND_RESULT_FROM_REMOTE),
127 data, reply);
128 }
129
ContinueMission(const std::string & srcDeviceId,const std::string & dstDeviceId,int32_t missionId,const sptr<IRemoteObject> & callback,const OHOS::AAFwk::WantParams & wantParams)130 int32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
131 int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
132 {
133 if (callback == nullptr) {
134 HILOGE("ContinueMission callback null");
135 return ERR_NULL_OBJECT;
136 }
137 sptr<IRemoteObject> remote = Remote();
138 if (remote == nullptr) {
139 HILOGE("ContinueMission remote service null");
140 return ERR_NULL_OBJECT;
141 }
142 MessageParcel data;
143 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
144 return ERR_FLATTEN_OBJECT;
145 }
146 PARCEL_WRITE_HELPER(data, String, srcDeviceId);
147 PARCEL_WRITE_HELPER(data, String, dstDeviceId);
148 PARCEL_WRITE_HELPER(data, Int32, missionId);
149 PARCEL_WRITE_HELPER(data, RemoteObject, callback);
150 PARCEL_WRITE_HELPER(data, Parcelable, &wantParams);
151 MessageParcel reply;
152 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION), data, reply);
153 }
154
ContinueMission(const std::string & srcDeviceId,const std::string & dstDeviceId,const std::string & bundleName,const sptr<IRemoteObject> & callback,const OHOS::AAFwk::WantParams & wantParams)155 int32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
156 const std::string& bundleName, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
157 {
158 if (callback == nullptr) {
159 HILOGE("ContinueMission callback null");
160 return ERR_NULL_OBJECT;
161 }
162 sptr<IRemoteObject> remote = Remote();
163 if (remote == nullptr) {
164 HILOGE("ContinueMission remote service null");
165 return ERR_NULL_OBJECT;
166 }
167 MessageParcel data;
168 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
169 return ERR_FLATTEN_OBJECT;
170 }
171 PARCEL_WRITE_HELPER(data, String, srcDeviceId);
172 PARCEL_WRITE_HELPER(data, String, dstDeviceId);
173 PARCEL_WRITE_HELPER(data, String, bundleName);
174 PARCEL_WRITE_HELPER(data, RemoteObject, callback);
175 PARCEL_WRITE_HELPER(data, Parcelable, &wantParams);
176 MessageParcel reply;
177 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME),
178 data, reply);
179 }
180
StartContinuation(const OHOS::AAFwk::Want & want,int32_t missionId,int32_t callerUid,int32_t status,uint32_t accessToken)181 int32_t DistributedSchedProxy::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
182 int32_t status, uint32_t accessToken)
183 {
184 sptr<IRemoteObject> remote = Remote();
185 if (remote == nullptr) {
186 HILOGE("StartContinuation remote service null");
187 return ERR_NULL_OBJECT;
188 }
189 MessageParcel data;
190 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
191 return ERR_FLATTEN_OBJECT;
192 }
193 PARCEL_WRITE_HELPER(data, Parcelable, &want);
194 PARCEL_WRITE_HELPER(data, Int32, missionId);
195 PARCEL_WRITE_HELPER(data, Int32, callerUid);
196 PARCEL_WRITE_HELPER(data, Int32, status);
197 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
198 MessageParcel reply;
199 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_CONTINUATION), data, reply);
200 }
201
NotifyCompleteContinuation(const std::u16string & devId,int32_t sessionId,bool isSuccess)202 void DistributedSchedProxy::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess)
203 {
204 sptr<IRemoteObject> remote = Remote();
205 if (remote == nullptr) {
206 HILOGE("NotifyCompleteContinuation remote service null");
207 return;
208 }
209 MessageParcel data;
210 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
211 return;
212 }
213 PARCEL_WRITE_HELPER_NORET(data, String16, devId);
214 PARCEL_WRITE_HELPER_NORET(data, Int32, sessionId);
215 PARCEL_WRITE_HELPER_NORET(data, Bool, isSuccess);
216 MessageParcel reply;
217 PARCEL_TRANSACT_SYNC_NORET(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_COMPLETE_CONTINUATION),
218 data, reply);
219 }
220
NotifyContinuationResultFromRemote(int32_t sessionId,bool isSuccess)221 int32_t DistributedSchedProxy::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess)
222 {
223 sptr<IRemoteObject> remote = Remote();
224 if (remote == nullptr) {
225 HILOGE("NotifyContinuationResultFromRemote remote service null");
226 return ERR_NULL_OBJECT;
227 }
228 MessageParcel data;
229 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
230 return ERR_FLATTEN_OBJECT;
231 }
232 PARCEL_WRITE_HELPER(data, Int32, sessionId);
233 PARCEL_WRITE_HELPER(data, Bool, isSuccess);
234 MessageParcel reply;
235 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
236 (IDSchedInterfaceCode::NOTIFY_CONTINUATION_RESULT_FROM_REMOTE), data, reply);
237 }
238
ConnectRemoteAbility(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,int32_t callerUid,int32_t callerPid,uint32_t accessToken)239 int32_t DistributedSchedProxy::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
240 int32_t callerUid, int32_t callerPid, uint32_t accessToken)
241 {
242 if (connect == nullptr) {
243 HILOGE("ConnectRemoteAbility connect is null");
244 return ERR_NULL_OBJECT;
245 }
246
247 sptr<IRemoteObject> remote = Remote();
248 if (remote == nullptr) {
249 HILOGE("ConnectRemoteAbility remote is null");
250 return ERR_NULL_OBJECT;
251 }
252 MessageParcel data;
253 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
254 return ERR_FLATTEN_OBJECT;
255 }
256 PARCEL_WRITE_HELPER(data, Parcelable, &want);
257 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
258 PARCEL_WRITE_HELPER(data, Int32, callerUid);
259 PARCEL_WRITE_HELPER(data, Int32, callerPid);
260 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
261 MessageParcel reply;
262 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_REMOTE_ABILITY),
263 data, reply);
264 }
265
DisconnectRemoteAbility(const sptr<IRemoteObject> & connect,int32_t callerUid,uint32_t accessToken)266 int32_t DistributedSchedProxy::DisconnectRemoteAbility(const sptr<IRemoteObject>& connect, int32_t callerUid,
267 uint32_t accessToken)
268 {
269 if (connect == nullptr) {
270 HILOGE("DisconnectRemoteAbility connect is null");
271 return ERR_NULL_OBJECT;
272 }
273
274 sptr<IRemoteObject> remote = Remote();
275 if (remote == nullptr) {
276 HILOGE("DisconnectRemoteAbility remote is null");
277 return ERR_NULL_OBJECT;
278 }
279 MessageParcel data;
280 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
281 return ERR_FLATTEN_OBJECT;
282 }
283 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
284 PARCEL_WRITE_HELPER(data, Int32, callerUid);
285 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
286 MessageParcel reply;
287 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_REMOTE_ABILITY),
288 data, reply);
289 }
290
ConnectAbilityFromRemote(const OHOS::AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,const sptr<IRemoteObject> & connect,const CallerInfo & callerInfo,const AccountInfo & accountInfo)291 int32_t DistributedSchedProxy::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want,
292 const AppExecFwk::AbilityInfo& abilityInfo, const sptr<IRemoteObject>& connect,
293 const CallerInfo& callerInfo, const AccountInfo& accountInfo)
294 {
295 if (connect == nullptr) {
296 HILOGE("ConnectAbilityFromRemote connect is null");
297 return ERR_NULL_OBJECT;
298 }
299
300 sptr<IRemoteObject> remote = Remote();
301 if (remote == nullptr) {
302 HILOGE("ConnectAbilityFromRemote remote is null");
303 return ERR_NULL_OBJECT;
304 }
305 MessageParcel data;
306 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
307 return ERR_FLATTEN_OBJECT;
308 }
309 DistributedWant dstbWant(want);
310 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
311 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
312 abilityInfo.ConvertToCompatiableAbilityInfo(compatibleAbilityInfo);
313 PARCEL_WRITE_HELPER(data, Parcelable, &compatibleAbilityInfo);
314 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
315 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
316 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
317 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
318 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
319 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
320 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
321 nlohmann::json extraInfoJson;
322 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
323 if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
324 extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
325 }
326 std::string extraInfo = extraInfoJson.dump();
327 PARCEL_WRITE_HELPER(data, String, extraInfo);
328 MessageParcel reply;
329 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
330 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_ABILITY_FROM_REMOTE),
331 data, reply);
332 }
333
DisconnectAbilityFromRemote(const sptr<IRemoteObject> & connect,int32_t uid,const std::string & sourceDeviceId)334 int32_t DistributedSchedProxy::DisconnectAbilityFromRemote(const sptr<IRemoteObject>& connect,
335 int32_t uid, const std::string& sourceDeviceId)
336 {
337 if (connect == nullptr) {
338 HILOGE("DisconnectAbilityFromRemote connect is null");
339 return ERR_NULL_OBJECT;
340 }
341
342 sptr<IRemoteObject> remote = Remote();
343 if (remote == nullptr) {
344 HILOGE("DisconnectAbilityFromRemote remote is null");
345 return ERR_NULL_OBJECT;
346 }
347 MessageParcel data;
348 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
349 return ERR_FLATTEN_OBJECT;
350 }
351 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
352 PARCEL_WRITE_HELPER(data, Int32, uid);
353 PARCEL_WRITE_HELPER(data, String, sourceDeviceId);
354 MessageParcel reply;
355 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
356 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_ABILITY_FROM_REMOTE),
357 data, reply);
358 }
359
NotifyProcessDiedFromRemote(const CallerInfo & callerInfo)360 int32_t DistributedSchedProxy::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo)
361 {
362 HILOGD("DistributedSchedProxy::NotifyProcessDiedFromRemote called");
363 sptr<IRemoteObject> remote = Remote();
364 if (remote == nullptr) {
365 HILOGE("NotifyProcessDiedFromRemote remote is null");
366 return ERR_NULL_OBJECT;
367 }
368 MessageParcel data;
369 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
370 return ERR_FLATTEN_OBJECT;
371 }
372 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
373 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
374 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
375 MessageParcel reply;
376 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_PROCESS_DIED_FROM_REMOTE),
377 data, reply);
378 }
379
380 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)381 int32_t DistributedSchedProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
382 {
383 HILOGI("called");
384 sptr<IRemoteObject> remote = Remote();
385 if (remote == nullptr) {
386 HILOGE("remote system ability is null");
387 return ERR_NULL_OBJECT;
388 }
389
390 MessageParcel data;
391 MessageParcel reply;
392 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
393 return ERR_FLATTEN_OBJECT;
394 }
395 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
396 PARCEL_WRITE_HELPER(data, Bool, fixConflict);
397 PARCEL_WRITE_HELPER(data, Int64, tag);
398 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS), data, reply);
399 }
400
StartSyncMissionsFromRemote(const CallerInfo & callerInfo,std::vector<DstbMissionInfo> & missionInfos)401 int32_t DistributedSchedProxy::StartSyncMissionsFromRemote(const CallerInfo& callerInfo,
402 std::vector<DstbMissionInfo>& missionInfos)
403 {
404 HILOGI("called");
405 sptr<IRemoteObject> remote = Remote();
406 if (remote == nullptr) {
407 HILOGE("remote service is null");
408 return ERR_NULL_OBJECT;
409 }
410 MessageParcel data;
411 MessageParcel reply;
412 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
413 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
414 return ERR_FLATTEN_OBJECT;
415 }
416 if (!CallerInfoMarshalling(callerInfo, data)) {
417 return ERR_FLATTEN_OBJECT;
418 }
419 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS_FROM_REMOTE),
420 data, reply, option);
421 if (error != ERR_NONE) {
422 HILOGW("fail, error: %{public}d", error);
423 return error;
424 }
425 int32_t version = reply.ReadInt32();
426 HILOGD("version : %{public}d", version);
427 return DstbMissionInfo::ReadDstbMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
428 }
429
StopSyncRemoteMissions(const std::string & devId)430 int32_t DistributedSchedProxy::StopSyncRemoteMissions(const std::string& devId)
431 {
432 HILOGI("called");
433 sptr<IRemoteObject> remote = Remote();
434 if (remote == nullptr) {
435 HILOGE("remote system ability is null");
436 return ERR_NULL_OBJECT;
437 }
438 MessageParcel data;
439 MessageParcel reply;
440 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
441 return ERR_FLATTEN_OBJECT;
442 }
443 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
444 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS), data, reply);
445 }
446
StopSyncMissionsFromRemote(const CallerInfo & callerInfo)447 int32_t DistributedSchedProxy::StopSyncMissionsFromRemote(const CallerInfo& callerInfo)
448 {
449 HILOGI("called");
450 sptr<IRemoteObject> remote = Remote();
451 if (remote == nullptr) {
452 HILOGE("remote service is null");
453 return ERR_NULL_OBJECT;
454 }
455 MessageParcel data;
456 MessageParcel reply;
457 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
458 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
459 return ERR_FLATTEN_OBJECT;
460 }
461 if (!CallerInfoMarshalling(callerInfo, data)) {
462 return ERR_FLATTEN_OBJECT;
463 }
464 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS_FROM_REMOTE),
465 data, reply, option);
466 if (error != ERR_NONE) {
467 HILOGW("sendRequest fail, error: %{public}d", error);
468 return error;
469 }
470 return reply.ReadInt32();
471 }
472
RegisterMissionListener(const std::u16string & devId,const sptr<IRemoteObject> & obj)473 int32_t DistributedSchedProxy::RegisterMissionListener(const std::u16string& devId,
474 const sptr<IRemoteObject>& obj)
475 {
476 HILOGI("RegisterMissionListener called");
477 sptr<IRemoteObject> remote = Remote();
478 if (remote == nullptr) {
479 HILOGE("remote system ability is null");
480 return ERR_NULL_OBJECT;
481 }
482 MessageParcel data;
483 MessageParcel reply;
484 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
485 return ERR_FLATTEN_OBJECT;
486 }
487 PARCEL_WRITE_HELPER(data, String16, devId);
488 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
489 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_MISSION_LISTENER),
490 data, reply);
491 }
492
RegisterOnListener(const std::string & type,const sptr<IRemoteObject> & obj)493 int32_t DistributedSchedProxy::RegisterOnListener(const std::string& type,
494 const sptr<IRemoteObject>& obj)
495 {
496 HILOGI("RegisterOnListener called");
497 sptr<IRemoteObject> remote = Remote();
498 if (remote == nullptr) {
499 HILOGE("remote system ability is null");
500 return ERR_NULL_OBJECT;
501 }
502 MessageParcel data;
503 MessageParcel reply;
504 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
505 return ERR_FLATTEN_OBJECT;
506 }
507 PARCEL_WRITE_HELPER(data, String, type);
508 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
509 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_ON_LISTENER),
510 data, reply);
511 }
512
RegisterOffListener(const std::string & type,const sptr<IRemoteObject> & obj)513 int32_t DistributedSchedProxy::RegisterOffListener(const std::string& type,
514 const sptr<IRemoteObject>& obj)
515 {
516 HILOGI("RegisterOffListener called");
517 sptr<IRemoteObject> remote = Remote();
518 if (remote == nullptr) {
519 HILOGE("remote system ability is null");
520 return ERR_NULL_OBJECT;
521 }
522 MessageParcel data;
523 MessageParcel reply;
524 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
525 return ERR_FLATTEN_OBJECT;
526 }
527 PARCEL_WRITE_HELPER(data, String, type);
528 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
529 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_OFF_LISTENER),
530 data, reply);
531 }
532
UnRegisterMissionListener(const std::u16string & devId,const sptr<IRemoteObject> & obj)533 int32_t DistributedSchedProxy::UnRegisterMissionListener(const std::u16string& devId,
534 const sptr<IRemoteObject>& obj)
535 {
536 HILOGI("UnRegisterMissionListener called");
537 sptr<IRemoteObject> remote = Remote();
538 if (remote == nullptr) {
539 HILOGE("remote system ability is null");
540 return ERR_NULL_OBJECT;
541 }
542 MessageParcel data;
543 MessageParcel reply;
544 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
545 return ERR_FLATTEN_OBJECT;
546 }
547 PARCEL_WRITE_HELPER(data, String16, devId);
548 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
549 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_MISSION_LISTENER),
550 data, reply);
551 }
552
GetMissionInfos(const std::string & deviceId,int32_t numMissions,std::vector<AAFwk::MissionInfo> & missionInfos)553 int32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int32_t numMissions,
554 std::vector<AAFwk::MissionInfo>& missionInfos)
555 {
556 HILOGI("called");
557 sptr<IRemoteObject> remote = Remote();
558 if (remote == nullptr) {
559 HILOGE("remote system ability is null");
560 return ERR_NULL_OBJECT;
561 }
562
563 MessageParcel data;
564 MessageParcel reply;
565 MessageOption option;
566 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
567 return ERR_FLATTEN_OBJECT;
568 }
569 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(deviceId));
570 PARCEL_WRITE_HELPER(data, Int32, numMissions);
571 int32_t ret = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_MISSION_INFOS), data, reply,
572 option);
573 if (ret != ERR_NONE) {
574 HILOGW("sendRequest fail, error: %{public}d", ret);
575 return ret;
576 }
577 return MissionInfoConverter::ReadMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
578 }
579
NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo> & missionInfos,const CallerInfo & callerInfo)580 int32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo>& missionInfos,
581 const CallerInfo& callerInfo)
582 {
583 HILOGI("NotifyMissionsChangedFromRemote is called");
584 sptr<IRemoteObject> remote = Remote();
585 if (remote == nullptr) {
586 HILOGE("NotifyMissionsChangedFromRemote remote service is null");
587 return ERR_NULL_OBJECT;
588 }
589
590 MessageParcel data;
591 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
592 return ERR_FLATTEN_OBJECT;
593 }
594 PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
595 if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(data, missionInfos)) {
596 return ERR_FLATTEN_OBJECT;
597 }
598 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
599 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
600 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
601 PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
602 MessageParcel reply;
603 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
604 int32_t error = remote->SendRequest(static_cast<uint32_t>
605 (IDSchedInterfaceCode::NOTIFY_MISSIONS_CHANGED_FROM_REMOTE), data, reply, option);
606 if (error != ERR_NONE) {
607 HILOGE("%{public}s transact failed, error: %{public}d", __func__, error);
608 return error;
609 }
610 int32_t result = reply.ReadInt32();
611 HILOGD("%{public}s get result from server data = %{public}d", __func__, result);
612 return result;
613 }
614
GetRemoteMissionSnapshotInfo(const std::string & networkId,int32_t missionId,std::unique_ptr<MissionSnapshot> & missionSnapshot)615 int32_t DistributedSchedProxy::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
616 std::unique_ptr<MissionSnapshot>& missionSnapshot)
617 {
618 if (networkId.empty()) {
619 HILOGE("networkId is null");
620 return ERR_NULL_OBJECT;
621 }
622 if (missionId < 0) {
623 HILOGE("missionId is invalid");
624 return INVALID_PARAMETERS_ERR;
625 }
626 sptr<IRemoteObject> remote = Remote();
627 if (remote == nullptr) {
628 HILOGE("remote is null");
629 return ERR_NULL_OBJECT;
630 }
631 MessageParcel data;
632 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
633 return ERR_FLATTEN_OBJECT;
634 }
635 PARCEL_WRITE_HELPER(data, String, networkId);
636 PARCEL_WRITE_HELPER(data, Int32, missionId);
637 MessageParcel reply;
638 MessageOption option;
639 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_REMOTE_MISSION_SNAPSHOT_INFO),
640 data, reply, option);
641 if (error != ERR_NONE) {
642 HILOGE("transact failed, error: %{public}d", error);
643 return error;
644 }
645 std::unique_ptr<MissionSnapshot> missionSnapshotPtr(reply.ReadParcelable<MissionSnapshot>());
646 missionSnapshot = std::move(missionSnapshotPtr);
647 return ERR_NONE;
648 }
649
SetMissionContinueState(int32_t missionId,const AAFwk::ContinueState & state)650 int32_t DistributedSchedProxy::SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state)
651 {
652 HILOGD("DistributedSchedProxy::SetMissionContinueState called");
653 sptr<IRemoteObject> remote = Remote();
654 if (remote == nullptr) {
655 HILOGE("SetMissionContinueState remote is null");
656 return ERR_NULL_OBJECT;
657 }
658
659 MessageParcel data;
660 MessageParcel reply;
661 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
662 return ERR_FLATTEN_OBJECT;
663 }
664 PARCEL_WRITE_HELPER(data, Int32, missionId);
665 PARCEL_WRITE_HELPER(data, Int32, static_cast<int32_t>(state));
666 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::SET_MISSION_CONTINUE_STATE),
667 data, reply);
668 }
669 #endif
670
CallerInfoMarshalling(const CallerInfo & callerInfo,MessageParcel & data)671 bool DistributedSchedProxy::CallerInfoMarshalling(const CallerInfo& callerInfo, MessageParcel& data)
672 {
673 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.uid, false);
674 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.pid, false);
675 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.callerType, false);
676 PARCEL_WRITE_HELPER_RET(data, String, callerInfo.sourceDeviceId, false);
677 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.duid, false);
678 PARCEL_WRITE_HELPER_RET(data, String, callerInfo.callerAppId, false);
679 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.dmsVersion, false);
680 return true;
681 }
682
StartRemoteAbilityByCall(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,int32_t callerUid,int32_t callerPid,uint32_t accessToken)683 int32_t DistributedSchedProxy::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want,
684 const sptr<IRemoteObject>& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken)
685 {
686 if (connect == nullptr) {
687 HILOGE("StartRemoteAbilityByCall connect is null");
688 return ERR_NULL_OBJECT;
689 }
690
691 sptr<IRemoteObject> remote = Remote();
692 if (remote == nullptr) {
693 HILOGE("StartRemoteAbilityByCall remote is null");
694 return ERR_NULL_OBJECT;
695 }
696 MessageParcel data;
697 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
698 return ERR_FLATTEN_OBJECT;
699 }
700 PARCEL_WRITE_HELPER(data, Parcelable, &want);
701 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
702 PARCEL_WRITE_HELPER(data, Int32, callerUid);
703 PARCEL_WRITE_HELPER(data, Int32, callerPid);
704 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
705 MessageParcel reply;
706 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY_BY_CALL),
707 data, reply);
708 }
709
ReleaseRemoteAbility(const sptr<IRemoteObject> & connect,const AppExecFwk::ElementName & element)710 int32_t DistributedSchedProxy::ReleaseRemoteAbility(const sptr<IRemoteObject>& connect,
711 const AppExecFwk::ElementName &element)
712 {
713 if (connect == nullptr) {
714 HILOGE("ReleaseRemoteAbility connect is null");
715 return ERR_NULL_OBJECT;
716 }
717
718 sptr<IRemoteObject> remote = Remote();
719 if (remote == nullptr) {
720 HILOGE("ReleaseRemoteAbility remote is null");
721 return ERR_NULL_OBJECT;
722 }
723 MessageParcel data;
724 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
725 return ERR_FLATTEN_OBJECT;
726 }
727 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
728 if (!data.WriteParcelable(&element)) {
729 HILOGE("ReleaseRemoteAbility write element error.");
730 return ERR_INVALID_VALUE;
731 }
732 MessageParcel reply;
733 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_REMOTE_ABILITY),
734 data, reply);
735 }
736
StartAbilityByCallFromRemote(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,const CallerInfo & callerInfo,const AccountInfo & accountInfo)737 int32_t DistributedSchedProxy::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want,
738 const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo)
739 {
740 if (connect == nullptr) {
741 HILOGE("StartAbilityByCallFromRemote connect is null");
742 return ERR_NULL_OBJECT;
743 }
744
745 sptr<IRemoteObject> remote = Remote();
746 if (remote == nullptr) {
747 HILOGE("StartAbilityByCallFromRemote remote is null");
748 return ERR_NULL_OBJECT;
749 }
750 MessageParcel data;
751 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
752 return ERR_FLATTEN_OBJECT;
753 }
754 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
755 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
756 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
757 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
758 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
759 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
760 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
761 nlohmann::json extraInfoJson;
762 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
763 if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
764 extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
765 }
766 std::string extraInfo = extraInfoJson.dump();
767 PARCEL_WRITE_HELPER(data, String, extraInfo);
768 DistributedWant dstbWant(want);
769 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
770 MessageParcel reply;
771 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
772 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
773 (IDSchedInterfaceCode::START_ABILITY_BY_CALL_FROM_REMOTE), data, reply);
774 }
775
ReleaseAbilityFromRemote(const sptr<IRemoteObject> & connect,const AppExecFwk::ElementName & element,const CallerInfo & callerInfo)776 int32_t DistributedSchedProxy::ReleaseAbilityFromRemote(const sptr<IRemoteObject>& connect,
777 const AppExecFwk::ElementName &element, const CallerInfo& callerInfo)
778 {
779 if (connect == nullptr) {
780 HILOGE("ReleaseAbilityFromRemote connect is null");
781 return ERR_NULL_OBJECT;
782 }
783
784 sptr<IRemoteObject> remote = Remote();
785 if (remote == nullptr) {
786 HILOGE("ReleaseAbilityFromRemote remote is null");
787 return ERR_NULL_OBJECT;
788 }
789 MessageParcel data;
790 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
791 return ERR_FLATTEN_OBJECT;
792 }
793 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
794 if (!data.WriteParcelable(&element)) {
795 HILOGE("ReleaseAbilityFromRemote write element error.");
796 return ERR_INVALID_VALUE;
797 }
798 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
799 std::string extraInfo = "";
800 PARCEL_WRITE_HELPER(data, String, extraInfo);
801 MessageParcel reply;
802 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
803 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_ABILITY_FROM_REMOTE),
804 data, reply);
805 }
806
StartRemoteFreeInstall(const OHOS::AAFwk::Want & want,int32_t callerUid,int32_t requestCode,uint32_t accessToken,const sptr<IRemoteObject> & callback)807 int32_t DistributedSchedProxy::StartRemoteFreeInstall(const OHOS::AAFwk::Want& want,
808 int32_t callerUid, int32_t requestCode, uint32_t accessToken, const sptr<IRemoteObject>& callback)
809 {
810 HILOGD("called.");
811 if (callback == nullptr) {
812 HILOGE("ContinueMission callback null");
813 return ERR_NULL_OBJECT;
814 }
815
816 sptr<IRemoteObject> remote = Remote();
817 if (remote == nullptr) {
818 HILOGE("remote callback null");
819 return ERR_NULL_OBJECT;
820 }
821
822 MessageParcel data;
823 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
824 HILOGE("write interface token null");
825 return ERR_FLATTEN_OBJECT;
826 }
827
828 PARCEL_WRITE_HELPER(data, Parcelable, &want);
829 PARCEL_WRITE_HELPER(data, Int32, callerUid);
830 PARCEL_WRITE_HELPER(data, Int32, requestCode);
831 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
832 PARCEL_WRITE_HELPER(data, RemoteObject, callback);
833 MessageParcel reply;
834 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_FREE_INSTALL),
835 data, reply);
836 }
837
StartFreeInstallFromRemote(const FreeInstallInfo & info,int64_t taskId)838 int32_t DistributedSchedProxy::StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId)
839 {
840 HILOGD("called.");
841 sptr<IRemoteObject> remote = Remote();
842 if (remote == nullptr) {
843 HILOGE("remote is null");
844 return ERR_NULL_OBJECT;
845 }
846
847 MessageParcel data;
848 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
849 HILOGE("write interface token null");
850 return ERR_FLATTEN_OBJECT;
851 }
852
853 DistributedWant dstbWant(info.want);
854 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
855 PARCEL_WRITE_HELPER(data, Int32, info.callerInfo.uid);
856 PARCEL_WRITE_HELPER(data, String, info.callerInfo.sourceDeviceId);
857 PARCEL_WRITE_HELPER(data, Int32, info.accountInfo.accountType);
858 PARCEL_WRITE_HELPER(data, StringVector, info.accountInfo.groupIdList);
859 PARCEL_WRITE_HELPER(data, String, info.callerInfo.callerAppId);
860 PARCEL_WRITE_HELPER(data, Int64, taskId);
861 DistributedWant cmpWant;
862 cmpWant.SetParam(CMPT_PARAM_FREEINSTALL_BUNDLENAMES, info.callerInfo.bundleNames);
863 PARCEL_WRITE_HELPER(data, Parcelable, &cmpWant);
864 nlohmann::json extraInfoJson;
865 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = info.callerInfo.accessToken;
866 extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE] = info.requestCode;
867 if (info.callerInfo.extraInfoJson.find(DMS_VERSION_ID) != info.callerInfo.extraInfoJson.end()) {
868 extraInfoJson[DMS_VERSION_ID] = info.callerInfo.extraInfoJson[DMS_VERSION_ID];
869 }
870 std::string extraInfo = extraInfoJson.dump();
871 PARCEL_WRITE_HELPER(data, String, extraInfo);
872 MessageParcel reply;
873 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
874 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_FREE_INSTALL_FROM_REMOTE),
875 data, reply);
876 }
877
NotifyCompleteFreeInstallFromRemote(int64_t taskId,int32_t resultCode)878 int32_t DistributedSchedProxy::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode)
879 {
880 HILOGD("called.");
881 sptr<IRemoteObject> remote = Remote();
882 if (remote == nullptr) {
883 HILOGE("remote is null");
884 return ERR_NULL_OBJECT;
885 }
886
887 MessageParcel data;
888 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
889 HILOGE("write interface token null");
890 return ERR_FLATTEN_OBJECT;
891 }
892
893 PARCEL_WRITE_HELPER(data, Int64, taskId);
894 PARCEL_WRITE_HELPER(data, Int32, resultCode);
895 MessageParcel reply;
896 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
897 (IDSchedInterfaceCode::NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE), data, reply);
898 }
899
900 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
StartRemoteShareForm(const std::string & remoteDeviceId,const AppExecFwk::FormShareInfo & formShareInfo)901 int32_t DistributedSchedProxy::StartRemoteShareForm(
902 const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
903 {
904 HILOGD("SHAREFORM:: func call");
905 if (remoteDeviceId.empty()) {
906 HILOGE("input params deviceId is nullptr.");
907 return INVALID_PARAMETERS_ERR;
908 }
909
910 auto remote = Remote();
911 if (remote == nullptr) {
912 HILOGE("fail to get dms remote.");
913 return DMSPROXY_SERVICE_ERR;
914 }
915
916 MessageParcel data;
917 MessageParcel reply;
918 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
919 HILOGE("WriteInterfaceToken failed");
920 return ERR_FLATTEN_OBJECT;
921 }
922
923 PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
924 PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
925
926 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM),
927 data, reply);
928 }
929
StartShareFormFromRemote(const std::string & remoteDeviceId,const AppExecFwk::FormShareInfo & formShareInfo)930 int32_t DistributedSchedProxy::StartShareFormFromRemote(
931 const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
932 {
933 HILOGD("SHAREFORM:: func call");
934 if (remoteDeviceId.empty()) {
935 HILOGE("input params deviceId is nullptr.");
936 return INVALID_PARAMETERS_ERR;
937 }
938
939 auto remote = Remote();
940 if (remote == nullptr) {
941 HILOGE("fail to get dms remote.");
942 return DMSPROXY_SERVICE_ERR;
943 }
944
945 MessageParcel data;
946 MessageParcel reply;
947 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
948 HILOGE("WriteInterfaceToken failed");
949 return ERR_FLATTEN_OBJECT;
950 }
951
952 PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
953 PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
954
955 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SHARE_FORM_FROM_REMOTE),
956 data, reply);
957 }
958 #endif
959
NotifyStateChangedFromRemote(int32_t abilityState,int32_t connectToken,const AppExecFwk::ElementName & element)960 int32_t DistributedSchedProxy::NotifyStateChangedFromRemote(int32_t abilityState, int32_t connectToken,
961 const AppExecFwk::ElementName& element)
962 {
963 sptr<IRemoteObject> remote = Remote();
964 if (remote == nullptr) {
965 HILOGE("NotifyStateChangedFromRemote remote service null");
966 return ERR_NULL_OBJECT;
967 }
968 MessageParcel data;
969 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
970 HILOGE("WriteInterfaceToken failed");
971 return ERR_FLATTEN_OBJECT;
972 }
973 PARCEL_WRITE_HELPER(data, Int32, abilityState);
974 PARCEL_WRITE_HELPER(data, Int32, connectToken);
975 if (!data.WriteParcelable(&element)) {
976 HILOGE("NotifyStateChangedFromRemote write element error.");
977 return ERR_INVALID_VALUE;
978 }
979 MessageParcel reply;
980 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_STATE_CHANGED_FROM_REMOTE),
981 data, reply);
982 }
983
GetDistributedComponentList(std::vector<std::string> & distributedComponents)984 int32_t DistributedSchedProxy::GetDistributedComponentList(std::vector<std::string>& distributedComponents)
985 {
986 sptr<IRemoteObject> remote = Remote();
987 if (remote == nullptr) {
988 HILOGE("GetDistributedComponentList remote is null");
989 return ERR_NULL_OBJECT;
990 }
991 MessageParcel data;
992 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
993 return ERR_FLATTEN_OBJECT;
994 }
995 MessageParcel reply;
996 MessageOption option;
997 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_DISTRIBUTED_COMPONENT_LIST),
998 data, reply, option);
999 if (error != ERR_NONE) {
1000 HILOGE("GetDistributedComponentList SendRequest error = %{public}d", error);
1001 return error;
1002 }
1003 int32_t result = reply.ReadInt32();
1004 if (result != ERR_NONE) {
1005 HILOGE("GetDistributedComponentList result = %{public}d", result);
1006 return result;
1007 }
1008 PARCEL_READ_HELPER(reply, StringVector, &distributedComponents);
1009 return ERR_NONE;
1010 }
1011
StopRemoteExtensionAbility(const OHOS::AAFwk::Want & want,int32_t callerUid,uint32_t accessToken,int32_t extensionType)1012 int32_t DistributedSchedProxy::StopRemoteExtensionAbility(
1013 const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType)
1014 {
1015 sptr<IRemoteObject> remote = Remote();
1016 if (remote == nullptr) {
1017 HILOGE("StopRemoteExtensionAbility remote service null");
1018 return ERR_NULL_OBJECT;
1019 }
1020 MessageParcel data;
1021 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1022 HILOGE("StopRemoteExtensionAbility WriteInterfaceToken failed");
1023 return ERR_FLATTEN_OBJECT;
1024 }
1025 PARCEL_WRITE_HELPER(data, Parcelable, &want);
1026 PARCEL_WRITE_HELPER(data, Int32, callerUid);
1027 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
1028 PARCEL_WRITE_HELPER(data, Int32, extensionType);
1029 MessageParcel reply;
1030 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_REMOTE_EXTERNSION_ABILITY),
1031 data, reply);
1032 }
1033
StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want & want,const CallerInfo & callerInfo,const AccountInfo & accountInfo,int32_t extensionType)1034 int32_t DistributedSchedProxy::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
1035 const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType)
1036 {
1037 sptr<IRemoteObject> remote = Remote();
1038 if (remote == nullptr) {
1039 HILOGE("StopExtensionAbilityFromRemote remote service null");
1040 return ERR_NULL_OBJECT;
1041 }
1042 MessageParcel data;
1043 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1044 HILOGE("StopExtensionAbilityFromRemote WriteInterfaceToken failed");
1045 return ERR_FLATTEN_OBJECT;
1046 }
1047 DistributedWant dstbWant(want);
1048 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
1049 PARCEL_WRITE_HELPER(data, Int32, extensionType);
1050 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
1051 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
1052 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
1053 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
1054 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
1055 nlohmann::json extraInfoJson;
1056 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
1057 std::string extraInfo = extraInfoJson.dump();
1058 PARCEL_WRITE_HELPER(data, String, extraInfo);
1059 MessageParcel reply;
1060 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
1061 (IDSchedInterfaceCode::STOP_EXTERNSION_ABILITY_FROM_REMOTE), data, reply);
1062 }
1063 } // namespace DistributedSchedule
1064 } // namespace OHOS
1065
1066