mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-27 17:10:44 +00:00
Merge branch 'master' of gitee.com:openharmony/base_location into master
Signed-off-by: liuxinbing <liuxinbing4@huawei.com>
This commit is contained in:
commit
300d2eb2c6
@ -76,7 +76,8 @@
|
||||
"image_framework",
|
||||
"movement",
|
||||
"device_standby",
|
||||
"time_service"
|
||||
"time_service",
|
||||
"netmanager_base"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
|
@ -56,9 +56,10 @@ declare_args() {
|
||||
hdf_drivers_interface_location_geofence_enable = true
|
||||
multimedia_image_framework_enable = true
|
||||
notification_distributed_notification_service_enable = true
|
||||
time_service_enable = true
|
||||
movement_client_enable = true
|
||||
location_device_standby_enable = true
|
||||
time_service_enable = true
|
||||
net_manager_enable = true
|
||||
|
||||
if (defined(global_parts_info) && !defined(global_parts_info.global_i18n)) {
|
||||
i18n_enable = false
|
||||
@ -152,4 +153,9 @@ declare_args() {
|
||||
!defined(global_parts_info.time_time_service)) {
|
||||
time_service_enable = false
|
||||
}
|
||||
|
||||
if (defined(global_parts_info) &&
|
||||
!defined(global_parts_info.communication_netmanager_base)) {
|
||||
net_manager_enable = false
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ int LocationDataRdbManager::GetSwitchMode()
|
||||
std::string value = "";
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
auto res = GetParameter(LOCATION_SWITCH_MODE, "", result, MAX_SIZE);
|
||||
if (res <= 0 || strlen(result) == 0) {
|
||||
if (res < 0 || strlen(result) == 0) {
|
||||
LBSLOGE(COMMON_UTILS, "%{public}s get para value failed, res: %{public}d", __func__, res);
|
||||
return UNKNOW_ERROR;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ local_base_sources = [
|
||||
"$LOCATION_NATIVE_DIR/locator_sdk/source/country_code_callback_host.cpp",
|
||||
"$LOCATION_NATIVE_DIR/locator_sdk/source/country_code_manager.cpp",
|
||||
"$LOCATION_NATIVE_DIR/locator_sdk/source/geo_convert_callback_host.cpp",
|
||||
"$LOCATION_NATIVE_DIR/locator_sdk/source/gnss_status_callback_host.cpp",
|
||||
"$LOCATION_NATIVE_DIR/locator_sdk/source/location_data_manager.cpp",
|
||||
"$LOCATION_NATIVE_DIR/locator_sdk/source/location_data_rdb_observer.cpp",
|
||||
"$LOCATION_NATIVE_DIR/locator_sdk/source/location_switch_callback_host.cpp",
|
||||
|
@ -24,8 +24,8 @@ namespace OHOS {
|
||||
namespace Location {
|
||||
class CountryCodeCallbackHost : public IRemoteStub<ICountryCodeCallback> {
|
||||
public:
|
||||
virtual int OnRemoteRequest(uint32_t code,
|
||||
MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
void OnCountryCodeChange(const std::shared_ptr<CountryCode>& country) override;
|
||||
};
|
||||
} // namespace Location
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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 GNSS_STATUS_CALLBACK_HOST_H
|
||||
#define GNSS_STATUS_CALLBACK_HOST_H
|
||||
|
||||
#include "iremote_stub.h"
|
||||
#include "i_gnss_status_callback.h"
|
||||
#include "satellite_status.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GnssStatusCallbackHost : public IRemoteStub<IGnssStatusCallback> {
|
||||
public:
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
void OnStatusChange(const std::unique_ptr<SatelliteStatus>& statusInfo) override;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // GNSS_STATUS_CALLBACK_HOST_H
|
@ -23,8 +23,8 @@ namespace OHOS {
|
||||
namespace Location {
|
||||
class LocatorCallbackHost : public IRemoteStub<ILocatorCallback> {
|
||||
public:
|
||||
virtual int OnRemoteRequest(uint32_t code,
|
||||
MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
void OnLocationReport(const std::unique_ptr<Location>& location) override;
|
||||
void OnLocatingStatusChange(const int status) override;
|
||||
void OnErrorReport(const int errorCode) override;
|
||||
|
@ -21,7 +21,7 @@ namespace Location {
|
||||
int CountryCodeCallbackHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(COUNTRY_CODE_CALLBACK, "CountryCodeCallbackHost::OnRemoteRequest!");
|
||||
LBSLOGD(COUNTRY_CODE_CALLBACK, "CountryCodeCallbackHost::OnRemoteRequest! code %{punlic}d", code);
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
LBSLOGE(COUNTRY_CODE_CALLBACK, "invalid token.");
|
||||
return -1;
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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 "gnss_status_callback_host.h"
|
||||
|
||||
#include "location_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
int GnssStatusCallbackHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(GNSS_STATUS_CALLBACK, "GnssStatusCallbackHost::OnRemoteRequest!");
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
LBSLOGE(GNSS_STATUS_CALLBACK, "invalid token.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case RECEIVE_STATUS_INFO_EVENT: {
|
||||
std::unique_ptr<SatelliteStatus> statusInfo = SatelliteStatus::Unmarshalling(data);
|
||||
OnStatusChange(statusInfo);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GnssStatusCallbackHost::OnStatusChange(const std::unique_ptr<SatelliteStatus>& statusInfo)
|
||||
{
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -21,7 +21,7 @@ namespace Location {
|
||||
int LocationSwitchCallbackHost::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(SWITCH_CALLBACK, "LocationSwitchCallbackHost::OnRemoteRequest!");
|
||||
LBSLOGD(SWITCH_CALLBACK, "LocationSwitchCallbackHost::OnRemoteRequest! code %{punlic}d", code);
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
LBSLOGE(SWITCH_CALLBACK, "invalid token.");
|
||||
return -1;
|
||||
@ -39,6 +39,7 @@ int LocationSwitchCallbackHost::OnRemoteRequest(
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LocationSwitchCallbackHost::OnSwitchChange(int switchState)
|
||||
{
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace Location {
|
||||
int LocatorCallbackHost::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
LBSLOGD(LOCATOR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest!");
|
||||
LBSLOGD(LOCATOR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest! code %{public}d", code);
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
LBSLOGE(LOCATOR_CALLBACK, "invalid token.");
|
||||
return -1;
|
||||
@ -51,6 +51,7 @@ int LocatorCallbackHost::OnRemoteRequest(uint32_t code,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LocatorCallbackHost::OnLocationReport(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
}
|
||||
|
@ -20,8 +20,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
void WriteAppLocatingStateEvent(const std::string& state, const pid_t pid, const pid_t uid);
|
||||
void WriteGnssStateEvent(const std::string& state, const pid_t pid, const pid_t uid);
|
||||
void WriteAppLocatingStateEvent(const std::string& state, const pid_t pid, const pid_t uid);
|
||||
void WriteLocationSwitchStateEvent(const std::string& state);
|
||||
void WriteLocationInnerEvent(const int event, std::vector<std::string> names, std::vector<std::string>& values);
|
||||
void WriteLocationInnerEvent(const int event, std::initializer_list<std::string> params);
|
||||
|
@ -35,6 +35,7 @@
|
||||
"ohos.permission.MANAGE_SETTINGS",
|
||||
"ohos.permission.ACTIVITY_MOTION",
|
||||
"ohos.permission.INTERNET",
|
||||
"ohos.permission.GET_NETWORK_INFO",
|
||||
"ohos.permission.RECEIVE_SMS",
|
||||
"ohos.permission.MANAGE_LOCAL_ACCOUNTS"
|
||||
],
|
||||
|
@ -81,6 +81,7 @@ void GeoConvertService::OnStop()
|
||||
LBSLOGD(GEO_CONVERT, "GeoConvertService::OnStop and disconnect");
|
||||
UnRegisterGeoServiceDeathRecipient();
|
||||
SetServiceConnectState(ServiceConnectState::STATE_DISCONNECT);
|
||||
conn_ = nullptr;
|
||||
}
|
||||
LBSLOGI(GEO_CONVERT, "GeoConvertService::OnStop service stopped.");
|
||||
}
|
||||
@ -346,6 +347,7 @@ void GeoConvertService::DisconnectAbilityConnect()
|
||||
if (conn_ != nullptr) {
|
||||
AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn_);
|
||||
SetServiceConnectState(ServiceConnectState::STATE_DISCONNECT);
|
||||
conn_ = nullptr;
|
||||
LBSLOGI(GEO_CONVERT, "UnloadGeoConvert OnStop and disconnect");
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,12 @@ if (location_feature_with_gnss) {
|
||||
"$LOCATION_GNSS_ROOT/source/gnss_ability_skeleton.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/gnss_common_event_subscriber.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/gnss_event_callback.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/ntp/elapsed_real_time_check.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/ntp/gps_time_manager.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/ntp/net_conn_observer.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/ntp/ntp_time_check.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/ntp/ntp_time_helper.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/ntp/time_manager.cpp",
|
||||
"$LOCATION_GNSS_ROOT/source/string_utils.cpp",
|
||||
"$LOCATION_LOCATOR_ROOT/source/location_config_manager.cpp",
|
||||
"$LOCATION_LOCATOR_ROOT/source/subability_common.cpp",
|
||||
@ -36,6 +42,7 @@ if (location_feature_with_gnss) {
|
||||
include_dirs = [
|
||||
"$LOCATION_ROOT_DIR/interfaces/inner_api/include",
|
||||
"$LOCATION_GNSS_ROOT/include",
|
||||
"$LOCATION_GNSS_ROOT/include/ntp",
|
||||
"$LOCATION_LOCATOR_ROOT/include",
|
||||
]
|
||||
|
||||
@ -143,6 +150,11 @@ if (location_feature_with_gnss) {
|
||||
defines += [ "TIME_SERVICE_ENABLE" ]
|
||||
}
|
||||
|
||||
if (net_manager_enable) {
|
||||
external_deps += [ "netmanager_base:net_conn_manager_if" ]
|
||||
defines += [ "NET_MANAGER_ENABLE" ]
|
||||
}
|
||||
|
||||
# Used to control the export of dynamic library symbols.
|
||||
version_script = "liblbsservice_gnss_version_script.txt"
|
||||
|
||||
@ -156,6 +168,7 @@ if (location_feature_with_gnss) {
|
||||
include_dirs = [
|
||||
"$LOCATION_ROOT_DIR/interfaces/inner_api/include",
|
||||
"$LOCATION_GNSS_ROOT/include",
|
||||
"$LOCATION_GNSS_ROOT/include/ntp",
|
||||
"$LOCATION_LOCATOR_ROOT/include",
|
||||
]
|
||||
|
||||
@ -251,6 +264,11 @@ if (location_feature_with_gnss) {
|
||||
defines += [ "TIME_SERVICE_ENABLE" ]
|
||||
}
|
||||
|
||||
if (net_manager_enable) {
|
||||
external_deps += [ "netmanager_base:net_conn_manager_if" ]
|
||||
defines += [ "NET_MANAGER_ENABLE" ]
|
||||
}
|
||||
|
||||
part_name = "location"
|
||||
subsystem_name = "location"
|
||||
}
|
||||
|
@ -45,6 +45,15 @@
|
||||
#include "geofence_event_callback.h"
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
#include "time_manager.h"
|
||||
#endif
|
||||
#ifdef NET_MANAGER_ENABLE
|
||||
#include "net_conn_observer.h"
|
||||
#include "net_conn_client.h"
|
||||
#include "net_specifier.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
#ifdef __aarch64__
|
||||
@ -211,6 +220,8 @@ public:
|
||||
LocationErrCode SendNetworkLocation(const std::unique_ptr<Location>& location) override;
|
||||
LocationErrCode InjectLocation();
|
||||
LocationErrCode InjectTime();
|
||||
LocationErrCode UpdateNtpTime(int64_t ntpTime, int64_t elapsedTime);
|
||||
void MonitorNetwork();
|
||||
|
||||
private:
|
||||
bool Init();
|
||||
@ -251,6 +262,12 @@ private:
|
||||
std::vector<sptr<INmeaMessageCallback>> nmeaCallback_;
|
||||
sptr<IGnssCallback> gnssCallback_;
|
||||
Location nlpLocation_;
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
TimeManager ntpTime_;
|
||||
#endif
|
||||
#ifdef NET_MANAGER_ENABLE
|
||||
sptr<NetConnObserver> netWorkObserver_ = nullptr;
|
||||
#endif
|
||||
#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
|
||||
sptr<IAGnssCallback> agnssCallback_;
|
||||
#endif
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 ELAPSED_REAL_TIME_CHECK_H
|
||||
#define ELAPSED_REAL_TIME_CHECK_H
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class ElapsedRealTimeCheck {
|
||||
public:
|
||||
static ElapsedRealTimeCheck* GetInstance();
|
||||
void CheckRealTime(int64_t time);
|
||||
bool CanTrustElapsedRealTime();
|
||||
|
||||
private:
|
||||
ElapsedRealTimeCheck();
|
||||
~ElapsedRealTimeCheck();
|
||||
|
||||
int64_t timeBegin_;
|
||||
int64_t timeBeginElapsed_;
|
||||
int64_t timeCheck_;
|
||||
int64_t timeCheckElapsed_;
|
||||
bool canTrustElapsedRealTime_ = true; // default is true, usually we trust this time.
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif // FEATURE_GNSS_SUPPORT
|
||||
#endif // ELAPSED_REAL_TIME_CHECK_H
|
43
services/location_gnss/gnss/include/ntp/gps_time_manager.h
Normal file
43
services/location_gnss/gnss/include/ntp/gps_time_manager.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 GPS_TIME_MANAGER_H
|
||||
#define GPS_TIME_MANAGER_H
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
||||
#include "time_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class GpsTimeManager {
|
||||
public:
|
||||
GpsTimeManager();
|
||||
~GpsTimeManager();
|
||||
int64_t GetGpsTime();
|
||||
void SetGpsTime(int64_t gpsTime, int64_t bootTimeMs);
|
||||
|
||||
private:
|
||||
bool CheckValid(int64_t gpsTime, int64_t lastSystemTime);
|
||||
TimeManager timeManager_;
|
||||
bool validFlag_ {false};
|
||||
int64_t lastSystemTime_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif // FEATURE_GNSS_SUPPORT
|
||||
#endif // GPS_TIME_MANAGER_H
|
47
services/location_gnss/gnss/include/ntp/net_conn_observer.h
Normal file
47
services/location_gnss/gnss/include/ntp/net_conn_observer.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 NETMANAGER_BASE_NET_CONN_CALLBACK_OBSERVER_H
|
||||
#define NETMANAGER_BASE_NET_CONN_CALLBACK_OBSERVER_H
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef NET_MANAGER_ENABLE
|
||||
|
||||
#include "net_all_capabilities.h"
|
||||
#include "net_conn_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class NetConnObserver : public NetManagerStandard::NetConnCallbackStub {
|
||||
public:
|
||||
int32_t NetAvailable(sptr<NetManagerStandard::NetHandle> &netHandle) override;
|
||||
|
||||
int32_t NetCapabilitiesChange(sptr<NetManagerStandard::NetHandle> &netHandle,
|
||||
const sptr<NetManagerStandard::NetAllCapabilities> &netAllCap) override;
|
||||
|
||||
int32_t NetConnectionPropertiesChange(sptr<NetManagerStandard::NetHandle> &netHandle,
|
||||
const sptr<NetManagerStandard::NetLinkInfo> &info) override;
|
||||
|
||||
int32_t NetLost(sptr<NetManagerStandard::NetHandle> &netHandle) override;
|
||||
|
||||
int32_t NetUnavailable() override;
|
||||
|
||||
int32_t NetBlockStatusChange(sptr<NetManagerStandard::NetHandle> &netHandle, bool blocked) override;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
#endif // NET_MANAGER_ENABLE
|
||||
#endif // NETMANAGER_BASE_NET_CONN_CALLBACK_OBSERVER_H
|
45
services/location_gnss/gnss/include/ntp/ntp_time_check.h
Normal file
45
services/location_gnss/gnss/include/ntp/ntp_time_check.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 GPS_NTP_TIME_CHECK_H
|
||||
#define GPS_NTP_TIME_CHECK_H
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
||||
#include "gps_time_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const int64_t DEFAULT_UNCERTAINTY = 30;
|
||||
class NtpTimeCheck {
|
||||
public:
|
||||
static NtpTimeCheck* GetInstance();
|
||||
bool CheckNtpTime(int64_t ntpMsTime, int64_t msTimeSynsBoot);
|
||||
int GetUncertainty();
|
||||
void SetGpsTime(int64_t gpsMsTime, int64_t bootTimeMs);
|
||||
|
||||
private:
|
||||
NtpTimeCheck();
|
||||
~NtpTimeCheck();
|
||||
bool CompareTime(int64_t currentNtpTime, int64_t compareTime);
|
||||
GpsTimeManager gpsTimeManager_;
|
||||
int difference_ = DEFAULT_UNCERTAINTY;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif // FEATURE_GNSS_SUPPORT
|
||||
#endif // GPS_NTP_TIME_CHECK_H
|
49
services/location_gnss/gnss/include/ntp/ntp_time_helper.h
Normal file
49
services/location_gnss/gnss/include/ntp/ntp_time_helper.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 NTP_TIME_HELPER_H
|
||||
#define NTP_TIME_HELPER_H
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
||||
#include <string>
|
||||
#include "time_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
|
||||
struct NtpTrustedTime {
|
||||
int64_t ntpTime = 0;
|
||||
int64_t ageMillis = 0;
|
||||
int64_t elapsedRealTime = 0;
|
||||
};
|
||||
|
||||
class NtpTimeHelper {
|
||||
public:
|
||||
static NtpTimeHelper* GetInstance();
|
||||
void RetrieveAndInjectNtpTime();
|
||||
|
||||
private:
|
||||
NtpTimeHelper() = default;
|
||||
~NtpTimeHelper() = default;
|
||||
|
||||
NtpTrustedTime ntpResult_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif // FEATURE_GNSS_SUPPORT
|
||||
#endif // NTP_TIME_HELPER_H
|
46
services/location_gnss/gnss/include/ntp/time_manager.h
Normal file
46
services/location_gnss/gnss/include/ntp/time_manager.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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_MANAGER_H
|
||||
#define TIME_MANAGER_H
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const int64_t EXPIRT_TIME = 14 * 24 * 60 * 60 * 1000L; // 14 day, two week
|
||||
|
||||
class TimeManager {
|
||||
public:
|
||||
TimeManager() = default;
|
||||
explicit TimeManager(int64_t expireTime) : expireTime_(expireTime) {}
|
||||
~TimeManager() = default;
|
||||
int64_t GetCurrentTime();
|
||||
void SetCurrentTime(int64_t msTime, int64_t msTimeSynsBoot);
|
||||
int64_t GetTimestamp();
|
||||
|
||||
private:
|
||||
int64_t timestamp_ = 0;
|
||||
int64_t timeSynsBoot_ = 0;
|
||||
int64_t expireTime_ = EXPIRT_TIME;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif // FEATURE_GNSS_SUPPORT
|
||||
#endif // TIME_MANAGER_H
|
@ -397,11 +397,11 @@ void AGnssNiManager::SendNiNotification(const GnssNiNotificationRequest ¬if)
|
||||
|
||||
void AGnssNiManager::SendUserResponse(GnssNiResponseCmd responseCmd)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (gnssInterface_ == nullptr) {
|
||||
LBSLOGE(GNSS, "gnssInterfacev1_0 is nullptr");
|
||||
return;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
gnssInterface_->SendNiUserResponse(niNotificationId_, responseCmd);
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@
|
||||
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
#include "time_service_client.h"
|
||||
#include "ntp_time_check.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
@ -70,10 +71,8 @@ constexpr const char *GEOFENCE_SERVICE_NAME = "geofence_interface_service";
|
||||
constexpr const char *UNLOAD_GNSS_TASK = "gnss_sa_unload";
|
||||
const uint32_t RETRY_INTERVAL_OF_UNLOAD_SA = 4 * 60 * EVENT_INTERVAL_UNITE;
|
||||
constexpr int32_t FENCE_MAX_ID = 1000000;
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
constexpr int DEFAULT_UNCERTAINTY = 30;
|
||||
#endif
|
||||
constexpr int NLP_FIX_VALID_TIME = 2;
|
||||
const int64_t INVALID_TIME = 0;
|
||||
}
|
||||
|
||||
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
|
||||
@ -104,11 +103,17 @@ GnssAbility::GnssAbility() : SystemAbility(LOCATION_GNSS_SA_ID, true)
|
||||
if (agnssNiManager != nullptr) {
|
||||
agnssNiManager->SubscribeSaStatusChangeListerner();
|
||||
}
|
||||
MonitorNetwork();
|
||||
LBSLOGI(GNSS, "ability constructed.");
|
||||
}
|
||||
|
||||
GnssAbility::~GnssAbility()
|
||||
{
|
||||
#ifdef NET_MANAGER_ENABLE
|
||||
if (netWorkObserver_ != nullptr) {
|
||||
NetManagerStandard::NetConnClient::GetInstance().UnregisterNetConnCallback(netWorkObserver_);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool GnssAbility::CheckIfHdiConnected()
|
||||
@ -125,8 +130,8 @@ bool GnssAbility::CheckIfHdiConnected()
|
||||
if (!IsDeviceLoaded(GEOFENCE_SERVICE_NAME)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void GnssAbility::OnStart()
|
||||
@ -515,27 +520,69 @@ LocationErrCode GnssAbility::SetPositionMode()
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
void GnssAbility::MonitorNetwork()
|
||||
{
|
||||
#ifdef NET_MANAGER_ENABLE
|
||||
NetManagerStandard::NetSpecifier netSpecifier;
|
||||
NetManagerStandard::NetAllCapabilities netAllCapabilities;
|
||||
netAllCapabilities.netCaps_.insert(NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET);
|
||||
netSpecifier.netCapabilities_ = netAllCapabilities;
|
||||
sptr<NetManagerStandard::NetSpecifier> specifier(
|
||||
new (std::nothrow) NetManagerStandard::NetSpecifier(netSpecifier));
|
||||
if (specifier == nullptr) {
|
||||
LBSLOGE(GNSS, "new operator error.specifier is nullptr");
|
||||
return;
|
||||
}
|
||||
netWorkObserver_ = sptr<NetConnObserver>((new (std::nothrow) NetConnObserver()));
|
||||
if (netWorkObserver_ == nullptr) {
|
||||
LBSLOGE(GNSS, "new operator error.netWorkObserver_ is nullptr");
|
||||
return;
|
||||
}
|
||||
int ret = NetManagerStandard::NetConnClient::GetInstance().RegisterNetConnCallback(specifier, netWorkObserver_, 0);
|
||||
LBSLOGI(GNSS, "RegisterNetConnCallback retcode= %{public}d", ret);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
LocationErrCode GnssAbility::InjectTime()
|
||||
{
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
sptr<IGnssInterface> gnssInterface = IGnssInterface::Get();
|
||||
if (gnssInterface == nullptr) {
|
||||
LBSLOGE(GNSS, "gnssInterface is nullptr");
|
||||
LBSLOGD(GNSS, "InjectTime");
|
||||
int64_t currentTime = ntpTime_.GetCurrentTime();
|
||||
if (currentTime == INVALID_TIME) {
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
GnssRefInfo refInfo;
|
||||
refInfo.type = GnssRefInfoType::GNSS_REF_INFO_TIME;
|
||||
auto wallTime = MiscServices::TimeServiceClient::GetInstance()->GetWallTimeMs();
|
||||
auto elapsedTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
|
||||
if (wallTime < 0 || elapsedTime < 0) {
|
||||
LBSLOGE(GNSS, "get time failed");
|
||||
if (elapsedTime < 0) {
|
||||
LBSLOGE(GNSS, "get boot time failed");
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
refInfo.time.time = wallTime;
|
||||
refInfo.time.elapsedRealtime = elapsedTime;
|
||||
refInfo.time.uncertaintyOfTime = DEFAULT_UNCERTAINTY;
|
||||
gnssInterface->SetGnssReferenceInfo(refInfo);
|
||||
auto ntpTimeCheck = NtpTimeCheck::GetInstance();
|
||||
if (ntpTimeCheck != nullptr && ntpTimeCheck->CheckNtpTime(currentTime, elapsedTime)) {
|
||||
GnssRefInfo refInfo;
|
||||
refInfo.type = GnssRefInfoType::GNSS_REF_INFO_TIME;
|
||||
refInfo.time.time = currentTime;
|
||||
refInfo.time.elapsedRealtime = elapsedTime;
|
||||
refInfo.time.uncertaintyOfTime = ntpTimeCheck->GetUncertainty();
|
||||
auto gnssInterface = IGnssInterface::Get();
|
||||
if (gnssInterface != nullptr) {
|
||||
LBSLOGI(GNSS, "inject ntp time: %{public}s unert %{public}d",
|
||||
std::to_string(currentTime).c_str(), ntpTimeCheck->GetUncertainty());
|
||||
gnssInterface->SetGnssReferenceInfo(refInfo);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
LocationErrCode GnssAbility::UpdateNtpTime(int64_t ntpTime, int64_t elapsedTime)
|
||||
{
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
if (ntpTime <= 0 || elapsedTime <= 0) {
|
||||
LBSLOGE(GNSS, "failed to UpdateNtpTime");
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
ntpTime_.SetCurrentTime(ntpTime, elapsedTime);
|
||||
#endif
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
@ -569,7 +616,9 @@ LocationErrCode GnssAbility::InjectLocation()
|
||||
GnssRefInfo refInfo;
|
||||
refInfo.type = GnssRefInfoType::GNSS_REF_INFO_LOCATION;
|
||||
refInfo.gnssLocation.fieldValidity =
|
||||
GnssLocationValidity::GNSS_LOCATION_LAT_VALID | GnssLocationValidity::GNSS_LOCATION_LONG_VALID;
|
||||
GnssLocationValidity::GNSS_LOCATION_LAT_VALID |
|
||||
GnssLocationValidity::GNSS_LOCATION_LONG_VALID |
|
||||
GnssLocationValidity::GNSS_LOCATION_HORIZONTAL_ACCURACY_VALID;
|
||||
refInfo.gnssLocation.latitude = nlpLocation_.GetLatitude();
|
||||
refInfo.gnssLocation.longitude = nlpLocation_.GetLongitude();
|
||||
refInfo.gnssLocation.altitude = nlpLocation_.GetAltitude();
|
||||
@ -1517,6 +1566,7 @@ void GnssAbility::SendMessage(uint32_t code, MessageParcel &data, MessageParcel
|
||||
}
|
||||
#endif
|
||||
case static_cast<uint32_t>(GnssInterfaceCode::SEND_NETWORK_LOCATION): {
|
||||
LBSLOGI(GNSS, "%{public}s: send network location", __func__);
|
||||
auto request = Location::Unmarshalling(data);
|
||||
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(code, request);
|
||||
SendEvent(event, reply);
|
||||
|
@ -343,6 +343,7 @@ int GnssAbilityStub::QuerySupportCoordinateSystemTypeInner(
|
||||
|
||||
int GnssAbilityStub::SendNetworkLocationInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity)
|
||||
{
|
||||
LBSLOGI(GNSS, "SendNetworkLocationInner");
|
||||
if (!PermissionManager::CheckCallingPermission(identity.GetUid(), identity.GetPid(), reply)) {
|
||||
return ERRCODE_PERMISSION_DENIED;
|
||||
}
|
||||
|
@ -25,6 +25,10 @@
|
||||
#include "common_hisysevent.h"
|
||||
#include "agnss_ni_manager.h"
|
||||
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
#include "ntp_time_check.h"
|
||||
#include "time_service_client.h"
|
||||
#endif
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
@ -37,6 +41,17 @@ bool g_hasLocation = false;
|
||||
bool g_svIncrease = false;
|
||||
std::unique_ptr<SatelliteStatus> g_svInfo = nullptr;
|
||||
|
||||
static void SetGpsTime(int64_t gpsTime)
|
||||
{
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
auto ntpTimeCheck = NtpTimeCheck::GetInstance();
|
||||
if (ntpTimeCheck != nullptr) {
|
||||
auto elapsedRealTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
|
||||
ntpTimeCheck->SetGpsTime(gpsTime, elapsedRealTime);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t GnssEventCallback::ReportLocation(const LocationInfo& location)
|
||||
{
|
||||
auto gnssAbility = GnssAbility::GetInstance();
|
||||
@ -80,6 +95,7 @@ int32_t GnssEventCallback::ReportLocation(const LocationInfo& location)
|
||||
#ifdef FEATURE_PASSIVE_SUPPORT
|
||||
gnssAbility->ReportLocationInfo(PASSIVE_ABILITY, locationNew);
|
||||
#endif
|
||||
SetGpsTime(locationNew->GetTimeStamp());
|
||||
IPCSkeleton::SetCallingIdentity(identity);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
#include "elapsed_real_time_check.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "location_log.h"
|
||||
#include "time_service_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const int64_t MAX_MISS_MS = 24 * 1000; // we only allow 24s misstake
|
||||
|
||||
ElapsedRealTimeCheck *ElapsedRealTimeCheck::GetInstance()
|
||||
{
|
||||
static ElapsedRealTimeCheck data;
|
||||
return &data;
|
||||
}
|
||||
|
||||
ElapsedRealTimeCheck::ElapsedRealTimeCheck() {}
|
||||
|
||||
ElapsedRealTimeCheck::~ElapsedRealTimeCheck() {}
|
||||
|
||||
void ElapsedRealTimeCheck::CheckRealTime(int64_t time)
|
||||
{
|
||||
if (timeBegin_ == 0) {
|
||||
timeBegin_ = time;
|
||||
timeBeginElapsed_ = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
|
||||
} else if (timeCheck_ == 0) {
|
||||
timeCheck_ = time;
|
||||
timeCheckElapsed_ = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
|
||||
} else {
|
||||
LBSLOGD(GNSS, "checkRealTime");
|
||||
}
|
||||
|
||||
if ((timeBegin_ != 0) && (timeCheck_ != 0)) {
|
||||
int64_t missTime = (timeCheck_ - timeBegin_) - (timeCheckElapsed_ - timeBeginElapsed_);
|
||||
LBSLOGD(GNSS,
|
||||
"checkRealTime timeBegin_:%{public}s, timeCheck_:%{public}s, timeBeginElapsed_:%{public}s, "
|
||||
"timeCheckElapsed_:%{public}s",
|
||||
std::to_string(timeBegin_).c_str(), std::to_string(timeCheck_).c_str(),
|
||||
std::to_string(timeBeginElapsed_).c_str(), std::to_string(timeCheckElapsed_).c_str());
|
||||
LBSLOGI(GNSS, "checkRealTime missTime:%{public}s", std::to_string(missTime).c_str());
|
||||
// we found missTime usually should not grow, results should be simillar on any moment.
|
||||
// so if very high missTime should be problem.
|
||||
if (std::abs(missTime) >= MAX_MISS_MS) {
|
||||
LBSLOGI(GNSS, "checkRealTime false");
|
||||
canTrustElapsedRealTime_ = false;
|
||||
} else {
|
||||
// sometimes just once system communication block, this could recover automaticly,
|
||||
// elapsedRealtime still be ok.
|
||||
canTrustElapsedRealTime_ = true;
|
||||
}
|
||||
timeCheck_ = 0;
|
||||
timeCheckElapsed_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ElapsedRealTimeCheck::CanTrustElapsedRealTime()
|
||||
{
|
||||
return canTrustElapsedRealTime_;
|
||||
}
|
||||
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif
|
72
services/location_gnss/gnss/source/ntp/gps_time_manager.cpp
Normal file
72
services/location_gnss/gnss/source/ntp/gps_time_manager.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
||||
#include "gps_time_manager.h"
|
||||
|
||||
#include "elapsed_real_time_check.h"
|
||||
#include "location_log.h"
|
||||
#include "time_service_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const int64_t INVALID_TIME = 0L;
|
||||
const int64_t MAX_MISSTAKE_TIME = 10 * 1000L;
|
||||
|
||||
GpsTimeManager::GpsTimeManager()
|
||||
{
|
||||
timeManager_ = TimeManager(EXPIRT_TIME);
|
||||
}
|
||||
|
||||
GpsTimeManager::~GpsTimeManager() {}
|
||||
|
||||
bool GpsTimeManager::CheckValid(int64_t gpsTime, int64_t lastSystemTime)
|
||||
{
|
||||
int64_t bootTimeDiff = gpsTime - timeManager_.GetTimestamp();
|
||||
int64_t systemTimeDiff = MiscServices::TimeServiceClient::GetInstance()->GetWallTimeMs() - lastSystemTime;
|
||||
if (abs(bootTimeDiff - systemTimeDiff) > MAX_MISSTAKE_TIME) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t GpsTimeManager::GetGpsTime()
|
||||
{
|
||||
int64_t tmpTime = timeManager_.GetCurrentTime();
|
||||
if ((!validFlag_) && (tmpTime > 0)) {
|
||||
if (!CheckValid(tmpTime, lastSystemTime_)) {
|
||||
return INVALID_TIME;
|
||||
}
|
||||
}
|
||||
return tmpTime;
|
||||
}
|
||||
|
||||
void GpsTimeManager::SetGpsTime(int64_t gpsMsTime, int64_t bootTimeMs)
|
||||
{
|
||||
validFlag_ = true;
|
||||
lastSystemTime_ = MiscServices::TimeServiceClient::GetInstance()->GetWallTimeMs();
|
||||
timeManager_.SetCurrentTime(gpsMsTime, bootTimeMs);
|
||||
auto elapsedRealTimeCheck = ElapsedRealTimeCheck::GetInstance();
|
||||
if (elapsedRealTimeCheck != nullptr) {
|
||||
elapsedRealTimeCheck->CheckRealTime(gpsMsTime);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif
|
75
services/location_gnss/gnss/source/ntp/net_conn_observer.cpp
Normal file
75
services/location_gnss/gnss/source/ntp/net_conn_observer.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef NET_MANAGER_ENABLE
|
||||
#include "net_conn_observer.h"
|
||||
|
||||
#include "location_log.h"
|
||||
#include "ntp_time_helper.h"
|
||||
|
||||
using namespace OHOS::NetManagerStandard;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
int32_t NetConnObserver::NetAvailable(sptr<NetHandle> &netHandle)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t NetConnObserver::NetCapabilitiesChange(sptr<NetHandle> &netHandle,
|
||||
const sptr<NetAllCapabilities> &netAllCap)
|
||||
{
|
||||
LBSLOGI(GNSS, "Observe network capabilities change");
|
||||
if (netAllCap == nullptr) {
|
||||
LBSLOGE(GNSS, "Observe network netAllCap is null");
|
||||
return -1;
|
||||
}
|
||||
if (netAllCap->netCaps_.count(NetCap::NET_CAPABILITY_INTERNET)) {
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
auto npTimeHelper = NtpTimeHelper::GetInstance();
|
||||
if (npTimeHelper != nullptr) {
|
||||
npTimeHelper->RetrieveAndInjectNtpTime();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t NetConnObserver::NetConnectionPropertiesChange(sptr<NetHandle> &netHandle,
|
||||
const sptr<NetLinkInfo> &info)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t NetConnObserver::NetLost(sptr<NetHandle> &netHandle)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t NetConnObserver::NetUnavailable()
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t NetConnObserver::NetBlockStatusChange(sptr<NetHandle> &netHandle, bool blocked)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
#endif
|
86
services/location_gnss/gnss/source/ntp/ntp_time_check.cpp
Normal file
86
services/location_gnss/gnss/source/ntp/ntp_time_check.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
#include "ntp_time_check.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "location_log.h"
|
||||
#include "time_service_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const int64_t INVALID_TIME = 0;
|
||||
const int64_t MISSTAKE_TIME = 50 * 1000; // 50s
|
||||
|
||||
NtpTimeCheck::NtpTimeCheck() {}
|
||||
|
||||
NtpTimeCheck::~NtpTimeCheck() {}
|
||||
|
||||
NtpTimeCheck *NtpTimeCheck::GetInstance()
|
||||
{
|
||||
static NtpTimeCheck data;
|
||||
return &data;
|
||||
}
|
||||
|
||||
bool NtpTimeCheck::CheckNtpTime(int64_t ntpMsTime, int64_t msTimeSynsBoot)
|
||||
{
|
||||
int64_t currentNtpTime =
|
||||
ntpMsTime + MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs() - msTimeSynsBoot;
|
||||
if (gpsTimeManager_.GetGpsTime() != INVALID_TIME) {
|
||||
return CompareTime(currentNtpTime, gpsTimeManager_.GetGpsTime());
|
||||
}
|
||||
|
||||
LBSLOGI(GNSS, "checkNtpTime return false");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NtpTimeCheck::CompareTime(int64_t currentNtpTime, int64_t compareTime)
|
||||
{
|
||||
LBSLOGI(GNSS, "compareTime currentNtpTime:%{public}s, compareTime:%{public}s",
|
||||
std::to_string(currentNtpTime).c_str(), std::to_string(compareTime).c_str());
|
||||
int64_t misstake = std::abs(currentNtpTime - compareTime);
|
||||
if (misstake > MISSTAKE_TIME) {
|
||||
LBSLOGI(GNSS, "find error ntp time:%{public}s", std::to_string(misstake).c_str());
|
||||
return false;
|
||||
} else {
|
||||
difference_ = misstake;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void NtpTimeCheck::SetGpsTime(int64_t gpsMsTime, int64_t bootTimeMs)
|
||||
{
|
||||
if (gpsMsTime <= 0 || bootTimeMs <= 0) {
|
||||
LBSLOGE(GNSS, "set gps time failed :%{public}s, %{public}s", std::to_string(gpsMsTime).c_str(),
|
||||
std::to_string(bootTimeMs).c_str());
|
||||
return;
|
||||
}
|
||||
gpsTimeManager_.SetGpsTime(gpsMsTime, bootTimeMs);
|
||||
}
|
||||
|
||||
int NtpTimeCheck::GetUncertainty()
|
||||
{
|
||||
return (difference_ > DEFAULT_UNCERTAINTY) ? difference_ : DEFAULT_UNCERTAINTY;
|
||||
}
|
||||
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif
|
67
services/location_gnss/gnss/source/ntp/ntp_time_helper.cpp
Normal file
67
services/location_gnss/gnss/source/ntp/ntp_time_helper.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
#include "ntp_time_helper.h"
|
||||
|
||||
#include <string>
|
||||
#include "gnss_ability.h"
|
||||
#include "location_log.h"
|
||||
#include "ntp_time_check.h"
|
||||
#include "time_service_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
static const int64_t NTP_INTERVAL = 24 * 60 * 60 * 1000;
|
||||
|
||||
NtpTimeHelper *NtpTimeHelper::GetInstance()
|
||||
{
|
||||
static NtpTimeHelper data;
|
||||
return &data;
|
||||
}
|
||||
|
||||
void NtpTimeHelper::RetrieveAndInjectNtpTime()
|
||||
{
|
||||
if (ntpResult_.elapsedRealTime > 0) {
|
||||
ntpResult_.ageMillis =
|
||||
MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs() - ntpResult_.elapsedRealTime;
|
||||
LBSLOGD(GNSS, "ntp age millis %{public}s", std::to_string(ntpResult_.ageMillis).c_str());
|
||||
}
|
||||
|
||||
auto gnssAbility = GnssAbility::GetInstance();
|
||||
if (ntpResult_.ntpTime == 0 || ntpResult_.ageMillis > NTP_INTERVAL) {
|
||||
auto ret = MiscServices::TimeServiceClient::GetInstance()->GetNtpTimeMs(ntpResult_.ntpTime);
|
||||
if (ret != ERR_OK) {
|
||||
ntpResult_.ntpTime = 0;
|
||||
LBSLOGE(GNSS, "failed to get ntp time %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
LBSLOGI(GNSS, "get ntp time %{public}s", std::to_string(ntpResult_.ntpTime).c_str());
|
||||
ntpResult_.elapsedRealTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs();
|
||||
ntpResult_.ageMillis = 0;
|
||||
if (gnssAbility != nullptr) {
|
||||
gnssAbility->UpdateNtpTime(ntpResult_.ntpTime, ntpResult_.elapsedRealTime);
|
||||
}
|
||||
}
|
||||
if (gnssAbility != nullptr) {
|
||||
gnssAbility->InjectTime();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif
|
68
services/location_gnss/gnss/source/ntp/time_manager.cpp
Normal file
68
services/location_gnss/gnss/source/ntp/time_manager.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
#include "time_manager.h"
|
||||
|
||||
#include <string>
|
||||
#include "common_utils.h"
|
||||
#include "elapsed_real_time_check.h"
|
||||
#include "location_log.h"
|
||||
#include "time_service_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
const int64_t INVALID_TIME = 0;
|
||||
const int64_t GPS_UTC_REFERENCE_TIME = 946656000; // 946656000:UTC time of 2000-01-01 00:00:00
|
||||
|
||||
int64_t TimeManager::GetCurrentTime()
|
||||
{
|
||||
LBSLOGI(GNSS, "beginning timestamp_ is %{public}s", std::to_string(timestamp_).c_str());
|
||||
if (timestamp_ < GPS_UTC_REFERENCE_TIME) {
|
||||
return INVALID_TIME;
|
||||
}
|
||||
if (!ElapsedRealTimeCheck::GetInstance()->CanTrustElapsedRealTime()) {
|
||||
LBSLOGI(GNSS, "getCurrentTime ElapsedRealTime INVALID_TIME");
|
||||
return INVALID_TIME;
|
||||
}
|
||||
|
||||
int64_t timeTillNow = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs() - timeSynsBoot_;
|
||||
if (timeTillNow >= expireTime_) {
|
||||
LBSLOGI(GNSS, "getCurrentTime INVALID_TIME");
|
||||
return INVALID_TIME;
|
||||
} else {
|
||||
LBSLOGI(GNSS, "getCurrentTime:%{public}s", std::to_string(timestamp_ + timeTillNow).c_str());
|
||||
return timestamp_ + timeTillNow;
|
||||
}
|
||||
}
|
||||
|
||||
void TimeManager::SetCurrentTime(int64_t msTime, int64_t msTimeSynsBoot)
|
||||
{
|
||||
timestamp_ = msTime;
|
||||
timeSynsBoot_ = msTimeSynsBoot;
|
||||
LBSLOGI(GNSS, "setCurrentTime timestamp_:%{public}s, mTimeReference:%{public}s",
|
||||
std::to_string(timestamp_).c_str(), std::to_string(timeSynsBoot_).c_str());
|
||||
}
|
||||
|
||||
int64_t TimeManager::GetTimestamp()
|
||||
{
|
||||
return timestamp_;
|
||||
}
|
||||
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // TIME_SERVICE_ENABLE
|
||||
#endif
|
@ -61,7 +61,6 @@ public:
|
||||
void OpenPrivacyDialog();
|
||||
void ConnectExtensionAbility(const AAFwk::Want &want, const std::string &commandStr);
|
||||
std::string GenerateStartCommand();
|
||||
int GetCachePrivacyType();
|
||||
bool SetCachePrivacyType(int value);
|
||||
|
||||
/*
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
void RemoveUnloadTask(uint32_t code) override;
|
||||
void PostUnloadTask(uint32_t code) override;
|
||||
ServiceRunningState QueryServiceState() const
|
||||
{
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
void InitSaAbility();
|
||||
|
@ -261,11 +261,6 @@ int LocationConfigManager::SetLocationSwitchState(int state)
|
||||
LocationErrCode LocationConfigManager::GetPrivacyTypeState(const int type, bool& isConfirmed)
|
||||
{
|
||||
int status = 0;
|
||||
int cacheState = GetCachePrivacyType();
|
||||
if (cacheState == DISABLED || cacheState == ENABLED) {
|
||||
isConfirmed = (status == 1);
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
if (!LocationDataRdbManager::GetLocationEnhanceStatus(status)) {
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
@ -273,11 +268,6 @@ LocationErrCode LocationConfigManager::GetPrivacyTypeState(const int type, bool&
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
int LocationConfigManager::GetCachePrivacyType()
|
||||
{
|
||||
return GetIntParameter(LOCATION_PRIVACY_MODE);
|
||||
}
|
||||
|
||||
bool LocationConfigManager::SetCachePrivacyType(int value)
|
||||
{
|
||||
char valueArray[MAX_SIZE] = {0};
|
||||
@ -296,7 +286,6 @@ LocationErrCode LocationConfigManager::SetPrivacyTypeState(const int type, bool
|
||||
if (!LocationDataRdbManager::SetLocationEnhanceStatus(status)) {
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
SetCachePrivacyType(status);
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ void LocatorAbility::SendSwitchState(const int state)
|
||||
|
||||
bool LocatorAbility::CheckIfLocatorConnecting()
|
||||
{
|
||||
return LocatorRequiredDataManager::GetInstance()->IsConnecting() && GetActiveRequestNum() > 0;
|
||||
return LocatorRequiredDataManager::GetInstance()->IsConnecting() || GetActiveRequestNum() > 0;
|
||||
}
|
||||
|
||||
LocationErrCode LocatorAbility::EnableAbility(bool isEnabled)
|
||||
@ -935,8 +935,7 @@ LocationErrCode LocatorAbility::StartLocating(std::unique_ptr<RequestConfig>& re
|
||||
|
||||
bool LocatorAbility::IsCacheVaildScenario(const sptr<RequestConfig>& requestConfig)
|
||||
{
|
||||
if (requestConfig->GetFixNumber() == 1 &&
|
||||
requestConfig->GetPriority() != LOCATION_PRIORITY_ACCURACY &&
|
||||
if (requestConfig->GetPriority() != LOCATION_PRIORITY_ACCURACY &&
|
||||
((requestConfig->GetPriority() == LOCATION_PRIORITY_LOCATING_SPEED) ||
|
||||
(requestConfig->GetScenario() == SCENE_DAILY_LIFE_SERVICE) ||
|
||||
((requestConfig->GetScenario() == SCENE_UNSET) && (requestConfig->GetPriority() == PRIORITY_FAST_FIRST_FIX)) ||
|
||||
@ -971,7 +970,7 @@ bool LocatorAbility::NeedReportCacheLocation(const std::shared_ptr<Request>& req
|
||||
if (reportManager_ == nullptr || request == nullptr) {
|
||||
return false;
|
||||
}
|
||||
// report cache location in single location request
|
||||
// report cache location
|
||||
if (IsSingleRequest(request->GetRequestConfig()) && IsCacheVaildScenario(request->GetRequestConfig())) {
|
||||
auto cacheLocation = reportManager_->GetCacheLocation(request);
|
||||
if (cacheLocation != nullptr && callback != nullptr) {
|
||||
@ -1622,19 +1621,19 @@ bool LocatorAbility::IsProcessRunning(pid_t pid, const uint32_t tokenId)
|
||||
sptr<ISystemAbilityManager> samgrClient = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgrClient == nullptr) {
|
||||
LBSLOGE(LOCATOR, "Get system ability manager failed.");
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
sptr<AppExecFwk::IAppMgr> iAppManager =
|
||||
iface_cast<AppExecFwk::IAppMgr>(samgrClient->GetSystemAbility(APP_MGR_SERVICE_ID));
|
||||
if (iAppManager == nullptr) {
|
||||
LBSLOGE(LOCATOR, "Failed to get ability manager service.");
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
std::vector<AppExecFwk::RunningProcessInfo> runningProcessList;
|
||||
int32_t res = iAppManager->GetAllRunningProcesses(runningProcessList);
|
||||
if (res != ERR_OK) {
|
||||
LBSLOGE(LOCATOR, "Failed to get all running process.");
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
auto it = std::find_if(runningProcessList.begin(), runningProcessList.end(), [pid] (auto runningProcessInfo) {
|
||||
return pid == runningProcessInfo.pid_;
|
||||
|
@ -35,8 +35,8 @@ const long NANOS_PER_MILLI = 1000000L;
|
||||
const int MAX_SA_SCHEDULING_JITTER_MS = 200;
|
||||
static constexpr double MAXIMUM_FUZZY_LOCATION_DISTANCE = 4000.0; // Unit m
|
||||
static constexpr double MINIMUM_FUZZY_LOCATION_DISTANCE = 3000.0; // Unit m
|
||||
static constexpr int GNSS_FIX_CACHED_TIME = 60;
|
||||
static constexpr int NLP_FIX_CACHED_TIME = 45;
|
||||
static constexpr int GNSS_FIX_CACHED_TIME = 25;
|
||||
static constexpr int NLP_FIX_CACHED_TIME = 25;
|
||||
|
||||
ReportManager* ReportManager::GetInstance()
|
||||
{
|
||||
|
@ -280,6 +280,7 @@ void NetworkAbility::RequestRecord(WorkRecord &workRecord, bool isAdded)
|
||||
if (GetRequestNum() == 0 && conn_ != nullptr) {
|
||||
LBSLOGI(NETWORK, "RequestRecord disconnect");
|
||||
AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn_);
|
||||
conn_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ export default class ConfirmUIExtAbility extends UIExtensionAbility {
|
||||
let storage: LocalStorage = new LocalStorage(param);
|
||||
session.loadContent('pages/ConfirmDialog', storage);
|
||||
session.setWindowBackgroundColor('#00000000');
|
||||
AppStorage.setOrCreate('ConfirmSession',session);
|
||||
AppStorage.setOrCreate('ConfirmSession', session);
|
||||
}
|
||||
|
||||
onSessionDestroy(session: UIExtensionContentSession) {
|
||||
|
@ -38,7 +38,7 @@ export default class LocationPrivacyExtAbility extends UIExtensionAbility {
|
||||
let storage: LocalStorage = new LocalStorage(param);
|
||||
session.loadContent('pages/LocationPrivacyDialog', storage);
|
||||
session.setWindowBackgroundColor('#00000000');
|
||||
AppStorage.setOrCreate('ConfirmSession',session);
|
||||
AppStorage.setOrCreate('ConfirmSession', session);
|
||||
}
|
||||
|
||||
onSessionDestroy(session: UIExtensionContentSession) {
|
||||
|
@ -17,8 +17,8 @@ import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSessi
|
||||
import commonEventManager from '@ohos.commonEventManager';
|
||||
|
||||
let TAG = '[AGNSS-NI:ConfirmDialog]==>';
|
||||
const AGNSS_NI_ACCEPT_EVENT: string = "usual.event.AGNSS_NI_ACCEPT";
|
||||
const AGNSS_NI_REJECT_EVENT: string = "usual.event.AGNSS_NI_REJECT";
|
||||
const AGNSS_NI_ACCEPT_EVENT: string = 'usual.event.AGNSS_NI_ACCEPT';
|
||||
const AGNSS_NI_REJECT_EVENT: string = 'usual.event.AGNSS_NI_REJECT';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -17,8 +17,8 @@ import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSessi
|
||||
import commonEventManager from '@ohos.commonEventManager';
|
||||
|
||||
let TAG = '[Location-Privacy]==>';
|
||||
const LOCATION_PRIVACY_ACCEPT_EVENT: string = "usual.event.LOCATION_PRIVACY_ACCEPT";
|
||||
const LOCATION_PRIVACY_REJECT_EVENT: string = "usual.event.LOCATION_PRIVACY_REJECT";
|
||||
const LOCATION_PRIVACY_ACCEPT_EVENT: string = 'usual.event.LOCATION_PRIVACY_ACCEPT';
|
||||
const LOCATION_PRIVACY_REJECT_EVENT: string = 'usual.event.LOCATION_PRIVACY_REJECT';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -26,6 +26,7 @@ if (location_feature_with_gnss) {
|
||||
"$GNSS_UNIT_TEST_DIR/source/gnss_ability_test.cpp",
|
||||
"$GNSS_UNIT_TEST_DIR/source/gnss_event_callback_test.cpp",
|
||||
"$GNSS_UNIT_TEST_DIR/source/gnss_interface_test.cpp",
|
||||
"$GNSS_UNIT_TEST_DIR/source/ntp_time_test.cpp",
|
||||
"$LOCATION_ROOT_DIR/test/mock/src/mock_service_registry.cpp",
|
||||
]
|
||||
|
||||
|
30
test/location_gnss/include/ntp_time_test.h
Normal file
30
test/location_gnss/include/ntp_time_test.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 NTP_TIME_TEST_H
|
||||
#define NTP_TIME_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class NtpTimeTest : public testing::Test {
|
||||
public:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // NTP_TIME_TEST_H
|
62
test/location_gnss/source/ntp_time_test.cpp
Normal file
62
test/location_gnss/source/ntp_time_test.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ntp_time_test.h"
|
||||
|
||||
#include "location_log.h"
|
||||
#include "ntp_time_check.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
void NtpTimeTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void NtpTimeTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(NtpTimeTest, NtpTimeCheckSetGpsTimeTest001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO)
|
||||
<< "NtpTimeTest, NtpTimeCheckSetGpsTimeTest001, TestSize.Level1";
|
||||
LBSLOGI(GNSS_TEST, "[NtpTimeTest] NtpTimeCheckSetGpsTimeTest001 begin");
|
||||
auto ntpTimeCheck = NtpTimeCheck::GetInstance();
|
||||
EXPECT_NE(nullptr, ntpTimeCheck);
|
||||
int64_t gpsMsTime = -1;
|
||||
int64_t bootTimeMs = -1;
|
||||
ntpTimeCheck->SetGpsTime(gpsMsTime, bootTimeMs);
|
||||
LBSLOGI(GNSS_TEST, "[NtpTimeTest] NtpTimeCheckSetGpsTimeTest001 end");
|
||||
}
|
||||
|
||||
HWTEST_F(NtpTimeTest, NtpTimeCheckCheckNtpTimeTest001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO)
|
||||
<< "NtpTimeTest, NtpTimeCheckCheckNtpTimeTest001, TestSize.Level1";
|
||||
LBSLOGI(GNSS_TEST, "[NtpTimeTest] NtpTimeCheckCheckNtpTimeTest001 begin");
|
||||
auto ntpTimeCheck = NtpTimeCheck::GetInstance();
|
||||
EXPECT_NE(nullptr, ntpTimeCheck);
|
||||
int64_t gpsMsTime = 1720522730000;
|
||||
int64_t bootTimeMs = 1;
|
||||
ntpTimeCheck->SetGpsTime(gpsMsTime, bootTimeMs);
|
||||
int64_t ntpMsTime = 1720522730000;
|
||||
int64_t msTimeSynsBoot = 1;
|
||||
ntpTimeCheck->CheckNtpTime(ntpMsTime, msTimeSynsBoot);
|
||||
LBSLOGI(GNSS_TEST, "[NtpTimeTest] NtpTimeCheckCheckNtpTimeTest001 end");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -202,14 +202,5 @@ HWTEST_F(LocationConfigManagerTest, SetCachePrivacyType001, TestSize.Level1)
|
||||
LocationConfigManager::GetInstance()->SetCachePrivacyType(111);
|
||||
LBSLOGI(LOCATOR, "[LocationConfigManagerTest] SetCachePrivacyType001 end");
|
||||
}
|
||||
|
||||
HWTEST_F(LocationConfigManagerTest, GetCachePrivacyType001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO)
|
||||
<< "LocationConfigManagerTest, GetCachePrivacyType001, TestSize.Level1";
|
||||
LBSLOGI(LOCATOR, "[LocationConfigManagerTest] GetCachePrivacyType001 begin");
|
||||
LocationConfigManager::GetInstance()->GetCachePrivacyType();
|
||||
LBSLOGI(LOCATOR, "[LocationConfigManagerTest] GetCachePrivacyType001 end");
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user