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 #ifndef TEST_WUKONG_APP_MANAGER_H
16 #define TEST_WUKONG_APP_MANAGER_H
17 
18 #include "ability_controller_stub.h"
19 #include "appexecfwk_errors.h"
20 #include "singleton.h"
21 
22 namespace OHOS {
23 namespace WuKong {
24 class AppManager : public DelayedSingleton<AppManager> {
25 public:
26     /**
27      * @brief start ability by bundleInfo's entryHapName and entryHap->mainAbility
28      * @param abilityName ability name
29      * @param bundleName bundle name
30      * @return Returns ERR_OK on success, others on failure.
31      */
32     ErrCode StartAbilityByBundleInfo(std::string abilityName, std::string bundleName);
33 
34     /**
35      * @brief start ability by uri name and typeVal name
36      * @param uriname uri name
37      * @param typeVal uritype name
38      * @return Returns ERR_OK on success, others on failure.
39      */
40     ErrCode StartAbilityByUriAndType(const std::string uri, const std::string typeVal);
41 
42     /**
43      * @brief start ability by uri name and ability name
44      * @param uriname uri name
45      * @param abilityName ability name
46      * @return Returns ERR_OK on success, others on failure.
47      */
48     ErrCode StartAbilityByAbilityAndUri(const std::string uri, const std::vector<std::string> &abilityName);
49 
50     void SetAbilityController();
51 
52 private:
53     class BlockAbilityController : public OHOS::AppExecFwk::AbilityControllerStub {
54     public:
55         /**
56          * @brief cold start.
57          * @param want want information
58          * @param bundleName bundle name
59          * @return whether this function is realize or not.
60          */
61         virtual bool AllowAbilityStart(const AAFwk::Want &want, const std::string &bundleName) override;
62 
63         /**
64          * @brief turn to background.
65          * @param bundleName bundle name
66          * @return whether this function is realize or not.
67          */
68         virtual bool AllowAbilityBackground(const std::string &bundleName) override;
69 
70     private:
71         std::vector<std::string> AllowBundleList;
72     };
73 
74     // block ability controller
75     sptr<BlockAbilityController> abilityController_;
76 };
77 }  // namespace WuKong
78 }  // namespace OHOS
79 #endif  // TEST_WUKONG_APP_MANAGER_H
80