Android: Use the shared HTTP analytics backend

We can now route Android analytics through Common::HttpAnalyticsBackend, drop the Volley sender, and keep the JNI layer limited to only transfer metadata since https://bugs.dolphin-emu.org/issues/11772 has been fixed.
This commit is contained in:
Simonx22 2025-11-08 10:47:24 -05:00
parent 9d27c145b9
commit 82f658a28f
11 changed files with 3 additions and 137 deletions

View File

@ -144,9 +144,6 @@ dependencies {
implementation("androidx.leanback:leanback:1.0.0")
implementation("androidx.tvprovider:tvprovider:1.0.0")
// For REST calls
implementation("com.android.volley:volley:1.2.1")
// For loading game covers from disk and GameTDB
implementation("io.coil-kt:coil:2.6.0")

View File

@ -11,7 +11,6 @@ import org.dolphinemu.dolphinemu.utils.ActivityTracker;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.GCAdapter;
import org.dolphinemu.dolphinemu.utils.WiimoteAdapter;
import org.dolphinemu.dolphinemu.utils.VolleyUtil;
public class DolphinApplication extends Application
{
@ -25,7 +24,6 @@ public class DolphinApplication extends Application
application = this;
sActivityTracker = new ActivityTracker();
registerActivityLifecycleCallbacks(sActivityTracker);
VolleyUtil.init(getApplicationContext());
System.loadLibrary("main");
GCAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);

View File

@ -5,8 +5,6 @@ package org.dolphinemu.dolphinemu.utils
import android.os.Build
import androidx.annotation.Keep
import androidx.fragment.app.FragmentActivity
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import org.dolphinemu.dolphinemu.DolphinApplication
import org.dolphinemu.dolphinemu.dialogs.AnalyticsDialog
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting
@ -37,21 +35,6 @@ object Analytics {
}
}
@Keep
@JvmStatic
fun sendReport(endpoint: String, data: ByteArray) {
val request: StringRequest = object : StringRequest(
Method.POST,
endpoint,
null,
Response.ErrorListener { Log.debug("Failed to send report") }) {
override fun getBody(): ByteArray {
return data
}
}
VolleyUtil.getQueue().add(request)
}
@Keep
@JvmStatic
fun getValue(key: String?): String {

View File

@ -1,24 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.utils;
import android.content.Context;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
public class VolleyUtil
{
private static RequestQueue queue;
public static void init(Context context)
{
if (queue == null)
queue = Volley.newRequestQueue(context);
}
public static RequestQueue getQueue()
{
return queue;
}
}

View File

@ -26,7 +26,6 @@ static jclass s_game_file_cache_class;
static jfieldID s_game_file_cache_pointer;
static jclass s_analytics_class;
static jmethodID s_send_analytics_report;
static jmethodID s_get_analytics_value;
static jclass s_pair_class;
@ -191,11 +190,6 @@ jclass GetAnalyticsClass()
return s_analytics_class;
}
jmethodID GetSendAnalyticsReport()
{
return s_send_analytics_report;
}
jmethodID GetAnalyticsValue()
{
return s_get_analytics_value;
@ -623,8 +617,6 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
const jclass analytics_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Analytics");
s_analytics_class = reinterpret_cast<jclass>(env->NewGlobalRef(analytics_class));
s_send_analytics_report =
env->GetStaticMethodID(s_analytics_class, "sendReport", "(Ljava/lang/String;[B)V");
s_get_analytics_value = env->GetStaticMethodID(s_analytics_class, "getValue",
"(Ljava/lang/String;)Ljava/lang/String;");
env->DeleteLocalRef(analytics_class);

View File

@ -19,7 +19,6 @@ jmethodID GetOnTitleChanged();
jmethodID GetFinishEmulationActivity();
jclass GetAnalyticsClass();
jmethodID GetSendAnalyticsReport();
jmethodID GetAnalyticsValue();
jclass GetGameFileClass();

View File

@ -18,7 +18,6 @@
#include <fmt/format.h>
#include <jni.h>
#include "Common/AndroidAnalytics.h"
#include "Common/Assert.h"
#include "Common/CPUDetect.h"
#include "Common/CommonPaths.h"
@ -221,24 +220,6 @@ static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common:
return result != JNI_FALSE;
}
static void ReportSend(const std::string& endpoint, const std::string& report)
{
JNIEnv* env = IDCache::GetEnvForThread();
jbyteArray output_array = env->NewByteArray(report.size());
jbyte* output = env->GetByteArrayElements(output_array, nullptr);
memcpy(output, report.data(), report.size());
env->ReleaseByteArrayElements(output_array, output, 0);
jstring j_endpoint = ToJString(env, endpoint);
env->CallStaticVoidMethod(IDCache::GetAnalyticsClass(), IDCache::GetSendAnalyticsReport(),
j_endpoint, output_array);
env->DeleteLocalRef(output_array);
env->DeleteLocalRef(j_endpoint);
}
static std::string GetAnalyticValue(const std::string& key)
{
JNIEnv* env = IDCache::GetEnvForThread();
@ -565,7 +546,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(J
UICommon::CreateDirectories();
Common::RegisterMsgAlertHandler(&MsgAlert);
Common::AndroidSetReportHandler(&ReportSend);
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
WiimoteReal::InitAdapterClass();

View File

@ -1,29 +0,0 @@
// Copyright 2018 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/AndroidAnalytics.h"
#include <functional>
#include <string>
namespace Common
{
static std::function<void(std::string, std::string)> s_android_send_report;
void AndroidSetReportHandler(std::function<void(std::string, std::string)> func)
{
s_android_send_report = std::move(func);
}
AndroidAnalyticsBackend::AndroidAnalyticsBackend(std::string passed_endpoint)
: m_endpoint{std::move(passed_endpoint)}
{
}
AndroidAnalyticsBackend::~AndroidAnalyticsBackend() = default;
void AndroidAnalyticsBackend::Send(std::string report)
{
s_android_send_report(m_endpoint, report);
}
} // namespace Common

View File

@ -1,25 +0,0 @@
// Copyright 2018 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <functional>
#include <string>
#include "Common/Analytics.h"
namespace Common
{
void AndroidSetReportHandler(std::function<void(std::string, std::string)> function);
class AndroidAnalyticsBackend : public AnalyticsReportingBackend
{
public:
explicit AndroidAnalyticsBackend(const std::string endpoint);
~AndroidAnalyticsBackend() override;
void Send(std::string report) override;
private:
std::string m_endpoint;
};
} // namespace Common

View File

@ -224,8 +224,6 @@ endif()
if(ANDROID)
target_sources(common PRIVATE
AndroidAnalytics.cpp
AndroidAnalytics.h
Logging/ConsoleListenerDroid.cpp
MemArenaAndroid.cpp
)

View File

@ -16,9 +16,10 @@
#include "Common/WindowsRegistry.h"
#elif defined(__APPLE__)
#include <objc/message.h>
#elif defined(ANDROID)
#endif
#if defined(ANDROID)
#include <functional>
#include "Common/AndroidAnalytics.h"
#endif
#include "Common/Analytics.h"
@ -74,11 +75,7 @@ void DolphinAnalytics::ReloadConfig()
std::unique_ptr<Common::AnalyticsReportingBackend> new_backend;
if (Config::Get(Config::MAIN_ANALYTICS_ENABLED))
{
#if defined(ANDROID)
new_backend = std::make_unique<Common::AndroidAnalyticsBackend>(ANALYTICS_ENDPOINT);
#else
new_backend = std::make_unique<Common::HttpAnalyticsBackend>(ANALYTICS_ENDPOINT);
#endif
}
m_reporter.SetBackend(std::move(new_backend));