1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci
16686862fbSopenharmony_ci#include "distributed_sched_proxy.h"
17686862fbSopenharmony_ci#include "dfx/dms_hitrace_constants.h"
18686862fbSopenharmony_ci#include "distributed_want.h"
19686862fbSopenharmony_ci#include "dms_constant.h"
20686862fbSopenharmony_ci#include "dtbschedmgr_log.h"
21686862fbSopenharmony_ci#include "ipc_types.h"
22686862fbSopenharmony_ci#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
23686862fbSopenharmony_ci#include "mission/mission_info_converter.h"
24686862fbSopenharmony_ci#include "pixel_map.h"
25686862fbSopenharmony_ci#endif
26686862fbSopenharmony_ci#include "parcel_helper.h"
27686862fbSopenharmony_ci#include "string_ex.h"
28686862fbSopenharmony_ci
29686862fbSopenharmony_cinamespace OHOS {
30686862fbSopenharmony_cinamespace DistributedSchedule {
31686862fbSopenharmony_ciusing namespace std;
32686862fbSopenharmony_ciusing namespace AAFwk;
33686862fbSopenharmony_ci
34686862fbSopenharmony_cinamespace {
35686862fbSopenharmony_ciconst std::string TAG = "DistributedSchedProxy";
36686862fbSopenharmony_ciconst std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
37686862fbSopenharmony_ciconst std::string EXTRO_INFO_JSON_KEY_ACCESS_TOKEN = "accessTokenID";
38686862fbSopenharmony_ciconst std::string EXTRO_INFO_JSON_KEY_REQUEST_CODE = "requestCode";
39686862fbSopenharmony_ciconst std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
40686862fbSopenharmony_ciconst std::string DMS_VERSION_ID = "dmsVersion";
41686862fbSopenharmony_ciconst std::string DMS_UID_SPEC_BUNDLE_NAME = "dmsCallerUidBundleName";
42686862fbSopenharmony_ci#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
43686862fbSopenharmony_ciconstexpr int32_t WAIT_TIME = 15;
44686862fbSopenharmony_ci#endif
45686862fbSopenharmony_ci}
46686862fbSopenharmony_ci
47686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartRemoteAbility(const OHOS::AAFwk::Want& want,
48686862fbSopenharmony_ci    int32_t callerUid, int32_t requestCode, uint32_t accessToken)
49686862fbSopenharmony_ci{
50686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
51686862fbSopenharmony_ci    if (remote == nullptr) {
52686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
53686862fbSopenharmony_ci    }
54686862fbSopenharmony_ci    MessageParcel data;
55686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
56686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
57686862fbSopenharmony_ci    }
58686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &want);
59686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerUid);
60686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, requestCode);
61686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint32, accessToken);
62686862fbSopenharmony_ci    MessageParcel msgReply;
63686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY),
64686862fbSopenharmony_ci        data, msgReply);
65686862fbSopenharmony_ci}
66686862fbSopenharmony_ci
67686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
68686862fbSopenharmony_ci    const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode,
69686862fbSopenharmony_ci    const CallerInfo& callerInfo, const AccountInfo& accountInfo)
70686862fbSopenharmony_ci{
71686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
72686862fbSopenharmony_ci    if (remote == nullptr) {
73686862fbSopenharmony_ci        HILOGE("StartAbilityFromRemote remote service null");
74686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
75686862fbSopenharmony_ci    }
76686862fbSopenharmony_ci    MessageParcel data;
77686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
78686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
79686862fbSopenharmony_ci    }
80686862fbSopenharmony_ci    DistributedWant dstbWant(want);
81686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
82686862fbSopenharmony_ci    AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
83686862fbSopenharmony_ci    abilityInfo.ConvertToCompatiableAbilityInfo(compatibleAbilityInfo);
84686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &compatibleAbilityInfo);
85686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, requestCode);
86686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
87686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
88686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
89686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
90686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
91686862fbSopenharmony_ci    nlohmann::json extraInfoJson;
92686862fbSopenharmony_ci    extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
93686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_ACCOUNT_ID] = accountInfo.activeAccountId;
94686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_USERID_ID] = accountInfo.userId;
95686862fbSopenharmony_ci    if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
96686862fbSopenharmony_ci        extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
97686862fbSopenharmony_ci    }
98686862fbSopenharmony_ci    std::string extraInfo = extraInfoJson.dump();
99686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, extraInfo);
100686862fbSopenharmony_ci    MessageParcel reply;
101686862fbSopenharmony_ci    HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
102686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_ABILITY_FROM_REMOTE),
103686862fbSopenharmony_ci        data, reply);
104686862fbSopenharmony_ci}
105686862fbSopenharmony_ci
106686862fbSopenharmony_ciint32_t DistributedSchedProxy::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode,
107686862fbSopenharmony_ci    const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode)
108686862fbSopenharmony_ci{
109686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
110686862fbSopenharmony_ci    if (remote == nullptr) {
111686862fbSopenharmony_ci        HILOGE("SendResultFromRemote remote service null");
112686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
113686862fbSopenharmony_ci    }
114686862fbSopenharmony_ci    MessageParcel data;
115686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
116686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
117686862fbSopenharmony_ci    }
118686862fbSopenharmony_ci    DistributedWant dstbWant(want);
119686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
120686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, requestCode);
121686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
122686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
123686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
124686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
125686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
126686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, resultCode);
127686862fbSopenharmony_ci    nlohmann::json extraInfoJson;
128686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_ACCOUNT_ID] = accountInfo.activeAccountId;
129686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_USERID_ID] = accountInfo.userId;
130686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_CALLER_INFO_EX] = callerInfo.extraInfoJson.dump();
131686862fbSopenharmony_ci    std::string extraInfo = extraInfoJson.dump();
132686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, extraInfo);
133686862fbSopenharmony_ci    MessageParcel reply;
134686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::SEND_RESULT_FROM_REMOTE),
135686862fbSopenharmony_ci        data, reply);
136686862fbSopenharmony_ci}
137686862fbSopenharmony_ci
138686862fbSopenharmony_ciint32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
139686862fbSopenharmony_ci    int32_t missionId, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
140686862fbSopenharmony_ci{
141686862fbSopenharmony_ci    if (callback == nullptr) {
142686862fbSopenharmony_ci        HILOGE("ContinueMission callback null");
143686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
144686862fbSopenharmony_ci    }
145686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
146686862fbSopenharmony_ci    if (remote == nullptr) {
147686862fbSopenharmony_ci        HILOGE("ContinueMission remote service null");
148686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
149686862fbSopenharmony_ci    }
150686862fbSopenharmony_ci    MessageParcel data;
151686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
152686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
153686862fbSopenharmony_ci    }
154686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, srcDeviceId);
155686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, dstDeviceId);
156686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, missionId);
157686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, callback);
158686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &wantParams);
159686862fbSopenharmony_ci    MessageParcel msgReply;
160686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION), data, msgReply);
161686862fbSopenharmony_ci}
162686862fbSopenharmony_ci
163686862fbSopenharmony_ciint32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
164686862fbSopenharmony_ci    const std::string& bundleName, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
165686862fbSopenharmony_ci{
166686862fbSopenharmony_ci    if (callback == nullptr) {
167686862fbSopenharmony_ci        HILOGE("ContinueMission callback null");
168686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
169686862fbSopenharmony_ci    }
170686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
171686862fbSopenharmony_ci    if (remote == nullptr) {
172686862fbSopenharmony_ci        HILOGE("ContinueMission remote service null");
173686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
174686862fbSopenharmony_ci    }
175686862fbSopenharmony_ci    MessageParcel data;
176686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
177686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
178686862fbSopenharmony_ci    }
179686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, srcDeviceId);
180686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, dstDeviceId);
181686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, bundleName);
182686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, callback);
183686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &wantParams);
184686862fbSopenharmony_ci    MessageParcel msgReply;
185686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME),
186686862fbSopenharmony_ci        data, msgReply);
187686862fbSopenharmony_ci}
188686862fbSopenharmony_ci
189686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
190686862fbSopenharmony_ci    int32_t status, uint32_t accessToken)
191686862fbSopenharmony_ci{
192686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
193686862fbSopenharmony_ci    if (remote == nullptr) {
194686862fbSopenharmony_ci        HILOGE("StartContinuation remote service null");
195686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
196686862fbSopenharmony_ci    }
197686862fbSopenharmony_ci    MessageParcel data;
198686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
199686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
200686862fbSopenharmony_ci    }
201686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &want);
202686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, missionId);
203686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerUid);
204686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, status);
205686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint32, accessToken);
206686862fbSopenharmony_ci    MessageParcel msgReply;
207686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_CONTINUATION),
208686862fbSopenharmony_ci        data, msgReply);
209686862fbSopenharmony_ci}
210686862fbSopenharmony_ci
211686862fbSopenharmony_civoid DistributedSchedProxy::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess)
212686862fbSopenharmony_ci{
213686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
214686862fbSopenharmony_ci    if (remote == nullptr) {
215686862fbSopenharmony_ci        HILOGE("NotifyCompleteContinuation remote service null");
216686862fbSopenharmony_ci        return;
217686862fbSopenharmony_ci    }
218686862fbSopenharmony_ci    MessageParcel data;
219686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
220686862fbSopenharmony_ci        return;
221686862fbSopenharmony_ci    }
222686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, String16, devId);
223686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, Int32, sessionId);
224686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_NORET(data, Bool, isSuccess);
225686862fbSopenharmony_ci    MessageParcel reply;
226686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_NORET(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_COMPLETE_CONTINUATION),
227686862fbSopenharmony_ci        data, reply);
228686862fbSopenharmony_ci}
229686862fbSopenharmony_ci
230686862fbSopenharmony_ciint32_t DistributedSchedProxy::NotifyDSchedEventResultFromRemote(const std::string type, int32_t dSchedEventResult)
231686862fbSopenharmony_ci{
232686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
233686862fbSopenharmony_ci    if (remote == nullptr) {
234686862fbSopenharmony_ci        HILOGE("NotifyDSchedEventResultFromRemote remote service null");
235686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
236686862fbSopenharmony_ci    }
237686862fbSopenharmony_ci    MessageParcel data;
238686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
239686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
240686862fbSopenharmony_ci    }
241686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, type);
242686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, dSchedEventResult);
243686862fbSopenharmony_ci    MessageParcel reply;
244686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
245686862fbSopenharmony_ci    (IDSchedInterfaceCode::NOTIFY_DSCHED_EVENT_RESULT_FROM_REMOTE), data, reply);
246686862fbSopenharmony_ci}
247686862fbSopenharmony_ci
248686862fbSopenharmony_ciint32_t DistributedSchedProxy::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess,
249686862fbSopenharmony_ci    const std::string dstInfo)
250686862fbSopenharmony_ci{
251686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
252686862fbSopenharmony_ci    if (remote == nullptr) {
253686862fbSopenharmony_ci        HILOGE("NotifyContinuationResultFromRemote remote service null");
254686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
255686862fbSopenharmony_ci    }
256686862fbSopenharmony_ci    MessageParcel data;
257686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
258686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
259686862fbSopenharmony_ci    }
260686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, sessionId);
261686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Bool, isSuccess);
262686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, dstInfo);
263686862fbSopenharmony_ci    MessageParcel reply;
264686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
265686862fbSopenharmony_ci    (IDSchedInterfaceCode::NOTIFY_CONTINUATION_RESULT_FROM_REMOTE), data, reply);
266686862fbSopenharmony_ci}
267686862fbSopenharmony_ci
268686862fbSopenharmony_ciint32_t DistributedSchedProxy::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
269686862fbSopenharmony_ci    int32_t callerUid, int32_t callerPid, uint32_t accessToken)
270686862fbSopenharmony_ci{
271686862fbSopenharmony_ci    if (connect == nullptr) {
272686862fbSopenharmony_ci        HILOGE("ConnectRemoteAbility connect is null");
273686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
274686862fbSopenharmony_ci    }
275686862fbSopenharmony_ci
276686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
277686862fbSopenharmony_ci    if (remote == nullptr) {
278686862fbSopenharmony_ci        HILOGE("ConnectRemoteAbility remote is null");
279686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
280686862fbSopenharmony_ci    }
281686862fbSopenharmony_ci    MessageParcel data;
282686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
283686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
284686862fbSopenharmony_ci    }
285686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &want);
286686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
287686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerUid);
288686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerPid);
289686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint32, accessToken);
290686862fbSopenharmony_ci    MessageParcel reply;
291686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_REMOTE_ABILITY),
292686862fbSopenharmony_ci        data, reply);
293686862fbSopenharmony_ci}
294686862fbSopenharmony_ci
295686862fbSopenharmony_ciint32_t DistributedSchedProxy::DisconnectRemoteAbility(const sptr<IRemoteObject>& connect, int32_t callerUid,
296686862fbSopenharmony_ci    uint32_t accessToken)
297686862fbSopenharmony_ci{
298686862fbSopenharmony_ci    if (connect == nullptr) {
299686862fbSopenharmony_ci        HILOGE("DisconnectRemoteAbility connect is null");
300686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
301686862fbSopenharmony_ci    }
302686862fbSopenharmony_ci
303686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
304686862fbSopenharmony_ci    if (remote == nullptr) {
305686862fbSopenharmony_ci        HILOGE("DisconnectRemoteAbility remote is null");
306686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
307686862fbSopenharmony_ci    }
308686862fbSopenharmony_ci    MessageParcel data;
309686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
310686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
311686862fbSopenharmony_ci    }
312686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
313686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerUid);
314686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint32, accessToken);
315686862fbSopenharmony_ci    MessageParcel reply;
316686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_REMOTE_ABILITY),
317686862fbSopenharmony_ci        data, reply);
318686862fbSopenharmony_ci}
319686862fbSopenharmony_ci
320686862fbSopenharmony_ciint32_t DistributedSchedProxy::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want,
321686862fbSopenharmony_ci    const AppExecFwk::AbilityInfo& abilityInfo, const sptr<IRemoteObject>& connect,
322686862fbSopenharmony_ci    const CallerInfo& callerInfo, const AccountInfo& accountInfo)
323686862fbSopenharmony_ci{
324686862fbSopenharmony_ci    if (connect == nullptr) {
325686862fbSopenharmony_ci        HILOGE("ConnectAbilityFromRemote connect is null");
326686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
327686862fbSopenharmony_ci    }
328686862fbSopenharmony_ci
329686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
330686862fbSopenharmony_ci    if (remote == nullptr) {
331686862fbSopenharmony_ci        HILOGE("ConnectAbilityFromRemote remote is null");
332686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
333686862fbSopenharmony_ci    }
334686862fbSopenharmony_ci    MessageParcel data;
335686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
336686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
337686862fbSopenharmony_ci    }
338686862fbSopenharmony_ci    DistributedWant dstbWant(want);
339686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
340686862fbSopenharmony_ci    AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo;
341686862fbSopenharmony_ci    abilityInfo.ConvertToCompatiableAbilityInfo(compatibleAbilityInfo);
342686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &compatibleAbilityInfo);
343686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
344686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
345686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
346686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
347686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
348686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
349686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
350686862fbSopenharmony_ci    nlohmann::json extraInfoJson;
351686862fbSopenharmony_ci    extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
352686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_ACCOUNT_ID] = accountInfo.activeAccountId;
353686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_USERID_ID] = accountInfo.userId;
354686862fbSopenharmony_ci    if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
355686862fbSopenharmony_ci        extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
356686862fbSopenharmony_ci    }
357686862fbSopenharmony_ci    std::string extraInfo = extraInfoJson.dump();
358686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, extraInfo);
359686862fbSopenharmony_ci    MessageParcel reply;
360686862fbSopenharmony_ci    HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
361686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONNECT_ABILITY_FROM_REMOTE),
362686862fbSopenharmony_ci        data, reply);
363686862fbSopenharmony_ci}
364686862fbSopenharmony_ci
365686862fbSopenharmony_ciint32_t DistributedSchedProxy::DisconnectAbilityFromRemote(const sptr<IRemoteObject>& connect,
366686862fbSopenharmony_ci    int32_t uid, const std::string& sourceDeviceId)
367686862fbSopenharmony_ci{
368686862fbSopenharmony_ci    if (connect == nullptr) {
369686862fbSopenharmony_ci        HILOGE("DisconnectAbilityFromRemote connect is null");
370686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
371686862fbSopenharmony_ci    }
372686862fbSopenharmony_ci
373686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
374686862fbSopenharmony_ci    if (remote == nullptr) {
375686862fbSopenharmony_ci        HILOGE("DisconnectAbilityFromRemote remote is null");
376686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
377686862fbSopenharmony_ci    }
378686862fbSopenharmony_ci    MessageParcel data;
379686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
380686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
381686862fbSopenharmony_ci    }
382686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
383686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, uid);
384686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, sourceDeviceId);
385686862fbSopenharmony_ci    MessageParcel reply;
386686862fbSopenharmony_ci    HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
387686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::DISCONNECT_ABILITY_FROM_REMOTE),
388686862fbSopenharmony_ci        data, reply);
389686862fbSopenharmony_ci}
390686862fbSopenharmony_ci
391686862fbSopenharmony_ciint32_t DistributedSchedProxy::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo)
392686862fbSopenharmony_ci{
393686862fbSopenharmony_ci    HILOGD("DistributedSchedProxy::NotifyProcessDiedFromRemote called");
394686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
395686862fbSopenharmony_ci    if (remote == nullptr) {
396686862fbSopenharmony_ci        HILOGE("NotifyProcessDiedFromRemote remote is null");
397686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
398686862fbSopenharmony_ci    }
399686862fbSopenharmony_ci    MessageParcel data;
400686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
401686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
402686862fbSopenharmony_ci    }
403686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
404686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
405686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
406686862fbSopenharmony_ci    MessageParcel reply;
407686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_PROCESS_DIED_FROM_REMOTE),
408686862fbSopenharmony_ci        data, reply);
409686862fbSopenharmony_ci}
410686862fbSopenharmony_ci
411686862fbSopenharmony_ci#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
412686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
413686862fbSopenharmony_ci{
414686862fbSopenharmony_ci    HILOGI("called");
415686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
416686862fbSopenharmony_ci    if (remote == nullptr) {
417686862fbSopenharmony_ci        HILOGE("remote system ability is null");
418686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
419686862fbSopenharmony_ci    }
420686862fbSopenharmony_ci
421686862fbSopenharmony_ci    MessageParcel data;
422686862fbSopenharmony_ci    MessageParcel reply;
423686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
424686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
425686862fbSopenharmony_ci    }
426686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
427686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Bool, fixConflict);
428686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int64, tag);
429686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS), data, reply);
430686862fbSopenharmony_ci}
431686862fbSopenharmony_ci
432686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartSyncMissionsFromRemote(const CallerInfo& callerInfo,
433686862fbSopenharmony_ci    std::vector<DstbMissionInfo>& missionInfos)
434686862fbSopenharmony_ci{
435686862fbSopenharmony_ci    HILOGI("called");
436686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
437686862fbSopenharmony_ci    if (remote == nullptr) {
438686862fbSopenharmony_ci        HILOGE("remote service is null");
439686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
440686862fbSopenharmony_ci    }
441686862fbSopenharmony_ci    MessageParcel data;
442686862fbSopenharmony_ci    MessageParcel reply;
443686862fbSopenharmony_ci    MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
444686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
445686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
446686862fbSopenharmony_ci    }
447686862fbSopenharmony_ci    if (!CallerInfoMarshalling(callerInfo, data)) {
448686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
449686862fbSopenharmony_ci    }
450686862fbSopenharmony_ci    int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::START_SYNC_MISSIONS_FROM_REMOTE),
451686862fbSopenharmony_ci        data, reply, option);
452686862fbSopenharmony_ci    if (error != ERR_NONE) {
453686862fbSopenharmony_ci        HILOGW("fail, error: %{public}d", error);
454686862fbSopenharmony_ci        return error;
455686862fbSopenharmony_ci    }
456686862fbSopenharmony_ci    int32_t version = reply.ReadInt32();
457686862fbSopenharmony_ci    HILOGD("version : %{public}d", version);
458686862fbSopenharmony_ci    return DstbMissionInfo::ReadDstbMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
459686862fbSopenharmony_ci}
460686862fbSopenharmony_ci
461686862fbSopenharmony_ciint32_t DistributedSchedProxy::StopSyncRemoteMissions(const std::string& devId)
462686862fbSopenharmony_ci{
463686862fbSopenharmony_ci    HILOGI("called");
464686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
465686862fbSopenharmony_ci    if (remote == nullptr) {
466686862fbSopenharmony_ci        HILOGE("remote system ability is null");
467686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
468686862fbSopenharmony_ci    }
469686862fbSopenharmony_ci    MessageParcel data;
470686862fbSopenharmony_ci    MessageParcel reply;
471686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
472686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
473686862fbSopenharmony_ci    }
474686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(devId));
475686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS), data, reply);
476686862fbSopenharmony_ci}
477686862fbSopenharmony_ci
478686862fbSopenharmony_ciint32_t DistributedSchedProxy::StopSyncMissionsFromRemote(const CallerInfo& callerInfo)
479686862fbSopenharmony_ci{
480686862fbSopenharmony_ci    HILOGI("called");
481686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
482686862fbSopenharmony_ci    if (remote == nullptr) {
483686862fbSopenharmony_ci        HILOGE("remote service is null");
484686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
485686862fbSopenharmony_ci    }
486686862fbSopenharmony_ci    MessageParcel data;
487686862fbSopenharmony_ci    MessageParcel reply;
488686862fbSopenharmony_ci    MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
489686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
490686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
491686862fbSopenharmony_ci    }
492686862fbSopenharmony_ci    if (!CallerInfoMarshalling(callerInfo, data)) {
493686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
494686862fbSopenharmony_ci    }
495686862fbSopenharmony_ci    int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::STOP_SYNC_MISSIONS_FROM_REMOTE),
496686862fbSopenharmony_ci        data, reply, option);
497686862fbSopenharmony_ci    if (error != ERR_NONE) {
498686862fbSopenharmony_ci        HILOGW("sendRequest fail, error: %{public}d", error);
499686862fbSopenharmony_ci        return error;
500686862fbSopenharmony_ci    }
501686862fbSopenharmony_ci    return reply.ReadInt32();
502686862fbSopenharmony_ci}
503686862fbSopenharmony_ci
504686862fbSopenharmony_ciint32_t DistributedSchedProxy::RegisterMissionListener(const std::u16string& devId,
505686862fbSopenharmony_ci    const sptr<IRemoteObject>& obj)
506686862fbSopenharmony_ci{
507686862fbSopenharmony_ci    HILOGI("RegisterMissionListener called");
508686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
509686862fbSopenharmony_ci    if (remote == nullptr) {
510686862fbSopenharmony_ci        HILOGE("remote system ability is null");
511686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
512686862fbSopenharmony_ci    }
513686862fbSopenharmony_ci    MessageParcel data;
514686862fbSopenharmony_ci    MessageParcel reply;
515686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
516686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
517686862fbSopenharmony_ci    }
518686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String16, devId);
519686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, obj);
520686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_MISSION_LISTENER),
521686862fbSopenharmony_ci        data, reply);
522686862fbSopenharmony_ci}
523686862fbSopenharmony_ci
524686862fbSopenharmony_ciint32_t DistributedSchedProxy::RegisterDSchedEventListener(const DSchedEventType& type,
525686862fbSopenharmony_ci    const sptr<IRemoteObject>& obj)
526686862fbSopenharmony_ci{
527686862fbSopenharmony_ci    HILOGI("RegisterDSchedEventListener called");
528686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
529686862fbSopenharmony_ci    if (remote == nullptr) {
530686862fbSopenharmony_ci        HILOGE("remote system ability is null");
531686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
532686862fbSopenharmony_ci    }
533686862fbSopenharmony_ci    MessageParcel data;
534686862fbSopenharmony_ci    MessageParcel reply;
535686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
536686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
537686862fbSopenharmony_ci    }
538686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint8, type);
539686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, obj);
540686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_DSCHED_EVENT_LISTENER),
541686862fbSopenharmony_ci        data, reply);
542686862fbSopenharmony_ci}
543686862fbSopenharmony_ci
544686862fbSopenharmony_ciint32_t DistributedSchedProxy::UnRegisterDSchedEventListener(const DSchedEventType& type,
545686862fbSopenharmony_ci    const sptr<IRemoteObject>& obj)
546686862fbSopenharmony_ci{
547686862fbSopenharmony_ci    HILOGI("UnRegisterDSchedEventListener called");
548686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
549686862fbSopenharmony_ci    if (remote == nullptr) {
550686862fbSopenharmony_ci        HILOGE("remote system ability is null");
551686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
552686862fbSopenharmony_ci    }
553686862fbSopenharmony_ci    MessageParcel data;
554686862fbSopenharmony_ci    MessageParcel reply;
555686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
556686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
557686862fbSopenharmony_ci    }
558686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint8, type);
559686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, obj);
560686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_DSCHED_EVENT_LISTENER),
561686862fbSopenharmony_ci        data, reply);
562686862fbSopenharmony_ci}
563686862fbSopenharmony_ci
564686862fbSopenharmony_ciint32_t DistributedSchedProxy::RegisterOnListener(const std::string& type,
565686862fbSopenharmony_ci    const sptr<IRemoteObject>& obj, int32_t callingUid)
566686862fbSopenharmony_ci{
567686862fbSopenharmony_ci    HILOGI("RegisterOnListener called");
568686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
569686862fbSopenharmony_ci    if (remote == nullptr) {
570686862fbSopenharmony_ci        HILOGE("remote system ability is null");
571686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
572686862fbSopenharmony_ci    }
573686862fbSopenharmony_ci    MessageParcel data;
574686862fbSopenharmony_ci    MessageParcel reply;
575686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
576686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
577686862fbSopenharmony_ci    }
578686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, type);
579686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, obj);
580686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callingUid);
581686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_ON_LISTENER),
582686862fbSopenharmony_ci        data, reply);
583686862fbSopenharmony_ci}
584686862fbSopenharmony_ci
585686862fbSopenharmony_ciint32_t DistributedSchedProxy::RegisterOffListener(const std::string& type,
586686862fbSopenharmony_ci    const sptr<IRemoteObject>& obj, int32_t callingUid)
587686862fbSopenharmony_ci{
588686862fbSopenharmony_ci    HILOGI("RegisterOffListener called");
589686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
590686862fbSopenharmony_ci    if (remote == nullptr) {
591686862fbSopenharmony_ci        HILOGE("remote system ability is null");
592686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
593686862fbSopenharmony_ci    }
594686862fbSopenharmony_ci    MessageParcel data;
595686862fbSopenharmony_ci    MessageParcel reply;
596686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
597686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
598686862fbSopenharmony_ci    }
599686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, type);
600686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, obj);
601686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callingUid);
602686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::REGISTER_OFF_LISTENER),
603686862fbSopenharmony_ci        data, reply);
604686862fbSopenharmony_ci}
605686862fbSopenharmony_ci
606686862fbSopenharmony_ciint32_t DistributedSchedProxy::UnRegisterMissionListener(const std::u16string& devId,
607686862fbSopenharmony_ci    const sptr<IRemoteObject>& obj)
608686862fbSopenharmony_ci{
609686862fbSopenharmony_ci    HILOGI("UnRegisterMissionListener called");
610686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
611686862fbSopenharmony_ci    if (remote == nullptr) {
612686862fbSopenharmony_ci        HILOGE("remote system ability is null");
613686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
614686862fbSopenharmony_ci    }
615686862fbSopenharmony_ci    MessageParcel data;
616686862fbSopenharmony_ci    MessageParcel reply;
617686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
618686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
619686862fbSopenharmony_ci    }
620686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String16, devId);
621686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, obj);
622686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::UNREGISTER_MISSION_LISTENER),
623686862fbSopenharmony_ci        data, reply);
624686862fbSopenharmony_ci}
625686862fbSopenharmony_ci
626686862fbSopenharmony_ciint32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int32_t numMissions,
627686862fbSopenharmony_ci    std::vector<AAFwk::MissionInfo>& missionInfos)
628686862fbSopenharmony_ci{
629686862fbSopenharmony_ci    HILOGI("called");
630686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
631686862fbSopenharmony_ci    if (remote == nullptr) {
632686862fbSopenharmony_ci        HILOGE("remote system ability is null");
633686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
634686862fbSopenharmony_ci    }
635686862fbSopenharmony_ci
636686862fbSopenharmony_ci    MessageParcel data;
637686862fbSopenharmony_ci    MessageParcel reply;
638686862fbSopenharmony_ci    MessageOption option;
639686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
640686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
641686862fbSopenharmony_ci    }
642686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String16, Str8ToStr16(deviceId));
643686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, numMissions);
644686862fbSopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_MISSION_INFOS), data, reply,
645686862fbSopenharmony_ci        option);
646686862fbSopenharmony_ci    if (ret != ERR_NONE) {
647686862fbSopenharmony_ci        HILOGW("sendRequest fail, error: %{public}d", ret);
648686862fbSopenharmony_ci        return ret;
649686862fbSopenharmony_ci    }
650686862fbSopenharmony_ci    return MissionInfoConverter::ReadMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
651686862fbSopenharmony_ci}
652686862fbSopenharmony_ci
653686862fbSopenharmony_ciint32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo>& missionInfos,
654686862fbSopenharmony_ci    const CallerInfo& callerInfo)
655686862fbSopenharmony_ci{
656686862fbSopenharmony_ci    HILOGI("NotifyMissionsChangedFromRemote is called");
657686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
658686862fbSopenharmony_ci    if (remote == nullptr) {
659686862fbSopenharmony_ci        HILOGE("NotifyMissionsChangedFromRemote remote service is null");
660686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
661686862fbSopenharmony_ci    }
662686862fbSopenharmony_ci
663686862fbSopenharmony_ci    MessageParcel data;
664686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
665686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
666686862fbSopenharmony_ci    }
667686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
668686862fbSopenharmony_ci    if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(data, missionInfos)) {
669686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
670686862fbSopenharmony_ci    }
671686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
672686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
673686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
674686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
675686862fbSopenharmony_ci    MessageParcel reply;
676686862fbSopenharmony_ci    MessageOption option { MessageOption::TF_SYNC, WAIT_TIME };
677686862fbSopenharmony_ci    int32_t error = remote->SendRequest(static_cast<uint32_t>
678686862fbSopenharmony_ci        (IDSchedInterfaceCode::NOTIFY_MISSIONS_CHANGED_FROM_REMOTE), data, reply, option);
679686862fbSopenharmony_ci    if (error != ERR_NONE) {
680686862fbSopenharmony_ci        HILOGE("%{public}s transact failed, error: %{public}d", __func__, error);
681686862fbSopenharmony_ci        return error;
682686862fbSopenharmony_ci    }
683686862fbSopenharmony_ci    int32_t result = reply.ReadInt32();
684686862fbSopenharmony_ci    HILOGD("%{public}s get result from server data = %{public}d", __func__, result);
685686862fbSopenharmony_ci    return result;
686686862fbSopenharmony_ci}
687686862fbSopenharmony_ci
688686862fbSopenharmony_ciint32_t DistributedSchedProxy::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
689686862fbSopenharmony_ci    std::unique_ptr<MissionSnapshot>& missionSnapshot)
690686862fbSopenharmony_ci{
691686862fbSopenharmony_ci    if (networkId.empty()) {
692686862fbSopenharmony_ci        HILOGE("networkId is null");
693686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
694686862fbSopenharmony_ci    }
695686862fbSopenharmony_ci    if (missionId < 0) {
696686862fbSopenharmony_ci        HILOGE("missionId is invalid");
697686862fbSopenharmony_ci        return INVALID_PARAMETERS_ERR;
698686862fbSopenharmony_ci    }
699686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
700686862fbSopenharmony_ci    if (remote == nullptr) {
701686862fbSopenharmony_ci        HILOGE("remote is null");
702686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
703686862fbSopenharmony_ci    }
704686862fbSopenharmony_ci    MessageParcel data;
705686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
706686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
707686862fbSopenharmony_ci    }
708686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, networkId);
709686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, missionId);
710686862fbSopenharmony_ci    MessageParcel reply;
711686862fbSopenharmony_ci    MessageOption option;
712686862fbSopenharmony_ci    int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_REMOTE_MISSION_SNAPSHOT_INFO),
713686862fbSopenharmony_ci        data, reply, option);
714686862fbSopenharmony_ci    if (error != ERR_NONE) {
715686862fbSopenharmony_ci        HILOGE("transact failed, error: %{public}d", error);
716686862fbSopenharmony_ci        return error;
717686862fbSopenharmony_ci    }
718686862fbSopenharmony_ci    std::unique_ptr<MissionSnapshot> missionSnapshotPtr(reply.ReadParcelable<MissionSnapshot>());
719686862fbSopenharmony_ci    missionSnapshot = std::move(missionSnapshotPtr);
720686862fbSopenharmony_ci    return ERR_NONE;
721686862fbSopenharmony_ci}
722686862fbSopenharmony_ci
723686862fbSopenharmony_ciint32_t DistributedSchedProxy::SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state)
724686862fbSopenharmony_ci{
725686862fbSopenharmony_ci    HILOGD("DistributedSchedProxy::SetMissionContinueState called");
726686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
727686862fbSopenharmony_ci    if (remote == nullptr) {
728686862fbSopenharmony_ci        HILOGE("SetMissionContinueState remote is null");
729686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
730686862fbSopenharmony_ci    }
731686862fbSopenharmony_ci
732686862fbSopenharmony_ci    MessageParcel data;
733686862fbSopenharmony_ci    MessageParcel reply;
734686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
735686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
736686862fbSopenharmony_ci    }
737686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, missionId);
738686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, static_cast<int32_t>(state));
739686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::SET_MISSION_CONTINUE_STATE),
740686862fbSopenharmony_ci        data, reply);
741686862fbSopenharmony_ci}
742686862fbSopenharmony_ci#endif
743686862fbSopenharmony_ci
744686862fbSopenharmony_cibool DistributedSchedProxy::CallerInfoMarshalling(const CallerInfo& callerInfo, MessageParcel& data)
745686862fbSopenharmony_ci{
746686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.uid, false);
747686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.pid, false);
748686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.callerType, false);
749686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, callerInfo.sourceDeviceId, false);
750686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.duid, false);
751686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, String, callerInfo.callerAppId, false);
752686862fbSopenharmony_ci    PARCEL_WRITE_HELPER_RET(data, Int32, callerInfo.dmsVersion, false);
753686862fbSopenharmony_ci    return true;
754686862fbSopenharmony_ci}
755686862fbSopenharmony_ci
756686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want,
757686862fbSopenharmony_ci    const sptr<IRemoteObject>& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken)
758686862fbSopenharmony_ci{
759686862fbSopenharmony_ci    if (connect == nullptr) {
760686862fbSopenharmony_ci        HILOGE("StartRemoteAbilityByCall connect is null");
761686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
762686862fbSopenharmony_ci    }
763686862fbSopenharmony_ci
764686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
765686862fbSopenharmony_ci    if (remote == nullptr) {
766686862fbSopenharmony_ci        HILOGE("StartRemoteAbilityByCall remote is null");
767686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
768686862fbSopenharmony_ci    }
769686862fbSopenharmony_ci    MessageParcel data;
770686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
771686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
772686862fbSopenharmony_ci    }
773686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &want);
774686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
775686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerUid);
776686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerPid);
777686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint32, accessToken);
778686862fbSopenharmony_ci    MessageParcel reply;
779686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY_BY_CALL),
780686862fbSopenharmony_ci        data, reply);
781686862fbSopenharmony_ci}
782686862fbSopenharmony_ci
783686862fbSopenharmony_ciint32_t DistributedSchedProxy::ReleaseRemoteAbility(const sptr<IRemoteObject>& connect,
784686862fbSopenharmony_ci    const AppExecFwk::ElementName &element)
785686862fbSopenharmony_ci{
786686862fbSopenharmony_ci    if (connect == nullptr) {
787686862fbSopenharmony_ci        HILOGE("ReleaseRemoteAbility connect is null");
788686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
789686862fbSopenharmony_ci    }
790686862fbSopenharmony_ci
791686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
792686862fbSopenharmony_ci    if (remote == nullptr) {
793686862fbSopenharmony_ci        HILOGE("ReleaseRemoteAbility remote is null");
794686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
795686862fbSopenharmony_ci    }
796686862fbSopenharmony_ci    MessageParcel data;
797686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
798686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
799686862fbSopenharmony_ci    }
800686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
801686862fbSopenharmony_ci    if (!data.WriteParcelable(&element)) {
802686862fbSopenharmony_ci        HILOGE("ReleaseRemoteAbility write element error.");
803686862fbSopenharmony_ci        return ERR_INVALID_VALUE;
804686862fbSopenharmony_ci    }
805686862fbSopenharmony_ci    MessageParcel reply;
806686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_REMOTE_ABILITY),
807686862fbSopenharmony_ci        data, reply);
808686862fbSopenharmony_ci}
809686862fbSopenharmony_ci
810686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want,
811686862fbSopenharmony_ci    const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo)
812686862fbSopenharmony_ci{
813686862fbSopenharmony_ci    if (connect == nullptr) {
814686862fbSopenharmony_ci        HILOGE("StartAbilityByCallFromRemote connect is null");
815686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
816686862fbSopenharmony_ci    }
817686862fbSopenharmony_ci
818686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
819686862fbSopenharmony_ci    if (remote == nullptr) {
820686862fbSopenharmony_ci        HILOGE("StartAbilityByCallFromRemote remote is null");
821686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
822686862fbSopenharmony_ci    }
823686862fbSopenharmony_ci    MessageParcel data;
824686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
825686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
826686862fbSopenharmony_ci    }
827686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
828686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
829686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.pid);
830686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
831686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
832686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
833686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
834686862fbSopenharmony_ci    nlohmann::json extraInfoJson;
835686862fbSopenharmony_ci    extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
836686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_ACCOUNT_ID] = accountInfo.activeAccountId;
837686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_USERID_ID] = accountInfo.userId;
838686862fbSopenharmony_ci    if (callerInfo.extraInfoJson.find(DMS_VERSION_ID) != callerInfo.extraInfoJson.end()) {
839686862fbSopenharmony_ci        extraInfoJson[DMS_VERSION_ID] = callerInfo.extraInfoJson[DMS_VERSION_ID];
840686862fbSopenharmony_ci    }
841686862fbSopenharmony_ci    if (callerInfo.extraInfoJson.find(DMS_UID_SPEC_BUNDLE_NAME) != callerInfo.extraInfoJson.end()) {
842686862fbSopenharmony_ci        extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME] = callerInfo.extraInfoJson[DMS_UID_SPEC_BUNDLE_NAME];
843686862fbSopenharmony_ci    }
844686862fbSopenharmony_ci
845686862fbSopenharmony_ci    std::string extraInfo = extraInfoJson.dump();
846686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, extraInfo);
847686862fbSopenharmony_ci    DistributedWant dstbWant(want);
848686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
849686862fbSopenharmony_ci    MessageParcel reply;
850686862fbSopenharmony_ci    HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
851686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
852686862fbSopenharmony_ci        (IDSchedInterfaceCode::START_ABILITY_BY_CALL_FROM_REMOTE), data, reply);
853686862fbSopenharmony_ci}
854686862fbSopenharmony_ci
855686862fbSopenharmony_ciint32_t DistributedSchedProxy::ReleaseAbilityFromRemote(const sptr<IRemoteObject>& connect,
856686862fbSopenharmony_ci    const AppExecFwk::ElementName &element, const CallerInfo& callerInfo)
857686862fbSopenharmony_ci{
858686862fbSopenharmony_ci    if (connect == nullptr) {
859686862fbSopenharmony_ci        HILOGE("ReleaseAbilityFromRemote connect is null");
860686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
861686862fbSopenharmony_ci    }
862686862fbSopenharmony_ci
863686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
864686862fbSopenharmony_ci    if (remote == nullptr) {
865686862fbSopenharmony_ci        HILOGE("ReleaseAbilityFromRemote remote is null");
866686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
867686862fbSopenharmony_ci    }
868686862fbSopenharmony_ci    MessageParcel data;
869686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
870686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
871686862fbSopenharmony_ci    }
872686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, connect);
873686862fbSopenharmony_ci    if (!data.WriteParcelable(&element)) {
874686862fbSopenharmony_ci        HILOGE("ReleaseAbilityFromRemote write element error.");
875686862fbSopenharmony_ci        return ERR_INVALID_VALUE;
876686862fbSopenharmony_ci    }
877686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
878686862fbSopenharmony_ci    std::string extraInfo = "";
879686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, extraInfo);
880686862fbSopenharmony_ci    MessageParcel reply;
881686862fbSopenharmony_ci    HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
882686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::RELEASE_ABILITY_FROM_REMOTE),
883686862fbSopenharmony_ci        data, reply);
884686862fbSopenharmony_ci}
885686862fbSopenharmony_ci
886686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartRemoteFreeInstall(const OHOS::AAFwk::Want& want,
887686862fbSopenharmony_ci    int32_t callerUid, int32_t requestCode, uint32_t accessToken, const sptr<IRemoteObject>& callback)
888686862fbSopenharmony_ci{
889686862fbSopenharmony_ci    HILOGD("called.");
890686862fbSopenharmony_ci    if (callback == nullptr) {
891686862fbSopenharmony_ci        HILOGE("ContinueMission callback null");
892686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
893686862fbSopenharmony_ci    }
894686862fbSopenharmony_ci
895686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
896686862fbSopenharmony_ci    if (remote == nullptr) {
897686862fbSopenharmony_ci        HILOGE("remote callback null");
898686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
899686862fbSopenharmony_ci    }
900686862fbSopenharmony_ci
901686862fbSopenharmony_ci    MessageParcel data;
902686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
903686862fbSopenharmony_ci        HILOGE("write interface token null");
904686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
905686862fbSopenharmony_ci    }
906686862fbSopenharmony_ci
907686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &want);
908686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerUid);
909686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, requestCode);
910686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint32, accessToken);
911686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, RemoteObject, callback);
912686862fbSopenharmony_ci    MessageParcel reply;
913686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_FREE_INSTALL),
914686862fbSopenharmony_ci        data, reply);
915686862fbSopenharmony_ci}
916686862fbSopenharmony_ci
917686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId)
918686862fbSopenharmony_ci{
919686862fbSopenharmony_ci    HILOGD("called.");
920686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
921686862fbSopenharmony_ci    if (remote == nullptr) {
922686862fbSopenharmony_ci        HILOGE("remote is null");
923686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
924686862fbSopenharmony_ci    }
925686862fbSopenharmony_ci
926686862fbSopenharmony_ci    MessageParcel data;
927686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
928686862fbSopenharmony_ci        HILOGE("write interface token null");
929686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
930686862fbSopenharmony_ci    }
931686862fbSopenharmony_ci
932686862fbSopenharmony_ci    DistributedWant dstbWant(info.want);
933686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
934686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, info.callerInfo.uid);
935686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, info.callerInfo.sourceDeviceId);
936686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, info.accountInfo.accountType);
937686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, StringVector, info.accountInfo.groupIdList);
938686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, info.callerInfo.callerAppId);
939686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int64, taskId);
940686862fbSopenharmony_ci    DistributedWant cmpWant;
941686862fbSopenharmony_ci    cmpWant.SetParam(CMPT_PARAM_FREEINSTALL_BUNDLENAMES, info.callerInfo.bundleNames);
942686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &cmpWant);
943686862fbSopenharmony_ci    nlohmann::json extraInfoJson;
944686862fbSopenharmony_ci    extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = info.callerInfo.accessToken;
945686862fbSopenharmony_ci    extraInfoJson[EXTRO_INFO_JSON_KEY_REQUEST_CODE] = info.requestCode;
946686862fbSopenharmony_ci    if (info.callerInfo.extraInfoJson.find(DMS_VERSION_ID) != info.callerInfo.extraInfoJson.end()) {
947686862fbSopenharmony_ci        extraInfoJson[DMS_VERSION_ID] = info.callerInfo.extraInfoJson[DMS_VERSION_ID];
948686862fbSopenharmony_ci    }
949686862fbSopenharmony_ci    std::string extraInfo = extraInfoJson.dump();
950686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, extraInfo);
951686862fbSopenharmony_ci    MessageParcel reply;
952686862fbSopenharmony_ci    HITRACE_METER_NAME(TraceTag::DSCHED, TraceValue::REMOTE_PROCEDURE_CALL);
953686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_FREE_INSTALL_FROM_REMOTE),
954686862fbSopenharmony_ci        data, reply);
955686862fbSopenharmony_ci}
956686862fbSopenharmony_ci
957686862fbSopenharmony_ciint32_t DistributedSchedProxy::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode)
958686862fbSopenharmony_ci{
959686862fbSopenharmony_ci    HILOGD("called.");
960686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
961686862fbSopenharmony_ci    if (remote == nullptr) {
962686862fbSopenharmony_ci        HILOGE("remote is null");
963686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
964686862fbSopenharmony_ci    }
965686862fbSopenharmony_ci
966686862fbSopenharmony_ci    MessageParcel data;
967686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
968686862fbSopenharmony_ci        HILOGE("write interface token null");
969686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
970686862fbSopenharmony_ci    }
971686862fbSopenharmony_ci
972686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int64, taskId);
973686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, resultCode);
974686862fbSopenharmony_ci    MessageParcel reply;
975686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
976686862fbSopenharmony_ci        (IDSchedInterfaceCode::NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE), data, reply);
977686862fbSopenharmony_ci}
978686862fbSopenharmony_ci
979686862fbSopenharmony_ci#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
980686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartRemoteShareForm(
981686862fbSopenharmony_ci    const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
982686862fbSopenharmony_ci{
983686862fbSopenharmony_ci    HILOGD("SHAREFORM:: func call");
984686862fbSopenharmony_ci    if (remoteDeviceId.empty()) {
985686862fbSopenharmony_ci        HILOGE("input params deviceId is nullptr.");
986686862fbSopenharmony_ci        return INVALID_PARAMETERS_ERR;
987686862fbSopenharmony_ci    }
988686862fbSopenharmony_ci
989686862fbSopenharmony_ci    auto remote = Remote();
990686862fbSopenharmony_ci    if (remote == nullptr) {
991686862fbSopenharmony_ci        HILOGE("fail to get dms remote.");
992686862fbSopenharmony_ci        return DMSPROXY_SERVICE_ERR;
993686862fbSopenharmony_ci    }
994686862fbSopenharmony_ci
995686862fbSopenharmony_ci    MessageParcel data;
996686862fbSopenharmony_ci    MessageParcel reply;
997686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
998686862fbSopenharmony_ci        HILOGE("WriteInterfaceToken failed");
999686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
1000686862fbSopenharmony_ci    }
1001686862fbSopenharmony_ci
1002686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
1003686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
1004686862fbSopenharmony_ci
1005686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_SHARE_FORM),
1006686862fbSopenharmony_ci        data, reply);
1007686862fbSopenharmony_ci}
1008686862fbSopenharmony_ci
1009686862fbSopenharmony_ciint32_t DistributedSchedProxy::StartShareFormFromRemote(
1010686862fbSopenharmony_ci    const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo)
1011686862fbSopenharmony_ci{
1012686862fbSopenharmony_ci    HILOGD("SHAREFORM:: func call");
1013686862fbSopenharmony_ci    if (remoteDeviceId.empty()) {
1014686862fbSopenharmony_ci        HILOGE("input params deviceId is nullptr.");
1015686862fbSopenharmony_ci        return INVALID_PARAMETERS_ERR;
1016686862fbSopenharmony_ci    }
1017686862fbSopenharmony_ci
1018686862fbSopenharmony_ci    auto remote = Remote();
1019686862fbSopenharmony_ci    if (remote == nullptr) {
1020686862fbSopenharmony_ci        HILOGE("fail to get dms remote.");
1021686862fbSopenharmony_ci        return DMSPROXY_SERVICE_ERR;
1022686862fbSopenharmony_ci    }
1023686862fbSopenharmony_ci
1024686862fbSopenharmony_ci    MessageParcel data;
1025686862fbSopenharmony_ci    MessageParcel reply;
1026686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1027686862fbSopenharmony_ci        HILOGE("WriteInterfaceToken failed");
1028686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
1029686862fbSopenharmony_ci    }
1030686862fbSopenharmony_ci
1031686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, remoteDeviceId);
1032686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo);
1033686862fbSopenharmony_ci
1034686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_SHARE_FORM_FROM_REMOTE),
1035686862fbSopenharmony_ci        data, reply);
1036686862fbSopenharmony_ci}
1037686862fbSopenharmony_ci#endif
1038686862fbSopenharmony_ci
1039686862fbSopenharmony_ciint32_t DistributedSchedProxy::NotifyStateChangedFromRemote(int32_t abilityState, int32_t connectToken,
1040686862fbSopenharmony_ci    const AppExecFwk::ElementName& element)
1041686862fbSopenharmony_ci{
1042686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
1043686862fbSopenharmony_ci    if (remote == nullptr) {
1044686862fbSopenharmony_ci        HILOGE("NotifyStateChangedFromRemote remote service null");
1045686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
1046686862fbSopenharmony_ci    }
1047686862fbSopenharmony_ci    MessageParcel data;
1048686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1049686862fbSopenharmony_ci        HILOGE("WriteInterfaceToken failed");
1050686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
1051686862fbSopenharmony_ci    }
1052686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, abilityState);
1053686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, connectToken);
1054686862fbSopenharmony_ci    if (!data.WriteParcelable(&element)) {
1055686862fbSopenharmony_ci        HILOGE("NotifyStateChangedFromRemote write element error.");
1056686862fbSopenharmony_ci        return ERR_INVALID_VALUE;
1057686862fbSopenharmony_ci    }
1058686862fbSopenharmony_ci    MessageParcel reply;
1059686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::NOTIFY_STATE_CHANGED_FROM_REMOTE),
1060686862fbSopenharmony_ci        data, reply);
1061686862fbSopenharmony_ci}
1062686862fbSopenharmony_ci
1063686862fbSopenharmony_ciint32_t DistributedSchedProxy::GetDistributedComponentList(std::vector<std::string>& distributedComponents)
1064686862fbSopenharmony_ci{
1065686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
1066686862fbSopenharmony_ci    if (remote == nullptr) {
1067686862fbSopenharmony_ci        HILOGE("GetDistributedComponentList remote is null");
1068686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
1069686862fbSopenharmony_ci    }
1070686862fbSopenharmony_ci    MessageParcel data;
1071686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1072686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
1073686862fbSopenharmony_ci    }
1074686862fbSopenharmony_ci    MessageParcel reply;
1075686862fbSopenharmony_ci    MessageOption option;
1076686862fbSopenharmony_ci    int32_t error = remote->SendRequest(static_cast<uint32_t>(IDSchedInterfaceCode::GET_DISTRIBUTED_COMPONENT_LIST),
1077686862fbSopenharmony_ci        data, reply, option);
1078686862fbSopenharmony_ci    if (error != ERR_NONE) {
1079686862fbSopenharmony_ci        HILOGE("GetDistributedComponentList SendRequest error = %{public}d", error);
1080686862fbSopenharmony_ci        return error;
1081686862fbSopenharmony_ci    }
1082686862fbSopenharmony_ci    int32_t result = reply.ReadInt32();
1083686862fbSopenharmony_ci    if (result != ERR_NONE) {
1084686862fbSopenharmony_ci        HILOGE("GetDistributedComponentList result = %{public}d", result);
1085686862fbSopenharmony_ci        return result;
1086686862fbSopenharmony_ci    }
1087686862fbSopenharmony_ci    PARCEL_READ_HELPER(reply, StringVector, &distributedComponents);
1088686862fbSopenharmony_ci    return ERR_NONE;
1089686862fbSopenharmony_ci}
1090686862fbSopenharmony_ci
1091686862fbSopenharmony_ciint32_t DistributedSchedProxy::StopRemoteExtensionAbility(
1092686862fbSopenharmony_ci    const OHOS::AAFwk::Want& want, int32_t callerUid, uint32_t accessToken, int32_t extensionType)
1093686862fbSopenharmony_ci{
1094686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
1095686862fbSopenharmony_ci    if (remote == nullptr) {
1096686862fbSopenharmony_ci        HILOGE("StopRemoteExtensionAbility remote service null");
1097686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
1098686862fbSopenharmony_ci    }
1099686862fbSopenharmony_ci    MessageParcel data;
1100686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1101686862fbSopenharmony_ci        HILOGE("StopRemoteExtensionAbility WriteInterfaceToken failed");
1102686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
1103686862fbSopenharmony_ci    }
1104686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &want);
1105686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerUid);
1106686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Uint32, accessToken);
1107686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, extensionType);
1108686862fbSopenharmony_ci    MessageParcel reply;
1109686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::STOP_REMOTE_EXTERNSION_ABILITY),
1110686862fbSopenharmony_ci        data, reply);
1111686862fbSopenharmony_ci}
1112686862fbSopenharmony_ci
1113686862fbSopenharmony_ciint32_t DistributedSchedProxy::StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& want,
1114686862fbSopenharmony_ci    const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t extensionType)
1115686862fbSopenharmony_ci{
1116686862fbSopenharmony_ci    sptr<IRemoteObject> remote = Remote();
1117686862fbSopenharmony_ci    if (remote == nullptr) {
1118686862fbSopenharmony_ci        HILOGE("StopExtensionAbilityFromRemote remote service null");
1119686862fbSopenharmony_ci        return ERR_NULL_OBJECT;
1120686862fbSopenharmony_ci    }
1121686862fbSopenharmony_ci    MessageParcel data;
1122686862fbSopenharmony_ci    if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
1123686862fbSopenharmony_ci        HILOGE("StopExtensionAbilityFromRemote WriteInterfaceToken failed");
1124686862fbSopenharmony_ci        return ERR_FLATTEN_OBJECT;
1125686862fbSopenharmony_ci    }
1126686862fbSopenharmony_ci    DistributedWant dstbWant(want);
1127686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Parcelable, &dstbWant);
1128686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, extensionType);
1129686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, callerInfo.uid);
1130686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);
1131686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, Int32, accountInfo.accountType);
1132686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, StringVector, accountInfo.groupIdList);
1133686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, callerInfo.callerAppId);
1134686862fbSopenharmony_ci    nlohmann::json extraInfoJson;
1135686862fbSopenharmony_ci    extraInfoJson[EXTRO_INFO_JSON_KEY_ACCESS_TOKEN] = callerInfo.accessToken;
1136686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_ACCOUNT_ID] = accountInfo.activeAccountId;
1137686862fbSopenharmony_ci    extraInfoJson[Constants::EXTRO_INFO_JSON_KEY_USERID_ID] = accountInfo.userId;
1138686862fbSopenharmony_ci    std::string extraInfo = extraInfoJson.dump();
1139686862fbSopenharmony_ci    PARCEL_WRITE_HELPER(data, String, extraInfo);
1140686862fbSopenharmony_ci    MessageParcel reply;
1141686862fbSopenharmony_ci    PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>
1142686862fbSopenharmony_ci        (IDSchedInterfaceCode::STOP_EXTERNSION_ABILITY_FROM_REMOTE), data, reply);
1143686862fbSopenharmony_ci}
1144686862fbSopenharmony_ci} // namespace DistributedSchedule
1145686862fbSopenharmony_ci} // namespace OHOS
1146686862fbSopenharmony_ci
1147