From 6e6765807ca85651583cef905462fc84a6d78215 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 19 Oct 2022 12:08:33 +0800 Subject: [PATCH 01/29] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=85=BC=E5=AE=B9bugfi?= =?UTF-8?q?x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- frameworks/src/bundle_state_common.cpp | 17 ++++++++++++----- frameworks/src/bundle_state_query.cpp | 4 ++-- frameworks/src/bundle_state_query_napi.cpp | 4 ++-- .../napi/include/bundle_state_common.h | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 12a2292..bd640e5 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -102,7 +102,7 @@ void BundleStateCommon::SetCallbackInfo( } void BundleStateCommon::GetBundleActiveEventForResult( - napi_env env, const std::vector &bundleActiveStates, napi_value result) + napi_env env, const std::vector &bundleActiveStates, napi_value result, bool isNewVersion) { int32_t index = 0; for (const auto &item : bundleActiveStates) { @@ -116,12 +116,19 @@ void BundleStateCommon::GetBundleActiveEventForResult( napi_value eventId = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.eventId_, &eventId)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); - + napi_value eventOccurredTime = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.timeStamp_, &eventOccurredTime)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", - eventOccurredTime)); + + if (isNewVersion) { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", + eventOccurredTime)); + } else { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateType", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateOccurredTime", + eventOccurredTime)); + } NAPI_CALL_RETURN_VOID(env, napi_set_element(env, result, index, bundleActiveState)); index++; diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 3506569..59f3ff1 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -317,7 +317,7 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -383,7 +383,7 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 9847228..433ec08 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -331,7 +331,7 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -386,7 +386,7 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index ab56949..56db22b 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -51,7 +51,7 @@ public: const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result); static void GetBundleActiveEventForResult( - napi_env env, const std::vector &BundleActiveState, napi_value result); + napi_env env, const std::vector &BundleActiveState, napi_value result, bool isNewVersion); static void GetBundleStateInfoByIntervalForResult( napi_env env, const std::vector &packageStats, napi_value result); -- Gitee From 1f801a401ebc6bfa559a30c4af7dbf0a64785a2d Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 19 Oct 2022 12:50:06 +0800 Subject: [PATCH 02/29] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=85=BC=E5=AE=B9bugfi?= =?UTF-8?q?x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- frameworks/src/bundle_state_common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index bd640e5..46b49e4 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -116,10 +116,10 @@ void BundleStateCommon::GetBundleActiveEventForResult( napi_value eventId = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.eventId_, &eventId)); - + napi_value eventOccurredTime = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.timeStamp_, &eventOccurredTime)); - + if (isNewVersion) { NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", -- Gitee From c24a27ea1259c0fc3e8c8dcd990d13904c464233 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 19 Oct 2022 14:15:32 +0800 Subject: [PATCH 03/29] =?UTF-8?q?bugfix=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- frameworks/src/bundle_state_query.cpp | 6 ++++-- frameworks/src/bundle_state_query_napi.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 59f3ff1..4e119aa 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -317,7 +317,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, false); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -383,7 +384,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, false); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 433ec08..cb7c1f5 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -331,7 +331,8 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, true); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -386,7 +387,8 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, true); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, -- Gitee From d0de54d8a5b33312027fac3375bccae4706a9d2d Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Thu, 20 Oct 2022 14:17:01 +0800 Subject: [PATCH 04/29] =?UTF-8?q?=E8=A1=A5=E5=85=85TDD=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=92=8CAPI=E7=89=88=E6=9C=AC=E5=85=BC=E5=AE=B9=E5=90=88?= =?UTF-8?q?=E5=85=A5monthly=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- frameworks/src/bundle_state_common.cpp | 15 +- frameworks/src/bundle_state_query.cpp | 6 +- frameworks/src/bundle_state_query_napi.cpp | 6 +- .../napi/include/bundle_state_common.h | 2 +- .../device_usage_statistics_jsunit.test.js | 713 ++++++++++++++++++ 5 files changed, 733 insertions(+), 9 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 12a2292..46b49e4 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -102,7 +102,7 @@ void BundleStateCommon::SetCallbackInfo( } void BundleStateCommon::GetBundleActiveEventForResult( - napi_env env, const std::vector &bundleActiveStates, napi_value result) + napi_env env, const std::vector &bundleActiveStates, napi_value result, bool isNewVersion) { int32_t index = 0; for (const auto &item : bundleActiveStates) { @@ -116,12 +116,19 @@ void BundleStateCommon::GetBundleActiveEventForResult( napi_value eventId = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.eventId_, &eventId)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); napi_value eventOccurredTime = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.timeStamp_, &eventOccurredTime)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", - eventOccurredTime)); + + if (isNewVersion) { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", + eventOccurredTime)); + } else { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateType", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateOccurredTime", + eventOccurredTime)); + } NAPI_CALL_RETURN_VOID(env, napi_set_element(env, result, index, bundleActiveState)); index++; diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 3506569..4e119aa 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -317,7 +317,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -383,7 +384,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 9847228..cb7c1f5 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -331,7 +331,8 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -386,7 +387,8 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index ab56949..56db22b 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -51,7 +51,7 @@ public: const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result); static void GetBundleActiveEventForResult( - napi_env env, const std::vector &BundleActiveState, napi_value result); + napi_env env, const std::vector &BundleActiveState, napi_value result, bool isNewVersion); static void GetBundleStateInfoByIntervalForResult( napi_env env, const std::vector &packageStats, napi_value result); 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 9cf9235..fac99b8 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 @@ -14,6 +14,7 @@ */ import bundleState from '@ohos.bundleState' +import usageStatistics from '@ohos.resourceschedule.usageStatistics' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -305,5 +306,717 @@ describe("DeviceUsageStatisticsJsTest", function () { } }); }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest013 + * @tc.desc: test isIdleState callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest013", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest013---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + try{ + usageStatistics.isIdleState(bundleName, (err, res) => { + if (err) { + console.info('BUNDLE_ACTIVE isIdleState callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE isIdleState callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch(error) { + console.info('BUNDLE_ACTIVE isIdleState callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest014 + * @tc.desc: test isIdleState promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest014", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest014---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + try{ + usageStatistics.isIdleState(bundleName).then((res) => { + console.info('BUNDLE_ACTIVE isIdleState promise success.'); + expect(true).assertEqual(true); + done(); + }).catch((err) => { + console.info('BUNDLE_ACTIVE isIdleState promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE isIdleState promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest015 + * @tc.desc: test queryAppGroup callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest015", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest015---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + try{ + usageStatistics.queryAppGroup(bundleName, (err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE queryAppGroup callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryAppGroup callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryAppGroup callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest016 + * @tc.desc: test queryAppGroup promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest016", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest016---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + try{ + usageStatistics.queryAppGroup(bundleName).then( res => { + console.info('BUNDLE_ACTIVE queryAppGroup promise success.'); + expect(true).assertEqual(true); + done(); + }).catch( err => { + console.info('BUNDLE_ACTIVE queryAppGroup promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryAppGroup promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest017 + * @tc.desc: test queryAppGroup callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest017", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest017---------------------------'); + try{ + usageStatistics.queryAppGroup((err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE queryAppGroup callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryAppGroup callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryAppGroup callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest018 + * @tc.desc: test queryAppGroup promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest018", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest018---------------------------'); + try{ + usageStatistics.queryAppGroup().then( res => { + console.info('BUNDLE_ACTIVE queryAppGroup promise success.'); + expect(true).assertEqual(true); + done(); + }).catch( err => { + console.info('BUNDLE_ACTIVE queryAppGroup promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryAppGroup promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest019 + * @tc.desc: test queryBundleStatsInfos callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest019", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest019---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try { + usageStatistics.queryBundleStatsInfos(beginTime, endTime, (err, res) => { + if (err) { + console.info('BUNDLE_ACTIVE queryBundleStatsInfos callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryBundleStatsInfos callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryBundleStatsInfos callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest020 + * @tc.desc: test queryBundleStatsInfos promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest020", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest020---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryBundleStatsInfos(beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryBundleStatsInfos promise success.'); + expect(true).assertEqual(true); + done(); + }).catch((err) => { + console.info('BUNDLE_ACTIVE queryBundleStatsInfos promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryBundleStatsInfos promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest021 + * @tc.desc: test queryBundleStatsInfoByInterval callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest021", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest021---------------------------'); + let intervalType = 0; + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryBundleStatsInfoByInterval(intervalType, beginTime, endTime, (err, res) => { + if (err) { + console.info('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest022 + * @tc.desc: test queryBundleStatsInfoByInterval promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest022", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest022---------------------------'); + let intervalType = 0; + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryBundleStatsInfoByInterval(intervalType, beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.'); + expect(true).assertEqual(true); + done(); + }).catch((err) => { + console.info('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest023 + * @tc.desc: test queryBundleEvents callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest023", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest023---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryBundleEvents(beginTime, endTime, (err, res) => { + if (err) { + console.info('BUNDLE_ACTIVE queryBundleEvents callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryBundleEvents callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryBundleEvents callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest024 + * @tc.desc: test queryBundleEvents promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest024", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest024---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryBundleEvents(beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryBundleEvents promise success.'); + expect(true).assertEqual(true); + done(); + }).catch((err) => { + console.info('BUNDLE_ACTIVE queryBundleEvents promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryBundleEvents promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest025 + * @tc.desc: test queryCurrentBundleEvents callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest025", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest025---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryCurrentBundleEvents(beginTime, endTime, (err, res) => { + if (err) { + console.info('BUNDLE_ACTIVE queryCurrentBundleEvents callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryCurrentBundleEvents callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest026 + * @tc.desc: test queryCurrentBundleEvents promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest026", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest026---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryCurrentBundleEvents(beginTime, endTime).then((res) => { + console.info('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.'); + expect(true).assertEqual(true); + done(); + }).catch((err) => { + console.info('BUNDLE_ACTIVE queryCurrentBundleEvents promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryCurrentBundleEvents promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest027 + * @tc.desc: test queryModuleUsageRecords callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest027", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest027---------------------------'); + let maxNum = 1; + try{ + usageStatistics.queryModuleUsageRecords(maxNum, (err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest028 + * @tc.desc: test queryModuleUsageRecords promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest028", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest028---------------------------'); + let maxNum = 1; + try{ + usageStatistics.queryModuleUsageRecords(maxNum).then( res => { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords promise success.'); + expect(true).assertEqual(true); + done(); + }).catch( err=> { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest029 + * @tc.desc: test queryModuleUsageRecords callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest029", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest029---------------------------'); + try{ + usageStatistics.queryModuleUsageRecords((err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest030 + * @tc.desc: test queryModuleUsageRecords promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest030", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest030---------------------------'); + try{ + usageStatistics.queryModuleUsageRecords().then( res => { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords promise success.'); + expect(true).assertEqual(true); + done(); + }).catch( err=> { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryModuleUsageRecords promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest031 + * @tc.desc: test setAppGroup callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest031", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest031---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + let newGroup = 30; + try{ + usageStatistics.setAppGroup(bundleName, newGroup, (err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE setAppGroup callback failure.'); + expect(true).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE setAppGroup callback success.'); + expect(false).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE setAppGroup callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest032 + * @tc.desc: test setAppGroup promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest032", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest032---------------------------'); + let bundleName = 'com.example.deviceUsageStatistics'; + let newGroup = 30; + try{ + usageStatistics.setAppGroup(bundleName, newGroup).then( res => { + console.info('BUNDLE_ACTIVE setAppGroup promise success.'); + expect(false).assertEqual(true); + done(); + }).catch( err => { + console.info('BUNDLE_ACTIVE setAppGroup promise failure.'); + expect(true).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE setAppGroup promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest033 + * @tc.desc: test unRegisterAppGroupCallBack callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest033", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest033---------------------------'); + try{ + usageStatistics.unRegisterAppGroupCallBack((err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack callback success.'); + expect(false).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack callback throw error.'); + expect(true).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest034 + * @tc.desc: test unRegisterAppGroupCallBack promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest034", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest034---------------------------'); + try{ + usageStatistics.unRegisterAppGroupCallBack().then( (res) => { + console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack promise success.'); + expect(false).assertEqual(true); + done(); + }).catch( err => { + console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack promise throw error.'); + expect(true).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest035 + * @tc.desc: test queryDeviceEventStats callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest035", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest035---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryDeviceEventStats(beginTime, endTime, (err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE queryDeviceEventStats callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryDeviceEventStats callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryDeviceEventStats callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest036 + * @tc.desc: test queryDeviceEventStats promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest036", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest036---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryDeviceEventStats(beginTime, endTime).then( res => { + console.info('BUNDLE_ACTIVE queryDeviceEventStats promise success.'); + expect(true).assertEqual(true); + done(); + }).catch( err=> { + console.info('BUNDLE_ACTIVE queryDeviceEventStats promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryDeviceEventStats promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest037 + * @tc.desc: test queryNotificationEventStats callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest037", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest037---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryNotificationEventStats(beginTime, endTime, (err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE queryNotificationEventStats callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE queryNotificationEventStats callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryNotificationEventStats callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest038 + * @tc.desc: test queryNotificationEventStats promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest038", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest038---------------------------'); + let beginTime = 0; + let endTime = 20000000000000; + try{ + usageStatistics.queryNotificationEventStats(beginTime, endTime).then( res => { + console.info('BUNDLE_ACTIVE queryNotificationEventStats promise success.'); + expect(true).assertEqual(true); + done(); + }).catch( err => { + console.info('BUNDLE_ACTIVE queryNotificationEventStats promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE queryNotificationEventStats promise throw error.'); + expect(false).assertEqual(true); + done(); + } + }) }) -- Gitee From 00ce78b71563ea8a979baed6c747f20721dfb395 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Fri, 21 Oct 2022 17:48:47 +0800 Subject: [PATCH 05/29] =?UTF-8?q?cppcheck=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../src/bundle_active_app_group_napi.cpp | 30 +++++++++---------- frameworks/src/bundle_state_query.cpp | 6 ++-- frameworks/src/bundle_state_query_napi.cpp | 6 ++-- .../innerkits/src/bundle_active_proxy.cpp | 3 +- services/common/src/bundle_active_core.cpp | 3 -- services/common/src/bundle_active_service.cpp | 6 ++-- .../src/bundle_active_usage_database.cpp | 6 ++-- .../src/bundle_active_group_handler.cpp | 6 ++-- .../src/bundle_active_user_service.cpp | 2 +- 9 files changed, 30 insertions(+), 38 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index f062222..9158974 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -84,15 +84,13 @@ napi_value ParseQueryAppGroupParameters(const napi_env &env, const napi_callback return BundleStateCommon::HandleParamErr(env, ERR_PARAMETERS_EMPTY, "bundleName"); } // argv[1]: callback - if (argc == PRIORITY_GROUP_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - if (valuetype != napi_function) { - params.errorCode = ERR_CALL_BACK_TYPE; - return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); - } - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + if (inputValueType != napi_function) { + params.errorCode = ERR_CALL_BACK_TYPE; + return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } + napi_create_reference(env, argv[1], 1, ¶ms.callback); } BundleStateCommon::AsyncInit(env, params, asyncCallbackInfo); return BundleStateCommon::NapiGetNull(env); @@ -195,9 +193,9 @@ napi_value ParseSetAppGroupParameters(const napi_env &env, const napi_callback_i } // argv[SECOND_ARG]: callback if (argc == APP_USAGE_PARAMS_BUNDLE_GROUP) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[SECOND_ARG], &valuetype)); - if (valuetype != napi_function) { + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[SECOND_ARG], &inputValueType)); + if (inputValueType != napi_function) { params.errorCode = ERR_CALL_BACK_TYPE; return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } @@ -259,7 +257,7 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) napi_value GetAppGroupChangeCallback(const napi_env &env, const napi_value &value) { napi_ref result = nullptr; - + registerObserver = new (std::nothrow) AppGroupObserver(); if (!registerObserver) { BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack callback is null"); @@ -281,7 +279,7 @@ napi_value ParseRegisterAppGroupCallBackParameters(const napi_env &env, const na params.errorCode = ERR_PARAMETERS_NUMBER; return BundleStateCommon::HandleParamErr(env, ERR_PARAMETERS_NUMBER, ""); } - + // arg[0] : callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); @@ -298,9 +296,9 @@ napi_value ParseRegisterAppGroupCallBackParameters(const napi_env &env, const na // argv[1]: asyncCallback if (argc == REGISTER_GROUP_CALLBACK_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - if (valuetype != napi_function) { + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + if (inputValueType != napi_function) { params.errorCode = ERR_CALL_BACK_TYPE; return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 4e119aa..edb88d8 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -63,9 +63,9 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i // argv[1]: callback if (argc == IS_IDLE_STATE_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + NAPI_ASSERT(env, inputValueType == napi_function, "ParseIsIdleStateParameters invalid parameter type, function expected."); napi_create_reference(env, argv[1], 1, ¶ms.callback); } diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index cb7c1f5..e7e775d 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -183,9 +183,9 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i // argv[1]: callback if (argc == IS_IDLE_STATE_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - if (valuetype != napi_function) { + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + if (inputValueType != napi_function) { params.errorCode = ERR_CALL_BACK_TYPE; return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index ae545d5..4b01289 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -134,7 +134,6 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfos(std::vector result; if (!data.WriteInterfaceToken(GetDescriptor())) { return ERR_PARCEL_WRITE_FALIED; } @@ -204,7 +203,7 @@ ErrCode BundleActiveProxy::QueryAppGroup(int32_t& appGroup, std::string& bundleN if (!data.WriteInterfaceToken(GetDescriptor())) { return ERR_PARCEL_WRITE_FALIED; } - + data.WriteString(bundleName); data.WriteInt32(userId); Remote() -> SendRequest(QUERY_APP_GROUP, data, reply, option); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index d872af4..6f878ee 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -225,9 +225,6 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial BUNDLE_ACTIVE_LOGI("first initialize user service"); std::shared_ptr service = std::make_shared(userId, *this, debug); - if (service == nullptr) { - return nullptr; - } service->Init(timeStamp); userStatServices_[userId] = service; BUNDLE_ACTIVE_LOGI("service is not null"); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 1b8ff5c..30c43f0 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -36,7 +36,6 @@ static const std::string PERMITTED_PROCESS_NAME = "foundation"; static const int32_t MAXNUM_UP_LIMIT = 1000; const int32_t EVENTS_PARAM = 5; static constexpr int32_t NO_DUMP_PARAM_NUMS = 0; -static constexpr int32_t MIN_DUMP_PARAM_NUMS = 1; const int32_t PACKAGE_USAGE_PARAM = 6; const int32_t MODULE_USAGE_PARAM = 4; const std::string NEEDED_PERMISSION = "ohos.permission.BUNDLE_ACTIVE_INFO"; @@ -320,7 +319,6 @@ ErrCode BundleActiveService::QueryBundleStatsInfoByInterval(std::vector& bundleActiveEvents, const int64_t beginTime, const int64_t endTime, int32_t userId) { - std::vector result; ErrCode ret = ERR_OK; int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); @@ -334,7 +332,7 @@ ErrCode BundleActiveService::QueryBundleEvents(std::vector& b ret = CheckSystemAppOrNativePermission(callingUid, tokenId); if (ret == ERR_OK) { ret = bundleActiveCore_->QueryBundleEvents(bundleActiveEvents, userId, beginTime, endTime, ""); - BUNDLE_ACTIVE_LOGI("QueryBundleEvents result is %{public}zu", result.size()); + BUNDLE_ACTIVE_LOGI("QueryBundleEvents result is %{public}zu", bundleActiveEvents.size()); } return ret; } @@ -682,7 +680,7 @@ int32_t BundleActiveService::Dump(int32_t fd, const std::vector int32_t ret = ERR_OK; if (argsInStr.size() == NO_DUMP_PARAM_NUMS) { DumpUsage(result); - } else if (argsInStr.size() >= MIN_DUMP_PARAM_NUMS) { + } else if { std::vector infos; if (argsInStr[0] == "-h") { DumpUsage(result); diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index ce3d393..8fe7773 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -237,12 +237,12 @@ void BundleActiveUsageDatabase::HandleTableInfo(uint32_t databaseType) } int32_t tableNameIndex; bundleActiveResult->GetColumnIndex(SQLITE_MASTER_NAME, tableNameIndex); - string tableName; if (databaseType >= 0 && databaseType < sortedTableArray_.size()) { if (!sortedTableArray_.at(databaseType).empty()) { sortedTableArray_.at(databaseType).clear(); } for (int32_t i = 0; i < tableNumber; i++) { + string tableName; bundleActiveResult->GoToRow(i); bundleActiveResult->GetString(tableNameIndex, tableName); sortedTableArray_.at(databaseType).push_back(ParseStartTime(tableName)); @@ -434,8 +434,8 @@ shared_ptr BundleActiveUsageDatabase::GetBundleActiveRdbSto void BundleActiveUsageDatabase::CheckDatabaseFile(uint32_t databaseType) { std::string databaseFileName = databaseFiles_.at(databaseType); - std::string dbFile; for (uint32_t i = 0; i < sizeof(SUFFIX_TYPE) / sizeof(SUFFIX_TYPE[0]); i++) { + std::string dbFile; dbFile = BUNDLE_ACTIVE_DATABASE_DIR + DATABASE_TYPE[databaseType] + SUFFIX_TYPE[i]; if ((access(dbFile.c_str(), F_OK) != 0) && (bundleActiveRdbStoreCache_.find(databaseFileName) != bundleActiveRdbStoreCache_.end())) { @@ -1511,8 +1511,8 @@ void BundleActiveUsageDatabase::RemoveFormData(const int32_t userId, const std:: return; } int32_t deletedRows = BUNDLE_ACTIVE_FAIL; - vector queryCondition; if (formRecordsTableName_ != UNKNOWN_TABLE_NAME) { + vector queryCondition; queryCondition.emplace_back(to_string(userId)); queryCondition.emplace_back(bundleName); queryCondition.emplace_back(moduleName); diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index 6c6ec42..fd897f7 100644 --- a/services/packagegroup/src/bundle_active_group_handler.cpp +++ b/services/packagegroup/src/bundle_active_group_handler.cpp @@ -75,13 +75,13 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe BUNDLE_ACTIVE_LOGI("query activated account failed"); return; } + if (activatedOsAccountIds.size() == 0) { + return; + } #else // OS_ACCOUNT_PART_ENABLED activatedOsAccountIds.push_back(DEFAULT_OS_ACCOUNT_ID); BUNDLE_ACTIVE_LOGI("os account part not enabled, use default id."); #endif // OS_ACCOUNT_PART_ENABLED - if (activatedOsAccountIds.size() == 0) { - return; - } for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) { bundleActiveGroupController_->CheckEachBundleState(activatedOsAccountIds[i]); bundleActiveGroupController_->RestoreToDatabase(activatedOsAccountIds[i]); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index d2dfaea..e7c0420 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -340,7 +340,7 @@ ErrCode BundleActiveUserService::QueryBundleStatsInfos(std::vectorendTime_ != 0 && endTime > currentStats->beginTime_) { + if (endTime > currentStats->beginTime_) { BUNDLE_ACTIVE_LOGI("QueryBundleStatsInfos need in memory stats"); for (auto it : currentStats->bundleStats_) { if (bundleName.empty()) { -- Gitee From 3aabc9f3899e1ac4f8a0e56af1cd429b99d24467 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Fri, 21 Oct 2022 18:03:37 +0800 Subject: [PATCH 06/29] =?UTF-8?q?cppcheck=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 30c43f0..a0b5048 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -680,7 +680,7 @@ int32_t BundleActiveService::Dump(int32_t fd, const std::vector int32_t ret = ERR_OK; if (argsInStr.size() == NO_DUMP_PARAM_NUMS) { DumpUsage(result); - } else if { + } else { std::vector infos; if (argsInStr[0] == "-h") { DumpUsage(result); -- Gitee From a6992b939e409f8aa929f23a4449e7032e3aa5db Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Sat, 22 Oct 2022 18:16:52 +0800 Subject: [PATCH 07/29] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=85=BC=E5=AE=B9bugfi?= =?UTF-8?q?x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- frameworks/src/bundle_state_common.cpp | 8 ++++---- frameworks/src/bundle_state_query.cpp | 6 ++++-- frameworks/src/bundle_state_query_napi.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index bd640e5..5c486ca 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -116,10 +116,10 @@ void BundleStateCommon::GetBundleActiveEventForResult( napi_value eventId = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.eventId_, &eventId)); - + napi_value eventOccurredTime = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.timeStamp_, &eventOccurredTime)); - + if (isNewVersion) { NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", @@ -366,8 +366,8 @@ napi_value BundleStateCommon::GetErrorValue(napi_env env, int32_t errCode) NAPI_CALL(env, napi_create_int32(env, reflectCode, &eCode)); NAPI_CALL(env, napi_create_string_utf8(env, errMsg.c_str(), errMsg.length(), &eMsg)); NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_set_named_property(env, result, "errCode", eCode)); - NAPI_CALL(env, napi_set_named_property(env, result, "errMessage", eMsg)); + NAPI_CALL(env, napi_set_named_property(env, result, "code", eCode)); + NAPI_CALL(env, napi_set_named_property(env, result, "message", eMsg)); return result; } diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 59f3ff1..4e119aa 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -317,7 +317,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, false); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -383,7 +384,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, false); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 433ec08..cb7c1f5 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -331,7 +331,8 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, true); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -386,7 +387,8 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result, true); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, -- Gitee From 0b2c01a72a1d9fe58fa9ae00b48939549853a69d Mon Sep 17 00:00:00 2001 From: houdisheng Date: Mon, 24 Oct 2022 09:07:11 +0800 Subject: [PATCH 08/29] =?UTF-8?q?cppcheck=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= 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 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 8fe7773..9593b62 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -435,8 +435,7 @@ void BundleActiveUsageDatabase::CheckDatabaseFile(uint32_t databaseType) { std::string databaseFileName = databaseFiles_.at(databaseType); for (uint32_t i = 0; i < sizeof(SUFFIX_TYPE) / sizeof(SUFFIX_TYPE[0]); i++) { - std::string dbFile; - dbFile = BUNDLE_ACTIVE_DATABASE_DIR + DATABASE_TYPE[databaseType] + SUFFIX_TYPE[i]; + std::string dbFile = BUNDLE_ACTIVE_DATABASE_DIR + DATABASE_TYPE[databaseType] + SUFFIX_TYPE[i]; if ((access(dbFile.c_str(), F_OK) != 0) && (bundleActiveRdbStoreCache_.find(databaseFileName) != bundleActiveRdbStoreCache_.end())) { bundleActiveRdbStoreCache_.erase(databaseFileName); -- Gitee From 239837bdff2d3602466aec371d6fe23e84bebb4b Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 25 Oct 2022 15:24:34 +0800 Subject: [PATCH 09/29] =?UTF-8?q?=E6=8F=90=E5=8D=87device=5Fusage=E4=BB=93?= =?UTF-8?q?=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/src/bundle_active_core.cpp | 40 +++++++++++++------ services/common/src/bundle_active_service.cpp | 3 +- .../include/bundle_active_group_controller.h | 2 +- .../src/bundle_active_group_controller.cpp | 38 +++++------------- .../unittest/device_usage_statistics_test.cpp | 19 +++++++-- 5 files changed, 56 insertions(+), 46 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index d872af4..f325fd0 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -753,36 +753,43 @@ ErrCode BundleActiveCore::UnRegisterAppGroupCallBack(const AccessToken::AccessTo void BundleActiveCore::AddObserverDeathRecipient(const sptr &observer) { std::lock_guard lock(deathRecipientMutex_); - if (!observer || !(observer->AsObject())) { + if (!observer) { BUNDLE_ACTIVE_LOGI("observer nullptr."); return; } + auto object = observer->AsObject(); + if (!object) { + BUNDLE_ACTIVE_LOGI("observer->AsObject() nullptr."); + return; + } auto it = recipientMap_.find(observer->AsObject()); if (it != recipientMap_.end()) { BUNDLE_ACTIVE_LOGI("This death recipient has been added."); return; - } else { - sptr deathRecipient = new (std::nothrow) RemoteDeathRecipient( - [this](const wptr &remote) { this->OnObserverDied(remote); }); - if (!deathRecipient) { - BUNDLE_ACTIVE_LOGI("create death recipient failed"); - return ; - } - observer->AsObject()->AddDeathRecipient(deathRecipient); - recipientMap_.emplace(observer->AsObject(), deathRecipient); } + sptr deathRecipient = new (std::nothrow) RemoteDeathRecipient( + [this](const wptr &remote) { this->OnObserverDied(remote); }); + if (!deathRecipient) { + BUNDLE_ACTIVE_LOGI("create death recipient failed"); + return ; + } + observer->AsObject()->AddDeathRecipient(deathRecipient); + recipientMap_.emplace(observer->AsObject(), deathRecipient); } void BundleActiveCore::RemoveObserverDeathRecipient(const sptr &observer) { std::lock_guard lock(deathRecipientMutex_); - if (!observer || !(observer->AsObject())) { + if (!observer) { + return; + } + auto object = observer->AsObject(); + if (!object) { return ; } auto iter = recipientMap_.find(observer->AsObject()); if (iter != recipientMap_.end()) { iter->first->RemoveDeathRecipient(iter->second); recipientMap_.erase(iter); - return ; } } @@ -805,7 +812,14 @@ void BundleActiveCore::OnObserverDiedInner(const wptr &remote) return; } for (const auto& item : groupChangeObservers_) { - if ((item.second) && ((item.second)->AsObject()) && ((item.second)->AsObject() == objectProxy)) { + if (!(item.second)) { + continue; + } + auto object = (item.second)->AsObject(); + if (!object) { + continue; + } + if (object == objectProxy) { groupChangeObservers_.erase(item.first); break; } diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 1b8ff5c..dbab5d0 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -627,7 +627,8 @@ ErrCode BundleActiveService::QueryNotificationEventStats(int64_t beginTime, int6 void BundleActiveService::QueryModuleRecordInfos(BundleActiveModuleRecord& moduleRecord) { - if (!GetBundleMgrProxy()) { + ErrCode errCode = GetBundleMgrProxy(); + if (errCode != ERR_OK) { return; } ApplicationInfo appInfo; diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index dbbd6db..f3da156 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -79,11 +79,11 @@ private: std::mutex mutex_; bool GetBundleMgrProxy(); std::weak_ptr activeGroupHandler_; - uint32_t EventToGroupReason(const int32_t eventId); int64_t timeoutForDirectlyUse_; int64_t timeoutForNotifySeen_; int64_t timeoutForSystemInteraction_; int64_t timeoutCalculated_ = 0; + std::map eventIdMatchReason_; sptr sptrBundleMgr_; bool calculationTimeOut(const std::shared_ptr& oneBundleHistory, const int64_t bootBasedTimeStamp); diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index aceddcd..d096cd9 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -38,6 +38,14 @@ BundleActiveGroupController::BundleActiveGroupController(const bool debug) screenTimeLevel_ = {0, 0, debug ? TWO_MINUTE : ONE_HOUR, debug ? FOUR_MINUTE : TWO_HOUR}; bootTimeLevel_ = {0, debug ? TWO_MINUTE : TWELVE_HOUR, debug ? FOUR_MINUTE : TWENTY_FOUR_HOUR, debug ? SIXTEEN_MINUTE : FOURTY_EIGHT_HOUR}; + eventIdMatchReason_ = { + {BundleActiveEvent::ABILITY_FOREGROUND, GROUP_EVENT_REASON_FOREGROUND}, + {BundleActiveEvent::ABILITY_BACKGROUND, GROUP_EVENT_REASON_BACKGROUND}, + {BundleActiveEvent::SYSTEM_INTERACTIVE, GROUP_EVENT_REASON_SYSTEM}, + {BundleActiveEvent::USER_INTERACTIVE, GROUP_EVENT_REASON_USER_INTERACTION}, + {BundleActiveEvent::NOTIFICATION_SEEN, GROUP_EVENT_REASON_NOTIFY_SEEN}, + {BundleActiveEvent::LONG_TIME_TASK_STARTTED, GROUP_EVENT_REASON_LONG_TIME_TASK_STARTTED}, + }; } void BundleActiveGroupController::RestoreDurationToDatabase() @@ -195,26 +203,6 @@ bool BundleActiveGroupController::calculationTimeOut( - lastGroupCalculatedTimeStamp > timeoutCalculated_; } -uint32_t BundleActiveGroupController::EventToGroupReason(const int32_t eventId) -{ - switch (eventId) { - case BundleActiveEvent::ABILITY_FOREGROUND: - return GROUP_EVENT_REASON_FOREGROUND; - case BundleActiveEvent::ABILITY_BACKGROUND: - return GROUP_EVENT_REASON_BACKGROUND; - case BundleActiveEvent::SYSTEM_INTERACTIVE: - return GROUP_EVENT_REASON_SYSTEM; - case BundleActiveEvent::USER_INTERACTIVE: - return GROUP_EVENT_REASON_USER_INTERACTION; - case BundleActiveEvent::NOTIFICATION_SEEN: - return GROUP_EVENT_REASON_NOTIFY_SEEN; - case BundleActiveEvent::LONG_TIME_TASK_STARTTED: - return GROUP_EVENT_REASON_LONG_TIME_TASK_STARTTED; - default: - return 0; - } -} - void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, const int64_t bootBasedTimeStamp, const int32_t userId) { @@ -227,19 +215,15 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co return; } int32_t eventId = event.eventId_; - if (eventId == BundleActiveEvent::ABILITY_FOREGROUND || - eventId == BundleActiveEvent::ABILITY_BACKGROUND || - eventId == BundleActiveEvent::SYSTEM_INTERACTIVE || - eventId == BundleActiveEvent::USER_INTERACTIVE || - eventId == BundleActiveEvent::NOTIFICATION_SEEN || - eventId == BundleActiveEvent::LONG_TIME_TASK_STARTTED) { + auto item = eventIdMatchReason_.find(eventId); + if (item != eventIdMatchReason_.end()) { std::shared_ptr bundleUsageHistory = bundleUserHistory_->GetUsageHistoryForBundle( event.bundleName_, userId, bootBasedTimeStamp, true); if (bundleUsageHistory == nullptr) { return; } int64_t timeUntilNextCheck; - uint32_t eventReason = EventToGroupReason(eventId); + uint32_t eventReason = item->second; switch (eventId) { case BundleActiveEvent::NOTIFICATION_SEEN: bundleUserHistory_->ReportUsage(bundleUsageHistory, event.bundleName_, ACTIVE_GROUP_DAILY, diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 9a4c4ad..c7d6f12 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -185,6 +185,16 @@ HWTEST_F(DeviceUsageStatisticsTest, int32_t errCode = BundleActiveClient::GetInstance().QueryModuleUsageRecords(maxNum, results, DEFAULT_USERID); EXPECT_EQ(errCode, 0); EXPECT_EQ(results.size(), 0); + + results.clear(); + maxNum = 0; + errCode = BundleActiveClient::GetInstance().QueryModuleUsageRecords(maxNum, results, DEFAULT_USERID); + EXPECT_NE(errCode, 0); + + results.clear(); + maxNum = 1001; + errCode = BundleActiveClient::GetInstance().QueryModuleUsageRecords(maxNum, results, DEFAULT_USERID); + EXPECT_NE(errCode, 0); } /* @@ -218,6 +228,9 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_SetAppGroup_001, F DEFAULT_GROUP = (result == DEFAULT_GROUP) ? (result + 10) : DEFAULT_GROUP; result = BundleActiveClient::GetInstance().SetAppGroup(g_defaultBundleName, DEFAULT_GROUP, COMMON_USERID); EXPECT_EQ(result, DEFAULT_ERRCODE); + + result = BundleActiveClient::GetInstance().SetAppGroup(g_defaultBundleName, DEFAULT_GROUP, -1); + EXPECT_NE(result, DEFAULT_ERRCODE); } /* @@ -293,8 +306,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryNotificationE * @tc.type: FUNC * @tc.require: SR000H0G4F AR000H2US8 */ -HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveGroupMap_001, Function - | MediumTest | Level0) +HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveGroupMap_001, Function | MediumTest | Level0) { int64_t minInterval = DeviceUsageStatsGroupMap::groupIntervalMap_ .at(DeviceUsageStatsGroupConst::ACTIVE_GROUP_FORCED_SET); @@ -319,8 +331,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveGroupM * @tc.type: FUNC * @tc.require: issuesI5SOZY */ -HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_DeathRecipient_001, Function - | MediumTest | Level0) +HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_DeathRecipient_001, Function | MediumTest | Level0) { auto deathTest = std::make_shared(); EXPECT_TRUE(deathTest!=nullptr); -- Gitee From 80686c7d0f9f546f8be9b0fb9b0529c6a1d6b233 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 25 Oct 2022 20:26:58 +0800 Subject: [PATCH 10/29] =?UTF-8?q?js=E7=9A=84=E6=B3=A8=E5=86=8C=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=88=86=E7=BB=84=E7=9B=91=E5=90=AC=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../src/bundle_active_app_group_napi.cpp | 5 +- .../device_usage_statistics_jsunit.test.js | 114 ++++++++++++++---- 2 files changed, 93 insertions(+), 26 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index f062222..ba4b201 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -340,8 +340,8 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { AsyncRegisterCallbackInfo *asyncCallbackInfo = (AsyncRegisterCallbackInfo *)data; if (asyncCallbackInfo) { - std::lock_guard lock(g_observerMutex_); if (asyncCallbackInfo->errorCode != ERR_OK) { + std::lock_guard lock(g_observerMutex_); registerObserver = nullptr; } napi_value result = nullptr; @@ -372,7 +372,6 @@ napi_value ParseUnRegisterAppGroupCallBackParameters(const napi_env &env, const return BundleStateCommon::HandleParamErr(env, ERR_PARAMETERS_NUMBER, ""); } - // argv[1]: callback if (argc == UN_REGISTER_GROUP_CALLBACK_PARAMS) { napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); @@ -421,8 +420,8 @@ napi_value UnRegisterAppGroupCallBack(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { AsyncUnRegisterCallbackInfo *asyncCallbackInfo = (AsyncUnRegisterCallbackInfo *)data; if (asyncCallbackInfo != nullptr) { - std::lock_guard lock(g_observerMutex_); if (asyncCallbackInfo->errorCode == ERR_OK) { + std::lock_guard lock(g_observerMutex_); registerObserver = nullptr; } napi_value result = nullptr; 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 fac99b8..d9bc3b7 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 @@ -857,51 +857,67 @@ describe("DeviceUsageStatisticsJsTest", function () { /* * @tc.name: DeviceUsageStatisticsJsTest033 - * @tc.desc: test unRegisterAppGroupCallBack callback. + * @tc.desc: test registerAppGroupCallBack callback. * @tc.type: FUNC * @tc.require: issueI5V2T4 */ it("DeviceUsageStatisticsJsTest033", 0, async function (done) { console.info('----------------------DeviceUsageStatisticsJsTest033---------------------------'); + let onBundleGroupChanged = (err, res) =>{ + console.log('BUNDLE_ACTIVE onBundleGroupChanged registerAppGroupCallBack callback success.'); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appUsageOldGroup is : ' + res.appOldGroup); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appUsageNewGroup is : ' + res.appNewGroup); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); + }; try{ - usageStatistics.unRegisterAppGroupCallBack((err, res) => { + usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, (err, res) => { if(err) { - console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack callback failure.'); + console.info('BUNDLE_ACTIVE registerAppGroupCallBack callback failure.'); expect(false).assertEqual(true); done(); } else { - console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack callback success.'); - expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE registerAppGroupCallBack callback success.'); + expect(true).assertEqual(true); done(); } }); } catch (error) { - console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack callback throw error.'); - expect(true).assertEqual(true); + console.info('BUNDLE_ACTIVE registerAppGroupCallBack callback failure.'); + expect(false).assertEqual(true); done(); } }) /* * @tc.name: DeviceUsageStatisticsJsTest034 - * @tc.desc: test unRegisterAppGroupCallBack promise. + * @tc.desc: test registerAppGroupCallBack promise. * @tc.type: FUNC * @tc.require: issueI5V2T4 */ it("DeviceUsageStatisticsJsTest034", 0, async function (done) { console.info('----------------------DeviceUsageStatisticsJsTest034---------------------------'); + let onBundleGroupChanged = (err, res) =>{ + console.log('BUNDLE_ACTIVE registerAppGroupCallBack registerAppGroupCallBack callback success.'); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); + console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); + }; try{ - usageStatistics.unRegisterAppGroupCallBack().then( (res) => { - console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack promise success.'); + usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( (res) => { + console.info('BUNDLE_ACTIVE registerAppGroupCallBack promise success.'); expect(false).assertEqual(true); done(); }).catch( err => { - console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack promise failure.'); - expect(false).assertEqual(true); + console.info('BUNDLE_ACTIVE registerAppGroupCallBack promise failure.'); + expect(true).assertEqual(true); done(); }); } catch (error) { - console.info('BUNDLE_ACTIVE unRegisterAppGroupCallBack promise throw error.'); + console.info('BUNDLE_ACTIVE registerAppGroupCallBack promise failure.'); expect(true).assertEqual(true); done(); } @@ -909,12 +925,64 @@ describe("DeviceUsageStatisticsJsTest", function () { /* * @tc.name: DeviceUsageStatisticsJsTest035 - * @tc.desc: test queryDeviceEventStats callback. + * @tc.desc: test unregisterAppGroupCallBack callback. * @tc.type: FUNC * @tc.require: issueI5V2T4 */ it("DeviceUsageStatisticsJsTest035", 0, async function (done) { console.info('----------------------DeviceUsageStatisticsJsTest035---------------------------'); + try{ + usageStatistics.unregisterAppGroupCallBack((err, res) => { + if(err) { + console.info('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failure.'); + expect(false).assertEqual(true); + done(); + } else { + console.info('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.'); + expect(true).assertEqual(true); + done(); + } + }); + } catch (error) { + console.info('BUNDLE_ACTIVE unregisterAppGroupCallBack callback throw error.'); + expect(false).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest036 + * @tc.desc: test unregisterAppGroupCallBack promise. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest036", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest036---------------------------'); + try{ + usageStatistics.unregisterAppGroupCallBack().then( (res) => { + console.info('BUNDLE_ACTIVE unregisterAppGroupCallBack promise success.'); + expect(false).assertEqual(true); + done(); + }).catch( err => { + console.info('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failure.'); + expect(false).assertEqual(true); + done(); + }); + } catch (error) { + console.info('BUNDLE_ACTIVE unregisterAppGroupCallBack promise throw error.'); + expect(true).assertEqual(true); + done(); + } + }) + + /* + * @tc.name: DeviceUsageStatisticsJsTest037 + * @tc.desc: test queryDeviceEventStats callback. + * @tc.type: FUNC + * @tc.require: issueI5V2T4 + */ + it("DeviceUsageStatisticsJsTest037", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest037---------------------------'); let beginTime = 0; let endTime = 20000000000000; try{ @@ -937,13 +1005,13 @@ describe("DeviceUsageStatisticsJsTest", function () { }) /* - * @tc.name: DeviceUsageStatisticsJsTest036 + * @tc.name: DeviceUsageStatisticsJsTest038 * @tc.desc: test queryDeviceEventStats promise. * @tc.type: FUNC * @tc.require: issueI5V2T4 */ - it("DeviceUsageStatisticsJsTest036", 0, async function (done) { - console.info('----------------------DeviceUsageStatisticsJsTest036---------------------------'); + it("DeviceUsageStatisticsJsTest038", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest038---------------------------'); let beginTime = 0; let endTime = 20000000000000; try{ @@ -964,13 +1032,13 @@ describe("DeviceUsageStatisticsJsTest", function () { }) /* - * @tc.name: DeviceUsageStatisticsJsTest037 + * @tc.name: DeviceUsageStatisticsJsTest039 * @tc.desc: test queryNotificationEventStats callback. * @tc.type: FUNC * @tc.require: issueI5V2T4 */ - it("DeviceUsageStatisticsJsTest037", 0, async function (done) { - console.info('----------------------DeviceUsageStatisticsJsTest037---------------------------'); + it("DeviceUsageStatisticsJsTest039", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest039---------------------------'); let beginTime = 0; let endTime = 20000000000000; try{ @@ -993,13 +1061,13 @@ describe("DeviceUsageStatisticsJsTest", function () { }) /* - * @tc.name: DeviceUsageStatisticsJsTest038 + * @tc.name: DeviceUsageStatisticsJsTest040 * @tc.desc: test queryNotificationEventStats promise. * @tc.type: FUNC * @tc.require: issueI5V2T4 */ - it("DeviceUsageStatisticsJsTest038", 0, async function (done) { - console.info('----------------------DeviceUsageStatisticsJsTest038---------------------------'); + it("DeviceUsageStatisticsJsTest040", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest040---------------------------'); let beginTime = 0; let endTime = 20000000000000; try{ -- Gitee From cf98280ae9a706d02f2d7bd6af7334fa770d44e1 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 25 Oct 2022 21:01:50 +0800 Subject: [PATCH 11/29] =?UTF-8?q?reviewbot=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index e7c0420..cddfcf7 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -375,8 +375,12 @@ ErrCode BundleActiveUserService::QueryBundleEvents(std::vectorendTime_ == 0) { + BUNDLE_ACTIVE_LOGI("QueryBundleEvents result in db is %{public}zu", bundleActiveEvent.size()); + return ERR_OK; + } // if we need a in-memory stats, combine current stats with bundleActiveEvent from database. - if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) { + if (endTime > currentStats->beginTime_) { BUNDLE_ACTIVE_LOGI("QueryBundleEvents need in memory stats"); int32_t eventBeginIdx = currentStats->events_.FindBestIndex(beginTime); int32_t eventSize = currentStats->events_.Size(); @@ -388,7 +392,7 @@ ErrCode BundleActiveUserService::QueryBundleEvents(std::vector Date: Tue, 25 Oct 2022 22:22:30 +0800 Subject: [PATCH 12/29] add Signed-off-by: shilei Change-Id: Id4e78b27bb78f0d748b0ec7e7eecf3bf0d0e8008 --- .../unittest/device_usage_statistics_jsunittest/config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json b/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json index 349b721..f8dc60a 100644 --- a/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json +++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json @@ -16,6 +16,7 @@ "package": "com.example.deviceUsageStatistics", "name": ".MyApplication", "deviceType": [ + "tablet", "default", "phone" ], @@ -72,4 +73,4 @@ ] } } - \ No newline at end of file + -- Gitee From 99fcbb2a39e120c13aaaa3823847bea3bb6d8efb Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 26 Oct 2022 17:26:15 +0800 Subject: [PATCH 13/29] =?UTF-8?q?=E6=96=B0=E5=A2=9Ecppcheck=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- frameworks/src/bundle_active_app_group_napi.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index 9158974..e75894b 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -60,9 +60,9 @@ napi_value ParseQueryAppGroupParameters(const napi_env &env, const napi_callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); if (valuetype == napi_function) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - if (valuetype != napi_function) { + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[0], &inputValueType)); + if (inputValueType != napi_function) { params.errorCode = ERR_CALL_BACK_TYPE; return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } -- Gitee From 037864edbc170316f0feb6fcb41479e4e7d386c0 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Thu, 27 Oct 2022 19:55:13 +0800 Subject: [PATCH 14/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0service=E7=AB=AF?= =?UTF-8?q?=E7=9A=84TDD=E7=94=A8=E4=BE=8B=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../common/include/bundle_active_service.h | 1 + services/common/src/bundle_active_service.cpp | 1 - test/unittest/BUILD.gn | 44 +++++- .../device_usage_statistics_service_test.cpp | 129 ++++++++++++++++++ 4 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 test/unittest/device_usage_statistics_service_test.cpp diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index f2ff1e8..a0fd14c 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -19,6 +19,7 @@ #include "bundle_mgr_interface.h" #include "singleton.h" +#include "app_mgr_interface.h" #include "ibundle_active_service.h" #include "bundle_active_stub.h" #include "bundle_active_core.h" diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index dbab5d0..05a2eaf 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -17,7 +17,6 @@ #include "power_mgr_client.h" #include "unistd.h" #include "accesstoken_kit.h" -#include "app_mgr_interface.h" #include "bundle_state_inner_errors.h" #include "bundle_active_event.h" diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 4151a21..84b3a37 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "device_usage_statistics/deviceusagestatisticstest" @@ -49,7 +50,48 @@ ohos_unittest("DeviceUsageStatsTest") { ] } +ohos_unittest("DeviceUsageStatsServiceTest") { + module_out_path = module_output_path + + sources = [ "device_usage_statistics_service_test.cpp" ] + + include_dirs = [ + "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr", + "//foundation/resourceschedule/device_usage_statistics/interfaces/innerkits/include", + "//foundation/resourceschedule/device_usage_statistics/services/common/include", + "//foundation/resourceschedule/device_usage_statistics/services/packageusage/include", + "//foundation/resourceschedule/device_usage_statistics/services/packagegroup/include", + ] + + configs = [ + "//foundation/ability/ability_runtime/interfaces/inner_api/wantagent:wantagent_innerkits_public_config" + ] + + deps = [ + "//foundation/resourceschedule/device_usage_statistics:usagestatservice", + "//foundation/resourceschedule/device_usage_statistics:usagestatsinner", + ] + + external_deps = [ + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "power_manager:powermgr_client", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_service", + ] +} + group("unittest") { testonly = true - deps = [ ":DeviceUsageStatsTest" ] + deps = [ + ":DeviceUsageStatsTest", + ":DeviceUsageStatsServiceTest", + ] } diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp new file mode 100644 index 0000000..0f89d25 --- /dev/null +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public + +#include + +#include +#include "system_ability_definition.h" + +#include "bundle_active_service.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DeviceUsageStats { + +class DeviceUsageStatisticsServiceTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DeviceUsageStatisticsServiceTest::SetUpTestCase(void) +{ +} + +void DeviceUsageStatisticsServiceTest::TearDownTestCase(void) +{ +} + +void DeviceUsageStatisticsServiceTest::SetUp(void) +{ +} + +void DeviceUsageStatisticsServiceTest::TearDown(void) +{ +} + +/* + * @tc.name: DeviceUsageStatisticsServiceTest_GetServiceObject_001 + * @tc.desc: get service object + * @tc.type: FUNC + * @tc.require: SR000GGTO8 AR000GH6PK + */ +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_GetServiceObject_001, Function | MediumTest | Level0) +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_NE(systemAbilityManager, nullptr); + + sptr remoteObject = + systemAbilityManager->GetSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); + EXPECT_NE(remoteObject, nullptr); +} + +/* + * @tc.name: DeviceUsageStatisticsServiceTest_dump_001 + * @tc.desc: get service object + * @tc.type: FUNC + * @tc.require: SR000GGTO8 AR000GH6PK + */ +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_dump_001, Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + BUNDLE_ACTIVE_LOGI("DeviceUsageStatisticsServiceTest create BundleActiveService!"); + + std::vector dumpOption{"-A", "Events"}; + std::vector dumpInfo; + service->ShellDump(dumpOption, dumpInfo); + + dumpOption.clear(); + dumpInfo.clear(); + dumpOption = {"-A", "PackageUsage"}; + service->ShellDump(dumpOption, dumpInfo); + + dumpOption.clear(); + dumpInfo.clear(); + dumpOption = {"-A", "ModuleUsage"}; + service->ShellDump(dumpOption, dumpInfo); + + std::vector args; + service->Dump(-1, args); + + args.clear(); + args = {to_utf16("-h")}; + service->Dump(-1, args); + + args.clear(); + args = {to_utf16("-A")}; + service->Dump(-1, args); + + args.clear(); + args = {to_utf16("-D")}; + service->Dump(-1, args); + EXPECT_TRUE(service!=nullptr); +} + +/* + * @tc.name: DeviceUsageStatisticsServiceTest_Shutdown_001 + * @tc.desc: get service object + * @tc.type: FUNC + * @tc.require: SR000GGTO8 AR000GH6PK + */ +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_Shutdown_001, Function | MediumTest | Level0) +{ + auto bundleActiveCore = std::make_shared(); + auto bundleActiveShutdownCallbackService = std::make_shared(bundleActiveCore); + BUNDLE_ACTIVE_LOGI("DeviceUsageStatisticsServiceTest create BundleActiveService!"); + bundleActiveShutdownCallbackService->ShutdownCallback(); + EXPECT_TRUE(bundleActiveShutdownCallbackService != nullptr); +} +} // namespace DeviceUsageStats +} // namespace OHOS \ No newline at end of file -- Gitee From 7f3cf65227426e4b909bef8309a3706a257f8633 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Thu, 27 Oct 2022 19:56:13 +0800 Subject: [PATCH 15/29] =?UTF-8?q?=E5=A2=9E=E5=8A=A0service=E7=AB=AF?= =?UTF-8?q?=E7=9A=84TDD=E7=94=A8=E4=BE=8B=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/src/bundle_active_stub.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index 5391fb4..ed8f8ce 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -20,6 +20,7 @@ #include "bundle_active_event.h" #include "bundle_active_event_stats.h" +#include "bundle_state_inner_errors.h" #include "bundle_active_log.h" #include "bundle_active_module_record.h" #include "bundle_active_package_stats.h" @@ -159,7 +160,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me auto observer = iface_cast(data.ReadRemoteObject()); if (!observer) { BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack observer is null, return"); - return false; + return ERR_MEMORY_OPERATION_FAILED; } BUNDLE_ACTIVE_LOGI("RegisterAppGroupCallBack observer is ok"); ErrCode errCode = RegisterAppGroupCallBack(observer); @@ -169,7 +170,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me auto observer = iface_cast(data.ReadRemoteObject()); if (!observer) { BUNDLE_ACTIVE_LOGE("UnRegisterAppGroupCallBack observer is null, return"); - return false; + return ERR_MEMORY_OPERATION_FAILED; } ErrCode errCode = UnRegisterAppGroupCallBack(observer); return reply.WriteInt32(errCode); -- Gitee From 2ef32cd0c40cf3b316934645f47bdbb70c14ddbe Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 28 Oct 2022 13:05:33 +0800 Subject: [PATCH 16/29] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E4=BE=A7=E7=9A=84TDD=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../innerkits/src/bundle_active_client.cpp | 5 ++-- services/common/src/bundle_active_service.cpp | 2 +- services/common/src/bundle_active_stub.cpp | 4 +-- .../device_usage_statistics_service_test.cpp | 29 +++++++++++-------- .../unittest/device_usage_statistics_test.cpp | 20 +++++++++++-- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 89cecd6..12d4da2 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -237,7 +237,7 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::OnRemoteDied(const wp void BundleActiveClient::BundleActiveClientDeathRecipient::OnServiceDiedInner() { - while (!BundleActiveClient::GetInstance().GetBundleActiveProxy()) { + while (BundleActiveClient::GetInstance().GetBundleActiveProxy() != ERR_OK) { sleep(SLEEP_TIME); } if (observer_) { @@ -245,5 +245,4 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::OnServiceDiedInner() } } } // namespace DeviceUsageStats -} // namespace OHOS - +} // namespace OHOS \ No newline at end of file diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 05a2eaf..d04bf10 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -560,7 +560,7 @@ ErrCode BundleActiveService::QueryModuleUsageRecords(int32_t maxNum, std::vector ErrCode errCode = ERR_OK; if (maxNum > MAXNUM_UP_LIMIT || maxNum <= 0) { BUNDLE_ACTIVE_LOGE("MaxNum is Invalid!"); - return errCode; + return ERR_FIND_APP_USAGE_RECORDS_FAILED; } int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); if (userId == -1) { diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index ed8f8ce..0408f06 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -160,7 +160,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me auto observer = iface_cast(data.ReadRemoteObject()); if (!observer) { BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack observer is null, return"); - return ERR_MEMORY_OPERATION_FAILED; + return false; } BUNDLE_ACTIVE_LOGI("RegisterAppGroupCallBack observer is ok"); ErrCode errCode = RegisterAppGroupCallBack(observer); @@ -170,7 +170,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me auto observer = iface_cast(data.ReadRemoteObject()); if (!observer) { BUNDLE_ACTIVE_LOGE("UnRegisterAppGroupCallBack observer is null, return"); - return ERR_MEMORY_OPERATION_FAILED; + return false; } ErrCode errCode = UnRegisterAppGroupCallBack(observer); return reply.WriteInt32(errCode); diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp index 0f89d25..0be275c 100644 --- a/test/unittest/device_usage_statistics_service_test.cpp +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -56,7 +56,7 @@ void DeviceUsageStatisticsServiceTest::TearDown(void) * @tc.name: DeviceUsageStatisticsServiceTest_GetServiceObject_001 * @tc.desc: get service object * @tc.type: FUNC - * @tc.require: SR000GGTO8 AR000GH6PK + * @tc.require: issuesI5SOZY */ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_GetServiceObject_001, Function | MediumTest | Level0) { @@ -71,9 +71,9 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_GetS /* * @tc.name: DeviceUsageStatisticsServiceTest_dump_001 - * @tc.desc: get service object + * @tc.desc: test dump * @tc.type: FUNC - * @tc.require: SR000GGTO8 AR000GH6PK + * @tc.require: issuesI5SOZY */ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_dump_001, Function | MediumTest | Level0) { @@ -112,18 +112,23 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_dump } /* - * @tc.name: DeviceUsageStatisticsServiceTest_Shutdown_001 - * @tc.desc: get service object + * @tc.name: DeviceUsageStatisticsServiceTest_QueryModuleUsageRecords_001 + * @tc.desc: QueryModuleUsageRecords * @tc.type: FUNC - * @tc.require: SR000GGTO8 AR000GH6PK + * @tc.require: issuesI5SOZY */ -HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_Shutdown_001, Function | MediumTest | Level0) +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_QueryModuleUsageRecords_001, + Function | MediumTest | Level0) { - auto bundleActiveCore = std::make_shared(); - auto bundleActiveShutdownCallbackService = std::make_shared(bundleActiveCore); - BUNDLE_ACTIVE_LOGI("DeviceUsageStatisticsServiceTest create BundleActiveService!"); - bundleActiveShutdownCallbackService->ShutdownCallback(); - EXPECT_TRUE(bundleActiveShutdownCallbackService != nullptr); + auto service = std::make_shared(); + std::vector results; + int32_t maxNum = 0; + ErrCode errCode = service->QueryModuleUsageRecords(maxNum, results, 100); + EXPECT_NE(errCode, 0); + + maxNum = 1001; + errCode = service->QueryModuleUsageRecords(maxNum, results, 100); + EXPECT_NE(errCode, 0); } } // namespace DeviceUsageStats } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index c7d6f12..edbb4f3 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -25,6 +25,7 @@ #include "bundle_active_event.h" #include "app_group_callback_stub.h" #include "bundle_active_group_map.h" +#include "app_group_callback_info.h" using namespace testing::ext; @@ -67,6 +68,20 @@ void DeviceUsageStatisticsTest::TearDown(void) { } +class TestAppGroupChangeCallback : public AppGroupCallbackStub { + void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; +}; + +void TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) +{ + BUNDLE_ACTIVE_LOGI("TestAppGroupChangeCallback::OnAppGroupChanged!"); + MessageParcel data; + if (!appGroupCallbackInfo.Marshalling(data)) { + BUNDLE_ACTIVE_LOGE("Marshalling fail"); + } + appGroupCallbackInfo.Unmarshalling(data); +} + /* * @tc.name: DeviceUsageStatisticsTest_GetServiceObject_001 * @tc.desc: get service object @@ -208,7 +223,7 @@ HWTEST_F(DeviceUsageStatisticsTest, { if (!observer) { BUNDLE_ACTIVE_LOGI("RegisterAppGroupCallBack construct observer!"); - observer = std::make_unique().release(); + observer = new (std::nothrow) TestAppGroupChangeCallback(); } ASSERT_NE(observer, nullptr); int32_t result = BundleActiveClient::GetInstance().RegisterAppGroupCallBack(observer); @@ -334,7 +349,8 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveGroupM HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_DeathRecipient_001, Function | MediumTest | Level0) { auto deathTest = std::make_shared(); - EXPECT_TRUE(deathTest!=nullptr); + deathTest->OnServiceDiedInner(); + EXPECT_TRUE(deathTest != nullptr); deathTest->OnRemoteDied(nullptr); } } // namespace DeviceUsageStats -- Gitee From b9ca922f4bef42318213612fe608e3cbf1353e31 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 28 Oct 2022 14:21:36 +0800 Subject: [PATCH 17/29] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- test/unittest/BUILD.gn | 12 ++---------- .../device_usage_statistics_service_test.cpp | 3 ++- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 84b3a37..a98b907 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/test.gni") -import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "device_usage_statistics/deviceusagestatisticstest" @@ -55,15 +54,8 @@ ohos_unittest("DeviceUsageStatsServiceTest") { sources = [ "device_usage_statistics_service_test.cpp" ] - include_dirs = [ - "//foundation/ability/ability_runtime/interfaces/inner_api/app_manager/include/appmgr", - "//foundation/resourceschedule/device_usage_statistics/interfaces/innerkits/include", - "//foundation/resourceschedule/device_usage_statistics/services/common/include", - "//foundation/resourceschedule/device_usage_statistics/services/packageusage/include", - "//foundation/resourceschedule/device_usage_statistics/services/packagegroup/include", - ] - configs = [ + ":module_private_config", "//foundation/ability/ability_runtime/interfaces/inner_api/wantagent:wantagent_innerkits_public_config" ] @@ -91,7 +83,7 @@ ohos_unittest("DeviceUsageStatsServiceTest") { group("unittest") { testonly = true deps = [ - ":DeviceUsageStatsTest", ":DeviceUsageStatsServiceTest", + ":DeviceUsageStatsTest", ] } diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp index 0be275c..0479c62 100644 --- a/test/unittest/device_usage_statistics_service_test.cpp +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -58,7 +58,8 @@ void DeviceUsageStatisticsServiceTest::TearDown(void) * @tc.type: FUNC * @tc.require: issuesI5SOZY */ -HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_GetServiceObject_001, Function | MediumTest | Level0) +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_GetServiceObject_001, + Function | MediumTest | Level0) { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); -- Gitee From f46933dc70f80ed656b4fa27320c0202069fc509 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 28 Oct 2022 14:27:09 +0800 Subject: [PATCH 18/29] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- test/unittest/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index a98b907..9dd5c38 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -56,7 +56,7 @@ ohos_unittest("DeviceUsageStatsServiceTest") { configs = [ ":module_private_config", - "//foundation/ability/ability_runtime/interfaces/inner_api/wantagent:wantagent_innerkits_public_config" + "//foundation/ability/ability_runtime/interfaces/inner_api/wantagent:wantagent_innerkits_public_config", ] deps = [ -- Gitee From 6368ebb7171fa0280e7b3e0341687d671a60baf4 Mon Sep 17 00:00:00 2001 From: Zhao-PengFei35 Date: Sat, 29 Oct 2022 09:48:54 +0800 Subject: [PATCH 19/29] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=83=A8=E4=BB=B6=E4=B8=AD=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=AE=8F=E9=9A=94=E7=A6=BB=E9=95=BF=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3=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: Zhao-PengFei35 --- BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index 7eabfb0..30d77f4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -166,7 +166,7 @@ ohos_shared_library("usagestatservice") { defines = [] if (bgtaskmgr_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] - defines += [ "RESOURCESCHEDULE_BGTASKMGR_ENABLE" ] + defines += [ "BGTASKMGR_ENABLE" ] } part_name = "${device_usage_statistics_part_name}" subsystem_name = "resourceschedule" -- Gitee From 0cfece88100407d301e6e446d30388afe2cf2fdc Mon Sep 17 00:00:00 2001 From: zhangxin_T Date: Sat, 29 Oct 2022 15:23:21 +0800 Subject: [PATCH 20/29] device usage so file decouple Signed-off-by: zhangxin_T --- BUILD.gn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index a666513..9109e84 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -36,11 +36,14 @@ ohos_shared_library("usagestatsinner") { "interfaces/innerkits/src/app_group_callback_stub.cpp", "interfaces/innerkits/src/bundle_active_client.cpp", "interfaces/innerkits/src/bundle_active_proxy.cpp", + "services/common/src/bundle_active_log.cpp", "services/packageusage/src/bundle_active_event.cpp", + "services/packageusage/src/bundle_active_event_stats.cpp", + "services/packageusage/src/bundle_active_form_record.cpp", + "services/packageusage/src/bundle_active_module_record.cpp", "services/packageusage/src/bundle_active_package_stats.cpp", ] public_configs = [ ":usagestatsinner_public_config" ] - deps = [ ":usagestatservice" ] external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", -- Gitee From 4a78761d7903f60bf4e06885ee21c3962223ddb5 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 4 Nov 2022 11:13:53 +0800 Subject: [PATCH 21/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E6=94=AF?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../innerkits/src/bundle_active_client.cpp | 5 +- .../include/bundle_active_account_helper.h | 2 - .../common/include/bundle_active_service.h | 1 + ...bundle_active_continuous_task_observer.cpp | 9 +- services/common/src/bundle_active_core.cpp | 16 +- services/common/src/bundle_active_service.cpp | 113 ++++--- .../src/bundle_active_group_controller.cpp | 15 +- .../src/bundle_active_user_history.cpp | 8 +- test/unittest/BUILD.gn | 42 ++- .../device_usage_statistics_mock_test.cpp | 305 ++++++++++++++++++ .../device_usage_statistics_service_test.cpp | 83 +++++ .../unittest/device_usage_statistics_test.cpp | 11 +- .../bundle_active_account_helper_mock.cpp | 30 ++ .../mock/bundle_active_client_mock.cpp | 30 ++ .../unittest/mock/bundle_active_core_mock.cpp | 37 +++ .../mock/bundle_active_service_mock.cpp | 30 ++ 16 files changed, 666 insertions(+), 71 deletions(-) create mode 100644 test/unittest/device_usage_statistics_mock_test.cpp create mode 100644 test/unittest/mock/bundle_active_account_helper_mock.cpp create mode 100644 test/unittest/mock/bundle_active_client_mock.cpp create mode 100644 test/unittest/mock/bundle_active_core_mock.cpp create mode 100644 test/unittest/mock/bundle_active_service_mock.cpp diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 12d4da2..f3d0566 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -230,9 +230,8 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::OnRemoteDied(const wp (void)object; BundleActiveClient::GetInstance().bundleActiveProxy_ = nullptr; BundleActiveClient::GetInstance().bundleClientHandler_->PostTask([this]() { - this->OnServiceDiedInner(); - }, - DELAY_TIME); + this->OnServiceDiedInner(); + }, DELAY_TIME); } void BundleActiveClient::BundleActiveClientDeathRecipient::OnServiceDiedInner() diff --git a/services/common/include/bundle_active_account_helper.h b/services/common/include/bundle_active_account_helper.h index cf7d311..b304aed 100644 --- a/services/common/include/bundle_active_account_helper.h +++ b/services/common/include/bundle_active_account_helper.h @@ -16,8 +16,6 @@ #ifndef BUNDLE_ACTIVE_ACCOUNT_HELPER_H #define BUNDLE_ACTIVE_ACCOUNT_HELPER_H -#include - #include "errors.h" #ifdef OS_ACCOUNT_PART_ENABLED #include "os_account_manager.h" diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index a0fd14c..f0e5dd3 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -228,6 +228,7 @@ private: ErrCode CheckBundleIsSystemAppAndHasPermission(const int32_t uid, OHOS::Security::AccessToken::AccessTokenID tokenId); ErrCode CheckSystemAppOrNativePermission(const int32_t uid, OHOS::Security::AccessToken::AccessTokenID tokenId); + ErrCode CheckNativePermission(OHOS::Security::AccessToken::AccessTokenID tokenId); void InitAppStateSubscriber(const std::shared_ptr& reportHandler); void InitContinuousSubscriber(const std::shared_ptr& reportHandler); bool SubscribeAppState(); diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index 6bfb491..403ba82 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -64,8 +64,13 @@ bool BundleActiveContinuousTaskObserver::GetBundleMgr() return false; } bundleMgr_ = iface_cast(remoteObject); - if ((!bundleMgr_) || (!bundleMgr_->AsObject())) { - BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability"); + if (!bundleMgr_) { + BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability, bundleMgr_"); + return false; + } + auto object = bundleMgr_->AsObject(); + if (!object) { + BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability, bundleMgr_->AsObject()"); return false; } } diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index f325fd0..5381d1f 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -241,7 +241,7 @@ void BundleActiveCore::OnBundleUninstalled(const int32_t userId, const std::stri BUNDLE_ACTIVE_LOGD("OnBundleUninstalled CALLED"); std::lock_guard lock(mutex_); int64_t timeNow = CheckTimeChangeAndGetWallTime(userId); - if (timeNow == -1) { + if (timeNow == ERR_TIME_OPERATION_FAILED) { return; } auto service = GetUserDataAndInitializeIfNeeded(userId, timeNow, debugCore_); @@ -269,8 +269,8 @@ void BundleActiveCore::OnStatsChanged(const int32_t userId) void BundleActiveCore::RestoreAllData() { - for (auto it = userStatServices_.begin(); it != userStatServices_.end(); ++it) { - std::shared_ptr service = it->second; + for (const auto& it : userStatServices_) { + std::shared_ptr service = it.second; if (service == nullptr) { BUNDLE_ACTIVE_LOGI("service in BundleActiveCore::RestoreToDatabaseLocked() is null"); return; @@ -278,7 +278,7 @@ void BundleActiveCore::RestoreAllData() BUNDLE_ACTIVE_LOGI("userid is %{public}d ", service->userId_); service->RestoreStats(true); if (bundleGroupController_ != nullptr && bundleGroupController_->bundleUserHistory_ != nullptr) { - bundleGroupController_->RestoreToDatabase(it->first); + bundleGroupController_->RestoreToDatabase(it.first); } } if (bundleGroupController_ != nullptr) { @@ -483,7 +483,7 @@ int32_t BundleActiveCore::ReportEvent(BundleActiveEvent& event, int32_t userId) "eventid %{public}d, in lock range", event.bundleName_.c_str(), (long long)event.timeStamp_, userId, event.eventId_); int64_t timeNow = CheckTimeChangeAndGetWallTime(userId); - if (timeNow == -1) { + if (timeNow == ERR_TIME_OPERATION_FAILED) { return -1; } ConvertToSystemTimeLocked(event); @@ -527,15 +527,15 @@ int32_t BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event) { BUNDLE_ACTIVE_LOGD("ReportEventToAllUserId called"); int64_t timeNow = CheckTimeChangeAndGetWallTime(); - if (timeNow == -1) { + if (timeNow == ERR_TIME_OPERATION_FAILED) { return -1; } if (userStatServices_.empty()) { return DEFAULT_USER_ID; } - for (auto it = userStatServices_.begin(); it != userStatServices_.end(); ++it) { + for (const auto& it : userStatServices_) { ConvertToSystemTimeLocked(event); - std::shared_ptr service = GetUserDataAndInitializeIfNeeded(it->first, timeNow, + std::shared_ptr service = GetUserDataAndInitializeIfNeeded(it.first, timeNow, debugCore_); if (service == nullptr) { BUNDLE_ACTIVE_LOGE("get user data service failed!"); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index d04bf10..173993f 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -73,31 +73,36 @@ void BundleActiveService::OnStart() void BundleActiveService::InitNecessaryState() { + std::set serviceIdSets{ + APP_MGR_SERVICE_ID, BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, POWER_MANAGER_SERVICE_ID, COMMON_EVENT_SERVICE_ID, + BACKGROUND_TASK_MANAGER_SERVICE_ID, TIME_SERVICE_ID, + }; sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (systemAbilityManager == nullptr - || systemAbilityManager->CheckSystemAbility(APP_MGR_SERVICE_ID) == nullptr - || systemAbilityManager->CheckSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) == nullptr - || systemAbilityManager->CheckSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr - || systemAbilityManager->CheckSystemAbility(COMMON_EVENT_SERVICE_ID) == nullptr - || systemAbilityManager->CheckSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr - || systemAbilityManager->CheckSystemAbility(TIME_SERVICE_ID) == nullptr) { - BUNDLE_ACTIVE_LOGI("request system service is not ready yet!"); + if (systemAbilityManager == nullptr) { + BUNDLE_ACTIVE_LOGI("GetSystemAbilityManager fail!"); auto task = [this]() { this->InitNecessaryState(); }; handler_->PostTask(task, DELAY_TIME); return; } + for (const auto& serviceItem : serviceIdSets) { + auto checkResult = systemAbilityManager->CheckSystemAbility(serviceItem); + if (!checkResult) { + BUNDLE_ACTIVE_LOGI("request system service is not ready yet!"); + auto task = [this]() { this->InitNecessaryState(); }; + handler_->PostTask(task, DELAY_TIME); + return; + } + } - if (systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID) == nullptr - || systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) == nullptr - || systemAbilityManager->GetSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr - || systemAbilityManager->GetSystemAbility(COMMON_EVENT_SERVICE_ID) == nullptr - || systemAbilityManager->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr - || systemAbilityManager->GetSystemAbility(TIME_SERVICE_ID) == nullptr) { - BUNDLE_ACTIVE_LOGI("request system service object is not ready yet!"); - auto task = [this]() { this->InitNecessaryState(); }; - handler_->PostTask(task, DELAY_TIME); - return; + for (const auto& serviceItem : serviceIdSets) { + auto getAbility = systemAbilityManager->GetSystemAbility(serviceItem); + if (!getAbility) { + BUNDLE_ACTIVE_LOGI("request system service object is not ready yet!"); + auto task = [this]() { this->InitNecessaryState(); }; + handler_->PostTask(task, DELAY_TIME); + return; + } } InitService(); ready_ = true; @@ -202,8 +207,8 @@ bool BundleActiveService::SubscribeContinuousTask() BUNDLE_ACTIVE_LOGE("SubscribeContinuousTask continuousTaskObserver_ is null, return"); return false; } - if (OHOS::BackgroundTaskMgr::BackgroundTaskMgrHelper::SubscribeBackgroundTask(*continuousTaskObserver_) - != OHOS::ERR_OK) { + ErrCode errCode = BackgroundTaskMgr::BackgroundTaskMgrHelper::SubscribeBackgroundTask(*continuousTaskObserver_); + if (errCode != ERR_OK) { BUNDLE_ACTIVE_LOGE("SubscribeBackgroundTask failed."); return false; } @@ -226,7 +231,7 @@ void BundleActiveService::OnStop() ErrCode BundleActiveService::ReportEvent(BundleActiveEvent& event, const int32_t userId) { AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); - if ((AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE)) { + if (CheckNativePermission(tokenId) == ERR_OK) { AccessToken::NativeTokenInfo callingTokenInfo; AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, callingTokenInfo); int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); @@ -259,7 +264,7 @@ ErrCode BundleActiveService::IsBundleIdle(bool& isBundleIdle, const std::string& AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); ErrCode ret = GetBundleMgrProxy(); if (ret != ERR_OK) { - BUNDLE_ACTIVE_LOGE("RegisterGroupCallBack Get bundle manager proxy failed!"); + BUNDLE_ACTIVE_LOGE("IsBundleIdle Get bundle manager proxy failed!"); return ret; } std::string callingBundleName = ""; @@ -340,28 +345,30 @@ ErrCode BundleActiveService::QueryBundleEvents(std::vector& b ErrCode BundleActiveService::SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) { - ErrCode ret = GetBundleMgrProxy(); + ErrCode ret = ERR_OK; + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); + bool isFlush = false; + if (userId == -1) { + ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); + if (ret != ERR_OK || userId == -1) { + return ERR_SYSTEM_ABILITY_SUPPORT_FAILED; + } + isFlush = true; + } + BUNDLE_ACTIVE_LOGI("SetAppGroup userId is %{public}d", userId); + + ret = GetBundleMgrProxy(); if (ret != ERR_OK) { - BUNDLE_ACTIVE_LOGE("RegisterGroupCallBack Get bundle manager proxy failed!"); + BUNDLE_ACTIVE_LOGE("SetAppGroup Get bundle manager proxy failed!"); return ret; } std::string localBundleName = ""; - int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); sptrBundleMgr_->GetBundleNameForUid(callingUid, localBundleName); if (localBundleName == bundleName) { BUNDLE_ACTIVE_LOGI("SetAppGroup can not set its bundleName"); return ERR_PERMISSION_DENIED; } AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); - bool isFlush = false; - if (userId == -1) { - ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); - if (ret != ERR_OK || userId == -1) { - return ERR_SYSTEM_ABILITY_SUPPORT_FAILED; - } - isFlush = true; - } - BUNDLE_ACTIVE_LOGI("SetAppGroup userid is %{public}d", userId); ret = CheckSystemAppOrNativePermission(callingUid, tokenId); if (ret == ERR_OK) { ret = bundleActiveCore_->SetAppGroup(bundleName, newGroup, userId, isFlush); @@ -440,7 +447,7 @@ ErrCode BundleActiveService::QueryAppGroup(int32_t& appGroup, std::string& bundl if (bundleName.empty()) { ret = GetBundleMgrProxy(); if (ret != ERR_OK) { - BUNDLE_ACTIVE_LOGE("Get bundle manager proxy failed!"); + BUNDLE_ACTIVE_LOGE("QueryAppGroup Get bundle manager proxy failed!"); return ret; } std::string localBundleName = ""; @@ -500,8 +507,13 @@ ErrCode BundleActiveService::GetBundleMgrProxy() return ERR_GET_SYSTEM_ABILITY_FAILED; } sptrBundleMgr_ = iface_cast(remoteObject); - if ((!sptrBundleMgr_) || (!sptrBundleMgr_->AsObject())) { - BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability"); + if (!sptrBundleMgr_) { + BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability, sptrBundleMgr_"); + return ERR_REMOTE_OBJECT_IF_CAST_FAILED; + } + auto object = sptrBundleMgr_->AsObject(); + if (!object) { + BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability, sptrBundleMgr_->AsObject()"); return ERR_REMOTE_OBJECT_IF_CAST_FAILED; } } @@ -523,7 +535,7 @@ ErrCode BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int32_ { ErrCode errCode = GetBundleMgrProxy(); if (errCode != ERR_OK) { - BUNDLE_ACTIVE_LOGE("RegisterGroupCallBack Get bundle manager proxy failed!"); + BUNDLE_ACTIVE_LOGE("CheckBundleIsSystemAppAndHasPermission Get bundle manager proxy failed!"); return errCode; } std::string bundleName = ""; @@ -538,12 +550,8 @@ ErrCode BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int32_ return ERR_OK; } -ErrCode BundleActiveService::CheckSystemAppOrNativePermission(const int32_t uid, - OHOS::Security::AccessToken::AccessTokenID tokenId) +ErrCode BundleActiveService::CheckNativePermission(OHOS::Security::AccessToken::AccessTokenID tokenId) { - if (CheckBundleIsSystemAppAndHasPermission(uid, tokenId) == ERR_OK) { - return ERR_OK; - } auto tokenFlag = AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (tokenFlag == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE) { return ERR_OK; @@ -554,6 +562,15 @@ ErrCode BundleActiveService::CheckSystemAppOrNativePermission(const int32_t uid, return ERR_PERMISSION_DENIED; } +ErrCode BundleActiveService::CheckSystemAppOrNativePermission(const int32_t uid, + OHOS::Security::AccessToken::AccessTokenID tokenId) +{ + if (CheckBundleIsSystemAppAndHasPermission(uid, tokenId) == ERR_OK) { + return ERR_OK; + } + return CheckNativePermission(tokenId); +} + ErrCode BundleActiveService::QueryModuleUsageRecords(int32_t maxNum, std::vector& results, int32_t userId) { @@ -631,14 +648,16 @@ void BundleActiveService::QueryModuleRecordInfos(BundleActiveModuleRecord& modul return; } ApplicationInfo appInfo; - if (!sptrBundleMgr_->GetApplicationInfo(moduleRecord.bundleName_, ApplicationFlag::GET_BASIC_APPLICATION_INFO, - moduleRecord.userId_, appInfo)) { + bool getInfoIsSuccess = sptrBundleMgr_->GetApplicationInfo(moduleRecord.bundleName_, + ApplicationFlag::GET_BASIC_APPLICATION_INFO, moduleRecord.userId_, appInfo); + if (!getInfoIsSuccess) { BUNDLE_ACTIVE_LOGE("GetApplicationInfo failed!"); return; } BundleInfo bundleInfo; - if (!sptrBundleMgr_->GetBundleInfo(moduleRecord.bundleName_, BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, - bundleInfo, moduleRecord.userId_)) { + getInfoIsSuccess = sptrBundleMgr_->GetBundleInfo(moduleRecord.bundleName_, + BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, moduleRecord.userId_); + if (!getInfoIsSuccess) { BUNDLE_ACTIVE_LOGE("GetBundleInfo failed!"); return; } diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index d096cd9..888f08e 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -129,7 +129,12 @@ bool BundleActiveGroupController::GetBundleMgrProxy() return false; } sptrBundleMgr_ = iface_cast(remoteObject); - if ((!sptrBundleMgr_) || (!sptrBundleMgr_->AsObject())) { + if (!sptrBundleMgr_) { + BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability, sptrBundleMgr_"); + return false; + } + auto object = sptrBundleMgr_->AsObject(); + if (!object) { BUNDLE_ACTIVE_LOGE("Failed to get system bundle manager services ability"); return false; } @@ -358,8 +363,12 @@ ErrCode BundleActiveGroupController::QueryAppGroup(int32_t& appGroup, bool BundleActiveGroupController::IsBundleInstalled(const std::string& bundleName, const int32_t userId) { ApplicationInfo bundleInfo; - if (sptrBundleMgr_ != nullptr && sptrBundleMgr_->GetApplicationInfo( - bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, bundleInfo) == false) { + if (!sptrBundleMgr_) { + return false; + } + bool getInfoIsSuccess = sptrBundleMgr_->GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, + userId, bundleInfo); + if (getInfoIsSuccess == false) { BUNDLE_ACTIVE_LOGE("IsBundleInstalled bundle is not installed!"); return false; } diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index cb11782..27922ae 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -214,16 +214,16 @@ int32_t BundleActiveUserHistory::SetAppGroup(const string& bundleName, const int bundleName.c_str(), newGroup, groupReason, userId); shared_ptr>> userBundleHistory = GetUserHistory(userId, false); if (!userBundleHistory) { - return -1; + return ERR_GET_BUNDLE_USED_HISTORY_FAILED; } shared_ptr oneBundleHistory = GetUsageHistoryInUserHistory(userBundleHistory, bundleName, bootBasedTimeStamp, false); if (!oneBundleHistory) { - return -1; + return ERR_GET_BUNDLE_USED_HISTORY_FAILED; } if (oneBundleHistory->currentGroup_ == newGroup && oneBundleHistory->reasonInGroup_ == groupReason) { BUNDLE_ACTIVE_LOGI("%{public}s group and reason is same as before, not update", bundleName.c_str()); - return 1; + return ERR_REPEAT_SET_APP_GROUP; } int32_t oldGroup = oneBundleHistory->currentGroup_; oneBundleHistory->currentGroup_ = newGroup; @@ -242,7 +242,7 @@ int32_t BundleActiveUserHistory::SetAppGroup(const string& bundleName, const int bundleActiveCore_.lock()->OnAppGroupChanged(callbackInfo); } } - return 0; + return ERR_OK; } void BundleActiveUserHistory::UpdateBootBasedAndScreenTime(const bool& isScreenOn, const int64_t bootBasedTimeStamp, diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9dd5c38..9761156 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -52,7 +52,46 @@ ohos_unittest("DeviceUsageStatsTest") { ohos_unittest("DeviceUsageStatsServiceTest") { module_out_path = module_output_path - sources = [ "device_usage_statistics_service_test.cpp" ] + sources = [ + "device_usage_statistics_service_test.cpp", + ] + + configs = [ + ":module_private_config", + "//foundation/ability/ability_runtime/interfaces/inner_api/wantagent:wantagent_innerkits_public_config", + ] + + deps = [ + "//foundation/resourceschedule/device_usage_statistics:usagestatservice", + "//foundation/resourceschedule/device_usage_statistics:usagestatsinner", + ] + + external_deps = [ + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "power_manager:powermgr_client", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_service", + ] +} + +ohos_unittest("DeviceUsageStatsMockTest") { + module_out_path = module_output_path + + sources = [ + "device_usage_statistics_mock_test.cpp", + "mock/bundle_active_account_helper_mock.cpp", + "mock/bundle_active_client_mock.cpp", + "mock/bundle_active_core_mock.cpp", + "mock/bundle_active_service_mock.cpp", + ] configs = [ ":module_private_config", @@ -83,6 +122,7 @@ ohos_unittest("DeviceUsageStatsServiceTest") { group("unittest") { testonly = true deps = [ + ":DeviceUsageStatsMockTest", ":DeviceUsageStatsServiceTest", ":DeviceUsageStatsTest", ] diff --git a/test/unittest/device_usage_statistics_mock_test.cpp b/test/unittest/device_usage_statistics_mock_test.cpp new file mode 100644 index 0000000..b8dfd60 --- /dev/null +++ b/test/unittest/device_usage_statistics_mock_test.cpp @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public + +#include + +#include +#include "system_ability_definition.h" + +#include "bundle_active_client.h" +#include "bundle_active_event.h" +#include "bundle_active_service.h" +#include "bundle_active_group_map.h" +#include "app_group_callback_stub.h" +#include "app_group_callback_info.h" +#include "iapp_group_callback.h" + + +using namespace testing::ext; + +namespace OHOS { +namespace DeviceUsageStats { +static std::string g_defaultBundleName = "com.ohos.camera"; +static std::string g_defaultMoudleName = "defaultmodulename"; +static std::string g_defaultFormName = "defaultformname"; +static int32_t DEFAULT_DIMENSION = 4; +static int64_t DEFAULT_FORMID = 1; +static int32_t DEFAULT_USERID = 0; +static int32_t COMMON_USERID = 100; +static int64_t LARGE_NUM = 20000000000000; +static int32_t DEFAULT_GROUP = 10; +static sptr observer = nullptr; +bool isGetBundleActiveProxy = true; +bool isGetUserId = true; +bool isGetBundleMgrProxy = true; +bool isCheckTimeChangeAndGetWallTime = true; + +class DeviceUsageStatisticsMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DeviceUsageStatisticsMockTest::SetUpTestCase(void) +{ +} + +void DeviceUsageStatisticsMockTest::TearDownTestCase(void) +{ +} + +void DeviceUsageStatisticsMockTest::SetUp(void) +{ +} + +void DeviceUsageStatisticsMockTest::TearDown(void) +{ +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_GetBundleActiveProxy_001 + * @tc.desc: test client getBundleActiveProxy boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_GetBundleActiveProxy_001, + Function | MediumTest | Level0) +{ + BundleActiveEvent eventA(g_defaultBundleName, g_defaultMoudleName, g_defaultFormName, + DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED); + EXPECT_NE(BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID), ERR_OK); + + bool isBundleIdle = false; + EXPECT_NE(BundleActiveClient::GetInstance().IsBundleIdle(isBundleIdle, g_defaultBundleName, DEFAULT_USERID), ERR_OK); + + std::vector packageStats; + EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleStatsInfoByInterval(packageStats, 4, 0, LARGE_NUM), ERR_OK); + EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleStatsInfos(packageStats, 4, 0, LARGE_NUM), ERR_OK); + + std::vector event; + EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleEvents(event, 0, LARGE_NUM, 100), ERR_OK); + EXPECT_NE(BundleActiveClient::GetInstance().QueryCurrentBundleEvents(event, 0, LARGE_NUM), ERR_OK); + + int32_t result = 0; + EXPECT_NE(BundleActiveClient::GetInstance().QueryAppGroup(result, g_defaultBundleName, COMMON_USERID), ERR_OK); + + EXPECT_NE(BundleActiveClient::GetInstance().SetAppGroup(g_defaultBundleName, DEFAULT_GROUP, COMMON_USERID), ERR_OK); + + EXPECT_NE(BundleActiveClient::GetInstance().RegisterAppGroupCallBack(observer), ERR_OK); + EXPECT_NE(BundleActiveClient::GetInstance().UnRegisterAppGroupCallBack(observer), ERR_OK); + + std::vector eventStats; + EXPECT_NE(BundleActiveClient::GetInstance().QueryDeviceEventStats(0, LARGE_NUM, eventStats), ERR_OK); + EXPECT_NE(BundleActiveClient::GetInstance().QueryNotificationEventStats(0, LARGE_NUM, eventStats), ERR_OK); + + std::vector moduleRecord; + int32_t maxNum = 1000; + EXPECT_NE(BundleActiveClient::GetInstance().QueryModuleUsageRecords(maxNum, moduleRecord, DEFAULT_USERID), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_GetBundleMgrProxy_001 + * @tc.desc: test service getBundleMgrProxy boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_GetBundleMgrProxy_001, + Function | MediumTest | Level0) +{ + BundleActiveEvent eventA(g_defaultBundleName, g_defaultMoudleName, g_defaultFormName, + DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED); + EXPECT_NE(BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryDeviceEventStats_001 + * @tc.desc: test service queryDeviceEventStats boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_QueryDeviceEventStats_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + std::vector eventStats; + EXPECT_NE(service->QueryDeviceEventStats(0, LARGE_NUM, eventStats, -1), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryNotificationEventStats_001 + * @tc.desc: test service queryNotificationEventStats boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_QueryNotificationEventStats_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + std::vector eventStats; + EXPECT_NE(service->QueryNotificationEventStats(0, LARGE_NUM, eventStats, -1), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryModuleUsageRecords_001 + * @tc.desc: test service queryModuleUsageRecords boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_QueryModuleUsageRecords_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + std::vector records; + EXPECT_NE(service->QueryModuleUsageRecords(1000, records, -1), ERR_OK); + + BundleActiveModuleRecord bundleActiveModuleRecord; + service->QueryModuleRecordInfos(bundleActiveModuleRecord); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryAppGroup_001 + * @tc.desc: test service queryAppGroup boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_QueryAppGroup_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + int32_t appGroup; + std::string bundleName; + EXPECT_NE(service->QueryAppGroup(appGroup, bundleName, -1), ERR_OK); + EXPECT_NE(service->QueryAppGroup(appGroup, bundleName, 100), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_AppGroupCallback_001 + * @tc.desc: test service appGroupCallback boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_AppGroupCallback_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + sptr observer = nullptr; + service->bundleActiveCore_ = nullptr; + EXPECT_NE(service->RegisterAppGroupCallBack(observer), ERR_OK); + EXPECT_NE(service->UnRegisterAppGroupCallBack(observer), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryBundleEvents_001 + * @tc.desc: test service queryBundleEvents boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_QueryBundleEvents_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + std::vector bundleActiveEvents; + EXPECT_NE(service->QueryBundleEvents(bundleActiveEvents, 0, LARGE_NUM, -1), ERR_OK); + EXPECT_NE(service->QueryCurrentBundleEvents(bundleActiveEvents, 0, LARGE_NUM), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryBundleStatsInfoByInterval_001 + * @tc.desc: test service queryBundleStatsInfoByInterval boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_QueryBundleStatsInfoByInterval_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + std::vector packageStats; + EXPECT_NE(service->QueryBundleStatsInfoByInterval(packageStats, 0, 0, LARGE_NUM, -1), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryBundleStatsInfos_001 + * @tc.desc: test service queryBundleStatsInfos boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_QueryBundleStatsInfos_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + + std::vector packageStats; + EXPECT_NE(service->QueryBundleStatsInfos(packageStats, 0, 0, LARGE_NUM), ERR_OK); +} + +/* + * @tc.name: DeviceUsageStatisticsMockTest_QueryBundleStatsInfos_001 + * @tc.desc: test service queryBundleStatsInfos boundary condition + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_CheckTimeChangeAndGetWallTime_001, + Function | MediumTest | Level0) +{ + auto bundleActiveCore = std::make_shared(); + + std::vector eventStats; + EXPECT_NE(bundleActiveCore->QueryNotificationEventStats(0, LARGE_NUM, eventStats, COMMON_USERID), ERR_OK); + EXPECT_NE(bundleActiveCore->QueryDeviceEventStats(0, LARGE_NUM, eventStats, COMMON_USERID), ERR_OK); + + std::vector moduleRecords; + EXPECT_NE(bundleActiveCore->QueryModuleUsageRecords(1000, moduleRecords, COMMON_USERID), ERR_OK); + + std::vector activeEvent; + ErrCode code = bundleActiveCore->QueryBundleEvents(activeEvent, COMMON_USERID, 0, LARGE_NUM, g_defaultBundleName); + EXPECT_NE(code, ERR_OK); + + std::vector packageStats; + code = bundleActiveCore->QueryBundleStatsInfos(packageStats, COMMON_USERID, 4, 0, LARGE_NUM, g_defaultBundleName); + EXPECT_NE(code, ERR_OK); + + BundleActiveEvent event; + EXPECT_NE(bundleActiveCore->ReportEventToAllUserId(event), ERR_OK); + + bundleActiveCore->OnBundleUninstalled(COMMON_USERID, g_defaultBundleName); + + isCheckTimeChangeAndGetWallTime = false; + EXPECT_NE(bundleActiveCore->QueryNotificationEventStats(0, LARGE_NUM, eventStats, COMMON_USERID), ERR_OK); + EXPECT_NE(bundleActiveCore->QueryDeviceEventStats(0, LARGE_NUM, eventStats, COMMON_USERID), ERR_OK); + EXPECT_NE(bundleActiveCore->QueryModuleUsageRecords(1000, moduleRecords, COMMON_USERID), ERR_OK); + + code = bundleActiveCore->QueryBundleEvents(activeEvent, COMMON_USERID, 0, LARGE_NUM, g_defaultBundleName); + EXPECT_NE(code, ERR_OK); + + code = bundleActiveCore->QueryBundleStatsInfos(packageStats, COMMON_USERID, 4, 0, LARGE_NUM, g_defaultBundleName); + EXPECT_NE(code, ERR_OK); + + bundleActiveCore->OnBundleUninstalled(COMMON_USERID, g_defaultBundleName); +} +} // namespace DeviceUsageStats +} // namespace OHOS + diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp index 0479c62..000f5aa 100644 --- a/test/unittest/device_usage_statistics_service_test.cpp +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -22,6 +22,8 @@ #include "system_ability_definition.h" #include "bundle_active_service.h" +#include "app_group_callback_stub.h" +#include "app_group_callback_info.h" using namespace testing::ext; @@ -52,6 +54,16 @@ void DeviceUsageStatisticsServiceTest::TearDown(void) { } +class TestServiceAppGroupChangeCallback : public AppGroupCallbackStub { +public: + void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; +}; + +void TestServiceAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) +{ + BUNDLE_ACTIVE_LOGI("TestServiceAppGroupChangeCallback::OnAppGroupChanged!"); +} + /* * @tc.name: DeviceUsageStatisticsServiceTest_GetServiceObject_001 * @tc.desc: get service object @@ -131,5 +143,76 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_Quer errCode = service->QueryModuleUsageRecords(maxNum, results, 100); EXPECT_NE(errCode, 0); } + +/* + * @tc.name: DeviceUsageStatisticsServiceTest_AppGroupCallback_001 + * @tc.desc: QueryModuleUsageRecords + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_AppGroupCallback_001, + Function | MediumTest | Level0) +{ + auto service = std::make_shared(); + BUNDLE_ACTIVE_LOGI("DeviceUsageStatisticsServiceTest create BundleActiveService!"); + sptr observer = new (std::nothrow) TestServiceAppGroupChangeCallback(); + service->bundleActiveCore_ = std::make_shared(); + EXPECT_EQ(service->RegisterAppGroupCallBack(observer), ERR_OK); + EXPECT_NE(service->RegisterAppGroupCallBack(observer), ERR_OK); + service->bundleActiveCore_->AddObserverDeathRecipient(observer); + + EXPECT_EQ(service->UnRegisterAppGroupCallBack(observer), ERR_OK); + EXPECT_NE(service->UnRegisterAppGroupCallBack(observer), ERR_OK); + + observer = nullptr; + EXPECT_NE(service->RegisterAppGroupCallBack(observer), ERR_OK); + + service->bundleActiveCore_->AddObserverDeathRecipient(observer); + service->bundleActiveCore_->RemoveObserverDeathRecipient(observer); + + wptr remote = nullptr; + service->bundleActiveCore_->OnObserverDied(remote); + service->bundleActiveCore_->OnObserverDiedInner(remote); +} + +/* + * @tc.name: DeviceUsageStatisticsServiceTest_OnUserRemoved_001 + * @tc.desc: QueryModuleUsageRecords + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_OnUserRemoved_001, + Function | MediumTest | Level0) +{ + int userId = 100; + auto bundleActiveCore = std::make_shared(); + bundleActiveCore->bundleGroupController_ = std::make_shared(bundleActiveCore->debugCore_); + bundleActiveCore->InitBundleGroupController(); + auto userService = std::make_shared(userId, *(bundleActiveCore.get()), false); + bundleActiveCore->userStatServices_[userId] = userService; + bundleActiveCore->currentUsedUser_ = userId; + bundleActiveCore->OnUserRemoved(userId); + bundleActiveCore->OnUserSwitched(userId); + bundleActiveCore->RestoreAllData(); + EXPECT_NE(bundleActiveCore, nullptr); +} + +/* + * @tc.name: DeviceUsageStatisticsServiceTest_RestoreAllData_001 + * @tc.desc: QueryModuleUsageRecords + * @tc.type: FUNC + * @tc.require: issuesI5SOZY + */ +HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_RestoreAllData_001, + Function | MediumTest | Level0) +{ + auto bundleActiveCore = std::make_shared(); + bundleActiveCore->bundleGroupController_ = std::make_shared(bundleActiveCore->debugCore_); + bundleActiveCore->InitBundleGroupController(); + bundleActiveCore->RestoreAllData(); + BundleActiveEvent event; + bundleActiveCore->ReportEventToAllUserId(event); + EXPECT_NE(bundleActiveCore, nullptr); +} } // namespace DeviceUsageStats } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index edbb4f3..bfc6b26 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -26,6 +26,7 @@ #include "app_group_callback_stub.h" #include "bundle_active_group_map.h" #include "app_group_callback_info.h" +#include "iapp_group_callback.h" using namespace testing::ext; @@ -42,7 +43,7 @@ static int32_t DEFAULT_ERRCODE = 0; static int64_t LARGE_NUM = 20000000000000; static int32_t DEFAULT_GROUP = 10; static std::vector GROUP_TYPE {10, 20, 30, 40, 50}; -static sptr observer = nullptr; +static sptr observer = nullptr; class DeviceUsageStatisticsTest : public testing::Test { public: @@ -69,6 +70,7 @@ void DeviceUsageStatisticsTest::TearDown(void) } class TestAppGroupChangeCallback : public AppGroupCallbackStub { +public: void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; }; @@ -126,6 +128,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryBundleEvents_ std::vector result; BundleActiveClient::GetInstance().QueryBundleEvents(result, 0, LARGE_NUM, 100); EXPECT_EQ(result.size() > 0, true); + EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleEvents(result, LARGE_NUM, LARGE_NUM, 100), 0); } /* @@ -153,6 +156,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackagesStats std::vector result; BundleActiveClient::GetInstance().QueryBundleStatsInfoByInterval(result, 4, 0, LARGE_NUM); EXPECT_EQ(result.size(), 0); + EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleStatsInfoByInterval(result, 4, LARGE_NUM, LARGE_NUM), 0); } /* @@ -349,6 +353,11 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveGroupM HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_DeathRecipient_001, Function | MediumTest | Level0) { auto deathTest = std::make_shared(); + deathTest->AddObserver(observer); + deathTest->RemoveObserver(); + deathTest->OnServiceDiedInner(); + + deathTest->observer_ = new (std::nothrow) TestAppGroupChangeCallback(); deathTest->OnServiceDiedInner(); EXPECT_TRUE(deathTest != nullptr); deathTest->OnRemoteDied(nullptr); diff --git a/test/unittest/mock/bundle_active_account_helper_mock.cpp b/test/unittest/mock/bundle_active_account_helper_mock.cpp new file mode 100644 index 0000000..00142ed --- /dev/null +++ b/test/unittest/mock/bundle_active_account_helper_mock.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include "bundle_active_account_helper.h" + +namespace OHOS { +namespace DeviceUsageStats { +extern bool isGetUserId; +ErrCode BundleActiveAccountHelper::GetUserId(const int32_t uid, int32_t& userId) +{ + if (!isGetUserId) { + return 0; + } + return -1; +} +} // namespace DeviceUsageStats +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/bundle_active_client_mock.cpp b/test/unittest/mock/bundle_active_client_mock.cpp new file mode 100644 index 0000000..cce9fa2 --- /dev/null +++ b/test/unittest/mock/bundle_active_client_mock.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "bundle_active_client.h" +#include "bundle_state_inner_errors.h" + +namespace OHOS { +namespace DeviceUsageStats { +extern bool isGetBundleActiveProxy; +ErrCode BundleActiveClient::GetBundleActiveProxy() +{ + if (!isGetBundleActiveProxy) { + return ERR_OK; + } + return ERR_SYSTEM_SERVICE_OPERATION_FAILED; +} +} // namespace DeviceUsageStats +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/bundle_active_core_mock.cpp b/test/unittest/mock/bundle_active_core_mock.cpp new file mode 100644 index 0000000..2f818be --- /dev/null +++ b/test/unittest/mock/bundle_active_core_mock.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "bundle_active_core.h" +#include "bundle_state_inner_errors.h" + +namespace OHOS { +namespace DeviceUsageStats { +extern bool isCheckTimeChangeAndGetWallTime; + +int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int32_t userId) +{ + if (!isCheckTimeChangeAndGetWallTime) { + return 2000000000000; + } + return ERR_TIME_OPERATION_FAILED; +} + +std::shared_ptr BundleActiveCore::GetUserDataAndInitializeIfNeeded(const int32_t userId, + const int64_t timeStamp, const bool debug) +{ + return nullptr; +} +} // namespace DeviceUsageStats +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/bundle_active_service_mock.cpp b/test/unittest/mock/bundle_active_service_mock.cpp new file mode 100644 index 0000000..b9dd33f --- /dev/null +++ b/test/unittest/mock/bundle_active_service_mock.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "bundle_active_service.h" +#include "bundle_state_inner_errors.h" + +namespace OHOS { +namespace DeviceUsageStats { +extern bool isGetBundleMgrProxy; +ErrCode BundleActiveService::GetBundleMgrProxy() +{ + if (!isGetBundleMgrProxy) { + return ERR_OK; + } + return ERR_SYSTEM_SERVICE_OPERATION_FAILED; +} +} // namespace DeviceUsageStats +} // namespace OHOS \ No newline at end of file -- Gitee From 437e47ffaa4b427e13be22387927752dc60eb2ba Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 4 Nov 2022 12:06:38 +0800 Subject: [PATCH 22/29] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E6=94=AF?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../innerkits/src/bundle_active_client.cpp | 4 +-- test/unittest/BUILD.gn | 4 +-- .../device_usage_statistics_mock_test.cpp | 21 +++++------- .../device_usage_statistics_service_test.cpp | 32 +++++++++---------- .../bundle_active_account_helper_mock.cpp | 4 --- .../mock/bundle_active_client_mock.cpp | 4 --- .../unittest/mock/bundle_active_core_mock.cpp | 7 ++-- .../mock/bundle_active_service_mock.cpp | 4 --- 8 files changed, 30 insertions(+), 50 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index f3d0566..483e894 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -230,8 +230,8 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::OnRemoteDied(const wp (void)object; BundleActiveClient::GetInstance().bundleActiveProxy_ = nullptr; BundleActiveClient::GetInstance().bundleClientHandler_->PostTask([this]() { - this->OnServiceDiedInner(); - }, DELAY_TIME); + this->OnServiceDiedInner(); + }, DELAY_TIME); } void BundleActiveClient::BundleActiveClientDeathRecipient::OnServiceDiedInner() diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9761156..4ec0bb7 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -52,9 +52,7 @@ ohos_unittest("DeviceUsageStatsTest") { ohos_unittest("DeviceUsageStatsServiceTest") { module_out_path = module_output_path - sources = [ - "device_usage_statistics_service_test.cpp", - ] + sources = [ "device_usage_statistics_service_test.cpp" ] configs = [ ":module_private_config", diff --git a/test/unittest/device_usage_statistics_mock_test.cpp b/test/unittest/device_usage_statistics_mock_test.cpp index b8dfd60..a0be54d 100644 --- a/test/unittest/device_usage_statistics_mock_test.cpp +++ b/test/unittest/device_usage_statistics_mock_test.cpp @@ -44,10 +44,6 @@ static int32_t COMMON_USERID = 100; static int64_t LARGE_NUM = 20000000000000; static int32_t DEFAULT_GROUP = 10; static sptr observer = nullptr; -bool isGetBundleActiveProxy = true; -bool isGetUserId = true; -bool isGetBundleMgrProxy = true; -bool isCheckTimeChangeAndGetWallTime = true; class DeviceUsageStatisticsMockTest : public testing::Test { public: @@ -86,8 +82,8 @@ HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_GetBundleA DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED); EXPECT_NE(BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID), ERR_OK); - bool isBundleIdle = false; - EXPECT_NE(BundleActiveClient::GetInstance().IsBundleIdle(isBundleIdle, g_defaultBundleName, DEFAULT_USERID), ERR_OK); + bool isIdle = false; + EXPECT_NE(BundleActiveClient::GetInstance().IsBundleIdle(isIdle, g_defaultBundleName, DEFAULT_USERID), ERR_OK); std::vector packageStats; EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleStatsInfoByInterval(packageStats, 4, 0, LARGE_NUM), ERR_OK); @@ -287,18 +283,17 @@ HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_CheckTimeC bundleActiveCore->OnBundleUninstalled(COMMON_USERID, g_defaultBundleName); - isCheckTimeChangeAndGetWallTime = false; - EXPECT_NE(bundleActiveCore->QueryNotificationEventStats(0, LARGE_NUM, eventStats, COMMON_USERID), ERR_OK); - EXPECT_NE(bundleActiveCore->QueryDeviceEventStats(0, LARGE_NUM, eventStats, COMMON_USERID), ERR_OK); - EXPECT_NE(bundleActiveCore->QueryModuleUsageRecords(1000, moduleRecords, COMMON_USERID), ERR_OK); + EXPECT_NE(bundleActiveCore->QueryNotificationEventStats(0, LARGE_NUM, eventStats, DEFAULT_USERID), ERR_OK); + EXPECT_NE(bundleActiveCore->QueryDeviceEventStats(0, LARGE_NUM, eventStats, DEFAULT_USERID), ERR_OK); + EXPECT_NE(bundleActiveCore->QueryModuleUsageRecords(1000, moduleRecords, DEFAULT_USERID), ERR_OK); - code = bundleActiveCore->QueryBundleEvents(activeEvent, COMMON_USERID, 0, LARGE_NUM, g_defaultBundleName); + code = bundleActiveCore->QueryBundleEvents(activeEvent, DEFAULT_USERID, 0, LARGE_NUM, g_defaultBundleName); EXPECT_NE(code, ERR_OK); - code = bundleActiveCore->QueryBundleStatsInfos(packageStats, COMMON_USERID, 4, 0, LARGE_NUM, g_defaultBundleName); + code = bundleActiveCore->QueryBundleStatsInfos(packageStats, DEFAULT_USERID, 4, 0, LARGE_NUM, g_defaultBundleName); EXPECT_NE(code, ERR_OK); - bundleActiveCore->OnBundleUninstalled(COMMON_USERID, g_defaultBundleName); + bundleActiveCore->OnBundleUninstalled(DEFAULT_USERID, g_defaultBundleName); } } // namespace DeviceUsageStats } // namespace OHOS diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp index 000f5aa..1a0c43e 100644 --- a/test/unittest/device_usage_statistics_service_test.cpp +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -185,16 +185,16 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_OnUs Function | MediumTest | Level0) { int userId = 100; - auto bundleActiveCore = std::make_shared(); - bundleActiveCore->bundleGroupController_ = std::make_shared(bundleActiveCore->debugCore_); - bundleActiveCore->InitBundleGroupController(); - auto userService = std::make_shared(userId, *(bundleActiveCore.get()), false); - bundleActiveCore->userStatServices_[userId] = userService; - bundleActiveCore->currentUsedUser_ = userId; - bundleActiveCore->OnUserRemoved(userId); - bundleActiveCore->OnUserSwitched(userId); - bundleActiveCore->RestoreAllData(); - EXPECT_NE(bundleActiveCore, nullptr); + auto coreObject = std::make_shared(); + coreObject->bundleGroupController_ = std::make_shared(coreObject->debugCore_); + coreObject->InitBundleGroupController(); + auto userService = std::make_shared(userId, *(coreObject.get()), false); + coreObject->userStatServices_[userId] = userService; + coreObject->currentUsedUser_ = userId; + coreObject->OnUserRemoved(userId); + coreObject->OnUserSwitched(userId); + coreObject->RestoreAllData(); + EXPECT_NE(coreObject, nullptr); } /* @@ -206,13 +206,13 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_OnUs HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_RestoreAllData_001, Function | MediumTest | Level0) { - auto bundleActiveCore = std::make_shared(); - bundleActiveCore->bundleGroupController_ = std::make_shared(bundleActiveCore->debugCore_); - bundleActiveCore->InitBundleGroupController(); - bundleActiveCore->RestoreAllData(); + auto coreObject = std::make_shared(); + coreObject->bundleGroupController_ = std::make_shared(coreObject->debugCore_); + coreObject->InitBundleGroupController(); + coreObject->RestoreAllData(); BundleActiveEvent event; - bundleActiveCore->ReportEventToAllUserId(event); - EXPECT_NE(bundleActiveCore, nullptr); + coreObject->ReportEventToAllUserId(event); + EXPECT_NE(coreObject, nullptr); } } // namespace DeviceUsageStats } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/bundle_active_account_helper_mock.cpp b/test/unittest/mock/bundle_active_account_helper_mock.cpp index 00142ed..ea9c9c4 100644 --- a/test/unittest/mock/bundle_active_account_helper_mock.cpp +++ b/test/unittest/mock/bundle_active_account_helper_mock.cpp @@ -18,12 +18,8 @@ namespace OHOS { namespace DeviceUsageStats { -extern bool isGetUserId; ErrCode BundleActiveAccountHelper::GetUserId(const int32_t uid, int32_t& userId) { - if (!isGetUserId) { - return 0; - } return -1; } } // namespace DeviceUsageStats diff --git a/test/unittest/mock/bundle_active_client_mock.cpp b/test/unittest/mock/bundle_active_client_mock.cpp index cce9fa2..e96349d 100644 --- a/test/unittest/mock/bundle_active_client_mock.cpp +++ b/test/unittest/mock/bundle_active_client_mock.cpp @@ -18,12 +18,8 @@ namespace OHOS { namespace DeviceUsageStats { -extern bool isGetBundleActiveProxy; ErrCode BundleActiveClient::GetBundleActiveProxy() { - if (!isGetBundleActiveProxy) { - return ERR_OK; - } return ERR_SYSTEM_SERVICE_OPERATION_FAILED; } } // namespace DeviceUsageStats diff --git a/test/unittest/mock/bundle_active_core_mock.cpp b/test/unittest/mock/bundle_active_core_mock.cpp index 2f818be..7104408 100644 --- a/test/unittest/mock/bundle_active_core_mock.cpp +++ b/test/unittest/mock/bundle_active_core_mock.cpp @@ -18,12 +18,11 @@ namespace OHOS { namespace DeviceUsageStats { -extern bool isCheckTimeChangeAndGetWallTime; - +static int64_t LARGE_NUM = 20000000000000; int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int32_t userId) { - if (!isCheckTimeChangeAndGetWallTime) { - return 2000000000000; + if (userId == 0) { + return LARGE_NUM; } return ERR_TIME_OPERATION_FAILED; } diff --git a/test/unittest/mock/bundle_active_service_mock.cpp b/test/unittest/mock/bundle_active_service_mock.cpp index b9dd33f..6cb0bab 100644 --- a/test/unittest/mock/bundle_active_service_mock.cpp +++ b/test/unittest/mock/bundle_active_service_mock.cpp @@ -18,12 +18,8 @@ namespace OHOS { namespace DeviceUsageStats { -extern bool isGetBundleMgrProxy; ErrCode BundleActiveService::GetBundleMgrProxy() { - if (!isGetBundleMgrProxy) { - return ERR_OK; - } return ERR_SYSTEM_SERVICE_OPERATION_FAILED; } } // namespace DeviceUsageStats -- Gitee From ceb8754863d4d39d5a12778c4ac7c4811b50bc79 Mon Sep 17 00:00:00 2001 From: MangTsang Date: Mon, 7 Nov 2022 17:16:45 +0800 Subject: [PATCH 23/29] replace time_service with time_client Signed-off-by: MangTsang --- BUILD.gn | 2 +- test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn | 2 +- test/unittest/BUILD.gn | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 6c08996..f8f8835 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -191,7 +191,7 @@ ohos_shared_library("usagestatservice") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] if (os_account_part_enabled) { diff --git a/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn b/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn index a220822..d0f432d 100644 --- a/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn +++ b/test/fuzztest/bundleactiveonremoterequest_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("BundleActiveOnRemoteRequestFuzzTest") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 4ec0bb7..00e5d9e 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -76,7 +76,7 @@ ohos_unittest("DeviceUsageStatsServiceTest") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] } @@ -113,7 +113,7 @@ ohos_unittest("DeviceUsageStatsMockTest") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] } -- Gitee From 15d480b4a8940e53748638ce26e43c3edb3175a4 Mon Sep 17 00:00:00 2001 From: MangTsang Date: Mon, 7 Nov 2022 19:39:01 +0800 Subject: [PATCH 24/29] add json to test Signed-off-by: MangTsang --- test/unittest/BUILD.gn | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 00e5d9e..524769b 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -23,6 +23,7 @@ config("module_private_config") { "//foundation/resourceschedule/device_usage_statistics/services/common/include", "//foundation/resourceschedule/device_usage_statistics/services/packageusage/include", "//foundation/resourceschedule/device_usage_statistics/services/packagegroup/include", + "//third_party/jsoncpp/include", ] } @@ -36,6 +37,7 @@ ohos_unittest("DeviceUsageStatsTest") { deps = [ "//foundation/resourceschedule/device_usage_statistics:usagestatservice", "//foundation/resourceschedule/device_usage_statistics:usagestatsinner", + "//third_party/jsoncpp:jsoncpp", ] external_deps = [ @@ -62,6 +64,7 @@ ohos_unittest("DeviceUsageStatsServiceTest") { deps = [ "//foundation/resourceschedule/device_usage_statistics:usagestatservice", "//foundation/resourceschedule/device_usage_statistics:usagestatsinner", + "//third_party/jsoncpp:jsoncpp", ] external_deps = [ @@ -99,6 +102,7 @@ ohos_unittest("DeviceUsageStatsMockTest") { deps = [ "//foundation/resourceschedule/device_usage_statistics:usagestatservice", "//foundation/resourceschedule/device_usage_statistics:usagestatsinner", + "//third_party/jsoncpp:jsoncpp", ] external_deps = [ -- Gitee From 20c405aa29de8425901f3bcb53c537c8e3e6c0f9 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 10 Nov 2022 10:08:31 +0800 Subject: [PATCH 25/29] =?UTF-8?q?reviewbot=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- frameworks/src/app_group_observer_napi.cpp | 2 +- .../src/bundle_active_app_group_napi.cpp | 16 +++++----- frameworks/src/bundle_state_common.cpp | 2 +- frameworks/src/bundle_state_query.cpp | 24 +++++++------- frameworks/src/bundle_state_query_napi.cpp | 32 +++++++++---------- .../include/app_group_callback_proxy.h | 4 +-- .../include/app_group_callback_stub.h | 4 +-- .../napi/include/app_group_observer_napi.h | 2 +- .../napi/include/bundle_state_condition.h | 2 -- .../napi/include/bundle_state_init.h | 2 +- .../napi/include/usage_statistics_init.h | 2 +- .../bundle_active_continuous_task_observer.h | 6 ++-- services/common/include/bundle_active_core.h | 2 +- ...undle_active_power_state_callback_stub.cpp | 2 +- .../src/bundle_active_usage_database.cpp | 2 +- .../include/bundle_active_calendar.h | 2 +- .../include/bundle_active_event_stats.h | 2 +- .../include/bundle_active_form_record.h | 2 +- .../include/bundle_active_module_record.h | 2 +- 19 files changed, 55 insertions(+), 57 deletions(-) diff --git a/frameworks/src/app_group_observer_napi.cpp b/frameworks/src/app_group_observer_napi.cpp index 028b50d..f9ab0c1 100644 --- a/frameworks/src/app_group_observer_napi.cpp +++ b/frameworks/src/app_group_observer_napi.cpp @@ -157,7 +157,7 @@ void AppGroupObserver::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCal callbackReceiveDataWorker->ref = bundleGroupCallbackInfo_.ref; delete callBackInfo; - work->data = (void *)callbackReceiveDataWorker; + work->data = static_cast(callbackReceiveDataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnAppGroupChanged); if (ret != 0) { delete callbackReceiveDataWorker; diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index cff62f5..9baa50e 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -133,8 +133,8 @@ napi_value QueryAppGroup(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -242,8 +242,8 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -347,8 +347,8 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -427,8 +427,8 @@ napi_value UnRegisterAppGroupCallBack(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 5c486ca..5088cf0 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -245,7 +245,7 @@ void BundleStateCommon::GetBundleStateInfoForResult(napi_env env, } void BundleStateCommon::GetModuleRecordBasicForResult(napi_env env, - const BundleActiveModuleRecord &oneModuleRecord, napi_value moduleObject) + const BundleActiveModuleRecord &moduleRecords, napi_value moduleObject) { napi_value bundleName = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneModuleRecord.bundleName_.c_str(), diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index edb88d8..ad3f874 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -117,8 +117,8 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -209,8 +209,8 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -322,8 +322,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -389,8 +389,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -516,8 +516,8 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -625,8 +625,8 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index e7e775d..a3523f0 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -139,8 +139,8 @@ napi_value QueryModuleUsageRecords(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -229,8 +229,8 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -336,8 +336,8 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -392,8 +392,8 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -508,8 +508,8 @@ napi_value QueryBundleStatsInfoByInterval(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -610,8 +610,8 @@ napi_value QueryBundleStatsInfos(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -713,8 +713,8 @@ napi_value QueryDeviceEventStats(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -766,8 +766,8 @@ napi_value QueryNotificationEventStats(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); + static_cast(asyncCallbackInfo, + &asyncCallbackInfo->asyncWork))); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); diff --git a/interfaces/innerkits/include/app_group_callback_proxy.h b/interfaces/innerkits/include/app_group_callback_proxy.h index 2dcc8bd..1de0867 100644 --- a/interfaces/innerkits/include/app_group_callback_proxy.h +++ b/interfaces/innerkits/include/app_group_callback_proxy.h @@ -29,14 +29,14 @@ namespace DeviceUsageStats { class BundleActiveGroupCallbackProxy : public IRemoteProxy { public: explicit BundleActiveGroupCallbackProxy(const sptr& impl); - virtual ~BundleActiveGroupCallbackProxy() override; + ~BundleActiveGroupCallbackProxy() override; DISALLOW_COPY_AND_MOVE(BundleActiveGroupCallbackProxy); /* * function: OnAppGroupChanged, bundleGroupChanged callback, IPC proxy, send message to stub. * parameters: AppGroupCallbackInfo * return: void. */ - virtual void OnAppGroupChanged( + void OnAppGroupChanged( const AppGroupCallbackInfo& appGroupCallbackInfo) override; private: diff --git a/interfaces/innerkits/include/app_group_callback_stub.h b/interfaces/innerkits/include/app_group_callback_stub.h index 96d90b7..50272de 100644 --- a/interfaces/innerkits/include/app_group_callback_stub.h +++ b/interfaces/innerkits/include/app_group_callback_stub.h @@ -30,14 +30,14 @@ public: * parameters: code, data, reply, option * return: errorcode. */ - virtual int OnRemoteRequest( + int OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; /* * function: OnAppGroupChanged, bundleGroupChanged callback, handle message from proxy. * parameters: AppGroupCallbackInfo * return: void. */ - virtual void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; + void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; private: DISALLOW_COPY_AND_MOVE(AppGroupCallbackStub); }; diff --git a/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h b/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h index f895d67..6950448 100644 --- a/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h +++ b/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h @@ -30,7 +30,7 @@ public: ~AppGroupObserver(); - virtual void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; + void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; void SetCallbackInfo(const napi_env &env, const napi_ref &ref); diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_condition.h b/interfaces/kits/bundlestats/napi/include/bundle_state_condition.h index 86e0999..b281135 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_condition.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_condition.h @@ -15,8 +15,6 @@ #ifndef FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_CONDITION_H #define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_CONDITION_H -#include - namespace OHOS { namespace DeviceUsageStats { class BundleStateCondition { diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_init.h b/interfaces/kits/bundlestats/napi/include/bundle_state_init.h index 8e65667..cb34bc7 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_init.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_init.h @@ -44,7 +44,7 @@ napi_module _module = { .nm_filename = nullptr, .nm_register_func = BundleStateInit, .nm_modname = "bundleState", - .nm_priv = ((void *)0), + .nm_priv = (static_cast(0)), .reserved = {0} }; } // namespace DeviceUsageStats diff --git a/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h b/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h index 10b8458..513c5ec 100644 --- a/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h +++ b/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h @@ -45,7 +45,7 @@ napi_module _usageStatisticsModule = { .nm_filename = nullptr, .nm_register_func = UsageStatisticsInit, .nm_modname = "resourcescheduler.usageStatistics", - .nm_priv = ((void *)0), + .nm_priv = (static_cast(0)), .reserved = {0} }; } // namespace DeviceUsageStats diff --git a/services/common/include/bundle_active_continuous_task_observer.h b/services/common/include/bundle_active_continuous_task_observer.h index 4da1288..ca7f97e 100644 --- a/services/common/include/bundle_active_continuous_task_observer.h +++ b/services/common/include/bundle_active_continuous_task_observer.h @@ -33,11 +33,11 @@ namespace DeviceUsageStats { class BundleActiveContinuousTaskObserver : public OHOS::BackgroundTaskMgr::BackgroundTaskSubscriber { public: using IBundleMgr = OHOS::AppExecFwk::IBundleMgr; - virtual void OnContinuousTaskStart(const std::shared_ptr + void OnContinuousTaskStart(const std::shared_ptr &continuousTaskCallbackInfo) override; - virtual void OnContinuousTaskStop(const std::shared_ptr + void OnContinuousTaskStop(const std::shared_ptr &continuousTaskCallbackInfo) override; - virtual void OnRemoteDied(const wptr &object) override; + void OnRemoteDied(const wptr &object) override; void Init(const std::shared_ptr& reportHandler); std::atomic isRemoteDied_ {false}; private: diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index dfba3f1..70fecf5 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -56,7 +56,7 @@ class BundleActiveCore : public BundleActiveStatsUpdateListener, public std::enable_shared_from_this { public: BundleActiveCore(); - virtual ~BundleActiveCore(); + ~BundleActiveCore(); /* * function: ReportEvent, used to report ability fourground/background/destroy event. diff --git a/services/common/src/bundle_active_power_state_callback_stub.cpp b/services/common/src/bundle_active_power_state_callback_stub.cpp index 6ec2ff1..7d344d2 100644 --- a/services/common/src/bundle_active_power_state_callback_stub.cpp +++ b/services/common/src/bundle_active_power_state_callback_stub.cpp @@ -23,7 +23,7 @@ int32_t BundleActivePowerStateCallbackStub::OnRemoteRequest(uint32_t code, Messa { std::u16string descriptor = BundleActivePowerStateCallbackStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); - PowerMgr::PowerState state = (PowerMgr::PowerState)data.ReadInt32(); + PowerMgr::PowerState state = static_cast(data.ReadInt32()); if (descriptor != remoteDescriptor) { BUNDLE_ACTIVE_LOGE("BundleActivePowerStateCallbackStub::OnRemoteRequest cannot get power mgr service"); return -1; diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 9593b62..ba7a13d 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1122,7 +1122,7 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime) } } -void BundleActiveUsageDatabase::RenewTableTime(int64_t changedTime) +void BundleActiveUsageDatabase::RenewTableTime(int64_t timeDiffMillis) { lock_guard lock(databaseMutex_); for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { diff --git a/services/packageusage/include/bundle_active_calendar.h b/services/packageusage/include/bundle_active_calendar.h index 41230b1..5f9aefe 100644 --- a/services/packageusage/include/bundle_active_calendar.h +++ b/services/packageusage/include/bundle_active_calendar.h @@ -16,7 +16,7 @@ #ifndef BUNDLE_ACTIVE_CALENDER_H #define BUNDLE_ACTIVE_CALENDER_H -#include +#include #include "bundle_active_constant.h" diff --git a/services/packageusage/include/bundle_active_event_stats.h b/services/packageusage/include/bundle_active_event_stats.h index 5b63239..a9b4949 100644 --- a/services/packageusage/include/bundle_active_event_stats.h +++ b/services/packageusage/include/bundle_active_event_stats.h @@ -83,7 +83,7 @@ public: * parameters: parcel * return: result of mashalling, true means successful, flase means failed. */ - virtual bool Marshalling(Parcel &parcel) const override; + bool Marshalling(Parcel &parcel) const override; /* * function: UnMarshalling, Unmashalling event stats object from parcel. diff --git a/services/packageusage/include/bundle_active_form_record.h b/services/packageusage/include/bundle_active_form_record.h index 57d0c1c..0155e04 100644 --- a/services/packageusage/include/bundle_active_form_record.h +++ b/services/packageusage/include/bundle_active_form_record.h @@ -86,7 +86,7 @@ public: * parameters: parcel * return: result of mashalling, true means successful, flase means failed. */ - virtual bool Marshalling(Parcel &parcel) const override; + bool Marshalling(Parcel &parcel) const override; /* * function: UnMarshalling, Unmashalling record object from parcel. * parameters: parcel diff --git a/services/packageusage/include/bundle_active_module_record.h b/services/packageusage/include/bundle_active_module_record.h index 0112a18..5146339 100644 --- a/services/packageusage/include/bundle_active_module_record.h +++ b/services/packageusage/include/bundle_active_module_record.h @@ -30,7 +30,7 @@ public: BundleActiveModuleRecord(); ~BundleActiveModuleRecord() {} static bool cmp(const BundleActiveModuleRecord& moduleRecordA, const BundleActiveModuleRecord& moduleRecordB); - virtual bool Marshalling(Parcel &parcel) const override; + bool Marshalling(Parcel &parcel) const override; std::shared_ptr UnMarshalling(Parcel &parcel); std::string ToString(); -- Gitee From 9a01c12b773710860eb9dd9b2aac8057f713ccb0 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 10 Nov 2022 11:18:07 +0800 Subject: [PATCH 26/29] =?UTF-8?q?reviewbot=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../src/bundle_active_app_group_napi.cpp | 8 +++---- frameworks/src/bundle_state_common.cpp | 22 +++++++++---------- frameworks/src/bundle_state_query_napi.cpp | 4 ++-- .../src/bundle_active_usage_database.cpp | 6 ++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index 9baa50e..573b5d6 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -133,8 +133,8 @@ napi_value QueryAppGroup(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -242,8 +242,8 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 5088cf0..065d9ee 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -248,42 +248,42 @@ void BundleStateCommon::GetModuleRecordBasicForResult(napi_env env, const BundleActiveModuleRecord &moduleRecords, napi_value moduleObject) { napi_value bundleName = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneModuleRecord.bundleName_.c_str(), + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, moduleRecords.bundleName_.c_str(), NAPI_AUTO_LENGTH, &bundleName)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "bundleName", bundleName)); napi_value appLabelId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.appLabelId_, &appLabelId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, moduleRecords.appLabelId_, &appLabelId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "appLabelId", appLabelId)); napi_value moduleName = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneModuleRecord.moduleName_.c_str(), NAPI_AUTO_LENGTH, + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, moduleRecords.moduleName_.c_str(), NAPI_AUTO_LENGTH, &moduleName)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "moduleName", moduleName)); napi_value labelId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.labelId_, &labelId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, moduleRecords.labelId_, &labelId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "labelId", labelId)); napi_value descriptionId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.descriptionId_, &descriptionId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, moduleRecords.descriptionId_, &descriptionId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "descriptionId", descriptionId)); napi_value abilityName = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneModuleRecord.abilityName_.c_str(), NAPI_AUTO_LENGTH, + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, moduleRecords.abilityName_.c_str(), NAPI_AUTO_LENGTH, &abilityName)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityName", abilityName)); napi_value abilityLableId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.abilityLableId_, &abilityLableId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, moduleRecords.abilityLableId_, &abilityLableId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityLableId", abilityLableId)); napi_value abilityDescriptionId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.abilityDescriptionId_, + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, moduleRecords.abilityDescriptionId_, &abilityDescriptionId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityDescriptionId", abilityDescriptionId)); napi_value abilityIconId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.abilityIconId_, &abilityIconId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, moduleRecords.abilityIconId_, &abilityIconId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityIconId", abilityIconId)); napi_value launchedCount = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, oneModuleRecord.launchedCount_, &launchedCount)); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, moduleRecords.launchedCount_, &launchedCount)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "launchedCount", launchedCount)); napi_value lastModuleUsedTime = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, oneModuleRecord.lastModuleUsedTime_, &lastModuleUsedTime)); + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, moduleRecords.lastModuleUsedTime_, &lastModuleUsedTime)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "lastModuleUsedTime", lastModuleUsedTime)); } diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index a3523f0..93736e1 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -139,8 +139,8 @@ napi_value QueryModuleUsageRecords(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index ba7a13d..d739e91 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1131,7 +1131,7 @@ void BundleActiveUsageDatabase::RenewTableTime(int64_t timeDiffMillis) } vector tableArray = sortedTableArray_.at(i); for (uint32_t j = 0; j < tableArray.size(); j++) { - int64_t newTime = tableArray.at(j) + changedTime; + int64_t newTime = tableArray.at(j) + timeDiffMillis; BUNDLE_ACTIVE_LOGI("new table time is %{public}lld", (long long)newTime); if (newTime < 0) { DeleteInvalidTable(i, tableArray.at(j)); @@ -1145,7 +1145,7 @@ void BundleActiveUsageDatabase::RenewTableTime(int64_t timeDiffMillis) } if (eventTableName_ != UNKNOWN_TABLE_NAME) { int64_t oldTime = ParseStartTime(eventTableName_); - int64_t newTime = oldTime + changedTime; + int64_t newTime = oldTime + timeDiffMillis; if (newTime < 0) { int32_t deletedResult = DeleteInvalidTable(EVENT_DATABASE_INDEX, oldTime); if (deletedResult == BUNDLE_ACTIVE_SUCCESS) { @@ -1160,7 +1160,7 @@ void BundleActiveUsageDatabase::RenewTableTime(int64_t timeDiffMillis) } if (formRecordsTableName_ != UNKNOWN_TABLE_NAME && moduleRecordsTableName_ != UNKNOWN_TABLE_NAME) { int64_t oldTime = ParseStartTime(moduleRecordsTableName_); - int64_t newTime = oldTime + changedTime; + int64_t newTime = oldTime + timeDiffMillis; int32_t renamedResult = RenameTableName(APP_GROUP_DATABASE_INDEX, oldTime, newTime); if (renamedResult == BUNDLE_ACTIVE_SUCCESS) { moduleRecordsTableName_ = MODULE_RECORD_LOG_TABLE + to_string(newTime); -- Gitee From d3c66586f3512346bc2c11af3669c45346ebac4b Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 10 Nov 2022 12:10:10 +0800 Subject: [PATCH 27/29] =?UTF-8?q?reviewbot=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../src/bundle_active_app_group_napi.cpp | 8 +++--- frameworks/src/bundle_state_query.cpp | 24 ++++++++-------- frameworks/src/bundle_state_query_napi.cpp | 28 +++++++++---------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index 573b5d6..8fbdb5c 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -347,8 +347,8 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -427,8 +427,8 @@ napi_value UnRegisterAppGroupCallBack(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index ad3f874..14778aa 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -117,8 +117,8 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -209,8 +209,8 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -322,8 +322,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -389,8 +389,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -516,8 +516,8 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -625,8 +625,8 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 93736e1..c44d6fd 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -229,8 +229,8 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -336,8 +336,8 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -392,8 +392,8 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -508,8 +508,8 @@ napi_value QueryBundleStatsInfoByInterval(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -610,8 +610,8 @@ napi_value QueryBundleStatsInfos(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -713,8 +713,8 @@ napi_value QueryDeviceEventStats(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); @@ -766,8 +766,8 @@ napi_value QueryNotificationEventStats(napi_env env, napi_callback_info info) BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, - static_cast(asyncCallbackInfo, - &asyncCallbackInfo->asyncWork))); + static_cast(asyncCallbackInfo), + &asyncCallbackInfo->asyncWork)); NAPI_CALL(env, napi_queue_async_work(env, callbackPtr->asyncWork)); if (callbackPtr->isCallback) { callbackPtr.release(); -- Gitee From 591d40083a3c27488bb5b83ae1e8a5d62f9e7ba2 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 10 Nov 2022 13:17:17 +0800 Subject: [PATCH 28/29] =?UTF-8?q?reviewbot=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 70fecf5..dfba3f1 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -56,7 +56,7 @@ class BundleActiveCore : public BundleActiveStatsUpdateListener, public std::enable_shared_from_this { public: BundleActiveCore(); - ~BundleActiveCore(); + virtual ~BundleActiveCore(); /* * function: ReportEvent, used to report ability fourground/background/destroy event. -- Gitee From fe9207aa64ed23288729e0766cae41d27618ad2d Mon Sep 17 00:00:00 2001 From: houdisheng Date: Mon, 14 Nov 2022 17:14:01 +0800 Subject: [PATCH 29/29] =?UTF-8?q?reviewbot=E5=89=A9=E4=BD=99=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../bundlestats/napi/include/app_group_observer_napi.h | 2 +- .../kits/bundlestats/napi/include/bundle_state_init.h | 8 ++++---- .../bundlestats/napi/include/bundle_state_inner_errors.h | 4 ++-- .../kits/bundlestats/napi/include/usage_statistics_init.h | 8 ++++---- services/common/include/bundle_active_log.h | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h b/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h index 6950448..12aec41 100644 --- a/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h +++ b/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h @@ -23,7 +23,7 @@ namespace OHOS { namespace DeviceUsageStats { -static const int8_t NO_ERROR = 0; +const int8_t NO_ERROR = 0; class AppGroupObserver : public AppGroupCallbackStub { public: AppGroupObserver() =default; diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_init.h b/interfaces/kits/bundlestats/napi/include/bundle_state_init.h index cb34bc7..7e17950 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_init.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_init.h @@ -26,10 +26,10 @@ extern "C" { #endif __attribute__((constructor)) void RegisterModule(void); -static napi_value BundleStateInit(napi_env env, napi_value exports); -static napi_value InitIntervalType(napi_env env, napi_value exports); -static napi_value InitGroupType(napi_env env, napi_value exports); -static napi_value EnumTypeConstructor(napi_env env, napi_callback_info info); +napi_value BundleStateInit(napi_env env, napi_value exports); +napi_value InitIntervalType(napi_env env, napi_value exports); +napi_value InitGroupType(napi_env env, napi_value exports); +napi_value EnumTypeConstructor(napi_env env, napi_callback_info info); #ifdef __cplusplus } diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h index a709d3c..3e37a88 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h @@ -105,7 +105,7 @@ enum ServiceError { ERR_REPEAT_SET_APP_GROUP, }; -static std::map saErrCodeMsgMap = { +std::map saErrCodeMsgMap = { {ERR_PERMISSION_DENIED, "Permission denied."}, {ERR_MEMORY_OPERATION_FAILED, "Memory operation failed. create object failed."}, {ERR_PARCEL_WRITE_FALIED, "Parcel operation failed. Failed to write the parcel."}, @@ -133,7 +133,7 @@ static std::map saErrCodeMsgMap = { "Get application group info failed. The application group infomation cannot be found."}, }; -static std::map paramErrCodeMsgMap = { +std::map paramErrCodeMsgMap = { {ERR_PARAMETERS_NUMBER, " api interface parameters count is error."}, {ERR_PARAMETERS_EMPTY, " cannot be empty."}, {ERR_CALL_BACK_TYPE, " Callback type must be function."}, diff --git a/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h b/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h index 513c5ec..4d1ae2c 100644 --- a/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h +++ b/interfaces/kits/bundlestats/napi/include/usage_statistics_init.h @@ -26,10 +26,10 @@ extern "C" { #endif __attribute__((constructor)) void RegisterModule(void); -static napi_value UsageStatisticsInit(napi_env env, napi_value exports); -static napi_value InitAppGroupType(napi_env env, napi_value exports); -static napi_value InitIntervalType(napi_env env, napi_value exports); -static napi_value EnumTypeConstructor(napi_env env, napi_callback_info info); +napi_value UsageStatisticsInit(napi_env env, napi_value exports); +napi_value InitAppGroupType(napi_env env, napi_value exports); +napi_value InitIntervalType(napi_env env, napi_value exports); +napi_value EnumTypeConstructor(napi_env env, napi_callback_info info); #ifdef __cplusplus diff --git a/services/common/include/bundle_active_log.h b/services/common/include/bundle_active_log.h index 68f5282..046bb00 100644 --- a/services/common/include/bundle_active_log.h +++ b/services/common/include/bundle_active_log.h @@ -29,7 +29,7 @@ namespace DeviceUsageStats { #define LOG_TAG_BUNDLE_ACTIVE "BUNDLE_ACTIVE" #endif -static constexpr OHOS::HiviewDFX::HiLogLabel BUNDLE_ACTIVE_LOG_LABEL = { +constexpr OHOS::HiviewDFX::HiLogLabel BUNDLE_ACTIVE_LOG_LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_BUNDLE_ACTIVE, LOG_TAG_BUNDLE_ACTIVE -- Gitee