From 9f6ee50020e9b5491aa9cba873a4e9a40fa5ee88 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Wed, 16 Feb 2022 17:12:38 +0000 Subject: [PATCH] Check codeCheck Signed-off-by: wanchengzhen --- .../ability_runtime/include/ability_context.h | 8 + .../include/ability_context_impl.h | 10 + .../include/local_call_record.h | 2 + .../src/local_call_container.cpp | 25 ++ .../ability_runtime/src/local_call_record.cpp | 11 + .../AMS/mock_serviceability_manager_service.h | 5 - .../ability/native/src/ability_thread.cpp | 19 + .../include/mock_ability_manager_service.h | 5 - .../mock/AMS/mock_ability_manager_service.h | 5 - .../AMS/mock_serviceability_manager_service.h | 5 - .../include/ability_manager_client.h | 11 - .../include/ability_manager_interface.h | 11 - .../include/ability_manager_proxy.h | 13 - .../include/ability_manager_service.h | 31 +- services/abilitymgr/include/ability_record.h | 2 + services/abilitymgr/include/call_container.h | 130 +++--- .../abilitymgr/include/data_ability_manager.h | 1 + .../include/kernal_ability_manager.h | 2 + .../include/kernal_system_app_manager.h | 2 + .../abilitymgr/include/mission_list_manager.h | 11 +- .../abilitymgr/include/pending_want_manager.h | 1 + .../abilitymgr/src/ability_manager_client.cpp | 7 - .../abilitymgr/src/ability_manager_proxy.cpp | 15 - .../src/ability_manager_service.cpp | 94 ++++- .../abilitymgr/src/ability_manager_stub.cpp | 8 +- services/abilitymgr/src/ability_record.cpp | 65 +++ .../src/ability_scheduler_proxy.cpp | 2 +- services/abilitymgr/src/call_container.cpp | 384 +++++++++--------- services/abilitymgr/src/call_record.cpp | 379 +++++++++-------- .../abilitymgr/src/data_ability_manager.cpp | 41 ++ .../abilitymgr/src/kernal_ability_manager.cpp | 8 + .../src/kernal_system_app_manager.cpp | 7 + services/abilitymgr/src/mission_list.cpp | 6 +- .../abilitymgr/src/mission_list_manager.cpp | 131 +++++- .../abilitymgr/src/pending_want_manager.cpp | 38 +- .../ability_manager_stub_mock.h | 6 +- .../ability_manager_stub_impl_mock.h | 6 +- .../ability_manager_stub_mock.h | 5 - services/appmgr/lmks.cfg | 7 + .../test/mock/include/mock_ability_manager.h | 5 - .../include/appmgr/mock_ability_mgr_host.h | 5 - .../mock/include/mock_ability_mgr_service.h | 6 - tools/aa/include/ability_command.h | 17 +- tools/aa/src/ability_command.cpp | 54 ++- tools/test/mock/mock_ability_manager_stub.h | 5 - 45 files changed, 973 insertions(+), 638 deletions(-) diff --git a/frameworks/kits/ability/ability_runtime/include/ability_context.h b/frameworks/kits/ability/ability_runtime/include/ability_context.h index 1f4e4d8af36..cb8cbdbdfa9 100644 --- a/frameworks/kits/ability/ability_runtime/include/ability_context.h +++ b/frameworks/kits/ability/ability_runtime/include/ability_context.h @@ -32,6 +32,7 @@ namespace OHOS { namespace AbilityRuntime { using RuntimeTask = std::function; using PermissionRequestTask = std::function&, const std::vector&)>; +class LocalCallContainer; class AbilityContext : public Context { public: virtual ~AbilityContext() = default; @@ -227,6 +228,13 @@ public: */ virtual ErrCode SetMissionLabel(const std::string &label) = 0; + /** + * @brief Get LocalCallContainer. + * + * @return Returns the LocalCallContainer. + */ + virtual sptr GetLocalCallContainer() = 0; + virtual void SetConfiguration(const std::shared_ptr &config) = 0; virtual std::shared_ptr GetConfiguration() const = 0; diff --git a/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h b/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h index c240fa64c41..be7cd26e54a 100644 --- a/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h +++ b/frameworks/kits/ability/ability_runtime/include/ability_context_impl.h @@ -115,6 +115,16 @@ public: return contentStorage_; } + /** + * @brief Get LocalCallContainer. + * + * @return Returns the LocalCallContainer. + */ + sptr GetLocalCallContainer() override + { + return localCallContainer_; + } + void SetConfiguration(const std::shared_ptr &config) override; std::shared_ptr GetConfiguration() const override; diff --git a/frameworks/kits/ability/ability_runtime/include/local_call_record.h b/frameworks/kits/ability/ability_runtime/include/local_call_record.h index 4fb8ae25b23..331caec0131 100644 --- a/frameworks/kits/ability/ability_runtime/include/local_call_record.h +++ b/frameworks/kits/ability/ability_runtime/include/local_call_record.h @@ -39,6 +39,8 @@ public: void InvokeCallBack() const; AppExecFwk::ElementName GetElementName() const; bool IsExistCallBack() const; + int GetRecordId(); + std::vector> GetCallers(); private: static int64_t callRecordId; diff --git a/frameworks/kits/ability/ability_runtime/src/local_call_container.cpp b/frameworks/kits/ability/ability_runtime/src/local_call_container.cpp index 13ed5205b1c..2a06359cb24 100644 --- a/frameworks/kits/ability/ability_runtime/src/local_call_container.cpp +++ b/frameworks/kits/ability/ability_runtime/src/local_call_container.cpp @@ -119,6 +119,31 @@ int LocalCallContainer::Release(const std::shared_ptr& callback) void LocalCallContainer::DumpCalls(std::vector &info) const { HILOG_DEBUG("LocalCallContainer::DumpCalls called."); + info.emplace_back(" caller connections:"); + for (auto iter = callProxyRecords_.begin(); iter != callProxyRecords_.end(); iter++) { + std::string tempstr = " LocalCallRecord"; + tempstr += " ID #" + std::to_string (iter->second->GetRecordId()) + "\n"; + tempstr += " callee"; + tempstr += " uri[" + iter->first + "]" + "\n"; + tempstr += " callers #" + std::to_string (iter->second->GetCallers().size()); + bool flag = true; + for (auto &callBack:iter->second->GetCallers()) { + if (callBack && !callBack->IsCallBack()) { + HILOG_INFO("%{public}s call back is not called.", __func__); + flag = false; + break; + } + } + if (flag) { + HILOG_INFO("%{public}s state is REQUESTEND.", __func__); + tempstr += " state #REQUESTEND"; + } else { + HILOG_INFO("%{public}s state is REQUESTING.", __func__); + tempstr += " state #REQUESTING"; + } + info.emplace_back(tempstr); + } + return; } void LocalCallContainer::OnAbilityConnectDone( diff --git a/frameworks/kits/ability/ability_runtime/src/local_call_record.cpp b/frameworks/kits/ability/ability_runtime/src/local_call_record.cpp index d2c30b86491..69abcfe95c2 100644 --- a/frameworks/kits/ability/ability_runtime/src/local_call_record.cpp +++ b/frameworks/kits/ability/ability_runtime/src/local_call_record.cpp @@ -113,5 +113,16 @@ bool LocalCallRecord::IsExistCallBack() const { return (callers_.size() > 0); } + +int LocalCallRecord::GetRecordId() +{ + return recordId_; +} + +std::vector> LocalCallRecord::GetCallers() +{ + return callers_; +} + } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h index 8dd975e7780..64a58e4af28 100644 --- a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h @@ -56,11 +56,6 @@ public: int TerminateAbility( const sptr &token, int resultCode = -1, const Want *resultWant = nullptr) override; - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index 9b980402d57..708880e822e 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -1593,6 +1593,25 @@ void AbilityThread::DumpAbilityInfo(const std::vector ¶ms, std: runner->DumpRunnerInfo(dumpInfo); info.push_back(dumpInfo); + if (!currentAbility_) { + APP_LOGI("currentAbility is nullptr."); + return; + } + + const auto ablityContext = currentAbility_->GetAbilityContext(); + if (!ablityContext) { + APP_LOGI("current ability context is nullptr."); + return; + } + + const auto localCallContainer = ablityContext->GetLocalCallContainer(); + if (!localCallContainer) { + APP_LOGI("current ability context locall call container is nullptr."); + return; + } + + localCallContainer->DumpCalls(info); + APP_LOGI("localCallContainer need to get calls info."); } diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index bc54e39062e..5b099201890 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -53,11 +53,6 @@ public: int TerminateAbility( const sptr &token, int resultCode = -1, const Want *resultWant = nullptr) override; - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index 59d78629135..d44cbd503d6 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -51,11 +51,6 @@ public: } int TerminateAbility( const sptr &token, int resultCode = -1, const Want *resultWant = nullptr) override; - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h index bab683317ad..32f421dde29 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -54,11 +54,6 @@ public: } int TerminateAbility( const sptr &token, int resultCode = -1, const Want *resultWant = nullptr) override; - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index aa9e4a9d779..a1276abb217 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -155,17 +155,6 @@ public: */ ErrCode TerminateAbility(const sptr &token, int resultCode, const Want *resultWant); - /** - * CloseAbility with want, return want from ability manager service. - * - * @param token Ability token. - * @param resultCode resultCode. - * @param Want Ability want returned. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr); - /** * TerminateAbility, terminate the special ability. * diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index 7bc635de351..f38d68f96f9 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -142,17 +142,6 @@ public: */ virtual int TerminateAbilityByCaller(const sptr &callerToken, int requestCode) = 0; - /** - * CloseAbility, close the special ability. - * - * @param token, the token of the ability to terminate. - * @param resultCode, the resultCode of the ability to terminate. - * @param resultWant, the Want of the ability to return. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) = 0; - /** * MinimizeAbility, minimize the special ability. * diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 6441c704a4e..79f078b1c1e 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -115,17 +115,6 @@ public: */ virtual int TerminateAbilityByCaller(const sptr &callerToken, int requestCode) override; - /** - * CloseAbility, close the special ability. - * - * @param token, the token of the ability to terminate. - * @param resultCode, the resultCode of the ability to terminate. - * @param resultWant, the Want of the ability to return. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CloseAbility( - const sptr &token, int resultCode, const Want *resultWant = nullptr) override; - /** * MinimizeAbility, minimize the special ability. * @@ -673,8 +662,6 @@ private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); bool WriteInterfaceToken(MessageParcel &data); - // flag = true : terminate; flag = false : close - int TerminateAbility(const sptr &token, int resultCode, const Want *resultWant, bool flag); private: static inline BrokerDelegator delegator_; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 296020c0381..7e1a5f32f77 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -143,17 +143,6 @@ public: */ virtual int TerminateAbilityByCaller(const sptr &callerToken, int requestCode) override; - /** - * CloseAbility, close the special ability. - * - * @param token, the token of the ability to terminate. - * @param resultCode, the resultCode of the ability to terminate. - * @param resultWant, the Want of the ability to return. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override; - /** * MinimizeAbility, minimize the special ability. * @@ -913,6 +902,8 @@ public: KEY_DUMPSYS_SERVICE, KEY_DUMPSYS_PENDING, KEY_DUMPSYS_PROCESS, + KEY_DUMPSYS_DATA, + KEY_DUMPSYS_SYSTEM_UI, }; friend class AbilityStackManager; @@ -925,8 +916,6 @@ protected: void OnAppStateChanged(const AppInfo &info) override; private: - int TerminateAbilityWithFlag(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr, bool flag = true); /** * initialization of ability manager service. * @@ -1071,17 +1060,21 @@ private: */ void DumpSysFuncInit(); void DumpSysInner( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId); + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); void DumpSysMissionListInner( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId); + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); void DumpSysAbilityInner( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId); + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); void DumpSysStateInner( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId); + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); void DumpSysPendingInner( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId); + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); void DumpSysProcess( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId); + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); + void DataDumpSysStateInner( + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); + void SystemDumpSysStateInner( + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); void InitConnectManager(int32_t userId, bool switchUser); void InitDataAbilityManager(int32_t userId, bool switchUser); diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 78633a38fd5..22bbcc7db97 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -666,6 +666,8 @@ public: */ void Dump(std::vector &info); + void DumpSys(std::vector &info, bool isClient = false); + /** * dump ability state info. * diff --git a/services/abilitymgr/include/call_container.h b/services/abilitymgr/include/call_container.h index 725d6552e09..84313aa1967 100644 --- a/services/abilitymgr/include/call_container.h +++ b/services/abilitymgr/include/call_container.h @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2021 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_AAFWK_CALL_CONTAINER_H -#define OHOS_AAFWK_CALL_CONTAINER_H - -#include -#include -#include - -#include "ability_connect_callback_interface.h" -#include "call_record.h" -#include "element_name.h" -#include "iremote_object.h" -#include "nocopyable.h" - -namespace OHOS { -namespace AAFwk { -class CallRecord; -/** - * @class CallContainer - * CallContainer provides a facility for managing the call records of ability. - */ -class CallContainer : public std::enable_shared_from_this { -public: - using CallMapType = std::map, std::shared_ptr>; - using RecipientMapType = std::map, sptr>; - - CallContainer(); - virtual ~CallContainer(); - - void AddCallRecord(const sptr & connect, const std::shared_ptr& callRecord); - std::shared_ptr GetCallRecord(const sptr & connect) const; - bool RemoveCallRecord(const sptr & connect); - bool CallRequestDone(const sptr & callStub); - void Dump(std::vector &info, const std::string &args = "") const; - bool IsNeedToCallRequest() const; - -private: - void RemoveConnectDeathRecipient(const sptr &connect); - void AddConnectDeathRecipient(const sptr &connect); - void OnConnectionDied(const wptr & remote); - -private: - CallMapType callRecordMap_; - RecipientMapType deathRecipientMap_; - - DISALLOW_COPY_AND_MOVE(CallContainer); -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_AAFWK_CALL_CONTAINER_H - +/* + * Copyright (c) 2021 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_AAFWK_CALL_CONTAINER_H +#define OHOS_AAFWK_CALL_CONTAINER_H + +#include +#include +#include + +#include "ability_connect_callback_interface.h" +#include "call_record.h" +#include "element_name.h" +#include "iremote_object.h" +#include "nocopyable.h" + +namespace OHOS { +namespace AAFwk { +class CallRecord; +/** + * @class CallContainer + * CallContainer provides a facility for managing the call records of ability. + */ +class CallContainer : public std::enable_shared_from_this { +public: + using CallMapType = std::map, std::shared_ptr>; + using RecipientMapType = std::map, sptr>; + + CallContainer(); + virtual ~CallContainer(); + + void AddCallRecord(const sptr & connect, const std::shared_ptr& callRecord); + std::shared_ptr GetCallRecord(const sptr & connect) const; + bool RemoveCallRecord(const sptr & connect); + bool CallRequestDone(const sptr & callStub); + void Dump(std::vector &info) const; + bool IsNeedToCallRequest() const; + +private: + void RemoveConnectDeathRecipient(const sptr &connect); + void AddConnectDeathRecipient(const sptr &connect); + void OnConnectionDied(const wptr & remote); + +private: + CallMapType callRecordMap_; + RecipientMapType deathRecipientMap_; + + DISALLOW_COPY_AND_MOVE(CallContainer); +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_CALL_CONTAINER_H + diff --git a/services/abilitymgr/include/data_ability_manager.h b/services/abilitymgr/include/data_ability_manager.h index 13b5a91517e..5d91f49a4fb 100644 --- a/services/abilitymgr/include/data_ability_manager.h +++ b/services/abilitymgr/include/data_ability_manager.h @@ -47,6 +47,7 @@ public: std::shared_ptr GetAbilityRecordByScheduler(const sptr &scheduler); void Dump(const char *func, int line); void DumpState(std::vector &info, const std::string &args = "") const; + void DumpSysState(std::vector &info, bool isClient = false, const std::string &args = "") const; void GetAbilityRunningInfos(std::vector &info); private: diff --git a/services/abilitymgr/include/kernal_ability_manager.h b/services/abilitymgr/include/kernal_ability_manager.h index dd1ec48af34..950e7ffbb6d 100644 --- a/services/abilitymgr/include/kernal_ability_manager.h +++ b/services/abilitymgr/include/kernal_ability_manager.h @@ -79,6 +79,8 @@ public: void DumpState(std::vector &info); + void DumpSysState(std::vector &info, bool isClient); + void OnAbilityDied(std::shared_ptr abilityRecord); void OnTimeOut(uint32_t msgId, int64_t eventId); diff --git a/services/abilitymgr/include/kernal_system_app_manager.h b/services/abilitymgr/include/kernal_system_app_manager.h index 55f2663ad99..eb30240281a 100644 --- a/services/abilitymgr/include/kernal_system_app_manager.h +++ b/services/abilitymgr/include/kernal_system_app_manager.h @@ -79,6 +79,8 @@ public: void DumpState(std::vector &info); + void DumpSysState(std::vector &info, bool isClient = false); + void OnAbilityDied(std::shared_ptr abilityRecord); void OnTimeOut(uint32_t msgId, int64_t eventId); diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 31677e667cc..2ba3229a483 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -81,6 +81,8 @@ public: */ void OnAbilityRequestDone(const sptr &token, const int32_t state); + void OnAppStateChanged(const AppInfo &info); + /** * attach ability thread ipc object. * @@ -124,11 +126,10 @@ public: * @param abilityRecord the ability to terminate * @param resultCode the terminate data * @param resultWant the terminate data - * @param flag mark terminate flag * @return int error code */ int TerminateAbility(const std::shared_ptr &abilityRecord, - int resultCode, const Want *resultWant, bool flag); + int resultCode, const Want *resultWant); /** * @brief Terminate ability with caller @@ -143,9 +144,8 @@ public: * @brief remove the mission from the mission list * * @param abilityRecord the ability need to remove - * @param flag mark is terminate or close */ - void RemoveTerminatingAbility(const std::shared_ptr &abilityRecord, bool flag); + void RemoveTerminatingAbility(const std::shared_ptr &abilityRecord); /** * @brief remove the mission list from the mission list manager @@ -364,7 +364,7 @@ private: bool RemoveMissionList(const std::list> lists, const std::shared_ptr &list); int ClearMissionLocked(int missionId, std::shared_ptr mission); - int TerminateAbilityLocked(const std::shared_ptr &abilityRecord, bool flag); + int TerminateAbilityLocked(const std::shared_ptr &abilityRecord); std::shared_ptr GetAbilityRecordByEventId(int64_t eventId) const; std::shared_ptr GetAbilityRecordByCaller( const std::shared_ptr &caller, int requestCode); @@ -379,6 +379,7 @@ private: void GetAllForegroundAbilities(std::list>& foregroundList); void GetForegroundAbilities(const std::shared_ptr& missionList, std::list>& foregroundList); + bool IsPC(); std::shared_ptr GetMissionBySpecifiedFlag(const std::string &flag) const; void HandleLoadTimeout(const std::shared_ptr &ability); diff --git a/services/abilitymgr/include/pending_want_manager.h b/services/abilitymgr/include/pending_want_manager.h index b12cbef86a8..55852046f41 100644 --- a/services/abilitymgr/include/pending_want_manager.h +++ b/services/abilitymgr/include/pending_want_manager.h @@ -159,6 +159,7 @@ public: void ClearPendingWantRecord(const std::string &bundleName); void Dump(std::vector &info); + void DumpByRecordId(std::vector &info, const std::string &args); private: sptr GetWantSenderLocked(const int32_t callingUid, const int32_t uid, const int32_t userId, diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 65fd32a775e..bf217771d14 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -165,13 +165,6 @@ ErrCode AbilityManagerClient::TerminateAbilityResult(const sptr & return abms->TerminateAbilityResult(token, startId); } -ErrCode AbilityManagerClient::CloseAbility(const sptr &token, int resultCode, const Want *resultWant) -{ - CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); - sptr abms = iface_cast(remoteObject_); - return abms->CloseAbility(token, resultCode, resultWant); -} - ErrCode AbilityManagerClient::MinimizeAbility(const sptr &token, bool fromUser) { CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 9a12330bd93..14980e30031 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -185,12 +185,6 @@ int AbilityManagerProxy::StartAbility(const Want &want, const StartOptions &star } int AbilityManagerProxy::TerminateAbility(const sptr &token, int resultCode, const Want *resultWant) -{ - return TerminateAbility(token, resultCode, resultWant, true); -} - -int AbilityManagerProxy::TerminateAbility(const sptr &token, - int resultCode, const Want *resultWant, bool flag) { int error; MessageParcel data; @@ -204,10 +198,6 @@ int AbilityManagerProxy::TerminateAbility(const sptr &token, HILOG_ERROR("data write failed."); return INNER_ERR; } - if (!data.WriteBool(flag)) { - HILOG_ERROR("data write flag failed."); - return INNER_ERR; - } error = Remote()->SendRequest(IAbilityManager::TERMINATE_ABILITY, data, reply, option); if (error != NO_ERROR) { HILOG_ERROR("Send request error: %{public}d", error); @@ -238,11 +228,6 @@ int AbilityManagerProxy::TerminateAbilityByCaller(const sptr &cal return reply.ReadInt32(); } -int AbilityManagerProxy::CloseAbility(const sptr &token, int resultCode, const Want *resultWant) -{ - return TerminateAbility(token, resultCode, resultWant, false); -} - int AbilityManagerProxy::ConnectAbility( const Want &want, const sptr &connect, const sptr &callerToken, int32_t userId) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index c25caa62646..b34c87e2134 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -111,6 +111,10 @@ const std::map AbilityManagerSer std::map::value_type("-p", KEY_DUMPSYS_PENDING), std::map::value_type("--process", KEY_DUMPSYS_PROCESS), std::map::value_type("-r", KEY_DUMPSYS_PROCESS), + std::map::value_type("--data", KEY_DUMPSYS_DATA), + std::map::value_type("-d", KEY_DUMPSYS_DATA), + std::map::value_type("--ui", KEY_DUMPSYS_SYSTEM_UI), + std::map::value_type("-k", KEY_DUMPSYS_SYSTEM_UI), }; const bool REGISTER_RESULT = @@ -512,17 +516,6 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st } int AbilityManagerService::TerminateAbility(const sptr &token, int resultCode, const Want *resultWant) -{ - return TerminateAbilityWithFlag(token, resultCode, resultWant, true); -} - -int AbilityManagerService::CloseAbility(const sptr &token, int resultCode, const Want *resultWant) -{ - return TerminateAbilityWithFlag(token, resultCode, resultWant, false); -} - -int AbilityManagerService::TerminateAbilityWithFlag(const sptr &token, int resultCode, - const Want *resultWant, bool flag) { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("Terminate ability for result: %{public}d", (resultWant != nullptr)); @@ -578,7 +571,7 @@ int AbilityManagerService::TerminateAbilityWithFlag(const sptr &t HILOG_ERROR("missionListManager is Null. userId=%{public}d", userId); return ERR_INVALID_VALUE; } - return missionListManager->TerminateAbility(abilityRecord, resultCode, resultWant, flag); + return missionListManager->TerminateAbility(abilityRecord, resultCode, resultWant); } else { auto stackManager = GetStackManagerByUserId(userId); if (!stackManager) { @@ -1642,6 +1635,9 @@ void AbilityManagerService::DumpSysFuncInit() dumpsysFuncMap_[KEY_DUMPSYS_SERVICE] = &AbilityManagerService::DumpSysStateInner; dumpsysFuncMap_[KEY_DUMPSYS_PENDING] = &AbilityManagerService::DumpSysPendingInner; dumpsysFuncMap_[KEY_DUMPSYS_PROCESS] = &AbilityManagerService::DumpSysProcess; + dumpsysFuncMap_[KEY_DUMPSYS_DATA] = &AbilityManagerService::DataDumpSysStateInner; + dumpsysFuncMap_[KEY_DUMPSYS_SYSTEM_UI] = &AbilityManagerService::SystemDumpSysStateInner; + } void AbilityManagerService::DumpSysInner( @@ -1659,7 +1655,7 @@ void AbilityManagerService::DumpSysInner( } void AbilityManagerService::DumpSysMissionListInner( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId) + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { std::shared_ptr targetManager; if (isUserID) { @@ -1690,7 +1686,7 @@ void AbilityManagerService::DumpSysMissionListInner( } } void AbilityManagerService::DumpSysAbilityInner( - const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId) + const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId) { std::shared_ptr targetManager; if (isUserID) { @@ -1756,18 +1752,34 @@ void AbilityManagerService::DumpSysStateInner( void AbilityManagerService::DumpSysPendingInner( const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId) { + std::shared_ptr targetManager; if (isUserID) { auto it = pendingWantManagers_.find(userId); - if (it != pendingWantManagers_.end()) { - it->second->Dump(info); + if (it == pendingWantManagers_.end()) { + info.push_back("error: No user found'."); return; } - info.push_back("error: No user found'."); + targetManager = it->second; + } else { + targetManager = pendingWantManager_; + } + + CHECK_POINTER(targetManager); + + std::vector argList; + SplitStr(args, " ", argList); + if (argList.empty()) { return; } - CHECK_POINTER(pendingWantManager_); - pendingWantManager_->Dump(info); + if (argList.size() == MIN_DUMP_ARGUMENT_NUM) { + targetManager->DumpByRecordId(info, argList[1]); + } else if (argList.size() < MIN_DUMP_ARGUMENT_NUM) { + targetManager->Dump(info); + } else { + info.emplace_back("error: invalid argument, please see 'ability dumpsys -h'."); + } + } void AbilityManagerService::DumpSysProcess( @@ -1815,6 +1827,47 @@ void AbilityManagerService::DumpSysProcess( } } +void AbilityManagerService::DataDumpSysStateInner( + const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId) +{ + std::shared_ptr targetManager; + if (isUserID) { + auto it = dataAbilityManagers_.find(userId); + if (it == dataAbilityManagers_.end()) { + info.push_back("error: No user found'."); + return; + } + targetManager = it->second; + } else { + targetManager = dataAbilityManager_; + } + + CHECK_POINTER(targetManager); + + std::vector argList; + SplitStr(args, " ", argList); + if (argList.empty()) { + return; + } + if (argList.size() == MIN_DUMP_ARGUMENT_NUM) { + targetManager->DumpSysState(info, isClient, argList[1]); + } else if (argList.size() < MIN_DUMP_ARGUMENT_NUM) { + targetManager->DumpSysState(info, isClient); + } else { + info.emplace_back("error: invalid argument, please see 'ability dump -h'."); + } +} + +void AbilityManagerService::SystemDumpSysStateInner( + const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId) +{ + if (useNewMission_) { + kernalAbilityManager_->DumpSysState(info,isClient); + } else { + systemAppManager_->DumpSysState(info,isClient); + } +} + void AbilityManagerService::DumpInner(const std::string &args, std::vector &info) { if (useNewMission_) { @@ -2212,11 +2265,12 @@ void AbilityManagerService::OnAbilityRequestDone(const sptr &toke void AbilityManagerService::OnAppStateChanged(const AppInfo &info) { HILOG_INFO("On app state changed."); - currentStackManager_->OnAppStateChanged(info); connectManager_->OnAppStateChanged(info); if (useNewMission_) { + currentMissionListManager_->OnAppStateChanged(info); kernalAbilityManager_->OnAppStateChanged(info); } else { + currentStackManager_->OnAppStateChanged(info); systemAppManager_->OnAppStateChanged(info); } dataAbilityManager_->OnAppStateChanged(info); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index a26f2142da7..6d679b09bd3 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -177,13 +177,7 @@ int AbilityManagerStub::TerminateAbilityInner(MessageParcel &data, MessageParcel sptr token = data.ReadParcelable(); int resultCode = data.ReadInt32(); Want *resultWant = data.ReadParcelable(); - bool flag = data.ReadBool(); - int32_t result; - if (flag) { - result = TerminateAbility(token, resultCode, resultWant); - } else { - result = CloseAbility(token, resultCode, resultWant); - } + int32_t result = TerminateAbility(token, resultCode, resultWant); reply.WriteInt32(result); if (resultWant != nullptr) { delete resultWant; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 1c398aea0b9..57e3dc7e235 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -947,6 +947,11 @@ void AbilityRecord::DumpAbilityState( dumpInfo = " ready #" + std::to_string(isReady_) + " window attached #" + std::to_string(isWindowAttached_) + " launcher #" + std::to_string(isLauncherAbility_); info.push_back(dumpInfo); + dumpInfo = " callee connections: "; + info.push_back(dumpInfo); + if (callContainer_) { + callContainer_->Dump(info); + } if (isLauncherRoot_ && IsNewVersion()) { dumpInfo = " can restart num #" + std::to_string(restartCount_); @@ -1562,5 +1567,65 @@ bool AbilityRecord::IsSwitchingPause() { return isSwitchingPause_; } + +void AbilityRecord::DumpSys(std::vector &info, bool isClient) +{ + std::string dumpInfo = " AbilityRecord ID #" + std::to_string(recordId_); + info.push_back(dumpInfo); + dumpInfo = " app name [" + GetAbilityInfo().applicationName + "]"; + info.push_back(dumpInfo); + dumpInfo = " main name [" + GetAbilityInfo().name + "]"; + info.push_back(dumpInfo); + dumpInfo = " bundle name [" + GetAbilityInfo().bundleName + "]"; + info.push_back(dumpInfo); + // get ability type(unknown/page/service/provider) + std::string typeStr; + GetAbilityTypeString(typeStr); + dumpInfo = " ability type [" + typeStr + "]"; + info.push_back(dumpInfo); + std::shared_ptr preAbility = GetPreAbilityRecord(); + if (preAbility == nullptr) { + dumpInfo = " previous ability app name [NULL]" + LINE_SEPARATOR; + dumpInfo += " previous ability file name [NULL]"; + } else { + dumpInfo = + " previous ability app name [" + preAbility->GetAbilityInfo().applicationName + "]" + LINE_SEPARATOR; + dumpInfo += " previous ability file name [" + preAbility->GetAbilityInfo().name + "]"; + } + info.push_back(dumpInfo); + std::shared_ptr nextAbility = GetNextAbilityRecord(); + if (nextAbility == nullptr) { + dumpInfo = " next ability app name [NULL]" + LINE_SEPARATOR; + dumpInfo += " next ability file name [NULL]"; + } else { + dumpInfo = + " next ability app name [" + nextAbility->GetAbilityInfo().applicationName + "]" + LINE_SEPARATOR; + dumpInfo += " next ability main name [" + nextAbility->GetAbilityInfo().name + "]"; + } + info.push_back(dumpInfo); + dumpInfo = " state #" + AbilityRecord::ConvertAbilityState(GetAbilityState()) + " start time [" + + std::to_string(startTime_) + "]"; + info.push_back(dumpInfo); + dumpInfo = " app state #" + AbilityRecord::ConvertAppState(appState_); + info.push_back(dumpInfo); + dumpInfo = " ready #" + std::to_string(isReady_) + " window attached #" + + std::to_string(isWindowAttached_) + " launcher #" + std::to_string(isLauncherAbility_); + info.push_back(dumpInfo); + + if (isLauncherRoot_ && IsNewVersion()) { + dumpInfo = " can restart num #" + std::to_string(restartCount_); + info.push_back(dumpInfo); + } + // add dump client info + if (isClient && scheduler_ && isReady_) { + std::vector params; + scheduler_->DumpAbilityInfo(params, info); + AppExecFwk::Configuration config; + if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { + info.emplace_back(" configuration: " + config.GetName()); + } + } +} + } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index 5ef0aa0f096..bdf34a06b6f 100755 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -41,7 +41,7 @@ void AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option; if (!WriteInterfaceToken(data)) { return; } diff --git a/services/abilitymgr/src/call_container.cpp b/services/abilitymgr/src/call_container.cpp index 5782444019f..4657a6051f2 100644 --- a/services/abilitymgr/src/call_container.cpp +++ b/services/abilitymgr/src/call_container.cpp @@ -1,189 +1,195 @@ -/* - * Copyright (c) 2021 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 "call_container.h" - -#include "hilog_wrapper.h" -#include "ability_manager_errors.h" -#include "ability_connect_callback_stub.h" -#include "ability_util.h" -#include "ability_event_handler.h" -#include "ability_manager_service.h" - -namespace OHOS { -namespace AAFwk { -CallContainer::CallContainer() -{} - -CallContainer::~CallContainer() -{ - std::for_each(deathRecipientMap_.begin(), - deathRecipientMap_.end(), - [&](RecipientMapType::reference recipient) { - recipient.first->RemoveDeathRecipient(recipient.second); - }); - - deathRecipientMap_.clear(); - callRecordMap_.clear(); -} - -void CallContainer::AddCallRecord(const sptr & connect, - const std::shared_ptr& callRecord) -{ - CHECK_POINTER(callRecord); - CHECK_POINTER(connect); - CHECK_POINTER(connect->AsObject()); - - auto iter = callRecordMap_.find(connect->AsObject()); - if (iter != callRecordMap_.end()) { - RemoveConnectDeathRecipient(connect); - callRecordMap_.erase(callRecordMap_.find(connect->AsObject())); - } - - AddConnectDeathRecipient(connect); - callRecord->SetConCallBack(connect); - callRecordMap_.emplace(connect->AsObject(), callRecord); - - HILOG_DEBUG("Add call record to callcontainer, target: %{public}s", - callRecord->GetTargetServiceName().GetURI().c_str()); -} - -std::shared_ptr CallContainer::GetCallRecord(const sptr & connect) const -{ - CHECK_POINTER_AND_RETURN(connect, nullptr); - CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr); - - auto mapIter = callRecordMap_.find(connect->AsObject()); - if (mapIter != callRecordMap_.end()) { - return mapIter->second; - } - - return nullptr; -} - -bool CallContainer::RemoveCallRecord(const sptr & connect) -{ - HILOG_DEBUG("call container release call record by callback."); - CHECK_POINTER_AND_RETURN(connect, nullptr); - CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr); - - auto iter = callRecordMap_.find(connect->AsObject()); - if (iter != callRecordMap_.end()) { - auto callrecord = iter->second; - if (callrecord) { - callrecord->SchedulerDisConnectDone(); - } - RemoveConnectDeathRecipient(connect); - callRecordMap_.erase(callRecordMap_.find(connect->AsObject())); - HILOG_DEBUG("remove call record is success."); - return true; - } - - if (callRecordMap_.empty()) { - // notify soft resouce service. - HILOG_DEBUG("this ability has no callrecord."); - } - - HILOG_WARN("remove call record is not exist."); - return false; -} - -void CallContainer::OnConnectionDied(const wptr & remote) -{ - HILOG_WARN("Call back is died."); - auto object = remote.promote(); - CHECK_POINTER(object); - - std::shared_ptr callRecord = nullptr; - auto mapIter = callRecordMap_.find(object); - if (mapIter != callRecordMap_.end()) { - callRecord = mapIter->second; - } - - auto abilityManagerService = DelayedSingleton::GetInstance(); - CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); - CHECK_POINTER(handler); - auto task = [abilityManagerService, callRecord]() { - abilityManagerService->OnCallConnectDied(callRecord); - }; - handler->PostTask(task); -} - -bool CallContainer::CallRequestDone(const sptr & callStub) -{ - HILOG_INFO("Call Request Done start."); - - CHECK_POINTER_AND_RETURN(callStub, false); - - std::for_each(callRecordMap_.begin(), - callRecordMap_.end(), - [&callStub](CallMapType::reference service) { - std::shared_ptr callRecord = service.second; - if (callRecord && callRecord->IsCallState(CallState::REQUESTING)) { - callRecord->SetCallStub(callStub); - callRecord->SchedulerConnectDone(); - } - }); - - HILOG_INFO("Call Request Done end."); - return true; -} - -void CallContainer::Dump(std::vector &info, const std::string &args) const -{ - HILOG_INFO("Dump call records."); -} - -bool CallContainer::IsNeedToCallRequest() const -{ - for (auto &iter : callRecordMap_) { - auto callRecord = iter.second; - if (callRecord && !callRecord->IsCallState(CallState::REQUESTED)) { - return true; - } - } - return false; -} - -void CallContainer::AddConnectDeathRecipient(const sptr &connect) -{ - CHECK_POINTER(connect); - CHECK_POINTER(connect->AsObject()); - auto it = deathRecipientMap_.find(connect->AsObject()); - if (it != deathRecipientMap_.end()) { - HILOG_ERROR("This death recipient has been added."); - return; - } else { - sptr deathRecipient = new AbilityConnectCallbackRecipient( - std::bind(&CallContainer::OnConnectionDied, this, std::placeholders::_1)); - connect->AsObject()->AddDeathRecipient(deathRecipient); - deathRecipientMap_.emplace(connect->AsObject(), deathRecipient); - } -} - -void CallContainer::RemoveConnectDeathRecipient(const sptr &connect) -{ - CHECK_POINTER(connect); - CHECK_POINTER(connect->AsObject()); - auto it = deathRecipientMap_.find(connect->AsObject()); - if (it != deathRecipientMap_.end()) { - it->first->RemoveDeathRecipient(it->second); - deathRecipientMap_.erase(it); - return; - } -} -} // namespace AAFwk -} // namesspace OHOS +/* + * Copyright (c) 2021 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 "call_container.h" + +#include "hilog_wrapper.h" +#include "ability_manager_errors.h" +#include "ability_connect_callback_stub.h" +#include "ability_util.h" +#include "ability_event_handler.h" +#include "ability_manager_service.h" + +namespace OHOS { +namespace AAFwk { +CallContainer::CallContainer() +{} + +CallContainer::~CallContainer() +{ + std::for_each(deathRecipientMap_.begin(), + deathRecipientMap_.end(), + [&](RecipientMapType::reference recipient) { + recipient.first->RemoveDeathRecipient(recipient.second); + }); + + deathRecipientMap_.clear(); + callRecordMap_.clear(); +} + +void CallContainer::AddCallRecord(const sptr & connect, + const std::shared_ptr& callRecord) +{ + CHECK_POINTER(callRecord); + CHECK_POINTER(connect); + CHECK_POINTER(connect->AsObject()); + + auto iter = callRecordMap_.find(connect->AsObject()); + if (iter != callRecordMap_.end()) { + RemoveConnectDeathRecipient(connect); + callRecordMap_.erase(callRecordMap_.find(connect->AsObject())); + } + + AddConnectDeathRecipient(connect); + callRecord->SetConCallBack(connect); + callRecordMap_.emplace(connect->AsObject(), callRecord); + + HILOG_DEBUG("Add call record to callcontainer, target: %{public}s", + callRecord->GetTargetServiceName().GetURI().c_str()); +} + +std::shared_ptr CallContainer::GetCallRecord(const sptr & connect) const +{ + CHECK_POINTER_AND_RETURN(connect, nullptr); + CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr); + + auto mapIter = callRecordMap_.find(connect->AsObject()); + if (mapIter != callRecordMap_.end()) { + return mapIter->second; + } + + return nullptr; +} + +bool CallContainer::RemoveCallRecord(const sptr & connect) +{ + HILOG_DEBUG("call container release call record by callback."); + CHECK_POINTER_AND_RETURN(connect, nullptr); + CHECK_POINTER_AND_RETURN(connect->AsObject(), nullptr); + + auto iter = callRecordMap_.find(connect->AsObject()); + if (iter != callRecordMap_.end()) { + auto callrecord = iter->second; + if (callrecord) { + callrecord->SchedulerDisConnectDone(); + } + RemoveConnectDeathRecipient(connect); + callRecordMap_.erase(callRecordMap_.find(connect->AsObject())); + HILOG_DEBUG("remove call record is success."); + return true; + } + + if (callRecordMap_.empty()) { + // notify soft resouce service. + HILOG_DEBUG("this ability has no callrecord."); + } + + HILOG_WARN("remove call record is not exist."); + return false; +} + +void CallContainer::OnConnectionDied(const wptr & remote) +{ + HILOG_WARN("Call back is died."); + auto object = remote.promote(); + CHECK_POINTER(object); + + std::shared_ptr callRecord = nullptr; + auto mapIter = callRecordMap_.find(object); + if (mapIter != callRecordMap_.end()) { + callRecord = mapIter->second; + } + + auto abilityManagerService = DelayedSingleton::GetInstance(); + CHECK_POINTER(abilityManagerService); + auto handler = abilityManagerService->GetEventHandler(); + CHECK_POINTER(handler); + auto task = [abilityManagerService, callRecord]() { + abilityManagerService->OnCallConnectDied(callRecord); + }; + handler->PostTask(task); +} + +bool CallContainer::CallRequestDone(const sptr & callStub) +{ + HILOG_INFO("Call Request Done start."); + + CHECK_POINTER_AND_RETURN(callStub, false); + + std::for_each(callRecordMap_.begin(), + callRecordMap_.end(), + [&callStub](CallMapType::reference service) { + std::shared_ptr callRecord = service.second; + if (callRecord && callRecord->IsCallState(CallState::REQUESTING)) { + callRecord->SetCallStub(callStub); + callRecord->SchedulerConnectDone(); + } + }); + + HILOG_INFO("Call Request Done end."); + return true; +} + +void CallContainer::Dump(std::vector &info) const +{ + HILOG_INFO("Dump call records."); + for (auto &iter : callRecordMap_) { + auto callRecord = iter.second; + if (callRecord) { + callRecord->Dump(info); + } + } +} + +bool CallContainer::IsNeedToCallRequest() const +{ + for (auto &iter : callRecordMap_) { + auto callRecord = iter.second; + if (callRecord && !callRecord->IsCallState(CallState::REQUESTED)) { + return true; + } + } + return false; +} + +void CallContainer::AddConnectDeathRecipient(const sptr &connect) +{ + CHECK_POINTER(connect); + CHECK_POINTER(connect->AsObject()); + auto it = deathRecipientMap_.find(connect->AsObject()); + if (it != deathRecipientMap_.end()) { + HILOG_ERROR("This death recipient has been added."); + return; + } else { + sptr deathRecipient = new AbilityConnectCallbackRecipient( + std::bind(&CallContainer::OnConnectionDied, this, std::placeholders::_1)); + connect->AsObject()->AddDeathRecipient(deathRecipient); + deathRecipientMap_.emplace(connect->AsObject(), deathRecipient); + } +} + +void CallContainer::RemoveConnectDeathRecipient(const sptr &connect) +{ + CHECK_POINTER(connect); + CHECK_POINTER(connect->AsObject()); + auto it = deathRecipientMap_.find(connect->AsObject()); + if (it != deathRecipientMap_.end()) { + it->first->RemoveDeathRecipient(it->second); + deathRecipientMap_.erase(it); + return; + } +} +} // namespace AAFwk +} // namesspace OHOS diff --git a/services/abilitymgr/src/call_record.cpp b/services/abilitymgr/src/call_record.cpp index 59098ac815b..af05bb49465 100644 --- a/services/abilitymgr/src/call_record.cpp +++ b/services/abilitymgr/src/call_record.cpp @@ -1,181 +1,200 @@ -/* - * Copyright (c) 2021 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 "call_record.h" - -#include "hilog_wrapper.h" -#include "ability_util.h" -#include "ability_event_handler.h" -#include "ability_manager_service.h" -#include "ability_record.h" -#include "element_name.h" - -namespace OHOS { -namespace AAFwk { -int64_t CallRecord::callRecordId = 0; - -CallRecord::CallRecord(const int32_t callerUid, const std::shared_ptr &targetService, - const sptr &connCallback, const sptr &callToken) - : callerUid_(callerUid), - state_(CallState::INIT), - service_(targetService), - connCallback_(connCallback), - callerToken_(callToken) -{ - recordId_ = callRecordId++; - startTime_ = AbilityUtil::SystemTimeMillis(); -} - -CallRecord::~CallRecord() -{ - if (callRemoteObject_ && callDeathRecipient_) { - callRemoteObject_->RemoveDeathRecipient(callDeathRecipient_); - } -} - -std::shared_ptr CallRecord::CreateCallRecord(const int32_t callerUid, - const std::shared_ptr &targetService, const sptr &connCallback, - const sptr &callToken) -{ - auto callRecord = std::make_shared(callerUid, targetService, connCallback, callToken); - CHECK_POINTER_AND_RETURN(callRecord, nullptr); - callRecord->SetCallState(CallState::INIT); - return callRecord; -} - -void CallRecord::SetCallStub(const sptr & call) -{ - CHECK_POINTER(call); - - callRemoteObject_ = call; - - HILOG_DEBUG("SetCallStub complete."); - - if (callDeathRecipient_ == nullptr) { - callDeathRecipient_ = - new AbilityCallRecipient(std::bind(&CallRecord::OnCallStubDied, this, std::placeholders::_1)); - } - - callRemoteObject_->AddDeathRecipient(callDeathRecipient_); -} - -sptr CallRecord::GetCallStub() -{ - return callRemoteObject_; -} - -void CallRecord::SetConCallBack(const sptr &connCallback) -{ - connCallback_ = connCallback; -} - -sptr CallRecord::GetConCallBack() const -{ - return connCallback_; -} - -AppExecFwk::ElementName CallRecord::GetTargetServiceName() const -{ - std::shared_ptr tmpService = service_.lock(); - if (tmpService) { - const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo(); - AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); - return element; - } - return AppExecFwk::ElementName(); -} - -sptr CallRecord::GetCallerToken() const -{ - return callerToken_; -} - -bool CallRecord::SchedulerConnectDone() -{ - HILOG_DEBUG("Scheduler Connect Done by callback. id:%{public}d", recordId_); - std::shared_ptr tmpService = service_.lock(); - if (!callRemoteObject_ || !connCallback_ || !tmpService) { - HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done."); - return false; - } - - const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo(); - AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); - connCallback_->OnAbilityConnectDone(element, callRemoteObject_, ERR_OK); - state_ = CallState::REQUESTED; - - HILOG_DEBUG("element: %{public}s, result: %{public}d. connectstate:%{public}d.", element.GetURI().c_str(), - ERR_OK, state_); - return true; -} - -bool CallRecord::SchedulerDisConnectDone() -{ - HILOG_DEBUG("Scheduler disconnect Done by callback. id:%{public}d", recordId_); - std::shared_ptr tmpService = service_.lock(); - if (!connCallback_ || !tmpService) { - HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done."); - return false; - } - - const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo(); - AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); - connCallback_->OnAbilityDisconnectDone(element, ERR_OK); - - return true; -} - -void CallRecord::OnCallStubDied(const wptr & remote) -{ - HILOG_WARN("callstub is died. id:%{public}d", recordId_); - auto object = remote.promote(); - CHECK_POINTER(object); - - auto abilityManagerService = DelayedSingleton::GetInstance(); - CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); - CHECK_POINTER(handler); - auto task = [abilityManagerService, callRecord = shared_from_this()]() { - abilityManagerService->OnCallConnectDied(callRecord); - }; - handler->PostTask(task); -} - -void CallRecord::Dump(std::vector &info) const -{ - HILOG_DEBUG("CallRecord::Dump is called"); -} - -int32_t CallRecord::GetCallerUid() const -{ - return callerUid_; -} - -bool CallRecord::IsCallState(const CallState& state) const -{ - return (state_ == state); -} - -void CallRecord::SetCallState(const CallState& state) -{ - state_ = state; -} - -int CallRecord::GetCallRecordId() const -{ - return recordId_; -} -} // namespace AAFwk +/* + * Copyright (c) 2021 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 "call_record.h" + +#include "hilog_wrapper.h" +#include "ability_util.h" +#include "ability_event_handler.h" +#include "ability_manager_service.h" +#include "ability_record.h" +#include "element_name.h" + +namespace OHOS { +namespace AAFwk { +int64_t CallRecord::callRecordId = 0; + +CallRecord::CallRecord(const int32_t callerUid, const std::shared_ptr &targetService, + const sptr &connCallback, const sptr &callToken) + : callerUid_(callerUid), + state_(CallState::INIT), + service_(targetService), + connCallback_(connCallback), + callerToken_(callToken) +{ + recordId_ = callRecordId++; + startTime_ = AbilityUtil::SystemTimeMillis(); +} + +CallRecord::~CallRecord() +{ + if (callRemoteObject_ && callDeathRecipient_) { + callRemoteObject_->RemoveDeathRecipient(callDeathRecipient_); + } +} + +std::shared_ptr CallRecord::CreateCallRecord(const int32_t callerUid, + const std::shared_ptr &targetService, const sptr &connCallback, + const sptr &callToken) +{ + auto callRecord = std::make_shared(callerUid, targetService, connCallback, callToken); + CHECK_POINTER_AND_RETURN(callRecord, nullptr); + callRecord->SetCallState(CallState::INIT); + return callRecord; +} + +void CallRecord::SetCallStub(const sptr & call) +{ + CHECK_POINTER(call); + + callRemoteObject_ = call; + + HILOG_DEBUG("SetCallStub complete."); + + if (callDeathRecipient_ == nullptr) { + callDeathRecipient_ = + new AbilityCallRecipient(std::bind(&CallRecord::OnCallStubDied, this, std::placeholders::_1)); + } + + callRemoteObject_->AddDeathRecipient(callDeathRecipient_); +} + +sptr CallRecord::GetCallStub() +{ + return callRemoteObject_; +} + +void CallRecord::SetConCallBack(const sptr &connCallback) +{ + connCallback_ = connCallback; +} + +sptr CallRecord::GetConCallBack() const +{ + return connCallback_; +} + +AppExecFwk::ElementName CallRecord::GetTargetServiceName() const +{ + std::shared_ptr tmpService = service_.lock(); + if (tmpService) { + const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo(); + AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); + return element; + } + return AppExecFwk::ElementName(); +} + +sptr CallRecord::GetCallerToken() const +{ + return callerToken_; +} + +bool CallRecord::SchedulerConnectDone() +{ + HILOG_DEBUG("Scheduler Connect Done by callback. id:%{public}d", recordId_); + std::shared_ptr tmpService = service_.lock(); + if (!callRemoteObject_ || !connCallback_ || !tmpService) { + HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done."); + return false; + } + + const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo(); + AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); + connCallback_->OnAbilityConnectDone(element, callRemoteObject_, ERR_OK); + state_ = CallState::REQUESTED; + + HILOG_DEBUG("element: %{public}s, result: %{public}d. connectstate:%{public}d.", element.GetURI().c_str(), + ERR_OK, state_); + return true; +} + +bool CallRecord::SchedulerDisConnectDone() +{ + HILOG_DEBUG("Scheduler disconnect Done by callback. id:%{public}d", recordId_); + std::shared_ptr tmpService = service_.lock(); + if (!connCallback_ || !tmpService) { + HILOG_ERROR("callstub or connCallback is nullptr, can't scheduler connect done."); + return false; + } + + const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo(); + AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); + connCallback_->OnAbilityDisconnectDone(element, ERR_OK); + + return true; +} + +void CallRecord::OnCallStubDied(const wptr & remote) +{ + HILOG_WARN("callstub is died. id:%{public}d", recordId_); + auto object = remote.promote(); + CHECK_POINTER(object); + + auto abilityManagerService = DelayedSingleton::GetInstance(); + CHECK_POINTER(abilityManagerService); + auto handler = abilityManagerService->GetEventHandler(); + CHECK_POINTER(handler); + auto task = [abilityManagerService, callRecord = shared_from_this()]() { + abilityManagerService->OnCallConnectDied(callRecord); + }; + handler->PostTask(task); +} + +void CallRecord::Dump(std::vector &info) const +{ + HILOG_DEBUG("CallRecord::Dump is called"); + + std::string tempstr = " CallRecord"; + tempstr += " ID #" + std::to_string (recordId_) + "\n"; + tempstr += " caller"; + auto abilityRecord = Token::GetAbilityRecordByToken(callerToken_); + + if (abilityRecord) { + AppExecFwk::ElementName element( + abilityRecord->GetAbilityInfo().deviceId, abilityRecord->GetAbilityInfo().bundleName, + abilityRecord->GetAbilityInfo().name); + tempstr += " uri [" + element.GetURI() + "]" + "\n"; + } + + std::string state = (state_ == CallState::INIT ? "INIT" : + state_ == CallState::REQUESTING ? "REQUESTING" : "REQUESTED"); + tempstr += " state #" + state; + tempstr += " start time [" + std::to_string (startTime_) + "]"; + info.emplace_back(tempstr); + HILOG_DEBUG("CallRecord::Dump is called1"); +} + +int32_t CallRecord::GetCallerUid() const +{ + return callerUid_; +} + +bool CallRecord::IsCallState(const CallState& state) const +{ + return (state_ == state); +} + +void CallRecord::SetCallState(const CallState& state) +{ + state_ = state; +} + +int CallRecord::GetCallRecordId() const +{ + return recordId_; +} +} // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index 898e3847432..7ffe496e91f 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -495,6 +495,47 @@ void DataAbilityManager::DumpState(std::vector &info, const std::st return; } +void DataAbilityManager::DumpSysState(std::vector &info, bool isClient, const std::string &args) const +{ + if (!args.empty()) { + auto it = std::find_if(dataAbilityRecordsLoaded_.begin(), + dataAbilityRecordsLoaded_.end(), + [&args](const auto &dataAbilityRecord) { return dataAbilityRecord.first.compare(args) == 0; }); + if (it != dataAbilityRecordsLoaded_.end()) { + info.emplace_back("AbilityName [ " + it->first + " ]"); + it->second->Dump(info); + // add dump client info + if (isClient && it->second->GetScheduler() && it->second->GetAbilityRecord()->IsReady()) { + std::vector params; + it->second->GetScheduler()->DumpAbilityInfo(params, info); + AppExecFwk::Configuration config; + if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { + info.emplace_back(" configuration: " + config.GetName()); + } + } + } else { + info.emplace_back(args + ": Nothing to dump."); + } + } else { + info.emplace_back(" dataAbilityRecords:"); + for (auto &&dataAbilityRecord : dataAbilityRecordsLoaded_) { + info.emplace_back(" uri [" + dataAbilityRecord.first + "]"); + dataAbilityRecord.second->Dump(info); + dataAbilityRecord.second->GetScheduler(); + // add dump client info + if (isClient && dataAbilityRecord.second->GetScheduler() && dataAbilityRecord.second->GetAbilityRecord()->IsReady()) { + std::vector params; + dataAbilityRecord.second->GetScheduler()->DumpAbilityInfo(params, info); + AppExecFwk::Configuration config; + if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { + info.emplace_back(" configuration: " + config.GetName()); + } + } + } + } + return; +} + void DataAbilityManager::GetAbilityRunningInfos(std::vector &info) { HILOG_INFO("Get ability running infos"); diff --git a/services/abilitymgr/src/kernal_ability_manager.cpp b/services/abilitymgr/src/kernal_ability_manager.cpp index 1667b8db46f..b7e65d4c93a 100644 --- a/services/abilitymgr/src/kernal_ability_manager.cpp +++ b/services/abilitymgr/src/kernal_ability_manager.cpp @@ -306,6 +306,14 @@ void KernalAbilityManager::DumpState(std::vector &info) } } +void KernalAbilityManager::DumpSysState(std::vector& info, bool isClient) +{ + info.emplace_back("SystemUIRecords:"); + for (auto &ability : abilities_) { + ability->DumpSys(info, isClient); + } +} + void KernalAbilityManager::OnAbilityDied(std::shared_ptr abilityRecord) { std::lock_guard guard(stackLock_); diff --git a/services/abilitymgr/src/kernal_system_app_manager.cpp b/services/abilitymgr/src/kernal_system_app_manager.cpp index a785eb6aca9..0270ce51c92 100644 --- a/services/abilitymgr/src/kernal_system_app_manager.cpp +++ b/services/abilitymgr/src/kernal_system_app_manager.cpp @@ -321,6 +321,13 @@ void KernalSystemAppManager::DumpState(std::vector &info) ability->Dump(info); } } +void KernalSystemAppManager::DumpSysState(std::vector &info, bool isClient) +{ + info.emplace_back("SystemUIRecords:"); + for (auto &ability : abilities_) { + ability->DumpSys(info,isClient); + } +} void KernalSystemAppManager::OnAbilityDied(std::shared_ptr abilityRecord) { diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission_list.cpp index 24e621a6808..3771dc7c029 100644 --- a/services/abilitymgr/src/mission_list.cpp +++ b/services/abilitymgr/src/mission_list.cpp @@ -239,7 +239,7 @@ std::string MissionList::GetTypeName() return "NORMAL"; } case MissionListType::DEFAULT_STANDARD: { - return "DEFAULT_STAND"; + return "DEFAULT_STANDARD"; } case MissionListType::DEFAULT_SINGLE: { return "DEFAULT_SINGLE"; @@ -282,12 +282,12 @@ void MissionList::DumpStateByRecordId( } void MissionList::DumpList(std::vector &info, bool isClient) { - std::string dumpInfo = " MissionList Type #" + GetTypeName(); + std::string dumpInfo = " MissionList Type #" + GetTypeName(); info.push_back(dumpInfo); for (const auto& mission : missions_) { if (mission) { - dumpInfo = " Mission ID #" + std::to_string(mission->GetMissionId()); + dumpInfo = " Mission ID #" + std::to_string(mission->GetMissionId()); dumpInfo += " mission name #[" + mission->GetMissionName() + "]" + " lockedState #" + std::to_string(mission->IsLockedState()); info.push_back(dumpInfo); diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 22c15e65d9c..945de36ea8d 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -592,6 +592,63 @@ void MissionListManager::OnAbilityRequestDone(const sptr &token, } } +void MissionListManager::OnAppStateChanged(const AppInfo &info) +{ + std::lock_guard guard(managerLock_); + + if (info.state == AppState::TERMINATED || info.state == AppState::END) { + for (const auto& abilityRecord : terminateAbilityList_) { + if (!abilityRecord) { + HILOG_ERROR("abilityRecord is nullptr."); + continue; + } + if (info.processName == abilityRecord->GetAbilityInfo().process || + info.processName == abilityRecord->GetApplicationInfo().bundleName) { + abilityRecord->SetAppState(info.state); + } + } + } else { + for (const auto& missionList : currentMissionLists_) { + auto missions = missionList->GetAllMissions(); + for (const auto& missionInfo : missions) { + if (!missionInfo) { + HILOG_ERROR("missionInfo is nullptr."); + continue; + } + auto abilityRecord = missionInfo->GetAbilityRecord(); + if (info.processName == abilityRecord->GetAbilityInfo().process || + info.processName == abilityRecord->GetApplicationInfo().bundleName) { + abilityRecord->SetAppState(info.state); + } + } + } + auto defaultStandardListmissions = defaultStandardList_->GetAllMissions(); + for (const auto& missionInfo : defaultStandardListmissions) { + if (!missionInfo) { + HILOG_ERROR("defaultStandardListmissions is nullptr."); + continue; + } + auto abilityRecord = missionInfo->GetAbilityRecord(); + if (info.processName == abilityRecord->GetAbilityInfo().process || + info.processName == abilityRecord->GetApplicationInfo().bundleName) { + abilityRecord->SetAppState(info.state); + } + } + auto defaultSingleListmissions = defaultSingleList_->GetAllMissions(); + for (const auto& missionInfo : defaultSingleListmissions) { + if (!missionInfo) { + HILOG_ERROR("defaultSingleListmissions is nullptr."); + continue; + } + auto abilityRecord = missionInfo->GetAbilityRecord(); + if (info.processName == abilityRecord->GetAbilityInfo().process || + info.processName == abilityRecord->GetApplicationInfo().bundleName) { + abilityRecord->SetAppState(info.state); + } + } + } +} + std::shared_ptr MissionListManager::GetAbilityRecordByToken( const sptr &token) const { @@ -809,7 +866,7 @@ void MissionListManager::CompleteBackground(const std::shared_ptr } int MissionListManager::TerminateAbility(const std::shared_ptr &abilityRecord, - int resultCode, const Want *resultWant, bool flag) + int resultCode, const Want *resultWant) { std::string element = abilityRecord->GetWant().GetElement().GetURI(); HILOG_DEBUG("Terminate ability, ability is %{public}s", element.c_str()); @@ -831,7 +888,7 @@ int MissionListManager::TerminateAbility(const std::shared_ptr &a abilityRecord->SaveResultToCallers(resultCode, resultWant); } - return TerminateAbilityLocked(abilityRecord, flag); + return TerminateAbilityLocked(abilityRecord); } int MissionListManager::TerminateAbility(const std::shared_ptr &caller, int requestCode) @@ -851,15 +908,15 @@ int MissionListManager::TerminateAbility(const std::shared_ptr &c return result; } - return TerminateAbility(targetAbility, DEFAULT_INVAL_VALUE, nullptr, true); + return TerminateAbility(targetAbility, DEFAULT_INVAL_VALUE, nullptr); } -int MissionListManager::TerminateAbilityLocked(const std::shared_ptr &abilityRecord, bool flag) +int MissionListManager::TerminateAbilityLocked(const std::shared_ptr &abilityRecord) { std::string element = abilityRecord->GetWant().GetElement().GetURI(); HILOG_DEBUG("Terminate ability locked, ability is %{public}s", element.c_str()); // remove AbilityRecord out of stack - RemoveTerminatingAbility(abilityRecord, flag); + RemoveTerminatingAbility(abilityRecord); abilityRecord->SendResultToCallers(); // 1. if the ability was foregorund, first should find wether there is other ability foregorund @@ -895,7 +952,7 @@ int MissionListManager::TerminateAbilityLocked(const std::shared_ptr &abilityRecord, bool flag) +void MissionListManager::RemoveTerminatingAbility(const std::shared_ptr &abilityRecord) { std::string element = abilityRecord->GetWant().GetElement().GetURI(); HILOG_DEBUG("RemoveTerminatingAbility, ability is %{public}s", element.c_str()); @@ -918,9 +975,9 @@ void MissionListManager::RemoveTerminatingAbility(const std::shared_ptrGetAbilityState()); return; } - // 3. if close ability, noting to do - if (!flag) { - HILOG_DEBUG("close ability schedule."); + // 3. if run on a laptop, noting to do + if (IsPC()) { + HILOG_DEBUG("Run on a laptop, no need to schedule next ability."); return; } @@ -1064,7 +1121,7 @@ int MissionListManager::ClearMissionLocked(int missionId, std::shared_ptrSetTerminatingState(); - auto ret = TerminateAbilityLocked(abilityRecord, false); + auto ret = TerminateAbilityLocked(abilityRecord); if (ret != ERR_OK) { HILOG_ERROR("clear mission error: %{public}d.", ret); return REMOVE_MISSION_FAILED; @@ -1609,48 +1666,51 @@ void MissionListManager::DumpMissionListByRecordId( void MissionListManager::DumpMissionList(std::vector &info, bool isClient, const std::string &args) { std::lock_guard guard(managerLock_); + + if (args.size() != 0 && + args != "NORMAL" && + args != "DEFAULT_STANDARD" && + args != "DEFAULT_SINGLE" && + args != "LAUNCHER") { + info.emplace_back("MissionList Type NORMAL|DEFAULT_STANDARD|DEFAULT_SINGLE|LAUNCHER"); + return; + } + std::string dumpInfo = "User ID #" + std::to_string(userId_); info.push_back(dumpInfo); if (args.size() == 0 || args == "NORMAL") { - dumpInfo = " current mission lists:{"; + dumpInfo = " Current mission lists:"; info.push_back(dumpInfo); for (const auto& missionList : currentMissionLists_) { if (missionList) { missionList->DumpList(info, isClient); } } - dumpInfo = " }"; - info.push_back(dumpInfo); } if (args.size() == 0 || args == "DEFAULT_STANDARD") { - dumpInfo = " default stand mission list:{"; + dumpInfo = " default stand mission list:"; info.push_back(dumpInfo); if (defaultStandardList_) { defaultStandardList_->DumpList(info, isClient); } - dumpInfo = " }"; - info.push_back(dumpInfo); } if (args.size() == 0 || args == "DEFAULT_SINGLE") { - dumpInfo = " default single mission list:{"; + dumpInfo = " default single mission list:"; info.push_back(dumpInfo); if (defaultSingleList_) { defaultSingleList_->DumpList(info, isClient); } - dumpInfo = " }"; - info.push_back(dumpInfo); } if (args.size() == 0 || args == "LAUNCHER") { - dumpInfo = " launcher mission list:{"; + dumpInfo = " launcher mission list:"; info.push_back(dumpInfo); if (launcherList_) { launcherList_->DumpList(info, isClient); } - dumpInfo = " }"; - info.push_back(dumpInfo); } + } void MissionListManager::DumpMissionInfos(std::vector &info) @@ -1869,6 +1929,33 @@ std::shared_ptr MissionListManager::GetMissionBySpecifiedFlag(const std return defaultStandardList_->GetMissionBySpecifiedFlag(flag); } +bool MissionListManager::IsPC() +{ + if (MissionDmInitCallback::isInit_) { + return isPC_; + } + std::string pkgName = "ohos.aafwk.aafwk_standard"; + auto callback = std::make_shared(); + int32_t ret = DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(pkgName, callback); + if (ret != ERR_OK) { + HILOG_WARN("DeviceManager initialization failed."); + return false; + } + DistributedHardware::DmDeviceInfo deviceInfo; + ret = DistributedHardware::DeviceManager::GetInstance().GetLocalDeviceInfo(pkgName, deviceInfo); + if (ret != ERR_OK) { + HILOG_WARN("Failed to get local device info."); + return false; + } + MissionDmInitCallback::isInit_ = true; + if (deviceInfo.deviceTypeId != DistributedHardware::DmDeviceType::DEVICE_TYPE_PC) { + HILOG_WARN("The device is not a laptop."); + return false; + } + isPC_ = true; + return isPC_; +} + bool MissionListManager::MissionDmInitCallback::isInit_ = false; void MissionListManager::MissionDmInitCallback::OnRemoteDied() { diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index 22f19601b8c..b1ffa0633c5 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -524,7 +524,7 @@ void PendingWantManager::Dump(std::vector &info) for (const auto &item : wantRecords_) { const auto &pendingKey = item.first; - dumpInfo = " PendWantRecord ID #" + std::to_string(pendingKey->GetUserId()) + + dumpInfo = " PendWantRecord ID #" + std::to_string(pendingKey->GetCode()) + " type #" + std::to_string(pendingKey->GetType()); info.push_back(dumpInfo); dumpInfo = " bundle name [" + pendingKey->GetBundleName() + "]"; @@ -548,5 +548,41 @@ void PendingWantManager::Dump(std::vector &info) } } } +void PendingWantManager::DumpByRecordId(std::vector &info, const std::string &args) +{ + + std::string dumpInfo = " PendingWantRecords:"; + info.push_back(dumpInfo); + + for (const auto &item : wantRecords_) { + const auto &pendingKey = item.first; + if (args == std::to_string(pendingKey->GetCode())) + { + dumpInfo = " PendWantRecord ID #" + std::to_string(pendingKey->GetCode()) + + " type #" + std::to_string(pendingKey->GetType()); + info.push_back(dumpInfo); + dumpInfo = " bundle name [" + pendingKey->GetBundleName() + "]"; + info.push_back(dumpInfo); + dumpInfo = " result who [" + pendingKey->GetRequestWho() + "]"; + info.push_back(dumpInfo); + dumpInfo = " request code #" + std::to_string(pendingKey->GetRequestCode()) + + " flags #" + std::to_string(pendingKey->GetFlags()); + info.push_back(dumpInfo); + dumpInfo = " resolved type [" + pendingKey->GetRequestResolvedType() + "]"; + info.push_back(dumpInfo); + dumpInfo = " Wants:"; + info.push_back(dumpInfo); + auto Wants = pendingKey->GetAllWantsInfos(); + for (const auto& Want : Wants) { + dumpInfo = " uri [" + Want.want.GetElement().GetDeviceID() + "//" + + Want.want.GetElement().GetBundleName() + "/" + Want.want.GetElement().GetAbilityName() + "]"; + info.push_back(dumpInfo); + dumpInfo = " resolved types [" + Want.resolvedTypes + "]"; + info.push_back(dumpInfo); + } + } + } + +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index 61bc3ac8ea0..d06f56e6423 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -101,11 +101,7 @@ public: { return 0; } - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } + virtual int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 224a3dfc6e7..ea21028ca66 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -101,11 +101,7 @@ public: { return 0; } - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } + virtual int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h index 86e8505154f..2b6a3166749 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h @@ -35,11 +35,6 @@ public: MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); MOCK_METHOD2(StartAbility, int(const Want &, int)); MOCK_METHOD3(TerminateAbility, int(const sptr &, int, const Want *)); - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } virtual int MinimizeAbility(const sptr &token, bool fromUser = false) override { return 0; diff --git a/services/appmgr/lmks.cfg b/services/appmgr/lmks.cfg index 543b9700b84..e02a3865092 100755 --- a/services/appmgr/lmks.cfg +++ b/services/appmgr/lmks.cfg @@ -1,4 +1,11 @@ { + "jobs" : [{ + "name" : "late-fs", + "cmds" : [ + "start lmks" + ] + } + ], "services" : [{ "name" : "lmks", "path" : ["/system/bin/lmks"], diff --git a/services/formmgr/test/mock/include/mock_ability_manager.h b/services/formmgr/test/mock/include/mock_ability_manager.h index d109939e55c..80b69f608f2 100644 --- a/services/formmgr/test/mock/include/mock_ability_manager.h +++ b/services/formmgr/test/mock/include/mock_ability_manager.h @@ -433,11 +433,6 @@ public: { return 0; } - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } virtual int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/services/test/mock/include/appmgr/mock_ability_mgr_host.h b/services/test/mock/include/appmgr/mock_ability_mgr_host.h index 68b2e0fe79c..171319d34d7 100644 --- a/services/test/mock/include/appmgr/mock_ability_mgr_host.h +++ b/services/test/mock/include/appmgr/mock_ability_mgr_host.h @@ -55,11 +55,6 @@ public: { return 0; } - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } virtual int MinimizeAbility(const sptr &token, bool fromUser) override { return 0; diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index d16763d5304..385f2b969d4 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -29,12 +29,6 @@ public: int32_t userId, int requestCode)); MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr &callerToken, int requestCode)); MOCK_METHOD3(TerminateAbility, int(const sptr &token, int resultCode, const Want *resultWant)); - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } - virtual int MinimizeAbility(const sptr &token, bool fromUser = false) override { return 0; diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 7fde0445cb4..361e88ca31f 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -29,8 +29,7 @@ const std::string HELP_MSG = "usage: aa \n" " help list available commands\n" " start start ability with options\n" " stop-service stop service with options\n" - " dump dump the ability stack info\n" - " dumpsys dump the ability info\n" + " dump dump the ability info\n" " force-stop force stop the process with bundle name\n" " test start the test framework with options\n"; @@ -63,17 +62,23 @@ const std::string HELP_MSG_DUMP = "usage: aa dump \n" " -e, --serv dump the service abilities\n" " -d, --data dump the data abilities\n"; -const std::string HELP_MSG_DUMPSYS = "usage: aa dumpsys \n" +const std::string HELP_MSG_DUMPSYS = "usage: aa dump \n" "options list:\n" " -h, --help list available commands\n" " -a, --all dump all abilities\n" " -l, --mission-list dump mission list\n" " -i, --ability dump abilityRecordId\n" - " -e, --extension dump elementName\n" + " -e, --extension dump elementName (API7 ExtensionRecords,API8 serviceAbilityRecords)\n" " -p, --pending dump pendingWantRecordId\n" " -r, --process dump process\n" + " -d, --data dump the data abilities\n" + " -k, --ui dump the kenarl ability list ui stack\n" " -u, --userId userId\n" - " -c, --client client\n"; + " -c, --client client\n" + " -c, -u are auxiliary parameters and cannot be used alone\n" + " The original -s parameter is invalid\n" + " The original -m parameter is invalid\n"; + const std::string HELP_MSG_TEST = "usage: aa test \n" @@ -133,7 +138,7 @@ private: ErrCode RunAsDumpCommandOptopt(); ErrCode MakeWantFromCmd(Want &want, std::string &windowMode); - ErrCode RunAsDumpSysCommandOptopt(); + ErrCode RunAsTestCommand(); bool IsTestCommandIntegrity(const std::map ¶ms); diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index c95050bd1d0..6f39796ed22 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -53,7 +53,7 @@ const struct option LONG_OPTIONS_DUMP[] = { {"mission-infos", no_argument, nullptr, 'S'}, {nullptr, 0, nullptr, 0}, }; -const std::string SHORT_OPTIONS_DUMPSYS = "hal::i:e::p::r::u:c"; +const std::string SHORT_OPTIONS_DUMPSYS = "hal::i:e::p::r::kd::u:c"; const struct option LONG_OPTIONS_DUMPSYS[] = { {"help", no_argument, nullptr, 'h'}, {"all", no_argument, nullptr, 'a'}, @@ -62,6 +62,8 @@ const struct option LONG_OPTIONS_DUMPSYS[] = { {"extension", no_argument, nullptr, 'e'}, {"pending", no_argument, nullptr, 'p'}, {"process", no_argument, nullptr, 'r'}, + {"data", no_argument, nullptr, 'd'}, + {"ui", no_argument, nullptr, 'k'}, {"userId", required_argument, nullptr, 'u'}, {"client", no_argument, nullptr, 'c'}, {nullptr, 0, nullptr, 0}, @@ -82,8 +84,8 @@ ErrCode AbilityManagerShellCommand::CreateCommandMap() {"screen", std::bind(&AbilityManagerShellCommand::RunAsScreenCommand, this)}, {"start", std::bind(&AbilityManagerShellCommand::RunAsStartAbility, this)}, {"stop-service", std::bind(&AbilityManagerShellCommand::RunAsStopService, this)}, - {"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpCommand, this)}, - {"dumpsys", std::bind(&AbilityManagerShellCommand::RunAsDumpsysCommand, this)}, + // {"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpCommand, this)}, + {"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpsysCommand, this)}, {"force-stop", std::bind(&AbilityManagerShellCommand::RunAsForceStop, this)}, {"test", std::bind(&AbilityManagerShellCommand::RunAsTestCommand, this)}, }; @@ -626,7 +628,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() break; } case 'l': { - if (isfirstCommand == false) { + if (isfirstCommand == false && optarg == nullptr) { isfirstCommand = true; } else { // 'aa dumpsys -i 10 -element -lastpage' @@ -664,7 +666,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() break; } case 'e': { - if (isfirstCommand == false) { + if (isfirstCommand == false && optarg == nullptr) { isfirstCommand = true; } else { // 'aa dumpsys -i 10 -element' @@ -679,7 +681,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() break; } case 'p': { - if (isfirstCommand == false) { + if (isfirstCommand == false && optarg == nullptr) { isfirstCommand = true; } else { result = OHOS::ERR_INVALID_VALUE; @@ -691,8 +693,15 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() break; } case 'r': { - if (isfirstCommand == false) { + if (isfirstCommand == false && optarg == nullptr) { isfirstCommand = true; + int PendingWantRecordId = DEFAULT_INVAL_VALUE; + (void)StrToInt(optarg, PendingWantRecordId); + if (PendingWantRecordId == DEFAULT_INVAL_VALUE) { + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; + } } else { // 'aa dumpsys -i 10 -render' if (strcmp(optarg, "ender")) { @@ -705,6 +714,36 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() // 'aa dumpsys --process' break; } + case 'd': { + if (isfirstCommand == false && optarg == nullptr) { + isfirstCommand = true; + } else { + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; + } + // 'aa dumpsys -d' + // 'aa dumpsys --data' + break; + } + case 'k': { + if (isfirstCommand == false) { + isfirstCommand = true; + if (isUserID == true) { + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append("-k is no userID option\n"); + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; + } + } else { + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; + } + // 'aa dumpsys -k' + // 'aa dumpsys --UI' + break; + } case 'u': { // 'aa dumpsys -u' // 'aa dumpsys --userId' @@ -740,6 +779,7 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() } else { if (isfirstCommand != true) { result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_NO_OPTION); resultReceiver_.append(HELP_MSG_DUMPSYS); return result; } diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 10a5692a201..990e06c9547 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -46,11 +46,6 @@ public: MOCK_METHOD4(StartAbility, int(const Want &want, const sptr &callerToken, int32_t userId, int requestCode)); MOCK_METHOD3(TerminateAbility, int(const sptr &token, int resultCode, const Want *resultWant)); - virtual int CloseAbility(const sptr &token, int resultCode = DEFAULT_INVAL_VALUE, - const Want *resultWant = nullptr) override - { - return 0; - } virtual int MinimizeAbility(const sptr &token, bool fromUser = false) override { return 0; -- Gitee