From b5d804c090f445d7da93dd5db585b954b75a0ef5 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Wed, 30 Mar 2011 21:13:35 -0700 Subject: [PATCH] Bug 646685 - Fix watchPosition after isBetterPosition was removed. r=blassey --- dom/src/geolocation/nsGeolocation.cpp | 8 +--- dom/src/geolocation/nsGeolocation.h | 1 - embedding/android/GeckoApp.java | 2 + embedding/android/GeckoAppShell.java | 45 ++++++++++++++-------- embedding/android/GeckoSurfaceView.java | 5 ++- widget/src/android/AndroidJavaWrappers.cpp | 2 + 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index de9d3e579e0..2ee8de160c5 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -243,7 +243,6 @@ nsGeolocationRequest::nsGeolocationRequest(nsGeolocation* aLocator, PRBool aWatchPositionRequest) : mAllowed(PR_FALSE), mCleared(PR_FALSE), - mIsFirstUpdate(PR_TRUE), mIsWatchPositionRequest(aWatchPositionRequest), mCallback(aCallback), mErrorCallback(aErrorCallback), @@ -463,11 +462,8 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition) void nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition) { - if (mIsFirstUpdate) { - mIsFirstUpdate = PR_FALSE; - nsCOMPtr ev = new RequestSendLocationEvent(aPosition, this); - NS_DispatchToMainThread(ev); - } + nsCOMPtr ev = new RequestSendLocationEvent(aPosition, this); + NS_DispatchToMainThread(ev); } void diff --git a/dom/src/geolocation/nsGeolocation.h b/dom/src/geolocation/nsGeolocation.h index 7dac97470ed..3e24ca66f13 100644 --- a/dom/src/geolocation/nsGeolocation.h +++ b/dom/src/geolocation/nsGeolocation.h @@ -117,7 +117,6 @@ class nsGeolocationRequest void NotifyError(PRInt16 errorCode); PRPackedBool mAllowed; PRPackedBool mCleared; - PRPackedBool mIsFirstUpdate; PRPackedBool mIsWatchPositionRequest; nsCOMPtr mTimeoutTimer; diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index 405bc256b14..bea7ec76f37 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -73,6 +73,7 @@ abstract public class GeckoApp public static boolean mStartedEarly = false; public static File sGREDir = null; static Thread mLibLoadThread = null; + public Handler mMainHandler; enum LaunchState {PreLaunch, Launching, WaitButton, Launched, GeckoRunning, GeckoExiting}; @@ -176,6 +177,7 @@ abstract public class GeckoApp public void onCreate(Bundle savedInstanceState) { mAppContext = this; + mMainHandler = new Handler(); SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE); String localeCode = settings.getString(getPackageName() + ".locale", ""); diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index 94c99bceac2..230d055f182 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -119,6 +119,11 @@ public class GeckoAppShell } } + // Get a Handler for the main java thread + public static Handler getMainHandler() { + return GeckoApp.mAppContext.mMainHandler; + } + private static Handler sHandler = null; // Get a Handler for a looper thread, or create one if it doesn't exist yet @@ -558,24 +563,32 @@ public class GeckoAppShell } } - public static void enableLocation(boolean enable) { - LocationManager lm = (LocationManager) - GeckoApp.surfaceView.getContext().getSystemService(Context.LOCATION_SERVICE); + public static void enableLocation(final boolean enable) { + + getMainHandler().post(new Runnable() { + public void run() { + GeckoSurfaceView view = GeckoApp.surfaceView; + LocationManager lm = (LocationManager) + view.getContext().getSystemService(Context.LOCATION_SERVICE); - if (enable) { - Criteria crit = new Criteria(); - crit.setAccuracy(Criteria.ACCURACY_FINE); - String provider = lm.getBestProvider(crit, true); - if (provider == null) - return; + if (enable) { + Criteria crit = new Criteria(); + crit.setAccuracy(Criteria.ACCURACY_FINE); + String provider = lm.getBestProvider(crit, true); + if (provider == null) + return; - Location loc = lm.getLastKnownLocation(provider); - if (loc != null) - sendEventToGecko(new GeckoEvent(loc, null)); - lm.requestLocationUpdates(provider, 100, (float).5, GeckoApp.surfaceView, Looper.getMainLooper()); - } else { - lm.removeUpdates(GeckoApp.surfaceView); - } + Looper l = Looper.getMainLooper(); + Location loc = lm.getLastKnownLocation(provider); + if (loc != null) { + view.onLocationChanged(loc); + } + lm.requestLocationUpdates(provider, 100, (float).5, view, l); + } else { + lm.removeUpdates(view); + } + } + }); } public static void moveTaskToBack() { diff --git a/embedding/android/GeckoSurfaceView.java b/embedding/android/GeckoSurfaceView.java index b9b2f293497..365b9c9a7d1 100644 --- a/embedding/android/GeckoSurfaceView.java +++ b/embedding/android/GeckoSurfaceView.java @@ -422,6 +422,7 @@ class GeckoSurfaceView // may want to expose multiple, or filter // for best. mLastGeoAddress = addresses.get(0); + GeckoAppShell.sendEventToGecko(new GeckoEvent(location[0], mLastGeoAddress)); } catch (Exception e) { Log.w("GeckoSurfaceView", "GeocoderTask "+e); } @@ -433,7 +434,7 @@ class GeckoSurfaceView public void onLocationChanged(Location location) { if (mGeocoder == null) - mGeocoder = new Geocoder(getContext()); + mGeocoder = new Geocoder(getContext(), Locale.getDefault()); if (mLastGeoAddress == null) { new GeocoderTask().execute(location); @@ -448,7 +449,7 @@ class GeckoSurfaceView // pfm value. don't want to slam the // geocoder with very similar values, so // only call after about 100m - if (results[0] > 100) + if (results[0] > 100) new GeocoderTask().execute(location); } diff --git a/widget/src/android/AndroidJavaWrappers.cpp b/widget/src/android/AndroidJavaWrappers.cpp index aa4d203f329..c6314c2037b 100644 --- a/widget/src/android/AndroidJavaWrappers.cpp +++ b/widget/src/android/AndroidJavaWrappers.cpp @@ -225,6 +225,7 @@ AndroidAddress::CreateGeoPositionAddress(JNIEnv *jenv, jobject jobj) nsJNIString postalCode(static_cast(jenv->CallObjectMethod(jobj, jGetPostalCodeMethod)), jenv); nsJNIString region(static_cast(jenv->CallObjectMethod(jobj, jGetAdminAreaMethod, 0)), jenv); +#ifdef DEBUG printf_stderr("!!!!!!!!!!!!!! AndroidAddress::CreateGeoPositionAddress:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n", NS_LossyConvertUTF16toASCII(streetNumber).get(), NS_LossyConvertUTF16toASCII(street).get(), @@ -235,6 +236,7 @@ AndroidAddress::CreateGeoPositionAddress(JNIEnv *jenv, jobject jobj) NS_LossyConvertUTF16toASCII(country).get(), NS_LossyConvertUTF16toASCII(countryCode).get(), NS_LossyConvertUTF16toASCII(postalCode).get()); +#endif return new nsGeoPositionAddress(streetNumber, street,