diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index eef33d68af4c780239d92890fb6991ff69bfcca7..ac2199a79b2fc02305d542ee95dd918a2de26a00 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -15,11 +15,9 @@ import("../../time.gni") config("time_client_config") { include_dirs = [ - "${time_service_path}/ipc/proxy/inner_api_include", - "${time_service_path}/ipc/stub/inner_api_include", - "${time_service_path}/ipc/base", "include", "${time_utils_path}/native/include", + "${time_service_path}/time/include", "${time_service_path}/time/include/inner_api_include", "${time_service_path}/timer/include", ] @@ -28,18 +26,21 @@ config("time_client_config") { ohos_shared_library("time_client") { sources = [ "${api_path}/src/time_service_client.cpp", - "${time_service_path}/ipc/proxy/time_service_proxy.cpp", - "${time_service_path}/ipc/stub/timer_call_back_stub.cpp", "${time_service_path}/time/src/itimer_info.cpp", + "${time_service_path}/time/src/simple_timer_info.cpp", "${time_service_path}/time/src/timer_call_back.cpp", ] configs = [ ":time_client_config" ] configs += [ "//build/config/gcc:symbol_visibility_hidden" ] - public_configs = [ ":time_client_config" ] + public_configs = [ + ":time_client_config", + "${time_service_path}:time_service_gen_config", + ] innerapi_tags = [ "platformsdk", "sasdk", ] + deps = [ "${time_service_path}:timeservice_proxy" ] external_deps = [ "ability_runtime:abilitykit_native", "ability_runtime:extensionkit_native", diff --git a/interfaces/inner_api/include/time_service_client.h b/interfaces/inner_api/include/time_service_client.h index 25057cea1a1a2a1c25c30f145dc2ee1519804690..cba461c06765cc2e912b489a970edcabdb338f74 100644 --- a/interfaces/inner_api/include/time_service_client.h +++ b/interfaces/inner_api/include/time_service_client.h @@ -22,7 +22,7 @@ #include "itimer_info.h" #include "refbase.h" -#include "time_service_interface.h" +#include "itime_service.h" #include "iservice_registry.h" #include "system_ability_definition.h" #include "system_ability_status_change_stub.h" @@ -469,6 +469,7 @@ private: sptr GetProxy(); void SetProxy(sptr proxy); void CheckNameLocked(std::string name); + int32_t ConvertErrCode(int32_t errCode); sptr listener_; static std::mutex instanceLock_; diff --git a/interfaces/inner_api/include/time_service_interface.h b/interfaces/inner_api/include/time_service_interface.h deleted file mode 100644 index ba5ac4b5c507a2f3978d59abf6429b4f4bdd2a47..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/include/time_service_interface.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#ifndef SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H -#define SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H - -#include "iremote_broker.h" -#include "itimer_info.h" -#include "want_agent_helper.h" -#include - -namespace OHOS { -namespace MiscServices { -class ITimeService : public IRemoteBroker { -public: - - enum APIVersion : int8_t { - API_VERSION_7 = 0, - API_VERSION_9 = 1, - }; - /** - * SetTime - * - * @param time int64_t set milliseconds - * @return int32_t ERR_OK on success, other on failure. - */ - virtual int32_t SetTime(int64_t time, APIVersion apiVersion = APIVersion::API_VERSION_7) = 0; - /** - * SetTimeZone - * - * @param timezoneId std::string &timezoneId string - * @return int32_t ERR_OK on success, other on failure. - */ - virtual int32_t SetTimeZone(const std::string &timezoneId, APIVersion apiVersion = APIVersion::API_VERSION_7) = 0; - - /** - * GetTimeZone - * - * @param timezoneId std::string &timezoneId string - * @return int32_t ERR_OK on success, other on failure. - */ - virtual int32_t GetTimeZone(std::string &timezoneId) = 0; - - /** - * GetThreadTimeMs - * - * @param times result of times ,unit: millisecond - * @return int32_t ERR_OK on success, other on failure. - */ - virtual int32_t GetThreadTimeMs(int64_t ×) = 0; - - /** - * GetThreadTimeNs - * - * @param times result of times ,unit: Nanosecond - * @return int32_t ERR_OK on success, other on failure. - */ - virtual int32_t GetThreadTimeNs(int64_t ×) = 0; - - /** - * CreateTimer - * - * @param type timer type - * @param repeat is repeat or not - * @param timerCallback remoteobject - * @return uint64_t > 0 on success, == 0 failure. - */ - virtual int32_t CreateTimer(const std::shared_ptr &timerOptions, sptr &timerCallback, - uint64_t &timerId) = 0; - - /** - * StartTimer - * - * @param timerId indicate timerId - * @param treggerTime trigger times - * @return bool true on success, false on failure. - */ - virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0; - - /** - * StopTimer - * - * @param timerId indicate timerId - * @return bool true on success, false on failure. - */ - virtual int32_t StopTimer(uint64_t timerId) = 0; - - /** - * DestroyTimer - * - * @param timerId indicate timerId - * @param isAsync indicate is async or not. - * @return bool true on success, false on failure. - */ - virtual int32_t DestroyTimer(uint64_t timerId, bool isAsync = false) = 0; - - /** - * ProxyTimer - * @param uid the uid - * @param pidList the pidlist. Passing an empty vector means proxy by uid. - * Max size is 1024. - * @param isProxy true if proxy, false if not proxy - * @param needRetrigger true if need retrigger, false if not and stop timer. - * @return bool true on success, false on failure. - */ - virtual bool ProxyTimer(int32_t uid, std::set pidList, bool isProxy, bool needRetrigger) = 0; - - /** - * AdjustTimer - * @param isAdjust true if adjust, false if not adjust. - * @param interval adjust period. - * @return int32_t return error code. - */ - virtual int32_t AdjustTimer(bool isAdjust, uint32_t interval, uint32_t delta) = 0; - - /** - * SetTimerExemption - * @param nameArr list for bundle name or proccess name. - * @param isExemption exemption or ctrl. - * @return int32_t return error code. - */ - virtual int32_t SetTimerExemption(const std::unordered_set &nameArr, bool isExemption) = 0; - - /** - * ResetAllProxy - * @return bool true on success, false on failure. - */ - virtual bool ResetAllProxy() = 0; - - /** - * @brief GetNtpTimeMs - * - * Obtain the wall time through ntp. - * - * @param time the wall time(the UTC time from 1970 0H:0M:0S) in milliseconds. - * @return int32_t return error code. - */ - virtual int32_t GetNtpTimeMs(int64_t &time) = 0; - - /** - * @brief GetRealTimeMs - * - * Obtain the wall time calculated based on the last NTP time. - * - * @param time the wall time(the UTC time from 1970 0H:0M:0S) in milliseconds. - * @return int32_t return error code. - */ - virtual int32_t GetRealTimeMs(int64_t &time) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.time.ITimeService"); -}; -} // namespace MiscServices -} // namespace OHOS -#endif // SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H \ No newline at end of file diff --git a/interfaces/inner_api/src/time_service_client.cpp b/interfaces/inner_api/src/time_service_client.cpp index 17373dd292ed5184cdb153c917f73483e46bfb71..648ef7b3955f1b2288836ce4979768c5cf3fabd8 100644 --- a/interfaces/inner_api/src/time_service_client.cpp +++ b/interfaces/inner_api/src/time_service_client.cpp @@ -24,6 +24,7 @@ #include "time_common.h" #include "time_service_proxy.h" #include "timer_call_back.h" +#include "simple_timer_info.h" namespace OHOS { namespace MiscServices { @@ -64,7 +65,12 @@ void TimeServiceClient::TimeServiceListener::OnAddSystemAbility( auto iter = recoverTimer.begin(); for (; iter != recoverTimer.end(); iter++) { auto timerId = iter->first; - proxy->CreateTimer(iter->second->timerInfo, timerCallbackInfoObject, timerId); + auto timerInfo = iter->second->timerInfo; + SimpleTimerInfo *simpleTimerInfo = new (std::nothrow) SimpleTimerInfo(timerInfo->name, timerInfo->type, + timerInfo->repeat, timerInfo->disposable, timerInfo->autoRestore, timerInfo->interval, + timerInfo->wantAgent); + if (simpleTimerInfo == nullptr) { return; } + proxy->CreateTimer(*simpleTimerInfo, timerCallbackInfoObject, timerId); if (iter->second->state == 1) { proxy->StartTimer(timerId, iter->second->triggerTime); } @@ -179,7 +185,7 @@ bool TimeServiceClient::SetTime(int64_t time) if (proxy == nullptr) { return false; } - return proxy->SetTime(time) == ERR_OK; + return proxy->SetTime(time, APIVersion::API_VERSION_7) == ERR_OK; } bool TimeServiceClient::SetTime(int64_t milliseconds, int32_t &code) @@ -193,7 +199,8 @@ bool TimeServiceClient::SetTime(int64_t milliseconds, int32_t &code) code = E_TIME_NULLPTR; return false; } - code = proxy->SetTime(milliseconds); + code = proxy->SetTime(milliseconds, APIVersion::API_VERSION_7); + code = ConvertErrCode(code); return code == ERR_OK; } @@ -206,7 +213,9 @@ int32_t TimeServiceClient::SetTimeV9(int64_t time) if (proxy == nullptr) { return E_TIME_NULLPTR; } - return proxy->SetTime(time, ITimeService::API_VERSION_9); + int32_t code = proxy->SetTime(time, APIVersion::API_VERSION_9); + code = ConvertErrCode(code); + return code; } bool TimeServiceClient::SetTimeZone(const std::string &timezoneId) @@ -218,7 +227,7 @@ bool TimeServiceClient::SetTimeZone(const std::string &timezoneId) if (proxy == nullptr) { return false; } - return proxy->SetTimeZone(timezoneId) == ERR_OK; + return proxy->SetTimeZone(timezoneId, APIVersion::API_VERSION_7) == ERR_OK; } bool TimeServiceClient::SetTimeZone(const std::string &timezoneId, int32_t &code) @@ -232,7 +241,8 @@ bool TimeServiceClient::SetTimeZone(const std::string &timezoneId, int32_t &code code = E_TIME_NULLPTR; return false; } - code = proxy->SetTimeZone(timezoneId); + code = proxy->SetTimeZone(timezoneId, APIVersion::API_VERSION_7); + code = ConvertErrCode(code); TIME_HILOGD(TIME_MODULE_CLIENT, "settimezone end"); return code == ERR_OK; } @@ -246,7 +256,9 @@ int32_t TimeServiceClient::SetTimeZoneV9(const std::string &timezoneId) if (proxy == nullptr) { return E_TIME_NULLPTR; } - return proxy->SetTimeZone(timezoneId, ITimeService::API_VERSION_9); + int32_t code = proxy->SetTimeZone(timezoneId, APIVersion::API_VERSION_9); + code = ConvertErrCode(code); + return code; } uint64_t TimeServiceClient::CreateTimer(std::shared_ptr timerOptions) @@ -299,8 +311,13 @@ int32_t TimeServiceClient::CreateTimerV9(std::shared_ptr timerOption if (proxy == nullptr) { return E_TIME_NULLPTR; } - auto errCode = proxy->CreateTimer(timerOptions, timerCallbackInfoObject, timerId); + SimpleTimerInfo *simpleTimerInfo = new (std::nothrow) SimpleTimerInfo(timerOptions->name, timerOptions->type, + timerOptions->repeat, timerOptions->disposable, timerOptions->autoRestore, timerOptions->interval, + timerOptions->wantAgent); + if (simpleTimerInfo == nullptr) { return E_TIME_NULLPTR; } + int32_t errCode = proxy->CreateTimer(*simpleTimerInfo, timerCallbackInfoObject, timerId); if (errCode != E_TIME_OK) { + errCode = ConvertErrCode(errCode); TIME_HILOGE(TIME_MODULE_CLIENT, "create timer failed, errCode=%{public}d", errCode); return errCode; } @@ -324,8 +341,7 @@ int32_t TimeServiceClient::CreateTimerV9(std::shared_ptr timerOption } TIME_HILOGD(TIME_MODULE_CLIENT, "CreateTimer id: %{public}" PRId64 "", timerId); - auto ret = TimerCallback::GetInstance()->InsertTimerCallbackInfo(timerId, timerOptions); - if (!ret) { + if (!TimerCallback::GetInstance()->InsertTimerCallbackInfo(timerId, timerOptions)) { return E_TIME_DEAL_FAILED; } return errCode; @@ -351,6 +367,7 @@ int32_t TimeServiceClient::StartTimerV9(uint64_t timerId, uint64_t triggerTime) } auto startRet = proxy->StartTimer(timerId, triggerTime); if (startRet != 0) { + startRet = ConvertErrCode(startRet); TIME_HILOGE(TIME_MODULE_CLIENT, "start timer failed: %{public}d", startRet); return startRet; } @@ -383,6 +400,7 @@ int32_t TimeServiceClient::StopTimerV9(uint64_t timerId) } auto stopRet = proxy->StopTimer(timerId); if (stopRet != 0) { + stopRet = ConvertErrCode(stopRet); TIME_HILOGE(TIME_MODULE_CLIENT, "stop timer failed: %{public}d", stopRet); return stopRet; } @@ -412,8 +430,9 @@ int32_t TimeServiceClient::DestroyTimerV9(uint64_t timerId) if (proxy == nullptr) { return E_TIME_NULLPTR; } - auto errCode = proxy->DestroyTimer(timerId, false); + auto errCode = proxy->DestroyTimer(timerId); if (errCode != 0) { + errCode = ConvertErrCode(errCode); TIME_HILOGE(TIME_MODULE_CLIENT, "destroy timer failed: %{public}d", errCode); return errCode; } @@ -451,7 +470,7 @@ int32_t TimeServiceClient::DestroyTimerAsyncV9(uint64_t timerId) return E_TIME_NULLPTR; } - auto errCode = proxy->DestroyTimer(timerId, true); + auto errCode = proxy->DestroyTimerAsync(timerId); if (errCode != 0) { TIME_HILOGE(TIME_MODULE_CLIENT, "destroy timer failed: %{public}d", errCode); return errCode; @@ -747,7 +766,10 @@ bool TimeServiceClient::ProxyTimer(int32_t uid, std::set pidList, bool isPr if (proxy == nullptr) { return false; } - return proxy->ProxyTimer(uid, pidList, isProxy, needRetrigger); + std::vector pidVector; + std::copy(pidList.begin(), pidList.end(), std::back_inserter(pidVector)); + auto errCode = proxy->ProxyTimer(uid, pidVector, isProxy, needRetrigger); + return errCode == E_TIME_OK; } int32_t TimeServiceClient::AdjustTimer(bool isAdjust, uint32_t interval, uint32_t delta) @@ -760,7 +782,9 @@ int32_t TimeServiceClient::AdjustTimer(bool isAdjust, uint32_t interval, uint32_ if (proxy == nullptr) { return E_TIME_NULLPTR; } - return proxy->AdjustTimer(isAdjust, interval, delta); + auto code = proxy->AdjustTimer(isAdjust, interval, delta); + code = ConvertErrCode(code); + return code; } int32_t TimeServiceClient::SetTimerExemption(const std::unordered_set &nameArr, bool isExemption) @@ -773,7 +797,15 @@ int32_t TimeServiceClient::SetTimerExemption(const std::unordered_setSetTimerExemption(nameArr, isExemption); + if (nameArr.empty()) { + TIME_HILOGE(TIME_MODULE_CLIENT, "Nothing need cache"); + return E_TIME_NOT_FOUND; + } + std::vector nameVector; + std::copy(nameArr.begin(), nameArr.end(), std::back_inserter(nameVector)); + auto code = proxy->SetTimerExemption(nameVector, isExemption); + code = ConvertErrCode(code); + return code; } bool TimeServiceClient::ResetAllProxy() @@ -787,7 +819,8 @@ bool TimeServiceClient::ResetAllProxy() if (proxy == nullptr) { return false; } - return proxy->ResetAllProxy(); + auto code = proxy->ResetAllProxy(); + return code == ERR_OK; } int32_t TimeServiceClient::GetNtpTimeMs(int64_t &time) @@ -799,7 +832,9 @@ int32_t TimeServiceClient::GetNtpTimeMs(int64_t &time) if (proxy == nullptr) { return E_TIME_NULLPTR; } - return proxy->GetNtpTimeMs(time); + auto code = proxy->GetNtpTimeMs(time); + code = ConvertErrCode(code); + return code; } int32_t TimeServiceClient::GetRealTimeMs(int64_t &time) @@ -811,7 +846,23 @@ int32_t TimeServiceClient::GetRealTimeMs(int64_t &time) if (proxy == nullptr) { return E_TIME_NULLPTR; } - return proxy->GetRealTimeMs(time); + auto code = proxy->GetRealTimeMs(time); + code = ConvertErrCode(code); + return code; +} + +int32_t TimeServiceClient::ConvertErrCode(int32_t errCode) +{ + switch (errCode) { + case ERR_INVALID_VALUE: + return E_TIME_WRITE_PARCEL_ERROR; + case ERR_INVALID_DATA: + return E_TIME_WRITE_PARCEL_ERROR; + case E_TIME_NULLPTR: + return E_TIME_DEAL_FAILED; + default: + return errCode; + } } sptr TimeServiceClient::GetProxy() diff --git a/services/BUILD.gn b/services/BUILD.gn index d506cf65ca1c72299c9b2294b715a1e51cbec6f8..8fc4ade9d285f9c4f3deda7c05ef2713c2945a95 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -11,21 +11,23 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("../time.gni") +config("time_service_gen_config") { + include_dirs = [ "${target_gen_dir}" ] +} + config("time_service_config") { visibility = [ ":*" ] include_dirs = [ + "${target_gen_dir}", "${api_path}/include", "../utils/native/include", "time/include", "time/include/inner_api_include", "timer/include", "dfx/include", - "ipc/base", - "ipc/proxy", - "ipc/stub", - "ipc/stub/inner_api_include", "${time_service_path}", ] cflags = [ "-fvisibility=hidden" ] @@ -38,6 +40,37 @@ config("time_service_config") { ] } +idl_gen_interface("timeservice_interface") { + sources = [ "ITimeService.idl" ] + sources_callback = [ "ITimerCallback.idl" ] + log_domainid = "0xD0001C41" + log_tag = "TimeClient" + subsystem_name = "time" + part_name = "time_service" +} + +ohos_source_set("timeservice_proxy") { + configs = [ ":time_service_config" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":timeservice_interface") + sources = filter_include(output_values, [ "*callback_stub.cpp" ]) + sources += filter_include(output_values, [ "*service_proxy.cpp" ]) + + deps = [ ":timeservice_interface" ] + external_deps = [ + "ability_runtime:wantagent_innerkits", + "hilog:libhilog", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + subsystem_name = "time" + part_name = "time_service" +} + ohos_shared_library("time_system_ability") { configs = [ "${time_utils_path}:utils_config" ] configs += [ ":time_service_config" ] @@ -45,8 +78,6 @@ ohos_shared_library("time_system_ability") { sources = [ "./time_system_ability.cpp", "dfx/src/time_sysevent.cpp", - "ipc/proxy/timer_call_back_proxy.cpp", - "ipc/stub/time_service_stub.cpp", "time/src/event_manager.cpp", "time/src/itimer_info.cpp", "time/src/ntp_trusted_time.cpp", @@ -63,8 +94,14 @@ ohos_shared_library("time_system_ability") { "timer/src/timer_manager.cpp", "timer/src/timer_proxy.cpp", ] + output_values = get_target_outputs(":timeservice_interface") + sources += filter_include(output_values, [ "*service_stub.cpp" ]) + sources += filter_include(output_values, [ "*callback_proxy.cpp" ]) - deps = [ "${time_utils_path}:time_utils" ] + deps = [ + ":timeservice_interface", + "${time_utils_path}:time_utils", + ] external_deps = [ "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", @@ -129,8 +166,6 @@ ohos_static_library("time_system_ability_static") { sources = [ "./time_system_ability.cpp", "dfx/src/time_sysevent.cpp", - "ipc/proxy/timer_call_back_proxy.cpp", - "ipc/stub/time_service_stub.cpp", "time/src/event_manager.cpp", "time/src/itimer_info.cpp", "time/src/ntp_trusted_time.cpp", @@ -147,8 +182,15 @@ ohos_static_library("time_system_ability_static") { "timer/src/timer_manager.cpp", "timer/src/timer_proxy.cpp", ] - - deps = [ "${time_utils_path}:time_utils" ] + output_values = get_target_outputs(":timeservice_interface") + print("time_system_ability_static output_values:", output_values) + sources += filter_include(output_values, [ "*service_stub.cpp" ]) + sources += filter_include(output_values, [ "*callback_proxy.cpp" ]) + + deps = [ + ":timeservice_interface", + "${time_utils_path}:time_utils", + ] external_deps = [ "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", diff --git a/services/ipc/stub/inner_api_include/timer_call_back_stub.h b/services/ITimeService.idl similarity index 30% rename from services/ipc/stub/inner_api_include/timer_call_back_stub.h rename to services/ITimeService.idl index b4b248e3b9a841d24c7a75300d9ae6f43643e791..67ff695e59f450b4f8abc2576d6cf0889fffa529 100644 --- a/services/ipc/stub/inner_api_include/timer_call_back_stub.h +++ b/services/ITimeService.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,28 +13,25 @@ * limitations under the License. */ -#ifndef TIMER_CALL_BACK_STUB_H -#define TIMER_CALL_BACK_STUB_H - -#include -#include -#include - -#include "itimer_call_back.h" -#include "time_common.h" - -namespace OHOS { -namespace MiscServices { -class TimerCallbackStub : public IRemoteStub { -public: - DISALLOW_COPY_AND_MOVE(TimerCallbackStub); - TimerCallbackStub() = default; - virtual ~TimerCallbackStub() = default; - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int OnTriggerStub(MessageParcel &data); -}; -} // namespace MiscServices -} // namespace OHOS -#endif // TIMER_CALL_BACK_STUB_H \ No newline at end of file +import ITimerCallback; +sequenceable OHOS.IRemoteObject; +sequenceable SimpleTimerInfo..OHOS.MiscServices.SimpleTimerInfo; +sequenceable OHOS.AbilityRuntime.WantAgent.WantAgent; +interface OHOS.MiscServices.ITimeService { + void SetTime([in] long time, [in] byte apiVersion); + void SetTimeZone([in] String timezoneId, [in] byte apiVersion); + void GetTimeZone([out] String timezoneId); + void GetThreadTimeMs([out] long time); + void GetThreadTimeNs([out] long time); + void CreateTimer([in] SimpleTimerInfo simpleTimerInfo, [in] IRemoteObject timerCallback, [out] unsigned long timerId); + void StartTimer([in] unsigned long timerId, [in] unsigned long triggerTime); + void StopTimer([in] unsigned long timerId); + void DestroyTimer([in] unsigned long timerId); + [oneway] void DestroyTimerAsync([in] unsigned long timerId); + void ProxyTimer([in] int uid, [in] List pidVector, [in] boolean isProxy, [in] boolean needRetrigger); + void ResetAllProxy(); + void AdjustTimer([in] boolean isAdjust, [in] unsigned int interval, [in] unsigned int delta); + void SetTimerExemption([in] List nameArr, [in] boolean isExemption); + void GetNtpTimeMs([out] long time); + void GetRealTimeMs([out] long time); +} diff --git a/services/ipc/base/itimer_call_back.h b/services/ITimerCallback.idl similarity index 49% rename from services/ipc/base/itimer_call_back.h rename to services/ITimerCallback.idl index c73c6787fe841e041f161cb5d8817b374a9cf064..9fb25311958e30e98e3c3637e3f23f47294246fd 100644 --- a/services/ipc/base/itimer_call_back.h +++ b/services/ITimerCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,28 +13,7 @@ * limitations under the License. */ -#ifndef I_TIMER_CALL_BACK_H -#define I_TIMER_CALL_BACK_H - -#include "iremote_broker.h" - -namespace OHOS { -namespace MiscServices { -class ITimerCallback : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.time.ITimerCallback"); - - /** - * trigger timer by id. - * - * @param timerId timerId - * - */ - virtual int32_t NotifyTimer(uint64_t timerId) = 0; - - enum Message { NOTIFY_TIMER = 1 }; -}; -} // namespace MiscServices -} // namespace OHOS - -#endif // I_TIMER_CALL_BACK_H \ No newline at end of file +package OGOS.Callback; +[callback] interface OHOS.MiscServices.ITimerCallback { + void NotifyTimer([in] unsigned long timeId); +} diff --git a/services/ipc/base/time_service_ipc_interface_code.h b/services/ipc/base/time_service_ipc_interface_code.h deleted file mode 100644 index 63a4b90ccdae416f2a32bf9b3ae046bfce99b59a..0000000000000000000000000000000000000000 --- a/services/ipc/base/time_service_ipc_interface_code.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2023 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. - */ - -#ifndef TIME_SERVICE_IPC_INTERFACE_CODE_H -#define TIME_SERVICE_IPC_INTERFACE_CODE_H - -/* SAID: 3702*/ -namespace OHOS { -namespace MiscServices { -enum class TimeServiceIpcInterfaceCode { - SET_TIME = 0, - SET_TIME_ZONE, - GET_TIME_ZONE, - GET_THREAD_TIME_MILLI, - GET_THREAD_TIME_NANO, - CREATE_TIMER, - START_TIMER, - STOP_TIMER, - DESTROY_TIMER, - PROXY_TIMER, - RESET_ALL_PROXY, - ADJUST_TIMER, - SET_TIMER_EXEMPTION, - GET_NTP_TIME_MILLI, - GET_REAL_TIME_MILLI, -}; -} // namespace MiscServices -} // namespace OHOS - -#endif // TIME_SERVICE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/services/ipc/proxy/inner_api_include/time_service_proxy.h b/services/ipc/proxy/inner_api_include/time_service_proxy.h deleted file mode 100644 index 5348a99a5c44b4101f9298a2720cd46dc426c58f..0000000000000000000000000000000000000000 --- a/services/ipc/proxy/inner_api_include/time_service_proxy.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#ifndef SERVICES_INCLUDE_TIME_SERVICE_PROXY_H -#define SERVICES_INCLUDE_TIME_SERVICE_PROXY_H - -#include "iremote_proxy.h" -#include "time_service_interface.h" -#include - -namespace OHOS { -namespace MiscServices { -class TimeServiceProxy : public IRemoteProxy { -public: - explicit TimeServiceProxy(const sptr &object); - ~TimeServiceProxy() = default; - DISALLOW_COPY_AND_MOVE(TimeServiceProxy); - - int32_t SetTime(int64_t time, APIVersion apiVersion = APIVersion::API_VERSION_7) override; - int32_t SetTimeZone(const std::string &timeZoneId, APIVersion apiVersion = APIVersion::API_VERSION_7) override; - int32_t GetTimeZone(std::string &timeZoneId) override; - int32_t GetThreadTimeMs(int64_t ×) override; - int32_t GetThreadTimeNs(int64_t ×) override; - int32_t CreateTimer(const std::shared_ptr &timerOptions, sptr &timerCallback, - uint64_t &timerId) override; - int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) override; - int32_t StopTimer(uint64_t timerId) override; - int32_t DestroyTimer(uint64_t timerId, bool isAsync) override; - bool ProxyTimer(int32_t uid, std::set pidList, bool isProxy, bool needRetrigger) override; - int32_t AdjustTimer(bool isAdjust, uint32_t interval, uint32_t delta) override; - int32_t SetTimerExemption(const std::unordered_set &nameArr, bool isExemption) override; - bool ResetAllProxy() override; - int32_t GetNtpTimeMs(int64_t &time) override; - int32_t GetRealTimeMs(int64_t &time) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace MiscServices -} // namespace OHOS -#endif // SERVICES_INCLUDE_TIME_SERVICE_PROXY_H \ No newline at end of file diff --git a/services/ipc/proxy/time_service_proxy.cpp b/services/ipc/proxy/time_service_proxy.cpp deleted file mode 100644 index d4614ff253262612d7bc58ef3a6167e072ac2fe6..0000000000000000000000000000000000000000 --- a/services/ipc/proxy/time_service_proxy.cpp +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright (C) 2021 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 "time_service_proxy.h" - -#include "iremote_broker.h" -#include "message_option.h" -#include "time_common.h" -#include "time_service_ipc_interface_code.h" - -namespace OHOS { -namespace MiscServices { -using namespace OHOS::HiviewDFX; - -TimeServiceProxy::TimeServiceProxy(const sptr &object) : IRemoteProxy(object) -{ -} - -int32_t TimeServiceProxy::SetTime(int64_t time, APIVersion apiVersion) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteInt64(time)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write time"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteInt8(apiVersion)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write apiVersion"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = - Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::SET_TIME), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "SetTime failed, error code is: %{public}d", result); - return result; - } - return result; -} - -int32_t TimeServiceProxy::CreateTimer(const std::shared_ptr &timerOptions, - sptr &timerCallback, uint64_t &timerId) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteString(timerOptions->name)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write name"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(timerOptions->type)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write type"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteBool(timerOptions->repeat)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write repeat"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteBool(timerOptions->disposable)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write disposable"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteBool(timerOptions->autoRestore)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write autoRestore"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(timerOptions->interval)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write interval"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteBool(timerOptions->wantAgent != nullptr)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write wantAgent status"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (timerOptions->wantAgent != nullptr && !data.WriteParcelable(&(*timerOptions->wantAgent))) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write wantAgent"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteRemoteObject(timerCallback)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write timerCallback"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(timerId)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write timerId"); - return E_TIME_WRITE_PARCEL_ERROR; - } - auto ret = - Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::CREATE_TIMER), data, reply, option); - if (ret == E_TIME_OK) { - timerId = reply.ReadUint64(); - } - return ret; -} - -int32_t TimeServiceProxy::StartTimer(uint64_t timerId, uint64_t triggerTime) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(timerId)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write timerId"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(triggerTime)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write triggerTime"); - return E_TIME_WRITE_PARCEL_ERROR; - } - return Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::START_TIMER), data, reply, option); -} - -int32_t TimeServiceProxy::StopTimer(uint64_t timerId) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(timerId)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write timerId"); - return E_TIME_WRITE_PARCEL_ERROR; - } - return Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::STOP_TIMER), data, reply, option); -} - -int32_t TimeServiceProxy::DestroyTimer(uint64_t timerId, bool isAsync) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(timerId)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write timerId"); - return E_TIME_WRITE_PARCEL_ERROR; - } - - if (isAsync) { - option.SetFlags(MessageOption::TF_ASYNC); - } - return Remote()->SendRequest( - static_cast(TimeServiceIpcInterfaceCode::DESTROY_TIMER), data, reply, option); -} - -int32_t TimeServiceProxy::SetTimeZone(const std::string &timeZoneId, APIVersion apiVersion) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteString(timeZoneId)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write timeZoneId"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteInt8(apiVersion)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write apiVersion"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = - Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::SET_TIME_ZONE), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "SetTimeZone failed, error code is: %{public}d", result); - return result; - } - return result; -} - -int32_t TimeServiceProxy::GetTimeZone(std::string &timeZoneId) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = - Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::GET_TIME_ZONE), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "GetTimeZone failed, error code is: %{public}d", result); - return result; - } - timeZoneId = reply.ReadString(); - return result; -} - -int32_t TimeServiceProxy::GetThreadTimeMs(int64_t ×) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = Remote()->SendRequest( - static_cast(TimeServiceIpcInterfaceCode::GET_THREAD_TIME_MILLI), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "GetThreadTimeMs failed, error code is: %{public}d", result); - return result; - } - times = reply.ReadInt64(); - return result; -} - -int32_t TimeServiceProxy::GetThreadTimeNs(int64_t ×) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = Remote()->SendRequest( - static_cast(TimeServiceIpcInterfaceCode::GET_THREAD_TIME_NANO), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "GetThreadTimeNs failed, error code is: %{public}d", result); - return result; - } - times = reply.ReadInt64(); - return result; -} - -bool TimeServiceProxy::ProxyTimer(int32_t uid, std::set pidList, bool isProxy, bool needRetrigger) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return false; - } - if (!data.WriteInt32(uid)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write uid"); - return false; - } - if (!data.WriteInt32(pidList.size())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write pid size"); - return false; - } - for (std::set::iterator pid = pidList.begin(); pid != pidList.end(); ++pid) { - if (!data.WriteInt32(*pid)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write pid"); - return false; - } - } - if (!data.WriteBool(isProxy)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write isProxy"); - return false; - } - if (!data.WriteBool(needRetrigger)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write needRetrigger"); - return false; - } - - int32_t result = - Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::PROXY_TIMER), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "ProxyTimer failed, error code is: %{public}d", result); - return false; - } - return true; -} - -int32_t TimeServiceProxy::AdjustTimer(bool isAdjust, uint32_t interval, uint32_t delta) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteBool(isAdjust)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write adjust state"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint32(interval)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write interval"); - return E_TIME_WRITE_PARCEL_ERROR; - } - if (!data.WriteUint32(delta)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write delta"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = - Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::ADJUST_TIMER), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Adjust Timer failed, error code is: %{public}d", result); - return result; - } - return result; -} - -int32_t TimeServiceProxy::SetTimerExemption(const std::unordered_set &nameArr, bool isExemption) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - - if (nameArr.empty()) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Nothing need cache"); - return E_TIME_NOT_FOUND; - } - - uint32_t size = static_cast(nameArr.size()); - if (!data.WriteUint32(size)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write size"); - return E_TIME_WRITE_PARCEL_ERROR; - } - - for (auto name : nameArr) { - if (!data.WriteString(name)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write name"); - return E_TIME_WRITE_PARCEL_ERROR; - } - } - - if (!data.WriteBool(isExemption)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write is exemption"); - return E_TIME_WRITE_PARCEL_ERROR; - } - - int32_t result = - Remote()->SendRequest(static_cast(TimeServiceIpcInterfaceCode::SET_TIMER_EXEMPTION), - data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Set Timer Exemption failed, error code is: %{public}d", result); - return result; - } - return result; -} - -bool TimeServiceProxy::ResetAllProxy() -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return false; - } - int32_t result = Remote()->SendRequest( - static_cast(TimeServiceIpcInterfaceCode::RESET_ALL_PROXY), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "ProxyTimer failed, error code is: %{public}d", result); - return false; - } - return true; -} - -int32_t TimeServiceProxy::GetNtpTimeMs(int64_t &time) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = Remote()->SendRequest( - static_cast(TimeServiceIpcInterfaceCode::GET_NTP_TIME_MILLI), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "GetNtpTimeMs failed, error code is: %{public}d", result); - return result; - } - time = reply.ReadInt64(); - return result; -} - -int32_t TimeServiceProxy::GetRealTimeMs(int64_t &time) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write descriptor"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int32_t result = Remote()->SendRequest( - static_cast(TimeServiceIpcInterfaceCode::GET_REAL_TIME_MILLI), data, reply, option); - if (result != ERR_NONE) { - TIME_HILOGE(TIME_MODULE_CLIENT, "GetRealTimeMs failed, error code is: %{public}d", result); - return result; - } - time = reply.ReadInt64(); - return result; -} -} // namespace MiscServices -} // namespace OHOS \ No newline at end of file diff --git a/services/ipc/proxy/timer_call_back_proxy.cpp b/services/ipc/proxy/timer_call_back_proxy.cpp deleted file mode 100644 index 675e4c7d37ede88f2f0901175abe5c065d0bc906..0000000000000000000000000000000000000000 --- a/services/ipc/proxy/timer_call_back_proxy.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 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 "timer_call_back_proxy.h" - -namespace OHOS { -namespace MiscServices { -TimerCallbackProxy::TimerCallbackProxy(const sptr &object) : IRemoteProxy(object) -{ -} - -TimerCallbackProxy::~TimerCallbackProxy() -{ - TIME_HILOGD(TIME_MODULE_CLIENT, "TimerCallbackProxy instance destoryed"); -} - -int32_t TimerCallbackProxy::NotifyTimer(const uint64_t timerId) -{ - TIME_HILOGD(TIME_MODULE_CLIENT, "start id: %{public}" PRId64 "", timerId); - sptr remote = Remote(); - if (remote == nullptr) { - return E_TIME_NULLPTR; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - - if (!data.WriteInterfaceToken(GetDescriptor())) { - TIME_HILOGE(TIME_MODULE_CLIENT, "write descriptor failed!"); - return E_TIME_WRITE_PARCEL_ERROR; - } - - if (!data.WriteUint64(timerId)) { - TIME_HILOGE(TIME_MODULE_CLIENT, "write timerId failed!"); - return E_TIME_WRITE_PARCEL_ERROR; - } - int ret = remote->SendRequest(static_cast(ITimerCallback::Message::NOTIFY_TIMER), data, reply, option); - if (ret != ERR_OK) { - TIME_HILOGE(TIME_MODULE_CLIENT, "SendRequest is failed, error code: %{public}d", ret); - } - return ret; -} -} // namespace MiscServices -} // namespace OHOS diff --git a/services/ipc/proxy/timer_call_back_proxy.h b/services/ipc/proxy/timer_call_back_proxy.h deleted file mode 100644 index b3e141fc0df9b168bf6c4a1ca53b7285aaf49729..0000000000000000000000000000000000000000 --- a/services/ipc/proxy/timer_call_back_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#ifndef TIMER_CALL_BACK_PROXY_H -#define TIMER_CALL_BACK_PROXY_H - -#include -#include -#include - -#include "itimer_call_back.h" -#include "time_common.h" - -namespace OHOS { -namespace MiscServices { -class TimerCallbackProxy : public IRemoteProxy { -public: - explicit TimerCallbackProxy(const sptr &object); - - ~TimerCallbackProxy(); - DISALLOW_COPY_AND_MOVE(TimerCallbackProxy); - int32_t NotifyTimer(const uint64_t timerId) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace MiscServices -} // namespace OHOS - -#endif // TIMER_CALL_BACK_PROXY_H \ No newline at end of file diff --git a/services/ipc/stub/time_service_stub.cpp b/services/ipc/stub/time_service_stub.cpp deleted file mode 100644 index 86108e6606ab82e68f2293de76d7899d6395863e..0000000000000000000000000000000000000000 --- a/services/ipc/stub/time_service_stub.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright (C) 2021 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 "simple_timer_info.h" -#include "time_common.h" -#include "time_xcollie.h" -#include "time_service_stub.h" -#include "ntp_update_time.h" -#include "ntp_trusted_time.h" - -namespace OHOS { -namespace MiscServices { -using namespace OHOS::HiviewDFX; -namespace { -static const uint32_t MAX_EXEMPTION_SIZE = 1000; -static const int MAX_PID_LIST_SIZE = 1024; -} - - -TimeServiceStub::TimeServiceStub() -{ - memberFuncMap_ = { - { TimeServiceIpcInterfaceCode::SET_TIME, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnSetTime(data, reply); } }, - { TimeServiceIpcInterfaceCode::SET_TIME_ZONE, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnSetTimeZone(data, reply); } }, - { TimeServiceIpcInterfaceCode::GET_TIME_ZONE, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnGetTimeZone(data, reply); } }, - { TimeServiceIpcInterfaceCode::GET_THREAD_TIME_MILLI, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnGetThreadTimeMs(data, reply); } }, - { TimeServiceIpcInterfaceCode::GET_THREAD_TIME_NANO, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnGetThreadTimeNs(data, reply); } }, - { TimeServiceIpcInterfaceCode::CREATE_TIMER, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnCreateTimer(data, reply); } }, - { TimeServiceIpcInterfaceCode::START_TIMER, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnStartTimer(data, reply); } }, - { TimeServiceIpcInterfaceCode::STOP_TIMER, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnStopTimer(data, reply); } }, - { TimeServiceIpcInterfaceCode::DESTROY_TIMER, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnDestroyTimer(data, reply); } }, - { TimeServiceIpcInterfaceCode::PROXY_TIMER, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnTimerProxy(data, reply); } }, - { TimeServiceIpcInterfaceCode::ADJUST_TIMER, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnAdjustTimer(data, reply); } }, - { TimeServiceIpcInterfaceCode::SET_TIMER_EXEMPTION, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { - return OnSetTimerExemption(data, reply); } }, - { TimeServiceIpcInterfaceCode::RESET_ALL_PROXY, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnAllProxyReset(data, reply); } }, - { TimeServiceIpcInterfaceCode::GET_NTP_TIME_MILLI, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnGetNtpTimeMs(data, reply); } }, - { TimeServiceIpcInterfaceCode::GET_REAL_TIME_MILLI, - [this] (MessageParcel &data, MessageParcel &reply) -> int32_t { return OnGetRealTimeMs(data, reply); } }, - }; -} - -TimeServiceStub::~TimeServiceStub() -{ - memberFuncMap_.clear(); -} - -int32_t TimeServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, " start##code = %{public}u", code); - std::u16string descriptor = TimeServiceStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - TIME_HILOGE(TIME_MODULE_SERVICE, " end##descriptor checked fail"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - #ifdef DEBUG_ENABLE - pid_t p = IPCSkeleton::GetCallingPid(); - pid_t p1 = IPCSkeleton::GetCallingUid(); - TIME_HILOGD(TIME_MODULE_SERVICE, "CallingPid = %{public}d, CallingUid = %{public}d, code = %{public}u", p, p1, - code); - #endif - if (code >= static_cast(TimeServiceIpcInterfaceCode::SET_TIME) && - code <= static_cast(TimeServiceIpcInterfaceCode::GET_REAL_TIME_MILLI)) { - auto itFunc = memberFuncMap_.find(static_cast(code)); - if (itFunc != memberFuncMap_.end()) { - auto memberFunc = itFunc->second; - if (memberFunc != nullptr) { - return memberFunc(data, reply); - } - } - } - int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); - TIME_HILOGD(TIME_MODULE_SERVICE, " end##ret = %{public}d", ret); - return ret; -} - -int32_t TimeServiceStub::OnSetTime(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, " start."); - TimeXCollie timeXCollie("TimeService::SetTime"); - int64_t time = data.ReadInt64(); - auto apiVersion = data.ReadInt8(); - if (apiVersion == APIVersion::API_VERSION_9) { - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - } - if (!TimePermission::CheckCallingPermission(TimePermission::setTime)) { - TIME_HILOGE(TIME_MODULE_SERVICE, "permission check setTime failed"); - return E_TIME_NO_PERMISSION; - } - int32_t ret = SetTime(time); - TIME_HILOGD(TIME_MODULE_SERVICE, " end##ret = %{public}d", ret); - return ret; -} - -int32_t TimeServiceStub::OnSetTimeZone(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, " start."); - TimeXCollie timeXCollie("TimeService::SetTimeZone"); - std::string timeZoneId = data.ReadString(); - auto apiVersion = data.ReadInt8(); - if (apiVersion == APIVersion::API_VERSION_9) { - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - } - if (!TimePermission::CheckCallingPermission(TimePermission::setTimeZone)) { - TIME_HILOGE(TIME_MODULE_SERVICE, "permission check setTime failed"); - return E_TIME_NO_PERMISSION; - } - int32_t ret = SetTimeZone(timeZoneId); - TIME_HILOGD(TIME_MODULE_SERVICE, " end##ret = %{public}d", ret); - return ret; -} - -int32_t TimeServiceStub::OnGetTimeZone(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, " start."); - TimeXCollie timeXCollie("TimeService::GetTimeZone"); - std::string timeZoneId; - int32_t ret = GetTimeZone(timeZoneId); - if (ret != ERR_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, " end##ret = %{public}d", ret); - return ret; - } - reply.WriteString(timeZoneId); - TIME_HILOGD(TIME_MODULE_SERVICE, " end."); - return ret; -} - -int32_t TimeServiceStub::OnGetThreadTimeMs(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, " start."); - TimeXCollie timeXCollie("TimeService::GetThreadTimeMs"); - int64_t time; - int32_t ret = GetThreadTimeMs(time); - if (ret != ERR_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, " end##ret = %{public}d", ret); - return ret; - } - reply.WriteInt64(time); - TIME_HILOGD(TIME_MODULE_SERVICE, " end."); - return ret; -} - -int32_t TimeServiceStub::OnGetThreadTimeNs(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, " start."); - TimeXCollie timeXCollie("TimeService::GetThreadTimeNs"); - int64_t time; - int32_t ret = GetThreadTimeNs(time); - if (ret != ERR_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, " end##ret = %{public}d", ret); - return ret; - } - reply.WriteInt64(time); - TIME_HILOGD(TIME_MODULE_SERVICE, " end."); - return ret; -} - -int32_t TimeServiceStub::OnCreateTimer(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - TimeXCollie timeXCollie("TimeService::CreateTimer"); - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - std::shared_ptr wantAgent{ nullptr }; - auto name = data.ReadString(); - auto type = data.ReadInt32(); - auto repeat = data.ReadBool(); - auto disposable = data.ReadBool(); - auto autoRestore = data.ReadBool(); - auto interval = data.ReadUint64(); - if (data.ReadBool()) { - wantAgent = std::shared_ptr( - data.ReadParcelable()); - if (!wantAgent) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Input wantagent nullptr"); - return E_TIME_NULLPTR; - } - } - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Input nullptr"); - return E_TIME_NULLPTR; - } - auto timerOptions = std::make_shared(); - timerOptions->name = name; - timerOptions->type = type; - timerOptions->repeat = repeat; - timerOptions->interval = interval; - timerOptions->disposable = disposable; - timerOptions->autoRestore = autoRestore; - timerOptions->wantAgent = wantAgent; - uint64_t timerId = data.ReadUint64(); - auto errCode = CreateTimer(timerOptions, obj, timerId); - if (errCode != E_TIME_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Create timer failed"); - return E_TIME_DEAL_FAILED; - } - if (!reply.WriteUint64(timerId)) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to write timerId"); - return E_TIME_WRITE_PARCEL_ERROR; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnStartTimer(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - TimeXCollie timeXCollie("TimeService::StartTimer"); - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - auto timerId = data.ReadUint64(); - auto triggerTime = data.ReadUint64(); - if (StartTimer(timerId, triggerTime) != E_TIME_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to start timer"); - return E_TIME_DEAL_FAILED; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnStopTimer(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - TimeXCollie timeXCollie("TimeService::StopTimer"); - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - auto timerId = data.ReadUint64(); - if (StopTimer(timerId) != E_TIME_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to stop timer"); - return E_TIME_DEAL_FAILED; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnDestroyTimer(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - TimeXCollie timeXCollie("TimeService::DestroyTimer"); - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - auto timerId = data.ReadUint64(); - if (DestroyTimer(timerId, false) != E_TIME_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to destory timer"); - return E_TIME_DEAL_FAILED; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnTimerProxy(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "on timer proxy start."); - TimeXCollie timeXCollie("TimeService::TimerProxy"); - if (!TimePermission::CheckProxyCallingPermission()) { - TIME_HILOGE(TIME_MODULE_SERVICE, "ProxyTimer permission check failed"); - return E_TIME_NO_PERMISSION; - } - auto uid = data.ReadInt32(); - auto pidListSize = data.ReadInt32(); - std::set pidList; - if (pidListSize < 0 || pidListSize > MAX_PID_LIST_SIZE) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Error pid list size."); - return E_TIME_READ_PARCEL_ERROR; - } - for (int i = 0; i < pidListSize; i++) { - auto pid = data.ReadInt32(); - if (pid != 0) { - pidList.insert(pid); - } - } - if (pidList.size() == 0) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Error pidList."); - return E_TIME_READ_PARCEL_ERROR; - } - auto isProxy = data.ReadBool(); - auto needRetrigger = data.ReadBool(); - if (!ProxyTimer(uid, pidList, isProxy, needRetrigger)) { - return E_TIME_DEAL_FAILED; - } - return ERR_OK; -} - -int32_t TimeServiceStub::OnAdjustTimer(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "on timer adjust start."); - TimeXCollie timeXCollie("TimeService::AdjustTimer"); - if (!TimePermission::CheckProxyCallingPermission()) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Adjust Timer permission check failed"); - return E_TIME_NO_PERMISSION; - } - bool isAdjust = false; - uint32_t interval = 0; - uint32_t delta = 0; - if (!data.ReadBool(isAdjust)) { - return E_TIME_READ_PARCEL_ERROR; - } - if (!data.ReadUint32(interval)) { - return E_TIME_READ_PARCEL_ERROR; - } - if (!data.ReadUint32(delta)) { - return E_TIME_READ_PARCEL_ERROR; - } - if (isAdjust && interval == 0) { - TIME_HILOGE(TIME_MODULE_SERVICE, "invalid parameter: interval"); - return E_TIME_READ_PARCEL_ERROR; - } - if (AdjustTimer(isAdjust, interval, delta) != E_TIME_OK) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Error adjust timer."); - return E_TIME_DEAL_FAILED; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "on timer adjust end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnSetTimerExemption(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "set timer exemption start."); - TimeXCollie timeXCollie("TimeService::SetTimerExemption"); - if (!TimePermission::CheckProxyCallingPermission()) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Set Timer Exemption permission check failed"); - return E_TIME_NO_PERMISSION; - } - std::unordered_set nameArr; - uint32_t size; - bool isExemption; - if (!data.ReadUint32(size)) { - return E_TIME_READ_PARCEL_ERROR; - } - if (size > MAX_EXEMPTION_SIZE) { - return E_TIME_PARAMETERS_INVALID; - } - for (uint32_t i = 0; i < size; ++i) { - std::string name; - if (!data.ReadString(name)) { - return E_TIME_READ_PARCEL_ERROR; - } - nameArr.insert(name); - } - - if (!data.ReadBool(isExemption)) { - return E_TIME_READ_PARCEL_ERROR; - } - SetTimerExemption(nameArr, isExemption); - TIME_HILOGD(TIME_MODULE_SERVICE, "set timer exemption end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnAllProxyReset(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - TimeXCollie timeXCollie("TimeService::AllProxyReset"); - if (!ResetAllProxy()) { - return E_TIME_DEAL_FAILED; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnGetNtpTimeMs(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - int64_t time = 0; - auto ret = GetNtpTimeMs(time); - if (ret != E_TIME_OK) { - return ret; - } - if (!reply.WriteUint64(time)) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to write NTP time"); - return E_TIME_WRITE_PARCEL_ERROR; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return ERR_OK; -} - -int32_t TimeServiceStub::OnGetRealTimeMs(MessageParcel &data, MessageParcel &reply) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { - TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); - return E_TIME_NOT_SYSTEM_APP; - } - int64_t time = 0; - auto ret = GetRealTimeMs(time); - if (ret != E_TIME_OK) { - return ret; - } - if (!reply.WriteUint64(time)) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to write NTP time"); - return E_TIME_WRITE_PARCEL_ERROR; - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return ERR_OK; -} -} // namespace MiscServices -} // namespace OHOS \ No newline at end of file diff --git a/services/ipc/stub/time_service_stub.h b/services/ipc/stub/time_service_stub.h deleted file mode 100644 index 464322df595e849d4d5db882c34ca34f290c4c4e..0000000000000000000000000000000000000000 --- a/services/ipc/stub/time_service_stub.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#ifndef SERVICES_INCLUDE_TIME_SERVICE_STUB_H -#define SERVICES_INCLUDE_TIME_SERVICE_STUB_H - -#include - -#include "ipc_skeleton.h" -#include "iremote_stub.h" -#include "itimer_call_back.h" -#include "time_service_interface.h" -#include "time_permission.h" -#include "time_service_ipc_interface_code.h" - -namespace OHOS { -namespace MiscServices { -class TimeServiceStub : public IRemoteStub { -public: - TimeServiceStub(); - ~TimeServiceStub(); - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - using TimeServiceFunc = std::function; - int32_t OnSetTime(MessageParcel &data, MessageParcel &reply); - int32_t OnSetTimeZone(MessageParcel &data, MessageParcel &reply); - int32_t OnGetTimeZone(MessageParcel &data, MessageParcel &reply); - int32_t OnGetThreadTimeMs(MessageParcel &data, MessageParcel &reply); - int32_t OnGetThreadTimeNs(MessageParcel &data, MessageParcel &reply); - - int32_t OnCreateTimer(MessageParcel &data, MessageParcel &reply); - int32_t OnStartTimer(MessageParcel &data, MessageParcel &reply); - int32_t OnStopTimer(MessageParcel &data, MessageParcel &reply); - int32_t OnDestroyTimer(MessageParcel &data, MessageParcel &reply); - int32_t OnNetworkTimeStatusOff(MessageParcel &data, MessageParcel &reply); - int32_t OnNetworkTimeStatusOn(MessageParcel &data, MessageParcel &reply); - int32_t OnTimerProxy(MessageParcel &data, MessageParcel &reply); - int32_t OnPidTimerProxy(MessageParcel &data, MessageParcel &reply); - int32_t OnAdjustTimer(MessageParcel &data, MessageParcel &reply); - int32_t OnSetTimerExemption(MessageParcel &data, MessageParcel &reply); - int32_t OnAllProxyReset(MessageParcel &data, MessageParcel &reply); - int32_t OnGetNtpTimeMs(MessageParcel &data, MessageParcel &reply); - int32_t OnGetRealTimeMs(MessageParcel &data, MessageParcel &reply); - std::map memberFuncMap_; -}; -} // namespace MiscServices -} // namespace OHOS - -#endif // SERVICES_INCLUDE_TIME_SERVICE_STUB_H \ No newline at end of file diff --git a/services/ipc/stub/timer_call_back_stub.cpp b/services/ipc/stub/timer_call_back_stub.cpp deleted file mode 100644 index 3f409aa8ddb108c37cdff13453201dc9a7120818..0000000000000000000000000000000000000000 --- a/services/ipc/stub/timer_call_back_stub.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021 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 "timer_call_back_stub.h" -#include "time_service_client.h" - -namespace OHOS { -namespace MiscServices { -int TimerCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "cmd = %{public}d, flags= %{public}d", code, option.GetFlags()); - std::u16string descriptor = GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - TIME_HILOGE(TIME_MODULE_SERVICE, " failed, descriptor is not matched!"); - return E_TIME_READ_PARCEL_ERROR; - } - - switch (code) { - case static_cast(ITimerCallback::Message::NOTIFY_TIMER): { - return OnTriggerStub(data); - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return ERR_OK; -} - -int TimerCallbackStub::OnTriggerStub(MessageParcel &data) -{ - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - auto timerId = data.ReadUint64(); - TIME_HILOGD(TIME_MODULE_CLIENT, "id: %{public}" PRId64 "", timerId); - NotifyTimer(timerId); - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - TimeServiceClient::GetInstance()->HandleRecoverMap(timerId); - return ERR_OK; -} -} // namespace MiscServices -} // namespace OHOS \ No newline at end of file diff --git a/services/time/include/inner_api_include/timer_call_back.h b/services/time/include/inner_api_include/timer_call_back.h index 7470a1ec02b8175dbc6488be834b27d28bcd28d4..738494c8ac191406ad6286d3722a8e50fb93d7e7 100644 --- a/services/time/include/inner_api_include/timer_call_back.h +++ b/services/time/include/inner_api_include/timer_call_back.h @@ -20,7 +20,7 @@ #include "itimer_info.h" #include "time_common.h" -#include "timer_call_back_stub.h" +#include "timer_callback_stub.h" namespace OHOS { namespace MiscServices { diff --git a/services/time/include/simple_timer_info.h b/services/time/include/simple_timer_info.h index 3ec2ee91e6c32770fe2f6dfaabfab3ddc509fd4b..eca91021f414db8b57e0bec957e2957eae044313 100644 --- a/services/time/include/simple_timer_info.h +++ b/services/time/include/simple_timer_info.h @@ -17,18 +17,28 @@ #define SIMPLE_TIMER_INFO_H #include "itimer_info.h" +#include "parcel.h" namespace OHOS { namespace MiscServices { -class SimpleTimerInfo : public ITimerInfo { +class SimpleTimerInfo : public ITimerInfo, public Parcelable { public: - SimpleTimerInfo(); + SimpleTimerInfo(std::string _name, + int _type, + bool _repeat, + bool _disposable, + bool _autoRestore, + uint64_t _interval, + std::shared_ptr _wantAgent); virtual ~SimpleTimerInfo(); void OnTrigger() override; void SetType(const int &type) override; void SetRepeat(bool repeat) override; void SetInterval(const uint64_t &interval) override; void SetWantAgent(std::shared_ptr wantAgent) override; + + bool Marshalling(Parcel& parcel) const override; + static SimpleTimerInfo *Unmarshalling(Parcel& parcel); }; } // namespace MiscServices } // namespace OHOS diff --git a/services/time/src/ntp_update_time.cpp b/services/time/src/ntp_update_time.cpp index de6275a760f7e96714abbc9de338df918f9e443c..945d76bdc5530389d4ad44ef9c0a873e8d09f599 100644 --- a/services/time/src/ntp_update_time.cpp +++ b/services/time/src/ntp_update_time.cpp @@ -289,7 +289,7 @@ void NtpUpdateTime::StartTimer() void NtpUpdateTime::Stop() { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - TimeSystemAbility::GetInstance()->DestroyTimer(timerId_, false); + TimeSystemAbility::GetInstance()->DestroyTimer(timerId_); } void NtpUpdateTime::RegisterSystemParameterListener() diff --git a/services/time/src/simple_timer_info.cpp b/services/time/src/simple_timer_info.cpp index bc9c7b98263b4343d790db43b90db7bc55a5d224..eee386261d58128311a5bcb3c526eddeda385c96 100644 --- a/services/time/src/simple_timer_info.cpp +++ b/services/time/src/simple_timer_info.cpp @@ -14,11 +14,25 @@ */ #include "simple_timer_info.h" +#include "time_hilog.h" namespace OHOS { namespace MiscServices { -SimpleTimerInfo::SimpleTimerInfo() +SimpleTimerInfo::SimpleTimerInfo(std::string _name, + int _type, + bool _repeat, + bool _disposable, + bool _autoRestore, + uint64_t _interval, + std::shared_ptr _wantAgent) { + name = _name; + type = _type; + repeat = _repeat; + disposable = _disposable; + autoRestore = _autoRestore; + interval = _interval; + wantAgent = _wantAgent; } SimpleTimerInfo::~SimpleTimerInfo() { @@ -43,5 +57,68 @@ void SimpleTimerInfo::SetWantAgent(std::shared_ptr wantAgent{ nullptr }; + if (parcel.ReadBool()) { + wantAgent = std::shared_ptr( + parcel.ReadParcelable()); + if (!wantAgent) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Input wantagent nullptr"); + return nullptr; + } + } + SimpleTimerInfo *simpleTimerInfo = new (std::nothrow) SimpleTimerInfo(name, type, repeat, disposable, autoRestore, + interval, wantAgent); + if (simpleTimerInfo == nullptr) { + TIME_HILOGE(TIME_MODULE_SERVICE, "SimpleTimerInfo nullptr"); + return nullptr; + } + return simpleTimerInfo; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/time/src/time_tick_notify.cpp b/services/time/src/time_tick_notify.cpp index 7aabad8d44451c945996c9eebe90331921ae3bee..349ac031f59382c59523bb3471c391de386e5672 100644 --- a/services/time/src/time_tick_notify.cpp +++ b/services/time/src/time_tick_notify.cpp @@ -94,7 +94,7 @@ std::pair TimeTickNotify::RefreshNextTriggerTime() void TimeTickNotify::Stop() { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - TimeSystemAbility::GetInstance()->DestroyTimer(timerId_, false); + TimeSystemAbility::GetInstance()->DestroyTimer(timerId_); TIME_HILOGD(TIME_MODULE_SERVICE, "end."); } } // namespace MiscServices diff --git a/services/time/src/timer_call_back.cpp b/services/time/src/timer_call_back.cpp index 008e25f876453417ce877a665dba47914276f6a6..c01d000f73ad9921cf8c35a2b82683f976074459 100644 --- a/services/time/src/timer_call_back.cpp +++ b/services/time/src/timer_call_back.cpp @@ -14,6 +14,7 @@ */ #include "timer_call_back.h" +#include "time_service_client.h" namespace OHOS { namespace MiscServices { @@ -88,6 +89,7 @@ int32_t TimerCallback::NotifyTimer(const uint64_t timerId) timerInfo->OnTrigger(); } TIME_HILOGD(TIME_MODULE_SERVICE, "end."); + TimeServiceClient::GetInstance()->HandleRecoverMap(timerId); return E_TIME_OK; } } // namespace MiscServices diff --git a/services/time_system_ability.cpp b/services/time_system_ability.cpp index a38ce355893189c28784f38f25b32fcefc24adb2..46787ed85d0633aa7f3e9eebc90f2b53c910c51d 100644 --- a/services/time_system_ability.cpp +++ b/services/time_system_ability.cpp @@ -37,11 +37,13 @@ #include "timer_manager_interface.h" #include "timer_proxy.h" #include "time_file_utils.h" +#include "time_xcollie.h" #include "common_event_manager.h" #include "common_event_support.h" #include "init_param.h" #include "parameters.h" #include "event_manager.h" +#include "simple_timer_info.h" #ifdef MULTI_ACCOUNT_ENABLE #include "os_account.h" @@ -50,6 +52,7 @@ using namespace std::chrono; using namespace OHOS::EventFwk; +using namespace OHOS::HiviewDFX; namespace OHOS { namespace MiscServices { @@ -72,6 +75,8 @@ static const std::vector ALL_DATA = { "timerId", "type", "flag", "w "uid", "bundleName", "wantAgent", "state", "triggerTime", \ "pid", "name"}; const std::string BOOTEVENT_PARAMETER = "bootevent.boot.completed"; +static const int MAX_PID_LIST_SIZE = 1024; +static const uint32_t MAX_EXEMPTION_SIZE = 1000; #ifdef SET_AUTO_REBOOT_ENABLE constexpr int64_t MILLISECOND_TO_NANO = 1000000; constexpr uint64_t TWO_MINUTES_TO_MILLI = 120000; @@ -373,7 +378,24 @@ int32_t TimeSystemAbility::CheckTimerPara(const DatabaseType type, const TimerPa return E_TIME_OK; } -int32_t TimeSystemAbility::CreateTimer(const std::shared_ptr &timerOptions, sptr &obj, +int32_t TimeSystemAbility::CreateTimer(const SimpleTimerInfo& simpleTimerInfo, + const sptr &timerCallback, + uint64_t &timerId) +{ + TimeXCollie timeXCollie("TimeService::CreateTimer"); + if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { + TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); + return E_TIME_NOT_SYSTEM_APP; + } + auto timerInfo = std::make_shared(simpleTimerInfo); + auto ret = CreateTimer(timerInfo, timerCallback, timerId); + if (ret != E_TIME_OK) { + return E_TIME_DEAL_FAILED; + } + return E_TIME_OK; +} + +int32_t TimeSystemAbility::CreateTimer(const std::shared_ptr &timerOptions, const sptr &obj, uint64_t &timerId) { if (obj == nullptr) { @@ -426,34 +448,66 @@ int32_t TimeSystemAbility::CreateTimer(TimerPara ¶s, std::functionStartTimer(timerId, triggerTime); + if (ret != E_TIME_OK) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to start timer"); + return E_TIME_DEAL_FAILED; + } return ret; } int32_t TimeSystemAbility::StopTimer(uint64_t timerId) { + TimeXCollie timeXCollie("TimeService::StopTimer"); + if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { + TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); + return E_TIME_NOT_SYSTEM_APP; + } auto timerManager = TimerManager::GetInstance(); if (timerManager == nullptr) { return E_TIME_NULLPTR; } auto ret = timerManager->StopTimer(timerId); + if (ret != E_TIME_OK) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to stop timer"); + return E_TIME_DEAL_FAILED; + } return ret; } -int32_t TimeSystemAbility::DestroyTimer(uint64_t timerId, bool isAsync) +int32_t TimeSystemAbility::DestroyTimer(uint64_t timerId) { + TimeXCollie timeXCollie("TimeService::DestroyTimer"); + if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { + TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); + return E_TIME_NOT_SYSTEM_APP; + } auto timerManager = TimerManager::GetInstance(); if (timerManager == nullptr) { return E_TIME_NULLPTR; } auto ret = timerManager->DestroyTimer(timerId); + if (ret != E_TIME_OK) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Failed to destory timer"); + return E_TIME_DEAL_FAILED; + } return ret; } +int32_t TimeSystemAbility::DestroyTimerAsync(uint64_t timerId) +{ + return DestroyTimer(timerId); +} + bool TimeSystemAbility::IsValidTime(int64_t time) { #if __SIZEOF_POINTER__ == 4 @@ -513,8 +567,19 @@ bool TimeSystemAbility::SetRealTime(int64_t time) return true; } -int32_t TimeSystemAbility::SetTime(int64_t time, APIVersion apiVersion) +int32_t TimeSystemAbility::SetTime(int64_t time, int8_t apiVersion) { + TimeXCollie timeXCollie("TimeService::SetTime"); + if (apiVersion == APIVersion::API_VERSION_9) { + if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { + TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); + return E_TIME_NOT_SYSTEM_APP; + } + } + if (!TimePermission::CheckCallingPermission(TimePermission::setTime)) { + TIME_HILOGE(TIME_MODULE_SERVICE, "permission check setTime failed"); + return E_TIME_NO_PERMISSION; + } if (!SetRealTime(time)) { return E_TIME_DEAL_FAILED; } @@ -732,8 +797,19 @@ int TimeSystemAbility::GetWallClockRtcId() return -1; } -int32_t TimeSystemAbility::SetTimeZone(const std::string &timeZoneId, APIVersion apiVersion) +int32_t TimeSystemAbility::SetTimeZone(const std::string &timeZoneId, int8_t apiVersion) { + TimeXCollie timeXCollie("TimeService::SetTimeZone"); + if (apiVersion == APIVersion::API_VERSION_9) { + if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { + TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); + return E_TIME_NOT_SYSTEM_APP; + } + } + if (!TimePermission::CheckCallingPermission(TimePermission::setTimeZone)) { + TIME_HILOGE(TIME_MODULE_SERVICE, "permission check setTime failed"); + return E_TIME_NO_PERMISSION; + } if (!TimeZoneInfo::GetInstance().SetTimezone(timeZoneId)) { TIME_HILOGE(TIME_MODULE_SERVICE, "Set timezone failed :%{public}s", timeZoneId.c_str()); return E_TIME_DEAL_FAILED; @@ -746,6 +822,7 @@ int32_t TimeSystemAbility::SetTimeZone(const std::string &timeZoneId, APIVersion int32_t TimeSystemAbility::GetTimeZone(std::string &timeZoneId) { + TimeXCollie timeXCollie("TimeService::GetTimeZone"); if (!TimeZoneInfo::GetInstance().GetTimezone(timeZoneId)) { TIME_HILOGE(TIME_MODULE_SERVICE, "get timezone failed"); return E_TIME_DEAL_FAILED; @@ -756,6 +833,7 @@ int32_t TimeSystemAbility::GetTimeZone(std::string &timeZoneId) int32_t TimeSystemAbility::GetThreadTimeMs(int64_t &time) { + TimeXCollie timeXCollie("TimeService::GetThreadTimeMs"); struct timespec tv {}; clockid_t cid; int ret = pthread_getcpuclockid(pthread_self(), &cid); @@ -771,6 +849,7 @@ int32_t TimeSystemAbility::GetThreadTimeMs(int64_t &time) int32_t TimeSystemAbility::GetThreadTimeNs(int64_t &time) { + TimeXCollie timeXCollie("TimeService::GetThreadTimeNs"); struct timespec tv {}; clockid_t cid; int ret = pthread_getcpuclockid(pthread_self(), &cid); @@ -795,51 +874,97 @@ bool TimeSystemAbility::GetTimeByClockId(clockid_t clockId, struct timespec &tv) int32_t TimeSystemAbility::AdjustTimer(bool isAdjust, uint32_t interval, uint32_t delta) { + TimeXCollie timeXCollie("TimeService::AdjustTimer"); + if (!TimePermission::CheckProxyCallingPermission()) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Adjust Timer permission check failed"); + return E_TIME_NO_PERMISSION; + } + if (isAdjust && interval == 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, "invalid parameter: interval"); + return E_TIME_READ_PARCEL_ERROR; + } auto timerManager = TimerManager::GetInstance(); if (timerManager == nullptr) { return E_TIME_NULLPTR; } if (!timerManager->AdjustTimer(isAdjust, interval, delta)) { - return E_TIME_NO_TIMER_ADJUST; + TIME_HILOGE(TIME_MODULE_SERVICE, "Error adjust timer."); + return E_TIME_DEAL_FAILED; } return E_TIME_OK; } -bool TimeSystemAbility::ProxyTimer(int32_t uid, std::set pidList, bool isProxy, bool needRetrigger) +int32_t TimeSystemAbility::ProxyTimer(int32_t uid, const std::vector& pidList, bool isProxy, bool needRetrigger) { + TimeXCollie timeXCollie("TimeService::TimerProxy"); + if (!TimePermission::CheckProxyCallingPermission()) { + TIME_HILOGE(TIME_MODULE_SERVICE, "ProxyTimer permission check failed"); + return E_TIME_NO_PERMISSION; + } + if (pidList.size() > MAX_PID_LIST_SIZE) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Error pid list size."); + return E_TIME_PARAMETERS_INVALID; + } + if (pidList.size() == 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Error pidList."); + return E_TIME_PARAMETERS_INVALID; + } auto timerManager = TimerManager::GetInstance(); if (timerManager == nullptr) { - return false; + return E_TIME_NULLPTR; + } + std::set pidSet; + std::copy(pidList.begin(), pidList.end(), std::insert_iterator>(pidSet, pidSet.begin())); + auto ret = timerManager->ProxyTimer(uid, pidSet, isProxy, needRetrigger); + if (!ret) { + return E_TIME_DEAL_FAILED; } - return timerManager->ProxyTimer(uid, pidList, isProxy, needRetrigger); + return ERR_OK; } -int32_t TimeSystemAbility::SetTimerExemption(const std::unordered_set &nameArr, bool isExemption) +int32_t TimeSystemAbility::SetTimerExemption(const std::vector &nameArr, bool isExemption) { + TimeXCollie timeXCollie("TimeService::SetTimerExemption"); + if (!TimePermission::CheckProxyCallingPermission()) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Set Timer Exemption permission check failed"); + return E_TIME_NO_PERMISSION; + } + if (nameArr.size() > MAX_EXEMPTION_SIZE) { + return E_TIME_PARAMETERS_INVALID; + } auto timerManager = TimerManager::GetInstance(); if (timerManager == nullptr) { return E_TIME_NULLPTR; } - timerManager->SetTimerExemption(nameArr, isExemption); + std::unordered_set nameSet; + std::copy(nameArr.begin(), nameArr.end(), std::inserter(nameSet, nameSet.begin())); + timerManager->SetTimerExemption(nameSet, isExemption); return E_TIME_OK; } -bool TimeSystemAbility::ResetAllProxy() +int32_t TimeSystemAbility::ResetAllProxy() { if (!TimePermission::CheckProxyCallingPermission()) { TIME_HILOGE(TIME_MODULE_SERVICE, "ResetAllProxy permission check failed"); - return false; + return E_TIME_NO_PERMISSION; } TIME_HILOGD(TIME_MODULE_SERVICE, "ResetAllProxy service"); auto timerManager = TimerManager::GetInstance(); if (timerManager == nullptr) { - return false; + return E_TIME_NULLPTR; + } + if (!timerManager->ResetAllProxy()) { + return E_TIME_DEAL_FAILED; } - return timerManager->ResetAllProxy(); + return E_TIME_OK; } int32_t TimeSystemAbility::GetNtpTimeMs(int64_t &time) { + if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { + TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); + return E_TIME_NOT_SYSTEM_APP; + } auto ret = NtpUpdateTime::GetInstance().GetNtpTime(time); if (!ret) { TIME_HILOGE(TIME_MODULE_SERVICE, "GetNtpTimeMs failed"); @@ -850,6 +975,10 @@ int32_t TimeSystemAbility::GetNtpTimeMs(int64_t &time) int32_t TimeSystemAbility::GetRealTimeMs(int64_t &time) { + if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { + TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); + return E_TIME_NOT_SYSTEM_APP; + } auto ret = NtpUpdateTime::GetInstance().GetRealTime(time); if (!ret) { TIME_HILOGE(TIME_MODULE_SERVICE, "GetRealTimeMs failed"); diff --git a/services/time_system_ability.h b/services/time_system_ability.h index 1194611bac41c11a7ad4b2041e9fd530f4041623..c283d3c04fb6fcaa16968ba80344be481aea33c0 100644 --- a/services/time_system_ability.h +++ b/services/time_system_ability.h @@ -33,6 +33,10 @@ #include "shutdown/sync_shutdown_callback_stub.h" #include "shutdown/shutdown_client.h" #include "cjson_helper.h" +#include "itimer_info.h" +#include "ipc_skeleton.h" +#include "time_permission.h" +#include "simple_timer_info.h" namespace OHOS { namespace MiscServices { @@ -54,25 +58,29 @@ public: TimeSystemAbility(); ~TimeSystemAbility(); static sptr GetInstance(); - int32_t SetTime(int64_t time, APIVersion apiVersion = APIVersion::API_VERSION_7) override; + int32_t SetTime(int64_t time, int8_t apiVersion = APIVersion::API_VERSION_7) override; bool SetRealTime(int64_t time); - int32_t SetTimeZone(const std::string &timeZoneId, APIVersion apiVersion = APIVersion::API_VERSION_7) override; + int32_t SetTimeZone(const std::string &timeZoneId, int8_t apiVersion = APIVersion::API_VERSION_7) override; int32_t GetTimeZone(std::string &timeZoneId) override; int32_t GetWallTimeMs(int64_t &time); int32_t GetBootTimeMs(int64_t &time); int32_t GetBootTimeNs(int64_t &time); int32_t GetThreadTimeMs(int64_t &time) override; int32_t GetThreadTimeNs(int64_t &time) override; - int32_t CreateTimer(const std::shared_ptr &timerOptions, sptr &obj, - uint64_t &timerId) override; + int32_t CreateTimer(const SimpleTimerInfo& simpleTimerInfo, + const sptr &timerCallback, + uint64_t &timerId) override; + int32_t CreateTimer(const std::shared_ptr &timerOptions, const sptr &obj, + uint64_t &timerId); int32_t CreateTimer(TimerPara ¶s, std::function callback, uint64_t &timerId); int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) override; int32_t StopTimer(uint64_t timerId) override; - int32_t DestroyTimer(uint64_t timerId, bool isAsync) override; - bool ProxyTimer(int32_t uid, std::set pidList, bool isProxy, bool needRetrigger) override; + int32_t DestroyTimer(uint64_t timerId) override; + int32_t DestroyTimerAsync(uint64_t timerId) override; + int32_t ProxyTimer(int32_t uid, const std::vector& pidList, bool isProxy, bool needRetrigger) override; int32_t AdjustTimer(bool isAdjust, uint32_t interval, uint32_t delta) override; - int32_t SetTimerExemption(const std::unordered_set &nameArr, bool isExemption) override; - bool ResetAllProxy() override; + int32_t SetTimerExemption(const std::vector &nameArr, bool isExemption) override; + int32_t ResetAllProxy() override; int32_t GetNtpTimeMs(int64_t &time) override; int32_t GetRealTimeMs(int64_t &time) override; #ifdef HIDUMPER_ENABLE diff --git a/test/fuzztest/timeservice_fuzzer/BUILD.gn b/test/fuzztest/timeservice_fuzzer/BUILD.gn index 67d19a4981a403f2dc3018ef51cfc1687dc16f31..1d7e39a16b75434434aa03564426d2aa6d180685 100644 --- a/test/fuzztest/timeservice_fuzzer/BUILD.gn +++ b/test/fuzztest/timeservice_fuzzer/BUILD.gn @@ -99,6 +99,7 @@ foreach(item, time_fuzztests) { module_out_path = "time_service/time" fuzz_config_file = "${time_root_path}/test/fuzztest/timeservice_fuzzer/${item.configFuzzer}" + configs = [ "${time_service_path}:time_service_gen_config" ] include_dirs = [ "${time_service_path}", diff --git a/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.cpp b/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.cpp index f3a213e0e93a67c277139c532f4e0fe493d63b6a..9ea6ce205be6c6d0c0b0c379cf96b6945c52d340 100644 --- a/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.cpp +++ b/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.cpp @@ -22,7 +22,7 @@ using namespace OHOS::MiscServices; namespace OHOS { -const std::u16string TIMESERVICE_INTERFACE_TOKEN = u"ohos.miscservices.time.ITimeService"; +const std::u16string TIMESERVICE_INTERFACE_TOKEN = u"OHOS.MiscServices.ITimeService"; void TimeServiceFuzzUtils::OnRemoteRequestTest(uint32_t code, const uint8_t *rawData, size_t size) { diff --git a/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.h b/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.h index 19fb85abd8052810c780aa2ab42f79a9f6aed042..3dd13806be593e38b818de480b3db973e56d41fe 100644 --- a/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.h +++ b/test/fuzztest/timeservice_fuzzer/common/time_service_fuzz_utils.h @@ -18,6 +18,7 @@ #include #include +#include "itime_service.h" namespace OHOS { class TimeServiceFuzzUtils { diff --git a/test/fuzztest/timeservice_fuzzer/timeboundarycode_fuzzer/timeboundarycode_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timeboundarycode_fuzzer/timeboundarycode_fuzzer.cpp index 74ff105175c42c202bc5a0a89668f544e0622da4..74c5f3c34b5d6a74f1be847e9e1334449c8ad4b2 100644 --- a/test/fuzztest/timeservice_fuzzer/timeboundarycode_fuzzer/timeboundarycode_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timeboundarycode_fuzzer/timeboundarycode_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::SET_TIMER_EXEMPTION) + 1U, data, size); + static_cast(ITimeServiceIpcCode::COMMAND_SET_TIMER_EXEMPTION) + 1U, data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timecreatetimer_fuzzer/timecreatetimer_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timecreatetimer_fuzzer/timecreatetimer_fuzzer.cpp index 1d458b9251c13f4007786cc7e9cf79b63f2224e7..9b670b62bdc19ac3023b9d0568fa176d4f35b3b7 100644 --- a/test/fuzztest/timeservice_fuzzer/timecreatetimer_fuzzer/timecreatetimer_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timecreatetimer_fuzzer/timecreatetimer_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::CREATE_TIMER), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_CREATE_TIMER), data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timedestroytimer_fuzzer/timedestroytimer_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timedestroytimer_fuzzer/timedestroytimer_fuzzer.cpp index 3d40731f988147b34db7c5c132e81627e5a5e8a5..db7fd8857a0f5de6d4884f5678ba2cfc3faf5f37 100644 --- a/test/fuzztest/timeservice_fuzzer/timedestroytimer_fuzzer/timedestroytimer_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timedestroytimer_fuzzer/timedestroytimer_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::DESTROY_TIMER), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_DESTROY_TIMER), data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timegetthreadtimemilli_fuzzer/timegetthreadtimemilli_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timegetthreadtimemilli_fuzzer/timegetthreadtimemilli_fuzzer.cpp index 0f0357d2808446840ca5babfdd07567f9896349a..cc92ff7aedb945271d0600ab27f5222328b811f3 100644 --- a/test/fuzztest/timeservice_fuzzer/timegetthreadtimemilli_fuzzer/timegetthreadtimemilli_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timegetthreadtimemilli_fuzzer/timegetthreadtimemilli_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::GET_THREAD_TIME_MILLI), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_GET_THREAD_TIME_MS), data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timegetthreadtimenano_fuzzer/timegetthreadtimenano_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timegetthreadtimenano_fuzzer/timegetthreadtimenano_fuzzer.cpp index 750d56c21ed80e9186cfd9567a8af104eb39715e..cc1ef8a32caeda5ef109af7c02ce9245f9acc8c8 100644 --- a/test/fuzztest/timeservice_fuzzer/timegetthreadtimenano_fuzzer/timegetthreadtimenano_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timegetthreadtimenano_fuzzer/timegetthreadtimenano_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::GET_THREAD_TIME_NANO), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_GET_THREAD_TIME_NS), data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timegettimezone_fuzzer/timegettimezone_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timegettimezone_fuzzer/timegettimezone_fuzzer.cpp index ed5c99880a5fdd515fc416193b68f87201c2be55..16a16d5c9ed9100f3ae0f57907bf665d5d39f38d 100644 --- a/test/fuzztest/timeservice_fuzzer/timegettimezone_fuzzer/timegettimezone_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timegettimezone_fuzzer/timegettimezone_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::GET_TIME_ZONE), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_GET_TIME_ZONE), data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timerproxy_fuzzer/timerproxy_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timerproxy_fuzzer/timerproxy_fuzzer.cpp index 14a7f3c72f2395460b8f8ea2cf9ae5edd3599d4c..6b9312fa3f3a68d6f81c1df66e99164d58eeb30f 100644 --- a/test/fuzztest/timeservice_fuzzer/timerproxy_fuzzer/timerproxy_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timerproxy_fuzzer/timerproxy_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" #include "timer_proxy.h" #include diff --git a/test/fuzztest/timeservice_fuzzer/timeservicesettimezone_fuzzer/timeservicesettimezone_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timeservicesettimezone_fuzzer/timeservicesettimezone_fuzzer.cpp index 9fb44b08217ca0b7774012fda5b08855d8887e65..0211ccf34012a1ce9ec7cf6513de352134fcb9e8 100644 --- a/test/fuzztest/timeservice_fuzzer/timeservicesettimezone_fuzzer/timeservicesettimezone_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timeservicesettimezone_fuzzer/timeservicesettimezone_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::SET_TIME_ZONE), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_SET_TIME_ZONE), data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timestarttimer_fuzzer/timestarttimer_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timestarttimer_fuzzer/timestarttimer_fuzzer.cpp index 6fd62d81817ee1283b048f2709c6c745a6fd99c8..85e9c1a64c99c2c4afd407e2d995bc143b55a4f4 100644 --- a/test/fuzztest/timeservice_fuzzer/timestarttimer_fuzzer/timestarttimer_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timestarttimer_fuzzer/timestarttimer_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::START_TIMER), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_START_TIMER), data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/timeservice_fuzzer/timestoptimer_fuzzer/timestoptimer_fuzzer.cpp b/test/fuzztest/timeservice_fuzzer/timestoptimer_fuzzer/timestoptimer_fuzzer.cpp index ab1afec7bfbe2cba822ef2c1434a59bb654b49be..f3a55cd1a7d47d31febbfe8fb7430e69e2ca8e91 100644 --- a/test/fuzztest/timeservice_fuzzer/timestoptimer_fuzzer/timestoptimer_fuzzer.cpp +++ b/test/fuzztest/timeservice_fuzzer/timestoptimer_fuzzer/timestoptimer_fuzzer.cpp @@ -20,7 +20,6 @@ #include #include "time_service_fuzz_utils.h" -#include "time_service_ipc_interface_code.h" using namespace OHOS::MiscServices; @@ -37,6 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) /* Run your code on data */ OHOS::TimeServiceFuzzUtils::OnRemoteRequestTest( - static_cast(TimeServiceIpcInterfaceCode::STOP_TIMER), data, size); + static_cast(ITimeServiceIpcCode::COMMAND_STOP_TIMER), data, size); return 0; } \ No newline at end of file diff --git a/test/unittest/service_test/src/time_client_test.cpp b/test/unittest/service_test/src/time_client_test.cpp index f65d8f2c174250bc812de1efa3b30b398c97a4bf..67d21e5d3a6c440b47e5f0b5ef382c4021bd6e3b 100644 --- a/test/unittest/service_test/src/time_client_test.cpp +++ b/test/unittest/service_test/src/time_client_test.cpp @@ -1162,7 +1162,9 @@ HWTEST_F(TimeClientTest, ReBatchAllTimers001, TestSize.Level1) std::set pidList; pidList.insert(pid); TimeServiceClient::GetInstance()->ProxyTimer(uid, pidList, true, true); - TimeSystemAbility::GetInstance()->ProxyTimer(uid, pidList, false, true); + std::vector pidVector; + pidVector.push_back(pid); + TimeSystemAbility::GetInstance()->ProxyTimer(uid, pidVector, false, true); struct timeval currentTime {}; gettimeofday(¤tTime, nullptr); diff --git a/utils/native/include/time_common.h b/utils/native/include/time_common.h index 958b40fea51782fb7843bcaca2cab0198350b6ff..9f0be474da4d7bc58a9c6886df1ffdc8f3449599 100644 --- a/utils/native/include/time_common.h +++ b/utils/native/include/time_common.h @@ -72,6 +72,11 @@ enum DatabaseType { STORE, }; +enum APIVersion : int8_t { + API_VERSION_7 = 0, + API_VERSION_9 = 1, +}; + class TimeUtils { public: static int32_t GetWallTimeMs(int64_t &time);