mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-23 23:10:05 +00:00
多用户优化
Signed-off-by: 李文龙 <liwenlong22@huawei.com>
This commit is contained in:
parent
2a8174f707
commit
95ada2620b
@ -42,7 +42,7 @@ static std::mt19937 g_gen(g_randomDevice());
|
||||
static std::uniform_int_distribution<> g_dis(0, 15); // random between 0 and 15
|
||||
static std::uniform_int_distribution<> g_dis2(8, 11); // random between 8 and 11
|
||||
const int64_t SEC_TO_NANO = 1000 * 1000 * 1000;
|
||||
|
||||
const int DEFAULT_USERID = 100;
|
||||
int CommonUtils::AbilityConvertToId(const std::string ability)
|
||||
{
|
||||
if (GNSS_ABILITY.compare(ability) == 0) {
|
||||
@ -404,17 +404,21 @@ std::string CommonUtils::GenerateUuid()
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool CommonUtils::CheckAppForUser(int32_t uid)
|
||||
|
||||
bool CommonUtils::CheckAppForUser(int32_t uid, std::string bundleName)
|
||||
{
|
||||
if (HookUtils::ExecuteHookWhenCheckAppForUser(bundleName)) {
|
||||
return true;
|
||||
}
|
||||
int currentUserId = 0;
|
||||
int userId = 0;
|
||||
bool ret = GetCurrentUserId(currentUserId);
|
||||
if (!ret) {
|
||||
return true;
|
||||
if (!GetCurrentUserId(currentUserId)) {
|
||||
currentUserId = DEFAULT_USERID;
|
||||
}
|
||||
auto result = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
|
||||
if (result != ERR_OK) {
|
||||
return true;
|
||||
LBSLOGE(COMMON_UTILS, "CheckAppForUser GetOsAccountLocalIdFromUid fail");
|
||||
return false;
|
||||
}
|
||||
if (userId != currentUserId) {
|
||||
return false;
|
||||
|
@ -116,6 +116,16 @@ bool HookUtils::ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, st
|
||||
return locatorRequestStruct.result;
|
||||
}
|
||||
|
||||
bool HookUtils::ExecuteHookWhenCheckAppForUser(std::string packageName)
|
||||
{
|
||||
LocatorRequestStruct locatorRequestStruct;
|
||||
locatorRequestStruct.bundleName = packageName;
|
||||
locatorRequestStruct.result = false;
|
||||
ExecuteHook(
|
||||
LocationProcessStage::LOCATOR_SA_LOCATION_PERMISSION_CHECK, (void *)&locatorRequestStruct, nullptr);
|
||||
return locatorRequestStruct.result;
|
||||
}
|
||||
|
||||
bool HookUtils::CheckGnssLocationValidity(const std::unique_ptr<Location>& location)
|
||||
{
|
||||
GnssLocationValidStruct gnssLocationValidStruct;
|
||||
|
@ -24,9 +24,9 @@ const int DEFAULT_USERID = 100;
|
||||
const int DEFAULT_SWITCHMODE = 2;
|
||||
const int UNKNOW_ERROR = -1;
|
||||
const int MAX_SIZE = 100;
|
||||
std::mutex LocationDataRdbManager::mutex_;
|
||||
const std::string LOCATION_ENHANCE_STATUS = "location_enhance_status";
|
||||
|
||||
const std::string LOCATION_ENHANCE_STATUS = "location_enhance_status";
|
||||
std::mutex LocationDataRdbManager::locationSwitchModeMutex_;
|
||||
std::string LocationDataRdbManager::GetLocationDataUri(std::string key)
|
||||
{
|
||||
int userId = 0;
|
||||
@ -106,7 +106,7 @@ int LocationDataRdbManager::GetSwitchMode()
|
||||
{
|
||||
char result[MAX_SIZE] = {0};
|
||||
std::string value = "";
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
std::unique_lock<std::mutex> lock(locationSwitchModeMutex_);
|
||||
auto res = GetParameter(LOCATION_SWITCH_MODE, "", result, MAX_SIZE);
|
||||
if (res < 0 || strlen(result) == 0) {
|
||||
LBSLOGE(COMMON_UTILS, "%{public}s get para value failed, res: %{public}d", __func__, res);
|
||||
@ -129,7 +129,7 @@ bool LocationDataRdbManager::SetSwitchStateToSyspara(int value)
|
||||
{
|
||||
char valueArray[MAX_SIZE] = {0};
|
||||
(void)sprintf_s(valueArray, sizeof(valueArray), "%d", value);
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
std::unique_lock<std::mutex> lock(locationSwitchModeMutex_);
|
||||
int res = SetParameter(LOCATION_SWITCH_MODE, valueArray);
|
||||
if (res < 0) {
|
||||
LBSLOGE(COMMON_UTILS, "%{public}s failed, res: %{public}d", __func__, res);
|
||||
@ -162,9 +162,10 @@ bool LocationDataRdbManager::ClearSwitchMode()
|
||||
if (code <= 0) {
|
||||
return false;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
std::unique_lock<std::mutex> lock(locationSwitchModeMutex_);
|
||||
int res = SetParameter(LOCATION_SWITCH_MODE, valueArray);
|
||||
if (res < 0) {
|
||||
LBSLOGE(COMMON_UTILS, "%{public}s failed, res: %{public}d", __func__, res);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -127,5 +127,14 @@ bool PermissionManager::CheckSystemPermission(uint32_t callerTokenId, uint64_t c
|
||||
bool isSysApp = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callerTokenIdEx);
|
||||
return isSysApp;
|
||||
}
|
||||
|
||||
bool PermissionManager::CheckIsSystemSA(uint32_t tokenId)
|
||||
{
|
||||
auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId);
|
||||
if (tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
@ -28,6 +28,7 @@
|
||||
#include "location_log.h"
|
||||
#include "locator_impl.h"
|
||||
#include "lbs_res_loader.h"
|
||||
#include "permission_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
@ -58,14 +59,28 @@ void CountryCodeManager::NotifyAllListener()
|
||||
return;
|
||||
}
|
||||
auto country = std::make_shared<CountryCode>(*lastCountry_);
|
||||
for (auto callback : countryCodeCallbacks_) {
|
||||
if (callback) {
|
||||
for (const auto& pair : countryCodeCallbacksMap_) {
|
||||
auto callback = pair.first;
|
||||
AppIdentity identity = pair.second;
|
||||
if (CheckPermissionforUser(identity)) {
|
||||
callback->OnCountryCodeChange(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CountryCodeManager::RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
bool CountryCodeManager::CheckPermissionforUser(AppIdentity &identity)
|
||||
{
|
||||
if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) {
|
||||
return true;
|
||||
}
|
||||
if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CountryCodeManager::RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(countryCodeCallbackMutex_, std::defer_lock);
|
||||
lock.lock();
|
||||
@ -74,23 +89,16 @@ void CountryCodeManager::RegisterCountryCodeCallback(const sptr<IRemoteObject>&
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
for (auto item : countryCodeCallbacks_) {
|
||||
if (item && item->AsObject() == callback) {
|
||||
LBSLOGE(COUNTRY_CODE, "callback has registered");
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
sptr<ICountryCodeCallback> countryCodeCallback = iface_cast<ICountryCodeCallback>(callback);
|
||||
if (countryCodeCallback == nullptr) {
|
||||
LBSLOGE(COUNTRY_CODE, "iface_cast ICountryCodeCallback failed!");
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
countryCodeCallbacks_.push_back(countryCodeCallback);
|
||||
LBSLOGD(COUNTRY_CODE, "after uid:%{public}d register, countryCodeCallbacks_ size:%{public}s",
|
||||
uid, std::to_string(countryCodeCallbacks_.size()).c_str());
|
||||
if (countryCodeCallbacks_.size() != 1) {
|
||||
countryCodeCallbacksMap_.insert(std::make_pair(countryCodeCallback, identity));
|
||||
LBSLOGD(COUNTRY_CODE, "after uid:%{public}d register, countryCodeCallbacksMap_ size:%{public}s",
|
||||
identity.GetUid(), std::to_string(countryCodeCallbacksMap_.size()).c_str());
|
||||
if (countryCodeCallbacksMap_.size() != 1) {
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
@ -108,8 +116,8 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr<IRemoteObject>
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
if (countryCodeCallbacks_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "countryCodeCallbacks_ size <= 0");
|
||||
if (countryCodeCallbacksMap_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "countryCodeCallbacksMap_ size <= 0");
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
@ -119,25 +127,19 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr<IRemoteObject>
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
size_t i = 0;
|
||||
for (; i < countryCodeCallbacks_.size(); i++) {
|
||||
if (countryCodeCallbacks_[i] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObject = countryCodeCallbacks_[i]->AsObject();
|
||||
std::map<sptr<ICountryCodeCallback>, AppIdentity>::iterator iter;
|
||||
for (iter = countryCodeCallbacksMap_.begin(); iter != countryCodeCallbacksMap_.end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = iter->first->AsObject();
|
||||
if (remoteObject == callback) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= countryCodeCallbacks_.size()) {
|
||||
LBSLOGD(GNSS, "countryCode callback is not in vector");
|
||||
lock.unlock();
|
||||
return;
|
||||
if (iter != countryCodeCallbacksMap_.end()) {
|
||||
countryCodeCallbacksMap_.erase(iter);
|
||||
}
|
||||
countryCodeCallbacks_.erase(countryCodeCallbacks_.begin() + i);
|
||||
LBSLOGD(COUNTRY_CODE, "after unregister, countryCodeCallbacks_ size:%{public}s",
|
||||
std::to_string(countryCodeCallbacks_.size()).c_str());
|
||||
if (countryCodeCallbacks_.size() != 0) {
|
||||
LBSLOGD(COUNTRY_CODE, "after unregister, countryCodeCallbacksMap_ size:%{public}s",
|
||||
std::to_string(countryCodeCallbacksMap_.size()).c_str());
|
||||
if (countryCodeCallbacksMap_.size() != 0) {
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
@ -149,7 +151,7 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr<IRemoteObject>
|
||||
bool CountryCodeManager::IsCountryCodeRegistered()
|
||||
{
|
||||
std::unique_lock lock(countryCodeCallbackMutex_);
|
||||
return countryCodeCallbacks_.size() != 0;
|
||||
return countryCodeCallbacksMap_.size() != 0;
|
||||
}
|
||||
|
||||
std::string CountryCodeManager::GetCountryCodeByLastLocation()
|
||||
@ -431,7 +433,7 @@ void CountryCodeManager::ReSubscribeEvent()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(countryCodeCallbackMutex_, std::defer_lock);
|
||||
lock.lock();
|
||||
if (countryCodeCallbacks_.size() <= 0) {
|
||||
if (countryCodeCallbacksMap_.size() <= 0) {
|
||||
LBSLOGD(COUNTRY_CODE, "no valid callback registed, no need to subscribe");
|
||||
lock.unlock();
|
||||
return;
|
||||
@ -445,7 +447,7 @@ void CountryCodeManager::ReUnsubscribeEvent()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(countryCodeCallbackMutex_, std::defer_lock);
|
||||
lock.lock();
|
||||
if (countryCodeCallbacks_.size() <= 0) {
|
||||
if (countryCodeCallbacksMap_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "no valid callback registed, no need to unsubscribe");
|
||||
lock.unlock();
|
||||
return;
|
||||
|
@ -274,7 +274,18 @@ bool LocatorImpl::RegisterCountryCodeCallback(const sptr<IRemoteObject>& callbac
|
||||
LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
|
||||
return false;
|
||||
}
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, uid);
|
||||
AppIdentity identity;
|
||||
identity.SetPid(IPCSkeleton::GetCallingPid());
|
||||
identity.SetUid(IPCSkeleton::GetCallingUid());
|
||||
identity.SetTokenId(IPCSkeleton::GetCallingTokenID());
|
||||
identity.SetTokenIdEx(IPCSkeleton::GetCallingFullTokenID());
|
||||
identity.SetFirstTokenId(IPCSkeleton::GetFirstTokenID());
|
||||
std::string bundleName = "";
|
||||
if (!CommonUtils::GetBundleNameByUid(identity.GetUid(), bundleName)) {
|
||||
LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", identity.GetUid());
|
||||
}
|
||||
identity.SetBundleName(bundleName);
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, identity);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -785,7 +796,18 @@ LocationErrCode LocatorImpl::RegisterCountryCodeCallbackV9(const sptr<IRemoteObj
|
||||
LBSLOGE(LOCATOR, "%{public}s countryCodeManager is nullptr", __func__);
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, 0);
|
||||
AppIdentity identity;
|
||||
identity.SetPid(IPCSkeleton::GetCallingPid());
|
||||
identity.SetUid(IPCSkeleton::GetCallingUid());
|
||||
identity.SetTokenId(IPCSkeleton::GetCallingTokenID());
|
||||
identity.SetTokenIdEx(IPCSkeleton::GetCallingFullTokenID());
|
||||
identity.SetFirstTokenId(IPCSkeleton::GetFirstTokenID());
|
||||
std::string bundleName = "";
|
||||
if (!CommonUtils::GetBundleNameByUid(identity.GetUid(), bundleName)) {
|
||||
LBSLOGD(LOCATOR, "Fail to Get bundle name: uid = %{public}d.", identity.GetUid());
|
||||
}
|
||||
identity.SetBundleName(bundleName);
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, identity);
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -590,7 +590,7 @@ LocationErrCode LocatorProxy::UnregisterNmeaMessageCallbackV9(const sptr<IRemote
|
||||
data.WriteObject<IRemoteObject>(callback);
|
||||
LocationErrCode errorCode =
|
||||
SendMsgWithDataReplyV9(static_cast<int>(LocatorInterfaceCode::UNREG_NMEA_CALLBACK_V9), data, reply);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::RegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode);
|
||||
LBSLOGD(LOCATOR_STANDARD, "Proxy::UnRegisterNmeaMessageCallbackV9 Transact ErrCodes = %{public}d", errorCode);
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,11 @@
|
||||
#define APP_IDENTITY_H
|
||||
|
||||
#include <string>
|
||||
#include <parcel.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
class AppIdentity {
|
||||
class AppIdentity : public Parcelable {
|
||||
public:
|
||||
AppIdentity();
|
||||
explicit AppIdentity(pid_t uid, pid_t pid, uint32_t tokenId, uint64_t tokenIdEx, uint32_t firstTokenId);
|
||||
@ -85,6 +86,32 @@ public:
|
||||
{
|
||||
bundleName_ = bundleName;
|
||||
}
|
||||
void ReadFromParcel(Parcel& parcel)
|
||||
{
|
||||
uid_ = parcel.ReadInt32();
|
||||
pid_ = parcel.ReadInt32();
|
||||
tokenId_ = parcel.ReadInt32();
|
||||
tokenIdEx_ = parcel.ReadInt64();
|
||||
firstTokenId_ = parcel.ReadInt32();
|
||||
bundleName_ = parcel.ReadString();
|
||||
}
|
||||
|
||||
bool Marshalling(Parcel& parcel) const
|
||||
{
|
||||
return parcel.WriteInt32(uid_) &&
|
||||
parcel.WriteInt32(pid_) &&
|
||||
parcel.WriteInt32(tokenId_) &&
|
||||
parcel.WriteInt64(tokenIdEx_) &&
|
||||
parcel.WriteInt32(firstTokenId_) &&
|
||||
parcel.WriteString(bundleName_);
|
||||
}
|
||||
|
||||
static std::shared_ptr<AppIdentity> Unmarshalling(Parcel& parcel)
|
||||
{
|
||||
auto identity = std::make_shared<AppIdentity>();
|
||||
identity->ReadFromParcel(parcel);
|
||||
return identity;
|
||||
}
|
||||
|
||||
std::string ToString() const;
|
||||
private:
|
||||
|
@ -176,7 +176,7 @@ public:
|
||||
static bool GetStringParameter(const std::string& type, std::string& value);
|
||||
static bool GetEdmPolicy(std::string& name);
|
||||
static std::string GenerateUuid();
|
||||
static bool CheckAppForUser(int32_t uid);
|
||||
static bool CheckAppForUser(int32_t uid, std::string packageName);
|
||||
static int64_t GetSinceBootTime();
|
||||
};
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "i_locator_callback.h"
|
||||
#include "i_country_code_callback.h"
|
||||
#include "location.h"
|
||||
#include "app_identity.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
@ -37,7 +38,7 @@ public:
|
||||
~CountryCodeManager();
|
||||
std::shared_ptr<CountryCode> GetIsoCountryCode();
|
||||
void UnregisterCountryCodeCallback(const sptr<IRemoteObject>& callback);
|
||||
void RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, pid_t uid);
|
||||
void RegisterCountryCodeCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity);
|
||||
void ReSubscribeEvent();
|
||||
void ReUnsubscribeEvent();
|
||||
bool IsCountryCodeRegistered();
|
||||
@ -54,6 +55,7 @@ private:
|
||||
bool SubscribeLocaleConfigEvent();
|
||||
bool UnsubscribeSimEvent();
|
||||
bool UnsubscribeNetworkStatusEvent();
|
||||
bool CheckPermissionforUser(AppIdentity &identity);
|
||||
|
||||
class LocatorCallback : public IRemoteStub<ILocatorCallback> {
|
||||
public:
|
||||
@ -80,7 +82,7 @@ private:
|
||||
|
||||
std::shared_ptr<CountryCode> lastCountryByLocation_;
|
||||
std::shared_ptr<CountryCode> lastCountry_;
|
||||
std::vector<sptr<ICountryCodeCallback>> countryCodeCallbacks_;
|
||||
std::map<sptr<ICountryCodeCallback>, AppIdentity> countryCodeCallbacksMap_;
|
||||
std::shared_ptr<SimSubscriber> simSubscriber_;
|
||||
std::shared_ptr<NetworkSubscriber> networkSubscriber_;
|
||||
std::mutex simSubscriberMutex_;
|
||||
|
@ -41,6 +41,7 @@ enum class LocationProcessStage {
|
||||
LOCATOR_SA_GET_ADDRESSES_FROM_LOCATIONNAME_PROCESS,
|
||||
WRITE_DFX_INNER_EVENT_PROCESS,
|
||||
ADD_REQUEST_TO_WORK_RECORD,
|
||||
LOCATOR_SA_LOCATION_PERMISSION_CHECK,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -89,6 +90,7 @@ public:
|
||||
static bool ExecuteHookWhenAddWorkRecord(bool stillState, bool idleState, std::string abilityName,
|
||||
std::string bundleName);
|
||||
static bool CheckGnssLocationValidity(const std::unique_ptr<Location>& location);
|
||||
static bool ExecuteHookWhenCheckAppForUser(std::string packageName);
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
static bool GetLocationEnhanceStatus(int32_t& state);
|
||||
static void SyncSwitchStatus();
|
||||
private:
|
||||
static std::mutex mutex_;
|
||||
static std::mutex locationSwitchModeMutex_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
static bool CheckRssProcessName(uint32_t tokenId);
|
||||
static bool CheckSystemPermission(uint32_t callerTokenId, uint64_t callerTokenIdEx);
|
||||
static int GetPermissionLevel(uint32_t tokenId, uint32_t firstTokenId);
|
||||
static bool CheckIsSystemSA(uint32_t tokenId);
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -159,9 +159,9 @@ public:
|
||||
LocationErrCode SendLocationRequest(WorkRecord &workrecord) override;
|
||||
LocationErrCode SetEnable(bool state) override;
|
||||
LocationErrCode RefrashRequirements() override;
|
||||
LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) override;
|
||||
LocationErrCode UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) override;
|
||||
LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) override;
|
||||
LocationErrCode UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) override;
|
||||
LocationErrCode RegisterCachedCallback(const std::unique_ptr<CachedGnssLocationsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback) override;
|
||||
@ -240,6 +240,7 @@ private:
|
||||
bool IsGnssfenceRequestMapExist();
|
||||
bool CheckBundleNameInGnssGeofenceRequestMap(const std::string& bundleName, int fenceId);
|
||||
bool ConnectGnssHdi();
|
||||
bool CheckGnssPermissionforUser(AppIdentity &identity);
|
||||
#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
|
||||
bool ConnectAgnssHdi();
|
||||
#endif
|
||||
@ -258,8 +259,8 @@ private:
|
||||
ffrt::mutex nmeaMutex_;
|
||||
ffrt::mutex hdiMutex_;
|
||||
ffrt::mutex statusMutex_;
|
||||
std::vector<sptr<IGnssStatusCallback>> gnssStatusCallback_;
|
||||
std::vector<sptr<INmeaMessageCallback>> nmeaCallback_;
|
||||
std::map<sptr<IGnssStatusCallback>, AppIdentity> gnssStatusCallbackMap_;
|
||||
std::map<sptr<INmeaMessageCallback>, AppIdentity> nmeaCallbackMap_;
|
||||
sptr<IGnssCallback> gnssCallback_;
|
||||
Location nlpLocation_;
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
@ -34,9 +34,9 @@ class IGnssAbility : public ISubAbility {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"location.IGnssAbility");
|
||||
virtual LocationErrCode RefrashRequirements() = 0;
|
||||
virtual LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
|
||||
virtual LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) = 0;
|
||||
virtual LocationErrCode UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
virtual LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
|
||||
virtual LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) = 0;
|
||||
virtual LocationErrCode UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) = 0;
|
||||
virtual LocationErrCode RegisterCachedCallback(const std::unique_ptr<CachedGnssLocationsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback) = 0;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "locationhub_ipc_interface_code.h"
|
||||
#include "location_log_event_ids.h"
|
||||
#include "location_data_rdb_manager.h"
|
||||
#include "permission_manager.h"
|
||||
|
||||
#ifdef NOTIFICATION_ENABLE
|
||||
#include "notification_request.h"
|
||||
@ -239,7 +240,8 @@ LocationErrCode GnssAbility::RefrashRequirements()
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback,
|
||||
AppIdentity &identity)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "register an invalid gnssStatus callback");
|
||||
@ -253,9 +255,9 @@ LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
std::unique_lock<ffrt::mutex> lock(gnssMutex_);
|
||||
gnssStatusCallback_.push_back(gnssStatusCallback);
|
||||
LBSLOGD(GNSS, "after uid:%{public}d register, gnssStatusCallback size:%{public}s",
|
||||
uid, std::to_string(gnssStatusCallback_.size()).c_str());
|
||||
gnssStatusCallbackMap_.insert(std::make_pair(gnssStatusCallback, identity));
|
||||
LBSLOGD(GNSS, "RegisterGnssStatusCallback uid:%{public}d register, gnssStatusCallback size:%{public}s",
|
||||
identity.GetUid(), std::to_string(gnssStatusCallbackMap_.size()).c_str());
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -272,28 +274,29 @@ LocationErrCode GnssAbility::UnregisterGnssStatusCallback(const sptr<IRemoteObje
|
||||
}
|
||||
|
||||
std::unique_lock<ffrt::mutex> lock(gnssMutex_);
|
||||
if (gnssStatusCallback_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "gnssStatusCallback_ size <= 0");
|
||||
if (gnssStatusCallbackMap_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "gnssStatusCallbackMap_ size <= 0");
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
size_t i = 0;
|
||||
for (; i < gnssStatusCallback_.size(); i++) {
|
||||
sptr<IRemoteObject> remoteObject = gnssStatusCallback_[i]->AsObject();
|
||||
std::map<sptr<IGnssStatusCallback>, AppIdentity>::iterator iter;
|
||||
for (iter = gnssStatusCallbackMap_.begin(); iter != gnssStatusCallbackMap_.end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = iter->first->AsObject();
|
||||
LBSLOGE(GNSS, "UnregisterGnssStatusCallback gnssStatusCallbackMap_");
|
||||
if (remoteObject == callback) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= gnssStatusCallback_.size()) {
|
||||
LBSLOGD(GNSS, "gnssStatus callback is not in vector");
|
||||
return ERRCODE_SUCCESS;
|
||||
if (iter != gnssStatusCallbackMap_.end()) {
|
||||
gnssStatusCallbackMap_.erase(iter);
|
||||
}
|
||||
gnssStatusCallback_.erase(gnssStatusCallback_.begin() + i);
|
||||
LBSLOGD(GNSS, "after unregister, gnssStatus callback size:%{public}s",
|
||||
std::to_string(gnssStatusCallback_.size()).c_str());
|
||||
std::to_string(gnssStatusCallbackMap_.size()).c_str());
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback,
|
||||
AppIdentity &identity)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
LBSLOGE(GNSS, "register an invalid nmea callback");
|
||||
@ -307,9 +310,9 @@ LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObjec
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
std::unique_lock<ffrt::mutex> lock(nmeaMutex_);
|
||||
nmeaCallback_.push_back(nmeaCallback);
|
||||
nmeaCallbackMap_.insert(std::make_pair(nmeaCallback, identity));
|
||||
LBSLOGD(GNSS, "after uid:%{public}d register, nmeaCallback size:%{public}s",
|
||||
uid, std::to_string(nmeaCallback_.size()).c_str());
|
||||
identity.GetUid(), std::to_string(nmeaCallbackMap_.size()).c_str());
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -326,24 +329,25 @@ LocationErrCode GnssAbility::UnregisterNmeaMessageCallback(const sptr<IRemoteObj
|
||||
}
|
||||
|
||||
std::unique_lock<ffrt::mutex> lock(nmeaMutex_);
|
||||
if (nmeaCallback_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "nmeaCallback_ size <= 0");
|
||||
if (nmeaCallbackMap_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "nmeaCallbackMap_ size <= 0");
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
size_t i = 0;
|
||||
for (; i < nmeaCallback_.size(); i++) {
|
||||
sptr<IRemoteObject> remoteObject = nmeaCallback_[i]->AsObject();
|
||||
|
||||
std::map<sptr<INmeaMessageCallback>, AppIdentity>::iterator iter;
|
||||
for (iter = nmeaCallbackMap_.begin(); iter != nmeaCallbackMap_.end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = iter->first->AsObject();
|
||||
if (remoteObject == callback) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= nmeaCallback_.size()) {
|
||||
LBSLOGD(GNSS, "nmea callback is not in vector");
|
||||
return ERRCODE_SUCCESS;
|
||||
if (iter != nmeaCallbackMap_.end()) {
|
||||
AppIdentity nmeaIdentity = iter->second;
|
||||
nmeaCallbackMap_.erase(iter);
|
||||
}
|
||||
nmeaCallback_.erase(nmeaCallback_.begin() + i);
|
||||
|
||||
LBSLOGD(GNSS, "after unregister, nmea callback size:%{public}s",
|
||||
std::to_string(nmeaCallback_.size()).c_str());
|
||||
std::to_string(nmeaCallbackMap_.size()).c_str());
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -948,16 +952,36 @@ void GnssAbility::ReportGnssSessionStatus(int status)
|
||||
void GnssAbility::ReportNmea(int64_t timestamp, const std::string &nmea)
|
||||
{
|
||||
std::unique_lock<ffrt::mutex> lock(nmeaMutex_);
|
||||
for (auto nmeaCallback : nmeaCallback_) {
|
||||
nmeaCallback->OnMessageChange(timestamp, nmea);
|
||||
for (const auto& pair : nmeaCallbackMap_) {
|
||||
auto nmeaCallback = pair.first;
|
||||
AppIdentity nmeaIdentity = pair.second;
|
||||
if (CheckGnssPermissionforUser(nmeaIdentity)) {
|
||||
nmeaCallback->OnMessageChange(timestamp, nmea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GnssAbility::CheckGnssPermissionforUser(AppIdentity &identity)
|
||||
{
|
||||
if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) {
|
||||
return true;
|
||||
}
|
||||
if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) {
|
||||
return true;
|
||||
}
|
||||
LBSLOGE(LOCATOR, "CheckGnssPermissionforUser fail: %{public}d", identity.GetUid());
|
||||
return false;
|
||||
}
|
||||
|
||||
void GnssAbility::ReportSv(const std::unique_ptr<SatelliteStatus> &sv)
|
||||
{
|
||||
std::unique_lock<ffrt::mutex> lock(gnssMutex_);
|
||||
for (auto gnssStatusCallback : gnssStatusCallback_) {
|
||||
gnssStatusCallback->OnStatusChange(sv);
|
||||
for (const auto& pair : gnssStatusCallbackMap_) {
|
||||
auto gnssStatusCallback = pair.first;
|
||||
AppIdentity gnssStatusIdentity = pair.second;
|
||||
if (CheckGnssPermissionforUser(gnssStatusIdentity)) {
|
||||
gnssStatusCallback->OnStatusChange(sv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,8 +172,10 @@ int GnssAbilityStub::RegisterGnssStatusCallbackInner(MessageParcel &data, Messag
|
||||
if (!PermissionManager::CheckCallingPermission(identity.GetUid(), identity.GetPid(), reply)) {
|
||||
return ERRCODE_PERMISSION_DENIED;
|
||||
}
|
||||
AppIdentity appIdentity;
|
||||
appIdentity.ReadFromParcel(data);
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
reply.WriteInt32(RegisterGnssStatusCallback(client, identity.GetUid()));
|
||||
reply.WriteInt32(RegisterGnssStatusCallback(client, appIdentity));
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -193,8 +195,10 @@ int GnssAbilityStub::RegisterNmeaMessageCallbackInner(MessageParcel &data, Messa
|
||||
if (!PermissionManager::CheckCallingPermission(identity.GetUid(), identity.GetPid(), reply)) {
|
||||
return ERRCODE_PERMISSION_DENIED;
|
||||
}
|
||||
AppIdentity appIdentity;
|
||||
appIdentity.ReadFromParcel(data);
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
reply.WriteInt32(RegisterNmeaMessageCallback(client, identity.GetUid()));
|
||||
reply.WriteInt32(RegisterNmeaMessageCallback(client, appIdentity));
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,9 @@ public:
|
||||
LocationErrCode SendLocationRequest(WorkRecord &workrecord) override;
|
||||
LocationErrCode SetEnable(bool state) override;
|
||||
LocationErrCode RefrashRequirements() override;
|
||||
LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) override;
|
||||
LocationErrCode UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) override;
|
||||
LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
|
||||
LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) override;
|
||||
LocationErrCode UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) override;
|
||||
LocationErrCode RegisterCachedCallback(const std::unique_ptr<CachedGnssLocationsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback) override;
|
||||
|
@ -112,9 +112,9 @@ public:
|
||||
LocationErrCode RegisterSwitchCallback(const sptr<IRemoteObject>& callback, pid_t uid);
|
||||
LocationErrCode UnregisterSwitchCallback(const sptr<IRemoteObject>& callback);
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid);
|
||||
LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity);
|
||||
LocationErrCode UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback);
|
||||
LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid);
|
||||
LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity);
|
||||
LocationErrCode UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback);
|
||||
LocationErrCode RegisterCachedLocationCallback(std::unique_ptr<CachedGnssLocationsRequest>& request,
|
||||
sptr<ICachedLocationsCallback>& callback, std::string bundleName);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "i_locating_required_data_callback.h"
|
||||
#include "locating_required_data_config.h"
|
||||
#include "system_ability_status_change_stub.h"
|
||||
#include "app_identity.h"
|
||||
#ifdef WIFI_ENABLE
|
||||
#include "wifi_scan.h"
|
||||
#endif
|
||||
@ -203,7 +204,7 @@ class LocatorRequiredDataManager {
|
||||
public:
|
||||
LocatorRequiredDataManager();
|
||||
~LocatorRequiredDataManager();
|
||||
__attribute__((no_sanitize("cfi"))) LocationErrCode RegisterCallback(
|
||||
__attribute__((no_sanitize("cfi"))) LocationErrCode RegisterCallback(AppIdentity &identity,
|
||||
std::shared_ptr<LocatingRequiredDataConfig>& config, const sptr<IRemoteObject>& callback);
|
||||
LocationErrCode UnregisterCallback(const sptr<IRemoteObject>& callback);
|
||||
void ReportData(const std::vector<std::shared_ptr<LocatingRequiredData>>& result);
|
||||
@ -223,6 +224,7 @@ public:
|
||||
private:
|
||||
void WifiInfoInit();
|
||||
bool isWifiCallbackRegistered();
|
||||
bool CheckDataPermissionforUser(AppIdentity &identity);
|
||||
std::shared_ptr<Wifi::WifiScan> wifiScanPtr_;
|
||||
sptr<LocatorWifiScanEventCallback> wifiScanEventCallback_;
|
||||
bool isWifiCallbackRegistered_ = false;
|
||||
@ -231,7 +233,7 @@ private:
|
||||
sptr<WifiServiceStatusChange>(new WifiServiceStatusChange());
|
||||
#endif
|
||||
std::mutex mutex_;
|
||||
std::vector<sptr<ILocatingRequiredDataCallback>> callbacks_;
|
||||
std::map<sptr<ILocatingRequiredDataCallback>, AppIdentity> callbacksMap_;
|
||||
std::shared_ptr<ScanHandler> scanHandler_;
|
||||
std::shared_ptr<ScanListHandler> scanListHandler_;
|
||||
};
|
||||
|
@ -84,7 +84,7 @@ LocationErrCode GnssAbilityProxy::RefrashRequirements()
|
||||
return LocationErrCode(reply.ReadInt32());
|
||||
}
|
||||
|
||||
LocationErrCode GnssAbilityProxy::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
LocationErrCode GnssAbilityProxy::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -93,6 +93,9 @@ LocationErrCode GnssAbilityProxy::RegisterGnssStatusCallback(const sptr<IRemoteO
|
||||
LBSLOGE(GNSS, "write interfaceToken fail!");
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
LBSLOGD(GNSS, "GnssAbilityProxy RegisterGnssStatusCallback uid: %{public}d, tokenId: %{public}d",
|
||||
identity.GetUid(), identity.GetTokenId());
|
||||
identity.Marshalling(data);
|
||||
data.WriteRemoteObject(callback);
|
||||
int error =
|
||||
Remote()->SendRequest(static_cast<uint32_t>(GnssInterfaceCode::REG_GNSS_STATUS), data, reply, option);
|
||||
@ -120,7 +123,8 @@ LocationErrCode GnssAbilityProxy::UnregisterGnssStatusCallback(const sptr<IRemot
|
||||
return LocationErrCode(reply.ReadInt32());
|
||||
}
|
||||
|
||||
LocationErrCode GnssAbilityProxy::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
LocationErrCode GnssAbilityProxy::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback,
|
||||
AppIdentity &identity)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -129,6 +133,9 @@ LocationErrCode GnssAbilityProxy::RegisterNmeaMessageCallback(const sptr<IRemote
|
||||
LBSLOGE(GNSS, "write interfaceToken fail!");
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
LBSLOGD(GNSS, "RegisterNmeaMessageCallback uid: %{public}d, tokenId: %{public}d",
|
||||
identity.GetUid(), identity.GetTokenId());
|
||||
identity.Marshalling(data);
|
||||
data.WriteRemoteObject(callback);
|
||||
int error = Remote()->SendRequest(static_cast<uint32_t>(GnssInterfaceCode::REG_NMEA), data, reply, option);
|
||||
LBSLOGI(GNSS, "%{public}s Transact Error = %{public}d", __func__, error);
|
||||
|
@ -531,14 +531,16 @@ LocationErrCode LocatorAbility::SendGnssRequest(int type, MessageParcel &data, M
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
LocationErrCode LocatorAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
LocationErrCode LocatorAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback,
|
||||
AppIdentity &identity)
|
||||
{
|
||||
LBSLOGD(LOCATOR, "uid is: %{public}d", uid);
|
||||
LBSLOGD(LOCATOR, "uid is: %{public}d", identity.GetUid());
|
||||
MessageParcel dataToStub;
|
||||
MessageParcel replyToStub;
|
||||
if (!dataToStub.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor())) {
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
identity.Marshalling(dataToStub);
|
||||
dataToStub.WriteRemoteObject(callback);
|
||||
return SendGnssRequest(static_cast<int>(GnssInterfaceCode::REG_GNSS_STATUS), dataToStub, replyToStub);
|
||||
}
|
||||
@ -558,13 +560,15 @@ LocationErrCode LocatorAbility::UnregisterGnssStatusCallback(const sptr<IRemoteO
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_GNSS_SUPPORT
|
||||
LocationErrCode LocatorAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid)
|
||||
LocationErrCode LocatorAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback,
|
||||
AppIdentity &identity)
|
||||
{
|
||||
MessageParcel dataToStub;
|
||||
MessageParcel replyToStub;
|
||||
if (!dataToStub.WriteInterfaceToken(GnssAbilityProxy::GetDescriptor())) {
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
identity.Marshalling(dataToStub);
|
||||
dataToStub.WriteRemoteObject(callback);
|
||||
return SendGnssRequest(static_cast<int>(GnssInterfaceCode::REG_NMEA), dataToStub, replyToStub);
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ void LocatorBackgroundProxy::OnUserSwitch(int32_t userId)
|
||||
LocationDataRdbManager::ClearSwitchMode();
|
||||
auto locatorAbility = LocatorAbility::GetInstance();
|
||||
if (locatorAbility != nullptr) {
|
||||
locatorAbility->ApplyRequests(1);
|
||||
locatorAbility->ApplyRequests(0);
|
||||
}
|
||||
if (!requestsList_->empty()) {
|
||||
StartLocator();
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "wifi_errcode.h"
|
||||
#endif
|
||||
#include "iservice_registry.h"
|
||||
#include "common_utils.h"
|
||||
#include "permission_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
@ -46,7 +48,7 @@ LocatorRequiredDataManager::~LocatorRequiredDataManager()
|
||||
}
|
||||
|
||||
__attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager::RegisterCallback(
|
||||
std::shared_ptr<LocatingRequiredDataConfig>& config, const sptr<IRemoteObject>& callback)
|
||||
AppIdentity &identity, std::shared_ptr<LocatingRequiredDataConfig>& config, const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
sptr<ILocatingRequiredDataCallback> dataCallback = iface_cast<ILocatingRequiredDataCallback>(callback);
|
||||
if (dataCallback == nullptr) {
|
||||
@ -64,9 +66,8 @@ __attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager::
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mutex_, std::defer_lock);
|
||||
lock.lock();
|
||||
callbacks_.push_back(dataCallback);
|
||||
LBSLOGD(LOCATOR, "after RegisterCallback, callback size:%{public}s", std::to_string(callbacks_.size()).c_str());
|
||||
if (config->GetNeedStartScan() && callbacks_.size() == 1) {
|
||||
callbacksMap_.insert(std::make_pair(dataCallback, identity));
|
||||
if (config->GetNeedStartScan() && callbacksMap_.size() == 1) {
|
||||
timeInterval_ = config->GetScanIntervalMs();
|
||||
if (scanHandler_ != nullptr) {
|
||||
scanHandler_->SendEvent(EVENT_START_SCAN, 0, 0);
|
||||
@ -88,22 +89,23 @@ LocationErrCode LocatorRequiredDataManager::UnregisterCallback(const sptr<IRemot
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
size_t i = 0;
|
||||
for (; i < callbacks_.size(); i++) {
|
||||
sptr<IRemoteObject> remoteObject = callbacks_[i]->AsObject();
|
||||
if (callbacksMap_.size() <= 0) {
|
||||
LBSLOGD(GNSS, "scan callback is not in vector");
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
std::map<sptr<ILocatingRequiredDataCallback>, AppIdentity>::iterator iter;
|
||||
for (iter = callbacksMap_.begin(); iter != callbacksMap_.end(); iter++) {
|
||||
sptr<IRemoteObject> remoteObject = iter->first->AsObject();
|
||||
if (remoteObject == callback) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (callbacks_.size() <= i) {
|
||||
LBSLOGD(GNSS, "scan callback is not in vector");
|
||||
return ERRCODE_SUCCESS;
|
||||
if (iter != callbacksMap_.end()) {
|
||||
callbacksMap_.erase(iter);
|
||||
}
|
||||
if (callbacks_.size() > 0) {
|
||||
callbacks_.erase(callbacks_.begin() + i);
|
||||
}
|
||||
LBSLOGD(LOCATOR, "after UnregisterCallback, callback size:%{public}s", std::to_string(callbacks_.size()).c_str());
|
||||
if (scanHandler_ != nullptr && callbacks_.size() == 0) {
|
||||
LBSLOGD(LOCATOR, "after UnregisterCallback, callback size:%{public}s",
|
||||
std::to_string(callbacksMap_.size()).c_str());
|
||||
if (scanHandler_ != nullptr && callbacksMap_.size() == 0) {
|
||||
scanHandler_->SendEvent(EVENT_STOP_SCAN, 0, 0);
|
||||
}
|
||||
return ERRCODE_SUCCESS;
|
||||
@ -307,11 +309,28 @@ void LocatorWifiScanEventCallback::OnWifiScanStateChanged(int state)
|
||||
void LocatorRequiredDataManager::ReportData(const std::vector<std::shared_ptr<LocatingRequiredData>>& result)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
for (size_t i = 0; i < callbacks_.size(); i++) {
|
||||
callbacks_[i]->OnLocatingDataChange(result);
|
||||
for (const auto& pair : callbacksMap_) {
|
||||
auto locatingRequiredDataCallback = pair.first;
|
||||
AppIdentity identity = pair.second;
|
||||
if (CheckDataPermissionforUser(identity)) {
|
||||
locatingRequiredDataCallback->OnLocatingDataChange(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LocatorRequiredDataManager::CheckDataPermissionforUser(AppIdentity &identity)
|
||||
{
|
||||
if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) {
|
||||
return true;
|
||||
}
|
||||
if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) {
|
||||
return true;
|
||||
}
|
||||
LBSLOGE(LOCATOR, "CheckDataPermissionforUser fail: %{public}d", identity.GetUid());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
__attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiScan(bool flag)
|
||||
{
|
||||
if (!flag) {
|
||||
@ -354,7 +373,7 @@ __attribute__((no_sanitize("cfi"))) void LocatorRequiredDataManager::StartWifiSc
|
||||
bool LocatorRequiredDataManager::IsConnecting()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (callbacks_.size() > 0) {
|
||||
if (callbacksMap_.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "location_log_event_ids.h"
|
||||
#include "geofence_request.h"
|
||||
#include "permission_manager.h"
|
||||
#include "hook_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
@ -487,7 +488,8 @@ int LocatorAbilityStub::PreRegisterGnssStatusCallback(MessageParcel &data, Messa
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
reply.WriteInt32(locatorAbility->RegisterGnssStatusCallback(client, identity.GetUid()));
|
||||
|
||||
reply.WriteInt32(locatorAbility->RegisterGnssStatusCallback(client, identity));
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
@ -528,7 +530,7 @@ int LocatorAbilityStub::PreRegisterNmeaMessageCallback(MessageParcel &data,
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
sptr<IRemoteObject> client = data.ReadObject<IRemoteObject>();
|
||||
reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity.GetUid()));
|
||||
reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity));
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
@ -569,7 +571,7 @@ int LocatorAbilityStub::PreRegisterNmeaMessageCallbackV9(MessageParcel &data,
|
||||
reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE);
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity.GetUid()));
|
||||
reply.WriteInt32(locatorAbility->RegisterNmeaMessageCallback(client, identity));
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
@ -1104,7 +1106,7 @@ int LocatorAbilityStub::PreRegisterLocatingRequiredDataCallback(MessageParcel &d
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
client->AddDeathRecipient(scanRecipient_);
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, client);
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, client);
|
||||
|
||||
reply.WriteInt32(errorCode);
|
||||
return ERRCODE_SUCCESS;
|
||||
@ -1325,13 +1327,14 @@ bool LocatorAbilityStub::CheckRequestAvailable(uint32_t code, AppIdentity &ident
|
||||
if (IsStopAction(code)) {
|
||||
return true;
|
||||
}
|
||||
if (PermissionManager::CheckSystemPermission(identity.GetTokenId(), identity.GetTokenIdEx())) {
|
||||
if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) {
|
||||
return true;
|
||||
}
|
||||
if (!CommonUtils::CheckAppForUser(identity.GetUid())) {
|
||||
return false;
|
||||
if (CommonUtils::CheckAppForUser(identity.GetUid(), identity.GetBundleName())) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
LBSLOGD(LOCATOR, "CheckRequestAvailable fail uid:%{public}d", identity.GetUid());
|
||||
return false;
|
||||
}
|
||||
int32_t LocatorAbilityStub::OnRemoteRequest(uint32_t code,
|
||||
MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
|
@ -208,8 +208,13 @@ std::unique_ptr<Location> ReportManager::GetPermittedLocation(const std::shared_
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
if (!PermissionManager::CheckSystemPermission(tokenId, tokenIdEx) &&
|
||||
!CommonUtils::CheckAppForUser(uid)) {
|
||||
if (!PermissionManager::CheckIsSystemSA(tokenId) &&
|
||||
!CommonUtils::CheckAppForUser(uid, bundleName)) {
|
||||
LBSLOGI(REPORT_MANAGER, "GetPermittedLocation uid: %{public}d CheckAppForUser fail", tokenId);
|
||||
auto locationErrorCallback = request->GetLocationErrorCallBack();
|
||||
if (locationErrorCallback != nullptr) {
|
||||
locationErrorCallback->OnErrorReport(LOCATING_FAILED_LOCATION_PERMISSION_DENIED);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<Location> finalLocation = std::make_unique<Location>(*location);
|
||||
|
@ -492,9 +492,7 @@ bool RequestManager::AddRequestToWorkRecord(std::string abilityName, std::shared
|
||||
if (requestConfig == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PermissionManager::CheckSystemPermission(tokenId, request->GetTokenIdEx()) &&
|
||||
!CommonUtils::CheckAppForUser(uid)) {
|
||||
if (!PermissionManager::CheckIsSystemSA(tokenId) && !CommonUtils::CheckAppForUser(uid, bundleName)) {
|
||||
LBSLOGD(REPORT_MANAGER, "AddRequestToWorkRecord uid: %{public}d ,CheckAppIsCurrentUser fail", uid);
|
||||
return false;
|
||||
}
|
||||
|
@ -24,11 +24,14 @@ namespace OHOS {
|
||||
if (size == 0) {
|
||||
return true;
|
||||
}
|
||||
AppIdentity identity;
|
||||
int pid = 1;
|
||||
identity.SetPid(pid);
|
||||
identity.SetUid(pid);
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
countryCodeManager->GetIsoCountryCode();
|
||||
countryCodeManager->UnregisterCountryCodeCallback(nullptr);
|
||||
int index = 0;
|
||||
countryCodeManager->RegisterCountryCodeCallback(nullptr, data[index++]);
|
||||
countryCodeManager->RegisterCountryCodeCallback(nullptr, identity);
|
||||
countryCodeManager->ReSubscribeEvent();
|
||||
countryCodeManager->ReUnsubscribeEvent();
|
||||
return true;
|
||||
|
@ -58,13 +58,15 @@ namespace OHOS {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES));
|
||||
auto gnssCallbackHost =
|
||||
sptr<GnssStatusCallbackNapi>(new (std::nothrow) GnssStatusCallbackNapi());
|
||||
proxy->RegisterGnssStatusCallback(gnssCallbackHost, data[index++]);
|
||||
AppIdentity identity;
|
||||
identity.SetPid(data[index++]);
|
||||
proxy->RegisterGnssStatusCallback(gnssCallbackHost, identity);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES));
|
||||
proxy->UnregisterGnssStatusCallback(gnssCallbackHost);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES));
|
||||
auto nmeaCallbackHost =
|
||||
sptr<NmeaMessageCallbackNapi>(new (std::nothrow) NmeaMessageCallbackNapi());
|
||||
proxy->RegisterNmeaMessageCallback(nmeaCallbackHost, data[index++]);
|
||||
proxy->RegisterNmeaMessageCallback(nmeaCallbackHost, identity);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES));
|
||||
proxy->UnregisterNmeaMessageCallback(nmeaCallbackHost);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIMES));
|
||||
|
@ -38,9 +38,11 @@ public:
|
||||
~MockGnssAbilityStub() {}
|
||||
MOCK_METHOD(void, SendMessage, (uint32_t code, MessageParcel &data, MessageParcel &reply));
|
||||
MOCK_METHOD(LocationErrCode, RefrashRequirements, ());
|
||||
MOCK_METHOD(LocationErrCode, RegisterGnssStatusCallback, (const sptr<IRemoteObject>& callback, pid_t uid));
|
||||
MOCK_METHOD(LocationErrCode, RegisterGnssStatusCallback, (const sptr<IRemoteObject>& callback,
|
||||
AppIdentity &identity));
|
||||
MOCK_METHOD(LocationErrCode, UnregisterGnssStatusCallback, (const sptr<IRemoteObject>& callback));
|
||||
MOCK_METHOD(LocationErrCode, RegisterNmeaMessageCallback, (const sptr<IRemoteObject>& callback, pid_t uid));
|
||||
MOCK_METHOD(LocationErrCode, RegisterNmeaMessageCallback, (const sptr<IRemoteObject>& callback,
|
||||
AppIdentity &identity));
|
||||
MOCK_METHOD(LocationErrCode, UnregisterNmeaMessageCallback, (const sptr<IRemoteObject>& callback));
|
||||
MOCK_METHOD(LocationErrCode, RegisterCachedCallback, (const std::unique_ptr<CachedGnssLocationsRequest>& request,
|
||||
const sptr<IRemoteObject>& callback));
|
||||
|
@ -220,12 +220,14 @@ HWTEST_F(GnssAbilityTest, RegisterGnssStatusCallback001, TestSize.Level1)
|
||||
*/
|
||||
pid_t lastCallingUid = 1;
|
||||
sptr<IRemoteObject> client = nullptr;
|
||||
|
||||
AppIdentity identity;
|
||||
identity.SetPid(lastCallingUid);
|
||||
identity.SetUid(23);
|
||||
/*
|
||||
* @tc.steps: step2. test register gnss status callback
|
||||
* @tc.expected: log info : "SendRegisterMsgToRemote callback is nullptr".
|
||||
*/
|
||||
EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterGnssStatusCallback(client, lastCallingUid));
|
||||
EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterGnssStatusCallback(client, identity));
|
||||
LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterGnssStatusCallback001 end");
|
||||
}
|
||||
|
||||
@ -243,12 +245,14 @@ HWTEST_F(GnssAbilityTest, RegisterAndUnregisterGnssStatusCallback001, TestSize.L
|
||||
* @tc.steps: step1. give the last calling uid
|
||||
*/
|
||||
pid_t lastCallingUid = 1;
|
||||
|
||||
AppIdentity identity;
|
||||
identity.SetPid(lastCallingUid);
|
||||
identity.SetUid(23);
|
||||
/*
|
||||
* @tc.steps: step2. test register gnss status callback
|
||||
* @tc.expected: no exception happens.
|
||||
*/
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterGnssStatusCallback(callbackStub_->AsObject(), lastCallingUid));
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterGnssStatusCallback(callbackStub_->AsObject(), identity));
|
||||
|
||||
/*
|
||||
* @tc.steps: step3. test unregister gnss status callback
|
||||
@ -296,12 +300,14 @@ HWTEST_F(GnssAbilityTest, RegisterNmeaMessageCallback001, TestSize.Level1)
|
||||
*/
|
||||
pid_t uid = 1;
|
||||
sptr<IRemoteObject> client = nullptr;
|
||||
|
||||
AppIdentity identity;
|
||||
identity.SetPid(uid);
|
||||
identity.SetUid(23);
|
||||
/*
|
||||
* @tc.steps: step2. test register nmea message callback
|
||||
* @tc.expected: log info : "register an invalid nmea callback".
|
||||
*/
|
||||
EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterNmeaMessageCallback(client, uid));
|
||||
EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterNmeaMessageCallback(client, identity));
|
||||
LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterNmeaMessageCallback001 end");
|
||||
}
|
||||
|
||||
@ -319,12 +325,14 @@ HWTEST_F(GnssAbilityTest, RegisterAndUnregisterNmeaMessageCallback001, TestSize.
|
||||
* @tc.steps: step1.the client is not null.
|
||||
*/
|
||||
pid_t uid = 1;
|
||||
|
||||
AppIdentity identity;
|
||||
identity.SetPid(uid);
|
||||
identity.SetUid(23);
|
||||
/*
|
||||
* @tc.steps: step2. test register nmea message callback
|
||||
* @tc.expected: no exception happens
|
||||
*/
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterNmeaMessageCallback(nemaCallbackStub_->AsObject(), uid));
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterNmeaMessageCallback(nemaCallbackStub_->AsObject(), identity));
|
||||
|
||||
/*
|
||||
* @tc.steps: step3. test unregister nmea message callback
|
||||
|
@ -53,7 +53,7 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback001, TestSize.Leve
|
||||
auto callback = sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
|
||||
ASSERT_TRUE(countryCodeManager != nullptr);
|
||||
countryCodeManager->UnregisterCountryCodeCallback(callback);
|
||||
EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size());
|
||||
EXPECT_EQ(0, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback001 end");
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback002, TestSize.Leve
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
ASSERT_TRUE(countryCodeManager != nullptr);
|
||||
countryCodeManager->UnregisterCountryCodeCallback(nullptr);
|
||||
EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size());
|
||||
EXPECT_EQ(0, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback002 end");
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback003, TestSize.Leve
|
||||
ASSERT_TRUE(countryCodeManager != nullptr);
|
||||
auto wrongCallback = sptr<NmeaMessageCallbackNapi>(new (std::nothrow) NmeaMessageCallbackNapi());
|
||||
countryCodeManager->UnregisterCountryCodeCallback(wrongCallback->AsObject());
|
||||
EXPECT_EQ(0, countryCodeManager->countryCodeCallbacks_.size());
|
||||
EXPECT_EQ(0, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback003 end");
|
||||
}
|
||||
|
||||
@ -90,14 +90,18 @@ HWTEST_F(CountryCodeManagerTest, UnregisterCountryCodeCallback004, TestSize.Leve
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
ASSERT_TRUE(countryCodeManager != nullptr);
|
||||
auto callback1 = sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback1, 0);
|
||||
AppIdentity identity;
|
||||
int pid = 2;
|
||||
identity.SetPid(pid);
|
||||
identity.SetUid(pid);
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback1, identity);
|
||||
|
||||
auto callback2 = sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback2, 1);
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback2, identity);
|
||||
|
||||
|
||||
countryCodeManager->UnregisterCountryCodeCallback(callback1); // size != 0, func will return
|
||||
EXPECT_EQ(1, countryCodeManager->countryCodeCallbacks_.size());
|
||||
EXPECT_EQ(1, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] UnregisterCountryCodeCallback004 end");
|
||||
}
|
||||
|
||||
@ -108,8 +112,12 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback001, TestSize.Level1
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback001 begin");
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
auto callback = sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, 0);
|
||||
EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size());
|
||||
AppIdentity identity;
|
||||
int pid = 10;
|
||||
identity.SetPid(pid);
|
||||
identity.SetUid(pid);
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, identity);
|
||||
EXPECT_NE(0, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback001 end");
|
||||
}
|
||||
|
||||
@ -120,8 +128,12 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback002, TestSize.Level1
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback002 begin");
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
ASSERT_TRUE(countryCodeManager != nullptr);
|
||||
countryCodeManager->RegisterCountryCodeCallback(nullptr, 0);
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size());
|
||||
AppIdentity identity;
|
||||
int pid = 3;
|
||||
identity.SetPid(pid);
|
||||
identity.SetUid(pid);
|
||||
countryCodeManager->RegisterCountryCodeCallback(nullptr, identity);
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback002 end");
|
||||
}
|
||||
|
||||
@ -133,8 +145,12 @@ HWTEST_F(CountryCodeManagerTest, RegisterCountryCodeCallback003, TestSize.Level1
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
ASSERT_TRUE(countryCodeManager != nullptr);
|
||||
auto wrongCallback = sptr<NmeaMessageCallbackNapi>(new (std::nothrow) NmeaMessageCallbackNapi());
|
||||
countryCodeManager->RegisterCountryCodeCallback(wrongCallback->AsObject(), 0);
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size());
|
||||
AppIdentity identity;
|
||||
int pid = 4;
|
||||
identity.SetPid(pid);
|
||||
identity.SetUid(pid);
|
||||
countryCodeManager->RegisterCountryCodeCallback(wrongCallback->AsObject(), identity);
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] RegisterCountryCodeCallback003 end");
|
||||
}
|
||||
|
||||
@ -144,7 +160,7 @@ HWTEST_F(CountryCodeManagerTest, ReSubscribeEvent001, TestSize.Level1)
|
||||
<< "CountryCodeManagerTest, ReSubscribeEvent001, TestSize.Level1";
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent001 begin");
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size());
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
countryCodeManager->ReSubscribeEvent();
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent001 end");
|
||||
}
|
||||
@ -156,8 +172,12 @@ HWTEST_F(CountryCodeManagerTest, ReSubscribeEvent002, TestSize.Level1)
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent002 begin");
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
auto callback = sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, 0);
|
||||
EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size());
|
||||
AppIdentity identity;
|
||||
int pid = 3;
|
||||
identity.SetPid(pid);
|
||||
identity.SetUid(pid);
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, identity);
|
||||
EXPECT_NE(0, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
countryCodeManager->ReSubscribeEvent();
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReSubscribeEvent002 end");
|
||||
}
|
||||
@ -168,7 +188,7 @@ HWTEST_F(CountryCodeManagerTest, ReUnsubscribeEvent001, TestSize.Level1)
|
||||
<< "CountryCodeManagerTest, ReUnsubscribeEvent001, TestSize.Level1";
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent001 begin");
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacks_.size());
|
||||
EXPECT_EQ(2, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
countryCodeManager->ReUnsubscribeEvent();
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent001 end");
|
||||
}
|
||||
@ -180,28 +200,16 @@ HWTEST_F(CountryCodeManagerTest, ReUnsubscribeEvent002, TestSize.Level1)
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent002 begin");
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
auto callback = sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, 0);
|
||||
EXPECT_NE(0, countryCodeManager->countryCodeCallbacks_.size());
|
||||
AppIdentity identity;
|
||||
int pid = 3;
|
||||
identity.SetPid(pid);
|
||||
identity.SetUid(pid);
|
||||
countryCodeManager->RegisterCountryCodeCallback(callback, identity);
|
||||
EXPECT_NE(0, countryCodeManager->countryCodeCallbacksMap_.size());
|
||||
countryCodeManager->ReUnsubscribeEvent();
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] ReUnsubscribeEvent002 end");
|
||||
}
|
||||
|
||||
HWTEST_F(CountryCodeManagerTest, NotifyAllListener001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO)
|
||||
<< "CountryCodeManagerTest, NotifyAllListener001, TestSize.Level1";
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] NotifyAllListener001 begin");
|
||||
auto countryCodeManager = CountryCodeManager::GetInstance();
|
||||
ASSERT_TRUE(countryCodeManager != nullptr);
|
||||
auto callback = sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
|
||||
sptr<ICountryCodeCallback> countryCodeCallback1 = iface_cast<ICountryCodeCallback>(callback);
|
||||
countryCodeManager->countryCodeCallbacks_.push_back(countryCodeCallback1);
|
||||
sptr<ICountryCodeCallback> countryCodeCallback2 = nullptr;
|
||||
countryCodeManager->countryCodeCallbacks_.push_back(countryCodeCallback2);
|
||||
countryCodeManager->NotifyAllListener();
|
||||
LBSLOGI(COUNTRY_CODE, "[CountryCodeManagerTest] NotifyAllListener001 end");
|
||||
}
|
||||
|
||||
HWTEST_F(CountryCodeManagerTest, GetCountryCodeByLastLocation001, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO)
|
||||
|
@ -63,7 +63,9 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback001, TestSize.Level1)
|
||||
dataConfig->SetNeedStartScan(true);
|
||||
dataConfig->SetScanIntervalMs(1);
|
||||
dataConfig->SetScanTimeoutMs(1);
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, nullptr);
|
||||
AppIdentity identity;
|
||||
identity.SetPid(1);
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, nullptr);
|
||||
EXPECT_EQ(ERRCODE_INVALID_PARAM, errorCode);
|
||||
errorCode = locatorDataManager->UnregisterCallback(nullptr);
|
||||
EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, errorCode);
|
||||
@ -82,9 +84,11 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback002, TestSize.Level1)
|
||||
dataConfig->SetNeedStartScan(false);
|
||||
dataConfig->SetScanIntervalMs(1);
|
||||
dataConfig->SetScanTimeoutMs(1);
|
||||
AppIdentity identity;
|
||||
identity.SetPid(1);
|
||||
auto callback =
|
||||
sptr<LocatingRequiredDataCallbackNapi>(new (std::nothrow) LocatingRequiredDataCallbackNapi());
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, callback->AsObject());
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, callback->AsObject());
|
||||
EXPECT_EQ(ERRCODE_NOT_SUPPORTED, errorCode);
|
||||
LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback002 end");
|
||||
}
|
||||
@ -101,9 +105,11 @@ HWTEST_F(LocatorRequiredDataManagerTest, RegisterCallback003, TestSize.Level1)
|
||||
dataConfig->SetNeedStartScan(false);
|
||||
dataConfig->SetScanIntervalMs(1);
|
||||
dataConfig->SetScanTimeoutMs(1);
|
||||
AppIdentity identity;
|
||||
identity.SetPid(1);
|
||||
auto callback =
|
||||
sptr<LocatingRequiredDataCallbackNapi>(new (std::nothrow) LocatingRequiredDataCallbackNapi());
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(dataConfig, callback->AsObject());
|
||||
LocationErrCode errorCode = locatorDataManager->RegisterCallback(identity, dataConfig, callback->AsObject());
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, errorCode);
|
||||
LBSLOGI(LOCATOR_CALLBACK, "[LocatorRequiredDataManagerTest] RegisterCallback003 end");
|
||||
}
|
||||
|
@ -1616,10 +1616,12 @@ HWTEST_F(LocatorServiceTest, locatorServiceGnssStatusCallback001, TestSize.Level
|
||||
|
||||
auto gnssCallbackHost =
|
||||
sptr<GnssStatusCallbackNapi>(new (std::nothrow) GnssStatusCallbackNapi());
|
||||
AppIdentity identity;
|
||||
identity.SetPid(1);
|
||||
// uid pid not match locationhub process
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED,
|
||||
locatorAbility->RegisterGnssStatusCallback(nullptr, SYSTEM_UID)); // invalid callback
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterGnssStatusCallback(gnssCallbackHost, SYSTEM_UID));
|
||||
locatorAbility->RegisterGnssStatusCallback(nullptr, identity)); // invalid callback
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterGnssStatusCallback(gnssCallbackHost, identity));
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterGnssStatusCallback(nullptr)); // invalid callback
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterGnssStatusCallback(gnssCallbackHost));
|
||||
LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGnssStatusCallback001 end");
|
||||
@ -1636,9 +1638,11 @@ HWTEST_F(LocatorServiceTest, locatorServiceNmeaMessageCallback001, TestSize.Leve
|
||||
sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
|
||||
auto nmeaCallbackHost =
|
||||
sptr<NmeaMessageCallbackNapi>(new (std::nothrow) NmeaMessageCallbackNapi());
|
||||
AppIdentity identity;
|
||||
identity.SetPid(1);
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED,
|
||||
locatorAbility->RegisterNmeaMessageCallback(nullptr, SYSTEM_UID)); // invalid callback
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterNmeaMessageCallback(nmeaCallbackHost, SYSTEM_UID));
|
||||
locatorAbility->RegisterNmeaMessageCallback(nullptr, identity)); // invalid callback
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterNmeaMessageCallback(nmeaCallbackHost, identity));
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterNmeaMessageCallback(nullptr)); // invalid callback
|
||||
EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterNmeaMessageCallback(nmeaCallbackHost));
|
||||
LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceNmeaMessageCallback001 end");
|
||||
|
Loading…
Reference in New Issue
Block a user