diff --git a/frameworks/ability_lite/BUILD.gn b/frameworks/ability_lite/BUILD.gn index 85b1a617e756df42968502878d1055023c9ef145..c57d37864fc1216b076af26420261bd48b5ddcee 100755 --- a/frameworks/ability_lite/BUILD.gn +++ b/frameworks/ability_lite/BUILD.gn @@ -79,8 +79,6 @@ lite_library("ability") { "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", "//foundation/communication/ipc_lite/frameworks/liteipc/include", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/freetype/include", "//utils/native/lite/kv_store/innerkits", diff --git a/frameworks/ability_lite/example/BUILD.gn b/frameworks/ability_lite/example/BUILD.gn index 5005a7e0c3638b3943cbb3063cc11b341dcda938..d568217046ff6a45c544ae72102a5f6b19403bbb 100644 --- a/frameworks/ability_lite/example/BUILD.gn +++ b/frameworks/ability_lite/example/BUILD.gn @@ -47,8 +47,6 @@ lite_library("hiability") { "//foundation/graphic/utils/interfaces/innerkits", "//foundation/graphic/ui/interfaces/kits", "//foundation/graphic/utils/interfaces/kits/gfx_utils", - "//kernel/liteos_a/kernel/common", - "//kernel/liteos_a/kernel/include", ] deps = [ diff --git a/frameworks/abilitymgr_lite/BUILD.gn b/frameworks/abilitymgr_lite/BUILD.gn index e6f6180cad8f269714821fb4af3f9755e325d042..e66514c614ff796613f47a3d30642b1a8045afd7 100755 --- a/frameworks/abilitymgr_lite/BUILD.gn +++ b/frameworks/abilitymgr_lite/BUILD.gn @@ -41,8 +41,6 @@ lite_library("abilitymanager") { "${appexecfwk_lite_path}/frameworks/bundle_lite/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//utils/native/lite/kv_store/innerkits", "//utils/native/lite/include", diff --git a/frameworks/abilitymgr_lite/include/abilityms_slite_client.h b/frameworks/abilitymgr_lite/include/abilityms_slite_client.h index 21e71ed83926c68790ad24e6768770fdd2708316..a87d3d3ab74d2f3f3f42d2e841fe5903ef142778 100755 --- a/frameworks/abilitymgr_lite/include/abilityms_slite_client.h +++ b/frameworks/abilitymgr_lite/include/abilityms_slite_client.h @@ -42,6 +42,8 @@ public: int ForceStopBundle(uint64_t token) const; + int ForceStop(char *bundlename) const; + ElementName *GetTopAbility() const; private: diff --git a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp index b5759c242cc4530a71f1d7f9d806eb58559b129a..e79972f41406f9b804d90c45c318342934374b8b 100755 --- a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp +++ b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp @@ -17,9 +17,12 @@ #include "abilityms_slite_client.h" +StartCheckFunc CALLBACKFUNC = nullptr; + extern "C" { int RegAbilityCallback(StartCheckFunc startChecktCallback) { + CALLBACKFUNC = startChecktCallback; return 0; } @@ -32,4 +35,14 @@ int ForceStopBundle(uint64_t token) { return OHOS::AbilityMsClient::GetInstance().ForceStopBundle(token); } + +int ForceStop(char *bundlename) +{ + return OHOS::AbilityMsClient::GetInstance().ForceStop(bundlename); +} + +StartCheckFunc getAbilityCallback() +{ + return CALLBACKFUNC; +} } diff --git a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp index 5852ee8b3e69577ff0424739e2b9585d0d10322a..6c5006c7f3d07a8cd5827fe4ec22a1e25169db86 100755 --- a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp +++ b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp @@ -135,4 +135,20 @@ ElementName *AbilityMsClient::GetTopAbility() const } return amsProxy_->GetTopAbility(); } + +int AbilityMsClient::ForceStop(char *bundlename) const +{ + AbilityMgrService *service = AbilityMgrService::GetInstance(); + if (service == nullptr) { + return PARAM_CHECK_ERROR; + } + char* name = Utils::Strdup(bundlename); + Request request = { + .msgId = TERMINATE_APP_BY_BUNDLENAME, + .data = reinterpret_cast(name), + .len = strlen(name), + } + + return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); +} } // namespace OHOS diff --git a/frameworks/want_lite/BUILD.gn b/frameworks/want_lite/BUILD.gn index 2d74e5a341a180756b46e176dc56d47a07b54393..016cad7726ffbd0a10aab9905b89c8ea8773c606 100755 --- a/frameworks/want_lite/BUILD.gn +++ b/frameworks/want_lite/BUILD.gn @@ -34,8 +34,6 @@ source_set("want") { "${appexecfwk_lite_path}/frameworks/bundle_lite/include", "${appexecfwk_lite_path}/utils/bundle_lite", "//foundation/communication/ipc_lite/interfaces/kits", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", ] defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ] diff --git a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h index 353da6d3e89701af30e41a82681dea4442464133..ee1f64430a8b2b9233e19e4ac5a474fdb294535d 100755 --- a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h +++ b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h @@ -44,6 +44,7 @@ enum AmsCommand { INNER_BEGIN, TERMINATE_APP = INNER_BEGIN, DUMP_ABILITY, + TERMINATE_APP_BY_BUNDLENAME, COMMAND_END, }; diff --git a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h index 37d9e88ce593fea15514c341b5b56e8e4ea548c7..f5fb63486ae739ea430be2188ce28a3b0e81bdf8 100755 --- a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h +++ b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h @@ -59,6 +59,21 @@ int ForceStopBundle(uint64_t token); * @return Returns the element name of the top ability. */ ElementName *GetTopAbility(); + +/** + * @brief Forcestop an ability based on the specified bundlename information. + * + * @param bundlename Indicates the bundlename of the ability. + * @return Returns 0 if this function is successfully called; returns another value otherwise. + */ +int ForceStop(char *bundlename); + +/** + * @brief get ability callback function + * + * @return Returns the ability callback function + */ +StartCheckFunc getAbilityCallback(); #ifdef __cplusplus #if __cplusplus } diff --git a/services/abilitymgr_lite/BUILD.gn b/services/abilitymgr_lite/BUILD.gn index ba3479bb09a6f1d987cc7febb099685feca453fc..072dbd057cdf6ae7836d230e6d94250fa56d76fc 100644 --- a/services/abilitymgr_lite/BUILD.gn +++ b/services/abilitymgr_lite/BUILD.gn @@ -83,8 +83,6 @@ lite_library("abilityms") { "//base/startup/appspawn_lite/services/include", "//base/security/permission/interfaces/kits/permission_lite", "//base/security/permission/services/permission_lite/pms/include", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//utils/native/lite/include", "include", diff --git a/services/abilitymgr_lite/include/ability_service.h b/services/abilitymgr_lite/include/ability_service.h index 3ffbabfd27202061f6b6fc72e3d7ef9714983aff..787a723388284bffe90ad2d30882ecdb392e3af8 100755 --- a/services/abilitymgr_lite/include/ability_service.h +++ b/services/abilitymgr_lite/include/ability_service.h @@ -45,6 +45,7 @@ public: ~AbilityService() override; int32_t StartAbility(const Want *want); int32_t TerminateAbility(uint16_t token); + int32_t ForceStop(char *bundlename); int32_t ForceStopBundle(uint16_t token); int32_t SchedulerLifecycleDone(uint64_t token, int32_t state); ElementName *GetTopAbility(); diff --git a/services/abilitymgr_lite/src/ability_mgr_service.cpp b/services/abilitymgr_lite/src/ability_mgr_service.cpp index 385e19039fad8420d2ca153f2e1ff5cb252ad61d..ccac550ea6debf750f25324c6db8016c9290afaa 100755 --- a/services/abilitymgr_lite/src/ability_mgr_service.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_service.cpp @@ -90,6 +90,9 @@ BOOL AbilityMgrService::ServiceMessageHandle(Service *service, Request *request) ret = AbilityService::GetInstance().TerminateAbility(request->msgValue); } else if (request->msgId == TERMINATE_APP) { ret = AbilityService::GetInstance().ForceStopBundle(request->msgValue); + } else if (request->msgId == TERMINATE_APP_BY_BUNDLENAME) { + char* bundleName = reinterpret_cast(request->data); + ret = AbilityService::GetInstance().ForceStop(bundleName); } return ret == ERR_OK; #else diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index 4cd2f32a59320703c94d8d427f3ff89e88b4bef2..b5e5cd663298ec5e96f9f4cd17fdd4c6cd02b41f 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -24,6 +24,7 @@ #include "ability_stack.h" #include "ability_state.h" #include "abilityms_log.h" +#include "ability_manager_inner.h" #include "bundle_manager.h" #include "cmsis_os.h" #include "js_app_host.h" @@ -174,8 +175,10 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) } HILOG_INFO(HILOG_MODULE_AAFWK, "Js app already started or starting."); } else { - // TODO ��֮ǰ��jsӦ�ò���һ��Ӧ�� JS2JS��������Ҫ�Ȱ�֮ǰ��JS�˳� - return ERR_OK; + // js to js + HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") + TerminateAbility(topRecord->GetToken()); + pendingToken_ = GenerateToken(); } } @@ -192,9 +195,9 @@ int32_t AbilityService::TerminateAbility(uint16_t token) return PARAM_NULL_ERROR; } uint16_t topToken = topRecord->GetToken(); - // TODO CHECK terminate ����,�Ƿ��иó����� + // TODO CHECK terminate token if (token == LAUNCHER_TOKEN) { - // �����ǰjs�ں�̨, �������˺�̨��js�ߵ�ǰ̨ + // if js is in background, the launcher goes back to background and js goes to active if (topToken != token && topRecord->GetState() == SCHEDULE_BACKGROUND) { HILOG_INFO(HILOG_MODULE_AAFWK, "Resume Js app [%u]", topToken); return SchedulerLifecycle(LAUNCHER_TOKEN, STATE_BACKGROUND); @@ -202,14 +205,13 @@ int32_t AbilityService::TerminateAbility(uint16_t token) return ERR_OK; } - // TODO CHECK�Ƿ��иó��� if (token != topToken) { APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_STOP_UNKNOWN_ABILITY_TOKEN); DeleteRecordInfo(token); return -1; } topRecord->SetTerminated(true); - // TerminateAbility TOP��js + // TerminateAbility top js return SchedulerLifecycleInner(topRecord, STATE_BACKGROUND); } @@ -233,11 +235,28 @@ int32_t AbilityService::ForceStopBundle(uint16_t token) return PARAM_NULL_ERROR; } if (launcherRecord->GetState() != SCHEDULE_ACTIVE) { - return SchedulerLifecycleInner(LAUNCHER_TOKEN, STATE_ACTIVE); + return SchedulerLifecycle(LAUNCHER_TOKEN, STATE_ACTIVE); } return ERR_OK; } +int32_t AbilityService::ForceStop(char* bundlename) +{ + //stop Launcher + if (strcmp(bundlename, LAUNCHER_BUNDLE_NAME) == 0) { + return TerminateAbility(0); + } + + //stop js app + if (strcmp(abilityStack_.GetTopAbility()->GetAppName(), bundlename) == 0) { + HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStop [%s]", bundlename); + AbilityRecord *topRecord = const_cast(abilityStack_.GetTopAbility()); + return TerminateAbility(topRecord->GetToken()); + } + + return PARAM_CHECK_ERROR; +} + int32_t AbilityService::ForceStopBundleInner(uint16_t token) { // free js mem and delete the record @@ -271,13 +290,17 @@ int32_t AbilityService::PreCheckStartAbility( return ERR_OK; } auto record = new AbilityRecord(); - record->SetToken(GenerateToken()); + if (pendingToken_ != 0) { + record->SetToken(pendingToken_); + } else { + record->SetToken(GenerateToken()); + } record->SetAppName(bundleName); record->SetAppPath(path); record->SetAppData(data, dataLength); record->SetState(SCHEDULE_STOP); abilityList_.Add(record); - if (CreateAppTask(record) != ERR_OK) { + if (pendingToken_ == 0 && CreateAppTask(record) != ERR_OK) { HILOG_ERROR(HILOG_MODULE_AAFWK, "CheckResponse CreateAppTask fail"); abilityList_.Erase(record->GetToken()); delete record; @@ -288,6 +311,14 @@ int32_t AbilityService::PreCheckStartAbility( bool AbilityService::CheckResponse(const char *bundleName) { + StartCheckFunc callBackFunc = getAbilityCallback(); + if (callBackFunc != nullptr) { + int ret = (*callBackFunc)(bundleName); + if (ret != ERR_OK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed bundlename is: [%s]", bundleName); + return false; + } + } return true; } @@ -411,7 +442,6 @@ void AbilityService::OnBackgroundDone(uint16_t token) if (token != LAUNCHER_TOKEN) { if (topRecord->GetToken() == token) { APP_EVENT(MT_ACE_APP_BACKGROUND); - topRecord->SetTerminated(true); (void) SchedulerLifecycle(LAUNCHER_TOKEN, STATE_ACTIVE); } return; @@ -483,7 +513,7 @@ int32_t AbilityService::SchedulerLifecycleInner(const AbilityRecord *record, int return PARAM_NULL_ERROR; } // dispatch js life cycle - if (record->GetToken() != LAUNCHER_TOKEN) { // jsӦ�� + if (record->GetToken() != LAUNCHER_TOKEN) { (void) SendMsgToJsAbility(state, record); return ERR_OK; } @@ -491,7 +521,7 @@ int32_t AbilityService::SchedulerLifecycleInner(const AbilityRecord *record, int if (g_NativeAbility == nullptr) { return PARAM_NULL_ERROR; } - // ����want�ڴ棬�ڷ���������ͷ� + // malloc want memory and release after use Want *info = static_cast(AdapterMalloc(sizeof(Want))); if (info == nullptr) { return MEMORY_MALLOC_ERROR; diff --git a/services/abilitymgr_lite/tools/BUILD.gn b/services/abilitymgr_lite/tools/BUILD.gn index 6280e90e5d4418af5beb100eeaa3bb45b5e9e163..7f5b6cda1ad16d3c4c33ab60cd0c8e3612dd4cb2 100755 --- a/services/abilitymgr_lite/tools/BUILD.gn +++ b/services/abilitymgr_lite/tools/BUILD.gn @@ -69,8 +69,6 @@ executable("aa") { "//foundation/communication/ipc_lite/interfaces/kits", "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//utils/native/lite/include", diff --git a/services/abilitymgr_lite/unittest/test_lv0/page_ability_test/BUILD.gn b/services/abilitymgr_lite/unittest/test_lv0/page_ability_test/BUILD.gn index b259a0a7f15869bdfed735d30b559f448cbd1f89..db1a2a5427dffff143ad700eff88aa1d7f348bbf 100644 --- a/services/abilitymgr_lite/unittest/test_lv0/page_ability_test/BUILD.gn +++ b/services/abilitymgr_lite/unittest/test_lv0/page_ability_test/BUILD.gn @@ -39,8 +39,6 @@ unittest("ability_test_pageAbilityTest_lv0") { "${appexecfwk_lite_path}/kits/appkit_lite/appkit_utils/include", "//foundation/distributedschedule/samgr_lite/interfaces/innerkits/samgr", "//foundation/distributedschedule/samgr_lite/interfaces/innerkits/registry", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", "//third_party/cJSON", "//utils/native/lite/include", ]