mirror of
https://gitee.com/openharmony/base_location
synced 2024-11-23 23:10:05 +00:00
!813 geo 服务断开后,conn_置空,移除监听
Merge pull request !813 from smilebear/master
This commit is contained in:
commit
63e30fe039
@ -346,6 +346,7 @@ void GeoConvertService::DisconnectAbilityConnect()
|
||||
{
|
||||
if (conn_ != nullptr) {
|
||||
AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn_);
|
||||
UnRegisterGeoServiceDeathRecipient();
|
||||
SetServiceConnectState(ServiceConnectState::STATE_DISCONNECT);
|
||||
conn_ = nullptr;
|
||||
LBSLOGI(GEO_CONVERT, "UnloadGeoConvert OnStop and disconnect");
|
||||
|
@ -42,6 +42,13 @@ public:
|
||||
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
|
||||
};
|
||||
|
||||
class NLPServiceDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
||||
NLPServiceDeathRecipient();
|
||||
~NLPServiceDeathRecipient() override;
|
||||
};
|
||||
|
||||
class NetworkAbility : public SystemAbility, public NetworkAbilityStub, public SubAbility {
|
||||
DECLEAR_SYSTEM_ABILITY(NetworkAbility);
|
||||
|
||||
@ -83,6 +90,7 @@ private:
|
||||
bool RequestNetworkLocation(WorkRecord &workRecord);
|
||||
bool RemoveNetworkLocation(WorkRecord &workRecord);
|
||||
void RegisterNLPServiceDeathRecipient();
|
||||
void UnRegisterNLPServiceDeathRecipient();
|
||||
bool IsConnect();
|
||||
|
||||
ffrt::mutex mutex_;
|
||||
@ -91,16 +99,11 @@ private:
|
||||
std::shared_ptr<NetworkHandler> networkHandler_;
|
||||
size_t mockLocationIndex_ = 0;
|
||||
bool registerToAbility_ = false;
|
||||
sptr<IRemoteObject::DeathRecipient> nlpServiceRecipient_ = sptr<NLPServiceDeathRecipient>(new
|
||||
(std::nothrow) NLPServiceDeathRecipient());
|
||||
ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
|
||||
sptr<AAFwk::IAbilityConnection> conn_;
|
||||
};
|
||||
|
||||
class NLPServiceDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
||||
NLPServiceDeathRecipient();
|
||||
~NLPServiceDeathRecipient() override;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
#endif // FEATURE_NETWORK_SUPPORT
|
||||
|
@ -280,7 +280,8 @@ void NetworkAbility::RequestRecord(WorkRecord &workRecord, bool isAdded)
|
||||
if (GetRequestNum() == 0 && conn_ != nullptr) {
|
||||
LBSLOGI(NETWORK, "RequestRecord disconnect");
|
||||
AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn_);
|
||||
conn_ = nullptr;
|
||||
UnRegisterNLPServiceDeathRecipient();
|
||||
conn_ = nullptr ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -487,10 +488,25 @@ void NetworkAbility::RegisterNLPServiceDeathRecipient()
|
||||
LBSLOGE(NETWORK, "%{public}s: nlpServiceProxy_ is nullptr", __func__);
|
||||
return;
|
||||
}
|
||||
sptr<IRemoteObject::DeathRecipient> death(new (std::nothrow) NLPServiceDeathRecipient());
|
||||
nlpServiceProxy_->AddDeathRecipient(death);
|
||||
if (nlpServiceRecipient_ != nullptr) {
|
||||
nlpServiceProxy_->AddDeathRecipient(nlpServiceRecipient_);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkAbility::UnRegisterNLPServiceDeathRecipient()
|
||||
{
|
||||
std::unique_lock<ffrt::mutex> uniqueLock(mutex_);
|
||||
if (nlpServiceProxy_ == nullptr) {
|
||||
LBSLOGE(NETWORK, "%{public}s: nlpServiceProxy_ is nullptr", __func__);
|
||||
return;
|
||||
}
|
||||
if (nlpServiceRecipient_ != nullptr) {
|
||||
nlpServiceProxy_->RemoveDeathRecipient(nlpServiceRecipient_);
|
||||
nlpServiceRecipient_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool NetworkAbility::IsConnect()
|
||||
{
|
||||
std::unique_lock<ffrt::mutex> uniqueLock(mutex_);
|
||||
|
Loading…
Reference in New Issue
Block a user