• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_INTERFACE_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_INTERCEPTOR_INTERFACE_H
18 
19 #include "ability_info.h"
20 #include "ability_manager_errors.h"
21 #include "want.h"
22 #include "task_handler_wrap.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
26 struct AbilityInterceptorParam {
AbilityInterceptorParamAbilityInterceptorParam27     AbilityInterceptorParam(const Want &want, int requestCode, int32_t userId, bool isWithUI,
28         const sptr<IRemoteObject> &callerToken, const std::function<bool(void)> &shouldBlockAllAppStartFunc)
29         : want(want), requestCode(requestCode), userId(userId),
30         isWithUI(isWithUI), callerToken(callerToken), shouldBlockAllAppStartFunc_(shouldBlockAllAppStartFunc){};
31     AbilityInterceptorParam(const Want &want, int requestCode, int32_t userId, bool isWithUI,
32         const sptr<IRemoteObject> &callerToken, const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo,
wantAbilityInterceptorParam33         bool isStartAsCaller = false, int32_t appIndex = 0) : want(want),
34         requestCode(requestCode), userId(userId), isWithUI(isWithUI), callerToken(callerToken),
35         abilityInfo(abilityInfo), isStartAsCaller(isStartAsCaller), appIndex(appIndex){};
36     const Want &want;
37     int32_t requestCode;
38     int32_t userId;
39     bool isWithUI = false;
40     const sptr<IRemoteObject> &callerToken;
41     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo;  // target abilityInfo get in afterCheckExecuter_
42     bool isStartAsCaller = false;
43     int32_t appIndex = 0;
44     std::function<bool(void)> shouldBlockAllAppStartFunc_;
45 };
46 
47 /**
48  * @class IAbilityInterceptor
49  * IAbilityInterceptor is used to intercept a different type of start request.
50  */
51 class IAbilityInterceptor {
52 public:
53     virtual ~IAbilityInterceptor() = default;
54 
55     /**
56      * Excute interception processing.
57      */
58     virtual ErrCode DoProcess(AbilityInterceptorParam param) = 0;
59 
60     /**
61      * Set handler for async task executing.
62      */
SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)63     virtual void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) {};
64 };
65 } // namespace AAFwk
66 } // namespace OHOS
67 #endif // OHOS_ABILITY_RUNTIME_ABILITY_INTERCEPTOR_INTERFACE_H