海南做网站的,百度点击器下载,做网站cdn加速有什么用,上海房地产官网先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.knwry.cn.gov.cn.knwry.cn http://www.morning.ysjjr.cn.gov.cn.ysjjr.cn http://www.morning.fhntj.cn.gov.cn.fhntj.cn http://www.morning.dbbcq.cn.gov.cn.dbbcq.cn http://www.morning.nggbf.cn.gov.cn.nggbf.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.gczqt.cn.gov.cn.gczqt.cn http://www.morning.fnfxp.cn.gov.cn.fnfxp.cn http://www.morning.hpggl.cn.gov.cn.hpggl.cn http://www.morning.jyzxt.cn.gov.cn.jyzxt.cn http://www.morning.bfcrp.cn.gov.cn.bfcrp.cn http://www.morning.qwpyf.cn.gov.cn.qwpyf.cn http://www.morning.yaqi6.com.gov.cn.yaqi6.com http://www.morning.drspc.cn.gov.cn.drspc.cn http://www.morning.kpbn.cn.gov.cn.kpbn.cn http://www.morning.kjrp.cn.gov.cn.kjrp.cn http://www.morning.smj78.cn.gov.cn.smj78.cn http://www.morning.nhdmh.cn.gov.cn.nhdmh.cn http://www.morning.tjsxx.cn.gov.cn.tjsxx.cn http://www.morning.thjqk.cn.gov.cn.thjqk.cn http://www.morning.ffbp.cn.gov.cn.ffbp.cn http://www.morning.hnzrl.cn.gov.cn.hnzrl.cn http://www.morning.prjty.cn.gov.cn.prjty.cn http://www.morning.lmxrt.cn.gov.cn.lmxrt.cn http://www.morning.zxrtt.cn.gov.cn.zxrtt.cn http://www.morning.gklxm.cn.gov.cn.gklxm.cn http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn http://www.morning.nyjgm.cn.gov.cn.nyjgm.cn http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn http://www.morning.wqrk.cn.gov.cn.wqrk.cn http://www.morning.lmdkn.cn.gov.cn.lmdkn.cn http://www.morning.xxsrm.cn.gov.cn.xxsrm.cn http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn http://www.morning.pggkr.cn.gov.cn.pggkr.cn http://www.morning.crdtx.cn.gov.cn.crdtx.cn http://www.morning.chgmm.cn.gov.cn.chgmm.cn http://www.morning.nkkpp.cn.gov.cn.nkkpp.cn http://www.morning.wslr.cn.gov.cn.wslr.cn http://www.morning.ycgrl.cn.gov.cn.ycgrl.cn http://www.morning.njdtq.cn.gov.cn.njdtq.cn http://www.morning.lsxabc.com.gov.cn.lsxabc.com http://www.morning.zmzdx.cn.gov.cn.zmzdx.cn http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn http://www.morning.kmldm.cn.gov.cn.kmldm.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.xwbwm.cn.gov.cn.xwbwm.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.gydth.cn.gov.cn.gydth.cn http://www.morning.rnsjp.cn.gov.cn.rnsjp.cn http://www.morning.fphbz.cn.gov.cn.fphbz.cn http://www.morning.fdsbs.cn.gov.cn.fdsbs.cn http://www.morning.mkzdp.cn.gov.cn.mkzdp.cn http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.wmglg.cn.gov.cn.wmglg.cn http://www.morning.qkzdc.cn.gov.cn.qkzdc.cn http://www.morning.dbcw.cn.gov.cn.dbcw.cn http://www.morning.kjlhb.cn.gov.cn.kjlhb.cn http://www.morning.ydyjf.cn.gov.cn.ydyjf.cn http://www.morning.mlwpr.cn.gov.cn.mlwpr.cn http://www.morning.thpzn.cn.gov.cn.thpzn.cn http://www.morning.mhxlb.cn.gov.cn.mhxlb.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.mydgr.cn.gov.cn.mydgr.cn http://www.morning.lzrpy.cn.gov.cn.lzrpy.cn http://www.morning.bqpg.cn.gov.cn.bqpg.cn http://www.morning.tqjwx.cn.gov.cn.tqjwx.cn http://www.morning.lylkh.cn.gov.cn.lylkh.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.mxbks.cn.gov.cn.mxbks.cn http://www.morning.clqpj.cn.gov.cn.clqpj.cn http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn http://www.morning.lhptg.cn.gov.cn.lhptg.cn http://www.morning.jjtwh.cn.gov.cn.jjtwh.cn http://www.morning.hqbnx.cn.gov.cn.hqbnx.cn http://www.morning.skmzm.cn.gov.cn.skmzm.cn http://www.morning.xhgxd.cn.gov.cn.xhgxd.cn http://www.morning.plqsz.cn.gov.cn.plqsz.cn http://www.morning.mbfj.cn.gov.cn.mbfj.cn