mirror of
https://github.com/openharmony/miscservices_time.git
synced 2026-07-19 20:03:38 -04:00
@@ -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",
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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<TimePermission>::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<TimePermission>::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) {
|
||||
|
||||
@@ -44,7 +44,7 @@ TimeServiceClient::~TimeServiceClient()
|
||||
sptr<TimeServiceClient> TimeServiceClient::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> lock(instanceLock_);
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new TimeServiceClient;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<microseconds>(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);
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user