2023-07-14 20:02:34 +02:00
|
|
|
#include <libportal/portal.h>
|
|
|
|
|
|
|
|
|
|
#include "../defines.h"
|
|
|
|
|
#include "../generated_headers/android_location_LocationManager.h"
|
|
|
|
|
|
|
|
|
|
static void location_updated (
|
|
|
|
|
XdpPortal* self,
|
|
|
|
|
gdouble latitude,
|
|
|
|
|
gdouble longitude,
|
|
|
|
|
gdouble altitude,
|
|
|
|
|
gdouble accuracy,
|
|
|
|
|
gdouble speed,
|
|
|
|
|
gdouble heading,
|
|
|
|
|
gchar* description,
|
|
|
|
|
gint64 timestamp_s,
|
|
|
|
|
gint64 timestamp_ms,
|
2025-03-26 21:25:39 +01:00
|
|
|
JavaVM *jvm)
|
|
|
|
|
{
|
2023-07-14 20:02:34 +02:00
|
|
|
JNIEnv *env;
|
|
|
|
|
(*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6);
|
|
|
|
|
jclass class = (*env)->FindClass(env, "android/location/LocationManager");
|
2025-03-26 21:25:39 +01:00
|
|
|
jlong timestamp = timestamp_s * 1000 + timestamp_ms;
|
|
|
|
|
(*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "locationUpdated", "(DDDDDDJ)V"), latitude, longitude, altitude, accuracy, speed, heading, timestamp);
|
2023-07-14 20:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_android_location_LocationManager_nativeGetLocation(JNIEnv *env, jobject) {
|
2023-08-09 12:35:26 +02:00
|
|
|
if (!getenv("ATL_UGLY_ENABLE_LOCATION")) {
|
|
|
|
|
// Location access is prohibited by default until sanboxing is implemented.
|
|
|
|
|
// Set ATL_UGLY_ENABLE_LOCATION environment variable to enable it.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-10 20:37:28 +01:00
|
|
|
|
|
|
|
|
static XdpPortal *portal = NULL;
|
2023-07-14 20:02:34 +02:00
|
|
|
if (!portal) {
|
|
|
|
|
portal = xdp_portal_new();
|
|
|
|
|
JavaVM *jvm;
|
|
|
|
|
(*env)->GetJavaVM(env, &jvm);
|
|
|
|
|
g_signal_connect(portal, "location-updated", G_CALLBACK(location_updated), jvm);
|
|
|
|
|
}
|
2024-02-10 20:37:28 +01:00
|
|
|
|
2023-07-14 20:02:34 +02:00
|
|
|
xdp_portal_location_monitor_start (portal, NULL, 0, 0, XDP_LOCATION_ACCURACY_EXACT, XDP_LOCATION_MONITOR_FLAG_NONE, NULL, NULL, NULL);
|
|
|
|
|
}
|