!799 geo 服务断开的事件切换

Merge pull request !799 from smilebear/master
This commit is contained in:
openharmony_ci 2024-07-27 13:52:42 +00:00 committed by Gitee
commit 1e3cdd0388
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 26 additions and 2 deletions

View File

@ -86,6 +86,7 @@ public:
bool ConnectService();
void NotifyConnected(const sptr<IRemoteObject>& remoteObject);
void DisconnectAbilityConnect();
void NotifyDisConnected();
bool ResetServiceProxy();
bool SendGeocodeRequest(int code, MessageParcel& dataParcel, MessageParcel& replyParcel, MessageOption& option);

View File

@ -32,7 +32,9 @@ namespace Location {
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
GeoConvertService::GetInstance());
const uint32_t EVENT_SEND_GEOREQUEST = 0x0100;
const char* UNLOAD_GEOCONVERT_TASK = "geoconvert_sa_unload";
const int GEOCONVERT_CONNECT_TIME_OUT = 1;
const int UNLOAD_GEOCONVERT_DELAY_TIME = 5;
GeoConvertService* GeoConvertService::GetInstance()
{
static GeoConvertService data;
@ -48,6 +50,9 @@ GeoConvertService::GeoConvertService() : SystemAbility(LOCATION_GEO_CONVERT_SA_I
GeoConvertService::~GeoConvertService()
{
if (geoConvertHandler_ != nullptr) {
geoConvertHandler_->RemoveTask(UNLOAD_GEOCONVERT_TASK);
}
conn_ = nullptr;
}
@ -320,8 +325,26 @@ bool GeoConvertService::CancelIdleState()
void GeoConvertService::UnloadGeoConvertSystemAbility()
{
if (!CheckIfGeoConvertConnecting()) {
if (geoConvertHandler_ == nullptr) {
LBSLOGE(GEO_CONVERT, "%{public}s geoConvertHandler_ is nullptr", __func__);
return;
}
geoConvertHandler_->RemoveTask(UNLOAD_GEOCONVERT_TASK);
if (CheckIfGeoConvertConnecting()) {
return;
}
auto task = [this]() {
LocationSaLoadManager::UnInitLocationSa(LOCATION_GEO_CONVERT_SA_ID);
GeoConvertService::GetInstance()->DisconnectAbilityConnect();
};
geoConvertHandler_->PostTask(task, UNLOAD_GEOCONVERT_TASK, UNLOAD_GEOCONVERT_DELAY_TIME);
}
void GeoConvertService::DisconnectAbilityConnect()
{
if (conn_ != nullptr) {
AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn_);
LBSLOGI(GEO_CONVERT, "UnloadGeoConvert OnStop and disconnect");
}
}

View File

@ -285,7 +285,7 @@ void NetworkAbility::RequestRecord(WorkRecord &workRecord, bool isAdded)
} else {
RemoveNetworkLocation(workRecord);
if (GetRequestNum() == 0 && conn_ != nullptr) {
LBSLOGD(NETWORK, "RequestRecord disconnect");
LBSLOGI(NETWORK, "RequestRecord disconnect");
AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn_);
}
}