diff --git a/frameworks/js/napi/auto_fill_manager/auto_fill_manager_module.cpp b/frameworks/js/napi/auto_fill_manager/auto_fill_manager_module.cpp index db06a13cf6..9f8acc3261 100644 --- a/frameworks/js/napi/auto_fill_manager/auto_fill_manager_module.cpp +++ b/frameworks/js/napi/auto_fill_manager/auto_fill_manager_module.cpp @@ -18,8 +18,8 @@ static napi_module _module = { .nm_version = 0, - .nm_modname = "app.ability.autoFillManager", .nm_register_func = OHOS::AbilityRuntime::JsAutoFillManagerInit, + .nm_modname = "app.ability.autoFillManager", }; extern "C" __attribute__((constructor)) void NAPI_app_ability_autofillmanager_AutoRegister(void) diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index 58a65e4455..7cb908c582 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -19,14 +19,15 @@ #include #include "ability_manager_client.h" -#include "hitrace_meter.h" +#include "event_handler.h" #include "hilog_wrapper.h" +#include "hitrace_meter.h" +#include "ipc_skeleton.h" +#include "ability_runtime/js_caller_complex.h" #include "js_context_utils.h" #include "js_data_struct_converter.h" #include "js_error_utils.h" #include "js_runtime_utils.h" -#include "ability_runtime/js_caller_complex.h" -#include "ipc_skeleton.h" #include "mission_info.h" #include "napi_common_ability.h" #include "napi_common_start_options.h" @@ -34,10 +35,8 @@ #include "napi_common_want.h" #include "napi_remote_object.h" #include "start_options.h" -#include "want.h" -#include "event_handler.h" -#include "hitrace_meter.h" #include "tokenid_kit.h" +#include "want.h" #ifdef SUPPORT_GRAPHICS #include "pixel_map_napi.h" @@ -227,14 +226,14 @@ napi_value JsAbilityContext::OnStartAbility(napi_env env, NapiCallbackInfo& info } AAFwk::Want want; - OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want); + OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want); InheritWindowMode(want); - decltype(info.argc) unwrapArgc = 1; + decltype(info.argc) unwrapArgc = ARGC_ONE; HILOG_INFO("StartAbility, ability:%{public}s.", want.GetElement().GetAbilityName().c_str()); AAFwk::StartOptions startOptions; - if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[1], napi_object)) { + if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) { HILOG_DEBUG("OnStartAbility start options is used."); - AppExecFwk::UnwrapStartOptions(env, info.argv[1], startOptions); + AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_ONE], startOptions); unwrapArgc++; } @@ -259,7 +258,7 @@ napi_value JsAbilityContext::OnStartAbility(napi_env env, NapiCallbackInfo& info return; } - *innerErrorCode = (unwrapArgc == 1) ? + *innerErrorCode = (unwrapArgc == ARGC_ONE) ? context->StartAbility(want, -1) : context->StartAbility(want, startOptions, -1); if ((want.GetFlags() & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND && *innerErrorCode != 0 && observer != nullptr) { @@ -303,14 +302,14 @@ napi_value JsAbilityContext::OnStartAbilityAsCaller(napi_env env, NapiCallbackIn } AAFwk::Want want; - OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want); + OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want); InheritWindowMode(want); - decltype(info.argc) unwrapArgc = 1; + decltype(info.argc) unwrapArgc = ARGC_ONE; HILOG_INFO("StartAbilityAsCaller, ability:%{public}s.", want.GetElement().GetAbilityName().c_str()); AAFwk::StartOptions startOptions; - if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[1], napi_object)) { + if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) { HILOG_DEBUG("OnStartAbilityAsCaller start options is used."); - AppExecFwk::UnwrapStartOptions(env, info.argv[1], startOptions); + AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_ONE], startOptions); unwrapArgc++; } NapiAsyncTask::CompleteCallback complete = @@ -321,7 +320,7 @@ napi_value JsAbilityContext::OnStartAbilityAsCaller(napi_env env, NapiCallbackIn task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)); return; } - auto innerErrorCode = (unwrapArgc == 1) ? + auto innerErrorCode = (unwrapArgc == ARGC_ONE) ? context->StartAbilityAsCaller(want, -1) : context->StartAbilityAsCaller(want, startOptions, -1); if (innerErrorCode == 0) { task.Resolve(env, CreateJsUndefined(env)); @@ -349,12 +348,12 @@ napi_value JsAbilityContext::OnStartAbilityWithAccount(napi_env env, NapiCallbac return CreateJsUndefined(env); } AAFwk::Want want; - OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want); + OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want); InheritWindowMode(want); - decltype(info.argc) unwrapArgc = 1; + decltype(info.argc) unwrapArgc = ARGC_ONE; HILOG_INFO("StartAbilityWithAccount, ability:%{public}s", want.GetElement().GetAbilityName().c_str()); int32_t accountId = 0; - if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) { + if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) { HILOG_DEBUG("the second parameter is invalid."); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -363,7 +362,7 @@ napi_value JsAbilityContext::OnStartAbilityWithAccount(napi_env env, NapiCallbac AAFwk::StartOptions startOptions; if (info.argc > ARGC_TWO && CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_object)) { HILOG_DEBUG("OnStartAbilityWithAccount start options is used."); - AppExecFwk::UnwrapStartOptions(env, info.argv[ARGC_TWO], startOptions); + AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_TWO], startOptions); unwrapArgc++; } @@ -426,7 +425,8 @@ napi_value JsAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo } AAFwk::Want want; - if (!CheckTypeForNapiValue(env, info.argv[0], napi_object) || !AppExecFwk::UnwrapWant(env, info.argv[0], want)) { + if (!CheckTypeForNapiValue(env, info.argv[INDEX_ZERO], napi_object) || + !AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { HILOG_ERROR("Failed to parse want!"); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -438,14 +438,14 @@ napi_value JsAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo napi_value retsult = nullptr; int32_t userId = DEFAULT_INVAL_VALUE; if (info.argc > ARGC_ONE) { - if (CheckTypeForNapiValue(env, info.argv[ARGC_ONE], napi_number)) { - if (!ConvertFromJsValue(env, info.argv[ARGC_ONE], userId)) { + if (CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_number)) { + if (!ConvertFromJsValue(env, info.argv[INDEX_ONE], userId)) { HILOG_ERROR("Failed to parse accountId!"); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); } - } else if (CheckTypeForNapiValue(env, info.argv[ARGC_ONE], napi_function)) { - lastParam = info.argv[ARGC_ONE]; + } else if (CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_function)) { + lastParam = info.argv[INDEX_ONE]; } else { HILOG_ERROR("Failed, input param type invalid"); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); @@ -453,8 +453,8 @@ napi_value JsAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo } } - if (info.argc > ARGC_TWO && CheckTypeForNapiValue(env, info.argv[ARGC_TWO], napi_function)) { - lastParam = info.argv[ARGC_TWO]; + if (info.argc > ARGC_TWO && CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_function)) { + lastParam = info.argv[INDEX_TWO]; } auto callBackDone = [calldata = calls] (const sptr &obj) { @@ -560,17 +560,17 @@ napi_value JsAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackI } AAFwk::Want want; - if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) { + if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { HILOG_ERROR("Failed to parse want!"); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); } InheritWindowMode(want); - decltype(info.argc) unwrapArgc = 1; + decltype(info.argc) unwrapArgc = ARGC_ONE; AAFwk::StartOptions startOptions; - if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[1], napi_object)) { + if (info.argc > ARGC_ONE && CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) { HILOG_DEBUG("OnStartAbilityForResult begin options is used."); - AppExecFwk::UnwrapStartOptions(env, info.argv[1], startOptions); + AppExecFwk::UnwrapStartOptions(env, info.argv[INDEX_ONE], startOptions); unwrapArgc++; } @@ -615,7 +615,7 @@ napi_value JsAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackI } else { want.SetParam(Want::PARAM_RESV_FOR_RESULT, true); curRequestCode_ = (curRequestCode_ == INT_MAX) ? 0 : (curRequestCode_ + 1); - (unwrapArgc == 1) ? context->StartAbilityForResult(want, curRequestCode_, std::move(task)) : + (unwrapArgc == ARGC_ONE) ? context->StartAbilityForResult(want, curRequestCode_, std::move(task)) : context->StartAbilityForResult(want, startOptions, curRequestCode_, std::move(task)); } HILOG_DEBUG("OnStartAbilityForResult is called end"); @@ -637,15 +637,15 @@ napi_value JsAbilityContext::OnStartAbilityForResultWithAccount(napi_env env, Na return CreateJsUndefined(env); } AAFwk::Want want; - if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) { + if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { HILOG_ERROR("Failed to parse want!"); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); } InheritWindowMode(want); - decltype(info.argc) unwrapArgc = 1; + decltype(info.argc) unwrapArgc = ARGC_ONE; int32_t accountId = 0; - if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) { + if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) { HILOG_ERROR("the second parameter is invalid."); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -715,7 +715,7 @@ napi_value JsAbilityContext::OnStartExtensionAbility(napi_env env, NapiCallbackI } AAFwk::Want want; - if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) { + if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { HILOG_ERROR("Failed to parse want!"); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -737,7 +737,7 @@ napi_value JsAbilityContext::OnStartExtensionAbility(napi_env env, NapiCallbackI } }; - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnStartExtensionAbility", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -755,8 +755,8 @@ napi_value JsAbilityContext::OnStartExtensionAbilityWithAccount(napi_env env, Na AAFwk::Want want; int32_t accountId = -1; - if (!AppExecFwk::UnwrapWant(env, info.argv[0], want) || - !OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) { + if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want) || + !OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) { ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); } @@ -777,7 +777,7 @@ napi_value JsAbilityContext::OnStartExtensionAbilityWithAccount(napi_env env, Na } }; - napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[ARGC_TWO] : nullptr; + napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[INDEX_TWO] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnStartExtensionAbilityWithAccount", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -794,7 +794,7 @@ napi_value JsAbilityContext::OnStopExtensionAbility(napi_env env, NapiCallbackIn } AAFwk::Want want; - if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) { + if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want)) { ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); } @@ -815,7 +815,7 @@ napi_value JsAbilityContext::OnStopExtensionAbility(napi_env env, NapiCallbackIn } }; - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::Schedule("JsAbilityContext::OnStopExtensionAbility", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -833,8 +833,8 @@ napi_value JsAbilityContext::OnStopExtensionAbilityWithAccount(napi_env env, Nap int32_t accountId = -1; AAFwk::Want want; - if (!AppExecFwk::UnwrapWant(env, info.argv[0], want) || - !AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) { + if (!AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want) || + !AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) { ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); } @@ -855,7 +855,7 @@ napi_value JsAbilityContext::OnStopExtensionAbilityWithAccount(napi_env env, Nap } }; - napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[ARGC_TWO] : nullptr; + napi_value lastParam = (info.argc > ARGC_TWO) ? info.argv[INDEX_TWO] : nullptr; napi_value result = nullptr; NapiAsyncTask::Schedule("JsAbilityContext::OnStopExtensionAbilityWithAccount", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -866,7 +866,7 @@ napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbac { HILOG_INFO("TerminateSelfWithResult"); - if (info.argc == 0) { + if (info.argc == ARGC_ZERO) { HILOG_ERROR("Not enough params"); ThrowTooFewParametersError(env); return CreateJsUndefined(env); @@ -874,7 +874,7 @@ napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbac int resultCode = 0; AAFwk::Want want; - if (!AppExecFwk::UnWrapAbilityResult(env, info.argv[0], resultCode, want)) { + if (!AppExecFwk::UnWrapAbilityResult(env, info.argv[INDEX_ZERO], resultCode, want)) { HILOG_ERROR("%s Failed to parse ability result!", __func__); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -902,7 +902,7 @@ napi_value JsAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbac } }; - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[1] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnTerminateSelfWithResult", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -922,14 +922,14 @@ napi_value JsAbilityContext::OnConnectAbility(napi_env env, NapiCallbackInfo& in // unwrap want AAFwk::Want want; - OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want); + OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want); HILOG_INFO("ConnectAbility, callee:%{public}s.%{public}s", want.GetBundle().c_str(), want.GetElement().GetAbilityName().c_str()); // unwarp connection sptr connection = new JSAbilityConnection(env); - connection->SetJsConnectionObject(info.argv[1]); + connection->SetJsConnectionObject(info.argv[INDEX_ONE]); int64_t connectId = g_serialNumber; ConnectionKey key; key.id = g_serialNumber; @@ -977,13 +977,13 @@ napi_value JsAbilityContext::OnConnectAbilityWithAccount(napi_env env, NapiCallb // unwrap want AAFwk::Want want; - OHOS::AppExecFwk::UnwrapWant(env, info.argv[0], want); + OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want); HILOG_INFO("ConnectAbilityWithAccount, bundlename:%{public}s abilityname:%{public}s", want.GetBundle().c_str(), want.GetElement().GetAbilityName().c_str()); int32_t accountId = 0; - if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[1], accountId)) { + if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) { HILOG_ERROR("the second parameter is invalid."); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -1042,7 +1042,7 @@ napi_value JsAbilityContext::OnDisconnectAbility(napi_env env, NapiCallbackInfo& // unwrap connectId int64_t connectId = -1; sptr connection = nullptr; - napi_get_value_int64(env, info.argv[0], &connectId); + napi_get_value_int64(env, info.argv[INDEX_ZERO], &connectId); HILOG_INFO("DisconnectAbility, connection:%{public}d.", static_cast(connectId)); auto item = std::find_if(g_connects.begin(), g_connects.end(), @@ -1076,7 +1076,7 @@ napi_value JsAbilityContext::OnDisconnectAbility(napi_env env, NapiCallbackInfo& task.Resolve(env, CreateJsUndefined(env)); }; - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[1] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::Schedule("JsAbilityContext::OnDisconnectAbility", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -1108,7 +1108,7 @@ napi_value JsAbilityContext::OnTerminateSelf(napi_env env, NapiCallbackInfo& inf } }; - napi_value lastParam = (info.argc > ARGC_ZERO) ? info.argv[ARGC_ZERO] : nullptr; + napi_value lastParam = (info.argc > ARGC_ZERO) ? info.argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnTerminateSelf", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -1129,7 +1129,7 @@ napi_value JsAbilityContext::OnRestoreWindowStage(napi_env env, NapiCallbackInfo ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); return CreateJsUndefined(env); } - auto errcode = context->RestoreWindowStage(env, info.argv[0]); + auto errcode = context->RestoreWindowStage(env, info.argv[INDEX_ZERO]); if (errcode != 0) { ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER); return CreateJsError(env, errcode, "RestoreWindowStage failed."); @@ -1146,11 +1146,11 @@ napi_value JsAbilityContext::OnRequestDialogService(napi_env env, NapiCallbackIn } AAFwk::Want want; - AppExecFwk::UnwrapWant(env, info.argv[0], want); + AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want); HILOG_INFO("RequestDialogService, target:%{public}s.%{public}s.", want.GetBundle().c_str(), want.GetElement().GetAbilityName().c_str()); - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; auto uasyncTask = CreateAsyncTaskWithLastParam(env, lastParam, nullptr, nullptr, &result); std::shared_ptr asyncTask = std::move(uasyncTask); @@ -1215,7 +1215,7 @@ napi_value JsAbilityContext::OnReportDrawnCompleted(napi_env env, NapiCallbackIn } }; - napi_value lastParam = info.argv[ARGC_ZERO]; + napi_value lastParam = info.argv[INDEX_ZERO]; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnReportDrawnCompleted", env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result)); @@ -1248,8 +1248,10 @@ void JsAbilityContext::InheritWindowMode(AAFwk::Want &want) return; } auto windowMode = context->GetCurrentWindowMode(); - if (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY || - windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) { + auto deviceType = context->GetDeviceType(); + if (deviceType != Global::Resource::DeviceType::DEVICE_TWOINONE && + (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY || + windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY)) { want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode); } HILOG_DEBUG("window mode is %{public}d", windowMode); @@ -1601,7 +1603,7 @@ napi_value JsAbilityContext::OnSetMissionContinueState(napi_env env, NapiCallbac } AAFwk::ContinueState state; - if (!ConvertFromJsValue(env, info.argv[0], state)) { + if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], state)) { HILOG_ERROR("OnSetMissionContinueState, parse state failed."); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -1630,7 +1632,7 @@ napi_value JsAbilityContext::OnSetMissionContinueState(napi_env env, NapiCallbac } }; - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::SetMissionContinueState", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -1658,7 +1660,7 @@ napi_value JsAbilityContext::OnSetMissionLabel(napi_env env, NapiCallbackInfo& i } std::string label; - if (!ConvertFromJsValue(env, info.argv[0], label)) { + if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], label)) { HILOG_ERROR("OnSetMissionLabel, parse label failed."); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return CreateJsUndefined(env); @@ -1681,7 +1683,7 @@ napi_value JsAbilityContext::OnSetMissionLabel(napi_env env, NapiCallbackInfo& i } }; - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnSetMissionLabel", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); @@ -1697,7 +1699,7 @@ napi_value JsAbilityContext::OnSetMissionIcon(napi_env env, NapiCallbackInfo& in return CreateJsUndefined(env); } - auto icon = OHOS::Media::PixelMapNapi::GetPixelMap(env, info.argv[0]); + auto icon = OHOS::Media::PixelMapNapi::GetPixelMap(env, info.argv[INDEX_ZERO]); if (!icon) { HILOG_ERROR("OnSetMissionIcon, parse icon failed."); ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); @@ -1721,7 +1723,7 @@ napi_value JsAbilityContext::OnSetMissionIcon(napi_env env, NapiCallbackInfo& in } }; - napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[1] : nullptr; + napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnSetMissionIcon", env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index 557ae9c518..fb4955e879 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -57,12 +57,14 @@ public: std::condition_variable condition; }; +static std::mutex g_connectsMutex; static std::map, key_compare> g_connects; static int64_t g_serialNumber = 0; void RemoveConnection(int64_t connectId) { HILOG_DEBUG("enter"); + std::lock_guard guard(g_connectsMutex); auto item = std::find_if(g_connects.begin(), g_connects.end(), [&connectId](const auto &obj) { return connectId == obj.first.id; @@ -701,14 +703,17 @@ private: } connection->SetJsConnectionObject(value); ConnectionKey key; - key.id = g_serialNumber; - key.want = want; - connection->SetConnectionId(key.id); - g_connects.emplace(key, connection); - if (g_serialNumber < INT32_MAX) { - g_serialNumber++; - } else { - g_serialNumber = 0; + { + std::lock_guard guard(g_connectsMutex); + key.id = g_serialNumber; + key.want = want; + connection->SetConnectionId(key.id); + g_connects.emplace(key, connection); + if (g_serialNumber < INT32_MAX) { + g_serialNumber++; + } else { + g_serialNumber = 0; + } } HILOG_DEBUG("Unable to find connection, make new one"); return true; @@ -765,6 +770,7 @@ private: void FindConnection(AAFwk::Want& want, sptr& connection, int64_t& connectId) const { HILOG_INFO("Disconnect ability begin, connection:%{public}d.", static_cast(connectId)); + std::lock_guard guard(g_connectsMutex); auto item = std::find_if(g_connects.begin(), g_connects.end(), [&connectId](const auto &obj) { @@ -1125,21 +1131,24 @@ void JSServiceExtensionConnection::HandleOnAbilityDisconnectDone(const AppExecFw } // release connect - HILOG_DEBUG("OnAbilityDisconnectDone g_connects.size:%{public}zu", g_connects.size()); - std::string bundleName = element.GetBundleName(); - std::string abilityName = element.GetAbilityName(); - auto item = std::find_if(g_connects.begin(), - g_connects.end(), - [bundleName, abilityName, connectionId = connectionId_]( - const auto &obj) { - return (bundleName == obj.first.want.GetBundle()) && - (abilityName == obj.first.want.GetElement().GetAbilityName()) && - connectionId == obj.first.id; - }); - if (item != g_connects.end()) { - // match bundlename && abilityname - g_connects.erase(item); - HILOG_DEBUG("OnAbilityDisconnectDone erase g_connects.size:%{public}zu", g_connects.size()); + { + std::lock_guard guard(g_connectsMutex); + HILOG_DEBUG("OnAbilityDisconnectDone g_connects.size:%{public}zu", g_connects.size()); + std::string bundleName = element.GetBundleName(); + std::string abilityName = element.GetAbilityName(); + auto item = std::find_if(g_connects.begin(), + g_connects.end(), + [bundleName, abilityName, connectionId = connectionId_]( + const auto &obj) { + return (bundleName == obj.first.want.GetBundle()) && + (abilityName == obj.first.want.GetElement().GetAbilityName()) && + connectionId == obj.first.id; + }); + if (item != g_connects.end()) { + // match bundlename && abilityname + g_connects.erase(item); + HILOG_DEBUG("OnAbilityDisconnectDone erase g_connects.size:%{public}zu", g_connects.size()); + } } napi_call_function(env_, obj, method, ARGC_ONE, argv, nullptr); } diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp index 5fdfe486f0..6b02fff834 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp @@ -428,8 +428,11 @@ bool JsUIExtension::ForegroundWindowWithInsightIntent(const AAFwk::Want &want, auto context = GetContext(); InsightIntentExecutorInfo executorInfo; - executorInfo.hapPath = context->GetAbilityInfo()->hapPath; - executorInfo.windowMode = context->GetAbilityInfo()->compileMode == AppExecFwk::CompileMode::ES_MODULE; + std::shared_ptr abilityInfo = context->GetAbilityInfo(); + if (abilityInfo != nullptr) { + executorInfo.hapPath = abilityInfo->hapPath; + executorInfo.windowMode = abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE; + } executorInfo.token = context->GetToken(); executorInfo.pageLoader = contentSessions_[sessionInfo->uiExtensionComponentId]; executorInfo.executeParam = std::make_shared(); diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index a01adbe20f..95fef9c8d3 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -259,8 +259,11 @@ bool JsUIExtensionBase::ForegroundWindowWithInsightIntent(const AAFwk::Want &wan }); InsightIntentExecutorInfo executorInfo; - executorInfo.hapPath = context_->GetAbilityInfo()->hapPath; - executorInfo.windowMode = context_->GetAbilityInfo()->compileMode == AppExecFwk::CompileMode::ES_MODULE; + std::shared_ptr abilityInfo = context_->GetAbilityInfo(); + if (abilityInfo != nullptr) { + executorInfo.hapPath = abilityInfo->hapPath; + executorInfo.windowMode = abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE; + } executorInfo.token = context_->GetToken(); executorInfo.pageLoader = contentSessions_[sessionInfo->uiExtensionComponentId]; executorInfo.executeParam = std::make_shared(); diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index 80ab9eecd9..42385ce6b4 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -120,10 +120,7 @@ bool AppfreezeInner::IsExitApp(const std::string& name) int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) { HITRACE_METER_FMT(HITRACE_TAG_APP, "AppfreezeInner::AcquireStack name:%s", info.errorObject.name.c_str()); - StartTrace(HITRACE_TAG_APP, "dumper MixStack"); - std::string stack = MixStackDumper::GetMixStack(onlyMainThread); - FinishTrace(HITRACE_TAG_APP); - + std::string stack = ""; std::string msgContent; auto mainHandler = appMainHandler_.lock(); diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 93e3000e33..1caa5f094c 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -520,9 +520,10 @@ public: * clear the application data. * * @param bundleName, bundle name in Application record. + * @param userId User ID. * @return Returns ERR_OK on success, others on failure. */ - ErrCode ClearUpApplicationData(const std::string &bundleName); + ErrCode ClearUpApplicationData(const std::string &bundleName, const int32_t userId = DEFAULT_INVAL_VALUE); /** * ContinueMission, continue ability from mission center. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 0946b8f2d5..cb970b2c02 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -607,7 +607,7 @@ public: * @param bundleName, bundle name in Application record. * @return */ - virtual int ClearUpApplicationData(const std::string &bundleName) = 0; + virtual int ClearUpApplicationData(const std::string &bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) = 0; /** * Uninstall app diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 66cbd8e22d..436c267483 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -175,9 +175,11 @@ public: * clear the application data. * * @param bundleName, bundle name in Application record. + * @param userId, the user id. * @return */ - virtual AppMgrResultCode ClearUpApplicationData(const std::string &bundleName); + virtual AppMgrResultCode ClearUpApplicationData(const std::string &bundleName, + const int32_t userId = -1); /** * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 25dca52bb2..ad865edcec 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -109,9 +109,11 @@ public: * clear the application data. * * @param bundleName, bundle name in Application record. + * @param userId the user id. * @return */ - virtual int32_t ClearUpApplicationData(const std::string &bundleName) = 0; + virtual int32_t ClearUpApplicationData(const std::string &bundleName, + const int32_t userId = -1) = 0; /** * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 4874037722..a09c843841 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -96,7 +96,8 @@ public: * @param bundleName, bundle name in Application record. * @return */ - virtual int32_t ClearUpApplicationData(const std::string &bundleName) override; + virtual int32_t ClearUpApplicationData(const std::string &bundleName, + const int32_t userId = -1) override; /** * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index e4450663e8..25a46deb91 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -302,11 +302,11 @@ AppMgrResultCode AppMgrClient::KillApplicationSelf() return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } -AppMgrResultCode AppMgrClient::ClearUpApplicationData(const std::string &bundleName) +AppMgrResultCode AppMgrClient::ClearUpApplicationData(const std::string &bundleName, const int32_t userId) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { - int32_t result = service->ClearUpApplicationData(bundleName); + int32_t result = service->ClearUpApplicationData(bundleName, userId); if (result == ERR_OK) { return AppMgrResultCode::RESULT_OK; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index c8e65b9ffc..919b4ee2a8 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -154,7 +154,7 @@ sptr AppMgrProxy::GetAmsMgr() return amsMgr; } -int32_t AppMgrProxy::ClearUpApplicationData(const std::string &bundleName) +int32_t AppMgrProxy::ClearUpApplicationData(const std::string &bundleName, const int32_t userId) { MessageParcel data; MessageParcel reply; @@ -166,6 +166,10 @@ int32_t AppMgrProxy::ClearUpApplicationData(const std::string &bundleName) HILOG_ERROR("parcel WriteString failed"); return ERR_FLATTEN_OBJECT; } + if (!data.WriteInt32(userId)) { + HILOG_ERROR("userId write failed."); + return ERR_INVALID_VALUE; + } int32_t ret = SendRequest(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA, data, reply, option); if (ret != NO_ERROR) { HILOG_WARN("SendRequest is failed, error code: %{public}d", ret); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 6ea93b3cfc..6e5ead205b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -246,7 +246,8 @@ int32_t AppMgrStub::HandleClearUpApplicationData(MessageParcel &data, MessagePar { HITRACE_METER(HITRACE_TAG_APP); std::string bundleName = data.ReadString(); - int32_t result = ClearUpApplicationData(bundleName); + int32_t userId = data.ReadInt32(); + int32_t result = ClearUpApplicationData(bundleName, userId); reply.WriteInt32(result); return NO_ERROR; } diff --git a/interfaces/inner_api/extension_manager/src/extension_manager_client.cpp b/interfaces/inner_api/extension_manager/src/extension_manager_client.cpp index 812d627315..6c48c22b56 100755 --- a/interfaces/inner_api/extension_manager/src/extension_manager_client.cpp +++ b/interfaces/inner_api/extension_manager/src/extension_manager_client.cpp @@ -104,7 +104,7 @@ ErrCode ExtensionManagerClient::ConnectServiceExtensionAbility(const Want &want, HILOG_INFO("name:%{public}s %{public}s, userId:%{public}d.", want.GetElement().GetBundleName().c_str(), want.GetElement().GetAbilityName().c_str(), userId); return abms->ConnectAbilityCommon(want, connect, nullptr, AppExecFwk::ExtensionAbilityType::SERVICE, - userId, true); + userId, false); } ErrCode ExtensionManagerClient::ConnectServiceExtensionAbility(const Want &want, @@ -120,7 +120,7 @@ ErrCode ExtensionManagerClient::ConnectServiceExtensionAbility(const Want &want, HILOG_INFO("name:%{public}s %{public}s, userId:%{public}d.", want.GetElement().GetBundleName().c_str(), want.GetElement().GetAbilityName().c_str(), userId); return abms->ConnectAbilityCommon( - want, connect, callerToken, AppExecFwk::ExtensionAbilityType::SERVICE, userId, true); + want, connect, callerToken, AppExecFwk::ExtensionAbilityType::SERVICE, userId, false); } ErrCode ExtensionManagerClient::ConnectEnterpriseAdminExtensionAbility(const Want &want, diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 64fab24186..47fe019d3d 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -63,7 +63,9 @@ abilityms_files = [ # new ability manager service here "src/task_data_persistence_mgr.cpp", - "src/ui_extension_ability_connect_manager.cpp", + "src/extension_record_manager.cpp", + "src/extension_record.cpp", + "src/ui_extension_record.cpp", "src/start_options.cpp", "src/stop_user_callback_proxy.cpp", "src/stop_user_callback_stub.cpp", diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index ed4bbd31a4..1421f22f8c 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -32,7 +32,7 @@ #include "connection_record.h" #include "element_name.h" #include "ui_extension_ability_connect_info.h" -#include "ui_extension_ability_connect_manager.h" +#include "extension_record_manager.h" #include "want.h" #include "iremote_object.h" #include "nocopyable.h" @@ -41,7 +41,7 @@ namespace OHOS { namespace AAFwk { using OHOS::AppExecFwk::AbilityType; using UIExtensionAbilityConnectInfo = AbilityRuntime::UIExtensionAbilityConnectInfo; -using UIExtensionAbilityConnectManager = AbilityRuntime::UIExtensionAbilityConnectManager; +using UIExtensionAbilityConnectManager = AbilityRuntime::ExtensionRecordManager; /** * @class AbilityConnectManager @@ -502,12 +502,12 @@ private: bool IsLauncher(std::shared_ptr serviceExtension) const; bool IsSceneBoard(std::shared_ptr serviceExtension) const; void KillProcessesByUserId() const; - inline bool IsUIExtensionAbility(const std::shared_ptr abilityRecord); + inline bool IsUIExtensionAbility(const std::shared_ptr &abilityRecord); inline bool CheckUIExtensionAbilityLoaded(const AbilityRequest &abilityRequest); - inline bool CheckUIExtensionAbilitySessionExistLocked(const std::shared_ptr abilityRecord); - inline int32_t AddUIExtensionAbilityRecord(const std::shared_ptr abilityRecord, - const std::string hostBundleName, const int32_t inputId) const; - inline void RemoveUIExtensionAbilityRecord(const std::shared_ptr abilityRecord); + inline bool CheckUIExtensionAbilitySessionExistLocked(const std::shared_ptr &abilityRecord); + inline int32_t AddUIExtensionAbilityRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, const int32_t inputId) const; + inline void RemoveUIExtensionAbilityRecord(const std::shared_ptr &abilityRecord); private: const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 458f3ca202..11e3e6e64e 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -497,7 +497,8 @@ public: * @param bundleName, bundle name in Application record. * @return */ - virtual int ClearUpApplicationData(const std::string &bundleName) override; + virtual int ClearUpApplicationData(const std::string &bundleName, + const int32_t userId = -1) override; /** * Uninstall app diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index aa1da583d4..04b5c6e29b 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -644,7 +644,8 @@ public: * @param bundleName, bundle name in Application record. * @return ERR_OK, return back success, others fail. */ - virtual int ClearUpApplicationData(const std::string &bundleName) override; + virtual int ClearUpApplicationData(const std::string &bundleName, + const int32_t userId = -1) override; /** * Uninstall app diff --git a/services/abilitymgr/include/app_gallery_enable_util.h b/services/abilitymgr/include/app_gallery_enable_util.h new file mode 100644 index 0000000000..68345ef656 --- /dev/null +++ b/services/abilitymgr/include/app_gallery_enable_util.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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_APP_GALLERY_ENABLE_UTIL_H +#define OHOS_ABILITY_APP_GALLERY_ENABLE_UTIL_H + +#include +#include "hilog_wrapper.h" +#include "parameters.h" + +namespace OHOS { +namespace AAFwk { +namespace AppGalleryEnableUtil { +const std::string ENABLE_APP_GALLERY_SELECTOR_UTIL = "abilitymanagerservice.support.appgallery.selector"; + +inline bool IsEnableAppGallerySelector() +{ + HILOG_DEBUG("call"); + std::string ret = OHOS::system::GetParameter(ENABLE_APP_GALLERY_SELECTOR_UTIL, "false"); + if (ret == "true") { + return true; + } + return false; +} +} // namespace AppGalleryEnableUtil +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_APP_GALLERY_ENABLE_UTIL_H diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 0a60a6a31d..0ce02c8739 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -21,6 +21,7 @@ #include "ability_debug_response_interface.h" #include "ability_info.h" +#include "ability_manager_client.h" #include "app_debug_listener_interface.h" #include "application_info.h" #include "appmgr/app_mgr_client.h" @@ -243,7 +244,7 @@ public: * * @param bundleName. */ - int ClearUpApplicationData(const std::string &bundleName); + int ClearUpApplicationData(const std::string &bundleName, const int32_t userId = -1); void AttachTimeOut(const sptr &token); diff --git a/services/abilitymgr/include/ui_extension_ability_record.h b/services/abilitymgr/include/extension_record.h similarity index 54% rename from services/abilitymgr/include/ui_extension_ability_record.h rename to services/abilitymgr/include/extension_record.h index dd5e11b912..303ff2fc16 100644 --- a/services/abilitymgr/include/ui_extension_ability_record.h +++ b/services/abilitymgr/include/extension_record.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_UI_EXTENSION_ABILITY_RECORD_H -#define OHOS_ABILITY_RUNTIME_UI_EXTENSION_ABILITY_RECORD_H +#ifndef OHOS_ABILITY_RUNTIME_EXTENSION_RECORD_H +#define OHOS_ABILITY_RUNTIME_EXTENSION_RECORD_H #include #include @@ -25,19 +25,28 @@ namespace OHOS { namespace AbilityRuntime { -class UIExtensionAbilityRecord : public std::enable_shared_from_this { +class ExtensionRecord : public std::enable_shared_from_this { public: - UIExtensionAbilityRecord(const std::shared_ptr abilityRecord, std::string hostBundleName, - int32_t uiExtensionAbilityId) - : abilityRecord_(abilityRecord), hostBundleName_(hostBundleName), uiExtensionAbilityId_(uiExtensionAbilityId) - {} + ExtensionRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, int32_t extensionRecordId); - virtual ~UIExtensionAbilityRecord() = default; + virtual ~ExtensionRecord(); + + sptr GetCallToken() const; + + sptr GetRootCallerToken() const; + + void SetRootCallerToken(sptr &rootCallerToken); + + virtual bool ContinueToGetCallerToken(); std::shared_ptr abilityRecord_ = nullptr; - std::string hostBundleName_ = ""; - int32_t uiExtensionAbilityId_ = 0; + std::string hostBundleName_; + int32_t extensionRecordId_ = 0; + +private: + sptr rootCallerToken_ = nullptr; }; } // namespace AbilityRuntime } // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_UI_EXTENSION_ABILITY_RECORD_H +#endif // OHOS_ABILITY_RUNTIME_EXTENSION_RECORD_H diff --git a/services/abilitymgr/include/extension_record_manager.h b/services/abilitymgr/include/extension_record_manager.h new file mode 100644 index 0000000000..910ae2ea84 --- /dev/null +++ b/services/abilitymgr/include/extension_record_manager.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023 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_EXTENSION_RECORD_MANAGER_H +#define OHOS_ABILITY_RUNTIME_EXTENSION_RECORD_MANAGER_H + +#include +#include +#include +#include + +#include "extension_record.h" + +namespace OHOS { +namespace AbilityRuntime { +constexpr int32_t INVALID_EXTENSION_RECORD_ID = 0; + +class ExtensionRecordManager : public std::enable_shared_from_this { +public: + using ExtensionAbilityRecordMap = std::map>; + + explicit ExtensionRecordManager(const int32_t userId); + virtual ~ExtensionRecordManager(); + + /** + * @brief Generate extension record id, if input id didn't exist, return it, else assign one. + * + * @param extensionRecordId Input extension record id. + * @return int32_t Generated extension record id. + */ + int32_t GenerateExtensionRecordId(const int32_t extensionRecordId); + + /** + * @brief Add extension record by id, if record exist, replace it. + * + * @param extensionRecordId extension record id. + * @param record extension record. + */ + void AddExtensionRecord(const int32_t extensionRecordId, const std::shared_ptr &record); + + /** + * @brief Remove extension record by id + * + * @param extensionRecordId extension record id. + */ + void RemoveExtensionRecord(const int32_t extensionRecordId); + + /** + * @brief Check if host bundleName matched to stored record by specified id. + * + * @param extensionRecordId extension record id. + * @param hostBundleName bundleName of target extension. + * @return true Matched. + * @return false Not Match. + */ + bool CheckExtensionLoaded(const int32_t extensionRecordId, const std::string &hostBundleName); + + static bool IsBelongToManager(const AppExecFwk::AbilityInfo &abilityInfo); + + bool IsFocused(int32_t extensionRecordId, const sptr& focusToken); + + int32_t CreateExtensionRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, int32_t &extensionRecordId); + +private: + int32_t userId_; + static std::atomic_int32_t extensionRecordId_; + std::mutex mutex_; + std::set extensionRecordIdSet_; + ExtensionAbilityRecordMap extensionRecords_; + + sptr GetRootCallerTokenLocked(int32_t extensionRecordId); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_EXTENSION_RECORD_MANAGER_H diff --git a/services/abilitymgr/include/ui_extension_ability_connect_manager.h b/services/abilitymgr/include/ui_extension_ability_connect_manager.h deleted file mode 100644 index 2b6e8d0061..0000000000 --- a/services/abilitymgr/include/ui_extension_ability_connect_manager.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2023 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_UI_EXTENSION_ABILITY_CONNECT_MANAGER_H -#define OHOS_ABILITY_RUNTIME_UI_EXTENSION_ABILITY_CONNECT_MANAGER_H - -#include -#include -#include -#include - -#include "ui_extension_ability_record.h" - -namespace OHOS { -namespace AbilityRuntime { -constexpr int32_t INVALID_UI_EXTENSION_ABILITY_ID = 0; - -class UIExtensionAbilityConnectManager : public std::enable_shared_from_this { -public: - using UIExtensionAbilityRecordMap = std::map>; - - explicit UIExtensionAbilityConnectManager(const int32_t userId); - virtual ~UIExtensionAbilityConnectManager(); - - /** - * @brief Generate uiextensionability id, if input id didn't exist, return it, else assign one. - * - * @param uiExtensionAbilityId Input uiextensionability id. - * @return int32_t Generated uiextensionability id. - */ - int32_t GenerateUIExtensionAbilityId(const int32_t uiExtensionAbilityId); - - /** - * @brief Add uiextensionability record by id, if record exist, replace it. - * - * @param uiExtensionAbilityId uiextensionability id. - * @param record uiextensionability record. - */ - void AddUIExtensionAbilityRecord(const int32_t uiExtensionAbilityId, - const std::shared_ptr record); - - /** - * @brief Remove uiextensionability record by id - * - * @param uiExtensionAbilityId uiextensionability id. - */ - void RemoveUIExtensionAbilityRecord(const int32_t uiExtensionAbilityId); - - /** - * @brief Check if host bundleName matched to stored record by specified id. - * - * @param uiExtensionAbilityId uiextensionability id. - * @param hostBundleName bundleName of target uiextensionability. - * @return true Matched. - * @return false Not Match. - */ - bool CheckUIExtensionAbilityLoaded(const int32_t uiExtensionAbilityId, const std::string hostBundleName); - -private: - int32_t userId_; - static std::atomic_int32_t uiExtensionAbilityId_; - std::mutex mutex_; - std::set uiExtensionAbilityIdSet_; - UIExtensionAbilityRecordMap uiExtensionAbilityRecords_; -}; -} // namespace AbilityRuntime -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_UI_EXTENSION_ABILITY_CONNECT_MANAGER_H diff --git a/services/abilitymgr/include/ui_extension_record.h b/services/abilitymgr/include/ui_extension_record.h new file mode 100644 index 0000000000..1a4c2e85d6 --- /dev/null +++ b/services/abilitymgr/include/ui_extension_record.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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_UI_EXTENSION_RECORD_H +#define OHOS_ABILITY_RUNTIME_UI_EXTENSION_RECORD_H + +#include +#include +#include +#include + +#include "extension_record.h" + +namespace OHOS { +namespace AbilityRuntime { +class UIExtensionRecord : public ExtensionRecord { +public: + UIExtensionRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, int32_t extensionRecordId); + + ~UIExtensionRecord() override; + + bool ContinueToGetCallerToken() override; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_UI_EXTENSION_RECORD_H diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index e5a948e99e..112917361b 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -30,7 +30,7 @@ #include "mock_session_manager_service.h" #include "parameter.h" #include "session/host/include/zidl/session_interface.h" -#include "ui_extension_ability_record.h" +#include "extension_record.h" #include "ui_extension_utils.h" namespace OHOS { @@ -69,7 +69,7 @@ const std::unordered_set FROZEN_WHITE_LIST { AbilityConnectManager::AbilityConnectManager(int userId) : userId_(userId) { - uiExtensionAbilityRecordMgr_ = std::make_unique(userId); + uiExtensionAbilityRecordMgr_ = std::make_unique(userId); } AbilityConnectManager::~AbilityConnectManager() @@ -114,6 +114,12 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("ability_name:%{public}s", abilityRequest.want.GetElement().GetURI().c_str()); + if (UIExtensionUtils::IsUIExtension(abilityRequest.abilityInfo.extensionAbilityType) && + !CheckUIExtensionAbilityLoaded(abilityRequest)) { + HILOG_WARN("Start uiextensionability with invalid id."); + return ERR_INVALID_VALUE; + } + std::shared_ptr targetService; bool isLoadedAbility = false; GetOrCreateServiceRecord(abilityRequest, false, targetService, isLoadedAbility); @@ -136,7 +142,7 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque if (IsUIExtensionAbility(targetService) && abilityRequest.sessionInfo != nullptr) { std::string hostBundleName = abilityRequest.abilityInfo.bundleName; int32_t inputId = abilityRequest.sessionInfo->want.GetIntParam(UIEXTENSION_ABILITY_ID, - INVALID_UI_EXTENSION_ABILITY_ID); + INVALID_EXTENSION_RECORD_ID); auto uiExtensionAbilityId = AddUIExtensionAbilityRecord(targetService, hostBundleName, inputId); HILOG_DEBUG("UIExtensionAbility id %{public}d.", uiExtensionAbilityId); } @@ -147,8 +153,7 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque } else if (IsUIExtensionAbility(targetService) && targetService->IsReady() && !targetService->IsAbilityState(AbilityState::INACTIVATING) && !targetService->IsAbilityState(AbilityState::BACKGROUNDING) && - targetService->IsAbilityWindowReady() && - CheckUIExtensionAbilityLoaded(abilityRequest)) { + targetService->IsAbilityWindowReady()) { targetService->SetWant(abilityRequest.want); CommandAbilityWindow(targetService, abilityRequest.sessionInfo, WIN_CMD_FOREGROUND); } else { @@ -723,7 +728,7 @@ int AbilityConnectManager::ScheduleDisconnectAbilityDoneLocked(const sptrRemoveConnectRecordFromList(connect); if (abilityRecord->IsConnectListEmpty() && abilityRecord->GetStartId() == 0) { if (IsUIExtensionAbility(abilityRecord) && CheckUIExtensionAbilitySessionExistLocked(abilityRecord)) { - HILOG_INFO("There exist ui extension component, don't terminate when disconnet."); + HILOG_INFO("There exist ui extension component, don't terminate when disconnect."); } else { HILOG_INFO("Service ability has no any connection, and not started, need terminate."); TerminateRecord(abilityRecord); @@ -2192,12 +2197,15 @@ void AbilityConnectManager::HandleUIExtWindowDiedTask(const sptr bool AbilityConnectManager::IsUIExtensionFocused(uint32_t uiExtensionTokenId, const sptr& focusToken) { + HILOG_DEBUG("called, id: %{public}u", uiExtensionTokenId); + CHECK_POINTER_AND_RETURN(uiExtensionAbilityRecordMgr_, false); std::lock_guard guard(Lock_); for (auto& item: uiExtensionMap_) { auto uiExtension = item.second.first.lock(); auto sessionInfo = item.second.second; if (uiExtension && uiExtension->GetApplicationInfo().accessTokenId == uiExtensionTokenId - && sessionInfo && sessionInfo->callerToken == focusToken) { + && uiExtensionAbilityRecordMgr_->IsFocused(uiExtension->GetUIExtensionAbilityId(), focusToken)) { + HILOG_INFO("id: %{public}u, isFocused.", uiExtensionTokenId); return true; } } @@ -2304,7 +2312,7 @@ void AbilityConnectManager::HandleExtensionDisconnectTask(const std::shared_ptr< } } -bool AbilityConnectManager::IsUIExtensionAbility(const std::shared_ptr abilityRecord) +bool AbilityConnectManager::IsUIExtensionAbility(const std::shared_ptr &abilityRecord) { CHECK_POINTER_AND_RETURN(abilityRecord, false); return UIExtensionUtils::IsUIExtension(abilityRecord->GetAbilityInfo().extensionAbilityType); @@ -2316,20 +2324,21 @@ bool AbilityConnectManager::CheckUIExtensionAbilityLoaded(const AbilityRequest & CHECK_POINTER_AND_RETURN(uiExtensionAbilityRecordMgr_, false); int32_t uiExtensionAbilityId = abilityRequest.sessionInfo->want.GetIntParam(UIEXTENSION_ABILITY_ID, - INVALID_UI_EXTENSION_ABILITY_ID); - if (uiExtensionAbilityId == INVALID_UI_EXTENSION_ABILITY_ID) { + INVALID_EXTENSION_RECORD_ID); + if (uiExtensionAbilityId == INVALID_EXTENSION_RECORD_ID) { HILOG_DEBUG("Didn't carry uiextension ability id when start."); return true; } - auto ret = uiExtensionAbilityRecordMgr_->CheckUIExtensionAbilityLoaded( + HILOG_INFO("UIExtensionAbility id: %{public}d.", uiExtensionAbilityId); + auto ret = uiExtensionAbilityRecordMgr_->CheckExtensionLoaded( uiExtensionAbilityId, abilityRequest.abilityInfo.bundleName); HILOG_DEBUG("UIExtensionAbility loaded status: %{public}s.", ret ? "true" : "false"); return ret; } bool AbilityConnectManager::CheckUIExtensionAbilitySessionExistLocked( - const std::shared_ptr abilityRecord) + const std::shared_ptr &abilityRecord) { CHECK_POINTER_AND_RETURN(abilityRecord, false); @@ -2344,26 +2353,21 @@ bool AbilityConnectManager::CheckUIExtensionAbilitySessionExistLocked( return false; } -int32_t AbilityConnectManager::AddUIExtensionAbilityRecord(const std::shared_ptr abilityRecord, - const std::string hostBundleName, const int32_t inputId) const +int32_t AbilityConnectManager::AddUIExtensionAbilityRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, const int32_t inputId) const { - CHECK_POINTER_AND_RETURN(abilityRecord, INVALID_UI_EXTENSION_ABILITY_ID); - CHECK_POINTER_AND_RETURN(uiExtensionAbilityRecordMgr_, INVALID_UI_EXTENSION_ABILITY_ID); - - auto uiExtensionAbilityId = uiExtensionAbilityRecordMgr_->GenerateUIExtensionAbilityId(inputId); - HILOG_DEBUG("Generated id is %{public}d.", uiExtensionAbilityId); - abilityRecord->SetUIExtensionAbilityId(uiExtensionAbilityId); - auto uiExtensionAbilityRecord = std::make_shared(abilityRecord, - hostBundleName, uiExtensionAbilityId); - uiExtensionAbilityRecordMgr_->AddUIExtensionAbilityRecord(uiExtensionAbilityId, uiExtensionAbilityRecord); + CHECK_POINTER_AND_RETURN(abilityRecord, INVALID_EXTENSION_RECORD_ID); + CHECK_POINTER_AND_RETURN(uiExtensionAbilityRecordMgr_, INVALID_EXTENSION_RECORD_ID); + int32_t uiExtensionAbilityId = inputId; + uiExtensionAbilityRecordMgr_->CreateExtensionRecord(abilityRecord, hostBundleName, uiExtensionAbilityId); return uiExtensionAbilityId; } -void AbilityConnectManager::RemoveUIExtensionAbilityRecord(const std::shared_ptr abilityRecord) +void AbilityConnectManager::RemoveUIExtensionAbilityRecord(const std::shared_ptr &abilityRecord) { CHECK_POINTER(abilityRecord); CHECK_POINTER(uiExtensionAbilityRecordMgr_); - uiExtensionAbilityRecordMgr_->RemoveUIExtensionAbilityRecord(abilityRecord->GetUIExtensionAbilityId()); + uiExtensionAbilityRecordMgr_->RemoveExtensionRecord(abilityRecord->GetUIExtensionAbilityId()); } } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_interceptor.cpp b/services/abilitymgr/src/ability_interceptor.cpp index df6544545d..11003d8db6 100644 --- a/services/abilitymgr/src/ability_interceptor.cpp +++ b/services/abilitymgr/src/ability_interceptor.cpp @@ -36,6 +36,7 @@ #include "permission_verification.h" #include "system_dialog_scheduler.h" #include "want.h" +#include "want_params_wrapper.h" namespace OHOS { namespace AAFwk { #ifdef SUPPORT_ERMS @@ -59,6 +60,11 @@ const std::string JUMP_DIALOG_TARGET_MODULE_NAME = "interceptor_targetModuleName const std::string JUMP_DIALOG_TARGET_LABEL_ID = "interceptor_targetLabelId"; const std::string UNREGISTER_EVENT_TASK = "unregister event task"; const std::string ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE = "abilitymanagerservice.support.ecologicalrulemgrservice"; +const std::string IS_FROM_PARENTCONTROL = "ohos.ability.isFromParentControl"; +const std::string INTERCEPT_PARAMETERS = "intercept_parammeters"; +const std::string INTERCEPT_BUNDLE_NAME = "intercept_bundleName"; +const std::string INTERCEPT_ABILITY_NAME = "intercept_abilityName"; +const std::string INTERCEPT_MODULE_NAME = "intercept_moduleName"; constexpr int KILL_PROCESS_DELAYTIME_MICRO_SECONDS = 5000; ErrCode CrowdTestInterceptor::DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground) @@ -119,13 +125,28 @@ ErrCode ControlInterceptor::DoProcess(const Want &want, int requestCode, int32_t if (CheckControl(want, userId, controlRule)) { HILOG_INFO("The target application is intercpted. %{public}s", controlRule.controlMessage.c_str()); #ifdef SUPPORT_GRAPHICS - if (isForeground && controlRule.controlWant != nullptr) { - int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(*controlRule.controlWant, - requestCode, userId)); - if (ret != ERR_OK) { - HILOG_ERROR("Control implicit start appgallery failed."); - return ret; + if (!isForeground || controlRule.controlWant == nullptr) { + HILOG_ERROR("Can not start control want"); + return ERR_INVALID_VALUE; + } + if (controlRule.controlWant->GetBoolParam(IS_FROM_PARENTCONTROL, false)) { + auto controlWant = controlRule.controlWant; + auto controlParam = controlWant->GetParams(); + sptr interceptParam = WantParamWrapper::Box(want.GetParams()); + if (interceptParam != nullptr) { + controlParam.SetParam(INTERCEPT_PARAMETERS, interceptParam); } + controlWant->SetParams(controlParam); + controlWant->SetParam(INTERCEPT_BUNDLE_NAME, want.GetElement().GetBundleName()); + controlWant->SetParam(INTERCEPT_ABILITY_NAME, want.GetElement().GetAbilityName()); + controlWant->SetParam(INTERCEPT_MODULE_NAME, want.GetElement().GetModuleName()); + controlRule.controlWant = controlWant; + } + int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(*controlRule.controlWant, + requestCode, userId)); + if (ret != ERR_OK) { + HILOG_ERROR("Control implicit start appgallery failed."); + return ret; } #endif if (controlRule.isEdm) { diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 197bb63143..d209dbc53a 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -552,12 +552,12 @@ ErrCode AbilityManagerClient::ForceTimeoutForTest(const std::string &abilityName } #endif -ErrCode AbilityManagerClient::ClearUpApplicationData(const std::string &bundleName) +ErrCode AbilityManagerClient::ClearUpApplicationData(const std::string &bundleName, const int32_t userId) { HILOG_INFO("call"); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->ClearUpApplicationData(bundleName); + return abms->ClearUpApplicationData(bundleName, userId); } ErrCode AbilityManagerClient::ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 41192fe9c9..7a9335b29d 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1617,7 +1617,7 @@ int AbilityManagerProxy::ForceTimeoutForTest(const std::string &abilityName, con } #endif -int AbilityManagerProxy::ClearUpApplicationData(const std::string &bundleName) +int AbilityManagerProxy::ClearUpApplicationData(const std::string &bundleName, const int32_t userId) { MessageParcel data; MessageParcel reply; @@ -1630,6 +1630,10 @@ int AbilityManagerProxy::ClearUpApplicationData(const std::string &bundleName) HILOG_ERROR("bundleName write failed."); return ERR_INVALID_VALUE; } + if (!data.WriteInt32(userId)) { + HILOG_ERROR("userId write failed."); + return ERR_INVALID_VALUE; + } int error = SendRequest(AbilityManagerInterfaceCode::CLEAR_UP_APPLICATION_DATA, data, reply, option); if (error != NO_ERROR) { HILOG_ERROR("Send request error: %{public}d", error); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 489b2cb681..3114b74b24 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -75,7 +75,7 @@ #include "string_wrapper.h" #include "system_ability_definition.h" #include "system_ability_token_callback.h" -#include "ui_extension_ability_connect_manager.h" +#include "extension_record_manager.h" #include "ui_extension_utils.h" #include "uri_permission_manager_client.h" #include "view_data.h" @@ -208,6 +208,7 @@ const int32_t BROKER_UID = 5557; const int32_t BROKER_RESERVE_UID = 5005; const int32_t DMS_UID = 5522; const int32_t PREPARE_TERMINATE_TIMEOUT_MULTIPLE = 10; +const int32_t BOOTEVENT_COMPLETED_DELAY_TIME = 1000; const std::string BUNDLE_NAME_KEY = "bundleName"; const std::string DM_PKG_NAME = "ohos.distributedhardware.devicemanager"; const std::string ACTION_CHOOSE = "ohos.want.action.select"; @@ -417,9 +418,12 @@ bool AbilityManagerService::Init() }; taskHandler_->SubmitTask(initExtensionConfigTask, "InitExtensionConfigTask"); - auto bootCompletedTask = []() { + auto bootCompletedTask = [handler = taskHandler_]() { if (ApplicationUtil::IsBootCompleted()) { - ApplicationUtil::AppFwkBootEventCallback(BOOTEVENT_BOOT_COMPLETED.c_str(), "true", nullptr); + auto task = []() { + ApplicationUtil::AppFwkBootEventCallback(BOOTEVENT_BOOT_COMPLETED.c_str(), "true", nullptr); + }; + handler->SubmitTask(task, "BootCompletedDelayTask", BOOTEVENT_COMPLETED_DELAY_TIME); } else { WatchParameter(BOOTEVENT_BOOT_COMPLETED.c_str(), ApplicationUtil::AppFwkBootEventCallback, nullptr); } @@ -5304,11 +5308,11 @@ int AbilityManagerService::KillProcess(const std::string &bundleName) return ERR_OK; } -int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) +int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName, const int32_t userId) { HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str()); CHECK_CALLER_IS_SYSTEM_APP; - int ret = DelayedSingleton::GetInstance()->ClearUpApplicationData(bundleName); + int ret = DelayedSingleton::GetInstance()->ClearUpApplicationData(bundleName, userId); if (ret != ERR_OK) { return CLEAR_APPLICATION_DATA_FAIL; } diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 5b28c751bc..2c17fc539f 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -653,7 +653,8 @@ int AbilityManagerStub::KillProcessInner(MessageParcel &data, MessageParcel &rep int AbilityManagerStub::ClearUpApplicationDataInner(MessageParcel &data, MessageParcel &reply) { std::string bundleName = Str16ToStr8(data.ReadString16()); - int result = ClearUpApplicationData(bundleName); + int32_t userId = data.ReadInt32(); + int result = ClearUpApplicationData(bundleName, userId); if (!reply.WriteInt32(result)) { HILOG_ERROR("ClearUpApplicationData error"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 14be7054d5..2323270949 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -242,10 +242,10 @@ int AppScheduler::KillApplicationByUid(const std::string &bundleName, int32_t ui return ERR_OK; } -int AppScheduler::ClearUpApplicationData(const std::string &bundleName) +int AppScheduler::ClearUpApplicationData(const std::string &bundleName, const int32_t userId) { CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); - int ret = (int)appMgrClient_->ClearUpApplicationData(bundleName); + int ret = (int)appMgrClient_->ClearUpApplicationData(bundleName, userId); if (ret != ERR_OK) { HILOG_ERROR("Fail to clear application data."); return INNER_ERR; diff --git a/services/abilitymgr/src/extension_record.cpp b/services/abilitymgr/src/extension_record.cpp new file mode 100644 index 0000000000..1eb2f682f0 --- /dev/null +++ b/services/abilitymgr/src/extension_record.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 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 "extension_record.h" +#include "ability_util.h" +#include "errors.h" + +namespace OHOS { +namespace AbilityRuntime { +ExtensionRecord::ExtensionRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, int32_t extensionRecordId) + : abilityRecord_(abilityRecord), hostBundleName_(hostBundleName), extensionRecordId_(extensionRecordId) +{} + +ExtensionRecord::~ExtensionRecord() = default; + +sptr ExtensionRecord::GetCallToken() const +{ + CHECK_POINTER_AND_RETURN(abilityRecord_, nullptr); + auto sessionInfo = abilityRecord_->GetSessionInfo(); + CHECK_POINTER_AND_RETURN(sessionInfo, nullptr); + return sessionInfo->callerToken; +} + +sptr ExtensionRecord::GetRootCallerToken() const +{ + return rootCallerToken_; +} + +void ExtensionRecord::SetRootCallerToken(sptr &rootCallerToken) +{ + rootCallerToken_ = rootCallerToken; +} + +bool ExtensionRecord::ContinueToGetCallerToken() +{ + return false; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/services/abilitymgr/src/extension_record_manager.cpp b/services/abilitymgr/src/extension_record_manager.cpp new file mode 100644 index 0000000000..5d9e912660 --- /dev/null +++ b/services/abilitymgr/src/extension_record_manager.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2023 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 "extension_record_manager.h" + +#include "ability_util.h" +#include "hilog_wrapper.h" +#include "ui_extension_utils.h" +#include "ui_extension_record.h" + +namespace OHOS { +namespace AbilityRuntime { +std::atomic_int32_t ExtensionRecordManager::extensionRecordId_ = INVALID_EXTENSION_RECORD_ID; + +ExtensionRecordManager::ExtensionRecordManager(const int32_t userId) : userId_(userId) +{ + HILOG_DEBUG("constructor."); +} + +ExtensionRecordManager::~ExtensionRecordManager() +{ + HILOG_INFO("deconstructor."); +} + +int32_t ExtensionRecordManager::GenerateExtensionRecordId(const int32_t extensionRecordId) +{ + HILOG_DEBUG("Input id is %{public}d.", extensionRecordId); + std::lock_guard lock(mutex_); + if (extensionRecordId != INVALID_EXTENSION_RECORD_ID && + !extensionRecordIdSet_.count(extensionRecordId)) { + extensionRecordIdSet_.insert(extensionRecordId); + extensionRecordId_ = extensionRecordId; + return extensionRecordId_; + } + + if (extensionRecordId == INVALID_EXTENSION_RECORD_ID) { + ++extensionRecordId_; + } + + while (extensionRecordIdSet_.count(extensionRecordId_)) { + extensionRecordId_++; + } + + return extensionRecordId_; +} + +void ExtensionRecordManager::AddExtensionRecord(const int32_t extensionRecordId, + const std::shared_ptr &record) +{ + HILOG_DEBUG("extensionRecordId %{public}d.", extensionRecordId); + std::lock_guard lock(mutex_); + extensionRecords_.emplace(extensionRecordId, record); +} + +void ExtensionRecordManager::RemoveExtensionRecord(const int32_t extensionRecordId) +{ + HILOG_DEBUG("extensionRecordId %{public}d.", extensionRecordId); + std::lock_guard lock(mutex_); + extensionRecords_.erase(extensionRecordId); +} + +bool ExtensionRecordManager::CheckExtensionLoaded(const int32_t extensionRecordId, + const std::string &hostBundleName) +{ + HILOG_DEBUG("extensionRecordId %{public}d.", extensionRecordId); + std::lock_guard lock(mutex_); + // find target record firstly + auto it = extensionRecords_.find(extensionRecordId); + if (it != extensionRecords_.end() && it->second != nullptr) { + // check bundleName + HILOG_DEBUG("Stored host bundleName: %{public}s, input bundleName is %{public}s.", + it->second->hostBundleName_.c_str(), hostBundleName.c_str()); + if (it->second->hostBundleName_ == hostBundleName) { + return true; + } + } + HILOG_DEBUG("Not found stored id %{public}d.", extensionRecordId); + return false; +} + +bool ExtensionRecordManager::IsBelongToManager(const AppExecFwk::AbilityInfo &abilityInfo) +{ + // only support UIExtension now + return AAFwk::UIExtensionUtils::IsUIExtension(abilityInfo.extensionAbilityType); +} + +bool ExtensionRecordManager::IsFocused(int32_t extensionRecordId, const sptr& focusToken) +{ + std::lock_guard lock(mutex_); + sptr rootCallerToken = GetRootCallerTokenLocked(extensionRecordId); + bool isFocused = rootCallerToken == focusToken; + HILOG_DEBUG("id: %{public}d isFocused: %{public}d.", extensionRecordId, isFocused); + return isFocused; +} + +sptr ExtensionRecordManager::GetRootCallerTokenLocked(int32_t extensionRecordId) +{ + auto it = extensionRecords_.find(extensionRecordId); + if (it != extensionRecords_.end() && it->second != nullptr) { + sptr rootCallerToken = it->second->GetRootCallerToken(); + if (rootCallerToken != nullptr) { + return rootCallerToken; + } + if (!it->second->ContinueToGetCallerToken()) { + return it->second->GetCallToken(); + } + auto callerToken = it->second->GetCallToken(); + if (callerToken == nullptr) { + HILOG_ERROR("callerToken is null, id: %{public}d.", extensionRecordId); + return nullptr; + } + auto callerAbilityRecord = AAFwk::Token::GetAbilityRecordByToken(callerToken); + if (callerAbilityRecord == nullptr) { + HILOG_ERROR("callerAbilityRecord is null, id: %{public}d.", extensionRecordId); + return nullptr; + } + if (callerAbilityRecord->GetUIExtensionAbilityId() == INVALID_EXTENSION_RECORD_ID) { + HILOG_DEBUG("update rootCallerToken, id: %{public}d.", extensionRecordId); + it->second->SetRootCallerToken(callerToken); + return callerToken; + } + rootCallerToken = GetRootCallerTokenLocked(callerAbilityRecord->GetUIExtensionAbilityId()); + HILOG_DEBUG("update rootCallerToken, id: %{public}d.", extensionRecordId); + it->second->SetRootCallerToken(rootCallerToken); + return rootCallerToken; + } + HILOG_ERROR("Not found id %{public}d.", extensionRecordId); + return nullptr; +} + +int32_t ExtensionRecordManager::CreateExtensionRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, int32_t &extensionRecordId) +{ + // factory pattern with ability request + if (abilityRecord == nullptr) { + HILOG_ERROR("abilityRecord is null"); + return ERR_NULL_OBJECT; + } + extensionRecordId = GenerateExtensionRecordId(extensionRecordId); + if (AAFwk::UIExtensionUtils::IsUIExtension(abilityRecord->GetAbilityInfo().extensionAbilityType)) { + std::shared_ptr extensionRecord = std::make_shared(abilityRecord, + hostBundleName, extensionRecordId); + std::lock_guard lock(mutex_); + HILOG_DEBUG("add UIExtension, id %{public}d.", extensionRecordId); + extensionRecords_[extensionRecordId] = extensionRecord; + abilityRecord->SetUIExtensionAbilityId(extensionRecordId); + return ERR_OK; + } + return ERR_INVALID_VALUE; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index 262c38f186..45fab311c8 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -18,6 +18,7 @@ #include "ability_manager_service.h" #include "ability_util.h" +#include "app_gallery_enable_util.h" #include "default_app_interface.h" #include "errors.h" #include "event_report.h" @@ -116,7 +117,7 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ HILOG_INFO("hint dialog doesn't generate."); return ERR_IMPLICIT_START_ABILITY_FAIL; } - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + if (AppGalleryEnableUtil::IsEnableAppGallerySelector() && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { want = sysDialogScheduler->GetSelectorDialogWant(dialogAppInfos, request.want, request.callerToken); return NotifyCreateModalDialog(request, want, userId, dialogAppInfos); } @@ -125,7 +126,7 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ abilityMgr->StartAbility(want); return ERR_IMPLICIT_START_ABILITY_FAIL; } else if (dialogAppInfos.size() == 0 && deviceType != STR_PHONE && deviceType != STR_DEFAULT) { - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + if (AppGalleryEnableUtil::IsEnableAppGallerySelector() && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { std::string type = MatchTypeAndUri(request.want); want = sysDialogScheduler->GetPcSelectorDialogWant(dialogAppInfos, request.want, type, userId, request.callerToken); @@ -167,7 +168,7 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ if (deviceType == STR_PHONE || deviceType == STR_DEFAULT) { HILOG_INFO("ImplicitQueryInfos success, Multiple apps to choose."); want = sysDialogScheduler->GetSelectorDialogWant(dialogAppInfos, request.want, request.callerToken); - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + if (AppGalleryEnableUtil::IsEnableAppGallerySelector() && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { return NotifyCreateModalDialog(request, want, userId, dialogAppInfos); } ret = abilityMgr->StartAbilityAsCaller(want, request.callerToken, nullptr); @@ -183,7 +184,7 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ std::string type = MatchTypeAndUri(request.want); want = sysDialogScheduler->GetPcSelectorDialogWant(dialogAppInfos, request.want, type, userId, request.callerToken); - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + if (AppGalleryEnableUtil::IsEnableAppGallerySelector() && Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { return NotifyCreateModalDialog(request, want, userId, dialogAppInfos); } ret = abilityMgr->StartAbilityAsCaller(want, request.callerToken, nullptr); diff --git a/services/abilitymgr/src/ui_extension_ability_connect_manager.cpp b/services/abilitymgr/src/ui_extension_ability_connect_manager.cpp deleted file mode 100644 index 57b2d6f25c..0000000000 --- a/services/abilitymgr/src/ui_extension_ability_connect_manager.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2023 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 "ui_extension_ability_connect_manager.h" - -#include "hilog_wrapper.h" - -namespace OHOS { -namespace AbilityRuntime { -std::atomic_int32_t UIExtensionAbilityConnectManager::uiExtensionAbilityId_ = INVALID_UI_EXTENSION_ABILITY_ID; - -UIExtensionAbilityConnectManager::UIExtensionAbilityConnectManager(const int userId) : userId_(userId) -{ - HILOG_DEBUG("constructor."); -} - -UIExtensionAbilityConnectManager::~UIExtensionAbilityConnectManager() -{ - HILOG_INFO("deconstructor."); -} - -int32_t UIExtensionAbilityConnectManager::GenerateUIExtensionAbilityId(const int32_t uiExtensionAbilityId) -{ - HILOG_DEBUG("Input id is %{public}d.", uiExtensionAbilityId); - std::lock_guard lock(mutex_); - if (uiExtensionAbilityId != INVALID_UI_EXTENSION_ABILITY_ID && - !uiExtensionAbilityIdSet_.count(uiExtensionAbilityId)) { - uiExtensionAbilityIdSet_.insert(uiExtensionAbilityId); - uiExtensionAbilityId_ = uiExtensionAbilityId; - return uiExtensionAbilityId_; - } - - if (uiExtensionAbilityId == INVALID_UI_EXTENSION_ABILITY_ID) { - ++uiExtensionAbilityId_; - } - - while (uiExtensionAbilityIdSet_.count(uiExtensionAbilityId_)) { - uiExtensionAbilityId_++; - } - - return uiExtensionAbilityId_; -} - -void UIExtensionAbilityConnectManager::AddUIExtensionAbilityRecord(const int32_t uiExtensionAbilityId, - const std::shared_ptr record) -{ - HILOG_DEBUG("UIExtensionAbilityId %{public}d.", uiExtensionAbilityId); - std::lock_guard lock(mutex_); - uiExtensionAbilityRecords_.emplace(uiExtensionAbilityId, record); -} - -void UIExtensionAbilityConnectManager::RemoveUIExtensionAbilityRecord(const int32_t uiExtensionAbilityId) -{ - HILOG_DEBUG("UIExtensionAbilityId %{public}d.", uiExtensionAbilityId); - std::lock_guard lock(mutex_); - uiExtensionAbilityRecords_.erase(uiExtensionAbilityId); -} - -bool UIExtensionAbilityConnectManager::CheckUIExtensionAbilityLoaded(const int32_t uiExtensionAbilityId, - const std::string hostBundleName) -{ - HILOG_DEBUG("UIExtensionAbilityId %{public}d.", uiExtensionAbilityId); - std::lock_guard lock(mutex_); - // find target record firstly - auto it = uiExtensionAbilityRecords_.find(uiExtensionAbilityId); - if (it != uiExtensionAbilityRecords_.end() && it->second != nullptr) { - // check bundlename - HILOG_DEBUG("Stored host bundleName: %{public}s, input bundleName is %{public}s.", - it->second->hostBundleName_.c_str(), hostBundleName.c_str()); - if (it->second->hostBundleName_ == hostBundleName) { - return true; - } - } - HILOG_DEBUG("Not found stored id %{public}d.", uiExtensionAbilityId); - return false; -} -} // namespace AbilityRuntime -} // namespace OHOS diff --git a/services/abilitymgr/src/ui_extension_record.cpp b/services/abilitymgr/src/ui_extension_record.cpp new file mode 100644 index 0000000000..6a577f8eec --- /dev/null +++ b/services/abilitymgr/src/ui_extension_record.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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 "ui_extension_record.h" +#include "ability_util.h" + +namespace OHOS { +namespace AbilityRuntime { +UIExtensionRecord::UIExtensionRecord(const std::shared_ptr &abilityRecord, + const std::string &hostBundleName, int32_t extensionRecordId) + : ExtensionRecord(abilityRecord, hostBundleName, extensionRecordId) +{} + +UIExtensionRecord::~UIExtensionRecord() = default; + +bool UIExtensionRecord::ContinueToGetCallerToken() +{ + return true; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index e5579e3cd7..1434e2986b 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -317,7 +317,8 @@ std::string AppfreezeManager::CatcherStacktrace(int pid) const HiviewDFX::DfxDumpCatcher dumplog; std::string ret; std::string msg; - if (!dumplog.DumpCatch(pid, 0, msg)) { + size_t defaultMaxFaultNum = 256; + if (!dumplog.DumpCatch(pid, 0, msg, defaultMaxFaultNum, true)) { ret = "Failed to dump stacktrace for " + std::to_string(pid) + "\n" + msg; } else { ret = msg; diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 98b4708c88..2028fbe6ca 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -113,7 +113,8 @@ public: * @param bundleName, bundle name in Application record. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t ClearUpApplicationData(const std::string &bundleName) override; + virtual int32_t ClearUpApplicationData(const std::string &bundleName, + const int32_t userId = -1) override; /** * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index c88d837a46..1513a8e521 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -261,7 +261,8 @@ public: * * @return */ - virtual void ClearUpApplicationData(const std::string &bundleName, const int32_t callerUid, const pid_t callerPid); + virtual void ClearUpApplicationData(const std::string &bundleName, + const int32_t callerUid, const pid_t callerPid, const int32_t userId = -1); /** * GetAllRunningProcesses, Obtains information about application processes that are running on the device. diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 9fb7503225..bf67aec104 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -295,7 +295,7 @@ sptr AppMgrService::GetAmsMgr() return amsMgrScheduler_; } -int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName) +int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName, const int32_t userId) { std::shared_ptr remoteClientManager = std::make_shared(); if(remoteClientManager == nullptr) { @@ -308,19 +308,21 @@ int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName) return ERR_INVALID_OPERATION; } int32_t callingUid = IPCSkeleton::GetCallingUid(); - std::string callerBundleName; - auto result = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callingUid, callerBundleName)); - if (result != ERR_OK) { - HILOG_ERROR("GetBundleName failed: %{public}d", result); - return ERR_INVALID_OPERATION; - } - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall && bundleName != callerBundleName) { - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_CLEAN_APPLICATION_DATA); - if (!isCallingPerm) { - HILOG_ERROR("Permission verification failed."); - return ERR_PERMISSION_DENIED; + if (callingUid != 0 || userId < 0) { + std::string callerBundleName; + auto result = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callingUid, callerBundleName)); + if (result != ERR_OK) { + HILOG_ERROR("GetBundleName failed: %{public}d.", result); + return ERR_INVALID_OPERATION; + } + auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + if (!isSaCall && bundleName != callerBundleName) { + auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( + AAFwk::PermissionConstants::PERMISSION_CLEAN_APPLICATION_DATA); + if (!isCallingPerm) { + HILOG_ERROR("Permission verification failed"); + return ERR_PERMISSION_DENIED; + } } } @@ -330,7 +332,7 @@ int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName) int32_t uid = IPCSkeleton::GetCallingUid(); pid_t pid = IPCSkeleton::GetCallingPid(); std::function clearUpApplicationDataFunc = - std::bind(&AppMgrServiceInner::ClearUpApplicationData, appMgrServiceInner_, bundleName, uid, pid); + std::bind(&AppMgrServiceInner::ClearUpApplicationData, appMgrServiceInner_, bundleName, uid, pid, userId); taskHandler_->SubmitTask(clearUpApplicationDataFunc, TASK_CLEAR_UP_APPLICATION_DATA); return ERR_OK; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 2a68563ec9..74405a6a49 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -170,6 +170,8 @@ constexpr int32_t BLUETOOTH_GROUPID = 1002; constexpr int32_t NETSYS_SOCKET_GROUPID = 1097; #endif +constexpr int32_t DEFAULT_INVAL_VALUE = -1; + int32_t GetUserIdByUid(int32_t uid) { return uid / BASE_USER_RANGE; @@ -1037,12 +1039,16 @@ int32_t AppMgrServiceInner::KillApplicationByUserIdLocked(const std::string &bun return result; } -void AppMgrServiceInner::ClearUpApplicationData(const std::string &bundleName, int32_t callerUid, pid_t callerPid) +void AppMgrServiceInner::ClearUpApplicationData(const std::string &bundleName, + int32_t callerUid, pid_t callerPid, const int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - auto userId = GetUserIdByUid(callerUid); + int32_t newUserId = userId; + if (userId == DEFAULT_INVAL_VALUE) { + newUserId = GetUserIdByUid(callerUid); + } HILOG_INFO("userId:%{public}d", userId); - ClearUpApplicationDataByUserId(bundleName, callerUid, callerPid, userId); + ClearUpApplicationDataByUserId(bundleName, callerUid, callerPid, newUserId); } void AppMgrServiceInner::ClearUpApplicationDataByUserId( @@ -1052,7 +1058,7 @@ void AppMgrServiceInner::ClearUpApplicationDataByUserId( HILOG_ERROR("invalid callerPid:%{public}d", callerPid); return; } - if (callerUid <= 0) { + if (callerUid < 0) { HILOG_ERROR("invalid callerUid:%{public}d", callerUid); return; } @@ -4318,7 +4324,7 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData) .bundleName = bundleName, .processName = bundleName, }; - AppExecFwk::AppfreezeManager::GetInstance()->AppfreezeHandle(faultData, info); + AppExecFwk::AppfreezeManager::GetInstance()->AppfreezeHandleWithStack(faultData, info); } HILOG_WARN("FaultData is: name: %{public}s, faultType: %{public}d, uid: %{public}d, pid: %{public}d," diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index 874c58a6f5..f215a85cb4 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -188,7 +188,7 @@ public: return 0; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index c971985572..112b6593bc 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -177,7 +177,7 @@ public: int UninstallApp(const std::string& bundleName, int32_t uid) override; - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index 87e8e6a959..5a19f08f88 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -116,7 +116,7 @@ public: MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions& startOptions)); MOCK_METHOD2(MoveMissionsToForeground, int(const std::vector& missionIds, int32_t topMissionId)); MOCK_METHOD2(MoveMissionsToBackground, int(const std::vector& missionIds, std::vector& result)); - MOCK_METHOD1(ClearUpApplicationData, int(const std::string&)); + MOCK_METHOD2(ClearUpApplicationData, int(const std::string&, int32_t userId)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); @@ -296,7 +296,7 @@ public: MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions& startOptions)); MOCK_METHOD2(MoveMissionsToForeground, int(const std::vector& missionIds, int32_t topMissionId)); MOCK_METHOD2(MoveMissionsToBackground, int(const std::vector& missionIds, std::vector& result)); - MOCK_METHOD1(ClearUpApplicationData, int(const std::string&)); + MOCK_METHOD2(ClearUpApplicationData, int(const std::string&, int32_t userId)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index 47e2800c16..cfd2d3ac95 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -169,7 +169,7 @@ public: MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 1ee76a9a0b..79e74a926f 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -183,7 +183,7 @@ public: return 0; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp index cd697a1ec0..cebc60a7e2 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp @@ -81,7 +81,7 @@ AppMgrResultCode AppMgrClient::KillApplication(const std::string& bundleName) return AppMgrResultCode::RESULT_OK; } -AppMgrResultCode AppMgrClient::ClearUpApplicationData(const std::string& bundleName) +AppMgrResultCode AppMgrClient::ClearUpApplicationData(const std::string& bundleName, const int32_t userId) { return AppMgrResultCode::RESULT_OK; } diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index 8f45ff76c6..9878190306 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -130,7 +130,7 @@ void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData& appData) HILOG_INFO("Test AppScheduler::OnAppStateChanged()"); } -int AppScheduler::ClearUpApplicationData(const std::string& bundleName) +int AppScheduler::ClearUpApplicationData(const std::string& bundleName, const int32_t userId) { HILOG_INFO("Test AppScheduler::ClearUpApplicationData()"); return ERR_OK; diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index b7b4b5e7fb..0073a33979 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -49,7 +49,7 @@ public: MOCK_METHOD0(GetAmsMgr, sptr()); MOCK_METHOD1(GetAppFreezingTime, void(int& time)); MOCK_METHOD1(SetAppFreezingTime, void(int time)); - MOCK_METHOD1(ClearUpApplicationData, int32_t(const std::string& bundleName)); + MOCK_METHOD2(ClearUpApplicationData, int32_t(const std::string& bundleName, int32_t userId)); MOCK_METHOD1(StartupResidentProcess, void(const std::vector& bundleInfos)); MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId)); MOCK_METHOD0(PreStartNWebSpawnProcess, int()); diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h index a65e20ac38..c37377c41e 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h @@ -44,7 +44,7 @@ public: MOCK_METHOD1(KillApplication, int32_t(const std::string& bundleName)); MOCK_METHOD2(KillApplicationByUid, int(const std::string&, const int uid)); MOCK_METHOD1(AbilityTerminated, void(const sptr& token)); - MOCK_METHOD3(ClearUpApplicationData, void(const std::string&, const int32_t, const pid_t)); + MOCK_METHOD4(ClearUpApplicationData, void(const std::string&, const int32_t, const pid_t, int32_t userId)); MOCK_METHOD1(IsBackgroundRunningRestricted, int32_t(const std::string&)); MOCK_METHOD1(GetAllRunningProcesses, int32_t(std::vector&)); MOCK_METHOD1(GetAllRenderProcesses, int32_t(std::vector&)); diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp b/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp index 923d4d4df6..1b7783660c 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp @@ -75,7 +75,7 @@ protected: class MockMockAppMgrService : public MockAppMgrService { public: MOCK_METHOD0(GetAmsMgr, sptr()); - MOCK_METHOD1(ClearUpApplicationData, int32_t(const std::string&)); + MOCK_METHOD2(ClearUpApplicationData, int32_t(const std::string&, int32_t userId)); MOCK_METHOD1(IsBackgroundRunningRestricted, int(const std::string& appName)); MOCK_METHOD1(GetAllRunningProcesses, int(std::vector&)); }; diff --git a/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp b/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp index 93e15bc5bf..e72cb13c49 100644 --- a/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp +++ b/test/moduletest/common/ams/ipc_app_mgr_test/ams_ipc_app_mgr_module_test.cpp @@ -58,7 +58,7 @@ void AmsIpcAppmgrModuleTest::TearDown() class MockMockAppMgrService : public MockAppMgrService { public: MOCK_METHOD0(GetAmsMgr, sptr()); - MOCK_METHOD1(ClearUpApplicationData, int32_t(const std::string&)); + MOCK_METHOD2(ClearUpApplicationData, int32_t(const std::string&, int32_t userId)); MOCK_METHOD1(IsBackgroundRunningRestricted, int(const std::string& bundleName)); MOCK_METHOD1(GetAllRunningProcesses, int(std::vector&)); }; @@ -216,13 +216,13 @@ HWTEST_F(AmsIpcAppmgrModuleTest, ExcuteAppmgrIPCInterface_007, TestSize.Level3) std::string testBundleName("testApp"); bool testResult = false; - auto mockHandler = [&](const std::string& name) { + auto mockHandler = [&](const std::string& name, const int32_t userId) { testResult = (name == testBundleName); mockMockAppMgr->Post(); return 0; }; - EXPECT_CALL(*mockMockAppMgr, ClearUpApplicationData(_)).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockMockAppMgr, ClearUpApplicationData(_, _)).WillOnce(Invoke(mockHandler)); appMgrClient->ClearUpApplicationData(testBundleName); mockMockAppMgr->Wait(); diff --git a/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h b/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h index f8c9160ee7..78764beb1a 100644 --- a/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h +++ b/test/moduletest/mock/include/appmgr/mock_ability_mgr_host.h @@ -213,7 +213,7 @@ public: { return 0; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index 88a6c58da0..493f9a1793 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -106,7 +106,7 @@ public: MOCK_METHOD2(SetMissionLabel, int(const sptr& token, const std::string& label)); MOCK_METHOD2(SetMissionIcon, int(const sptr& token, const std::shared_ptr& icon)); - MOCK_METHOD1(ClearUpApplicationData, int(const std::string&)); + MOCK_METHOD2(ClearUpApplicationData, int(const std::string&, int32_t userId)); MOCK_METHOD2(GetWantSenderInfo, int(const sptr& target, std::shared_ptr& info)); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 35f6c2ffe3..4705b4d954 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -139,6 +139,8 @@ ohos_source_set("abilityms_test_source") { "${ability_runtime_services_path}/abilitymgr/src/data_ability_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/dialog_session_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/dlp_state_item.cpp", + "${ability_runtime_services_path}/abilitymgr/src/extension_record.cpp", + "${ability_runtime_services_path}/abilitymgr/src/extension_record_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/free_install_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent_profile.cpp", @@ -154,6 +156,7 @@ ohos_source_set("abilityms_test_source") { "${ability_runtime_services_path}/abilitymgr/src/start_ability_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/start_ability_handler/start_ability_sandbox_savefile.cpp", "${ability_runtime_services_path}/abilitymgr/src/task_data_persistence_mgr.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ui_extension_record.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_controller.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_event_handler.cpp", "${ability_runtime_services_path}/abilitymgr/src/want_receiver_proxy.cpp", diff --git a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp index e096e98aee..6bfb8cd530 100644 --- a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp +++ b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp @@ -3082,14 +3082,71 @@ HWTEST_F(AbilityConnectManagerTest, IsUIExtensionFocused_001, TestSize.Level1) bool isFocused = connectManager->IsUIExtensionFocused( serviceRecord_->GetApplicationInfo().accessTokenId, serviceRecord1_->GetToken()); EXPECT_EQ(isFocused, false); + connectManager.reset(); +} - sptr sessionInfo = new (std::nothrow) SessionInfo(); - sessionInfo->callerToken = serviceRecord1_->GetToken(); +/* + * Feature: AbilityConnectManager + * Function: IsUIExtensionFocused + * SubFunction: IsUIExtensionFocused + * FunctionPoints: NA + * EnvConditions: NA + * CaseDescription: Verify AbilityConnectManager IsUIExtensionFocused + */ +HWTEST_F(AbilityConnectManagerTest, IsUIExtensionFocused_002, TestSize.Level1) +{ + std::shared_ptr connectManager = std::make_shared(3); + ASSERT_NE(connectManager, nullptr); + connectManager->uiExtensionMap_.clear(); + + std::string device = "device"; + std::string abilityName = "uiExtensionUserAbility"; + std::string appName = "uiExtensionUser"; + std::string bundleName = "com.ix.uiExtensionUser"; + std::string moduleName = "entry"; + auto request = GenerateAbilityRequest(device, abilityName, appName, bundleName, moduleName); + auto uiExtensionUser = AbilityRecord::CreateAbilityRecord(request); + EXPECT_NE(uiExtensionUser, nullptr); + + std::string abilityName1 = "uiExtensionAbility1"; + std::string appName1 = "uiExtensionProvider1"; + std::string bundleName1 = "com.ix.uiExtensionProvider1"; + std::string moduleName1 = "entry"; + auto request1 = GenerateAbilityRequest(device, abilityName1, appName1, bundleName1, moduleName1); + auto uiExtension1 = AbilityRecord::CreateAbilityRecord(request1); + EXPECT_NE(uiExtension1, nullptr); + uiExtension1->abilityInfo_.extensionAbilityType = ExtensionAbilityType::SYS_COMMON_UI; + sptr sessionInfo1 = new (std::nothrow) SessionInfo(); + sessionInfo1->callerToken = uiExtensionUser->GetToken(); + uiExtension1->sessionInfo_ = sessionInfo1; connectManager->uiExtensionMap_.emplace( - callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(serviceRecord_, sessionInfo)); - isFocused = connectManager->IsUIExtensionFocused( - serviceRecord_->GetApplicationInfo().accessTokenId, serviceRecord1_->GetToken()); - EXPECT_EQ(isFocused, true); + callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(uiExtension1, sessionInfo1)); + int32_t extensionId1 = 1; + int32_t ret = connectManager->uiExtensionAbilityRecordMgr_->CreateExtensionRecord(uiExtension1, "", extensionId1); + EXPECT_EQ(ret, ERR_OK); + bool isFocused1 = connectManager->IsUIExtensionFocused( + uiExtension1->GetApplicationInfo().accessTokenId, uiExtensionUser->GetToken()); + EXPECT_EQ(isFocused1, true); + + std::string abilityName2 = "uiExtensionAbility2"; + std::string appName2 = "uiExtensionProvider2"; + std::string bundleName2 = "com.ix.uiExtensionProvider2"; + std::string moduleName2 = "entry"; + auto request2 = GenerateAbilityRequest(device, abilityName2, appName2, bundleName2, moduleName2); + auto uiExtension2 = AbilityRecord::CreateAbilityRecord(request2); + EXPECT_NE(uiExtension2, nullptr); + uiExtension2->abilityInfo_.extensionAbilityType = ExtensionAbilityType::SYS_COMMON_UI; + sptr sessionInfo2 = new (std::nothrow) SessionInfo(); + sessionInfo2->callerToken = uiExtension1->GetToken(); + uiExtension2->sessionInfo_ = sessionInfo2; + connectManager->uiExtensionMap_.emplace( + callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(uiExtension2, sessionInfo2)); + int32_t extensionId2 = 2; + ret = connectManager->uiExtensionAbilityRecordMgr_->CreateExtensionRecord(uiExtension2, "", extensionId2); + EXPECT_EQ(ret, ERR_OK); + bool isFocused2 = connectManager->IsUIExtensionFocused( + uiExtension2->GetApplicationInfo().accessTokenId, uiExtensionUser->GetToken()); + EXPECT_EQ(isFocused2, true); connectManager.reset(); } diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 203b60eb6d..0ff9d8a2b3 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -220,7 +220,7 @@ public: return; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 57f41e1621..21c1c5e832 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -221,7 +221,7 @@ public: return; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 67a3431729..5bce2f4ff1 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -231,7 +231,7 @@ public: return 0; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 39e23c43cb..19ed6df1ba 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -209,7 +209,7 @@ public: return; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp b/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp index bf87b7b08f..78415283fa 100644 --- a/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp +++ b/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp @@ -424,7 +424,7 @@ HWTEST_F(AmsAppMgrClientTest, AppMgrClient_014, TestSize.Level1) sptr token; EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService()); EXPECT_CALL(*(static_cast((iface_cast(client_->GetRemoteObject())).GetRefPtr())), - ClearUpApplicationData(_)) + ClearUpApplicationData(_, _)) .Times(1) .WillOnce(Return(ERR_NO_MEMORY)); EXPECT_EQ(AppMgrResultCode::ERROR_SERVICE_NOT_READY, client_->ClearUpApplicationData("com.test")); @@ -444,7 +444,7 @@ HWTEST_F(AmsAppMgrClientTest, AppMgrClient_015, TestSize.Level1) EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ConnectAppMgrService()); sptr appMgr(new MockAppMgrService()); EXPECT_CALL(*(static_cast((iface_cast(client_->GetRemoteObject())).GetRefPtr())), - ClearUpApplicationData(_)) + ClearUpApplicationData(_, _)) .Times(1) .WillOnce(Return(ERR_OK)); EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->ClearUpApplicationData("com.test")); diff --git a/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp b/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp index ed05d9234c..0b55e90805 100644 --- a/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp +++ b/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp @@ -206,7 +206,7 @@ HWTEST_F(AmsIpcAppMgrInterfaceTest, ClearUpApplicationData_008, TestSize.Level1) sptr mockAppMgr(new MockAppMgrService()); sptr appMgrClient = iface_cast(mockAppMgr); - EXPECT_CALL(*mockAppMgr, ClearUpApplicationData(_)).Times(1); + EXPECT_CALL(*mockAppMgr, ClearUpApplicationData(_, _)).Times(1); appMgrClient->ClearUpApplicationData("PROCESS"); diff --git a/test/unittest/app_scheduler_test/app_mgr_client_mock.h b/test/unittest/app_scheduler_test/app_mgr_client_mock.h index f88e740301..89af016380 100755 --- a/test/unittest/app_scheduler_test/app_mgr_client_mock.h +++ b/test/unittest/app_scheduler_test/app_mgr_client_mock.h @@ -38,7 +38,7 @@ public: MOCK_METHOD0(UpdateApplicationInfoInstalledDone, AppMgrResultCode()); MOCK_METHOD1(KillApplication, AppMgrResultCode(const std::string&)); MOCK_METHOD2(KillApplicationByUid, AppMgrResultCode(const std::string &bundleName, const int uid)); - MOCK_METHOD1(ClearUpApplicationData, AppMgrResultCode(const std::string&)); + MOCK_METHOD2(ClearUpApplicationData, AppMgrResultCode(const std::string&, int32_t userId)); MOCK_METHOD1(StartupResidentProcess, void(const std::vector &bundleInfos)); MOCK_METHOD2(StartSpecifiedAbility, void(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo)); MOCK_METHOD1(GetAllRunningProcesses, AppMgrResultCode(std::vector &info)); diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 145abcc266..0d43fdf2c9 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -724,7 +724,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_KillApplicationByUid_002, TestSize.Level */ HWTEST_F(AppSchedulerTest, AppScheduler_ClearUpApplicationData_001, TestSize.Level1) { - EXPECT_CALL(*clientMock_, ClearUpApplicationData(_)).Times(1) + EXPECT_CALL(*clientMock_, ClearUpApplicationData(_, _)).Times(1) .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY)); DelayedSingleton::GetInstance()->appMgrClient_ = std::move(clientMock_); std::string bundleName = "bundleName"; @@ -742,7 +742,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_ClearUpApplicationData_001, TestSize.Lev */ HWTEST_F(AppSchedulerTest, AppScheduler_ClearUpApplicationData_002, TestSize.Level1) { - EXPECT_CALL(*clientMock_, ClearUpApplicationData(_)).Times(1) + EXPECT_CALL(*clientMock_, ClearUpApplicationData(_, _)).Times(1) .WillOnce(Return(AppMgrResultCode::RESULT_OK)); DelayedSingleton::GetInstance()->appMgrClient_ = std::move(clientMock_); std::string bundleName = "bundleName"; diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index 65dca38ea3..b49aa40fba 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -128,7 +128,7 @@ class MockAppMgrStub : public AppMgrStub { return nullptr; } - int32_t ClearUpApplicationData(const std::string &bundleName) override + int32_t ClearUpApplicationData(const std::string &bundleName, const int32_t userId) override { return 0; } diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index fb644baeef..391189b747 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -194,7 +194,7 @@ public: return; } - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index 994a90e51f..453b629f0e 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -154,7 +154,7 @@ public: MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif - int ClearUpApplicationData(const std::string& bundleName) override + int ClearUpApplicationData(const std::string& bundleName, const int32_t userId = DEFAULT_INVAL_VALUE) override { return 0; } diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index e7e1830f08..bb31abe97f 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -115,7 +115,7 @@ public: MOCK_METHOD2(SetMissionLabel, int(const sptr& token, const std::string& label)); MOCK_METHOD2(SetMissionIcon, int(const sptr& token, const std::shared_ptr& icon)); - MOCK_METHOD1(ClearUpApplicationData, int(const std::string&)); + MOCK_METHOD2(ClearUpApplicationData, int(const std::string&, int32_t userId)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info));