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