diff options
| author | zackhow <zackhow@gmail.com> | 2018-08-19 17:38:29 -0400 |
|---|---|---|
| committer | zackhow <zackhow@gmail.com> | 2018-08-23 17:31:17 -0400 |
| commit | 82f82a6b7d727ff3dcc8b4e5a4d7fc9a214a8596 (patch) | |
| tree | ba0620e78bd04bd0a74557ac4f43ef81ed9b5f29 /Source/Core | |
| parent | 8e5c3d5b4eff43b9e830831efc91dccf77f00b66 (diff) | |
Android: Add usage statistics to android.
Added an option in General config to enable/disable usage statistics. Added a popup on first open if
the user would like to engage in reporting. Clicking cancel or out of the box opts out. Only
clicking 'Ok' will enable reporting. Also added a new android specific values to report.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Common/Analytics.cpp | 1 | ||||
| -rw-r--r-- | Source/Core/Common/Analytics.h | 1 | ||||
| -rw-r--r-- | Source/Core/Common/AndroidAnalytics.cpp | 27 | ||||
| -rw-r--r-- | Source/Core/Common/AndroidAnalytics.h | 26 | ||||
| -rw-r--r-- | Source/Core/Common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | Source/Core/Core/Analytics.cpp | 18 | ||||
| -rw-r--r-- | Source/Core/Core/Analytics.h | 8 |
7 files changed, 79 insertions, 3 deletions
diff --git a/Source/Core/Common/Analytics.cpp b/Source/Core/Common/Analytics.cpp index 57670fd1e7..ab25cecabd 100644 --- a/Source/Core/Common/Analytics.cpp +++ b/Source/Core/Common/Analytics.cpp @@ -190,5 +190,4 @@ void HttpAnalyticsBackend::Send(std::string report) if (m_http.IsValid()) m_http.Post(m_endpoint, report); } - } // namespace Common diff --git a/Source/Core/Common/Analytics.h b/Source/Core/Common/Analytics.h index 6015d1d6f3..4516334ae5 100644 --- a/Source/Core/Common/Analytics.h +++ b/Source/Core/Common/Analytics.h @@ -183,5 +183,4 @@ protected: std::string m_endpoint; HttpRequest m_http{std::chrono::seconds{5}}; }; - } // namespace Common diff --git a/Source/Core/Common/AndroidAnalytics.cpp b/Source/Core/Common/AndroidAnalytics.cpp new file mode 100644 index 0000000000..43912e5b1b --- /dev/null +++ b/Source/Core/Common/AndroidAnalytics.cpp @@ -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 diff --git a/Source/Core/Common/AndroidAnalytics.h b/Source/Core/Common/AndroidAnalytics.h new file mode 100644 index 0000000000..b96d67cb19 --- /dev/null +++ b/Source/Core/Common/AndroidAnalytics.h @@ -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 diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index d7327a2a47..507e08662e 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -71,6 +71,7 @@ endif() if(ANDROID) target_sources(common PRIVATE + AndroidAnalytics.cpp Logging/ConsoleListenerDroid.cpp ) elseif(WIN32) diff --git a/Source/Core/Core/Analytics.cpp b/Source/Core/Core/Analytics.cpp index e6fdc9309a..43c703a64d 100644 --- a/Source/Core/Core/Analytics.cpp +++ b/Source/Core/Core/Analytics.cpp @@ -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"); diff --git a/Source/Core/Core/Analytics.h b/Source/Core/Core/Analytics.h index d1900d4ae9..8c2415b92d 100644 --- a/Source/Core/Core/Analytics.h +++ b/Source/Core/Core/Analytics.h @@ -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(); |
