diff --git a/frameworks/src/bundle_state_init.cpp b/frameworks/src/bundle_state_init.cpp index c7604a7171e598423a33560a7315909a12419637..9e8d9171bebc162ca44c545217e79b2029b73fe3 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 ca0c2dd7bad71f5cd0f2d7803c27b48c4906ecac..fc604720db50f41b35608f400cbb87c733bc44c9 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 69de6e20edae7bfa4938f737aaebc88b5091f3ac..98f8516d90d5522fc7bc5f0aa4d1f4d724e2e636 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/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index afcd66689231809b1b602143a30c95ddf7146f1f..6187d85e29225a91ed97d709abbade838c441046 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 0aef910221dc9c5c378bdb23b3710761af52d77b..5e18960cb1b8a4e1518981e63737347d6751efa5 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 5805f0977273c67a3bd7dce9fdbb99bec11e3545..d68ee08de662dcf41b990ce8f6d88537edaf8488 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 93faaa276fdf8c86883f40470afbae44b4e93c05..177a13c3a4991be74e1fc4d15a5d2e18e188e3cd 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; diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 5f649f0be2019aa811e7b9ce78c45c9c8df71ce9..e13eff1ad8d48cde8f6ead805de7800b4cb6f2a0 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); } diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 0d3017bf6492cdca34aabd450fe83577097f41f6..46edec5d13f1eab09ae8d8b957c5a4cf529c8315 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