• 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_INSIGHT_INTENT_EXECUTE_MANAGER_H
17 #define OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_MANAGER_H
18 
19 #include <map>
20 #include "ability_connect_callback_stub.h"
21 #include "cpp/mutex.h"
22 #include "event_report.h"
23 #include "extract_insight_intent_profile.h"
24 #include "insight_intent_execute_param.h"
25 #include "insight_intent_execute_result.h"
26 #include "iremote_object.h"
27 #include "singleton.h"
28 
29 namespace OHOS {
30 namespace AAFwk {
31 enum class InsightIntentExecuteState {
32     UNKNOWN = 0,
33     EXECUTING,
34     EXECUTE_DONE,
35     REMOTE_DIED
36 };
37 
38 struct InsightIntentExecuteRecord {
39     InsightIntentExecuteState state = InsightIntentExecuteState::UNKNOWN;
40     uint64_t key = 0;
41     sptr<IRemoteObject> callerToken = nullptr;
42     sptr<IRemoteObject::DeathRecipient> deathRecipient = nullptr;
43     std::string bundleName;
44     std::string callerBundleName;
45 };
46 
47 class InsightIntentExecuteConnection : public AbilityConnectionStub {
48 public:
49     InsightIntentExecuteConnection() = default;
50 
51     ~InsightIntentExecuteConnection() override = default;
52 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)53     void OnAbilityConnectDone(
54         const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override
55     {}
56 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)57     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override
58     {}
59 };
60 
61 class InsightIntentExecuteRecipient : public IRemoteObject::DeathRecipient {
62 public:
InsightIntentExecuteRecipient(uint64_t intentId)63     explicit InsightIntentExecuteRecipient(uint64_t intentId) : intentId_(intentId)
64     {}
65 
66     ~InsightIntentExecuteRecipient() override = default;
67 
68     void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
69 
70 private:
71     uint64_t intentId_ = 0;
72 };
73 
74 class InsightIntentExecuteManager : public std::enable_shared_from_this<InsightIntentExecuteManager> {
75 DECLARE_DELAYED_SINGLETON(InsightIntentExecuteManager)
76 public:
77     int32_t CheckAndUpdateParam(uint64_t key, const sptr<IRemoteObject> &callerToken,
78         const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param, std::string callerBundleName = "",
79         const bool ignoreAbilityName = false);
80 
81     int32_t CheckAndUpdateWant(Want &want, AppExecFwk::ExecuteMode executeMode, std::string callerBundleName = "");
82 
83     int32_t RemoveExecuteIntent(uint64_t intentId);
84 
85     int32_t ExecuteIntentDone(uint64_t intentId, int32_t resultCode,
86         const AppExecFwk::InsightIntentExecuteResult &result);
87 
88     int32_t RemoteDied(uint64_t intentId);
89 
90     int32_t GetBundleName(uint64_t intentId, std::string &bundleName) const;
91 
92     int32_t GetCallerBundleName(uint64_t intentId, std::string &callerBundleName) const;
93 
94     static int32_t GenerateWant(const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param,
95         const AbilityRuntime::ExtractInsightIntentGenericInfo &decoratorInfo,
96         Want &want);
97 
98     std::map<int32_t, int64_t> GetAllIntentExemptionInfo() const;
99 
100     void SetIntentExemptionInfo(int32_t uid);
101 
102     bool CheckIntentIsExemption(int32_t uid);
103 
104     static int32_t CheckCallerPermission();
105 
106     static int32_t CheckGetInsightIntenInfoPermission();
107 private:
108     mutable ffrt::mutex mutex_;
109     mutable ffrt::mutex intentExemptionLock_;
110     uint64_t intentIdCount_ = 0;
111     std::map<uint64_t, std::shared_ptr<InsightIntentExecuteRecord>> records_;
112     std::map<int32_t, int64_t> intentExemptionDeadlineTime_;
113 
114     int32_t AddRecord(uint64_t key, const sptr<IRemoteObject> &callerToken, const std::string &bundleName,
115         uint64_t &intentId, const std::string &callerBundleName);
116 
117     static int32_t IsValidCall(const Want &want);
118 
119     static int32_t AddWantUirsAndFlagsFromParam(
120         const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param, Want &want);
121     static int32_t CheckAndUpdateDecoratorParams(
122         const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param,
123         const AbilityRuntime::ExtractInsightIntentGenericInfo &decoratorInfo,
124         Want &want);
125     static int32_t UpdateFuncDecoratorParams(const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param,
126         AbilityRuntime::ExtractInsightIntentInfo &info, Want &want);
127     static int32_t UpdatePageDecoratorParams(const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param,
128         AbilityRuntime::ExtractInsightIntentInfo &info, Want &want);
129     static int32_t UpdateEntryDecoratorParams(const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param,
130         AbilityRuntime::ExtractInsightIntentInfo &info, Want &want);
131     static int32_t UpdateEntryDecoratorParams(Want &want, AppExecFwk::ExecuteMode executeMode);
132     static std::string GetMainElementName(const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param);
133 
134     void SendIntentReport(EventInfo &eventInfo, int32_t errCode);
135 };
136 } // namespace AAFwk
137 } // namespace OHOS
138 #endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTE_MANAGER_H
139