From a37bd79d5cf0e41e5681cd0effb5914009c8c77a Mon Sep 17 00:00:00 2001 From: irov Date: Fri, 25 Aug 2023 17:44:35 +0300 Subject: [PATCH] wip apple GDPR fix android GDPR --- ...GeneralDataProtectionRegulationPlugin.java | 6 +- ...GeneralDataProtectionRegulationInterface.h | 20 ++++ ...pleGeneralDataProtectionRegulationPlugin.h | 23 +++++ ...leGeneralDataProtectionRegulationPlugin.mm | 93 +++++++++++++++++++ ...lDataProtectionRegulationScriptEmbedding.h | 21 +++++ ...DataProtectionRegulationScriptEmbedding.mm | 65 +++++++++++++ ...leGeneralDataProtectionRegulationService.h | 24 +++++ ...eGeneralDataProtectionRegulationService.mm | 58 ++++++++++++ .../CMakeLists.txt | 27 ++++++ 9 files changed, 334 insertions(+), 3 deletions(-) create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationInterface.h create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.h create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.mm create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.h create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm create mode 100644 src/Plugins/AppleGeneralDataProtectionRegulationPlugin/CMakeLists.txt diff --git a/gradle/plugins/GeneralDataProtectionRegulation/src/main/java/org/Mengine/Plugin/GeneralDataProtectionRegulation/MengineGeneralDataProtectionRegulationPlugin.java b/gradle/plugins/GeneralDataProtectionRegulation/src/main/java/org/Mengine/Plugin/GeneralDataProtectionRegulation/MengineGeneralDataProtectionRegulationPlugin.java index 39d54da42a..1bc7071071 100644 --- a/gradle/plugins/GeneralDataProtectionRegulation/src/main/java/org/Mengine/Plugin/GeneralDataProtectionRegulation/MengineGeneralDataProtectionRegulationPlugin.java +++ b/gradle/plugins/GeneralDataProtectionRegulation/src/main/java/org/Mengine/Plugin/GeneralDataProtectionRegulation/MengineGeneralDataProtectionRegulationPlugin.java @@ -32,14 +32,14 @@ public void onAppPrepare(MengineApplication application) throws MenginePluginInv this.sendEvent(MengineEvent.EVENT_GDPR_PASS, m_passGDPR); } - public void setGDPRPass() { + public void setGDPRPass(boolean passGDPR) { SharedPreferences settings = this.getPrivateSharedPreferences(); SharedPreferences.Editor editor = settings.edit(); - editor.putBoolean("gdpr_pass", true); + editor.putBoolean("gdpr_pass", passGDPR); editor.commit(); - m_passGDPR = true; + m_passGDPR = passGDPR; this.sendEvent(MengineEvent.EVENT_GDPR_PASS, true); } diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationInterface.h b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationInterface.h new file mode 100644 index 0000000000..896c32c44d --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationInterface.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Interface/ServiceInterface.h" + +namespace Mengine +{ + class AppleGeneralDataProtectionRegulationServiceInterface + : public ServiceInterface + { + SERVICE_DECLARE( "AppleGeneralDataProtectionRegulationServiceInterface" ) + + public: + virtual void setGDPRPass( bool _passGDPR ) = 0; + virtual bool isGDPRPass() const = 0; + }; +} +////////////////////////////////////////////////////////////////////////// +#define APPLE_GENERALDATAPROTECTIONREGULATION_SERVICE()\ + ((Mengine::AppleGeneralDataProtectionRegulationServiceInterface *)SERVICE_GET(Mengine::AppleGeneralDataProtectionRegulationServiceInterface)) +////////////////////////////////////////////////////////////////////////// diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.h b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.h new file mode 100644 index 0000000000..b9eb3af44e --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Kernel/PluginBase.h" + +namespace Mengine +{ + class AppleGeneralDataProtectionRegulationPlugin + : public PluginBase + { + PLUGIN_DECLARE( "AppleGeneralDataProtectionRegulation" ) + + public: + AppleGeneralDataProtectionRegulationPlugin(); + ~AppleGeneralDataProtectionRegulationPlugin() override; + + protected: + bool _availablePlugin() const override; + bool _initializePlugin() override; + void _finalizePlugin() override; + void _destroyPlugin() override; + }; +} + diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.mm b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.mm new file mode 100644 index 0000000000..07320fe0c7 --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationPlugin.mm @@ -0,0 +1,93 @@ +#include "AppleGeneralDataProtectionRegulationPlugin.h" + +#ifdef MENGINE_USE_SCRIPT_SERVICE +# include "Interface/ScriptServiceInterface.h" + +# include "AppleGeneralDataProtectionRegulationScriptEmbedding.h" +#endif + +#include "AppleGeneralDataProtectionRegulationInterface.h" + +#include "Kernel/ConfigHelper.h" +#include "Kernel/OptionHelper.h" +#include "Kernel/FactorableUnique.h" +#include "Kernel/NotificationHelper.h" + +////////////////////////////////////////////////////////////////////////// +SERVICE_EXTERN( AppleGeneralDataProtectionRegulationService ); +////////////////////////////////////////////////////////////////////////// +PLUGIN_FACTORY( AppleGeneralDataProtectionRegulation, Mengine::AppleGeneralDataProtectionRegulationPlugin ) +////////////////////////////////////////////////////////////////////////// +namespace Mengine +{ + ////////////////////////////////////////////////////////////////////////// + AppleGeneralDataProtectionRegulationPlugin::AppleGeneralDataProtectionRegulationPlugin() + { + } + ////////////////////////////////////////////////////////////////////////// + AppleGeneralDataProtectionRegulationPlugin::~AppleGeneralDataProtectionRegulationPlugin() + { + } + ////////////////////////////////////////////////////////////////////////// + bool AppleGeneralDataProtectionRegulationPlugin::_availablePlugin() const + { + if( HAS_OPTION( "applegeneraldataprotectionregulation" ) == true ) + { + return true; + } + + if( HAS_OPTION( "noapplegeneraldataprotectionregulation" ) == true ) + { + return false; + } + + bool AppleGeneralDataProtectionRegulationPlugin_Available = CONFIG_VALUE( "AppleGeneralDataProtectionRegulationPlugin", "Available", true ); + + if( AppleGeneralDataProtectionRegulationPlugin_Available == false ) + { + return false; + } + + return true; + } + ////////////////////////////////////////////////////////////////////////// + bool AppleGeneralDataProtectionRegulationPlugin::_initializePlugin() + { + if( SERVICE_CREATE( AppleGeneralDataProtectionRegulationService, MENGINE_DOCUMENT_FACTORABLE ) == false ) + { + return false; + } + +#ifdef MENGINE_USE_SCRIPT_SERVICE + NOTIFICATION_ADDOBSERVERLAMBDA_THIS( NOTIFICATOR_SCRIPT_EMBEDDING, [this]() + { + SCRIPT_SERVICE() + ->addScriptEmbedding( STRINGIZE_STRING_LOCAL( "AppleGeneralDataProtectionRegulationScriptEmbedding" ), Helper::makeFactorableUnique( MENGINE_DOCUMENT_FACTORABLE ) ); + }, MENGINE_DOCUMENT_FACTORABLE ); + + NOTIFICATION_ADDOBSERVERLAMBDA_THIS( NOTIFICATOR_SCRIPT_EJECTING, []() + { + SCRIPT_SERVICE() + ->removeScriptEmbedding( STRINGIZE_STRING_LOCAL( "AppleGeneralDataProtectionRegulationScriptEmbedding" ) ); + }, MENGINE_DOCUMENT_FACTORABLE ); +#endif + + return true; + } + ////////////////////////////////////////////////////////////////////////// + void AppleGeneralDataProtectionRegulationPlugin::_finalizePlugin() + { +#ifdef MENGINE_USE_SCRIPT_SERVICE + NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_SCRIPT_EMBEDDING ); + NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_SCRIPT_EJECTING ); +#endif + + SERVICE_FINALIZE( AppleGeneralDataProtectionRegulationService ); + } + ////////////////////////////////////////////////////////////////////////// + void AppleGeneralDataProtectionRegulationPlugin::_destroyPlugin() + { + SERVICE_DESTROY( AppleGeneralDataProtectionRegulationService ); + } + ////////////////////////////////////////////////////////////////////////// +} diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.h b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.h new file mode 100644 index 0000000000..b121201aed --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Interface/ScriptEmbeddingInterface.h" + +#include "Kernel/Factorable.h" + +namespace Mengine +{ + class AppleGeneralDataProtectionRegulationScriptEmbedding + : public ScriptEmbeddingInterface + , public Factorable + { + public: + AppleGeneralDataProtectionRegulationScriptEmbedding(); + ~AppleGeneralDataProtectionRegulationScriptEmbedding() override; + + public: + bool embed( pybind::kernel_interface * _kernel ) override; + void eject( pybind::kernel_interface * _kernel ) override; + }; +} diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm new file mode 100644 index 0000000000..1c99281412 --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm @@ -0,0 +1,65 @@ +#include "AppleGeneralDataProtectionRegulationScriptEmbedding.h" + +#include "AppleGeneralDataProtectionRegulationInterface.h" + +#include "Interface/ScriptServiceInterface.h" + +#include "Environment/Python/PythonIncluder.h" +#include "Environment/Python/PythonDocumentTraceback.h" + +#include "Kernel/FactorableUnique.h" +#include "Kernel/ConstStringHelper.h" +#include "Kernel/DocumentHelper.h" +#include "Kernel/Logger.h" + +namespace Mengine +{ + namespace Detail + { + ////////////////////////////////////////////////////////////////////////// + static void s_AppleGeneralDataProtectionRegulation_setGDPRPass( bool _passGDPR ) + { + APPLE_GENERALDATAPROTECTIONREGULATION_SERVICE() + ->setGDPRPass( _passGDPR ); + } + ////////////////////////////////////////////////////////////////////////// + static void s_AppleGeneralDataProtectionRegulation_isGDPRPass( bool _passGDPR ) + { + bool passGDPR = APPLE_GENERALDATAPROTECTIONREGULATION_SERVICE() + ->isGDPRPass(); + + return passGDPR; + } + ////////////////////////////////////////////////////////////////////////// + } + ////////////////////////////////////////////////////////////////////////// + AppleGeneralDataProtectionRegulationScriptEmbedding::AppleGeneralDataProtectionRegulationEmbedding() + { + } + ////////////////////////////////////////////////////////////////////////// + AppleGeneralDataProtectionRegulationScriptEmbedding::~AppleGeneralDataProtectionRegulationEmbedding() + { + } + ////////////////////////////////////////////////////////////////////////// + bool AppleGeneralDataProtectionRegulationScriptEmbedding::embed( pybind::kernel_interface * _kernel ) + { + SCRIPT_SERVICE() + ->setAvailablePlugin( "AppleGeneralDataProtectionRegulation", true ); + + pybind::def_function( _kernel, "appleSetGDPRPass", &Detail::s_AppleGeneralDataProtectionRegulation_setGDPRPass ); + pybind::def_function( _kernel, "appleIsGDPRPass", &Detail::s_AppleGeneralDataProtectionRegulation_isGDPRPass ); + + return true; + } + ////////////////////////////////////////////////////////////////////////// + void AppleGeneralDataProtectionRegulationScriptEmbedding::eject( pybind::kernel_interface * _kernel ) + { + SCRIPT_SERVICE() + ->setAvailablePlugin( "AppleGeneralDataProtectionRegulation", false ); + + _kernel->remove_from_module( "appleSetGDPRPass", nullptr ); + _kernel->remove_from_module( "appleIsGDPRPass", nullptr ); + } + ////////////////////////////////////////////////////////////////////////// +} + diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h new file mode 100644 index 0000000000..6e185c5646 --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.h @@ -0,0 +1,24 @@ +#pragma once + +#include "AppleGeneralDataProtectionRegulationInterface.h" + +#include "Kernel/ServiceBase.h" + +namespace Mengine +{ + class AppleGeneralDataProtectionRegulationService + : public ServiceBase + { + public: + AppleGeneralDataProtectionRegulationService(); + ~AppleGeneralDataProtectionRegulationService() override; + + protected: + bool _initializeService() override; + void _finalizeService() override; + + public: + void setGDPRPass( bool _passGDPR ) override; + bool isGDPRPass() const override; + }; +} diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm new file mode 100644 index 0000000000..2dd0ea3596 --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationService.mm @@ -0,0 +1,58 @@ +#include "AppleGeneralDataProtectionRegulationService.h" + +#include "Environment/Apple/AppleUtils.h" + +#include "Kernel/Logger.h" + +#import +#import + +//////////////////////////////////////////////////////////////////////////// +SERVICE_FACTORY( AppleGeneralDataProtectionRegulationService, Mengine::AppleGeneralDataProtectionRegulationService ); +////////////////////////////////////////////////////////////////////////// +namespace Mengine +{ + ////////////////////////////////////////////////////////////////////////// + AppleGeneralDataProtectionRegulationService::AppleGeneralDataProtectionRegulationService() + { + } + ////////////////////////////////////////////////////////////////////////// + AppleGeneralDataProtectionRegulationService::~AppleGeneralDataProtectionRegulationService() + { + } + ///////////////////////////////////////////////////////////////////////////// + bool AppleGeneralDataProtectionRegulationService::_initializeService() + { + //Empty + + return true; + } + //////////////////////////////////////////////////////////////////////// + void AppleGeneralDataProtectionRegulationService::_finalizeService() + { + //Empty + } + ////////////////////////////////////////////////////////////////////////// + void AppleGeneralDataProtectionRegulationService::setGDPRPass( bool _passGDPR ) + { + LOGGER_MESSAGE( "set GDPR pass [%d]" + , _passGDPR + ); + + if (@available(iOS 14.0, *)) { + UIWindowScene * foregroundScene = nil; + for( UIWindowScene * scene in UIApplication.sharedApplication.connectedScenes ) { + if( scene.activationState == UISceneActivationStateForegroundActive ) { + foregroundScene = scene; + } + } + + if( foregroundScene != nil ) { + [SKStoreReviewController requestReviewInScene:foregroundScene]; + } + } else if (@available(iOS 10.3, *)) { + [SKStoreReviewController requestReview]; + } + } + ////////////////////////////////////////////////////////////////////////// +} diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/CMakeLists.txt b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/CMakeLists.txt new file mode 100644 index 0000000000..6dc4687816 --- /dev/null +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/CMakeLists.txt @@ -0,0 +1,27 @@ +MENGINE_PROJECT(AppleGeneralDataProtectionRegulationPlugin) + +ADD_FILTER( +src + AppleGeneralDataProtectionRegulationInterface.h + AppleGeneralDataProtectionRegulationService.h + AppleGeneralDataProtectionRegulationService.mm + + AppleGeneralDataProtectionRegulationPlugin.h + AppleGeneralDataProtectionRegulationPlugin.mm +) + +if(MENGINE_USE_SCRIPT_SERVICE) + ADD_FILTER( + embedding + AppleGeneralDataProtectionRegulationScriptEmbedding.h + AppleGeneralDataProtectionRegulationScriptEmbedding.mm + ) + + INCLUDE_DIRECTORIES(${THIRDPARTY_DIR}/pybind/include) +endif() + +ADD_MENGINE_PLUGIN(MENGINE_PLUGIN_APPLE_GENERALDATAPROTECTIONREGULATION) + +if(MENGINE_USE_SCRIPT_SERVICE) + TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${THIRDPARTY_LIB_DIR}/${MENGINE_LIB_PREFIX}pybind${MENGINE_LIB_SUFFIX}) +endif() \ No newline at end of file