1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci#include "system_dialog_scheduler.h" 16eace7efcSopenharmony_ci 17eace7efcSopenharmony_ci#include "ability_record.h" 18eace7efcSopenharmony_ci#include "ability_util.h" 19eace7efcSopenharmony_ci#include "app_utils.h" 20eace7efcSopenharmony_ci#include "application_util.h" 21eace7efcSopenharmony_ci#include "display_info.h" 22eace7efcSopenharmony_ci#include "display_manager.h" 23eace7efcSopenharmony_ci#include "hitrace_meter.h" 24eace7efcSopenharmony_ci#include "scene_board_judgement.h" 25eace7efcSopenharmony_ci#include "ui_extension_utils.h" 26eace7efcSopenharmony_ci 27eace7efcSopenharmony_cinamespace OHOS { 28eace7efcSopenharmony_cinamespace AAFwk { 29eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_WIDTH = 328 * 2; 30eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_HEIGHT = 350 * 2; 31eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_HEIGHT_NARROW = 350 * 2; 32eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_WIDTH_NARROW = 328 * 2; 33eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PHONE_H1 = 240 * 2; 34eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PHONE_H2 = 340 * 2; 35eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PHONE_H3 = 350 * 2; 36eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PC_H0 = 1; 37eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PC_H2 = (64 * 2 + 56 + 48 + 54 + 64 + 48 + 2) * 2; 38eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PC_H3 = (64 * 3 + 56 + 48 + 54 + 64 + 48 + 2) * 2; 39eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PC_H4 = (64 * 4 + 56 + 48 + 54 + 64 + 48 + 2) * 2; 40eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_DIALOG_PC_H5 = (64 * 4 + 56 + 48 + 54 + 64 + 48 + 58 + 2) * 2; 41eace7efcSopenharmony_ci 42eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_PORTRAIT_PHONE_H1 = 280; 43eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_PORTRAIT_PHONE_H2 = 400; 44eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_PORTRAIT_PHONE_H3 = 410; 45eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_SIGNAL_BAR = 24; 46eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_HEIGHT = 350; 47eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_HEIGHT_NARROW = 350; 48eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_PHONE_H1 = 280; 49eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_PHONE_H2 = 400; 50eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_PHONE_H3 = 410; 51eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_COUNT_THREE = 3; 52eace7efcSopenharmony_ciconst int32_t UI_SELECTOR_LANDSCAPE_COUNT_FOUR = 4; 53eace7efcSopenharmony_ciconst float UI_SELECTOR_LANDSCAPE_GRILLE_LARGE = 0.107692; 54eace7efcSopenharmony_ciconst float UI_SELECTOR_LANDSCAPE_GRILLE_SAMLL = 0.015385; 55eace7efcSopenharmony_ciconst float UI_SELECTOR_LANDSCAPE_MAX_RATIO = 0.9; 56eace7efcSopenharmony_ciconst float UI_SELECTOR_PORTRAIT_WIDTH_RATIO = 0.8; 57eace7efcSopenharmony_ciconst float UI_SELECTOR_PORTRAIT_WIDTH_EDGE_RATIO = 0.1; 58eace7efcSopenharmony_ciconst float UI_SELECTOR_PORTRAIT_HEIGHT_RATIO = 0.98; 59eace7efcSopenharmony_ci 60eace7efcSopenharmony_ciconst int32_t UI_TIPS_DIALOG_WIDTH = 328 * 2; 61eace7efcSopenharmony_ciconst int32_t UI_TIPS_DIALOG_HEIGHT = 135 * 2; 62eace7efcSopenharmony_ciconst int32_t UI_TIPS_DIALOG_HEIGHT_NARROW = 135 * 2; 63eace7efcSopenharmony_ciconst int32_t UI_TIPS_DIALOG_WIDTH_NARROW = 328 * 2; 64eace7efcSopenharmony_ci 65eace7efcSopenharmony_ciconst int32_t UI_JUMP_INTERCEPTOR_DIALOG_WIDTH = 328 * 2; 66eace7efcSopenharmony_ciconst int32_t UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT = 135 * 2; 67eace7efcSopenharmony_ciconst int32_t UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT_NARROW = 135 * 2; 68eace7efcSopenharmony_ciconst int32_t UI_JUMP_INTERCEPTOR_DIALOG_WIDTH_NARROW = 328 * 2; 69eace7efcSopenharmony_ci 70eace7efcSopenharmony_ciconst int32_t UI_ANR_DIALOG_WIDTH = 328 * 2; 71eace7efcSopenharmony_ciconst int32_t UI_ANR_DIALOG_HEIGHT = 192 * 2; 72eace7efcSopenharmony_ciconst std::string APP_NAME = "appName"; 73eace7efcSopenharmony_ciconst std::string IS_DEFAULT_SELECTOR = "isDefaultSelector"; 74eace7efcSopenharmony_ciconst std::string OFF_SET_X = "offsetX"; 75eace7efcSopenharmony_ciconst std::string OFF_SET_Y = "offsetY"; 76eace7efcSopenharmony_ciconst std::string WIDTH = "width"; 77eace7efcSopenharmony_ciconst std::string HEIGHT = "height"; 78eace7efcSopenharmony_ciconst std::string MODEL_FLAG = "modelFlag"; 79eace7efcSopenharmony_ciconst std::string ACTION = "action"; 80eace7efcSopenharmony_ciconst std::string OVERSIZE_HEIGHT = "oversizeHeight"; 81eace7efcSopenharmony_ci 82eace7efcSopenharmony_ciconst int32_t UI_HALF = 2; 83eace7efcSopenharmony_ciconst int32_t UI_DEFAULT_BUTTOM_CLIP = 100; 84eace7efcSopenharmony_ciconst int32_t UI_WIDTH_780DP = 1560; 85eace7efcSopenharmony_ciconst int32_t UI_DEFAULT_WIDTH = 2560; 86eace7efcSopenharmony_ciconst int32_t UI_DEFAULT_HEIGHT = 1600; 87eace7efcSopenharmony_ci 88eace7efcSopenharmony_ciconst std::string STR_PHONE = "phone"; 89eace7efcSopenharmony_ciconst std::string STR_DEFAULT = "default"; 90eace7efcSopenharmony_ciconst std::string DIALOG_NAME_ANR = "dialog_anr_service"; 91eace7efcSopenharmony_ciconst std::string DIALOG_NAME_TIPS = "dialog_tips_service"; 92eace7efcSopenharmony_ciconst std::string DIALOG_SELECTOR_NAME = "dialog_selector_service"; 93eace7efcSopenharmony_ciconst std::string DIALOG_JUMP_INTERCEPTOR_NAME = "dialog_jump_interceptor_service"; 94eace7efcSopenharmony_ci 95eace7efcSopenharmony_ciconst std::string BUNDLE_NAME = "bundleName"; 96eace7efcSopenharmony_ciconst std::string BUNDLE_NAME_DIALOG = "com.ohos.amsdialog"; 97eace7efcSopenharmony_ciconst std::string DIALOG_PARAMS = "params"; 98eace7efcSopenharmony_ciconst std::string DIALOG_POSITION = "position"; 99eace7efcSopenharmony_ciconst std::string VERTICAL_SCREEN_DIALOG_POSITION = "landscapeScreen"; 100eace7efcSopenharmony_ciconst std::string ABILITY_NAME_FREEZE_DIALOG = "SwitchUserDialog"; 101eace7efcSopenharmony_ciconst std::string ABILITY_NAME_ASSERT_FAULT_DIALOG = "AssertFaultDialog"; 102eace7efcSopenharmony_ciconst std::string ABILITY_NAME_TIPS_DIALOG = "TipsDialog"; 103eace7efcSopenharmony_ciconst std::string ABILITY_NAME_SELECTOR_DIALOG = "SelectorDialog"; 104eace7efcSopenharmony_ciconst std::string ABILITY_NAME_APPGALLERY_SELECTOR_DIALOG = "AppSelectorExtensionAbility"; 105eace7efcSopenharmony_ciconst std::string UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; 106eace7efcSopenharmony_ciconst std::string UIEXTENSION_SYS_COMMON_UI = "sys/commonUI"; 107eace7efcSopenharmony_ciconst std::string CALLER_TOKEN = "callerToken"; 108eace7efcSopenharmony_ciconst std::string ABILITY_NAME_JUMP_INTERCEPTOR_DIALOG = "JumpInterceptorDialog"; 109eace7efcSopenharmony_ciconst std::string TYPE_ONLY_MATCH_WILDCARD = "reserved/wildcard"; 110eace7efcSopenharmony_ciconst std::string ORIENTATION = "orientation"; 111eace7efcSopenharmony_ci 112eace7efcSopenharmony_ciconst int32_t LINE_NUMS_ZERO = 0; 113eace7efcSopenharmony_ciconst int32_t LINE_NUMS_TWO = 2; 114eace7efcSopenharmony_ciconst int32_t LINE_NUMS_THREE = 3; 115eace7efcSopenharmony_ciconst int32_t LINE_NUMS_FOUR = 4; 116eace7efcSopenharmony_ciconst int32_t LINE_NUMS_EIGHT = 8; 117eace7efcSopenharmony_ci 118eace7efcSopenharmony_ciconst float WIDTH_MULTIPLE = 0.8; 119eace7efcSopenharmony_ciconst float HEIGHT_MULTIPLE = 0.3; 120eace7efcSopenharmony_ciconst float SETX_WIDTH_MULTIPLE = 0.1; 121eace7efcSopenharmony_ci 122eace7efcSopenharmony_ciWant SystemDialogScheduler::GetTipsDialogWant(const sptr<IRemoteObject> &callerToken) 123eace7efcSopenharmony_ci{ 124eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 125eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "GetTipsDialogWant start"); 126eace7efcSopenharmony_ci 127eace7efcSopenharmony_ci DialogPosition position; 128eace7efcSopenharmony_ci GetDialogPositionAndSize(DialogType::DIALOG_TIPS, position); 129eace7efcSopenharmony_ci 130eace7efcSopenharmony_ci nlohmann::json jsonObj; 131eace7efcSopenharmony_ci jsonObj[IS_DEFAULT_SELECTOR] = AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); 132eace7efcSopenharmony_ci const std::string params = jsonObj.dump(); 133eace7efcSopenharmony_ci 134eace7efcSopenharmony_ci AAFwk::Want want; 135eace7efcSopenharmony_ci want.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_TIPS_DIALOG); 136eace7efcSopenharmony_ci want.SetParam(DIALOG_POSITION, GetDialogPositionParams(position)); 137eace7efcSopenharmony_ci want.SetParam(DIALOG_PARAMS, params); 138eace7efcSopenharmony_ci auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); 139eace7efcSopenharmony_ci if (abilityRecord && !UIExtensionUtils::IsUIExtension(abilityRecord->GetAbilityInfo().extensionAbilityType)) { 140eace7efcSopenharmony_ci want.SetParam(CALLER_TOKEN, callerToken); 141eace7efcSopenharmony_ci } 142eace7efcSopenharmony_ci return want; 143eace7efcSopenharmony_ci} 144eace7efcSopenharmony_ci 145eace7efcSopenharmony_ciWant SystemDialogScheduler::GetJumpInterceptorDialogWant(Want &targetWant) 146eace7efcSopenharmony_ci{ 147eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "start"); 148eace7efcSopenharmony_ci 149eace7efcSopenharmony_ci DialogPosition position; 150eace7efcSopenharmony_ci GetDialogPositionAndSize(DialogType::DIALOG_JUMP_INTERCEPTOR, position); 151eace7efcSopenharmony_ci 152eace7efcSopenharmony_ci nlohmann::json jsonObj; 153eace7efcSopenharmony_ci jsonObj[IS_DEFAULT_SELECTOR] = AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); 154eace7efcSopenharmony_ci jsonObj["bundleName"] = targetWant.GetElement().GetBundleName(); 155eace7efcSopenharmony_ci jsonObj["abilityName"] = targetWant.GetElement().GetAbilityName(); 156eace7efcSopenharmony_ci jsonObj["moduleName"] = targetWant.GetElement().GetModuleName(); 157eace7efcSopenharmony_ci const std::string params = jsonObj.dump(); 158eace7efcSopenharmony_ci 159eace7efcSopenharmony_ci targetWant.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_JUMP_INTERCEPTOR_DIALOG); 160eace7efcSopenharmony_ci targetWant.SetParam(DIALOG_POSITION, GetDialogPositionParams(position)); 161eace7efcSopenharmony_ci targetWant.SetParam(DIALOG_PARAMS, params); 162eace7efcSopenharmony_ci targetWant.GetStringParam(DIALOG_PARAMS); 163eace7efcSopenharmony_ci return targetWant; 164eace7efcSopenharmony_ci} 165eace7efcSopenharmony_ci 166eace7efcSopenharmony_civoid SystemDialogScheduler::DialogPortraitPositionAdaptive( 167eace7efcSopenharmony_ci DialogPosition &position, float densityPixels, int lineNums) const 168eace7efcSopenharmony_ci{ 169eace7efcSopenharmony_ci if (lineNums > LINE_NUMS_EIGHT) { 170eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_PORTRAIT_PHONE_H3 * densityPixels); 171eace7efcSopenharmony_ci return; 172eace7efcSopenharmony_ci } else if (lineNums > LINE_NUMS_FOUR) { 173eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_PORTRAIT_PHONE_H2 * densityPixels); 174eace7efcSopenharmony_ci return; 175eace7efcSopenharmony_ci } else if (lineNums > LINE_NUMS_ZERO) { 176eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_PORTRAIT_PHONE_H1 * densityPixels); 177eace7efcSopenharmony_ci return; 178eace7efcSopenharmony_ci } 179eace7efcSopenharmony_ci 180eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "dialog portrait lineNums is zero"); 181eace7efcSopenharmony_ci} 182eace7efcSopenharmony_ci 183eace7efcSopenharmony_civoid SystemDialogScheduler::GetSelectorDialogPortraitPosition( 184eace7efcSopenharmony_ci DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const 185eace7efcSopenharmony_ci{ 186eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "PortraitPosition height %{public}d width %{public}d density %{public}f", 187eace7efcSopenharmony_ci height, width, densityPixels); 188eace7efcSopenharmony_ci position.width = static_cast<int32_t>(width * UI_SELECTOR_PORTRAIT_WIDTH_RATIO); 189eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_DIALOG_HEIGHT * densityPixels); 190eace7efcSopenharmony_ci position.width_narrow = static_cast<int32_t>(width * UI_SELECTOR_PORTRAIT_WIDTH_RATIO); 191eace7efcSopenharmony_ci position.height_narrow = static_cast<int32_t>(UI_SELECTOR_DIALOG_HEIGHT_NARROW * densityPixels); 192eace7efcSopenharmony_ci 193eace7efcSopenharmony_ci if (width < UI_WIDTH_780DP) { 194eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DIALOG, "show dialog narrow"); 195eace7efcSopenharmony_ci position.width = position.width_narrow; 196eace7efcSopenharmony_ci position.height = position.height_narrow; 197eace7efcSopenharmony_ci } 198eace7efcSopenharmony_ci 199eace7efcSopenharmony_ci DialogPortraitPositionAdaptive(position, densityPixels, lineNums); 200eace7efcSopenharmony_ci 201eace7efcSopenharmony_ci int32_t portraitMax = static_cast<int32_t>(height * UI_SELECTOR_PORTRAIT_HEIGHT_RATIO); 202eace7efcSopenharmony_ci if (portraitMax < position.height) { 203eace7efcSopenharmony_ci position.oversizeHeight = true; 204eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_PORTRAIT_PHONE_H1 * densityPixels); 205eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DIALOG, "portrait ratio 0.9 height: %{public}d", portraitMax); 206eace7efcSopenharmony_ci } 207eace7efcSopenharmony_ci 208eace7efcSopenharmony_ci position.offsetX = static_cast<int32_t>(width * UI_SELECTOR_PORTRAIT_WIDTH_EDGE_RATIO); 209eace7efcSopenharmony_ci position.offsetY = static_cast<int32_t>((height * UI_SELECTOR_PORTRAIT_HEIGHT_RATIO - position.height)); 210eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "dialog offset x:%{public}d y:%{public}d h:%{public}d w:%{public}d", 211eace7efcSopenharmony_ci position.offsetX, position.offsetY, position.height, position.width); 212eace7efcSopenharmony_ci} 213eace7efcSopenharmony_ci 214eace7efcSopenharmony_civoid SystemDialogScheduler::DialogLandscapePositionAdaptive( 215eace7efcSopenharmony_ci DialogPosition &position, float densityPixels, int lineNums) const 216eace7efcSopenharmony_ci{ 217eace7efcSopenharmony_ci if (lineNums > LINE_NUMS_EIGHT) { 218eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_LANDSCAPE_PHONE_H3 * densityPixels); 219eace7efcSopenharmony_ci return; 220eace7efcSopenharmony_ci } else if (lineNums > LINE_NUMS_FOUR) { 221eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_LANDSCAPE_PHONE_H2 * densityPixels); 222eace7efcSopenharmony_ci return; 223eace7efcSopenharmony_ci } else if (lineNums > LINE_NUMS_ZERO) { 224eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_LANDSCAPE_PHONE_H1 * densityPixels); 225eace7efcSopenharmony_ci return; 226eace7efcSopenharmony_ci } 227eace7efcSopenharmony_ci 228eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "dialog landscape lineNums is zero"); 229eace7efcSopenharmony_ci} 230eace7efcSopenharmony_ci 231eace7efcSopenharmony_civoid SystemDialogScheduler::GetSelectorDialogLandscapePosition( 232eace7efcSopenharmony_ci DialogPosition &position, int32_t height, int32_t width, int lineNums, float densityPixels) const 233eace7efcSopenharmony_ci{ 234eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "LandscapePosition height %{public}d width %{public}d density %{public}f", 235eace7efcSopenharmony_ci height, width, densityPixels); 236eace7efcSopenharmony_ci position.width = static_cast<int32_t>(width * 237eace7efcSopenharmony_ci (UI_SELECTOR_LANDSCAPE_GRILLE_LARGE * UI_SELECTOR_LANDSCAPE_COUNT_FOUR + 238eace7efcSopenharmony_ci UI_SELECTOR_LANDSCAPE_GRILLE_SAMLL * UI_SELECTOR_LANDSCAPE_COUNT_THREE)); 239eace7efcSopenharmony_ci position.height = static_cast<int32_t>((UI_SELECTOR_LANDSCAPE_HEIGHT) * densityPixels); 240eace7efcSopenharmony_ci position.width_narrow = static_cast<int32_t>(width * 241eace7efcSopenharmony_ci (UI_SELECTOR_LANDSCAPE_GRILLE_LARGE * UI_SELECTOR_LANDSCAPE_COUNT_FOUR + 242eace7efcSopenharmony_ci UI_SELECTOR_LANDSCAPE_GRILLE_SAMLL * UI_SELECTOR_LANDSCAPE_COUNT_THREE)); 243eace7efcSopenharmony_ci position.height_narrow = static_cast<int32_t>((UI_SELECTOR_LANDSCAPE_HEIGHT_NARROW) * densityPixels); 244eace7efcSopenharmony_ci DialogLandscapePositionAdaptive(position, densityPixels, lineNums); 245eace7efcSopenharmony_ci 246eace7efcSopenharmony_ci int32_t landscapeMax = static_cast<int32_t>( 247eace7efcSopenharmony_ci (height - UI_SELECTOR_LANDSCAPE_SIGNAL_BAR * densityPixels) * UI_SELECTOR_LANDSCAPE_MAX_RATIO); 248eace7efcSopenharmony_ci if (position.height > landscapeMax) { 249eace7efcSopenharmony_ci position.oversizeHeight = true; 250eace7efcSopenharmony_ci position.height = static_cast<int32_t>(UI_SELECTOR_LANDSCAPE_PHONE_H1 * densityPixels); 251eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DIALOG, "landscape ratio 0.9 height:%{public}d", landscapeMax); 252eace7efcSopenharmony_ci } 253eace7efcSopenharmony_ci 254eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "dialog height is %{public}d", position.height); 255eace7efcSopenharmony_ci position.offsetX = static_cast<int32_t>((width - position.width) / UI_HALF); 256eace7efcSopenharmony_ci position.offsetY = static_cast<int32_t>((height * UI_SELECTOR_PORTRAIT_HEIGHT_RATIO - position.height)); 257eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "dialog offset x:%{public}d y:%{public}d h:%{public}d w:%{public}d", 258eace7efcSopenharmony_ci position.offsetX, position.offsetY, position.height, position.width); 259eace7efcSopenharmony_ci} 260eace7efcSopenharmony_ci 261eace7efcSopenharmony_civoid SystemDialogScheduler::GetSelectorDialogPositionAndSize( 262eace7efcSopenharmony_ci DialogPosition &portraitPosition, DialogPosition &landscapePosition, int lineNums) const 263eace7efcSopenharmony_ci{ 264eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 265eace7efcSopenharmony_ci portraitPosition.wideScreen = !AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); 266eace7efcSopenharmony_ci portraitPosition.align = AppUtils::GetInstance().IsSelectorDialogDefaultPossion() ? 267eace7efcSopenharmony_ci DialogAlign::BOTTOM : DialogAlign::CENTER; 268eace7efcSopenharmony_ci landscapePosition.wideScreen = portraitPosition.wideScreen; 269eace7efcSopenharmony_ci landscapePosition.align = portraitPosition.align; 270eace7efcSopenharmony_ci 271eace7efcSopenharmony_ci auto display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 272eace7efcSopenharmony_ci if (display == nullptr) { 273eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DIALOG, "GetDefaultDisplay fail, try again"); 274eace7efcSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 275eace7efcSopenharmony_ci } 276eace7efcSopenharmony_ci if (display == nullptr) { 277eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DIALOG, "GetDefaultDisplay fail"); 278eace7efcSopenharmony_ci return; 279eace7efcSopenharmony_ci } 280eace7efcSopenharmony_ci 281eace7efcSopenharmony_ci auto displayInfo = display->GetDisplayInfo(); 282eace7efcSopenharmony_ci if (displayInfo == nullptr) { 283eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DIALOG, "GetDisplayInfo fail"); 284eace7efcSopenharmony_ci return; 285eace7efcSopenharmony_ci } 286eace7efcSopenharmony_ci 287eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "GetOrientation, %{public}d %{public}f", 288eace7efcSopenharmony_ci displayInfo->GetDisplayOrientation(), display->GetVirtualPixelRatio()); 289eace7efcSopenharmony_ci if (displayInfo->GetDisplayOrientation() == Rosen::DisplayOrientation::PORTRAIT || 290eace7efcSopenharmony_ci displayInfo->GetDisplayOrientation() == Rosen::DisplayOrientation::PORTRAIT_INVERTED) { 291eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DIALOG, "GetOrientation, PORTRAIT or PORTRAIT_INVERTED"); 292eace7efcSopenharmony_ci GetSelectorDialogPortraitPosition(portraitPosition, display->GetHeight(), display->GetWidth(), 293eace7efcSopenharmony_ci lineNums, display->GetVirtualPixelRatio()); 294eace7efcSopenharmony_ci GetSelectorDialogLandscapePosition(landscapePosition, display->GetWidth(), display->GetHeight(), 295eace7efcSopenharmony_ci lineNums, display->GetVirtualPixelRatio()); 296eace7efcSopenharmony_ci return; 297eace7efcSopenharmony_ci } 298eace7efcSopenharmony_ci 299eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DIALOG, "GetOrientation, LANDSCAPE or LANDSCAPE_INVERTED"); 300eace7efcSopenharmony_ci GetSelectorDialogPortraitPosition(portraitPosition, display->GetWidth(), display->GetHeight(), 301eace7efcSopenharmony_ci lineNums, display->GetVirtualPixelRatio()); 302eace7efcSopenharmony_ci GetSelectorDialogLandscapePosition(landscapePosition, display->GetHeight(), display->GetWidth(), 303eace7efcSopenharmony_ci lineNums, display->GetVirtualPixelRatio()); 304eace7efcSopenharmony_ci} 305eace7efcSopenharmony_ci 306eace7efcSopenharmony_ciint SystemDialogScheduler::GetSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant, 307eace7efcSopenharmony_ci Want &targetWant, const sptr<IRemoteObject> &callerToken) 308eace7efcSopenharmony_ci{ 309eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 310eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "start"); 311eace7efcSopenharmony_ci DialogPosition portraitPosition; 312eace7efcSopenharmony_ci DialogPosition landscapePosition; 313eace7efcSopenharmony_ci GetSelectorDialogPositionAndSize(portraitPosition, landscapePosition, static_cast<int>(dialogAppInfos.size())); 314eace7efcSopenharmony_ci std::string params = GetSelectorParams(dialogAppInfos); 315eace7efcSopenharmony_ci 316eace7efcSopenharmony_ci requestWant.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_SELECTOR_DIALOG); 317eace7efcSopenharmony_ci requestWant.SetParam(DIALOG_POSITION, GetDialogPositionParams(portraitPosition)); 318eace7efcSopenharmony_ci requestWant.SetParam(VERTICAL_SCREEN_DIALOG_POSITION, GetDialogPositionParams(landscapePosition)); 319eace7efcSopenharmony_ci requestWant.SetParam(DIALOG_PARAMS, params); 320eace7efcSopenharmony_ci return GetSelectorDialogWantCommon(dialogAppInfos, requestWant, targetWant, callerToken); 321eace7efcSopenharmony_ci} 322eace7efcSopenharmony_ci 323eace7efcSopenharmony_ciconst std::string SystemDialogScheduler::GetSelectorParams(const std::vector<DialogAppInfo> &infos) const 324eace7efcSopenharmony_ci{ 325eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 326eace7efcSopenharmony_ci if (infos.empty()) { 327eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::DIALOG, "invalid abilityInfos"); 328eace7efcSopenharmony_ci return {}; 329eace7efcSopenharmony_ci } 330eace7efcSopenharmony_ci 331eace7efcSopenharmony_ci nlohmann::json jsonObject; 332eace7efcSopenharmony_ci jsonObject[IS_DEFAULT_SELECTOR] = AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); 333eace7efcSopenharmony_ci 334eace7efcSopenharmony_ci nlohmann::json hapListObj = nlohmann::json::array(); 335eace7efcSopenharmony_ci for (const auto &aInfo : infos) { 336eace7efcSopenharmony_ci nlohmann::json aObj; 337eace7efcSopenharmony_ci aObj["label"] = std::to_string(aInfo.abilityLabelId); 338eace7efcSopenharmony_ci aObj["icon"] = std::to_string(aInfo.abilityIconId); 339eace7efcSopenharmony_ci aObj["bundle"] = aInfo.bundleName; 340eace7efcSopenharmony_ci aObj["ability"] = aInfo.abilityName; 341eace7efcSopenharmony_ci aObj["module"] = aInfo.moduleName; 342eace7efcSopenharmony_ci aObj["appIndex"] = std::to_string(aInfo.appIndex); 343eace7efcSopenharmony_ci aObj["bundleLabel"] = std::to_string(aInfo.bundleLabelId); 344eace7efcSopenharmony_ci aObj["bundleIcon"] = std::to_string(aInfo.bundleIconId); 345eace7efcSopenharmony_ci hapListObj.emplace_back(aObj); 346eace7efcSopenharmony_ci } 347eace7efcSopenharmony_ci jsonObject["hapList"] = hapListObj; 348eace7efcSopenharmony_ci 349eace7efcSopenharmony_ci return jsonObject.dump(); 350eace7efcSopenharmony_ci} 351eace7efcSopenharmony_ci 352eace7efcSopenharmony_ciint SystemDialogScheduler::GetPcSelectorDialogWant(const std::vector<DialogAppInfo> &dialogAppInfos, Want &requestWant, 353eace7efcSopenharmony_ci Want &targetWant, const std::string &type, int32_t userId, const sptr<IRemoteObject> &callerToken) 354eace7efcSopenharmony_ci{ 355eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 356eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "start"); 357eace7efcSopenharmony_ci DialogPosition position; 358eace7efcSopenharmony_ci GetDialogPositionAndSize(DialogType::DIALOG_SELECTOR, position, static_cast<int>(dialogAppInfos.size())); 359eace7efcSopenharmony_ci 360eace7efcSopenharmony_ci std::string params = GetPcSelectorParams(dialogAppInfos, type, userId, requestWant.GetAction()); 361eace7efcSopenharmony_ci requestWant.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_SELECTOR_DIALOG); 362eace7efcSopenharmony_ci requestWant.SetParam(DIALOG_POSITION, GetDialogPositionParams(position)); 363eace7efcSopenharmony_ci requestWant.SetParam(DIALOG_PARAMS, params); 364eace7efcSopenharmony_ci return GetSelectorDialogWantCommon(dialogAppInfos, requestWant, targetWant, callerToken); 365eace7efcSopenharmony_ci} 366eace7efcSopenharmony_ci 367eace7efcSopenharmony_ciconst std::string SystemDialogScheduler::GetPcSelectorParams(const std::vector<DialogAppInfo> &infos, 368eace7efcSopenharmony_ci const std::string &type, int32_t userId, const std::string &action) const 369eace7efcSopenharmony_ci{ 370eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "start"); 371eace7efcSopenharmony_ci if (infos.empty()) { 372eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::DIALOG, "invalid abilityInfos"); 373eace7efcSopenharmony_ci return {}; 374eace7efcSopenharmony_ci } 375eace7efcSopenharmony_ci 376eace7efcSopenharmony_ci nlohmann::json jsonObject; 377eace7efcSopenharmony_ci jsonObject[IS_DEFAULT_SELECTOR] = AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); 378eace7efcSopenharmony_ci jsonObject[ACTION] = action; 379eace7efcSopenharmony_ci if (type == TYPE_ONLY_MATCH_WILDCARD) { 380eace7efcSopenharmony_ci jsonObject[MODEL_FLAG] = true; 381eace7efcSopenharmony_ci } else { 382eace7efcSopenharmony_ci jsonObject[MODEL_FLAG] = false; 383eace7efcSopenharmony_ci } 384eace7efcSopenharmony_ci 385eace7efcSopenharmony_ci nlohmann::json hapListObj = nlohmann::json::array(); 386eace7efcSopenharmony_ci for (const auto &info : infos) { 387eace7efcSopenharmony_ci nlohmann::json aObj; 388eace7efcSopenharmony_ci aObj["label"] = std::to_string(info.abilityLabelId); 389eace7efcSopenharmony_ci aObj["icon"] = std::to_string(info.abilityIconId); 390eace7efcSopenharmony_ci aObj["bundle"] = info.bundleName; 391eace7efcSopenharmony_ci aObj["ability"] = info.abilityName; 392eace7efcSopenharmony_ci aObj["module"] = info.moduleName; 393eace7efcSopenharmony_ci aObj["type"] = type; 394eace7efcSopenharmony_ci aObj["userId"] = std::to_string(userId); 395eace7efcSopenharmony_ci aObj["appIndex"] = std::to_string(info.appIndex); 396eace7efcSopenharmony_ci aObj["bundleLabel"] = std::to_string(info.bundleLabelId); 397eace7efcSopenharmony_ci aObj["bundleIcon"] = std::to_string(info.bundleIconId); 398eace7efcSopenharmony_ci hapListObj.emplace_back(aObj); 399eace7efcSopenharmony_ci } 400eace7efcSopenharmony_ci jsonObject["hapList"] = hapListObj; 401eace7efcSopenharmony_ci 402eace7efcSopenharmony_ci return jsonObject.dump(); 403eace7efcSopenharmony_ci} 404eace7efcSopenharmony_ci 405eace7efcSopenharmony_ciint SystemDialogScheduler::GetSelectorDialogWantCommon(const std::vector<DialogAppInfo> &dialogAppInfos, 406eace7efcSopenharmony_ci Want &requestWant, Want &targetWant, const sptr<IRemoteObject> &callerToken) 407eace7efcSopenharmony_ci{ 408eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 409eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "start"); 410eace7efcSopenharmony_ci bool isCallerStageBasedModel = true; 411eace7efcSopenharmony_ci if (callerToken != nullptr) { 412eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "set callertoken to targetWant"); 413eace7efcSopenharmony_ci auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); 414eace7efcSopenharmony_ci if (abilityRecord && !abilityRecord->GetAbilityInfo().isStageBasedModel) { 415eace7efcSopenharmony_ci isCallerStageBasedModel = false; 416eace7efcSopenharmony_ci } 417eace7efcSopenharmony_ci if (abilityRecord && UIExtensionUtils::IsUIExtension(abilityRecord->GetAbilityInfo().extensionAbilityType)) { 418eace7efcSopenharmony_ci // SelectorDialog can't bind to the window of UIExtension, so set CALLER_TOKEN to null. 419eace7efcSopenharmony_ci requestWant.RemoveParam(CALLER_TOKEN); 420eace7efcSopenharmony_ci } else { 421eace7efcSopenharmony_ci requestWant.SetParam(CALLER_TOKEN, callerToken); 422eace7efcSopenharmony_ci } 423eace7efcSopenharmony_ci } 424eace7efcSopenharmony_ci if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && isCallerStageBasedModel) { 425eace7efcSopenharmony_ci auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); 426eace7efcSopenharmony_ci if (bundleMgrHelper == nullptr) { 427eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DIALOG, "bundleMgrHelper null"); 428eace7efcSopenharmony_ci return INNER_ERR; 429eace7efcSopenharmony_ci } 430eace7efcSopenharmony_ci std::string bundleName; 431eace7efcSopenharmony_ci if (!IN_PROCESS_CALL(bundleMgrHelper->QueryAppGalleryBundleName(bundleName))) { 432eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DIALOG, "QueryAppGalleryBundleName failed"); 433eace7efcSopenharmony_ci return INNER_ERR; 434eace7efcSopenharmony_ci } 435eace7efcSopenharmony_ci targetWant.SetElementName(bundleName, ABILITY_NAME_APPGALLERY_SELECTOR_DIALOG); 436eace7efcSopenharmony_ci targetWant.SetParam(UIEXTENSION_TYPE_KEY, UIEXTENSION_SYS_COMMON_UI); 437eace7efcSopenharmony_ci targetWant.SetParam("isCreateAppGallerySelector", true); 438eace7efcSopenharmony_ci } 439eace7efcSopenharmony_ci return ERR_OK; 440eace7efcSopenharmony_ci} 441eace7efcSopenharmony_ci 442eace7efcSopenharmony_ciconst std::string SystemDialogScheduler::GetDialogPositionParams(const DialogPosition position) const 443eace7efcSopenharmony_ci{ 444eace7efcSopenharmony_ci nlohmann::json dialogPositionData; 445eace7efcSopenharmony_ci dialogPositionData[OFF_SET_X] = position.offsetX; 446eace7efcSopenharmony_ci dialogPositionData[OFF_SET_Y] = position.offsetY; 447eace7efcSopenharmony_ci dialogPositionData[WIDTH] = position.width; 448eace7efcSopenharmony_ci dialogPositionData[HEIGHT] = position.height; 449eace7efcSopenharmony_ci dialogPositionData[OVERSIZE_HEIGHT] = position.oversizeHeight; 450eace7efcSopenharmony_ci return dialogPositionData.dump(); 451eace7efcSopenharmony_ci} 452eace7efcSopenharmony_ci 453eace7efcSopenharmony_civoid SystemDialogScheduler::InitDialogPosition(DialogType type, DialogPosition &position) const 454eace7efcSopenharmony_ci{ 455eace7efcSopenharmony_ci position.wideScreen = !AppUtils::GetInstance().IsSelectorDialogDefaultPossion(); 456eace7efcSopenharmony_ci position.align = AppUtils::GetInstance().IsSelectorDialogDefaultPossion() ? 457eace7efcSopenharmony_ci DialogAlign::BOTTOM : DialogAlign::CENTER; 458eace7efcSopenharmony_ci auto display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 459eace7efcSopenharmony_ci 460eace7efcSopenharmony_ci switch (type) { 461eace7efcSopenharmony_ci case DialogType::DIALOG_ANR: 462eace7efcSopenharmony_ci if (position.wideScreen) { 463eace7efcSopenharmony_ci position.width = UI_ANR_DIALOG_WIDTH; 464eace7efcSopenharmony_ci position.height = UI_ANR_DIALOG_HEIGHT; 465eace7efcSopenharmony_ci position.width_narrow = UI_ANR_DIALOG_WIDTH; 466eace7efcSopenharmony_ci position.height_narrow = UI_ANR_DIALOG_HEIGHT; 467eace7efcSopenharmony_ci position.align = DialogAlign::CENTER; 468eace7efcSopenharmony_ci } else { 469eace7efcSopenharmony_ci position.width = display->GetWidth(); 470eace7efcSopenharmony_ci position.height = display->GetHeight(); 471eace7efcSopenharmony_ci position.width_narrow = display->GetWidth(); 472eace7efcSopenharmony_ci position.height_narrow = display->GetHeight(); 473eace7efcSopenharmony_ci position.window_width = UI_ANR_DIALOG_WIDTH; 474eace7efcSopenharmony_ci position.window_height = UI_ANR_DIALOG_HEIGHT; 475eace7efcSopenharmony_ci position.align = DialogAlign::CENTER; 476eace7efcSopenharmony_ci } 477eace7efcSopenharmony_ci break; 478eace7efcSopenharmony_ci case DialogType::DIALOG_SELECTOR: 479eace7efcSopenharmony_ci position.width = UI_SELECTOR_DIALOG_WIDTH; 480eace7efcSopenharmony_ci position.height = UI_SELECTOR_DIALOG_HEIGHT; 481eace7efcSopenharmony_ci position.width_narrow = UI_SELECTOR_DIALOG_WIDTH_NARROW; 482eace7efcSopenharmony_ci position.height_narrow = UI_SELECTOR_DIALOG_HEIGHT_NARROW; 483eace7efcSopenharmony_ci break; 484eace7efcSopenharmony_ci case DialogType::DIALOG_TIPS: 485eace7efcSopenharmony_ci position.width = UI_TIPS_DIALOG_WIDTH; 486eace7efcSopenharmony_ci position.height = UI_TIPS_DIALOG_HEIGHT; 487eace7efcSopenharmony_ci position.width_narrow = UI_TIPS_DIALOG_WIDTH_NARROW; 488eace7efcSopenharmony_ci position.height_narrow = UI_TIPS_DIALOG_HEIGHT_NARROW; 489eace7efcSopenharmony_ci break; 490eace7efcSopenharmony_ci case DialogType::DIALOG_JUMP_INTERCEPTOR: 491eace7efcSopenharmony_ci position.width = UI_JUMP_INTERCEPTOR_DIALOG_WIDTH; 492eace7efcSopenharmony_ci position.height = UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT; 493eace7efcSopenharmony_ci position.width_narrow = UI_JUMP_INTERCEPTOR_DIALOG_WIDTH_NARROW; 494eace7efcSopenharmony_ci position.height_narrow = UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT_NARROW; 495eace7efcSopenharmony_ci break; 496eace7efcSopenharmony_ci default: 497eace7efcSopenharmony_ci position.width = UI_DEFAULT_WIDTH; 498eace7efcSopenharmony_ci position.height = UI_DEFAULT_HEIGHT; 499eace7efcSopenharmony_ci position.width_narrow = UI_DEFAULT_WIDTH; 500eace7efcSopenharmony_ci position.height_narrow = UI_DEFAULT_HEIGHT; 501eace7efcSopenharmony_ci break; 502eace7efcSopenharmony_ci } 503eace7efcSopenharmony_ci} 504eace7efcSopenharmony_ci 505eace7efcSopenharmony_civoid SystemDialogScheduler::DialogPositionAdaptive(DialogPosition &position, int lineNums) const 506eace7efcSopenharmony_ci{ 507eace7efcSopenharmony_ci if (position.wideScreen) { 508eace7efcSopenharmony_ci if (lineNums <= LINE_NUMS_TWO) { 509eace7efcSopenharmony_ci position.height = UI_SELECTOR_DIALOG_PC_H2; 510eace7efcSopenharmony_ci } else if (lineNums == LINE_NUMS_THREE) { 511eace7efcSopenharmony_ci position.height = UI_SELECTOR_DIALOG_PC_H3; 512eace7efcSopenharmony_ci } else if (lineNums == LINE_NUMS_FOUR) { 513eace7efcSopenharmony_ci position.height = UI_SELECTOR_DIALOG_PC_H4; 514eace7efcSopenharmony_ci } else if (lineNums > LINE_NUMS_FOUR) { 515eace7efcSopenharmony_ci position.height = UI_SELECTOR_DIALOG_PC_H5; 516eace7efcSopenharmony_ci } else { 517eace7efcSopenharmony_ci position.height = UI_SELECTOR_DIALOG_PC_H0; 518eace7efcSopenharmony_ci } 519eace7efcSopenharmony_ci } else { 520eace7efcSopenharmony_ci position.height = (lineNums > LINE_NUMS_EIGHT) ? UI_SELECTOR_DIALOG_PHONE_H3 : 521eace7efcSopenharmony_ci (lineNums > LINE_NUMS_THREE ? UI_SELECTOR_DIALOG_PHONE_H2 : 522eace7efcSopenharmony_ci (lineNums > LINE_NUMS_ZERO ? UI_SELECTOR_DIALOG_PHONE_H1 : position.height)); 523eace7efcSopenharmony_ci } 524eace7efcSopenharmony_ci} 525eace7efcSopenharmony_ci 526eace7efcSopenharmony_civoid SystemDialogScheduler::GetDialogPositionAndSize(DialogType type, DialogPosition &position, int lineNums) const 527eace7efcSopenharmony_ci{ 528eace7efcSopenharmony_ci HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); 529eace7efcSopenharmony_ci InitDialogPosition(type, position); 530eace7efcSopenharmony_ci 531eace7efcSopenharmony_ci auto display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 532eace7efcSopenharmony_ci if (display == nullptr) { 533eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::DIALOG, "GetDefaultDisplay fail, try again"); 534eace7efcSopenharmony_ci display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 535eace7efcSopenharmony_ci } 536eace7efcSopenharmony_ci if (display != nullptr) { 537eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DIALOG, "display width:%{public}d, height:%{public}d", display->GetWidth(), 538eace7efcSopenharmony_ci display->GetHeight()); 539eace7efcSopenharmony_ci if (display->GetWidth() < UI_WIDTH_780DP) { 540eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DIALOG, "show dialog narrow"); 541eace7efcSopenharmony_ci position.width = position.width_narrow; 542eace7efcSopenharmony_ci position.height = position.height_narrow; 543eace7efcSopenharmony_ci } 544eace7efcSopenharmony_ci 545eace7efcSopenharmony_ci if (type == DialogType::DIALOG_SELECTOR) { 546eace7efcSopenharmony_ci DialogPositionAdaptive(position, lineNums); 547eace7efcSopenharmony_ci } 548eace7efcSopenharmony_ci switch (position.align) { 549eace7efcSopenharmony_ci case DialogAlign::CENTER: 550eace7efcSopenharmony_ci if (position.wideScreen) { 551eace7efcSopenharmony_ci position.offsetX = (display->GetWidth() - position.width) / UI_HALF; 552eace7efcSopenharmony_ci position.offsetY = (display->GetHeight() - position.height) / UI_HALF; 553eace7efcSopenharmony_ci } else { 554eace7efcSopenharmony_ci position.window_width = position.window_width / UI_HALF; 555eace7efcSopenharmony_ci position.window_height = position.window_height / UI_HALF; 556eace7efcSopenharmony_ci position.offsetX = LINE_NUMS_ZERO; 557eace7efcSopenharmony_ci position.offsetY = LINE_NUMS_ZERO; 558eace7efcSopenharmony_ci } 559eace7efcSopenharmony_ci break; 560eace7efcSopenharmony_ci case DialogAlign::BOTTOM: 561eace7efcSopenharmony_ci position.width = display->GetWidth() * WIDTH_MULTIPLE; 562eace7efcSopenharmony_ci position.height = display->GetHeight() * HEIGHT_MULTIPLE; 563eace7efcSopenharmony_ci position.offsetX = display->GetWidth() * SETX_WIDTH_MULTIPLE; 564eace7efcSopenharmony_ci position.offsetY = display->GetHeight() - position.height - UI_DEFAULT_BUTTOM_CLIP; 565eace7efcSopenharmony_ci break; 566eace7efcSopenharmony_ci default: 567eace7efcSopenharmony_ci position.offsetX = (display->GetWidth() - position.width) / UI_HALF; 568eace7efcSopenharmony_ci position.offsetY = (display->GetHeight() - position.height - UI_DEFAULT_BUTTOM_CLIP) / UI_HALF; 569eace7efcSopenharmony_ci break; 570eace7efcSopenharmony_ci } 571eace7efcSopenharmony_ci } else { 572eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::DIALOG, "fail, use default wide"); 573eace7efcSopenharmony_ci if (type == DialogType::DIALOG_SELECTOR) { 574eace7efcSopenharmony_ci DialogPositionAdaptive(position, lineNums); 575eace7efcSopenharmony_ci } 576eace7efcSopenharmony_ci position.offsetX = (UI_DEFAULT_WIDTH - position.width) / UI_HALF; 577eace7efcSopenharmony_ci position.offsetY = UI_DEFAULT_HEIGHT - position.height - UI_DEFAULT_BUTTOM_CLIP; 578eace7efcSopenharmony_ci } 579eace7efcSopenharmony_ci} 580eace7efcSopenharmony_ci 581eace7efcSopenharmony_cibool SystemDialogScheduler::GetAssertFaultDialogWant(Want &want) 582eace7efcSopenharmony_ci{ 583eace7efcSopenharmony_ci auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); 584eace7efcSopenharmony_ci if (bundleMgrHelper == nullptr) { 585eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DIALOG, "Failed get bms"); 586eace7efcSopenharmony_ci return false; 587eace7efcSopenharmony_ci } 588eace7efcSopenharmony_ci 589eace7efcSopenharmony_ci std::string bundleName; 590eace7efcSopenharmony_ci auto callingUid = IPCSkeleton::GetCallingUid(); 591eace7efcSopenharmony_ci if (IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callingUid, bundleName)) != ERR_OK) { 592eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DIALOG, "VerifyPermission get bundle name failed"); 593eace7efcSopenharmony_ci return false; 594eace7efcSopenharmony_ci } 595eace7efcSopenharmony_ci 596eace7efcSopenharmony_ci want.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_ASSERT_FAULT_DIALOG); 597eace7efcSopenharmony_ci want.SetParam(BUNDLE_NAME, bundleName); 598eace7efcSopenharmony_ci want.SetParam(UIEXTENSION_TYPE_KEY, UIEXTENSION_SYS_COMMON_UI); 599eace7efcSopenharmony_ci return true; 600eace7efcSopenharmony_ci} 601eace7efcSopenharmony_ci 602eace7efcSopenharmony_ciWant SystemDialogScheduler::GetSwitchUserDialogWant() 603eace7efcSopenharmony_ci{ 604eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DIALOG, "start"); 605eace7efcSopenharmony_ci AAFwk::Want dialogWant; 606eace7efcSopenharmony_ci dialogWant.SetElementName(BUNDLE_NAME_DIALOG, ABILITY_NAME_FREEZE_DIALOG); 607eace7efcSopenharmony_ci 608eace7efcSopenharmony_ci return dialogWant; 609eace7efcSopenharmony_ci} 610eace7efcSopenharmony_ci} // namespace AAFwk 611eace7efcSopenharmony_ci} // namespace OHOS 612