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 "user_callback_proxy.h"
17
18#include "hilog_tag_wrapper.h"
19
20namespace OHOS {
21namespace AAFwk {
22void UserCallbackProxy::OnStopUserDone(int userId, int errcode)
23{
24    SendRequestCommon(userId, errcode, IUserCallback::UserCallbackCmd::ON_STOP_USER_DONE);
25}
26
27void UserCallbackProxy::OnStartUserDone(int userId, int errcode)
28{
29    SendRequestCommon(userId, errcode, IUserCallback::UserCallbackCmd::ON_START_USER_DONE);
30}
31
32void UserCallbackProxy::SendRequestCommon(int userId, int errcode, IUserCallback::UserCallbackCmd cmd)
33{
34    MessageParcel data;
35    MessageParcel reply;
36    MessageOption option(MessageOption::TF_ASYNC);
37
38    TAG_LOGI(AAFwkTag::ABILITYMGR,
39        "UserCallbackProxy, sendrequest, cmd:%{public}d, userId:%{public}d, errcode:%{public}d", cmd, userId, errcode);
40    if (!data.WriteInterfaceToken(IUserCallback::GetDescriptor())) {
41        TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
42        return;
43    }
44
45    if (!data.WriteInt32(userId)) {
46        TAG_LOGE(AAFwkTag::ABILITYMGR, "write userId error");
47        return;
48    }
49
50    if (!data.WriteInt32(errcode)) {
51        TAG_LOGE(AAFwkTag::ABILITYMGR, "write errcode error");
52        return;
53    }
54
55    sptr<IRemoteObject> remote = Remote();
56    if (remote == nullptr) {
57        TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote object");
58        return;
59    }
60
61    int error = remote->SendRequest(cmd, data, reply, option);
62    if (error != NO_ERROR) {
63        TAG_LOGE(AAFwkTag::ABILITYMGR, "SendRequest fail, error: %{public}d", error);
64        return;
65    }
66}
67}  // namespace AAFwk
68}  // namespace OHOS
69