diff --git a/bundle.json b/bundle.json index b23b89f7d10324843e2812da0c8ac32a13633bb6..ee2c86688bc1e6a2827141856e55c6d22d72b258 100644 --- a/bundle.json +++ b/bundle.json @@ -44,6 +44,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 deeae087e8b58e28acac19bd1ed50a57dbd29bcd..91eb29b3a3ee8b8d4ef33132a1560b5246e6724a 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -55,6 +55,7 @@ ohos_shared_library("batteryservice") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "drivers_interface_battery:libbattery_proxy_2.0", + "eventhandler:libeventhandler", "ffrt:libffrt", "hdf_core:libhdi", "hdf_core:libpub_utils", @@ -89,6 +90,10 @@ ohos_shared_library("batteryservice") { external_deps += [ "config_policy:configpolicy_util" ] } + 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 dd292f00fe8e479645c35fd0ef175496575876d8..6e971eecb3dbec06c4bf688ce002f4977c04dbe0 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 6079a1967f4a2da69c555862130f4da439fb260d..fd68ecde976417f817b6f377f53ef41a0bd00f0d 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 8d75f652b044e6086453f759863630277690a551..846c7f44795c257779262a8c5784dd811d48b20d 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