• 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 
16 #ifndef OHOS_ABILITY_RUNTIME_ABILITY_INTERCEPTOR_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_INTERCEPTOR_H
18 
19 #include "ability_util.h"
20 #include "disposed_observer.h"
21 #include "in_process_call_wrapper.h"
22 #include "task_handler_wrap.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace EcologicalRuleMgrService {
27 struct AbilityCallerInfo;
28 struct AbilityExperienceRule;
29 }
30 namespace AAFwk {
31 using namespace OHOS::EcologicalRuleMgrService;
32 using ErmsCallerInfo = OHOS::EcologicalRuleMgrService::AbilityCallerInfo;
33 using ExperienceRule = OHOS::EcologicalRuleMgrService::AbilityExperienceRule;
34 
35 class AbilityInterceptor {
36 public:
37     virtual ~AbilityInterceptor() = default;
38 
39     /**
40      * Excute interception processing.
41      */
42     virtual ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground,
43         const sptr<IRemoteObject> &callerToken) = 0;
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)44     virtual void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) {};
45 };
46 
47 // start ability interceptor
48 class CrowdTestInterceptor : public AbilityInterceptor {
49 public:
50     CrowdTestInterceptor() = default;
51     ~CrowdTestInterceptor() = default;
52     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground,
53         const sptr<IRemoteObject> &callerToken) override;
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)54     virtual void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) override
55     {
56         return;
57     };
58 private:
59     bool CheckCrowdtest(const Want &want, int32_t userId);
60 };
61 
62 class ControlInterceptor : public AbilityInterceptor {
63 public:
64     ControlInterceptor() = default;
65     ~ControlInterceptor() = default;
66     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground,
67         const sptr<IRemoteObject> &callerToken) override;
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)68     virtual void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) override
69     {
70         return;
71     };
72 private:
73     bool CheckControl(const Want &want, int32_t userId, AppExecFwk::AppRunningControlRuleResult &controlRule);
74 };
75 
76 class DisposedRuleInterceptor : public AbilityInterceptor,
77                                 public std::enable_shared_from_this<DisposedRuleInterceptor> {
78 public:
79     DisposedRuleInterceptor() = default;
80     ~DisposedRuleInterceptor() = default;
81     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground,
82         const sptr<IRemoteObject> &callerToken) override;
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)83     void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) override
84     {
85         taskHandler_ = taskHandler;
86     };
87     void UnregisterObserver(const std::string &bundleName);
88 private:
89     bool CheckControl(const Want &want, int32_t userId, AppExecFwk::DisposedRule &disposedRule);
90     bool CheckDisposedRule(const Want &want, AppExecFwk::DisposedRule &disposedRule);
91     ErrCode StartNonBlockRule(const Want &want, AppExecFwk::DisposedRule &disposedRule);
92     sptr<AppExecFwk::IAppMgr> GetAppMgr();
93     ErrCode CreateModalUIExtension(const Want &want, const sptr<IRemoteObject> &callerToken);
94 private:
95     std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
96     std::map<std::string, sptr<DisposedObserver>> disposedObserverMap_;
97     ffrt::mutex observerLock_;
98 };
99 
100 class EcologicalRuleInterceptor : public AbilityInterceptor {
101 public:
102     EcologicalRuleInterceptor() = default;
103     ~EcologicalRuleInterceptor() = default;
104     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground,
105         const sptr<IRemoteObject> &callerToken) override;
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)106     virtual void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) override
107     {
108         return;
109     };
110 private:
111     void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId);
112 };
113 
114 // ability jump interceptor
115 class AbilityJumpInterceptor : public AbilityInterceptor {
116 public:
117     AbilityJumpInterceptor() = default;
118     ~AbilityJumpInterceptor() = default;
119     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground,
120         const sptr<IRemoteObject> &callerToken) override;
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)121     virtual void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) override
122     {
123         return;
124     };
125 
126 private:
127     bool CheckControl(std::shared_ptr<AppExecFwk::BundleMgrHelper> &undleMgrHelper, const Want &want, int32_t userId,
128         AppExecFwk::AppJumpControlRule &controlRule);
129     bool CheckIfJumpExempt(std::shared_ptr<AppExecFwk::BundleMgrHelper> &undleMgrHelper,
130         AppExecFwk::AppJumpControlRule &controlRule, int32_t userId);
131     bool CheckIfExemptByBundleName(std::shared_ptr<AppExecFwk::BundleMgrHelper> &undleMgrHelper,
132         const std::string &bundleName, const std::string &permission, int32_t userId);
133     bool LoadAppLabelInfo(std::shared_ptr<AppExecFwk::BundleMgrHelper> &undleMgrHelper, Want &want,
134         AppExecFwk::AppJumpControlRule &controlRule, int32_t userId);
135 };
136 } // namespace AAFwk
137 } // namespace OHOS
138 #endif // OHOS_ABILITY_RUNTIME_ABILITY_INTERCEPTOR_H
139