mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-04-28 12:17:57 +03:00
LocationManager: expose more information from the backend to the apps
note: GnssStatus was accidentally bundled into ab5b600bf1
This commit is contained in:
parent
d2e2ab37bc
commit
12121d2d48
5 changed files with 87 additions and 9 deletions
|
@ -14,12 +14,13 @@ static void location_updated (
|
|||
gchar* description,
|
||||
gint64 timestamp_s,
|
||||
gint64 timestamp_ms,
|
||||
JavaVM *jvm
|
||||
) {
|
||||
JavaVM *jvm)
|
||||
{
|
||||
JNIEnv *env;
|
||||
(*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6);
|
||||
jclass class = (*env)->FindClass(env, "android/location/LocationManager");
|
||||
(*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "locationUpdated", "(DDD)V"), latitude, longitude, heading);
|
||||
jlong timestamp = timestamp_s * 1000 + timestamp_ms;
|
||||
(*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "locationUpdated", "(DDDDDDJ)V"), latitude, longitude, altitude, accuracy, speed, heading, timestamp);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_location_LocationManager_nativeGetLocation(JNIEnv *env, jobject) {
|
||||
|
|
|
@ -23,7 +23,7 @@ public class SensorManager {
|
|||
new LocationManager().requestLocationUpdates(null, 0, 0, new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
listener.onSensorChanged(new SensorEvent(new float[]{(float)location.getBearing()}, sensor));
|
||||
listener.onSensorChanged(new SensorEvent(new float[]{location.getBearing()}, sensor));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
|
|
@ -4,12 +4,27 @@ public class Location {
|
|||
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
private double altitude;
|
||||
private double accuracy;
|
||||
private double speed;
|
||||
private double bearing;
|
||||
private long timestamp;
|
||||
|
||||
public Location (double latitude, double longitude, double bearing) {
|
||||
/* for internal use */
|
||||
public Location (double latitude,
|
||||
double longitude,
|
||||
double altitude,
|
||||
double accuracy,
|
||||
double speed,
|
||||
double bearing,
|
||||
long timestamp) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = altitude;
|
||||
this.accuracy = accuracy;
|
||||
this.speed = speed;
|
||||
this.bearing = bearing;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
|
@ -20,8 +35,43 @@ public class Location {
|
|||
return longitude;
|
||||
}
|
||||
|
||||
public double getBearing() {
|
||||
return bearing;
|
||||
public boolean hasAltitude() {
|
||||
return altitude != -Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
public double getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
public boolean hasAccuracy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public float getAccuracy() {
|
||||
return (float)accuracy;
|
||||
}
|
||||
|
||||
public boolean hasSpeed() {
|
||||
return speed != -1;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return (float)speed;
|
||||
}
|
||||
|
||||
public boolean hasBearing() {
|
||||
return bearing != -1;
|
||||
}
|
||||
|
||||
public float getBearing() {
|
||||
return (float)bearing;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return "fused";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package android.location;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import java.lang.Runnable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -26,9 +29,15 @@ public class LocationManager {
|
|||
|
||||
private native void nativeGetLocation();
|
||||
|
||||
private static void locationUpdated(double latitude, double longitude, double heading) {
|
||||
private static void locationUpdated(double latitude,
|
||||
double longitude,
|
||||
double altitude,
|
||||
double accuracy,
|
||||
double speed,
|
||||
double bearing,
|
||||
long timestamp) {
|
||||
for (LocationListener locationListener : listeners) {
|
||||
locationListener.onLocationChanged(new Location(latitude, longitude, heading));
|
||||
locationListener.onLocationChanged(new Location(latitude, longitude, altitude, accuracy, speed, bearing, timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,4 +51,21 @@ public class LocationManager {
|
|||
public List<String> getAllProviders() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<String> getProviders(boolean enabledOnly) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public boolean registerGnssStatusCallback(GnssStatus.Callback callback, Handler handler) {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.onSatelliteStatusChanged(new GnssStatus());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public void unregisterGnssStatusCallback(GnssStatus.Callback callback) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -259,6 +259,7 @@ srcs = [
|
|||
'android/hardware/input/InputManager.java',
|
||||
'android/hardware/usb/UsbManager.java',
|
||||
'android/location/Criteria.java',
|
||||
'android/location/GnssStatus.java',
|
||||
'android/location/Location.java',
|
||||
'android/location/LocationListener.java',
|
||||
'android/location/LocationManager.java',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue