• 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 #include "ability_manager_adapter.h"
16 
17 #include "account_log_wrapper.h"
18 #include "mock_app_account_authenticator_stub.h"
19 
20 namespace OHOS {
21 namespace AccountSA {
22 namespace {
23 const std::string STRING_BUNDLE = "com.example.name";
24 } // namespace
25 using namespace AAFwk;
26 std::shared_ptr<AbilityManagerAdapter> AbilityManagerAdapter::instance_ = nullptr;
27 std::mutex AbilityManagerAdapter::mockInstanceMutex_;
28 
GetInstance()29 std::shared_ptr<AbilityManagerAdapter> AbilityManagerAdapter::GetInstance()
30 {
31     std::lock_guard<std::mutex> lock(mockInstanceMutex_);
32     if (instance_ == nullptr) {
33         instance_ = std::make_shared<AbilityManagerAdapter>();
34     }
35     return instance_;
36 }
37 
AbilityManagerAdapter()38 AbilityManagerAdapter::AbilityManagerAdapter()
39 {}
40 
~AbilityManagerAdapter()41 AbilityManagerAdapter::~AbilityManagerAdapter()
42 {}
43 
ConnectAbility(const AAFwk::Want & want,const sptr<AAFwk::IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t userId)44 ErrCode AbilityManagerAdapter::ConnectAbility(const AAFwk::Want &want, const sptr<AAFwk::IAbilityConnection> &connect,
45     const sptr<IRemoteObject> &callerToken, int32_t userId)
46 {
47     if (want.GetBundle() == STRING_BUNDLE) {
48         sptr<AccountSA::MockAppAccountAuthenticator> mockServicePtr_ =
49             new (std::nothrow) AccountSA::MockAppAccountAuthenticator();
50         int resultCode = ERR_OK;
51         AppExecFwk::ElementName element = want.GetElement();
52         connect->OnAbilityConnectDone(element, mockServicePtr_, resultCode);
53     } else {
54         int resultCode = ERR_OK;
55         AppExecFwk::ElementName element = want.GetElement();
56         connect->OnAbilityConnectDone(element, nullptr, resultCode);
57     }
58     return ERR_OK;
59 }
60 
DisconnectAbility(const sptr<AAFwk::IAbilityConnection> & connect)61 ErrCode AbilityManagerAdapter::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &connect)
62 {
63     return ERR_OK;
64 }
65 
StartUser(int accountId)66 ErrCode AbilityManagerAdapter::StartUser(int accountId)
67 {
68     return ERR_OK;
69 }
70 
StopUser(int accountId,const sptr<AAFwk::IStopUserCallback> & callback)71 ErrCode AbilityManagerAdapter::StopUser(int accountId, const sptr<AAFwk::IStopUserCallback> &callback)
72 {
73     return ERR_OK;
74 }
75 } // namespace AccountSA
76 } // namespace OHOS