From 4c8fab422026ce05b34adeb9e1918cbf118b334f Mon Sep 17 00:00:00 2001 From: fengyang Date: Mon, 29 Apr 2024 12:42:17 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BD=BF=E7=94=A8isLauncher=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=9B=BF=E6=8D=A2=E7=A1=AC=E7=BC=96=E7=A0=81Launcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- .../include/bundle_active_bundle_mgr_helper.h | 6 ++++- .../src/bundle_active_bundle_mgr_helper.cpp | 22 +++++++++++++++++++ services/common/src/bundle_active_core.cpp | 4 ++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/services/common/include/bundle_active_bundle_mgr_helper.h b/services/common/include/bundle_active_bundle_mgr_helper.h index 94592bf..092cb26 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,16 @@ public: bool GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag, const int userId, AppExecFwk::ApplicationInfo &appInfo); + bool IsLauncherApp(std::string bundleName, int32_t userId); + private: bool Connect(); private: + std::unordered_set luncherAppSet_; + std::unordered_set isNotluncherAppSet_; 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 e584f0c..67ddb93 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -99,5 +99,27 @@ bool BundleActiveBundleMgrHelper::Connect() bundleMgr_ = iface_cast(remoteObject); return bundleMgr_ ? true : false; } + +bool BundleActiveBundleMgrHelper::IsLauncherApp(std::string bundleName, int32_t userId) +{ + if (luncherAppSet_.find(bundleName) != luncherAppSet_.end()) { + return true; + } + if (isNotluncherAppSet_.find(bundleName) != luncherAppSet_.end()) { + return false; + } + AppExecFwk::ApplicationInfo appInfo; + if (GetApplicationInfo(bundleName, + AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, userId, appInfo) != ERR_OK) { + BUNDLE_ACTIVE_LOGE("get applicationInfo failed."); + return false; + } + if (appInfo.isLauncherApp) { + luncherAppSet_.insert(bundleName); + return true; + } + isNotluncherAppSet_.insert(bundleName); + 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 06ad2e5..9d77a35 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::IsLauncherApp(event.bundleName_, userId)) { BUNDLE_ACTIVE_LOGI("launcher event, only update app group"); bundleGroupController_->ReportEvent(event, bootBasedTimeStamp, userId); return 0; -- Gitee From aff54b57e400042a4de3373bac33ea68757c7f56 Mon Sep 17 00:00:00 2001 From: fengyang Date: Mon, 29 Apr 2024 14:04:23 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BD=BF=E7=94=A8isLauncher=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E7=A1=AC=E7=BC=96=E7=A0=81Launcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- services/common/src/bundle_active_core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 9d77a35..0150d04 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -469,7 +469,7 @@ int32_t BundleActiveCore::ReportEvent(BundleActiveEvent& event, int32_t userId) } sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); - if (BundleActiveBundleMgrHelper::IsLauncherApp(event.bundleName_, userId)) { + if (BundleActiveBundleMgrHelper::GetInstance()->IsLauncherApp(event.bundleName_, userId)) { BUNDLE_ACTIVE_LOGI("launcher event, only update app group"); bundleGroupController_->ReportEvent(event, bootBasedTimeStamp, userId); return 0; -- Gitee From afc0e12e7db5d6c3955d28a9bc0551f4398fb011 Mon Sep 17 00:00:00 2001 From: fengyang Date: Mon, 29 Apr 2024 16:40:31 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81Launcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- services/common/src/bundle_active_bundle_mgr_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index 67ddb93..5b3ee64 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -110,7 +110,7 @@ bool BundleActiveBundleMgrHelper::IsLauncherApp(std::string bundleName, int32_t } AppExecFwk::ApplicationInfo appInfo; if (GetApplicationInfo(bundleName, - AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, userId, appInfo) != ERR_OK) { + AppExecFwk::BundleFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo) != ERR_OK) { BUNDLE_ACTIVE_LOGE("get applicationInfo failed."); return false; } -- Gitee From 81810707278d40fe160bae48e22968cb5f1b6d71 Mon Sep 17 00:00:00 2001 From: fengyang Date: Mon, 29 Apr 2024 18:44:03 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- services/common/src/bundle_active_bundle_mgr_helper.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index 5b3ee64..fefab2d 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" @@ -110,7 +111,7 @@ bool BundleActiveBundleMgrHelper::IsLauncherApp(std::string bundleName, int32_t } AppExecFwk::ApplicationInfo appInfo; if (GetApplicationInfo(bundleName, - AppExecFwk::BundleFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo) != ERR_OK) { + AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo) != ERR_OK) { BUNDLE_ACTIVE_LOGE("get applicationInfo failed."); return false; } -- Gitee From b90a271b078729c4ecced94251e29514eb2a4a64 Mon Sep 17 00:00:00 2001 From: fengyang Date: Mon, 29 Apr 2024 22:26:05 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- services/common/include/bundle_active_bundle_mgr_helper.h | 1 - services/common/src/bundle_active_bundle_mgr_helper.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/services/common/include/bundle_active_bundle_mgr_helper.h b/services/common/include/bundle_active_bundle_mgr_helper.h index 092cb26..89d5ce2 100644 --- a/services/common/include/bundle_active_bundle_mgr_helper.h +++ b/services/common/include/bundle_active_bundle_mgr_helper.h @@ -67,7 +67,6 @@ private: private: std::unordered_set luncherAppSet_; - std::unordered_set isNotluncherAppSet_; sptr bundleMgr_ = nullptr; std::mutex connectionMutex_; DECLARE_DELAYED_SINGLETON(BundleActiveBundleMgrHelper); diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index fefab2d..fdb9cbb 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -106,9 +106,6 @@ bool BundleActiveBundleMgrHelper::IsLauncherApp(std::string bundleName, int32_t if (luncherAppSet_.find(bundleName) != luncherAppSet_.end()) { return true; } - if (isNotluncherAppSet_.find(bundleName) != luncherAppSet_.end()) { - return false; - } AppExecFwk::ApplicationInfo appInfo; if (GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo) != ERR_OK) { @@ -119,7 +116,6 @@ bool BundleActiveBundleMgrHelper::IsLauncherApp(std::string bundleName, int32_t luncherAppSet_.insert(bundleName); return true; } - isNotluncherAppSet_.insert(bundleName); return false; } } // namespace DeviceUsageStats -- Gitee From a3ab7f4128c7f3f79fd4af3644779ef29253ad83 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 30 Apr 2024 12:56:27 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81launcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/common/include/bundle_active_bundle_mgr_helper.h | 2 +- services/common/src/bundle_active_bundle_mgr_helper.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/common/include/bundle_active_bundle_mgr_helper.h b/services/common/include/bundle_active_bundle_mgr_helper.h index 89d5ce2..056c6a8 100644 --- a/services/common/include/bundle_active_bundle_mgr_helper.h +++ b/services/common/include/bundle_active_bundle_mgr_helper.h @@ -60,7 +60,7 @@ public: bool GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag, const int userId, AppExecFwk::ApplicationInfo &appInfo); - bool IsLauncherApp(std::string bundleName, int32_t userId); + bool IsLauncherApp(const std::string &bundleName, int32_t userId); private: bool Connect(); diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index fdb9cbb..106d38c 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -101,7 +101,7 @@ bool BundleActiveBundleMgrHelper::Connect() return bundleMgr_ ? true : false; } -bool BundleActiveBundleMgrHelper::IsLauncherApp(std::string bundleName, int32_t userId) +bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, int32_t userId) { if (luncherAppSet_.find(bundleName) != luncherAppSet_.end()) { return true; -- Gitee From e626cbe2448f2df2ef692b6ba90ea9c5d6bab3be Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 30 Apr 2024 12:57:23 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81launcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- services/common/include/bundle_active_bundle_mgr_helper.h | 2 +- services/common/src/bundle_active_bundle_mgr_helper.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/common/include/bundle_active_bundle_mgr_helper.h b/services/common/include/bundle_active_bundle_mgr_helper.h index 056c6a8..e31675e 100644 --- a/services/common/include/bundle_active_bundle_mgr_helper.h +++ b/services/common/include/bundle_active_bundle_mgr_helper.h @@ -60,7 +60,7 @@ public: bool GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag, const int userId, AppExecFwk::ApplicationInfo &appInfo); - bool IsLauncherApp(const std::string &bundleName, int32_t userId); + bool IsLauncherApp(const std::string &bundleName, const int32_t userId); private: bool Connect(); diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index 106d38c..207b5ae 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -101,7 +101,7 @@ bool BundleActiveBundleMgrHelper::Connect() return bundleMgr_ ? true : false; } -bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, int32_t userId) +bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, const int32_t userId) { if (luncherAppSet_.find(bundleName) != luncherAppSet_.end()) { return true; -- Gitee From bdabb9b480b357b896837cfe4c5b797e1e88f092 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 30 Apr 2024 14:23:08 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- services/common/include/bundle_active_bundle_mgr_helper.h | 2 +- services/common/src/bundle_active_bundle_mgr_helper.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/common/include/bundle_active_bundle_mgr_helper.h b/services/common/include/bundle_active_bundle_mgr_helper.h index e31675e..5256a37 100644 --- a/services/common/include/bundle_active_bundle_mgr_helper.h +++ b/services/common/include/bundle_active_bundle_mgr_helper.h @@ -66,7 +66,7 @@ private: bool Connect(); private: - std::unordered_set luncherAppSet_; + std::unordered_set launcherAppSet_; sptr bundleMgr_ = nullptr; std::mutex connectionMutex_; DECLARE_DELAYED_SINGLETON(BundleActiveBundleMgrHelper); diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index 207b5ae..c85504d 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -103,7 +103,7 @@ bool BundleActiveBundleMgrHelper::Connect() bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, const int32_t userId) { - if (luncherAppSet_.find(bundleName) != luncherAppSet_.end()) { + if (launcherAppSet_.find(bundleName) != launcherAppSet_.end()) { return true; } AppExecFwk::ApplicationInfo appInfo; @@ -113,7 +113,7 @@ bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, c return false; } if (appInfo.isLauncherApp) { - luncherAppSet_.insert(bundleName); + launcherAppSet_.insert(bundleName); return true; } return false; -- Gitee