• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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_DIALOG_SESSION_MANAGEER_H
17 #define OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGEER_H
18 #include <list>
19 #include <unordered_map>
20 #include <string>
21 #include "ability_record.h"
22 #include "cpp/mutex.h"
23 #include "dialog_session_info.h"
24 #include "json_serializer.h"
25 #include "nocopyable.h"
26 #include "parcel.h"
27 #include "refbase.h"
28 #include "system_dialog_scheduler.h"
29 #include "want.h"
30 
31 namespace OHOS {
32 namespace AAFwk {
33 enum class SelectorType {
34     WITHOUT_SELECTOR = -1,
35     IMPLICIT_START_SELECTOR = 0,
36     APP_CLONE_SELECTOR = 1,
37     INTERCEPTOR_SELECTOR = 2
38 };
39 
40 struct DialogCallerInfo {
41     int32_t userId = -1;
42     int requestCode = -1;
43     sptr<IRemoteObject> callerToken;
44     Want targetWant;
45     SelectorType type = SelectorType::WITHOUT_SELECTOR;
46     // for app gallery selector
47     bool needGrantUriPermission = false;
48 };
49 
50 struct StartupSessionInfo {
51     AbilityRequest abilityRequest;
52 };
53 
54 struct QueryERMSInfo {
55     int32_t recordId;
56     std::string appId;
57     std::string startTime;
58     bool isEmbeddedAllowed;
59 };
60 
61 class DialogSessionManager {
62 public:
63     static DialogSessionManager &GetInstance();
64     ~DialogSessionManager() = default;
65 
66     sptr<DialogSessionInfo> GetDialogSessionInfo(const std::string &dialogSessionId) const;
67 
68     std::shared_ptr<DialogCallerInfo> GetDialogCallerInfo(const std::string &dialogSessionId) const;
69 
70     std::shared_ptr<StartupSessionInfo> GetStartupSessionInfo(const std::string &dialogSessionId) const;
71 
72     int SendDialogResult(const Want &want, const std::string &dialogSessionId, bool isAllowed);
73 
74     int CreateJumpModalDialog(AbilityRequest &abilityRequest, int32_t userId, const Want &replaceWant);
75 
76     int CreateImplicitSelectorModalDialog(AbilityRequest &abilityRequest, const Want &want, int32_t userId,
77         std::vector<DialogAppInfo> &dialogAppInfos, bool needGrantUriPermission = false);
78 
79     int CreateCloneSelectorModalDialog(AbilityRequest &abilityRequest, const Want &want, int32_t userId,
80         std::vector<DialogAppInfo> &dialogAppInfos, const std::string &replaceWant);
81 
82     int HandleErmsResult(AbilityRequest &abilityRequest, int32_t userId, const Want &replaceWant);
83 
84     int32_t HandleErmsResultBySCB(AbilityRequest &abilityRequest, const Want &replaceWant);
85 
86     bool IsCreateCloneSelectorDialog(const std::string &bundleName, int32_t userId);
87 
88     bool UpdateExtensionWantWithDialogCallerInfo(AbilityRequest &abilityRequest,
89         const sptr<IRemoteObject> &callerToken, bool isSCBCall);
90 
91     std::string GenerateDialogSessionId();
92 
93     void OnlySetDialogCallerInfo(AbilityRequest &abilityRequest, int32_t userId, SelectorType type,
94         const std::string &dialogSessionId, bool needGrantUriPermission);
95 private:
96     DialogSessionManager() = default;
97 
98     void SetDialogSessionInfo(const std::string &dialogSessionId, sptr<DialogSessionInfo> &dilogSessionInfo,
99         std::shared_ptr<DialogCallerInfo> &dialogCallerInfo);
100 
101     void SetStartupSessionInfo(const std::string &dialogSessionId, const AbilityRequest &abilityRequest);
102 
103     int32_t NotifySCBToRecoveryAfterInterception(const std::string &dialogSessionId,
104         const AbilityRequest &abilityRequest);
105 
106     void ClearDialogContext(const std::string &dialogSessionId);
107 
108     void ClearAllDialogContexts();
109 
110     std::string GenerateDialogSessionRecordCommon(AbilityRequest &abilityRequest, int32_t userId,
111         const AAFwk::WantParams &parameters, std::vector<DialogAppInfo> &dialogAppInfos, SelectorType type,
112         bool needGrantUriPermission = false);
113 
114     void GenerateCallerAbilityInfo(AbilityRequest &abilityRequest, DialogAbilityInfo &callerAbilityInfo);
115 
116     void GenerateSelectorTargetAbilityInfos(std::vector<DialogAppInfo> &dialogAppInfos,
117         std::vector<DialogAbilityInfo> &targetAbilityInfos);
118 
119     void GenerateJumpTargetAbilityInfos(AbilityRequest &abilityRequest,
120         std::vector<DialogAbilityInfo> &targetAbilityInfos);
121 
122     void GenerateDialogCallerInfo(AbilityRequest &abilityRequest, int32_t userId,
123         std::shared_ptr<DialogCallerInfo> dialogCallerInfo, SelectorType type,
124         bool needGrantUriPermission = false);
125 
126     int CreateModalDialogCommon(const Want &replaceWant, sptr<IRemoteObject> callerToken,
127         const std::string &dialogSessionId);
128 
129     void SetQueryERMSInfo(const std::string &dialogSessionId, const AbilityRequest &abilityRequest);
130 
131     bool NotifyQueryERMSFinished(const std::string &dialogSessionId, bool isAllowed);
132 
133     void NotifyAbilityRequestFailure(const std::string &dialogSessionId, const Want &want);
134 
135     mutable ffrt::mutex dialogSessionRecordLock_;
136     std::unordered_map<std::string, sptr<DialogSessionInfo>> dialogSessionInfoMap_;
137     std::unordered_map<std::string, std::shared_ptr<DialogCallerInfo>> dialogCallerInfoMap_;
138     std::unordered_map<std::string, std::shared_ptr<StartupSessionInfo>> startupSessionInfoMap_;
139 
140     ffrt::mutex queryERMSInfoLock_;
141     std::unordered_map<std::string, QueryERMSInfo> queryERMSInfoMap_;
142 
143     DISALLOW_COPY_AND_MOVE(DialogSessionManager);
144 };
145 }  // namespace AAFwk
146 }  // namespace OHOS
147 #endif // OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGEER_H
148