• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int32_t userId = -1;
34     int requestCode = 0;
35     bool isStartAsCaller = false;
36     const StartOptions* startOptions = nullptr;
37 
GetValidUserIdStartAbilityParams38     int32_t GetValidUserId()
39     {
40         return validUserId;
41     }
SetValidUserIdStartAbilityParams42     void SetValidUserId(int32_t value)
43     {
44         validUserId = value;
45     }
46     bool IsCallerSandboxApp();
47     bool OtherAppsAccessDlp();
48     bool DlpAccessOtherApps();
49     bool SandboxExternalAuth();
50     bool IsCallerSysApp();
51     std::shared_ptr<AbilityRecord> GetCallerRecord();
52     int32_t GetCallerAppIndex();
53 
54     EventInfo BuildEventInfo();
55 private:
56     int32_t validUserId = 0;
57     std::optional<bool> otherAppsAccessDlp;
58     std::optional<bool> dlpAccessOtherApps;
59     std::optional<bool> sandboxExternalAuth;
60     std::optional<bool> isCallerSysApp;
61     std::optional<std::shared_ptr<AbilityRecord>> callerRecord;
62     std::optional<int32_t> callerAppIndex;
63 };
64 
65 class StartAbilityHandler {
66 public:
67     StartAbilityHandler() = default;
68     StartAbilityHandler(StartAbilityHandler &) = delete;
69     void operator=(StartAbilityHandler &) = delete;
70     virtual ~StartAbilityHandler() = default;
71     virtual bool MatchStartRequest(StartAbilityParams &params);
72     virtual int HandleStartRequest(StartAbilityParams &params);
GetPriority()73     virtual int GetPriority()
74     {
75         return 0;
76     }
GetHandlerName()77     virtual std::string GetHandlerName()
78     {
79         return "";
80     }
81 };
82 } // namespace AAFwk
83 } // namespace OHOS
84 #endif // OHOS_ABILITY_RUNTIME_START_ABILITY_HANDLER_H