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     int32_t appIndex = 0;
64     AppExecFwk::MultiAppModeData multiAppMode;
65 };
66 /**
67  * @class SystemDialogScheduler
68  * SystemDialogScheduler.
69  */
70 class SystemDialogScheduler : public DelayedSingleton<SystemDialogScheduler> {
71 public:
72 
73     explicit SystemDialogScheduler() = default;
74     virtual ~SystemDialogScheduler() = default;
75 
76     int GetSelectorDialogWantCommon(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant,
77         Want &targetWant, const sptr<IRemoteObject> &callerToken);
78     int GetPcSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant, Want &targetWant,
79         const std::string &type, int32_t userId, const sptr<IRemoteObject> &callerToken);
80     int GetSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant, Want &targetWant,
81         const sptr<IRemoteObject> &callerToken);
82     Want GetTipsDialogWant(const sptr<IRemoteObject> &callerToken);
83     Want GetJumpInterceptorDialogWant(Want &targetWant);
84     Want GetSwitchUserDialogWant();
85     bool GetAssertFaultDialogWant(Want &want);
86 
87 private:
88     const std::string GetSelectorParams(const std::vector<DialogAppInfo> &infos) const;
89     const std::string GetPcSelectorParams(const std::vector<DialogAppInfo> &infos,
90         const std::string &type, int32_t userId, const std::string &action) const;
91     const std::string GetDialogPositionParams(const DialogPosition position) const;
92 
93     void InitDialogPosition(DialogType type, DialogPosition &position) const;
94     void GetDialogPositionAndSize(DialogType type, DialogPosition &position, int lineNums = 0) const;
95     void GetSelectorDialogPositionAndSize(
96         DialogPosition &portraitPosition, DialogPosition &landscapePosition, int lineNums) const;
97     void GetSelectorDialogLandscapePosition(
98         DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const;
99     void DialogLandscapePositionAdaptive(
100         DialogPosition &position, float densityPixels, int lineNums) const;
101     void GetSelectorDialogPortraitPosition(
102         DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const;
103     void DialogPortraitPositionAdaptive(
104         DialogPosition &position, float densityPixels, int lineNums) const;
105     void DialogPositionAdaptive(DialogPosition &position, int lineNums) const;
106 };
107 }  // namespace AAFwk
108 }  // namespace OHOS
109 #endif  // OHOS_ABILITY_RUNTIME_SYSTEM_DIALOG_SCHEDULER_H
110