Merge branch 'master' of gitee.com:openharmony/ability_ability_runtime into DuliBianYi_20241016

Signed-off-by: jiangzhijun8 <jiangzhijun7@huawei.com>
This commit is contained in:
jiangzhijun8 2024-11-06 09:09:41 +00:00
commit 864d0d8ea3
170 changed files with 2265 additions and 1537 deletions

View File

@ -56,6 +56,7 @@
"dlp_permission_service",
"dsoftbus",
"eventhandler",
"ets_frontend",
"ets_runtime",
"ets_utils",
"faultloggerd",
@ -99,9 +100,7 @@
"toolchain",
"webview",
"window_manager",
"zlib",
"ets_frontend",
"runtime_core"
"zlib"
],
"third_party": [
"libjpeg-turbo"
@ -437,7 +436,7 @@
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/ui_extension_ability",
"header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/ui_extension_base",
"header_files": [
"ui_extension_context.h"
]

View File

@ -27,7 +27,6 @@ ohos_shared_library("ark_interop_helper_ffi") {
"hilog:libhilog",
"napi:ace_napi",
"napi:ark_interop",
"runtime_core:libarkbase_static",
]
sanitize = {
cfi = true

View File

@ -44,7 +44,7 @@ ohos_shared_library("autostartupcallback") {
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:libwm"
"window_manager:libwm",
]
if (ability_runtime_graphics) {

View File

@ -56,8 +56,8 @@ template("delegator") {
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"napi:ace_napi",
"ipc:ipc_napi",
"napi:ace_napi",
]
cflags_cc = []

View File

@ -48,9 +48,9 @@ ohos_shared_library("napi_ability_common") {
external_deps = [
"ability_base:base",
"ability_base:want",
"bundle_framework:appexecfwk_base",
"access_token:libtokenid_sdk",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"hilog:libhilog",

View File

@ -63,6 +63,7 @@ ohos_shared_library("napi_common") {
"json:nlohmann_json_static",
"libuv:uv",
"napi:ace_napi",
"samgr:samgr_proxy",
]
public_external_deps = [
@ -78,6 +79,7 @@ ohos_shared_library("napi_common") {
]
public_external_deps += [
"form_fwk:form_manager",
"graphic_2d:EGL",
"window_manager:libdm",
]
}

View File

@ -124,7 +124,7 @@ int LocalCallContainer::ReleaseCall(const std::shared_ptr<CallerCallBack>& callb
void LocalCallContainer::ClearFailedCallConnection(const std::shared_ptr<CallerCallBack> &callback)
{
TAG_LOGD(AAFwkTag::LOCAL_CALL, "called");
TAG_LOGI(AAFwkTag::LOCAL_CALL, "called");
if (callback == nullptr) {
TAG_LOGE(AAFwkTag::LOCAL_CALL, "callback is nullptr");
return;
@ -141,7 +141,16 @@ void LocalCallContainer::ClearFailedCallConnection(const std::shared_ptr<CallerC
TAG_LOGE(AAFwkTag::LOCAL_CALL, "connection conversion failed");
return;
}
std::string deviceId = localCallRecord->GetElementName().GetDeviceID();
if (deviceId.empty()) {
connections_.erase(connect);
return;
}
TAG_LOGI(AAFwkTag::LOCAL_CALL, "try releaseCall");
auto abilityClient = AAFwk::AbilityManagerClient::GetInstance();
if (abilityClient != nullptr) {
abilityClient->ReleaseCall(connect, localCallRecord->GetElementName());
}
connections_.erase(connect);
}

View File

@ -419,9 +419,7 @@ ohos_shared_library("abilitykit_native") {
"window_manager:libwsutils",
]
public_external_deps += [
"window_manager:libdm",
]
public_external_deps += [ "window_manager:libdm" ]
}
innerapi_tags = [ "platformsdk" ]
@ -571,6 +569,7 @@ config("uiability_config") {
"${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/distributed",
"${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/kits",
"${ability_runtime_path}/interfaces/kits/native/ability/native/recovery/",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_services_path}/abilitymgr/include/utils",
@ -1163,16 +1162,10 @@ ohos_shared_library("continuation_ipc") {
"json:nlohmann_json_static",
"resource_management:global_resmgr",
]
public_external_deps = [
# "accessibility:accessibility_common",
# "libuv:uv",
]
public_external_deps = []
if (ability_runtime_graphics) {
public_external_deps += [
# "form_fwk:form_manager",
# "window_manager:libdm",
]
public_external_deps += []
}
defines = []
@ -1253,9 +1246,9 @@ ohos_shared_library("service_extension_module") {
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"json:nlohmann_json_static",
"ipc:ipc_core",
"ipc:ipc_napi",
"json:nlohmann_json_static",
"napi:ace_napi",
]
@ -1380,6 +1373,7 @@ config("ui_extension_public_config") {
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/insight_intent_executor",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
"${windowmanager_path}/interfaces/kits/napi/embeddable_window_stage",
"${windowmanager_path}/interfaces/kits/napi/extension_window",
]
@ -1390,13 +1384,13 @@ ohos_shared_library("ui_extension") {
sources = [
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_base.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_context.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_uiservice_uiext_connection.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/ui_extension.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/ui_extension_context.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/ui_extension_servicehost_stub_impl.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_base/js_ui_extension_base.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_base/js_ui_extension_content_session.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_base/js_ui_extension_context.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_base/js_uiservice_uiext_connection.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_base/ui_extension_context.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_base/ui_extension_servicehost_stub_impl.cpp",
]
public_configs = [ ":ui_extension_public_config" ]
@ -1469,8 +1463,8 @@ ohos_shared_library("ui_extension_module") {
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"napi:ace_napi",
"ipc:ipc_napi",
"napi:ace_napi",
"window_manager:libwm",
]
if (ability_runtime_graphics) {
@ -1487,7 +1481,7 @@ config("share_extension_config") {
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native/share_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
@ -1538,7 +1532,7 @@ config("action_extension_config") {
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native/action_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
@ -1606,15 +1600,13 @@ ohos_shared_library("share_extension_module") {
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"napi:ace_napi",
"ipc:ipc_core",
"ipc:ipc_napi",
"napi:ace_napi",
]
if (ability_runtime_graphics) {
external_deps += [
"window_manager:libwm",
]
external_deps += [ "window_manager:libwm" ]
}
relative_install_dir = "extensionability/"
@ -1671,15 +1663,13 @@ ohos_shared_library("action_extension_module") {
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"napi:ace_napi",
"ipc:ipc_core",
"ipc:ipc_napi",
"napi:ace_napi",
]
if (ability_runtime_graphics) {
external_deps += [
"window_manager:libwm",
]
external_deps += [ "window_manager:libwm" ]
}
relative_install_dir = "extensionability/"
@ -1692,7 +1682,7 @@ config("embedded_ui_extension_config") {
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/embedded_ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
@ -1855,7 +1845,7 @@ config("auto_fill_extension_config") {
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/auto_fill_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
]
}
@ -1932,9 +1922,9 @@ ohos_shared_library("auto_fill_extension_module") {
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"napi:ace_napi",
"ipc:ipc_core",
"ipc:ipc_napi",
"napi:ace_napi",
"window_manager:libwm",
]
if (ability_runtime_graphics) {
@ -1950,7 +1940,7 @@ config("photo_editor_extension_config") {
visibility = [ ":*" ]
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
@ -2041,9 +2031,9 @@ ohos_shared_library("photo_editor_extension_module") {
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"napi:ace_napi",
"ipc:ipc_core",
"ipc:ipc_napi",
"napi:ace_napi",
]
if (ability_runtime_graphics) {

View File

@ -17,6 +17,7 @@
#include <cinttypes>
#include <cstdint>
#include <charconv>
#include "hilog_tag_wrapper.h"
#include "form_mgr_errors.h"
@ -112,10 +113,10 @@ private:
std::string strFormId;
ConvertFromJsValue(env, info.argv[0], strFormId);
int64_t formId = 0;
try {
formId = strFormId.empty() ? -1 : std::stoll(strFormId);
}catch (...) {
TAG_LOGE(AAFwkTag::FORM_EXT, "stoll error strFormId:%{public}s", strFormId.c_str());
auto res = std::from_chars(strFormId.c_str(), strFormId.c_str() + strFormId.size(), formId);
if (res.ec != std::errc()) {
TAG_LOGE(AAFwkTag::FORM_EXT, "from_chars error strFormId:%{public}s", strFormId.c_str());
formId = -1;
}
AppExecFwk::FormProviderData formProviderData;

View File

@ -151,7 +151,13 @@ void ResourceConfigHelper::UpdateResConfig(std::unique_ptr<Global::Resource::Res
TAG_LOGD(AAFwkTag::ABILITY, "set themeId: %{public}u", resConfig->GetThemeId());
}
}
resConfig->SetThemeIcon(!themeIcon_.empty());
if (!themeIcon_.empty()) {
uint32_t themeIcon = 0;
if (ConvertStringToUint32(themeIcon_, themeIcon)) {
resConfig->SetThemeIcon(themeIcon);
TAG_LOGD(AAFwkTag::ABILITY, "set themeIcon: %{public}u", themeIcon);
}
}
}
bool ResourceConfigHelper::ConvertStringToUint32(std::string source, uint32_t &result)

View File

@ -387,6 +387,7 @@ bool UIAbilityThread::SchedulePrepareTerminateAbility()
TAG_LOGI(AAFwkTag::UIABILITY, "ret: %{public}d", ret);
return ret;
}
isPrepareTerminateAbilityDone_.store(false);
wptr<UIAbilityThread> weak = this;
auto task = [weak]() {
TAG_LOGI(AAFwkTag::UIABILITY, "prepare terminate task");

View File

@ -12,9 +12,9 @@
# limitations under the License.
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//commonlibrary/memory_utils/purgeable_mem_config.gni")
import("//build/ohos.gni")
import("//build/templates/abc/ohos_abc.gni")
import("//commonlibrary/memory_utils/purgeable_mem_config.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
ohos_abc("delegator_mgmt") {
@ -187,9 +187,9 @@ ohos_shared_library("appkit_native") {
"faultloggerd:libfaultloggerd",
"ffrt:libffrt",
"graphic_2d:2d_graphics",
"graphic_2d:EGL",
"graphic_2d:libcomposer",
"graphic_2d:librender_service_base",
"graphic_2d:EGL",
"hicollie:libhicollie",
"hilog:libhilog",
"hisysevent:libhisysevent",

View File

@ -955,6 +955,7 @@ void ContextImpl::SubscribeToOverlayEvents(std::shared_ptr<Global::Resource::Res
const std::string &name, const std::string &hapModuleName, std::string &loadPath,
std::vector<AppExecFwk::OverlayModuleInfo> overlayModuleInfos)
{
std::lock_guard<std::mutex> lock(overlaySubscriberMutex_);
if (overlaySubscriber_ != nullptr) {
return;
}
@ -976,6 +977,7 @@ void ContextImpl::SubscribeToOverlayEvents(std::shared_ptr<Global::Resource::Res
void ContextImpl::UnsubscribeToOverlayEvents()
{
std::lock_guard<std::mutex> lock(overlaySubscriberMutex_);
if (overlaySubscriber_ != nullptr) {
EventFwk::CommonEventManager::UnSubscribeCommonEvent(overlaySubscriber_);
overlaySubscriber_ = nullptr;

View File

@ -62,7 +62,7 @@
#include "locale_config.h"
#include "ace_forward_compatibility.h"
#include "form_constants.h"
#include "include/private/EGL/cache.h"
#include "cache.h"
#ifdef SUPPORT_APP_PREFERRED_LANGUAGE
#include "preferred_language.h"
#endif
@ -191,6 +191,8 @@ void MainThread::GetNativeLibPath(const BundleInfo &bundleInfo, const HspList &h
libPath += (libPath.back() == '/') ? nativeLibraryPath : "/" + nativeLibraryPath;
TAG_LOGD(AAFwkTag::APPKIT, "lib path = %{private}s", libPath.c_str());
appLibPaths["default"].emplace_back(libPath);
} else {
TAG_LOGI(AAFwkTag::APPKIT, "nativeLibraryPath is empty");
}
for (auto &hapInfo : bundleInfo.hapModuleInfos) {
@ -2628,7 +2630,6 @@ void MainThread::ForceFullGC()
void MainThread::Start()
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::APPKIT, "App main thread create, pid:%{public}d", getprocpid());
std::shared_ptr<EventRunner> runner = EventRunner::GetMainEventRunner();

View File

@ -62,6 +62,7 @@ using SetRecordCallBack = void (*)(const std::function<void(void)> &startRecordF
std::mutex g_debuggerMutex;
std::mutex g_loadsoMutex;
std::mutex ConnectServerManager::instanceMutex_;
std::mutex ConnectServerManager::callbackMutex_;
std::unordered_map<int, std::pair<void*, const DebuggerPostTask>> g_debuggerInfo;
ConnectServerManager::~ConnectServerManager()
@ -110,6 +111,13 @@ void ConnectServerManager::StartConnectServer(const std::string& bundleName, int
return;
}
startServerForSocketPair(socketFd);
std::lock_guard<std::mutex> lock(callbackMutex_);
for (const auto &callback : connectServerCallbacks_) {
if (callback != nullptr) {
callback();
}
}
}
void ConnectServerManager::StopConnectServer(bool isCloseSo)
@ -444,4 +452,22 @@ void ConnectServerManager::SetRecordResults(const std::string &jsonArrayStr)
}
sendLayoutMessage(jsonArrayStr);
}
void ConnectServerManager::RegistConnectServerCallback(const ServerConnectCallback &connectServerCallback)
{
if (connectServerCallback == nullptr) {
TAG_LOGE(AAFwkTag::JSRUNTIME, "null callback");
return;
}
std::lock_guard<std::mutex> lock(callbackMutex_);
for (const auto &callback : connectServerCallbacks_) {
if (callback == connectServerCallback) {
TAG_LOGE(AAFwkTag::JSRUNTIME, "callback exist");
return;
}
}
connectServerCallbacks_.emplace_back(connectServerCallback);
TAG_LOGD(AAFwkTag::JSRUNTIME, "regist succeed");
}
} // namespace OHOS::AbilityRuntime

View File

@ -22,6 +22,7 @@
using DebuggerPostTask = std::function<void(std::function<void()>&&)>;
using DebuggerInfo = std::unordered_map<int, std::pair<void*, const DebuggerPostTask>>;
using InstanceMap = std::unordered_map<int32_t, std::string>;
using ServerConnectCallback = void(*)(void);
#ifdef APP_USE_ARM
constexpr char ARK_DEBUGGER_LIB_PATH[] = "libark_inspector.z.so";
#elif defined(APP_USE_X86_64)
@ -58,6 +59,7 @@ public:
bool SetRecordCallback(const std::function<void(void)> &startRecordFunc,
const std::function<void(void)> &stopRecordFunc);
void SetRecordResults(const std::string &jsonArrayStr);
void RegistConnectServerCallback(const ServerConnectCallback &connectServerCallback);
private:
ConnectServerManager() = default;
@ -68,11 +70,13 @@ private:
std::mutex mutex_;
static std::mutex instanceMutex_;
static std::mutex callbackMutex_;
std::atomic<bool> isConnected_ = false;
std::unordered_map<int32_t, std::pair<std::string, int32_t>> instanceMap_;
std::function<void(int32_t)> createLayoutInfo_;
std::function<void(int32_t)> setStatus_;
std::function<void(int32_t)> setArkUIStateProfilerStatus_;
std::vector<ServerConnectCallback> connectServerCallbacks_;
ConnectServerManager(const ConnectServerManager&) = delete;
ConnectServerManager(ConnectServerManager&&) = delete;
ConnectServerManager& operator=(const ConnectServerManager&) = delete;

View File

@ -97,6 +97,7 @@ const std::string TARGET_OHM = "targetohm";
const std::string SINCE_VERSION = "sinceVersion";
constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state";
const std::string MERGE_SOURCE_MAP_PATH = "ets/sourceMaps.map";
static auto PermissionCheckFunc = []() {
Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
@ -732,8 +733,17 @@ bool JsRuntime::Initialize(const Options& options)
}
if (!options.preload) {
std::string loadPath = ExtractorUtil::GetLoadFilePath(options.hapPath);
bool newCreate = false;
std::shared_ptr<Extractor> extractor = ExtractorUtil::GetExtractor(loadPath, newCreate);
bool hasFile = false;
if (!extractor) {
TAG_LOGD(AAFwkTag::JSRUNTIME, "Get extractor failed. hapPath[%{private}s]", loadPath.c_str());
} else {
hasFile = extractor->HasEntry(MERGE_SOURCE_MAP_PATH);
}
auto operatorObj = std::make_shared<JsEnv::SourceMapOperator>(options.bundleName, isModular,
options.isDebugVersion);
hasFile);
InitSourceMap(operatorObj);
if (options.isUnique) {
@ -1294,11 +1304,16 @@ bool JsRuntime::PopPreloadObj(const std::string& key, std::unique_ptr<NativeRefe
if (preloadList_.find(key) == preloadList_.end()) {
return false;
}
if (preloadList_[key] != nullptr) {
obj = std::move(preloadList_[key]);
preloadList_.erase(key);
return true;
}
preloadList_.erase(key);
return false;
}
NativeEngine& JsRuntime::GetNativeEngine() const
{
return *GetNativeEnginePointer();

View File

@ -113,7 +113,7 @@ void OHOSJsEnvironmentImpl::InitTimerModule(NativeEngine* engine)
{
TAG_LOGD(AAFwkTag::JSRUNTIME, "called");
CHECK_POINTER(engine);
auto ret = OHOS::JsSysModule::Timer::RegisterTime(reinterpret_cast<napi_env>(engine));
auto ret = JsSysModule::Timer::RegisterTime(reinterpret_cast<napi_env>(engine));
if (!ret) {
TAG_LOGE(AAFwkTag::JSRUNTIME, "Register timer failed");
}

View File

@ -325,6 +325,7 @@ PROCESS_EXIT:
EXIT_PID: {type: INT32, desc: pid}
PROCESS_NAME: {type: STRING, desc: process name}
EXTENSION_TYPE: {type: INT32, desc: process exit extension type}
EXIT_REASON: {type: INT32, desc: process exit reason}
PROCESS_START_FAILED:
__BASE: {type: FAULT, level: CRITICAL, tag: app, desc: process start failed, preserve: true}

View File

@ -730,10 +730,11 @@ public:
/**
* @brief mark a process which is going restart.
* @param uid the uid of the process.
* @param instanceKey the instance key of the process.
*
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t SignRestartAppFlag(int32_t uid)
virtual int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
return 0;
}
@ -855,13 +856,8 @@ public:
*/
virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName, std::vector<int32_t> &pidList) = 0;
/**
* Get appIndex of pid.
* @param pid The pid.
* @param appIndex appIndex of pid.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex)
virtual int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
const std::string& reason)
{
return 0;
}

View File

@ -117,7 +117,7 @@ enum class AppMgrInterfaceCode {
CHECK_IS_KIA_PROCESS = 91,
GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME = 92,
GET_All_RUNNING_INSTANCE_KEYS_BY_SELF = 93,
GET_APP_INDEX_BY_PID = 94,
KILL_APP_SELF_WITH_INSTANCE_KEY = 94,
};
} // AppExecFwk
} // OHOS

View File

@ -641,10 +641,11 @@ public:
/**
* @brief mark a process which is going restart.
* @param uid the uid of the process.
* @param instanceKey the instance key of the process.
*
* @return Returns ERR_OK on success, others on failure.
*/
int32_t SignRestartAppFlag(int32_t uid) override;
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey) override;
/**
* Get appRunningUniqueId by pid.
@ -740,7 +741,8 @@ public:
virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName,
std::vector<int32_t> &pidList) override;
virtual int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) override;
virtual int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
const std::string& reason) override;
private:
bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply);
bool WriteInterfaceToken(MessageParcel &data);

View File

@ -158,7 +158,7 @@ private:
int32_t HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
int32_t HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
int32_t HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetAppIndexByPid(MessageParcel &data, MessageParcel &reply);
int32_t HandleKillAppSelfWithInstanceKey(MessageParcel &data, MessageParcel &reply);
int32_t OnRemoteRequestInner(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option);

View File

@ -65,6 +65,8 @@ struct RunningProcessInfo : public Parcelable {
bool isStrictMode = false;
std::int32_t bundleType = 0;
std::int32_t appCloneIndex = -1;
std::string instanceKey = "";
AppExecFwk::MultiAppModeType appMode = AppExecFwk::MultiAppModeType::UNSPECIFIED;
bool ReadFromParcel(Parcel &parcel);
virtual bool Marshalling(Parcel &parcel) const override;

View File

@ -1750,7 +1750,7 @@ int32_t AppMgrProxy::UpdateRenderState(pid_t renderPid, int32_t state)
return reply.ReadInt32();
}
int32_t AppMgrProxy::SignRestartAppFlag(int32_t uid)
int32_t AppMgrProxy::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
MessageParcel data;
@ -1761,6 +1761,7 @@ int32_t AppMgrProxy::SignRestartAppFlag(int32_t uid)
return IPC_PROXY_ERR;
}
PARCEL_UTIL_WRITE_RET_INT(data, Int32, uid);
PARCEL_UTIL_WRITE_RET_INT(data, String, instanceKey);
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::SIGN_RESTART_APP_FLAG, data, reply, option);
return reply.ReadInt32();
@ -2073,25 +2074,22 @@ int32_t AppMgrProxy::CheckIsKiaProcess(pid_t pid, bool &isKia)
return ERR_OK;
}
int32_t AppMgrProxy::GetAppIndexByPid(pid_t pid, int32_t &appIndex)
int32_t AppMgrProxy::KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
const std::string& reason)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!WriteInterfaceToken(data)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
return ERR_INVALID_VALUE;
}
PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
PARCEL_UTIL_WRITE_RET_INT(data, String, instanceKey);
PARCEL_UTIL_WRITE_RET_INT(data, Bool, clearPageStack);
PARCEL_UTIL_WRITE_RET_INT(data, String, reason);
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_APP_INDEX_BY_PID, data, reply, option);
int32_t ret = reply.ReadInt32();
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "failed,ret=%{public}d.", ret);
return ret;
}
appIndex = reply.ReadInt32();
return ERR_OK;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::KILL_APP_SELF_WITH_INSTANCE_KEY, data, reply, option);
return reply.ReadInt32();
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -345,8 +345,8 @@ int32_t AppMgrStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &da
return HandleRegisterKiaInterceptor(data, reply);
case static_cast<uint32_t>(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS):
return HandleCheckIsKiaProcess(data, reply);
case static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_INDEX_BY_PID):
return HandleGetAppIndexByPid(data, reply);
case static_cast<uint32_t>(AppMgrInterfaceCode::KILL_APP_SELF_WITH_INSTANCE_KEY):
return HandleKillAppSelfWithInstanceKey(data, reply);
}
return INVALID_FD;
}
@ -1468,7 +1468,8 @@ int32_t AppMgrStub::HandleSignRestartAppFlag(MessageParcel &data, MessageParcel
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto uid = data.ReadInt32();
auto ret = SignRestartAppFlag(uid);
auto instanceKey = data.ReadString();
auto ret = SignRestartAppFlag(uid, instanceKey);
if (!reply.WriteInt32(ret)) {
TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
return IPC_STUB_ERR;
@ -1691,19 +1692,16 @@ int32_t AppMgrStub::HandleCheckIsKiaProcess(MessageParcel &data, MessageParcel &
return NO_ERROR;
}
int32_t AppMgrStub::HandleGetAppIndexByPid(MessageParcel &data, MessageParcel &reply)
int32_t AppMgrStub::HandleKillAppSelfWithInstanceKey(MessageParcel &data, MessageParcel &reply)
{
TAG_LOGD(AAFwkTag::APPMGR, "call");
auto pid = data.ReadInt32();
int32_t appIndex = -1;
int32_t result = GetAppIndexByPid(pid, appIndex);
auto instanceKey = data.ReadString();
auto clearPageStack = data.ReadBool();
auto reason = data.ReadString();
auto result = KillAppSelfWithInstanceKey(instanceKey, clearPageStack, reason);
if (!reply.WriteInt32(result)) {
TAG_LOGE(AAFwkTag::APPMGR, "fail to write GetAppIndexByPid result.");
return IPC_STUB_ERR;
}
if (!reply.WriteInt32(appIndex)) {
TAG_LOGE(AAFwkTag::APPMGR, "fail to write appIndex.");
return IPC_STUB_ERR;
TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}

View File

@ -61,6 +61,10 @@ bool RunningProcessInfo::ReadFromParcel(Parcel &parcel)
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionType);
extensionType_ = static_cast<ExtensionAbilityType>(extensionType);
appCloneIndex = parcel.ReadInt32();
instanceKey = Str16ToStr8(parcel.ReadString16());
int32_t appModeType;
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appModeType);
appMode = static_cast<AppExecFwk::MultiAppModeType>(appModeType);
return true;
}
@ -95,6 +99,8 @@ bool RunningProcessInfo::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(processType_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(extensionType_));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appCloneIndex);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(instanceKey));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(appMode));
return true;
}
} // namespace AppExecFwk

View File

@ -11,9 +11,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/config/components/idl_tool/idl.gni")
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
import("//build/config/components/idl_tool/idl.gni")
idl_interface_sources = [
"${target_gen_dir}/quick_fix_manager_proxy.cpp",

View File

@ -104,8 +104,8 @@ ohos_shared_library("runtime") {
"config_policy:configpolicy_util",
"ets_runtime:libark_jsruntime",
"ets_utils:console",
"ets_utils:worker",
"ets_utils:timer",
"ets_utils:worker",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"hilog:libhilog",
@ -116,7 +116,6 @@ ohos_shared_library("runtime") {
"jsoncpp:jsoncpp",
"napi:ace_napi",
"resource_management:global_resmgr",
"runtime_core:libarkbase_static",
"samgr:samgr_proxy",
"zlib:shared_libz",
]
@ -124,7 +123,6 @@ ohos_shared_library("runtime") {
public_external_deps = [
"ability_base:session_info",
"ability_base:want",
"ets_utils:console",
]
defines = []

View File

@ -495,6 +495,7 @@ private:
// False: no need to get a new fms remote object.
volatile bool resetFlag_ = false;
std::mutex overlaySubscriberMutex_;
std::shared_ptr<AppExecFwk::OverlayEventSubscriber> overlaySubscriber_;
};
} // namespace AbilityRuntime

View File

@ -29,8 +29,8 @@ enum InitStatus { NOT_EXECUTED, EXECUTED_SUCCESSFULLY };
}
class SourceMapOperator : public std::enable_shared_from_this<SourceMapOperator> {
public:
SourceMapOperator(const std::string bundleName, bool isModular, bool isDebugVersion)
: bundleName_(bundleName), isModular_(isModular), isDebugVersion_(isDebugVersion), initStatus_(NOT_EXECUTED) {}
SourceMapOperator(const std::string bundleName, bool isModular, bool hasFile)
: bundleName_(bundleName), isModular_(isModular), hasFile_(hasFile), initStatus_(NOT_EXECUTED) {}
~SourceMapOperator() = default;
@ -60,7 +60,7 @@ public:
if (sourceMapObj_ == nullptr) {
return "";
}
if (isDebugVersion_) {
if (hasFile_) {
return sourceMapObj_->TranslateBySourceMap(stackStr);
} else {
return NOT_FOUNDMAP + stackStr;
@ -88,7 +88,7 @@ public:
private:
const std::string bundleName_;
bool isModular_ = false;
bool isDebugVersion_ = false;
bool hasFile_ = false;
std::shared_ptr<SourceMap> sourceMapObj_;
InitStatus initStatus_;
};

View File

@ -66,6 +66,7 @@ abilityms_files = [
"src/interceptor/screen_unlock_interceptor.cpp",
"src/interceptor/start_other_app_interceptor.cpp",
"src/window_focus_changed_listener.cpp",
"src/window_visibility_changed_listener.cpp",
# start ability handler
"src/start_ability_handler.cpp",

View File

@ -102,8 +102,9 @@ public:
/**
* Sign the restart flag by uid of ability from ability cache manager.
* @param uid the ability uid to be searched in cache manager.
* @param instanceKey the instance key of the process.
*/
void SignRestartAppFlag(int32_t uid);
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
/**
* Delete the invalid ability by bundleName from ability cache manager.

View File

@ -325,7 +325,7 @@ public:
void CloseAssertDialog(const std::string &assertSessionId);
void SignRestartAppFlag(int32_t uid);
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
std::shared_ptr<AAFwk::AbilityRecord> GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token);
void UninstallApp(const std::string &bundleName);

View File

@ -75,6 +75,7 @@ class IStatusBarDelegate;
}
namespace Rosen {
class FocusChangeInfo;
class WindowVisibilityInfo;
}
namespace AAFwk {
@ -87,6 +88,7 @@ constexpr const char* KEY_SESSION_ID = "com.ohos.param.sessionId";
using OHOS::AppExecFwk::IAbilityController;
struct StartAbilityInfo;
class WindowFocusChangedListener;
class WindowVisibilityChangedListener;
/**
* @class AbilityManagerService
@ -1197,6 +1199,9 @@ public:
void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
void HandleWindowVisibilityChanged(
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos);
virtual int GetDialogSessionInfo(const std::string &dialogSessionId,
sptr<DialogSessionInfo> &dialogSessionInfo) override;
@ -1921,6 +1926,9 @@ private:
int StartAbilityPublicPrechainCheck(StartAbilityParams &params);
int StartAbilityPrechainInterceptor(StartAbilityParams &params);
bool StartAbilityInChain(StartAbilityParams &params, int &result);
void InitWindowVisibilityChangedListener();
void FreeWindowVisibilityChangedListener();
bool CheckProcessIsBackground(int32_t pid, AbilityState currentState);
bool CheckIfOperateRemote(const Want &want);
std::string AnonymizeDeviceId(const std::string& deviceId);
@ -2255,8 +2263,9 @@ private:
void WaitBootAnimationStart();
int32_t SignRestartAppFlag(int32_t userId, int32_t uid, bool isAppRecovery = false);
int32_t CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex);
int32_t SignRestartAppFlag(int32_t userId, int32_t uid, const std::string &instanceKey,
AppExecFwk::MultiAppModeType type, bool isAppRecovery = false);
int32_t CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex, int32_t userId);
int StartUIAbilityForOptionWrap(const Want &want, const StartOptions &options, sptr<IRemoteObject> callerToken,
bool isPendingWantCaller, int32_t userId, int requestCode, uint32_t callerTokenId = 0, bool isImplicit = false,
@ -2323,6 +2332,7 @@ private:
bool CheckWorkSchedulerPermission(const sptr<IRemoteObject> &callerToken, const uint32_t uid);
sptr<WindowVisibilityChangedListener> windowVisibilityChangedListener_;
std::shared_ptr<TaskHandlerWrap> taskHandler_;
std::shared_ptr<AbilityEventHandler> eventHandler_;
ServiceRunningState state_;
@ -2334,10 +2344,13 @@ private:
std::shared_ptr<UserController> userController_;
sptr<AppExecFwk::IAbilityController> abilityController_ = nullptr;
bool controllerIsAStabilityTest_ = false;
std::unordered_set<int32_t> windowVisibleList_;
ffrt::mutex globalLock_;
ffrt::mutex bgtaskObserverMutex_;
ffrt::mutex abilityTokenLock_;
ffrt::mutex preStartSessionMapLock_;
ffrt::mutex windowVisibleListLock_;
std::multimap<std::string, std::string> timeoutMap_;
std::map<std::string, sptr<SessionInfo>> preStartSessionMap_;

View File

@ -277,6 +277,7 @@ struct AbilityRequest {
bool uriReservedFlag = false;
std::string reservedBundleName;
bool isFromIcon = false;
bool isShellCall = false;
std::pair<bool, LaunchReason> IsContinuation() const
{
auto flags = want.GetFlags();
@ -400,7 +401,7 @@ public:
*
* @return Returns ERR_OK on success, others on failure.
*/
int LoadAbility();
int LoadAbility(bool isShellCall = false);
/**
* foreground the ability.
@ -413,7 +414,7 @@ public:
* process request of foregrounding the ability.
*
*/
void ProcessForegroundAbility(uint32_t tokenId, uint32_t sceneFlag = 0);
void ProcessForegroundAbility(uint32_t tokenId, uint32_t sceneFlag = 0, bool isShellCall = false);
/**
* post foreground timeout task for ui ability.

View File

@ -40,6 +40,9 @@ namespace OHOS {
namespace AppExecFwk {
class Configuration;
}
namespace AbilityRuntime {
struct LoadParam;
}
namespace AAFwk {
/**
* @enum AppAbilityState
@ -139,16 +142,14 @@ public:
/**
* load ability with token, ability info and application info.
*
* @param token, the token of ability.
* @param preToken, the token of ability's caller.
* @param loadParam, the loadParam of ability.
* @param abilityInfo, ability info.
* @param applicationInfo, application info.
* @param want ability want
* @return true on success ,false on failure.
*/
int LoadAbility(sptr<IRemoteObject> token, sptr<IRemoteObject> preToken,
const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo,
const Want &want, int32_t abilityRecordId, const std::string &instanceKey);
int LoadAbility(const AbilityRuntime::LoadParam &loadParam, const AppExecFwk::AbilityInfo &abilityInfo,
const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want);
/**
* terminate ability with token.

View File

@ -18,6 +18,7 @@
#include "ability_interceptor_interface.h"
#include "ability_record.h"
#include "app_mgr_interface.h"
#include "disposed_observer.h"
#include "task_utils_wrap.h"

View File

@ -222,7 +222,7 @@ public:
int32_t GetMissionCount() const;
void GetActiveAbilityList(int32_t uid, std::vector<std::string> &abilityList, int32_t pid = NO_PID);
void SignRestartAppFlag(int32_t uid);
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
private:
std::string GetTypeName();

View File

@ -365,7 +365,7 @@ public:
bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord) override;
void SignRestartAppFlag(int32_t uid) override;
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey) override;
void SetAnimationFlag(bool IsAnimationEnabled);
#ifdef SUPPORT_SCREEN

View File

@ -113,7 +113,7 @@ public:
const AAFwk::ContinueState &state) = 0;
virtual bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord) = 0;
virtual void SignRestartAppFlag(int32_t uid) = 0;
virtual void SignRestartAppFlag(int32_t uid, const std::string &instanceKey) = 0;
#ifdef SUPPORT_SCREEN
public:
virtual int SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label) = 0;

View File

@ -56,6 +56,7 @@ public:
int32_t GetUserId();
bool IsEqualsRequestWant(const Want &otherWant);
int32_t GetAppIndex();
void GetAllBundleNames(std::vector<std::string> &bundleNames);
private:
int32_t type_ = {};

View File

@ -31,6 +31,7 @@
#include "pending_want_record.h"
#include "pending_want_common_event.h"
#include "sender_info.h"
#include "task_handler_wrap.h"
#include "want_sender_info.h"
namespace OHOS {
@ -184,17 +185,10 @@ private:
bool CheckWindowState(int32_t pid);
void EraseBundleRecord(const std::vector<WantsInfo> &wantsInfos, std::shared_ptr<PendingWantKey> key);
void InsertBundleRecord(const std::vector<WantsInfo> &wantsInfos, std::shared_ptr<PendingWantKey> key);
bool QueryRecordByBundle(const std::string &bundleName);
private:
std::shared_ptr<TaskHandlerWrap> taskHandler_;
std::map<std::shared_ptr<PendingWantKey>, sptr<PendingWantRecord>> wantRecords_;
std::map<std::string, std::vector<std::shared_ptr<PendingWantKey>>> bundleRecords_;
ffrt::mutex mutex_;
ffrt::mutex bundleRecordsMutex_;
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -24,25 +24,47 @@
namespace OHOS {
namespace AAFwk {
typedef struct RestartAppKey {
int32_t uid = 0;
std::string instanceKey = "";
RestartAppKey(std::string callingInstanceKey, int32_t callingUid)
{
instanceKey = callingInstanceKey;
uid = callingUid;
}
bool operator ==(const struct RestartAppKey &other) const
{
return instanceKey == other.instanceKey && uid == other.uid;
}
} RestartAppKeyType;
struct RestartAppKeyHash {
size_t operator()(const RestartAppKeyType &p) const
{
return std::hash<std::string>()(p.instanceKey) ^ std::hash<int>()(p.uid);
}
};
/**
* @class RestartAppManager
* RestartAppManager provides a facility for managing restart app history.
*/
class RestartAppManager {
public:
using RestartAppMapType = std::unordered_map<RestartAppKeyType, time_t, RestartAppKeyHash>;
virtual ~RestartAppManager() = default;
static RestartAppManager &GetInstance();
bool IsRestartAppFrequent(int32_t uid, time_t time);
void AddRestartAppHistory(int32_t uid, time_t time);
bool IsForegroundToRestartApp() const;
bool IsRestartAppFrequent(const RestartAppKeyType &key, time_t time);
void AddRestartAppHistory(const RestartAppKeyType &key, time_t time);
private:
RestartAppManager() = default;
DISALLOW_COPY_AND_MOVE(RestartAppManager);
ffrt::mutex restartAppMapLock_;
std::unordered_map<int32_t, time_t> restartAppHistory_; // RestartAppKey:time
RestartAppMapType restartAppHistory_; // RestartAppKey:time
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -56,7 +56,7 @@ public:
}
};
void SignRestartAppFlag(int32_t uid, bool isAppRecovery = false);
void SignRestartAppFlag(int32_t uid, const std::string &instanceKey, bool isAppRecovery = false);
/**
* StartUIAbility with request.
@ -162,7 +162,7 @@ public:
*/
void SetRootSceneSession(const sptr<IRemoteObject> &rootSceneSession);
int NotifySCBToStartUIAbility(const AbilityRequest &abilityRequest);
int NotifySCBToStartUIAbility(AbilityRequest &abilityRequest);
void CancelSameAbilityTimeoutTask(const AppExecFwk::AbilityInfo &abilityInfo);
int NotifySCBToPreStartUIAbility(const AbilityRequest &abilityRequest,

View File

@ -85,6 +85,8 @@ public:
*/
int32_t CheckMultiInstanceKeyForExtension(const AbilityRequest &abilityRequest);
bool VerifyCallerToken(AbilityRequest &abilityRequest);
private:
/**
* AbilityPermissionUtil, the private constructor.

View File

@ -54,14 +54,6 @@ public:
* @return Flag if the want contains atomic service url.
*/
static bool IsAtomicServiceUrl(const Want& want);
/**
* Get app index.
*
* @param want The want.
* @return AppIndex if the want contains app index.
*/
static int32_t GetAppIndex(const Want& want);
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_MANAGER_WINDOW_VISIBILITY_CHANGE_LISTENER_H
#define OHOS_ABILITY_MANAGER_WINDOW_VISIBILITY_CHANGE_LISTENER_H
#include "task_handler_wrap.h"
#include "window_manager.h"
namespace OHOS {
namespace AAFwk {
class AbilityManagerService;
class WindowVisibilityChangedListener : public OHOS::Rosen::IVisibilityChangedListener {
public:
WindowVisibilityChangedListener(
const std::weak_ptr<AbilityManagerService> &owner, const std::shared_ptr<AAFwk::TaskHandlerWrap> &handler);
virtual ~WindowVisibilityChangedListener() = default;
void OnWindowVisibilityChanged(
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos) override;
private:
std::weak_ptr<AbilityManagerService> owner_;
std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_MANAGER_WINDOW_VISIBILITY_CHANGE_LISTENER_H

View File

@ -284,13 +284,14 @@ void AbilityCacheManager::RemoveLauncherDeathRecipient()
}
}
void AbilityCacheManager::SignRestartAppFlag(int32_t uid)
void AbilityCacheManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
std::lock_guard<std::mutex> lock(mutex_);
auto it = devRecLru_.begin();
while (it != devRecLru_.end()) {
auto abilityRecord = *it;
if (abilityRecord != nullptr && abilityRecord->GetUid() == uid) {
if (abilityRecord != nullptr && abilityRecord->GetUid() == uid &&
abilityRecord->GetInstanceKey() == instanceKey) {
abilityRecord->SetRestartAppFlag(true);
}
it++;

View File

@ -27,6 +27,7 @@
#include "hitrace_meter.h"
#include "int_wrapper.h"
#include "multi_instance_utils.h"
#include "param.h"
#include "res_sched_util.h"
#include "session/host/include/zidl/session_interface.h"
#include "startup_util.h"
@ -1030,7 +1031,7 @@ int AbilityConnectManager::ScheduleConnectAbilityDoneLocked(
}
CompleteStartServiceReq(abilityRecord->GetURI());
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::CONNECT_END, abilityRecord->GetPid(),
abilityRecord->GetUid());
abilityRecord->GetUid(), 0, abilityRecord->GetAbilityRecordId());
return ERR_OK;
}
@ -1433,9 +1434,14 @@ void AbilityConnectManager::LoadAbility(const std::shared_ptr<AbilityRecord> &ab
}
UpdateUIExtensionInfo(abilityRecord);
AbilityRuntime::LoadParam loadParam;
loadParam.abilityRecordId = abilityRecord->GetRecordId();
loadParam.isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall();
loadParam.token = token;
loadParam.preToken = perToken;
loadParam.instanceKey = abilityRecord->GetInstanceKey();
DelayedSingleton<AppScheduler>::GetInstance()->LoadAbility(
token, perToken, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo(),
abilityRecord->GetWant(), abilityRecord->GetRecordId(), abilityRecord->GetInstanceKey());
loadParam, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo(), abilityRecord->GetWant());
abilityRecord->SetLoadState(AbilityLoadState::LOADING);
}
@ -1506,7 +1512,7 @@ void AbilityConnectManager::PostTimeOutTask(const std::shared_ptr<AbilityRecord>
taskName = std::string("ConnectTimeout_") + std::to_string(connectRecordId);
delayTime = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * CONNECT_TIMEOUT_MULTIPLE;
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::CONNECT_BEGIN, abilityRecord->GetPid(),
abilityRecord->GetUid(), delayTime);
abilityRecord->GetUid(), delayTime, abilityRecord->GetAbilityRecordId());
} else {
TAG_LOGE(AAFwkTag::ABILITYMGR, "messageId error");
return;
@ -1668,6 +1674,11 @@ int AbilityConnectManager::DispatchInactive(const std::shared_ptr<AbilityRecord>
}
eventHandler_->RemoveEvent(AbilityManagerService::INACTIVE_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId());
if (abilityRecord->GetAbilityInfo().extensionAbilityType == AppExecFwk::ExtensionAbilityType::SERVICE) {
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::LOAD_END,
abilityRecord->GetPid(), abilityRecord->GetUid(), 0, abilityRecord->GetAbilityRecordId());
}
// complete inactive
abilityRecord->SetAbilityState(AbilityState::INACTIVE);
if (abilityRecord->IsCreateByConnect()) {
@ -3115,18 +3126,19 @@ int32_t AbilityConnectManager::GetUIExtensionSessionInfo(const sptr<IRemoteObjec
return uiExtensionAbilityRecordMgr_->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo);
}
void AbilityConnectManager::SignRestartAppFlag(int32_t uid)
void AbilityConnectManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
{
std::lock_guard lock(serviceMapMutex_);
for (auto &[key, abilityRecord] : serviceMap_) {
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid) {
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid ||
abilityRecord->GetInstanceKey() != instanceKey) {
continue;
}
abilityRecord->SetRestartAppFlag(true);
}
}
AbilityCacheManager::GetInstance().SignRestartAppFlag(uid);
AbilityCacheManager::GetInstance().SignRestartAppFlag(uid, instanceKey);
}
bool AbilityConnectManager::AddToServiceMap(const std::string &key, std::shared_ptr<AbilityRecord> abilityRecord)

View File

@ -465,8 +465,7 @@ ErrCode AbilityManagerClient::CloseUIAbilityBySCB(sptr<SessionInfo> sessionInfo)
}
auto abms = GetAbilityManager();
CHECK_POINTER_RETURN_NOT_CONNECTED(abms);
TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, CloseUIAbilityBySCB target: %{public}s",
sessionInfo->want.GetElement().GetURI().c_str());
TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, CloseUIAbilityBySCB");
return abms->CloseUIAbilityBySCB(sessionInfo);
}

View File

@ -93,6 +93,7 @@
#include "session_manager_lite.h"
#include "window_focus_changed_listener.h"
#endif
#include "window_visibility_changed_listener.h"
using OHOS::AppExecFwk::ElementName;
using OHOS::Security::AccessToken::AccessTokenKit;
@ -241,6 +242,7 @@ constexpr const char* BOOTEVENT_BOOT_ANIMATION_READY = "bootevent.bootanimation.
constexpr const char* NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow";
constexpr const char* PERMISSIONMGR_BUNDLE_NAME = "com.ohos.permissionmanager";
constexpr const char* PERMISSIONMGR_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility";
constexpr const char* SCENEBOARD_BUNDLE_NAME = "com.ohos.sceneboard";
constexpr const char* IS_CALL_BY_SCB = "isCallBySCB";
constexpr const char* SPECIFY_TOKEN_ID = "specifyTokenId";
constexpr const char* PROCESS_SUFFIX = "embeddable";
@ -301,6 +303,7 @@ void AbilityManagerService::OnStart()
#ifdef SUPPORT_SCREEN
AddSystemAbilityListener(MULTIMODAL_INPUT_SERVICE_ID);
#endif
AddSystemAbilityListener(WINDOW_MANAGER_SERVICE_ID);
TAG_LOGI(AAFwkTag::ABILITYMGR, "onStart success");
auto pid = getpid();
std::unordered_map<std::string, std::string> payload;
@ -1019,13 +1022,6 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller invalid");
return ERR_INVALID_CALLER;
}
if (callerToken != nullptr) {
bool isAppKilling = IN_PROCESS_CALL(DelayedSingleton<AppScheduler>::GetInstance()->IsAppKilling(callerToken));
if (isAppKilling) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller killing");
return ERR_INVALID_CALLER;
}
}
{
#ifdef WITH_DLP
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "CHECK_DLP");
@ -2518,6 +2514,10 @@ void AbilityManagerService::OnAddSystemAbility(int32_t systemAbilityId, const st
break;
}
#endif
case WINDOW_MANAGER_SERVICE_ID: {
InitWindowVisibilityChangedListener();
break;
}
default:
break;
}
@ -2539,6 +2539,10 @@ void AbilityManagerService::OnRemoveSystemAbility(int32_t systemAbilityId, const
UnsubscribeBundleEventCallback();
break;
}
case WINDOW_MANAGER_SERVICE_ID: {
FreeWindowVisibilityChangedListener();
break;
}
default:
break;
}
@ -3644,8 +3648,8 @@ int AbilityManagerService::CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionI
auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid());
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
TAG_LOGI(AAFwkTag::ABILITYMGR,
"close session: %{public}d, resultCode: %{public}d", sessionInfo->persistentId, sessionInfo->resultCode);
TAG_LOGI(AAFwkTag::ABILITYMGR, "close session: %{public}d, resultCode: %{public}d, isClearSession: %{public}d",
sessionInfo->persistentId, sessionInfo->resultCode, sessionInfo->isClearSession);
auto abilityRecord = uiAbilityManager->GetUIAbilityRecordBySessionInfo(sessionInfo);
CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE);
if (!IsAbilityControllerForeground(abilityRecord->GetAbilityInfo().bundleName)) {
@ -7499,6 +7503,7 @@ int AbilityManagerService::StopUser(int userId, const sptr<IUserCallback> &callb
int AbilityManagerService::LogoutUser(int32_t userId)
{
TAG_LOGI(AAFwkTag::ABILITYMGR, "LogoutUser in service:%{public}d", userId);
if (IPCSkeleton::GetCallingUid() != ACCOUNT_MGR_SERVICE_UID) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "permission verification failed, not account process");
return CHECK_PERMISSION_FAILED;
@ -11257,55 +11262,50 @@ int32_t AbilityManagerService::GetUIExtensionSessionInfo(const sptr<IRemoteObjec
int32_t AbilityManagerService::RestartApp(const AAFwk::Want &want, bool isAppRecovery)
{
TAG_LOGI(AAFwkTag::ABILITYMGR, "RestartApp, isAppRecovery: %{public}d", isAppRecovery);
auto appIndex = WantUtils::GetAppIndex(want);
int result = CheckRestartAppWant(want, appIndex);
auto callerPid = IPCSkeleton::GetCallingPid();
AppExecFwk::RunningProcessInfo processInfo;
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo);
int32_t callerUid = IPCSkeleton::GetCallingUid();
int32_t userId = callerUid / BASE_USER_RANGE;
auto result = CheckRestartAppWant(want, processInfo.appCloneIndex, userId);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "checkRestartAppWant error");
return result;
}
int32_t callerUid = IPCSkeleton::GetCallingUid();
int64_t now = time(nullptr);
if (!isAppRecovery && RestartAppManager::GetInstance().IsRestartAppFrequent(callerUid, now)) {
return AAFwk::ERR_RESTART_APP_FREQUENT;
}
bool isForegroundToRestartApp = RestartAppManager::GetInstance().IsForegroundToRestartApp();
if (!isForegroundToRestartApp) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "restartApp, isForegroundToRestartApp failed");
if (!processInfo.isFocused && !processInfo.isAbilityForegrounding) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "restartApp, is not foreground");
return AAFwk::NOT_TOP_ABILITY;
}
int32_t userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE;
result = SignRestartAppFlag(userId, callerUid, isAppRecovery);
RestartAppKeyType key(processInfo.instanceKey, callerUid);
int64_t now = time(nullptr);
if (!isAppRecovery && RestartAppManager::GetInstance().IsRestartAppFrequent(key, now)) {
return AAFwk::ERR_RESTART_APP_FREQUENT;
}
result = SignRestartAppFlag(userId, callerUid, processInfo.instanceKey, processInfo.appMode, isAppRecovery);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "signRestartAppFlag error");
return result;
}
result = DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf(false, "RestartApp");
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "killApplicationSelf error");
return result;
}
TAG_LOGD(AAFwkTag::ABILITYMGR, "restartApp, without checkCallAbilityPermission.");
(const_cast<Want &>(want)).SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, appIndex);
result = StartAbilityWrap(want, nullptr,
DEFAULT_INVAL_VALUE, false, DEFAULT_INVAL_VALUE, false, 0, isForegroundToRestartApp);
(const_cast<Want &>(want)).SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, processInfo.appCloneIndex);
(const_cast<Want &>(want)).SetParam(AAFwk::Want::APP_INSTANCE_KEY, processInfo.instanceKey);
(const_cast<Want &>(want)).RemoveParam(Want::CREATE_APP_INSTANCE_KEY);
result = StartAbilityWrap(want, nullptr, DEFAULT_INVAL_VALUE, false, DEFAULT_INVAL_VALUE, false, 0, true);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility error");
return result;
}
if (!isAppRecovery) {
RestartAppManager::GetInstance().AddRestartAppHistory(callerUid, now);
RestartAppManager::GetInstance().AddRestartAppHistory(key, now);
}
return result;
}
int32_t AbilityManagerService::CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex)
int32_t AbilityManagerService::CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex, int32_t userId)
{
std::string bundleName = want.GetElement().GetBundleName();
auto userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE;
if (!CheckCallingTokenId(bundleName, userId, appIndex)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "no itself called, no allowed");
return AAFwk::ERR_RESTART_APP_INCORRECT_ABILITY;
@ -11325,34 +11325,40 @@ int32_t AbilityManagerService::CheckRestartAppWant(const AAFwk::Want &want, int3
return ERR_OK;
}
int32_t AbilityManagerService::SignRestartAppFlag(int32_t userId, int32_t uid, bool isAppRecovery)
int32_t AbilityManagerService::SignRestartAppFlag(int32_t userId, int32_t uid, const std::string &instanceKey,
AppExecFwk::MultiAppModeType type, bool isAppRecovery)
{
auto appMgr = AppMgrUtil::GetAppMgr();
if (appMgr == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
return ERR_INVALID_VALUE;
}
auto ret = IN_PROCESS_CALL(appMgr->SignRestartAppFlag(uid));
auto ret = IN_PROCESS_CALL(appMgr->SignRestartAppFlag(uid, instanceKey));
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgr signRestartAppFlag error");
return ret;
}
auto connectManager = GetConnectManagerByUserId(userId);
connectManager->SignRestartAppFlag(uid);
connectManager->SignRestartAppFlag(uid, instanceKey);
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
auto uiAbilityManager = GetUIAbilityManagerByUserId(userId);
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
uiAbilityManager->SignRestartAppFlag(uid, isAppRecovery);
return ERR_OK;
}
uiAbilityManager->SignRestartAppFlag(uid, instanceKey, isAppRecovery);
} else {
auto missionListManager = GetMissionListManagerByUserId(userId);
if (missionListManager == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListManager null userId:%{public}d", userId);
return ERR_INVALID_VALUE;
}
missionListManager->SignRestartAppFlag(uid);
return ERR_OK;
missionListManager->SignRestartAppFlag(uid, instanceKey);
}
if (type == AppExecFwk::MultiAppModeType::MULTI_INSTANCE) {
return appMgr->KillAppSelfWithInstanceKey(instanceKey, false, "RestartInstance");
} else {
return DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf(false, "RestartApp");
}
}
bool AbilityManagerService::IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken, const std::string &appId)
@ -11398,6 +11404,81 @@ bool AbilityManagerService::IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToke
return erms->DoProcess(want, GetUserId());
}
bool AbilityManagerService::CheckProcessIsBackground(int32_t pid, AbilityState currentState)
{
TAG_LOGI(AAFwkTag::ABILITYMGR, "pid:%{public}d, currentState:%{public}d", pid, currentState);
std::lock_guard<ffrt::mutex> myLockGuard(windowVisibleListLock_);
if (currentState == AAFwk::AbilityState::BACKGROUND &&
windowVisibleList_.find(pid) != windowVisibleList_.end()) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "Process window is occluded");
return false;
}
if (currentState != AAFwk::AbilityState::BACKGROUND) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "Process is not on background Pass");
return false;
}
return true;
}
void AbilityManagerService::InitWindowVisibilityChangedListener()
{
if (windowVisibilityChangedListener_ != nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "visibility already initiate");
return;
}
windowVisibilityChangedListener_ =
new (std::nothrow) WindowVisibilityChangedListener(weak_from_this(), taskHandler_);
if (windowVisibilityChangedListener_ == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "window visibility changed listener null");
return;
}
Rosen::WindowManager::GetInstance().RegisterVisibilityChangedListener(windowVisibilityChangedListener_);
}
void AbilityManagerService::FreeWindowVisibilityChangedListener()
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (windowVisibilityChangedListener_ == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "visibility listener already free");
return;
}
Rosen::WindowManager::GetInstance().UnregisterVisibilityChangedListener(windowVisibilityChangedListener_);
windowVisibilityChangedListener_ = nullptr;
}
void AbilityManagerService::HandleWindowVisibilityChanged(
const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (windowVisibilityInfos.empty()) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "window visibility info empty");
return;
}
std::lock_guard<ffrt::mutex> myLockGuard(windowVisibleListLock_);
for (const auto &info : windowVisibilityInfos) {
if (info == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "null info");
continue;
}
int uid = 0;
std::string bundleName;
if (info->windowType_ == Rosen::WindowType::WINDOW_TYPE_DESKTOP &&
info->visibilityState_ == Rosen::WINDOW_VISIBILITY_STATE_NO_OCCLUSION) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "desktop is visible clear windowVisibleList_");
windowVisibleList_.clear();
continue;
}
DelayedSingleton<AppScheduler>::GetInstance()->GetBundleNameByPid(info->pid_, bundleName, uid);
if (info->visibilityState_ == Rosen::WINDOW_VISIBILITY_STATE_NO_OCCLUSION &&
bundleName != SCENEBOARD_BUNDLE_NAME) {
windowVisibleList_.insert(info->pid_);
}
}
}
bool AbilityManagerService::ShouldPreventStartAbility(const AbilityRequest &abilityRequest)
{
std::shared_ptr<AbilityRecord> abilityRecord = Token::GetAbilityRecordByToken(abilityRequest.callerToken);
@ -11432,8 +11513,7 @@ bool AbilityManagerService::ShouldPreventStartAbility(const AbilityRequest &abil
TAG_LOGD(AAFwkTag::ABILITYMGR, "Is not UI Ability Pass");
return false;
}
if (abilityRecord->GetAbilityState() != AAFwk::AbilityState::BACKGROUND) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "Process is not on background Pass");
if (!CheckProcessIsBackground(abilityRecord->GetPid(), abilityRecord->GetAbilityState())) {
return false;
}
if (continuousFlag) {

View File

@ -41,6 +41,7 @@
#include "system_ability_token_callback.h"
#include "ui_extension_utils.h"
#include "uri_permission_manager_client.h"
#include "param.h"
#include "permission_constants.h"
#include "process_options.h"
#include "uri_utils.h"
@ -308,7 +309,7 @@ void AbilityRecord::LoadUIAbility()
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::LOAD, methodName);
}
int AbilityRecord::LoadAbility()
int AbilityRecord::LoadAbility(bool isShellCall)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "LoadLifecycle: abilityName:%{public}s", abilityInfo_.name.c_str());
@ -344,9 +345,20 @@ int AbilityRecord::LoadAbility()
std::lock_guard guard(wantLock_);
want_.SetParam(ABILITY_OWNER_USERID, ownerMissionUserId_);
AbilityRuntime::LoadParam loadParam;
loadParam.abilityRecordId = recordId_;
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
loadParam.isShellCall = isShellCall;
} else {
loadParam.isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall();
}
loadParam.token = token_;
loadParam.preToken = callerToken_;
loadParam.instanceKey = instanceKey_;
auto result = DelayedSingleton<AppScheduler>::GetInstance()->LoadAbility(
token_, callerToken_, abilityInfo_, abilityInfo_.applicationInfo, want_, recordId_, instanceKey_);
loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_);
want_.RemoveParam(ABILITY_OWNER_USERID);
want_.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
SetLoadState(AbilityLoadState::LOADING);
auto isAttachDebug = DelayedSingleton<AppScheduler>::GetInstance()->IsAttachDebug(abilityInfo_.bundleName);
@ -448,7 +460,7 @@ void AbilityRecord::ForegroundUIExtensionAbility(uint32_t sceneFlag)
}
}
void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, uint32_t sceneFlag)
void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, uint32_t sceneFlag, bool isShellCall)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
std::string element = GetElementName().GetURI();
@ -476,7 +488,7 @@ void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, uint32_t sceneFla
} else {
TAG_LOGD(AAFwkTag::ABILITYMGR, "To load ability.");
lifeCycleStateInfo_.sceneFlagBak = sceneFlag;
LoadAbility();
LoadAbility(isShellCall);
}
}
@ -489,10 +501,10 @@ void AbilityRecord::PostForegroundTimeoutTask()
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * FOREGROUND_TIMEOUT_MULTIPLE;
SendEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, foregroundTimeout / HALF_TIMEOUT);
SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, foregroundTimeout);
std::string methodName = "ForegroundAbility";
std::string methodName = "ProcessForegroundAbility";
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::FOREGROUND, methodName);
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_BEGIN, GetPid(), GetUid(),
foregroundTimeout);
foregroundTimeout, GetAbilityRecordId());
}
void AbilityRecord::RemoveForegroundTimeoutTask()
@ -534,7 +546,7 @@ void AbilityRecord::PostUIExtensionAbilityTimeoutTask(uint32_t messageId)
SendEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, timeout / HALF_TIMEOUT, recordId_, true);
SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, timeout, recordId_, true);
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_BEGIN, GetPid(), GetUid(),
timeout);
timeout, GetAbilityRecordId());
break;
}
default: {
@ -1444,7 +1456,8 @@ void AbilityRecord::SetAbilityState(AbilityState state)
SetRestarting(false);
}
if (state == AbilityState::FOREGROUND) {
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_END, GetPid(), GetUid());
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_END, GetPid(),
GetUid(), 0, GetAbilityRecordId());
}
}
#endif // SUPPORT_SCREEN
@ -1503,7 +1516,11 @@ void AbilityRecord::SetScheduler(const sptr<IAbilityScheduler> &scheduler)
void AbilityRecord::AfterLoaded()
{
FreezeUtil::GetInstance().DeleteAppLifecycleEvent(GetPid());
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::LOAD_END, GetPid(), GetUid());
if (GetAbilityInfo().extensionAbilityType != AppExecFwk::ExtensionAbilityType::SERVICE) {
ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::LOAD_END, GetPid(),
GetUid(), 0, GetAbilityRecordId());
}
if (IsSceneBoard()) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "Sceneboard Added");
}

View File

@ -66,21 +66,14 @@ bool AppScheduler::Init(const std::weak_ptr<AppStateCallback> &callback)
return true;
}
int AppScheduler::LoadAbility(sptr<IRemoteObject> token, sptr<IRemoteObject> preToken,
const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo,
const Want &want, int32_t abilityRecordId, const std::string &instanceKey)
int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam &loadParam, const AppExecFwk::AbilityInfo &abilityInfo,
const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR);
/* because the errcode type of AppMgr Client API will be changed to int,
* so must to covert the return result */
AbilityRuntime::LoadParam loadParam;
loadParam.abilityRecordId = abilityRecordId;
loadParam.isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall();
loadParam.token = token;
loadParam.preToken = preToken;
loadParam.instanceKey = instanceKey;
int ret = static_cast<int>(IN_PROCESS_CALL(
appMgrClient_->LoadAbility(abilityInfo, applicationInfo, want, loadParam)));
if (ret != ERR_OK) {

View File

@ -175,7 +175,7 @@ void ConnectionRecord::CompleteDisconnect(int resultCode, bool isCallerDied, boo
}
CHECK_POINTER(targetService_);
const AppExecFwk::AbilityInfo &abilityInfo = targetService_->GetAbilityInfo();
AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName,
AppExecFwk::ElementName element(targetService_->GetWant().GetDeviceId(), abilityInfo.bundleName,
abilityInfo.name, abilityInfo.moduleName);
auto code = isTargetDied ? (resultCode - 1) : resultCode;
auto onDisconnectDoneTask = [connCallback = GetAbilityConnectCallback(), element, code]() {

View File

@ -15,7 +15,7 @@
#include "interceptor/disposed_rule_interceptor.h"
#include "ability_record.h"
#include "ability_manager_service.h"
#include "global_constant.h"
#include "hitrace_meter.h"
#include "iservice_registry.h"
@ -250,7 +250,7 @@ ErrCode DisposedRuleInterceptor::CreateModalUIExtension(const Want &want, const
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
if (abilityRecord == nullptr) {
if (abilityRecord == nullptr || abilityRecord->GetAbilityInfo().type != AppExecFwk::AbilityType::PAGE) {
auto systemUIExtension = std::make_shared<OHOS::Rosen::ModalSystemUiExtension>();
(const_cast<Want &>(want)).SetParam(UIEXTENSION_MODAL_TYPE, 1);
return IN_PROCESS_CALL(systemUIExtension->CreateModalUIExtension(want)) ? ERR_OK : INNER_ERR;

View File

@ -117,9 +117,7 @@ bool EcologicalRuleInterceptor::DoProcess(Want &want, int32_t userId)
InitErmsCallerInfo(want, nullptr, callerInfo, userId);
ExperienceRule rule;
AAFwk::Want newWant = want;
newWant.RemoveAllFd();
auto ret = IN_PROCESS_CALL(AbilityEcologicalRuleMgrServiceClient::GetInstance()->QueryStartExperience(newWant,
auto ret = IN_PROCESS_CALL(AbilityEcologicalRuleMgrServiceClient::GetInstance()->QueryStartExperience(want,
callerInfo, rule));
if (ret != ERR_OK) {
TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "check ecological rule failed");

View File

@ -468,7 +468,7 @@ void MissionList::GetActiveAbilityList(int32_t uid, std::vector<std::string> &ab
}
}
void MissionList::SignRestartAppFlag(int32_t uid)
void MissionList::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
for (auto it = missions_.begin(); it != missions_.end();) {
auto mission = *it;
@ -485,6 +485,10 @@ void MissionList::SignRestartAppFlag(int32_t uid)
it++;
continue;
}
if (abilityRecord->GetInstanceKey() != instanceKey) {
it++;
continue;
}
abilityRecord->SetRestartAppFlag(true);
it = missions_.erase(it);
}

View File

@ -4272,20 +4272,20 @@ void MissionListManager::SendKeyEvent(const AbilityRequest &abilityRequest)
EventReport::SendKeyEvent(EventName::START_PRIVATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
}
void MissionListManager::SignRestartAppFlag(int32_t uid)
void MissionListManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
std::lock_guard guard(managerLock_);
for (const auto& missionList : currentMissionLists_) {
if (!missionList) {
continue;
}
missionList->SignRestartAppFlag(uid);
missionList->SignRestartAppFlag(uid, instanceKey);
}
if (defaultStandardList_) {
defaultStandardList_->SignRestartAppFlag(uid);
defaultStandardList_->SignRestartAppFlag(uid, instanceKey);
}
if (defaultSingleList_) {
defaultSingleList_->SignRestartAppFlag(uid);
defaultSingleList_->SignRestartAppFlag(uid, instanceKey);
}
}

View File

@ -142,5 +142,13 @@ bool PendingWantKey::IsEqualsRequestWant(const Want &otherWant)
std::lock_guard<std::mutex> lock(requestWantMutex_);
return requestWant_.IsEquals(otherWant);
}
void PendingWantKey::GetAllBundleNames(std::vector<std::string> &bundleNames)
{
std::lock_guard<std::mutex> lock(wantsInfosMutex_);
for (const auto &wantInfo : allWantsInfos_) {
bundleNames.emplace_back(wantInfo.want.GetBundle());
}
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -29,9 +29,11 @@ namespace AAFwk {
using namespace OHOS::EventFwk;
using namespace std::chrono;
using namespace std::placeholders;
constexpr const char* PENDING_WANT_MANAGER = "PendingWantManager";
PendingWantManager::PendingWantManager()
{
taskHandler_ = TaskHandlerWrap::CreateQueueHandler(PENDING_WANT_MANAGER);
}
PendingWantManager::~PendingWantManager()
@ -114,7 +116,6 @@ sptr<IWantSender> PendingWantManager::GetWantSenderLocked(const int32_t callingU
}
MakeWantSenderCanceledLocked(*ref);
wantRecords_.erase(ref->GetKey());
EraseBundleRecord(wantSenderInfo.allWants, ref->GetKey());
}
if (!needCreate) {
@ -128,7 +129,6 @@ sptr<IWantSender> PendingWantManager::GetWantSenderLocked(const int32_t callingU
rec->SetCallerUid(callingUid);
pendingKey->SetCode(PendingRecordIdCreate());
wantRecords_.insert(std::make_pair(pendingKey, rec));
InsertBundleRecord(wantSenderInfo.allWants, pendingKey);
TAG_LOGD(AAFwkTag::WANTAGENT, "wantRecords_ size %{public}zu", wantRecords_.size());
return rec;
}
@ -252,9 +252,6 @@ void PendingWantManager::CancelWantSenderLocked(PendingWantRecord &record, bool
MakeWantSenderCanceledLocked(record);
if (cleanAbility) {
wantRecords_.erase(record.GetKey());
if (record.GetKey() != nullptr) {
EraseBundleRecord(record.GetKey()->GetAllWantsInfos(), record.GetKey());
}
}
}
@ -604,37 +601,30 @@ int32_t PendingWantManager::GetWantSenderInfo(const sptr<IWantSender> &target, s
void PendingWantManager::ClearPendingWantRecord(const std::string &bundleName, int32_t uid)
{
auto abilityManagerService = DelayedSingleton<AbilityManagerService>::GetInstance();
CHECK_POINTER(abilityManagerService);
auto handler = abilityManagerService->GetTaskHandler();
CHECK_POINTER(handler);
CHECK_POINTER(taskHandler_);
TAG_LOGI(AAFwkTag::WANTAGENT, "begin");
auto task = [bundleName, uid, self = shared_from_this()]() { self->ClearPendingWantRecordTask(bundleName, uid); };
handler->SubmitTask(task);
taskHandler_->SubmitTask(task);
}
void PendingWantManager::ClearPendingWantRecordTask(const std::string &bundleName, int32_t uid)
{
if (!QueryRecordByBundle(bundleName)) {
return;
}
TAG_LOGI(AAFwkTag::WANTAGENT, "begin");
std::lock_guard<ffrt::mutex> locker(mutex_);
if (!QueryRecordByBundle(bundleName)) {
return;
}
auto iter = wantRecords_.begin();
while (iter != wantRecords_.end()) {
bool hasBundle = false;
const auto &pendingRecord = iter->second;
if ((pendingRecord != nullptr)) {
auto wantInfos = pendingRecord->GetKey()->GetAllWantsInfos();
for (const auto &wantInfo: wantInfos) {
if (wantInfo.want.GetBundle() == bundleName && uid == pendingRecord->GetUid()) {
std::vector<std::string> bundleNameVec;
pendingRecord->GetKey()->GetAllBundleNames(bundleNameVec);
for (const auto &bundleItem: bundleNameVec) {
if (bundleItem == bundleName && uid == pendingRecord->GetUid()) {
hasBundle = true;
break;
}
}
if (hasBundle) {
EraseBundleRecord(wantInfos, pendingRecord->GetKey());
iter = wantRecords_.erase(iter);
TAG_LOGI(AAFwkTag::WANTAGENT, "wantRecords_ size %{public}zu", wantRecords_.size());
} else {
@ -697,6 +687,7 @@ void PendingWantManager::Dump(std::vector<std::string> &info)
std::string dumpInfo = " PendingWantRecords:";
info.push_back(dumpInfo);
std::lock_guard<ffrt::mutex> locker(mutex_);
for (const auto &item : wantRecords_) {
const auto &pendingKey = item.first;
dumpInfo = " PendWantRecord ID #" + std::to_string(pendingKey->GetCode()) +
@ -729,6 +720,7 @@ void PendingWantManager::DumpByRecordId(std::vector<std::string> &info, const st
std::string dumpInfo = " PendingWantRecords:";
info.push_back(dumpInfo);
std::lock_guard<ffrt::mutex> locker(mutex_);
for (const auto &item : wantRecords_) {
const auto &pendingKey = item.first;
if (args == std::to_string(pendingKey->GetCode())) {
@ -774,52 +766,5 @@ int32_t PendingWantManager::GetAllRunningInstanceKeysByBundleName(
return IN_PROCESS_CALL(appMgr->GetAllRunningInstanceKeysByBundleName(bundleName, appKeyVec));
}
void PendingWantManager::EraseBundleRecord(
const std::vector<WantsInfo> &wantsInfos, std::shared_ptr<PendingWantKey> key)
{
std::lock_guard<ffrt::mutex> locker(bundleRecordsMutex_);
for (const auto &wantInfo : wantsInfos) {
auto it = bundleRecords_.find(wantInfo.want.GetBundle());
if (it != bundleRecords_.end()) {
auto &recordVec = it->second;
recordVec.erase(std::remove_if(recordVec.begin(), recordVec.end(),
[key](std::shared_ptr<PendingWantKey> value) {
return value == key;
}),
recordVec.end());
if (recordVec.empty()) {
bundleRecords_.erase(wantInfo.want.GetBundle());
}
}
}
}
void PendingWantManager::InsertBundleRecord(
const std::vector<WantsInfo> &wantsInfos, std::shared_ptr<PendingWantKey> key)
{
std::lock_guard<ffrt::mutex> locker(bundleRecordsMutex_);
for (const auto &wantInfo : wantsInfos) {
auto it = bundleRecords_.find(wantInfo.want.GetBundle());
if (it != bundleRecords_.end()) {
auto &recordVec = it->second;
recordVec.emplace_back(key);
} else {
std::vector<std::shared_ptr<PendingWantKey>> pendingWantVector;
pendingWantVector.emplace_back(key);
bundleRecords_[wantInfo.want.GetBundle()] = pendingWantVector;
}
}
}
bool PendingWantManager::QueryRecordByBundle(const std::string &bundleName)
{
std::lock_guard<ffrt::mutex> locker(bundleRecordsMutex_);
auto bundleIter = bundleRecords_.find(bundleName);
if (bundleIter != bundleRecords_.end()) {
return true;
}
return false;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -14,6 +14,7 @@
*/
#include "ability_resident_process_rdb.h"
#include <charconv>
#include "hilog_tag_wrapper.h"
#include "parser_util.h"
@ -205,12 +206,13 @@ int32_t AmsResidentProcessRdb::GetResidentProcessEnable(const std::string &bundl
TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, ret: %{public}d", ret);
return Rdb_Search_Record_Err;
}
try {
enable = static_cast<bool>(std::stoul(flag));
} catch (...) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "stoul fail, flag: %{public}s", flag.c_str());
unsigned long value = 0;
auto res = std::from_chars(flag.c_str(), flag.c_str() + flag.size(), value);
if (res.ec != std::errc()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "from_chars error flag:%{public}s", flag.c_str());
return Rdb_Search_Record_Err;
}
enable = static_cast<bool>(value);
return Rdb_OK;
}

View File

@ -28,11 +28,11 @@ RestartAppManager &RestartAppManager::GetInstance()
return instance;
}
bool RestartAppManager::IsRestartAppFrequent(int32_t uid, time_t time)
bool RestartAppManager::IsRestartAppFrequent(const RestartAppKeyType &key, time_t time)
{
std::lock_guard<ffrt::mutex> lock(restartAppMapLock_);
constexpr int64_t MIN_RESTART_TIME = 10;
auto it = restartAppHistory_.find(uid);
auto it = restartAppHistory_.find(key);
if ((it != restartAppHistory_.end()) && (it->second + MIN_RESTART_TIME > time)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "restart too frequently. try again at least 10s later");
return true;
@ -40,24 +40,11 @@ bool RestartAppManager::IsRestartAppFrequent(int32_t uid, time_t time)
return false;
}
void RestartAppManager::AddRestartAppHistory(int32_t uid, time_t time)
void RestartAppManager::AddRestartAppHistory(const RestartAppKeyType &key, time_t time)
{
std::lock_guard<ffrt::mutex> lock(restartAppMapLock_);
TAG_LOGD(AAFwkTag::ABILITYMGR, "Refresh history, uid=%{public}d", uid);
restartAppHistory_[uid] = time;
}
bool RestartAppManager::IsForegroundToRestartApp() const
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
auto callerPid = IPCSkeleton::GetCallingPid();
AppExecFwk::RunningProcessInfo processInfo;
DelayedSingleton<AppScheduler>::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo);
if (processInfo.isFocused || processInfo.isAbilityForegrounding) {
return true;
}
TAG_LOGE(AAFwkTag::ABILITYMGR, "IsForegroundToRestartApp, state not foreground");
return false;
TAG_LOGD(AAFwkTag::ABILITYMGR, "Refresh uid=%{public}d, instanceKey:%{public}s", key.uid, key.instanceKey.c_str());
restartAppHistory_[key] = time;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -30,6 +30,7 @@
#include "session/host/include/zidl/session_interface.h"
#include "startup_util.h"
#include "ui_extension_utils.h"
#include "utils/ability_permission_util.h"
#ifdef SUPPORT_GRAPHICS
#include "ability_first_frame_state_observer_manager.h"
#endif
@ -46,6 +47,7 @@ constexpr int DEFAULT_DMS_MISSION_ID = -1;
constexpr const char* PARAM_SPECIFIED_PROCESS_FLAG = "ohoSpecifiedProcessFlag";
constexpr const char* DMS_PROCESS_NAME = "distributedsched";
constexpr const char* DMS_PERSISTENT_ID = "ohos.dms.persistentId";
constexpr const char* IS_SHELL_CALL = "isShellCall";
#ifdef SUPPORT_ASAN
constexpr int KILL_TIMEOUT_MULTIPLE = 45;
#else
@ -108,7 +110,8 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp
if (!uiAbilityRecord->IsReady() || sessionInfo->isNewWant) {
AddCallerRecord(abilityRequest, sessionInfo, uiAbilityRecord);
}
uiAbilityRecord->ProcessForegroundAbility(sessionInfo->callingTokenId, sceneFlag);
auto isShellCall = abilityRequest.want.GetBoolParam(IS_SHELL_CALL, false);
uiAbilityRecord->ProcessForegroundAbility(sessionInfo->callingTokenId, sceneFlag, isShellCall);
CheckSpecified(abilityRequest, uiAbilityRecord);
SendKeyEvent(abilityRequest);
return ERR_OK;
@ -130,6 +133,7 @@ std::shared_ptr<AbilityRecord> UIAbilityLifecycleManager::GenerateAbilityRecord(
TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionToken invalid");
return nullptr;
}
abilityRequest.want.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
uiAbilityRecord->SetIsNewWant(sessionInfo->isNewWant);
if (sessionInfo->isNewWant) {
uiAbilityRecord->SetWant(abilityRequest.want);
@ -164,6 +168,14 @@ bool UIAbilityLifecycleManager::CheckSessionInfo(sptr<SessionInfo> sessionInfo)
TAG_LOGE(AAFwkTag::ABILITYMGR, "token's Descriptor: %{public}s", descriptor.c_str());
return false;
}
bool needCheckCallerIsExist = sessionInfo->want.GetBoolParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST, false);
if (needCheckCallerIsExist && sessionInfo->callerToken) {
auto callerAbility = Token::GetAbilityRecordByToken(sessionInfo->callerToken);
if (callerAbility == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "callerAbility not exist");
return false;
}
}
return true;
}
@ -335,11 +347,15 @@ int UIAbilityLifecycleManager::AbilityWindowConfigTransactionDone(const sptr<IRe
return ERR_OK;
}
int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &abilityRequest)
int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &abilityRequest)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
abilityRequest.want.SetParam(IS_SHELL_CALL, AAFwk::PermissionVerification::GetInstance()->IsShellCall());
std::lock_guard<ffrt::mutex> guard(sessionLock_);
// start abilty with persistentId by dms
if (!AbilityPermissionUtil::GetInstance().VerifyCallerToken(abilityRequest)) {
return ERR_INVALID_VALUE;
}
// start ability with persistentId by dms
int32_t persistentId = abilityRequest.want.GetIntParam(DMS_PERSISTENT_ID, 0);
TAG_LOGD(AAFwkTag::ABILITYMGR, "NotifySCBToStartUIAbility, want with persistentId: %{public}d.", persistentId);
if (persistentId != 0 &&
@ -362,9 +378,10 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a
return ERR_OK;
}
auto isSpecified = (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED);
if (isSpecified) {
auto isCreating = abilityRequest.want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false);
if (isSpecified && !isCreating) {
CancelSameAbilityTimeoutTask(abilityInfo);
PreCreateProcessName(const_cast<AbilityRequest &>(abilityRequest));
PreCreateProcessName(abilityRequest);
specifiedRequestMap_.emplace(specifiedRequestId_, abilityRequest);
DelayedSingleton<AppScheduler>::GetInstance()->StartSpecifiedAbility(
abilityRequest.want, abilityRequest.abilityInfo, specifiedRequestId_);
@ -373,7 +390,6 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a
}
auto sessionInfo = CreateSessionInfo(abilityRequest);
sessionInfo->requestCode = abilityRequest.requestCode;
auto isCreating = abilityRequest.want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false);
if (abilityInfo.applicationInfo.multiAppMode.multiAppModeType != AppExecFwk::MultiAppModeType::MULTI_INSTANCE ||
!isCreating) {
sessionInfo->persistentId = GetPersistentIdByAbilityRequest(abilityRequest, sessionInfo->reuse);
@ -2652,12 +2668,13 @@ int32_t UIAbilityLifecycleManager::UpdateSessionInfoBySCB(std::list<SessionInfo>
return ERR_OK;
}
void UIAbilityLifecycleManager::SignRestartAppFlag(int32_t uid, bool isAppRecovery)
void UIAbilityLifecycleManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey, bool isAppRecovery)
{
std::lock_guard<ffrt::mutex> guard(sessionLock_);
auto tempSessionAbilityMap = sessionAbilityMap_;
for (auto &[sessionId, abilityRecord] : tempSessionAbilityMap) {
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid) {
if (abilityRecord == nullptr || abilityRecord->GetUid() != uid ||
abilityRecord->GetInstanceKey() != instanceKey) {
continue;
}
abilityRecord->SetRestartAppFlag(true);

View File

@ -231,5 +231,23 @@ int32_t AbilityPermissionUtil::CheckMultiInstanceKeyForExtension(const AbilityRe
}
return ERR_OK;
}
bool AbilityPermissionUtil::VerifyCallerToken(AbilityRequest &abilityRequest)
{
if (abilityRequest.callerToken == nullptr) {
return true;
}
if (PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
return true;
}
abilityRequest.want.SetParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST, true);
bool isAppKilling = IN_PROCESS_CALL(DelayedSingleton<AppScheduler>::GetInstance()->IsAppKilling(
abilityRequest.callerToken));
if (isAppKilling) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller killing");
return false;
}
return true;
}
} // AAFwk
} // OHOS

View File

@ -40,6 +40,7 @@ constexpr const char* PARAM_RESV_ANCO_CALLER_UID = "ohos.anco.param.callerUid";
constexpr const char* PARAM_RESV_ANCO_CALLER_BUNDLENAME = "ohos.anco.param.callerBundleName";
constexpr const char* WANT_PARAMS_APP_RESTART_FLAG = "ohos.aafwk.app.restart";
constexpr const char* CALLER_REQUEST_CODE = "ohos.extra.param.key.callerRequestCode";
constexpr const char* IS_SHELL_CALL = "isShellCall";
}
UpdateCallerInfoUtil &UpdateCallerInfoUtil::GetInstance()
@ -66,6 +67,8 @@ void UpdateCallerInfoUtil::UpdateCallerInfo(Want& want, const sptr<IRemoteObject
want.RemoveParam(Want::PARAM_RESV_CALLER_PID);
want.SetParam(Want::PARAM_RESV_CALLER_PID, callerPid);
want.RemoveParam(WANT_PARAMS_APP_RESTART_FLAG);
want.RemoveParam(IS_SHELL_CALL);
want.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
if (!abilityRecord) {
@ -145,6 +148,8 @@ void UpdateCallerInfoUtil::UpdateAsCallerInfoFromToken(Want& want, sptr<IRemoteO
want.RemoveParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME);
want.RemoveParam(Want::PARAM_RESV_CALLER_ABILITY_NAME);
want.RemoveParam(WANT_PARAMS_APP_RESTART_FLAG);
want.RemoveParam(IS_SHELL_CALL);
want.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
auto abilityRecord = Token::GetAbilityRecordByToken(asCallerSourceToken);
if (abilityRecord == nullptr) {
@ -179,6 +184,8 @@ void UpdateCallerInfoUtil::UpdateAsCallerInfoFromCallerRecord(Want& want, sptr<I
want.RemoveParam(Want::PARAM_RESV_CALLER_ABILITY_NAME);
want.RemoveParam(Want::PARAM_RESV_CALLER_NATIVE_NAME);
want.RemoveParam(WANT_PARAMS_APP_RESTART_FLAG);
want.RemoveParam(IS_SHELL_CALL);
want.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
auto callerRecord = Token::GetAbilityRecordByToken(callerToken);
CHECK_POINTER(callerRecord);
auto sourceInfo = callerRecord->GetCallerInfo();
@ -217,6 +224,8 @@ bool UpdateCallerInfoUtil::UpdateAsCallerInfoFromDialog(Want& want)
want.SetParam(Want::PARAM_RESV_CALLER_ABILITY_NAME, callerAbilityName);
want.RemoveParam(Want::PARAM_RESV_CALLER_NATIVE_NAME);
want.RemoveParam(WANT_PARAMS_APP_RESTART_FLAG);
want.RemoveParam(IS_SHELL_CALL);
want.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
if (callerBundleName == "") {
want.SetParam(Want::PARAM_RESV_CALLER_NATIVE_NAME,
dialogCallerWant.GetStringParam(Want::PARAM_RESV_CALLER_NATIVE_NAME));
@ -244,6 +253,8 @@ void UpdateCallerInfoUtil::UpdateCallerInfoFromToken(Want& want, const sptr<IRem
want.RemoveParam(Want::PARAM_RESV_CALLER_PID);
want.SetParam(Want::PARAM_RESV_CALLER_PID, callerPid);
want.RemoveParam(WANT_PARAMS_APP_RESTART_FLAG);
want.RemoveParam(IS_SHELL_CALL);
want.RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
std::string callerBundleName = abilityRecord->GetAbilityInfo().bundleName;
want.RemoveParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME);

View File

@ -81,23 +81,5 @@ bool WantUtils::IsAtomicServiceUrl(const Want& want)
}
return isAtomicServiceShortUrl;
}
int32_t WantUtils::GetAppIndex(const Want& want)
{
int32_t appIndex = want.GetIntParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, -1);
if (appIndex == -1) {
auto appMgr = AppMgrUtil::GetAppMgr();
if (appMgr == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
return appIndex;
}
auto callingPid = IPCSkeleton::GetCallingPid();
auto ret = IN_PROCESS_CALL(appMgr->GetAppIndexByPid(callingPid, appIndex));
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "appMgr GetAppIndexByPid error");
}
}
return appIndex;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "window_visibility_changed_listener.h"
#include "ability_manager_service.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AAFwk {
using namespace OHOS::Rosen;
WindowVisibilityChangedListener::WindowVisibilityChangedListener(
const std::weak_ptr<AbilityManagerService> &owner, const std::shared_ptr<AAFwk::TaskHandlerWrap> &handler)
: owner_(owner), taskHandler_(handler)
{}
void WindowVisibilityChangedListener::OnWindowVisibilityChanged(
const std::vector<sptr<WindowVisibilityInfo>> &windowVisibilityInfos)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (windowVisibilityInfos.empty()) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "windowVisibilityInfo is empty");
return;
}
if (taskHandler_ == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "null taskHandler");
return;
}
auto task = [inner = owner_, windowVisibilityInfos] {
auto owner = inner.lock();
if (owner == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "get fail");
return;
}
owner->HandleWindowVisibilityChanged(windowVisibilityInfos);
};
taskHandler_->SubmitTask(task);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -683,10 +683,11 @@ public:
/**
* @brief mark a process which is going restart.
* @param uid the uid of the process.
* @param instanceKey the instance key of the process.
*
* @return Returns ERR_OK on success, others on failure.
*/
int32_t SignRestartAppFlag(int32_t uid) override;
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey) override;
/**
* Get appRunningUniqueId by pid.
@ -772,7 +773,8 @@ public:
*/
virtual void RestartResidentProcessDependedOnWeb() override;
int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) override;
virtual int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
const std::string& reason) override;
private:
/**
* Init, Initialize application services.

View File

@ -314,6 +314,8 @@ public:
virtual int32_t KillApplicationSelf(const bool clearPageStack = false,
const std::string& reason = "KillApplicationSelf");
int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack, const std::string& reason);
/**
* KillApplicationByUserId, kill the application by user ID.
*
@ -1237,9 +1239,7 @@ public:
/**
* Mark processes of the uid as the app is going to be restarted.
*/
int32_t SignRestartAppFlag(int32_t uid);
int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) const;
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
/**
* Set application assertion pause state.
@ -1402,8 +1402,9 @@ private:
*/
void RestartResidentProcess(std::shared_ptr<AppRunningRecord> appRecord);
bool CheckLoadAbilityConditions(const sptr<IRemoteObject> &token,
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo);
bool CheckLoadAbilityConditions(std::shared_ptr<AAFwk::Want> want,
std::shared_ptr<AbilityRuntime::LoadParam> loadParam, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo);
/**
* query bundle info for the given bundleName
@ -1471,7 +1472,8 @@ private:
void StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags,
std::shared_ptr<AppRunningRecord> appRecord, const int uid, const BundleInfo &bundleInfo,
const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag = true,
bool isPreload = false, const std::string &moduleName = "", const std::string &abilityName = "",
bool isPreload = false, AppExecFwk::PreloadMode preloadMode = AppExecFwk::PreloadMode::PRE_MAKE,
const std::string &moduleName = "", const std::string &abilityName = "",
bool strictMode = false, sptr<IRemoteObject> token = nullptr,
std::shared_ptr<AAFwk::Want> want = nullptr,
ExtensionAbilityType ExtensionAbilityType = ExtensionAbilityType::UNSPECIFIED);
@ -1625,6 +1627,8 @@ private:
void AfterLoadAbility(std::shared_ptr<AppRunningRecord> appRecord, std::shared_ptr<AbilityInfo> abilityInfo,
std::shared_ptr<AbilityRuntime::LoadParam> loadParam);
void RemoveRenderRecordNoAttach(const std::shared_ptr<AppRunningRecord> &hostRecord, int32_t renderPid);
private:
/**
* ClearUpApplicationData, clear the application data.
@ -1654,7 +1658,8 @@ private:
int32_t KillApplicationByBundleName(const std::string &bundleName, const bool clearPageStack = false,
const std::string& reason = "KillApplicationByBundleName");
bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &appRecord);
bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &appRecord, bool isPreload,
AppExecFwk::PreloadMode preloadMode);
bool SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> appRecord, ProcessStartFailedReason reason,
int32_t subReason);
@ -1727,7 +1732,7 @@ private:
*/
bool NotifyMemMgrPriorityChanged(const std::shared_ptr<AppRunningRecord> appRecord);
void HandlePreloadApplication(const PreloadRequest &request, AppExecFwk::PreloadMode preloadMode);
void HandlePreloadApplication(const PreloadRequest &request);
std::string GetSpecifiedProcessFlag(std::shared_ptr<AbilityInfo> abilityInfo, std::shared_ptr<AAFwk::Want> want);
@ -1736,7 +1741,8 @@ private:
std::shared_ptr<AbilityInfo> abilityInfo, const std::string &processName,
const std::string &specifiedProcessFlag, const BundleInfo &bundleInfo,
const HapModuleInfo &hapModuleInfo, std::shared_ptr<AAFwk::Want> want,
bool appExistFlag, bool isPreload, sptr<IRemoteObject> token = nullptr);
bool appExistFlag, bool isPreload, AppExecFwk::PreloadMode preloadMode,
sptr<IRemoteObject> token = nullptr);
int32_t CreatNewStartMsg(const Want &want, const AbilityInfo &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo, const std::string &processName,
@ -1776,6 +1782,8 @@ private:
* @param appRecord indicates the process is going to die.
*/
void NotifyAppAttachFailed(std::shared_ptr<AppRunningRecord> appRecord);
void NotifyLoadAbilityFailed(sptr<IRemoteObject> token);
private:
/**
* Notify application status.

View File

@ -32,6 +32,7 @@ struct PreloadRequest {
BundleInfo bundleInfo;
HapModuleInfo hapModuleInfo;
int32_t appIndex = 0; // not used
AppExecFwk::PreloadMode preloadMode;
};
class AppPreloader {

View File

@ -254,6 +254,8 @@ public:
bool ProcessExitByBundleNameAndUid(
const std::string &bundleName, const int uid, std::list<pid_t> &pids, const bool clearPageStack = false);
bool ProcessExitByTokenIdAndInstance(uint32_t accessTokenId, const std::string &instanceKey, std::list<pid_t> &pids,
bool clearPageStack);
bool GetPidsByUserId(int32_t userId, std::list<pid_t> &pids);
void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false);
@ -310,7 +312,7 @@ public:
*/
int32_t GetAllAppRunningRecordCountByBundleName(const std::string &bundleName);
int32_t SignRestartAppFlag(int32_t uid);
int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey);
int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId);

View File

@ -36,6 +36,7 @@ namespace AppExecFwk {
enum class SpawnConnectionState { STATE_NOT_CONNECT, STATE_CONNECTED, STATE_CONNECT_FAILED };
using HspList = std::vector<BaseSharedBundleInfo>;
using DataGroupInfoList = std::vector<DataGroupInfo>;
using JITPermissionsList = std::vector<std::string>;
const int32_t MAX_FLAG_INDEX = 32;
const int32_t MAX_PROC_NAME_LEN = 256;
const int32_t START_FLAG_BASE = 1;
@ -78,6 +79,7 @@ struct AppSpawnStartMsg {
int32_t childProcessType = CHILD_PROCESS_TYPE_NOT_CHILD;
std::map<std::string, int32_t> fds;
bool isolationMode = false;
JITPermissionsList jitPermissionsList; // list of JIT permissions
};
constexpr auto LEN_PID = sizeof(pid_t);

View File

@ -19,12 +19,17 @@
#include "ability_info.h"
#include "app_spawn_client.h"
#include "global_constant.h"
#include "hitrace_meter.h"
#include "want.h"
namespace OHOS {
namespace AppExecFwk {
namespace AppspawnUtil {
constexpr const char* DLP_PARAMS_INDEX = "ohos.dlp.params.index";
constexpr const char*
JIT_PERMISSION_ALLOW_WRITABLE_CODE_MEMORY = "ohos.permission.kernel.ALLOW_WRITABLE_CODE_MEMORY";
constexpr const char*
JIT_PERMISSION_DISABLE_CODE_MEMORY_PROTECTION = "ohos.permission.kernel.DISABLE_CODE_MEMORY_PROTECTION";
static uint32_t BuildStartFlags(const AAFwk::Want &want, const ApplicationInfo &applicationInfo)
{
@ -84,6 +89,23 @@ static uint32_t BuildStartFlags(const AAFwk::Want &want, const AbilityInfo &abil
return startFlags;
}
static void SetJITPermissions(uint32_t accessTokenId, JITPermissionsList &jitPermissionsList)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(
accessTokenId,
JIT_PERMISSION_ALLOW_WRITABLE_CODE_MEMORY,
false) == Security::AccessToken::PERMISSION_GRANTED) {
jitPermissionsList.emplace_back(JIT_PERMISSION_ALLOW_WRITABLE_CODE_MEMORY);
}
if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(
accessTokenId,
JIT_PERMISSION_DISABLE_CODE_MEMORY_PROTECTION,
false) == Security::AccessToken::PERMISSION_GRANTED) {
jitPermissionsList.emplace_back(JIT_PERMISSION_DISABLE_CODE_MEMORY_PROTECTION);
}
}
} // namespace AppspawnUtil
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -51,8 +51,9 @@ constexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility
constexpr const char* TASK_SCENE_BOARD_ATTACH_TIMEOUT = "sceneBoardAttachTimeoutTask";
constexpr const char* TASK_ATTACHED_TO_STATUS_BAR = "AttachedToStatusBar";
constexpr const char* TASK_BLOCK_PROCESS_CACHE_BY_PIDS = "BlockProcessCacheByPids";
constexpr const char* POWER_OFF_ABILITY = "BlockProcessCacheByPids";
constexpr int32_t SCENE_BOARD_ATTACH_TIMEOUT_TASK_TIME = 1000;
constexpr const char* TASK_LOAD_ABILITY = "LoadAbilityTask";
constexpr int32_t LOAD_TASK_TIMEOUT = 30000; // ms
}; // namespace
AmsMgrScheduler::AmsMgrScheduler(
@ -109,16 +110,20 @@ void AmsMgrScheduler::LoadAbility(const std::shared_ptr<AbilityInfo> &abilityInf
amsHandler_->SubmitTask(timeoutTask, TASK_SCENE_BOARD_ATTACH_TIMEOUT, SCENE_BOARD_ATTACH_TIMEOUT_TASK_TIME);
}
if (abilityInfo->bundleName == AAFwk::AppUtils::GetInstance().GetMigrateClientBundleName()) {
amsHandler_->SubmitTask(loadAbilityFunc, AAFwk::TaskAttribute{
.taskName_ = TASK_LOAD_ABILITY,
AAFwk::TaskAttribute taskAttr{
.taskName_ = "LoadAbilityTask",
.taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE,
.taskPriority_ = AAFwk::TaskQueuePriority::IMMEDIATE
});
return;
.timeoutMillis_ = LOAD_TASK_TIMEOUT
};
if (abilityInfo->bundleName == AAFwk::AppUtils::GetInstance().GetMigrateClientBundleName()) {
taskAttr.taskPriority_ = AAFwk::TaskQueuePriority::IMMEDIATE;
}
if (abilityInfo->bundleName == SCENE_BOARD_BUNDLE_NAME && abilityInfo->name == POWER_OFF_ABILITY) {
taskAttr.insertHead_ = true;
}
amsHandler_->SubmitTask(loadAbilityFunc);
amsHandler_->SubmitTask(loadAbilityFunc, taskAttr);
}
void AmsMgrScheduler::UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state)
@ -300,7 +305,7 @@ void AmsMgrScheduler::AbilityAttachTimeOut(const sptr<IRemoteObject> &token)
auto task = [amsMgrServiceInner = amsMgrServiceInner_, token]() {
amsMgrServiceInner->HandleAbilityAttachTimeOut(token);
};
amsHandler_->SubmitTask(task);
amsHandler_->SubmitTask(task, "AbilityAttachTimeOut");
}
void AmsMgrScheduler::PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag)
@ -315,7 +320,10 @@ void AmsMgrScheduler::PrepareTerminate(const sptr<IRemoteObject> &token, bool cl
return;
}
auto task = [=]() { amsMgrServiceInner_->PrepareTerminate(token, clearMissionFlag); };
amsHandler_->SubmitTask(task, AAFwk::TaskQoS::USER_INTERACTIVE);
amsHandler_->SubmitTask(task, {
.taskName_ = "PrepareTerminate",
.taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE
});
}
int32_t AmsMgrScheduler::UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid)
@ -421,7 +429,10 @@ void AmsMgrScheduler::StartSpecifiedAbility(const AAFwk::Want &want, const AppEx
return;
}
auto task = [=]() { amsMgrServiceInner_->StartSpecifiedAbility(want, abilityInfo, requestId); };
amsHandler_->SubmitTask(task, AAFwk::TaskQoS::USER_INTERACTIVE);
amsHandler_->SubmitTask(task, {
.taskName_ = "StartSpecifiedAbility",
.taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE
});
}
void AmsMgrScheduler::StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
@ -437,7 +448,10 @@ void AmsMgrScheduler::StartSpecifiedProcess(const AAFwk::Want &want, const AppEx
return;
}
auto task = [=]() { amsMgrServiceInner_->StartSpecifiedProcess(want, abilityInfo, requestId); };
amsHandler_->SubmitTask(task, AAFwk::TaskQoS::USER_INTERACTIVE);
amsHandler_->SubmitTask(task, {
.taskName_ = "StartSpecifiedProcess",
.taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE
});
}
void AmsMgrScheduler::RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response)
@ -450,7 +464,7 @@ void AmsMgrScheduler::RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpe
return;
}
auto task = [=]() { amsMgrServiceInner_->RegisterStartSpecifiedAbilityResponse(response); };
amsHandler_->SubmitTask(task);
amsHandler_->SubmitTask(task, "RegisterStartSpecifiedAbilityResponse");
}
int AmsMgrScheduler::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug)

View File

@ -97,6 +97,10 @@ bool AppMgrEventUtil::SendProcessStartEvent(const std::shared_ptr<AppRunningReco
} else {
TAG_LOGI(AAFwkTag::APPMGR, "abilities failed");
}
#define START_UP_ABILITY_TYPE_PREMAKE 100
if (eventInfo.isPreload) {
eventInfo.abilityType = START_UP_ABILITY_TYPE_PREMAKE + eventInfo.preloadMode;
}
if (!callerAppRecord) {
Security::AccessToken::NativeTokenInfo nativeTokenInfo = {};
auto token = appRecord->GetCallerTokenId() == -1 ?

View File

@ -25,6 +25,7 @@
#include "app_death_recipient.h"
#include "app_mgr_constants.h"
#include "datetime_ex.h"
#include "fd_guard.h"
#include "freeze_util.h"
#include "global_constant.h"
#include "hilog_tag_wrapper.h"
@ -42,6 +43,7 @@
namespace OHOS {
namespace AppExecFwk {
using AAFwk::FdGuard;
constexpr const char* OPTION_KEY_HELP = "-h";
constexpr const char* OPTION_KEY_DUMP_IPC = "--ipc";
constexpr const char* OPTION_KEY_DUMP_FFRT = "--ffrt";
@ -149,6 +151,7 @@ ErrCode AppMgrService::Init()
taskHandler_ = AAFwk::TaskHandlerWrap::CreateConcurrentQueueHandler("app_mgr_task_queue",
DEFAULT_CONCURRENT_NUMBER);
taskHandler_->SetPrintTaskLog(true);
eventHandler_ = std::make_shared<AMSEventHandler>(taskHandler_, appMgrServiceInner_);
appMgrServiceInner_->SetTaskHandler(taskHandler_);
appMgrServiceInner_->SetEventHandler(eventHandler_);
@ -922,7 +925,7 @@ void AppMgrService::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::
auto task = [appMgrServiceInner = appMgrServiceInner_, recordId, want, flag]() {
appMgrServiceInner->ScheduleAcceptWantDone(recordId, want, flag);
};
taskHandler_->SubmitTask(task);
taskHandler_->SubmitTask(task, "ScheduleAcceptWantDone");
}
void AppMgrService::ScheduleNewProcessRequestDone(const int32_t recordId, const AAFwk::Want &want,
@ -938,7 +941,10 @@ void AppMgrService::ScheduleNewProcessRequestDone(const int32_t recordId, const
auto task = [appMgrServiceInner = appMgrServiceInner_, recordId, want, flag]() {
appMgrServiceInner->ScheduleNewProcessRequestDone(recordId, want, flag);
};
taskHandler_->SubmitTask(task, AAFwk::TaskQoS::USER_INTERACTIVE);
taskHandler_->SubmitTask(task, AAFwk::TaskAttribute{
.taskName_ = "ScheduleNewProcessRequestDone",
.taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE
});
}
int AppMgrService::GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens)
@ -969,13 +975,22 @@ int32_t AppMgrService::PreStartNWebSpawnProcess()
int32_t AppMgrService::StartRenderProcess(const std::string &renderParam, int32_t ipcFd,
int32_t sharedFd, int32_t crashFd, pid_t &renderPid, bool isGPU)
{
FdGuard ipcFdGuard(ipcFd);
FdGuard sharedFdGuard(sharedFd);
FdGuard crashFdGuard(crashFd);
if (!IsReady()) {
TAG_LOGE(AAFwkTag::APPMGR, "not ready");
return ERR_INVALID_OPERATION;
}
return appMgrServiceInner_->StartRenderProcess(IPCSkeleton::GetCallingPid(),
auto result = appMgrServiceInner_->StartRenderProcess(IPCSkeleton::GetCallingPid(),
renderParam, ipcFd, sharedFd, crashFd, renderPid, isGPU);
if (result == ERR_OK) {
ipcFdGuard.Release();
sharedFdGuard.Release();
crashFdGuard.Release();
}
return result;
}
void AppMgrService::AttachRenderProcess(const sptr<IRemoteObject> &scheduler)
@ -1371,11 +1386,22 @@ int32_t AppMgrService::IsAppRunning(const std::string &bundleName, int32_t appCl
int32_t AppMgrService::StartChildProcess(pid_t &childPid, const ChildProcessRequest &request)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
std::vector<FdGuard> fds;
for (const auto &[name, fd] : request.args.fds) {
fds.emplace_back(fd);
}
if (!IsReady()) {
TAG_LOGE(AAFwkTag::APPMGR, "not ready");
return ERR_INVALID_OPERATION;
}
return appMgrServiceInner_->StartChildProcess(IPCSkeleton::GetCallingPid(), childPid, request);
auto result = appMgrServiceInner_->StartChildProcess(IPCSkeleton::GetCallingPid(), childPid, request);
if (result == ERR_OK) {
for (auto &fd : fds) {
fd.Release();
}
}
return result;
}
int32_t AppMgrService::GetChildProcessInfoForSelf(ChildProcessInfo &info)
@ -1474,7 +1500,7 @@ int32_t AppMgrService::UpdateRenderState(pid_t renderPid, int32_t state)
return appMgrServiceInner_->UpdateRenderState(renderPid, state);
}
int32_t AppMgrService::SignRestartAppFlag(int32_t uid)
int32_t AppMgrService::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
if (!IsReady()) {
TAG_LOGE(AAFwkTag::APPMGR, "not ready");
@ -1486,7 +1512,7 @@ int32_t AppMgrService::SignRestartAppFlag(int32_t uid)
TAG_LOGE(AAFwkTag::APPMGR, "verification failed");
return ERR_PERMISSION_DENIED;
}
return appMgrServiceInner_->SignRestartAppFlag(uid);
return appMgrServiceInner_->SignRestartAppFlag(uid, instanceKey);
}
int32_t AppMgrService::GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId)
@ -1667,19 +1693,14 @@ int32_t AppMgrService::CheckIsKiaProcess(pid_t pid, bool &isKia)
return appMgrServiceInner_->CheckIsKiaProcess(pid, isKia);
}
int32_t AppMgrService::GetAppIndexByPid(pid_t pid, int32_t &appIndex)
int32_t AppMgrService::KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
const std::string& reason)
{
bool isCallingPermission =
AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS);
if (!isCallingPermission) {
TAG_LOGE(AAFwkTag::APPMGR, "verification failed");
return ERR_PERMISSION_DENIED;
}
if (!appMgrServiceInner_) {
TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr");
return ERR_INVALID_VALUE;
}
return appMgrServiceInner_->GetAppIndexByPid(pid, appIndex);
return appMgrServiceInner_->KillAppSelfWithInstanceKey(instanceKey, clearPageStack, reason);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -215,6 +215,7 @@ constexpr const char* EVENT_KEY_PID = "PID";
constexpr const char* EVENT_KEY_PACKAGE_NAME = "PACKAGE_NAME";
constexpr const char* EVENT_KEY_PROCESS_NAME = "PROCESS_NAME";
constexpr const char* EVENT_KEY_MESSAGE = "MSG";
constexpr const char* EVENT_KEY_FOREGROUND = "FOREGROUND";
// Developer mode param
constexpr const char* DEVELOPER_MODE_STATE = "const.security.developermode.state";
@ -379,7 +380,9 @@ void AppMgrServiceInner::Init()
DelayedSingleton<AppStateObserverManager>::GetInstance()->Init();
DelayedSingleton<RenderStateObserverManager>::GetInstance()->Init();
dfxTaskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("dfx_freeze_task_queue");
dfxTaskHandler_->SetPrintTaskLog(true);
otherTaskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("other_app_mgr_task_queue");
otherTaskHandler_->SetPrintTaskLog(true);
willKillPidsNum_ = 0;
delayKillTaskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("delay_kill_task_queue");
if (securityModeManager_) {
@ -474,12 +477,13 @@ int32_t AppMgrServiceInner::PreloadApplication(const std::string &bundleName, in
return ret;
}
auto task = [inner = shared_from_this(), request, preloadMode] () {
request.preloadMode = preloadMode;
auto task = [inner = shared_from_this(), request] () {
if (!inner) {
TAG_LOGE(AAFwkTag::APPMGR, "null appMgrServiceInner");
return;
}
inner->HandlePreloadApplication(request, preloadMode);
inner->HandlePreloadApplication(request);
};
if (!taskHandler_) {
TAG_LOGE(AAFwkTag::APPMGR, "null taskHandler_");
@ -491,7 +495,7 @@ int32_t AppMgrServiceInner::PreloadApplication(const std::string &bundleName, in
return ERR_OK;
}
void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request, AppExecFwk::PreloadMode preloadMode)
void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
auto abilityInfo = request.abilityInfo;
@ -534,9 +538,9 @@ void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request,
appRecord = CreateAppRunningRecord(loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, want);
if (appRecord != nullptr) {
appRecord->SetPreloadState(PreloadState::PRELOADING);
appRecord->SetNeedPreloadModule(preloadMode == AppExecFwk::PreloadMode::PRELOAD_MODULE);
appRecord->SetNeedPreloadModule(request.preloadMode == AppExecFwk::PreloadMode::PRELOAD_MODULE);
LoadAbilityNoAppRecord(appRecord, false, appInfo, abilityInfo, processName, specifiedProcessFlag, bundleInfo,
hapModuleInfo, want, appExistFlag, true);
hapModuleInfo, want, appExistFlag, true, request.preloadMode);
}
}
@ -608,8 +612,9 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
TAG_LOGE(AAFwkTag::APPMGR, "null loadParam");
return;
}
if (!CheckLoadAbilityConditions(loadParam->token, abilityInfo, appInfo)) {
if (!CheckLoadAbilityConditions(want, loadParam, abilityInfo, appInfo)) {
TAG_LOGE(AAFwkTag::APPMGR, "checkLoadAbilityConditions fail");
NotifyLoadAbilityFailed(loadParam->token);
return;
}
if (abilityInfo->type == AbilityType::PAGE) {
@ -660,6 +665,7 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name,
processName, appInfo->uid, bundleInfo, specifiedProcessFlag, &isProcCache, loadParam->instanceKey);
if (appRecord && appRecord->IsCaching()) {
TAG_LOGD(AAFwkTag::APPMGR, "process %{public}s is caching start ability set to blocked", processName.c_str());
appRecord->SetProcessCacheBlocked(true);
appRecord = nullptr;
}
@ -678,13 +684,15 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
appRecord = CreateAppRunningRecord(loadParam, appInfo, abilityInfo,
processName, bundleInfo, hapModuleInfo, want, isKia);
LoadAbilityNoAppRecord(appRecord, loadParam->isShellCall, appInfo, abilityInfo, processName,
specifiedProcessFlag, bundleInfo, hapModuleInfo, want, appExistFlag, false, loadParam->token);
specifiedProcessFlag, bundleInfo, hapModuleInfo, want, appExistFlag, false,
AppExecFwk::PreloadMode::PRESS_DOWN, loadParam->token);
if (ProcessKia(isKia, appRecord, watermarkBusinessName, isWatermarkEnabled) != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "ProcessKia failed");
return;
}
} else {
TAG_LOGI(AAFwkTag::APPMGR, "have apprecord");
appRunningManager_->UpdateConfigurationDelayed(appRecord);
if (!isProcCache) {
SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::MULTI_INSTANCE);
} else {
@ -727,17 +735,22 @@ void AppMgrServiceInner::AfterLoadAbility(std::shared_ptr<AppRunningRecord> appR
PerfProfile::GetInstance().Dump();
PerfProfile::GetInstance().Reset();
auto reportLoadTask = [appRecord]() {
auto reportLoadTask = [appRecord, abilityRecordId = loadParam->abilityRecordId]() {
auto priorityObj = appRecord->GetPriorityObject();
if (priorityObj) {
auto timeOut = AbilityRuntime::GlobalConstant::GetLoadTimeOutBase() *
AAFwk::AppUtils::GetInstance().GetTimeoutUnitTimeRatio();
if (appRecord->GetExtensionType() == ExtensionAbilityType::SERVICE) {
timeOut = AbilityRuntime::GlobalConstant::GetLoadAndInactiveTimeout() *
AAFwk::AppUtils::GetInstance().GetTimeoutUnitTimeRatio();
}
AAFwk::ResSchedUtil::GetInstance().ReportLoadingEventToRss(AAFwk::LoadingStage::LOAD_BEGIN,
priorityObj->GetPid(), appRecord->GetUid(), timeOut);
priorityObj->GetPid(), appRecord->GetUid(), timeOut, static_cast<int64_t>(abilityRecordId));
}
};
if (taskHandler_) {
taskHandler_->SubmitTask(reportLoadTask);
taskHandler_->SubmitTask(reportLoadTask, "reportLoadTask");
}
appRecord->UpdateAbilityState(loadParam->token, AbilityState::ABILITY_STATE_CREATE);
@ -798,10 +811,11 @@ void AppMgrServiceInner::RemoveUIExtensionLauncherItem(std::shared_ptr<AppRunnin
appRunningManager_->RemoveUIExtensionLauncherItemById(uiExtensionAbilityId);
}
bool AppMgrServiceInner::CheckLoadAbilityConditions(const sptr<IRemoteObject> &token,
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo)
bool AppMgrServiceInner::CheckLoadAbilityConditions(std::shared_ptr<AAFwk::Want> want,
std::shared_ptr<AbilityRuntime::LoadParam> loadParam, const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo)
{
if (!token || !abilityInfo || !appInfo) {
if (!loadParam || !loadParam->token || !abilityInfo || !appInfo) {
TAG_LOGE(AAFwkTag::APPMGR, "param error");
return false;
}
@ -813,6 +827,22 @@ bool AppMgrServiceInner::CheckLoadAbilityConditions(const sptr<IRemoteObject> &t
TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo and appInfo have diff appName");
return false;
}
bool needCheckCallerIsExist = false;
if (want) {
needCheckCallerIsExist = want->GetBoolParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST, false);
want->RemoveParam(Want::PARAMS_NEED_CHECK_CALLER_IS_EXIST);
}
if (needCheckCallerIsExist && loadParam->preToken) {
auto appRecord = GetAppRunningRecordByAbilityToken(loadParam->preToken);
if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "preToken not exist");
return false;
}
if (appRecord->IsKilling()) {
TAG_LOGE(AAFwkTag::APPMGR, "app is killing");
return false;
}
}
return true;
}
@ -905,7 +935,8 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptr<AppRunning
bool isShellCall, std::shared_ptr<ApplicationInfo> appInfo,
std::shared_ptr<AbilityInfo> abilityInfo, const std::string &processName,
const std::string &specifiedProcessFlag, const BundleInfo &bundleInfo, const HapModuleInfo &hapModuleInfo,
std::shared_ptr<AAFwk::Want> want, bool appExistFlag, bool isPreload, sptr<IRemoteObject> token)
std::shared_ptr<AAFwk::Want> want, bool appExistFlag, bool isPreload, AppExecFwk::PreloadMode preloadMode,
sptr<IRemoteObject> token)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::APPMGR, "processName:%{public}s, isPreload:%{public}d",
@ -927,7 +958,7 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptr<AppRunning
otherTaskHandler_->SubmitTask([appRecord, abilityInfo, pThis = shared_from_this()]() {
pThis->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_SET_COLD_START, false, false);
pThis->SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::COLD);
}, FIRST_FRAME_NOTIFY_TASK_DELAY);
}, "AppStateChangedNotify", FIRST_FRAME_NOTIFY_TASK_DELAY);
}
uint32_t startFlags = (want == nullptr) ? 0 : AppspawnUtil::BuildStartFlags(*want, *abilityInfo);
int32_t bundleIndex = 0;
@ -937,8 +968,8 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptr<AppRunning
bool strictMode = (want == nullptr) ? false : want->GetBoolParam(STRICT_MODE, false);
appRecord->SetStrictMode(strictMode);
StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord,
appInfo->uid, bundleInfo, appInfo->bundleName, bundleIndex, appExistFlag, isPreload, abilityInfo->moduleName,
abilityInfo->name, strictMode, token, want, abilityInfo->extensionAbilityType);
appInfo->uid, bundleInfo, appInfo->bundleName, bundleIndex, appExistFlag, isPreload, preloadMode,
abilityInfo->moduleName, abilityInfo->name, strictMode, token, want, abilityInfo->extensionAbilityType);
if (isShellCall) {
std::string perfCmd = (want == nullptr) ? "" : want->GetStringParam(PERF_CMD);
bool isSandboxApp = (want == nullptr) ? false : want->GetBoolParam(ENTER_SANDBOX, false);
@ -1119,6 +1150,19 @@ void AppMgrServiceInner::NotifyAppAttachFailed(std::shared_ptr<AppRunningRecord>
}
}
void AppMgrServiceInner::NotifyLoadAbilityFailed(sptr<IRemoteObject> token)
{
CHECK_POINTER_AND_RETURN_LOG(token, "token null.");
std::vector<sptr<IRemoteObject>> abilityTokens;
abilityTokens.emplace_back(token);
std::lock_guard lock(appStateCallbacksLock_);
for (const auto &item : appStateCallbacks_) {
if (item.callback != nullptr) {
item.callback->OnAppRemoteDied(abilityTokens);
}
}
}
void AppMgrServiceInner::LaunchApplication(const std::shared_ptr<AppRunningRecord> &appRecord)
{
CHECK_POINTER_AND_RETURN_LOG(appRecord, "appRecord null");
@ -1327,7 +1371,6 @@ void AppMgrServiceInner::ApplicationTerminated(const int32_t recordId)
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null");
return;
}
auto appRecord = GetAppRunningRecordByAppRecordId(recordId);
if (!appRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "get appRecord fail");
@ -1363,15 +1406,16 @@ void AppMgrServiceInner::ApplicationTerminated(const int32_t recordId)
ApplicationTerminatedSendProcessEvent(appRecord);
taskHandler_->CancelTask("DELAY_KILL_PROCESS_" + std::to_string(recordId));
auto uid = appRecord->GetUid();
bool foreground = appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND ||
appRecord->GetState() == ApplicationState::APP_STATE_FOCUS;
auto result = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "PROCESS_KILL",
OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
EVENT_KEY_PID, std::to_string(eventInfo.pid),
EVENT_KEY_PROCESS_NAME, eventInfo.processName,
EVENT_KEY_MESSAGE, "Kill Reason:app exit");
EVENT_KEY_PID, std::to_string(eventInfo.pid), EVENT_KEY_PROCESS_NAME, eventInfo.processName,
EVENT_KEY_MESSAGE, "Kill Reason:app exit", EVENT_KEY_FOREGROUND, foreground);
TAG_LOGW(AAFwkTag::APPMGR, "hisysevent write result=%{public}d, send [FRAMEWORK,PROCESS_KILL], pid=%{public}d,"
" processName=%{public}s, msg=Kill Reason:app exit", result, eventInfo.pid, eventInfo.processName.c_str());
" processName=%{public}s, msg=Kill Reason:app exit, FOREGROUND = %{public}d",
result, eventInfo.pid, eventInfo.processName.c_str(), foreground);
NotifyAppRunningStatusEvent(appRecord->GetBundleName(), uid, AbilityRuntime::RunningStatus::APP_RUNNING_STOP);
}
@ -1576,20 +1620,17 @@ void AppMgrServiceInner::SendProcessExitEventTask(
eventInfo.pid = pid;
eventInfo.processName = appRecord->GetProcessName();
eventInfo.extensionType = static_cast<int32_t>(appRecord->GetExtensionType());
eventInfo.exitReason = appRecord->GetExitReason();
if (exitResult) {
eventInfo.exitResult = EXIT_SUCESS;
AAFwk::EventReport::SendProcessExitEvent(AAFwk::EventName::PROCESS_EXIT, eventInfo);
TAG_LOGI(AAFwkTag::APPMGR, "time: %{public}" PRId64 ", exitResult: %{public}d, pid: %{public}d",
eventInfo.time, eventInfo.exitResult, eventInfo.pid);
return;
}
if (--count <= 0) {
eventInfo.exitResult = EXIT_FAILED;
AAFwk::EventReport::SendProcessExitEvent(AAFwk::EventName::PROCESS_EXIT, eventInfo);
TAG_LOGI(AAFwkTag::APPMGR, "time: %{public}" PRId64 ", exitResult: %{public}d, pid: %{public}d",
eventInfo.time, eventInfo.exitResult, eventInfo.pid);
return;
}
@ -1636,16 +1677,48 @@ int32_t AppMgrServiceInner::KillApplicationSelf(const bool clearPageStack, const
TAG_LOGI(AAFwkTag::APPMGR, "remote process exited successs");
return ERR_OK;
}
int32_t result = ERR_OK;
for (auto iter = pids.begin(); iter != pids.end(); ++iter) {
auto result = KillProcessByPid(*iter, reason);
if (result < 0) {
auto singleRet = KillProcessByPid(*iter, reason);
if (singleRet < 0) {
TAG_LOGE(AAFwkTag::APPMGR, "killApplication fail for bundleName:%{public}s pid:%{public}d",
bundleName.c_str(), *iter);
result = singleRet;
}
}
return result;
}
int32_t AppMgrServiceInner::KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack,
const std::string& reason)
{
if (!appRunningManager_) {
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null");
return ERR_NO_INIT;
}
int64_t startTime = SystemTimeMillisecond();
auto callingTokenId = IPCSkeleton::GetCallingTokenID();
TAG_LOGI(AAFwkTag::APPMGR, "callingTokenId value: %{public}d", callingTokenId);
std::list<pid_t> pids;
if (!appRunningManager_->ProcessExitByTokenIdAndInstance(callingTokenId, instanceKey, pids, clearPageStack)) {
TAG_LOGI(AAFwkTag::APPMGR, "not exist");
return ERR_OK;
}
if (WaitForRemoteProcessExit(pids, startTime)) {
TAG_LOGI(AAFwkTag::APPMGR, "remote process exited success");
return ERR_OK;
}
int32_t result = ERR_OK;
for (auto iter = pids.begin(); iter != pids.end(); ++iter) {
auto singleRet = KillProcessByPid(*iter, reason);
if (singleRet < 0) {
TAG_LOGE(AAFwkTag::APPMGR, "Failed to kill pid:%{public}d", *iter);
result = singleRet;
}
}
return result;
}
int32_t AppMgrServiceInner::KillApplicationByBundleName(
const std::string &bundleName, const bool clearPageStack, const std::string& reason)
@ -2409,13 +2482,16 @@ int32_t AppMgrServiceInner::KillProcessByPidInner(const pid_t pid, const std::st
DelayedSingleton<CacheProcessManager>::GetInstance()->OnProcessKilled(appRecord);
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
eventInfo.processName = appRecord->GetProcessName();
bool foreground = appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND ||
appRecord->GetState() == ApplicationState::APP_STATE_FOCUS;
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_TERMINATE, HiSysEventType::BEHAVIOR, eventInfo);
int result = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, "PROCESS_KILL",
OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_KEY_PID, std::to_string(eventInfo.pid),
EVENT_KEY_PROCESS_NAME, eventInfo.processName, EVENT_KEY_MESSAGE, killReason);
EVENT_KEY_PROCESS_NAME, eventInfo.processName, EVENT_KEY_MESSAGE, killReason,
EVENT_KEY_FOREGROUND, foreground);
TAG_LOGW(AAFwkTag::APPMGR, "hisysevent write result=%{public}d, send event [FRAMEWORK,PROCESS_KILL], pid="
"%{public}d, processName=%{public}s, msg=%{public}s", result, pid, eventInfo.processName.c_str(),
killReason.c_str());
"%{public}d, processName=%{public}s, msg=%{public}s, FOREGROUND = %{public}d",
result, pid, eventInfo.processName.c_str(), killReason.c_str(), foreground);
return ret;
}
@ -3341,6 +3417,9 @@ int32_t AppMgrServiceInner::CreateStartMsg(const std::string &processName, uint3
AAFwk::AutoSyncTaskHandle autoSync(otherTaskHandler_->SubmitTask([&]() {
AddMountPermission(bundleInfo.applicationInfo.accessTokenId, startMsg.permissions);
}, AAFwk::TaskAttribute{
.taskName_ = "AddMountPermission",
.taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE
}));
HspList hspList;
@ -3368,7 +3447,7 @@ int32_t AppMgrServiceInner::CreateStartMsg(const std::string &processName, uint3
SetAtomicServiceInfo(bundleType, startMsg);
SetOverlayInfo(bundleInfo.name, userId, startMsg);
SetAppInfo(bundleInfo, startMsg);
AppspawnUtil::SetJITPermissions(bundleInfo.applicationInfo.accessTokenId, startMsg.jitPermissionsList);
TAG_LOGI(AAFwkTag::APPMGR, "apl: %{public}s, bundleName: %{public}s, startFlags: %{public}d",
startMsg.apl.c_str(), bundleInfo.name.c_str(), startFlags);
@ -3432,8 +3511,9 @@ void AppMgrServiceInner::QueryExtensionSandBox(const std::string &moduleName, co
void AppMgrServiceInner::StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags,
std::shared_ptr<AppRunningRecord> appRecord, const int uid, const BundleInfo &bundleInfo,
const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag, bool isPreload,
const std::string &moduleName, const std::string &abilityName, bool strictMode, sptr<IRemoteObject> token,
std::shared_ptr<AAFwk::Want> want, ExtensionAbilityType ExtensionAbilityType)
AppExecFwk::PreloadMode preloadMode, const std::string &moduleName, const std::string &abilityName,
bool strictMode, sptr<IRemoteObject> token, std::shared_ptr<AAFwk::Want> want,
ExtensionAbilityType ExtensionAbilityType)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::APPMGR, "bundleName: %{public}s, isPreload: %{public}d", bundleName.c_str(), isPreload);
@ -3521,7 +3601,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
OnAppStarted(appRecord);
}
PerfProfile::GetInstance().SetAppForkEndTime(GetTickCount());
SendProcessStartEvent(appRecord);
SendProcessStartEvent(appRecord, isPreload, preloadMode);
ProcessAppDebug(appRecord, appRecord->IsDebugApp());
}
@ -3608,7 +3688,8 @@ bool AppMgrServiceInner::SendCreateAtomicServiceProcessEvent(const std::shared_p
return AppMgrEventUtil::SendCreateAtomicServiceProcessEvent(callerAppRecord, appRecord, moduleName, abilityName);
}
bool AppMgrServiceInner::SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &appRecord)
bool AppMgrServiceInner::SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &appRecord, bool isPreload,
AppExecFwk::PreloadMode preloadMode)
{
if (!appRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord null");
@ -3617,6 +3698,8 @@ bool AppMgrServiceInner::SendProcessStartEvent(const std::shared_ptr<AppRunningR
AAFwk::EventInfo eventInfo;
auto callerPid = appRecord->GetCallerPid() == -1 ? IPCSkeleton::GetCallingPid() : appRecord->GetCallerPid();
auto callerAppRecord = GetAppRunningRecordByPid(callerPid);
eventInfo.isPreload = isPreload;
eventInfo.preloadMode = static_cast<int32_t>(preloadMode);
AppMgrEventUtil::SendProcessStartEvent(callerAppRecord, appRecord, eventInfo);
SendReStartProcessEvent(eventInfo, appRecord->GetUid());
return true;
@ -4643,7 +4726,8 @@ int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config, con
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "configuration_->CompareDifferent");
configuration_->CompareDifferent(changeKeyV, config);
}
TAG_LOGI(AAFwkTag::APPMGR, "changeKeyV size: %{public}zu", changeKeyV.size());
TAG_LOGI(AAFwkTag::APPMGR, "changeKeyV size: %{public}zu Config: %{public}s",
changeKeyV.size(), config.GetName().c_str());
if (config.GetItem(AAFwk::GlobalConfigurationKey::THEME).empty() && changeKeyV.empty()) {
TAG_LOGE(AAFwkTag::APPMGR, "changeKeyV empty");
return ERR_INVALID_VALUE;
@ -4783,6 +4867,7 @@ void AppMgrServiceInner::InitGlobalConfiguration()
configuration_->AddItem(AAFwk::GlobalConfigurationKey::DEVICE_TYPE, deviceType);
configuration_->AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_SIZE_SCALE, "1.0");
configuration_->AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE, "1.0");
TAG_LOGI(AAFwkTag::APPMGR, "InitGlobalConfiguration Config: %{public}s", configuration_->GetName().c_str());
}
std::shared_ptr<AppExecFwk::Configuration> AppMgrServiceInner::GetConfiguration()
@ -5379,10 +5464,32 @@ int AppMgrServiceInner::GetRenderProcessTerminationStatus(pid_t renderPid, int &
TAG_LOGD(AAFwkTag::APPMGR, "Get render process termination status success, renderPid:%{public}d, status:%{public}d",
renderPid, status);
hostRecord->RemoveRenderPid(renderPid);
RemoveRenderRecordNoAttach(hostRecord, renderPid);
return 0;
}
void AppMgrServiceInner::RemoveRenderRecordNoAttach(const std::shared_ptr<AppRunningRecord> &hostRecord,
int32_t renderPid)
{
if (!hostRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "hostRecord null");
return;
}
auto renderRecord = hostRecord->GetRenderRecordByPid(renderPid);
if (!renderRecord) {
TAG_LOGD(AAFwkTag::APPMGR, "renderRecord null");
return;
}
if (renderRecord->GetScheduler() == nullptr) {
hostRecord->RemoveRenderRecord(renderRecord);
{
std::lock_guard<ffrt::mutex> lock(renderUidSetLock_);
renderUidSet_.erase(renderRecord->GetUid());
}
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnRenderProcessDied(renderRecord);
}
}
void AppMgrServiceInner::OnRenderRemoteDied(const wptr<IRemoteObject> &remote)
{
TAG_LOGE(AAFwkTag::APPMGR, "on render remote died");
@ -5835,6 +5942,7 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData)
return ERR_OK;
}
std::string bundleName = appRecord->GetBundleName();
std::string processName = appRecord->GetProcessName();
if (AppExecFwk::AppfreezeManager::GetInstance()->IsProcessDebug(pid, bundleName)) {
TAG_LOGW(AAFwkTag::APPMGR,
"don't report event and kill:%{public}s, pid:%{public}d, bundleName:%{public}s",
@ -5852,22 +5960,23 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData)
}
}
auto notifyAppTask = [appRecord, pid, callerUid, bundleName, faultData, innerService = shared_from_this()]() {
auto notifyAppTask = [appRecord, pid, callerUid, bundleName, processName, faultData,
innerService = shared_from_this()]() {
if (faultData.faultType == FaultDataType::APP_FREEZE) {
AppfreezeManager::AppInfo info = {
.pid = pid,
.uid = callerUid,
.bundleName = bundleName,
.processName = bundleName,
.processName = processName,
};
AppExecFwk::AppfreezeManager::GetInstance()->AppfreezeHandleWithStack(faultData, info);
}
TAG_LOGW(AAFwkTag::APPMGR,
"name: %{public}s, faultType: %{public}d, uid: %{public}d, pid: %{public}d,"
"bundleName: %{public}s, faultData.forceExit:%{public}d, faultData.waitSaveState:%{public}d",
faultData.errorObject.name.c_str(), faultData.faultType,
callerUid, pid, bundleName.c_str(), faultData.forceExit, faultData.waitSaveState);
"name: %{public}s, faultType: %{public}d, uid: %{public}d, pid: %{public}d, bundleName: %{public}s,"
" processName: %{public}s, faultData.forceExit:%{public}d, faultData.waitSaveState:%{public}d",
faultData.errorObject.name.c_str(), faultData.faultType, callerUid, pid, bundleName.c_str(),
processName.c_str(), faultData.forceExit, faultData.waitSaveState);
};
if (!dfxTaskHandler_) {
@ -6790,7 +6899,8 @@ void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptr<A
}
auto userId = GetUserIdByUid(appRecord->GetUid());
if (appRecord->IsKeepAliveApp() && (userId == 0 || userId == currentUserId_)) {
if (appRecord->IsKeepAliveApp() && (userId == 0 || userId == currentUserId_) &&
appRecord->GetBundleName() != SCENE_BOARD_BUNDLE_NAME) {
if (ExitResidentProcessManager::GetInstance().IsKilledForUpgradeWeb(appRecord->GetBundleName())) {
TAG_LOGI(AAFwkTag::APPMGR, "is killed for upgrade web");
return;
@ -7510,25 +7620,14 @@ int32_t AppMgrServiceInner::UpdateRenderState(pid_t renderPid, int32_t state)
renderRecord, state);
}
int32_t AppMgrServiceInner::SignRestartAppFlag(int32_t uid)
int32_t AppMgrServiceInner::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
TAG_LOGD(AAFwkTag::APPMGR, "call.");
if (!appRunningManager_) {
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null");
return ERR_NO_INIT;
}
return appRunningManager_->SignRestartAppFlag(uid);
}
int32_t AppMgrServiceInner::GetAppIndexByPid(pid_t pid, int32_t &appIndex) const
{
auto appRecord = GetAppRunningRecordByPid(pid);
if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "no appRecord, pid:%{public}d", pid);
return ERR_INVALID_VALUE;
}
appIndex = appRecord->GetAppIndex();
return ERR_OK;
return appRunningManager_->SignRestartAppFlag(uid, instanceKey);
}
int32_t AppMgrServiceInner::GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId)
@ -7879,7 +7978,7 @@ void AppMgrServiceInner::SubmitCacheLoadAbilityTask()
[taskHandler](LoadAbilityTaskFunc loadAbilityFunc) {
auto LoadAbilityhandler = taskHandler.lock();
if (LoadAbilityhandler != nullptr && loadAbilityFunc) {
LoadAbilityhandler->SubmitTask(loadAbilityFunc);
LoadAbilityhandler->SubmitTask(loadAbilityFunc, "loadAbilityFunc");
}
});
loadAbilityTaskFuncList_.clear();
@ -8114,6 +8213,10 @@ bool AppMgrServiceInner::IsProcessContainsOnlyUIAbility(const pid_t pid)
void AppMgrServiceInner::MakeIsolateSandBoxProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo,
const HapModuleInfo &hapModuleInfo, std::string &processName) const
{
if (abilityInfo == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo nullptr");
return;
}
auto type = abilityInfo->type;
auto extensionType = abilityInfo->extensionAbilityType;
if (type != AppExecFwk::AbilityType::EXTENSION ||
@ -8121,10 +8224,13 @@ void AppMgrServiceInner::MakeIsolateSandBoxProcessName(const std::shared_ptr<Abi
extensionType == AppExecFwk::ExtensionAbilityType::SERVICE) {
return;
}
for (auto extensionInfo: hapModuleInfo.extensionInfos) {
if (extensionInfo.name == abilityInfo->name && extensionInfo.needCreateSandbox) {
for (const auto& extensionInfo: hapModuleInfo.extensionInfos) {
if (extensionInfo.name == abilityInfo->name) {
if (extensionInfo.needCreateSandbox) {
processName = (processName + ":" + abilityInfo->name);
}
return;
}
}
}

View File

@ -365,6 +365,46 @@ bool AppRunningManager::ProcessExitByBundleNameAndUid(
return (pids.empty() ? false : true);
}
bool AppRunningManager::ProcessExitByTokenIdAndInstance(uint32_t accessTokenId, const std::string &instanceKey,
std::list<pid_t> &pids, bool clearPageStack)
{
auto appRunningMap = GetAppRunningRecordMap();
for (const auto &item : appRunningMap) {
const auto &appRecord = item.second;
if (appRecord == nullptr) {
continue;
}
auto appInfo = appRecord->GetApplicationInfo();
if (appInfo == nullptr) {
continue;
}
if (appInfo->multiAppMode.multiAppModeType != MultiAppModeType::MULTI_INSTANCE) {
TAG_LOGI(AAFwkTag::APPMGR, "not multi-instance");
}
if (appInfo->accessTokenId != accessTokenId) {
continue;
}
if (appRecord->GetInstanceKey() != instanceKey) {
continue;
}
if (appRecord->GetPriorityObject() == nullptr) {
continue;
}
pid_t pid = appRecord->GetPriorityObject()->GetPid();
if (pid <= 0) {
continue;
}
pids.push_back(pid);
if (clearPageStack) {
appRecord->ScheduleClearPageStack();
}
appRecord->SetKilling();
appRecord->ScheduleProcessSecurityExit();
}
return pids.empty() ? false : true;
}
bool AppRunningManager::GetPidsByBundleNameUserIdAndAppIndex(const std::string &bundleName,
const int userId, const int appIndex, std::list<pid_t> &pids)
{
@ -651,7 +691,10 @@ void AppRunningManager::TerminateAbility(const sptr<IRemoteObject> &token, bool
}
#endif //SUPPORT_SCREEN
auto isLauncherApp = appRecord->GetApplicationInfo()->isLauncherApp;
if (isLastAbility && (!appRecord->IsKeepAliveApp() ||
auto isKeepAliveApp = appRecord->IsKeepAliveApp();
TAG_LOGI(AAFwkTag::APPMGR, "TerminateAbility:isLast:%{public}d,keepAlive:%{public}d",
isLastAbility, isKeepAliveApp);
if (isLastAbility && (!isKeepAliveApp ||
!ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient()) && !isLauncherApp) {
auto cacheProcMgr = DelayedSingleton<CacheProcessManager>::GetInstance();
if (cacheProcMgr != nullptr) {
@ -666,7 +709,7 @@ void AppRunningManager::TerminateAbility(const sptr<IRemoteObject> &token, bool
}
return;
}
TAG_LOGD(AAFwkTag::APPMGR, "The ability is the last in the app:%{public}s.", appRecord->GetName().c_str());
TAG_LOGI(AAFwkTag::APPMGR, "Terminate last ability in app:%{public}s.", appRecord->GetName().c_str());
appRecord->SetTerminating();
if (clearMissionFlag && appMgrServiceInner != nullptr) {
auto delayTime = appRecord->ExtensionAbilityRecordExists() ?
@ -740,11 +783,10 @@ int32_t AppRunningManager::AssignRunningProcessInfoByAppRecord(
auto appInfo = appRecord->GetApplicationInfo();
if (appInfo) {
info.bundleType = static_cast<int32_t>(appInfo->bundleType);
info.appMode = appInfo->multiAppMode.multiAppModeType;
}
if (appInfo && (static_cast<int32_t>(appInfo->multiAppMode.multiAppModeType) ==
static_cast<int32_t>(MultiAppModeType::APP_CLONE))) {
info.appCloneIndex = appRecord->GetAppIndex();
}
info.instanceKey = appRecord->GetInstanceKey();
return ERR_OK;
}
@ -1371,13 +1413,13 @@ std::shared_ptr<ChildProcessRecord> AppRunningManager::OnChildProcessRemoteDied(
return nullptr;
}
int32_t AppRunningManager::SignRestartAppFlag(int32_t uid)
int32_t AppRunningManager::SignRestartAppFlag(int32_t uid, const std::string &instanceKey)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
std::lock_guard guard(runningRecordMapMutex_);
for (const auto &item : appRunningRecordMap_) {
const auto &appRecord = item.second;
if (appRecord == nullptr || appRecord->GetUid() != uid) {
if (appRecord == nullptr || appRecord->GetUid() != uid || appRecord->GetInstanceKey() != instanceKey) {
continue;
}
TAG_LOGD(AAFwkTag::APPMGR, "sign");
@ -1607,7 +1649,10 @@ bool AppRunningManager::HandleUserRequestClean(const sptr<IRemoteObject> &abilit
TAG_LOGE(AAFwkTag::APPMGR, "null appRecord");
return false;
}
if (appRecord->GetSupportProcessCacheState() == SupportProcessCacheState::SUPPORT) {
TAG_LOGI(AAFwkTag::APPMGR, "support porcess cache should not force clean");
return false;
}
auto abilityRecord = appRecord->GetAbilityRunningRecordByToken(abilityToken);
if (!abilityRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "null abilityRecord");
@ -1616,8 +1661,7 @@ bool AppRunningManager::HandleUserRequestClean(const sptr<IRemoteObject> &abilit
abilityRecord->SetUserRequestCleaningStatus();
bool canKill = appRecord->IsAllAbilityReadyToCleanedByUserRequest();
bool isProcessSupportCache = appRecord->GetSupportProcessCacheState() == SupportProcessCacheState::SUPPORT;
if (!canKill || isProcessSupportCache ||appRecord->IsKeepAliveApp()) {
if (!canKill || appRecord->IsKeepAliveApp()) {
return false;
}
@ -1661,6 +1705,9 @@ int32_t AppRunningManager::UpdateConfigurationDelayed(const std::shared_ptr<AppR
auto it = updateConfigurationDelayedMap_.find(appRecord->GetRecordId());
if (it != updateConfigurationDelayedMap_.end() && it->second) {
auto delayConfig = appRecord->GetDelayConfiguration();
if (delayConfig == nullptr) {
appRecord->ResetDelayConfiguration();
}
TAG_LOGI(AAFwkTag::APPKIT, "delayConfig: %{public}s", delayConfig->GetName().c_str());
result = appRecord->UpdateConfiguration(*delayConfig);
appRecord->ResetDelayConfiguration();

View File

@ -1177,6 +1177,9 @@ void AppRunningRecord::TerminateAbility(const sptr<IRemoteObject> &token, const
}
auto abilityRecord = GetAbilityRunningRecordByToken(token);
if (abilityRecord) {
TAG_LOGI(AAFwkTag::APPMGR, "TerminateAbility:%{public}s", abilityRecord->GetName().c_str());
}
if (!isTimeout) {
StateChangedNotifyObserver(
abilityRecord, static_cast<int32_t>(AbilityState::ABILITY_STATE_TERMINATED), true, false);

View File

@ -38,6 +38,10 @@ constexpr const char* VERSION_PREFIX = "v";
constexpr const char* APPSPAWN_CLIENT_USER_NAME = "APP_MANAGER_SERVICE";
constexpr int32_t RIGHT_SHIFT_STEP = 1;
constexpr int32_t START_FLAG_TEST_NUM = 1;
constexpr const char* JITPERMISSIONSLIST_NAME = "name";
constexpr const char* JITPERMISSIONSLIST_NAME_VALUE = "JITPermissions";
constexpr const char* JITPERMISSIONSLIST_COUNT = "ohos.encaps.count";
constexpr const char* JITPERMISSIONSLIST_PERMISSIONS_NAME = "permissions";
}
AppSpawnClient::AppSpawnClient(bool isNWebSpawn)
{
@ -145,6 +149,17 @@ static std::string DumpHspListToJson(const HspList &hspList)
return hspListJson.dump();
}
static std::string DumpJITPermissionListToJson(const JITPermissionsList &jitPermissionsList)
{
nlohmann::json jitPermissionsListJson;
jitPermissionsListJson[JITPERMISSIONSLIST_NAME] = JITPERMISSIONSLIST_NAME_VALUE;
jitPermissionsListJson[JITPERMISSIONSLIST_COUNT] = jitPermissionsList.size();
for (auto& jitPermission : jitPermissionsList) {
jitPermissionsListJson[JITPERMISSIONSLIST_PERMISSIONS_NAME].emplace_back(jitPermission);
}
return jitPermissionsListJson.dump();
}
static std::string DumpAppEnvToJson(const std::map<std::string, std::string> &appEnv)
{
nlohmann::json appEnvJson;
@ -154,15 +169,6 @@ static std::string DumpAppEnvToJson(const std::map<std::string, std::string> &ap
return appEnvJson.dump();
}
static std::string DumpExtensionSandboxDirsToJson(const std::map<std::string, std::string> &extensionSandboxDirs)
{
nlohmann::json extensionSandboxDirsJson;
for (auto &[userId, sandboxDir] : extensionSandboxDirs) {
extensionSandboxDirsJson[userId] = sandboxDir;
}
return extensionSandboxDirsJson.dump();
}
int32_t AppSpawnClient::SetDacInfo(const AppSpawnStartMsg &startMsg, AppSpawnReqMsgHandle reqHandle)
{
int32_t ret = 0;
@ -350,6 +356,16 @@ int32_t AppSpawnClient::AppspawnSetExtMsgMore(const AppSpawnStartMsg &startMsg,
}
}
if (!startMsg.jitPermissionsList.empty()) {
std::string jitPermissionsStr = DumpJITPermissionListToJson(startMsg.jitPermissionsList);
ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_JIT_PERMISSIONS, jitPermissionsStr.c_str());
if (ret) {
TAG_LOGE(AAFwkTag::APPMGR, "fail, ret: %{public}d", ret);
return ret;
}
TAG_LOGD(AAFwkTag::APPMGR, "Send JIT Permission: %{public}s", jitPermissionsStr.c_str());
}
return ret;
}

View File

@ -44,7 +44,7 @@ void WindowFocusChangedListener::OnFocused(const sptr<FocusChangeInfo> &focusCha
}
owner->HandleFocused(focusChangeInfo);
};
taskHandler_->SubmitTask(task);
taskHandler_->SubmitTask(task, "WindowFocusChangedListener::OnFocused");
}
}
@ -64,7 +64,7 @@ void WindowFocusChangedListener::OnUnfocused(const sptr<FocusChangeInfo> &focusC
}
owner->HandleUnfocused(focusChangeInfo);
};
taskHandler_->SubmitTask(task);
taskHandler_->SubmitTask(task, "WindowFocusChangedListener::OnUnfocused");
}
}
#endif // SUPPORT_SCREEN

View File

@ -50,7 +50,7 @@ void WindowPidVisibilityChangedListener::NotifyWindowPidVisibilityChanged(
}
serviceInner->HandleWindowPidVisibilityChanged(windowPidVisibilityInfo);
};
taskHandler_->SubmitTask(task);
taskHandler_->SubmitTask(task, "NotifyWindowPidVisibilityChanged");
}
#endif // SUPPORT_SCREEN
} // namespace AppExecFwk

View File

@ -49,7 +49,7 @@ void WindowVisibilityChangedListener::OnWindowVisibilityChanged(
}
serviceInner->HandleWindowVisibilityChanged(windowVisibilityInfos);
};
taskHandler_->SubmitTask(task);
taskHandler_->SubmitTask(task, "OnWindowVisibilityChanged");
}
#endif // SUPPORT_SCREEN
} // namespace AppExecFwk

View File

@ -55,6 +55,9 @@ struct EventInfo {
int64_t duration = 0;
int32_t reason = -1;
int32_t subReason = -1;
int32_t exitReason = -1;
bool isPreload = false;
int32_t preloadMode = 0;
};
enum class EventName {

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_FD_GUARD_H
#define OHOS_ABILITY_RUNTIME_FD_GUARD_H
#include <cstdint>
#include <unistd.h>
namespace OHOS {
namespace AAFwk {
class FdGuard {
public:
FdGuard() = default;
explicit FdGuard(int32_t fd) : fd_(fd) {}
~FdGuard()
{
if (fd_ > -1) {
close(fd_);
}
}
FdGuard(const FdGuard &) = delete;
FdGuard(FdGuard &&other) : fd_(other.fd_)
{
other.fd_ = -1;
}
void operator=(const FdGuard &) = delete;
FdGuard &operator=(FdGuard &&other)
{
if (fd_ > -1) {
close(fd_);
}
fd_ = other.fd_;
other.fd_ = -1;
return *this;
}
int32_t GetFd() const
{
return fd_;
}
int32_t Release()
{
auto ret = fd_;
fd_ = -1;
return ret;
}
void Reset()
{
if (fd_ > -1) {
close(fd_);
}
fd_ = -1;
}
private:
int32_t fd_ = -1;
};
} // AAFwk
} // OHOS
#endif // OHOS_ABILITY_RUNTIME_FD_GUARD_H

View File

@ -50,7 +50,8 @@ public:
std::string GetThawReasonByAbilityType(const AbilityInfo &abilityInfo);
void GetAllFrozenPidsFromRSS(std::unordered_set<int32_t> &frozenPids);
bool CheckShouldForceKillProcess(int32_t pid);
void ReportLoadingEventToRss(LoadingStage stage, int32_t pid, int32_t uid, int64_t timeDuration = 0);
void ReportLoadingEventToRss(LoadingStage stage, int32_t pid, int32_t uid,
int64_t timeDuration = 0, int64_t abilityRecordId = -1);
private:
ResSchedUtil() = default;
~ResSchedUtil() = default;

Some files were not shown because too many files have changed in this diff Show More