Merge pull request #7350 from zackhow/android-analytics

Android: Add usage statistics to android
This commit is contained in:
Pierre Bourdon 2018-08-27 04:37:17 +02:00 committed by GitHub
commit 246b1f4459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 439 additions and 22 deletions

View File

@ -88,6 +88,9 @@ dependencies {
implementation "com.android.support:leanback-v17:$androidSupportVersion"
implementation "com.android.support:support-tv-provider:$androidSupportVersion"
// For REST calls
implementation 'com.android.volley:volley:1.1.0'
// For showing the banner as a circle a-la Material Design Guidelines
implementation 'de.hdodenhof:circleimageview:2.1.0'

View File

@ -4,6 +4,7 @@ import android.app.Application;
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
import org.dolphinemu.dolphinemu.utils.VolleyUtil;
public class DolphinApplication extends Application
{
@ -12,6 +13,7 @@ public class DolphinApplication extends Application
{
super.onCreate();
VolleyUtil.init(getApplicationContext());
System.loadLibrary("main");
if (PermissionsHandler.hasWriteAccess(getApplicationContext()))

View File

@ -322,7 +322,7 @@ public final class NativeLibrary
/**
* Begins emulation.
*/
public static native void Run(String path);
public static native void Run(String path, boolean firstOpen);
/**
* Begins emulation from the specified savestate.

View File

@ -27,13 +27,15 @@ public class Settings
public static final String SECTION_BINDINGS = "Android";
public static final String SECTION_ANALYTICS = "Analytics";
private String gameId;
private static final Map<String, List<String>> configFileSectionsMap = new HashMap<>();
static
{
configFileSectionsMap.put(SettingsFile.FILE_NAME_DOLPHIN, Arrays.asList(SECTION_INI_CORE, SECTION_INI_INTERFACE, SECTION_BINDINGS));
configFileSectionsMap.put(SettingsFile.FILE_NAME_DOLPHIN, Arrays.asList(SECTION_INI_CORE, SECTION_INI_INTERFACE, SECTION_BINDINGS, SECTION_ANALYTICS));
configFileSectionsMap.put(SettingsFile.FILE_NAME_GFX, Arrays.asList(SECTION_GFX_SETTINGS, SECTION_GFX_ENHANCEMENTS, SECTION_GFX_HACKS, SECTION_STEREOSCOPY));
configFileSectionsMap.put(SettingsFile.FILE_NAME_WIIMOTE, Arrays.asList(SECTION_WIIMOTE + 1, SECTION_WIIMOTE + 2, SECTION_WIIMOTE + 3, SECTION_WIIMOTE + 4));
}

View File

@ -210,14 +210,17 @@ public final class SettingsFragmentPresenter
Setting overclock = null;
Setting speedLimit = null;
Setting audioStretch = null;
Setting analytics = null;
SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE);
SettingSection analyticsSection = mSettings.getSection(Settings.SECTION_ANALYTICS);
cpuCore = coreSection.getSetting(SettingsFile.KEY_CPU_CORE);
dualCore = coreSection.getSetting(SettingsFile.KEY_DUAL_CORE);
overclockEnable = coreSection.getSetting(SettingsFile.KEY_OVERCLOCK_ENABLE);
overclock = coreSection.getSetting(SettingsFile.KEY_OVERCLOCK_PERCENT);
speedLimit = coreSection.getSetting(SettingsFile.KEY_SPEED_LIMIT);
audioStretch = coreSection.getSetting(SettingsFile.KEY_AUDIO_STRETCH);
analytics = analyticsSection.getSetting(SettingsFile.KEY_ANALYTICS_ENABLED);
// TODO: Having different emuCoresEntries/emuCoresValues for each architecture is annoying.
// The proper solution would be to have one emuCoresEntries and one emuCoresValues
@ -246,6 +249,7 @@ public final class SettingsFragmentPresenter
sl.add(new SliderSetting(SettingsFile.KEY_OVERCLOCK_PERCENT, Settings.SECTION_INI_CORE, R.string.overclock_title, R.string.overclock_title_description, 400, "%", 100, overclock));
sl.add(new SliderSetting(SettingsFile.KEY_SPEED_LIMIT, Settings.SECTION_INI_CORE, R.string.speed_limit, 0, 200, "%", 100, speedLimit));
sl.add(new CheckBoxSetting(SettingsFile.KEY_AUDIO_STRETCH, Settings.SECTION_INI_CORE, R.string.audio_stretch, R.string.audio_stretch_description, false, audioStretch));
sl.add(new CheckBoxSetting(SettingsFile.KEY_ANALYTICS_ENABLED, Settings.SECTION_ANALYTICS, R.string.analytics, 0, false, analytics));
}
private void addInterfaceSettings(ArrayList<SettingsItem> sl)

View File

@ -50,6 +50,9 @@ public final class SettingsFile
public static final String KEY_SLOT_A_DEVICE = "SlotA";
public static final String KEY_SLOT_B_DEVICE = "SlotB";
public static final String KEY_ANALYTICS_ENABLED = "Enabled";
public static final String KEY_ANALYTICS_PERMISSION_ASKED = "PermissionAsked";
public static final String KEY_USE_PANIC_HANDLERS = "UsePanicHandlers";
public static final String KEY_OSD_MESSAGES = "OnScreenDisplayMessages";
@ -294,12 +297,14 @@ public final class SettingsFile
catch (FileNotFoundException e)
{
Log.error("[SettingsFile] File not found: " + ini.getAbsolutePath() + e.getMessage());
view.onSettingsFileNotFound();
if (view != null)
view.onSettingsFileNotFound();
}
catch (IOException e)
{
Log.error("[SettingsFile] Error reading from: " + ini.getAbsolutePath()+ e.getMessage());
view.onSettingsFileNotFound();
if (view != null)
view.onSettingsFileNotFound();
}
finally
{
@ -384,12 +389,14 @@ public final class SettingsFile
catch (FileNotFoundException e)
{
Log.error("[SettingsFile] File not found: " + fileName + ".ini: " + e.getMessage());
view.showToastMessage("Error saving " + fileName + ".ini: " + e.getMessage());
if (view != null)
view.showToastMessage("Error saving " + fileName + ".ini: " + e.getMessage());
}
catch (UnsupportedEncodingException e)
{
Log.error("[SettingsFile] Bad encoding; please file a bug report: " + fileName + ".ini: " + e.getMessage());
view.showToastMessage("Error saving " + fileName + ".ini: " + e.getMessage());
if (view != null)
view.showToastMessage("Error saving " + fileName + ".ini: " + e.getMessage());
}
finally
{
@ -490,6 +497,23 @@ public final class SettingsFile
sections.put(Settings.SECTION_INI_CORE, coreSection);
}
public static void firstAnalyticsAdd(boolean enabled)
{
HashMap<String, SettingSection> dolphinSections = readFile(SettingsFile.FILE_NAME_DOLPHIN, null);
SettingSection analyticsSection = dolphinSections.get(Settings.SECTION_ANALYTICS);
Setting analyticsEnabled = new StringSetting(KEY_ANALYTICS_ENABLED, Settings.SECTION_ANALYTICS, enabled ? "True" : "False");
Setting analyticsFirstAsk = new StringSetting(KEY_ANALYTICS_PERMISSION_ASKED, Settings.SECTION_ANALYTICS, "True");
analyticsSection.putSetting(analyticsFirstAsk);
analyticsSection.putSetting(analyticsEnabled);
dolphinSections.put(Settings.SECTION_ANALYTICS, analyticsSection);
TreeMap<String, SettingSection> saveSection = new TreeMap<>(dolphinSections);
saveFile(SettingsFile.FILE_NAME_DOLPHIN, saveSection, null);
}
/**
* For a line of text, determines what type of data is being represented, and returns
* a Setting object containing this data.

View File

@ -24,11 +24,10 @@ import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService.DirectoryInitializationState;
import org.dolphinemu.dolphinemu.utils.DirectoryStateReceiver;
import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.StartupHandler;
import java.io.File;
import rx.functions.Action1;
public final class EmulationFragment extends Fragment implements SurfaceHolder.Callback
{
private static final String KEY_GAMEPATH = "gamepath";
@ -84,7 +83,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
String gamePath = getArguments().getString(KEY_GAMEPATH);
mEmulationState = new EmulationState(gamePath, getTemporaryStateFilePath());
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
boolean firstOpen = preferences.getBoolean(StartupHandler.NEW_SESSION, true);
SharedPreferences.Editor sPrefsEditor = preferences.edit();
sPrefsEditor.putBoolean(StartupHandler.NEW_SESSION, false);
sPrefsEditor.apply();
mEmulationState = new EmulationState(gamePath, getTemporaryStateFilePath(), firstOpen);
}
/**
@ -264,10 +268,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
private Surface mSurface;
private boolean mRunWhenSurfaceIsValid;
private boolean loadPreviousTemporaryState;
private boolean firstOpen;
private final String temporaryStatePath;
EmulationState(String gamePath, String temporaryStatePath)
EmulationState(String gamePath, String temporaryStatePath, boolean firstOpen)
{
this.firstOpen = firstOpen;
mGamePath = gamePath;
this.temporaryStatePath = temporaryStatePath;
// Starting state is stopped.
@ -411,7 +417,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
else
{
Log.debug("[EmulationFragment] Starting emulation thread.");
NativeLibrary.Run(mGamePath);
NativeLibrary.Run(mGamePath, firstOpen);
}
}, "NativeEmulation");
mEmulationThread.start();

View File

@ -89,6 +89,20 @@ public final class MainActivity extends AppCompatActivity implements MainView
mPresenter.onDestroy();
}
@Override
protected void onStart()
{
super.onStart();
StartupHandler.checkSessionReset(this);
}
@Override
protected void onStop()
{
super.onStop();
StartupHandler.setSessionTime(this);
}
// TODO: Replace with a ButterKnife injection.
private void findViews()
{

View File

@ -74,6 +74,20 @@ public final class TvMainActivity extends FragmentActivity implements MainView
mPresenter.onDestroy();
}
@Override
protected void onStart()
{
super.onStart();
StartupHandler.checkSessionReset(this);
}
@Override
protected void onStop()
{
super.onStop();
StartupHandler.setSessionTime(this);
}
void setupUI() {
final FragmentManager fragmentManager = getSupportFragmentManager();
mBrowseFragment = new BrowseSupportFragment();

View File

@ -0,0 +1,125 @@
package org.dolphinemu.dolphinemu.utils;
import android.app.AlertDialog;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import com.android.volley.Request;
import com.android.volley.toolbox.StringRequest;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
public class Analytics
{
private static DirectoryStateReceiver directoryStateReceiver;
private static final String analyticsAsked = Settings.SECTION_ANALYTICS + "_" + SettingsFile.KEY_ANALYTICS_PERMISSION_ASKED;
private static final String analyticsEnabled = Settings.SECTION_ANALYTICS + "_" + SettingsFile.KEY_ANALYTICS_ENABLED;
private static final String DEVICE_MANUFACTURER = "DEVICE_MANUFACTURER";
private static final String DEVICE_OS = "DEVICE_OS";
private static final String DEVICE_MODEL = "DEVICE_MODEL";
private static final String DEVICE_TYPE = "DEVICE_TYPE";
private static String deviceType;
public static void checkAnalyticsInit(Context context)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (!preferences.getBoolean(analyticsAsked, false))
{
if (!DirectoryInitializationService.areDolphinDirectoriesReady())
{
// Wait for directories to get initialized
IntentFilter statusIntentFilter = new IntentFilter(
DirectoryInitializationService.BROADCAST_ACTION);
directoryStateReceiver = new DirectoryStateReceiver(directoryInitializationState ->
{
if (directoryInitializationState == DirectoryInitializationService.DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED)
{
LocalBroadcastManager.getInstance(context).unregisterReceiver(directoryStateReceiver);
directoryStateReceiver = null;
showMessage(context, preferences);
}
});
// Registers the DirectoryStateReceiver and its intent filters
LocalBroadcastManager.getInstance(context).registerReceiver(
directoryStateReceiver,
statusIntentFilter);
}
else
{
showMessage(context, preferences);
}
}
// Get device type now since we have a context
deviceType = TvUtil.isLeanback(context) ? "android-tv" : "android-mobile";
}
private static void showMessage(Context context, SharedPreferences preferences)
{
// We asked, set to true regardless of answer
SharedPreferences.Editor sPrefsEditor = preferences.edit();
sPrefsEditor.putBoolean(analyticsAsked, true);
sPrefsEditor.apply();
new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.analytics))
.setMessage(context.getString(R.string.analytics_desc))
.setPositiveButton(R.string.yes, (dialogInterface, i) ->
{
sPrefsEditor.putBoolean(analyticsEnabled, true);
sPrefsEditor.apply();
SettingsFile.firstAnalyticsAdd(true);
})
.setNegativeButton(R.string.no, (dialogInterface, i) ->
{
sPrefsEditor.putBoolean(analyticsEnabled, false);
sPrefsEditor.apply();
SettingsFile.firstAnalyticsAdd(false);
})
.create()
.show();
}
public static void sendReport(String endpoint, byte[] data)
{
StringRequest request = new StringRequest(Request.Method.POST, endpoint,
null, error -> Log.debug("Send Report Failure code: "
+ error.networkResponse.statusCode))
{
@Override
public byte[] getBody()
{
return data;
}
};
VolleyUtil.getQueue().add(request);
}
public static String getValue(String key)
{
switch (key)
{
case DEVICE_MODEL:
return Build.MODEL;
case DEVICE_MANUFACTURER:
return Build.MANUFACTURER;
case DEVICE_OS:
return String.valueOf(Build.VERSION.SDK_INT);
case DEVICE_TYPE:
return deviceType;
default:
return "";
}
}
}

View File

@ -1,19 +1,31 @@
package org.dolphinemu.dolphinemu.utils;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
import java.util.Date;
public final class StartupHandler
{
public static final String NEW_SESSION = "NEW_SESSION";
public static final String LAST_CLOSED = "LAST_CLOSED";
public static final Long SESSION_TIMEOUT = 21600000L; // 6 hours in milliseconds
public static void HandleInit(FragmentActivity parent)
{
// Ask the user to grant write permission if it's not already granted
PermissionsHandler.checkWritePermission(parent);
// Ask the user if he wants to enable analytics if we haven't yet.
Analytics.checkAnalyticsInit(parent);
String start_file = "";
Bundle extras = parent.getIntent().getExtras();
if (extras != null)
@ -30,4 +42,33 @@ public final class StartupHandler
parent.finish();
}
}
/**
* There isn't a good way to determine a new session. setSessionTime is called if the main
* activity goes into the background.
*/
public static void setSessionTime(Context context)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor sPrefsEditor = preferences.edit();
sPrefsEditor.putLong(LAST_CLOSED, new Date(System.currentTimeMillis()).getTime());
sPrefsEditor.apply();
}
/**
* Called to determine if we treat this activity start as a new session.
*/
public static void checkSessionReset(Context context)
{
Long currentTime = new Date(System.currentTimeMillis()).getTime();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Long lastOpen = preferences.getLong(LAST_CLOSED, 0);
if (currentTime > (lastOpen + SESSION_TIMEOUT))
{
// Passed at emulation start to trigger first open event.
SharedPreferences.Editor sPrefsEditor = preferences.edit();
sPrefsEditor.putBoolean(NEW_SESSION, true);
sPrefsEditor.apply();
}
}
}

View File

@ -0,0 +1,22 @@
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

@ -135,6 +135,8 @@
<string name="wiimote_speaker_description">Enable sound output through the speaker on a real Wiimote (DolphinBar required).</string>
<string name="audio_stretch">Audio Stretching</string>
<string name="audio_stretch_description">Stretches audio to reduce stuttering. Increases latency.</string>
<string name="analytics">Enable usage statistics reporting</string>
<string name="analytics_desc">If authorized, Dolphin can collect data on its performance, feature usage, and configuration, as well as data on your system\'s hardware and operating system.\n\nNo private data is ever collected. This data helps us understand how people and emulated games use Dolphin and prioritize our efforts. It also helps us identify rare configurations that are causing bugs, performance and stability issues. This authorization can be revoked at any time through Dolphin\'s settings.</string>
<string name="gametdb_thanks">Thanks to GameTDB.com for providing GameCube and Wii covers!</string>
<!-- Interface Preference Fragment -->

View File

@ -20,6 +20,10 @@ static jmethodID s_game_file_constructor;
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;
namespace IDCache
{
JavaVM* GetJavaVM()
@ -37,6 +41,20 @@ jmethodID GetDisplayAlertMsg()
return s_display_alert_msg;
}
jclass GetAnalyticsClass()
{
return s_analytics_class;
}
jmethodID GetSendAnalyticsReport()
{
return s_send_analytics_report;
}
jmethodID GetAnalyticsValue()
{
return s_get_analytics_value;
}
jclass GetGameFileClass()
{
return s_game_file_class;
@ -91,6 +109,13 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
s_game_file_cache_class = reinterpret_cast<jclass>(env->NewGlobalRef(game_file_cache_class));
s_game_file_cache_pointer = env->GetFieldID(game_file_cache_class, "mPointer", "J");
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;");
return JNI_VERSION;
}
@ -103,6 +128,7 @@ void JNI_OnUnload(JavaVM* vm, void* reserved)
env->DeleteGlobalRef(s_native_library_class);
env->DeleteGlobalRef(s_game_file_class);
env->DeleteGlobalRef(s_game_file_cache_class);
env->DeleteGlobalRef(s_analytics_class);
}
#ifdef __cplusplus

View File

@ -8,11 +8,17 @@
namespace IDCache
{
static constexpr jint JNI_VERSION = JNI_VERSION_1_6;
JavaVM* GetJavaVM();
jclass GetNativeLibraryClass();
jmethodID GetDisplayAlertMsg();
jclass GetAnalyticsClass();
jmethodID GetSendAnalyticsReport();
jmethodID GetAnalyticsValue();
jclass GetGameFileClass();
jfieldID GetGameFilePointer();
jmethodID GetGameFileConstructor();

View File

@ -16,6 +16,7 @@
#include <thread>
#include <utility>
#include "Common/AndroidAnalytics.h"
#include "Common/CPUDetect.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
@ -26,6 +27,7 @@
#include "Common/MsgHandler.h"
#include "Common/Version.h"
#include "Core/Analytics.h"
#include "Core/Boot/Boot.h"
#include "Core/BootManager.h"
#include "Core/ConfigLoaders/GameConfigLoader.h"
@ -156,6 +158,47 @@ static bool MsgAlert(const char* caption, const char* text, bool yes_no, MsgType
return result != JNI_FALSE;
}
static void ReportSend(std::string endpoint, std::string report)
{
// Associate the current Thread with the Java VM.
JNIEnv* env;
IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr);
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);
env->CallStaticVoidMethod(IDCache::GetAnalyticsClass(), IDCache::GetSendAnalyticsReport(),
ToJString(env, endpoint), output_array);
IDCache::GetJavaVM()->DetachCurrentThread();
}
static std::string GetAnalyticValue(std::string key)
{
// Associate the current Thread with the Java VM.
JNIEnv* env;
bool attached = false;
int getEnvStat =
IDCache::GetJavaVM()->GetEnv(reinterpret_cast<void**>(&env), IDCache::JNI_VERSION);
if (getEnvStat == JNI_EDETACHED)
{
IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr);
attached = true;
}
jstring value = reinterpret_cast<jstring>(env->CallStaticObjectMethod(
IDCache::GetAnalyticsClass(), IDCache::GetAnalyticsValue(), ToJString(env, key)));
std::string stdvalue = GetJString(env, value);
// Only detach the thread if it wasn't already attached
if (attached)
IDCache::GetJavaVM()->DetachCurrentThread();
return stdvalue;
}
#ifdef __cplusplus
extern "C" {
#endif
@ -216,8 +259,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling
jboolean enable);
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
JNIEnv* env, jobject obj, jstring jFile);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Z(
JNIEnv* env, jobject obj, jstring jFile, jboolean jfirstOpen);
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate);
@ -500,8 +543,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimo
WiimoteReal::Refresh();
}
static void Run(const std::string& path, std::optional<std::string> savestate_path = {},
bool delete_savestate = false)
static void Run(const std::string& path, bool first_open,
std::optional<std::string> savestate_path = {}, bool delete_savestate = false)
{
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", path.c_str());
@ -510,10 +553,17 @@ static void Run(const std::string& path, std::optional<std::string> savestate_pa
OSD::AddCallback(OSD::CallbackType::Shutdown, ButtonManager::Shutdown);
RegisterMsgAlertHandler(&MsgAlert);
Common::AndroidSetReportHandler(&ReportSend);
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
std::unique_lock<std::mutex> guard(s_host_identity_lock);
UICommon::Init();
if (first_open)
{
DolphinAnalytics::Instance()->ReportDolphinStart(GetAnalyticValue("DEVICE_TYPE"));
}
WiimoteReal::InitAdapterClass();
// No use running the loop when booting fails
@ -551,17 +601,17 @@ static void Run(const std::string& path, std::optional<std::string> savestate_pa
}
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
JNIEnv* env, jobject obj, jstring jFile)
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Z(
JNIEnv* env, jobject obj, jstring jFile, jboolean jfirstOpen)
{
Run(GetJString(env, jFile));
Run(GetJString(env, jFile), jfirstOpen);
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate)
{
Run(GetJString(env, jFile), GetJString(env, jSavestate), jDeleteSavestate);
Run(GetJString(env, jFile), false, GetJString(env, jSavestate), jDeleteSavestate);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,

View File

@ -190,5 +190,4 @@ void HttpAnalyticsBackend::Send(std::string report)
if (m_http.IsValid())
m_http.Post(m_endpoint, report);
}
} // namespace Common

View File

@ -183,5 +183,4 @@ protected:
std::string m_endpoint;
HttpRequest m_http{std::chrono::seconds{5}};
};
} // namespace Common

View File

@ -0,0 +1,27 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <functional>
#include <string>
#include "Common/AndroidAnalytics.h"
namespace Common
{
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

@ -0,0 +1,26 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#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

@ -71,6 +71,7 @@ endif()
if(ANDROID)
target_sources(common PRIVATE
AndroidAnalytics.cpp
Logging/ConsoleListenerDroid.cpp
)
elseif(WIN32)

View File

@ -10,6 +10,9 @@
#include <windows.h>
#elif defined(__APPLE__)
#include <CoreServices/CoreServices.h>
#elif defined(ANDROID)
#include <functional>
#include "Common/AndroidAnalytics.h"
#endif
#include "Common/Analytics.h"
@ -35,6 +38,14 @@ constexpr const char* ANALYTICS_ENDPOINT = "https://analytics.dolphin-emu.org/re
std::mutex DolphinAnalytics::s_instance_mutex;
std::shared_ptr<DolphinAnalytics> DolphinAnalytics::s_instance;
#if defined(ANDROID)
static std::function<std::string(std::string)> s_get_val_func;
void DolphinAnalytics::AndroidSetGetValFunc(std::function<std::string(std::string)> func)
{
s_get_val_func = std::move(func);
}
#endif
DolphinAnalytics::DolphinAnalytics()
{
ReloadConfig();
@ -59,7 +70,11 @@ void DolphinAnalytics::ReloadConfig()
std::unique_ptr<Common::AnalyticsReportingBackend> new_backend;
if (SConfig::GetInstance().m_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));
@ -152,6 +167,9 @@ void DolphinAnalytics::MakeBaseBuilder()
}
#elif defined(ANDROID)
builder.AddData("os-type", "android");
builder.AddData("android-manufacturer", s_get_val_func("DEVICE_MANUFACTURER"));
builder.AddData("android-model", s_get_val_func("DEVICE_MODEL"));
builder.AddData("android-version", s_get_val_func("DEVICE_OS"));
#elif defined(__APPLE__)
builder.AddData("os-type", "osx");

View File

@ -10,6 +10,9 @@
#include "Common/Analytics.h"
#if defined(ANDROID)
#include <functional>
#endif
// Non generic part of the Dolphin Analytics framework. See Common/Analytics.h
// for the main documentation.
@ -19,10 +22,13 @@ public:
// Performs lazy-initialization of a singleton and returns the instance.
static std::shared_ptr<DolphinAnalytics> Instance();
#if defined(ANDROID)
// Get value from java.
static void AndroidSetGetValFunc(std::function<std::string(std::string)> function);
#endif
// Resets and recreates the analytics system in order to reload
// configuration.
void ReloadConfig();
// Rotates the unique identifier used for this instance of Dolphin and saves
// it into the configuration.
void GenerateNewIdentity();