/* * Copyright (c) 2024 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. */ #ifndef APPACCOUNT_COMMON_H #define APPACCOUNT_COMMON_H #include #include #include "app_account_authenticator_callback_stub.h" #include "app_account_common.h" #include "app_account_manager.h" #include "app_account_subscriber.h" #include "cj_common_ffi.h" #include "want.h" #include "appaccount_defination.h" namespace OHOS::AccountSA { class SubscribePtr : public AppAccountSubscriber { public: explicit SubscribePtr(const AppAccountSubscribeInfo &subscribeInfo); void SetCallbackRef(std::function callbackRef); void OnAccountsChanged(const std::vector &accounts) override; std::function ref_; }; struct AsyncContextForSubscribe { std::string type; std::vector owners; std::shared_ptr subscriber = nullptr; std::function callbackRef; }; struct AsyncContextForUnSubscribe { std::string type; std::vector> subscribers = {nullptr}; std::function callbackRef; }; struct CheckAccountLabelsContext { std::string name; std::string owner; std::vector labels; std::function callbackRef = nullptr; sptr appAccountMgrCb = nullptr; ErrCode errCode = ERR_OK; }; class AuthenticatorAsyncCallback : public AppAccountAuthenticatorCallbackStub { public: explicit AuthenticatorAsyncCallback( std::function cRef, std::function sRef); ~AuthenticatorAsyncCallback(); void OnResult(int32_t resultCode, const AAFwk::Want &result) override; void OnRequestRedirected(AAFwk::Want &request) override; void OnRequestContinued() override; bool onResultRetBool = false; std::vector onResultRetNames; std::vector onResultRetOwners; AAFwk::Want result_; AAFwk::Want request_; ErrCode errCode = ERR_OK; private: std::mutex mutex_; bool isDone = false; std::function checkAccountLabelsCallbackRef = nullptr; std::function selectAccountsCallbackRef = nullptr; }; struct SelectAccountsContext { SelectAccountsOptions options; std::vector appAccountInfos; std::function callbackRef = nullptr; sptr appAccountMgrCb = nullptr; ErrCode errCode = ERR_OK; }; struct JSAuthCallback { std::function onResult = nullptr; std::function onRequestRedirected = nullptr; std::function onRequestContinued = nullptr; }; class AppAccountManagerCallback : public AppAccountAuthenticatorCallbackStub { public: explicit AppAccountManagerCallback(JSAuthCallback callback); ~AppAccountManagerCallback(); void OnResult(int32_t resultCode, const AAFwk::Want &result) override; void OnRequestRedirected(AAFwk::Want &request) override; void OnRequestContinued() override; AAFwk::Want result_; JSAuthCallback callback_; ErrCode errCode = ERR_OK; // account: AppAccountInfo std::string nameResult; std::string ownerResult; //tokenInfo: AuthTokenInfo std::string authTypeResult; std::string tokenResult; private: std::mutex mutex_; bool isDone = false; }; } // namespace OHOS::AccountSA #endif