diff --git a/frameworks/js/napi/ability/ability.js b/frameworks/js/napi/ability/ability.js index b0db2e1d20..c043d6d578 100644 --- a/frameworks/js/napi/ability/ability.js +++ b/frameworks/js/napi/ability/ability.js @@ -25,7 +25,7 @@ class Ability { onWindowStageDestroy() { } onForeground(want) { } onBackground() { } - onPrepareTerminate() { + onPrepareToTerminate() { return false; } onMemoryLevel(level) { } diff --git a/frameworks/native/ability/native/ability_runtime/js_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ability.cpp index ee16b2d7bf..5bad1c0c4b 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability.cpp @@ -502,7 +502,7 @@ bool JsAbility::OnPrepareTerminate() HILOG_DEBUG("call, ability: %{public}s.", GetAbilityName().c_str()); Ability::OnPrepareTerminate(); - NativeValue *jsValue = CallObjectMethod("onPrepareTerminate", nullptr, 0, true); + NativeValue *jsValue = CallObjectMethod("onPrepareToTerminate", nullptr, 0, true); auto numberValue = ConvertNativeValueTo(jsValue); if (numberValue == nullptr) { HILOG_ERROR("numberValue is nullptr."); diff --git a/frameworks/native/ability/native/ability_thread.cpp b/frameworks/native/ability/native/ability_thread.cpp index 798c83afdc..b2fefe9f5d 100644 --- a/frameworks/native/ability/native/ability_thread.cpp +++ b/frameworks/native/ability/native/ability_thread.cpp @@ -63,6 +63,7 @@ constexpr static char WALLPAPER_EXTENSION[] = "WallpaperExtension"; constexpr static char FILEACCESS_EXT_ABILITY[] = "FileAccessExtension"; constexpr static char ENTERPRISE_ADMIN_EXTENSION[] = "EnterpriseAdminExtension"; constexpr static char INPUTMETHOD_EXTENSION[] = "InputMethodExtensionAbility"; +constexpr static char APP_ACCOUNT_AUTHORIZATION_EXTENSION[] = "AppAccountAuthorizationExtension"; AbilityThread::AbilityThread() : abilityImpl_(nullptr), token_(nullptr), currentAbility_(nullptr), abilityHandler_(nullptr), runner_(nullptr) @@ -167,6 +168,9 @@ std::string AbilityThread::CreateAbilityName(const std::shared_ptrextensionAbilityType == ExtensionAbilityType::UI) { abilityName = UI_EXTENSION; } + if (abilityInfo->extensionAbilityType == ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION) { + abilityName = APP_ACCOUNT_AUTHORIZATION_EXTENSION; + } HILOG_DEBUG("CreateAbilityName extension type, abilityName:%{public}s", abilityName.c_str()); } else { abilityName = abilityInfo->name; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 2afaf92721..628b6aa0ec 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -112,6 +112,51 @@ constexpr uint32_t CHECK_MAIN_THREAD_IS_ALIVE = 1; const std::string OVERLAY_STATE_CHANGED = "usual.event.OVERLAY_STATE_CHANGED"; +std::string GetLibPath(const std::string &hapPath, bool isPreInstallApp) +{ + std::string libPath = LOCAL_CODE_PATH; + if (isPreInstallApp) { + auto pos = hapPath.rfind("/"); + libPath = hapPath.substr(0, pos); + } + return libPath; +} + +bool GetHapSoPath(const HapModuleInfo &hapInfo, AppLibPathMap &appLibPaths, bool isPreInstallApp) +{ + if (hapInfo.compressNativeLibs) { + return false; + } + + if (hapInfo.nativeLibraryPath.empty()) { + return true; + } + + std::string libPath = GetLibPath(hapInfo.hapPath, isPreInstallApp); + libPath += (libPath.back() == '/') ? hapInfo.nativeLibraryPath : "/" + hapInfo.nativeLibraryPath; + HILOG_INFO("module lib path = %{public}s", libPath.c_str()); + appLibPaths["default"].emplace_back(libPath); + return true; +} + +void GetHspNativeLibPath(const BaseSharedBundleInfo &hspInfo, AppLibPathMap &appLibPaths, bool isPreInstallApp) +{ + if (hspInfo.nativeLibraryPath.empty()) { + return; + } + + std::string appLibPathKey = hspInfo.bundleName + "/" + hspInfo.moduleName; + std::string libPath = LOCAL_CODE_PATH; + if (!hspInfo.compressNativeLibs) { + libPath = GetLibPath(hspInfo.hapPath, isPreInstallApp); + appLibPathKey = "default"; + } + libPath = libPath.back() == '/' ? libPath : libPath + "/"; + libPath += hspInfo.bundleName + "/" + hspInfo.nativeLibraryPath; + HILOG_DEBUG("appLibPathKey: %{private}s, libPath: %{private}s", appLibPathKey.c_str(), libPath.c_str()); + appLibPaths[appLibPathKey].emplace_back(libPath); +} + void GetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, AppLibPathMap &appLibPaths) { std::string patchNativeLibraryPath = bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath; @@ -150,13 +195,13 @@ void GetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, AppL HILOG_INFO("name: %{public}s, patch lib path = %{private}s", hapInfo.name.c_str(), patchLibPath.c_str()); appLibPaths[appLibPathKey].emplace_back(patchLibPath); } - - std::string libPath = LOCAL_CODE_PATH; - if (hapInfo.isLibIsolated) { - libPath += (libPath.back() == '/') ? hapInfo.nativeLibraryPath : "/" + hapInfo.nativeLibraryPath; - } else { - libPath += (libPath.back() == '/') ? nativeLibraryPath : "/" + nativeLibraryPath; + if (GetHapSoPath(hapInfo, appLibPaths, bundleInfo.isPreInstallApp)) { + continue; } + + std::string libPath = LOCAL_CODE_PATH; + const auto &tmpNativePath = hapInfo.isLibIsolated ? hapInfo.nativeLibraryPath : nativeLibraryPath; + libPath += (libPath.back() == '/') ? tmpNativePath : "/" + tmpNativePath; HILOG_DEBUG("appLibPathKey: %{private}s, libPath: %{private}s", appLibPathKey.c_str(), libPath.c_str()); appLibPaths[appLibPathKey].emplace_back(libPath); } @@ -164,16 +209,7 @@ void GetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, AppL for (auto &hspInfo : hspList) { HILOG_DEBUG("bundle:%s, module:%s, nativeLibraryPath:%s", hspInfo.bundleName.c_str(), hspInfo.moduleName.c_str(), hspInfo.nativeLibraryPath.c_str()); - if (hspInfo.nativeLibraryPath.empty()) { - continue; - } - - std::string appLibPathKey = hspInfo.bundleName + "/" + hspInfo.moduleName; - std::string libPath = LOCAL_CODE_PATH; - libPath = libPath.back() == '/' ? libPath : libPath + "/"; - libPath += hspInfo.bundleName + "/" + hspInfo.nativeLibraryPath; - HILOG_DEBUG("appLibPathKey: %{private}s, libPath: %{private}s", appLibPathKey.c_str(), libPath.c_str()); - appLibPaths[appLibPathKey].emplace_back(libPath); + GetHspNativeLibPath(hspInfo, appLibPaths, bundleInfo.isPreInstallApp); } } } // namespace @@ -815,9 +851,13 @@ bool MainThread::InitCreate( std::shared_ptr &contextDeal, ApplicationInfo &appInfo, ProcessInfo &processInfo) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + // get application shared point + application_ = std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName()); if (application_ == nullptr) { + HILOG_ERROR("InitCreate application create failed"); return false; } + applicationInfo_ = std::make_shared(appInfo); if (applicationInfo_ == nullptr) { HILOG_ERROR("MainThread::InitCreate create applicationInfo_ failed"); @@ -1054,6 +1094,46 @@ void MainThread::HandleOnOverlayChanged(const EventFwk::CommonEventData &data, return ret; } +bool IsNeedLoadLibrary(const std::string &bundleName) +{ + std::vector needLoadLibraryBundleNames{ + "com.ohos.contactsdataability", + "com.ohos.medialibrary.medialibrarydata", + "com.ohos.telephonydataability", + "com.ohos.FusionSearch", + "com.ohos.formrenderservice" + }; + + for (const auto &item : needLoadLibraryBundleNames) { + if (item == bundleName) { + return true; + } + } + return false; +} + +bool GetBundleForLaunchApplication(sptr bundleMgr, const std::string &bundleName, + int32_t appIndex, BundleInfo &bundleInfo) +{ + bool queryResult; + if (appIndex != 0) { + HILOG_INFO("GetSandboxBundleInfo, bundleName = %{public}s", bundleName.c_str()); + queryResult = (bundleMgr->GetSandboxBundleInfo(bundleName, + appIndex, UNSPECIFIED_USERID, bundleInfo) == 0); + } else { + HILOG_INFO("GetBundleInfo, bundleName = %{public}s", bundleName.c_str()); + queryResult = (bundleMgr->GetBundleInfoForSelf( + (static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)), bundleInfo) == ERR_OK); + } + return queryResult; +} + /** * * @brief Launch the application. @@ -1070,19 +1150,32 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con return; } - std::string contactsDataAbility("com.ohos.contactsdataability"); - std::string mediaDataAbility("com.ohos.medialibrary.medialibrarydata"); - std::string telephonyDataAbility("com.ohos.telephonydataability"); - std::string fusionSearchAbility("com.ohos.FusionSearch"); - std::string formRenderExtensionAbility("com.ohos.formrenderservice"); auto appInfo = appLaunchData.GetApplicationInfo(); + ProcessInfo processInfo = appLaunchData.GetProcessInfo(); + HILOG_DEBUG("MainThread handle launch application, InitCreate Start."); + std::shared_ptr contextDeal; + if (!InitCreate(contextDeal, appInfo, processInfo)) { + HILOG_ERROR("MainThread::handleLaunchApplication InitCreate failed"); + return; + } + sptr bundleMgr = contextDeal->GetBundleManager(); + if (bundleMgr == nullptr) { + HILOG_ERROR("MainThread::handleLaunchApplication GetBundleManager is nullptr"); + return; + } + auto bundleName = appInfo.bundleName; - if (bundleName == contactsDataAbility || bundleName == mediaDataAbility || bundleName == telephonyDataAbility - || bundleName == fusionSearchAbility || bundleName == formRenderExtensionAbility) { + BundleInfo bundleInfo; + if (!GetBundleForLaunchApplication(bundleMgr, bundleName, appLaunchData.GetAppIndex(), bundleInfo)) { + HILOG_ERROR("HandleLaunchApplication GetBundleInfo failed!"); + return; + } + + if (IsNeedLoadLibrary(bundleName)) { std::vector localPaths; ChangeToLocalPath(bundleName, appInfo.moduleSourceDirs, localPaths); LoadAbilityLibrary(localPaths); - LoadNativeLiabrary(appInfo.nativeLibraryPath); + LoadNativeLiabrary(bundleInfo, appInfo.nativeLibraryPath); } if (appInfo.needAppDetail) { HILOG_DEBUG("MainThread::handleLaunchApplication %{public}s need add app detail ability library path", @@ -1090,56 +1183,13 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con LoadAppDetailAbilityLibrary(appInfo.appDetailAbilityLibraryPath); } LoadAppLibrary(); - // get application shared point - application_ = std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName()); - if (application_ == nullptr) { - HILOG_ERROR("HandleLaunchApplication::application launch failed"); - return; - } - ProcessInfo processInfo = appLaunchData.GetProcessInfo(); - - HILOG_DEBUG("MainThread handle launch application, InitCreate Start."); - std::shared_ptr contextDeal = nullptr; - if (!InitCreate(contextDeal, appInfo, processInfo)) { - HILOG_ERROR("MainThread::handleLaunchApplication InitCreate failed"); - return; - } - + applicationForDump_ = application_; mixStackDumper_ = std::make_shared(); if (!mixStackDumper_->IsInstalled()) { mixStackDumper_->InstallDumpHandler(application_, signalHandler_); } - sptr bundleMgr = contextDeal->GetBundleManager(); - if (bundleMgr == nullptr) { - HILOG_ERROR("MainThread::handleLaunchApplication GetBundleManager is nullptr"); - return; - } - - BundleInfo bundleInfo; - bool queryResult; - if (appLaunchData.GetAppIndex() != 0) { - HILOG_INFO("GetSandboxBundleInfo, bundleName = %{public}s", appInfo.bundleName.c_str()); - queryResult = (bundleMgr->GetSandboxBundleInfo(appInfo.bundleName, - appLaunchData.GetAppIndex(), UNSPECIFIED_USERID, bundleInfo) == 0); - } else { - HILOG_INFO("GetBundleInfo, bundleName = %{public}s", appInfo.bundleName.c_str()); - queryResult = (bundleMgr->GetBundleInfoForSelf( - (static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)), bundleInfo) == ERR_OK); - } - - if (!queryResult) { - HILOG_ERROR("HandleLaunchApplication GetBundleInfo failed!"); - return; - } - bool moduelJson = false; bool isStageBased = false; bool findEntryHapModuleInfo = false; @@ -1362,25 +1412,61 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con HILOG_DEBUG("MainThread::handleLaunchApplication called end."); } -void MainThread::LoadNativeLiabrary(std::string &nativeLibraryPath) -{ #ifdef ABILITY_LIBRARY_LOADER - if (nativeLibraryPath.empty()) { - HILOG_WARN("Native library path is empty."); - return; +void MainThread::CalcNativeLiabraryEntries(const BundleInfo &bundleInfo, std::string &nativeLibraryPath) +{ + bool loadSoFromDir = bundleInfo.hapModuleInfos.empty(); + std::vector nativeFileEntries; + for (const auto &item: bundleInfo.hapModuleInfos) { + if (!item.compressNativeLibs) { + HILOG_DEBUG("handle entries for: %{public}s, with path: %{public}s", item.moduleName.c_str(), + item.nativeLibraryPath.c_str()); + if (item.nativeLibraryPath.empty()) { + HILOG_DEBUG("nativeLibraryPath empty: %{public}s", item.moduleName.c_str()); + continue; + } + std::string libPath = GetLibPath(item.hapPath, bundleInfo.isPreInstallApp); + libPath += (libPath.back() == '/') ? item.nativeLibraryPath : "/" + item.nativeLibraryPath; + HILOG_INFO("module lib path: %{public}s", libPath.c_str()); + if (libPath.back() != '/') { + libPath.push_back('/'); + } + for (const auto &entryName : item.nativeLibraryFileNames) { + HILOG_DEBUG("add entry: %{public}s.", entryName.c_str()); + nativeFileEntries.emplace_back(libPath + entryName); + } + } else { + HILOG_DEBUG("compressNativeLibs flag true for: %{public}s.", item.moduleName.c_str()); + loadSoFromDir = true; + } + } + + if (loadSoFromDir) { + if (nativeLibraryPath.empty()) { + HILOG_WARN("Native library path is empty."); + return; + } + + if (nativeLibraryPath.back() == '/') { + nativeLibraryPath.pop_back(); + } + std::string libPath = LOCAL_CODE_PATH; + libPath += (libPath.back() == '/') ? nativeLibraryPath : "/" + nativeLibraryPath; + HILOG_DEBUG("native library path = %{public}s", libPath.c_str()); + + if (!ScanDir(libPath, nativeFileEntries_)) { + HILOG_WARN("%{public}s scanDir %{public}s not exits", __func__, libPath.c_str()); + } } - if (nativeLibraryPath.back() == '/') { - nativeLibraryPath.pop_back(); - } - std::string libPath = LOCAL_CODE_PATH; - libPath += (libPath.back() == '/') ? nativeLibraryPath : "/" + nativeLibraryPath; - HILOG_DEBUG("native library path = %{public}s", libPath.c_str()); - - if (!ScanDir(libPath, nativeFileEntries_)) { - HILOG_WARN("%{public}s scanDir %{public}s not exits", __func__, libPath.c_str()); + if (!nativeFileEntries.empty()) { + nativeFileEntries_.insert(nativeFileEntries_.end(), nativeFileEntries.begin(), nativeFileEntries.end()); } +} +void MainThread::LoadNativeLiabrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath) +{ + CalcNativeLiabraryEntries(bundleInfo, nativeLibraryPath); if (nativeFileEntries_.empty()) { HILOG_WARN("No native library"); return; @@ -1411,8 +1497,8 @@ void MainThread::LoadNativeLiabrary(std::string &nativeLibraryPath) HILOG_DEBUG("%{public}s Success to dlopen %{public}s", __func__, fileEntry.c_str()); handleAbilityLib_.emplace_back(handleAbilityLib); } -#endif } +#endif void MainThread::ChangeToLocalPath(const std::string &bundleName, const std::vector &sourceDirs, std::vector &localPath) 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 b602fe12b0..effcd13bb7 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1005,6 +1005,13 @@ public: const Want &want, const sptr &callerToken); + /** + * Set rootSceneSession by SCB. + * + * @param rootSceneSession Indicates root scene session of SCB. + */ + void SetRootSceneSession(const sptr &rootSceneSession); + private: class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { public: 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 2c6a85c86a..76f61ea0e3 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -48,10 +48,13 @@ #include "uri.h" #ifdef SUPPORT_GRAPHICS #include "window_manager_service_handler.h" -#include "iprepare_terminate_callback_interface.h" #endif namespace OHOS { +namespace Rosen { +class RootSceneSession; +} // namespace Rosen + namespace AAFwk { constexpr const char* ABILITY_MANAGER_SERVICE_NAME = "AbilityManagerService"; const int DEFAULT_INVAL_VALUE = -1; @@ -951,6 +954,13 @@ public: return 0; } + /** + * Set rootSceneSession by SCB. + * + * @param rootSceneSession Indicates root scene session of SCB. + */ + virtual void SetRootSceneSession(const sptr &rootSceneSession) {} + enum { // ipc id 1-1000 for kit // ipc id for terminating ability (1) @@ -1131,7 +1141,10 @@ public: SEND_ABILITY_RESULT_BY_TOKEN, - // prepare terminate ability (64) + // ipc id for set rootSceneSession (64) + SET_ROOTSSCENESESSION, + + // prepare terminate ability (65) PREPARE_TERMINATE_ABILITY, // ipc id 1001-2000 for DMS diff --git a/interfaces/inner_api/ability_manager/include/iprepare_terminate_callback_interface.h b/interfaces/inner_api/ability_manager/include/iprepare_terminate_callback_interface.h index 884bb0a0b0..284bb943d8 100644 --- a/interfaces/inner_api/ability_manager/include/iprepare_terminate_callback_interface.h +++ b/interfaces/inner_api/ability_manager/include/iprepare_terminate_callback_interface.h @@ -26,8 +26,8 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.prepareTerminateCallback"); virtual void DoPrepareTerminate() {}; enum { - // ipc id for DoPrepareTerminate - ON_DO_PREPARE_TERMINATE, + // ipc id for DoPrepareTerminate (1) + ON_DO_PREPARE_TERMINATE = 1, CODE_MAX }; }; diff --git a/interfaces/kits/native/ability/native/ability.h b/interfaces/kits/native/ability/native/ability.h index 52c5d1ca69..b497eb1e74 100644 --- a/interfaces/kits/native/ability/native/ability.h +++ b/interfaces/kits/native/ability/native/ability.h @@ -881,8 +881,7 @@ public: /** * @brief Called when ability prepare terminate. * - * - * @return Return true if ability need stop terminating; return false if ability need be terminated. + * @return Return true if ability need to stop terminating; return false if ability need to terminate. */ virtual bool OnPrepareTerminate(); diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 8109a9a31f..acdc463d6b 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -558,7 +558,8 @@ private: */ void LoadAbilityLibrary(const std::vector &libraryPaths); - void LoadNativeLiabrary(std::string &nativeLibraryPath); + void CalcNativeLiabraryEntries(const BundleInfo &bundleInfo, std::string &nativeLibraryPath); + void LoadNativeLiabrary(const BundleInfo &bundleInfo, std::string &nativeLibraryPath); void LoadAppDetailAbilityLibrary(std::string &nativeLibraryPath); diff --git a/js_environment/frameworks/js_environment/BUILD.gn b/js_environment/frameworks/js_environment/BUILD.gn index 358641b5e2..289d2f4186 100644 --- a/js_environment/frameworks/js_environment/BUILD.gn +++ b/js_environment/frameworks/js_environment/BUILD.gn @@ -48,5 +48,6 @@ ohos_shared_library("js_environment") { ] subsystem_name = "ability" + innerapi_tags = [ "platformsdk_indirect" ] part_name = "ability_runtime" } diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 9968b1788b..96e6e4fea7 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -151,6 +151,7 @@ ohos_shared_library("abilityms") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "window_manager:libwsutils", + "window_manager:scene_session", ] if (background_task_mgr_continuous_task_enable) { @@ -189,6 +190,7 @@ ohos_shared_library("abilityms") { version_script = "libabilityms.map" subsystem_name = "ability" + innerapi_tags = [ "platformsdk_indirect" ] part_name = "ability_runtime" } diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 51c97ff647..8f2d16b0b3 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -778,6 +778,13 @@ public: virtual int32_t ShareDataDone(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam) override; + /** + * Set rootSceneSession by SCB. + * + * @param rootSceneSession Indicates root scene session of SCB. + */ + virtual void SetRootSceneSession(const sptr &rootSceneSession) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 5410b2259d..15aa3e6b51 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1010,6 +1010,13 @@ public: int32_t GetConfiguration(AppExecFwk::Configuration& config); + /** + * Set rootSceneSession by SCB. + * + * @param rootSceneSession Indicates root scene session of SCB. + */ + virtual void SetRootSceneSession(const sptr &rootSceneSession) override; + // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index e5297b15f5..294d377cd1 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -216,6 +216,7 @@ private: int AcquireShareDataInner(MessageParcel &data, MessageParcel &reply); int ShareDataDoneInner(MessageParcel &data, MessageParcel &reply); int GetAbilityTokenByCalleeObjInner(MessageParcel &data, MessageParcel &reply); + int SetRootSceneSessionInner(MessageParcel &data, MessageParcel &reply); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index 0c5157b12a..6dc68b84af 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -19,6 +19,7 @@ #include #include "ability_record.h" +#include "session/host/include/root_scene_session.h" #include "session_info.h" namespace OHOS { @@ -95,6 +96,17 @@ public: * @return Returns ERR_OK on success, others on failure. */ int CloseUIAbility(const std::shared_ptr &abilityRecord); + + /** + * Set rootSceneSession by SCB. + * + * @param rootSceneSession Indicates root scene session of SCB. + */ + inline void SetRootSceneSession(const sptr &rootSceneSession) + { + rootSceneSession_ = rootSceneSession; + } + private: std::shared_ptr GetAbilityRecordByToken(const sptr &token) const; void UpdateAbilityRecordLaunchReason(const AbilityRequest &abilityRequest, @@ -116,6 +128,7 @@ private: mutable std::recursive_mutex sessionLock_; std::map> sessionAbilityMap_; std::list> terminateAbilityList_; + sptr rootSceneSession_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index e5192c943e..0602b68b78 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -24,6 +24,7 @@ #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "iservice_registry.h" +#include "session/host/include/root_scene_session.h" #include "session_info.h" #include "string_ex.h" #include "system_ability_definition.h" @@ -1050,5 +1051,12 @@ ErrCode AbilityManagerClient::ShareDataDone( return abms->ShareDataDone(token, resultCode, uniqueId, wantParam); } +void AbilityManagerClient::SetRootSceneSession(const sptr &rootSceneSession) +{ + HILOG_INFO("call"); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN(abms); + return abms->SetRootSceneSession(rootSceneSession); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index c871f2544c..4af13c9adb 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -24,6 +24,7 @@ #include "ability_scheduler_proxy.h" #include "ability_scheduler_stub.h" #include "ability_util.h" +#include "session/host/include/root_scene_session.h" #include "session_info.h" namespace OHOS { @@ -3943,5 +3944,31 @@ int32_t AbilityManagerProxy::ShareDataDone( HILOG_INFO("AbilityManagerProxy::ShareDataDone end."); return reply.ReadInt32(); } + +void AbilityManagerProxy::SetRootSceneSession(const sptr &rootSceneSession) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("WriteInterfaceToken failed."); + return; + } + if (!data.WriteRemoteObject(rootSceneSession->AsObject())) { + HILOG_ERROR("WriteRemoteObject failed."); + return; + } + + auto remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("remote is nullptr."); + return; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + auto error = remote->SendRequest(IAbilityManager::SET_ROOTSSCENESESSION, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + } +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 2dc09fcae0..90ce68fec8 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -6255,9 +6255,16 @@ int AbilityManagerService::PrepareTerminateAbility(const sptr &to return CHECK_PERMISSION_FAILED; } + auto type = abilityRecord->GetAbilityInfo().type; + if (type != AppExecFwk::AbilityType::PAGE) { + HILOG_ERROR("Only support PAGE."); + callback->DoPrepareTerminate(); + return RESOLVE_CALL_ABILITY_TYPE_ERR; + } + auto timeoutTask = [&callback]() { callback->DoPrepareTerminate(); - } + }; int prepareTerminateTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * PREPARE_TERMINATE_TIMEOUT_MULTIPLE; if (handler_) { @@ -6957,5 +6964,14 @@ int32_t AbilityManagerService::ShareDataDone( handler_->RemoveEvent(SHAREDATA_TIMEOUT_MSG, uniqueId); return GetShareDataPairAndReturnData(abilityRecord, resultCode, uniqueId, wantParam); } + +void AbilityManagerService::SetRootSceneSession(const sptr &rootSceneSession) +{ + if (!CheckCallingTokenId(BUNDLE_NAME_SCENEBOARD, U0_USER_ID)) { + HILOG_ERROR("Not sceneboard called, not allowed."); + return; + } + uiAbilityLifecycleManager_->SetRootSceneSession(rootSceneSession); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 4348ffd9ec..1f36525979 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -23,6 +23,7 @@ #include "ability_manager_errors.h" #include "ability_scheduler_proxy.h" #include "ability_scheduler_stub.h" +#include "session/host/include/root_scene_session.h" #include "session_info.h" namespace OHOS { @@ -2026,5 +2027,17 @@ int AbilityManagerStub::VerifyPermissionInner(MessageParcel &data, MessageParcel } return NO_ERROR; } + +int AbilityManagerStub::SetRootSceneSessionInner(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("Call."); + auto rootSceneSession = iface_cast(data.ReadRemoteObject()); + if (rootSceneSession == nullptr) { + HILOG_ERROR("Read rootSceneSession failed."); + return ERR_INVALID_VALUE; + } + SetRootSceneSession(rootSceneSession); + return NO_ERROR; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index 35f76fa023..2e3a87615a 100644 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -189,7 +189,7 @@ bool AbilitySchedulerProxy::SchedulePrepareTerminateAbility() HILOG_ERROR("Remote() is NULL"); return false; } - int32_t err = Remote()->SendRequest(IAbilityScheduler::SCHEDULE_ABILITY_PREPARE_TERMINATE, data, reply, option); + int32_t err = remote->SendRequest(IAbilityScheduler::SCHEDULE_ABILITY_PREPARE_TERMINATE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("end failed. err: %{public}d", err); return false; diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index a7e26320c0..e848b94694 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -488,7 +488,7 @@ bool MissionListManager::CreateOrReusedMissionInfo(const AbilityRequest &ability std::string missionName = GetMissionName(abilityRequest); auto mgr = DelayedSingleton::GetInstance(); - if (needFind && !abilityRequest.abilityInfo.applicationInfo.isLauncherApp && mgr && + if (needFind && mgr && mgr->FindReusedMissionInfo(missionName, abilityRequest.specifiedFlag, isFindRecentStandard, info) && info.missionInfo.id > 0) { reUsedMissionInfo = true; @@ -549,7 +549,7 @@ void MissionListManager::GetTargetMissionAndAbility(const AbilityRequest &abilit info.missionInfo.label = targetRecord->GetLabel(); } - if (abilityRequest.abilityInfo.applicationInfo.isLauncherApp || abilityRequest.abilityInfo.excludeFromMissions) { + if (abilityRequest.abilityInfo.excludeFromMissions) { return; } diff --git a/services/abilitymgr/src/prepare_terminate_callback_proxy.cpp b/services/abilitymgr/src/prepare_terminate_callback_proxy.cpp index 82fd82ab1f..98f419c94a 100644 --- a/services/abilitymgr/src/prepare_terminate_callback_proxy.cpp +++ b/services/abilitymgr/src/prepare_terminate_callback_proxy.cpp @@ -38,7 +38,7 @@ void PrepareTerminateCallbackProxy::DoPrepareTerminate() HILOG_ERROR("Remote() is NULL"); return; } - int error = Remote()->SendRequest(ON_DO_PREPARE_TERMINATE, data, reply, option); + int error = remote->SendRequest(ON_DO_PREPARE_TERMINATE, data, reply, option); if (error != ERR_OK) { HILOG_ERROR("SendRequest fail, error: %{public}d", error); } diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 7ff8d0c35c..191ea4b9e5 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -65,6 +65,7 @@ ohos_shared_library("perm_verification") { ] subsystem_name = "ability" + innerapi_tags = [ "platformsdk_indirect" ] part_name = "ability_runtime" } 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 d2f4fcc2e6..5707391c4c 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -1519,10 +1519,11 @@ HWTEST_F(MainThreadTest, LoadNativeLiabrary_0100, TestSize.Level1) HILOG_INFO("%{public}s start.", __func__); std::string nativeLibraryPath = ""; ASSERT_NE(mainThread_, nullptr); - mainThread_->LoadNativeLiabrary(nativeLibraryPath); + BundleInfo bundleInfo; + mainThread_->LoadNativeLiabrary(bundleInfo, nativeLibraryPath); nativeLibraryPath = "test/"; - mainThread_->LoadNativeLiabrary(nativeLibraryPath); + mainThread_->LoadNativeLiabrary(bundleInfo, nativeLibraryPath); HILOG_INFO("%{public}s end.", __func__); } #endif