diff --git a/services/common/include/bundle_active_bundle_mgr_helper.h b/services/common/include/bundle_active_bundle_mgr_helper.h index 94592bf8a054ac757bbaf7dd690803b637935cf9..5256a3719bd3dbfb5fcf8394803cfecf3a09275a 100644 --- a/services/common/include/bundle_active_bundle_mgr_helper.h +++ b/services/common/include/bundle_active_bundle_mgr_helper.h @@ -22,6 +22,7 @@ #include "ipc_skeleton.h" #include "iremote_object.h" #include "singleton.h" +#include #include "bundle_active_log.h" @@ -59,13 +60,15 @@ public: bool GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag, const int userId, AppExecFwk::ApplicationInfo &appInfo); + bool IsLauncherApp(const std::string &bundleName, const int32_t userId); + private: bool Connect(); private: + std::unordered_set launcherAppSet_; sptr bundleMgr_ = nullptr; std::mutex connectionMutex_; - DECLARE_DELAYED_SINGLETON(BundleActiveBundleMgrHelper); }; } // namespace DeviceUsageStats diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index e584f0c0dc8d9ce1354788d1695598d0dd384c41..c85504df3b01de7733ad9bb619c8d2bf68b2ef5a 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -16,6 +16,7 @@ #include "bundle_active_bundle_mgr_helper.h" #include "accesstoken_kit.h" +#include "application_info.h" #include "iservice_registry.h" #include "system_ability_definition.h" #include "tokenid_kit.h" @@ -99,5 +100,23 @@ bool BundleActiveBundleMgrHelper::Connect() bundleMgr_ = iface_cast(remoteObject); return bundleMgr_ ? true : false; } + +bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, const int32_t userId) +{ + if (launcherAppSet_.find(bundleName) != launcherAppSet_.end()) { + return true; + } + AppExecFwk::ApplicationInfo appInfo; + if (GetApplicationInfo(bundleName, + AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo) != ERR_OK) { + BUNDLE_ACTIVE_LOGE("get applicationInfo failed."); + return false; + } + if (appInfo.isLauncherApp) { + launcherAppSet_.insert(bundleName); + return true; + } + return false; +} } // namespace DeviceUsageStats } // namespace OHOS \ No newline at end of file diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 06ad2e5c4c4e21874b5ba55b3c14f894540fc52a..0150d042417a461b38cbe9ae0790ffa196e02593 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -20,11 +20,11 @@ #include "bundle_active_event_stats.h" #include "bundle_active_report_handler.h" #include "bundle_active_group_common.h" +#include "bundle_active_bundle_mgr_helper.h" #include "bundle_active_constant.h" namespace OHOS { namespace DeviceUsageStats { -const std::string LAUNCHER_BUNDLE_NAME = "com.ohos.launcher"; #ifndef OS_ACCOUNT_PART_ENABLED const int32_t DEFAULT_OS_ACCOUNT_ID = 0; // 0 is the default id when there is no os_account part #endif // OS_ACCOUNT_PART_ENABLED @@ -469,7 +469,7 @@ int32_t BundleActiveCore::ReportEvent(BundleActiveEvent& event, int32_t userId) } sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); - if (event.bundleName_ == LAUNCHER_BUNDLE_NAME) { + if (BundleActiveBundleMgrHelper::GetInstance()->IsLauncherApp(event.bundleName_, userId)) { BUNDLE_ACTIVE_LOGI("launcher event, only update app group"); bundleGroupController_->ReportEvent(event, bootBasedTimeStamp, userId); return 0;