diff --git a/gradle/app/AndroidManifest.xml b/gradle/app/AndroidManifest.xml index 886b28e15d..333d43be06 100644 --- a/gradle/app/AndroidManifest.xml +++ b/gradle/app/AndroidManifest.xml @@ -1,8 +1,7 @@ - + @@ -19,18 +18,21 @@ android:label="@string/app_name" android:name="org.Mengine.Project.FinalApplication" android:icon="@mipmap/ic_launcher" - android:roundIcon="@mipmap/ic_launcher" + android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" - android:theme="@style/Theme.AppCompat.Light.NoActionBar" + android:theme="@style/MengineApplicationTheme" android:networkSecurityConfig="@xml/network_security_config" android:hardwareAccelerated="true"> android:configChanges="mcc|mnc|fontScale|touchscreen|density|layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"> diff --git a/gradle/app/build.gradle b/gradle/app/build.gradle index a75111d8c5..d250e928fc 100644 --- a/gradle/app/build.gradle +++ b/gradle/app/build.gradle @@ -16,6 +16,7 @@ def ANDROID_APP_SPLIT_ENABLE = Utils.getBooleanProperty(project, "ANDROID_APP_SP def ANDROID_APP_BUNDLE_ENABLE = Utils.getBooleanProperty(project, "ANDROID_APP_BUNDLE_ENABLE", false) def ANDROID_APP_DELIVERY_PACKAGES = Utils.getStringProperty(project, "ANDROID_APP_DELIVERY_PACKAGES", null) def ANDROID_APP_BUILD_NUMBER = Utils.getIntegerProperty(project, "ANDROID_APP_BUILD_NUMBER", 0) +def ANDROID_APP_SCREEN_ORIENTATION = Utils.getStringProperty(project, "ANDROID_APP_SCREEN_ORIENTATION", "portrait") def MENGINE_APP_LIBRARY_MENGINE = Utils.existAppLibrary(project, "MENGINE_APP_LIBRARY_MENGINE") def MENGINE_APP_LIBRARY_OPENAL32 = Utils.existAppLibrary(project, "MENGINE_APP_LIBRARY_OPENAL32") @@ -168,6 +169,10 @@ android { } defaultConfig { + manifestPlaceholders = [ANDROID_APP_SCREEN_ORIENTATION: ANDROID_APP_SCREEN_ORIENTATION] + + println "ANDROID_APP_SCREEN_ORIENTATION: $ANDROID_APP_SCREEN_ORIENTATION" + if (project.hasProperty("ANDROID_APP_ID")) { applicationId ANDROID_APP_ID diff --git a/gradle/build.gradle b/gradle/build.gradle index b9d3e6b81f..c8017e1b2a 100644 --- a/gradle/build.gradle +++ b/gradle/build.gradle @@ -32,7 +32,7 @@ buildscript { } if (Utils.existAppPlugin(project, "MENGINE_APP_PLUGIN_APPLOVIN") == true) { - classpath 'com.applovin.quality:AppLovinQualityServiceGradlePlugin:5.6.3' + classpath 'com.applovin.quality:AppLovinQualityServiceGradlePlugin:5.6.4' } } } diff --git a/gradle/gradle.properties.ci b/gradle/gradle.properties.ci index 59368f25c7..9619b178ed 100644 --- a/gradle/gradle.properties.ci +++ b/gradle/gradle.properties.ci @@ -14,4 +14,4 @@ org.gradle.jvmargs=-Xms4096M -Xmx4096M -Dkotlin.daemon.jvm.options\="-Xmx4096M" android.useAndroidX=true android.useFullClasspathForDexingTransform=true -android.enableJetifier=true \ No newline at end of file +android.enableJetifier=false \ No newline at end of file diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineActivity.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineActivity.java index 4c69c4dcbe..521bbc9905 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineActivity.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineActivity.java @@ -2,11 +2,8 @@ import android.content.Context; import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; -import android.content.res.Resources; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -28,68 +25,23 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsControllerCompat; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; -import java.io.Writer; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.List; -import java.util.concurrent.CountDownLatch; public class MengineActivity extends AppCompatActivity { public static final String TAG = "MengineActivity"; - private static native Object AndroidMain_bootstrap(String nativeLibraryDir, String[] _args); - private static native void AndroidMain_destroy(Object application); - - private static native void AndroidEnv_setMengineAndroidActivityJNI(Object activity); - private static native void AndroidEnv_removeMengineAndroidActivityJNI(); - - private static native boolean AndroidEnvironmentService_isDevelopmentMode(); - private static native String AndroidEnvironmentService_getCompanyName(); - private static native String AndroidEnvironmentService_getProjectName(); - private static native String AndroidEnvironmentService_getExtraPreferencesFolderName(); - private static native boolean AndroidEnvironmentService_hasCurrentAccount(); - private static native void AndroidEnvironmentService_deleteCurrentAccount(); - private static native String AndroidEnvironmentService_getCurrentAccountFolderName(); - private static native boolean AndroidEnvironmentService_writeCurrentLogToFile(Writer writer); - private static native boolean AndroidEnvironmentService_writeOldLogToFile(Writer writer); - private static native int AndroidEnvironmentService_getProjectVersion(); - - private static native void AndroidNativePython_addPlugin(String name, Object plugin); - private static native void AndroidNativePython_call(String plugin, String method, Object []args); - - public static native void AndroidPlatform_surfaceCreatedEvent(Surface surface); - public static native void AndroidPlatform_surfaceDestroyedEvent(Surface surface); - public static native void AndroidPlatform_surfaceChangedEvent(Surface surface, int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float rate); - public static native void AndroidPlatform_keyEvent(boolean isDown, int keyCode, int repeatCount); - public static native void AndroidPlatform_textEvent(int unicode); - public static native void AndroidPlatform_touchEvent(int action, int pointerId, float x, float y, float pressure); - public static native void AndroidPlatform_accelerationEvent(float x, float y, float z); - public static native void AndroidPlatform_pauseEvent(); - public static native void AndroidPlatform_resumeEvent(); - public static native void AndroidPlatform_stopEvent(); - public static native void AndroidPlatform_startEvent(); - public static native void AndroidPlatform_clipboardChangedEvent(); - public static native void AndroidPlatform_windowFocusChangedEvent(boolean focus); - public static native void AndroidPlatform_quitEvent(); - public static native void AndroidPlatform_lowMemory(); - public static native void AndroidPlatform_trimMemory(int level); - public static native void AndroidPlatform_changeLocale(String locale); - - private static boolean ACTIVITY_CREATED = false; - private static boolean ACTIVITY_DESTROY = false; - - private boolean m_initializePython = false; - - private Object m_nativeApplication; private Locale m_currentLocale; private static final Map m_requestCodes = new HashMap<>(); @@ -97,8 +49,6 @@ public class MengineActivity extends AppCompatActivity { private static final Object m_syncronizationSemaphores = new Object(); private Map m_semaphores; - private Thread m_threadMain; - private MengineCommandHandler m_commandHandler; private RelativeLayout m_contentView; @@ -114,19 +64,19 @@ public MengineActivity() { } public boolean isDevelopmentMode() { - return AndroidEnvironmentService_isDevelopmentMode(); + return MengineNative.AndroidEnvironmentService_isDevelopmentMode(); } public String getCompanyName() { - return AndroidEnvironmentService_getCompanyName(); + return MengineNative.AndroidEnvironmentService_getCompanyName(); } public String getProjectName() { - return AndroidEnvironmentService_getProjectName(); + return MengineNative.AndroidEnvironmentService_getProjectName(); } public int getProjectVersion() { - return AndroidEnvironmentService_getProjectVersion(); + return MengineNative.AndroidEnvironmentService_getProjectVersion(); } public MengineApplication getMengineApplication() { @@ -177,10 +127,6 @@ protected List getEngineListeners() { @SuppressWarnings("unchecked") public T getPlugin(Class cls) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return null; - } - MengineApplication application = this.getMengineApplication(); T plugin = application.getPlugin(cls); @@ -189,10 +135,6 @@ public T getPlugin(Class cls) { } public String getSessionId() { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return ""; - } - MengineApplication application = this.getMengineApplication(); String sessionId = application.getSessionId(); @@ -201,10 +143,6 @@ public String getSessionId() { } public String getVersionName() { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return ""; - } - MengineApplication application = this.getMengineApplication(); String versionName = application.getVersionName(); @@ -213,20 +151,12 @@ public String getVersionName() { } public void setState(String name, Object value) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return; - } - MengineApplication application = this.getMengineApplication(); application.setState(name, value); } public boolean hasMetaData(String name) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return false; - } - MengineApplication application = this.getMengineApplication(); boolean result = application.hasMetaData(name); @@ -235,10 +165,6 @@ public boolean hasMetaData(String name) { } public String getMetaDataString(String name) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return null; - } - MengineApplication application = this.getMengineApplication(); String value = application.getMetaDataString(name); @@ -247,10 +173,6 @@ public String getMetaDataString(String name) { } public boolean getMetaDataBoolean(String name) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return false; - } - MengineApplication application = this.getMengineApplication(); boolean value = application.getMetaDataBoolean(name); @@ -259,10 +181,6 @@ public boolean getMetaDataBoolean(String name) { } public int getMetaDataInteger(String name) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return 0; - } - MengineApplication application = this.getMengineApplication(); int value = application.getMetaDataInteger(name); @@ -333,18 +251,6 @@ protected void onCreate(Bundle savedInstanceState) { MengineLog.logMessageRelease(TAG, "onCreate: %s", savedInstanceState); - if (MengineActivity.ACTIVITY_CREATED == true) { - MengineAnalytics.buildEvent("mng_activity_create_failed") - .addParameterString("reason", "application already created") - .logAndFlush(); - - this.finishWithAlertDialog("[ERROR] Application already created"); - - return; - } - - MengineActivity.ACTIVITY_CREATED = true; - try { Thread.currentThread().setName("MengineActivity"); } catch (final Exception e) { @@ -365,73 +271,15 @@ protected void onCreate(Bundle savedInstanceState) { return; } + application.setMengineActivity(this); + this.setState("activity.lifecycle", "create"); this.setState("activity.init", "begin"); - m_initializePython = false; - Looper mainLooper = Looper.getMainLooper(); m_commandHandler = new MengineCommandHandler(mainLooper, this); m_semaphores = new HashMap<>(); - this.setState("activity.init", "setup_orientation"); - - Resources resources = this.getResources(); - int orientation = resources.getInteger(R.integer.app_screen_orientation); - - switch(orientation) { - case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_LANDSCAPE"); - break; - case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_PORTRAIT"); - break; - case ActivityInfo.SCREEN_ORIENTATION_USER: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_USER"); - break; - case ActivityInfo.SCREEN_ORIENTATION_BEHIND: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_BEHIND"); - break; - case ActivityInfo.SCREEN_ORIENTATION_SENSOR: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_SENSOR"); - break; - case ActivityInfo.SCREEN_ORIENTATION_NOSENSOR: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_NOSENSOR"); - break; - case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_SENSOR_LANDSCAPE"); - break; - case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_SENSOR_PORTRAIT"); - break; - case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_REVERSE_LANDSCAPE"); - break; - case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_REVERSE_PORTRAIT"); - break; - case ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_FULL_SENSOR"); - break; - case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_USER_LANDSCAPE"); - break; - case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_USER_PORTRAIT"); - break; - case ActivityInfo.SCREEN_ORIENTATION_FULL_USER: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_FULL_USER"); - break; - case ActivityInfo.SCREEN_ORIENTATION_LOCKED: - MengineLog.logMessage(TAG, "setRequestedOrientation SCREEN_ORIENTATION_LOCKED"); - break; - default: - MengineLog.logWarning(TAG, "setRequestedOrientation UNKNOWN: %d", orientation); - break; - } - - this.setRequestedOrientation(orientation); - this.setState("activity.init", "setup_relativelayout"); RelativeLayout contentView = new RelativeLayout(this); @@ -440,9 +288,7 @@ protected void onCreate(Bundle savedInstanceState) { this.setState("activity.init", "setup_surface"); - CountDownLatch runLatch = new CountDownLatch(1); - - MengineSurfaceView surface = new MengineSurfaceView(this, runLatch); + MengineSurfaceView surface = new MengineSurfaceView(this); m_surfaceView = surface; @@ -468,34 +314,16 @@ protected void onCreate(Bundle savedInstanceState) { this.setState("activity.init", "bootstrap"); - AndroidEnv_setMengineAndroidActivityJNI(this); - - ApplicationInfo applicationInfo = application.getApplicationInfo(); - String nativeLibraryDir = applicationInfo.nativeLibraryDir; - String options = application.getApplicationOptions(); - - String[] optionsArgs = options.split(" "); - - Object nativeApplication = AndroidMain_bootstrap(nativeLibraryDir, optionsArgs); + MengineNative.AndroidEnv_setMengineAndroidActivityJNI(this); - if (nativeApplication == null) { - MengineAnalytics.buildEvent("mng_activity_create_failed") - .addParameterString("reason", "bootstrap failed") - .logAndFlush(); - - this.finishWithAlertDialog("[ERROR] bootstrap failed"); - - return; - } - - m_nativeApplication = nativeApplication; + MengineNative.AndroidNativePython_addPlugin("Activity", this); this.setState("activity.init", "plugin_create"); List plugins = this.getPlugins(); for (MenginePlugin p : plugins) { - p.setActivity(this); + p.setMengineActivity(this); } List listeners = this.getActivityListeners(); @@ -527,13 +355,6 @@ protected void onCreate(Bundle savedInstanceState) { } } - this.setState("activity.init", "setup_main"); - - MengineMain main = new MengineMain(this, m_nativeApplication, runLatch); - - m_threadMain = new Thread(main); - m_threadMain.start(); - this.setState("activity.init", "end"); this.setState("activity.lifecycle", "created"); @@ -548,33 +369,87 @@ protected void onPostCreate(@Nullable Bundle savedInstanceState) { MengineLog.logMessage(TAG, "onPostCreate"); } + @SuppressWarnings("deprecation") + private void setupFullscreenModeListener() { + Window window = this.getWindow(); + View decorView = window.getDecorView(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + decorView.setOnApplyWindowInsetsListener((v, insets) -> { + boolean isSystemBarsVisible = insets.isVisible(WindowInsets.Type.systemBars()); + + if (isSystemBarsVisible == true) { + MengineActivity.this.syncFullscreenWindow(); + } + + return insets; + }); + } else { + decorView.setOnSystemUiVisibilityChangeListener(visibility -> { + boolean isFullscreenEnable = (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; + boolean isNavigationHidden = (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; + + if (isFullscreenEnable == false || isNavigationHidden == false) { + MengineActivity.this.syncFullscreenWindow(); + } + }); + } + } + + @SuppressWarnings("deprecation") + private void releaseFullscreenModeListener() { + Window window = this.getWindow(); + View decorView = window.getDecorView(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + decorView.setOnApplyWindowInsetsListener(null); + } else { + decorView.setOnSystemUiVisibilityChangeListener(null); + } + } + + @SuppressWarnings("deprecation") + private void syncFullscreenWindowR(Window window) { + int flags = View.SYSTEM_UI_FLAG_FULLSCREEN | + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + + View decorView = window.getDecorView(); + decorView.setSystemUiVisibility(flags); + + window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); + } + @SuppressWarnings("deprecation") private void syncFullscreenWindow() { + MengineLog.logMessage(TAG, "sync fullscreen mode"); + Window window = this.getWindow(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.setDecorFitsSystemWindows(false); + WindowInsetsController insetsController = window.getInsetsController(); - if (insetsController == null) { - MengineLog.logError(TAG, "insets controller is null"); - return; + if (insetsController == null) { + this.syncFullscreenWindowR(window); + } else { + insetsController.hide(WindowInsets.Type.systemBars()); + insetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); } - - insetsController.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars()); - insetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); } else { - int flags = View.SYSTEM_UI_FLAG_FULLSCREEN | - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_STABLE; - - View decorView = window.getDecorView(); - decorView.setSystemUiVisibility(flags); - - window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); + this.syncFullscreenWindowR(window); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + WindowManager.LayoutParams params = window.getAttributes(); + params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; + window.setAttributes(params); } } @@ -592,7 +467,7 @@ public void onWindowFocusChanged(boolean hasFocus) { this.syncFullscreenWindow(); } - MengineActivity.AndroidPlatform_windowFocusChangedEvent(hasFocus); + MengineNative.AndroidPlatform_windowFocusChangedEvent(hasFocus); } @Override @@ -603,7 +478,7 @@ public void onAttachedToWindow() { MengineLog.logMessage(TAG, "onAttachedToWindow"); - this.syncFullscreenWindow(); + this.setupFullscreenModeListener(); } @Override @@ -613,6 +488,8 @@ public void onDetachedFromWindow() { this.setState("activity.lifecycle", "detached_from_window"); MengineLog.logMessage(TAG, "onDetachedFromWindow"); + + this.releaseFullscreenModeListener(); } @Override @@ -635,86 +512,10 @@ public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { ); } - public void onMengineInitializeBaseServices() { - MengineLog.logInfo(TAG, "onMengineInitializeBaseServices"); - - MengineLog.initialize(this); - - MengineApplication application = (MengineApplication)this.getApplication(); - - List listeners = this.getEngineListeners(); - - for (MenginePluginEngineListener l : listeners) { - if (l.onAvailable(application) == false) { - continue; - } - - l.onMengineInitializeBaseServices(this); - } - } - - public void onMengineCreateApplication() { - MengineLog.logInfo(TAG, "onMengineCreateApplication"); - - MengineApplication application = (MengineApplication)this.getApplication(); - - List listeners = this.getEngineListeners(); - - for (MenginePluginEngineListener l : listeners) { - if (l.onAvailable(application) == false) { - continue; - } - - l.onMengineCreateApplication(this); - } - } - - public void onMenginePlatformRun() { - MengineLog.logInfo(TAG, "onMenginePlatformRun"); - - MengineApplication application = (MengineApplication)this.getApplication(); - - List listeners = this.getEngineListeners(); - - for (MenginePluginEngineListener l : listeners) { - if (l.onAvailable(application) == false) { - continue; - } - - l.onMenginePlatformRun(this); - } - } - - public void onMenginePlatformStop() { - MengineLog.logInfo(TAG, "onMenginePlatformStop"); - - MengineApplication application = (MengineApplication)this.getApplication(); - - List listeners = this.getEngineListeners(); - - for (MenginePluginEngineListener l : listeners) { - if (l.onAvailable(application) == false) { - continue; - } - - l.onMenginePlatformStop(this); - } - - MengineLog.finalize(this); - } - - public void onMengineCurrentSceneChange(String name) { - MengineLog.logInfo(TAG, "onMengineCurrentSceneChange: %s" - , name - ); - - this.setState("current.scene", name); - } - @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { this.setState("activity.result", "request: " + requestCode + "result: " + resultCode ); - + MengineLog.logMessageRelease(TAG, "onActivityResult request: %d result: %d" , requestCode , resultCode @@ -765,7 +566,7 @@ public void onStart() { this.setState("activity.lifecycle", "started"); - MengineActivity.AndroidPlatform_startEvent(); + MengineNative.AndroidPlatform_startEvent(); } @Override @@ -790,7 +591,7 @@ public void onStop() { this.setState("activity.lifecycle", "stoped"); - MengineActivity.AndroidPlatform_stopEvent(); + MengineNative.AndroidPlatform_stopEvent(); } @Override @@ -819,7 +620,7 @@ public void onPause() { this.setState("activity.lifecycle", "paused"); - MengineActivity.AndroidPlatform_pauseEvent(); + MengineNative.AndroidPlatform_pauseEvent(); } @Override @@ -848,7 +649,7 @@ public void onResume() { this.setState("activity.lifecycle", "resumed"); - MengineActivity.AndroidPlatform_resumeEvent(); + MengineNative.AndroidPlatform_resumeEvent(); } @Override @@ -874,22 +675,10 @@ public void onNewIntent(Intent intent) { @Override public void onDestroy() { - if (MengineActivity.ACTIVITY_DESTROY == true) { - MengineLog.logWarning(TAG, "onDestroy: already destroyed"); - - super.onDestroy(); - - return; - } - - MengineActivity.ACTIVITY_DESTROY = true; - this.setState("activity.lifecycle", "destroy"); MengineLog.logMessageRelease(TAG, "onDestroy"); - AndroidPlatform_quitEvent(); - MengineApplication application = (MengineApplication)this.getApplication(); if (application.isInvalidInitialize() == true) { @@ -900,20 +689,29 @@ public void onDestroy() { return; } - try { - m_threadMain.join(1000); - } catch (final InterruptedException e) { - MengineLog.logError(TAG, "thread main join exception: %s" - , e.getMessage() - ); + MengineNative.AndroidNativePython_removePlugin("Activity"); + + MengineNative.AndroidEnv_removeMengineAndroidActivityJNI(); + + if (m_clipboard != null) { + m_clipboard.handleDestroy(); + m_clipboard = null; } - m_threadMain = null; + if (m_surfaceView != null) { + m_surfaceView.handleDestroy(); + m_surfaceView = null; + } - AndroidMain_destroy(m_nativeApplication); - m_nativeApplication = null; + if (m_softInput != null) { + m_softInput.handleDestroy(); + m_softInput = null; + } - AndroidEnv_removeMengineAndroidActivityJNI(); + if (m_contentView != null) { + m_contentView.removeAllViews(); + m_contentView = null; + } m_semaphores = null; m_commandHandler = null; @@ -931,9 +729,11 @@ public void onDestroy() { List plugins = this.getPlugins(); for (MenginePlugin p : plugins) { - p.setActivity(null); + p.setMengineActivity(null); } + application.setMengineActivity(null); + super.onDestroy(); } @@ -968,7 +768,7 @@ public void onLowMemory() { MengineLog.logMessage(TAG, "onLowMemory"); - MengineActivity.AndroidPlatform_lowMemory(); + MengineNative.AndroidPlatform_lowMemory(); } @Override @@ -981,7 +781,7 @@ public void onTrimMemory(int level) { , level ); - MengineActivity.AndroidPlatform_trimMemory(level); + MengineNative.AndroidPlatform_trimMemory(level); } @Override @@ -1013,7 +813,7 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) { String language = m_currentLocale.getLanguage(); - MengineActivity.AndroidPlatform_changeLocale(language); + MengineNative.AndroidPlatform_changeLocale(language); } } @@ -1087,58 +887,7 @@ public static int genRequestCode(String name) { * Python Methods **********************************************************************************************/ - public void onPythonEmbeddedInitialize() { - MengineLog.logInfo(TAG, "onPythonEmbeddedInitialize"); - - m_initializePython = true; - - AndroidNativePython_addPlugin("Activity", this); - - MengineApplication application = (MengineApplication)this.getApplication(); - AndroidNativePython_addPlugin("Application", application); - - List plugins = this.getPlugins(); - - for (MenginePlugin p : plugins) { - if (p.onAvailable(application) == false) { - continue; - } - - try { - Class cls = p.getClass(); - - Field PLUGIN_EMBEDDING = cls.getField("PLUGIN_EMBEDDING"); - - if( PLUGIN_EMBEDDING.getBoolean(null) == false ) { - continue; - } - } catch (final NoSuchFieldException e) { - continue; - } catch (final IllegalAccessException e) { - continue; - } - - String name = p.getPluginName(); - - this.addPythonPlugin(name, p); - } - } - - public void onPythonEmbeddedFinalize() { - m_initializePython = false; - } - public void pythonCall(String plugin, String method, Object ... args) { - if (m_initializePython == false) { - MengineLog.logWarning(TAG,"pythonCall call before embedding plugin: %s method: %s args: %s" - , plugin - , method - , Arrays.toString(args) - ); - - return; - } - if (BuildConfig.DEBUG == true) { MengineLog.logInfo(TAG, "pythonCall plugin [%s] method [%s] args [%s]" , plugin @@ -1149,20 +898,7 @@ public void pythonCall(String plugin, String method, Object ... args) { this.setState("python.call", plugin + "." + method); - AndroidNativePython_call(plugin, method, args); - } - - public void addPythonPlugin(String name, Object plugin) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return; - } - - MengineLog.logMessage(TAG, "addPythonPlugin name: %s plugin: %s" - , name - , plugin - ); - - AndroidNativePython_addPlugin(name, plugin); + MengineNative.AndroidNativePython_call(plugin, method, args); } /*********************************************************************************************** @@ -1170,10 +906,6 @@ public void addPythonPlugin(String name, Object plugin) { **********************************************************************************************/ public void activateSemaphore(String name) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return; - } - MengineLog.logMessage(TAG, "activateSemaphore semaphore: %s" , name ); @@ -1210,10 +942,6 @@ public void activateSemaphore(String name) { } public void deactivateSemaphore(String name) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return; - } - MengineLog.logMessage(TAG, "deactivateSemaphore semaphore: %s" , name ); @@ -1224,10 +952,6 @@ public void deactivateSemaphore(String name) { } public void waitSemaphore(String name, MengineSemaphoreListener cb) { - if (MengineActivity.ACTIVITY_DESTROY == true) { - return; - } - MengineLog.logMessage(TAG, "waitSemaphore semaphore: %s" , name ); @@ -1342,11 +1066,11 @@ public boolean linkingOpenMail(String email, String subject, String body) { try { ArrayList fileUris = new ArrayList<>(); - boolean hasAccount = AndroidEnvironmentService_hasCurrentAccount(); + boolean hasAccount = MengineNative.AndroidEnvironmentService_hasCurrentAccount(); if (hasAccount == true) { - String extraPreferencesFolderName = AndroidEnvironmentService_getExtraPreferencesFolderName(); - String accountFolderName = AndroidEnvironmentService_getCurrentAccountFolderName(); + String extraPreferencesFolderName = MengineNative.AndroidEnvironmentService_getExtraPreferencesFolderName(); + String accountFolderName = MengineNative.AndroidEnvironmentService_getCurrentAccountFolderName(); File filesDir = context.getFilesDir(); @@ -1403,7 +1127,7 @@ public boolean linkingOpenMail(String email, String subject, String body) { logFileStream.write("[BEGIN CURRENT LOG]\n\n"); - if (AndroidEnvironmentService_writeCurrentLogToFile(logFileStream) == true) { + if (MengineNative.AndroidEnvironmentService_writeCurrentLogToFile(logFileStream) == true) { logFileStream.write("\n\n[END CURRENT LOG]"); logFileStream.flush(); logFileStream.close(); @@ -1465,7 +1189,7 @@ public boolean linkingOpenMail(String email, String subject, String body) { oldLogFileStream.write("[BEGIN OLD LOG]\n\n"); - if (AndroidEnvironmentService_writeOldLogToFile(oldLogFileStream) == true) { + if (MengineNative.AndroidEnvironmentService_writeOldLogToFile(oldLogFileStream) == true) { oldLogFileStream.write("\n\n[END OLD LOG]"); oldLogFileStream.flush(); oldLogFileStream.close(); @@ -1551,7 +1275,7 @@ public boolean linkingOpenDeleteAccount() { application.removeSessionData(); - MengineActivity.AndroidEnvironmentService_deleteCurrentAccount(); + MengineNative.AndroidEnvironmentService_deleteCurrentAccount(); MengineUtils.showOkAlertDialog(this, () -> { this.finishAndRemoveTask(); diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineApplication.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineApplication.java index 2fd1050b1e..c369fc0b9a 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineApplication.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineApplication.java @@ -28,33 +28,24 @@ public class MengineApplication extends Application { private static final String TAG = "MengineApplication"; - private static native void AndroidEnv_setMengineAndroidApplicationJNI(Object activity, ClassLoader cl); - private static native void AndroidEnv_removeMengineAndroidApplicationJNI(); - - private static native boolean AndroidEnv_isMasterRelease(); - private static native String AndroidEnv_getEngineGITSHA1(); - private static native String AndroidEnv_getEngineVersion(); - private static native String AndroidEnv_getBuildDate(); - private static native String AndroidEnv_getBuildUsername(); - public boolean isMasterRelease() { - return AndroidEnv_isMasterRelease(); + return MengineNative.AndroidEnv_isMasterRelease(); } public String getEngineGITSHA1() { - return AndroidEnv_getEngineGITSHA1(); + return MengineNative.AndroidEnv_getEngineGITSHA1(); } public String getEngineVersion() { - return AndroidEnv_getEngineVersion(); + return MengineNative.AndroidEnv_getEngineVersion(); } public String getBuildDate() { - return AndroidEnv_getBuildDate(); + return MengineNative.AndroidEnv_getBuildDate(); } public String getBuildUsername() { - return AndroidEnv_getBuildUsername(); + return MengineNative.AndroidEnv_getBuildUsername(); } private String m_androidId; @@ -71,6 +62,16 @@ public String getBuildUsername() { private boolean m_invalidInitialize = false; private String m_invalidInitializeReason = null; + private MengineActivity m_activity; + + private MengineMain m_main; + + private Object m_nativeApplication; + + private boolean m_isMengineInitializeBaseServices = false; + private boolean m_isMengineCreateApplication = false; + private boolean m_isMenginePlatformRun = false; + private ConnectivityManager.NetworkCallback m_networkCallback; private final ArrayList m_plugins = new ArrayList<>(); @@ -390,6 +391,26 @@ private String getSecureAndroidId() { return androidId; } + public void setMengineActivity(MengineActivity activity) { + m_activity = activity; + } + + public MengineActivity getMengineActivity() { + return m_activity; + } + + public boolean isMengineInitializeBaseServices() { + return m_isMengineInitializeBaseServices; + } + + public boolean isMengineCreateApplication() { + return m_isMengineCreateApplication; + } + + public boolean isMenginePlatformRun() { + return m_isMenginePlatformRun; + } + public void setState(String name, Object value) { m_states.put(name, value); @@ -891,6 +912,10 @@ protected static String generateInstallKey() { return installKey; } + public Object getNativeApplication() { + return m_nativeApplication; + } + @Override public void onCreate() { super.onCreate(); @@ -1093,7 +1118,7 @@ public void onCreate() { ClassLoader cl = MengineApplication.class.getClassLoader(); - AndroidEnv_setMengineAndroidApplicationJNI(this, cl); + MengineNative.AndroidEnv_setMengineAndroidApplicationJNI(this, cl); String engine_gitsha1 = this.getEngineGITSHA1(); this.setState("engine.gitsha1", engine_gitsha1); @@ -1114,7 +1139,7 @@ public void onCreate() { l.onAppPrepare(this); } catch (final MenginePluginInvalidInitializeException e) { - MengineAnalytics.buildEvent("mng_app_init_failed") + MengineAnalytics.buildEvent("mng_app_create_failed") .addParameterException("exception", e) .logAndFlush(); @@ -1141,7 +1166,7 @@ public void onCreate() { l.onAppCreate(this); } catch (MenginePluginInvalidInitializeException e) { - MengineAnalytics.buildEvent("mng_app_init_failed") + MengineAnalytics.buildEvent("mng_app_create_failed") .addParameterException("exception", e) .logAndFlush(); @@ -1154,6 +1179,47 @@ public void onCreate() { } } + ApplicationInfo applicationInfo = this.getApplicationInfo(); + String nativeLibraryDir = applicationInfo.nativeLibraryDir; + String options = this.getApplicationOptions(); + + String[] optionsArgs = options.split(" "); + + Object nativeApplication = MengineNative.AndroidMain_bootstrap(nativeLibraryDir, optionsArgs); + + if (nativeApplication == null) { + MengineAnalytics.buildEvent("mng_activity_create_failed") + .addParameterString("reason", "bootstrap failed") + .logAndFlush(); + + this.invalidInitialize("[ERROR] bootstrap failed"); + + return; + } + + m_nativeApplication = nativeApplication; + + for (MenginePlugin p : m_plugins) { + if (p.onAvailable(this) == false) { + continue; + } + + if (p.isEmbedding() == false) { + continue; + } + + String name = p.getPluginName(); + + MengineNative.AndroidNativePython_addPlugin(name, p); + } + + this.setState("application.init", "run_main"); + + MengineNative.AndroidNativePython_addPlugin("Application", this); + + m_main = new MengineMain(m_nativeApplication); + m_main.start(); + this.setState("application.init", "completed"); } @@ -1171,6 +1237,20 @@ public void onTerminate() { l.onAppTerminate(this); } + for (MenginePlugin p : m_plugins) { + if (p.onAvailable(this) == false) { + continue; + } + + if (p.isEmbedding() == false) { + continue; + } + + String name = p.getPluginName(); + + MengineNative.AndroidNativePython_removePlugin(name); + } + for (MenginePlugin plugin : m_plugins) { plugin.onFinalize(this); } @@ -1180,7 +1260,15 @@ public void onTerminate() { MengineLog.setMengineApplication(null); MengineAnalytics.setMengineApplication(null); - AndroidEnv_removeMengineAndroidApplicationJNI(); + MengineNative.AndroidNativePython_removePlugin("Application"); + + m_main.stop(); + m_main = null; + + MengineNative.AndroidMain_destroy(m_nativeApplication); + m_nativeApplication = null; + + MengineNative.AndroidEnv_removeMengineAndroidApplicationJNI(); super.onTerminate(); } @@ -1219,6 +1307,82 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) { } } + public void onMengineInitializeBaseServices() { + MengineLog.logInfo(TAG, "onMengineInitializeBaseServices"); + + m_isMengineInitializeBaseServices = true; + + MengineLog.initializeBaseServices(); + + List listeners = this.getEngineListeners(); + + for (MenginePluginEngineListener l : listeners) { + if (l.onAvailable(this) == false) { + continue; + } + + l.onMengineInitializeBaseServices(this); + } + } + + public void onMengineCreateApplication() { + MengineLog.logInfo(TAG, "onMengineCreateApplication"); + + m_isMengineCreateApplication = true; + + List listeners = this.getEngineListeners(); + + for (MenginePluginEngineListener l : listeners) { + if (l.onAvailable(this) == false) { + continue; + } + + l.onMengineCreateApplication(this); + } + } + + public void onMenginePlatformRun() { + MengineLog.logInfo(TAG, "onMenginePlatformRun"); + + m_isMenginePlatformRun = true; + + List listeners = this.getEngineListeners(); + + for (MenginePluginEngineListener l : listeners) { + if (l.onAvailable(this) == false) { + continue; + } + + l.onMenginePlatformRun(this); + } + } + + public void onMenginePlatformStop() { + MengineLog.logInfo(TAG, "onMenginePlatformStop"); + + m_isMenginePlatformRun = false; + + List listeners = this.getEngineListeners(); + + for (MenginePluginEngineListener l : listeners) { + if (l.onAvailable(this) == false) { + continue; + } + + l.onMenginePlatformStop(this); + } + + MengineLog.finalizeBaseServices(); + } + + public void onMengineCurrentSceneChange(String name) { + MengineLog.logInfo(TAG, "onMengineCurrentSceneChange: %s" + , name + ); + + this.setState("current.scene", name); + } + public void onMengineLogger(int level, int filter, String category, String msg) { List listeners = this.getLoggerListeners(); diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineClipboard.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineClipboard.java index dee41dad3e..10a34ab135 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineClipboard.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineClipboard.java @@ -8,7 +8,7 @@ public class MengineClipboard extends View implements ClipboardManager.OnPrimaryClipChangedListener { public static final String TAG = "MengineClipboard"; - protected final ClipboardManager m_cm; + protected ClipboardManager m_cm; public MengineClipboard(Context context) { super(context); @@ -22,6 +22,13 @@ public MengineClipboard(Context context) { } } + public void handleDestroy() { + if (m_cm != null) { + m_cm.removePrimaryClipChangedListener(this); + m_cm = null; + } + } + public boolean hasText() { if (m_cm == null) { return false; @@ -95,6 +102,6 @@ public void setText(String text) { public void onPrimaryClipChanged() { MengineLog.logMessage(TAG, "clipboard changed"); - MengineActivity.AndroidPlatform_clipboardChangedEvent(); + MengineNative.AndroidPlatform_clipboardChangedEvent(); } } \ No newline at end of file diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineLog.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineLog.java index affa5128e8..32379acc29 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineLog.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineLog.java @@ -10,8 +10,6 @@ import java.util.IllegalFormatException; public class MengineLog { - private static native void AndroidEnvironmentService_log(int level, String tag, String msg); - public final static int LM_SILENT = 0; public final static int LM_FATAL = 1; public final static int LM_MESSAGE_RELEASE = 2; @@ -48,12 +46,12 @@ public static void setMengineApplication(MengineApplication application) { MengineLog.m_application = application; } - public static void initialize(MengineActivity activity) { + public static void initializeBaseServices() { MengineLog.m_initializeBaseServices = true; synchronized (MengineLog.m_lock) { for (HistoryRecord record : MengineLog.m_history) { - AndroidEnvironmentService_log(record.level, record.tag, record.message); + MengineNative.AndroidEnvironmentService_log(record.level, record.tag, record.message); if (record.application == null) { MengineLog.m_application.onMengineLogger(record.level, record.filter, record.tag, record.message); @@ -64,7 +62,7 @@ public static void initialize(MengineActivity activity) { } } - public static void finalize(MengineActivity activity) { + public static void finalizeBaseServices() { MengineLog.m_initializeBaseServices = false; } @@ -110,7 +108,7 @@ private static String log(int level, @Size(min = 1L,max = 23L) String tag, int f synchronized (MengineLog.m_lock) { if (MengineLog.m_initializeBaseServices == true) { - AndroidEnvironmentService_log(level, tag, totalMsg); + MengineNative.AndroidEnvironmentService_log(level, tag, totalMsg); } else { HistoryRecord record = new HistoryRecord(); record.level = level; diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineMain.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineMain.java index c5b6b1d00b..f0e5356f1a 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineMain.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineMain.java @@ -7,17 +7,33 @@ public class MengineMain implements Runnable { public static final String TAG = "MengineMain"; - private static native boolean AndroidMain_main(Object application); - - protected final MengineActivity m_activity; + protected static CountDownLatch m_runLatch = new CountDownLatch(1); protected final Object m_nativeApplication; - protected final CountDownLatch m_runLatch; - public MengineMain(MengineActivity activity, Object nativeApplication, CountDownLatch runLatch) { - m_activity = activity; + protected Thread m_thread; + + public MengineMain(Object nativeApplication) { m_nativeApplication = nativeApplication; - m_runLatch = runLatch; + } + + public static void runLatch() { + m_runLatch.countDown(); + } + + public void start() { + m_thread = new Thread(this); + m_thread.start(); + } + + public void stop() { + try { + m_thread.join(); + } catch (final InterruptedException e) { + MengineLog.logError(TAG, "thread main join exception: %s" + , e.getMessage() + ); + } } @Override @@ -48,8 +64,8 @@ public void run() { return; } - if (AndroidMain_main(m_nativeApplication) == false) { - MengineUtils.finishActivityWithAlertDialog(m_activity, "main finish with failed"); + if (MengineNative.AndroidMain_main(m_nativeApplication) == false) { + MengineLog.logMessage(TAG, "main finish with failed" ); return; } diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineNative.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineNative.java new file mode 100644 index 0000000000..18b220f13b --- /dev/null +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineNative.java @@ -0,0 +1,63 @@ +package org.Mengine.Base; + +import android.view.Surface; + +import java.io.Writer; + +public class MengineNative { + public static final String TAG = "MengineNative"; + + public static native boolean AndroidMain_main(Object application); + public static native Object AndroidMain_bootstrap(String nativeLibraryDir, String[] _args); + public static native void AndroidMain_destroy(Object application); + + public static native void AndroidMain_crash(String reason); + + public static native void AndroidEnv_setMengineAndroidActivityJNI(Object activity); + public static native void AndroidEnv_removeMengineAndroidActivityJNI(); + + public static native void AndroidEnvironmentService_log(int level, String tag, String msg); + public static native void AnroidEnvironmentService_callMengineSemaphoreListener(Object impl); + public static native void AnroidEnvironmentService_destroyMengineSemaphoreListener(Object impl); + public static native boolean AndroidEnvironmentService_isDevelopmentMode(); + public static native String AndroidEnvironmentService_getCompanyName(); + public static native String AndroidEnvironmentService_getProjectName(); + public static native String AndroidEnvironmentService_getExtraPreferencesFolderName(); + public static native boolean AndroidEnvironmentService_hasCurrentAccount(); + public static native void AndroidEnvironmentService_deleteCurrentAccount(); + public static native String AndroidEnvironmentService_getCurrentAccountFolderName(); + public static native boolean AndroidEnvironmentService_writeCurrentLogToFile(Writer writer); + public static native boolean AndroidEnvironmentService_writeOldLogToFile(Writer writer); + public static native int AndroidEnvironmentService_getProjectVersion(); + + public static native void AndroidNativePython_addPlugin(String name, Object plugin); + public static native void AndroidNativePython_removePlugin(String name); + public static native void AndroidNativePython_call(String plugin, String method, Object []args); + + public static native void AndroidPlatform_surfaceCreatedEvent(Surface surface); + public static native void AndroidPlatform_surfaceDestroyedEvent(Surface surface); + public static native void AndroidPlatform_surfaceChangedEvent(Surface surface, int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float rate); + public static native void AndroidPlatform_keyEvent(boolean isDown, int keyCode, int repeatCount); + public static native void AndroidPlatform_textEvent(int unicode); + public static native void AndroidPlatform_touchEvent(int action, int pointerId, float x, float y, float pressure); + public static native void AndroidPlatform_accelerationEvent(float x, float y, float z); + public static native void AndroidPlatform_pauseEvent(); + public static native void AndroidPlatform_resumeEvent(); + public static native void AndroidPlatform_stopEvent(); + public static native void AndroidPlatform_startEvent(); + public static native void AndroidPlatform_clipboardChangedEvent(); + public static native void AndroidPlatform_windowFocusChangedEvent(boolean focus); + public static native void AndroidPlatform_quitEvent(); + public static native void AndroidPlatform_lowMemory(); + public static native void AndroidPlatform_trimMemory(int level); + public static native void AndroidPlatform_changeLocale(String locale); + + public static native void AndroidEnv_setMengineAndroidApplicationJNI(Object activity, ClassLoader cl); + public static native void AndroidEnv_removeMengineAndroidApplicationJNI(); + + public static native boolean AndroidEnv_isMasterRelease(); + public static native String AndroidEnv_getEngineGITSHA1(); + public static native String AndroidEnv_getEngineVersion(); + public static native String AndroidEnv_getBuildDate(); + public static native String AndroidEnv_getBuildUsername(); +} \ No newline at end of file diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePlugin.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePlugin.java index 7e6de88d96..d0a9098ae8 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePlugin.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePlugin.java @@ -2,6 +2,7 @@ import androidx.annotation.Size; +import java.lang.reflect.Field; import java.util.Locale; public class MenginePlugin implements MenginePluginInterface { @@ -10,14 +11,6 @@ public class MenginePlugin implements MenginePluginInterface { private String m_pluginName; private Boolean m_availableStatus = null; - public MengineApplication getMengineApplication() { - return m_application; - } - - public MengineActivity getMengineActivity() { - return m_activity; - } - public boolean onInitialize(MengineApplication application, String pluginName) { m_application = application; m_pluginName = pluginName; @@ -29,10 +22,18 @@ public void onFinalize(MengineApplication application) { m_application = null; } - public void setActivity(MengineActivity activity) { + public MengineApplication getMengineApplication() { + return m_application; + } + + public void setMengineActivity(MengineActivity activity) { m_activity = activity; } + public MengineActivity getMengineActivity() { + return m_activity; + } + public String getPluginName() { return m_pluginName; } @@ -51,6 +52,24 @@ public boolean isAvailable() { return m_availableStatus; } + public boolean isEmbedding() { + try { + Class cls = this.getClass(); + + Field PLUGIN_EMBEDDING = cls.getField("PLUGIN_EMBEDDING"); + + if( PLUGIN_EMBEDDING.getBoolean(null) == false ) { + return false; + } + } catch (final NoSuchFieldException e) { + return false; + } catch (final IllegalAccessException e) { + return false; + } + + return true; + } + public boolean hasOption(String option) { boolean value = m_application.hasOption(option); diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePluginEngineListener.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePluginEngineListener.java index 088d6c0cb0..8cdd30356f 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePluginEngineListener.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MenginePluginEngineListener.java @@ -1,27 +1,27 @@ package org.Mengine.Base; public interface MenginePluginEngineListener extends MenginePluginInterface { - default void onMengineInitializeBaseServices(MengineActivity activity) { + default void onMengineInitializeBaseServices(MengineApplication application) { //Empty } - default void onMengineCreateApplication(MengineActivity activity) { + default void onMengineCreateApplication(MengineApplication application) { //Empty } - default void onMenginePlatformRun(MengineActivity activity) { + default void onMenginePlatformRun(MengineApplication application) { //Empty } - default void onMenginePlatformStop(MengineActivity activity) { + default void onMenginePlatformStop(MengineApplication application) { //Empty } - default void onMengineCurrentSceneChange(MengineActivity activity, String name) { + default void onMengineCurrentSceneChange(MengineApplication application, String name) { //Empty } - default void onMengineCaughtException(MengineApplication activity, Throwable e) { + default void onMengineCaughtException(MengineApplication application, Throwable e) { //Empty } } \ No newline at end of file diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSemaphoreListener.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSemaphoreListener.java index 63f2b74f61..59fe5f2216 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSemaphoreListener.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSemaphoreListener.java @@ -1,9 +1,6 @@ package org.Mengine.Base; public class MengineSemaphoreListener { - private static native void AnroidEnvironmentService_callMengineSemaphoreListener(Object impl); - private static native void AnroidEnvironmentService_destroyMengineSemaphoreListener(Object impl); - private Object m_impl; MengineSemaphoreListener(Object impl) { @@ -11,11 +8,12 @@ public class MengineSemaphoreListener { } public void destroy() { - AnroidEnvironmentService_destroyMengineSemaphoreListener(m_impl); + MengineNative.AnroidEnvironmentService_destroyMengineSemaphoreListener(m_impl); + m_impl = null; } public void call() { - AnroidEnvironmentService_callMengineSemaphoreListener(m_impl); + MengineNative.AnroidEnvironmentService_callMengineSemaphoreListener(m_impl); } } \ No newline at end of file diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSoftInput.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSoftInput.java index 36506b1c08..065eebf34a 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSoftInput.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSoftInput.java @@ -15,22 +15,8 @@ public class MengineSoftInput extends View implements View.OnKeyListener { public static final String TAG = "MengineSoftInput"; - protected final InputMethodManager m_imm; - protected final View m_prevView; - - public MengineSoftInput(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - - InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); - - m_imm = imm; - - m_prevView = null; - - this.setFocusableInTouchMode(true); - this.setFocusable(true); - this.setOnKeyListener(this); - } + protected InputMethodManager m_imm; + protected View m_prevView; public MengineSoftInput(Context context, View prevView) { super(context); @@ -46,6 +32,15 @@ public MengineSoftInput(Context context, View prevView) { this.setOnKeyListener(this); } + public void handleDestroy() { + m_imm = null; + m_prevView = null; + + this.setFocusable(false); + this.setFocusableInTouchMode(false); + this.setOnKeyListener(null); + } + @Override public boolean onCheckIsTextEditor() { return true; diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSurfaceView.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSurfaceView.java index c77f279cb3..c293a33341 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSurfaceView.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineSurfaceView.java @@ -21,22 +21,18 @@ public class MengineSurfaceView extends SurfaceView implements SurfaceHolder.Callback, View.OnKeyListener, View.OnTouchListener, SensorEventListener { public static final String TAG = "MengineSurfaceView"; - private final CountDownLatch m_runLatch; - - private final SensorManager m_sensorManager; + private SensorManager m_sensorManager; private Sensor m_accelerometer; private Sensor m_linearAccelerometer; - private final Display m_display; + private Display m_display; private int m_surfaceWidth; private int m_surfaceHeight; - public MengineSurfaceView(Context context, CountDownLatch runLatch) { + public MengineSurfaceView(Context context) { super(context); - m_runLatch = runLatch; - this.getHolder().addCallback(this); m_display = MengineUtils.getDefaultDisplay(context); @@ -63,7 +59,7 @@ public void handlePause() { m_sensorManager.unregisterListener(this, m_linearAccelerometer); } - MengineActivity.AndroidPlatform_pauseEvent(); + MengineNative.AndroidPlatform_pauseEvent(); } public void handleResume() { @@ -78,7 +74,16 @@ public void handleResume() { m_sensorManager.registerListener(this, m_linearAccelerometer, SensorManager.SENSOR_DELAY_GAME); } - MengineActivity.AndroidPlatform_resumeEvent(); + MengineNative.AndroidPlatform_resumeEvent(); + } + + public void handleDestroy() { + this.handlePause(); + + this.getHolder().removeCallback(this); + + m_display = null; + m_sensorManager = null; } Surface getSurface() { @@ -97,7 +102,7 @@ public void surfaceCreated(SurfaceHolder holder) { return; } - MengineActivity.AndroidPlatform_surfaceCreatedEvent(surface); + MengineNative.AndroidPlatform_surfaceCreatedEvent(surface); } @Override @@ -112,12 +117,16 @@ public void surfaceDestroyed(SurfaceHolder holder) { return; } - MengineActivity.AndroidPlatform_surfaceDestroyedEvent(surface); + MengineNative.AndroidPlatform_surfaceDestroyedEvent(surface); } @Override public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) { - MengineLog.logMessage(TAG, "surfaceChanged"); + MengineLog.logMessage(TAG, "surfaceChanged format: %d width: %d height: %d" + , format + , width + , height + ); m_surfaceWidth = width; m_surfaceHeight = height; @@ -139,9 +148,9 @@ public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, float refreshRate = m_display.getRefreshRate(); Surface surface = holder.getSurface(); - MengineActivity.AndroidPlatform_surfaceChangedEvent(surface, width, height, deviceWidth, deviceHeight, refreshRate); + MengineNative.AndroidPlatform_surfaceChangedEvent(surface, width, height, deviceWidth, deviceHeight, refreshRate); - m_runLatch.countDown(); + MengineMain.runLatch(); } public static boolean isKeyEventHasText(KeyEvent event) { @@ -187,17 +196,17 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { } if (action == KeyEvent.ACTION_DOWN) { - MengineActivity.AndroidPlatform_keyEvent(true, keyCode, repeatCount); + MengineNative.AndroidPlatform_keyEvent(true, keyCode, repeatCount); if (MengineSurfaceView.isKeyEventHasText(event) == true) { int unicode = event.getUnicodeChar(); - MengineActivity.AndroidPlatform_textEvent(unicode); + MengineNative.AndroidPlatform_textEvent(unicode); } return true; } else if (action == KeyEvent.ACTION_UP) { - MengineActivity.AndroidPlatform_keyEvent(false, keyCode, repeatCount); + MengineNative.AndroidPlatform_keyEvent(false, keyCode, repeatCount); return true; } @@ -215,7 +224,7 @@ protected void nativeTouchEvent(MotionEvent event, int index, int action) { float yn = y / m_surfaceHeight; float pn = Math.min(p, 1.f); - MengineActivity.AndroidPlatform_touchEvent(action, pointerId, xn, yn, pn); + MengineNative.AndroidPlatform_touchEvent(action, pointerId, xn, yn, pn); } @Override @@ -273,7 +282,7 @@ public void onSensorChanged(SensorEvent event) { float yn = y / SensorManager.GRAVITY_EARTH; float zn = z / SensorManager.GRAVITY_EARTH; - MengineActivity.AndroidPlatform_accelerationEvent(xn, yn, zn); + MengineNative.AndroidPlatform_accelerationEvent(xn, yn, zn); }break; case Sensor.TYPE_LINEAR_ACCELERATION: { //AndroidPlatform_accelerationEvent(xn, yn, zn); diff --git a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineUtils.java b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineUtils.java index ed4c3f184a..9b8f3a9b4f 100644 --- a/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineUtils.java +++ b/gradle/libraries/Mengine/src/main/java/org/Mengine/Base/MengineUtils.java @@ -11,6 +11,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.Rect; import android.graphics.Typeface; import android.net.Uri; @@ -182,7 +183,7 @@ public static Handler performOnMainThreadDelayed(Runnable runnable, long delayMi return handler; } - public static Timer scheduleAtFixedRate(Activity activity, long period, Runnable runnable) { + public static Timer scheduleOnUiAtFixedRate(Activity activity, long period, Runnable runnable) { Timer timer = new Timer(); TimerTask task = new TimerTask() { @@ -895,4 +896,28 @@ public static Rect getDeviceWindowRect(Context context, Display display) return new Rect(0, 0, width, height); } } + + public static int getDeviceScreenSize(Context context) { + Resources resources = context.getResources(); + Configuration configuration = resources.getConfiguration(); + int screenLayout = configuration.screenLayout; + + int screenLayoutSize = screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; + + return screenLayoutSize; + } + + public static boolean isDeviceTablet(Context context) { + int screenLayoutSize = MengineUtils.getDeviceScreenSize(context); + + if (screenLayoutSize == Configuration.SCREENLAYOUT_SIZE_LARGE || screenLayoutSize == Configuration.SCREENLAYOUT_SIZE_XLARGE) { + return true; + } + + return false; + } + + public static boolean isDebuggerConnected() { + return android.os.Debug.isDebuggerConnected(); + } } diff --git a/gradle/plugins/AppLovin/NonetBanners/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBanners.java b/gradle/plugins/AppLovin/NonetBanners/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBanners.java index 57f1b95f8a..c18ea5af7c 100644 --- a/gradle/plugins/AppLovin/NonetBanners/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBanners.java +++ b/gradle/plugins/AppLovin/NonetBanners/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBanners.java @@ -12,6 +12,7 @@ import androidx.core.content.res.ResourcesCompat; import org.Mengine.Base.MengineActivity; +import org.Mengine.Base.MengineApplication; import org.Mengine.Base.MenginePluginInvalidInitializeException; import org.Mengine.Base.MengineUtils; import org.xmlpull.v1.XmlPullParser; @@ -44,7 +45,7 @@ class NonetBanner { protected Timer m_refreshTimer; @Override - public void initializeNonetBanners(MengineActivity activity, MengineAppLovinPlugin plugin) throws MenginePluginInvalidInitializeException { + public void onAppCreate(MengineApplication application, MengineAppLovinPlugin plugin) throws MenginePluginInvalidInitializeException { m_plugin = plugin; m_banners = new ArrayList<>(); @@ -52,9 +53,9 @@ public void initializeNonetBanners(MengineActivity activity, MengineAppLovinPlug m_visible = false; m_requestId = 0; - this.m_plugin.logMessage("[NONET_BANNER] initialize"); + m_plugin.logMessage("[NONET_BANNER] initialize"); - Resources resources = activity.getResources(); + Resources resources = application.getResources(); int MengineAppLovinPlugin_NonetBannerDurationTime = resources.getInteger(R.integer.mengine_applovin_nonet_banner_duration_time); @@ -78,7 +79,7 @@ public void initializeNonetBanners(MengineActivity activity, MengineAppLovinPlug Map attributes = new HashMap<>(); - for(int index = 0; index != attributeCount; ++index) { + for (int index = 0; index != attributeCount; ++index) { String key = parser.getAttributeName(index); String value = parser.getAttributeValue(index); @@ -88,7 +89,7 @@ public void initializeNonetBanners(MengineActivity activity, MengineAppLovinPlug String image = attributes.get("image"); String url = attributes.get("url"); - this.addNonetBanner(activity, image, url); + this.addNonetBanner(application, image, url); } } catch (final XmlPullParserException e) { m_plugin.logError("[NONET_BANNER] XmlPullParserException: %s" @@ -103,12 +104,22 @@ public void initializeNonetBanners(MengineActivity activity, MengineAppLovinPlug return; } + } + + @Override + public void onAppTerminate(MengineApplication application, MengineAppLovinPlugin plugin) { + m_banners = null; + + m_plugin = null; + } + @Override + public void onCreate(MengineActivity activity) throws MenginePluginInvalidInitializeException { if (m_banners.isEmpty() == true) { return; } - Timer refreshTimer = MengineUtils.scheduleAtFixedRate(activity, m_showBannerDurationTime, () -> { + Timer refreshTimer = MengineUtils.scheduleOnUiAtFixedRate(activity, m_showBannerDurationTime, () -> { int refreshRequestId; String oldBanenrUrl; String newBannerUrl; @@ -153,12 +164,35 @@ public void initializeNonetBanners(MengineActivity activity, MengineAppLovinPlug }); m_refreshTimer = refreshTimer; + + if (m_visible == true) { + this.show(); + } + } + + @Override + public void onDestroy() { + if (m_refreshTimer != null) { + m_refreshTimer.cancel(); + m_refreshTimer = null; + } + + synchronized (this) { + if (m_showBanner != null) { + MengineActivity activity = m_plugin.getMengineActivity(); + + ViewGroup viewGroup = activity.getContentViewGroup(); + viewGroup.removeView(m_showBanner.view); + + m_showBanner = null; + } + } } - protected void addNonetBanner(MengineActivity activity, String image, String url) { - Resources resources = activity.getResources(); - Context context = activity.getBaseContext(); - String packageName = activity.getPackageName(); + protected void addNonetBanner(MengineApplication application, String image, String url) { + Resources resources = application.getResources(); + Context context = application.getBaseContext(); + String packageName = application.getPackageName(); int resId = resources.getIdentifier(image, "drawable", packageName); @@ -210,26 +244,6 @@ public void onClick(View v) { m_banners.add(banner); } - @Override - public void finalizeNonetBanners(MengineActivity activity, MengineAppLovinPlugin plugin) { - if (m_refreshTimer != null) { - m_refreshTimer.cancel(); - m_refreshTimer = null; - } - - synchronized (this) { - if (m_showBanner != null) { - ViewGroup viewGroup = activity.getContentViewGroup(); - viewGroup.removeView(m_showBanner.view); - - m_showBanner = null; - } - } - - m_plugin = null; - m_banners = null; - } - protected NonetBanner getCurrentBanner() { long timestamp = MengineUtils.getTimestamp(); timestamp /= m_showBannerDurationTime; diff --git a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBanner.java b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBanner.java index 8080a93096..942df7b045 100644 --- a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBanner.java +++ b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBanner.java @@ -23,6 +23,8 @@ import java.util.Map; public class MengineAppLovinBanner extends MengineAppLovinBase implements MaxAdRequestListener, MaxAdViewAdListener, MaxAdRevenueListener, MaxAdReviewListener { + protected final String m_placement; + protected MaxAdView m_adView; protected volatile boolean m_visible; @@ -31,14 +33,19 @@ public class MengineAppLovinBanner extends MengineAppLovinBase implements MaxAdR public MengineAppLovinBanner(MengineAppLovinPlugin plugin, String adUnitId, String placement) { super(MaxAdFormat.BANNER, plugin, adUnitId); + m_placement = placement; + m_visible = false; m_loaded = false; + } - MengineActivity activity = plugin.getMengineActivity(); + @Override + public void onCreate(MengineActivity activity) { + super.onCreate(activity); - MaxAdView adView = new MaxAdView(adUnitId, activity); + MaxAdView adView = new MaxAdView(m_adUnitId, activity); - adView.setPlacement(placement); + adView.setPlacement(m_placement); adView.setListener(this); adView.setRequestListener(this); @@ -59,24 +66,29 @@ public MengineAppLovinBanner(MengineAppLovinPlugin plugin, String adUnitId, Stri adView.setExtraParameter("adaptive_banner", "true"); adView.setVisibility(View.GONE); - adView.stopAutoRefresh(); + + if (m_visible == false) { + adView.stopAutoRefresh(); + } else { + adView.startAutoRefresh(); + } m_adView = adView; m_plugin.logMessage("[%s] create adUnitId: %s placement: %s size: [%d, %d]" , m_adFormat.getLabel() - , adUnitId - , placement + , m_adUnitId + , m_placement , widthPx , heightPx ); - m_plugin.setState("applovin.banner.state." + adUnitId, "init"); + m_plugin.setState("applovin.banner.state." + m_adUnitId, "init"); MengineAppLovinMediationInterface mediationAmazon = m_plugin.getMediationAmazon(); if (mediationAmazon != null) { - mediationAmazon.initializeMediatorBanner(activity, plugin, adView, () -> { + mediationAmazon.initializeMediatorBanner(activity, m_plugin, adView, () -> { MengineAppLovinBanner.this.loadAd(); }); } else { @@ -86,8 +98,8 @@ public MengineAppLovinBanner(MengineAppLovinPlugin plugin, String adUnitId, Stri } @Override - public void destroy() { - super.destroy(); + public void onDestroy() { + super.onDestroy(); if (m_adView != null) { m_adView.setListener(null); @@ -187,45 +199,47 @@ protected void disableAdView(@NonNull MaxAdView adView) { viewGroup.removeView(adView); } - public boolean bannerVisible(boolean show) { - MaxAdView copy_adView = m_adView; - - m_plugin.runOnUiThread(() -> { - if (m_visible == show) { - return; - } + private void updateVisible() { + MengineAppLovinBanner.this.log("bannerVisible", Map.of("show", m_visible)); - m_visible = show; - - MengineAppLovinBanner.this.log("bannerVisible", Map.of("show", show)); - - MengineAppLovinNonetBannersInterface nonetBanners = m_plugin.getNonetBanners(); + MengineAppLovinNonetBannersInterface nonetBanners = m_plugin.getNonetBanners(); - if (show == true) { - if (nonetBanners != null) { - if (m_loaded == true) { - nonetBanners.hide(); + if (m_visible == true) { + if (nonetBanners != null) { + if (m_loaded == true) { + nonetBanners.hide(); - if (copy_adView != null) { - MengineAppLovinBanner.this.enableAdView(copy_adView); - } - } else { - nonetBanners.show(); + if (m_adView != null) { + MengineAppLovinBanner.this.enableAdView(m_adView); } } else { - if (copy_adView != null) { - MengineAppLovinBanner.this.enableAdView(copy_adView); - } + nonetBanners.show(); } } else { - if (copy_adView != null) { - MengineAppLovinBanner.this.disableAdView(copy_adView); + if (m_adView != null) { + MengineAppLovinBanner.this.enableAdView(m_adView); } + } + } else { + if (m_adView != null) { + MengineAppLovinBanner.this.disableAdView(m_adView); + } - if (nonetBanners != null) { - nonetBanners.hide(); - } + if (nonetBanners != null) { + nonetBanners.hide(); } + } + } + + public boolean bannerVisible(boolean show) { + m_plugin.runOnUiThread(() -> { + if (m_visible == show) { + return; + } + + m_visible = show; + + MengineAppLovinBanner.this.updateVisible(); }); return true; diff --git a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBase.java b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBase.java index 35df4b9d7d..80720c9e66 100644 --- a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBase.java +++ b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinBase.java @@ -13,6 +13,7 @@ import com.applovin.mediation.MaxReward; import com.applovin.sdk.AppLovinSdkUtils; +import org.Mengine.Base.MengineActivity; import org.Mengine.Base.MengineAnalyticsEventBuilder; import org.Mengine.Base.MengineUtils; @@ -41,8 +42,11 @@ public MengineAppLovinBase(MaxAdFormat adFormat, MengineAppLovinPlugin plugin, S m_requestId = 0; } - public void destroy() { - m_plugin = null; + public void onCreate(MengineActivity activity) { + //Empty + } + + public void onDestroy() { } public void loadAd() { diff --git a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinInterstitial.java b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinInterstitial.java index 18a58d6fd8..62051996f9 100644 --- a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinInterstitial.java +++ b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinInterstitial.java @@ -24,9 +24,14 @@ public class MengineAppLovinInterstitial extends MengineAppLovinBase implements public MengineAppLovinInterstitial(MengineAppLovinPlugin plugin, String adUnitId) { super(MaxAdFormat.INTERSTITIAL, plugin, adUnitId); - MengineActivity activity = m_plugin.getMengineActivity(); + //Empty + } + + @Override + public void onCreate(MengineActivity activity) { + super.onCreate(activity); - MaxInterstitialAd interstitialAd = new MaxInterstitialAd(adUnitId, activity); + MaxInterstitialAd interstitialAd = new MaxInterstitialAd(m_adUnitId, activity); interstitialAd.setListener(this); interstitialAd.setRequestListener(this); @@ -38,7 +43,7 @@ public MengineAppLovinInterstitial(MengineAppLovinPlugin plugin, String adUnitId m_plugin.logMessage("[%s] create adUnitId: %s" , m_adFormat.getLabel() - , adUnitId + , m_adUnitId ); m_plugin.setState("applovin.interstitial.state." + m_adUnitId, "init"); @@ -46,7 +51,7 @@ public MengineAppLovinInterstitial(MengineAppLovinPlugin plugin, String adUnitId MengineAppLovinMediationInterface mediationAmazon = m_plugin.getMediationAmazon(); if (mediationAmazon != null) { - mediationAmazon.loadMediatorInterstitial(activity, plugin, m_interstitialAd, () -> { + mediationAmazon.loadMediatorInterstitial(activity, m_plugin, m_interstitialAd, () -> { MengineAppLovinInterstitial.this.loadAd(); }); } else { @@ -55,8 +60,8 @@ public MengineAppLovinInterstitial(MengineAppLovinPlugin plugin, String adUnitId } @Override - public void destroy() { - super.destroy(); + public void onDestroy() { + super.onDestroy(); if (m_interstitialAd != null) { m_interstitialAd.destroy(); diff --git a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinMediationInterface.java b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinMediationInterface.java index c71b352d8e..992fc859e2 100644 --- a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinMediationInterface.java +++ b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinMediationInterface.java @@ -1,14 +1,15 @@ package org.Mengine.Plugin.AppLovin; import org.Mengine.Base.MengineActivity; +import org.Mengine.Base.MengineApplication; import com.applovin.mediation.ads.MaxAdView; import com.applovin.mediation.ads.MaxInterstitialAd; import com.applovin.mediation.ads.MaxRewardedAd; public interface MengineAppLovinMediationInterface { - void initializeMediator(MengineActivity activity, MengineAppLovinPlugin plugin); - void finalizeMediator(MengineActivity activity, MengineAppLovinPlugin plugin); + void initializeMediator(MengineApplication application, MengineAppLovinPlugin plugin); + void finalizeMediator(MengineApplication application, MengineAppLovinPlugin plugin); void initializeMediatorBanner(MengineActivity activity, MengineAppLovinPlugin plugin, MaxAdView adView, MengineAppLovinMediationLoadAdCallback loadAdCallback); void loadMediatorInterstitial(MengineActivity activity, MengineAppLovinPlugin plugin, MaxInterstitialAd interstitialAd, MengineAppLovinMediationLoadAdCallback loadAdCallback); diff --git a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBannersInterface.java b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBannersInterface.java index 87fc5e1a00..fe571ce890 100644 --- a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBannersInterface.java +++ b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinNonetBannersInterface.java @@ -1,11 +1,15 @@ package org.Mengine.Plugin.AppLovin; import org.Mengine.Base.MengineActivity; +import org.Mengine.Base.MengineApplication; import org.Mengine.Base.MenginePluginInvalidInitializeException; public interface MengineAppLovinNonetBannersInterface { - void initializeNonetBanners(MengineActivity activity, MengineAppLovinPlugin plugin) throws MenginePluginInvalidInitializeException; - void finalizeNonetBanners(MengineActivity activity, MengineAppLovinPlugin plugin); + void onAppCreate(MengineApplication application, MengineAppLovinPlugin plugin) throws MenginePluginInvalidInitializeException; + void onAppTerminate(MengineApplication application, MengineAppLovinPlugin plugin); + + void onCreate(MengineActivity activity) throws MenginePluginInvalidInitializeException; + void onDestroy(); void show(); void hide(); diff --git a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinPlugin.java b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinPlugin.java index 0da4a8f388..6e9e708571 100644 --- a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinPlugin.java +++ b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinPlugin.java @@ -20,18 +20,20 @@ import org.Mengine.Base.MengineAdFormat; import org.Mengine.Base.MengineAdMediation; import org.Mengine.Base.MengineAdRevenueParam; +import org.Mengine.Base.MenginePluginApplicationListener; import org.Mengine.Base.MengineTransparencyConsentParam; import org.Mengine.Base.MengineApplication; import org.Mengine.Base.MenginePlugin; import org.Mengine.Base.MenginePluginActivityListener; import org.Mengine.Base.MenginePluginEngineListener; import org.Mengine.Base.MenginePluginInvalidInitializeException; +import org.Mengine.Base.MengineUtils; import java.util.HashMap; import java.util.List; import java.util.Map; -public class MengineAppLovinPlugin extends MenginePlugin implements MenginePluginActivityListener, MenginePluginEngineListener { +public class MengineAppLovinPlugin extends MenginePlugin implements MenginePluginApplicationListener, MenginePluginActivityListener, MenginePluginEngineListener { public static final String PLUGIN_NAME = "MengineAppLovin"; public static final boolean PLUGIN_EMBEDDING = true; @@ -52,12 +54,13 @@ public class MengineAppLovinPlugin extends MenginePlugin implements MenginePlugi private MengineAppLovinNonetBannersInterface m_nonetBanners; @Override - public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException { + public void onAppCreate(MengineApplication application) throws MenginePluginInvalidInitializeException { m_banners = new HashMap<>(); m_interstitials = new HashMap<>(); m_rewardeds = new HashMap<>(); - AppLovinSdk appLovinSdk = AppLovinSdk.getInstance(activity); + AppLovinSdk appLovinSdk = AppLovinSdk.getInstance(application); + AppLovinSdkSettings settings = appLovinSdk.getSettings(); String MengineAppLovinPlugin_CCPA = this.getMetaDataString(PLUGIN_METADATA_CCPA); @@ -68,9 +71,9 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws ); if (MengineAppLovinPlugin_CCPA.equalsIgnoreCase("YES") == true) { - AppLovinPrivacySettings.setDoNotSell(true, activity); + AppLovinPrivacySettings.setDoNotSell(true, application); } else if (MengineAppLovinPlugin_CCPA.equalsIgnoreCase("NO") == true) { - AppLovinPrivacySettings.setDoNotSell(false, activity); + AppLovinPrivacySettings.setDoNotSell(false, application); } else if (MengineAppLovinPlugin_CCPA.equalsIgnoreCase("UNKNOWN") == true) { // Nothing } else { @@ -118,8 +121,6 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws settings.setCreativeDebuggerEnabled(false); } - MengineApplication application = this.getMengineApplication(); - String sessionId = application.getSessionId(); settings.setUserIdentifier(sessionId); @@ -127,10 +128,10 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws this.logMessage("%s: %s" , PLUGIN_METADATA_SDK_KEY - , MengineAppLovinPlugin_SdkKey + , MengineUtils.getDebugValue(MengineAppLovinPlugin_SdkKey, "[REDACTED]") ); - AppLovinSdkInitializationConfiguration config = AppLovinSdkInitializationConfiguration.builder(MengineAppLovinPlugin_SdkKey, activity) + AppLovinSdkInitializationConfiguration config = AppLovinSdkInitializationConfiguration.builder(MengineAppLovinPlugin_SdkKey, application) .setMediationProvider( AppLovinMediationProvider.MAX ) .build(); @@ -162,7 +163,7 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws ); } - MengineTransparencyConsentParam consent = activity.makeTransparencyConsentParam(); + MengineTransparencyConsentParam consent = application.makeTransparencyConsentParam(); application.onMengineTransparencyConsent(consent); @@ -178,7 +179,7 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MengineAppLovinMediationInterface mediationAmazon = this.newInstance("org.Mengine.Plugin.AppLovin.MengineAppLovinMediationAmazon", false); if (mediationAmazon != null) { - mediationAmazon.initializeMediator(activity, this); + mediationAmazon.initializeMediator(application, this); m_mediationAmazon = mediationAmazon; } else { @@ -188,7 +189,7 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MengineAppLovinNonetBannersInterface nonetBanners = this.newInstance("org.Mengine.Plugin.AppLovin.MengineAppLovinNonetBanners", false); if (nonetBanners != null) { - nonetBanners.initializeNonetBanners(activity, this); + nonetBanners.onAppCreate(application, this); m_nonetBanners = nonetBanners; } else { @@ -197,42 +198,73 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws } @Override - public void onDestroy(MengineActivity activity) { + public void onAppTerminate(MengineApplication application) { if (m_mediationAmazon != null) { - m_mediationAmazon.finalizeMediator(activity, this); + m_mediationAmazon.finalizeMediator(application, this); m_mediationAmazon = null; } + m_banners = null; + m_interstitials = null; + m_rewardeds = null; + + if (m_nonetBanners != null) { + m_nonetBanners.onAppTerminate(application, this); + m_nonetBanners = null; + } + } + + @Override + public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException { + if (m_nonetBanners != null) { + m_nonetBanners.onCreate(activity); + } + if (m_banners != null) { for (MengineAppLovinBanner banner : m_banners.values()) { - banner.destroy(); + banner.onCreate(activity); } - - m_banners = null; } if (m_interstitials != null) { for (MengineAppLovinInterstitial interstitial : m_interstitials.values()) { - interstitial.destroy(); + interstitial.onCreate(activity); } - - m_interstitials = null; } if (m_rewardeds != null) { for (MengineAppLovinRewarded rewarded : m_rewardeds.values()) { - rewarded.destroy(); + rewarded.onCreate(activity); + } + } + } + + @Override + public void onDestroy(MengineActivity activity) { + if (m_banners != null) { + for (MengineAppLovinBanner banner : m_banners.values()) { + banner.onDestroy(); + } + } + + if (m_interstitials != null) { + for (MengineAppLovinInterstitial interstitial : m_interstitials.values()) { + interstitial.onDestroy(); } + } - m_rewardeds = null; + if (m_rewardeds != null) { + for (MengineAppLovinRewarded rewarded : m_rewardeds.values()) { + rewarded.onDestroy(); + } } if (m_nonetBanners != null) { - m_nonetBanners.finalizeNonetBanners(activity, this); - m_nonetBanners = null; + m_nonetBanners.onDestroy(); } } + public MengineAppLovinMediationInterface getMediationAmazon() { return m_mediationAmazon; } @@ -256,6 +288,12 @@ public boolean initBanner(String adUnitId, String placement) { try { MengineAppLovinBanner banner = new MengineAppLovinBanner(this, adUnitId, placement); + MengineActivity activity = this.getMengineActivity(); + + if (activity != null) { + banner.onCreate(activity); + } + m_banners.put(adUnitId, banner); } catch (final Exception e) { this.logError("[ERROR] initBanner adUnitId: %s placement: %s catch exception: %s" @@ -319,6 +357,12 @@ public boolean initInterstitial(String adUnitId) { try { MengineAppLovinInterstitial interstitial = new MengineAppLovinInterstitial(this, adUnitId); + MengineActivity activity = this.getMengineActivity(); + + if (activity != null) { + interstitial.onCreate(activity); + } + m_interstitials.put(adUnitId, interstitial); } catch (final Exception e) { this.logError("[ERROR] initInterstitial adUnitId: %s catch exception: %s" @@ -385,6 +429,12 @@ public boolean initRewarded(String adUnitId) { try { MengineAppLovinRewarded rewarded = new MengineAppLovinRewarded(this, adUnitId); + MengineActivity activity = this.getMengineActivity(); + + if (activity != null) { + rewarded.onCreate(activity); + } + m_rewardeds.put(adUnitId, rewarded); } catch (final Exception e) { this.logError("[ERROR] initRewarded adUnitId: %s catch exception: %s" diff --git a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinRewarded.java b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinRewarded.java index 0cf2aa0567..f6f044cce3 100644 --- a/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinRewarded.java +++ b/gradle/plugins/AppLovin/src/main/java/org/Mengine/Plugin/AppLovin/MengineAppLovinRewarded.java @@ -25,9 +25,14 @@ public class MengineAppLovinRewarded extends MengineAppLovinBase implements MaxA public MengineAppLovinRewarded(MengineAppLovinPlugin plugin, String adUnitId) { super(MaxAdFormat.REWARDED, plugin, adUnitId); - MengineActivity activity = m_plugin.getMengineActivity(); + //Empty + } + + @Override + public void onCreate(MengineActivity activity) { + super.onCreate(activity); - MaxRewardedAd rewardedAd = MaxRewardedAd.getInstance(adUnitId, activity); + MaxRewardedAd rewardedAd = MaxRewardedAd.getInstance(m_adUnitId, activity); rewardedAd.setListener(this); rewardedAd.setRequestListener(this); @@ -39,7 +44,7 @@ public MengineAppLovinRewarded(MengineAppLovinPlugin plugin, String adUnitId) { m_plugin.logMessage("[%s] create adUnitId: %s" , m_adFormat.getLabel() - , adUnitId + , m_adUnitId ); m_plugin.setState("applovin.rewarded.state." + m_adUnitId, "init"); @@ -47,7 +52,7 @@ public MengineAppLovinRewarded(MengineAppLovinPlugin plugin, String adUnitId) { MengineAppLovinMediationInterface mediationAmazon = m_plugin.getMediationAmazon(); if (mediationAmazon != null) { - mediationAmazon.loadMediatorRewarded(activity, plugin, m_rewardedAd, () -> { + mediationAmazon.loadMediatorRewarded(activity, m_plugin, m_rewardedAd, () -> { MengineAppLovinRewarded.this.loadAd(); }); } else { @@ -56,8 +61,8 @@ public MengineAppLovinRewarded(MengineAppLovinPlugin plugin, String adUnitId) { } @Override - public void destroy() { - super.destroy(); + public void onDestroy() { + super.onDestroy(); if (m_rewardedAd != null) { m_rewardedAd.destroy(); diff --git a/gradle/plugins/Facebook/src/main/java/org/Mengine/Plugin/Facebook/MengineFacebookPlugin.java b/gradle/plugins/Facebook/src/main/java/org/Mengine/Plugin/Facebook/MengineFacebookPlugin.java index 3df8399c06..59980d5d36 100644 --- a/gradle/plugins/Facebook/src/main/java/org/Mengine/Plugin/Facebook/MengineFacebookPlugin.java +++ b/gradle/plugins/Facebook/src/main/java/org/Mengine/Plugin/Facebook/MengineFacebookPlugin.java @@ -44,7 +44,7 @@ import java.util.List; import java.util.Map; -public class MengineFacebookPlugin extends MenginePlugin implements MenginePluginAnalyticsListener, MenginePluginApplicationListener, MenginePluginRemoteMessageListener, MenginePluginActivityListener, MenginePluginPushTokenListener, MenginePluginSessionIdListener { +public class MengineFacebookPlugin extends MenginePlugin implements MenginePluginAnalyticsListener, MenginePluginApplicationListener, MenginePluginRemoteMessageListener, MenginePluginPushTokenListener, MenginePluginSessionIdListener { public static final String PLUGIN_NAME = "MengineFacebook"; public static final boolean PLUGIN_EMBEDDING = true; @@ -68,10 +68,7 @@ public void onAppCreate(MengineApplication application) throws MenginePluginInva , e.getMessage() ); } - } - @Override - public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException { if (BuildConfig.DEBUG == true) { FacebookSdk.setIsDebugEnabled(true); @@ -79,7 +76,7 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws FacebookSdk.addLoggingBehavior(LoggingBehavior.DEVELOPER_ERRORS); } - LoginManager.getInstance().retrieveLoginStatus(activity, new LoginStatusCallback() { + LoginManager.getInstance().retrieveLoginStatus(application, new LoginStatusCallback() { @Override public void onCompleted(@NonNull AccessToken accessToken) { MengineFacebookPlugin.this.logMessage("retrieve login [onCompleted] application: %s user: %s token: %s" @@ -180,14 +177,15 @@ public void onError(@NonNull FacebookException e) { } }); - String sessionId = activity.getSessionId(); + String sessionId = application.getSessionId(); AppEventsLogger.setUserID(sessionId); - m_logger = AppEventsLogger.newLogger(activity); + AppEventsLogger logger = AppEventsLogger.newLogger(application); + m_logger = logger; } @Override - public void onDestroy(MengineActivity activity) { + public void onAppTerminate(MengineApplication application) { if (m_logger != null) { m_logger.flush(); m_logger = null; diff --git a/gradle/plugins/Firebase/firebase.gradle b/gradle/plugins/Firebase/firebase.gradle index b11cb5a6db..82a9d46f69 100644 --- a/gradle/plugins/Firebase/firebase.gradle +++ b/gradle/plugins/Firebase/firebase.gradle @@ -1,3 +1,3 @@ dependencies { - implementation platform('com.google.firebase:firebase-bom:33.5.1') + implementation platform('com.google.firebase:firebase-bom:33.6.0') } \ No newline at end of file diff --git a/gradle/plugins/FirebaseCrashlytics/src/main/java/org/Mengine/Plugin/FirebaseCrashlytics/MengineFirebaseCrashlyticsPlugin.java b/gradle/plugins/FirebaseCrashlytics/src/main/java/org/Mengine/Plugin/FirebaseCrashlytics/MengineFirebaseCrashlyticsPlugin.java index bc3db028ad..43a03ffce1 100644 --- a/gradle/plugins/FirebaseCrashlytics/src/main/java/org/Mengine/Plugin/FirebaseCrashlytics/MengineFirebaseCrashlyticsPlugin.java +++ b/gradle/plugins/FirebaseCrashlytics/src/main/java/org/Mengine/Plugin/FirebaseCrashlytics/MengineFirebaseCrashlyticsPlugin.java @@ -9,6 +9,7 @@ import org.Mengine.Base.MengineApplication; import org.Mengine.Base.MengineFatalErrorException; import org.Mengine.Base.MengineLog; +import org.Mengine.Base.MengineNative; import org.Mengine.Base.MenginePlugin; import org.Mengine.Base.MenginePluginActivityListener; import org.Mengine.Base.MenginePluginApplicationListener; @@ -27,8 +28,9 @@ public void onAppInit(MengineApplication application, boolean isMainProcess) thr FirebaseCrashlytics.getInstance().setCustomKey("is_dev", BuildConfig.DEBUG); boolean isBuildPublish = application.isBuildPublish(); + boolean isDebuggerConnected = MengineUtils.isDebuggerConnected(); - if (isBuildPublish == false && android.os.Debug.isDebuggerConnected() == false) { + if (isBuildPublish == false && isDebuggerConnected == false) { FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false); } } @@ -46,6 +48,14 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MengineUtils.makeToastDelayed(activity, "Last launch ended in a crash", 10000L); } } + + boolean isFirebaseCrashlyticsForceCrash = this.hasOption("firebase.crashlytics.forcecrash"); + + if (isFirebaseCrashlyticsForceCrash == true) { + MengineUtils.performOnMainThreadDelayed(() -> { + MengineFirebaseCrashlyticsPlugin.this.testCrash(); + }, 5000L); + } } @Override @@ -121,7 +131,7 @@ public void testCrash() { this.setCustomKey("test.crash", true); - throw new RuntimeException("Firebase Crashlytics Test Crash"); + MengineNative.AndroidMain_crash("Android test crash"); } @Override diff --git a/gradle/plugins/FirebasePerformanceMonitoring/src/main/java/org/Mengine/Plugin/FirebasePerformanceMonitoring/MengineFirebasePerformanceMonitoringPlugin.java b/gradle/plugins/FirebasePerformanceMonitoring/src/main/java/org/Mengine/Plugin/FirebasePerformanceMonitoring/MengineFirebasePerformanceMonitoringPlugin.java index 832c090910..82548396c6 100644 --- a/gradle/plugins/FirebasePerformanceMonitoring/src/main/java/org/Mengine/Plugin/FirebasePerformanceMonitoring/MengineFirebasePerformanceMonitoringPlugin.java +++ b/gradle/plugins/FirebasePerformanceMonitoring/src/main/java/org/Mengine/Plugin/FirebasePerformanceMonitoring/MengineFirebasePerformanceMonitoringPlugin.java @@ -32,7 +32,7 @@ public void onAppTerminate(MengineApplication application) { } @Override - public void onMenginePlatformRun(MengineActivity activity) { + public void onMenginePlatformRun(MengineApplication activity) { m_startupTrace.stop(); } } diff --git a/gradle/plugins/GoogleConsent/build.gradle b/gradle/plugins/GoogleConsent/build.gradle index a14bd4ed4e..df08a078b4 100644 --- a/gradle/plugins/GoogleConsent/build.gradle +++ b/gradle/plugins/GoogleConsent/build.gradle @@ -6,6 +6,5 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.ump:user-messaging-platform:2.2.0' } \ No newline at end of file diff --git a/gradle/plugins/GoogleGameSocial/src/main/java/org/Mengine/Plugin/GoogleGameSocial/MengineGoogleGameSocialPlugin.java b/gradle/plugins/GoogleGameSocial/src/main/java/org/Mengine/Plugin/GoogleGameSocial/MengineGoogleGameSocialPlugin.java index 19eb889dc7..14bbbd1d43 100644 --- a/gradle/plugins/GoogleGameSocial/src/main/java/org/Mengine/Plugin/GoogleGameSocial/MengineGoogleGameSocialPlugin.java +++ b/gradle/plugins/GoogleGameSocial/src/main/java/org/Mengine/Plugin/GoogleGameSocial/MengineGoogleGameSocialPlugin.java @@ -8,6 +8,7 @@ import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; +import com.google.android.gms.games.AchievementsClient; import com.google.android.gms.games.GamesSignInClient; import com.google.android.gms.games.PlayGames; import com.google.android.gms.games.PlayGamesSdk; @@ -16,11 +17,12 @@ import org.Mengine.Base.MengineApplication; import org.Mengine.Base.MenginePlugin; import org.Mengine.Base.MenginePluginActivityListener; +import org.Mengine.Base.MenginePluginApplicationListener; import org.Mengine.Base.MenginePluginInvalidInitializeException; import org.Mengine.Plugin.GoogleService.MengineGoogleServicePlugin; -public class MengineGoogleGameSocialPlugin extends MenginePlugin implements MenginePluginActivityListener { +public class MengineGoogleGameSocialPlugin extends MenginePlugin implements MenginePluginApplicationListener, MenginePluginActivityListener { public static final String PLUGIN_NAME = "MengineGGameSocial"; public static final boolean PLUGIN_EMBEDDING = true; @@ -36,9 +38,12 @@ public boolean onAvailable(MengineApplication application) { } @Override - public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException { - PlayGamesSdk.initialize(activity); + public void onAppCreate(MengineApplication application) throws MenginePluginInvalidInitializeException { + PlayGamesSdk.initialize(application); + } + @Override + public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException { GamesSignInClient gamesSignInClient = PlayGames.getGamesSignInClient(activity); gamesSignInClient.isAuthenticated().addOnCompleteListener(isAuthenticatedTask -> { @@ -70,14 +75,24 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws m_achievementLauncher = achievementLauncher; } + @Override + public void onDestroy(MengineActivity activity) { + if (m_achievementLauncher != null) { + m_achievementLauncher.unregister(); + + m_achievementLauncher = null; + } + } + public boolean showAchievements() { this.logMessage("showAchievements"); this.runOnUiThread(() -> { MengineActivity activity = this.getMengineActivity(); - PlayGames.getAchievementsClient(activity) - .getAchievementsIntent() + AchievementsClient achievementsClient = PlayGames.getAchievementsClient(activity); + + achievementsClient.getAchievementsIntent() .addOnSuccessListener(intent -> { MengineGoogleGameSocialPlugin.this.logMessageRelease("get achievements successful"); @@ -105,7 +120,9 @@ public boolean unlockAchievement(String achievementId) { this.runOnUiThread(() -> { MengineActivity activity = this.getMengineActivity(); - PlayGames.getAchievementsClient(activity).unlockImmediate(achievementId) + AchievementsClient achievementsClient = PlayGames.getAchievementsClient(activity); + + achievementsClient.unlockImmediate(achievementId) .addOnSuccessListener(unused -> { MengineGoogleGameSocialPlugin.this.logMessage("unlockAchievement complete achievementId: %s" , achievementId @@ -135,7 +152,9 @@ public boolean incrementAchievement(String achievementId, int numSteps) { this.runOnUiThread(() -> { MengineActivity activity = this.getMengineActivity(); - PlayGames.getAchievementsClient(activity).incrementImmediate(achievementId, numSteps) + AchievementsClient achievementsClient = PlayGames.getAchievementsClient(activity); + + achievementsClient.incrementImmediate(achievementId, numSteps) .addOnSuccessListener(aBoolean -> { MengineGoogleGameSocialPlugin.this.logMessage("incrementAchievement complete achievementId: %s numSteps: %d" , achievementId @@ -165,7 +184,9 @@ public boolean revealAchievement(String achievementId) { this.runOnUiThread(() -> { MengineActivity activity = this.getMengineActivity(); - PlayGames.getAchievementsClient(activity).revealImmediate(achievementId) + AchievementsClient achievementsClient = PlayGames.getAchievementsClient(activity); + + achievementsClient.revealImmediate(achievementId) .addOnSuccessListener(unused -> { MengineGoogleGameSocialPlugin.this.logMessage("revealAchievement complete achievementId: %s" , achievementId diff --git a/gradle/plugins/GoogleInAppReviews/src/main/java/org/Mengine/Plugin/GoogleInAppReviews/MengineGoogleInAppReviewsPlugin.java b/gradle/plugins/GoogleInAppReviews/src/main/java/org/Mengine/Plugin/GoogleInAppReviews/MengineGoogleInAppReviewsPlugin.java index e69673de1f..346b54b5f7 100644 --- a/gradle/plugins/GoogleInAppReviews/src/main/java/org/Mengine/Plugin/GoogleInAppReviews/MengineGoogleInAppReviewsPlugin.java +++ b/gradle/plugins/GoogleInAppReviews/src/main/java/org/Mengine/Plugin/GoogleInAppReviews/MengineGoogleInAppReviewsPlugin.java @@ -44,6 +44,12 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws }); } + @Override + public void onDestroy(MengineActivity activity) { + m_manager = null; + m_reviewInfo = null; + } + public void launchTheInAppReview() { if (m_reviewInfo == null) { this.logError("[ERROR] reviewInfo == null"); diff --git a/gradle/plugins/GooglePlayBilling/src/main/java/org/Mengine/Plugin/GooglePlayBilling/MengineGooglePlayBillingPlugin.java b/gradle/plugins/GooglePlayBilling/src/main/java/org/Mengine/Plugin/GooglePlayBilling/MengineGooglePlayBillingPlugin.java index 3c4b9e27b0..487849a08a 100644 --- a/gradle/plugins/GooglePlayBilling/src/main/java/org/Mengine/Plugin/GooglePlayBilling/MengineGooglePlayBillingPlugin.java +++ b/gradle/plugins/GooglePlayBilling/src/main/java/org/Mengine/Plugin/GooglePlayBilling/MengineGooglePlayBillingPlugin.java @@ -26,6 +26,7 @@ import org.Mengine.Base.MengineInAppPurchaseParam; import org.Mengine.Base.MenginePlugin; import org.Mengine.Base.MenginePluginActivityListener; +import org.Mengine.Base.MenginePluginApplicationListener; import org.Mengine.Base.MenginePluginInvalidInitializeException; import java.util.ArrayList; @@ -33,7 +34,7 @@ import java.util.List; import java.util.Map; -public class MengineGooglePlayBillingPlugin extends MenginePlugin implements MenginePluginActivityListener { +public class MengineGooglePlayBillingPlugin extends MenginePlugin implements MenginePluginApplicationListener, MenginePluginActivityListener { public static final String PLUGIN_NAME = "MengineGPlayBilling"; public static final boolean PLUGIN_EMBEDDING = true; @@ -41,7 +42,7 @@ public class MengineGooglePlayBillingPlugin extends MenginePlugin implements Men private BillingClient m_billingClient; @Override - public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException { + public void onAppCreate(MengineApplication application) throws MenginePluginInvalidInitializeException { m_productsDetails = new ArrayList<>(); PurchasesUpdatedListener purchasesUpdatedListener = (billingResult, purchases) -> { @@ -145,20 +146,18 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws } }; - Context context = activity.getApplicationContext(); - PendingPurchasesParams pendingPurchasesParams = PendingPurchasesParams.newBuilder() .enableOneTimeProducts() .build(); - m_billingClient = BillingClient.newBuilder(context) + m_billingClient = BillingClient.newBuilder(application) .setListener(purchasesUpdatedListener) .enablePendingPurchases(pendingPurchasesParams) .build(); } @Override - public void onDestroy(MengineActivity activity) { + public void onAppTerminate(MengineApplication application) { m_productsDetails = null; if (m_billingClient != null) { diff --git a/gradle/plugins/SplashScreen/src/main/java/org/Mengine/Plugin/SplashScreen/MengineSplashScreenPlugin.java b/gradle/plugins/SplashScreen/src/main/java/org/Mengine/Plugin/SplashScreen/MengineSplashScreenPlugin.java index 35bcad5207..e966fae916 100644 --- a/gradle/plugins/SplashScreen/src/main/java/org/Mengine/Plugin/SplashScreen/MengineSplashScreenPlugin.java +++ b/gradle/plugins/SplashScreen/src/main/java/org/Mengine/Plugin/SplashScreen/MengineSplashScreenPlugin.java @@ -18,6 +18,8 @@ import androidx.core.content.res.ResourcesCompat; import org.Mengine.Base.MengineActivity; +import org.Mengine.Base.MengineApplication; +import org.Mengine.Base.MengineNative; import org.Mengine.Base.MenginePlugin; import org.Mengine.Base.MenginePluginEngineListener; import org.Mengine.Base.MenginePluginInvalidInitializeException; @@ -34,7 +36,7 @@ public class MengineSplashScreenPlugin extends MenginePlugin implements MengineP private Drawable getDrawableSplashScreen(Context context) { Resources resources = context.getResources(); Resources.Theme theme = context.getTheme(); - Drawable drawable = ResourcesCompat.getDrawable(resources, R.drawable.mengine_splashscreen, theme); + Drawable drawable = ResourcesCompat.getDrawable(resources, R.drawable.mengine_launchscreen, theme); return drawable; } @@ -43,7 +45,14 @@ private ImageView createBackground(Context context) { ImageView image = new ImageView(context); Drawable mengine_splashscreen = this.getDrawableSplashScreen(context); image.setBackground(mengine_splashscreen); - image.setScaleType(ImageView.ScaleType.CENTER_CROP); + + boolean mengine_splashscreen_background_inside = context.getResources().getBoolean(R.bool.mengine_splashscreen_background_inside); + + if (mengine_splashscreen_background_inside == true) { + image.setScaleType(ImageView.ScaleType.CENTER_INSIDE); + } else { + image.setScaleType(ImageView.ScaleType.CENTER_CROP); + } ViewGroup.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); image.setLayoutParams(params); @@ -76,6 +85,14 @@ private TextView createTextSessionId(Context context, String message) { @Override public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException { + MengineApplication application = activity.getMengineApplication(); + + if (application.isMenginePlatformRun() == true) { + this.setState("splashscreen.state", "skip"); + + return; + } + this.setState("splashscreen.state", "init"); ViewGroup viewGroup = activity.getContentViewGroup(); @@ -111,8 +128,27 @@ public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws } @Override - public void onMenginePlatformRun(MengineActivity activity) { + public void onDestroy(MengineActivity activity) { + if (m_image != null) { + m_image.clearAnimation(); + m_image = null; + } + + if (m_text != null) { + m_text.clearAnimation(); + m_text = null; + } + } + + @Override + public void onMenginePlatformRun(MengineApplication application) { MengineUtils.performOnMainThread(() -> { + MengineActivity activity = application.getMengineActivity(); + + if (activity == null) { + return; + } + this.hideSplash(activity); }); } diff --git a/src/Applications/AndroidApplication/AndroidMain.cpp b/src/Applications/AndroidApplication/AndroidMain.cpp index c8acc53d35..2f22d0445b 100644 --- a/src/Applications/AndroidApplication/AndroidMain.cpp +++ b/src/Applications/AndroidApplication/AndroidMain.cpp @@ -3,6 +3,8 @@ #include "AndroidApplication.h" +#include "Kernel/Crash.h" + #include "Config/StdLib.h" #include "Config/New.h" @@ -11,7 +13,7 @@ extern "C" ////////////////////////////////////////////////////////////////////////// static bool already_bootstrapped = false; ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jobject JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidMain_1bootstrap )(JNIEnv * _env, jclass _cls, jstring _nativeLibraryDir, jobjectArray _args) + JNIEXPORT jobject JNICALL MENGINE_JAVA_INTERFACE( AndroidMain_1bootstrap )(JNIEnv * _env, jclass _cls, jstring _nativeLibraryDir, jobjectArray _args) { if( already_bootstrapped == true ) { @@ -66,7 +68,7 @@ extern "C" return nullptr; } - jobject j_application = _env->NewDirectByteBuffer( application, sizeof(Mengine::AndroidApplication) ); + jobject j_application = _env->NewDirectByteBuffer( application, sizeof(void *) ); if ( j_application == nullptr) { @@ -80,7 +82,7 @@ extern "C" return j_application; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jboolean JNICALL MENGINE_MAIN_JAVA_INTERFACE( AndroidMain_1main )(JNIEnv * _env, jclass _cls, jobject _application) + JNIEXPORT jboolean JNICALL MENGINE_JAVA_INTERFACE( AndroidMain_1main )(JNIEnv * _env, jclass _cls, jobject _application) { if( Mengine::Mengine_JNI_SetupThread() == JNI_FALSE ) { @@ -105,11 +107,20 @@ extern "C" return true; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidMain_1destroy )(JNIEnv * _env, jclass _cls, jobject _application) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidMain_1destroy )(JNIEnv * _env, jclass _cls, jobject _application) { Mengine::AndroidApplication * application = (Mengine::AndroidApplication *)_env->GetDirectBufferAddress( _application ); delete application; } ////////////////////////////////////////////////////////////////////////// + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidMain_1crash )(JNIEnv * _env, jclass _cls, jstring _reason) + { + const Mengine::Char * reason_str = _env->GetStringUTFChars( _reason, nullptr ); + + Mengine::Helper::crash( reason_str ); + + _env->ReleaseStringUTFChars( _reason, reason_str ); + } + ////////////////////////////////////////////////////////////////////////// } \ No newline at end of file diff --git a/src/Applications/SDLApplication/SDLApplication.cpp b/src/Applications/SDLApplication/SDLApplication.cpp index e3f6b1420a..a55de28de8 100644 --- a/src/Applications/SDLApplication/SDLApplication.cpp +++ b/src/Applications/SDLApplication/SDLApplication.cpp @@ -47,7 +47,7 @@ namespace Mengine { } ////////////////////////////////////////////////////////////////////////// - bool SDLApplication::initializeOptionsService_( int32_t _argc, const Char ** const _argv ) + bool SDLApplication::initializeOptionsService_( int32_t _argc, Char ** const _argv ) { ArgumentsInterfacePtr arguments = Helper::makeFactorableUnique( MENGINE_DOCUMENT_FUNCTION ); @@ -155,7 +155,7 @@ namespace Mengine #endif } ////////////////////////////////////////////////////////////////////////// - bool SDLApplication::bootstrap( int32_t _argc, const Char ** const _argv ) + bool SDLApplication::bootstrap( int32_t _argc, Char ** const _argv ) { #if defined(MENGINE_PLUGIN_MENGINE_SHARED) # error "MENGINE_PLUGIN_MENGINE_SHARED for SDL not implemented" diff --git a/src/Applications/SDLApplication/SDLApplication.h b/src/Applications/SDLApplication/SDLApplication.h index 5832e86c82..5f70b365cf 100644 --- a/src/Applications/SDLApplication/SDLApplication.h +++ b/src/Applications/SDLApplication/SDLApplication.h @@ -13,7 +13,7 @@ namespace Mengine ~SDLApplication(); public: - bool bootstrap( int32_t _argc, const Char ** const _argv ); + bool bootstrap( int32_t _argc, Char ** const _argv ); public: bool initialize(); @@ -23,7 +23,7 @@ namespace Mengine void loop(); protected: - bool initializeOptionsService_( int32_t argc, const Char ** const _argv ); + bool initializeOptionsService_( int32_t argc, Char ** const _argv ); bool initializeLoggerService_(); protected: diff --git a/src/Bootstrapper/Bootstrapper.cpp b/src/Bootstrapper/Bootstrapper.cpp index 94da203fd9..adecc671d9 100644 --- a/src/Bootstrapper/Bootstrapper.cpp +++ b/src/Bootstrapper/Bootstrapper.cpp @@ -2238,6 +2238,8 @@ namespace Mengine SERVICE_FINALIZE( iOSKernelService ); #endif + SERVICE_FINALIZE( PlatformService ); + SERVICE_FINALIZE( EnvironmentService ); this->unregisterBaseTypes_(); @@ -2245,7 +2247,6 @@ namespace Mengine SERVICE_FINALIZE( AnalyticsService ); SERVICE_FINALIZE( StatisticService ); - SERVICE_FINALIZE( PlatformService ); SERVICE_FINALIZE( LoggerService ); SERVICE_FINALIZE( MemoryService ); SERVICE_FINALIZE( OptionsService ); diff --git a/src/Environment/Android/AndroidActivityHelper.cpp b/src/Environment/Android/AndroidActivityHelper.cpp index 3cea8ef807..d45b1cd3f6 100644 --- a/src/Environment/Android/AndroidActivityHelper.cpp +++ b/src/Environment/Android/AndroidActivityHelper.cpp @@ -15,7 +15,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// jmethodID AndroidGetActivityMethodID( JNIEnv * _jenv, const Char * _name, const Char * _signature ) { - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); + jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity( _jenv ); jmethodID jmethodID_function = _jenv->GetMethodID( jclassMengineActivity, _name, _signature ); @@ -119,7 +119,7 @@ namespace Mengine { jmethodID jmethodId = Helper::AndroidGetActivityMethodID( _jenv, _name, _signature ); - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); + jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity( _jenv ); MENGINE_VA_LIST_TYPE args; MENGINE_VA_LIST_START( args, _signature ); @@ -135,7 +135,7 @@ namespace Mengine { jmethodID jmethodId = Helper::AndroidGetActivityMethodID( _jenv, _name, _signature ); - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); + jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity( _jenv ); MENGINE_VA_LIST_TYPE args; MENGINE_VA_LIST_START( args, _signature ); @@ -153,7 +153,7 @@ namespace Mengine { jmethodID jmethodId = Helper::AndroidGetActivityMethodID( _jenv, _name, _signature ); - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); + jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity( _jenv ); MENGINE_VA_LIST_TYPE args; MENGINE_VA_LIST_START( args, _signature ); @@ -171,7 +171,7 @@ namespace Mengine { jmethodID jmethodId = Helper::AndroidGetActivityMethodID( _jenv, _name, _signature ); - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); + jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity( _jenv ); MENGINE_VA_LIST_TYPE args; MENGINE_VA_LIST_START( args, _signature ); @@ -189,7 +189,7 @@ namespace Mengine { jmethodID jmethodId = Helper::AndroidGetActivityMethodID( _jenv, _name, _signature ); - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); + jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity( _jenv ); MENGINE_VA_LIST_TYPE args; MENGINE_VA_LIST_START( args, _signature ); diff --git a/src/Environment/Android/AndroidApplicationHelper.cpp b/src/Environment/Android/AndroidApplicationHelper.cpp index 957eec2a06..13fc661080 100644 --- a/src/Environment/Android/AndroidApplicationHelper.cpp +++ b/src/Environment/Android/AndroidApplicationHelper.cpp @@ -15,7 +15,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// jmethodID AndroidGetApplicationMethodID( JNIEnv * _jenv, const Char * _name, const Char * _signature ) { - jclass jclassMengineApplication = Mengine_JNI_GetJClassMengineApplication(); + jclass jclassMengineApplication = Mengine_JNI_GetJClassMengineApplication( _jenv ); MENGINE_ASSERTION_FATAL( jclassMengineApplication != nullptr, "invalid get android application class for method '%s' with signature '%s'" , _name diff --git a/src/Environment/Android/AndroidAssetService.cpp b/src/Environment/Android/AndroidAssetService.cpp index 8536c7763e..6f1e9d3126 100644 --- a/src/Environment/Android/AndroidAssetService.cpp +++ b/src/Environment/Android/AndroidAssetService.cpp @@ -1,7 +1,7 @@ #include "AndroidAssetService.h" #include "Environment/Android/AndroidEnv.h" -#include "Environment/Android/AndroidActivityHelper.h" +#include "Environment/Android/AndroidApplicationHelper.h" #include "Kernel/AssertionMemoryPanic.h" #include "Kernel/Logger.h" @@ -24,7 +24,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// bool AndroidAssetService::_initializeService() { - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_FALSE ) { LOGGER_ERROR( "invalid get asset manager" ); @@ -35,7 +35,7 @@ namespace Mengine MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" ); - jobject jAssetManager = Helper::AndroidCallObjectActivityMethod( jenv, "getAssets", "()Landroid/content/res/AssetManager;" ); + jobject jAssetManager = Helper::AndroidCallObjectApplicationMethod( jenv, "getAssets", "()Landroid/content/res/AssetManager;" ); if( jAssetManager == nullptr ) { diff --git a/src/Environment/Android/AndroidDeclaration.h b/src/Environment/Android/AndroidDeclaration.h index fa23e2c5d9..f8f501ba96 100644 --- a/src/Environment/Android/AndroidDeclaration.h +++ b/src/Environment/Android/AndroidDeclaration.h @@ -6,10 +6,4 @@ #define MENGINE_JAVA_FUNCTION_INTERFACE(prefix, class, function) MENGINE_JAVA_CONCAT2(prefix, class, function) #define MENGINE_JAVA_PREFIX org_Mengine_Base -#define MENGINE_LOG_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineLog, function) -#define MENGINE_SEMAPHORE_LISTENER_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineSemaphoreListener, function) -#define MENGINE_ANALYTICS_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineAnalytics, function) -#define MENGINE_ANALYTICSEVENTBUILDER_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineAnalyticsEventBuilder, function) -#define MENGINE_APPLICATION_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineApplication, function) -#define MENGINE_ACTIVITY_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineActivity, function) -#define MENGINE_MAIN_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineMain, function) \ No newline at end of file +#define MENGINE_JAVA_INTERFACE(function) MENGINE_JAVA_FUNCTION_INTERFACE(MENGINE_JAVA_PREFIX, MengineNative, function) diff --git a/src/Environment/Android/AndroidEnv.cpp b/src/Environment/Android/AndroidEnv.cpp index f706a702e2..3609ab478e 100644 --- a/src/Environment/Android/AndroidEnv.cpp +++ b/src/Environment/Android/AndroidEnv.cpp @@ -9,27 +9,21 @@ static JavaVM * g_androidEnvJavaVM; -static jclass g_jclass_MengineApplication; static jobject g_jobject_MengineApplication; static jobject g_jobject_MengineClassLoader; -static jclass g_jclass_MengineActivity; static jobject g_jobject_MengineActivity; extern "C" { ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_APPLICATION_JAVA_INTERFACE( AndroidEnv_1setMengineAndroidApplicationJNI )(JNIEnv * env, jclass cls, jobject obj, jobject cl) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1setMengineAndroidApplicationJNI )(JNIEnv * env, jclass cls, jobject obj, jobject cl) { - g_jclass_MengineApplication = (jclass)env->NewGlobalRef( cls ); g_jobject_MengineApplication = (jobject)env->NewGlobalRef( obj ); g_jobject_MengineClassLoader = (jobject)env->NewGlobalRef( cl ); } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_APPLICATION_JAVA_INTERFACE( AndroidEnv_1removeMengineAndroidApplicationJNI )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1removeMengineAndroidApplicationJNI )(JNIEnv * env, jclass cls) { - env->DeleteGlobalRef( g_jclass_MengineApplication ); - g_jclass_MengineApplication = nullptr; - env->DeleteGlobalRef( g_jobject_MengineApplication ); g_jobject_MengineApplication = nullptr; @@ -37,22 +31,18 @@ extern "C" g_jobject_MengineClassLoader = nullptr; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnv_1setMengineAndroidActivityJNI )(JNIEnv * env, jclass cls, jobject obj) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1setMengineAndroidActivityJNI )(JNIEnv * env, jclass cls, jobject obj) { - g_jclass_MengineActivity = (jclass)env->NewGlobalRef( cls ); g_jobject_MengineActivity = (jobject)env->NewGlobalRef( obj ); } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnv_1removeMengineAndroidActivityJNI )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1removeMengineAndroidActivityJNI )(JNIEnv * env, jclass cls) { - env->DeleteGlobalRef( g_jclass_MengineActivity ); - g_jclass_MengineActivity = nullptr; - env->DeleteGlobalRef( g_jobject_MengineActivity ); g_jobject_MengineActivity = nullptr; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jboolean JNICALL MENGINE_APPLICATION_JAVA_INTERFACE( AndroidEnv_1isMasterRelease )(JNIEnv * env, jclass cls) + JNIEXPORT jboolean JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1isMasterRelease )(JNIEnv * env, jclass cls) { bool mode = Mengine::Helper::isMasterRelease(); @@ -61,7 +51,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_APPLICATION_JAVA_INTERFACE( AndroidEnv_1getEngineGITSHA1 )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1getEngineGITSHA1 )(JNIEnv * env, jclass cls) { const Mengine::Char * ENGINE_GIT_SHA1 = Mengine::Helper::getEngineGITSHA1(); @@ -70,7 +60,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_APPLICATION_JAVA_INTERFACE( AndroidEnv_1getEngineVersion )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1getEngineVersion )(JNIEnv * env, jclass cls) { const Mengine::Char * ENGINE_VERSION = Mengine::Helper::getEngineVersion(); @@ -79,7 +69,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_APPLICATION_JAVA_INTERFACE( AndroidEnv_1getBuildDate )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1getBuildDate )(JNIEnv * env, jclass cls) { const Mengine::Char * BUILD_DATE = Mengine::Helper::getBuildDate(); @@ -88,7 +78,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_APPLICATION_JAVA_INTERFACE( AndroidEnv_1getBuildUsername )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnv_1getBuildUsername )(JNIEnv * env, jclass cls) { const Mengine::Char * BUILD_USERNAME = Mengine::Helper::getBuildUsername(); @@ -123,7 +113,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// jboolean Mengine_JNI_ExistMengineApplication() { - if( g_jclass_MengineApplication == nullptr ) + if( g_jobject_MengineApplication == nullptr ) { return JNI_FALSE; } @@ -131,9 +121,11 @@ namespace Mengine return JNI_TRUE; } ////////////////////////////////////////////////////////////////////////// - jclass Mengine_JNI_GetJClassMengineApplication() + jclass Mengine_JNI_GetJClassMengineApplication( JNIEnv * _jenv ) { - return g_jclass_MengineApplication; + jclass jclass_MengineApplication = _jenv->GetObjectClass( g_jobject_MengineApplication ); + + return jclass_MengineApplication; } ////////////////////////////////////////////////////////////////////////// jobject Mengine_JNI_GetJObjectMengineApplication() @@ -143,7 +135,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// jboolean Mengine_JNI_ExistMengineActivity() { - if( g_jclass_MengineActivity == nullptr ) + if( g_jobject_MengineActivity == nullptr ) { return JNI_FALSE; } @@ -151,9 +143,11 @@ namespace Mengine return JNI_TRUE; } ////////////////////////////////////////////////////////////////////////// - jclass Mengine_JNI_GetJClassMengineActivity() + jclass Mengine_JNI_GetJClassMengineActivity( JNIEnv * _jenv ) { - return g_jclass_MengineActivity; + jclass jclass_MengineActivity = _jenv->GetObjectClass( g_jobject_MengineActivity ); + + return jclass_MengineActivity; } ////////////////////////////////////////////////////////////////////////// jobject Mengine_JNI_GetJObjectMengineActivity() diff --git a/src/Environment/Android/AndroidEnv.h b/src/Environment/Android/AndroidEnv.h index fe8e25b328..0e16382970 100644 --- a/src/Environment/Android/AndroidEnv.h +++ b/src/Environment/Android/AndroidEnv.h @@ -9,10 +9,12 @@ namespace Mengine int Mengine_JNI_SetupThread(); jboolean Mengine_JNI_ExistMengineApplication(); - jclass Mengine_JNI_GetJClassMengineApplication(); + jclass Mengine_JNI_GetJClassMengineApplication( JNIEnv * _jenv ); jobject Mengine_JNI_GetJObjectMengineApplication(); + jboolean Mengine_JNI_ExistMengineActivity(); - jclass Mengine_JNI_GetJClassMengineActivity(); + jclass Mengine_JNI_GetJClassMengineActivity( JNIEnv * _jenv ); jobject Mengine_JNI_GetJObjectMengineActivity(); + jclass Mengine_JNI_FindClass( JNIEnv *_jenv, const char *_className ); } \ No newline at end of file diff --git a/src/Environment/Android/AndroidHelper.cpp b/src/Environment/Android/AndroidHelper.cpp index 0a4666abbb..9a6b6f2778 100644 --- a/src/Environment/Android/AndroidHelper.cpp +++ b/src/Environment/Android/AndroidHelper.cpp @@ -653,14 +653,14 @@ namespace Mengine return result; } ////////////////////////////////////////////////////////////////////////// - bool AndroidGetActivityFilesDirCanonicalPath( JNIEnv * _jenv, Char * const _path ) + bool AndroidGetApplicationFilesDirCanonicalPath( JNIEnv * _jenv, Char * const _path ) { - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); - jobject jobjectMengineActivity = Mengine_JNI_GetJObjectMengineActivity(); + jclass jclassMengineApplication = Mengine_JNI_GetJClassMengineApplication( _jenv ); + jobject jobjectMengineApplication = Mengine_JNI_GetJObjectMengineApplication(); - jmethodID midContext_GetFilesDir = _jenv->GetMethodID( jclassMengineActivity, "getFilesDir", "()Ljava/io/File;" ); + jmethodID midContext_GetFilesDir = _jenv->GetMethodID( jclassMengineApplication, "getFilesDir", "()Ljava/io/File;" ); - jobject filesDir = _jenv->CallObjectMethod( jobjectMengineActivity, midContext_GetFilesDir ); + jobject filesDir = _jenv->CallObjectMethod( jobjectMengineApplication, midContext_GetFilesDir ); if( filesDir == nullptr ) { @@ -695,7 +695,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// jobject AndroidGetActivitySurface( JNIEnv * _jenv ) { - jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity(); + jclass jclassMengineActivity = Mengine_JNI_GetJClassMengineActivity( _jenv ); jobject jobjectMengineActivity = Mengine_JNI_GetJObjectMengineActivity(); jmethodID midMengineActivity_getNativeSurface = _jenv->GetMethodID( jclassMengineActivity, "getSurface", "()Landroid/view/Surface;" ); @@ -717,7 +717,7 @@ namespace Mengine _jenv->ExceptionClear(); - jclass jclassMengineApplication = Mengine_JNI_GetJClassMengineApplication(); + jclass jclassMengineApplication = Mengine_JNI_GetJClassMengineApplication( _jenv ); if( jclassMengineApplication == nullptr ) { diff --git a/src/Environment/Android/AndroidHelper.h b/src/Environment/Android/AndroidHelper.h index abd3b91bb5..2bf3d3b7a9 100644 --- a/src/Environment/Android/AndroidHelper.h +++ b/src/Environment/Android/AndroidHelper.h @@ -82,7 +82,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// bool AndroidWriteMemory( JNIEnv * _jenv, const MemoryInterfacePtr & _memory, jobject _writer ); ////////////////////////////////////////////////////////////////////////// - bool AndroidGetActivityFilesDirCanonicalPath( JNIEnv * _jenv, Char * const _path ); + bool AndroidGetApplicationFilesDirCanonicalPath( JNIEnv * _jenv, Char * const _path ); ////////////////////////////////////////////////////////////////////////// jobject AndroidGetActivitySurface( JNIEnv * _jenv ); ////////////////////////////////////////////////////////////////////////// diff --git a/src/Frameworks/PythonFramework/PythonScriptService.cpp b/src/Frameworks/PythonFramework/PythonScriptService.cpp index 6ee81160e1..ce607c099f 100644 --- a/src/Frameworks/PythonFramework/PythonScriptService.cpp +++ b/src/Frameworks/PythonFramework/PythonScriptService.cpp @@ -43,6 +43,7 @@ #include "Kernel/ContentHelper.h" #include "Kernel/VocabularyHelper.h" #include "Kernel/PrefetcherHelper.h" +#include "Kernel/ThreadMutexScope.h" #include "Config/StdString.h" #include "Config/StdIO.h" @@ -372,10 +373,6 @@ namespace Mengine uint64_t buildNumber = Helper::getBuildNumber(); this->addGlobalModuleT( "_BUILD_NUMBER", buildNumber ); - m_availablePlugins = pybind::make_dict_t( kernel ); - - this->addGlobalModule( "_PLUGINS", m_availablePlugins.ptr() ); - pybind::def_functor( m_kernel, "setAvailablePlugin", this, &PythonScriptService::setAvailablePlugin ); pybind::def_functor( m_kernel, "isAvailablePlugin", this, &PythonScriptService::isAvailablePlugin ); @@ -606,12 +603,16 @@ namespace Mengine #endif } + m_pluginsMutex = Helper::createThreadMutex( MENGINE_DOCUMENT_FACTORABLE ); + return true; } ////////////////////////////////////////////////////////////////////////// void PythonScriptService::_finalizeService() { - m_availablePlugins = nullptr; + m_pluginsMutex = nullptr; + + m_availablePlugins.clear(); #if defined(MENGINE_DEBUG) pybind::observer_bind_call * observer = m_kernel->get_observer_bind_call(); @@ -1137,19 +1138,25 @@ namespace Mengine pybind::dict_remove_t( m_kernel, dir_bltin, _name ); } ////////////////////////////////////////////////////////////////////////// - void PythonScriptService::setAvailablePlugin( const Char * _name, bool _available ) + void PythonScriptService::setAvailablePlugin( const ConstString & _name, bool _available ) { - m_availablePlugins[_name] = _available; + MENGINE_THREAD_MUTEX_SCOPE( m_pluginsMutex ); + + m_availablePlugins.emplace( _name, _available ); } ////////////////////////////////////////////////////////////////////////// - bool PythonScriptService::isAvailablePlugin( const Char * _name ) const + bool PythonScriptService::isAvailablePlugin( const ConstString & _name ) const { - if( m_availablePlugins.exist( _name ) == false ) + MENGINE_THREAD_MUTEX_SCOPE( m_pluginsMutex ); + + MapAvailablePlugins::const_iterator it_found = m_availablePlugins.find( _name ); + + if( it_found == m_availablePlugins.end() ) { return false; } - bool available = m_availablePlugins.get( _name ); + bool available = it_found->second; return available; } diff --git a/src/Frameworks/PythonFramework/PythonScriptService.h b/src/Frameworks/PythonFramework/PythonScriptService.h index 1f561d7186..1cb7ef0354 100644 --- a/src/Frameworks/PythonFramework/PythonScriptService.h +++ b/src/Frameworks/PythonFramework/PythonScriptService.h @@ -52,8 +52,8 @@ namespace Mengine void removeGlobalModule( const Char * _name ) override; public: - void setAvailablePlugin( const Char * _name, bool _available ) override; - bool isAvailablePlugin( const Char * _name ) const override; + void setAvailablePlugin( const ConstString & _name, bool _available ) override; + bool isAvailablePlugin( const ConstString & _name ) const override; public: void addModulePath( const FileGroupInterfacePtr & _fileGroup, const VectorScriptModulePack & _modules ) override; @@ -115,11 +115,14 @@ namespace Mengine protected: pybind::kernel_interface * m_kernel; + ThreadMutexInterfacePtr m_pluginsMutex; + ScriptModuleFinderPtr m_moduleFinder; PyObject * m_moduleMengine; - pybind::dict m_availablePlugins; + typedef Map MapAvailablePlugins; + MapAvailablePlugins m_availablePlugins; VectorScriptModulePack m_bootstrapperModules; diff --git a/src/Interface/ScriptServiceInterface.h b/src/Interface/ScriptServiceInterface.h index 7168f6edf9..a9adfcedae 100644 --- a/src/Interface/ScriptServiceInterface.h +++ b/src/Interface/ScriptServiceInterface.h @@ -61,8 +61,8 @@ namespace Mengine virtual void removeGlobalModule( const Char * _name ) = 0; public: - virtual void setAvailablePlugin( const Char * _name, bool _available ) = 0; - virtual bool isAvailablePlugin( const Char * _name ) const = 0; + virtual void setAvailablePlugin( const ConstString & _name, bool _available ) = 0; + virtual bool isAvailablePlugin( const ConstString & _name ) const = 0; public: virtual bool addScriptEmbedding( const ConstString & _name, const ScriptEmbeddingInterfacePtr & _embedding ) = 0; diff --git a/src/Platforms/AndroidPlatform/AndroidPlatformService.cpp b/src/Platforms/AndroidPlatform/AndroidPlatformService.cpp index a9b11eae7d..b27c86b9f2 100644 --- a/src/Platforms/AndroidPlatform/AndroidPlatformService.cpp +++ b/src/Platforms/AndroidPlatform/AndroidPlatformService.cpp @@ -82,7 +82,7 @@ extern "C" { ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1getCompanyName )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1getCompanyName )(JNIEnv * env, jclass cls) { Mengine::Char companyName[MENGINE_APPLICATION_COMPANY_MAXNAME + 1] = {'\0'}; APPLICATION_SERVICE() @@ -93,7 +93,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1getProjectName )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1getProjectName )(JNIEnv * env, jclass cls) { Mengine::Char projectName[MENGINE_PLATFORM_PROJECT_TITLE_MAXNAME + 1] = {'\0'}; APPLICATION_SERVICE() @@ -104,7 +104,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1getExtraPreferencesFolderName )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1getExtraPreferencesFolderName )(JNIEnv * env, jclass cls) { Mengine::Path extraPreferencesFolderName = {'\0'}; PLATFORM_SERVICE() @@ -115,7 +115,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jboolean JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1hasCurrentAccount )(JNIEnv * env, jclass cls) + JNIEXPORT jboolean JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1hasCurrentAccount )(JNIEnv * env, jclass cls) { bool result = ACCOUNT_SERVICE() ->hasCurrentAccount(); @@ -123,7 +123,7 @@ extern "C" return (jboolean)result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1deleteCurrentAccount )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1deleteCurrentAccount )(JNIEnv * env, jclass cls) { Mengine::Helper::dispatchMainThreadEvent( []() { @@ -132,7 +132,7 @@ extern "C" } ); } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jstring JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1getCurrentAccountFolderName )(JNIEnv * env, jclass cls) + JNIEXPORT jstring JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1getCurrentAccountFolderName )(JNIEnv * env, jclass cls) { const Mengine::AccountInterfacePtr & account = ACCOUNT_SERVICE() ->getCurrentAccount(); @@ -151,7 +151,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jboolean JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1writeCurrentLogToFile )(JNIEnv * env, jclass cls, jobject _writer) + JNIEXPORT jboolean JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1writeCurrentLogToFile )(JNIEnv * env, jclass cls, jobject _writer) { LOGGER_SERVICE() ->flushMessages(); @@ -179,7 +179,7 @@ extern "C" return JNI_TRUE; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jboolean JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1writeOldLogToFile )(JNIEnv * env, jclass cls, jobject _writer) + JNIEXPORT jboolean JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1writeOldLogToFile )(JNIEnv * env, jclass cls, jobject _writer) { const Mengine::MemoryInterfacePtr & memory = LOGGER_SERVICE() ->getOldLogMemory(); @@ -197,7 +197,7 @@ extern "C" return JNI_TRUE; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jboolean JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1isDevelopmentMode )(JNIEnv * env, jclass cls) + JNIEXPORT jboolean JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1isDevelopmentMode )(JNIEnv * env, jclass cls) { bool mode = Mengine::Helper::isDevelopmentMode(); @@ -206,7 +206,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jint JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidEnvironmentService_1getProjectVersion )(JNIEnv * env, jclass cls) + JNIEXPORT jint JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1getProjectVersion )(JNIEnv * env, jclass cls) { uint32_t projectVersion = APPLICATION_SERVICE() ->getProjectVersion(); @@ -216,7 +216,7 @@ extern "C" return result; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_SEMAPHORE_LISTENER_JAVA_INTERFACE( AnroidEnvironmentService_1callMengineSemaphoreListener )(JNIEnv * env, jclass cls, jobject _impl) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AnroidEnvironmentService_1callMengineSemaphoreListener )(JNIEnv * env, jclass cls, jobject _impl) { void * impl_MengineFunctorVoid = env->GetDirectBufferAddress( _impl ); @@ -225,7 +225,7 @@ extern "C" functor->invoke(); } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_SEMAPHORE_LISTENER_JAVA_INTERFACE( AnroidEnvironmentService_1destroyMengineSemaphoreListener )(JNIEnv * env, jclass cls, jobject _impl) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AnroidEnvironmentService_1destroyMengineSemaphoreListener )(JNIEnv * env, jclass cls, jobject _impl) { void * impl_MengineFunctorVoid = env->GetDirectBufferAddress( _impl ); @@ -234,7 +234,7 @@ extern "C" Mengine::IntrusivePtrBase::intrusive_ptr_dec_ref( functor ); } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_LOG_JAVA_INTERFACE( AndroidEnvironmentService_1log )(JNIEnv * env, jclass cls, jint _level, jstring _tag, jstring _msg) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidEnvironmentService_1log )(JNIEnv * env, jclass cls, jint _level, jstring _tag, jstring _msg) { if( SERVICE_IS_INITIALIZE( Mengine::LoggerServiceInterface ) == false ) { @@ -294,7 +294,7 @@ extern "C" env->ReleaseStringUTFChars( _msg, msg_str ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1surfaceCreatedEvent )(JNIEnv * env, jclass cls, jobject surface) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1surfaceCreatedEvent )(JNIEnv * env, jclass cls, jobject surface) { ANativeWindow * nativeWindow = ANativeWindow_fromSurface( env, surface ); @@ -304,7 +304,7 @@ extern "C" platformExtension->androidNativeSurfaceCreatedEvent( nativeWindow ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1surfaceDestroyedEvent )(JNIEnv * env, jclass cls, jobject surface) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1surfaceDestroyedEvent )(JNIEnv * env, jclass cls, jobject surface) { ANativeWindow * nativeWindow = ANativeWindow_fromSurface( env, surface ); @@ -314,7 +314,7 @@ extern "C" platformExtension->androidNativeSurfaceDestroyedEvent( nativeWindow ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1surfaceChangedEvent )(JNIEnv * env, jclass cls, jobject surface, jint surfaceWidth, jint surfaceHeight, jint deviceWidth, jint deviceHeight, jfloat rate) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1surfaceChangedEvent )(JNIEnv * env, jclass cls, jobject surface, jint surfaceWidth, jint surfaceHeight, jint deviceWidth, jint deviceHeight, jfloat rate) { ANativeWindow * nativeWindow = ANativeWindow_fromSurface( env, surface ); @@ -324,7 +324,7 @@ extern "C" platformExtension->androidNativeSurfaceChangedEvent( nativeWindow, surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, rate ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1keyEvent )(JNIEnv * env, jclass cls, jboolean isDown, jint keyCode, jint repeatCount) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1keyEvent )(JNIEnv * env, jclass cls, jboolean isDown, jint keyCode, jint repeatCount) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -332,7 +332,7 @@ extern "C" platformExtension->androidNativeKeyEvent( isDown, keyCode, repeatCount ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1textEvent )(JNIEnv * env, jclass cls, jint unicode) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1textEvent )(JNIEnv * env, jclass cls, jint unicode) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -340,7 +340,7 @@ extern "C" platformExtension->androidNativeTextEvent( unicode ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1touchEvent )(JNIEnv * env, jclass cls, jint action, jint pointerId, jfloat x, jfloat y, jfloat pressure) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1touchEvent )(JNIEnv * env, jclass cls, jint action, jint pointerId, jfloat x, jfloat y, jfloat pressure) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -348,7 +348,7 @@ extern "C" platformExtension->androidNativeTouchEvent( action, pointerId, x, y, pressure ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1accelerationEvent )(JNIEnv * env, jclass cls, jfloat x, jfloat y, jfloat z) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1accelerationEvent )(JNIEnv * env, jclass cls, jfloat x, jfloat y, jfloat z) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -356,7 +356,7 @@ extern "C" platformExtension->androidNativeAccelerationEvent( x, y, z ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1pauseEvent )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1pauseEvent )(JNIEnv * env, jclass cls) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -364,7 +364,7 @@ extern "C" platformExtension->androidNativePauseEvent(); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1resumeEvent )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1resumeEvent )(JNIEnv * env, jclass cls) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -372,7 +372,7 @@ extern "C" platformExtension->androidNativeResumeEvent(); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1stopEvent )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1stopEvent )(JNIEnv * env, jclass cls) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -380,7 +380,7 @@ extern "C" platformExtension->androidNativeStopEvent(); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1startEvent )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1startEvent )(JNIEnv * env, jclass cls) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -388,7 +388,7 @@ extern "C" platformExtension->androidNativeStartEvent(); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1clipboardChangedEvent )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1clipboardChangedEvent )(JNIEnv * env, jclass cls) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -396,7 +396,7 @@ extern "C" platformExtension->androidNativeClipboardChangedEvent(); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1windowFocusChangedEvent )(JNIEnv * env, jclass cls, jboolean _focus) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1windowFocusChangedEvent )(JNIEnv * env, jclass cls, jboolean _focus) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -404,7 +404,7 @@ extern "C" platformExtension->androidNativeWindowFocusChangedEvent( _focus ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1quitEvent )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1quitEvent )(JNIEnv * env, jclass cls) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -412,7 +412,7 @@ extern "C" platformExtension->androidNativeQuitEvent(); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1lowMemory )(JNIEnv * env, jclass cls) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1lowMemory )(JNIEnv * env, jclass cls) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -420,7 +420,7 @@ extern "C" platformExtension->androidNativeLowMemoryEvent(); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1trimMemory )(JNIEnv * env, jclass cls, jint level) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1trimMemory )(JNIEnv * env, jclass cls, jint level) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -428,7 +428,7 @@ extern "C" platformExtension->androidNativeTrimMemoryEvent( level ); } /////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidPlatform_1changeLocale )(JNIEnv * env, jclass cls, jstring _language) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidPlatform_1changeLocale )(JNIEnv * env, jclass cls, jstring _language) { Mengine::AndroidPlatformServiceExtensionInterface * platformExtension = PLATFORM_SERVICE() ->getUnknown(); @@ -480,16 +480,16 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// size_t AndroidPlatformService::getUserPath( Char * const _userPath ) const { - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_FALSE ) { - LOGGER_ERROR( "invalid get user path [not exist activity]" ); + LOGGER_ERROR( "invalid get user path [not exist application]" ); return 0; } JNIEnv * jenv = Mengine_JNI_GetEnv(); - if( Helper::AndroidGetActivityFilesDirCanonicalPath( jenv, _userPath ) == false ) + if( Helper::AndroidGetApplicationFilesDirCanonicalPath( jenv, _userPath ) == false ) { LOGGER_ERROR( "invalid get user path" ); @@ -702,8 +702,6 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// void AndroidPlatformService::_finalizeService() { - NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_PLATFORM_RUN ); - NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_PLATFORM_STOP ); NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_BOOTSTRAPPER_INITIALIZE_BASE_SERVICES ); NOTIFICATION_REMOVEOBSERVER_THIS( NOTIFICATOR_BOOTSTRAPPER_CREATE_APPLICATION ); @@ -755,13 +753,13 @@ namespace Mengine NOTIFICATION_NOTIFY( NOTIFICATOR_PLATFORM_RUN ); - if( Mengine_JNI_ExistMengineActivity() == JNI_TRUE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_TRUE ) { JNIEnv * jenv = Mengine_JNI_GetEnv(); MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" ); - Helper::AndroidCallVoidActivityMethod( jenv, "onMenginePlatformRun", "()V" ); + Helper::AndroidCallVoidApplicationMethod( jenv, "onMenginePlatformRun", "()V" ); } return true; @@ -958,7 +956,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// void AndroidPlatformService::notifyBootstrapperInitializeBaseServices_() { - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_FALSE ) { return; } @@ -967,12 +965,12 @@ namespace Mengine MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" ); - Helper::AndroidCallVoidActivityMethod( jenv, "onMengineInitializeBaseServices", "()V" ); + Helper::AndroidCallVoidApplicationMethod( jenv, "onMengineInitializeBaseServices", "()V" ); } ////////////////////////////////////////////////////////////////////////// void AndroidPlatformService::notifyBootstrapperCreateApplication_() { - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_FALSE ) { return; } @@ -981,20 +979,20 @@ namespace Mengine MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" ); - Helper::AndroidCallVoidActivityMethod( jenv, "onMengineCreateApplication", "()V" ); + Helper::AndroidCallVoidApplicationMethod( jenv, "onMengineCreateApplication", "()V" ); } ////////////////////////////////////////////////////////////////////////// void AndroidPlatformService::stopPlatform() { NOTIFICATION_NOTIFY( NOTIFICATOR_PLATFORM_STOP ); - if( Mengine_JNI_ExistMengineActivity() == JNI_TRUE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_TRUE ) { JNIEnv * jenv = Mengine_JNI_GetEnv(); MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" ); - Helper::AndroidCallVoidActivityMethod( jenv, "onMenginePlatformStop", "()V" ); + Helper::AndroidCallVoidApplicationMethod( jenv, "onMenginePlatformStop", "()V" ); } this->pushQuitEvent_(); @@ -1337,6 +1335,15 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// void AndroidPlatformService::messageBox( const Char * _caption, const Char * _format, ... ) const { + if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) + { + LOGGER_ERROR( "invalid message box [not exist activity]" ); + + return; + } + + JNIEnv * jenv = Mengine_JNI_GetEnv(); + Char str[MENGINE_LOGGER_MAX_MESSAGE + 1] = {'\0'}; MENGINE_VA_LIST_TYPE args; @@ -1355,15 +1362,6 @@ namespace Mengine return; } - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) - { - LOGGER_ERROR( "invalid message box [not exist activity]" ); - - return; - } - - JNIEnv * jenv = Mengine_JNI_GetEnv(); - jstring j_caption = jenv->NewStringUTF( _caption ); jstring j_message = jenv->NewStringUTF( str ); @@ -1636,13 +1634,6 @@ namespace Mengine jenv->DeleteLocalRef( jReturnValue ); - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) - { - LOGGER_ERROR( "invalid get android id [not exist activity]" ); - - return 0; - } - return size; } ////////////////////////////////////////////////////////////////////////// diff --git a/src/Platforms/AndroidPlatform/AndroidPlatformService.h b/src/Platforms/AndroidPlatform/AndroidPlatformService.h index 706fa993f0..733af289f9 100644 --- a/src/Platforms/AndroidPlatform/AndroidPlatformService.h +++ b/src/Platforms/AndroidPlatform/AndroidPlatformService.h @@ -55,7 +55,7 @@ namespace Mengine void finalizeFileService() override; public: - bool runPlatform() override; + bool runPlatform() override; void loopPlatform() override; bool updatePlatform() override; bool tickPlatform( Timestamp _frameTime, float _frameTimeF, bool _render, bool _flush, bool _pause ) override; diff --git a/src/Plugins/AmplifierPlugin/AmplifierScriptEmbedding.cpp b/src/Plugins/AmplifierPlugin/AmplifierScriptEmbedding.cpp index d38598034f..568048c706 100644 --- a/src/Plugins/AmplifierPlugin/AmplifierScriptEmbedding.cpp +++ b/src/Plugins/AmplifierPlugin/AmplifierScriptEmbedding.cpp @@ -369,7 +369,7 @@ namespace Mengine } SCRIPT_SERVICE() - ->setAvailablePlugin( "Amplifier", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Amplifier"), true ); pybind::def_functor_args( _kernel, "musicPlay", scriptMethod, &AmplifierScriptMethod::musicPlay ); pybind::def_functor( _kernel, "musicSetVolume", scriptMethod, &AmplifierScriptMethod::musicSetVolume ); diff --git a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonEventHandlerInterface.h b/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonEventHandlerInterface.h deleted file mode 100644 index 94518e1048..0000000000 --- a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonEventHandlerInterface.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "Environment/Android/AndroidIncluder.h" - -#include "Kernel/Mixin.h" -#include "Kernel/String.h" - -namespace Mengine -{ - ////////////////////////////////////////////////////////////////////////// - class AndroidNativePythonEventHandlerInterface - : public Mixin - { - public: - virtual bool hasPythonMethod( const ConstString & _plugin, const ConstString & _method ) const = 0; - virtual void callPythonMethod( const ConstString & _plugin, const ConstString & _method, jobjectArray _args ) const = 0; - virtual void addPlugin( const ConstString & _name, jobject _plugin ) = 0; - }; - ////////////////////////////////////////////////////////////////////////// - typedef IntrusivePtr AndroidNativePythonEventHandlerInterfacePtr; - ////////////////////////////////////////////////////////////////////////// -} \ No newline at end of file diff --git a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonInterface.h b/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonInterface.h index 7bada31153..63e6916965 100644 --- a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonInterface.h +++ b/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonInterface.h @@ -15,6 +15,12 @@ namespace Mengine { SERVICE_DECLARE( "AndroidNativePythonService" ) + public: + virtual bool hasPythonMethod( const ConstString & _plugin, const ConstString & _method ) const = 0; + virtual void callPythonMethod( const ConstString & _plugin, const ConstString & _method, jobjectArray _args ) const = 0; + virtual void addPlugin( const ConstString & _name, jobject _jplugin ) = 0; + virtual jobject removePlugin( const ConstString & _name ) = 0; + public: virtual pybind::object addAndroidCallback( const ConstString & _plugin, const ConstString & _method, const pybind::object & _cb, const pybind::args & _args ) = 0; virtual void removeAndroidCallback( const ConstString & _plugin, const ConstString & _method, const pybind::object & _cb ) = 0; diff --git a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.cpp b/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.cpp index 234470bedc..c4e24ca203 100644 --- a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.cpp +++ b/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.cpp @@ -7,15 +7,6 @@ #include "Interface/PlatformServiceInterface.h" #include "Interface/AndroidKernelServiceInterface.h" -#include "Kernel/FactorableUnique.h" -#include "Kernel/Logger.h" -#include "Kernel/NotificationHelper.h" -#include "Kernel/Error.h" -#include "Kernel/AssertionFactory.h" -#include "Kernel/FactoryPool.h" -#include "Kernel/ThreadMutexScope.h" -#include "Kernel/ThreadHelper.h" - #include "Environment/Android/AndroidIncluder.h" #include "Environment/Android/AndroidEnv.h" #include "Environment/Android/AndroidDeclaration.h" @@ -28,31 +19,29 @@ #include "AndroidNativePythonFunctorBoolean.h" #include "AndroidNativePythonScriptEmbedding.h" +#include "Kernel/FactorableUnique.h" +#include "Kernel/Logger.h" +#include "Kernel/NotificationHelper.h" +#include "Kernel/Error.h" +#include "Kernel/AssertionFactory.h" +#include "Kernel/FactoryPool.h" +#include "Kernel/ThreadMutexScope.h" +#include "Kernel/ThreadHelper.h" + #include "Config/StdString.h" #include "Config/Utility.h" -////////////////////////////////////////////////////////////////////////// -static Mengine::AndroidNativePythonService * s_androidNativePythonService = nullptr; ////////////////////////////////////////////////////////////////////////// extern "C" { ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidNativePython_1call )(JNIEnv * env, jclass cls, jstring _plugin, jstring _method, jobjectArray _args) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidNativePython_1call )(JNIEnv * env, jclass cls, jstring _plugin, jstring _method, jobjectArray _args) { Mengine::ConstString plugin = Mengine::Helper::AndroidMakeConstStringFromJString( env, _plugin ); Mengine::ConstString method = Mengine::Helper::AndroidMakeConstStringFromJString( env, _method ); - if( s_androidNativePythonService == nullptr ) - { - __android_log_print( ANDROID_LOG_ERROR, "Mengine", "invalid android call plugin '%s' method '%s'" - , plugin.c_str() - , method.c_str() - ); - - return; - } - - if( s_androidNativePythonService->hasPythonMethod( plugin, method ) == false ) + if( ANDROID_NATIVEPYTHON_SERVICE() + ->hasPythonMethod( plugin, method ) == false ) { return; } @@ -61,29 +50,29 @@ extern "C" Mengine::Helper::dispatchMainThreadEvent( [plugin, method, new_args]() { - s_androidNativePythonService->callPythonMethod( plugin, method, new_args ); + ANDROID_NATIVEPYTHON_SERVICE() + ->callPythonMethod( plugin, method, new_args ); } ); } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidNativePython_1addPlugin )(JNIEnv * env, jclass cls, jstring _name, jobject _plugin) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidNativePython_1addPlugin )(JNIEnv * env, jclass cls, jstring _name, jobject _plugin) { Mengine::ConstString name = Mengine::Helper::AndroidMakeConstStringFromJString(env, _name); - if( s_androidNativePythonService == nullptr ) - { - __android_log_print( ANDROID_LOG_ERROR, "Mengine", "invalid android add plugin '%s'" - , name.c_str() - ); + jobject new_plugin = env->NewGlobalRef( _plugin ); - return; - } + ANDROID_NATIVEPYTHON_SERVICE() + ->addPlugin( name, new_plugin ); + } + ////////////////////////////////////////////////////////////////////////// + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidNativePython_1removePlugin )(JNIEnv * env, jclass cls, jstring _name) + { + Mengine::ConstString name = Mengine::Helper::AndroidMakeConstStringFromJString(env, _name); - jobject new_plugin = env->NewGlobalRef( _plugin ); + jobject jplugin = ANDROID_NATIVEPYTHON_SERVICE() + ->removePlugin( name ); - Mengine::Helper::dispatchMainThreadEvent([name, new_plugin]() - { - s_androidNativePythonService->addPlugin( name, new_plugin ); - } ); + env->DeleteGlobalRef( jplugin ); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } @@ -127,21 +116,8 @@ namespace Mengine m_factoryAndroidNativePythonFunctorVoid = Helper::makeFactoryPool( MENGINE_DOCUMENT_FACTORABLE ); m_factoryAndroidNativePythonFunctorBoolean = Helper::makeFactoryPool( MENGINE_DOCUMENT_FACTORABLE ); - ThreadMutexInterfacePtr callbacksMutex = THREAD_SYSTEM() - ->createMutex( MENGINE_DOCUMENT_FACTORABLE ); - - m_callbacksMutex = callbacksMutex; - - s_androidNativePythonService = this; - - if( Mengine_JNI_ExistMengineActivity() == JNI_TRUE ) - { - JNIEnv * jenv = Mengine_JNI_GetEnv(); - - MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" ); - - Helper::AndroidCallVoidActivityMethod( jenv, "onPythonEmbeddedInitialize", "()V" ); - } + m_callbacksMutex = Helper::createThreadMutex( MENGINE_DOCUMENT_FACTORABLE ); + m_pluginsMutex = Helper::createThreadMutex( MENGINE_DOCUMENT_FACTORABLE ); return true; } @@ -157,14 +133,8 @@ namespace Mengine MENGINE_ASSERTION_MEMORY_PANIC( jenv, "invalid get jenv" ); - if( Mengine_JNI_ExistMengineActivity() == JNI_TRUE ) - { - Helper::AndroidCallVoidActivityMethod( jenv, "onPythonEmbeddedFinalize", "()V" ); - } - - s_androidNativePythonService = nullptr; - m_callbacksMutex = nullptr; + m_pluginsMutex = nullptr; m_callbacks.clear(); @@ -270,16 +240,38 @@ namespace Mengine jenv->DeleteGlobalRef( _args ); } ////////////////////////////////////////////////////////////////////////// - void AndroidNativePythonService::addPlugin( const ConstString & _name, jobject _plugin ) + void AndroidNativePythonService::addPlugin( const ConstString & _name, jobject _jplugin ) { - MENGINE_ASSERTION_FATAL( m_plugins.find( Helper::stringizeString( _name ) ) == m_plugins.end(), "invalid add plugin '%s' [double]" + SCRIPT_SERVICE() + ->setAvailablePlugin( _name, true ); + + MENGINE_THREAD_MUTEX_SCOPE( m_pluginsMutex ); + + MENGINE_ASSERTION_FATAL( m_plugins.find( _name ) == m_plugins.end(), "invalid add plugin '%s' [double]" , _name.c_str() ); + m_plugins.emplace( _name, _jplugin ); + } + ////////////////////////////////////////////////////////////////////////// + jobject AndroidNativePythonService::removePlugin( const ConstString & _name ) + { SCRIPT_SERVICE() - ->setAvailablePlugin( _name.c_str(), true ); + ->setAvailablePlugin( _name, false ); + + MENGINE_THREAD_MUTEX_SCOPE( m_pluginsMutex ); - m_plugins.emplace( _name, _plugin ); + MapAndroidPlugins::iterator it_found = m_plugins.find( _name ); + + MENGINE_ASSERTION_FATAL( it_found != m_plugins.end(), "invalid remove plugin '%s' [empty]" + , _name.c_str() + ); + + jobject jplugin = it_found->second; + + m_plugins.erase( it_found ); + + return jplugin; } ////////////////////////////////////////////////////////////////////////// pybind::object AndroidNativePythonService::addAndroidCallback( const ConstString & _plugin, const ConstString & _method, const pybind::object & _cb, const pybind::args & _args ) @@ -664,7 +656,7 @@ namespace Mengine AndroidSemaphoreListenerInterface * listener_ptr = _listener.get(); AndroidSemaphoreListenerInterface::intrusive_ptr_add_ref( listener_ptr ); - jobject jpoint_listener = jenv->NewDirectByteBuffer( listener_ptr, sizeof(AndroidSemaphoreListenerInterface) ); + jobject jpoint_listener = jenv->NewDirectByteBuffer( listener_ptr, sizeof(void *) ); jobject jfunctor = jenv->NewObject( jclass_MengineSemaphoreListener, jmethodID_MengineSemaphoreListener_constructor, jpoint_listener ); @@ -678,36 +670,35 @@ namespace Mengine jenv->DeleteLocalRef( jclass_MengineSemaphoreListener ); } ////////////////////////////////////////////////////////////////////////// - bool AndroidNativePythonService::getAndroidMethod( JNIEnv * _jenv, const ConstString & _plugin, const ConstString & _method, const pybind::args & _args, const Char * _retType, jvalue * const _jargs, jobject * const _jfree, uint32_t * const _freeCount, jobject * const _jplugin, jmethodID * const _jmethodId ) const + jobject AndroidNativePythonService::getAndroidPlugin( const ConstString & _plugin ) const { - MENGINE_ASSERTION_FATAL( _args.size() <= 32, "android method plugin '%s' method '%s' max args [32 < %u]" - , _plugin.c_str() - , _method.c_str() - , _args.size() - ); + MENGINE_THREAD_MUTEX_SCOPE( m_pluginsMutex ); MapAndroidPlugins::const_iterator it_found = m_plugins.find( _plugin ); if( it_found == m_plugins.end() ) { - LOGGER_ERROR( "android not register plugin '%s' (call method '%s' args '%s')" - , _plugin.c_str() - , _method.c_str() - , _args.repr().c_str() - ); - - return false; + return nullptr; } jobject jplugin = it_found->second; - jclass plugin_class = _jenv->GetObjectClass( jplugin ); + return jplugin; + } + ////////////////////////////////////////////////////////////////////////// + bool AndroidNativePythonService::getAndroidMethod( JNIEnv * _jenv, const ConstString & _plugin, const ConstString & _method, const pybind::args & _args, const Char * _retType, jvalue * const _jargs, jobject * const _jfree, uint32_t * const _freeCount, jobject * const _jplugin, jmethodID * const _jmethodId ) const + { + MENGINE_ASSERTION_FATAL( _args.size() <= 32, "android method plugin '%s' method '%s' max args [32 < %u]" + , _plugin.c_str() + , _method.c_str() + , _args.size() + ); + + jobject jplugin = this->getAndroidPlugin( _plugin ); if( jplugin == nullptr ) { - Helper::AndroidEnvExceptionCheck( _jenv ); - - LOGGER_ERROR( "android not found java plugin '%s' (call method '%s' args '%s')" + LOGGER_ERROR( "android not register plugin '%s' (call method '%s' args '%s')" , _plugin.c_str() , _method.c_str() , _args.repr().c_str() @@ -716,6 +707,8 @@ namespace Mengine return false; } + jclass plugin_class = _jenv->GetObjectClass( jplugin ); + Char signature[1024 + 1] = {'\0'}; StdString::strcat( signature, "(" ); @@ -854,7 +847,7 @@ namespace Mengine ////////////////////////////////////////////////////////////////////////// void AndroidNativePythonService::notifyChangeSceneComplete_( const ScenePtr & _scene ) { - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_FALSE ) { return; } @@ -869,14 +862,14 @@ namespace Mengine jstring sceneName_jvalue = jenv->NewStringUTF( sceneName_str ); - Helper::AndroidCallVoidActivityMethod( jenv, "onMengineCurrentSceneChange", "(Ljava/lang/String;)V", sceneName_jvalue ); + Helper::AndroidCallVoidApplicationMethod( jenv, "onMengineCurrentSceneChange", "(Ljava/lang/String;)V", sceneName_jvalue ); jenv->DeleteLocalRef( sceneName_jvalue ); } ////////////////////////////////////////////////////////////////////////// void AndroidNativePythonService::notifyRemoveSceneComplete_() { - if( Mengine_JNI_ExistMengineActivity() == JNI_FALSE ) + if( Mengine_JNI_ExistMengineApplication() == JNI_FALSE ) { return; } @@ -887,7 +880,7 @@ namespace Mengine jstring sceneName_jvalue = jenv->NewStringUTF( "" ); - Helper::AndroidCallVoidActivityMethod( jenv, "onMengineCurrentSceneChange", "(Ljava/lang/String;)V", sceneName_jvalue ); + Helper::AndroidCallVoidApplicationMethod( jenv, "onMengineCurrentSceneChange", "(Ljava/lang/String;)V", sceneName_jvalue ); jenv->DeleteLocalRef( sceneName_jvalue ); } diff --git a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.h b/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.h index 69b5494e4d..5bd9b309b8 100644 --- a/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.h +++ b/src/Plugins/AndroidNativePythonPlugin/AndroidNativePythonService.h @@ -6,7 +6,6 @@ #include "Environment/Python/PythonIncluder.h" #include "AndroidNativePythonInterface.h" -#include "AndroidNativePythonEventHandlerInterface.h" #include "Kernel/Scene.h" #include "Kernel/ServiceBase.h" @@ -17,7 +16,6 @@ namespace Mengine { class AndroidNativePythonService : public ServiceBase - , public AndroidNativePythonEventHandlerInterface { public: AndroidNativePythonService(); @@ -30,7 +28,8 @@ namespace Mengine public: bool hasPythonMethod( const ConstString & _plugin, const ConstString & _method ) const override; void callPythonMethod( const ConstString & _plugin, const ConstString & _method, jobjectArray _args ) const override; - void addPlugin( const ConstString & _name, jobject _plugin ) override; + void addPlugin( const ConstString & _name, jobject _jplugin ) override; + jobject removePlugin( const ConstString & _name ) override; public: pybind::object addAndroidCallback( const ConstString & _plugin, const ConstString & _method, const pybind::object & _cb, const pybind::args & _args ) override; @@ -50,6 +49,7 @@ namespace Mengine void waitSemaphore( const ConstString & _name, const AndroidSemaphoreListenerInterfacePtr & _listener ) override; protected: + jobject getAndroidPlugin( const ConstString & _plugin ) const; bool getAndroidMethod( JNIEnv * _jenv, const ConstString & _plugin, const ConstString & _method, const pybind::args & _args, const Char * _retType, jvalue * const _jargs, jobject * const _jfree, uint32_t * const _freeCount, jobject * const _jplugin, jmethodID * const _jmethodId ) const; protected: @@ -74,6 +74,7 @@ namespace Mengine MapAndroidCallbacks m_callbacks; ThreadMutexInterfacePtr m_callbacksMutex; + ThreadMutexInterfacePtr m_pluginsMutex; typedef Map MapAndroidPlugins; MapAndroidPlugins m_plugins; diff --git a/src/Plugins/AndroidNativePythonPlugin/CMakeLists.txt b/src/Plugins/AndroidNativePythonPlugin/CMakeLists.txt index 2f779ac7d7..8ec37fd218 100644 --- a/src/Plugins/AndroidNativePythonPlugin/CMakeLists.txt +++ b/src/Plugins/AndroidNativePythonPlugin/CMakeLists.txt @@ -6,7 +6,6 @@ src AndroidNativePythonPlugin.cpp AndroidNativePythonInterface.h - AndroidNativePythonEventHandlerInterface.h AndroidNativePythonService.h AndroidNativePythonService.cpp diff --git a/src/Plugins/AppleAdjustPlugin/AppleAdjustScriptEmbedding.mm b/src/Plugins/AppleAdjustPlugin/AppleAdjustScriptEmbedding.mm index 33995e1b25..337d3323b4 100644 --- a/src/Plugins/AppleAdjustPlugin/AppleAdjustScriptEmbedding.mm +++ b/src/Plugins/AppleAdjustPlugin/AppleAdjustScriptEmbedding.mm @@ -42,7 +42,7 @@ static bool AppleAdjust_revenueTracking(const ConstString & _token, double _amou bool AppleAdjustScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleAdjust", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleAdjust"), true ); pybind::def_function( _kernel, "appleAdjustEventTraking", &Detail::AppleAdjust_eventTraking ); pybind::def_function( _kernel, "appleAdjustRevenueTracking", diff --git a/src/Plugins/AppleAppLovinPlugin/AppleAppLovinScriptEmbedding.mm b/src/Plugins/AppleAppLovinPlugin/AppleAppLovinScriptEmbedding.mm index 8d42df9412..2a0c3880b7 100644 --- a/src/Plugins/AppleAppLovinPlugin/AppleAppLovinScriptEmbedding.mm +++ b/src/Plugins/AppleAppLovinPlugin/AppleAppLovinScriptEmbedding.mm @@ -289,7 +289,7 @@ static void appleAppLovin_loadAndShowCMPFlow(const pybind::dict & _cbs, const py bool AppleAppLovinScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleAppLovin", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleAppLovin"), true ); AppleAppLovinServiceInterface * service = APPLE_APPLOVIN_SERVICE(); diff --git a/src/Plugins/AppleAppTrackingPlugin/AppleAppTrackingScriptEmbedding.mm b/src/Plugins/AppleAppTrackingPlugin/AppleAppTrackingScriptEmbedding.mm index 3b2f37e779..299e382346 100644 --- a/src/Plugins/AppleAppTrackingPlugin/AppleAppTrackingScriptEmbedding.mm +++ b/src/Plugins/AppleAppTrackingPlugin/AppleAppTrackingScriptEmbedding.mm @@ -39,7 +39,7 @@ static void AppleAppTracking_authorization(const pybind::object & _cb, const pyb bool AppleAppTrackingScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleAppTracking", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleAppTracking"), true ); pybind::enum_( _kernel, "AppleAppTrackingAuthorization" ) .def( "EAATA_NONE", EAATA_NONE ) diff --git a/src/Plugins/AppleFacebookPlugin/AppleFacebookScriptEmbedding.mm b/src/Plugins/AppleFacebookPlugin/AppleFacebookScriptEmbedding.mm index 20a061321b..7f5b347844 100644 --- a/src/Plugins/AppleFacebookPlugin/AppleFacebookScriptEmbedding.mm +++ b/src/Plugins/AppleFacebookPlugin/AppleFacebookScriptEmbedding.mm @@ -118,7 +118,7 @@ static void AppleFacebook_setProvider(const pybind::dict & _cbs, const pybind::a bool AppleFacebookScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleFacebook", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleFacebook"), true ); AppleFacebookServiceInterface * service = APPLE_FACEBOOK_SERVICE(); diff --git a/src/Plugins/AppleFirebaseRemoteConfigPlugin/AppleFirebaseRemoteConfigScriptEmbedding.mm b/src/Plugins/AppleFirebaseRemoteConfigPlugin/AppleFirebaseRemoteConfigScriptEmbedding.mm index e8b70dc088..6ea3ea7601 100644 --- a/src/Plugins/AppleFirebaseRemoteConfigPlugin/AppleFirebaseRemoteConfigScriptEmbedding.mm +++ b/src/Plugins/AppleFirebaseRemoteConfigPlugin/AppleFirebaseRemoteConfigScriptEmbedding.mm @@ -27,7 +27,7 @@ bool AppleFirebaseRemoteConfigScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleFirebaseRemoteConfig", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleFirebaseRemoteConfig"), true ); AppleFirebaseRemoteConfigServiceInterface * service = APPLE_FIREBASE_REMOTECONFIG_SERVICE(); diff --git a/src/Plugins/AppleGameCenterPlugin/AppleGameCenterScriptEmbedding.mm b/src/Plugins/AppleGameCenterPlugin/AppleGameCenterScriptEmbedding.mm index e92effb214..0c78b90733 100644 --- a/src/Plugins/AppleGameCenterPlugin/AppleGameCenterScriptEmbedding.mm +++ b/src/Plugins/AppleGameCenterPlugin/AppleGameCenterScriptEmbedding.mm @@ -88,7 +88,7 @@ static bool AppleGameCenter_reportScore( const ConstString & _key, int64_t _scor bool AppleGameCenterScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleGameCenter", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleGameCenter"), true ); AppleGameCenterServiceInterface * service = APPLE_GAMECENTER_SERVICE(); diff --git a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm index e280a3aeda..8d09dce8eb 100644 --- a/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm +++ b/src/Plugins/AppleGeneralDataProtectionRegulationPlugin/AppleGeneralDataProtectionRegulationScriptEmbedding.mm @@ -26,7 +26,7 @@ bool AppleGeneralDataProtectionRegulationScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleGeneralDataProtectionRegulation", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleGeneralDataProtectionRegulation"), true ); AppleGeneralDataProtectionRegulationServiceInterface * service = APPLE_GENERALDATAPROTECTIONREGULATION_SERVICE(); @@ -39,7 +39,7 @@ void AppleGeneralDataProtectionRegulationScriptEmbedding::eject( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleGeneralDataProtectionRegulation", false ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleGeneralDataProtectionRegulation"), false ); _kernel->remove_from_module( "appleSetGDPRPass", nullptr ); _kernel->remove_from_module( "appleIsGDPRPass", nullptr ); diff --git a/src/Plugins/AppleMARSDKPlugin/AppleMARSDKScriptEmbedding.mm b/src/Plugins/AppleMARSDKPlugin/AppleMARSDKScriptEmbedding.mm index 0b76d24473..6e47fdddab 100644 --- a/src/Plugins/AppleMARSDKPlugin/AppleMARSDKScriptEmbedding.mm +++ b/src/Plugins/AppleMARSDKPlugin/AppleMARSDKScriptEmbedding.mm @@ -211,7 +211,7 @@ static int64_t AppleMARSDK_getInternetDate() bool AppleMARSDKScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleMARSDK", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleMARSDK"), true ); pybind::def_function_kernel_args( _kernel, "appleMARSDKSetProvider", &Detail::AppleMARSDK_setProvider ); pybind::def_function( _kernel, "appleMARSDKLogin", &Detail::AppleMARSDK_login ); diff --git a/src/Plugins/AppleStoreInAppPurchasePlugin/AppleStoreInAppPurchaseScriptEmbedding.mm b/src/Plugins/AppleStoreInAppPurchasePlugin/AppleStoreInAppPurchaseScriptEmbedding.mm index 87b69132f6..c1b5b92f37 100644 --- a/src/Plugins/AppleStoreInAppPurchasePlugin/AppleStoreInAppPurchaseScriptEmbedding.mm +++ b/src/Plugins/AppleStoreInAppPurchasePlugin/AppleStoreInAppPurchaseScriptEmbedding.mm @@ -174,7 +174,7 @@ static void s_AppleStoreInAppPurchase_restoreCompletedTransactions() bool AppleStoreInAppPurchaseScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleStoreInAppPurchase", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleStoreInAppPurchase"), true ); AppleStoreInAppPurchaseServiceInterface * service = APPLE_STOREINAPPPURCHASE_SERVICE(); diff --git a/src/Plugins/AppleStoreReviewPlugin/AppleStoreReviewScriptEmbedding.mm b/src/Plugins/AppleStoreReviewPlugin/AppleStoreReviewScriptEmbedding.mm index e6b699d7b8..a876802c63 100644 --- a/src/Plugins/AppleStoreReviewPlugin/AppleStoreReviewScriptEmbedding.mm +++ b/src/Plugins/AppleStoreReviewPlugin/AppleStoreReviewScriptEmbedding.mm @@ -26,7 +26,7 @@ bool AppleStoreReviewScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AppleStoreReview", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AppleStoreReview"), true ); AppleStoreReviewServiceInterface * service = APPLE_STOREREVIEW_SERVICE(); diff --git a/src/Plugins/AreaOfInterestPlugin/AreaOfInterestScriptEmbedding.cpp b/src/Plugins/AreaOfInterestPlugin/AreaOfInterestScriptEmbedding.cpp index a3e98b1fbc..57bde8fe55 100644 --- a/src/Plugins/AreaOfInterestPlugin/AreaOfInterestScriptEmbedding.cpp +++ b/src/Plugins/AreaOfInterestPlugin/AreaOfInterestScriptEmbedding.cpp @@ -88,7 +88,7 @@ namespace Mengine bool AreaOfInterestScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "AreaOfInterest", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("AreaOfInterest"), true ); pybind::interface_>( _kernel, "AreaOfInterestZoneInterface" ) .def( "freeze", &AreaOfInterestZoneInterface::freeze ) diff --git a/src/Plugins/AstralaxPlugin/AstralaxScriptEmbedding.cpp b/src/Plugins/AstralaxPlugin/AstralaxScriptEmbedding.cpp index bb9f7f54eb..a3b7e399fd 100644 --- a/src/Plugins/AstralaxPlugin/AstralaxScriptEmbedding.cpp +++ b/src/Plugins/AstralaxPlugin/AstralaxScriptEmbedding.cpp @@ -62,7 +62,7 @@ namespace Mengine bool AstralaxScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Astralax", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Astralax"), true ); pybind::interface_>( _kernel, "ResourceAstralax", false ) .def( "getResourceImageCount", &ResourceAstralax::getResourceImageCount ) diff --git a/src/Plugins/DevToDebugPlugin/DevToDebugScriptEmbedding.cpp b/src/Plugins/DevToDebugPlugin/DevToDebugScriptEmbedding.cpp index 479bf80fc4..051616f1cf 100644 --- a/src/Plugins/DevToDebugPlugin/DevToDebugScriptEmbedding.cpp +++ b/src/Plugins/DevToDebugPlugin/DevToDebugScriptEmbedding.cpp @@ -404,7 +404,7 @@ namespace Mengine bool DevToDebugScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "DevToDebug", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("DevToDebug"), true ); pybind::def_function( _kernel, "addDevToDebugTab", &Detail::addDevToDebugTab ); pybind::def_function( _kernel, "getDevToDebugTab", &Detail::getDevToDebugTab ); diff --git a/src/Plugins/DevToDebugPlugin/DevToDebugService.cpp b/src/Plugins/DevToDebugPlugin/DevToDebugService.cpp index 78cede2f11..2b6cefe13e 100644 --- a/src/Plugins/DevToDebugPlugin/DevToDebugService.cpp +++ b/src/Plugins/DevToDebugPlugin/DevToDebugService.cpp @@ -54,7 +54,7 @@ extern "C" { ////////////////////////////////////////////////////////////////////////// - JNIEXPORT jboolean JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidDevDebuggerMengine_1createDevTab )(JNIEnv * env, jclass cls, jstring _tab) + JNIEXPORT jboolean JNICALL MENGINE_JAVA_INTERFACE( AndroidDevDebuggerMengine_1createDevTab )(JNIEnv * env, jclass cls, jstring _tab) { Mengine::ConstString tab_cstr = Mengine::Helper::AndroidMakeConstStringFromJString( env, _tab ); @@ -76,7 +76,7 @@ extern "C" return JNI_TRUE; } ////////////////////////////////////////////////////////////////////////// - JNIEXPORT void JNICALL MENGINE_ACTIVITY_JAVA_INTERFACE( AndroidDevDebuggerMengine_1addDevButton )(JNIEnv * env, jclass cls, jstring _tab, jstring _id, jstring _title, jobject _cb) + JNIEXPORT void JNICALL MENGINE_JAVA_INTERFACE( AndroidDevDebuggerMengine_1addDevButton )(JNIEnv * env, jclass cls, jstring _tab, jstring _id, jstring _title, jobject _cb) { Mengine::ConstString tab = Mengine::Helper::AndroidMakeConstStringFromJString( env, _tab ); Mengine::ConstString id = Mengine::Helper::AndroidMakeConstStringFromJString( env, _id ); diff --git a/src/Plugins/GraphicsPlugin/GraphicsScriptEmbedding.cpp b/src/Plugins/GraphicsPlugin/GraphicsScriptEmbedding.cpp index fe915a34b2..ed764a3bf9 100644 --- a/src/Plugins/GraphicsPlugin/GraphicsScriptEmbedding.cpp +++ b/src/Plugins/GraphicsPlugin/GraphicsScriptEmbedding.cpp @@ -28,7 +28,7 @@ namespace Mengine bool GraphicsScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Graphics", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Graphics"), true ); pybind::interface_>( _kernel, "Graphics", false ) .def( "setLineWidth", &Graphics::setLineWidth ) diff --git a/src/Plugins/ImGUIPlugin/ImGUIScriptEmbedding.cpp b/src/Plugins/ImGUIPlugin/ImGUIScriptEmbedding.cpp index 744f186894..d16688b6c9 100644 --- a/src/Plugins/ImGUIPlugin/ImGUIScriptEmbedding.cpp +++ b/src/Plugins/ImGUIPlugin/ImGUIScriptEmbedding.cpp @@ -30,7 +30,7 @@ namespace Mengine bool ImGUIScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "ImGUI", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("ImGUI"), true ); pybind::interface_>( _kernel, "ImGUIScriptRender", false ) ; diff --git a/src/Plugins/JSONPlugin/JSONScriptEmbedding.cpp b/src/Plugins/JSONPlugin/JSONScriptEmbedding.cpp index bc601c377d..9d9ececaa1 100644 --- a/src/Plugins/JSONPlugin/JSONScriptEmbedding.cpp +++ b/src/Plugins/JSONPlugin/JSONScriptEmbedding.cpp @@ -105,7 +105,7 @@ namespace Mengine bool JSONScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "JSON", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("JSON"), true ); pybind::interface_>( _kernel, "ResourceJSON", false ) .def_static_kernel( "getJSON", &Helper::s_getJSON ) diff --git a/src/Plugins/MoviePlugin/Movie2ScriptEmbedding.cpp b/src/Plugins/MoviePlugin/Movie2ScriptEmbedding.cpp index ec4f59066f..d0decdf4e2 100644 --- a/src/Plugins/MoviePlugin/Movie2ScriptEmbedding.cpp +++ b/src/Plugins/MoviePlugin/Movie2ScriptEmbedding.cpp @@ -353,7 +353,7 @@ namespace Mengine bool Movie2ScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Movie2", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Movie2"), true ); pybind::interface_>( _kernel, "Movie2", false ) .def( "setResourceMovie2", &Movie2::setResourceMovie2 ) diff --git a/src/Plugins/OzzAnimationPlugin/OzzScriptEmbedding.cpp b/src/Plugins/OzzAnimationPlugin/OzzScriptEmbedding.cpp index 05607d0748..114aecebf7 100644 --- a/src/Plugins/OzzAnimationPlugin/OzzScriptEmbedding.cpp +++ b/src/Plugins/OzzAnimationPlugin/OzzScriptEmbedding.cpp @@ -62,7 +62,7 @@ namespace Mengine bool OzzScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Ozz", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Ozz"), true ); pybind::def_function( _kernel, "createOzzSampler", &Detail::createOzzSampler ); diff --git a/src/Plugins/PathfinderPlugin/PathfinderScriptEmbedding.cpp b/src/Plugins/PathfinderPlugin/PathfinderScriptEmbedding.cpp index 2418712fd3..e3b27cc0c9 100644 --- a/src/Plugins/PathfinderPlugin/PathfinderScriptEmbedding.cpp +++ b/src/Plugins/PathfinderPlugin/PathfinderScriptEmbedding.cpp @@ -25,7 +25,7 @@ namespace Mengine bool PathfinderScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Pathfinder", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Pathfinder"), true ); MENGINE_UNUSED( _kernel ); diff --git a/src/Plugins/ResourcePrefetcherPlugin/ResourcePrefetcherScriptEmbedding.cpp b/src/Plugins/ResourcePrefetcherPlugin/ResourcePrefetcherScriptEmbedding.cpp index 786bab46b2..7154601168 100644 --- a/src/Plugins/ResourcePrefetcherPlugin/ResourcePrefetcherScriptEmbedding.cpp +++ b/src/Plugins/ResourcePrefetcherPlugin/ResourcePrefetcherScriptEmbedding.cpp @@ -201,7 +201,7 @@ namespace Mengine bool ResourcePrefetcherScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "ResourcePrefetcher", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("ResourcePrefetcher"), true ); pybind::def_function_args( _kernel, "prefetchResources", &Detail::prefetchResources ); pybind::def_function( _kernel, "unfetchResources", &Detail::unfetchResources ); diff --git a/src/Plugins/SpinePlugin/SpineScriptEmbedding.cpp b/src/Plugins/SpinePlugin/SpineScriptEmbedding.cpp index ce32377096..5319a09d7b 100644 --- a/src/Plugins/SpinePlugin/SpineScriptEmbedding.cpp +++ b/src/Plugins/SpinePlugin/SpineScriptEmbedding.cpp @@ -68,7 +68,7 @@ namespace Mengine bool SpineScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Spine", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Spine"), true ); pybind::interface_ >( _kernel, "Spine", false ) .def( "setResourceSpineSkeleton", &Spine::setResourceSpineSkeleton ) diff --git a/src/Plugins/SteamPlugin/SteamScriptEmbedding.cpp b/src/Plugins/SteamPlugin/SteamScriptEmbedding.cpp index b565d90da4..a6c060a505 100644 --- a/src/Plugins/SteamPlugin/SteamScriptEmbedding.cpp +++ b/src/Plugins/SteamPlugin/SteamScriptEmbedding.cpp @@ -90,7 +90,7 @@ namespace Mengine bool SteamScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Steam", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Steam"), true ); pybind::def_function( _kernel, "steamSetAchievement", &Detail::steamSetAchievement ); pybind::def_function_kernel( _kernel, "steamGetAchievement", &Detail::steamGetAchievement ); diff --git a/src/Plugins/TexturepackerPlugin/TexturepackerScriptEmbedding.cpp b/src/Plugins/TexturepackerPlugin/TexturepackerScriptEmbedding.cpp index 5cd99b8ee5..f62bc8f6b4 100644 --- a/src/Plugins/TexturepackerPlugin/TexturepackerScriptEmbedding.cpp +++ b/src/Plugins/TexturepackerPlugin/TexturepackerScriptEmbedding.cpp @@ -48,7 +48,7 @@ namespace Mengine bool TexturepackerScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Texturepacker", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Texturepacker"), true ); pybind::interface_>( _kernel, "ResourceTexturepacker", false ) .def_static( "getFrame", &Detail::ResourceTexturepacker_getFrame ) diff --git a/src/Plugins/VideoPlugin/VideoScriptEmbedding.cpp b/src/Plugins/VideoPlugin/VideoScriptEmbedding.cpp index 94ec3ac712..eb9fc162c7 100644 --- a/src/Plugins/VideoPlugin/VideoScriptEmbedding.cpp +++ b/src/Plugins/VideoPlugin/VideoScriptEmbedding.cpp @@ -92,7 +92,7 @@ namespace Mengine bool VideoScriptEmbedding::embed( pybind::kernel_interface * _kernel ) { SCRIPT_SERVICE() - ->setAvailablePlugin( "Video", true ); + ->setAvailablePlugin( STRINGIZE_STRING_LOCAL("Video"), true ); pybind::interface_>( _kernel, "ResourceVideo", false ) .def( "setFrameRate", &ResourceVideo::setFrameRate )