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 7e3b629b23c7ff231ca7bfd77aab7dbc94f5c928..ceca9cbdaf9d52d38431833d4dc0d5e1f0fb49ab 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 @@ -128,8 +128,9 @@ public: MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); - #ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif diff --git a/frameworks/kits/ability/native/include/ability_thread.h b/frameworks/kits/ability/native/include/ability_thread.h index 245cc8e87a3c54cc28a004fd104b5840a1059bc9..1c93b53567e6ba13f304291b0ad5409b3e6f1ad9 100644 --- a/frameworks/kits/ability/native/include/ability_thread.h +++ b/frameworks/kits/ability/native/include/ability_thread.h @@ -395,8 +395,6 @@ public: std::vector> ExecuteBatch( const std::vector> &operations); private: - void DumpAbilityInfoInner(const std::vector ¶ms, std::vector &info); - void DumpOtherInfo(std::vector &info); /** * @description: Create the abilityname. * diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index 4a17f18ac64dcd20f778fcb7e9478f7271e1f400..80e5322f9a9cc10f4bd77c01bdf3b55cd4dfd846 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -1500,44 +1500,15 @@ std::shared_ptr AbilityThread::BuildAbilityConte return abilityContextImpl; } -void AbilityThread::DumpAbilityInfo(const std::vector ¶ms, std::vector &info) -{ - HILOG_INFO("%{public}s begin.", __func__); - if (token_ == nullptr) { - HILOG_ERROR("DumpAbilityInfo::failed, token_ nullptr"); - return; - } - wptr weak = this; - auto task = [weak, params, token = token_]() { - auto abilityThread = weak.promote(); - if (abilityThread == nullptr) { - HILOG_ERROR("abilityThread is nullptr, ScheduleAbilityTransaction failed."); - return; - } - std::vector dumpInfo; - abilityThread->DumpAbilityInfoInner(params, dumpInfo); - ErrCode err = AbilityManagerClient::GetInstance()->DumpAbilityInfoDone(dumpInfo, token); - if (err != ERR_OK) { - HILOG_ERROR("AbilityThread:: DumpAbilityInfo failed err = %{public}d", err); - } - }; - - if (abilityHandler_ == nullptr) { - HILOG_ERROR("AbilityThread::ScheduleAbilityTransaction abilityHandler_ == nullptr"); - return; - } - - abilityHandler_->PostTask(task); -} - #ifdef SUPPORT_GRAPHICS -void AbilityThread::DumpAbilityInfoInner(const std::vector ¶ms, std::vector &info) +void AbilityThread::DumpAbilityInfo(const std::vector ¶ms, std::vector &info) { HILOG_INFO("%{public}s begin.", __func__); if (currentAbility_ == nullptr && currentExtension_ == nullptr) { HILOG_INFO("currentAbility and currentExtension_ is nullptr."); return; } + if (currentAbility_ != nullptr) { if (abilityImpl_->IsStageBasedModel()) { auto scene = currentAbility_->GetScene(); @@ -1554,35 +1525,19 @@ void AbilityThread::DumpAbilityInfoInner(const std::vector ¶ms, } currentAbility_->Dump(params, info); } + if (currentExtension_ != nullptr) { currentExtension_->Dump(params, info); } - if (params.empty()) { + + if (!params.empty()) { HILOG_INFO("params not empty"); - DumpOtherInfo(info); return; } - HILOG_INFO("%{public}s end.", __func__); -} -#else -void AbilityThread::DumpAbilityInfoInner(const std::vector ¶ms, std::vector &info) -{ - HILOG_INFO("%{public}s begin.", __func__); - if (currentAbility_ != nullptr) { - currentAbility_->Dump(params, info); - } - if (currentExtension_ != nullptr) { - currentExtension_->Dump(params, info); - } - DumpOtherInfo(info); -} -#endif - -void AbilityThread::DumpOtherInfo(std::vector &info) -{ std::string dumpInfo = " event:"; info.push_back(dumpInfo); + if (!abilityHandler_) { HILOG_INFO("abilityHandler_ is nullptr."); return; @@ -1592,9 +1547,11 @@ void AbilityThread::DumpOtherInfo(std::vector &info) HILOG_INFO("runner_ is nullptr."); return; } + dumpInfo = ""; runner->DumpRunnerInfo(dumpInfo); info.push_back(dumpInfo); + if (currentAbility_ != nullptr) { const auto ablityContext = currentAbility_->GetAbilityContext(); if (!ablityContext) { @@ -1608,7 +1565,13 @@ void AbilityThread::DumpOtherInfo(std::vector &info) } localCallContainer->DumpCalls(info); } + + HILOG_INFO("%{public}s end.", __func__); } +#else +void AbilityThread::DumpAbilityInfo(const std::vector ¶ms, std::vector &info) +{} +#endif sptr AbilityThread::CallRequest() { 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 b197add6c09ec322bb8945c8aaeb6589416f8e1c..f115ef88ae61ac995119c4d5649e3689cdd50e62 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 @@ -136,8 +136,9 @@ public: MOCK_METHOD2(GetWantSenderInfo, int(const sptr &target, std::shared_ptr &info)); MOCK_METHOD3(StartAbilityByCall, int(const Want &, const sptr &, const sptr &)); - #ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif diff --git a/frameworks/kits/appkit/test/Mock/include/mock_app_mgr_service.h b/frameworks/kits/appkit/test/Mock/include/mock_app_mgr_service.h index 9914c4a58d15d5590c505ce4b1a3e368f52351fe..a3dd0c002c279c2396482a12041ddd1b2956c5d7 100644 --- a/frameworks/kits/appkit/test/Mock/include/mock_app_mgr_service.h +++ b/frameworks/kits/appkit/test/Mock/include/mock_app_mgr_service.h @@ -53,6 +53,7 @@ public: int32_t sharedFd, pid_t &renderPid)); MOCK_METHOD1(AttachRenderProcess, void(const sptr &renderScheduler)); MOCK_METHOD1(PostANRTaskByProcessID, void(const pid_t pid)); + MOCK_METHOD0(BlockAppService, int()); void AttachApplication(const sptr &app) { 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 175cdc5df95458ad00a70327a073e31d6ed5b1e6..4d15d473e760af5946fa79e1e7607f6a43637f95 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -130,8 +130,9 @@ public: MOCK_METHOD1(GetProcessRunningInfos, int(std::vector &info)); MOCK_METHOD3(StartAbilityByCall, int(const Want &, const sptr &, const sptr &)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr &token)); - #ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif 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 748415dc1d795ad42eb572868e0231c567aa943c..cb0fb25ac06365c7b548be47c1ad1fe6f57e9aa8 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -132,8 +132,8 @@ public: MOCK_METHOD1(GetProcessRunningInfos, int(std::vector &info)); MOCK_METHOD3(StartAbilityByCall, int(const Want &, const sptr &, const sptr &)); - #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index 65d8a7a61cf512dc588ee345f6af4355061a5948..98b875a13e831d94e3d83747ef639857981c3063 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -659,14 +659,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode BlockAbility(int32_t abilityRecordId); - + #endif /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ ErrCode BlockAppService(); - #endif /** * Free install ability from remote DMS. @@ -680,15 +679,6 @@ public: ErrCode FreeInstallAbilityFromRemote(const Want &want, const sptr &callback, int32_t userId, int requestCode = DEFAULT_INVAL_VALUE); - /** - * Called when client complete dump. - * - * @param infos The dump info. - * @param callerToken The caller ability token. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode DumpAbilityInfoDone(std::vector &infos, const sptr &callerToken); - private: class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { public: diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index 7aeacdf246163a1eefd7571a082bae82f9fa3346..00368abf3c242b24fc5958add3872812c19456bc 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -564,25 +564,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAbility(int32_t abilityRecordId) = 0; - + #endif /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAppService() = 0; - #endif - - /** - * Called when client complete dump. - * - * @param infos The dump info. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int DumpAbilityInfoDone(std::vector &infos, const sptr &callerToken) - { - return 0; - } /** * Call free install from remote. @@ -769,9 +757,6 @@ public: // ipc id for set mission icon (58) SET_MISSION_ICON, - // dump ability info done (59) - DUMP_ABILITY_INFO_DONE, - // ipc id 1001-2000 for DMS // ipc id for starting ability (1001) START_ABILITY = 1001, diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h index 10a89922e7c3e946ae08f1d9634da0b280e49ce0..1258ec153c7c121b55317dda985b9fa50ca8e4c8 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h @@ -201,14 +201,12 @@ public: */ virtual AppMgrResultCode UpdateConfiguration(const Configuration &config); - #ifdef ABILITY_COMMAND_FOR_TEST /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAppService(); - #endif /** * Start a user test diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h index 134638d417ef6015740edb71fa357bce6c2d3f4b..9e90823da8731ab50f5d9c977b5bc26ed28ba574 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h @@ -193,14 +193,13 @@ public: * @return Returns true on success, others on failure. */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) = 0; - #ifdef ABILITY_COMMAND_FOR_TEST + /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAppService() = 0; - #endif /** * Start nweb render process, called by nweb host. diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h index 99e473594d4e38ca056f950e0017848ae7f511b0..7055e76774af44f3c5c4e6d0824208df7fe028d1 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h @@ -214,14 +214,12 @@ public: */ virtual void PostANRTaskByProcessID(const pid_t pid) override; - #ifdef ABILITY_COMMAND_FOR_TEST /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAppService() override; - #endif private: bool SendTransactCmd(IAppMgr::Message code, MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h index 3357c6c0af82359ea5fde57d64e63f90a2834c6e..acdc7aa0aec1b2f5b31225a264b9e28f7ddd9f49 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h @@ -78,9 +78,7 @@ private: int32_t HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply); int32_t HandlePostANRTaskByProcessID(MessageParcel &data, MessageParcel &reply); -#ifdef ABILITY_COMMAND_FOR_TEST int32_t HandleBlockAppServiceDone(MessageParcel &data, MessageParcel &reply); -#endif using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp index ea489116d5340a47b572320ce5215afc77fd407e..6eaf560d4299cc5185fe25f7bfe43635025f9aa8 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp @@ -527,7 +527,6 @@ void AppMgrClient::PostANRTaskByProcessID(const pid_t pid) service->PostANRTaskByProcessID(pid); } -#ifdef ABILITY_COMMAND_FOR_TEST int AppMgrClient::BlockAppService() { HILOG_INFO("%{public}s", __func__); @@ -538,6 +537,5 @@ int AppMgrClient::BlockAppService() } return service->BlockAppService(); } -#endif } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp index d0cd9254b7107e4ff905b08bac60114ce2a942aa..eb119bc66ab0dcfa82747fa4efdd62326a27dd2b 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -659,7 +659,6 @@ void AppMgrProxy::PostANRTaskByProcessID(const pid_t pid) } } -#ifdef ABILITY_COMMAND_FOR_TEST int AppMgrProxy::BlockAppService() { MessageParcel data; @@ -678,6 +677,5 @@ int AppMgrProxy::BlockAppService() } return reply.ReadInt32(); } -#endif } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp index 1767b452a906b3592057aae133c743159e52e55b..db2f82baca3819c5e9af21111af074d848cf986c 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp @@ -78,10 +78,8 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleAttachRenderProcess; memberFuncMap_[static_cast(IAppMgr::Message::POST_ANR_TASK_BY_PID)] = &AppMgrStub::HandlePostANRTaskByProcessID; -#ifdef ABILITY_COMMAND_FOR_TEST memberFuncMap_[static_cast(IAppMgr::Message::BLOCK_APP_SERVICE)] = &AppMgrStub::HandleBlockAppServiceDone; -#endif } AppMgrStub::~AppMgrStub() @@ -399,7 +397,6 @@ int32_t AppMgrStub::HandlePostANRTaskByProcessID(MessageParcel &data, MessagePar return NO_ERROR; } -#ifdef ABILITY_COMMAND_FOR_TEST int32_t AppMgrStub::HandleBlockAppServiceDone(MessageParcel &data, MessageParcel &reply) { HILOG_INFO("%{public}s", __func__); @@ -407,6 +404,5 @@ int32_t AppMgrStub::HandleBlockAppServiceDone(MessageParcel &data, MessageParcel reply.WriteInt32(result); return result; } -#endif } // namespace AppExecFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 6ee3bf15ae85e10bef800447133ba534e7479d22..92120fc5441e6aeeb04dad3423d997e9a416937d 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -521,14 +521,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAbility(int32_t abilityRecordId) override; - + #endif /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAppService() override; - #endif /** * Call free install from remote. @@ -542,14 +541,6 @@ public: virtual int FreeInstallAbilityFromRemote(const Want &want, const sptr &callback, int32_t userId, int requestCode = DEFAULT_INVAL_VALUE) override; - /** - * Called when client complete dump. - * - * @param infos The dump info. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int DumpAbilityInfoDone(std::vector &infos, const sptr &callerToken) override; - private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index ca48d010af2bfbbc04ec237a076a08dd3bc2027e..f98783942a691bbac9a4cb391d1865d6b29d209a 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -579,15 +579,6 @@ public: virtual int SetMissionLabel(const sptr &abilityToken, const std::string &label) override; - /** - * Called when client complete dump. - * - * @param infos The dump info. - * @param callerToken The caller ability token. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int DumpAbilityInfoDone(std::vector &infos, const sptr &callerToken) override; - #ifdef SUPPORT_GRAPHICS virtual int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) override; @@ -694,12 +685,6 @@ public: */ virtual int BlockAbility(int32_t abilityRecordId) override; - /** - * Block app manager service. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int BlockAppService() override; - /** * force timeout ability. * @@ -710,6 +695,12 @@ public: virtual int ForceTimeoutForTest(const std::string &abilityName, const std::string &state) override; #endif + /** + * Block app manager service. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int BlockAppService() override; + bool GetDataAbilityUri(const std::vector &abilityInfos, const std::string &mainAbility, std::string &uri); @@ -774,7 +765,6 @@ public: static constexpr uint32_t RESTART_ABILITY_TIMEOUT = 500; // ms static constexpr uint32_t FOREGROUNDNEW_TIMEOUT = 5000; // ms static constexpr uint32_t BACKGROUNDNEW_TIMEOUT = 3000; // ms - static constexpr uint32_t DUMP_TIMEOUT = 5000; // ms static constexpr uint32_t MIN_DUMP_ARGUMENT_NUM = 2; static constexpr uint32_t MAX_WAIT_SYSTEM_UI_NUM = 600; @@ -939,6 +929,10 @@ private: 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); + ErrCode ProcessOneParam(std::string& args, std::string &result); + ErrCode ProcessTwoParam(const std::string& firstParam, const std::string& secondParam, std::string &result); + ErrCode ProcessThreeParam(const std::string& firstParam, const std::string& secondParam, + const std::string& thirdParam, std::string &result); ErrCode ProcessMultiParam(std::vector &argsStr, std::string &result); void ShowHelp(std::string &result); void ShowIllealInfomation(std::string &result); diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index d99a36528161766f5d5a25b8255b5d0ba2dbec30..b15980a23afdde1af9950e84aa916f38c3cdd32f 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -166,11 +166,10 @@ private: #ifdef ABILITY_COMMAND_FOR_TEST int BlockAmsServiceInner(MessageParcel &data, MessageParcel &reply); int BlockAbilityInner(MessageParcel &data, MessageParcel &reply); - int BlockAppServiceInner(MessageParcel &data, MessageParcel &reply); #endif + int BlockAppServiceInner(MessageParcel &data, MessageParcel &reply); int GetTopAbilityInner(MessageParcel &data, MessageParcel &reply); - int DumpAbilityInfoDoneInner(MessageParcel &data, MessageParcel &reply); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 8dde862c72567fc865faa4ace4b30f5f650e13ea..cf0d01ffebbfafa7d6881b649d79d831595c3736 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -581,15 +581,7 @@ public: void DumpSys(std::vector &info, bool isClient = false); - void DumpClientInfo(std::vector &info, const std::vector ¶ms, - bool isClient = false, bool dumpConfig = true) const; - - /** - * Called when client complete dump. - * - * @param infos The dump info. - */ - void DumpAbilityInfoDone(std::vector &infos); + void DumpClientInfo(std::vector &info, bool isClient = false); /** * dump ability state info. @@ -784,10 +776,6 @@ private: int32_t restratMax_ = -1; std::string specifiedFlag_; std::mutex lock_; - mutable std::mutex dumpLock_; - mutable std::condition_variable dumpCondition_; - mutable bool isDumpWaiting_ = false; - std::vector dumpInfos_; }; class AbilityRecordNew : public AbilityRecord { diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index ca8df0960e7e4aea212750c91acb9d95aeef2ce4..4c37329e4ccb3a806821e60854e9e6e1d3f13535 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -290,14 +290,12 @@ public: */ void PostANRTaskByProcessID(const pid_t pid); - #ifdef ABILITY_COMMAND_FOR_TEST /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ int BlockAppService(); - #endif protected: /** diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 9f6d12c3f0438b4d18cd8464d0d34194b4d5e153..652c6dba0b5a34d881e366ef2e47df4522b1b52f 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -769,6 +769,7 @@ ErrCode AbilityManagerClient::BlockAbility(int32_t abilityRecordId) CHECK_POINTER_RETURN_NOT_CONNECTED(abms); return abms->BlockAbility(abilityRecordId); } +#endif ErrCode AbilityManagerClient::BlockAppService() { @@ -777,7 +778,6 @@ ErrCode AbilityManagerClient::BlockAppService() CHECK_POINTER_RETURN_NOT_CONNECTED(abms); return abms->BlockAppService(); } -#endif sptr AbilityManagerClient::GetAbilityManager() { @@ -829,14 +829,5 @@ AppExecFwk::ElementName AbilityManagerClient::GetTopAbility() return abms->GetTopAbility(); } - -ErrCode AbilityManagerClient::DumpAbilityInfoDone(std::vector &infos, - const sptr &callerToken) -{ - HILOG_INFO("DumpAbilityInfoDone begin."); - auto abms = GetAbilityManager(); - CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->DumpAbilityInfoDone(infos, callerToken); -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index df4efe3d1ae32f0ab4af29a801aec127bc3de62e..8c3d6016eee88ea384c42b227e1d755fd3bd260c 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -2345,7 +2345,7 @@ int AbilityManagerProxy::BlockAbility(int32_t abilityRecordId) } return reply.ReadInt32(); } - +#endif int AbilityManagerProxy::BlockAppService() { MessageParcel data; @@ -2361,7 +2361,7 @@ int AbilityManagerProxy::BlockAppService() } return reply.ReadInt32(); } -#endif + int AbilityManagerProxy::FreeInstallAbilityFromRemote(const Want &want, const sptr &callback, int32_t userId, int requestCode) { @@ -2401,39 +2401,5 @@ int AbilityManagerProxy::FreeInstallAbilityFromRemote(const Want &want, const sp return reply.ReadInt32(); } - -int AbilityManagerProxy::DumpAbilityInfoDone(std::vector &infos, const sptr &callerToken) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - HILOG_ERROR("write interface token failed."); - return INNER_ERR; - } - - if (!data.WriteStringVector(infos)) { - HILOG_ERROR("infos write failed."); - return INNER_ERR; - } - - if (!data.WriteRemoteObject(callerToken)) { - HILOG_ERROR("infos write failed."); - return INNER_ERR; - } - - if (!Remote()) { - HILOG_ERROR("Remote nullptr."); - return INNER_ERR; - } - - auto error = Remote()->SendRequest(IAbilityManager::DUMP_ABILITY_INFO_DONE, data, reply, option); - if (error != NO_ERROR) { - HILOG_ERROR("Send request error: %{public}d", error); - return error; - } - - return reply.ReadInt32(); -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 99550cf8bc1d3bdc6eaed01b74fdf88727495a55..03d1c13e2870b0f50527f06c63b9d56d010bba00 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -258,7 +258,7 @@ bool AbilityManagerService::Init() } auto startSystemTask = [aams = shared_from_this()]() { aams->StartSystemApplication(); }; - handler_->PostTask(startSystemTask, "StartSystemApplication"); + handler_->PostTask(startSystemTask, "startLauncherAbility"); HILOG_INFO("Init success."); return true; } @@ -2920,8 +2920,20 @@ void AbilityManagerService::StartingSystemUiAbility() { #ifdef SUPPORT_GRAPHICS HILOG_DEBUG("%{public}s", __func__); + AppExecFwk::AbilityInfo systemUiInfo; + auto bms = GetBundleManager(); + CHECK_POINTER_IS_NULLPTR(bms); Want systemUiWant; systemUiWant.SetElementName(AbilityConfig::SYSTEM_UI_BUNDLE_NAME, AbilityConfig::SYSTEM_UI_ABILITY_NAME); + uint32_t waitCnt = 0; + // Wait 10 minutes for the installation to complete. + IN_PROCESS_CALL_WITHOUT_RET( + while (!bms->QueryAbilityInfo(systemUiWant, systemUiInfo) && waitCnt < MAX_WAIT_SYSTEM_UI_NUM) { + HILOG_INFO("Waiting query system ui info completed."); + usleep(REPOLL_TIME_MICRO_SECONDS); + waitCnt++; + } + ); (void)StartAbility(systemUiWant, U0_USER_ID, DEFAULT_INVAL_VALUE); #endif } @@ -3969,10 +3981,30 @@ void AbilityManagerService::StartingScreenLockAbility() { #ifdef SUPPORT_GRAPHICS HILOG_DEBUG("%{public}s", __func__); + auto bms = GetBundleManager(); + CHECK_POINTER_IS_NULLPTR(bms); + + constexpr int maxAttemptNums = 5; auto userId = GetUserId(); + int attemptNums = 1; + AppExecFwk::AbilityInfo screenLockInfo; Want screenLockWant; screenLockWant.SetElementName(AbilityConfig::SCREEN_LOCK_BUNDLE_NAME, AbilityConfig::SCREEN_LOCK_ABILITY_NAME); - (void)StartAbility(screenLockWant, userId, DEFAULT_INVAL_VALUE); + HILOG_DEBUG("%{public}s, QueryAbilityInfo, userId is %{public}d", __func__, userId); + IN_PROCESS_CALL_WITHOUT_RET( + while (!(bms->QueryAbilityInfo(screenLockWant, + OHOS::AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId, screenLockInfo)) && + attemptNums <= maxAttemptNums) { + HILOG_INFO("Waiting query mms service completed."); + usleep(REPOLL_TIME_MICRO_SECONDS); + attemptNums++; + } + ); + + HILOG_INFO("attemptNums : %{public}d", attemptNums); + if (attemptNums <= maxAttemptNums) { + (void)StartAbility(screenLockWant, userId, DEFAULT_INVAL_VALUE); + } #endif } @@ -4309,13 +4341,12 @@ int AbilityManagerService::BlockAbility(int32_t abilityRecordId) HILOG_DEBUG("%{public}s", __func__); return currentMissionListManager_->BlockAbility(abilityRecordId); } - +#endif int AbilityManagerService::BlockAppService() { HILOG_DEBUG("%{public}s", __func__); return DelayedSingleton::GetInstance()->BlockAppService(); } -#endif bool AbilityManagerService::CheckIsFreeInstall(const Want &want) { @@ -4663,6 +4694,83 @@ int AbilityManagerService::Dump(int fd, const std::vector &args) return errCode; } +ErrCode AbilityManagerService::ProcessOneParam(std::string& args, std::string &result) +{ + if (args == "-h") { + ShowHelp(result); + return ERR_OK; + } + + std::string cmd; + auto iter = ONE_ARG_SET.find(args); + if (iter != ONE_ARG_SET.end()) { + cmd = *iter; + } else { + return ERR_AAFWK_HIDUMP_INVALID_ARGS; + } + + cmd += " "; + std::vector dumpResults; + DumpSysState(cmd, dumpResults, false, false, -1); + for (auto it : dumpResults) { + result += it + "\n"; + } + return ERR_OK; +} + +ErrCode AbilityManagerService::ProcessTwoParam(const std::string& firstParam, const std::string& secondParam, + std::string &result) +{ + std::string cmd; + auto iter = TWO_ARGS_SET.find(firstParam); + if (iter != TWO_ARGS_SET.end()) { + cmd = *iter; + } else { + return ERR_AAFWK_HIDUMP_INVALID_ARGS; + } + + bool isClient = false; + if (cmd == "-a" && secondParam == "-c") { + isClient = true; + } + + if (isClient) { + cmd = cmd + " "; + } else { + cmd = cmd + " " + secondParam + " "; + } + + std::vector dumpResults; + DumpSysState(cmd, dumpResults, isClient, false, -1); + for (auto it : dumpResults) { + result += it + "\n"; + } + return ERR_OK; +} + +ErrCode AbilityManagerService::ProcessThreeParam(const std::string& firstParam, const std::string& secondParam, + const std::string& thirdParam, std::string &result) +{ + if (firstParam != "-a" || secondParam != "-u") { + return ERR_AAFWK_HIDUMP_INVALID_ARGS; + } + + int userID = DEFAULT_INVAL_VALUE; + (void)StrToInt(thirdParam, userID); + HILOG_DEBUG("%{public}s, userID is : %{public}d", __func__, userID); + if (userID < 0) { + return ERR_AAFWK_HIDUMP_INVALID_ARGS; + } + + std::string cmd = "-a "; + std::vector dumpResults; + DumpSysState(cmd, dumpResults, false, true, userID); + for (auto it : dumpResults) { + result += it + "\n"; + } + return ERR_OK; +} + ErrCode AbilityManagerService::ProcessMultiParam(std::vector &argsStr, std::string &result) { HILOG_DEBUG("%{public}s begin", __func__); @@ -4771,17 +4879,5 @@ bool AbilityManagerService::IsTopAbility(const sptr &callerToken) return false; } - -int AbilityManagerService::DumpAbilityInfoDone(std::vector &infos, const sptr &callerToken) -{ - HILOG_DEBUG("DumpAbilityInfoDone begin"); - auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); - if (abilityRecord == nullptr) { - HILOG_ERROR("abilityRecord nullptr"); - return ERR_INVALID_VALUE; - } - abilityRecord->DumpAbilityInfoDone(infos); - return ERR_OK; -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 8e0fef33fe708503e289dea9a7c9a7f2a883224d..defe99b6522a4153566b3e6e8f69c17306af4053 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -122,8 +122,8 @@ void AbilityManagerStub::SecondStepInit() #ifdef ABILITY_COMMAND_FOR_TEST requestFuncMap_[BLOCK_ABILITY] = &AbilityManagerStub::BlockAbilityInner; requestFuncMap_[BLOCK_AMS_SERVICE] = &AbilityManagerStub::BlockAmsServiceInner; - requestFuncMap_[BLOCK_APP_SERVICE] = &AbilityManagerStub::BlockAppServiceInner; #endif + requestFuncMap_[BLOCK_APP_SERVICE] = &AbilityManagerStub::BlockAppServiceInner; } void AbilityManagerStub::ThirdStepInit() @@ -139,7 +139,6 @@ void AbilityManagerStub::ThirdStepInit() requestFuncMap_[GET_TOP_ABILITY] = &AbilityManagerStub::GetTopAbilityInner; requestFuncMap_[SET_MISSION_ICON] = &AbilityManagerStub::SetMissionIconInner; requestFuncMap_[REGISTER_WINDOW_HANDLER] = &AbilityManagerStub::RegisterWindowHandlerInner; - requestFuncMap_[DUMP_ABILITY_INFO_DONE] = &AbilityManagerStub::DumpAbilityInfoDoneInner; } int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -1367,7 +1366,7 @@ int AbilityManagerStub::BlockAmsServiceInner(MessageParcel &data, MessageParcel } return NO_ERROR; } - +#endif int AbilityManagerStub::BlockAppServiceInner(MessageParcel &data, MessageParcel &reply) { int32_t result = BlockAppService(); @@ -1377,7 +1376,6 @@ int AbilityManagerStub::BlockAppServiceInner(MessageParcel &data, MessageParcel } return NO_ERROR; } -#endif int AbilityManagerStub::FreeInstallAbilityFromRemoteInner(MessageParcel &data, MessageParcel &reply) { @@ -1403,18 +1401,5 @@ int AbilityManagerStub::FreeInstallAbilityFromRemoteInner(MessageParcel &data, M } return NO_ERROR; } - -int AbilityManagerStub::DumpAbilityInfoDoneInner(MessageParcel &data, MessageParcel &reply) -{ - std::vector infos; - data.ReadStringVector(&infos); - sptr callerToken = data.ReadRemoteObject(); - int32_t result = DumpAbilityInfoDone(infos, callerToken); - if (!reply.WriteInt32(result)) { - HILOG_ERROR("reply write failed."); - return ERR_INVALID_VALUE; - } - return NO_ERROR; -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 3968deec21693d4b96edcace6848469d2c90ab19..64476eccd61c91f72b7c3d9a17ba2921218265c1 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -868,7 +868,16 @@ void AbilityRecord::DumpAbilityState( } // add dump client info - DumpClientInfo(info, params, isClient, params.empty()); + if (isClient && scheduler_ && isReady_) { + scheduler_->DumpAbilityInfo(params, info); + if (!params.empty()) { + return; + } + AppExecFwk::Configuration config; + if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { + info.emplace_back(" configuration: " + config.GetName()); + } + } } void AbilityRecord::SetStartTime() @@ -910,7 +919,13 @@ void AbilityRecord::DumpService(std::vector &info, std::vectorDumpAbilityInfo(params, info); + AppExecFwk::Configuration config; + if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { + info.emplace_back(" configuration: " + config.GetName()); + } + } } void AbilityRecord::GetAbilityRecordInfo(AbilityRecordInfo &recordInfo) @@ -1445,65 +1460,19 @@ void AbilityRecord::DumpSys(std::vector &info, bool isClient) dumpInfo = " can restart num #" + std::to_string(restartCount_); info.push_back(dumpInfo); } - const std::vector params; - DumpClientInfo(info, params, isClient); -} - -void AbilityRecord::DumpClientInfo(std::vector &info, const std::vector ¶ms, - bool isClient, bool dumpConfig) const -{ - if (!isClient || !scheduler_ || !isReady_) { - HILOG_ERROR("something nullptr."); - return; - } - std::unique_lock lock(dumpLock_); - scheduler_->DumpAbilityInfo(params, info); - - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - if (handler) { - handler->PostTask([condition = &dumpCondition_, isWaiting = &isDumpWaiting_]() { - HILOG_INFO("Dump time out, isWaiting:%{public}d.", *isWaiting); - if (*isWaiting && condition != nullptr) { - condition->notify_all(); - } - }, std::string("Dump") + std::to_string(recordId_), AbilityManagerService::DUMP_TIMEOUT); - } - - HILOG_INFO("Dump begin wait."); - isDumpWaiting_ = true; - dumpCondition_.wait(lock); - isDumpWaiting_ = false; - HILOG_INFO("Dump done and begin parse."); - for (auto one : dumpInfos_) { - info.emplace_back(one); - } - - if (!dumpConfig) { - HILOG_INFO("not dumpConfig."); - return; - } - AppExecFwk::Configuration config; - if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { - info.emplace_back(" configuration: " + config.GetName()); - } + DumpClientInfo(info, isClient); } -void AbilityRecord::DumpAbilityInfoDone(std::vector &infos) +void AbilityRecord::DumpClientInfo(std::vector &info, bool isClient) { - HILOG_INFO("DumpAbilityInfoDone begin."); - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - if (handler) { - handler->RemoveTask(std::string("Dump") + std::to_string(recordId_)); - } - if (!isDumpWaiting_) { - HILOG_ERROR("not waiting."); - return; - } - dumpInfos_.clear(); - for (auto info : infos) { - dumpInfos_.emplace_back(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()); + } } - dumpCondition_.notify_all(); } void AbilityRecord::GrantUriPermission(const Want &want) diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index 8f9a4b57672bb1fa3bbc0c80094c02baa13a3559..9494914a09475505c57f1e4dbe057bae55be35fa 100644 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -987,7 +987,7 @@ void AbilitySchedulerProxy::DumpAbilityInfo(const std::vector ¶ { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option; if (!WriteInterfaceToken(data)) { HILOG_ERROR("DumpAbilityRunner fail to write token"); return; @@ -1002,6 +1002,12 @@ void AbilitySchedulerProxy::DumpAbilityInfo(const std::vector ¶ if (err != NO_ERROR) { HILOG_ERROR("DumpAbilityRunner fail to SendRequest. err: %{public}d", err); } + + int32_t stackNum = reply.ReadInt32(); + for (int i = 0; i < stackNum; i++) { + std::string stac = Str16ToStr8(reply.ReadString16()); + info.emplace_back(stac); + } } sptr AbilitySchedulerProxy::CallRequest() diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index e724e02104c25dc77d4918277c11d5bfa6fa3f5f..370964d3f5f556b6655c70421a6cb8886b01f56b 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -607,6 +607,11 @@ int AbilitySchedulerStub::DumpAbilityInfoInner(MessageParcel &data, MessageParce DumpAbilityInfo(params, infos); + reply.WriteInt32(infos.size()); + for (auto stack : infos) { + reply.WriteString16(Str8ToStr16(stack)); + } + return NO_ERROR; } int AbilitySchedulerStub::CallRequestInner(MessageParcel &data, MessageParcel &reply) diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 94dd1d377b2bb0ee5e76e881dd8bd1595fa22c7f..d7fa2cf35debcd6bfafaf4c0268da1ff112804b9 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -371,7 +371,6 @@ void AppScheduler::PostANRTaskByProcessID(const pid_t pid) appMgrClient_->PostANRTaskByProcessID(pid); } -#ifdef ABILITY_COMMAND_FOR_TEST int AppScheduler::BlockAppService() { HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); @@ -383,6 +382,5 @@ int AppScheduler::BlockAppService() } return ERR_OK; } -#endif } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h b/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h index c708e7e6644b864d79f2583417d18438b7ea81e0..8b77a7a1719493ce91ac541fbe8c6432a03ee311 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h @@ -282,8 +282,9 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector &info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector &info)); - #ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif 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 982fcca260a9dc30b3541942c3f6077cc80f3682..e7e444eadf8a98c47aedde9b76e31c1301d88729 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 @@ -283,8 +283,9 @@ public: MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector &info)); MOCK_METHOD3(StartAbilityByCall, int(const Want &, const sptr &, const sptr &)); - #ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif 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 5a36444777566c85b7cdf0d0f219df718c7a99c8..57cb1cc2277aa0ce56e85ec405d4750aea6ad6e6 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 @@ -60,8 +60,9 @@ public: MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector &info)); MOCK_METHOD3(StartAbilityByCall, int(const Want &, const sptr &, const sptr &)); - #ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 997a64f641c19ee002c274b71887fd4b77dc1c27..e88f1b0dfb769fc1554bf1f8ed32c5492ff216fa 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -222,14 +222,12 @@ public: */ virtual void PostANRTaskByProcessID(const pid_t pid) override; - #ifdef ABILITY_COMMAND_FOR_TEST /** * Block app service. * * @return Returns ERR_OK on success, others on failure. */ virtual int BlockAppService() override; - #endif private: /** diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index eed844184553df62657406dd062bc8c517a7125c..11fe774b6571a61d007fa21564fb6ddd964bba64 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -41,9 +41,9 @@ namespace { using namespace std::chrono_literals; static const int EXPERIENCE_MEM_THRESHOLD = 20; static const int APP_MS_TIMEOUT = 180; -#ifdef ABILITY_COMMAND_FOR_TEST +//#ifdef ABILITY_COMMAND_FOR_TEST static const int APP_MS_BLOCK = 65; -#endif +//#endif static const float PERCENTAGE = 100.0; const std::string TASK_ATTACH_APPLICATION = "AttachApplicationTask"; const std::string TASK_APPLICATION_FOREGROUNDED = "ApplicationForegroundedTask"; @@ -462,7 +462,6 @@ void AppMgrService::PostANRTaskByProcessID(const pid_t pid) object->ScheduleANRProcess(); } -#ifdef ABILITY_COMMAND_FOR_TEST int AppMgrService::BlockAppService() { HILOG_DEBUG("%{public}s begin", __func__); @@ -478,6 +477,5 @@ int AppMgrService::BlockAppService() handler_->PostTask(task); return ERR_OK; } -#endif } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/test/mock/include/mock_app_mgr_service.h b/services/appmgr/test/mock/include/mock_app_mgr_service.h index a7cd74f528e3b935635a4d3e440298f0c7fe20ee..44ff3edb2676db22d4067a88a5b5373c90f7e6e7 100644 --- a/services/appmgr/test/mock/include/mock_app_mgr_service.h +++ b/services/appmgr/test/mock/include/mock_app_mgr_service.h @@ -56,9 +56,7 @@ public: void(const int32_t recordId, const AAFwk::Want &want, const std::string &flag)); MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector> &tokens)); MOCK_METHOD1(PostANRTaskByProcessID, void(const pid_t pid)); - #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAppService, int()); - #endif virtual int StartUserTestProcess( const AAFwk::Want &want, const sptr &observer, const BundleInfo &bundleInfo, int32_t userId) diff --git a/services/formmgr/test/mock/include/mock_ability_manager.h b/services/formmgr/test/mock/include/mock_ability_manager.h index a8a779da08ced4a7a08a13f33b63b957538be9cf..32652e5c5d3fbec78689ccaa0fc8fbf81e74a2aa 100644 --- a/services/formmgr/test/mock/include/mock_ability_manager.h +++ b/services/formmgr/test/mock/include/mock_ability_manager.h @@ -721,16 +721,16 @@ public: return 0; } - virtual int BlockAppService() + virtual int BlockAbility(int32_t abilityRecordId) { return 0; } + #endif - virtual int BlockAbility(int32_t abilityRecordId) + virtual int BlockAppService() { return 0; } - #endif private: Semaphore sem_; diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index e614e92b1f183ee912493c593986069e1b486402..b9ba93b6314ff99de1270348b301d6ece93f2873 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -105,8 +105,9 @@ public: MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector &info)); MOCK_METHOD3(StartAbilityByCall, int(const Want &, const sptr &, const sptr &)); - #ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + #ifdef ABILITY_COMMAND_FOR_TEST MOCK_METHOD0(BlockAmsService, int()); MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); #endif diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 93e24984a685f67208a64b3fe22425fb22c11179..48904c6a216cedd9c086e133b08d9adb903554b6 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -167,8 +167,9 @@ private: ErrCode RunAsSendAppNotRespondinProcessID(); ErrCode RunAsBlockAbilityCommand(); ErrCode RunAsBlockAmsServiceCommand(); - ErrCode RunAsBlockAppServiceCommand(); #endif + ErrCode RunAsBlockAppServiceCommand(); + sptr GetAbilityManagerService(); ErrCode MakeWantFromCmd(Want &want, std::string &windowMode); diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 2b5d3c7add4f06b23a85e0a3cf4897daa938ef0f..5e08dc5646bcbbbca11eaee760ef3fc50b5e60ce 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -90,8 +90,8 @@ ErrCode AbilityManagerShellCommand::CreateCommandMap() {"ApplicationNotRespondin", std::bind(&AbilityManagerShellCommand::RunAsSendAppNotRespondinProcessID, this)}, {"block-ability", std::bind(&AbilityManagerShellCommand::RunAsBlockAbilityCommand, this)}, {"block-ams-service", std::bind(&AbilityManagerShellCommand::RunAsBlockAmsServiceCommand, this)}, - {"block-app-service", std::bind(&AbilityManagerShellCommand::RunAsBlockAppServiceCommand, this)}, #endif + {"block-app-service", std::bind(&AbilityManagerShellCommand::RunAsBlockAppServiceCommand, this)}, }; return OHOS::ERR_OK; @@ -1176,7 +1176,7 @@ ErrCode AbilityManagerShellCommand::RunAsBlockAmsServiceCommand() } return result; } - +#endif ErrCode AbilityManagerShellCommand::RunAsBlockAppServiceCommand() { HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); @@ -1192,6 +1192,5 @@ ErrCode AbilityManagerShellCommand::RunAsBlockAppServiceCommand() } return result; } -#endif } // namespace AAFwk } // namespace OHOS diff --git a/tools/aa/src/ability_tool_command.cpp b/tools/aa/src/ability_tool_command.cpp index 7f81d13971efd51a6e770516bd67e3627d285da5..5c9cfeb40189334e7aeaba9ff45f4ba3f32aada5 100644 --- a/tools/aa/src/ability_tool_command.cpp +++ b/tools/aa/src/ability_tool_command.cpp @@ -230,9 +230,8 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption std::string deviceId = ""; std::string bundleName = ""; std::string abilityName = ""; - std::string paramName = ""; - std::string paramValue = ""; - std::smatch sm; + std::string key = ""; + std::string value = ""; int32_t windowMode = AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED; int flags = 0; bool isColdStart = false; @@ -268,23 +267,18 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption break; case 'o': if (optind + 1 >= argc_) { - HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), - ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); + HILOG_DEBUG("'aa %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_LACK_VALUE + "\n"); return OHOS::ERR_INVALID_VALUE; } - paramName = optarg; - paramValue = argv_[optind + 1]; - if (paramName == "windowMode" && - std::regex_match(paramValue, sm, std::regex(STRING_TEST_REGEX_INTEGER_NUMBERS))) { - windowMode = std::stoi(paramValue); + key = optarg; + value = argv_[optind + 1]; + if (key == "windowMode") { + windowMode = std::stoi(value); } break; case 'f': - paramValue = optarg; - if (std::regex_match(paramValue, sm, std::regex(STRING_TEST_REGEX_INTEGER_NUMBERS))) { - flags = std::stoi(paramValue); - } + flags = std::stoi(optarg); break; case 'C': isColdStart = true; @@ -299,7 +293,7 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption // Parameter check if (abilityName.size() == 0 || bundleName.size() == 0) { - HILOG_DEBUG("'ability_tool %{public}s' without enough options.", cmd_.c_str()); + HILOG_DEBUG("'aa %{public}s' without enough options.", cmd_.c_str()); if (abilityName.size() == 0) { resultReceiver_.append(ABILITY_TOOL_HELP_MSG_NO_ABILITY_NAME_OPTION + "\n"); } @@ -334,8 +328,7 @@ ErrCode AbilityToolCommand::ParseStartAbilityArgsFromCmd(Want& want, StartOption windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY && windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY && windowMode != AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING) { - HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), - ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID.c_str()); + HILOG_DEBUG("'aa %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_WINDOW_MODE_INVALID + "\n"); return OHOS::ERR_INVALID_VALUE; } @@ -381,7 +374,7 @@ ErrCode AbilityToolCommand::ParseStopServiceArgsFromCmd(Want& want) } if (abilityName.size() == 0 || bundleName.size() == 0) { - HILOG_INFO("'ability_tool %{public}s' without enough options.", cmd_.c_str()); + HILOG_INFO("'aa %{public}s' without enough options.", cmd_.c_str()); if (abilityName.size() == 0) { resultReceiver_.append(ABILITY_TOOL_HELP_MSG_NO_ABILITY_NAME_OPTION + "\n"); } @@ -400,8 +393,8 @@ ErrCode AbilityToolCommand::ParseStopServiceArgsFromCmd(Want& want) ErrCode AbilityToolCommand::ParseTestArgsFromCmd(std::map& params, bool isDebug) { - std::string paramKey; - std::string paramValue; + std::string key; + std::string value; std::smatch sm; int option = -1; int index = 0; @@ -428,14 +421,13 @@ ErrCode AbilityToolCommand::ParseTestArgsFromCmd(std::map= argc_) { - HILOG_DEBUG("'ability_tool %{public}s' %{public}s", cmd_.c_str(), - ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); + HILOG_DEBUG("'aa %{public}s' %{public}s", cmd_.c_str(), ABILITY_TOOL_HELP_MSG_LACK_VALUE.c_str()); resultReceiver_.append(ABILITY_TOOL_HELP_MSG_LACK_VALUE + "\n"); return OHOS::ERR_INVALID_VALUE; } - paramKey = "-s "; - paramKey.append(optarg); - params[paramKey] = argv_[optind + 1]; + key = "-s "; + key.append(optarg); + params[key] = argv_[optind + 1]; break; case 'p': params["-p"] = optarg; @@ -444,13 +436,13 @@ ErrCode AbilityToolCommand::ParseTestArgsFromCmd(std::map