Skip to content

Commit

Permalink
wip apple GDPR
Browse files Browse the repository at this point in the history
fix android GDPR
  • Loading branch information
irov committed Aug 25, 2023
1 parent a17d2f0 commit a37bd79
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
//////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
@@ -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;
};
}

Original file line number Diff line number Diff line change
@@ -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<AppleGeneralDataProtectionRegulationScriptEmbedding>( 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 );
}
//////////////////////////////////////////////////////////////////////////
}
Original file line number Diff line number Diff line change
@@ -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;
};
}
Original file line number Diff line number Diff line change
@@ -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 );
}
//////////////////////////////////////////////////////////////////////////
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "AppleGeneralDataProtectionRegulationInterface.h"

#include "Kernel/ServiceBase.h"

namespace Mengine
{
class AppleGeneralDataProtectionRegulationService
: public ServiceBase<AppleGeneralDataProtectionRegulationServiceInterface>
{
public:
AppleGeneralDataProtectionRegulationService();
~AppleGeneralDataProtectionRegulationService() override;

protected:
bool _initializeService() override;
void _finalizeService() override;

public:
void setGDPRPass( bool _passGDPR ) override;
bool isGDPRPass() const override;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "AppleGeneralDataProtectionRegulationService.h"

#include "Environment/Apple/AppleUtils.h"

#include "Kernel/Logger.h"

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>

////////////////////////////////////////////////////////////////////////////
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];
}
}
//////////////////////////////////////////////////////////////////////////
}
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a37bd79

Please sign in to comment.