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)412 int32_t DistributedSchedProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
413 {
414 HILOGI("called");
415 sptr<IRemoteObject> remote = Remote();
416 if (remote == nullptr) {
417 HILOGE("remote system ability is null");
418 return ERR_NULL_OBJECT;
419 }
420
421 MessageParcel data;
422 MessageParcel reply;
423 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
424 return ERR_FLATTEN_OBJECT;
425 }
426 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
427 PARCEL_WRITE_HELPER(data, Bool, fixConflict);
428 PARCEL_WRITE_HELPER(data, Int64, tag);
429 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS), data, reply);
430 }
431
StartSyncMissionsFromRemote(const CallerInfo & callerInfo,std::vector<DstbMissionInfo> & missionInfos)432 int32_t DistributedSchedProxy::StartSyncMissionsFromRemote(const CallerInfo& callerInfo,
433 std::vector<DstbMissionInfo>& missionInfos)
434 {
435 HILOGI("called");
436 sptr<IRemoteObject> remote = Remote();
437 if (remote == nullptr) {
438 HILOGE("remote service is null");
439 return ERR_NULL_OBJECT;
440 }
441 MessageParcel data;
442 MessageParcel reply;
443 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
444 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
445 return ERR_FLATTEN_OBJECT;
446 }
447 if (!CallerInfoMarshalling(callerInfo, data)) {
448 return ERR_FLATTEN_OBJECT;
449 }
450 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS_FROM_REMOTE),
451 data, reply, option);
452 if (error != ERR_NONE) {
453 HILOGW("fail, error: %{public}d", error);
454 return error;
455 }
456 int32_t version = reply.ReadInt32();
457 HILOGD("version : %{public}d", version);
458 return DstbMissionInfo::ReadDstbMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
459 }
460
StopSyncRemoteMissions(const std::string & devId)461 int32_t DistributedSchedProxy::StopSyncRemoteMissions(const std::string& devId)
462 {
463 HILOGI("called");
464 sptr<IRemoteObject> remote = Remote();
465 if (remote == nullptr) {
466 HILOGE("remote system ability is null");
467 return ERR_NULL_OBJECT;
468 }
469 MessageParcel data;
470 MessageParcel reply;
471 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
472 return ERR_FLATTEN_OBJECT;
473 }
474 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
475 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS), data, reply);
476 }
477
StopSyncMissionsFromRemote(const CallerInfo & callerInfo)478 int32_t DistributedSchedProxy::StopSyncMissionsFromRemote(const CallerInfo& callerInfo)
479 {
480 HILOGI("called");
481 sptr<IRemoteObject> remote = Remote();
482 if (remote == nullptr) {
483 HILOGE("remote service is null");
484 return ERR_NULL_OBJECT;
485 }
486 MessageParcel data;
487 MessageParcel reply;
488 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
489 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
490 return ERR_FLATTEN_OBJECT;
491 }
492 if (!CallerInfoMarshalling(callerInfo, data)) {
493 return ERR_FLATTEN_OBJECT;
494 }
495 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS_FROM_REMOTE),
496 data, reply, option);
497 if (error != ERR_NONE) {
498 HILOGW("sendRequest fail, error: %{public}d", error);
499 return error;
500 }
501 return reply.ReadInt32();
502 }
503
RegisterMissionListener(const std::u16string & devId,const sptr<IRemoteObject> & obj)504 int32_t DistributedSchedProxy::RegisterMissionListener(const std::u16string& devId,
505 const sptr<IRemoteObject>& obj)
506 {
507 HILOGI("RegisterMissionListener called");
508 sptr<IRemoteObject> remote = Remote();
509 if (remote == nullptr) {
510 HILOGE("remote system ability is null");
511 return ERR_NULL_OBJECT;
512 }
513 MessageParcel data;
514 MessageParcel reply;
515 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
516 return ERR_FLATTEN_OBJECT;
517 }
518 PARCEL_WRITE_HELPER(data, String16, devId);
519 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
520 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_MISSION_LISTENER),
521 data, reply);
522 }
523
RegisterDSchedEventListener(const DSchedEventType & type,const sptr<IRemoteObject> & obj)524 int32_t DistributedSchedProxy::RegisterDSchedEventListener(const DSchedEventType& type,
525 const sptr<IRemoteObject>& obj)
526 {
527 HILOGI("RegisterDSchedEventListener called");
528 sptr<IRemoteObject> remote = Remote();
529 if (remote == nullptr) {
530 HILOGE("remote system ability is null");
531 return ERR_NULL_OBJECT;
532 }
533 MessageParcel data;
534 MessageParcel reply;
535 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
536 return ERR_FLATTEN_OBJECT;
537 }
538 PARCEL_WRITE_HELPER(data, Uint8, type);
539 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
540 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_DSCHED_EVENT_LISTENER),
541 data, reply);
542 }
543
UnRegisterDSchedEventListener(const DSchedEventType & type,const sptr<IRemoteObject> & obj)544 int32_t DistributedSchedProxy::UnRegisterDSchedEventListener(const DSchedEventType& type,
545 const sptr<IRemoteObject>& obj)
546 {
547 HILOGI("UnRegisterDSchedEventListener called");
548 sptr<IRemoteObject> remote = Remote();
549 if (remote == nullptr) {
550 HILOGE("remote system ability is null");
551 return ERR_NULL_OBJECT;
552 }
553 MessageParcel data;
554 MessageParcel reply;
555 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
556 return ERR_FLATTEN_OBJECT;
557 }
558 PARCEL_WRITE_HELPER(data, Uint8, type);
559 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
560 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_DSCHED_EVENT_LISTENER),
561 data, reply);
562 }
563
RegisterOnListener(const std::string & type,const sptr<IRemoteObject> & obj)564 int32_t DistributedSchedProxy::RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj)
565 {
566 HILOGI("RegisterOnListener called");
567 sptr<IRemoteObject> remote = Remote();
568 if (remote == nullptr) {
569 HILOGE("remote system ability is null");
570 return ERR_NULL_OBJECT;
571 }
572 MessageParcel data;
573 MessageParcel reply;
574 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
575 return ERR_FLATTEN_OBJECT;
576 }
577 PARCEL_WRITE_HELPER(data, String, type);
578 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
579 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_ON_LISTENER),
580 data, reply);
581 }
582
RegisterOffListener(const std::string & type,const sptr<IRemoteObject> & obj)583 int32_t DistributedSchedProxy::RegisterOffListener(const std::string& type, const sptr<IRemoteObject>& obj)
584 {
585 HILOGI("RegisterOffListener called");
586 sptr<IRemoteObject> remote = Remote();
587 if (remote == nullptr) {
588 HILOGE("remote system ability is null");
589 return ERR_NULL_OBJECT;
590 }
591 MessageParcel data;
592 MessageParcel reply;
593 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
594 return ERR_FLATTEN_OBJECT;
595 }
596 PARCEL_WRITE_HELPER(data, String, type);
597 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
598 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_OFF_LISTENER),
599 data, reply);
600 }
601
UnRegisterMissionListener(const std::u16string & devId,const sptr<IRemoteObject> & obj)602 int32_t DistributedSchedProxy::UnRegisterMissionListener(const std::u16string& devId,
603 const sptr<IRemoteObject>& obj)
604 {
605 HILOGI("UnRegisterMissionListener called");
606 sptr<IRemoteObject> remote = Remote();
607 if (remote == nullptr) {
608 HILOGE("remote system ability is null");
609 return ERR_NULL_OBJECT;
610 }
611 MessageParcel data;
612 MessageParcel reply;
613 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
614 return ERR_FLATTEN_OBJECT;
615 }
616 PARCEL_WRITE_HELPER(data, String16, devId);
617 PARCEL_WRITE_HELPER(data, RemoteObject, obj);
618 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_MISSION_LISTENER),
619 data, reply);
620 }
621
GetMissionInfos(const std::string & deviceId,int32_t numMissions,std::vector<AAFwk::MissionInfo> & missionInfos)622 int32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int32_t numMissions,
623 std::vector<AAFwk::MissionInfo>& missionInfos)
624 {
625 HILOGI("called");
626 sptr<IRemoteObject> remote = Remote();
627 if (remote == nullptr) {
628 HILOGE("remote system ability is null");
629 return ERR_NULL_OBJECT;
630 }
631
632 MessageParcel data;
633 MessageParcel reply;
634 MessageOption option;
635 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
636 return ERR_FLATTEN_OBJECT;
637 }
638 PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(deviceId));
639 PARCEL_WRITE_HELPER(data, Int32, numMissions);
640 int32_t ret = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_MISSION_INFOS), data, reply,
641 option);
642 if (ret != ERR_NONE) {
643 HILOGW("sendRequest fail, error: %{public}d", ret);
644 return ret;
645 }
646 return MissionInfoConverter::ReadMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
647 }
648
NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo> & missionInfos,const CallerInfo & callerInfo)649 int32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo>& missionInfos,
650 const CallerInfo& callerInfo)
651 {
652 HILOGI("NotifyMissionsChangedFromRemote is called");
653 sptr<IRemoteObject> remote = Remote();
654 if (remote == nullptr) {
655 HILOGE("NotifyMissionsChangedFromRemote remote service is null");
656 return ERR_NULL_OBJECT;
657 }
658
659 MessageParcel data;
660 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
661 return ERR_FLATTEN_OBJECT;
662 }
663 PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
664 if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(data, missionInfos)) {
665 return ERR_FLATTEN_OBJECT;
666 }
667 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
668 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
669 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
670 PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
671 MessageParcel reply;
672 MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
673 int32_t error = remote->SendRequest(static_cast<uint32_t>
674 (IDSchedInterfaceCode::NOTIFY_MISSIONS_CHANGED_FROM_REMOTE), data, reply, option);
675 if (error != ERR_NONE) {
676 HILOGE("%{public}s transact failed, error: %{public}d", __func__, error);
677 return error;
678 }
679 int32_t result = reply.ReadInt32();
680 HILOGD("%{public}s get result from server data = %{public}d", __func__, result);
681 return result;
682 }
683
GetRemoteMissionSnapshotInfo(const std::string & networkId,int32_t missionId,std::unique_ptr<MissionSnapshot> & missionSnapshot)684 int32_t DistributedSchedProxy::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
685 std::unique_ptr<MissionSnapshot>& missionSnapshot)
686 {
687 if (networkId.empty()) {
688 HILOGE("networkId is null");
689 return ERR_NULL_OBJECT;
690 }
691 if (missionId < 0) {
692 HILOGE("missionId is invalid");
693 return INVALID_PARAMETERS_ERR;
694 }
695 sptr<IRemoteObject> remote = Remote();
696 if (remote == nullptr) {
697 HILOGE("remote is null");
698 return ERR_NULL_OBJECT;
699 }
700 MessageParcel data;
701 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
702 return ERR_FLATTEN_OBJECT;
703 }
704 PARCEL_WRITE_HELPER(data, String, networkId);
705 PARCEL_WRITE_HELPER(data, Int32, missionId);
706 MessageParcel reply;
707 MessageOption option;
708 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_REMOTE_MISSION_SNAPSHOT_INFO),
709 data, reply, option);
710 if (error != ERR_NONE) {
711 HILOGE("transact failed, error: %{public}d", error);
712 return error;
713 }
714 std::unique_ptr<MissionSnapshot> missionSnapshotPtr(reply.ReadParcelable<MissionSnapshot>());
715 missionSnapshot = std::move(missionSnapshotPtr);
716 return ERR_NONE;
717 }
718
SetMissionContinueState(int32_t missionId,const AAFwk::ContinueState & state)719 int32_t DistributedSchedProxy::SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state)
720 {
721 HILOGD("DistributedSchedProxy::SetMissionContinueState called");
722 sptr<IRemoteObject> remote = Remote();
723 if (remote == nullptr) {
724 HILOGE("SetMissionContinueState remote is null");
725 return ERR_NULL_OBJECT;
726 }
727
728 MessageParcel data;
729 MessageParcel reply;
730 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
731 return ERR_FLATTEN_OBJECT;
732 }
733 PARCEL_WRITE_HELPER(data, Int32, missionId);
734 PARCEL_WRITE_HELPER(data, Int32, static_cast<int32_t>(state));
735 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::SET_MISSION_CONTINUE_STATE),
736 data, reply);
737 }
738 #endif
739
CallerInfoMarshalling(const CallerInfo & callerInfo,MessageParcel & data)740 bool DistributedSchedProxy::CallerInfoMarshalling(const CallerInfo& callerInfo, MessageParcel& data)
741 {
742 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.uid, false);
743 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.pid, false);
744 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.callerType, false);
745 PARCEL_WRITE_HELPER_RET(data, String, callerInfo.sourceDeviceId, false);
746 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.duid, false);
747 PARCEL_WRITE_HELPER_RET(data, String, callerInfo.callerAppId, false);
748 PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.dmsVersion, false);
749 return true;
750 }
751
StartRemoteAbilityByCall(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,int32_t callerUid,int32_t callerPid,uint32_t accessToken)752 int32_t DistributedSchedProxy::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want,
753 const sptr<IRemoteObject>& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken)
754 {
755 if (connect == nullptr) {
756 HILOGE("StartRemoteAbilityByCall connect is null");
757 return ERR_NULL_OBJECT;
758 }
759
760 sptr<IRemoteObject> remote = Remote();
761 if (remote == nullptr) {
762 HILOGE("StartRemoteAbilityByCall remote is null");
763 return ERR_NULL_OBJECT;
764 }
765 MessageParcel data;
766 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
767 return ERR_FLATTEN_OBJECT;
768 }
769 PARCEL_WRITE_HELPER(data, Parcelable, &want);
770 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
771 PARCEL_WRITE_HELPER(data, Int32, callerUid);
772 PARCEL_WRITE_HELPER(data, Int32, callerPid);
773 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
774 MessageParcel reply;
775 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY_BY_CALL),
776 data, reply);
777 }
778
ReleaseRemoteAbility(const sptr<IRemoteObject> & connect,const AppExecFwk::ElementName & element)779 int32_t DistributedSchedProxy::ReleaseRemoteAbility(const sptr<IRemoteObject>& connect,
780 const AppExecFwk::ElementName &element)
781 {
782 if (connect == nullptr) {
783 HILOGE("ReleaseRemoteAbility connect is null");
784 return ERR_NULL_OBJECT;
785 }
786
787 sptr<IRemoteObject> remote = Remote();
788 if (remote == nullptr) {
789 HILOGE("ReleaseRemoteAbility remote is null");
790 return ERR_NULL_OBJECT;
791 }
792 MessageParcel data;
793 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
794 return ERR_FLATTEN_OBJECT;
795 }
796 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
797 if (!data.WriteParcelable(&element)) {
798 HILOGE("ReleaseRemoteAbility write element error.");
799 return ERR_INVALID_VALUE;
800 }
801 MessageParcel reply;
802 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_REMOTE_ABILITY),
803 data, reply);
804 }
805
StartAbilityByCallFromRemote(const OHOS::AAFwk::Want & want,const sptr<IRemoteObject> & connect,const CallerInfo & callerInfo,const AccountInfo & accountInfo)806 int32_t DistributedSchedProxy::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want,
807 const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo)
808 {
809 if (connect == nullptr) {
810 HILOGE("StartAbilityByCallFromRemote connect is null");
811 return ERR_NULL_OBJECT;
812 }
813
814 sptr<IRemoteObject> remote = Remote();
815 if (remote == nullptr) {
816 HILOGE("StartAbilityByCallFromRemote remote is null");
817 return ERR_NULL_OBJECT;
818 }
819 MessageParcel data;
820 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
821 return ERR_FLATTEN_OBJECT;
822 }
823 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
824 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
825 PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
826 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
827 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
828 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
829 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
830 nlohmann::json extraInfoJson;
831 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
832 extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_ACCOUNT_ID] = accountInfo.activeAccountId;
833 extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_USERID_ID] = accountInfo.userId;
834 if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
835 extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
836 }
837 if (callerInfo.extraInfoJson.find(DMS_UID_SPEC_BUNDLE_NAME) != callerInfo.extraInfoJson.end()) {
838 extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME] = callerInfo.extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME];
839 }
840
841 std::string extraInfo = extraInfoJson.dump();
842 PARCEL_WRITE_HELPER(data, String, extraInfo);
843 DistributedWant dstbWant(want);
844 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
845 MessageParcel reply;
846 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
847 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
848 (IDSchedInterfaceCode::START_ABILITY_BY_CALL_FROM_REMOTE), data, reply);
849 }
850
ReleaseAbilityFromRemote(const sptr<IRemoteObject> & connect,const AppExecFwk::ElementName & element,const CallerInfo & callerInfo)851 int32_t DistributedSchedProxy::ReleaseAbilityFromRemote(const sptr<IRemoteObject>& connect,
852 const AppExecFwk::ElementName &element, const CallerInfo& callerInfo)
853 {
854 if (connect == nullptr) {
855 HILOGE("ReleaseAbilityFromRemote connect is null");
856 return ERR_NULL_OBJECT;
857 }
858
859 sptr<IRemoteObject> remote = Remote();
860 if (remote == nullptr) {
861 HILOGE("ReleaseAbilityFromRemote remote is null");
862 return ERR_NULL_OBJECT;
863 }
864 MessageParcel data;
865 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
866 return ERR_FLATTEN_OBJECT;
867 }
868 PARCEL_WRITE_HELPER(data, RemoteObject, connect);
869 if (!data.WriteParcelable(&element)) {
870 HILOGE("ReleaseAbilityFromRemote write element error.");
871 return ERR_INVALID_VALUE;
872 }
873 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
874 std::string extraInfo = "";
875 PARCEL_WRITE_HELPER(data, String, extraInfo);
876 MessageParcel reply;
877 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
878 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_ABILITY_FROM_REMOTE),
879 data, reply);
880 }
881
StartRemoteFreeInstall(const OHOS::AAFwk::Want & want,int32_t callerUid,int32_t requestCode,uint32_t accessToken,const sptr<IRemoteObject> & callback)882 int32_t DistributedSchedProxy::StartRemoteFreeInstall(const OHOS::AAFwk::Want& want,
883 int32_t callerUid, int32_t requestCode, uint32_t accessToken, const sptr<IRemoteObject>& callback)
884 {
885 HILOGD("called.");
886 if (callback == nullptr) {
887 HILOGE("ContinueMission callback null");
888 return ERR_NULL_OBJECT;
889 }
890
891 sptr<IRemoteObject> remote = Remote();
892 if (remote == nullptr) {
893 HILOGE("remote callback null");
894 return ERR_NULL_OBJECT;
895 }
896
897 MessageParcel data;
898 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
899 HILOGE("write interface token null");
900 return ERR_FLATTEN_OBJECT;
901 }
902
903 PARCEL_WRITE_HELPER(data, Parcelable, &want);
904 PARCEL_WRITE_HELPER(data, Int32, callerUid);
905 PARCEL_WRITE_HELPER(data, Int32, requestCode);
906 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
907 PARCEL_WRITE_HELPER(data, RemoteObject, callback);
908 MessageParcel reply;
909 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_FREE_INSTALL),
910 data, reply);
911 }
912
StartFreeInstallFromRemote(const FreeInstallInfo & info,int64_t taskId)913 int32_t DistributedSchedProxy::StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId)
914 {
915 HILOGD("called.");
916 sptr<IRemoteObject> remote = Remote();
917 if (remote == nullptr) {
918 HILOGE("remote is null");
919 return ERR_NULL_OBJECT;
920 }
921
922 MessageParcel data;
923 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
924 HILOGE("write interface token null");
925 return ERR_FLATTEN_OBJECT;
926 }
927
928 DistributedWant dstbWant(info.want);
929 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
930 PARCEL_WRITE_HELPER(data, Int32, info.callerInfo.uid);
931 PARCEL_WRITE_HELPER(data, String, info.callerInfo.sourceDeviceId);
932 PARCEL_WRITE_HELPER(data, Int32, info.accountInfo.accountType);
933 PARCEL_WRITE_HELPER(data, StringVector, info.accountInfo.groupIdList);
934 PARCEL_WRITE_HELPER(data, String, info.callerInfo.callerAppId);
935 PARCEL_WRITE_HELPER(data, Int64, taskId);
936 DistributedWant cmpWant;
937 cmpWant.SetParam(CMPT_PARAM_FREEINSTALL_BUNDLENAMES, info.callerInfo.bundleNames);
938 PARCEL_WRITE_HELPER(data, Parcelable, &cmpWant);
939 nlohmann::json extraInfoJson;
940 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = info.callerInfo.accessToken;
941 extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE] = info.requestCode;
942 if (info.callerInfo.extraInfoJson.find(DMS_VERSION_ID) != info.callerInfo.extraInfoJson.end()) {
943 extraInfoJson[DMS_VERSION_ID] = info.callerInfo.extraInfoJson[DMS_VERSION_ID];
944 }
945 std::string extraInfo = extraInfoJson.dump();
946 PARCEL_WRITE_HELPER(data, String, extraInfo);
947 MessageParcel reply;
948 HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
949 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_FREE_INSTALL_FROM_REMOTE),
950 data, reply);
951 }
952
NotifyCompleteFreeInstallFromRemote(int64_t taskId,int32_t resultCode)953 int32_t DistributedSchedProxy::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode)
954 {
955 HILOGD("called.");
956 sptr<IRemoteObject> remote = Remote();
957 if (remote == nullptr) {
958 HILOGE("remote is null");
959 return ERR_NULL_OBJECT;
960 }
961
962 MessageParcel data;
963 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
964 HILOGE("write interface token null");
965 return ERR_FLATTEN_OBJECT;
966 }
967
968 PARCEL_WRITE_HELPER(data, Int64, taskId);
969 PARCEL_WRITE_HELPER(data, Int32, resultCode);
970 MessageParcel reply;
971 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
972 (IDSchedInterfaceCode::NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE), data, reply);
973 }
974
975 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
StartRemoteShareForm(const std::string & remoteDeviceId,const AppExecFwk::FormShareInfo & formShareInfo)976 int32_t DistributedSchedProxy::StartRemoteShareForm(
977 const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
978 {
979 HILOGD("SHAREFORM:: func call");
980 if (remoteDeviceId.empty()) {
981 HILOGE("input params deviceId is nullptr.");
982 return INVALID_PARAMETERS_ERR;
983 }
984
985 auto remote = Remote();
986 if (remote == nullptr) {
987 HILOGE("fail to get dms remote.");
988 return DMSPROXY_SERVICE_ERR;
989 }
990
991 MessageParcel data;
992 MessageParcel reply;
993 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
994 HILOGE("WriteInterfaceToken failed");
995 return ERR_FLATTEN_OBJECT;
996 }
997
998 PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
999 PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
1000
1001 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM),
1002 data, reply);
1003 }
1004
StartShareFormFromRemote(const std::string & remoteDeviceId,const AppExecFwk::FormShareInfo & formShareInfo)1005 int32_t DistributedSchedProxy::StartShareFormFromRemote(
1006 const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
1007 {
1008 HILOGD("SHAREFORM:: func call");
1009 if (remoteDeviceId.empty()) {
1010 HILOGE("input params deviceId is nullptr.");
1011 return INVALID_PARAMETERS_ERR;
1012 }
1013
1014 auto remote = Remote();
1015 if (remote == nullptr) {
1016 HILOGE("fail to get dms remote.");
1017 return DMSPROXY_SERVICE_ERR;
1018 }
1019
1020 MessageParcel data;
1021 MessageParcel reply;
1022 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1023 HILOGE("WriteInterfaceToken failed");
1024 return ERR_FLATTEN_OBJECT;
1025 }
1026
1027 PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
1028 PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
1029
1030 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SHARE_FORM_FROM_REMOTE),
1031 data, reply);
1032 }
1033 #endif
1034
NotifyStateChangedFromRemote(int32_t abilityState,int32_t connectToken,const AppExecFwk::ElementName & element)1035 int32_t DistributedSchedProxy::NotifyStateChangedFromRemote(int32_t abilityState, int32_t connectToken,
1036 const AppExecFwk::ElementName& element)
1037 {
1038 sptr<IRemoteObject> remote = Remote();
1039 if (remote == nullptr) {
1040 HILOGE("NotifyStateChangedFromRemote remote service null");
1041 return ERR_NULL_OBJECT;
1042 }
1043 MessageParcel data;
1044 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1045 HILOGE("WriteInterfaceToken failed");
1046 return ERR_FLATTEN_OBJECT;
1047 }
1048 PARCEL_WRITE_HELPER(data, Int32, abilityState);
1049 PARCEL_WRITE_HELPER(data, Int32, connectToken);
1050 if (!data.WriteParcelable(&element)) {
1051 HILOGE("NotifyStateChangedFromRemote write element error.");
1052 return ERR_INVALID_VALUE;
1053 }
1054 MessageParcel reply;
1055 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_STATE_CHANGED_FROM_REMOTE),
1056 data, reply);
1057 }
1058
GetDistributedComponentList(std::vector<std::string> & distributedComponents)1059 int32_t DistributedSchedProxy::GetDistributedComponentList(std::vector<std::string>& distributedComponents)
1060 {
1061 sptr<IRemoteObject> remote = Remote();
1062 if (remote == nullptr) {
1063 HILOGE("GetDistributedComponentList remote is null");
1064 return ERR_NULL_OBJECT;
1065 }
1066 MessageParcel data;
1067 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1068 return ERR_FLATTEN_OBJECT;
1069 }
1070 MessageParcel reply;
1071 MessageOption option;
1072 int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_DISTRIBUTED_COMPONENT_LIST),
1073 data, reply, option);
1074 if (error != ERR_NONE) {
1075 HILOGE("GetDistributedComponentList SendRequest error = %{public}d", error);
1076 return error;
1077 }
1078 int32_t result = reply.ReadInt32();
1079 if (result != ERR_NONE) {
1080 HILOGE("GetDistributedComponentList result = %{public}d", result);
1081 return result;
1082 }
1083 PARCEL_READ_HELPER(reply, StringVector, &distributedComponents);
1084 return ERR_NONE;
1085 }
1086
StopRemoteExtensionAbility(const OHOS::AAFwk::Want & want,int32_t callerUid,uint32_t accessToken,int32_t extensionType)1087 int32_t DistributedSchedProxy::StopRemoteExtensionAbility(
1088 const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType)
1089 {
1090 sptr<IRemoteObject> remote = Remote();
1091 if (remote == nullptr) {
1092 HILOGE("StopRemoteExtensionAbility remote service null");
1093 return ERR_NULL_OBJECT;
1094 }
1095 MessageParcel data;
1096 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1097 HILOGE("StopRemoteExtensionAbility WriteInterfaceToken failed");
1098 return ERR_FLATTEN_OBJECT;
1099 }
1100 PARCEL_WRITE_HELPER(data, Parcelable, &want);
1101 PARCEL_WRITE_HELPER(data, Int32, callerUid);
1102 PARCEL_WRITE_HELPER(data, Uint32, accessToken);
1103 PARCEL_WRITE_HELPER(data, Int32, extensionType);
1104 MessageParcel reply;
1105 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_REMOTE_EXTERNSION_ABILITY),
1106 data, reply);
1107 }
1108
StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want & want,const CallerInfo & callerInfo,const AccountInfo & accountInfo,int32_t extensionType)1109 int32_t DistributedSchedProxy::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
1110 const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType)
1111 {
1112 sptr<IRemoteObject> remote = Remote();
1113 if (remote == nullptr) {
1114 HILOGE("StopExtensionAbilityFromRemote remote service null");
1115 return ERR_NULL_OBJECT;
1116 }
1117 MessageParcel data;
1118 if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1119 HILOGE("StopExtensionAbilityFromRemote WriteInterfaceToken failed");
1120 return ERR_FLATTEN_OBJECT;
1121 }
1122 DistributedWant dstbWant(want);
1123 PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
1124 PARCEL_WRITE_HELPER(data, Int32, extensionType);
1125 PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
1126 PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
1127 PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
1128 PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
1129 PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
1130 nlohmann::json extraInfoJson;
1131 extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
1132 extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_ACCOUNT_ID] = accountInfo.activeAccountId;
1133 extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_USERID_ID] = accountInfo.userId;
1134 std::string extraInfo = extraInfoJson.dump();
1135 PARCEL_WRITE_HELPER(data, String, extraInfo);
1136 MessageParcel reply;
1137 PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
1138 (IDSchedInterfaceCode::STOP_EXTERNSION_ABILITY_FROM_REMOTE), data, reply);
1139 }
1140 } // namespace DistributedSchedule
1141 } // namespace OHOS
1142
1143