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_stub.h" 17 18 #include <securec.h> 19 #include "account_error_no.h" 20 #include "account_log_wrapper.h" 21 #include "app_account_common.h" 22 #include "ipc_skeleton.h" 23 #include "want.h" 24 25 namespace OHOS { 26 namespace AccountSA { AppAccountAuthorizationExtensionStub()27 AppAccountAuthorizationExtensionStub::AppAccountAuthorizationExtensionStub() 28 {} 29 ~AppAccountAuthorizationExtensionStub()30 AppAccountAuthorizationExtensionStub::~AppAccountAuthorizationExtensionStub() 31 {} 32 OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int AppAccountAuthorizationExtensionStub::OnRemoteRequest( 34 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 35 { 36 ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d", code, IPCSkeleton::GetCallingUid()); 37 if (data.ReadInterfaceToken() != GetDescriptor()) { 38 ACCOUNT_LOGE("check descriptor failed!"); 39 return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR; 40 } 41 switch (code) { 42 case static_cast<uint32_t>(AppAccountAuthorizationExtensionInterfaceCode::START_AUTHENTICATION): 43 return ProcStartAuthorization(data, reply); 44 default: 45 break; 46 } 47 ACCOUNT_LOGD("Code is not find"); 48 return IPCObjectStub::OnRemoteRequest(code, data, reply, option); 49 } 50 ReadRequest(MessageParcel & data,AuthorizationRequest & request)51 static ErrCode ReadRequest(MessageParcel &data, AuthorizationRequest &request) 52 { 53 if (!data.ReadBool(request.isEnableContext)) { 54 ACCOUNT_LOGE("failed to write request isEnableContext"); 55 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR; 56 } 57 if (!data.ReadInt32(request.callerUid)) { 58 ACCOUNT_LOGE("failed to write request callerUid"); 59 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR; 60 } 61 std::shared_ptr<AAFwk::WantParams> parameters(data.ReadParcelable<AAFwk::WantParams>()); 62 if (parameters == nullptr) { 63 ACCOUNT_LOGE("failed to read request parameters"); 64 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR; 65 } 66 request.parameters = (*parameters); 67 auto callback = iface_cast<IAppAccountAuthorizationExtensionCallback>(data.ReadRemoteObject()); 68 if (callback == nullptr) { 69 ACCOUNT_LOGE("failed to read domain callback"); 70 return ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR; 71 } 72 request.callback = callback; 73 return ERR_OK; 74 } 75 ProcStartAuthorization(MessageParcel & data,MessageParcel & reply)76 ErrCode AppAccountAuthorizationExtensionStub::ProcStartAuthorization(MessageParcel &data, MessageParcel &reply) 77 { 78 AuthorizationRequest request; 79 ErrCode result = ReadRequest(data, request); 80 if (result != ERR_OK) { 81 return result; 82 } 83 result = StartAuthorization(request); 84 if (!reply.WriteInt32(result)) { 85 ACCOUNT_LOGE("failed to write result"); 86 return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR; 87 } 88 return ERR_NONE; 89 } 90 } // namespace AccountSA 91 } // namespace OHOS