diff --git a/services/BUILD.gn b/services/BUILD.gn index ce76a4befd2e8fe4a9500d1c5d3deb7d1e6d1dd9..b5fdde62436b37a7524c971b355dd6a146e35251 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -38,8 +38,6 @@ ohos_shared_library("time_system_ability") { configs += [ "//build/config/gcc:symbol_visibility_hidden" ] sources = [ "./time_system_ability.cpp", - "dfx/src/time_cmd_dispatcher.cpp", - "dfx/src/time_cmd_parse.cpp", "dfx/src/time_sysevent.cpp", "ipc/proxy/timer_call_back_proxy.cpp", "ipc/stub/time_service_stub.cpp", @@ -82,6 +80,14 @@ ohos_shared_library("time_system_ability") { "samgr:samgr_proxy", ] defines = [] + if (time_service_hidumper_able) { + defines += [ "HIDUMPER_ENABLE" ] + sources += [ + "dfx/src/time_cmd_dispatcher.cpp", + "dfx/src/time_cmd_parse.cpp", + ] + } + if (device_standby) { external_deps += [ "device_standby:standby_innerkits" ] defines += [ "DEVICE_STANDBY_ENABLE" ] @@ -111,8 +117,6 @@ ohos_static_library("time_system_ability_static") { configs += [ "//build/config/gcc:symbol_visibility_hidden" ] sources = [ "./time_system_ability.cpp", - "dfx/src/time_cmd_dispatcher.cpp", - "dfx/src/time_cmd_parse.cpp", "dfx/src/time_sysevent.cpp", "ipc/proxy/timer_call_back_proxy.cpp", "ipc/stub/time_service_stub.cpp", @@ -155,6 +159,14 @@ ohos_static_library("time_system_ability_static") { "samgr:samgr_proxy", ] defines = [] + if (time_service_hidumper_able) { + defines += [ "HIDUMPER_ENABLE" ] + sources += [ + "dfx/src/time_cmd_dispatcher.cpp", + "dfx/src/time_cmd_parse.cpp", + ] + } + if (device_standby) { external_deps += [ "device_standby:standby_innerkits" ] defines += [ "DEVICE_STANDBY_ENABLE" ] diff --git a/services/time_system_ability.cpp b/services/time_system_ability.cpp index a45dea11c7f9f527b65cc4bc138d69e1d376da13..b616a3d68d07f9e5e7b341271182800436797d43 100644 --- a/services/time_system_ability.cpp +++ b/services/time_system_ability.cpp @@ -128,6 +128,7 @@ sptr TimeSystemAbility::GetInstance() return instance_; } +#ifdef HIDUMPER_ENABLE void TimeSystemAbility::InitDumpCmd() { auto cmdTime = std::make_shared(std::vector({ "-time" }), @@ -179,6 +180,7 @@ void TimeSystemAbility::InitDumpCmd() [this](int fd, const std::vector &input) { DumpAdjustTime(fd, input); }); TimeCmdDispatcher::GetInstance().RegisterCommand(cmdAdjustTimer); } +#endif void TimeSystemAbility::OnStart() { @@ -204,7 +206,9 @@ void TimeSystemAbility::OnStart() AddSystemAbilityListener(POWER_MANAGER_SERVICE_ID); AddSystemAbilityListener(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID); AddSystemAbilityListener(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN); +#ifdef HIDUMPER_ENABLE InitDumpCmd(); +#endif if (Init() != ERR_OK) { auto callback = [this]() { sleep(INIT_INTERVAL); @@ -547,6 +551,7 @@ int32_t TimeSystemAbility::SetTime(int64_t time, APIVersion apiVersion) return ERR_OK; } +#ifdef HIDUMPER_ENABLE int TimeSystemAbility::Dump(int fd, const std::vector &args) { int uid = static_cast(IPCSkeleton::GetCallingUid()); @@ -667,6 +672,7 @@ void TimeSystemAbility::DumpAdjustTime(int fd, const std::vector &i dprintf(fd, "\n - dump adjust timer info:\n"); TimerProxy::GetInstance().ShowAdjustTimerInfo(fd); } +#endif int TimeSystemAbility::SetRtcTime(time_t sec) { diff --git a/services/time_system_ability.h b/services/time_system_ability.h index 17ff6d80a4b572444169fa5651972ea79780ca9c..d5c2524a87484d2cd70f54f246f80b60d0ffd3a3 100644 --- a/services/time_system_ability.h +++ b/services/time_system_ability.h @@ -23,8 +23,10 @@ #include "event_handler.h" #include "securec.h" #include "system_ability.h" +#ifdef HIDUMPER_ENABLE #include "time_cmd_dispatcher.h" #include "time_cmd_parse.h" +#endif #include "time_service_notify.h" #include "time_service_stub.h" #include "timer_manager.h" @@ -72,6 +74,7 @@ public: bool ResetAllProxy() override; int32_t GetNtpTimeMs(int64_t &time) override; int32_t GetRealTimeMs(int64_t &time) override; +#ifdef HIDUMPER_ENABLE int Dump(int fd, const std::vector &args) override; void DumpAllTimeInfo(int fd, const std::vector &input); void DumpTimerInfo(int fd, const std::vector &input); @@ -84,6 +87,7 @@ public: void DumpProxyDelayTime(int fd, const std::vector &input); void DumpAdjustTime(int fd, const std::vector &input); void InitDumpCmd(); +#endif void RegisterCommonEventSubscriber(); bool RecoverTimer(); diff --git a/services/timer/include/timer_manager.h b/services/timer/include/timer_manager.h index 4d473f595cd208fa059ebb5dffb93d344889e851..dfa2a3e6c93d56dc253dbd19602eb4f9b55f3b73 100644 --- a/services/timer/include/timer_manager.h +++ b/services/timer/include/timer_manager.h @@ -59,10 +59,12 @@ public: bool AdjustTimer(bool isAdjust, uint32_t interval) override; void SetTimerExemption(const std::unordered_set &nameArr, bool isExemption) override; bool ResetAllProxy() override; +#ifdef HIDUMPER_ENABLE bool ShowTimerEntryMap(int fd); bool ShowTimerEntryById(int fd, uint64_t timerId); bool ShowTimerTriggerById(int fd, uint64_t timerId); bool ShowIdleTimerInfo(int fd); +#endif void OnUserRemoved(int userId); void OnPackageRemoved(int uid); ~TimerManager() override; diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index 59c060ae29f66851a486825cd8e6f281932ef63c..4f1ef53fd3752175f2352de2d925bee684b94517 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -1238,6 +1238,7 @@ steady_clock::time_point MaxTriggerTime(steady_clock::time_point now, return triggerAtTime + milliseconds(static_cast(BATCH_WINDOW_COE * futurity.count())); } +#ifdef HIDUMPER_ENABLE bool TimerManager::ShowTimerEntryMap(int fd) { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); @@ -1323,6 +1324,7 @@ bool TimerManager::ShowIdleTimerInfo(int fd) TIME_HILOGD(TIME_MODULE_SERVICE, "end."); return true; } +#endif void TimerManager::OnUserRemoved(int userId) { diff --git a/test/fuzztest/timeservice_fuzzer/timereceivedmessage_fuzzer/timereceivedmessage_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timereceivedmessage_fuzzer/timereceivedmessage_fuzzer.cpp index 3a92a493ccd885c087a2c110b1bbc21aaf6b357e..b7c78350f584fb350491d0d1b04c69dccd5a8d39 100644 --- a/test/fuzztest/timeservice_fuzzer/timereceivedmessage_fuzzer/timereceivedmessage_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timereceivedmessage_fuzzer/timereceivedmessage_fuzzer.cpp @@ -37,6 +37,7 @@ constexpr size_t THRESHOLD = 4; constexpr int32_t NTP_PACKAGE_SIZE = 48; const std::u16string TIMESERVICE_INTERFACE_TOKEN = u"ohos.miscservices.time.ITimeService"; +#ifdef HIDUMPER_ENABLE bool FuzzTimeDump(const uint8_t *rawData, size_t size) { std::vector args; @@ -46,6 +47,7 @@ bool FuzzTimeDump(const uint8_t *rawData, size_t size) TimeSystemAbility::GetInstance()->Dump(fd, args); return true; } +#endif bool FuzzTimeReceivedMessage(const uint8_t *data, size_t size) { @@ -66,7 +68,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) return 0; } /* Run your code on data */ +#ifdef HIDUMPER_ENABLE OHOS::FuzzTimeDump(data, size); +#endif OHOS::FuzzTimeReceivedMessage(data, size); return 0; } \ No newline at end of file diff --git a/test/unittest/service_test/src/time_dfx_test.cpp b/test/unittest/service_test/src/time_dfx_test.cpp index 228e28156a0b7e8fa8bfe1b20c96f16dc0472600..fb80541fdd691750abb4aebec149d53fd4ca6387 100644 --- a/test/unittest/service_test/src/time_dfx_test.cpp +++ b/test/unittest/service_test/src/time_dfx_test.cpp @@ -40,7 +40,9 @@ using namespace OHOS::MiscServices; using namespace OHOS::Security::AccessToken; constexpr const uint16_t EACH_LINE_LENGTH = 100; +#ifdef HIDUMPER_ENABLE constexpr const char *CMD = "hidumper -s 3702 -a"; +#endif class TimeDfxTest : public testing::Test { public: @@ -83,6 +85,7 @@ bool TimeDfxTest::ExecuteCmd(const std::string &cmd, std::string &result) return true; } +#ifdef HIDUMPER_ENABLE /** * @tc.name: DumpAllTimeInfo001 * @tc.desc: dump all time info @@ -339,5 +342,6 @@ HWTEST_F(TimeDfxTest, DumpAdjustTime001, TestSize.Level0) EXPECT_NE(result.find("dump adjust time"), std::string::npos); TIME_HILOGD(TIME_MODULE_SERVICE, "-adjust -a: %{public}s", result.c_str()); } +#endif } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/service_test/src/time_service_test.cpp b/test/unittest/service_test/src/time_service_test.cpp index 729be7d3aa11eb4b79bafe09db0a1ccdddc7204d..1716552250833a7b03dc84d5d825ded0a504a988 100644 --- a/test/unittest/service_test/src/time_service_test.cpp +++ b/test/unittest/service_test/src/time_service_test.cpp @@ -1327,6 +1327,7 @@ HWTEST_F(TimeServiceTest, TimerManager007, TestSize.Level0) TimerManager::GetInstance()->mPendingIdleUntil_ = alarm; } +#ifdef HIDUMPER_ENABLE /** * @tc.name: TimerManager008. * @tc.desc: test ShowTimerEntryById TIMER_ID not in timerEntryMap_. @@ -1356,6 +1357,7 @@ HWTEST_F(TimeServiceTest, TimerManager009, TestSize.Level0) TimerManager::GetInstance()->DestroyTimer(TIMER_ID); EXPECT_TRUE(res); } +#endif /** * @tc.name: TimerManager010. diff --git a/time.gni b/time.gni index 509f66c9e241b727163879ab753b238478b29028..4c79cb9f4ff8fb8d8cabef48ee0b008b13b4848e 100755 --- a/time.gni +++ b/time.gni @@ -26,7 +26,8 @@ time_sanitize_debug = false declare_args() { device_standby = true - time_hicollie_able = true + time_service_hicollie_able = true + time_service_hidumper_able = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_device_standby)) { device_standby = false diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 9ca13e5028ba022b193fa4e54f763ea59579a1b9..db7a9e256c1358d907f1f9f673e73b5136d16bec 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -44,7 +44,7 @@ ohos_source_set("time_utils") { ] defines = [] - if (time_hicollie_able) { + if (time_service_hicollie_able) { external_deps += [ "hicollie:libhicollie" ] defines += [ "HICOLLIE_ENABLE" ] }