/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "pinauth_proxy.h" #include "pinauth_log_wrapper.h" namespace OHOS { namespace UserIAM { namespace PinAuth { PinAuthProxy::PinAuthProxy(const sptr &object) : IRemoteProxy(object) { PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::PinAuthProxy start"); } PinAuthProxy::~PinAuthProxy() { PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::~PinAuthProxy start"); } bool PinAuthProxy::RegisterInputer(sptr inputer) { MessageParcel data; MessageParcel reply; PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::RegisterInputer start"); if (!data.WriteInterfaceToken(PinAuthProxy::GetDescriptor())) { PINAUTH_HILOGE(MODULE_FRAMEWORKS, "write descriptor failed"); return false; } if (!data.WriteRemoteObject(inputer->AsObject())) { PINAUTH_HILOGE(MODULE_FRAMEWORKS, "write inputer failed"); return false; } bool ret = SendRequest(static_cast(IRemotePinAuth::REGISTER_INPUTER), data, reply, true); bool result = false; if (!ret) { PINAUTH_HILOGE(MODULE_FRAMEWORKS, "SendRequest is failed, error code: %d", ret); } else { result = reply.ReadBool(); PINAUTH_HILOGI(MODULE_FRAMEWORKS, "SendRequest is OK"); } return result; } void PinAuthProxy::UnRegisterInputer() { MessageParcel data; MessageParcel reply; PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::UnRegisterInputer start"); if (!data.WriteInterfaceToken(PinAuthProxy::GetDescriptor())) { PINAUTH_HILOGE(MODULE_FRAMEWORKS, "write descriptor failed!"); return; } bool ret = SendRequest(static_cast(IRemotePinAuth::UNREGISTER_INPUTER), data, reply, false); if (!ret) { PINAUTH_HILOGE(MODULE_FRAMEWORKS, "UnRegisterInputer SendRequest failed!"); } } bool PinAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, bool isSync) { PINAUTH_HILOGI(MODULE_FRAMEWORKS, "PinAuthProxy::SendRequest start"); sptr remote = Remote(); if (remote == nullptr) { PINAUTH_HILOGE(MODULE_FRAMEWORKS, "failed to get remote."); return false; } MessageOption option(isSync ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC); int32_t result = remote->SendRequest(code, data, reply, option); if (result != OHOS::NO_ERROR) { PINAUTH_HILOGE(MODULE_FRAMEWORKS, "failed to SendRequest.result = %{public}d", result); return false; } return true; } } // namespace PinAuth } // namespace UserIAM } // namespace OHOS