!177 getLastLocation返回值添加判空逻辑

Merge pull request !177 from ruan-shaofei/master
This commit is contained in:
openharmony_ci
2022-09-01 06:56:44 +00:00
committed by Gitee
@@ -121,6 +121,9 @@ std::string CountryCodeManager::GetCountryCodeByLastLocation()
std::shared_ptr<ReportManager> reportManager = DelayedSingleton<ReportManager>::GetInstance();
if (reportManager) {
auto lastLocation = reportManager->GetLastLocation();
if (lastLocation == nullptr) {
return code;
}
auto location = std::make_unique<Location>(*lastLocation);
code = GetCountryCodeByLocation(location);
lastCountryByLocation_->SetCountryCodeStr(code);
@@ -262,14 +265,12 @@ bool CountryCodeManager::SubscribeLocaleConfigEvent()
{
auto eventCallback = [](const char *key, const char *value, void *context) {
LBSLOGD(COUNTRY_CODE, "LOCALE_KEY changed");
if (key && value && context) {
auto manager = DelayedSingleton<CountryCodeManager>::GetInstance();
if (manager == nullptr) {
LBSLOGE(COUNTRY_CODE, "SubscribeLocaleConfigEvent CountryCodeManager is nullptr");
return;
}
manager->GetIsoCountryCode();
auto manager = DelayedSingleton<CountryCodeManager>::GetInstance();
if (manager == nullptr) {
LBSLOGE(COUNTRY_CODE, "SubscribeLocaleConfigEvent CountryCodeManager is nullptr");
return;
}
manager->GetIsoCountryCode();
};
int ret = WatchParameter(LOCALE_KEY.c_str(), eventCallback, nullptr);