1 /*
2  * Copyright (c) 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 #ifndef OHOS_ABILITY_RUNTIME_START_ABILITY_HANDLER_H
17 #define OHOS_ABILITY_RUNTIME_START_ABILITY_HANDLER_H
18 #include <memory>
19 #include <optional>
20 
21 #include "ability_record.h"
22 #include "event_report.h"
23 #include "want.h"
24 #include "refbase.h"
25 
26 namespace OHOS {
27 class IRemoteObject;
28 namespace AAFwk {
29 struct StartAbilityParams {
StartAbilityParamsStartAbilityParams30     StartAbilityParams(Want &reqWant) : want(reqWant) {}
31     Want &want;
32     sptr<IRemoteObject> callerToken;
33     sptr<IRemoteObject> asCallerSourceToken;
34     int32_t userId = -1;
35     int requestCode = 0;
36     bool isStartAsCaller = false;
37     const StartOptions* startOptions = nullptr;
38 
GetValidUserIdStartAbilityParams39     int32_t GetValidUserId()
40     {
41         return validUserId;
42     }
SetValidUserIdStartAbilityParams43     void SetValidUserId(int32_t value)
44     {
45         validUserId = value;
46     }
47     bool IsCallerSandboxApp();
48 
49 #ifdef WITH_DLP
50     bool OtherAppsAccessDlp();
51     bool DlpAccessOtherApps();
52     bool SandboxExternalAuth();
53 #endif // WITH_DLP
54     bool IsCallerSysApp();
55     std::shared_ptr<AbilityRecord> GetCallerRecord();
56     int32_t GetCallerAppIndex();
57 
58     EventInfo BuildEventInfo();
59 private:
60     int32_t validUserId = 0;
61 #ifdef WITH_DLP
62     std::optional<bool> otherAppsAccessDlp;
63     std::optional<bool> dlpAccessOtherApps;
64 #endif // WITH_DLP
65     std::optional<bool> sandboxExternalAuth;
66     std::optional<bool> isCallerSysApp;
67     std::optional<std::shared_ptr<AbilityRecord>> callerRecord;
68     std::optional<int32_t> callerAppIndex;
69 };
70 
71 class StartAbilityHandler {
72 public:
73     StartAbilityHandler() = default;
74     StartAbilityHandler(StartAbilityHandler &) = delete;
75     void operator=(StartAbilityHandler &) = delete;
76     virtual ~StartAbilityHandler() = default;
77     virtual bool MatchStartRequest(StartAbilityParams &params);
78     virtual int HandleStartRequest(StartAbilityParams &params);
GetPriority()79     virtual int GetPriority()
80     {
81         return 0;
82     }
GetHandlerName()83     virtual std::string GetHandlerName()
84     {
85         return "";
86     }
87 };
88 } // namespace AAFwk
89 } // namespace OHOS
90 #endif // OHOS_ABILITY_RUNTIME_START_ABILITY_HANDLER_H