From 86a3d4b10700db5d00f01bb447ad143e1e3ae8e4 Mon Sep 17 00:00:00 2001 From: chenjunwu Date: Tue, 24 Sep 2024 14:30:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20add=20macro=20for=20user=20dump=20?= =?UTF-8?q?=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle.json | 1 + services/BUILD.gn | 5 +++++ services/native/src/battery_dump.cpp | 18 ++++++++++++++++++ test/systemtest/BUILD.gn | 4 ++++ .../src/battery_event_system_test.cpp | 16 ++++++++++++++++ 5 files changed, 44 insertions(+) diff --git a/bundle.json b/bundle.json index b5ca83f..6030acb 100644 --- a/bundle.json +++ b/bundle.json @@ -43,6 +43,7 @@ "drivers_interface_display", "drivers_interface_input", "drivers_interface_light", + "eventhandler", "ffrt", "graphic_surface", "hdf_core", diff --git a/services/BUILD.gn b/services/BUILD.gn index 53c8824..9ce8cfa 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -57,6 +57,7 @@ ohos_shared_library("batteryservice") { "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "drivers_interface_battery:libbattery_proxy_2.0", + "eventhandler:libeventhandler", "ffrt:libffrt", "hdf_core:libhdi", "hdf_core:libpub_utils", @@ -78,6 +79,10 @@ ohos_shared_library("batteryservice") { defines = [ "BATTERY_MANAGER_SET_LOW_CAPACITY_THRESHOLD" ] } + if (build_variant == "user") { + defines += [ "BATTERY_USER_VERSION" ] + } + subsystem_name = "powermgr" part_name = "battery_manager" } diff --git a/services/native/src/battery_dump.cpp b/services/native/src/battery_dump.cpp index dd292f0..6e971ee 100644 --- a/services/native/src/battery_dump.cpp +++ b/services/native/src/battery_dump.cpp @@ -36,10 +36,12 @@ void BatteryDump::DumpBatteryHelp(int32_t fd) dprintf(fd, "Usage:\n"); dprintf(fd, " -h: dump help\n"); dprintf(fd, " -i: dump battery info\n"); +#ifndef BATTERY_USER_VERSION dprintf(fd, " -u: unplug battery charging state\n"); dprintf(fd, " -r: reset battery state\n"); dprintf(fd, " --capacity : set battery capacity, the capacity range [0, 100]\n"); dprintf(fd, " --uevent : set battery uevent\n"); +#endif } void BatteryDump::DumpCurrentTime(int32_t fd) @@ -103,8 +105,12 @@ bool BatteryDump::MockUnplugged(int32_t fd, sptr& service, const BATTERY_HILOGW(FEATURE_CHARGING, "args cannot be empty or invalid"); return false; } +#ifndef BATTERY_USER_VERSION service->MockUnplugged(); dprintf(fd, "unplugged battery charging state \n"); +#else + dprintf(fd, "[Failed] User version is not support \n"); +#endif return true; } @@ -114,8 +120,12 @@ bool BatteryDump::Reset(int32_t fd, sptr& service, const std::ve BATTERY_HILOGW(FEATURE_CHARGING, "args cannot be empty or invalid"); return false; } +#ifndef BATTERY_USER_VERSION service->Reset(); dprintf(fd, "reset battery state \n"); +#else + dprintf(fd, "[Failed] User version is not support \n"); +#endif return true; } @@ -125,6 +135,7 @@ bool BatteryDump::MockCapacity(int32_t fd, sptr &service, const BATTERY_HILOGW(FEATURE_BATT_INFO, "args cannot be empty or invalid"); return false; } +#ifndef BATTERY_USER_VERSION int32_t capacity = 0; std::string capacityStr = Str16ToStr8(args[1]); if (!StrToInt(capacityStr, capacity)) { @@ -137,6 +148,9 @@ bool BatteryDump::MockCapacity(int32_t fd, sptr &service, const } service->MockCapacity(capacity); dprintf(fd, "battery capacity %d \n", capacity); +#else + dprintf(fd, "[Failed] User version is not support \n"); +#endif return true; } @@ -146,9 +160,13 @@ bool BatteryDump::MockUevent(int32_t fd, sptr &service, const st BATTERY_HILOGW(FEATURE_BATT_INFO, "args cannot be empty or invalid"); return false; } +#ifndef BATTERY_USER_VERSION std::string uevent = Str16ToStr8(args[1]); service->MockUevent(uevent); dprintf(fd, "battery uevent %s \n", uevent.c_str()); +#else + dprintf(fd, "[Failed] User version is not support \n"); +#endif return true; } } // namespace PowerMgr diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index 6079a19..fd68ecd 100644 --- a/test/systemtest/BUILD.gn +++ b/test/systemtest/BUILD.gn @@ -126,6 +126,10 @@ ohos_systemtest("test_battery_event_systemtest") { "safwk:system_ability_fwk", "samgr:samgr_proxy", ] + + if (build_variant == "user") { + defines += [ "BATTERY_USER_VERSION" ] + } } group("systemtest") { diff --git a/test/systemtest/src/battery_event_system_test.cpp b/test/systemtest/src/battery_event_system_test.cpp index 8d75f65..846c7f4 100644 --- a/test/systemtest/src/battery_event_system_test.cpp +++ b/test/systemtest/src/battery_event_system_test.cpp @@ -439,6 +439,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest001, TestSize.Level0) * @tc.name: BatteryEventSystemTest * @tc.desc: Verify the receive the common event */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest002, TestSize.Level0) { shared_ptr subscriber = CommonEventBatteryChangedTest::RegisterEvent(); @@ -451,6 +452,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest002, TestSize.Level0) EXPECT_EQ(CommonEventSupport::COMMON_EVENT_BATTERY_CHANGED, g_action); CommonEventManager::UnSubscribeCommonEvent(subscriber); } +#endif /* * @tc.number: BatteryEventSystemTest003 @@ -458,6 +460,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest002, TestSize.Level0) * @tc.desc: Verify the receive the common event * @tc.require: issueI6KRS8 */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest003, TestSize.Level0) { shared_ptr subscriber = CommonEventBatteryChargingTest::RegisterEvent(); @@ -470,6 +473,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest003, TestSize.Level0) auto ret = CommonEventManager::UnSubscribeCommonEvent(subscriber); EXPECT_TRUE(ret); } +#endif /* * @tc.number: BatteryEventSystemTest004 @@ -477,6 +481,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest003, TestSize.Level0) * @tc.desc: Verify the receive the common event * @tc.require: issueI6KRS8 */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest004, TestSize.Level0) { shared_ptr subscriber = CommonEventBatteryDischargingTest::RegisterEvent(); @@ -489,6 +494,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest004, TestSize.Level0) auto ret = CommonEventManager::UnSubscribeCommonEvent(subscriber); EXPECT_TRUE(ret); } +#endif /* * @tc.number: BatteryEventSystemTest005 @@ -496,6 +502,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest004, TestSize.Level0) * @tc.desc: Verify the receive the common event * @tc.require: issueI6KRS8 */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest005, TestSize.Level0) { shared_ptr subscriber = CommonEventBatteryOkayTest::RegisterEvent(); @@ -508,6 +515,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest005, TestSize.Level0) auto ret = CommonEventManager::UnSubscribeCommonEvent(subscriber); EXPECT_TRUE(ret); } +#endif /* * @tc.number: BatteryEventSystemTest006 @@ -515,6 +523,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest005, TestSize.Level0) * @tc.desc: Verify the receive the common event * @tc.require: issueI6KRS8 */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest006, TestSize.Level0) { shared_ptr subscriber = CommonEventBatteryDisconnectTest::RegisterEvent(); @@ -527,6 +536,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest006, TestSize.Level0) auto ret = CommonEventManager::UnSubscribeCommonEvent(subscriber); EXPECT_TRUE(ret); } +#endif /* * @tc.number: BatteryEventSystemTest007 @@ -534,6 +544,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest006, TestSize.Level0) * @tc.desc: Verify the receive the common event * @tc.require: issueI6KRS8 */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest007, TestSize.Level0) { shared_ptr subscriber = CommonEventBatteryConnectTest::RegisterEvent(); @@ -546,6 +557,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest007, TestSize.Level0) auto ret = CommonEventManager::UnSubscribeCommonEvent(subscriber); EXPECT_TRUE(ret); } +#endif /* * @tc.number: BatteryEventSystemTest008 @@ -553,6 +565,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest007, TestSize.Level0) * @tc.desc: Verify the receive the common event * @tc.require: issueI6KRS8 */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest008, TestSize.Level0) { shared_ptr subscriber = CommonEventChargeTypeChangedTest::RegisterEvent(); @@ -565,6 +578,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest008, TestSize.Level0) auto ret = CommonEventManager::UnSubscribeCommonEvent(subscriber); EXPECT_TRUE(ret); } +#endif /* * @tc.number: BatteryEventSystemTest009 @@ -572,6 +586,7 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest008, TestSize.Level0) * @tc.desc: Test capacity and unplugged dump, verify the receive the common event * @tc.require: issueI6Z8RB */ +#ifndef BATTERY_USER_VERSION HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest009, TestSize.Level0) { shared_ptr subscriber = CommonEventDumpCapacityTest::RegisterEvent(); @@ -623,4 +638,5 @@ HWTEST_F(BatteryEventSystemTest, BatteryEventSystemTest009, TestSize.Level0) auto ret = CommonEventManager::UnSubscribeCommonEvent(subscriber); EXPECT_TRUE(ret); } +#endif } // namespace -- Gitee