mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-23 14:43:43 +00:00
Initial implementation of location sharing
Signed-off-by: zyphlar <zyphlar@gmail.com>
This commit is contained in:
@@ -53,6 +53,7 @@ set(SRC
|
||||
app/organicmaps/sdk/editor/OpeningHours.cpp
|
||||
app/organicmaps/sdk/editor/OsmOAuth.cpp
|
||||
app/organicmaps/sdk/Framework.cpp
|
||||
app/organicmaps/location/LocationSharingJni.cpp
|
||||
app/organicmaps/sdk/isolines/IsolinesManager.cpp
|
||||
app/organicmaps/sdk/LocationState.cpp
|
||||
app/organicmaps/sdk/Map.cpp
|
||||
@@ -94,6 +95,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE .)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
# CoMaps libs
|
||||
map
|
||||
location_sharing
|
||||
# ge0
|
||||
# tracking
|
||||
# routing
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "app/organicmaps/sdk/core/jni_helper.hpp"
|
||||
|
||||
#include "location_sharing/location_sharing_types.hpp"
|
||||
#include "location_sharing/crypto_util.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
using namespace location_sharing;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
// Generate session credentials
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_app_organicmaps_location_LocationSharingManager_nativeGenerateSessionCredentials(
|
||||
JNIEnv * env, jclass)
|
||||
{
|
||||
SessionCredentials creds = SessionCredentials::Generate();
|
||||
|
||||
// Create String array [sessionId, encryptionKey]
|
||||
jobjectArray result = env->NewObjectArray(2, env->FindClass("java/lang/String"), nullptr);
|
||||
if (!result)
|
||||
{
|
||||
LOG(LERROR, ("Failed to create result array"));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jstring sessionId = jni::ToJavaString(env, creds.sessionId);
|
||||
jstring encryptionKey = jni::ToJavaString(env, creds.encryptionKey);
|
||||
|
||||
env->SetObjectArrayElement(result, 0, sessionId);
|
||||
env->SetObjectArrayElement(result, 1, encryptionKey);
|
||||
|
||||
env->DeleteLocalRef(sessionId);
|
||||
env->DeleteLocalRef(encryptionKey);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Generate share URL
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_app_organicmaps_location_LocationSharingManager_nativeGenerateShareUrl(
|
||||
JNIEnv * env, jclass, jstring jSessionId, jstring jEncryptionKey, jstring jServerBaseUrl)
|
||||
{
|
||||
std::string sessionId = jni::ToNativeString(env, jSessionId);
|
||||
std::string encryptionKey = jni::ToNativeString(env, jEncryptionKey);
|
||||
std::string serverBaseUrl = jni::ToNativeString(env, jServerBaseUrl);
|
||||
|
||||
SessionCredentials creds(sessionId, encryptionKey);
|
||||
std::string shareUrl = creds.GenerateShareUrl(serverBaseUrl);
|
||||
|
||||
return jni::ToJavaString(env, shareUrl);
|
||||
}
|
||||
|
||||
// Encrypt payload
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_app_organicmaps_location_LocationSharingManager_nativeEncryptPayload(
|
||||
JNIEnv * env, jclass, jstring jEncryptionKey, jstring jPayloadJson)
|
||||
{
|
||||
std::string encryptionKey = jni::ToNativeString(env, jEncryptionKey);
|
||||
std::string payloadJson = jni::ToNativeString(env, jPayloadJson);
|
||||
|
||||
auto encryptedOpt = crypto::EncryptAes256Gcm(encryptionKey, payloadJson);
|
||||
if (!encryptedOpt.has_value())
|
||||
{
|
||||
LOG(LERROR, ("Encryption failed"));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string resultJson = encryptedOpt->ToJson();
|
||||
return jni::ToJavaString(env, resultJson);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
Reference in New Issue
Block a user