• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 #ifndef OHOS_ABILITY_RUNTIME_SYSTEM_DIALOG_SCHEDULER_H
16 #define OHOS_ABILITY_RUNTIME_SYSTEM_DIALOG_SCHEDULER_H
17 
18 #include <functional>
19 
20 #include "application_info.h"
21 #include "bundle_mgr_interface.h"
22 #include "singleton.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
26 enum class DialogType {
27     DIALOG_ANR = 0,
28     DIALOG_TIPS,
29     DIALOG_SELECTOR,
30     DIALOG_JUMP_INTERCEPTOR,
31 };
32 enum class DialogAlign {
33     TOP = 0,
34     CENTER,
35     BOTTOM,
36     LEFT,
37     RIGHT,
38 };
39 struct DialogPosition {
40     int32_t offsetX = 0;
41     int32_t offsetY = 0;
42     int32_t width = 0;
43     int32_t height = 0;
44     int32_t window_width = 0;
45     int32_t window_height = 0;
46     int32_t window_offsetX = 0;
47     int32_t window_offsetY = 0;
48     int32_t width_narrow = 0;
49     int32_t height_narrow = 0;
50     bool wideScreen = true;
51     bool oversizeHeight = false;
52     DialogAlign align = DialogAlign::CENTER;
53 };
54 struct DialogAppInfo {
55     int32_t abilityIconId = 0;
56     int32_t abilityLabelId = 0;
57     int32_t bundleIconId = 0;
58     int32_t bundleLabelId = 0;
59     std::string bundleName = {};
60     std::string abilityName = {};
61     std::string moduleName = {};
62     bool visible = true;
63     bool isAppLink = false;
64     int32_t appIndex = 0;
65     AppExecFwk::MultiAppModeData multiAppMode;
66 };
67 /**
68  * @class SystemDialogScheduler
69  * SystemDialogScheduler.
70  */
71 class SystemDialogScheduler : public DelayedSingleton<SystemDialogScheduler> {
72 public:
73 
74     explicit SystemDialogScheduler() = default;
75     virtual ~SystemDialogScheduler() = default;
76 
77     int GetSelectorDialogWantCommon(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant,
78         Want &targetWant, const sptr<IRemoteObject> &callerToken);
79     int GetPcSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant, Want &targetWant,
80         const std::string &type, int32_t userId, const sptr<IRemoteObject> &callerToken);
81     int GetSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant, Want &targetWant,
82         const sptr<IRemoteObject> &callerToken);
83     Want GetTipsDialogWant(const sptr<IRemoteObject> &callerToken);
84     Want GetJumpInterceptorDialogWant(Want &targetWant);
85     Want GetSwitchUserDialogWant();
86     bool GetAssertFaultDialogWant(Want &want);
87 
88 private:
89     const std::string GetSelectorParams(const std::vector<DialogAppInfo> &infos) const;
90     const std::string GetPcSelectorParams(const std::vector<DialogAppInfo> &infos,
91         const std::string &type, int32_t userId, const std::string &action) const;
92     const std::string GetDialogPositionParams(const DialogPosition position) const;
93 
94     void InitDialogPosition(DialogType type, DialogPosition &position) const;
95     void GetDialogPositionAndSize(DialogType type, DialogPosition &position, int lineNums = 0) const;
96     void GetSelectorDialogPositionAndSize(
97         DialogPosition &portraitPosition, DialogPosition &landscapePosition, int lineNums) const;
98     void GetSelectorDialogLandscapePosition(
99         DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const;
100     void DialogLandscapePositionAdaptive(
101         DialogPosition &position, float densityPixels, int lineNums) const;
102     void GetSelectorDialogPortraitPosition(
103         DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const;
104     void DialogPortraitPositionAdaptive(
105         DialogPosition &position, float densityPixels, int lineNums) const;
106     void DialogPositionAdaptive(DialogPosition &position, int lineNums) const;
107 };
108 }  // namespace AAFwk
109 }  // namespace OHOS
110 #endif  // OHOS_ABILITY_RUNTIME_SYSTEM_DIALOG_SCHEDULER_H
111