1 /* 2 * Copyright (c) 2022-2023 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 DIALOG_JUMP_INTERCEPTOR, 30 }; 31 enum class DialogAlign { 32 TOP = 0, 33 CENTER, 34 BOTTOM, 35 LEFT, 36 RIGHT, 37 }; 38 struct DialogPosition { 39 int32_t offsetX = 0; 40 int32_t offsetY = 0; 41 int32_t width = 0; 42 int32_t height = 0; 43 int32_t window_width = 0; 44 int32_t window_height = 0; 45 int32_t window_offsetX = 0; 46 int32_t window_offsetY = 0; 47 int32_t width_narrow = 0; 48 int32_t height_narrow = 0; 49 bool wideScreen = true; 50 bool oversizeHeight = false; 51 DialogAlign align = DialogAlign::CENTER; 52 }; 53 struct DialogAppInfo { 54 int32_t iconId = 0; 55 int32_t labelId = 0; 56 std::string bundleName = {}; 57 std::string abilityName = {}; 58 std::string moduleName = {}; 59 }; 60 /** 61 * @class SystemDialogScheduler 62 * SystemDialogScheduler. 63 */ 64 class SystemDialogScheduler : public DelayedSingleton<SystemDialogScheduler> { 65 public: 66 67 explicit SystemDialogScheduler() = default; 68 virtual ~SystemDialogScheduler() = default; 69 70 bool GetANRDialogWant(int userId, int pid, AAFwk::Want &want); 71 Want GetPcSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &targetWant, 72 const std::string &type, int32_t userId, const sptr<IRemoteObject> &callerToken); 73 Want GetSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &targetWant, 74 const sptr<IRemoteObject> &callerToken); 75 Want GetTipsDialogWant(const sptr<IRemoteObject> &callerToken); 76 Want GetJumpInterceptorDialogWant(Want &targetWant); 77 SetDeviceType(const std::string & deviceType)78 void SetDeviceType(const std::string &deviceType) 79 { 80 deviceType_ = deviceType; 81 } 82 GetDeviceType()83 const std::string GetDeviceType() 84 { 85 return deviceType_; 86 } 87 88 private: 89 const std::string GetAnrParams(const DialogPosition position, const std::string &appName) const; 90 const std::string GetSelectorParams(const std::vector<DialogAppInfo> &infos) const; 91 const std::string GetPcSelectorParams(const std::vector<DialogAppInfo> &infos, 92 const std::string &type, int32_t userId, const std::string &action) const; 93 const std::string GetDialogPositionParams(const DialogPosition position) const; 94 95 void InitDialogPosition(DialogType type, DialogPosition &position) const; 96 void GetDialogPositionAndSize(DialogType type, DialogPosition &position, int lineNums = 0) const; 97 void GetSelectorDialogPositionAndSize( 98 DialogPosition &portraitPosition, DialogPosition &landscapePosition, int lineNums) const; 99 void GetSelectorDialogLandscapePosition( 100 DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const; 101 void DialogLandscapePositionAdaptive( 102 DialogPosition &position, float densityPixels, int lineNums) const; 103 void GetSelectorDialogPortraitPosition( 104 DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const; 105 void DialogPortraitPositionAdaptive( 106 DialogPosition &position, float densityPixels, int lineNums) const; 107 void DialogPositionAdaptive(DialogPosition &position, int lineNums) const; 108 109 sptr<AppExecFwk::IBundleMgr> GetBundleManager(); 110 111 void GetAppNameFromResource(int32_t labelId, 112 const std::string &bundleName, int32_t userId, std::string &appName); 113 114 private: 115 sptr<AppExecFwk::IBundleMgr> iBundleManager_; 116 std::string deviceType_ = {}; 117 }; 118 } // namespace AAFwk 119 } // namespace OHOS 120 #endif // OHOS_ABILITY_RUNTIME_SYSTEM_DIALOG_SCHEDULER_H 121