Skip to content

Commit

Permalink
improve android use sessionId
Browse files Browse the repository at this point in the history
update android version 6.28.0
  • Loading branch information
irov committed Aug 22, 2023
1 parent 33aa03b commit 07a1a76
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ public void pythonCall(String plugin, String method, Object ... args) {
return;
}

if (BuildConfig.DEBUG) {
if (BuildConfig.DEBUG == true) {
MengineLog.logInfo(TAG, "pythonCall plugin [%s] method [%s] args [%s]"
, plugin
, method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,51 +441,35 @@ protected boolean createPlugin(String type) {
m_plugins.add(plugin);
m_dictionaryPlugins.put(name, plugin);

if (plugin instanceof MenginePluginAnalyticsListener) {
MenginePluginAnalyticsListener listener = (MenginePluginAnalyticsListener)plugin;

if (plugin instanceof MenginePluginAnalyticsListener listener) {
m_analyticsListeners.add(listener);
}

if (plugin instanceof MenginePluginLoggerListener) {
MenginePluginLoggerListener listener = (MenginePluginLoggerListener)plugin;

if (plugin instanceof MenginePluginLoggerListener listener) {
m_loggerListeners.add(listener);
}

if (plugin instanceof MenginePluginActivityLifecycleListener) {
MenginePluginActivityLifecycleListener listener = (MenginePluginActivityLifecycleListener)plugin;

if (plugin instanceof MenginePluginActivityLifecycleListener listener) {
m_activityLifecycleListeners.add(listener);
}

if (plugin instanceof MenginePluginKeyListener) {
MenginePluginKeyListener listener = (MenginePluginKeyListener)plugin;

if (plugin instanceof MenginePluginKeyListener listener) {
m_keyListeners.add(listener);
}

if (plugin instanceof MenginePluginApplicationListener) {
MenginePluginApplicationListener listener = (MenginePluginApplicationListener)plugin;

if (plugin instanceof MenginePluginApplicationListener listener) {
m_applicationListeners.add(listener);
}

if (plugin instanceof MenginePluginActivityListener) {
MenginePluginActivityListener listener = (MenginePluginActivityListener)plugin;

if (plugin instanceof MenginePluginActivityListener listener) {
m_activityListeners.add(listener);
}

if (plugin instanceof MenginePluginExtensionListener) {
MenginePluginExtensionListener listener = (MenginePluginExtensionListener)plugin;

if (plugin instanceof MenginePluginExtensionListener listener) {
m_extensionListeners.add(listener);
}

if (plugin instanceof MenginePluginEngineListener) {
MenginePluginEngineListener listener = (MenginePluginEngineListener)plugin;

if (plugin instanceof MenginePluginEngineListener listener) {
m_engineListeners.add(listener);
}

Expand Down Expand Up @@ -708,6 +692,7 @@ public void onCreate() {
m_installKey = installKey;
m_installTimestamp = installTimestamp;
m_installDate = installDate;
m_installVersion = installVersion;
m_installRND = installRND;
m_sessionIndex = sessionIndex;
m_sessionId = sessionId;
Expand Down Expand Up @@ -750,9 +735,7 @@ public void onCreate() {

this.setState("application.init", "plugins_prepare");

if (m_sessionId.isEmpty() == false) {
this.sendEvent(MengineEvent.EVENT_SESSION_ID, m_sessionId);
}
this.sendEvent(MengineEvent.EVENT_SESSION_ID, m_sessionId);

long app_init_start_timestamp = MengineAnalytics.buildEvent("mng_app_init_start")
.log();
Expand All @@ -775,6 +758,7 @@ public void onCreate() {
.log();
} catch (MenginePluginInvalidInitializeException e) {
this.invalidInitialize("invalid plugin %s callback onAppCreate exception: %s"
, l.getPluginName()
, e.getPluginName()
);
}
Expand Down Expand Up @@ -834,7 +818,7 @@ public void attachBaseContext(Context base) {
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);

MengineLog.logInfo(TAG, "onConfigurationChanged config: %s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@
import android.os.Bundle;

public interface MenginePluginActivityLifecycleListener extends MenginePluginInterface {
void onMengineActivityLifecycleResumed(Activity activity);
void onMengineActivityLifecyclePaused(Activity activity);
void onMengineActivityLifecycleStarted(Activity activity);
void onMengineActivityLifecycleStopped(Activity activity);
void onMengineActivityLifecycleDestroyed(Activity activity);
void onMengineActivityLifecycleCreated(Activity activity, Bundle bundle);
void onMengineActivityLifecycleSaveInstanceState(Activity activity, Bundle bundle);
default void onMengineActivityLifecycleResumed(Activity activity) {
//Empty
}

default void onMengineActivityLifecyclePaused(Activity activity) {
//Empty
}

default void onMengineActivityLifecycleStarted(Activity activity) {
//Empty
}

default void onMengineActivityLifecycleStopped(Activity activity) {
//Empty
}

default void onMengineActivityLifecycleDestroyed(Activity activity) {
//Empty
}

default void onMengineActivityLifecycleCreated(Activity activity, Bundle bundle) {
//Empty
}

default void onMengineActivityLifecycleSaveInstanceState(Activity activity, Bundle bundle) {
//Empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import android.content.Context;
import android.content.res.Configuration;

import androidx.annotation.NonNull;

public interface MenginePluginApplicationListener extends MenginePluginInterface {
default void onAppPrepare(MengineApplication application) throws MenginePluginInvalidInitializeException {
//Empty
}

void onAppCreate(MengineApplication application) throws MenginePluginInvalidInitializeException;
default void onAppCreate(MengineApplication application) throws MenginePluginInvalidInitializeException {
//Empty
}

default void onAppTerminate(MengineApplication application) {
//Empty
Expand All @@ -18,7 +22,7 @@ default void onAppAttachBaseContext(MengineApplication application, Context base
//Empty
}

default void onAppConfigurationChanged(MengineApplication application, Configuration newConfig) {
default void onAppConfigurationChanged(MengineApplication application, @NonNull Configuration newConfig) {
//Empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public boolean onPluginExtensionInitialize(MengineApplication application, Mengi
}

public void onPluginExtensionFinalize(MengineActivity activity, MenginePlugin plugin) {
m_application = null;
m_activity = null;
m_plugin = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onAppCreate(MengineApplication application) throws MenginePluginInva

AdjustConfig config = new AdjustConfig(application, MengineAdjustPlugin_AppToken, environment);

if (BuildConfig.DEBUG) {
if (BuildConfig.DEBUG == true) {
config.setLogLevel(LogLevel.VERBOSE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws

appLovinSdk.setMediationProvider("max");

MengineApplication application = activity.getMengineApplication();
String sessionId = application.getSessionId();

appLovinSdk.setUserIdentifier(sessionId);

boolean MengineAppLovinPlugin_IsAgeRestrictedUser = activity.getMetaDataBoolean(PLUGIN_METADATA_IS_AGE_RESTRICTED_USER, true);

this.logMessage("%s: %b"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.Mengine.Plugin.DataDog;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

Expand All @@ -12,15 +13,17 @@

import org.Mengine.Base.MengineActivity;
import org.Mengine.Base.MengineApplication;
import org.Mengine.Base.MengineEvent;
import org.Mengine.Base.MengineLog;
import org.Mengine.Base.MenginePlugin;
import org.Mengine.Base.MenginePluginActivityListener;
import org.Mengine.Base.MenginePluginApplicationListener;
import org.Mengine.Base.MenginePluginInvalidInitializeException;
import org.Mengine.Base.MenginePluginLoggerListener;

import java.util.Map;

public class MengineDataDogPlugin extends MenginePlugin implements MenginePluginLoggerListener, MenginePluginActivityListener {
public class MengineDataDogPlugin extends MenginePlugin implements MenginePluginLoggerListener, MenginePluginApplicationListener, MenginePluginActivityListener {
public static final String PLUGIN_NAME = "DevToDev";
public static final boolean PLUGIN_EMBEDDING = true;

Expand All @@ -31,8 +34,17 @@ public class MengineDataDogPlugin extends MenginePlugin implements MenginePlugin
private Logger m_loggerDataDog;

@Override
public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException {
String MengineDataDogPlugin_Site = activity.getMetaDataString(PLUGIN_METADATA_SITE);
public void onEvent(MengineApplication application, MengineEvent event, Object ... args) {
if (event == MengineEvent.EVENT_SESSION_ID) {
String sessionId = (String)args[0];

m_loggerDataDog.addAttribute("session_id", sessionId);
}
}

@Override
public void onAppPrepare(MengineApplication application) throws MenginePluginInvalidInitializeException {
String MengineDataDogPlugin_Site = application.getMetaDataString(PLUGIN_METADATA_SITE);

if (MengineDataDogPlugin_Site == null) {
this.invalidInitialize("initialize unsetup [%s]", PLUGIN_METADATA_SITE);
Expand Down Expand Up @@ -65,7 +77,7 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws
return;
}

String MengineDataDogPlugin_ClientToken = activity.getMetaDataString(PLUGIN_METADATA_CLIENT_TOKEN);
String MengineDataDogPlugin_ClientToken = application.getMetaDataString(PLUGIN_METADATA_CLIENT_TOKEN);

if (MengineDataDogPlugin_ClientToken == null) {
this.invalidInitialize("initialize unsetup [%s]", PLUGIN_METADATA_CLIENT_TOKEN);
Expand All @@ -87,7 +99,7 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws
.useSite(site)
.build();

String MengineDataDogPlugin_ServiceName = activity.getMetaDataString(PLUGIN_METADATA_SERVICE_NAME);
String MengineDataDogPlugin_ServiceName = application.getMetaDataString(PLUGIN_METADATA_SERVICE_NAME);

this.logInfo("%s: %s"
, PLUGIN_METADATA_SERVICE_NAME
Expand All @@ -102,7 +114,9 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws

Credentials credentials = new Credentials(clientToken, envName, variant, rumApplicationId, serviceName);

Datadog.initialize(activity, credentials, config, TrackingConsent.GRANTED);
Context context = application.getApplicationContext();

Datadog.initialize(context, credentials, config, TrackingConsent.GRANTED);

if (BuildConfig.DEBUG == true) {
Datadog.setVerbosity(Log.VERBOSE);
Expand All @@ -115,14 +129,9 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws
.setLoggerName("MengineDataDog")
.build();

MengineApplication application = activity.getMengineApplication();

String installKey = application.getInstallKey();
loggerDataDog.addAttribute("install_key", installKey);

String sessionId = application.getSessionId();
loggerDataDog.addAttribute("session_id", sessionId);

long sessionIndex = application.getSessionIndex();
loggerDataDog.addAttribute("session_index", sessionIndex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws

DTDAnalyticsConfiguration configuration = new DTDAnalyticsConfiguration();

if (BuildConfig.DEBUG) {
if (BuildConfig.DEBUG == true) {
configuration.setLogLevel(DTDLogLevel.Debug);
} else {
configuration.setLogLevel(DTDLogLevel.Error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ public void onAppPrepare(MengineApplication application) throws MenginePluginInv

m_logger = AppEventsLogger.newLogger(context);

String sessionId = application.getSessionId();
AppEventsLogger.setUserID(sessionId);

try {
AppEventsLogger.activateApp(application);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public void onEvent(MengineApplication application, MengineEvent event, Object .
public void onAppPrepare(MengineApplication application) throws MenginePluginInvalidInitializeException {
m_firebaseAnalytics = FirebaseAnalytics.getInstance(application);

String sessionId = application.getSessionId();
m_firebaseAnalytics.setUserId(sessionId);

String installKey = application.getInstallKey();
long installTimestamp = application.getInstallTimestamp();
String installVersion = application.getInstallVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void onEvent(MengineApplication application, MengineEvent event, Object .
public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException {
Map<String, Object> config = new HashMap<>();

if (BuildConfig.DEBUG) {
if (BuildConfig.DEBUG == true) {
config.put("enableLogging", true);
} else {
config.put("enableLogging", false);
Expand Down
4 changes: 2 additions & 2 deletions gradle/plugins/Sentry/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'io.sentry:sentry-android-gradle-plugin:3.11.1'
classpath 'io.sentry:sentry-android-gradle-plugin:3.12.0'
}
}

Expand All @@ -20,7 +20,7 @@ android {
}

dependencies {
implementation 'io.sentry:sentry-android:6.27.0'
implementation 'io.sentry:sentry-android:6.28.0'
}

apply from: rootProject.projectDir.getAbsolutePath() + '/plugins/plugin_extensions.gradle'
12 changes: 6 additions & 6 deletions src/Kernel/HashHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Mengine
return x4;
}
//////////////////////////////////////////////////////////////////////////
MENGINE_CONSTEXPR HashType makeHash( const Char * _data, const HashType _len )
MENGINE_CONSTEXPR HashType makeHash( const Char * _data, size_t _len )
{
if( _len == 0 )
{
Expand All @@ -39,19 +39,19 @@ namespace Mengine

const Char * p = _data;

const HashType b = *p;
HashType b = *p;

HashType x = b << 7;

for( HashType i = 0; i != _len; ++i )
for( size_t i = 0; i != _len; ++i )
{
const HashType b2 = *p++;
const HashType x2 = Helper::xmul12864( 1000003ULL, x );
HashType b2 = *p++;
HashType x2 = Helper::xmul12864( 1000003ULL, x );

x = x2 ^ b2;
}

x ^= _len;
x ^= (HashType)_len;

if( x == -1 )
{
Expand Down

0 comments on commit 07a1a76

Please sign in to comment.