From b8bf9966eddfbe515a802707523550518e030f2d Mon Sep 17 00:00:00 2001 From: Harmonica Date: Mon, 15 Mar 2021 20:50:29 +0800 Subject: [PATCH 01/23] =?UTF-8?q?update=20README=5Fzh.md.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=80=E4=B8=AA=E5=8A=A0=E7=B2=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_zh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_zh.md b/README_zh.md index b46b40d..e039be7 100755 --- a/README_zh.md +++ b/README_zh.md @@ -16,7 +16,7 @@ - **AbilityKit**是Ability框架提供给开发者的开发包,开发者基于该开发包可以开发出基于Ability组件的应用。基于Ability组件开发的应用有两种类型:基于Javascript语言开发的Ability(**JS Ability**)和基于C/C++语言开发的Ability(**Native Ability**)。**JS应用开发框架**是开发者开发JS Ability所用到框架,是在AbilityKit基础封装的包含JS UI组件的一套方便开发者能够迅速开发Ability应用的框架。 - **Ability**是系统调度应用的最小单元,是能够完成一个独立功能的组件,一个应用可以包含一个或多个Ability。Ability分为两种类型:Page类型的Ability和Service类型的Ability - - **Page类型的Ability:**带有界面,为用户提供人机交互的能力。 + - **Page类型的Ability**:带有界面,为用户提供人机交互的能力。 - **Service类型的Ability**:不带界面,为用户提供后台任务机制。 - **AbilitySlice**是单个页面及其控制逻辑的总和,是Page类型Ability特有的组件,一个Page类型的Ability可以包含多个AbilitySlice,此时,这些页面提供的业务能力应当是高度相关的。Page类型的Ability和AbilitySlice的关系如下图2所示: -- Gitee From 2a32bdb44556a8336ef9defe5a9272e8ebeb7c7d Mon Sep 17 00:00:00 2001 From: mamingshuai Date: Wed, 7 Apr 2021 14:21:58 +0800 Subject: [PATCH 02/23] add issue and pr template --- .gitee/ISSUE_TEMPLATE.zh-CN.md | 11 +++++++++++ .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .gitee/ISSUE_TEMPLATE.zh-CN.md create mode 100644 .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md new file mode 100644 index 0000000..651e02c --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE.zh-CN.md @@ -0,0 +1,11 @@ +### 该问题是怎么引起的? + + + +### 重现步骤 + + + +### 报错信息 + + diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100644 index 0000000..86dd358 --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,12 @@ +### 相关的Issue + + +### 原因(目的、解决的问题等) + + +### 描述(做了什么,变更了什么) + + +### 测试用例(新增、改动、可能影响的功能) + + -- Gitee From cc6dd7dd0d020bd3c46a54d3118dad66cb514f2a Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Thu, 20 May 2021 19:35:09 +0800 Subject: [PATCH 03/23] IssueNo:#I3S9OD Description:add ams log Sig:startup Feature or Bugfix:Bugfix Binary Source:No --- services/abilitymgr_lite/include/util/abilityms_log.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/abilitymgr_lite/include/util/abilityms_log.h b/services/abilitymgr_lite/include/util/abilityms_log.h index d16a590..159f298 100755 --- a/services/abilitymgr_lite/include/util/abilityms_log.h +++ b/services/abilitymgr_lite/include/util/abilityms_log.h @@ -16,9 +16,7 @@ #ifndef OHOS_LOGGING_H #define OHOS_LOGGING_H -#ifndef APP_PLATFORM_WATCHGT #include "log.h" -#endif namespace OHOS { #undef LOG_TAG -- Gitee From 0736988b1065f12580d71b4125ac7f9b6bc76c4b Mon Sep 17 00:00:00 2001 From: Zhaoyuan Date: Sat, 10 Jul 2021 21:02:06 +0800 Subject: [PATCH 04/23] add forcestop and callbackfunc and jstojs --- .../src/slite/ability_manager_inner.cpp | 13 ++++++++ .../src/slite/abilityms_slite_client.cpp | 16 +++++++++ .../ability_service_interface.h | 1 + .../slite/ability_manager_inner.h | 15 +++++++++ .../abilitymgr_lite/include/ability_service.h | 1 + .../src/ability_mgr_service.cpp | 3 ++ .../abilitymgr_lite/src/ability_service.cpp | 33 +++++++++++++++++-- 7 files changed, 80 insertions(+), 2 deletions(-) diff --git a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp index b5759c2..3c1103c 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; + 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 5852ee8..6c5006c 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/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h index 353da6d..de91cb6 100755 --- a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h +++ b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h @@ -45,6 +45,7 @@ enum AmsCommand { TERMINATE_APP = INNER_BEGIN, DUMP_ABILITY, COMMAND_END, + TERMINATE_APP_BY_BUNDLENAME, }; /** diff --git a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h index 37d9e88..f5fb634 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/include/ability_service.h b/services/abilitymgr_lite/include/ability_service.h index 3ffbabf..787a723 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 385e190..07af420 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 fdd7885..846c843 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" @@ -175,7 +176,9 @@ 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; + HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") + TerminateAbility(topRecord->GetToken()); + pendingToken_ = GenerateToken() } } @@ -238,6 +241,23 @@ int32_t AbilityService::ForceStopBundle(uint16_t token) 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(GetTopAbility()->bundlename, 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 +291,17 @@ int32_t AbilityService::PreCheckStartAbility( return ERR_OK; } auto record = new AbilityRecord(); + 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 +312,11 @@ int32_t AbilityService::PreCheckStartAbility( bool AbilityService::CheckResponse(const char *bundleName) { + StartCheckFunc callBackFunc = getAbilityCallback(); + if (callBackFunc != nullptr) { + int ret = (*callBackFunc)(bundleName); + return (ret == 0) ? true : false; + } return true; } -- Gitee From ad78caac5b88faaf466332502b8cd6c43440d7f7 Mon Sep 17 00:00:00 2001 From: Zhaoyuan Date: Sat, 10 Jul 2021 21:02:06 +0800 Subject: [PATCH 05/23] add forcestop and callbackfunc and jstojs --- .../src/slite/ability_manager_inner.cpp | 13 +++++++ .../src/slite/abilityms_slite_client.cpp | 16 +++++++++ .../ability_service_interface.h | 1 + .../slite/ability_manager_inner.h | 15 ++++++++ .../abilitymgr_lite/include/ability_service.h | 1 + .../src/ability_mgr_service.cpp | 3 ++ .../abilitymgr_lite/src/ability_service.cpp | 34 +++++++++++++++++-- 7 files changed, 80 insertions(+), 3 deletions(-) diff --git a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp index b5759c2..3c1103c 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; + 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 5852ee8..6c5006c 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/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h index 353da6d..de91cb6 100755 --- a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h +++ b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h @@ -45,6 +45,7 @@ enum AmsCommand { TERMINATE_APP = INNER_BEGIN, DUMP_ABILITY, COMMAND_END, + TERMINATE_APP_BY_BUNDLENAME, }; /** diff --git a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h index 37d9e88..f5fb634 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/include/ability_service.h b/services/abilitymgr_lite/include/ability_service.h index 3ffbabf..787a723 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 385e190..07af420 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 fdd7885..42d0038 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" @@ -175,7 +176,9 @@ 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; + HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") + TerminateAbility(topRecord->GetToken()); + pendingToken_ = GenerateToken() } } @@ -238,6 +241,23 @@ int32_t AbilityService::ForceStopBundle(uint16_t token) 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(GetTopAbility()->bundlename, 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 +291,17 @@ int32_t AbilityService::PreCheckStartAbility( return ERR_OK; } auto record = new AbilityRecord(); + 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 +312,11 @@ int32_t AbilityService::PreCheckStartAbility( bool AbilityService::CheckResponse(const char *bundleName) { + StartCheckFunc callBackFunc = getAbilityCallback(); + if (callBackFunc != nullptr) { + int ret = (*callBackFunc)(bundleName); + return (ret == 0) ? true : false; + } return true; } @@ -411,7 +440,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; -- Gitee From 3cd295c31ffefe89ba7638961ebddeaed1f2bd89 Mon Sep 17 00:00:00 2001 From: Zhaoyuan Date: Wed, 14 Jul 2021 21:08:53 +0800 Subject: [PATCH 06/23] fix commiters --- .../ability_service_interface.h | 2 +- .../abilitymgr_lite/src/ability_service.cpp | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h index de91cb6..ee1f644 100755 --- a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h +++ b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h @@ -44,8 +44,8 @@ enum AmsCommand { INNER_BEGIN, TERMINATE_APP = INNER_BEGIN, DUMP_ABILITY, - COMMAND_END, TERMINATE_APP_BY_BUNDLENAME, + COMMAND_END, }; /** diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index 01d912a..7755ebf 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -175,7 +175,7 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) } HILOG_INFO(HILOG_MODULE_AAFWK, "Js app already started or starting."); } else { - // TODO ��֮ǰ��jsӦ�ò���һ��Ӧ�� JS2JS��������Ҫ�Ȱ�֮ǰ��JS�˳� + // js to js HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") TerminateAbility(topRecord->GetToken()); pendingToken_ = GenerateToken() @@ -195,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); @@ -205,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); } @@ -315,7 +314,10 @@ bool AbilityService::CheckResponse(const char *bundleName) StartCheckFunc callBackFunc = getAbilityCallback(); if (callBackFunc != nullptr) { int ret = (*callBackFunc)(bundleName); - return (ret == 0) ? true : false; + if (ret != ERR_OK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed bundlename is: [%s]", bundleName); + return false; + } } return true; } @@ -511,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; } @@ -519,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; -- Gitee From 2ef2e0ce934ac6831cf7522a65fc16def1609658 Mon Sep 17 00:00:00 2001 From: Zhaoyuan Date: Fri, 16 Jul 2021 10:45:12 +0800 Subject: [PATCH 07/23] move kernel include and fix bugs --- frameworks/ability_lite/BUILD.gn | 2 -- frameworks/ability_lite/example/BUILD.gn | 2 -- frameworks/abilitymgr_lite/BUILD.gn | 2 -- frameworks/abilitymgr_lite/include/abilityms_slite_client.h | 2 ++ .../abilitymgr_lite/src/slite/ability_manager_inner.cpp | 4 ++-- frameworks/want_lite/BUILD.gn | 2 -- services/abilitymgr_lite/BUILD.gn | 2 -- services/abilitymgr_lite/src/ability_mgr_service.cpp | 2 +- services/abilitymgr_lite/src/ability_service.cpp | 4 ++-- services/abilitymgr_lite/tools/BUILD.gn | 2 -- .../unittest/test_lv0/page_ability_test/BUILD.gn | 2 -- 11 files changed, 7 insertions(+), 19 deletions(-) diff --git a/frameworks/ability_lite/BUILD.gn b/frameworks/ability_lite/BUILD.gn index 85b1a61..c57d378 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 5005a7e..d568217 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 e6f6180..e66514c 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 21e71ed..a87d3d3 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 3c1103c..e79972f 100755 --- a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp +++ b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp @@ -17,7 +17,7 @@ #include "abilityms_slite_client.h" -StartCheckFunc CALLBACKFUNC; +StartCheckFunc CALLBACKFUNC = nullptr; extern "C" { int RegAbilityCallback(StartCheckFunc startChecktCallback) @@ -43,6 +43,6 @@ int ForceStop(char *bundlename) StartCheckFunc getAbilityCallback() { - return CALLBACKFUNC + return CALLBACKFUNC; } } diff --git a/frameworks/want_lite/BUILD.gn b/frameworks/want_lite/BUILD.gn index 2d74e5a..016cad7 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/services/abilitymgr_lite/BUILD.gn b/services/abilitymgr_lite/BUILD.gn index ba3479b..072dbd0 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/src/ability_mgr_service.cpp b/services/abilitymgr_lite/src/ability_mgr_service.cpp index 07af420..ccac550 100755 --- a/services/abilitymgr_lite/src/ability_mgr_service.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_service.cpp @@ -91,7 +91,7 @@ BOOL AbilityMgrService::ServiceMessageHandle(Service *service, Request *request) } 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) + char* bundleName = reinterpret_cast(request->data); ret = AbilityService::GetInstance().ForceStop(bundleName); } return ret == ERR_OK; diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index 7755ebf..b5e5cd6 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -178,7 +178,7 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) // js to js HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") TerminateAbility(topRecord->GetToken()); - pendingToken_ = GenerateToken() + pendingToken_ = GenerateToken(); } } @@ -248,7 +248,7 @@ int32_t AbilityService::ForceStop(char* bundlename) } //stop js app - if (strcmp(GetTopAbility()->bundlename, bundlename) == 0) { + 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()); diff --git a/services/abilitymgr_lite/tools/BUILD.gn b/services/abilitymgr_lite/tools/BUILD.gn index 6280e90..7f5b6cd 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 b259a0a..db1a2a5 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", ] -- Gitee From 36d6eba8d358d10f44c094866e5e4811ffc8fbdb Mon Sep 17 00:00:00 2001 From: Zhaoyuan Date: Fri, 16 Jul 2021 10:45:12 +0800 Subject: [PATCH 08/23] move kernel include and fix bugs Signed-off-by: Zhaoyuan --- frameworks/ability_lite/BUILD.gn | 2 -- frameworks/ability_lite/example/BUILD.gn | 2 -- frameworks/abilitymgr_lite/BUILD.gn | 2 -- frameworks/abilitymgr_lite/include/abilityms_slite_client.h | 2 ++ .../abilitymgr_lite/src/slite/ability_manager_inner.cpp | 4 ++-- frameworks/want_lite/BUILD.gn | 2 -- services/abilitymgr_lite/BUILD.gn | 2 -- services/abilitymgr_lite/src/ability_mgr_service.cpp | 2 +- services/abilitymgr_lite/src/ability_service.cpp | 4 ++-- services/abilitymgr_lite/tools/BUILD.gn | 2 -- .../unittest/test_lv0/page_ability_test/BUILD.gn | 2 -- 11 files changed, 7 insertions(+), 19 deletions(-) diff --git a/frameworks/ability_lite/BUILD.gn b/frameworks/ability_lite/BUILD.gn index 85b1a61..c57d378 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 5005a7e..d568217 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 e6f6180..e66514c 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 21e71ed..a87d3d3 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 3c1103c..e79972f 100755 --- a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp +++ b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp @@ -17,7 +17,7 @@ #include "abilityms_slite_client.h" -StartCheckFunc CALLBACKFUNC; +StartCheckFunc CALLBACKFUNC = nullptr; extern "C" { int RegAbilityCallback(StartCheckFunc startChecktCallback) @@ -43,6 +43,6 @@ int ForceStop(char *bundlename) StartCheckFunc getAbilityCallback() { - return CALLBACKFUNC + return CALLBACKFUNC; } } diff --git a/frameworks/want_lite/BUILD.gn b/frameworks/want_lite/BUILD.gn index 2d74e5a..016cad7 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/services/abilitymgr_lite/BUILD.gn b/services/abilitymgr_lite/BUILD.gn index ba3479b..072dbd0 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/src/ability_mgr_service.cpp b/services/abilitymgr_lite/src/ability_mgr_service.cpp index 07af420..ccac550 100755 --- a/services/abilitymgr_lite/src/ability_mgr_service.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_service.cpp @@ -91,7 +91,7 @@ BOOL AbilityMgrService::ServiceMessageHandle(Service *service, Request *request) } 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) + char* bundleName = reinterpret_cast(request->data); ret = AbilityService::GetInstance().ForceStop(bundleName); } return ret == ERR_OK; diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index 7755ebf..b5e5cd6 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -178,7 +178,7 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) // js to js HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") TerminateAbility(topRecord->GetToken()); - pendingToken_ = GenerateToken() + pendingToken_ = GenerateToken(); } } @@ -248,7 +248,7 @@ int32_t AbilityService::ForceStop(char* bundlename) } //stop js app - if (strcmp(GetTopAbility()->bundlename, bundlename) == 0) { + 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()); diff --git a/services/abilitymgr_lite/tools/BUILD.gn b/services/abilitymgr_lite/tools/BUILD.gn index 6280e90..7f5b6cd 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 b259a0a..db1a2a5 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", ] -- Gitee From 96b7edcad811d5258b8fe2c24720dd1af117ebea Mon Sep 17 00:00:00 2001 From: LiuWei Date: Sun, 25 Jul 2021 22:49:16 +0800 Subject: [PATCH 09/23] IssueNo:#I42B2I Code optimization for ams Description:Code optimization for ams. Sig:aafwk Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: LiuWei --- .../abilitymgr_lite/include/ability_service.h | 10 +++ .../abilitymgr_lite/src/ability_service.cpp | 72 +++++++++++-------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/services/abilitymgr_lite/include/ability_service.h b/services/abilitymgr_lite/include/ability_service.h index 787a723..282a0b3 100755 --- a/services/abilitymgr_lite/include/ability_service.h +++ b/services/abilitymgr_lite/include/ability_service.h @@ -37,6 +37,13 @@ struct AbilitySvcInfo { class AbilityService : public NoCopyable { public: + typedef void (AbilityService::*LifecycleFunc)(uint16_t token); + struct LifecycleFuncStr + { + int32_t state; + LifecycleFunc func_ptr; + }; + static AbilityService& GetInstance() { static AbilityService instance; @@ -72,10 +79,13 @@ private: void SetAbilityState(uint64_t token, int32_t state); void UpdataRecord(AbilitySvcInfo *info); int32_t ForceStopBundleInner(uint16_t token); + bool IsValidAbility(AbilityInfo *abilityInfo); uint16_t pendingToken_ { 0 }; AbilityList abilityList_ {}; AbilityStack abilityStack_ {}; + SliteAbility *nativeAbility_ = nullptr; + static LifecycleFuncStr lifecycleFuncList_[STATE_BACKGROUND + 1]; }; } // namespace OHOS #endif // OHOS_ABILITY_SERVICE_H diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index b5e5cd6..d542ee8 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -42,7 +42,14 @@ constexpr int32_t QUEUE_LENGTH = 32; constexpr int32_t SIZE_COEFFICIENT = 12; constexpr int32_t TASK_STACK_SIZE = 0x400 * SIZE_COEFFICIENT; constexpr int32_t APP_TASK_PRI = 25; -SliteAbility *g_NativeAbility = nullptr; + +AbilityService::LifecycleFuncStr AbilityService::lifecycleFuncList_[] = { + {STATE_UNINITIALIZED, &AbilityService::OnDestroyDone}, + {STATE_INITIAL, nullptr}, + {STATE_INACTIVE, nullptr}, + {STATE_ACTIVE, &AbilityService::OnActiveDone}, + {STATE_BACKGROUND, &AbilityService::OnBackgroundDone}, +}; AbilityService::AbilityService() { @@ -70,6 +77,20 @@ void AbilityService::CleanWant() AdapterFree(want_); } +bool AbilityService::IsValidAbility(AbilityInfo *abilityInfo) +{ + if (abilityInfo == nullptr) { + return false; + } + if (abilityInfo->bundleName == nullptr || abilityInfo->srcPath == nullptr) { + return false; + } + if (strlen(abilityInfo->bundleName) == 0 || strlen(abilityInfo->srcPath) == 0) { + return false; + } + return true; +} + int32_t AbilityService::StartAbility(const Want *want) { if (want == nullptr || want->element == nullptr) { @@ -97,8 +118,7 @@ int32_t AbilityService::StartAbility(const Want *want) // JS APP AbilityInfo abilityInfo = { nullptr, nullptr }; QueryAbilityInfo(want, &abilityInfo); - if ((abilityInfo.bundleName == nullptr) || (strlen(abilityInfo.bundleName) == 0) || - (abilityInfo.srcPath == nullptr) || (strlen(abilityInfo.srcPath) == 0)) { + if (!IsValidAbility(&abilityInfo)) { APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_START_UNKNOWN_BUNDLE_INFO); ClearAbilityInfo(&abilityInfo); AdapterFree(info); @@ -249,8 +269,8 @@ int32_t AbilityService::ForceStop(char* bundlename) //stop js app if (strcmp(abilityStack_.GetTopAbility()->GetAppName(), bundlename) == 0) { - HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStop [%s]", bundlename); AbilityRecord *topRecord = const_cast(abilityStack_.GetTopAbility()); + HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStop [%u]", topRecord->GetToken()); return TerminateAbility(topRecord->GetToken()); } @@ -312,12 +332,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; - } + if (callBackFunc == nullptr) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed: null"); + return true; + } + int32_t ret = (*callBackFunc)(bundleName); + if (ret != ERR_OK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed: check"); + return false; } return true; } @@ -325,6 +347,7 @@ bool AbilityService::CheckResponse(const char *bundleName) int32_t AbilityService::CreateAppTask(AbilityRecord *record) { if ((record == nullptr) || (record->GetAppName() == nullptr)) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "CreateAppTask fail: null"); return PARAM_NULL_ERROR; } @@ -339,8 +362,9 @@ int32_t AbilityService::CreateAppTask(AbilityRecord *record) auto jsAppHost = new JsAppHost(); stTskInitParam.uwArg = reinterpret_cast((uintptr_t)jsAppHost); UINT32 appTaskId = 0; - UINT32 res = LOS_TaskCreate(&appTaskId, &stTskInitParam); - if (res != LOS_OK) { + UINT32 ret = LOS_TaskCreate(&appTaskId, &stTskInitParam); + if (ret != LOS_OK) { + HILOG_ERROR(HILOG_MODULE_AAFWK, "CreateAppTask fail: ret = %d", ret); APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_START_CREATE_TSAK_FAILED); delete jsAppHost; LOS_TaskUnlock(); @@ -518,7 +542,7 @@ int32_t AbilityService::SchedulerLifecycleInner(const AbilityRecord *record, int return ERR_OK; } // dispatch native life cycle - if (g_NativeAbility == nullptr) { + if (nativeAbility_ == nullptr) { return PARAM_NULL_ERROR; } // malloc want memory and release after use @@ -535,7 +559,7 @@ int32_t AbilityService::SchedulerLifecycleInner(const AbilityRecord *record, int SetWantElement(info, elementName); ClearElement(&elementName); SetWantData(info, record->GetAppData(), record->GetDataLength()); - SchedulerAbilityLifecycle(g_NativeAbility, *info, state); + SchedulerAbilityLifecycle(nativeAbility_, *info, state); ClearWant(info); return ERR_OK; } @@ -563,21 +587,9 @@ void AbilityService::SchedulerAbilityLifecycle(SliteAbility *ability, const Want int32_t AbilityService::SchedulerLifecycleDone(uint64_t token, int32_t state) { - switch (state) { - case STATE_ACTIVE: { - OnActiveDone(token); - break; - } - case STATE_BACKGROUND: { - OnBackgroundDone(token); - break; - } - case STATE_UNINITIALIZED: { - OnDestroyDone(token); - break; - } - default: { - break; + for (auto temp : lifecycleFuncList_) { + if (state == temp.state && temp.func_ptr != nullptr) { + (this->*temp.func_ptr)(token); } } return ERR_OK; @@ -635,7 +647,7 @@ ElementName *AbilityService::GetTopAbility() void AbilityService::setNativeAbility(const SliteAbility *ability) { - g_NativeAbility = const_cast(ability); + nativeAbility_ = const_cast(ability); } } // namespace OHOS -- Gitee From 55f9d06b8646a263d2c374cb0ed36872d72f3805 Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Tue, 27 Jul 2021 15:22:33 +0800 Subject: [PATCH 10/23] fix bugs --- .../abilitymgr_lite/src/slite/abilityms_slite_client.cpp | 3 ++- services/abilitymgr_lite/src/ability_service.cpp | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp index 6c5006c..5b07467 100755 --- a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp +++ b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp @@ -25,6 +25,7 @@ #include "securec.h" #include "unistd.h" #include "want_utils.h" +#include "utils.h" namespace OHOS { bool AbilityMsClient::Initialize() const @@ -147,7 +148,7 @@ int AbilityMsClient::ForceStop(char *bundlename) const .msgId = TERMINATE_APP_BY_BUNDLENAME, .data = reinterpret_cast(name), .len = strlen(name), - } + }; return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); } diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index b5e5cd6..1e14230 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -176,7 +176,7 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) HILOG_INFO(HILOG_MODULE_AAFWK, "Js app already started or starting."); } else { // js to js - HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") + HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js"); TerminateAbility(topRecord->GetToken()); pendingToken_ = GenerateToken(); } @@ -249,8 +249,8 @@ int32_t AbilityService::ForceStop(char* bundlename) //stop js app if (strcmp(abilityStack_.GetTopAbility()->GetAppName(), bundlename) == 0) { - HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStop [%s]", bundlename); AbilityRecord *topRecord = const_cast(abilityStack_.GetTopAbility()); + HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStop [%u]", topRecord->GetToken()); return TerminateAbility(topRecord->GetToken()); } @@ -315,7 +315,7 @@ bool AbilityService::CheckResponse(const char *bundleName) if (callBackFunc != nullptr) { int ret = (*callBackFunc)(bundleName); if (ret != ERR_OK) { - HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed bundlename is: [%s]", bundleName); + HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed"); return false; } } -- Gitee From d129caafd3db4c45c6fba749acc5b48becf003f4 Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Tue, 27 Jul 2021 15:22:33 +0800 Subject: [PATCH 11/23] fix bugs Signed-off-by: zhaoyuan --- .../abilitymgr_lite/src/slite/abilityms_slite_client.cpp | 3 ++- services/abilitymgr_lite/src/ability_service.cpp | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp index 6c5006c..5b07467 100755 --- a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp +++ b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp @@ -25,6 +25,7 @@ #include "securec.h" #include "unistd.h" #include "want_utils.h" +#include "utils.h" namespace OHOS { bool AbilityMsClient::Initialize() const @@ -147,7 +148,7 @@ int AbilityMsClient::ForceStop(char *bundlename) const .msgId = TERMINATE_APP_BY_BUNDLENAME, .data = reinterpret_cast(name), .len = strlen(name), - } + }; return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); } diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index b5e5cd6..1e14230 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -176,7 +176,7 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) HILOG_INFO(HILOG_MODULE_AAFWK, "Js app already started or starting."); } else { // js to js - HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js") + HILOG_INFO(HILOG_MODULE_AAFWK, "Terminate pre js app when js to js"); TerminateAbility(topRecord->GetToken()); pendingToken_ = GenerateToken(); } @@ -249,8 +249,8 @@ int32_t AbilityService::ForceStop(char* bundlename) //stop js app if (strcmp(abilityStack_.GetTopAbility()->GetAppName(), bundlename) == 0) { - HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStop [%s]", bundlename); AbilityRecord *topRecord = const_cast(abilityStack_.GetTopAbility()); + HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStop [%u]", topRecord->GetToken()); return TerminateAbility(topRecord->GetToken()); } @@ -315,7 +315,7 @@ bool AbilityService::CheckResponse(const char *bundleName) if (callBackFunc != nullptr) { int ret = (*callBackFunc)(bundleName); if (ret != ERR_OK) { - HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed bundlename is: [%s]", bundleName); + HILOG_ERROR(HILOG_MODULE_AAFWK, "calling ability callback failed"); return false; } } -- Gitee From 0bb081d0d06ec3c3c3406ec4ac5f4fc23268af92 Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Tue, 27 Jul 2021 01:07:54 -0700 Subject: [PATCH 12/23] IssueNo:#I3ZZD0 Description:StartRemoteAbility Sig:aafwk Feature or Bugfix: Feature Binary Source: No --- services/abilitymgr_lite/BUILD.gn | 1 + .../include/ability_mgr_feature.h | 4 +++ .../src/ability_mgr_feature.cpp | 36 +++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr_lite/BUILD.gn b/services/abilitymgr_lite/BUILD.gn index ba3479b..ffcd552 100644 --- a/services/abilitymgr_lite/BUILD.gn +++ b/services/abilitymgr_lite/BUILD.gn @@ -77,6 +77,7 @@ lite_library("abilityms") { "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", "${appexecfwk_lite_path}/frameworks/bundle_lite/include", "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/dmsfwk_lite/interfaces/innerkits", "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", "//foundation/graphic/wms/interfaces/innerkits", diff --git a/services/abilitymgr_lite/include/ability_mgr_feature.h b/services/abilitymgr_lite/include/ability_mgr_feature.h index 12b574c..7f782c1 100755 --- a/services/abilitymgr_lite/include/ability_mgr_feature.h +++ b/services/abilitymgr_lite/include/ability_mgr_feature.h @@ -18,10 +18,13 @@ #include "ability_mgr_handler.h" #include "ability_service_interface.h" +#include "dmsfwk_interface.h" #include "feature.h" #include "iproxy_client.h" #include "iunknown.h" #include "nocopyable.h" +#define DISTRIBUTED_SCHEDULE_SERVICE "dtbschedsrv" +#define DMSLITE_FEATURE "dmslite" namespace OHOS { typedef int32 (*InvokeFunc)(const void *origin, IpcIo *req); @@ -46,6 +49,7 @@ public: private: AbilityMgrFeature(); static int32 StartAbilityInner(const Want *want, pid_t callingUid); + static int32 StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid); static int32 ConnectAbilityInner(const Want *want, SvcIdentity *svc, uint64_t token, pid_t callingUid); static int32 StopAbilityInner(const Want *want, pid_t callingUid); static int32 StartAbilityInvoke(const void *origin, IpcIo *req); diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index 4ca8788..e8d17cc 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -131,14 +131,46 @@ int32 AbilityMgrFeature::StartAbilityInvoke(const void *origin, IpcIo *req) if (!DeserializeWant(&want, req)) { return EC_FAILURE; } - int retVal = StartAbilityInner(&want, uid); + int32 retVal; + const char *deviceId = want.element->deviceId; + if (deviceId != nullptr && *deviceId != '\0') { + retVal = StartRemoteAbilityInner(&want, devideId, uid); + } else { + retVal = StartAbilityInner(&want, uid); + } ClearWant(&want); return retVal; } int32 AbilityMgrFeature::StartAbility(const Want *want) { - return StartAbilityInner(want, -1); + int32 retVal; + const char *deviceId = want.element->deviceId; + if (deviceId != nullptr && *deviceId != '\0') { + retVal = StartRemoteAbilityInner(&want, devideId, -1); + } else { + retVal = StartAbilityInner(want, -1); + } + return retVal; +} + +int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid) +{ + int32 retVal; + IUnknown *iUnknown = SAMGR_GetInstance()->getFeatureApi(DISTRIBUTED_SCHEDULE_SERVICE, DMSLITE_FEATURE); + DmsProxy *dmsInterface = NULL; + if (iUnknown == NULL) { + return EC_INVALID; + } + retVal = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void**) &dmsInterface); + if (retVal != EC_SUCCESS) { + return EC_INVALID; + } + CallerInfo callerInfo = { + .uid = uid + }; + retVal = dmsInterface->StartRemoteAbility((Want *)want, &callerInfo, NULL); + return retVal; } int32 AbilityMgrFeature::StartAbilityInner(const Want *want, pid_t callingUid) -- Gitee From a74ed945c19f5598e69a453a0db4b5593c72004f Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Tue, 27 Jul 2021 04:05:20 -0700 Subject: [PATCH 13/23] IssueNo:#I3ZZD0 Description:StartRemoteAbility Sig:aafwk Feature or Bugfix: Feature Binary Source: No --- services/abilitymgr_lite/src/ability_mgr_feature.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index e8d17cc..2935cdd 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -134,7 +134,7 @@ int32 AbilityMgrFeature::StartAbilityInvoke(const void *origin, IpcIo *req) int32 retVal; const char *deviceId = want.element->deviceId; if (deviceId != nullptr && *deviceId != '\0') { - retVal = StartRemoteAbilityInner(&want, devideId, uid); + retVal = StartRemoteAbilityInner(&want, deviceId, uid); } else { retVal = StartAbilityInner(&want, uid); } @@ -145,9 +145,9 @@ int32 AbilityMgrFeature::StartAbilityInvoke(const void *origin, IpcIo *req) int32 AbilityMgrFeature::StartAbility(const Want *want) { int32 retVal; - const char *deviceId = want.element->deviceId; + const char *deviceId = want->element->deviceId; if (deviceId != nullptr && *deviceId != '\0') { - retVal = StartRemoteAbilityInner(&want, devideId, -1); + retVal = StartRemoteAbilityInner(&want, deviceId, -1); } else { retVal = StartAbilityInner(want, -1); } @@ -157,7 +157,7 @@ int32 AbilityMgrFeature::StartAbility(const Want *want) int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid) { int32 retVal; - IUnknown *iUnknown = SAMGR_GetInstance()->getFeatureApi(DISTRIBUTED_SCHEDULE_SERVICE, DMSLITE_FEATURE); + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(DISTRIBUTED_SCHEDULE_SERVICE, DMSLITE_FEATURE); DmsProxy *dmsInterface = NULL; if (iUnknown == NULL) { return EC_INVALID; -- Gitee From 3410dc01aab0a2e254e8b65fda4c0b24c42a960a Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Tue, 27 Jul 2021 04:17:03 -0700 Subject: [PATCH 14/23] IssueNo:#I3ZZD0 Description:StartRemoteAbility Sig:aafwk Feature or Bugfix: Feature Binary Source: No --- services/abilitymgr_lite/src/ability_mgr_feature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index 2935cdd..3c5d0cc 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -147,7 +147,7 @@ int32 AbilityMgrFeature::StartAbility(const Want *want) int32 retVal; const char *deviceId = want->element->deviceId; if (deviceId != nullptr && *deviceId != '\0') { - retVal = StartRemoteAbilityInner(&want, deviceId, -1); + retVal = StartRemoteAbilityInner(want, deviceId, -1); } else { retVal = StartAbilityInner(want, -1); } -- Gitee From 25d562996db7a9179fc5558111bf3a1d9cb6d35c Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Tue, 27 Jul 2021 06:18:32 -0700 Subject: [PATCH 15/23] IssueNo:#I3ZZD0 Description:StartRemoteAbility Sig:aafwk Feature or Bugfix: Feature Binary Source: No --- services/abilitymgr_lite/src/ability_mgr_feature.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index 3c5d0cc..c0a0502 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -144,25 +144,17 @@ int32 AbilityMgrFeature::StartAbilityInvoke(const void *origin, IpcIo *req) int32 AbilityMgrFeature::StartAbility(const Want *want) { - int32 retVal; - const char *deviceId = want->element->deviceId; - if (deviceId != nullptr && *deviceId != '\0') { - retVal = StartRemoteAbilityInner(want, deviceId, -1); - } else { - retVal = StartAbilityInner(want, -1); - } - return retVal; + return StartAbilityInner(want, -1); } int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid) { - int32 retVal; IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(DISTRIBUTED_SCHEDULE_SERVICE, DMSLITE_FEATURE); DmsProxy *dmsInterface = NULL; if (iUnknown == NULL) { return EC_INVALID; } - retVal = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void**) &dmsInterface); + int32 retVal = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void**) &dmsInterface); if (retVal != EC_SUCCESS) { return EC_INVALID; } -- Gitee From 8a17b3b4b3a9dbbc522b2eda4e389ac498cb352c Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Wed, 28 Jul 2021 05:02:39 -0700 Subject: [PATCH 16/23] IssueNo:#I3ZZD0 Description:StartRemoteAbility Sig:aafwk Feature or Bugfix:Feature Binary Source:No Signed-off-by: qiudengcheng --- frameworks/abilitymgr_lite/BUILD.gn | 2 + .../abilitymgr_lite/src/ability_manager.cpp | 12 ++ frameworks/want_lite/include/want_utils.h | 10 ++ frameworks/want_lite/src/want.cpp | 139 ++++++++++++++++++ interfaces/kits/ability_lite/ability_errors.h | 6 + .../kits/ability_lite/ability_manager.h | 13 ++ interfaces/kits/want_lite/want.h | 37 +++++ services/abilitymgr_lite/BUILD.gn | 1 + .../include/ability_mgr_feature.h | 5 +- .../src/ability_mgr_feature.cpp | 40 ++++- 10 files changed, 260 insertions(+), 5 deletions(-) diff --git a/frameworks/abilitymgr_lite/BUILD.gn b/frameworks/abilitymgr_lite/BUILD.gn index e6f6180..1711438 100755 --- a/frameworks/abilitymgr_lite/BUILD.gn +++ b/frameworks/abilitymgr_lite/BUILD.gn @@ -19,7 +19,9 @@ lite_library("abilitymanager") { cflags_cc = cflags sources = [ + "src/ability_callback_utils.cpp", "src/ability_manager.cpp", + "src/ability_self_callback.cpp", "src/ability_service_manager.cpp", "src/abilityms_client.cpp", ] diff --git a/frameworks/abilitymgr_lite/src/ability_manager.cpp b/frameworks/abilitymgr_lite/src/ability_manager.cpp index c63b523..b36cc00 100755 --- a/frameworks/abilitymgr_lite/src/ability_manager.cpp +++ b/frameworks/abilitymgr_lite/src/ability_manager.cpp @@ -20,6 +20,7 @@ #include "ability_service_interface.h" #include "ability_service_manager.h" #include "abilityms_client.h" +#include "ability_self_callback.h" extern "C" { const int DEFAULT_TOKEN = 1; @@ -34,6 +35,17 @@ int StartAbility(const Want *want) return OHOS::AbilityMsClient::GetInstance().ScheduleAms(want, 0, nullptr, START_ABILITY); } +int StartAbilityWithCallback(const Want *want, AbilityClientCallback abilityClientCallback) +{ + if (want == nullptr || abilityClientCallback == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "want or callback is null, StartAbilityWithCallback failed!"); + return -1; + } + const SvcIdentity *svc = OHOS::AbilitySelfCallback::GetInstance().RegisterAbilitySelfCallback(abilityClientCallback); + OHOS::AbilityMsClient::GetInstance().Initialize(); + return OHOS::AbilityMsClient::GetInstance().ScheduleAms(want, 0, svc, START_ABILITY); +} + int StopAbility(const Want *want) { if (want == nullptr) { diff --git a/frameworks/want_lite/include/want_utils.h b/frameworks/want_lite/include/want_utils.h index e9c955e..171ebe3 100644 --- a/frameworks/want_lite/include/want_utils.h +++ b/frameworks/want_lite/include/want_utils.h @@ -18,6 +18,12 @@ #include "want.h" +typedef struct { + uint8_t type = 0; + void *entity = nullptr; + uint8_t totalLen = 0; +} Tlv; + #ifdef __cplusplus #if __cplusplus extern "C" { @@ -29,6 +35,10 @@ extern "C" { bool SerializeWant(IpcIo *io, const Want *want); bool DeserializeWant(Want *want, IpcIo *io); +void FreeTlvStruct(Tlv *tlv); +bool UpdateWantData(Want *want, Tlv *tlv); +Tlv *EncapTlv(uint8_t type, uint8_t length, void *value, uint8_t valueLen); +Tlv *CombineKeyValueTlv(Tlv *keyTlv, Tlv *valueTlv); #endif #ifdef __cplusplus diff --git a/frameworks/want_lite/src/want.cpp b/frameworks/want_lite/src/want.cpp index 1525463..cd79063 100755 --- a/frameworks/want_lite/src/want.cpp +++ b/frameworks/want_lite/src/want.cpp @@ -51,6 +51,9 @@ constexpr static char URI_SEPARATOR = ';'; constexpr static int VALUE_NULL = 0; constexpr static int VALUE_OBJECT = 1; constexpr static int DATA_LENGTH = 2048; +constexpr uint8_t INT_VALUE_TYPE = 6; +constexpr uint8_t STRING_VALUE_TYPE = 13; +constexpr uint8_t KEY_VALUE_PAIR_TYPE = 97; #endif void ClearWant(Want *want) @@ -85,6 +88,142 @@ bool SetWantElement(Want *want, ElementName element) return true; } +Tlv *EncapTlv(uint8_t type, uint8_t length, void *value, uint8_t valueLen) +{ + void *entity = nullptr; + + // Tlv header can only has 2 bytes. + uint8_t totalLen = valueLen + 2; + entity = calloc(1, totalLen); + if (entity == nullptr) { + AdapterFree(entity); + return nullptr; + } + + if (memcpy_s((unsigned char *)entity, 1, &type, 1) != 0 || + memcpy_s((unsigned char *)entity + 1, 1, &length, 1) != 0 || + memcpy_s((unsigned char *)entity + 2, valueLen, value, valueLen) != 0) { + AdapterFree(entity); + return nullptr; + } + + Tlv *newTlv = new Tlv(); + newTlv->type = type; + newTlv->entity = entity; + newTlv->totalLen = totalLen; + return newTlv; +} + +void FreeTlvStruct(Tlv *tlv) +{ + AdapterFree(tlv->entity); + AdapterFree(tlv); +} + +Tlv *CombineKeyValueTlv(Tlv *keyTlv, Tlv *valueTlv) +{ + uint8_t newTlvValueLen = keyTlv->totalLen + valueTlv->totalLen; + void *newTlvValue = calloc(1, newTlvValueLen); + if (newTlvValue == nullptr) { + return nullptr; + } + if (memcpy_s((unsigned char *)newTlvValue, keyTlv->totalLen, keyTlv->entity, keyTlv->totalLen) != 0 || + memcpy_s((unsigned char *)newTlvValue + keyTlv->totalLen, valueTlv->totalLen, valueTlv->entity, valueTlv->totalLen) != 0) { + AdapterFree(newTlvValue); + return nullptr; + } + + Tlv *newTlv = EncapTlv(KEY_VALUE_PAIR_TYPE, newTlvValueLen, newTlvValue, newTlvValueLen); + AdapterFree(newTlvValue); + return newTlv; +} + +bool UpdateWantData(Want *want, Tlv *tlv) +{ + bool result = false; + if (want->data != nullptr) { + void *newWantData = calloc(1, tlv->totalLen + want->dataLength); + if (newWantData == nullptr) { + return result; + } + if (memcpy_s(newWantData, want->dataLength, want->data, want->dataLength) != 0 || + memcpy_s((unsigned char*)newWantData + want->dataLength, tlv->totalLen, tlv->entity, tlv->totalLen) != 0) { + AdapterFree(want->data); + return result; + } + AdapterFree(want->data); + want->data = newWantData; + want->dataLength = tlv->totalLen + want->dataLength; + result = true; + } else { + want->data = tlv->entity; + want->dataLength = tlv->totalLen; + result = true; + } + return result; +} + +bool SetIntParam(Want *want, const char *key, int8_t keyLen, int32_t value) +{ + bool result = false; + if (keyLen <= 0) { + return result; + } + + Tlv *keyTlv = EncapTlv(STRING_VALUE_TYPE, keyLen, (void *)key, keyLen); + if (keyTlv == nullptr) { + return result; + } + unsigned char intBuffer[4] = {0}; + for (int i = 0; i < 4; i++) { + intBuffer[i] = value >> (8 * (3- i)); + } + Tlv *valueTlv = EncapTlv(INT_VALUE_TYPE, sizeof(int), (void *)intBuffer, sizeof(int)); + if (valueTlv == nullptr) { + FreeTlvStruct(keyTlv); + return result; + } + Tlv *newTlv = CombineKeyValueTlv(keyTlv, valueTlv); + FreeTlvStruct(keyTlv); + FreeTlvStruct(valueTlv); + if (newTlv == nullptr) { + return result; + } + if (UpdateWantData(want, newTlv)) { + AdapterFree(newTlv); + } + return result; +} + +bool SetStrParam(Want *want, const char *key, int8_t keyLen, const char *value, int8_t valueLen) +{ + bool result = false; + if (keyLen <= 0 || valueLen <= 0) { + return result; + } + + Tlv *keyTlv = EncapTlv(STRING_VALUE_TYPE, keyLen, (void *)key, keyLen); + if (keyTlv == nullptr) { + return result; + } + + Tlv *valueTlv = EncapTlv(STRING_VALUE_TYPE, valueLen, (void *)value, valueLen); + if (valueTlv == nullptr) { + FreeTlvStruct(keyTlv); + return result; + } + Tlv *newTlv = CombineKeyValueTlv(keyTlv, valueTlv); + FreeTlvStruct(keyTlv); + FreeTlvStruct(valueTlv); + if (newTlv == nullptr) { + return result; + } + if (UpdateWantData(want, newTlv)) { + AdapterFree(newTlv); + } + return result; +} + #ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER bool SetWantSvcIdentity(Want *want, SvcIdentity sid) { diff --git a/interfaces/kits/ability_lite/ability_errors.h b/interfaces/kits/ability_lite/ability_errors.h index ca007b5..4701cd8 100755 --- a/interfaces/kits/ability_lite/ability_errors.h +++ b/interfaces/kits/ability_lite/ability_errors.h @@ -71,6 +71,12 @@ enum { /** The parameter is error. */ PARAM_CHECK_ERROR, + /** Get callback type error. */ + GET_CALLBACK_TYPE_ERROR, + + /** Generate callback local serviceId error. */ + CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED, + /** Command error. */ COMMAND_ERROR = 0x7fff, }; diff --git a/interfaces/kits/ability_lite/ability_manager.h b/interfaces/kits/ability_lite/ability_manager.h index b4122b5..4e8da39 100644 --- a/interfaces/kits/ability_lite/ability_manager.h +++ b/interfaces/kits/ability_lite/ability_manager.h @@ -49,6 +49,19 @@ extern "C" { #endif #endif /* __cplusplus */ +/** + * @brief Called when desired ability has been started. + * + * This function can be registered through {@link StartAbility} to receive the start ability result. + * + * @param resultCode Indicates the status code returned for starting ability result. For details, see {@link AppexecfwkErrors}. + * @param resultMessage Indicates the result message returned with the status code. + * + * @since 6.0 + * @version 6.0 + */ +typedef void (*AbilityClientCallback)(const uint8_t resultCode, const void *resultMessage); + /** * @brief Starts an ability based on the specified {@link Want} information. * diff --git a/interfaces/kits/want_lite/want.h b/interfaces/kits/want_lite/want.h index c1f1f3e..faa1db0 100644 --- a/interfaces/kits/want_lite/want.h +++ b/interfaces/kits/want_lite/want.h @@ -92,6 +92,43 @@ extern "C" { */ void ClearWant(Want *want); +/** + * @brief Sets key and value to the want which would be passed to remote deive to start remote ability. + * + * @param want Indicates the pointer to the Want object to set. + * @param key Indicates the pointer to the key which would be added to the want. + * @param keyLen Indicates the length of key. + * @param value Indicate the int value which would be added to the want. + * + * @return Returns true if the setting is successful; returns false otherwise. + */ +bool SetIntParam(Want *want, const char *key, uint8_t keyLen, int32_t value); + +/** + * @brief Sets key and value to the want which would be passed to remote deive to start remote ability. + * + * @param want Indicates the pointer to the Want object to set. + * @param key Indicates the pointer to the key which would be added to the want. + * @param keyLen Indicates the length of key. + * @param value Indicate the pointer to the value which would be added to the want. + * + * @return Returns true if the setting is successful; returns false otherwise. + */ +bool SetStrParam(Want *want, const char *key, uint8_t keyLen, const char *value, uint8_t valueLen); + +/** + * @brief Sets the element variable for a specified Want object. + * + * To start a specified ability, you should call this function to set the {@link ElementName} required for starting + * the ability. + * + * @param want Indicates the pointer to the Want object to set. + * @param element Indicates the {@link ElementName} containing information required for starting the ability. + * + * @return Returns true if the setting is successful; returns false otherwise. + */ +bool SetWantElement(Want *want, ElementName element); + /** * @brief Sets the element variable for a specified Want object. * diff --git a/services/abilitymgr_lite/BUILD.gn b/services/abilitymgr_lite/BUILD.gn index ffcd552..9b0aa26 100644 --- a/services/abilitymgr_lite/BUILD.gn +++ b/services/abilitymgr_lite/BUILD.gn @@ -72,6 +72,7 @@ lite_library("abilityms") { "${aafwk_lite_path}/interfaces/kits/want_lite", "${aafwk_lite_path}/frameworks/want_lite/include", "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", + "${aafwk_lite_path}/frameworks/abilitymgr_lite/include", "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", "${appexecfwk_lite_path}/utils/bundle_lite", "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", diff --git a/services/abilitymgr_lite/include/ability_mgr_feature.h b/services/abilitymgr_lite/include/ability_mgr_feature.h index 7f782c1..fe73e3e 100755 --- a/services/abilitymgr_lite/include/ability_mgr_feature.h +++ b/services/abilitymgr_lite/include/ability_mgr_feature.h @@ -28,6 +28,7 @@ namespace OHOS { typedef int32 (*InvokeFunc)(const void *origin, IpcIo *req); +typedef void (*OnRequestCallbackFunc)(const void *data, int32_t ret); class AbilityMgrFeature : public Feature { public: @@ -49,7 +50,7 @@ public: private: AbilityMgrFeature(); static int32 StartAbilityInner(const Want *want, pid_t callingUid); - static int32 StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid); + static int32 StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid, OnRequestCallbackFunc callback); static int32 ConnectAbilityInner(const Want *want, SvcIdentity *svc, uint64_t token, pid_t callingUid); static int32 StopAbilityInner(const Want *want, pid_t callingUid); static int32 StartAbilityInvoke(const void *origin, IpcIo *req); @@ -68,9 +69,11 @@ private: static void OnFeatureInitialize(Feature *feature, Service *parent, Identity identity); static void OnFeatureStop(Feature *feature, Identity identity); static BOOL OnFeatureMessage(Feature *feature, Request *request); + static void OnRequestCallback(const void *data, int32_t ret); private: Identity identity_; + static SvcIdentity *svc_; static InvokeFunc invokeFuncList[INNER_BEGIN]; DISALLOW_COPY_AND_MOVE(AbilityMgrFeature); }; diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index c0a0502..4301200 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -15,6 +15,7 @@ #include "ability_mgr_feature.h" +#include "ability_callback_utils.h" #include "ability_connect_trans_param.h" #include "ability_errors.h" #include "ability_info.h" @@ -120,6 +121,22 @@ BOOL AbilityMgrFeature::OnFeatureMessage(Feature *feature, Request *request) return TRUE; } +void AbilityMgrFeature::OnRequestCallback(const void *data, int32_t ret) +{ + IpcIo io; + char ipcData[IPC_IO_DATA_MAX]; + IpcIo reply; + IpcIoInit(&io, ipcData, IPC_IO_DATA_MAX, 0); + IpcIoPushInt32(&io, static_cast(ret)); + int32_t transRet = Transact(NULL, *svc_, START_ABILITY_CALLBACK, &io, &reply, LITEIPC_FLAG_ONEWAY, NULL); + if (ret != LITEIPC_OK) { + HILOG_ERROR(HILOG_MODULE_APP, "AbilityManagerFeature InnerSelfTransact fialed %{public}d\n", ret); + } + #ifdef __LINUX__ + BinderRelease(svc_->ipcContext, svc_->handle); + #endif +} + int32 AbilityMgrFeature::StartAbilityInvoke(const void *origin, IpcIo *req) { pid_t uid = GetCallingUid(origin); @@ -131,10 +148,21 @@ int32 AbilityMgrFeature::StartAbilityInvoke(const void *origin, IpcIo *req) if (!DeserializeWant(&want, req)) { return EC_FAILURE; } - int32 retVal; + SvcIdentity *svc = IpcIoPopSvc(req); + if (svc_ != nullptr) { + AdapterFree(svc_); + } + if (svc != nullptr) { + svc_ = svc; + } + if (want.element == nullptr) { + PRINTE("AbilityMgrFeature", "invalid argument"); + return EC_INVALID; + } const char *deviceId = want.element->deviceId; + int32 retVal; if (deviceId != nullptr && *deviceId != '\0') { - retVal = StartRemoteAbilityInner(&want, deviceId, uid); + retVal = StartRemoteAbilityInner(&want, deviceId, uid, OnRequestCallback); } else { retVal = StartAbilityInner(&want, uid); } @@ -147,8 +175,12 @@ int32 AbilityMgrFeature::StartAbility(const Want *want) return StartAbilityInner(want, -1); } -int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid) +int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid, OnRequestCallbackFunc callback) { + IDmsListener *myCallback = new IDmsListener(); + if (callback != nullptr) { + myCallback->OnResultCallback = callback; + } IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(DISTRIBUTED_SCHEDULE_SERVICE, DMSLITE_FEATURE); DmsProxy *dmsInterface = NULL; if (iUnknown == NULL) { @@ -161,7 +193,7 @@ int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *d CallerInfo callerInfo = { .uid = uid }; - retVal = dmsInterface->StartRemoteAbility((Want *)want, &callerInfo, NULL); + retVal = dmsInterface->StartRemoteAbility((Want *)want, &callerInfo, myCallback); return retVal; } -- Gitee From 35477b4e94ab8c85eb08bbd62e8a7bc1bdc6ead0 Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Wed, 28 Jul 2021 06:01:57 -0700 Subject: [PATCH 17/23] IssueNo:#I42UOJ Description:StartRemoteAbility With Callback Sig:aafwk Feature or Bugfix:Feature Binary Source:No Signed-off-by: qiudengcheng --- frameworks/want_lite/src/want.cpp | 6 +----- services/abilitymgr_lite/src/ability_mgr_feature.cpp | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/frameworks/want_lite/src/want.cpp b/frameworks/want_lite/src/want.cpp index cd79063..9d7f092 100755 --- a/frameworks/want_lite/src/want.cpp +++ b/frameworks/want_lite/src/want.cpp @@ -95,10 +95,6 @@ Tlv *EncapTlv(uint8_t type, uint8_t length, void *value, uint8_t valueLen) // Tlv header can only has 2 bytes. uint8_t totalLen = valueLen + 2; entity = calloc(1, totalLen); - if (entity == nullptr) { - AdapterFree(entity); - return nullptr; - } if (memcpy_s((unsigned char *)entity, 1, &type, 1) != 0 || memcpy_s((unsigned char *)entity + 1, 1, &length, 1) != 0 || @@ -148,7 +144,7 @@ bool UpdateWantData(Want *want, Tlv *tlv) } if (memcpy_s(newWantData, want->dataLength, want->data, want->dataLength) != 0 || memcpy_s((unsigned char*)newWantData + want->dataLength, tlv->totalLen, tlv->entity, tlv->totalLen) != 0) { - AdapterFree(want->data); + AdapterFree(newWantData); return result; } AdapterFree(want->data); diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index 4301200..f3c2c96 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -129,7 +129,7 @@ void AbilityMgrFeature::OnRequestCallback(const void *data, int32_t ret) IpcIoInit(&io, ipcData, IPC_IO_DATA_MAX, 0); IpcIoPushInt32(&io, static_cast(ret)); int32_t transRet = Transact(NULL, *svc_, START_ABILITY_CALLBACK, &io, &reply, LITEIPC_FLAG_ONEWAY, NULL); - if (ret != LITEIPC_OK) { + if (transRet != LITEIPC_OK) { HILOG_ERROR(HILOG_MODULE_APP, "AbilityManagerFeature InnerSelfTransact fialed %{public}d\n", ret); } #ifdef __LINUX__ -- Gitee From 36698a85c1ab0ababb1e4227abe7dae97ede025a Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Wed, 28 Jul 2021 06:20:32 -0700 Subject: [PATCH 18/23] IssueNo:#I42UOJ Description:StartRemoteAbility With Callback Sig:aafwk Feature or Bugfix:Feature Binary Source:No Signed-off-by: qiudengcheng --- frameworks/want_lite/src/want.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/want_lite/src/want.cpp b/frameworks/want_lite/src/want.cpp index 9d7f092..f7ac6cc 100755 --- a/frameworks/want_lite/src/want.cpp +++ b/frameworks/want_lite/src/want.cpp @@ -187,6 +187,7 @@ bool SetIntParam(Want *want, const char *key, int8_t keyLen, int32_t value) } if (UpdateWantData(want, newTlv)) { AdapterFree(newTlv); + result = true; } return result; } @@ -216,6 +217,7 @@ bool SetStrParam(Want *want, const char *key, int8_t keyLen, const char *value, } if (UpdateWantData(want, newTlv)) { AdapterFree(newTlv); + result = true; } return result; } -- Gitee From e57d720ec89a62e50d906a9607db8d10492ae7fe Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Wed, 28 Jul 2021 06:27:24 -0700 Subject: [PATCH 19/23] IssueNo:#I42UOJ Description:StartRemoteAbility With Callback Sig:aafwk Feature or Bugfix:Feature Binary Source:No Signed-off-by: qiudengcheng --- .../include/ability_callback_utils.h | 34 ++++++ .../include/ability_self_callback.h | 47 +++++++ .../src/ability_callback_utils.cpp | 45 +++++++ .../src/ability_self_callback.cpp | 115 ++++++++++++++++++ 4 files changed, 241 insertions(+) create mode 100755 frameworks/abilitymgr_lite/include/ability_callback_utils.h create mode 100755 frameworks/abilitymgr_lite/include/ability_self_callback.h create mode 100755 frameworks/abilitymgr_lite/src/ability_callback_utils.cpp create mode 100755 frameworks/abilitymgr_lite/src/ability_self_callback.cpp diff --git a/frameworks/abilitymgr_lite/include/ability_callback_utils.h b/frameworks/abilitymgr_lite/include/ability_callback_utils.h new file mode 100755 index 0000000..56f4ea2 --- /dev/null +++ b/frameworks/abilitymgr_lite/include/ability_callback_utils.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 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_CALLBACK_UTILS_H +#define OHOS_ABILITY_CALLBACK_UTILS_H + +#include + +#include "ability_info.h" +#include "ability_errors.h" +#include "ability_manager.h" + +namespace OHOS { +constexpr char START_ABILITY_SUCCESS[] = "Start ability success!"; + +enum { + START_ABILITY_CALLBACK +}; + +std::string ObtainErrorMessage(uint8_t errorCode); +} // namespace +#endif // OHOS_ABILITY_CALLBACK_UTILS_H \ No newline at end of file diff --git a/frameworks/abilitymgr_lite/include/ability_self_callback.h b/frameworks/abilitymgr_lite/include/ability_self_callback.h new file mode 100755 index 0000000..eca1f84 --- /dev/null +++ b/frameworks/abilitymgr_lite/include/ability_self_callback.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 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_SELF_CALLBACK_H +#define OHOS_ABILITY_SELF_CALLBACK_H + +#include +#include + +#include "ability_manager.h" +#include "liteipc_adapter.h" +#include "nocopyable.h" + +namespace OHOS { +class AbilitySelfCallback { +public: + static AbilitySelfCallback &GetInstance() + { + static AbilitySelfCallback instance; + return instance; + } + ~AbilitySelfCallback(); + const SvcIdentity *RegisterAbilitySelfCallback(AbilityClientCallback &abilityClientCallback); + const AbilityClientCallback GetCallback(); +private: + AbilitySelfCallback() = default; + static int32_t Callback(const IpcContext *context, void *ipcMsg, IpcIo *io, void *arg); + int32_t GenerateLocalServiceId(); + AbilityClientCallback abilityClientCallback_ { nullptr }; + SvcIdentity *svcIdentity_ { nullptr }; + + DISALLOW_COPY_AND_MOVE(AbilitySelfCallback); +}; +} // namespace +#endif // OHOS_ABILITY_SELF_CALLBACK_H \ No newline at end of file diff --git a/frameworks/abilitymgr_lite/src/ability_callback_utils.cpp b/frameworks/abilitymgr_lite/src/ability_callback_utils.cpp new file mode 100755 index 0000000..148f817 --- /dev/null +++ b/frameworks/abilitymgr_lite/src/ability_callback_utils.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 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 "ability_callback_utils.h" + +namespace OHOS { +std::string ObtainErrorMessage(uint8_t errorCode) +{ + switch (errorCode) { + case PARAM_NULL_ERROR: + return "PARAM_NULL_ERROR"; + case MEMORY_MALLOC_ERROR: + return "MEMORY_MALLOC_ERROR"; + case DUMP_ABILITIES_ERROR: + return "DUMP_ABILITIES_ERROR"; + case IPC_REQUEST_ERROR: + return "IPC_REQUEST_ERROR"; + case SERIALIZE_ERROR: + return "SERIALIZE_ERROR"; + case CREATE_APPTASK_ERROR: + return "CREATE_APPTASK_ERROR"; + case SCHEDULER_LIFECYCLE_ERROR: + return "SCHEDULER_LIFECYCLE_ERROR"; + case PARAM_CHECK_ERROR: + return "PARAM_CHECK_ERROR"; + case COMMAND_ERROR: + return "COMMAND_ERROR"; + default: { + return ""; + } + } +} +} // namespace \ No newline at end of file diff --git a/frameworks/abilitymgr_lite/src/ability_self_callback.cpp b/frameworks/abilitymgr_lite/src/ability_self_callback.cpp new file mode 100755 index 0000000..fbc1f65 --- /dev/null +++ b/frameworks/abilitymgr_lite/src/ability_self_callback.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020 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 "ability_self_callback.h" + +#include "adapter.h" +#include "ability_callback_utils.h" +#include "ability_manager.h" +#include "iproxy_client.h" +#include "log.h" +#include "samgr_lite.h" + +namespace OHOS { +AbilitySelfCallback::~AbilitySelfCallback() +{ + if (svcIdentity_ != nullptr) { + (void) UnregisterIpcCallback(*svcIdentity_); + AdapterFree(svcIdentity_); + } +} + +int32_t InnerCallback(const char *resultMessage, uint8_t resultCode, const AbilityClientCallback &abilityClientCallback) +{ + if (resultMessage == nullptr || abilityClientCallback == nullptr) { + return PARAM_NULL_ERROR; + } + if (resultCode == ERR_OK) { + abilityClientCallback(resultCode, resultMessage); + } else { + abilityClientCallback(resultCode, ObtainErrorMessage(resultCode).c_str()); + } + return ERR_OK; +} + +int32_t AbilitySelfCallback::Callback(const IpcContext *context, void *ipcMsg, IpcIo *io, void *arg) +{ + if (ipcMsg == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "AbilitySelfCallback ipcMsg is nullptr"); + return PARAM_NULL_ERROR; + } + + if (io == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "AbilitySelfCallback io is nullptr"); + FreeBuffer(NULL, ipcMsg); + return PARAM_NULL_ERROR; + } + AbilityClientCallback abilityClientCallback = GetInstance().GetCallback(); + if (abilityClientCallback == nullptr) { + FreeBuffer(NULL, ipcMsg); + return PARAM_NULL_ERROR; + } + uint32_t callbackType = 0; + int32_t ret = GetCode(ipcMsg, &callbackType); + if (ret != LITEIPC_OK) { + FreeBuffer(NULL, ipcMsg); + HILOG_ERROR(HILOG_MODULE_APP, "AbilitySelfCallbck get callback type failed"); + return GET_CALLBACK_TYPE_ERROR; + } + auto resultCode = static_cast(IpcIoPopInt32(io)); + FreeBuffer(NULL, ipcMsg); + if (callbackType == START_ABILITY_CALLBACK) { + return InnerCallback(START_ABILITY_SUCCESS, resultCode, abilityClientCallback); + } + HILOG_ERROR(HILOG_MODULE_APP, "AbilitySelfCallback get error callback type"); + return GET_CALLBACK_TYPE_ERROR; +} + +int32 AbilitySelfCallback::GenerateLocalServiceId() +{ + svcIdentity_ = reinterpret_cast(AdapterMalloc(sizeof(SvcIdentity))); + if (svcIdentity_ == nullptr) { + return CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED; + } + + int32_t ret = RegisterIpcCallback(Callback, 0, IPC_WAIT_FOREVER, svcIdentity_, NULL); + if (ret != LITEIPC_OK) { + AdapterFree(svcIdentity_); + svcIdentity_ = nullptr; + return CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED; + } + return ERR_OK; +} + +const SvcIdentity *AbilitySelfCallback::RegisterAbilitySelfCallback(AbilityClientCallback &abilityClientCallback) +{ + if (abilityClientCallback == nullptr) { + return nullptr; + } + if (svcIdentity_ == nullptr) { + int32 ret = GenerateLocalServiceId(); + if (ret != ERR_OK) { + return nullptr; + } + } + abilityClientCallback_ = abilityClientCallback; + return svcIdentity_; +} + +const AbilityClientCallback AbilitySelfCallback::GetCallback() +{ + return abilityClientCallback_; +} +} // namespace \ No newline at end of file -- Gitee From c64cb0abb528973a38d43b5b47b9b038ddb47ba7 Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Wed, 28 Jul 2021 06:46:50 -0700 Subject: [PATCH 20/23] IssueNo:#I42UOJ Description:StartRemoteAbility With Callback Sig:aafwk Feature or Bugfix:Feature Binary Source:No Signed-off-by: qiudengcheng --- services/abilitymgr_lite/include/ability_mgr_feature.h | 1 + services/abilitymgr_lite/src/ability_mgr_feature.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/abilitymgr_lite/include/ability_mgr_feature.h b/services/abilitymgr_lite/include/ability_mgr_feature.h index fe73e3e..f305583 100755 --- a/services/abilitymgr_lite/include/ability_mgr_feature.h +++ b/services/abilitymgr_lite/include/ability_mgr_feature.h @@ -74,6 +74,7 @@ private: private: Identity identity_; static SvcIdentity *svc_; + static IDmsListener *myCallback_; static InvokeFunc invokeFuncList[INNER_BEGIN]; DISALLOW_COPY_AND_MOVE(AbilityMgrFeature); }; diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index f3c2c96..b834e28 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -109,6 +109,7 @@ void AbilityMgrFeature::OnFeatureStop(Feature *feature, Identity identity) { (void) feature; (void) identity; + AdapterFree(myCallback_); } BOOL AbilityMgrFeature::OnFeatureMessage(Feature *feature, Request *request) @@ -177,9 +178,11 @@ int32 AbilityMgrFeature::StartAbility(const Want *want) int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *deviceId, pid_t uid, OnRequestCallbackFunc callback) { - IDmsListener *myCallback = new IDmsListener(); + if (myCallback_ == nullptr) { + myCallback_ = new IDmsListener(); + } if (callback != nullptr) { - myCallback->OnResultCallback = callback; + myCallback_->OnResultCallback = callback; } IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(DISTRIBUTED_SCHEDULE_SERVICE, DMSLITE_FEATURE); DmsProxy *dmsInterface = NULL; @@ -193,7 +196,7 @@ int32 AbilityMgrFeature::StartRemoteAbilityInner(const Want *want, const char *d CallerInfo callerInfo = { .uid = uid }; - retVal = dmsInterface->StartRemoteAbility((Want *)want, &callerInfo, myCallback); + retVal = dmsInterface->StartRemoteAbility((Want *)want, &callerInfo, myCallback_); return retVal; } -- Gitee From dd73287d29307a8018182d47060a0c8561773e31 Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Wed, 28 Jul 2021 21:01:10 -0700 Subject: [PATCH 21/23] IssueNo:#I42UOJ Description:StartRemoteAbility With Callback Sig:aafwk Feature or Bugfix:Feature Binary Source:No Signed-off-by: qiudengcheng --- services/abilitymgr_lite/src/ability_mgr_feature.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index b834e28..cd2ad35 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -32,6 +32,9 @@ #include "want_utils.h" namespace OHOS { +SvcIdentity * AbilityMgrFeature::svc_ = nullptr; +IDmsListener* AbilityMgrFeature::myCallback_ = nullptr; + AbilityMgrFeatureImpl g_amsImpl = { SERVER_IPROXY_IMPL_BEGIN, .Invoke = AbilityMgrFeature::Invoke, @@ -110,6 +113,7 @@ void AbilityMgrFeature::OnFeatureStop(Feature *feature, Identity identity) (void) feature; (void) identity; AdapterFree(myCallback_); + AdapterFree(svc_); } BOOL AbilityMgrFeature::OnFeatureMessage(Feature *feature, Request *request) -- Gitee From a9ca13f0af8409904459eaf15c7948af8665fc66 Mon Sep 17 00:00:00 2001 From: qiudengcheng Date: Fri, 30 Jul 2021 20:19:11 -0700 Subject: [PATCH 22/23] IssueNo:#I439VD Description:StartRemoteAbility Callback caused Crash Sig:aafwk Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: qiudengcheng --- .../include/ability_mgr_feature.h | 2 +- .../abilitymgr_lite/src/ability_mgr_feature.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/abilitymgr_lite/include/ability_mgr_feature.h b/services/abilitymgr_lite/include/ability_mgr_feature.h index f305583..4bbcafb 100755 --- a/services/abilitymgr_lite/include/ability_mgr_feature.h +++ b/services/abilitymgr_lite/include/ability_mgr_feature.h @@ -73,7 +73,7 @@ private: private: Identity identity_; - static SvcIdentity *svc_; + static SvcIdentity svc_; static IDmsListener *myCallback_; static InvokeFunc invokeFuncList[INNER_BEGIN]; DISALLOW_COPY_AND_MOVE(AbilityMgrFeature); diff --git a/services/abilitymgr_lite/src/ability_mgr_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_feature.cpp index cd2ad35..44f4d12 100644 --- a/services/abilitymgr_lite/src/ability_mgr_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_feature.cpp @@ -32,7 +32,7 @@ #include "want_utils.h" namespace OHOS { -SvcIdentity * AbilityMgrFeature::svc_ = nullptr; +SvcIdentity AbilityMgrFeature::svc_ = {0}; IDmsListener* AbilityMgrFeature::myCallback_ = nullptr; AbilityMgrFeatureImpl g_amsImpl = { @@ -113,7 +113,6 @@ void AbilityMgrFeature::OnFeatureStop(Feature *feature, Identity identity) (void) feature; (void) identity; AdapterFree(myCallback_); - AdapterFree(svc_); } BOOL AbilityMgrFeature::OnFeatureMessage(Feature *feature, Request *request) @@ -133,12 +132,12 @@ void AbilityMgrFeature::OnRequestCallback(const void *data, int32_t ret) IpcIo reply; IpcIoInit(&io, ipcData, IPC_IO_DATA_MAX, 0); IpcIoPushInt32(&io, static_cast(ret)); - int32_t transRet = Transact(NULL, *svc_, START_ABILITY_CALLBACK, &io, &reply, LITEIPC_FLAG_ONEWAY, NULL); + int32_t transRet = Transact(NULL, svc_, START_ABILITY_CALLBACK, &io, &reply, LITEIPC_FLAG_ONEWAY, NULL); if (transRet != LITEIPC_OK) { HILOG_ERROR(HILOG_MODULE_APP, "AbilityManagerFeature InnerSelfTransact fialed %{public}d\n", ret); } #ifdef __LINUX__ - BinderRelease(svc_->ipcContext, svc_->handle); + BinderRelease(svc_.ipcContext, svc_.handle); #endif } @@ -154,11 +153,12 @@ int32 AbilityMgrFeature::StartAbilityInvoke(const void *origin, IpcIo *req) return EC_FAILURE; } SvcIdentity *svc = IpcIoPopSvc(req); - if (svc_ != nullptr) { - AdapterFree(svc_); - } if (svc != nullptr) { - svc_ = svc; + svc_ = *svc; + } else { + PRINTE("AbilityMgrFeature", "invalid svc"); + svc_ = {0}; + return EC_INVALID; } if (want.element == nullptr) { PRINTE("AbilityMgrFeature", "invalid argument"); -- Gitee From 7b2240139d7289ba6c5f446b4e4e3f380c001a48 Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Sun, 1 Aug 2021 13:21:26 +0800 Subject: [PATCH 23/23] fix bugs Signed-off-by: zhaoyuan --- services/abilitymgr_lite/include/ability_service.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/abilitymgr_lite/include/ability_service.h b/services/abilitymgr_lite/include/ability_service.h index 787a723..999c401 100755 --- a/services/abilitymgr_lite/include/ability_service.h +++ b/services/abilitymgr_lite/include/ability_service.h @@ -26,6 +26,7 @@ #include "nocopyable.h" #include "want.h" #include "slite_ability.h" +#include "ability_state.h" namespace OHOS { struct AbilitySvcInfo { -- Gitee