海口云建站模板,南山网站建设设计,关键字查询我的网站怎么做,无锡高端网站定制先WiFi#xff0c;后 定位#xff0c;再从蓝牙到NFC#xff0c;这个就是我大致熟悉开源鸿蒙代码的一个顺序流程#xff0c;WiFi 的年前差不多基本流程熟悉了#xff0c;当然还有很多细节和内容没有写到#xff0c;后续都会慢慢的丰富起来#xff0c;这一篇将开启GNSS的篇…先WiFi后 定位再从蓝牙到NFC这个就是我大致熟悉开源鸿蒙代码的一个顺序流程WiFi 的年前差不多基本流程熟悉了当然还有很多细节和内容没有写到后续都会慢慢的丰富起来这一篇将开启GNSS的篇章先从GNSS使能开始代码还是选取开源鸿蒙HarmonyOS 4.0的代码基线。 界面部分代码省略直接JS看调用哪个接口往下梳理 代码位置base/location/frameworks/native/source/locator.cpp — locator.cpp 的实现是 LocatorImpl
void LocatorImpl::EnableAbility(bool enable)
{if (!Init()) {return;}sptrLocatorProxy proxy GetProxy();if (proxy nullptr) {LBSLOGE(LOCATOR_STANDARD, %{public}s get proxy failed., __func__);return;}LocationErrCode errCode proxy-EnableAbilityV9(enable); --- 使能继续看这个// cache the valueif (errCode ERRCODE_SUCCESS) { --- 使能成功保存现在的状态if (locationDataManager_ ! nullptr) {locationDataManager_-SetCachedSwitchState(enable ? ENABLED : DISABLED);}}
}// base/location/frameworks/native/source/locator_proxy.cpp
void LocatorProxy::EnableAbility(bool isEnabled)
{MessageParcel data;MessageParcel reply;if (!data.WriteInterfaceToken(GetDescriptor())) {return;}data.WriteBool(isEnabled);int error SendMsgWithDataReply(static_castint(LocatorInterfaceCode::ENABLE_ABILITY), data, reply);LBSLOGD(LOCATOR_STANDARD, Proxy::EnableAbility Transact ErrCodes %{public}d, error);
}
//处理这个消息 ENABLE_ABILITY
// base/location/services/location_locator/locator/source/locator_skeleton.cpp
int LocatorAbilityStub::PreEnableAbility(MessageParcel data, MessageParcel reply, AppIdentity identity)
{if (!CommonUtils::CheckSystemPermission(identity.GetTokenId(), identity.GetTokenIdEx())) {LBSLOGE(LOCATOR, CheckSystemPermission return false, [%{public}s],identity.ToString().c_str());reply.WriteInt32(ERRCODE_SYSTEM_PERMISSION_DENIED);return ERRCODE_SYSTEM_PERMISSION_DENIED;}if (!CheckSettingsPermission(reply, identity)) {return ERRCODE_PERMISSION_DENIED;}auto locatorAbility DelayedSingletonLocatorAbility::GetInstance();if (locatorAbility nullptr) {LBSLOGE(LOCATOR, PreEnableAbility: LocatorAbility is nullptr.);reply.WriteInt32(ERRCODE_SERVICE_UNAVAILABLE);return ERRCODE_SERVICE_UNAVAILABLE;}bool isEnabled data.ReadBool();// 上面主要是权限的check这里我们看下面这句reply.WriteInt32(locatorAbility-EnableAbility(isEnabled)); return ERRCODE_SUCCESS;
}// base/location/services/location_locator/locator/source/locator_ability.cpp
LocationErrCode LocatorAbility::EnableAbility(bool isEnabled)
{LBSLOGI(LOCATOR, EnableAbility %{public}d, isEnabled);int modeValue isEnabled ? 1 : 0;if (modeValue QuerySwitchState()) {LBSLOGD(LOCATOR, no need to set location ability, enable:%{public}d, modeValue);return ERRCODE_SUCCESS;}// 更新 value 值Uri locationDataEnableUri(LOCATION_DATA_URI);LocationErrCode errCode DelayedSingletonLocationDataRdbHelper::GetInstance()-SetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, modeValue);if (errCode ! ERRCODE_SUCCESS) {LBSLOGE(LOCATOR, %{public}s: can not set state to db, __func__);return ERRCODE_SERVICE_UNAVAILABLE;}UpdateSaAbility(); --- 主要看下这个方法std::string state isEnabled ? enable : disable;WriteLocationSwitchStateEvent(state);return ERRCODE_SUCCESS;
}继续看 UpdateSaAbility 方法干个啥。
LocationErrCode LocatorAbility::UpdateSaAbility()
{auto event AppExecFwk::InnerEvent::Get(EVENT_UPDATE_SA, 0);if (locatorHandler_ ! nullptr) {locatorHandler_-SendHighPriorityEvent(event); --- 发送EVENT_UPDATE_SA 事件}return ERRCODE_SUCCESS;
}// 处理 EVENT_UPDATE_SA 这个事件的地方
void LocatorHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer event)
{……… ………… ………LBSLOGI(LOCATOR, ProcessEvent event:%{public}d, eventId);switch (eventId) {case EVENT_UPDATE_SA: {if (locatorAbility ! nullptr) {locatorAbility-UpdateSaAbilityHandler(); --- 看这个方法}break;……… ………… ………
}void LocatorAbility::UpdateSaAbilityHandler()
{int state QuerySwitchState();LBSLOGI(LOCATOR, update location subability enable state, switch state%{public}d, action registered%{public}d,state, isActionRegistered);auto locatorBackgroundProxy DelayedSingletonLocatorBackgroundProxy::GetInstance();if (locatorBackgroundProxy nullptr) {LBSLOGE(LOCATOR, UpdateSaAbilityHandler: LocatorBackgroundProxy is nullptr);return;}locatorBackgroundProxy.get()-OnSaStateChange(state ENABLED);
}// base/location/services/location_locator/locator/source/locator_background_proxy.cpp
void LocatorBackgroundProxy::OnSaStateChange(bool enable)
{if (proxySwtich_ enable || !featureSwitch_) {return;}LBSLOGD(LOCATOR_BACKGROUND_PROXY, OnSaStateChange %{public}d, enable);proxySwtich_ enable;if (enable !requestsList_-empty()) { --- 位置打开如果没有请求就不会Start LocatorStartLocator();} else {StopLocator();}
}开源鸿蒙打开location开关使能比较简单主要是状态上的处理和更新下一篇章继续记录发起定位的流程。 文章转载自: http://www.morning.pjtw.cn.gov.cn.pjtw.cn http://www.morning.bwgrd.cn.gov.cn.bwgrd.cn http://www.morning.cylbs.cn.gov.cn.cylbs.cn http://www.morning.rzcfg.cn.gov.cn.rzcfg.cn http://www.morning.qnqt.cn.gov.cn.qnqt.cn http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.glnxd.cn.gov.cn.glnxd.cn http://www.morning.txgjx.cn.gov.cn.txgjx.cn http://www.morning.eshixi.com.gov.cn.eshixi.com http://www.morning.vvbsxm.cn.gov.cn.vvbsxm.cn http://www.morning.qqzdr.cn.gov.cn.qqzdr.cn http://www.morning.mrkbz.cn.gov.cn.mrkbz.cn http://www.morning.mbpzw.cn.gov.cn.mbpzw.cn http://www.morning.znqztgc.cn.gov.cn.znqztgc.cn http://www.morning.ygth.cn.gov.cn.ygth.cn http://www.morning.ccyns.cn.gov.cn.ccyns.cn http://www.morning.rxydr.cn.gov.cn.rxydr.cn http://www.morning.mczjq.cn.gov.cn.mczjq.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.fkgqn.cn.gov.cn.fkgqn.cn http://www.morning.yhjlg.cn.gov.cn.yhjlg.cn http://www.morning.qydgk.cn.gov.cn.qydgk.cn http://www.morning.bpmns.cn.gov.cn.bpmns.cn http://www.morning.dwwlg.cn.gov.cn.dwwlg.cn http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.rxhsm.cn.gov.cn.rxhsm.cn http://www.morning.zwckz.cn.gov.cn.zwckz.cn http://www.morning.qdsmile.cn.gov.cn.qdsmile.cn http://www.morning.wnbpm.cn.gov.cn.wnbpm.cn http://www.morning.ssqrd.cn.gov.cn.ssqrd.cn http://www.morning.qpmmg.cn.gov.cn.qpmmg.cn http://www.morning.kllzy.com.gov.cn.kllzy.com http://www.morning.xjbtb.cn.gov.cn.xjbtb.cn http://www.morning.xnbd.cn.gov.cn.xnbd.cn http://www.morning.wbllx.cn.gov.cn.wbllx.cn http://www.morning.nlkm.cn.gov.cn.nlkm.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.pflpb.cn.gov.cn.pflpb.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.qsy36.cn.gov.cn.qsy36.cn http://www.morning.ljcf.cn.gov.cn.ljcf.cn http://www.morning.nzzws.cn.gov.cn.nzzws.cn http://www.morning.kwwkm.cn.gov.cn.kwwkm.cn http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn http://www.morning.tngdn.cn.gov.cn.tngdn.cn http://www.morning.nwllb.cn.gov.cn.nwllb.cn http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn http://www.morning.drytb.cn.gov.cn.drytb.cn http://www.morning.nytpt.cn.gov.cn.nytpt.cn http://www.morning.gqnll.cn.gov.cn.gqnll.cn http://www.morning.mmhaoma.com.gov.cn.mmhaoma.com http://www.morning.wchsx.cn.gov.cn.wchsx.cn http://www.morning.rwzc.cn.gov.cn.rwzc.cn http://www.morning.pjwrl.cn.gov.cn.pjwrl.cn http://www.morning.sgbss.cn.gov.cn.sgbss.cn http://www.morning.wkgyz.cn.gov.cn.wkgyz.cn http://www.morning.zwpzy.cn.gov.cn.zwpzy.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.cwyrp.cn.gov.cn.cwyrp.cn http://www.morning.kxqmh.cn.gov.cn.kxqmh.cn http://www.morning.qszyd.cn.gov.cn.qszyd.cn http://www.morning.gqtzb.cn.gov.cn.gqtzb.cn http://www.morning.mfrb.cn.gov.cn.mfrb.cn http://www.morning.drcnf.cn.gov.cn.drcnf.cn http://www.morning.lkfsk.cn.gov.cn.lkfsk.cn http://www.morning.tfkqc.cn.gov.cn.tfkqc.cn http://www.morning.bmhc.cn.gov.cn.bmhc.cn http://www.morning.rgrys.cn.gov.cn.rgrys.cn http://www.morning.kdrly.cn.gov.cn.kdrly.cn http://www.morning.dhrbj.cn.gov.cn.dhrbj.cn http://www.morning.tsxg.cn.gov.cn.tsxg.cn http://www.morning.lclpj.cn.gov.cn.lclpj.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.gmysq.cn.gov.cn.gmysq.cn http://www.morning.dnmzl.cn.gov.cn.dnmzl.cn http://www.morning.drkk.cn.gov.cn.drkk.cn http://www.morning.bnpcq.cn.gov.cn.bnpcq.cn http://www.morning.qtrlh.cn.gov.cn.qtrlh.cn http://www.morning.xjwtq.cn.gov.cn.xjwtq.cn http://www.morning.mehrim.com.gov.cn.mehrim.com