diff --git a/BUILD.gn b/BUILD.gn index 0ff33f0..ab3b370 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -19,8 +19,8 @@ group("time_native_packages") { if (is_standard_system) { deps = [ "etc/init:timeservice.cfg", - "interfaces/innerkits:time_client", "interfaces/kits/js/declaration:time", + "interfaces/innerkits:time_client", "interfaces/kits/js/napi/system_time:systemtime", "interfaces/kits/js/napi/system_timer:systemtimer", "profile:miscservices_time_sa_profiles", diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index c58d1a2..a6ee68c 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -26,12 +26,12 @@ config("time_client_config") { ohos_shared_library("time_client") { sources = [ "${time_service_path}/time_manager/src/itimer_info.cpp", - "${time_service_path}/time_manager/src/time_service_client.cpp", "${time_service_path}/time_manager/src/time_service_proxy.cpp", "${time_service_path}/time_manager/src/time_service_stub.cpp", - "${time_service_path}/time_manager/src/timer_call_back.cpp", + "${time_service_path}/time_manager/src/time_service_client.cpp", "${time_service_path}/time_manager/src/timer_call_back_proxy.cpp", "${time_service_path}/time_manager/src/timer_call_back_stub.cpp", + "${time_service_path}/time_manager/src/timer_call_back.cpp", ] configs = [ ":time_client_config" ] diff --git a/interfaces/kits/js/napi/system_timer/BUILD.gn b/interfaces/kits/js/napi/system_timer/BUILD.gn index 318b7de..98348ce 100644 --- a/interfaces/kits/js/napi/system_timer/BUILD.gn +++ b/interfaces/kits/js/napi/system_timer/BUILD.gn @@ -50,11 +50,10 @@ ohos_shared_library("systemtimer") { deps = [ "//base/miscservices/time/services:time_service", - "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/intent:intent", "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/ace/napi:ace_napi", "//third_party/libuv:uv_static", ] diff --git a/services/BUILD.gn b/services/BUILD.gn index 4503003..67b0311 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -70,6 +70,7 @@ ohos_shared_library("time_service") { "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "ces_standard:cesfwk_innerkits", + "native_appdatamgr:native_rdb", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/time_manager/src/ntp_trusted_time.cpp b/services/time_manager/src/ntp_trusted_time.cpp index 0efe452..3f2bca2 100644 --- a/services/time_manager/src/ntp_trusted_time.cpp +++ b/services/time_manager/src/ntp_trusted_time.cpp @@ -53,10 +53,12 @@ bool NtpTrustedTime::ForceRefresh(std::string ntpServer) int64_t NtpTrustedTime::CurrentTimeMillis() { + TIME_HILOGD(TIME_MODULE_SERVICE, "start."); if (mTimeResult == nullptr) { TIME_HILOGD(TIME_MODULE_SERVICE, "Missing authoritative time source"); return INVALID_MILLIS; } + TIME_HILOGD(TIME_MODULE_SERVICE, "end."); return mTimeResult->CurrentTimeMillis(); } diff --git a/services/time_manager/src/sntp_client.cpp b/services/time_manager/src/sntp_client.cpp index 73446bd..f2bbde4 100644 --- a/services/time_manager/src/sntp_client.cpp +++ b/services/time_manager/src/sntp_client.cpp @@ -117,7 +117,7 @@ bool SNTPClient::RequestTime(std::string host) close(SendSocket); return false; } - + TIME_HILOGD(TIME_MODULE_SERVICE, "RequestTime5."); char bufferRx[NTP_PACKAGE_SIZE] = { 0 }; // Receive until the peer closes the connection iResult = recv(SendSocket, bufferRx, NTP_PACKAGE_SIZE, 0); @@ -126,7 +126,7 @@ bool SNTPClient::RequestTime(std::string host) close(SendSocket); return false; } - + TIME_HILOGD(TIME_MODULE_SERVICE, "RequestTime6."); ReceivedMessage(bufferRx); TIME_HILOGD(TIME_MODULE_SERVICE, "end."); return true; @@ -145,6 +145,7 @@ int SNTPClient::GetClockOffset(void) uint64_t SNTPClient::GetNtpTimestamp64(int offset, char* buffer) { + TIME_HILOGD(TIME_MODULE_SERVICE, "start."); const int _len = sizeof(uint64_t); char valueRx[_len]; errno_t ret = memset_s(valueRx, sizeof(uint64_t), 0, sizeof(uint64_t)); diff --git a/services/time_manager/src/time_service.cpp b/services/time_manager/src/time_service.cpp index 33a0598..dc738c5 100644 --- a/services/time_manager/src/time_service.cpp +++ b/services/time_manager/src/time_service.cpp @@ -307,10 +307,12 @@ bool TimeService::DestroyTimer(uint64_t timerId) int32_t TimeService::SetTime(const int64_t time) { pid_t uid = IPCSkeleton::GetCallingUid(); - auto hasPerm = DelayedSingleton::GetInstance()->CheckCallingPermission(uid, setTimePermName_); - if (!hasPerm) { - TIME_HILOGE(TIME_MODULE_SERVICE, "Permission check failed, uid : %{public}d", uid); - return E_TIME_NO_PERMISSION; + if (uid != 0) { + auto hasPerm = DelayedSingleton::GetInstance()->CheckCallingPermission(uid, setTimePermName_); + if (!hasPerm) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Permission check failed, uid : %{public}d", uid); + return E_TIME_NO_PERMISSION; + } } TIME_HILOGI(TIME_MODULE_SERVICE, "Setting time of day to milliseconds: %{public}" PRId64 "", time); if (time < 0 || time / 1000LL >= LONG_MAX) { diff --git a/services/time_manager/src/time_service_client.cpp b/services/time_manager/src/time_service_client.cpp index 613d5a5..a3233e0 100644 --- a/services/time_manager/src/time_service_client.cpp +++ b/services/time_manager/src/time_service_client.cpp @@ -44,7 +44,7 @@ TimeServiceClient::~TimeServiceClient() sptr TimeServiceClient::GetInstance() { if (instance_ == nullptr) { - std::lock_guard lock(instanceLock_); + std::lock_guard autoLock(instanceLock_); if (instance_ == nullptr) { instance_ = new TimeServiceClient; } diff --git a/services/time_manager/src/time_service_proxy.cpp b/services/time_manager/src/time_service_proxy.cpp index c7fd527..50cef20 100644 --- a/services/time_manager/src/time_service_proxy.cpp +++ b/services/time_manager/src/time_service_proxy.cpp @@ -143,12 +143,12 @@ bool TimeServiceProxy::DestroyTimer(uint64_t timerId) if (!data.WriteInterfaceToken(GetDescriptor())) { TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write parcelable"); - return E_TIME_WRITE_PARCEL_ERROR; + return false; } if (!data.WriteUint64(timerId)) { TIME_HILOGE(TIME_MODULE_CLIENT, "Failed to write parcelable"); - return E_TIME_WRITE_PARCEL_ERROR; + return false; } int32_t result = Remote()->SendRequest(DESTORY_TIMER, data, reply, option); if (result != ERR_NONE) { diff --git a/services/time_manager/src/time_tick_notify.cpp b/services/time_manager/src/time_tick_notify.cpp index cc2e878..39843a0 100644 --- a/services/time_manager/src/time_tick_notify.cpp +++ b/services/time_manager/src/time_tick_notify.cpp @@ -67,7 +67,8 @@ void TimeTickNotify::RefreshNextTriggerTime() time_t t = time(NULL); struct tm *tblock = localtime(&t); TIME_HILOGI(TIME_MODULE_SERVICE, "Time now: %{public}s", asctime(tblock)); - auto UTCTimeMicro = system_clock::now().time_since_epoch().count(); + auto UTCTimeMicro = duration_cast(system_clock::now().time_since_epoch()).count(); + TIME_HILOGD(TIME_MODULE_SERVICE, "Time Now Mirc: %{public}" PRId64 "", UTCTimeMicro); auto BootTimeNano = steady_clock::now().time_since_epoch().count(); auto BootTimeMilli = BootTimeNano / NANO_TO_MILESECOND; auto timeMilliseconds = GetMillisecondsFromUTC(UTCTimeMicro); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 7a99b85..d08c447 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -42,8 +42,8 @@ ohos_source_set("time_utils") { external_deps = [ "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", "permission_standard:libpermissionsdk_standard", + "ipc:ipc_core", ] part_name = "time_native" diff --git a/utils/native/src/time_permission.cpp b/utils/native/src/time_permission.cpp index 2064ed3..e37971f 100644 --- a/utils/native/src/time_permission.cpp +++ b/utils/native/src/time_permission.cpp @@ -47,7 +47,7 @@ bool TimePermission::CheckCallingPermission(int32_t uid, std::string permName) if (!ret) { TIME_HILOGE(TIME_MODULE_COMMON, "get bundle name failed"); // always true - return true; + return false; } auto userId = uid / UID_TO_USERID; TIME_HILOGI(TIME_MODULE_COMMON, "VerifyPermission bundleName: %{public}s, permission: %{public}s",