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