1 /* 2 * Copyright (c) 2022 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 "bundle_mgr_interface.h" 21 #include "singleton.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 enum class DialogType { 26 DIALOG_ANR = 0, 27 DIALOG_TIPS, 28 DIALOG_SELECTOR, 29 }; 30 enum class DialogAlign { 31 TOP = 0, 32 CENTER, 33 BOTTOM, 34 LEFT, 35 RIGHT, 36 }; 37 struct DialogPosition { 38 int32_t offsetX = 0; 39 int32_t offsetY = 0; 40 int32_t width = 0; 41 int32_t height = 0; 42 int32_t window_width = 0; 43 int32_t window_height = 0; 44 int32_t window_offsetX = 0; 45 int32_t window_offsetY = 0; 46 int32_t width_narrow = 0; 47 int32_t height_narrow = 0; 48 bool wideScreen = true; 49 DialogAlign align = DialogAlign::CENTER; 50 }; 51 struct DialogAppInfo { 52 int32_t iconId = 0; 53 int32_t labelId = 0; 54 std::string bundleName = {}; 55 std::string abilityName = {}; 56 std::string moduleName = {}; 57 }; 58 /** 59 * @class SystemDialogScheduler 60 * SystemDialogScheduler. 61 */ 62 class SystemDialogScheduler : public DelayedSingleton<SystemDialogScheduler> { 63 public: 64 65 explicit SystemDialogScheduler() = default; 66 virtual ~SystemDialogScheduler() = default; 67 68 bool GetANRDialogWant(int userId, int pid, AAFwk::Want &want); 69 Want GetSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &targetWant); 70 Want GetTipsDialogWant(); 71 SetDeviceType(const std::string & deviceType)72 void SetDeviceType(const std::string &deviceType) 73 { 74 deviceType_ = deviceType; 75 } 76 77 private: 78 const std::string GetAnrParams(const DialogPosition position, const std::string &appName) const; 79 const std::string GetSelectorParams(const std::vector<DialogAppInfo> &infos) const; 80 const std::string GetDialogPositionParams(const DialogPosition position) const; 81 82 void InitDialogPosition(DialogType type, DialogPosition &position) const; 83 void GetDialogPositionAndSize(DialogType type, DialogPosition &position, int lineNums = 0) const; 84 void DialogPositionAdaptive(DialogPosition &position, int lineNums) const; 85 86 sptr<AppExecFwk::IBundleMgr> GetBundleManager(); 87 88 void GetAppNameFromResource(int32_t labelId, 89 const std::string &bundleName, int32_t userId, std::string &appName); 90 91 private: 92 sptr<AppExecFwk::IBundleMgr> iBundleManager_; 93 std::string deviceType_ = {}; 94 }; 95 } // namespace AAFwk 96 } // namespace OHOS 97 #endif // OHOS_ABILITY_RUNTIME_SYSTEM_DIALOG_SCHEDULER_H 98