1 /*
2 * Copyright (c) 2024 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 #include "appaccount_common.h"
16
17 #include "account_error_no.h"
18 #include "account_log_wrapper.h"
19 #include "app_account_constants.h"
20 #include "app_account_manager.h"
21
22 namespace OHOS::AccountSA {
AuthenticatorAsyncCallback(std::function<void (RetDataBool)> cRef,std::function<void (ErrCArrAppAccountInfo)> sRef)23 AuthenticatorAsyncCallback::AuthenticatorAsyncCallback(
24 std::function<void(RetDataBool)> cRef,
25 std::function<void(ErrCArrAppAccountInfo)> sRef)
26 : checkAccountLabelsCallbackRef(cRef), selectAccountsCallbackRef(sRef) {}
27
~AuthenticatorAsyncCallback()28 AuthenticatorAsyncCallback::~AuthenticatorAsyncCallback() {}
29
OnResult(int32_t resultCode,const AAFwk::Want & result)30 void AuthenticatorAsyncCallback::OnResult(int32_t resultCode, const AAFwk::Want &result)
31 {
32 {
33 std::lock_guard<std::mutex> lock(mutex_);
34 if (isDone) {
35 return;
36 }
37 isDone = true;
38 }
39
40 this->errCode = resultCode;
41 this->onResultRetBool = result.GetBoolParam(Constants::KEY_BOOLEAN_RESULT, false);
42 this->onResultRetNames = result.GetStringArrayParam(Constants::KEY_ACCOUNT_NAMES);
43 this->onResultRetOwners = result.GetStringArrayParam(Constants::KEY_ACCOUNT_OWNERS);
44 }
45
OnRequestRedirected(AAFwk::Want & request)46 void AuthenticatorAsyncCallback::OnRequestRedirected(AAFwk::Want &request) {}
47
OnRequestContinued()48 void AuthenticatorAsyncCallback::OnRequestContinued() {}
49
AppAccountManagerCallback(JSAuthCallback callback)50 AppAccountManagerCallback::AppAccountManagerCallback(JSAuthCallback callback): callback_(callback) {}
51
~AppAccountManagerCallback()52 AppAccountManagerCallback::~AppAccountManagerCallback() {}
53
OnResult(int32_t resultCode,const AAFwk::Want & result)54 void AppAccountManagerCallback::OnResult(int32_t resultCode, const AAFwk::Want &result)
55 {
56 {
57 std::lock_guard<std::mutex> lock(mutex_);
58 if (isDone) {
59 return;
60 }
61 isDone = true;
62 }
63
64 this->errCode = resultCode;
65 // account: AppAccountInfo
66 this->nameResult = result.GetStringParam(Constants::KEY_ACCOUNT_NAMES);
67 this->ownerResult = result.GetStringParam(Constants::KEY_ACCOUNT_OWNERS);
68 //tokenInfo: AuthTokenInfo
69 this->authTypeResult = result.GetStringParam(Constants::KEY_AUTH_TYPE);
70 this->tokenResult = result.GetStringParam(Constants::KEY_TOKEN);
71 }
72
OnRequestRedirected(AAFwk::Want & request)73 void AppAccountManagerCallback::OnRequestRedirected(AAFwk::Want &request) {}
74
OnRequestContinued()75 void AppAccountManagerCallback::OnRequestContinued() {}
76
SubscribePtr(const AppAccountSubscribeInfo & subscribeInfo)77 SubscribePtr::SubscribePtr(const AppAccountSubscribeInfo &subscribeInfo) : AppAccountSubscriber(subscribeInfo) {}
78
OnAccountsChanged(const std::vector<AppAccountInfo> & accounts)79 void SubscribePtr::OnAccountsChanged(const std::vector<AppAccountInfo> &accounts) {}
SetCallbackRef(std::function<void (CArrAppAccountInfo)> callbackRef)80 void SubscribePtr::SetCallbackRef(std::function<void(CArrAppAccountInfo)> callbackRef)
81 {
82 ref_ = callbackRef;
83 }
84 } // namespace::OHOS::AccountSA