• 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 #ifdef SUPPORT_ERMS
21 #include "ecological_rule_mgr_service_client.h"
22 #else
23 #include "erms_mgr_param.h"
24 #include "erms_mgr_interface.h"
25 #endif
26 #include "in_process_call_wrapper.h"
27 #include "want.h"
28 
29 namespace OHOS {
30 namespace AAFwk {
31 #ifdef SUPPORT_ERMS
32 using ErmsCallerInfo = OHOS::EcologicalRuleMgrService::CallerInfo;
33 using ExperienceRule = OHOS::EcologicalRuleMgrService::ExperienceRule;
34 #else
35 using ErmsCallerInfo = OHOS::AppExecFwk::ErmsParams::CallerInfo;
36 using ExperienceRule = OHOS::AppExecFwk::ErmsParams::ExperienceRule;
37 #endif
38 
39 class AbilityInterceptor {
40 public:
41     virtual ~AbilityInterceptor();
42 
43     /**
44      * Excute interception processing.
45      */
46     virtual ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground) = 0;
47 };
48 
49 // start ability interceptor
50 class CrowdTestInterceptor : public AbilityInterceptor {
51 public:
52     CrowdTestInterceptor();
53     ~CrowdTestInterceptor();
54     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground) override;
55 private:
56     bool CheckCrowdtest(const Want &want, int32_t userId);
57 };
58 
59 class ControlInterceptor : public AbilityInterceptor {
60 public:
61     ControlInterceptor();
62     ~ControlInterceptor();
63     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground) override;
64 private:
65     bool CheckControl(const Want &want, int32_t userId, AppExecFwk::AppRunningControlRuleResult &controlRule);
66 };
67 
68 class EcologicalRuleInterceptor : public AbilityInterceptor {
69 public:
70     EcologicalRuleInterceptor();
71     ~EcologicalRuleInterceptor();
72     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground) override;
73 private:
74 #ifdef SUPPORT_ERMS
75     void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId);
76 #else
77     bool CheckRule(const Want &want, ErmsCallerInfo &callerInfo, ExperienceRule &rule);
78 #endif
79 };
80 
81 // ability jump interceptor
82 class AbilityJumpInterceptor : public AbilityInterceptor {
83 public:
84     AbilityJumpInterceptor();
85     ~AbilityJumpInterceptor();
86     ErrCode DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground) override;
87 
88 private:
89     bool CheckControl(sptr<AppExecFwk::IBundleMgr> &bms, const Want &want, int32_t userId,
90         AppExecFwk::AppJumpControlRule &controlRule);
91     bool CheckIfJumpExempt(sptr<AppExecFwk::IBundleMgr> &bms, AppExecFwk::AppJumpControlRule &controlRule,
92         int32_t userId);
93     bool CheckIfExemptByBundleName(sptr<AppExecFwk::IBundleMgr> &bms, const std::string &bundleName,
94         const std::string &permission, int32_t userId);
95     bool LoadAppLabelInfo(sptr<AppExecFwk::IBundleMgr> &bms, Want &want, AppExecFwk::AppJumpControlRule &controlRule,
96         int32_t userId);
97 };
98 } // namespace AAFwk
99 } // namespace OHOS
100 #endif // OHOS_ABILITY_RUNTIME_ABILITY_INTERCEPTOR_H
101