• 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 };
38 
39 struct DialogCallerInfo {
40     int32_t userId = -1;
41     int requestCode = -1;
42     sptr<IRemoteObject> callerToken;
43     Want targetWant;
44     SelectorType type = SelectorType::WITHOUT_SELECTOR;
45     // for app gallery selector
46     bool needGrantUriPermission = false;
47 };
48 
49 struct StartupSessionInfo {
50     AbilityRequest abilityRequest;
51 };
52 
53 struct QueryERMSInfo {
54     int32_t recordId;
55     std::string appId;
56     std::string startTime;
57     bool isEmbeddedAllowed;
58 };
59 
60 class DialogSessionManager {
61 public:
62     static DialogSessionManager &GetInstance();
63     ~DialogSessionManager() = default;
64 
65     sptr<DialogSessionInfo> GetDialogSessionInfo(const std::string &dialogSessionId) const;
66 
67     std::shared_ptr<DialogCallerInfo> GetDialogCallerInfo(const std::string &dialogSessionId) const;
68 
69     std::shared_ptr<StartupSessionInfo> GetStartupSessionInfo(const std::string &dialogSessionId) const;
70 
71     int SendDialogResult(const Want &want, const std::string &dialogSessionId, bool isAllowed);
72 
73     int CreateJumpModalDialog(AbilityRequest &abilityRequest, int32_t userId, const Want &replaceWant);
74 
75     int CreateImplicitSelectorModalDialog(AbilityRequest &abilityRequest, const Want &want, int32_t userId,
76         std::vector<DialogAppInfo> &dialogAppInfos, bool needGrantUriPermission = false);
77 
78     int CreateCloneSelectorModalDialog(AbilityRequest &abilityRequest, const Want &want, int32_t userId,
79         std::vector<DialogAppInfo> &dialogAppInfos, const std::string &replaceWant);
80 
81     int HandleErmsResult(AbilityRequest &abilityRequest, int32_t userId, const Want &replaceWant);
82 
83     int32_t HandleErmsResultBySCB(AbilityRequest &abilityRequest, const Want &replaceWant);
84 
85     bool IsCreateCloneSelectorDialog(const std::string &bundleName, int32_t userId);
86 
87     bool UpdateExtensionWantWithDialogCallerInfo(AbilityRequest &abilityRequest,
88         const sptr<IRemoteObject> &callerToken, bool isSCBCall);
89 private:
90     DialogSessionManager() = default;
91     std::string GenerateDialogSessionId();
92 
93     void SetDialogSessionInfo(const std::string &dialogSessionId, sptr<DialogSessionInfo> &dilogSessionInfo,
94         std::shared_ptr<DialogCallerInfo> &dialogCallerInfo);
95 
96     void SetStartupSessionInfo(const std::string &dialogSessionId, const AbilityRequest &abilityRequest);
97 
98     int32_t NotifySCBToRecoveryAfterInterception(const std::string &dialogSessionId,
99         const AbilityRequest &abilityRequest);
100 
101     void ClearDialogContext(const std::string &dialogSessionId);
102 
103     void ClearAllDialogContexts();
104 
105     std::string GenerateDialogSessionRecordCommon(AbilityRequest &abilityRequest, int32_t userId,
106         const AAFwk::WantParams &parameters, std::vector<DialogAppInfo> &dialogAppInfos, SelectorType type,
107         bool needGrantUriPermission = false);
108 
109     void GenerateCallerAbilityInfo(AbilityRequest &abilityRequest, DialogAbilityInfo &callerAbilityInfo);
110 
111     void GenerateSelectorTargetAbilityInfos(std::vector<DialogAppInfo> &dialogAppInfos,
112         std::vector<DialogAbilityInfo> &targetAbilityInfos);
113 
114     void GenerateJumpTargetAbilityInfos(AbilityRequest &abilityRequest,
115         std::vector<DialogAbilityInfo> &targetAbilityInfos);
116 
117     void GenerateDialogCallerInfo(AbilityRequest &abilityRequest, int32_t userId,
118         std::shared_ptr<DialogCallerInfo> dialogCallerInfo, SelectorType type,
119         bool needGrantUriPermission = false);
120 
121     int CreateModalDialogCommon(const Want &replaceWant, sptr<IRemoteObject> callerToken,
122         const std::string &dialogSessionId);
123 
124     void SetQueryERMSInfo(const std::string &dialogSessionId, const AbilityRequest &abilityRequest);
125 
126     bool NotifyQueryERMSFinished(const std::string &dialogSessionId, bool isAllowed);
127 
128     mutable ffrt::mutex dialogSessionRecordLock_;
129     std::unordered_map<std::string, sptr<DialogSessionInfo>> dialogSessionInfoMap_;
130     std::unordered_map<std::string, std::shared_ptr<DialogCallerInfo>> dialogCallerInfoMap_;
131     std::unordered_map<std::string, std::shared_ptr<StartupSessionInfo>> startupSessionInfoMap_;
132 
133     ffrt::mutex queryERMSInfoLock_;
134     std::unordered_map<std::string, QueryERMSInfo> queryERMSInfoMap_;
135 
136     DISALLOW_COPY_AND_MOVE(DialogSessionManager);
137 };
138 }  // namespace AAFwk
139 }  // namespace OHOS
140 #endif // OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGEER_H
141