• 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 class DialogSessionManager {
54 public:
55     static DialogSessionManager &GetInstance();
56     ~DialogSessionManager() = default;
57 
58     sptr<DialogSessionInfo> GetDialogSessionInfo(const std::string &dialogSessionId) const;
59 
60     std::shared_ptr<DialogCallerInfo> GetDialogCallerInfo(const std::string &dialogSessionId) const;
61 
62     std::shared_ptr<StartupSessionInfo> GetStartupSessionInfo(const std::string &dialogSessionId) const;
63 
64     int SendDialogResult(const Want &want, const std::string &dialogSessionId, bool isAllowed);
65 
66     int CreateJumpModalDialog(AbilityRequest &abilityRequest, int32_t userId, const Want &replaceWant);
67 
68     int CreateImplicitSelectorModalDialog(AbilityRequest &abilityRequest, const Want &want, int32_t userId,
69         std::vector<DialogAppInfo> &dialogAppInfos, bool needGrantUriPermission = false);
70 
71     int CreateCloneSelectorModalDialog(AbilityRequest &abilityRequest, const Want &want, int32_t userId,
72         std::vector<DialogAppInfo> &dialogAppInfos, const std::string &replaceWant);
73 
74     int HandleErmsResult(AbilityRequest &abilityRequest, int32_t userId, const Want &replaceWant);
75 
76     int32_t HandleErmsResultBySCB(AbilityRequest &abilityRequest, const Want &replaceWant);
77 
78     bool IsCreateCloneSelectorDialog(const std::string &bundleName, int32_t userId);
79 
80     bool UpdateExtensionWantWithDialogCallerInfo(AbilityRequest &abilityRequest,
81         const sptr<IRemoteObject> &callerToken, bool isSCBCall);
82 private:
83     DialogSessionManager() = default;
84     std::string GenerateDialogSessionId();
85 
86     void SetDialogSessionInfo(const std::string &dialogSessionId, sptr<DialogSessionInfo> &dilogSessionInfo,
87         std::shared_ptr<DialogCallerInfo> &dialogCallerInfo);
88 
89     void SetStartupSessionInfo(const std::string &dialogSessionId, const AbilityRequest &abilityRequest);
90 
91     int32_t NotifySCBToRecoveryAfterInterception(const std::string &dialogSessionId,
92         const AbilityRequest &abilityRequest);
93 
94     void ClearDialogContext(const std::string &dialogSessionId);
95 
96     void ClearAllDialogContexts();
97 
98     std::string GenerateDialogSessionRecordCommon(AbilityRequest &abilityRequest, int32_t userId,
99         const AAFwk::WantParams &parameters, std::vector<DialogAppInfo> &dialogAppInfos, SelectorType type,
100         bool needGrantUriPermission = false);
101 
102     void GenerateCallerAbilityInfo(AbilityRequest &abilityRequest, DialogAbilityInfo &callerAbilityInfo);
103 
104     void GenerateSelectorTargetAbilityInfos(std::vector<DialogAppInfo> &dialogAppInfos,
105         std::vector<DialogAbilityInfo> &targetAbilityInfos);
106 
107     void GenerateJumpTargetAbilityInfos(AbilityRequest &abilityRequest,
108         std::vector<DialogAbilityInfo> &targetAbilityInfos);
109 
110     void GenerateDialogCallerInfo(AbilityRequest &abilityRequest, int32_t userId,
111         std::shared_ptr<DialogCallerInfo> dialogCallerInfo, SelectorType type,
112         bool needGrantUriPermission = false);
113 
114     int CreateModalDialogCommon(const Want &replaceWant, sptr<IRemoteObject> callerToken,
115         const std::string &dialogSessionId);
116 
117     mutable ffrt::mutex dialogSessionRecordLock_;
118     std::unordered_map<std::string, sptr<DialogSessionInfo>> dialogSessionInfoMap_;
119     std::unordered_map<std::string, std::shared_ptr<DialogCallerInfo>> dialogCallerInfoMap_;
120     std::unordered_map<std::string, std::shared_ptr<StartupSessionInfo>> startupSessionInfoMap_;
121 
122     DISALLOW_COPY_AND_MOVE(DialogSessionManager);
123 };
124 }  // namespace AAFwk
125 }  // namespace OHOS
126 #endif // OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGEER_H
127