1 /*
2 * Copyright (c) 2023 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 "app_account_authorization_extension_callback_proxy.h"
17
18 #include <securec.h>
19 #include "account_error_no.h"
20 #include "account_log_wrapper.h"
21 #include "want.h"
22
23 namespace OHOS {
24 namespace AccountSA {
AppAccountAuthorizationExtensionCallbackProxy(const sptr<IRemoteObject> & object)25 AppAccountAuthorizationExtensionCallbackProxy::AppAccountAuthorizationExtensionCallbackProxy(
26 const sptr<IRemoteObject> &object)
27 : IRemoteProxy<IAppAccountAuthorizationExtensionCallback>(object)
28 {}
29
~AppAccountAuthorizationExtensionCallbackProxy()30 AppAccountAuthorizationExtensionCallbackProxy::~AppAccountAuthorizationExtensionCallbackProxy()
31 {}
32
SendRequest(AppAccountAuthorizationExtensionCallbackInterfaceCode code,MessageParcel & data)33 ErrCode AppAccountAuthorizationExtensionCallbackProxy::SendRequest(
34 AppAccountAuthorizationExtensionCallbackInterfaceCode code, MessageParcel &data)
35 {
36 sptr<IRemoteObject> remote = Remote();
37 if (remote == nullptr) {
38 ACCOUNT_LOGE("remote is nullptr, code = %{public}d", code);
39 return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
40 }
41 MessageParcel reply;
42 MessageOption option(MessageOption::TF_ASYNC);
43 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
44 }
45
OnResult(const AsyncCallbackError & businessError,const AAFwk::WantParams & parameters)46 void AppAccountAuthorizationExtensionCallbackProxy::OnResult(
47 const AsyncCallbackError &businessError, const AAFwk::WantParams ¶meters)
48 {
49 MessageParcel data;
50 if (!data.WriteInterfaceToken(GetDescriptor())) {
51 ACCOUNT_LOGE("failed to write descriptor");
52 return;
53 }
54 if (!data.WriteInt32(businessError.code)) {
55 ACCOUNT_LOGE("failed to write error code");
56 return;
57 }
58 if (!data.WriteString(businessError.message)) {
59 ACCOUNT_LOGE("failed to write error message");
60 return;
61 }
62 if (!data.WriteParcelable(&businessError.data)) {
63 ACCOUNT_LOGE("failed to write error data");
64 return;
65 }
66 if (!data.WriteParcelable(¶meters)) {
67 ACCOUNT_LOGE("failed to write request parameters");
68 return;
69 }
70 ErrCode result = SendRequest(AppAccountAuthorizationExtensionCallbackInterfaceCode::ON_RESULT, data);
71 if (result != ERR_OK) {
72 ACCOUNT_LOGE("failed to send request, error code: %{public}d", result);
73 }
74 }
75
OnRequestRedirected(const AAFwk::Want & request)76 void AppAccountAuthorizationExtensionCallbackProxy::OnRequestRedirected(const AAFwk::Want& request)
77 {
78 MessageParcel data;
79 if (!data.WriteInterfaceToken(GetDescriptor())) {
80 ACCOUNT_LOGE("failed to write descriptor");
81 return;
82 }
83 if (!data.WriteParcelable(&request)) {
84 ACCOUNT_LOGE("failed to write request");
85 return;
86 }
87 ErrCode result = SendRequest(AppAccountAuthorizationExtensionCallbackInterfaceCode::ON_REQUEST_REDIRECTED, data);
88 if (result != ERR_OK) {
89 ACCOUNT_LOGE("failed to send request, error code: %{public}d", result);
90 }
91 }
92 } // namespace AccountSA
93 } // namespace OHOS
94