Gears Android WIFI/基站定位源代码分析
2010-03-18 16:11:00 来源:WEB开发网// Avoid holding the mutex locked while notifying observers.
data_mutex_.Unlock();
if (is_update_available) {
is_first_scan_complete_ = true;
NotifyListeners();
}
#if USING_CCTESTS
// This is needed for running the WiFi test on the emulator.
// See wifi_data_provider_android.h for details.
if (!first_callback_made_ && wifi_data_.access_point_data.empty()) {
first_callback_made_ = true;
NotifyListeners();
}
#endif
}
从以上代码可以看出,WIFI定位和基站定位的逻辑差不多,只是前者获取的WIFI的扫描结果,而后者获取的基站信息。后面代码的基本上就统一起来了,接下来我们继续看。
5.把变化(WIFI/基站)通知给相应的监听者。
AndroidWifiDataProvider和AndroidRadioDataProvider都是继承了 DeviceDataProviderImplBase,DeviceDataProviderImplBase的主要功能就是管理所有Listeners。
static DeviceDataProvider *Register(ListenerInterface *listener) {
MutexLock mutex(&instance_mutex_);
if (!instance_) {
instance_ = new DeviceDataProvider();
}
assert(instance_);
instance_->Ref();
instance_->AddListener(listener);
return instance_;
}
static bool Unregister(ListenerInterface *listener) {
MutexLock mutex(&instance_mutex_);
if (!instance_->RemoveListener(listener)) {
return false;
}
if (instance_->Unref()) {
delete instance_;
instance_ = NULL;
}
return true;
}
6.谁在监听变化(WIFI/基站)
NetworkLocationProvider在监听变化(WIFI/基站):
radio_data_provider_ = RadioDataProvider::Register(this);
wifi_data_provider_ = WifiDataProvider::Register(this);
当有变化时,会调用函数DeviceDataUpdateAvailable:
更多精彩
赞助商链接