1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2023-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 16eace7efcSopenharmony_ci#ifndef OHOS_AAFwk_UI_EXTENSION_UTILS_H 17eace7efcSopenharmony_ci#define OHOS_AAFwk_UI_EXTENSION_UTILS_H 18eace7efcSopenharmony_ci 19eace7efcSopenharmony_ci#include <unordered_set> 20eace7efcSopenharmony_ci 21eace7efcSopenharmony_ci#include "extension_ability_info.h" 22eace7efcSopenharmony_ci#include "ipc_skeleton.h" 23eace7efcSopenharmony_ci 24eace7efcSopenharmony_cinamespace OHOS { 25eace7efcSopenharmony_cinamespace AAFwk { 26eace7efcSopenharmony_cinamespace { 27eace7efcSopenharmony_ciconstexpr int EDM_SA_UID = 3057; 28eace7efcSopenharmony_ci} 29eace7efcSopenharmony_cinamespace UIExtensionUtils { 30eace7efcSopenharmony_ci// ui extension type list 31eace7efcSopenharmony_ciinline std::unordered_set<AppExecFwk::ExtensionAbilityType> GetUiExtensionSet() 32eace7efcSopenharmony_ci{ 33eace7efcSopenharmony_ci return std::unordered_set<AppExecFwk::ExtensionAbilityType> { 34eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SHARE, 35eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::ACTION, 36eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::EMBEDDED_UI, 37eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::INSIGHT_INTENT_UI, 38eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::AUTO_FILL_PASSWORD, 39eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::UI, 40eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL, 41eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_USERAUTH, 42eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON, 43eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_ATOMICSERVICEPANEL, 44eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_POWER, 45eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_SHARE, 46eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::HMS_ACCOUNT, 47eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::ADS, 48eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::VOIP, 49eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::STATUS_BAR_VIEW, 50eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_MEETIMECALL, 51eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_MEETIMECONTACT, 52eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_MEETIMEMESSAGE, 53eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_PRINT, 54eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_MEETIMECONTACT, 55eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_MEETIMECALLLOG, 56eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER, 57eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI, 58eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_NAVIGATION, 59eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_APPSELECTOR, 60eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_CAMERA, 61eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_FILEPICKER, 62eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::AUTO_FILL_SMART, 63eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::LIVEVIEW_LOCKSCREEN, 64eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOEDITOR, 65eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::PHOTO_EDITOR, 66eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_AUDIOPICKER, 67eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYS_VISUAL, 68eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::RECENT_PHOTO 69eace7efcSopenharmony_ci }; 70eace7efcSopenharmony_ci} 71eace7efcSopenharmony_ci 72eace7efcSopenharmony_ciinline bool IsUIExtension(const AppExecFwk::ExtensionAbilityType type) 73eace7efcSopenharmony_ci{ 74eace7efcSopenharmony_ci return GetUiExtensionSet().count(type) > 0; 75eace7efcSopenharmony_ci} 76eace7efcSopenharmony_ci 77eace7efcSopenharmony_ciinline bool IsSystemUIExtension(const AppExecFwk::ExtensionAbilityType type) 78eace7efcSopenharmony_ci{ 79eace7efcSopenharmony_ci const std::unordered_set<AppExecFwk::ExtensionAbilityType> systemUiExtensionSet = { 80eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_COMMON, 81eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_ATOMICSERVICEPANEL, 82eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_POWER, 83eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_MEETIMECALL, 84eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_MEETIMECONTACT, 85eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_MEETIMEMESSAGE, 86eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_PRINT, 87eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL, 88eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_SHARE, 89eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_MEETIMECONTACT, 90eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_MEETIMECALLLOG, 91eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER, 92eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_NAVIGATION, 93eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_APPSELECTOR, 94eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::UI, 95eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI, 96eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOEDITOR, 97eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::ADS, 98eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_AUDIOPICKER, 99eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::AUTO_FILL_PASSWORD, 100eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_CAMERA, 101eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::AUTO_FILL_SMART, 102eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_FILEPICKER, 103eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSDIALOG_USERAUTH, 104eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::HMS_ACCOUNT, 105eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYS_VISUAL, 106eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::RECENT_PHOTO 107eace7efcSopenharmony_ci }; 108eace7efcSopenharmony_ci return systemUiExtensionSet.find(type) != systemUiExtensionSet.end(); 109eace7efcSopenharmony_ci} 110eace7efcSopenharmony_ci 111eace7efcSopenharmony_ci// In this case, extension which be starting needs that caller should be the system app, otherwise not supported. 112eace7efcSopenharmony_ciinline bool IsSystemCallerNeeded(const AppExecFwk::ExtensionAbilityType type) 113eace7efcSopenharmony_ci{ 114eace7efcSopenharmony_ci const std::unordered_set<AppExecFwk::ExtensionAbilityType> uiExtensionStartingSet = { 115eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::PHOTO_EDITOR, 116eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::INSIGHT_INTENT_UI, 117eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::LIVEVIEW_LOCKSCREEN, 118eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SHARE, 119eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::ACTION, 120eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::STATUS_BAR_VIEW, 121eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::VOIP 122eace7efcSopenharmony_ci }; 123eace7efcSopenharmony_ci return uiExtensionStartingSet.find(type) != uiExtensionStartingSet.end(); 124eace7efcSopenharmony_ci} 125eace7efcSopenharmony_ci 126eace7efcSopenharmony_ci// In this collection, extension can be embedded by public app, which requires vertical businesses to ensure security. 127eace7efcSopenharmony_ciinline bool IsPublicForEmbedded(const AppExecFwk::ExtensionAbilityType type) 128eace7efcSopenharmony_ci{ 129eace7efcSopenharmony_ci const std::unordered_set<AppExecFwk::ExtensionAbilityType> publicForEmbeddedSet = { 130eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::EMBEDDED_UI, // EMBEDDED_UI usage within the app 131eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::ADS, 132eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL, 133eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYS_VISUAL, 134eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::AUTO_FILL_SMART, 135eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::AUTO_FILL_PASSWORD 136eace7efcSopenharmony_ci }; 137eace7efcSopenharmony_ci return publicForEmbeddedSet.find(type) != publicForEmbeddedSet.end(); 138eace7efcSopenharmony_ci} 139eace7efcSopenharmony_ci 140eace7efcSopenharmony_ci// In this collection, extension can be embedded by public app, which some UX effects are constrained 141eace7efcSopenharmony_ciinline bool IsPublicForConstrainedEmbedded(const AppExecFwk::ExtensionAbilityType type) 142eace7efcSopenharmony_ci{ 143eace7efcSopenharmony_ci const std::unordered_set<AppExecFwk::ExtensionAbilityType> publicForConstrainedEmbeddedSet = { 144eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER, 145eace7efcSopenharmony_ci AppExecFwk::ExtensionAbilityType::RECENT_PHOTO 146eace7efcSopenharmony_ci }; 147eace7efcSopenharmony_ci return publicForConstrainedEmbeddedSet.find(type) != publicForConstrainedEmbeddedSet.end(); 148eace7efcSopenharmony_ci} 149eace7efcSopenharmony_ci 150eace7efcSopenharmony_ciinline bool IsEnterpriseAdmin(const AppExecFwk::ExtensionAbilityType type) 151eace7efcSopenharmony_ci{ 152eace7efcSopenharmony_ci bool enterpriseAdminSa = (IPCSkeleton::GetCallingUid() == EDM_SA_UID); 153eace7efcSopenharmony_ci bool isEnterpriseAdmin = (type == AppExecFwk::ExtensionAbilityType::ENTERPRISE_ADMIN); 154eace7efcSopenharmony_ci return enterpriseAdminSa && isEnterpriseAdmin; 155eace7efcSopenharmony_ci} 156eace7efcSopenharmony_ci 157eace7efcSopenharmony_ciinline bool IsWindowExtension(const AppExecFwk::ExtensionAbilityType type) 158eace7efcSopenharmony_ci{ 159eace7efcSopenharmony_ci return type == AppExecFwk::ExtensionAbilityType::WINDOW; 160eace7efcSopenharmony_ci} 161eace7efcSopenharmony_ci} // namespace UIExtensionUtils 162eace7efcSopenharmony_ci} // namespace AAFwk 163eace7efcSopenharmony_ci} // namespace OHOS 164eace7efcSopenharmony_ci#endif // OHOS_AAFwk_UI_EXTENSION_UTILS_H 165