mirror of
https://gitee.com/openharmony/base_location
synced 2025-02-17 09:29:53 +00:00
bugfix:review
Signed-off-by: 李文龙 <liwenlong22@huawei.com>
This commit is contained in:
parent
cd10126cf6
commit
c73b870581
@ -32,6 +32,7 @@
|
||||
#include "accesstoken_kit.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "os_account_info.h"
|
||||
#include "permission_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
@ -426,7 +427,7 @@ std::string CommonUtils::GenerateUuid()
|
||||
bool CommonUtils::CheckAppForUser(int32_t uid)
|
||||
{
|
||||
std::string bundleName = "";
|
||||
if (CommonUtils::GetBundleNameByUid(identity.GetUid(), bundleName)) {
|
||||
if (CommonUtils::GetBundleNameByUid(uid, bundleName)) {
|
||||
if (HookUtils::ExecuteHookWhenCheckAppForUser(bundleName)) {
|
||||
return true;
|
||||
}
|
||||
@ -461,7 +462,7 @@ int64_t CommonUtils::GetSinceBootTime()
|
||||
|
||||
bool CommonUtils::CheckPermissionforUser(AppIdentity &identity)
|
||||
{
|
||||
if (PermissionManager::CheckIsSystemSA(identity.GetTokenId())) {
|
||||
if (PermissionManager::CheckIsSystemSa(identity.GetTokenId())) {
|
||||
return true;
|
||||
}
|
||||
if (CommonUtils::CheckAppForUser(identity.GetUid())) {
|
||||
|
@ -173,7 +173,7 @@ int LocationDataRdbManager::GetSwitchStateFromSysparaForUser(int32_t userId)
|
||||
bool LocationDataRdbManager::SetSwitchStateToSysparaForUser(int value, int32_t userId)
|
||||
{
|
||||
char result[MAX_SIZE] = {0};
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
std::unique_lock<std::mutex> lock(locationSwitchModeMutex_);
|
||||
nlohmann::json oldSwitchInfo;
|
||||
auto res = GetParameter(LOCATION_SWITCH_MODE, "", result, MAX_SIZE);
|
||||
if (res < 0 || strlen(result) == 0) {
|
||||
|
@ -61,9 +61,10 @@ void CountryCodeManager::NotifyAllListener()
|
||||
auto country = std::make_shared<CountryCode>(*lastCountry_);
|
||||
for (const auto& pair : countryCodeCallbacksMap_) {
|
||||
auto callback = pair.first;
|
||||
sptr<ICountryCodeCallback> countryCodeCallback = iface_cast<ICountryCodeCallback>(callback);
|
||||
AppIdentity identity = pair.second;
|
||||
if (CheckPermissionforUser(identity)) {
|
||||
callback->OnCountryCodeChange(country);
|
||||
if (CommonUtils::CheckPermissionforUser(identity)) {
|
||||
countryCodeCallback->OnCountryCodeChange(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,19 +78,7 @@ void CountryCodeManager::RegisterCountryCodeCallback(const sptr<IRemoteObject>&
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
sptr<ICountryCodeCallback> countryCodeCallback = iface_cast<ICountryCodeCallback>(callback);
|
||||
if (countryCodeCallback == nullptr) {
|
||||
LBSLOGE(COUNTRY_CODE, "iface_cast ICountryCodeCallback failed!");
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
auto iter = countryCodeCallbacksMap_.find(countryCodeCallback);
|
||||
if (iter != countryCodeCallbacksMap_.end()) {
|
||||
LBSLOGE(COUNTRY_CODE, "ICountryCodeCallback has registered!");
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
countryCodeCallbacksMap_[countryCodeCallback] = identity;
|
||||
countryCodeCallbacksMap_[callback] = 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) {
|
||||
@ -110,24 +99,7 @@ void CountryCodeManager::UnregisterCountryCodeCallback(const sptr<IRemoteObject>
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
if (countryCodeCallbacksMap_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "countryCodeCallbacksMap_ size <= 0");
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
sptr<ICountryCodeCallback> countryCodeCallback = iface_cast<ICountryCodeCallback>(callback);
|
||||
if (countryCodeCallback == nullptr) {
|
||||
LBSLOGE(COUNTRY_CODE, "iface_cast ICountryCodeCallback failed!");
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
auto iter = countryCodeCallbacksMap_.find(callback);
|
||||
if (iter != countryCodeCallbacksMap_.end()) {
|
||||
countryCodeCallbacksMap_.erase(iter);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "string_ex.h"
|
||||
#include "location_log.h"
|
||||
#include "location.h"
|
||||
#include "app_identity.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Location {
|
||||
|
@ -81,7 +81,7 @@ private:
|
||||
|
||||
std::shared_ptr<CountryCode> lastCountryByLocation_;
|
||||
std::shared_ptr<CountryCode> lastCountry_;
|
||||
std::map<sptr<ICountryCodeCallback>, AppIdentity> countryCodeCallbacksMap_;
|
||||
std::map<sptr<IRemoteObject>, AppIdentity> countryCodeCallbacksMap_;
|
||||
std::shared_ptr<SimSubscriber> simSubscriber_;
|
||||
std::shared_ptr<NetworkSubscriber> networkSubscriber_;
|
||||
std::mutex simSubscriberMutex_;
|
||||
|
@ -259,8 +259,8 @@ private:
|
||||
ffrt::mutex nmeaMutex_;
|
||||
ffrt::mutex hdiMutex_;
|
||||
ffrt::mutex statusMutex_;
|
||||
std::map<sptr<IGnssStatusCallback>, AppIdentity> gnssStatusCallbackMap_;
|
||||
std::map<sptr<INmeaMessageCallback>, AppIdentity> nmeaCallbackMap_;
|
||||
std::map<sptr<IRemoteObject>, AppIdentity> gnssStatusCallbackMap_;
|
||||
std::map<sptr<IRemoteObject>, AppIdentity> nmeaCallbackMap_;
|
||||
sptr<IGnssCallback> gnssCallback_;
|
||||
Location nlpLocation_;
|
||||
#ifdef TIME_SERVICE_ENABLE
|
||||
|
@ -249,13 +249,8 @@ LocationErrCode GnssAbility::RegisterGnssStatusCallback(const sptr<IRemoteObject
|
||||
}
|
||||
sptr<IRemoteObject::DeathRecipient> death(new (std::nothrow) GnssStatusCallbackDeathRecipient());
|
||||
callback->AddDeathRecipient(death);
|
||||
sptr<IGnssStatusCallback> gnssStatusCallback = iface_cast<IGnssStatusCallback>(callback);
|
||||
if (gnssStatusCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast switch callback fail!");
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
std::unique_lock<ffrt::mutex> lock(gnssMutex_);
|
||||
gnssStatusCallbackMap_.insert(std::make_pair(gnssStatusCallback, identity));
|
||||
gnssStatusCallbackMap_[callback] = identity;
|
||||
LBSLOGD(GNSS, "RegisterGnssStatusCallback uid:%{public}d register, gnssStatusCallback size:%{public}s",
|
||||
identity.GetUid(), std::to_string(gnssStatusCallbackMap_.size()).c_str());
|
||||
return ERRCODE_SUCCESS;
|
||||
@ -267,25 +262,8 @@ LocationErrCode GnssAbility::UnregisterGnssStatusCallback(const sptr<IRemoteObje
|
||||
LBSLOGE(GNSS, "unregister an invalid gnssStatus callback");
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
sptr<IGnssStatusCallback> gnssStatusCallback = iface_cast<IGnssStatusCallback>(callback);
|
||||
if (gnssStatusCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast gnssStatus callback fail!");
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
|
||||
std::unique_lock<ffrt::mutex> lock(gnssMutex_);
|
||||
if (gnssStatusCallbackMap_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "gnssStatusCallbackMap_ size <= 0");
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
auto iter = gnssStatusCallbackMap_.find(callback);
|
||||
if (iter != gnssStatusCallbackMap_.end()) {
|
||||
gnssStatusCallbackMap_.erase(iter);
|
||||
}
|
||||
@ -303,13 +281,8 @@ LocationErrCode GnssAbility::RegisterNmeaMessageCallback(const sptr<IRemoteObjec
|
||||
}
|
||||
sptr<IRemoteObject::DeathRecipient> death(new (std::nothrow) NmeaCallbackDeathRecipient());
|
||||
callback->AddDeathRecipient(death);
|
||||
sptr<INmeaMessageCallback> nmeaCallback = iface_cast<INmeaMessageCallback>(callback);
|
||||
if (nmeaCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast nmea callback fail!");
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
std::unique_lock<ffrt::mutex> lock(nmeaMutex_);
|
||||
nmeaCallbackMap_.insert(std::make_pair(nmeaCallback, identity));
|
||||
nmeaCallbackMap_[callback] = identity;
|
||||
LBSLOGD(GNSS, "after uid:%{public}d register, nmeaCallback size:%{public}s",
|
||||
identity.GetUid(), std::to_string(nmeaCallbackMap_.size()).c_str());
|
||||
return ERRCODE_SUCCESS;
|
||||
@ -321,25 +294,8 @@ LocationErrCode GnssAbility::UnregisterNmeaMessageCallback(const sptr<IRemoteObj
|
||||
LBSLOGE(GNSS, "unregister an invalid nmea callback");
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
sptr<INmeaMessageCallback> nmeaCallback = iface_cast<INmeaMessageCallback>(callback);
|
||||
if (nmeaCallback == nullptr) {
|
||||
LBSLOGE(GNSS, "cast nmea callback fail!");
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
|
||||
std::unique_lock<ffrt::mutex> lock(nmeaMutex_);
|
||||
if (nmeaCallbackMap_.size() <= 0) {
|
||||
LBSLOGE(COUNTRY_CODE, "nmeaCallbackMap_ size <= 0");
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
auto iter = nmeaCallbackMap_.find(callback);
|
||||
if (iter != nmeaCallbackMap_.end()) {
|
||||
nmeaCallbackMap_.erase(iter);
|
||||
}
|
||||
@ -951,9 +907,10 @@ void GnssAbility::ReportNmea(int64_t timestamp, const std::string &nmea)
|
||||
{
|
||||
std::unique_lock<ffrt::mutex> lock(nmeaMutex_);
|
||||
for (const auto& pair : nmeaCallbackMap_) {
|
||||
auto nmeaCallback = pair.first;
|
||||
auto callback = pair.first;
|
||||
sptr<INmeaMessageCallback> nmeaCallback = iface_cast<INmeaMessageCallback>(callback);
|
||||
AppIdentity nmeaIdentity = pair.second;
|
||||
if (CheckPermissionforUser(nmeaIdentity)) {
|
||||
if (CommonUtils::CheckPermissionforUser(nmeaIdentity)) {
|
||||
nmeaCallback->OnMessageChange(timestamp, nmea);
|
||||
}
|
||||
}
|
||||
@ -963,9 +920,10 @@ void GnssAbility::ReportSv(const std::unique_ptr<SatelliteStatus> &sv)
|
||||
{
|
||||
std::unique_lock<ffrt::mutex> lock(gnssMutex_);
|
||||
for (const auto& pair : gnssStatusCallbackMap_) {
|
||||
auto gnssStatusCallback = pair.first;
|
||||
auto callback = pair.first;
|
||||
sptr<IGnssStatusCallback> gnssStatusCallback = iface_cast<IGnssStatusCallback>(callback);
|
||||
AppIdentity gnssStatusIdentity = pair.second;
|
||||
if (CheckPermissionforUser(gnssStatusIdentity)) {
|
||||
if (CommonUtils::CheckPermissionforUser(gnssStatusIdentity)) {
|
||||
gnssStatusCallback->OnStatusChange(sv);
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ private:
|
||||
WifiEvent wifiScanEventCallback_ = {0};
|
||||
#endif
|
||||
std::mutex mutex_;
|
||||
std::map<sptr<ILocatingRequiredDataCallback>, AppIdentity> callbacksMap_;
|
||||
std::map<sptr<IRemoteObject>, AppIdentity> callbacksMap_;
|
||||
std::shared_ptr<ScanHandler> scanHandler_;
|
||||
std::shared_ptr<WifiSdkHandler> wifiSdkHandler_;
|
||||
};
|
||||
|
@ -52,24 +52,14 @@ LocatorRequiredDataManager::~LocatorRequiredDataManager()
|
||||
__attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager::RegisterCallback(
|
||||
AppIdentity &identity, std::shared_ptr<LocatingRequiredDataConfig>& config, const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
sptr<ILocatingRequiredDataCallback> dataCallback = iface_cast<ILocatingRequiredDataCallback>(callback);
|
||||
if (dataCallback == nullptr) {
|
||||
LBSLOGE(LOCATOR, "%{public}s iface_cast ILocatingRequiredDataCallback failed!", __func__);
|
||||
return ERRCODE_INVALID_PARAM;
|
||||
}
|
||||
if (config->GetType() == LocatingRequiredDataType::WIFI) {
|
||||
#ifdef WIFI_ENABLE
|
||||
std::unique_lock<std::mutex> lock(mutex_, std::defer_lock);
|
||||
lock.lock();
|
||||
auto iter = callbacksMap_.find(dataCallback);
|
||||
if (iter != callbacksMap_.end()) {
|
||||
LBSLOGE(LOCATOR, "dataCallback has registered!");
|
||||
lock.unlock();
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
callbacksMap_[dataCallback] = identity;
|
||||
LBSLOGD(LOCATOR, "after RegisterCallback, callback size:%{public}s", std::to_string(callbacks_.size()).c_str());
|
||||
if (config->GetNeedStartScan() && (callbacks_.size() == 1 || !IsWifiCallbackRegistered())) {
|
||||
callbacksMap_[callback] = identity;
|
||||
LBSLOGD(LOCATOR, "after RegisterCallback, callback size:%{public}s",
|
||||
std::to_string(callbacksMap_.size()).c_str());
|
||||
if (config->GetNeedStartScan() && (callbacksMap_.size() == 1 || !IsWifiCallbackRegistered())) {
|
||||
if (wifiSdkHandler_ != nullptr) {
|
||||
wifiSdkHandler_->SendEvent(EVENT_REGISTER_WIFI_CALLBACK, 0, 0);
|
||||
}
|
||||
@ -88,30 +78,15 @@ __attribute__((no_sanitize("cfi"))) LocationErrCode LocatorRequiredDataManager::
|
||||
|
||||
LocationErrCode LocatorRequiredDataManager::UnregisterCallback(const sptr<IRemoteObject>& callback)
|
||||
{
|
||||
sptr<ILocatingRequiredDataCallback> dataCallback = iface_cast<ILocatingRequiredDataCallback>(callback);
|
||||
if (dataCallback == nullptr) {
|
||||
LBSLOGE(LOCATOR, "%{public}s iface_cast ILocatingRequiredDataCallback failed!", __func__);
|
||||
return ERRCODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
#ifdef WIFI_ENABLE
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
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;
|
||||
}
|
||||
}
|
||||
auto iter = callbacksMap_.find(callback);
|
||||
if (iter != callbacksMap_.end()) {
|
||||
callbacksMap_.erase(iter);
|
||||
}
|
||||
LBSLOGD(LOCATOR, "after UnregisterCallback, callback size:%{public}s",
|
||||
std::to_string(callbacksMap_.size()).c_str());
|
||||
if (callbacks_.size() > 0) {
|
||||
if (callbacksMap_.size() > 0) {
|
||||
return ERRCODE_SUCCESS;
|
||||
}
|
||||
if (wifiSdkHandler_ != nullptr) {
|
||||
@ -299,9 +274,11 @@ void LocatorRequiredDataManager::ReportData(const std::vector<std::shared_ptr<Lo
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
for (const auto& pair : callbacksMap_) {
|
||||
auto locatingRequiredDataCallback = pair.first;
|
||||
auto callback = pair.first;
|
||||
sptr<ILocatingRequiredDataCallback> locatingRequiredDataCallback =
|
||||
iface_cast<ILocatingRequiredDataCallback>(callback);
|
||||
AppIdentity identity = pair.second;
|
||||
if (CheckPermissionforUser(identity)) {
|
||||
if (CommonUtils::CheckPermissionforUser(identity)) {
|
||||
locatingRequiredDataCallback->OnLocatingDataChange(result);
|
||||
}
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ std::unique_ptr<Location> ReportManager::GetPermittedLocation(const std::shared_
|
||||
return nullptr;
|
||||
}
|
||||
AppIdentity identity;
|
||||
identity.SetUid(IPCSkeleton::GetCallingUid());
|
||||
identity.SetTokenId(IPCSkeleton::GetCallingTokenID());
|
||||
identity.SetUid(request->GetUid());
|
||||
identity.SetTokenId(request->GetTokenId());
|
||||
if (!CommonUtils::CheckPermissionforUser(identity)) {
|
||||
//app is not in current user, not need to report
|
||||
LBSLOGI(REPORT_MANAGER, "GetPermittedLocation uid: %{public}d CheckAppForUser fail", tokenId);
|
||||
|
@ -389,7 +389,8 @@ bool RequestManager::IsRequestAvailable(std::shared_ptr<Request>& request)
|
||||
identity.SetUid(request->GetUid());
|
||||
identity.SetTokenId(request->GetTokenId());
|
||||
if (!CommonUtils::CheckPermissionforUser(identity)) {
|
||||
LBSLOGD(REPORT_MANAGER, "AddRequestToWorkRecord uid: %{public}d ,CheckAppIsCurrentUser fail", uid);
|
||||
LBSLOGD(REPORT_MANAGER, "AddRequestToWorkRecord uid: %{public}d ,CheckAppIsCurrentUser fail",
|
||||
request->GetUid());
|
||||
return false;
|
||||
}
|
||||
// for once_request app, if it has timed out, do not add to workRecord
|
||||
|
Loading…
x
Reference in New Issue
Block a user