• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 <gtest/gtest.h>
17 #include <gmock/gmock.h>
18 #include "ability_manager_adapter.h"
19 
20 #include "account_log_wrapper.h"
21 #include "mock_app_account_authenticator_stub.h"
22 #include "string_wrapper.h"
23 
24 namespace OHOS {
25 namespace AccountSA {
26 namespace {
27 const std::string STRING_BUNDLE = "com.example.name";
28 const std::string STRING_ABILITY_NAME_WITH_CONNECT_FAILED = "com.example.MainAbilityWithConnectFailed";
29 const std::string STRING_ABILITY_NAME_WITH_NO_PROXY = "com.example.MainAbilityWithNoProxy";
30 } // namespace
31 using namespace AAFwk;
32 
GetInstance()33 AbilityManagerAdapter *AbilityManagerAdapter::GetInstance()
34 {
35     static AbilityManagerAdapter *instance = new (std::nothrow) AbilityManagerAdapter();
36     return instance;
37 }
38 
AbilityManagerAdapter()39 AbilityManagerAdapter::AbilityManagerAdapter()
40 {}
41 
~AbilityManagerAdapter()42 AbilityManagerAdapter::~AbilityManagerAdapter()
43 {}
44 
ConnectAbility(const AAFwk::Want & want,const sptr<AAFwk::IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t userId)45 ErrCode AbilityManagerAdapter::ConnectAbility(const AAFwk::Want &want, const sptr<AAFwk::IAbilityConnection> &connect,
46     const sptr<IRemoteObject> &callerToken, int32_t userId)
47 {
48     if (want.GetBundle() == STRING_BUNDLE) {
49         sptr<AccountSA::MockAppAccountAuthenticator> mockServicePtr_ =
50             new (std::nothrow) AccountSA::MockAppAccountAuthenticator();
51         int resultCode = ERR_OK;
52         AppExecFwk::ElementName element = want.GetElement();
53         connect->OnAbilityConnectDone(element, mockServicePtr_, resultCode);
54     } else {
55         int resultCode = ERR_OK;
56         AppExecFwk::ElementName element = want.GetElement();
57         connect->OnAbilityConnectDone(element, nullptr, resultCode);
58     }
59     return ERR_OK;
60 }
61 
DisconnectAbility(const sptr<AAFwk::IAbilityConnection> & connect)62 ErrCode AbilityManagerAdapter::DisconnectAbility(const sptr<AAFwk::IAbilityConnection> &connect)
63 {
64     return ERR_OK;
65 }
66 
StartUser(int accountId,const sptr<AAFwk::IUserCallback> & callback,bool isAppRecovery)67 ErrCode AbilityManagerAdapter::StartUser(int accountId, const sptr<AAFwk::IUserCallback> &callback, bool isAppRecovery)
68 {
69     return ERR_OK;
70 }
71 
StopUser(int accountId,const sptr<AAFwk::IUserCallback> & callback)72 ErrCode AbilityManagerAdapter::StopUser(int accountId, const sptr<AAFwk::IUserCallback> &callback)
73 {
74     return ERR_OK;
75 }
76 
LogoutUser(int32_t accountId,const sptr<IUserCallback> & callback)77 ErrCode AbilityManagerAdapter::LogoutUser(int32_t accountId, const sptr<IUserCallback> &callback)
78 {
79     return ERR_OK;
80 }
81 
IsAllAppDied(int32_t accountId)82 bool AbilityManagerAdapter::IsAllAppDied(int32_t accountId)
83 {
84     return true;
85 }
86 
Connect()87 void Connect()
88 {
89 }
90 
DoConnectAbility(const sptr<IRemoteObject> proxy,const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t userId=-1)91 ErrCode DoConnectAbility(
92     const sptr<IRemoteObject> proxy,
93     const Want &want,
94     const sptr<IAbilityConnection> &connect,
95     const sptr<IRemoteObject> &callerToken,
96     int32_t userId = -1)
97 {
98     return ERR_OK;
99 }
100 
GetAbilityManager()101 sptr<IRemoteObject> GetAbilityManager()
102 {
103     sptr<IRemoteObject> iRemoteObject;
104     return  iRemoteObject;
105 }
106 
ResetProxy(const wptr<IRemoteObject> & remote)107 void ResetProxy(const wptr<IRemoteObject>& remote)
108 {}
109 } // namespace AccountSA
110 } // namespace OHOS