Bug 735011 - geolocation - support enableHighAccuracy position option. r=dougt

This commit is contained in:
Josh Dhaliwal 2012-03-21 10:52:35 -07:00
parent 36b55e394a
commit 5062750d82
9 changed files with 100 additions and 2 deletions

View File

@ -385,6 +385,11 @@ nsGeolocationRequest::Allow()
if (tempAge >= 0)
maximumAge = tempAge;
}
bool highAccuracy;
rv = mOptions->GetEnableHighAccuracy(&highAccuracy);
if (NS_SUCCEEDED(rv) && highAccuracy) {
geoService->SetHigherAccuracy(true);
}
}
if (lastPosition && maximumAge > 0 &&
@ -480,6 +485,16 @@ nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition)
void
nsGeolocationRequest::Shutdown()
{
if (mOptions) {
bool highAccuracy;
nsresult rv = mOptions->GetEnableHighAccuracy(&highAccuracy);
if (NS_SUCCEEDED(rv) && highAccuracy) {
nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance();
if (geoService)
geoService->SetHigherAccuracy(false);
}
}
if (mTimeoutTimer) {
mTimeoutTimer->Cancel();
mTimeoutTimer = nsnull;
@ -702,6 +717,24 @@ nsGeolocationService::SetDisconnectTimer()
nsITimer::TYPE_ONE_SHOT);
}
void
nsGeolocationService::SetHigherAccuracy(bool aEnable)
{
if (!mHigherAccuracy && aEnable) {
for (PRInt32 i = 0; i < mProviders.Count(); i++) {
mProviders[i]->SetHighAccuracy(true);
}
}
if (mHigherAccuracy && !aEnable) {
for (PRInt32 i = 0; i < mProviders.Count(); i++) {
mProviders[i]->SetHighAccuracy(false);
}
}
mHigherAccuracy = aEnable;
}
void
nsGeolocationService::StopDevice()
{

View File

@ -134,7 +134,9 @@ public:
NS_DECL_NSIGEOLOCATIONUPDATE
NS_DECL_NSIOBSERVER
nsGeolocationService() {}
nsGeolocationService() {
mHigherAccuracy = false;
}
nsresult Init();
@ -154,6 +156,9 @@ public:
// create, or reinitalize the callback timer
void SetDisconnectTimer();
// request higher accuracy, if possible
void SetHigherAccuracy(bool aEnable);
private:
~nsGeolocationService();
@ -173,6 +178,9 @@ private:
// This is the last geo position that we have seen.
nsCOMPtr<nsIDOMGeoPosition> mLastPosition;
// Current state of requests for higher accuracy
bool mHigherAccuracy;
};

View File

@ -163,6 +163,9 @@ WifiGeoPositionProvider.prototype = {
this.started = false;
},
setHighAccuracy: function(enable) {
},
getAccessTokenForURL: function(url)
{
// check to see if we have an access token:

View File

@ -82,3 +82,11 @@ AndroidLocationProvider::Shutdown()
return NS_OK;
}
NS_IMETHODIMP
AndroidLocationProvider::SetHighAccuracy(bool enable)
{
if (!AndroidBridge::Bridge())
return NS_ERROR_NOT_IMPLEMENTED;
AndroidBridge::Bridge()->EnableLocationHighAccuracy(enable);
return NS_OK;
}

View File

@ -183,3 +183,9 @@ GonkGPSGeolocationProvider::Shutdown()
return NS_OK;
}
NS_IMETHODIMP
GonkGPSGeolocationProvider::SetHighAccuracy(bool)
{
return NS_OK;
}

View File

@ -135,6 +135,8 @@ public class GeckoAppShell
private static Sensor gOrientationSensor = null;
private static Sensor gProximitySensor = null;
private static boolean mLocationHighAccuracy = false;
/* The Android-side API: API methods that Android calls */
// Initialization methods
@ -562,6 +564,19 @@ public class GeckoAppShell
if (enable) {
Criteria criteria = new Criteria();
criteria.setSpeedRequired(false);
criteria.setBearingRequired(false);
criteria.setAltitudeRequired(false);
if (mLocationHighAccuracy) {
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
} else {
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setCostAllowed(false);
criteria.setPowerRequirement(Criteria.POWER_LOW);
}
String provider = lm.getBestProvider(criteria, true);
if (provider == null)
return;
@ -579,6 +594,11 @@ public class GeckoAppShell
});
}
public static void enableLocationHighAccuracy(final boolean enable) {
Log.i(LOGTAG, "Location provider - high accuracy: " + enable);
mLocationHighAccuracy = enable;
}
public static void enableSensor(int aSensortype) {
SensorManager sm = (SensorManager)
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);

View File

@ -331,6 +331,18 @@ AndroidBridge::EnableLocation(bool aEnable)
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable);
}
void
AndroidBridge::EnableLocationHighAccuracy(bool aEnable)
{
ALOG_BRIDGE("AndroidBridge::EnableLocationHighAccuracy");
JNIEnv *env = GetJNIEnv();
if (!env)
return;
AutoLocalJNIFrame jniFrame(env, 1);
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocationHighAccuracy, aEnable);
}
void
AndroidBridge::EnableSensor(int aSensorType) {
ALOG_BRIDGE("AndroidBridge::EnableSensor");

View File

@ -177,6 +177,7 @@ public:
void AcknowledgeEventSync();
void EnableLocation(bool aEnable);
void EnableLocationHighAccuracy(bool aEnable);
void EnableSensor(int aSensorType);
@ -462,6 +463,7 @@ protected:
jmethodID jNotifyScreenShot;
jmethodID jAcknowledgeEventSync;
jmethodID jEnableLocation;
jmethodID jEnableLocationHighAccuracy;
jmethodID jEnableSensor;
jmethodID jDisableSensor;
jmethodID jReturnIMEQueryResult;

View File

@ -67,7 +67,7 @@ interface nsIGeolocationUpdate : nsISupports {
* startup is called, any geo location change should call
* callback.update().
*/
[scriptable, uuid(701413ED-0F51-64F7-71C7-4369D8E07D6E)]
[scriptable, uuid(483BE98B-F747-490A-8AF1-53146D2D5373)]
interface nsIGeolocationProvider : nsISupports {
/**
@ -87,6 +87,12 @@ interface nsIGeolocationProvider : nsISupports {
* Shuts down the location device.
*/
void shutdown();
/**
* hint to provide to use any amount of power to provide a better result
*/
void setHighAccuracy(in boolean enable);
};
%{C++