mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 20:22:00 +00:00
Bug 1386240 - [1.3] Check success status when enabling or disabling geolocation events. r=jchen
This commit is contained in:
parent
09ca1b1297
commit
14c89f86b5
@ -27,8 +27,10 @@ AndroidLocationProvider::~AndroidLocationProvider()
|
||||
NS_IMETHODIMP
|
||||
AndroidLocationProvider::Startup()
|
||||
{
|
||||
java::GeckoAppShell::EnableLocation(true);
|
||||
return NS_OK;
|
||||
if (java::GeckoAppShell::EnableLocation(true)) {
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -43,8 +45,10 @@ AndroidLocationProvider::Watch(nsIGeolocationUpdate* aCallback)
|
||||
NS_IMETHODIMP
|
||||
AndroidLocationProvider::Shutdown()
|
||||
{
|
||||
java::GeckoAppShell::EnableLocation(false);
|
||||
return NS_OK;
|
||||
if (java::GeckoAppShell::EnableLocation(false)) {
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -317,37 +317,28 @@ public class GeckoAppShell
|
||||
@WrapForJNI(calledFrom = "gecko")
|
||||
// Permissions are explicitly checked when requesting content permission.
|
||||
@SuppressLint("MissingPermission")
|
||||
/* package */ static void enableLocation(final boolean enable) {
|
||||
if (!ThreadUtils.isOnUiThread()) {
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
enableLocation(enable);
|
||||
} catch (final SecurityException e) {
|
||||
Log.e(LOGTAG, "No location permission", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
LocationManager lm = getLocationManager(getApplicationContext());
|
||||
private static synchronized boolean enableLocation(final boolean enable) {
|
||||
final LocationManager lm = getLocationManager(getApplicationContext());
|
||||
if (lm == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!enable) {
|
||||
lm.removeUpdates(getLocationListener());
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
Location lastKnownLocation = getLastKnownLocation(lm);
|
||||
if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) &&
|
||||
!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Location lastKnownLocation = getLastKnownLocation(lm);
|
||||
if (lastKnownLocation != null) {
|
||||
getLocationListener().onLocationChanged(lastKnownLocation);
|
||||
}
|
||||
|
||||
Criteria criteria = new Criteria();
|
||||
final Criteria criteria = new Criteria();
|
||||
criteria.setSpeedRequired(false);
|
||||
criteria.setBearingRequired(false);
|
||||
criteria.setAltitudeRequired(false);
|
||||
@ -361,12 +352,14 @@ public class GeckoAppShell
|
||||
criteria.setPowerRequirement(Criteria.POWER_LOW);
|
||||
}
|
||||
|
||||
String provider = lm.getBestProvider(criteria, true);
|
||||
if (provider == null)
|
||||
return;
|
||||
final String provider = lm.getBestProvider(criteria, true);
|
||||
if (provider == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Looper l = Looper.getMainLooper();
|
||||
final Looper l = Looper.getMainLooper();
|
||||
lm.requestLocationUpdates(provider, 100, 0.5f, getLocationListener(), l);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static LocationManager getLocationManager(Context context) {
|
||||
@ -391,7 +384,7 @@ public class GeckoAppShell
|
||||
/* package */ static native void onSensorChanged(int hal_type, float x, float y, float z,
|
||||
float w, int accuracy, long time);
|
||||
|
||||
@WrapForJNI(calledFrom = "ui", dispatchTo = "gecko")
|
||||
@WrapForJNI(calledFrom = "any", dispatchTo = "gecko")
|
||||
/* package */ static native void onLocationChanged(double latitude, double longitude,
|
||||
double altitude, float accuracy,
|
||||
float bearing, float speed, long time);
|
||||
@ -488,12 +481,12 @@ public class GeckoAppShell
|
||||
|
||||
// Geolocation.
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
public void onLocationChanged(final Location location) {
|
||||
// No logging here: user-identifying information.
|
||||
GeckoAppShell.onLocationChanged(location.getLatitude(), location.getLongitude(),
|
||||
location.getAltitude(), location.getAccuracy(),
|
||||
location.getBearing(), location.getSpeed(),
|
||||
location.getTime());
|
||||
GeckoAppShell.onLocationChanged(
|
||||
location.getLatitude(), location.getLongitude(),
|
||||
location.getAltitude(), location.getAccuracy(),
|
||||
location.getBearing(), location.getSpeed(), location.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -188,7 +188,7 @@ auto GeckoAppShell::EnableBatteryNotifications() -> void
|
||||
constexpr char GeckoAppShell::EnableLocation_t::name[];
|
||||
constexpr char GeckoAppShell::EnableLocation_t::signature[];
|
||||
|
||||
auto GeckoAppShell::EnableLocation(bool a0) -> void
|
||||
auto GeckoAppShell::EnableLocation(bool a0) -> bool
|
||||
{
|
||||
return mozilla::jni::Method<EnableLocation_t>::Call(GeckoAppShell::Context(), nullptr, a0);
|
||||
}
|
||||
|
@ -571,13 +571,13 @@ public:
|
||||
|
||||
struct EnableLocation_t {
|
||||
typedef GeckoAppShell Owner;
|
||||
typedef void ReturnType;
|
||||
typedef void SetterType;
|
||||
typedef bool ReturnType;
|
||||
typedef bool SetterType;
|
||||
typedef mozilla::jni::Args<
|
||||
bool> Args;
|
||||
static constexpr char name[] = "enableLocation";
|
||||
static constexpr char signature[] =
|
||||
"(Z)V";
|
||||
"(Z)Z";
|
||||
static const bool isStatic = true;
|
||||
static const mozilla::jni::ExceptionMode exceptionMode =
|
||||
mozilla::jni::ExceptionMode::ABORT;
|
||||
@ -587,7 +587,7 @@ public:
|
||||
mozilla::jni::DispatchTarget::CURRENT;
|
||||
};
|
||||
|
||||
static auto EnableLocation(bool) -> void;
|
||||
static auto EnableLocation(bool) -> bool;
|
||||
|
||||
struct EnableLocationHighAccuracy_t {
|
||||
typedef GeckoAppShell Owner;
|
||||
@ -1416,7 +1416,7 @@ public:
|
||||
static const mozilla::jni::ExceptionMode exceptionMode =
|
||||
mozilla::jni::ExceptionMode::ABORT;
|
||||
static const mozilla::jni::CallingThread callingThread =
|
||||
mozilla::jni::CallingThread::UI;
|
||||
mozilla::jni::CallingThread::ANY;
|
||||
static const mozilla::jni::DispatchTarget dispatchTarget =
|
||||
mozilla::jni::DispatchTarget::GECKO;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user