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 msgReply;
61 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY),
62 data, msgReply);
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 msgReply;
152 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION), data, msgReply);
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 msgReply;
177 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME),
178 data, msgReply);
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 msgReply;
199 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_CONTINUATION),
200 data, msgReply);
201 }
202
NotifyCompleteContinuation(const std::u16string & devId,int32_t sessionId,bool isSuccess)203 void DistributedSchedProxy::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess)
204 {
205 sptr<IRemoteObject> remote = Remote();
206 if (remote == nullptr) {
207 HILOGE("NotifyCompleteContinuation remote service null");
208 return;
209 }
210 MessageParcel data;
211 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
212 return;
213 }
214 PARCEL_WRITE_HELPER_NORET(data, String16, devId);
215 PARCEL_WRITE_HELPER_NORET(data, Int32, sessionId);
216 PARCEL_WRITE_HELPER_NORET(data, Bool, isSuccess);
217 MessageParcel reply;
218 PARCEL_TRANSACT_SYNC_NORET(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_COMPLETE_CONTINUATION),
219 data, reply);
220 }
221
NotifyDSchedEventResultFromRemote(const std::string type,int32_t dSchedEventResult)222 int32_t DistributedSchedProxy::NotifyDSchedEventResultFromRemote(const std::string type, int32_t dSchedEventResult)
223 {
224 sptr<IRemoteObject> remote = Remote();
225 if (remote == nullptr) {
226 HILOGE("NotifyDSchedEventResultFromRemote remote service null");
227 return ERR_NULL_OBJECT;
228 }
229 MessageParcel data;
230 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
231 return ERR_FLATTEN_OBJECT;
232 }
233 PARCEL_WRITE_HELPER(data, String, type);
234 PARCEL_WRITE_HELPER(data, Int32, dSchedEventResult);
235 MessageParcel reply;
236 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
237 (IDSchedInterfaceCode::NOTIFY_DSCHED_EVENT_RESULT_FROM_REMOTE), data, reply);
238 }
239
NotifyContinuationResultFromRemote(int32_t sessionId,bool isSuccess)240 int32_t DistributedSchedProxy::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess)
241 {
242 sptr<IRemoteObject> remote = Remote();
243 if (remote == nullptr) {
244 HILOGE("NotifyContinuationResultFromRemote remote service null");
245 return ERR_NULL_OBJECT;
246 }
247 MessageParcel data;
248 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
249 return ERR_FLATTEN_OBJECT;
250 }
251 PARCEL_WRITE_HELPER(data, Int32, sessionId);
252 PARCEL_WRITE_HELPER(data, Bool, isSuccess);
253 MessageParcel reply;
254 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
255 (IDSchedInterfaceCode::NOTIFY_CONTINUATION_RESULT_FROM_REMOTE), data, reply);
256 }
257
ConnectRemoteAbility(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,int32_t callerUid,int32_t callerPid,uint32_t accessToken)258 int32_t DistributedSchedProxy::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
259 int32_t callerUid, int32_t callerPid, uint32_t accessToken)
260 {
261 if (connect == nullptr) {
262 HILOGE("ConnectRemoteAbility connect is null");
263 return ERR_NULL_OBJECT;
264 }
265
266 sptr<IRemoteObject> remote = Remote();
267 if (remote == nullptr) {
268 HILOGE("ConnectRemoteAbility remote is null");
269 return ERR_NULL_OBJECT;
270 }
271 MessageParcel data;
272 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
273 return ERR_FLATTEN_OBJECT;
274 }
275 PARCEL_WRITE_HELPER(data, Parcelable, &want);
276 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
277 PARCEL_WRITE_HELPER(data, Int32, callerUid);
278 PARCEL_WRITE_HELPER(data, Int32, callerPid);
279 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
280 MessageParcel reply;
281 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_REMOTE_ABILITY),
282 data, reply);
283 }
284
DisconnectRemoteAbility(const sptr<IRemoteObject> & connect,int32_t callerUid,uint32_t accessToken)285 int32_t DistributedSchedProxy::DisconnectRemoteAbility(const sptr<IRemoteObject>& connect, int32_t callerUid,
286 uint32_t accessToken)
287 {
288 if (connect == nullptr) {
289 HILOGE("DisconnectRemoteAbility connect is null");
290 return ERR_NULL_OBJECT;
291 }
292
293 sptr<IRemoteObject> remote = Remote();
294 if (remote == nullptr) {
295 HILOGE("DisconnectRemoteAbility remote is null");
296 return ERR_NULL_OBJECT;
297 }
298 MessageParcel data;
299 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
300 return ERR_FLATTEN_OBJECT;
301 }
302 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
303 PARCEL_WRITE_HELPER(data, Int32, callerUid);
304 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
305 MessageParcel reply;
306 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_REMOTE_ABILITY),
307 data, reply);
308 }
309
ConnectAbilityFromRemote(const OHOS::AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,const sptr<IRemoteObject> & connect,const CallerInfo & callerInfo,const AccountInfo & accountInfo)310 int32_t DistributedSchedProxy::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want,
311 const AppExecFwk::AbilityInfo& abilityInfo, const sptr<IRemoteObject>& connect,
312 const CallerInfo& callerInfo, const AccountInfo& accountInfo)
313 {
314 if (connect == nullptr) {
315 HILOGE("ConnectAbilityFromRemote connect is null");
316 return ERR_NULL_OBJECT;
317 }
318
319 sptr<IRemoteObject> remote = Remote();
320 if (remote == nullptr) {
321 HILOGE("ConnectAbilityFromRemote remote is null");
322 return ERR_NULL_OBJECT;
323 }
324 MessageParcel data;
325 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
326 return ERR_FLATTEN_OBJECT;
327 }
328 DistributedWant dstbWant(want);
329 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
330 AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
331 abilityInfo.ConvertToCompatiableAbilityInfo(compatibleAbilityInfo);
332 PARCEL_WRITE_HELPER(data, Parcelable, &compatibleAbilityInfo);
333 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
334 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
335 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
336 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
337 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
338 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
339 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
340 nlohmann::json extraInfoJson;
341 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
342 if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
343 extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
344 }
345 std::string extraInfo = extraInfoJson.dump();
346 PARCEL_WRITE_HELPER(data, String, extraInfo);
347 MessageParcel reply;
348 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
349 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_ABILITY_FROM_REMOTE),
350 data, reply);
351 }
352
DisconnectAbilityFromRemote(const sptr<IRemoteObject> & connect,int32_t uid,const std::string & sourceDeviceId)353 int32_t DistributedSchedProxy::DisconnectAbilityFromRemote(const sptr<IRemoteObject>& connect,
354 int32_t uid, const std::string& sourceDeviceId)
355 {
356 if (connect == nullptr) {
357 HILOGE("DisconnectAbilityFromRemote connect is null");
358 return ERR_NULL_OBJECT;
359 }
360
361 sptr<IRemoteObject> remote = Remote();
362 if (remote == nullptr) {
363 HILOGE("DisconnectAbilityFromRemote remote is null");
364 return ERR_NULL_OBJECT;
365 }
366 MessageParcel data;
367 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
368 return ERR_FLATTEN_OBJECT;
369 }
370 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
371 PARCEL_WRITE_HELPER(data, Int32, uid);
372 PARCEL_WRITE_HELPER(data, String, sourceDeviceId);
373 MessageParcel reply;
374 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
375 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_ABILITY_FROM_REMOTE),
376 data, reply);
377 }
378
NotifyProcessDiedFromRemote(const CallerInfo & callerInfo)379 int32_t DistributedSchedProxy::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo)
380 {
381 HILOGD("DistributedSchedProxy::NotifyProcessDiedFromRemote called");
382 sptr<IRemoteObject> remote = Remote();
383 if (remote == nullptr) {
384 HILOGE("NotifyProcessDiedFromRemote remote is null");
385 return ERR_NULL_OBJECT;
386 }
387 MessageParcel data;
388 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
389 return ERR_FLATTEN_OBJECT;
390 }
391 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
392 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
393 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
394 MessageParcel reply;
395 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_PROCESS_DIED_FROM_REMOTE),
396 data, reply);
397 }
398
399 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)400 int32_t DistributedSchedProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
401 {
402 HILOGI("called");
403 sptr<IRemoteObject> remote = Remote();
404 if (remote == nullptr) {
405 HILOGE("remote system ability is null");
406 return ERR_NULL_OBJECT;
407 }
408
409 MessageParcel data;
410 MessageParcel reply;
411 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
412 return ERR_FLATTEN_OBJECT;
413 }
414 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
415 PARCEL_WRITE_HELPER(data, Bool, fixConflict);
416 PARCEL_WRITE_HELPER(data, Int64, tag);
417 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS), data, reply);
418 }
419
StartSyncMissionsFromRemote(const CallerInfo & callerInfo,std::vector<DstbMissionInfo> & missionInfos)420 int32_t DistributedSchedProxy::StartSyncMissionsFromRemote(const CallerInfo& callerInfo,
421 std::vector<DstbMissionInfo>& missionInfos)
422 {
423 HILOGI("called");
424 sptr<IRemoteObject> remote = Remote();
425 if (remote == nullptr) {
426 HILOGE("remote service is null");
427 return ERR_NULL_OBJECT;
428 }
429 MessageParcel data;
430 MessageParcel reply;
431 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
432 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
433 return ERR_FLATTEN_OBJECT;
434 }
435 if (!CallerInfoMarshalling(callerInfo, data)) {
436 return ERR_FLATTEN_OBJECT;
437 }
438 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS_FROM_REMOTE),
439 data, reply, option);
440 if (error != ERR_NONE) {
441 HILOGW("fail, error: %{public}d", error);
442 return error;
443 }
444 int32_t version = reply.ReadInt32();
445 HILOGD("version : %{public}d", version);
446 return DstbMissionInfo::ReadDstbMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
447 }
448
StopSyncRemoteMissions(const std::string & devId)449 int32_t DistributedSchedProxy::StopSyncRemoteMissions(const std::string& devId)
450 {
451 HILOGI("called");
452 sptr<IRemoteObject> remote = Remote();
453 if (remote == nullptr) {
454 HILOGE("remote system ability is null");
455 return ERR_NULL_OBJECT;
456 }
457 MessageParcel data;
458 MessageParcel reply;
459 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
460 return ERR_FLATTEN_OBJECT;
461 }
462 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
463 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS), data, reply);
464 }
465
StopSyncMissionsFromRemote(const CallerInfo & callerInfo)466 int32_t DistributedSchedProxy::StopSyncMissionsFromRemote(const CallerInfo& callerInfo)
467 {
468 HILOGI("called");
469 sptr<IRemoteObject> remote = Remote();
470 if (remote == nullptr) {
471 HILOGE("remote service is null");
472 return ERR_NULL_OBJECT;
473 }
474 MessageParcel data;
475 MessageParcel reply;
476 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
477 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
478 return ERR_FLATTEN_OBJECT;
479 }
480 if (!CallerInfoMarshalling(callerInfo, data)) {
481 return ERR_FLATTEN_OBJECT;
482 }
483 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS_FROM_REMOTE),
484 data, reply, option);
485 if (error != ERR_NONE) {
486 HILOGW("sendRequest fail, error: %{public}d", error);
487 return error;
488 }
489 return reply.ReadInt32();
490 }
491
RegisterMissionListener(const std::u16string & devId,const sptr<IRemoteObject> & obj)492 int32_t DistributedSchedProxy::RegisterMissionListener(const std::u16string& devId,
493 const sptr<IRemoteObject>& obj)
494 {
495 HILOGI("RegisterMissionListener called");
496 sptr<IRemoteObject> remote = Remote();
497 if (remote == nullptr) {
498 HILOGE("remote system ability is null");
499 return ERR_NULL_OBJECT;
500 }
501 MessageParcel data;
502 MessageParcel reply;
503 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
504 return ERR_FLATTEN_OBJECT;
505 }
506 PARCEL_WRITE_HELPER(data, String16, devId);
507 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
508 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_MISSION_LISTENER),
509 data, reply);
510 }
511
RegisterDSchedEventListener(const std::string & type,const sptr<IRemoteObject> & obj)512 int32_t DistributedSchedProxy::RegisterDSchedEventListener(const std::string& type,
513 const sptr<IRemoteObject>& obj)
514 {
515 HILOGI("RegisterDSchedEventListener called");
516 sptr<IRemoteObject> remote = Remote();
517 if (remote == nullptr) {
518 HILOGE("remote system ability is null");
519 return ERR_NULL_OBJECT;
520 }
521 MessageParcel data;
522 MessageParcel reply;
523 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
524 return ERR_FLATTEN_OBJECT;
525 }
526 PARCEL_WRITE_HELPER(data, String, type);
527 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
528 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_DSCHED_EVENT_LISTENER),
529 data, reply);
530 }
531
RegisterOnListener(const std::string & type,const sptr<IRemoteObject> & obj)532 int32_t DistributedSchedProxy::RegisterOnListener(const std::string& type,
533 const sptr<IRemoteObject>& obj)
534 {
535 HILOGI("RegisterOnListener called");
536 sptr<IRemoteObject> remote = Remote();
537 if (remote == nullptr) {
538 HILOGE("remote system ability is null");
539 return ERR_NULL_OBJECT;
540 }
541 MessageParcel data;
542 MessageParcel reply;
543 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
544 return ERR_FLATTEN_OBJECT;
545 }
546 PARCEL_WRITE_HELPER(data, String, type);
547 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
548 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_ON_LISTENER),
549 data, reply);
550 }
551
RegisterOffListener(const std::string & type,const sptr<IRemoteObject> & obj)552 int32_t DistributedSchedProxy::RegisterOffListener(const std::string& type,
553 const sptr<IRemoteObject>& obj)
554 {
555 HILOGI("RegisterOffListener called");
556 sptr<IRemoteObject> remote = Remote();
557 if (remote == nullptr) {
558 HILOGE("remote system ability is null");
559 return ERR_NULL_OBJECT;
560 }
561 MessageParcel data;
562 MessageParcel reply;
563 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
564 return ERR_FLATTEN_OBJECT;
565 }
566 PARCEL_WRITE_HELPER(data, String, type);
567 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
568 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_OFF_LISTENER),
569 data, reply);
570 }
571
UnRegisterMissionListener(const std::u16string & devId,const sptr<IRemoteObject> & obj)572 int32_t DistributedSchedProxy::UnRegisterMissionListener(const std::u16string& devId,
573 const sptr<IRemoteObject>& obj)
574 {
575 HILOGI("UnRegisterMissionListener called");
576 sptr<IRemoteObject> remote = Remote();
577 if (remote == nullptr) {
578 HILOGE("remote system ability is null");
579 return ERR_NULL_OBJECT;
580 }
581 MessageParcel data;
582 MessageParcel reply;
583 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
584 return ERR_FLATTEN_OBJECT;
585 }
586 PARCEL_WRITE_HELPER(data, String16, devId);
587 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
588 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_MISSION_LISTENER),
589 data, reply);
590 }
591
GetMissionInfos(const std::string & deviceId,int32_t numMissions,std::vector<AAFwk::MissionInfo> & missionInfos)592 int32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int32_t numMissions,
593 std::vector<AAFwk::MissionInfo>& missionInfos)
594 {
595 HILOGI("called");
596 sptr<IRemoteObject> remote = Remote();
597 if (remote == nullptr) {
598 HILOGE("remote system ability is null");
599 return ERR_NULL_OBJECT;
600 }
601
602 MessageParcel data;
603 MessageParcel reply;
604 MessageOption option;
605 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
606 return ERR_FLATTEN_OBJECT;
607 }
608 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(deviceId));
609 PARCEL_WRITE_HELPER(data, Int32, numMissions);
610 int32_t ret = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_MISSION_INFOS), data, reply,
611 option);
612 if (ret != ERR_NONE) {
613 HILOGW("sendRequest fail, error: %{public}d", ret);
614 return ret;
615 }
616 return MissionInfoConverter::ReadMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
617 }
618
NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo> & missionInfos,const CallerInfo & callerInfo)619 int32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo>& missionInfos,
620 const CallerInfo& callerInfo)
621 {
622 HILOGI("NotifyMissionsChangedFromRemote is called");
623 sptr<IRemoteObject> remote = Remote();
624 if (remote == nullptr) {
625 HILOGE("NotifyMissionsChangedFromRemote remote service is null");
626 return ERR_NULL_OBJECT;
627 }
628
629 MessageParcel data;
630 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
631 return ERR_FLATTEN_OBJECT;
632 }
633 PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
634 if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(data, missionInfos)) {
635 return ERR_FLATTEN_OBJECT;
636 }
637 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
638 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
639 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
640 PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
641 MessageParcel reply;
642 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
643 int32_t error = remote->SendRequest(static_cast<uint32_t>
644 (IDSchedInterfaceCode::NOTIFY_MISSIONS_CHANGED_FROM_REMOTE), data, reply, option);
645 if (error != ERR_NONE) {
646 HILOGE("%{public}s transact failed, error: %{public}d", __func__, error);
647 return error;
648 }
649 int32_t result = reply.ReadInt32();
650 HILOGD("%{public}s get result from server data = %{public}d", __func__, result);
651 return result;
652 }
653
GetRemoteMissionSnapshotInfo(const std::string & networkId,int32_t missionId,std::unique_ptr<MissionSnapshot> & missionSnapshot)654 int32_t DistributedSchedProxy::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
655 std::unique_ptr<MissionSnapshot>& missionSnapshot)
656 {
657 if (networkId.empty()) {
658 HILOGE("networkId is null");
659 return ERR_NULL_OBJECT;
660 }
661 if (missionId < 0) {
662 HILOGE("missionId is invalid");
663 return INVALID_PARAMETERS_ERR;
664 }
665 sptr<IRemoteObject> remote = Remote();
666 if (remote == nullptr) {
667 HILOGE("remote is null");
668 return ERR_NULL_OBJECT;
669 }
670 MessageParcel data;
671 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
672 return ERR_FLATTEN_OBJECT;
673 }
674 PARCEL_WRITE_HELPER(data, String, networkId);
675 PARCEL_WRITE_HELPER(data, Int32, missionId);
676 MessageParcel reply;
677 MessageOption option;
678 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_REMOTE_MISSION_SNAPSHOT_INFO),
679 data, reply, option);
680 if (error != ERR_NONE) {
681 HILOGE("transact failed, error: %{public}d", error);
682 return error;
683 }
684 std::unique_ptr<MissionSnapshot> missionSnapshotPtr(reply.ReadParcelable<MissionSnapshot>());
685 missionSnapshot = std::move(missionSnapshotPtr);
686 return ERR_NONE;
687 }
688
SetMissionContinueState(int32_t missionId,const AAFwk::ContinueState & state)689 int32_t DistributedSchedProxy::SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state)
690 {
691 HILOGD("DistributedSchedProxy::SetMissionContinueState called");
692 sptr<IRemoteObject> remote = Remote();
693 if (remote == nullptr) {
694 HILOGE("SetMissionContinueState remote is null");
695 return ERR_NULL_OBJECT;
696 }
697
698 MessageParcel data;
699 MessageParcel reply;
700 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
701 return ERR_FLATTEN_OBJECT;
702 }
703 PARCEL_WRITE_HELPER(data, Int32, missionId);
704 PARCEL_WRITE_HELPER(data, Int32, static_cast<int32_t>(state));
705 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::SET_MISSION_CONTINUE_STATE),
706 data, reply);
707 }
708 #endif
709
CallerInfoMarshalling(const CallerInfo & callerInfo,MessageParcel & data)710 bool DistributedSchedProxy::CallerInfoMarshalling(const CallerInfo& callerInfo, MessageParcel& data)
711 {
712 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.uid, false);
713 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.pid, false);
714 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.callerType, false);
715 PARCEL_WRITE_HELPER_RET(data, String, callerInfo.sourceDeviceId, false);
716 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.duid, false);
717 PARCEL_WRITE_HELPER_RET(data, String, callerInfo.callerAppId, false);
718 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.dmsVersion, false);
719 return true;
720 }
721
StartRemoteAbilityByCall(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,int32_t callerUid,int32_t callerPid,uint32_t accessToken)722 int32_t DistributedSchedProxy::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want,
723 const sptr<IRemoteObject>& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken)
724 {
725 if (connect == nullptr) {
726 HILOGE("StartRemoteAbilityByCall connect is null");
727 return ERR_NULL_OBJECT;
728 }
729
730 sptr<IRemoteObject> remote = Remote();
731 if (remote == nullptr) {
732 HILOGE("StartRemoteAbilityByCall remote is null");
733 return ERR_NULL_OBJECT;
734 }
735 MessageParcel data;
736 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
737 return ERR_FLATTEN_OBJECT;
738 }
739 PARCEL_WRITE_HELPER(data, Parcelable, &want);
740 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
741 PARCEL_WRITE_HELPER(data, Int32, callerUid);
742 PARCEL_WRITE_HELPER(data, Int32, callerPid);
743 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
744 MessageParcel reply;
745 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY_BY_CALL),
746 data, reply);
747 }
748
ReleaseRemoteAbility(const sptr<IRemoteObject> & connect,const AppExecFwk::ElementName & element)749 int32_t DistributedSchedProxy::ReleaseRemoteAbility(const sptr<IRemoteObject>& connect,
750 const AppExecFwk::ElementName &element)
751 {
752 if (connect == nullptr) {
753 HILOGE("ReleaseRemoteAbility connect is null");
754 return ERR_NULL_OBJECT;
755 }
756
757 sptr<IRemoteObject> remote = Remote();
758 if (remote == nullptr) {
759 HILOGE("ReleaseRemoteAbility remote is null");
760 return ERR_NULL_OBJECT;
761 }
762 MessageParcel data;
763 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
764 return ERR_FLATTEN_OBJECT;
765 }
766 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
767 if (!data.WriteParcelable(&element)) {
768 HILOGE("ReleaseRemoteAbility write element error.");
769 return ERR_INVALID_VALUE;
770 }
771 MessageParcel reply;
772 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_REMOTE_ABILITY),
773 data, reply);
774 }
775
StartAbilityByCallFromRemote(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,const CallerInfo & callerInfo,const AccountInfo & accountInfo)776 int32_t DistributedSchedProxy::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want,
777 const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo)
778 {
779 if (connect == nullptr) {
780 HILOGE("StartAbilityByCallFromRemote connect is null");
781 return ERR_NULL_OBJECT;
782 }
783
784 sptr<IRemoteObject> remote = Remote();
785 if (remote == nullptr) {
786 HILOGE("StartAbilityByCallFromRemote 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 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
795 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
796 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
797 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
798 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
799 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
800 nlohmann::json extraInfoJson;
801 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
802 if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
803 extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
804 }
805 std::string extraInfo = extraInfoJson.dump();
806 PARCEL_WRITE_HELPER(data, String, extraInfo);
807 DistributedWant dstbWant(want);
808 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
809 MessageParcel reply;
810 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
811 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
812 (IDSchedInterfaceCode::START_ABILITY_BY_CALL_FROM_REMOTE), data, reply);
813 }
814
ReleaseAbilityFromRemote(const sptr<IRemoteObject> & connect,const AppExecFwk::ElementName & element,const CallerInfo & callerInfo)815 int32_t DistributedSchedProxy::ReleaseAbilityFromRemote(const sptr<IRemoteObject>& connect,
816 const AppExecFwk::ElementName &element, const CallerInfo& callerInfo)
817 {
818 if (connect == nullptr) {
819 HILOGE("ReleaseAbilityFromRemote connect is null");
820 return ERR_NULL_OBJECT;
821 }
822
823 sptr<IRemoteObject> remote = Remote();
824 if (remote == nullptr) {
825 HILOGE("ReleaseAbilityFromRemote remote is null");
826 return ERR_NULL_OBJECT;
827 }
828 MessageParcel data;
829 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
830 return ERR_FLATTEN_OBJECT;
831 }
832 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
833 if (!data.WriteParcelable(&element)) {
834 HILOGE("ReleaseAbilityFromRemote write element error.");
835 return ERR_INVALID_VALUE;
836 }
837 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
838 std::string extraInfo = "";
839 PARCEL_WRITE_HELPER(data, String, extraInfo);
840 MessageParcel reply;
841 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
842 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_ABILITY_FROM_REMOTE),
843 data, reply);
844 }
845
StartRemoteFreeInstall(const OHOS::AAFwk::Want & want,int32_t callerUid,int32_t requestCode,uint32_t accessToken,const sptr<IRemoteObject> & callback)846 int32_t DistributedSchedProxy::StartRemoteFreeInstall(const OHOS::AAFwk::Want& want,
847 int32_t callerUid, int32_t requestCode, uint32_t accessToken, const sptr<IRemoteObject>& callback)
848 {
849 HILOGD("called.");
850 if (callback == nullptr) {
851 HILOGE("ContinueMission callback null");
852 return ERR_NULL_OBJECT;
853 }
854
855 sptr<IRemoteObject> remote = Remote();
856 if (remote == nullptr) {
857 HILOGE("remote callback null");
858 return ERR_NULL_OBJECT;
859 }
860
861 MessageParcel data;
862 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
863 HILOGE("write interface token null");
864 return ERR_FLATTEN_OBJECT;
865 }
866
867 PARCEL_WRITE_HELPER(data, Parcelable, &want);
868 PARCEL_WRITE_HELPER(data, Int32, callerUid);
869 PARCEL_WRITE_HELPER(data, Int32, requestCode);
870 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
871 PARCEL_WRITE_HELPER(data, RemoteObject, callback);
872 MessageParcel reply;
873 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_FREE_INSTALL),
874 data, reply);
875 }
876
StartFreeInstallFromRemote(const FreeInstallInfo & info,int64_t taskId)877 int32_t DistributedSchedProxy::StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId)
878 {
879 HILOGD("called.");
880 sptr<IRemoteObject> remote = Remote();
881 if (remote == nullptr) {
882 HILOGE("remote is null");
883 return ERR_NULL_OBJECT;
884 }
885
886 MessageParcel data;
887 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
888 HILOGE("write interface token null");
889 return ERR_FLATTEN_OBJECT;
890 }
891
892 DistributedWant dstbWant(info.want);
893 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
894 PARCEL_WRITE_HELPER(data, Int32, info.callerInfo.uid);
895 PARCEL_WRITE_HELPER(data, String, info.callerInfo.sourceDeviceId);
896 PARCEL_WRITE_HELPER(data, Int32, info.accountInfo.accountType);
897 PARCEL_WRITE_HELPER(data, StringVector, info.accountInfo.groupIdList);
898 PARCEL_WRITE_HELPER(data, String, info.callerInfo.callerAppId);
899 PARCEL_WRITE_HELPER(data, Int64, taskId);
900 DistributedWant cmpWant;
901 cmpWant.SetParam(CMPT_PARAM_FREEINSTALL_BUNDLENAMES, info.callerInfo.bundleNames);
902 PARCEL_WRITE_HELPER(data, Parcelable, &cmpWant);
903 nlohmann::json extraInfoJson;
904 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = info.callerInfo.accessToken;
905 extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE] = info.requestCode;
906 if (info.callerInfo.extraInfoJson.find(DMS_VERSION_ID) != info.callerInfo.extraInfoJson.end()) {
907 extraInfoJson[DMS_VERSION_ID] = info.callerInfo.extraInfoJson[DMS_VERSION_ID];
908 }
909 std::string extraInfo = extraInfoJson.dump();
910 PARCEL_WRITE_HELPER(data, String, extraInfo);
911 MessageParcel reply;
912 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
913 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_FREE_INSTALL_FROM_REMOTE),
914 data, reply);
915 }
916
NotifyCompleteFreeInstallFromRemote(int64_t taskId,int32_t resultCode)917 int32_t DistributedSchedProxy::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode)
918 {
919 HILOGD("called.");
920 sptr<IRemoteObject> remote = Remote();
921 if (remote == nullptr) {
922 HILOGE("remote is null");
923 return ERR_NULL_OBJECT;
924 }
925
926 MessageParcel data;
927 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
928 HILOGE("write interface token null");
929 return ERR_FLATTEN_OBJECT;
930 }
931
932 PARCEL_WRITE_HELPER(data, Int64, taskId);
933 PARCEL_WRITE_HELPER(data, Int32, resultCode);
934 MessageParcel reply;
935 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
936 (IDSchedInterfaceCode::NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE), data, reply);
937 }
938
939 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
StartRemoteShareForm(const std::string & remoteDeviceId,const AppExecFwk::FormShareInfo & formShareInfo)940 int32_t DistributedSchedProxy::StartRemoteShareForm(
941 const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
942 {
943 HILOGD("SHAREFORM:: func call");
944 if (remoteDeviceId.empty()) {
945 HILOGE("input params deviceId is nullptr.");
946 return INVALID_PARAMETERS_ERR;
947 }
948
949 auto remote = Remote();
950 if (remote == nullptr) {
951 HILOGE("fail to get dms remote.");
952 return DMSPROXY_SERVICE_ERR;
953 }
954
955 MessageParcel data;
956 MessageParcel reply;
957 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
958 HILOGE("WriteInterfaceToken failed");
959 return ERR_FLATTEN_OBJECT;
960 }
961
962 PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
963 PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
964
965 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM),
966 data, reply);
967 }
968
StartShareFormFromRemote(const std::string & remoteDeviceId,const AppExecFwk::FormShareInfo & formShareInfo)969 int32_t DistributedSchedProxy::StartShareFormFromRemote(
970 const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
971 {
972 HILOGD("SHAREFORM:: func call");
973 if (remoteDeviceId.empty()) {
974 HILOGE("input params deviceId is nullptr.");
975 return INVALID_PARAMETERS_ERR;
976 }
977
978 auto remote = Remote();
979 if (remote == nullptr) {
980 HILOGE("fail to get dms remote.");
981 return DMSPROXY_SERVICE_ERR;
982 }
983
984 MessageParcel data;
985 MessageParcel reply;
986 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
987 HILOGE("WriteInterfaceToken failed");
988 return ERR_FLATTEN_OBJECT;
989 }
990
991 PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
992 PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
993
994 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SHARE_FORM_FROM_REMOTE),
995 data, reply);
996 }
997 #endif
998
NotifyStateChangedFromRemote(int32_t abilityState,int32_t connectToken,const AppExecFwk::ElementName & element)999 int32_t DistributedSchedProxy::NotifyStateChangedFromRemote(int32_t abilityState, int32_t connectToken,
1000 const AppExecFwk::ElementName& element)
1001 {
1002 sptr<IRemoteObject> remote = Remote();
1003 if (remote == nullptr) {
1004 HILOGE("NotifyStateChangedFromRemote remote service null");
1005 return ERR_NULL_OBJECT;
1006 }
1007 MessageParcel data;
1008 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1009 HILOGE("WriteInterfaceToken failed");
1010 return ERR_FLATTEN_OBJECT;
1011 }
1012 PARCEL_WRITE_HELPER(data, Int32, abilityState);
1013 PARCEL_WRITE_HELPER(data, Int32, connectToken);
1014 if (!data.WriteParcelable(&element)) {
1015 HILOGE("NotifyStateChangedFromRemote write element error.");
1016 return ERR_INVALID_VALUE;
1017 }
1018 MessageParcel reply;
1019 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_STATE_CHANGED_FROM_REMOTE),
1020 data, reply);
1021 }
1022
GetDistributedComponentList(std::vector<std::string> & distributedComponents)1023 int32_t DistributedSchedProxy::GetDistributedComponentList(std::vector<std::string>& distributedComponents)
1024 {
1025 sptr<IRemoteObject> remote = Remote();
1026 if (remote == nullptr) {
1027 HILOGE("GetDistributedComponentList remote is null");
1028 return ERR_NULL_OBJECT;
1029 }
1030 MessageParcel data;
1031 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1032 return ERR_FLATTEN_OBJECT;
1033 }
1034 MessageParcel reply;
1035 MessageOption option;
1036 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_DISTRIBUTED_COMPONENT_LIST),
1037 data, reply, option);
1038 if (error != ERR_NONE) {
1039 HILOGE("GetDistributedComponentList SendRequest error = %{public}d", error);
1040 return error;
1041 }
1042 int32_t result = reply.ReadInt32();
1043 if (result != ERR_NONE) {
1044 HILOGE("GetDistributedComponentList result = %{public}d", result);
1045 return result;
1046 }
1047 PARCEL_READ_HELPER(reply, StringVector, &distributedComponents);
1048 return ERR_NONE;
1049 }
1050
StopRemoteExtensionAbility(const OHOS::AAFwk::Want & want,int32_t callerUid,uint32_t accessToken,int32_t extensionType)1051 int32_t DistributedSchedProxy::StopRemoteExtensionAbility(
1052 const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType)
1053 {
1054 sptr<IRemoteObject> remote = Remote();
1055 if (remote == nullptr) {
1056 HILOGE("StopRemoteExtensionAbility remote service null");
1057 return ERR_NULL_OBJECT;
1058 }
1059 MessageParcel data;
1060 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1061 HILOGE("StopRemoteExtensionAbility WriteInterfaceToken failed");
1062 return ERR_FLATTEN_OBJECT;
1063 }
1064 PARCEL_WRITE_HELPER(data, Parcelable, &want);
1065 PARCEL_WRITE_HELPER(data, Int32, callerUid);
1066 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
1067 PARCEL_WRITE_HELPER(data, Int32, extensionType);
1068 MessageParcel reply;
1069 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_REMOTE_EXTERNSION_ABILITY),
1070 data, reply);
1071 }
1072
StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want & want,const CallerInfo & callerInfo,const AccountInfo & accountInfo,int32_t extensionType)1073 int32_t DistributedSchedProxy::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
1074 const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType)
1075 {
1076 sptr<IRemoteObject> remote = Remote();
1077 if (remote == nullptr) {
1078 HILOGE("StopExtensionAbilityFromRemote remote service null");
1079 return ERR_NULL_OBJECT;
1080 }
1081 MessageParcel data;
1082 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1083 HILOGE("StopExtensionAbilityFromRemote WriteInterfaceToken failed");
1084 return ERR_FLATTEN_OBJECT;
1085 }
1086 DistributedWant dstbWant(want);
1087 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
1088 PARCEL_WRITE_HELPER(data, Int32, extensionType);
1089 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
1090 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
1091 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
1092 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
1093 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
1094 nlohmann::json extraInfoJson;
1095 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
1096 std::string extraInfo = extraInfoJson.dump();
1097 PARCEL_WRITE_HELPER(data, String, extraInfo);
1098 MessageParcel reply;
1099 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
1100 (IDSchedInterfaceCode::STOP_EXTERNSION_ABILITY_FROM_REMOTE), data, reply);
1101 }
1102 } // namespace DistributedSchedule
1103 } // namespace OHOS
1104
1105