From bd3149ebca9c304412f5ff44aec3832a07e6eba1 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 12 Apr 2022 14:11:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9API=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=EF=BC=8CTDD=E7=94=A8=E4=BE=8BSR=20AR=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- frameworks/src/bundle_state_init.cpp | 2 +- .../bundlestats/js/@ohos.bundleState.d.ts | 4 ++-- .../device_usage_statistics_jsunit.test.js | 16 +++++++-------- .../unittest/device_usage_statistics_test.cpp | 20 ++++++++++++++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/frameworks/src/bundle_state_init.cpp b/frameworks/src/bundle_state_init.cpp index c7604a7..9e8d917 100644 --- a/frameworks/src/bundle_state_init.cpp +++ b/frameworks/src/bundle_state_init.cpp @@ -40,7 +40,7 @@ static napi_value BundleStateInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("queryBundleActiveStates", QueryBundleActiveStates), DECLARE_NAPI_FUNCTION("queryBundleStateInfoByInterval", QueryBundleStateInfoByInterval), DECLARE_NAPI_FUNCTION("queryBundleStateInfos", QueryBundleStateInfos), - DECLARE_NAPI_FUNCTION("getModuleUsageRecord", GetModuleUsageRecord) + DECLARE_NAPI_FUNCTION("getRecentUsageModules", GetModuleUsageRecord) }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index ca0c2dd..fc60472 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -341,8 +341,8 @@ declare namespace bundleState { * @param maxNum Indicates max record number in result, max is 1000. * @return Returns the {@link BundleActiveModuleInfo} object Array containing the state data of the current module. */ - function getModuleUsageRecord(maxNum: number, callback: AsyncCallback>): void; - function getModuleUsageRecord(maxNum: number): Promise>; + function getRecentUsageModules(maxNum: number, callback: AsyncCallback>): void; + function getRecentUsageModules(maxNum: number): Promise>; } export default bundleState; diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js index 69de6e2..98f8516 100644 --- a/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js +++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js @@ -332,19 +332,19 @@ describe("DeviceUsageStatisticsJsTest", function () { /* * @tc.name: DeviceUsageStatisticsJsTest013 - * @tc.desc: test getModuleUsageRecord callback. + * @tc.desc: test getRecentUsageModules callback. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GU2UE AR0003GU3EQ */ it("DeviceUsageStatisticsJsTest013", 0, async function (done) { console.info('----------------------DeviceUsageStatisticsJsTest013---------------------------'); let maxNum = 1; - bundleState.getModuleUsageRecord(maxNum, (err, res) => { + bundleState.getRecentUsageModules(maxNum, (err, res) => { if (err) { - console.info('BUNDLE_ACTIVE getModuleUsageRecord callback failure.'); + console.info('BUNDLE_ACTIVE getRecentUsageModules callback failure.'); expect(false).assertEqual(true); } else { - console.info('BUNDLE_ACTIVE getModuleUsageRecord callback success.'); + console.info('BUNDLE_ACTIVE getRecentUsageModules callback success.'); expect(true).assertEqual(true); } }); @@ -356,14 +356,14 @@ describe("DeviceUsageStatisticsJsTest", function () { /* * @tc.name: DeviceUsageStatisticsJsTest014 - * @tc.desc: test getModuleUsageRecord promise. + * @tc.desc: test getRecentUsageModules promise. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GU2UE AR0003GU3EQ */ it("DeviceUsageStatisticsJsTest014", 0, async function (done) { console.info('----------------------DeviceUsageStatisticsJsTest014---------------------------'); let maxNum = 1; - bundleState.getModuleUsageRecord(maxNum).then((res) => { + bundleState.getRecentUsageModules(maxNum).then((res) => { console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'); expect(true).assertEqual(true); }).catch((err) => { diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 0d3017b..46edec5 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -85,7 +85,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_GetServiceObject_0 * @tc.name: DeviceUsageStatisticsTest_ReportEvent_001 * @tc.desc: report a mock event * @tc.type: FUNC - * @tc.require: SR000GGTO7 AR000GH6PJ + * @tc.require: SR000GGTO7 SR000GU31B AR000GH6PJ AR000GU380 */ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_ReportEvent_001, Function | MediumTest | Level0) { @@ -159,6 +159,24 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackageGroup_ int result = BundleActiveClient::GetInstance().QueryPackageGroup(); EXPECT_EQ(result, -1); } + +/* + * @tc.name: DeviceUsageStatisticsTest_QueryFormStatistics_001 + * @tc.desc: QueryFormStatistics + * @tc.type: FUNC + * @tc.require: SR000GU2T1 AR000GU37U + */ +HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryFormStatistics_001, Function | MediumTest | Level0) +{ + int maxNum = 1; + BundleActiveEvent eventA(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, DEFAULT_FORM_NAME, + DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED); + BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID); + std::vector results; + int errCode = BundleActiveClient::GetInstance().QueryFormStatistics(maxNum, results, DEFAULT_USERID); + EXPECT_EQ(errCode, 0); + EXPECT_EQ(results.size(), 0); +} } // namespace DeviceUsageStats } // namespace OHOS -- Gitee From 18c890e3b7df9497e324efbc9a4f966c228bcfad Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 12 Apr 2022 18:28:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A1=A8=E5=9C=A8=E5=88=A0=E9=99=A4app?= =?UTF-8?q?=E5=90=8E=E6=9C=AA=E5=88=A0=E9=99=A4=E5=AF=B9=E5=BA=94app?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_usage_database.cpp | 1 - services/packagegroup/include/bundle_active_user_history.h | 2 ++ services/packagegroup/src/bundle_active_group_controller.cpp | 4 +++- services/packagegroup/src/bundle_active_user_history.cpp | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index afcd666..6187d85 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1352,7 +1352,6 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t void BundleActiveUsageDatabase::OnPackageUninstalled(const int userId, const string& bundleName) { - // 加入应用删除后删除卡片 lock_guard lock(databaseMutex_); for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { if (sortedTableArray_.at(i).empty()) { diff --git a/services/packagegroup/include/bundle_active_user_history.h b/services/packagegroup/include/bundle_active_user_history.h index 0aef910..5e18960 100644 --- a/services/packagegroup/include/bundle_active_user_history.h +++ b/services/packagegroup/include/bundle_active_user_history.h @@ -58,6 +58,8 @@ public: void PrintData(int userId); void UpdateBootBasedAndScreenTime(const bool& isScreenOn, const int64_t bootBasedTimeStamp, const bool& isShutdown = false); + void OnBundleUninstalled(const int userId, const std::string bundleName); + private: bool isScreenOn_; }; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 5805f09..d68ee08 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -94,12 +94,14 @@ void BundleActiveGroupController::SetHandlerAndCreateUserHistory( void BundleActiveGroupController::OnBundleUninstalled(const int userId, const std::string bundleName) { std::lock_guard lock(mutex_); + BUNDLE_ACTIVE_LOGI("OnBundleUninstalled called, userId is %{public}d, bundlename is %{public}s", + userId, bundleName.c_str()); auto oneUserHistory = bundleUserHistory_->GetUserHistory(userId, false); if (oneUserHistory == nullptr) { return; } oneUserHistory->erase(bundleName); - bundleUserHistory_->WriteBundleUsage(userId); + bundleUserHistory_->OnBundleUninstalled(userId, bundleName); } bool BundleActiveGroupController::GetBundleMgrProxy() diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 93faaa2..177a13c 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -51,6 +51,11 @@ void BundleActiveUserHistory::WriteBundleUsage(const int userId) database_.PutBundleHistoryData(userId, userHistory); } +void BundleActiveUserHistory::OnBundleUninstalled(const int userId, const std::string bundleName) +{ + database_.OnPackageUninstalled(userId, bundleName); +} + BundleActiveUserHistory::BundleActiveUserHistory(const int64_t bootBasedTimeStamp) { bootBasedTimeStamp_ = bootBasedTimeStamp; -- Gitee From 73e3aaf0c443abfe7d35800b0fe3e8b586ec7024 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 12 Apr 2022 18:35:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9C=AA=E5=88=A0=E9=99=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packageusage/src/bundle_active_user_service.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 5f649f0..e13eff1 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -66,6 +66,12 @@ void BundleActiveUserService::DeleteUninstalledBundleStats(const std::string& bu } } } + for (auto it : moduleRecords_) { + if (it.first.find(bundleName) != std::string::npos) { + moduleRecords_.erase(it.first); + break; + } + } database_.OnPackageUninstalled(userId_, bundleName); } -- Gitee