From 5cb9c7f6b7cd922e99307b6cd81f46396604aa74 Mon Sep 17 00:00:00 2001 From: autumn330 Date: Sat, 3 Apr 2021 23:15:15 +0800 Subject: [PATCH 1/4] IssueNo:#I3EV3K Description:Force stop bundle interface. Sig:aafwk Feature or Bugfix: Bugfix Binary Source: No --- .../include/abilityms_slite_client.h | 4 + .../src/slite/ability_manager_inner.cpp | 10 ++ .../src/slite/abilityms_slite_client.cpp | 23 +++ .../ability_service_interface.h | 2 + .../slite/ability_manager_inner.h | 28 ++++ .../kits/ability_lite/slite/ability_manager.h | 6 + .../include/ability_mgr_slite_feature.h | 2 + .../abilitymgr_lite/include/ability_service.h | 3 + .../src/ability_mgr_service.cpp | 4 +- .../src/ability_mgr_slite_feature.cpp | 13 ++ .../abilitymgr_lite/src/ability_service.cpp | 135 +++++++++++++----- 11 files changed, 192 insertions(+), 38 deletions(-) diff --git a/frameworks/abilitymgr_lite/include/abilityms_slite_client.h b/frameworks/abilitymgr_lite/include/abilityms_slite_client.h index b1feab9..21e71ed 100755 --- a/frameworks/abilitymgr_lite/include/abilityms_slite_client.h +++ b/frameworks/abilitymgr_lite/include/abilityms_slite_client.h @@ -40,6 +40,10 @@ public: int SchedulerLifecycleDone(uint64_t token, int state) const; + int ForceStopBundle(uint64_t token) const; + + ElementName *GetTopAbility() const; + private: AbilityMsClient() = default; diff --git a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp index 7d36ad1..f2e2cfe 100755 --- a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp +++ b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp @@ -27,4 +27,14 @@ int SchedulerLifecycleDone(uint64_t token, int state) { return OHOS::AbilityMsClient::GetInstance().SchedulerLifecycleDone(token, state); } + +int ForceStopBundle(uint64_t token) +{ + return OHOS::AbilityMsClient::GetInstance().ForceStopBundle(token); +} + +ElementName *GetTopAbility() +{ + return OHOS::AbilityMsClient::GetInstance().GetTopAbility(); +} } diff --git a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp index 0d61854..a93a371 100755 --- a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp +++ b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp @@ -112,4 +112,27 @@ int AbilityMsClient::SchedulerLifecycleDone(uint64_t token, int state) const }; return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); } + +int AbilityMsClient::ForceStopBundle(uint64_t token) const +{ + AbilityMgrService *service = AbilityMgrService::GetInstance(); + if (service == nullptr) { + return PARAM_CHECK_ERROR; + } + Request request = { + .msgId = TERMINATE_APP, + .data = nullptr, + .len = 0, + .msgValue = static_cast(token & 0xFFFF), + }; + return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr); +} + +ElementName *AbilityMsClient::GetTopAbility() const +{ + if (!Initialize()) { + return -1; + } + return amsProxy_->GetTopAbility(); +} } // namespace OHOS diff --git a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h index 7089861..353da6d 100755 --- a/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h +++ b/interfaces/innerkits/abilitymgr_lite/ability_service_interface.h @@ -70,6 +70,8 @@ struct AmsSliteInterface { int32 (*StartAbility)(const Want *want); int32 (*TerminateAbility)(uint64_t token); int32 (*SchedulerLifecycleDone)(uint64_t token, int state); + int32 (*ForceStopBundle)(uint64_t token); + ElementName *(*GetTopAbility)(); }; #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h index 3b5241d..27f7ca2 100755 --- a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h +++ b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h @@ -26,9 +26,37 @@ extern "C" { typedef int (*StartCheckFunc)(const char *bundleName); +/** + * @brief Register the check function for the ability starting. + * + * @param startChecktCallback Indicates the check function for the ability starting. + * @return Returns 0 if this function is successfully called; returns another value otherwise. + */ int RegAbilityCallback(StartCheckFunc startChecktCallback); +/** + * @brief Schedule the lifecycle of the ability. + * + * @param token Indicates the token of the ability. + * @param state Indicates the state of the lifecycle. + * @return Returns 0 if this function is successfully called; returns another value otherwise. + */ int SchedulerLifecycleDone(uint64_t token, int state); + +/** + * @brief Forcestop an ability based on the specified token information. + * + * @param token Indicates the token of the ability. + * @return Returns 0 if this function is successfully called; returns another value otherwise. + */ +int ForceStopBundle(uint64_t token); + +/** + * @brief Get the element name of the top ability. + * + * @return Returns the element name of the top ability. + */ +ElementName *GetTopAbility(); #ifdef __cplusplus #if __cplusplus } diff --git a/interfaces/kits/ability_lite/slite/ability_manager.h b/interfaces/kits/ability_lite/slite/ability_manager.h index aa26a67..d997f9f 100755 --- a/interfaces/kits/ability_lite/slite/ability_manager.h +++ b/interfaces/kits/ability_lite/slite/ability_manager.h @@ -32,6 +32,12 @@ extern "C" { */ int StartAbility(const Want *want); +/** + * @brief Terminate an ability based on the specified token information. + * + * @param token Indicates the token of the ability. + * @return Returns 0 if this function is successfully called; returns another value otherwise. + */ int TerminateAbility(uint64_t token); #ifdef __cplusplus #if __cplusplus diff --git a/services/abilitymgr_lite/include/ability_mgr_slite_feature.h b/services/abilitymgr_lite/include/ability_mgr_slite_feature.h index 9a37fd1..bc0b70a 100755 --- a/services/abilitymgr_lite/include/ability_mgr_slite_feature.h +++ b/services/abilitymgr_lite/include/ability_mgr_slite_feature.h @@ -29,6 +29,8 @@ public: static int32 StartAbility(const Want *want); static int32 TerminateAbility(uint64_t token); static int32 SchedulerLifecycleDone(uint64_t token, int state); + static int32 ForceStopBundle(uint64_t token); + static ElementName *GetTopAbility(); static AbilityMgrSliteFeature *GetInstance() { diff --git a/services/abilitymgr_lite/include/ability_service.h b/services/abilitymgr_lite/include/ability_service.h index 02e9a34..3ffbabf 100755 --- a/services/abilitymgr_lite/include/ability_service.h +++ b/services/abilitymgr_lite/include/ability_service.h @@ -45,7 +45,9 @@ public: ~AbilityService() override; int32_t StartAbility(const Want *want); int32_t TerminateAbility(uint16_t token); + int32_t ForceStopBundle(uint16_t token); int32_t SchedulerLifecycleDone(uint64_t token, int32_t state); + ElementName *GetTopAbility(); void setNativeAbility(const SliteAbility *ability); void StartLauncher(); void CleanWant(); @@ -68,6 +70,7 @@ private: bool SendMsgToJsAbility(int32_t msgId, const AbilityRecord *record); void SetAbilityState(uint64_t token, int32_t state); void UpdataRecord(AbilitySvcInfo *info); + int32_t ForceStopBundleInner(uint16_t token); uint16_t pendingToken_ { 0 }; AbilityList abilityList_ {}; diff --git a/services/abilitymgr_lite/src/ability_mgr_service.cpp b/services/abilitymgr_lite/src/ability_mgr_service.cpp index 08fd2ff..385e190 100755 --- a/services/abilitymgr_lite/src/ability_mgr_service.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_service.cpp @@ -86,8 +86,10 @@ BOOL AbilityMgrService::ServiceMessageHandle(Service *service, Request *request) int token = request->msgValue & 0xFF; int state = (request->msgValue >> BYTE_OFFSET) & 0xFF; ret = AbilityService::GetInstance().SchedulerLifecycleDone(token, state); - } else if (request->msgId == TERMINATE_ABILITY) { + } else if (request->msgId == TERMINATE_ABILITY) { ret = AbilityService::GetInstance().TerminateAbility(request->msgValue); + } else if (request->msgId == TERMINATE_APP) { + ret = AbilityService::GetInstance().ForceStopBundle(request->msgValue); } return ret == ERR_OK; #else diff --git a/services/abilitymgr_lite/src/ability_mgr_slite_feature.cpp b/services/abilitymgr_lite/src/ability_mgr_slite_feature.cpp index 12bff89..a17006a 100755 --- a/services/abilitymgr_lite/src/ability_mgr_slite_feature.cpp +++ b/services/abilitymgr_lite/src/ability_mgr_slite_feature.cpp @@ -33,6 +33,8 @@ AbilityMgrSliteFeatureImpl g_amsSliteImpl = { .StartAbility = AbilityMgrSliteFeature::StartAbility, .TerminateAbility = AbilityMgrSliteFeature::TerminateAbility, .SchedulerLifecycleDone = AbilityMgrSliteFeature::SchedulerLifecycleDone, + .ForceStopBundle = AbilityMgrSliteFeature::ForceStopBundle, + .GetTopAbility = AbilityMgrSliteFeature::GetTopAbility, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -105,4 +107,15 @@ int32_t AbilityMgrSliteFeature::SchedulerLifecycleDone(uint64_t token, int state { return AbilityService::GetInstance().SchedulerLifecycleDone(token, state); } + +int32_t AbilityMgrSliteFeature::ForceStopBundle(uint64_t token) +{ + uint16_t slitToken = token & 0xFFFF; + return AbilityService::GetInstance().ForceStopBundle(slitToken); +} + +ElementName *AbilityMgrSliteFeature::GetTopAbility() +{ + return AbilityService::GetInstance().GetTopAbility(); +} } // namespace OHOS diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index 41cf6e9..28335bb 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -42,8 +42,6 @@ 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; -AbilityMgrService *g_AbilityService = nullptr; -AbilityMgrSliteFeature *g_AbilityFeature = nullptr; AbilityService::AbilityService() { @@ -83,22 +81,22 @@ int32_t AbilityService::StartAbility(const Want *want) return PARAM_NULL_ERROR; } - // TODO Èç¹ûÒѾ­ÔÚǰ̨£¬ÔòÖ±½Ó·µ»Ø + // TODO ����Ѿ���ǰ̨����ֱ�ӷ��� AbilitySvcInfo *info = static_cast(AdapterMalloc(sizeof(AbilitySvcInfo))); if (info == nullptr) { HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability Service AbilitySvcInfo is null"); return PARAM_NULL_ERROR; } - // TODO ³õʼ»¯info + // TODO ��ʼ��info - // ×é×°infoÐÅÏ¢ - // Èç¹ûÊÇ×ÀÃæ + // ��װinfo��Ϣ + // ��������� if (strcmp(bundleName, LAUNCHER_BUNDLE_NAME) == 0) { info->bundleName = Utils::Strdup(bundleName); info->path = nullptr; } else { - // JSÓ¦Óà + // JSӦ�� AbilityInfo abilityInfo = { nullptr, nullptr }; QueryAbilityInfo(want, &abilityInfo); if ((abilityInfo.bundleName == nullptr) || (strlen(abilityInfo.bundleName) == 0) || @@ -152,27 +150,27 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) return PARAM_NULL_ERROR; } uint16_t topToken = topRecord->GetToken(); - // Æô¶¯µÄÊÇ×ÀÃæ + // ������������ if (strcmp(info->bundleName, LAUNCHER_BUNDLE_NAME) == 0) { UpdataRecord(info); - // Top²»ÊÇ×ÀÃæ£¬¶øÊÇJSÓ¦ÓÃÇÒ²»ÔÚºǫ́ + // Top�������棬����JSӦ���Ҳ��ں�̨ if (topToken != LAUNCHER_TOKEN && topRecord->GetState() != SCHEDULE_BACKGROUND) { HILOG_INFO(HILOG_MODULE_AAFWK, "Change Js app to background."); (void) SchedulerLifecycleInner(topRecord, STATE_BACKGROUND); } else { - // TODO ÕâÀïÊÇ·ñ»¹Í¨ÖªLauncher TOPÊÇ×ÀÃæ£¬»òÕßtop²»ÊÇ×ÀÃæ£¬jsÔÚºǫ́ + // TODO �����Ƿ�֪ͨLauncher TOP�����棬����top�������棬js�ں�̨ (void) SchedulerLifecycle(LAUNCHER_TOKEN, STATE_ACTIVE); } return ERR_OK; } - // TODO CheckÊÇ·ñÔÊÐíÆô¶¯ + // TODO Check�Ƿ��������� if (!CheckResponse(info->bundleName)) { return -1; } - // Æô¶¯jsÇÒTOPÊÇjsÓ¦Óã¬ÇÒÒѾ­´´½¨ÁËtask + // ����js��TOP��jsӦ�ã����Ѿ�������task if (topRecord->IsAttached() && topRecord->GetToken() != LAUNCHER_TOKEN) { - // ¸ú֮ǰÆðµÄÊÇͬһ¸öÓ¦Óà tocheck + // ��֮ǰ�����ͬһ��Ӧ�� tocheck if (strcmp(info->bundleName, topRecord->GetAppName()) == 0) { if (topRecord->GetState() == SCHEDULE_BACKGROUND) { HILOG_INFO(HILOG_MODULE_AAFWK, "StartAbility Resume app when background."); @@ -181,7 +179,7 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) } HILOG_INFO(HILOG_MODULE_AAFWK, "Js app already started or starting."); } else { - // TODO ºÍ֮ǰµÄjsÓ¦Óò»ÊÇÒ»¸öÓ¦Óà JS2JS³¡¾°£¬ÐèÒªÏȰÑ֮ǰµÄJSÍ˳ö + // TODO ��֮ǰ��jsӦ�ò���һ��Ӧ�� JS2JS��������Ҫ�Ȱ�֮ǰ��JS�˳� return ERR_OK; } } @@ -199,9 +197,9 @@ int32_t AbilityService::TerminateAbility(uint16_t token) return PARAM_NULL_ERROR; } uint16_t topToken = topRecord->GetToken(); - // TODO CHECK terminate ×ÀÃæ,ÊÇ·ñÓиó¡¾°£¿ + // TODO CHECK terminate ����,�Ƿ��иó����� if (token == LAUNCHER_TOKEN) { - // Èç¹ûµ±Ç°jsÔÚºǫ́, Ôò×ÀÃæÍ˺ǫ́£¬js×ßµ½Ç°Ì¨ + // �����ǰjs�ں�̨, �������˺�̨��js�ߵ�ǰ̨ if (topToken != token && topRecord->GetState() == SCHEDULE_BACKGROUND) { HILOG_INFO(HILOG_MODULE_AAFWK, "Resume Js app [%u]", topToken); return SchedulerLifecycle(LAUNCHER_TOKEN, STATE_BACKGROUND); @@ -209,17 +207,58 @@ int32_t AbilityService::TerminateAbility(uint16_t token) return ERR_OK; } - // TODO CHECKÊÇ·ñÓиó¡¾° + // 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); } +int32_t AbilityService::ForceStopBundle(uint16_t token) +{ + HILOG_INFO(HILOG_MODULE_AAFWK, "ForceStopBundle [%u]", token); + if (token == LAUNCHER_TOKEN) { + HILOG_INFO(HILOG_MODULE_AAFWK, "Launcher does not support force stop."); + return ERR_OK; + } + + // free js mem and delete the record + AbilityRecord *record = abilityList_.Get(token); + if (ForceStopBundleInner(token) != ERR_OK) { + return PARAM_CHECK_ERROR; + } + + // active the launcher + AbilityRecord *launcherRecord = abilityList_.Get(LAUNCHER_TOKEN); + if (launcherRecord == nullptr) { + return PARAM_NULL_ERROR; + } + if (launcherRecord->GetState() != SCHEDULE_ACTIVE) { + return SchedulerLifecycleInner(LAUNCHER_TOKEN, STATE_ACTIVE); + } + return ERR_OK; +} + +int32_t AbilityService::ForceStopBundleInner(uint16_t token) +{ + // free js mem and delete the record + AbilityRecord *record = abilityList_.Get(token); + if (record == nullptr) { + return PARAM_NULL_ERROR; + } + auto jsAppHost = const_cast(record->GetJsAppHost()); + if (jsAppHost != nullptr) { + // free js mem + jsAppHost->ForceDestroy(); + } + DeleteRecordInfo(token); + return ERR_OK; +} + int32_t AbilityService::PreCheckStartAbility( const char *bundleName, const char *path, const void *data, uint16_t dataLength) { @@ -229,11 +268,11 @@ int32_t AbilityService::PreCheckStartAbility( } auto curRecord = abilityList_.Get(bundleName); if (curRecord != nullptr) { - // µ±Ç°ÒѾ­ÊÇǰ̨£¬²»´¦Àí + // ��ǰ�Ѿ���ǰ̨�������� if (curRecord->GetState() == SCHEDULE_ACTIVE) { HILOG_ERROR(HILOG_MODULE_AAFWK, "PreCheckStartAbility cur state active."); } else if (curRecord->GetState() == SCHEDULE_BACKGROUND) { - // Æô¶¯µÄjsÔÚºǫ́£¬ÔòÏȽ«×ÀÃæ×ßµ½ºǫ́ + // ������js�ں�̨�����Ƚ������ߵ���̨ SchedulerLifecycle(LAUNCHER_TOKEN, STATE_BACKGROUND); } return ERR_OK; @@ -245,7 +284,7 @@ int32_t AbilityService::PreCheckStartAbility( record->SetAppData(data, dataLength); record->SetState(SCHEDULE_STOP); abilityList_.Add(record); - // ´´½¨APP TASK + // ����APP TASK if (CreateAppTask(record) != ERR_OK) { HILOG_ERROR(HILOG_MODULE_AAFWK, "CheckResponse CreateAppTask fail"); abilityList_.Erase(record->GetToken()); @@ -294,7 +333,7 @@ int32_t AbilityService::CreateAppTask(AbilityRecord *record) // LoadPermissions(record->GetAppName(), appTaskId) record->SetState(SCHEDULE_INACTIVE); - // TODO ÕâÀïÔÚSchedulerLifecycleÖ®ºó + // TODO ������SchedulerLifecycle֮�� abilityStack_.PushAbility(record); APP_EVENT(MT_ACE_APP_START); if (SchedulerLifecycle(LAUNCHER_TOKEN, STATE_BACKGROUND) != 0) { @@ -349,7 +388,7 @@ void AbilityService::OnActiveDone(uint16_t token) return; } if (token == LAUNCHER_TOKEN) { - // Èç¹ûÊÇ×ÀÃæ¼¤»î£¬µ«JSµÄ״̬²»Îªºǫ́£¬ÔòÍ˳öJS + // ��������漤���JS��״̬��Ϊ��̨�����˳�JS if (topRecord->GetToken() != LAUNCHER_TOKEN) { if (topRecord->GetState() != SCHEDULE_BACKGROUND) { APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_START_LAUNCHER_EXIT_FAILED); @@ -362,7 +401,7 @@ void AbilityService::OnActiveDone(uint16_t token) } return; } - // Èç¹ûÆô¶¯µÄÊÇjs + // �����������js if (topRecord->GetToken() == token) { APP_EVENT(MT_ACE_APP_ACTIVE); } @@ -376,7 +415,7 @@ void AbilityService::OnBackgroundDone(uint16_t token) if (topRecord == nullptr) { return; } - // JS×ßµ½ºǫ́£¬¼¤»îLAUNCHER + // JS�ߵ���̨������LAUNCHER if (token != LAUNCHER_TOKEN) { if (topRecord->GetToken() == token) { APP_EVENT(MT_ACE_APP_BACKGROUND); @@ -385,11 +424,11 @@ void AbilityService::OnBackgroundDone(uint16_t token) } return; } - // launcher×ßµ½ºǫ́³¡¾° + // launcher�ߵ���̨���� if (topRecord->GetToken() != LAUNCHER_TOKEN) { (void) SchedulerLifecycleInner(topRecord, STATE_ACTIVE); } else { - // TODO CHECKÕâ¸ö³¡¾°»¹ÓÐûÓÐ + // TODO CHECK�����������û�� HILOG_WARN(HILOG_MODULE_AAFWK, "Js app exit, but has no js app."); } } @@ -397,7 +436,7 @@ void AbilityService::OnBackgroundDone(uint16_t token) void AbilityService::OnDestroyDone(uint16_t token) { HILOG_INFO(HILOG_MODULE_AAFWK, "OnDestroyDone [%u]", token); - // ×ÀÃæ²»»ádestroy + // ���治��destroy if (token == LAUNCHER_TOKEN) { SetAbilityState(token, SCHEDULE_STOP); return; @@ -413,13 +452,13 @@ void AbilityService::OnDestroyDone(uint16_t token) DeleteRecordInfo(token); SetAbilityState(token, SCHEDULE_STOP); - // ÎÞÆäËûJSÐèÒªÆô¶¯µÄ³¡¾°£¬Ö±½Ó¼¤»î×ÀÃæ + // ������JS��Ҫ�����ij�����ֱ�Ӽ������� if (pendingToken_ == 0) { (void) SchedulerLifecycle(LAUNCHER_TOKEN, STATE_ACTIVE); return; } - // JS2JS³¡¾° + // JS2JS���� auto record = abilityList_.Get(pendingToken_); if (CreateAppTask(record) != ERR_OK) { abilityList_.Erase(pendingToken_); @@ -452,16 +491,16 @@ int32_t AbilityService::SchedulerLifecycleInner(const AbilityRecord *record, int if (record == nullptr) { return PARAM_NULL_ERROR; } - // ֪ͨ¶ÔÓ¦µÄability£¬×ßÏàÓ¦µÄÉúÃüÖÜÆÚ - if (record->GetToken() != LAUNCHER_TOKEN) { // jsÓ¦Óà + // ֪ͨ��Ӧ��ability������Ӧ���������� + if (record->GetToken() != LAUNCHER_TOKEN) { // jsӦ�� (void) SendMsgToJsAbility(state, record); return ERR_OK; } - // native Ó¦Ó㬻ñÈ¡nativeµÄability£¬µ÷ÓÃÏàÓ¦µÄÉúÃüÖÜÆÚ + // native Ӧ�ã���ȡnative��ability��������Ӧ���������� if (g_NativeAbility == nullptr) { return PARAM_NULL_ERROR; } - // ÉêÇëwantÄڴ棬ÔÚ·þÎñ¶ËÓÃÍêÊÍ·Å + // ����want�ڴ棬�ڷ���������ͷ� Want *info = static_cast(AdapterMalloc(sizeof(Want))); if (info == nullptr) { return MEMORY_MALLOC_ERROR; @@ -512,7 +551,7 @@ int32_t AbilityService::SchedulerLifecycleDone(uint64_t token, int32_t state) OnBackgroundDone(token); break; } - case STATE_UNINITIALIZED: { // TODO DESTROYÈçºÎÌåÏÖ + case STATE_UNINITIALIZED: { OnDestroyDone(token); break; } @@ -549,10 +588,32 @@ bool AbilityService::SendMsgToJsAbility(int32_t state, const AbilityRecord *reco return ret == osOK; } +ElementName *AbilityService::GetTopAbility() +{ + auto topRecord = const_cast(abilityStack_.GetTopAbility()); + AbilityRecord *launcherRecord = abilityList_.Get(LAUNCHER_TOKEN); + if (topRecord == nullptr || launcherRecord == nullptr) { + return nullptr; + } + ElementName *element = reinterpret_cast(AdapterMalloc(sizeof(ElementName))); + if (element == nullptr || memset_s(element, sizeof(ElementName), 0, sizeof(ElementName)) != EOK) { + AdapterFree(element); + return nullptr; + } + if (topRecord->GetToken() == LAUNCHER_TOKEN || launcherRecord->GetState() == SCHEDULE_ACTIVE) { + SetElementBundleName(element, LAUNCHER_BUNDLE_NAME); + return element; + } + + // case js active or background when launcher not active + if (topRecord->GetState() == SCHEDULE_ACTIVE || topRecord->GetState() == SCHEDULE_BACKGROUND) { + SetElementBundleName(element, topRecord->GetAppName()); + } + return element; +} + void AbilityService::setNativeAbility(const SliteAbility *ability) { - g_AbilityFeature = AbilityMgrSliteFeature::GetInstance(); - g_AbilityService = AbilityMgrService::GetInstance(); g_NativeAbility = const_cast(ability); } } // namespace OHOS -- Gitee From c96a485134c9fa137bde7336b060aeda73fac3e3 Mon Sep 17 00:00:00 2001 From: autumn330 <99329532@qq.com> Date: Fri, 9 Apr 2021 10:13:12 +0800 Subject: [PATCH 2/4] =?UTF-8?q?update=20frameworks/abilitymgr=5Flite/src/s?= =?UTF-8?q?lite/abilityms=5Fslite=5Fclient.cpp.=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AC=94=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp index a93a371..5852ee8 100755 --- a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp +++ b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp @@ -131,7 +131,7 @@ int AbilityMsClient::ForceStopBundle(uint64_t token) const ElementName *AbilityMsClient::GetTopAbility() const { if (!Initialize()) { - return -1; + return nullptr; } return amsProxy_->GetTopAbility(); } -- Gitee From 93ab8d92e5da15fc106c348b2731bed8ce821217 Mon Sep 17 00:00:00 2001 From: autumn330 <99329532@qq.com> Date: Fri, 9 Apr 2021 10:14:12 +0800 Subject: [PATCH 3/4] =?UTF-8?q?update=20interfaces/innerkits/abilitymgr=5F?= =?UTF-8?q?lite/slite/ability=5Fmanager=5Finner.h.=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AC=94=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../innerkits/abilitymgr_lite/slite/ability_manager_inner.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h index 27f7ca2..37d9e88 100755 --- a/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h +++ b/interfaces/innerkits/abilitymgr_lite/slite/ability_manager_inner.h @@ -18,6 +18,8 @@ #include "stdint.h" +#include "element_name.h" + #ifdef __cplusplus #if __cplusplus extern "C" { -- Gitee From 8f0320d668ff25ccc8f63988dea0b1c2b50a5b42 Mon Sep 17 00:00:00 2001 From: LiuWei Date: Sat, 10 Apr 2021 22:32:54 +0800 Subject: [PATCH 4/4] Description:Get top ability interface. IssueNo:#I3EV3K Sig:aafwk Feature or Bugfix: Bugfix Binary Source: No --- .../src/slite/ability_manager_inner.cpp | 5 -- .../abilitymgr_lite/src/ability_service.cpp | 54 +++++++++---------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp index f2e2cfe..b5759c2 100755 --- a/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp +++ b/frameworks/abilitymgr_lite/src/slite/ability_manager_inner.cpp @@ -32,9 +32,4 @@ int ForceStopBundle(uint64_t token) { return OHOS::AbilityMsClient::GetInstance().ForceStopBundle(token); } - -ElementName *GetTopAbility() -{ - return OHOS::AbilityMsClient::GetInstance().GetTopAbility(); -} } diff --git a/services/abilitymgr_lite/src/ability_service.cpp b/services/abilitymgr_lite/src/ability_service.cpp index 28335bb..4cd2f32 100755 --- a/services/abilitymgr_lite/src/ability_service.cpp +++ b/services/abilitymgr_lite/src/ability_service.cpp @@ -81,22 +81,19 @@ int32_t AbilityService::StartAbility(const Want *want) return PARAM_NULL_ERROR; } - // TODO ����Ѿ���ǰ̨����ֱ�ӷ��� AbilitySvcInfo *info = static_cast(AdapterMalloc(sizeof(AbilitySvcInfo))); if (info == nullptr) { HILOG_ERROR(HILOG_MODULE_AAFWK, "Ability Service AbilitySvcInfo is null"); return PARAM_NULL_ERROR; } - // TODO ��ʼ��info - // ��װinfo��Ϣ - // ��������� if (strcmp(bundleName, LAUNCHER_BUNDLE_NAME) == 0) { + // Launcher info->bundleName = Utils::Strdup(bundleName); info->path = nullptr; } else { - // JSӦ�� + // JS APP AbilityInfo abilityInfo = { nullptr, nullptr }; QueryAbilityInfo(want, &abilityInfo); if ((abilityInfo.bundleName == nullptr) || (strlen(abilityInfo.bundleName) == 0) || @@ -150,27 +147,25 @@ int32_t AbilityService::StartAbility(AbilitySvcInfo *info) return PARAM_NULL_ERROR; } uint16_t topToken = topRecord->GetToken(); - // ������������ + // start launcher if (strcmp(info->bundleName, LAUNCHER_BUNDLE_NAME) == 0) { UpdataRecord(info); - // Top�������棬����JSӦ���Ҳ��ں�̨ if (topToken != LAUNCHER_TOKEN && topRecord->GetState() != SCHEDULE_BACKGROUND) { HILOG_INFO(HILOG_MODULE_AAFWK, "Change Js app to background."); (void) SchedulerLifecycleInner(topRecord, STATE_BACKGROUND); } else { - // TODO �����Ƿ�֪ͨLauncher TOP�����棬����top�������棬js�ں�̨ (void) SchedulerLifecycle(LAUNCHER_TOKEN, STATE_ACTIVE); } return ERR_OK; } - // TODO Check�Ƿ��������� + if (!CheckResponse(info->bundleName)) { - return -1; + return PARAM_CHECK_ERROR; } - // ����js��TOP��jsӦ�ã����Ѿ�������task + // start js app if (topRecord->IsAttached() && topRecord->GetToken() != LAUNCHER_TOKEN) { - // ��֮ǰ�����ͬһ��Ӧ�� tocheck + // start app is top if (strcmp(info->bundleName, topRecord->GetAppName()) == 0) { if (topRecord->GetState() == SCHEDULE_BACKGROUND) { HILOG_INFO(HILOG_MODULE_AAFWK, "StartAbility Resume app when background."); @@ -268,11 +263,9 @@ int32_t AbilityService::PreCheckStartAbility( } auto curRecord = abilityList_.Get(bundleName); if (curRecord != nullptr) { - // ��ǰ�Ѿ���ǰ̨�������� if (curRecord->GetState() == SCHEDULE_ACTIVE) { - HILOG_ERROR(HILOG_MODULE_AAFWK, "PreCheckStartAbility cur state active."); + HILOG_ERROR(HILOG_MODULE_AAFWK, "PreCheckStartAbility current state active."); } else if (curRecord->GetState() == SCHEDULE_BACKGROUND) { - // ������js�ں�̨�����Ƚ������ߵ���̨ SchedulerLifecycle(LAUNCHER_TOKEN, STATE_BACKGROUND); } return ERR_OK; @@ -284,7 +277,6 @@ int32_t AbilityService::PreCheckStartAbility( record->SetAppData(data, dataLength); record->SetState(SCHEDULE_STOP); abilityList_.Add(record); - // ����APP TASK if (CreateAppTask(record) != ERR_OK) { HILOG_ERROR(HILOG_MODULE_AAFWK, "CheckResponse CreateAppTask fail"); abilityList_.Erase(record->GetToken()); @@ -333,7 +325,6 @@ int32_t AbilityService::CreateAppTask(AbilityRecord *record) // LoadPermissions(record->GetAppName(), appTaskId) record->SetState(SCHEDULE_INACTIVE); - // TODO ������SchedulerLifecycle֮�� abilityStack_.PushAbility(record); APP_EVENT(MT_ACE_APP_START); if (SchedulerLifecycle(LAUNCHER_TOKEN, STATE_BACKGROUND) != 0) { @@ -387,8 +378,9 @@ void AbilityService::OnActiveDone(uint16_t token) if (topRecord == nullptr) { return; } + + // the launcher active if (token == LAUNCHER_TOKEN) { - // ��������漤���JS��״̬��Ϊ��̨�����˳�JS if (topRecord->GetToken() != LAUNCHER_TOKEN) { if (topRecord->GetState() != SCHEDULE_BACKGROUND) { APP_ERRCODE_EXTRA(EXCE_ACE_APP_START, EXCE_ACE_APP_START_LAUNCHER_EXIT_FAILED); @@ -401,7 +393,7 @@ void AbilityService::OnActiveDone(uint16_t token) } return; } - // �����������js + // the js app active if (topRecord->GetToken() == token) { APP_EVENT(MT_ACE_APP_ACTIVE); } @@ -415,7 +407,7 @@ void AbilityService::OnBackgroundDone(uint16_t token) if (topRecord == nullptr) { return; } - // JS�ߵ���̨������LAUNCHER + // the js background if (token != LAUNCHER_TOKEN) { if (topRecord->GetToken() == token) { APP_EVENT(MT_ACE_APP_BACKGROUND); @@ -424,19 +416,18 @@ void AbilityService::OnBackgroundDone(uint16_t token) } return; } - // launcher�ߵ���̨���� + // the launcher background if (topRecord->GetToken() != LAUNCHER_TOKEN) { (void) SchedulerLifecycleInner(topRecord, STATE_ACTIVE); - } else { - // TODO CHECK�����������û�� - HILOG_WARN(HILOG_MODULE_AAFWK, "Js app exit, but has no js app."); + return; } + HILOG_WARN(HILOG_MODULE_AAFWK, "Js app exit, but has no js app."); } void AbilityService::OnDestroyDone(uint16_t token) { HILOG_INFO(HILOG_MODULE_AAFWK, "OnDestroyDone [%u]", token); - // ���治��destroy + // the launcher destroy if (token == LAUNCHER_TOKEN) { SetAbilityState(token, SCHEDULE_STOP); return; @@ -452,13 +443,13 @@ void AbilityService::OnDestroyDone(uint16_t token) DeleteRecordInfo(token); SetAbilityState(token, SCHEDULE_STOP); - // ������JS��Ҫ�����ij�����ֱ�Ӽ������� + // no pending token if (pendingToken_ == 0) { (void) SchedulerLifecycle(LAUNCHER_TOKEN, STATE_ACTIVE); return; } - // JS2JS���� + // start pending token auto record = abilityList_.Get(pendingToken_); if (CreateAppTask(record) != ERR_OK) { abilityList_.Erase(pendingToken_); @@ -491,12 +482,12 @@ int32_t AbilityService::SchedulerLifecycleInner(const AbilityRecord *record, int if (record == nullptr) { return PARAM_NULL_ERROR; } - // ֪ͨ��Ӧ��ability������Ӧ���������� + // dispatch js life cycle if (record->GetToken() != LAUNCHER_TOKEN) { // jsӦ�� (void) SendMsgToJsAbility(state, record); return ERR_OK; } - // native Ӧ�ã���ȡnative��ability��������Ӧ���������� + // dispatch native life cycle if (g_NativeAbility == nullptr) { return PARAM_NULL_ERROR; } @@ -624,4 +615,9 @@ int InstallNativeAbility(const AbilityInfo *abilityInfo, const OHOS::SliteAbilit OHOS::AbilityService::GetInstance().setNativeAbility(ability); return ERR_OK; } + +ElementName *GetTopAbility() +{ + return OHOS::AbilityService::GetInstance().GetTopAbility(); +} } \ No newline at end of file -- Gitee