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