相关配置:
framework/base/core/res/res/values/config.xml
<!-- Whether to enable network location overlay which allows network
location provider to be replaced by an app at run-time. When disabled,
only the config_networkLocationProviderPackageName package will be
searched for network location provider, otherwise packages whose
signature matches the signatures of config_locationProviderPackageNames
will be searched, and the service with the highest version number will
be picked. Anyone who wants to disable the overlay mechanism can set it
to false.
-->
<bool name="config_enableNetworkLocationOverlay" translatable="false">true</bool>
<!-- Package name providing network location support. Used only when
config_enableNetworkLocationOverlay is false. -->
<string name="config_networkLocationProviderPackageName" translatable="false">@null</string>
<!-- Whether to enable fused location provider overlay which allows fused
location provider to be replaced by an app at run-time. When disabled,
only the config_fusedLocationProviderPackageName package will be
searched for fused location provider, otherwise packages whose
signature matches the signatures of config_locationProviderPackageNames
will be searched, and the service with the highest version number will
be picked. Anyone who wants to disable the overlay mechanism can set it
to false.
-->
<bool name="config_enableFusedLocationOverlay" translatable="false">true</bool>
<!-- Package name providing fused location support. Used only when
config_enableFusedLocationOverlay is false. -->
<string name="config_fusedLocationProviderPackageName" translatable="false">com.android.location.fused</string>
<!-- Whether to enable geocoder overlay which allows geocoder to be replaced
by an app at run-time. When disabled, only the
config_geocoderProviderPackageName package will be searched for
geocoder, otherwise packages whose signature matches the signatures of
config_locationProviderPackageNames will be searched, and the service
with the highest version number will be picked. Anyone who wants to
disable the overlay mechanism can set it to false.
-->
<bool name="config_enableGeocoderOverlay" translatable="false">true</bool>
<!-- Package name providing geocoder API support. Used only when
config_enableGeocoderOverlay is false. -->
<string name="config_geocoderProviderPackageName" translatable="false">@null</string>
<!-- Package name(s) containing location provider support.
These packages can contain services implementing location providers,
such as the Geocode Provider, Network Location Provider, and
Fused Location Provider. They will each be searched for
service components implementing these providers.
It is strongly recommended that the packages explicitly named
below are on the system image, so that they will not map to
a 3rd party application.
The location framework also has support for installation
of new location providers at run-time. The new package does not
have to be explicitly listed here, however it must have a signature
that matches the signature of at least one package on this list.
-->
<string-array name="config_locationProviderPackageNames" translatable="false">
<!-- The standard AOSP fused location provider -->
<item>com.android.location.fused</item>
</string-array>
实际生效的是 厂商定制
device/sample/overlays/location/frameworks/base/core/res/res/values
<!-- Enable overlay for all location components. -->
<bool name="config_enableNetworkLocationOverlay" translatable="false">true</bool>
<bool name="config_enableFusedLocationOverlay" translatable="false">true</bool>
<bool name="config_enableGeocoderOverlay" translatable="false">true</bool>
<bool name="config_enableGeofenceOverlay" translatable="false">true</bool>
<!--
Sets the package names whose certificates should be used to
verify location providers are allowed to be loaded.
-->
<string-array name="config_locationProviderPackageNames" translatable="false">
<item>com.google.android.gms</item>
<item>com.android.location.fused</item>
</string-array>
创建:
framework:
LocationManagerService
此处待补充其他类型
GeocodeProvider:
mGeocodeProvider = GeocoderProxy.createAndBind(mContext,
com.android.internal.R.bool.config_enableGeocoderOverlay,
com.android.internal.R.string.config_geocoderProviderPackageName,
com.android.internal.R.array.config_locationProviderPackageNames,
mLocationHandler);
GeocoderProxy{
核心是 mServiceWatcher
ServiceWatcher() 中初始化mSignatureSets
ServiceWatcher.bindBestPackageLocked() 中选择mSignatureSets包存的包,然后选择版本最大的包。(不理解,版本号大的就好吗?) 然后 bindToPackageLocked
提供两个接口:
getFromLocation 位置转名字
getFromLocationName 名字转位置
}
--------------------------------------------------------------------------
cts测试:
android.webkit.cts.GeolocationTest {
RAW_HTML 网页实现
setUp():
1. mOnUiThread 初始化,JavaScript 和 Geolocation(enable 和 databasepath)
2. test providers 准备(mock location)addTestProviders()
testSimpleGeolocationRequestAcceptOnce():{
初始化 TestSimpleGeolocationRequestWebChromeClient chromeClientAcceptOnce {
onGeolocationPermissionsShowPrompt()关键函数配置网页权限 mReceivedRequest在这里刷新
}
loadUrlAndUpdateLocation(URL_1){
新起线程加载url
新起线程更新模拟地址 250ms更新一次
}
检查两个值
chromeClientAcceptOnce.mReceivedRequest :Geolocation prompt
mJavascriptStatusReceiver.mHasPosition:{
JavascriptStatusReceiver{
gotLocation() : RAW_HTML 中去调用该接口“navigator.geolocation.getCurrentPosition”
}
}
}
testSimpleGeolocationRequestAcceptAlways()
}
----------------------------------------------------
webkit
navigator.geolocation.getCurrentPosition 实现:
以下不确定:
接口实现
external\chromium_org\third_party\WebKit\Source\modules\geolocation.cpp:void Geolocation::getCurrentPosition
调用
external\chromium_org\third_party\WebKit\Source\bindings\v8\custom\V8GeolocationCustom.cpp
测试
external\chromium_org\chrome\test\webdriver\test\chromedriver_tests.py