• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_authenticator_callback_stub.h"
17 
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20 #include "app_account_common.h"
21 
22 namespace OHOS {
23 namespace AccountSA {
AppAccountAuthenticatorCallbackStub()24 AppAccountAuthenticatorCallbackStub::AppAccountAuthenticatorCallbackStub()
25 {}
26 
~AppAccountAuthenticatorCallbackStub()27 AppAccountAuthenticatorCallbackStub::~AppAccountAuthenticatorCallbackStub()
28 {}
29 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int AppAccountAuthenticatorCallbackStub::OnRemoteRequest(
31     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
32 {
33     if (data.ReadInterfaceToken() != GetDescriptor()) {
34         ACCOUNT_LOGE("failed to check descriptor! code %{public}u.", code);
35         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
36     }
37 
38     ErrCode errCode = ERR_OK;
39     switch (code) {
40         case static_cast<uint32_t>(AppAccountAuthenticatorCallbackInterfaceCode::ACCOUNT_RESULT): {
41             int32_t resultCode = data.ReadInt32();
42             std::shared_ptr<AAFwk::Want> resultPtr(data.ReadParcelable<AAFwk::Want>());
43             if (resultPtr == nullptr) {
44                 AAFwk::Want result;
45                 OnResult(ERR_JS_ACCOUNT_AUTHENTICATOR_SERVICE_EXCEPTION, result);
46                 errCode = ERR_APPACCOUNT_SERVICE_OAUTH_INVALID_RESPONSE;
47             } else {
48                 OnResult(resultCode, *resultPtr);
49             }
50             if (!reply.WriteInt32(errCode)) {
51                 ACCOUNT_LOGE("failed to write reply");
52                 return IPC_STUB_WRITE_PARCEL_ERR;
53             }
54             break;
55         }
56         case static_cast<uint32_t>(AppAccountAuthenticatorCallbackInterfaceCode::ACCOUNT_REQUEST_REDIRECTED): {
57             std::shared_ptr<AAFwk::Want> requestPtr(data.ReadParcelable<AAFwk::Want>());
58             if (requestPtr == nullptr) {
59                 AAFwk::Want request;
60                 OnRequestRedirected(request);
61                 errCode = ERR_APPACCOUNT_SERVICE_OAUTH_INVALID_RESPONSE;
62             } else {
63                 OnRequestRedirected(*requestPtr);
64             }
65             if (!reply.WriteInt32(errCode)) {
66                 ACCOUNT_LOGE("failed to write reply");
67                 return IPC_STUB_WRITE_PARCEL_ERR;
68             }
69             break;
70         }
71         case static_cast<uint32_t>(AppAccountAuthenticatorCallbackInterfaceCode::ACCOUNT_REQUEST_CONTINUED): {
72             OnRequestContinued();
73             break;
74         }
75         default:
76             ACCOUNT_LOGI("default, code = %{public}u, flags = %{public}u", code, option.GetFlags());
77             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
78     }
79     return ERR_NONE;
80 }
81 }  // namespace AccountSA
82 }  // namespace OHOS
83