From 196e06c129e4c6a251ed01084fe421d5d755ab73 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Mon, 8 Nov 2021 10:56:54 +0800 Subject: [PATCH 1/3] Modify test code Signed-off-by: zhaoyuan17 --- frameworks/kits/ability/native/test/BUILD.gn | 4 - .../test/mock/include/bundle_mgr_interface.h | 24 +- .../test/mock/include/mock_bundle_manager.cpp | 462 +++++++++++++++-- .../test/mock/include/mock_bundle_manager.h | 475 ++++-------------- .../test/mock/include/sys_mgr_client_mock.cpp | 8 +- .../test/unittest/ability_context_test.cpp | 12 +- .../napi_data_ability_helper.cpp | 21 +- 7 files changed, 580 insertions(+), 426 deletions(-) diff --git a/frameworks/kits/ability/native/test/BUILD.gn b/frameworks/kits/ability/native/test/BUILD.gn index 225948c089..6e86d97832 100755 --- a/frameworks/kits/ability/native/test/BUILD.gn +++ b/frameworks/kits/ability/native/test/BUILD.gn @@ -262,12 +262,9 @@ ohos_unittest("ability_context_test") { deps = [ "${INNERKITS_PATH}/want:want", - "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", - "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", "//foundation/appexecfwk/standard/kits:appkit_native", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock_main", @@ -278,7 +275,6 @@ ohos_unittest("ability_context_test") { external_deps = [ "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", - "multimodalinput_base:libmmi-client", ] } diff --git a/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h b/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h index 7d5c9febf8..8e0f4bd4ce 100644 --- a/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h +++ b/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h @@ -31,6 +31,10 @@ using OHOS::AAFwk::Want; namespace OHOS { namespace AppExecFwk { + +struct FormInfo; +struct ShortcutInfo; + enum class DumpFlag { DUMP_BUNDLE_LIST = 1, DUMP_ALL_BUNDLE_INFO, @@ -169,6 +173,7 @@ public: virtual bool GetBundleInfosByMetaData(const std::string &metaData, std::vector &bundleInfos) = 0; virtual bool QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo) = 0; virtual bool QueryAbilityInfos(const Want &want, std::vector &abilityInfos) = 0; + virtual bool QueryAbilityInfosForClone(const Want &want, std::vector &abilityInfos) = 0; virtual bool QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo) = 0; virtual bool QueryKeepAliveBundleInfos(std::vector &bundleInfos) = 0; virtual std::string GetAbilityLabel(const std::string &bundleName, const std::string &className) = 0; @@ -205,11 +210,16 @@ public: virtual bool RegisterPermissionsChanged( const std::vector &uids, const sptr &callback) = 0; virtual bool UnregisterPermissionsChanged(const sptr &callback) = 0; + virtual bool GetAllFormsInfo(std::vector &formInfos) = 0; + virtual bool GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfos) = 0; + virtual bool GetFormsInfoByModule( + const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) = 0; + virtual bool GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) = 0; + virtual bool GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) = 0; virtual sptr GetBundleInstaller() = 0; - virtual bool GetModuleUsageRecords( - const int32_t number, std::vector &moduleUsageRecords) = 0; virtual bool NotifyActivityLifeStatus( const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) = 0; + enum class Message { GET_APPLICATION_INFO, GET_APPLICATION_INFOS, @@ -225,6 +235,8 @@ public: CHECK_IS_SYSTEM_APP_BY_UID, GET_BUNDLE_INFOS_BY_METADATA, QUERY_ABILITY_INFO, + QUERY_ABILITY_INFOS, + QUERY_ABILITY_INFOS_FOR_CLONE, QUERY_ABILITY_INFO_BY_URI, QUERY_KEEPALIVE_BUNDLE_INFOS, GET_ABILITY_LABEL, @@ -255,9 +267,15 @@ public: REGISTER_ALL_PERMISSIONS_CHANGED, REGISTER_PERMISSIONS_CHANGED, UNREGISTER_PERMISSIONS_CHANGED, + GET_ALL_FORMS_INFO, + GET_FORMS_INFO_BY_APP, + GET_FORMS_INFO_BY_MODULE, + GET_MODULE_USAGE_RECORD, + GET_SHORTCUT_INFO, GET_BUNDLE_INSTALLER, + NOTIFY_ACTIVITY_LIFE_STATUS, }; }; } // namespace AppExecFwk } // namespace OHOS -#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_BUNDLEMGR_INCLUDE_MOCK_BUNDLE_MGR_INTERFACE_H \ No newline at end of file +#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_BUNDLEMGR_INCLUDE_MOCK_BUNDLE_MGR_INTERFACE_H diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp index ad5672e844..44586273df 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp @@ -21,7 +21,67 @@ namespace OHOS { namespace AppExecFwk { -bool BundleMgrProxy::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo) +bool BundleMgrProxy::GetApplicationInfo( + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) +{ + if (appName.empty()) { + return false; + } + appInfo.name = "Helloworld"; + appInfo.bundleName = "com.ohos.hiworld"; + return true; +} +bool BundleMgrProxy::GetApplicationInfos( + const ApplicationFlag flag, const int userId, std::vector &appInfos) +{ + return true; +} +bool BundleMgrProxy::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo) +{ + return true; +} +bool BundleMgrProxy::GetBundleInfos(const BundleFlag flag, std::vector &bundleInfos) +{ + return true; +} +int BundleMgrProxy::GetUidByBundleName(const std::string &bundleName, const int userId) +{ + return 0; +} +std::string BundleMgrProxy::GetAppIdByBundleName(const std::string &bundleName, const int userId) +{ + return ""; +} +bool BundleMgrProxy::GetBundleNameForUid(const int uid, std::string &bundleName) +{ + return true; +} +bool BundleMgrProxy::GetBundlesForUid(const int uid, std::vector &bundleNames) +{ + return true; +} +bool BundleMgrProxy::GetNameForUid(const int uid, std::string &name) +{ + return true; +} +bool BundleMgrProxy::GetBundleGids(const std::string &bundleName, std::vector &gids) +{ + return true; +} +std::string BundleMgrProxy::GetAppType(const std::string &bundleName) +{ + GTEST_LOG_(INFO) << " BundleMgrProxy::GetAppTyp"; + return "system"; +} +bool BundleMgrProxy::CheckIsSystemAppByUid(const int uid) +{ + return true; +} +bool BundleMgrProxy::GetBundleInfosByMetaData(const std::string &metaData, std::vector &bundleInfos) +{ + return true; +} +bool BundleMgrProxy::QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo) { ElementName eleName = want.GetElement(); if (eleName.GetBundleName().empty()) { @@ -33,35 +93,240 @@ bool BundleMgrProxy::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abil abilityInfo.applicationName = "Helloworld"; return true; } - -bool BundleMgrProxy::QueryAbilityInfoByUri(const std::string &uri, AbilityInfo &abilityInfo) +bool BundleMgrProxy::QueryAbilityInfos(const Want &want, std::vector &abilityInfos) +{ + return true; +} +bool BundleMgrProxy::QueryAbilityInfosForClone(const Want &want, std::vector &abilityInfos) +{ + return true; +} +bool BundleMgrProxy::QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo) { return false; } +bool BundleMgrProxy::QueryKeepAliveBundleInfos(std::vector &bundleInfos) +{ + return true; +} +std::string BundleMgrProxy::GetAbilityLabel(const std::string &bundleName, const std::string &className) +{ + return ""; +} +bool BundleMgrProxy::GetBundleArchiveInfo( + const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) +{ + return true; +} +bool BundleMgrProxy::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) +{ + GTEST_LOG_(INFO) << " BundleMgrProxy::GetHapModuleInfo"; + hapModuleInfo.name = abilityInfo.package; + return true; +} +bool BundleMgrProxy::GetLaunchWantForBundle(const std::string &bundleName, Want &want) +{ + return true; +} +int BundleMgrProxy::CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) +{ + return 0; +} +int BundleMgrProxy::CheckPermission(const std::string &bundleName, const std::string &permission) +{ + return 0; +} +bool BundleMgrProxy::GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) +{ + return true; +} +bool BundleMgrProxy::GetAllPermissionGroupDefs(std::vector &permissionDefs) +{ + return true; +} +bool BundleMgrProxy::GetAppsGrantedPermissions( + const std::vector &permissions, std::vector &appNames) +{ + return true; +} +bool BundleMgrProxy::HasSystemCapability(const std::string &capName) +{ + return true; +} +bool BundleMgrProxy::GetSystemAvailableCapabilities(std::vector &systemCaps) +{ + return true; +} +bool BundleMgrProxy::IsSafeMode() +{ + return true; +} +bool BundleMgrProxy::CleanBundleCacheFiles( + const std::string &bundleName, const sptr &cleanCacheCallback) +{ + return true; +} +bool BundleMgrProxy::CleanBundleDataFiles(const std::string &bundleName) +{ + return true; +} +bool BundleMgrProxy::RegisterBundleStatusCallback(const sptr &bundleStatusCallback) +{ + return true; +} +bool BundleMgrProxy::ClearBundleStatusCallback(const sptr &bundleStatusCallback) +{ + return true; +} +bool BundleMgrProxy::UnregisterBundleStatusCallback() +{ + return true; +} +bool BundleMgrProxy::DumpInfos(const DumpFlag flag, const std::string &bundleName, std::string &result) +{ + return true; +} +bool BundleMgrProxy::IsApplicationEnabled(const std::string &bundleName) +{ + return true; +} +bool BundleMgrProxy::SetApplicationEnabled(const std::string &bundleName, bool isEnable) +{ + return true; +} +bool BundleMgrProxy::IsAbilityEnabled(const AbilityInfo &abilityInfo) +{ + return true; +} +bool BundleMgrProxy::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled) +{ + return true; +} +std::string BundleMgrProxy::GetAbilityIcon(const std::string &bundleName, const std::string &className) +{ + return ""; +} +bool BundleMgrProxy::CanRequestPermission( + const std::string &bundleName, const std::string &permissionName, const int userId) +{ + return true; +} +bool BundleMgrProxy::RequestPermissionFromUser( + const std::string &bundleName, const std::string &permission, const int userId) +{ + return true; +} +bool BundleMgrProxy::RegisterAllPermissionsChanged(const sptr &callback) +{ + return true; +} +bool BundleMgrProxy::RegisterPermissionsChanged( + const std::vector &uids, const sptr &callback) +{ + return true; +} +bool BundleMgrProxy::UnregisterPermissionsChanged(const sptr &callback) +{ + return true; +} +bool BundleMgrProxy::GetAllFormsInfo(std::vector &formInfos) +{ + return true; +} +bool BundleMgrProxy::GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfos) +{ + return true; +} +bool BundleMgrProxy::GetFormsInfoByModule( + const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) +{ + return true; +} +bool BundleMgrProxy::GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) +{ + return true; +} +bool BundleMgrProxy::GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) +{ + return true; +} +sptr BundleMgrProxy::GetBundleInstaller() +{ + return nullptr; +} +bool BundleMgrProxy::NotifyActivityLifeStatus( + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) +{ + return true; +} -bool BundleMgrProxy::GetApplicationInfo( - const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) +int BundleMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + GTEST_LOG_(INFO) << " BundleMgrStub::OnRemoteRequest"; + return 0; +} + +bool BundleMgrService::GetApplicationInfo( + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) { if (appName.empty()) { return false; } appInfo.name = "Helloworld"; - appInfo.bundleName = "com.ohos.hiworld"; + appInfo.bundleName = "com.foobar.hiworld"; return true; } - -std::string BundleMgrProxy::GetAppType(const std::string &bundleName) +bool BundleMgrService::GetApplicationInfos( + const ApplicationFlag flag, const int userId, std::vector &appInfos) { - GTEST_LOG_(INFO) << " BundleMgrProxy::GetAppTyp"; - return "system"; + return true; } - -int BundleMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +bool BundleMgrService::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo) +{ + return true; +} +bool BundleMgrService::GetBundleInfos(const BundleFlag flag, std::vector &bundleInfos) +{ + return true; +} +int BundleMgrService::GetUidByBundleName(const std::string &bundleName, const int userId) { return 0; } - -bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo) +std::string BundleMgrService::GetAppIdByBundleName(const std::string &bundleName, const int userId) +{ + return ""; +} +bool BundleMgrService::GetBundleNameForUid(const int uid, std::string &bundleName) +{ + return true; +} +bool BundleMgrService::GetBundlesForUid(const int uid, std::vector &bundleNames) +{ + return true; +} +bool BundleMgrService::GetNameForUid(const int uid, std::string &name) +{ + return true; +} +bool BundleMgrService::GetBundleGids(const std::string &bundleName, std::vector &gids) +{ + return true; +} +std::string BundleMgrService::GetAppType(const std::string &bundleName) +{ + GTEST_LOG_(INFO) << " BundleMgrService::GetAppType"; + return "system"; +} +bool BundleMgrService::CheckIsSystemAppByUid(const int uid) +{ + return true; +} +bool BundleMgrService::GetBundleInfosByMetaData(const std::string &metaData, std::vector &bundleInfos) +{ + return true; +} +bool BundleMgrService::QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo) { ElementName elementName = want.GetElement(); if (elementName.GetBundleName().empty()) { @@ -81,33 +346,170 @@ bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &ab } return true; } - -bool BundleMgrService::QueryAbilityInfoByUri(const std::string &uri, AbilityInfo &abilityInfo) +bool BundleMgrService::QueryAbilityInfos(const Want &want, std::vector &abilityInfos) +{ + return true; +} +bool BundleMgrService::QueryAbilityInfosForClone(const Want &want, std::vector &abilityInfos) +{ + return true; +} +bool BundleMgrService::QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo) { return false; } - -bool BundleMgrService::GetApplicationInfo( - const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) +bool BundleMgrService::QueryKeepAliveBundleInfos(std::vector &bundleInfos) { - if (appName.empty()) { - return false; - } - appInfo.name = "Helloworld"; - appInfo.bundleName = "com.foobar.hiworld"; return true; } - -std::string BundleMgrService::GetAppType(const std::string &bundleName) +std::string BundleMgrService::GetAbilityLabel(const std::string &bundleName, const std::string &className) { - GTEST_LOG_(INFO) << " BundleMgrService::GetAppType"; - return "system"; + return ""; +} +bool BundleMgrService::GetBundleArchiveInfo( + const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) +{ + return true; } - bool BundleMgrService::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) { GTEST_LOG_(INFO) << " BundleMgrService::GetHapModuleInfo"; - hapModuleInfo.name = "Captain"; + hapModuleInfo.name = abilityInfo.package; + return true; +} +bool BundleMgrService::GetLaunchWantForBundle(const std::string &bundleName, Want &want) +{ + return true; +} +int BundleMgrService::CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) +{ + return 0; +} +int BundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission) +{ + return 0; +} +bool BundleMgrService::GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) +{ + return true; +} +bool BundleMgrService::GetAllPermissionGroupDefs(std::vector &permissionDefs) +{ + return true; +} +bool BundleMgrService::GetAppsGrantedPermissions( + const std::vector &permissions, std::vector &appNames) +{ + return true; +} +bool BundleMgrService::HasSystemCapability(const std::string &capName) +{ + return true; +} +bool BundleMgrService::GetSystemAvailableCapabilities(std::vector &systemCaps) +{ + return true; +} +bool BundleMgrService::IsSafeMode() +{ + return true; +} +bool BundleMgrService::CleanBundleCacheFiles( + const std::string &bundleName, const sptr &cleanCacheCallback) +{ + return true; +} +bool BundleMgrService::CleanBundleDataFiles(const std::string &bundleName) +{ + return true; +} +bool BundleMgrService::RegisterBundleStatusCallback(const sptr &bundleStatusCallback) +{ + return true; +} +bool BundleMgrService::ClearBundleStatusCallback(const sptr &bundleStatusCallback) +{ + return true; +} +bool BundleMgrService::UnregisterBundleStatusCallback() +{ + return true; +} +bool BundleMgrService::DumpInfos(const DumpFlag flag, const std::string &bundleName, std::string &result) +{ + return true; +} +bool BundleMgrService::IsApplicationEnabled(const std::string &bundleName) +{ + return true; +} +bool BundleMgrService::SetApplicationEnabled(const std::string &bundleName, bool isEnable) +{ + return true; +} +bool BundleMgrService::IsAbilityEnabled(const AbilityInfo &abilityInfo) +{ + return true; +} +bool BundleMgrService::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled) +{ + return true; +} +std::string BundleMgrService::GetAbilityIcon(const std::string &bundleName, const std::string &className) +{ + return ""; +} +bool BundleMgrService::CanRequestPermission( + const std::string &bundleName, const std::string &permissionName, const int userId) +{ + return true; +} +bool BundleMgrService::RequestPermissionFromUser( + const std::string &bundleName, const std::string &permission, const int userId) +{ + return true; +} +bool BundleMgrService::RegisterAllPermissionsChanged(const sptr &callback) +{ + return true; +} +bool BundleMgrService::RegisterPermissionsChanged( + const std::vector &uids, const sptr &callback) +{ + return true; +} +bool BundleMgrService::UnregisterPermissionsChanged(const sptr &callback) +{ + return true; +} +bool BundleMgrService::GetAllFormsInfo(std::vector &formInfos) +{ + return true; +} +bool BundleMgrService::GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfos) +{ + return true; +} +bool BundleMgrService::GetFormsInfoByModule( + const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) +{ + return true; +} +bool BundleMgrService::GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) +{ + return true; +} +bool BundleMgrService::GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) +{ + return true; +} +sptr BundleMgrService::GetBundleInstaller() +{ + return nullptr; +} +bool BundleMgrService::NotifyActivityLifeStatus( + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) +{ return true; } } // namespace AppExecFwk diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h index 945dcf3ba6..4bd5996343 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h @@ -17,6 +17,7 @@ #define OHOS_AAFWK_ABILITY_MOCK_BUNDLE_MANAGER_H #include +#include #include "ability_info.h" #include "application_info.h" @@ -33,202 +34,69 @@ public: {} ~BundleMgrProxy() = default; - virtual bool QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo) override; - virtual bool QueryAbilityInfoByUri(const std::string &uri, AbilityInfo &abilityInfo) override; - - virtual std::string GetAppType(const std::string &bundleName) override; - virtual bool GetApplicationInfo( const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) override; virtual bool GetApplicationInfos( - const ApplicationFlag flag, const int userId, std::vector &appInfos) override - { - return true; - }; - bool QueryAbilityInfos(const Want &want, std::vector &abilityInfos) override - { - return true; - }; - bool CheckIsSystemAppByUid(const int uid) override - { - return true; - }; - virtual bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo) override - { - return true; - }; - virtual bool GetBundleInfos(const BundleFlag flag, std::vector &bundleInfos) override - { - return true; - }; - virtual int GetUidByBundleName(const std::string &bundleName, const int userId) override - { - return 0; - }; - virtual bool GetBundleNameForUid(const int uid, std::string &bundleName) override - { - return true; - }; - virtual bool GetBundleGids(const std::string &bundleName, std::vector &gids) override - { - return true; - }; - virtual bool GetBundleInfosByMetaData(const std::string &metaData, std::vector &bundleInfos) override - { - return true; - }; - virtual bool QueryKeepAliveBundleInfos(std::vector &bundleInfos) override - { - return true; - }; - virtual std::string GetAbilityLabel(const std::string &bundleName, const std::string &className) override - { - return ""; - }; - // obtains information about an application bundle contained in a OHOS Ability Package (HAP). + const ApplicationFlag flag, const int userId, std::vector &appInfos) override; + virtual bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo) override; + virtual bool GetBundleInfos(const BundleFlag flag, std::vector &bundleInfos) override; + virtual int GetUidByBundleName(const std::string &bundleName, const int userId) override; + virtual std::string GetAppIdByBundleName(const std::string &bundleName, const int userId) override; + virtual bool GetBundleNameForUid(const int uid, std::string &bundleName) override; + virtual bool GetBundlesForUid(const int uid, std::vector &bundleNames) override; + virtual bool GetNameForUid(const int uid, std::string &name) override; + virtual bool GetBundleGids(const std::string &bundleName, std::vector &gids) override; + virtual std::string GetAppType(const std::string &bundleName) override; + virtual bool CheckIsSystemAppByUid(const int uid) override; + virtual bool GetBundleInfosByMetaData(const std::string &metaData, std::vector &bundleInfos) override; + virtual bool QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo) override; + virtual bool QueryAbilityInfos(const Want &want, std::vector &abilityInfos) override; + virtual bool QueryAbilityInfosForClone(const Want &want, std::vector &abilityInfos) override; + virtual bool QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo) override; + virtual bool QueryKeepAliveBundleInfos(std::vector &bundleInfos) override; + virtual std::string GetAbilityLabel(const std::string &bundleName, const std::string &className) override; virtual bool GetBundleArchiveInfo( - const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) override - { - return true; - }; + const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) override; virtual bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) override; - // obtains the Want for starting the main ability of an application based on the given bundle name. - virtual bool GetLaunchWantForBundle(const std::string &bundleName, Want &want) override - { - return true; - }; - // checks whether the publickeys of two bundles are the same. - virtual int CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) override - { - return 0; - }; - // checks whether a specified bundle has been granted a specific permission. - virtual int CheckPermission(const std::string &bundleName, const std::string &permission) override - { - return 0; - }; - virtual bool GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) override - { - return true; - }; - virtual bool GetAllPermissionGroupDefs(std::vector &permissionDefs) override - { - return true; - }; + virtual bool GetLaunchWantForBundle(const std::string &bundleName, Want &want) override; + virtual int CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) override; + virtual int CheckPermission(const std::string &bundleName, const std::string &permission) override; + virtual bool GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) override; + virtual bool GetAllPermissionGroupDefs(std::vector &permissionDefs) override; virtual bool GetAppsGrantedPermissions( - const std::vector &permissions, std::vector &appNames) override - { - return true; - }; - virtual bool HasSystemCapability(const std::string &capName) override - { - return true; - }; - virtual bool GetSystemAvailableCapabilities(std::vector &systemCaps) override - { - return true; - }; - virtual bool IsSafeMode() override - { - return true; - }; - // clears cache data of a specified application. + const std::vector &permissions, std::vector &appNames) override; + virtual bool HasSystemCapability(const std::string &capName) override; + virtual bool GetSystemAvailableCapabilities(std::vector &systemCaps) override; + virtual bool IsSafeMode() override; virtual bool CleanBundleCacheFiles( - const std::string &bundleName, const sptr &cleanCacheCallback) override - { - return true; - }; - virtual bool CleanBundleDataFiles(const std::string &bundleName) override - { - return true; - }; - virtual bool RegisterBundleStatusCallback(const sptr &bundleStatusCallback) override - { - return true; - }; - virtual bool ClearBundleStatusCallback(const sptr &bundleStatusCallback) override - { - return true; - }; - // unregister callback of all application - virtual bool UnregisterBundleStatusCallback() override - { - return true; - }; - virtual bool DumpInfos(const DumpFlag flag, const std::string &bundleName, std::string &result) override - { - return true; - }; - virtual sptr GetBundleInstaller() override - { - return nullptr; - }; + const std::string &bundleName, const sptr &cleanCacheCallback) override; + virtual bool CleanBundleDataFiles(const std::string &bundleName) override; + virtual bool RegisterBundleStatusCallback(const sptr &bundleStatusCallback) override; + virtual bool ClearBundleStatusCallback(const sptr &bundleStatusCallback) override; + virtual bool UnregisterBundleStatusCallback() override; + virtual bool DumpInfos(const DumpFlag flag, const std::string &bundleName, std::string &result) override; + virtual bool IsApplicationEnabled(const std::string &bundleName) override; + virtual bool SetApplicationEnabled(const std::string &bundleName, bool isEnable) override; + virtual bool IsAbilityEnabled(const AbilityInfo &abilityInfo) override; + virtual bool SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled) override; + virtual std::string GetAbilityIcon(const std::string &bundleName, const std::string &className) override; virtual bool CanRequestPermission( - const std::string &bundleName, const std::string &permissionName, const int userId) override - { - printf("===================22222222===========\n"); - return false; - } + const std::string &bundleName, const std::string &permissionName, const int userId) override; virtual bool RequestPermissionFromUser( - const std::string &bundleName, const std::string &permission, const int userId) override - { - return true; - } - virtual std::string GetAppIdByBundleName(const std::string &bundleName, const int userId) override - { - return ""; - } - virtual bool GetBundlesForUid(const int uid, std::vector &bundleNames) override - { - return true; - } - virtual bool GetNameForUid(const int uid, std::string &name) override - { - return true; - } - virtual bool IsAbilityEnabled(const AbilityInfo &abilityInfo) override - { - return true; - } - virtual bool SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled) override - { - return true; - } - virtual std::string GetAbilityIcon(const std::string &bundleName, const std::string &className) override - { - return ""; - } - virtual bool RegisterAllPermissionsChanged(const sptr &callback) override - { - return true; - } + const std::string &bundleName, const std::string &permission, const int userId) override; + virtual bool RegisterAllPermissionsChanged(const sptr &callback) override; virtual bool RegisterPermissionsChanged( - const std::vector &uids, const sptr &callback) override - { - return true; - } - virtual bool UnregisterPermissionsChanged(const sptr &callback) override - { - return true; - } - virtual bool IsApplicationEnabled(const std::string &bundleName) override - { - return true; - } - virtual bool SetApplicationEnabled(const std::string &bundleName, bool isEnable) override - { - return true; - } - virtual bool GetModuleUsageRecords( - const int32_t number, std::vector &moduleUsageRecords) override - { - return true; - } + const std::vector &uids, const sptr &callback) override; + virtual bool UnregisterPermissionsChanged(const sptr &callback) override; + virtual bool GetAllFormsInfo(std::vector &formInfos) override; + virtual bool GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfos) override; + virtual bool GetFormsInfoByModule( + const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) override; + virtual bool GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) override; + virtual bool GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) override; + virtual sptr GetBundleInstaller() override; virtual bool NotifyActivityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) override - { - return true; - } + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) override; }; class BundleMgrStub : public IRemoteStub { @@ -240,202 +108,69 @@ public: class BundleMgrService : public BundleMgrStub { public: - virtual bool QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo) override; - virtual bool QueryAbilityInfoByUri(const std::string &uri, AbilityInfo &abilityInfo) override; - - virtual std::string GetAppType(const std::string &bundleName) override; - virtual bool GetApplicationInfo( const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) override; virtual bool GetApplicationInfos( - const ApplicationFlag flag, const int userId, std::vector &appInfos) override - { - return true; - }; - virtual bool QueryAbilityInfos(const Want &want, std::vector &abilityInfos) override - { - return true; - }; - virtual bool CheckIsSystemAppByUid(const int uid) override - { - return true; - }; - virtual bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo) override - { - return true; - }; - virtual bool GetBundleInfos(const BundleFlag flag, std::vector &bundleInfos) override - { - return true; - }; - virtual int GetUidByBundleName(const std::string &bundleName, const int userId) override - { - return 0; - }; - virtual bool GetBundleNameForUid(const int uid, std::string &bundleName) override - { - return true; - }; - virtual bool GetBundleGids(const std::string &bundleName, std::vector &gids) override - { - return true; - }; - virtual bool GetBundleInfosByMetaData(const std::string &metaData, std::vector &bundleInfos) override - { - return true; - }; - virtual bool QueryKeepAliveBundleInfos(std::vector &bundleInfos) override - { - return true; - }; - virtual std::string GetAbilityLabel(const std::string &bundleName, const std::string &className) override - { - return ""; - }; - // obtains information about an application bundle contained in a OHOS Ability Package (HAP). + const ApplicationFlag flag, const int userId, std::vector &appInfos) override; + virtual bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo) override; + virtual bool GetBundleInfos(const BundleFlag flag, std::vector &bundleInfos) override; + virtual int GetUidByBundleName(const std::string &bundleName, const int userId) override; + virtual std::string GetAppIdByBundleName(const std::string &bundleName, const int userId) override; + virtual bool GetBundleNameForUid(const int uid, std::string &bundleName) override; + virtual bool GetBundlesForUid(const int uid, std::vector &bundleNames) override; + virtual bool GetNameForUid(const int uid, std::string &name) override; + virtual bool GetBundleGids(const std::string &bundleName, std::vector &gids) override; + virtual std::string GetAppType(const std::string &bundleName) override; + virtual bool CheckIsSystemAppByUid(const int uid) override; + virtual bool GetBundleInfosByMetaData(const std::string &metaData, std::vector &bundleInfos) override; + virtual bool QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo) override; + virtual bool QueryAbilityInfos(const Want &want, std::vector &abilityInfos) override; + virtual bool QueryAbilityInfosForClone(const Want &want, std::vector &abilityInfos) override; + virtual bool QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo) override; + virtual bool QueryKeepAliveBundleInfos(std::vector &bundleInfos) override; + virtual std::string GetAbilityLabel(const std::string &bundleName, const std::string &className) override; virtual bool GetBundleArchiveInfo( - const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) override - { - return true; - }; + const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) override; virtual bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) override; - // obtains the Want for starting the main ability of an application based on the given bundle name. - virtual bool GetLaunchWantForBundle(const std::string &bundleName, Want &want) override - { - return true; - }; - // checks whether the publickeys of two bundles are the same. - virtual int CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) override - { - return 0; - }; - // checks whether a specified bundle has been granted a specific permission. - virtual int CheckPermission(const std::string &bundleName, const std::string &permission) override - { - return 0; - }; - virtual bool GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) override - { - return true; - }; - virtual bool GetAllPermissionGroupDefs(std::vector &permissionDefs) override - { - return true; - }; + virtual bool GetLaunchWantForBundle(const std::string &bundleName, Want &want) override; + virtual int CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) override; + virtual int CheckPermission(const std::string &bundleName, const std::string &permission) override; + virtual bool GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) override; + virtual bool GetAllPermissionGroupDefs(std::vector &permissionDefs) override; virtual bool GetAppsGrantedPermissions( - const std::vector &permissions, std::vector &appNames) override - { - return true; - }; - virtual bool HasSystemCapability(const std::string &capName) override - { - return true; - }; - virtual bool GetSystemAvailableCapabilities(std::vector &systemCaps) override - { - return true; - }; - virtual bool IsSafeMode() override - { - return true; - }; - // clears cache data of a specified application. + const std::vector &permissions, std::vector &appNames) override; + virtual bool HasSystemCapability(const std::string &capName) override; + virtual bool GetSystemAvailableCapabilities(std::vector &systemCaps) override; + virtual bool IsSafeMode() override; virtual bool CleanBundleCacheFiles( - const std::string &bundleName, const sptr &cleanCacheCallback) override - { - return true; - }; - virtual bool CleanBundleDataFiles(const std::string &bundleName) override - { - return true; - }; - virtual bool RegisterBundleStatusCallback(const sptr &bundleStatusCallback) override - { - return true; - }; - virtual bool ClearBundleStatusCallback(const sptr &bundleStatusCallback) override - { - return true; - }; - // unregister callback of all application - virtual bool UnregisterBundleStatusCallback() override - { - return true; - }; - virtual bool DumpInfos(const DumpFlag flag, const std::string &bundleName, std::string &result) override - { - return true; - }; - virtual sptr GetBundleInstaller() override - { - return nullptr; - }; + const std::string &bundleName, const sptr &cleanCacheCallback) override; + virtual bool CleanBundleDataFiles(const std::string &bundleName) override; + virtual bool RegisterBundleStatusCallback(const sptr &bundleStatusCallback) override; + virtual bool ClearBundleStatusCallback(const sptr &bundleStatusCallback) override; + virtual bool UnregisterBundleStatusCallback() override; + virtual bool DumpInfos(const DumpFlag flag, const std::string &bundleName, std::string &result) override; + virtual bool IsApplicationEnabled(const std::string &bundleName) override; + virtual bool SetApplicationEnabled(const std::string &bundleName, bool isEnable) override; + virtual bool IsAbilityEnabled(const AbilityInfo &abilityInfo) override; + virtual bool SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled) override; + virtual std::string GetAbilityIcon(const std::string &bundleName, const std::string &className) override; virtual bool CanRequestPermission( - const std::string &bundleName, const std::string &permissionName, const int userId) override - { - printf("===================333333333333333333===========\n"); - return false; - } + const std::string &bundleName, const std::string &permissionName, const int userId) override; virtual bool RequestPermissionFromUser( - const std::string &bundleName, const std::string &permission, const int userId) override - { - return true; - } - virtual std::string GetAppIdByBundleName(const std::string &bundleName, const int userId) override - { - return ""; - } - virtual bool GetBundlesForUid(const int uid, std::vector &bundleNames) override - { - return true; - } - virtual bool GetNameForUid(const int uid, std::string &name) override - { - return true; - } - virtual bool IsAbilityEnabled(const AbilityInfo &abilityInfo) override - { - return true; - } - virtual bool SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled) override - { - return true; - } - virtual std::string GetAbilityIcon(const std::string &bundleName, const std::string &className) override - { - return ""; - } - virtual bool RegisterAllPermissionsChanged(const sptr &callback) override - { - return true; - } + const std::string &bundleName, const std::string &permission, const int userId) override; + virtual bool RegisterAllPermissionsChanged(const sptr &callback) override; virtual bool RegisterPermissionsChanged( - const std::vector &uids, const sptr &callback) override - { - return true; - } - virtual bool UnregisterPermissionsChanged(const sptr &callback) override - { - return true; - } - virtual bool IsApplicationEnabled(const std::string &bundleName) override - { - return true; - } - virtual bool SetApplicationEnabled(const std::string &bundleName, bool isEnable) override - { - return true; - } - virtual bool GetModuleUsageRecords( - const int32_t number, std::vector &moduleUsageRecords) override - { - return true; - } + const std::vector &uids, const sptr &callback) override; + virtual bool UnregisterPermissionsChanged(const sptr &callback) override; + virtual bool GetAllFormsInfo(std::vector &formInfos) override; + virtual bool GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfos) override; + virtual bool GetFormsInfoByModule( + const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) override; + virtual bool GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) override; + virtual bool GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) override; + virtual sptr GetBundleInstaller() override; virtual bool NotifyActivityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) override - { - return true; - } + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) override; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp b/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp index 84e9d46816..5c38f8601b 100644 --- a/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp +++ b/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include "sys_mgr_client.h" #include "hilog_wrapper.h" #include "if_system_ability_manager.h" @@ -30,6 +30,7 @@ SysMrgClient::~SysMrgClient() sptr SysMrgClient::GetSystemAbility(const int32_t systemAbilityId) { + GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::GetSystemAbility( " << systemAbilityId << " )"; if (servicesMap_[systemAbilityId] == nullptr) { OHOS::sptr abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -40,11 +41,14 @@ sptr SysMrgClient::GetSystemAbility(const int32_t systemAbilityId OHOS::sptr object = abilityManager->GetSystemAbility(systemAbilityId); servicesMap_[systemAbilityId] = object; } - return servicesMap_[systemAbilityId]; + auto ret = servicesMap_[systemAbilityId]; + GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::GetSystemAbility( " << ret.GetRefPtr() << " )"; + return ret; } void SysMrgClient::RegisterSystemAbility(const int32_t systemAbilityId, sptr broker) { + GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::RegisterSystemAbility( " << broker.GetRefPtr() << " )"; servicesMap_[systemAbilityId] = broker; } } // namespace AppExecFwk diff --git a/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp b/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp index 52231897ad..b3395c7b43 100644 --- a/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp +++ b/frameworks/kits/ability/native/test/unittest/ability_context_test.cpp @@ -52,6 +52,8 @@ void AbilityContextTest::SetUpTestCase(void) GTEST_LOG_(INFO) << "AppExecFwk_AbilityContext_SetUpTestCase start"; OHOS::sptr bundleObject = new (std::nothrow) BundleMgrService(); OHOS::sptr abilityObject = new (std::nothrow) OHOS::AAFwk::MockAbilityManagerService(); + GTEST_LOG_(INFO) << "AppExecFwk_AbilityContext_SetUpTestCase bundleObject->" << bundleObject.GetRefPtr(); + GTEST_LOG_(INFO) << "AppExecFwk_AbilityContext_SetUpTestCase abilityObject->" << abilityObject.GetRefPtr(); auto sysMgr = OHOS::DelayedSingleton::GetInstance(); if (sysMgr == NULL) { @@ -77,7 +79,6 @@ void AbilityContextTest::SetUp(void) void AbilityContextTest::TearDown(void) {} - /** * @tc.number: AaFwk_AbilityContext_StartAbility_0100 * @tc.name: StartAbility @@ -565,13 +566,14 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_GetHapModuleInfo_0100, TestSize.Level std::shared_ptr contextDeal = std::make_shared(); std::shared_ptr abilityInfo = std::make_shared(); - std::string name = "Captain"; - abilityInfo->name = name; + std::string name = "com.ohos.callui"; + std::string package = "com.ohos.callui"; + abilityInfo->bundleName = name; + abilityInfo->package = package; contextDeal->SetAbilityInfo(abilityInfo); context_->AttachBaseContext(contextDeal); - Want want; std::shared_ptr info = context_->GetHapModuleInfo(); - EXPECT_STREQ(info->name.c_str(), name.c_str()); + EXPECT_STREQ(info->name.c_str(), package.c_str()); GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 end"; } } // namespace AppExecFwk diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp index b8788c8a79..2eb02378d0 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp @@ -906,15 +906,21 @@ void FindRegisterObs(napi_env env, DAHelperOnOffCB *data) // if match callback ,or match both callback and uri napi_value callbackA = 0; napi_get_reference_value(data->cbBase.cbInfo.env, data->cbBase.cbInfo.callback, &callbackA); + std::string strUri = data->uri; do { auto helper = std::find_if( - registerInstances_.begin(), registerInstances_.end(), [callbackA](const DAHelperOnOffCB *helper) { + registerInstances_.begin(), registerInstances_.end(), [callbackA, strUri](const DAHelperOnOffCB *helper) { bool result = false; if (helper == nullptr || helper->cbBase.cbInfo.callback == nullptr) { HILOG_ERROR("UnRegisterExecuteCB %{public}s is nullptr", ((helper == nullptr) ? "helper" : "helper->cbBase.cbInfo.callback")); return result; } + if (helper->uri != strUri) { + HILOG_ERROR("UnRegisterExecuteCB find uri inconsistent, h=[%{public}s] u=[%{public}s]", + helper->uri.c_str(), strUri.c_str()); + return result; + } napi_value callbackB = 0; napi_get_reference_value(helper->cbBase.cbInfo.env, helper->cbBase.cbInfo.callback, &callbackB); auto ret = napi_strict_equals(helper->cbBase.cbInfo.env, callbackA, callbackB, &result); @@ -922,18 +928,9 @@ void FindRegisterObs(napi_env env, DAHelperOnOffCB *data) return result; }); if (helper != registerInstances_.end()) { - OHOS::Uri uri((*helper)->uri); - // if uri is not empty, uri and callback has to be equal at the same time. - if (data->uri == uri.ToString()) { - // match callback, or match both callback and uri - data->NotifyList.emplace_back(*helper); - registerInstances_.erase(helper); + data->NotifyList.emplace_back(*helper); + registerInstances_.erase(helper); HILOG_INFO("NAPI_UnRegister Instances erase size = %{public}zu", registerInstances_.size()); - } else { - HILOG_INFO("NAPI_UnRegister uri=%{public}s,helper.Uri=%{public}s", - data->uri.c_str(), - uri.ToString().c_str()); - } } else { HILOG_INFO("NAPI_UnRegister not match any callback. %{public}zu", registerInstances_.size()); break; // not match any callback From e3fec09cfe96c00f9040b841753ff60fd456526b Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Mon, 8 Nov 2021 13:47:34 +0800 Subject: [PATCH 2/3] Fix codex Signed-off-by: zhaoyuan17 --- .../test/mock/include/bundle_mgr_interface.h | 1 - .../test/mock/include/mock_bundle_manager.cpp | 38 ++-- .../test/mock/include/mock_bundle_manager.h | 6 +- .../test/mock/include/sys_mgr_client_mock.cpp | 9 +- .../napi_data_ability_helper.cpp | 173 ++++++++++-------- 5 files changed, 124 insertions(+), 103 deletions(-) diff --git a/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h b/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h index 8e0f4bd4ce..e194fe3a2a 100644 --- a/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h +++ b/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h @@ -31,7 +31,6 @@ using OHOS::AAFwk::Want; namespace OHOS { namespace AppExecFwk { - struct FormInfo; struct ShortcutInfo; diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp index 44586273df..35fff14f3c 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace AppExecFwk { bool BundleMgrProxy::GetApplicationInfo( - const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) { if (appName.empty()) { return false; @@ -32,7 +32,7 @@ bool BundleMgrProxy::GetApplicationInfo( return true; } bool BundleMgrProxy::GetApplicationInfos( - const ApplicationFlag flag, const int userId, std::vector &appInfos) + const ApplicationFlag flag, const int userId, std::vector &appInfos) { return true; } @@ -145,7 +145,7 @@ bool BundleMgrProxy::GetAllPermissionGroupDefs(std::vector &permi return true; } bool BundleMgrProxy::GetAppsGrantedPermissions( - const std::vector &permissions, std::vector &appNames) + const std::vector &permissions, std::vector &appNames) { return true; } @@ -162,7 +162,7 @@ bool BundleMgrProxy::IsSafeMode() return true; } bool BundleMgrProxy::CleanBundleCacheFiles( - const std::string &bundleName, const sptr &cleanCacheCallback) + const std::string &bundleName, const sptr &cleanCacheCallback) { return true; } @@ -207,12 +207,12 @@ std::string BundleMgrProxy::GetAbilityIcon(const std::string &bundleName, const return ""; } bool BundleMgrProxy::CanRequestPermission( - const std::string &bundleName, const std::string &permissionName, const int userId) + const std::string &bundleName, const std::string &permissionName, const int userId) { return true; } bool BundleMgrProxy::RequestPermissionFromUser( - const std::string &bundleName, const std::string &permission, const int userId) + const std::string &bundleName, const std::string &permission, const int userId) { return true; } @@ -221,7 +221,7 @@ bool BundleMgrProxy::RegisterAllPermissionsChanged(const sptr &uids, const sptr &callback) + const std::vector &uids, const sptr &callback) { return true; } @@ -238,7 +238,7 @@ bool BundleMgrProxy::GetFormsInfoByApp(const std::string &bundleName, std::vecto return true; } bool BundleMgrProxy::GetFormsInfoByModule( - const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) + const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) { return true; } @@ -255,7 +255,7 @@ sptr BundleMgrProxy::GetBundleInstaller() return nullptr; } bool BundleMgrProxy::NotifyActivityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) { return true; } @@ -267,7 +267,7 @@ int BundleMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa } bool BundleMgrService::GetApplicationInfo( - const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) { if (appName.empty()) { return false; @@ -277,7 +277,7 @@ bool BundleMgrService::GetApplicationInfo( return true; } bool BundleMgrService::GetApplicationInfos( - const ApplicationFlag flag, const int userId, std::vector &appInfos) + const ApplicationFlag flag, const int userId, std::vector &appInfos) { return true; } @@ -367,7 +367,7 @@ std::string BundleMgrService::GetAbilityLabel(const std::string &bundleName, con return ""; } bool BundleMgrService::GetBundleArchiveInfo( - const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) + const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) { return true; } @@ -398,7 +398,7 @@ bool BundleMgrService::GetAllPermissionGroupDefs(std::vector &per return true; } bool BundleMgrService::GetAppsGrantedPermissions( - const std::vector &permissions, std::vector &appNames) + const std::vector &permissions, std::vector &appNames) { return true; } @@ -415,7 +415,7 @@ bool BundleMgrService::IsSafeMode() return true; } bool BundleMgrService::CleanBundleCacheFiles( - const std::string &bundleName, const sptr &cleanCacheCallback) + const std::string &bundleName, const sptr &cleanCacheCallback) { return true; } @@ -460,12 +460,12 @@ std::string BundleMgrService::GetAbilityIcon(const std::string &bundleName, cons return ""; } bool BundleMgrService::CanRequestPermission( - const std::string &bundleName, const std::string &permissionName, const int userId) + const std::string &bundleName, const std::string &permissionName, const int userId) { return true; } bool BundleMgrService::RequestPermissionFromUser( - const std::string &bundleName, const std::string &permission, const int userId) + const std::string &bundleName, const std::string &permission, const int userId) { return true; } @@ -474,7 +474,7 @@ bool BundleMgrService::RegisterAllPermissionsChanged(const sptr &uids, const sptr &callback) + const std::vector &uids, const sptr &callback) { return true; } @@ -491,7 +491,7 @@ bool BundleMgrService::GetFormsInfoByApp(const std::string &bundleName, std::vec return true; } bool BundleMgrService::GetFormsInfoByModule( - const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) + const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) { return true; } @@ -508,7 +508,7 @@ sptr BundleMgrService::GetBundleInstaller() return nullptr; } bool BundleMgrService::NotifyActivityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) { return true; } diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h index 4bd5996343..b342c838f8 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h @@ -93,7 +93,8 @@ public: virtual bool GetFormsInfoByModule( const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) override; virtual bool GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) override; - virtual bool GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) override; + virtual bool GetModuleUsageRecords( + const int32_t number, std::vector &moduleUsageRecords) override; virtual sptr GetBundleInstaller() override; virtual bool NotifyActivityLifeStatus( const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) override; @@ -167,7 +168,8 @@ public: virtual bool GetFormsInfoByModule( const std::string &bundleName, const std::string &moduleName, std::vector &formInfos) override; virtual bool GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) override; - virtual bool GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) override; + virtual bool GetModuleUsageRecords( + const int32_t number, std::vector &moduleUsageRecords) override; virtual sptr GetBundleInstaller() override; virtual bool NotifyActivityLifeStatus( const std::string &bundleName, const std::string &abilityName, const int64_t launchTime) override; diff --git a/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp b/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp index 5c38f8601b..76386d83a9 100644 --- a/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp +++ b/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp @@ -30,7 +30,8 @@ SysMrgClient::~SysMrgClient() sptr SysMrgClient::GetSystemAbility(const int32_t systemAbilityId) { - GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::GetSystemAbility( " << systemAbilityId << " )"; + GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::GetSystemAbility( " + << systemAbilityId << " )"; if (servicesMap_[systemAbilityId] == nullptr) { OHOS::sptr abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -42,13 +43,15 @@ sptr SysMrgClient::GetSystemAbility(const int32_t systemAbilityId servicesMap_[systemAbilityId] = object; } auto ret = servicesMap_[systemAbilityId]; - GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::GetSystemAbility( " << ret.GetRefPtr() << " )"; + GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::GetSystemAbility( " + << ret.GetRefPtr() << " )"; return ret; } void SysMrgClient::RegisterSystemAbility(const int32_t systemAbilityId, sptr broker) { - GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::RegisterSystemAbility( " << broker.GetRefPtr() << " )"; + GTEST_LOG_(INFO) << "AaFwk_Ability_GetHapModuleInfo_0100 SysMrgClient::RegisterSystemAbility( " + << broker.GetRefPtr() << " )"; servicesMap_[systemAbilityId] = broker; } } // namespace AppExecFwk diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp index 2eb02378d0..e91b7929d0 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp @@ -894,6 +894,51 @@ napi_value UnRegisterAsync( return result; } +static void FindRegisterObsByCallBack(napi_env env, DAHelperOnOffCB *data) +{ + HILOG_INFO("NAPI_UnRegister, UnRegisterExecuteCB callback is not null."); + if (data == nullptr || data->dataAbilityHelper == nullptr) { + HILOG_ERROR("NAPI_UnRegister, param is null."); + return; + } + // if match callback ,or match both callback and uri + napi_value callbackA = 0; + napi_get_reference_value(data->cbBase.cbInfo.env, data->cbBase.cbInfo.callback, &callbackA); + std::string strUri = data->uri; + do { + auto helper = std::find_if( + registerInstances_.begin(), + registerInstances_.end(), + [callbackA, strUri](const DAHelperOnOffCB *helper) { + bool result = false; + if (helper == nullptr || helper->cbBase.cbInfo.callback == nullptr) { + HILOG_ERROR("UnRegisterExecuteCB %{public}s is nullptr", + ((helper == nullptr) ? "helper" : "helper->cbBase.cbInfo.callback")); + return result; + } + if (helper->uri != strUri) { + HILOG_ERROR("UnRegisterExecuteCB find uri inconsistent, h=[%{public}s] u=[%{public}s]", + helper->uri.c_str(), strUri.c_str()); + return result; + } + napi_value callbackB = 0; + napi_get_reference_value(helper->cbBase.cbInfo.env, helper->cbBase.cbInfo.callback, &callbackB); + auto ret = napi_strict_equals(helper->cbBase.cbInfo.env, callbackA, callbackB, &result); + HILOG_INFO("NAPI_UnRegister cb equals status=%{public}d result=%{public}d.", ret, result); + return result; + }); + if (helper != registerInstances_.end()) { + data->NotifyList.emplace_back(*helper); + registerInstances_.erase(helper); + HILOG_INFO("NAPI_UnRegister Instances erase size = %{public}zu", registerInstances_.size()); + } else { + HILOG_INFO("NAPI_UnRegister not match any callback. %{public}zu", registerInstances_.size()); + break; // not match any callback + } + } while (true); + HILOG_INFO("NAPI_UnRegister, UnRegisterExecuteCB FindRegisterObsByCallBack Called End."); +} + void FindRegisterObs(napi_env env, DAHelperOnOffCB *data) { HILOG_INFO("NAPI_UnRegister, FindRegisterObs main event thread execute."); @@ -903,39 +948,7 @@ void FindRegisterObs(napi_env env, DAHelperOnOffCB *data) } if (data->cbBase.cbInfo.callback != nullptr) { HILOG_INFO("NAPI_UnRegister, UnRegisterExecuteCB callback is not null."); - // if match callback ,or match both callback and uri - napi_value callbackA = 0; - napi_get_reference_value(data->cbBase.cbInfo.env, data->cbBase.cbInfo.callback, &callbackA); - std::string strUri = data->uri; - do { - auto helper = std::find_if( - registerInstances_.begin(), registerInstances_.end(), [callbackA, strUri](const DAHelperOnOffCB *helper) { - bool result = false; - if (helper == nullptr || helper->cbBase.cbInfo.callback == nullptr) { - HILOG_ERROR("UnRegisterExecuteCB %{public}s is nullptr", - ((helper == nullptr) ? "helper" : "helper->cbBase.cbInfo.callback")); - return result; - } - if (helper->uri != strUri) { - HILOG_ERROR("UnRegisterExecuteCB find uri inconsistent, h=[%{public}s] u=[%{public}s]", - helper->uri.c_str(), strUri.c_str()); - return result; - } - napi_value callbackB = 0; - napi_get_reference_value(helper->cbBase.cbInfo.env, helper->cbBase.cbInfo.callback, &callbackB); - auto ret = napi_strict_equals(helper->cbBase.cbInfo.env, callbackA, callbackB, &result); - HILOG_INFO("NAPI_UnRegister cb equals status=%{public}d result=%{public}d.", ret, result); - return result; - }); - if (helper != registerInstances_.end()) { - data->NotifyList.emplace_back(*helper); - registerInstances_.erase(helper); - HILOG_INFO("NAPI_UnRegister Instances erase size = %{public}zu", registerInstances_.size()); - } else { - HILOG_INFO("NAPI_UnRegister not match any callback. %{public}zu", registerInstances_.size()); - break; // not match any callback - } - } while (true); + FindRegisterObsByCallBack(env, data); } else { HILOG_INFO("NAPI_UnRegister, uri=%{public}s.", data->uri.c_str()); if (data->uri != "") { @@ -1114,6 +1127,54 @@ void NAPIDataAbilityObserver::SetCallbackRef(const napi_ref &ref) HILOG_INFO("NAPIDataAbilityObserver::%{public}s, called. end", __func__); } +static void OnChangeJSThreadWorker(uv_work_t *work, int status) +{ + HILOG_INFO("OnChange, uv_queue_work"); + if (work == nullptr) { + HILOG_ERROR("OnChange, uv_queue_work input work is nullptr"); + return; + } + DAHelperOnOffCB *onCB = (DAHelperOnOffCB *)work->data; + NAPIDataAbilityObserver* obs = onCB->observer; + onCB->observer = nullptr; + if (obs != nullptr) { + obs->ChangeWorkRun(); + } + napi_value result[ARGS_TWO] = {0}; + result[PARAM0] = GetCallbackErrorValue(onCB->cbBase.cbInfo.env, NO_ERROR); + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(onCB->cbBase.cbInfo.env, &undefined); + napi_value callResult = 0; + napi_get_reference_value(onCB->cbBase.cbInfo.env, onCB->cbBase.cbInfo.callback, &callback); + napi_call_function(onCB->cbBase.cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult); + if (obs != nullptr) { + if (obs->GetWorkInt() == 1) { + obs->ReleaseJSCallback(); + DAHelperOnOffCB* assicuated = obs->GetAssociatedObject(); + if (assicuated != nullptr) { + HILOG_INFO("OnChange, uv_queue_work ReleaseJSCallback Called"); + obs->SetAssociatedObject(nullptr); + delete assicuated; + assicuated = nullptr; + } + } + else { + obs->ChangeWorkRunDone(); + obs->ChangeWorkPreDone(); + } + } + if (onCB != nullptr) { + delete onCB; + onCB = nullptr; + } + if (work != nullptr) { + delete work; + work = nullptr; + } + HILOG_INFO("OnChange, uv_queue_work. end"); +} + void NAPIDataAbilityObserver::OnChange() { HILOG_INFO("%{public}s, called.", __func__); @@ -1153,51 +1214,7 @@ void NAPIDataAbilityObserver::OnChange() loop, work, [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - HILOG_INFO("OnChange, uv_queue_work"); - // JS Thread - DAHelperOnOffCB *onCB = (DAHelperOnOffCB *)work->data; - NAPIDataAbilityObserver* obs = onCB->observer; - onCB->observer = nullptr; - if (obs != nullptr) { - obs->ChangeWorkRun(); - } - napi_value result[ARGS_TWO] = {0}; - result[PARAM0] = GetCallbackErrorValue(onCB->cbBase.cbInfo.env, NO_ERROR); - napi_value callback = 0; - napi_value undefined = 0; - napi_get_undefined(onCB->cbBase.cbInfo.env, &undefined); - napi_value callResult = 0; - napi_get_reference_value(onCB->cbBase.cbInfo.env, onCB->cbBase.cbInfo.callback, &callback); - napi_call_function(onCB->cbBase.cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult); - - if (obs != nullptr) { - if (obs->GetWorkInt() == 1) { - obs->ReleaseJSCallback(); - DAHelperOnOffCB* assicuated = obs->GetAssociatedObject(); - if (assicuated != nullptr) { - HILOG_INFO("OnChange, uv_queue_work ReleaseJSCallback Called"); - obs->SetAssociatedObject(nullptr); - delete assicuated; - assicuated = nullptr; - } - } - else { - obs->ChangeWorkRunDone(); - obs->ChangeWorkPreDone(); - } - } - - if (onCB != nullptr) { - delete onCB; - onCB = nullptr; - } - if (work != nullptr) { - delete work; - work = nullptr; - } - HILOG_INFO("OnChange, uv_queue_work. end"); - }); + OnChangeJSThreadWorker); if (rev != 0) { if (onCB != nullptr) { delete onCB; From 7fc9f6aeedf296dda22f2795288f770e62b06228 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Mon, 8 Nov 2021 14:35:58 +0800 Subject: [PATCH 3/3] Fix codex Signed-off-by: zhaoyuan17 --- .../native/test/mock/include/mock_bundle_manager.cpp | 2 +- .../napi/aafwk/featureAbility/napi_data_ability_helper.cpp | 7 +++---- .../ability_mgr_service_test/ability_mgr_module_test.cpp | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp index 35fff14f3c..39cfe46001 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp @@ -114,7 +114,7 @@ std::string BundleMgrProxy::GetAbilityLabel(const std::string &bundleName, const return ""; } bool BundleMgrProxy::GetBundleArchiveInfo( - const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) + const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo) { return true; } diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp index e91b7929d0..d9262accff 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp @@ -1131,8 +1131,8 @@ static void OnChangeJSThreadWorker(uv_work_t *work, int status) { HILOG_INFO("OnChange, uv_queue_work"); if (work == nullptr) { - HILOG_ERROR("OnChange, uv_queue_work input work is nullptr"); - return; + HILOG_ERROR("OnChange, uv_queue_work input work is nullptr"); + return; } DAHelperOnOffCB *onCB = (DAHelperOnOffCB *)work->data; NAPIDataAbilityObserver* obs = onCB->observer; @@ -1158,8 +1158,7 @@ static void OnChangeJSThreadWorker(uv_work_t *work, int status) delete assicuated; assicuated = nullptr; } - } - else { + } else { obs->ChangeWorkRunDone(); obs->ChangeWorkPreDone(); } diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index 6e6617c350..03f78d43c5 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -80,9 +80,9 @@ public: std::shared_ptr GetTopAbility(); void ClearStack(); - inline static std::shared_ptr mockAppMgrClient_{nullptr}; - inline static std::shared_ptr abilityMgrServ_{nullptr}; - sptr scheduler_{nullptr}; + inline static std::shared_ptr mockAppMgrClient_ {nullptr}; + inline static std::shared_ptr abilityMgrServ_ {nullptr}; + sptr scheduler_ {nullptr}; inline static bool doOnce_ = false; // In order for mock to execute once static constexpr int TEST_WAIT_TIME = 100000;