From e5d33b77fb0b019043d095d8d8347801bfc6da1b Mon Sep 17 00:00:00 2001 From: opacam Date: Mon, 28 Jan 2019 22:58:10 +0100 Subject: [PATCH] Remove the libraries loading mechanism Because we have proved that we don't need that (we take care of that in gradle configuration)...so...there is no need to keep the loading mechanism to only load a single library `libmain.so` which is the only one we need to load...all others will be loaded automatically by the android os library system. Note: This changes affects bootstraps: sdl2, webview and service_only --- .../java/org/kivy/android/PythonService.java | 6 +- .../java/org/kivy/android/PythonUtil.java | 82 -------------- .../java/org/kivy/android/PythonActivity.java | 7 -- .../java/org/kivy/android/PythonUtil.java | 100 ------------------ .../main/java/org/libsdl/app/SDLActivity.java | 95 ++++++----------- .../java/org/kivy/android/PythonActivity.java | 10 +- .../java/org/kivy/android/PythonActivity.java | 10 +- 7 files changed, 34 insertions(+), 276 deletions(-) delete mode 100644 pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java delete mode 100644 pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java diff --git a/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java b/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java index 1f4eb83594..e965e3dfbd 100644 --- a/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java +++ b/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java @@ -14,8 +14,6 @@ import android.os.Process; import java.io.File; -import org.kivy.android.PythonUtil; - import org.renpy.android.Hardware; @@ -142,9 +140,7 @@ public void onTaskRemoved(Intent rootIntent) { @Override public void run(){ - String app_root = getFilesDir().getAbsolutePath() + "/app"; - File app_root_file = new File(app_root); - PythonUtil.loadLibraries(app_root_file); + System.loadLibrary("main"); this.mService = this; nativeStart( androidPrivate, androidArgument, diff --git a/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java b/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java deleted file mode 100644 index 37df5f9265..0000000000 --- a/pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.kivy.android; - -import java.io.File; - -import android.util.Log; -import java.util.ArrayList; -import java.io.FilenameFilter; -import java.util.regex.Pattern; - - -public class PythonUtil { - private static final String TAG = "pythonutil"; - - protected static void addLibraryIfExists(ArrayList libsList, String pattern, File libsDir) { - // pattern should be the name of the lib file, without the - // preceding "lib" or suffix ".so", for instance "ssl.*" will - // match files of the form "libssl.*.so". - File [] files = libsDir.listFiles(); - - pattern = "lib" + pattern + "\\.so"; - Pattern p = Pattern.compile(pattern); - for (int i = 0; i < files.length; ++i) { - File file = files[i]; - String name = file.getName(); - Log.v(TAG, "Checking pattern " + pattern + " against " + name); - if (p.matcher(name).matches()) { - Log.v(TAG, "Pattern " + pattern + " matched file " + name); - libsList.add(name.substring(3, name.length() - 3)); - } - } - } - - protected static ArrayList getLibraries(File filesDir) { - - String libsDirPath = filesDir.getParentFile().getParentFile().getAbsolutePath() + "/lib/"; - File libsDir = new File(libsDirPath); - - ArrayList libsList = new ArrayList(); - addLibraryIfExists(libsList, "crystax", libsDir); - addLibraryIfExists(libsList, "sqlite3", libsDir); - addLibraryIfExists(libsList, "ffi", libsDir); - addLibraryIfExists(libsList, "ssl.*", libsDir); - addLibraryIfExists(libsList, "crypto.*", libsDir); - libsList.add("python2.7"); - libsList.add("python3.5m"); - libsList.add("python3.6m"); - libsList.add("python3.7m"); - libsList.add("main"); - return libsList; - } - - public static void loadLibraries(File filesDir) { - - String filesDirPath = filesDir.getAbsolutePath(); - boolean foundPython = false; - - for (String lib : getLibraries(filesDir)) { - Log.v(TAG, "Loading library: " + lib); - try { - System.loadLibrary(lib); - if (lib.startsWith("python")) { - foundPython = true; - } - } catch(UnsatisfiedLinkError e) { - // If this is the last possible libpython - // load, and it has failed, give a more - // general error - Log.v(TAG, "Library loading error: " + e.getMessage()); - if (lib.startsWith("python3.7") && !foundPython) { - throw new java.lang.RuntimeException("Could not load any libpythonXXX.so"); - } else if (lib.startsWith("python")) { - continue; - } else { - Log.v(TAG, "An UnsatisfiedLinkError occurred loading " + lib); - throw e; - } - } - } - - Log.v(TAG, "Loaded everything!"); - } -} diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java index c3db253092..3cbdb5dabc 100644 --- a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java +++ b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java @@ -43,7 +43,6 @@ import org.libsdl.app.SDL; import org.libsdl.app.SDLActivity; -import org.kivy.android.PythonUtil; import org.kivy.android.launcher.Project; import org.renpy.android.ResourceManager; @@ -80,12 +79,6 @@ protected void onCreate(Bundle savedInstanceState) { new UnpackFilesTask().execute(getAppRoot()); } - public void loadLibraries() { - String app_root = new String(getAppRoot()); - File app_root_file = new File(app_root); - PythonUtil.loadLibraries(app_root_file); - } - public void recursiveDelete(File f) { if (f.isDirectory()) { for (File r : f.listFiles()) { diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java deleted file mode 100644 index 3b4429c9a9..0000000000 --- a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.kivy.android; - -import java.io.File; - -import android.util.Log; -import java.util.ArrayList; -import java.io.FilenameFilter; -import java.util.regex.Pattern; - -public class PythonUtil { - private static final String TAG = "pythonutil"; - - protected static void addLibraryIfExists(ArrayList libsList, String pattern, File libsDir) { - // pattern should be the name of the lib file, without the - // preceding "lib" or suffix ".so", for instance "ssl.*" will - // match files of the form "libssl.*.so". - File [] files = libsDir.listFiles(); - - pattern = "lib" + pattern + "\\.so"; - Pattern p = Pattern.compile(pattern); - for (int i = 0; i < files.length; ++i) { - File file = files[i]; - String name = file.getName(); - Log.v(TAG, "Checking pattern " + pattern + " against " + name); - if (p.matcher(name).matches()) { - Log.v(TAG, "Pattern " + pattern + " matched file " + name); - libsList.add(name.substring(3, name.length() - 3)); - } - } - } - - protected static ArrayList getLibraries(File filesDir) { - - String libsDirPath = filesDir.getParentFile().getParentFile().getAbsolutePath() + "/lib/"; - File libsDir = new File(libsDirPath); - - ArrayList libsList = new ArrayList(); - addLibraryIfExists(libsList, "crystax", libsDir); - addLibraryIfExists(libsList, "sqlite3", libsDir); - addLibraryIfExists(libsList, "ffi", libsDir); - libsList.add("SDL2"); - libsList.add("SDL2_image"); - libsList.add("SDL2_mixer"); - libsList.add("SDL2_ttf"); - addLibraryIfExists(libsList, "ssl.*", libsDir); - addLibraryIfExists(libsList, "crypto.*", libsDir); - libsList.add("python2.7"); - libsList.add("python3.5m"); - libsList.add("python3.6m"); - libsList.add("python3.7m"); - libsList.add("main"); - return libsList; - } - - public static void loadLibraries(File filesDir) { - - String filesDirPath = filesDir.getAbsolutePath(); - boolean foundPython = false; - - for (String lib : getLibraries(filesDir)) { - Log.v(TAG, "Loading library: " + lib); - try { - System.loadLibrary(lib); - if (lib.startsWith("python")) { - foundPython = true; - } - } catch(UnsatisfiedLinkError e) { - // If this is the last possible libpython - // load, and it has failed, give a more - // general error - Log.v(TAG, "Library loading error: " + e.getMessage()); - if (lib.startsWith("python3.7") && !foundPython) { - throw new java.lang.RuntimeException("Could not load any libpythonXXX.so"); - } else if (lib.startsWith("python")) { - continue; - } else { - Log.v(TAG, "An UnsatisfiedLinkError occurred loading " + lib); - throw e; - } - } - } - - try { - System.load(filesDirPath + "/lib/python2.7/lib-dynload/_io.so"); - System.load(filesDirPath + "/lib/python2.7/lib-dynload/unicodedata.so"); - } catch(UnsatisfiedLinkError e) { - Log.v(TAG, "Failed to load _io.so or unicodedata.so...but that's okay."); - } - - try { - // System.loadLibrary("ctypes"); - System.load(filesDirPath + "/lib/python2.7/lib-dynload/_ctypes.so"); - } catch(UnsatisfiedLinkError e) { - Log.v(TAG, "Unsatisfied linker when loading ctypes"); - } - - Log.v(TAG, "Loaded everything!"); - } -} - diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/libsdl/app/SDLActivity.java b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/libsdl/app/SDLActivity.java index 311b2f1df4..71ece7ce10 100644 --- a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/libsdl/app/SDLActivity.java +++ b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/libsdl/app/SDLActivity.java @@ -98,7 +98,7 @@ protected static SDLGenericMotionListener_API12 getMotionListener() { if (mMotionListener == null) { if (Build.VERSION.SDK_INT >= 26) { mMotionListener = new SDLGenericMotionListener_API26(); - } else + } else if (Build.VERSION.SDK_INT >= 24) { mMotionListener = new SDLGenericMotionListener_API24(); } else { @@ -114,14 +114,7 @@ protected static SDLGenericMotionListener_API12 getMotionListener() { * It can be overridden by derived classes. */ protected String getMainSharedObject() { - String library; - String[] libraries = SDLActivity.mSingleton.getLibraries(); - if (libraries.length > 0) { - library = "lib" + libraries[libraries.length - 1] + ".so"; - } else { - library = "libmain.so"; - } - return getContext().getApplicationInfo().nativeLibraryDir + "/" + library; + return getContext().getApplicationInfo().nativeLibraryDir + "/libmain.so"; } /** @@ -132,32 +125,6 @@ protected String getMainFunction() { return "SDL_main"; } - /** - * This method is called by SDL before loading the native shared libraries. - * It can be overridden to provide names of shared libraries to be loaded. - * The default implementation returns the defaults. It never returns null. - * An array returned by a new implementation must at least contain "SDL2". - * Also keep in mind that the order the libraries are loaded may matter. - * @return names of shared libraries to be loaded (e.g. "SDL2", "main"). - */ - protected String[] getLibraries() { - return new String[] { - "SDL2", - // "SDL2_image", - // "SDL2_mixer", - // "SDL2_net", - // "SDL2_ttf", - "main" - }; - } - - // Load the .so - public void loadLibraries() { - for (String lib : getLibraries()) { - SDL.loadLibrary(lib); - } - } - /** * This method is called by SDL before starting the native application thread. * It can be overridden to provide the arguments after the application name. @@ -199,7 +166,7 @@ protected void onCreate(Bundle savedInstanceState) { // Load shared libraries String errorMsgBrokenLib = ""; try { - loadLibraries(); + SDL.loadLibrary("main"); } catch(UnsatisfiedLinkError e) { System.err.println(e.getMessage()); mBrokenLibraries = true; @@ -326,15 +293,15 @@ public static int getCurrentOrientation() { case Surface.ROTATION_0: result = SDL_ORIENTATION_PORTRAIT; break; - + case Surface.ROTATION_90: result = SDL_ORIENTATION_LANDSCAPE; break; - + case Surface.ROTATION_180: result = SDL_ORIENTATION_PORTRAIT_FLIPPED; break; - + case Surface.ROTATION_270: result = SDL_ORIENTATION_LANDSCAPE_FLIPPED; break; @@ -584,7 +551,7 @@ public void handleMessage(Message msg) { View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE; - window.getDecorView().setSystemUiVisibility(flags); + window.getDecorView().setSystemUiVisibility(flags); window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); SDLActivity.mFullscreenModeActive = true; @@ -609,7 +576,7 @@ public void handleMessage(Message msg) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0); - + mScreenKeyboardShown = false; } break; @@ -650,14 +617,14 @@ boolean sendCommand(int command, Object data) { // or 500ms have passed. boolean bShouldWait = false; - + if (data instanceof Integer) { // Let's figure out if we're already laid out fullscreen or not. Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics(); display.getRealMetrics( realMetrics ); - - boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) && + + boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) && (realMetrics.heightPixels == mSurface.getHeight())); if (((Integer)data).intValue() == 1) { @@ -682,7 +649,7 @@ boolean sendCommand(int command, Object data) { // size we need, instead of grabbing a size that's still got // the navigation and/or status bars before they're hidden. // - // We'll wait for up to half a second, because some devices + // We'll wait for up to half a second, because some devices // take a surprisingly long time for the surface resize, but // then we'll just give up and return. // @@ -743,7 +710,7 @@ public static void setWindowStyle(boolean fullscreen) { /** * This method is called by SDL using JNI. * This is a static method for JNI convenience, it calls a non-static method - * so that is can be overridden + * so that is can be overridden */ public static void setOrientation(int w, int h, boolean resizable, String hint) { @@ -751,11 +718,11 @@ public static void setOrientation(int w, int h, boolean resizable, String hint) mSingleton.setOrientationBis(w, h, resizable, hint); } } - + /** * This can be overridden */ - public void setOrientationBis(int w, int h, boolean resizable, String hint) + public void setOrientationBis(int w, int h, boolean resizable, String hint) { int orientation = -1; @@ -795,7 +762,7 @@ public void setOrientationBis(int w, int h, boolean resizable, String hint) /** * This method is called by SDL using JNI. */ - public static boolean isScreenKeyboardShown() + public static boolean isScreenKeyboardShown() { if (mTextEdit == null) { return false; @@ -820,7 +787,7 @@ public static boolean supportsRelativeMouse() return false; } - // DeX mode in Samsung Experience 9.0 and earlier doesn't support relative mice properly under + // DeX mode in Samsung Experience 9.0 and earlier doesn't support relative mice properly under // Android 7 APIs, and simply returns no data under Android 8 APIs. // // This is fixed in Samsung Experience 9.5, which corresponds to Android 8.1.0, and @@ -902,7 +869,7 @@ public static boolean isTablet() { */ public static boolean isChromebook() { return getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management"); - } + } /** * This method is called by SDL using JNI. @@ -948,7 +915,7 @@ public static boolean getManifestEnvironmentVariables() { } } /* environment variables set! */ - return true; + return true; } catch (Exception e) { Log.v("SDL", "exception " + e.toString()); } @@ -956,7 +923,7 @@ public static boolean getManifestEnvironmentVariables() { } // This method is called by SDLControllerManager's API 26 Generic Motion Handler. - public static View getContentView() + public static View getContentView() { return mSingleton.mLayout; } @@ -1011,12 +978,12 @@ public static boolean showTextInput(int x, int y, int w, int h) { } public static boolean isTextInputEvent(KeyEvent event) { - + // Key pressed with Ctrl should be sent as SDL_KEYDOWN/SDL_KEYUP and not SDL_TEXTINPUT if (Build.VERSION.SDK_INT >= 11) { if (event.isCtrlPressed()) { return false; - } + } } return event.isPrintingKey() || event.getKeyCode() == KeyEvent.KEYCODE_SPACE; @@ -1350,7 +1317,7 @@ public void onSystemUiVisibilityChange(int visibility) { } } - } + } /** * This method is called by SDL using JNI. @@ -1862,7 +1829,7 @@ public void onSensorChanged(SensorEvent event) { // Since we may have an orientation set, we won't receive onConfigurationChanged events. // We thus should check here. int newOrientation = SDLActivity.SDL_ORIENTATION_UNKNOWN; - + float x, y; switch (mDisplay.getRotation()) { case Surface.ROTATION_90: @@ -1896,7 +1863,7 @@ public void onSensorChanged(SensorEvent event) { y / SensorManager.GRAVITY_EARTH, event.values[2] / SensorManager.GRAVITY_EARTH); - + } } @@ -1964,7 +1931,7 @@ public boolean onCheckIsTextEditor() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { - /* + /* * This handles the hardware keyboard input */ if (event.getAction() == KeyEvent.ACTION_DOWN) { @@ -2084,7 +2051,7 @@ public boolean deleteSurroundingText(int beforeLength, int afterLength) { while (beforeLength-- > 0) { boolean ret_key = sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)) && sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)); - ret = ret && ret_key; + ret = ret && ret_key; } return ret; } @@ -2103,7 +2070,7 @@ interface SDLClipboardHandler { class SDLClipboardHandler_API11 implements - SDLClipboardHandler, + SDLClipboardHandler, android.content.ClipboardManager.OnPrimaryClipChangedListener { protected android.content.ClipboardManager mClipMgr; @@ -2134,7 +2101,7 @@ public void clipboardSetText(String string) { mClipMgr.setText(string); mClipMgr.addPrimaryClipChangedListener(this); } - + @Override public void onPrimaryClipChanged() { SDLActivity.onNativeClipboardChanged(); @@ -2144,9 +2111,9 @@ public void onPrimaryClipChanged() { class SDLClipboardHandler_Old implements SDLClipboardHandler { - + protected android.text.ClipboardManager mClipMgrOld; - + SDLClipboardHandler_Old() { mClipMgrOld = (android.text.ClipboardManager) SDL.getContext().getSystemService(Context.CLIPBOARD_SERVICE); } diff --git a/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java b/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java index 4ed1b4e10a..486230325e 100644 --- a/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java +++ b/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java @@ -46,8 +46,6 @@ import android.webkit.WebViewClient; import android.webkit.WebView; -import org.kivy.android.PythonUtil; - import org.renpy.android.ResourceManager; import org.renpy.android.AssetExtract; @@ -122,7 +120,7 @@ protected void onCreate(Bundle savedInstanceState) { // Load shared libraries String errorMsgBrokenLib = ""; try { - loadLibraries(); + System.loadLibrary("main"); } catch(UnsatisfiedLinkError e) { System.err.println(e.getMessage()); mBrokenLibraries = true; @@ -198,12 +196,6 @@ public void onDestroy() { android.os.Process.killProcess(android.os.Process.myPid()); } - public void loadLibraries() { - String app_root = new String(getAppRoot()); - File app_root_file = new File(app_root); - PythonUtil.loadLibraries(app_root_file); - } - public void recursiveDelete(File f) { if (f.isDirectory()) { for (File r : f.listFiles()) { diff --git a/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java b/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java index 62e677d5b9..2b28e1ed61 100644 --- a/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java +++ b/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java @@ -48,8 +48,6 @@ import android.webkit.WebViewClient; import android.webkit.WebView; -import org.kivy.android.PythonUtil; - import org.kivy.android.WebViewLoader; import org.renpy.android.ResourceManager; @@ -131,7 +129,7 @@ protected void onCreate(Bundle savedInstanceState) { // Load shared libraries String errorMsgBrokenLib = ""; try { - loadLibraries(); + System.loadLibrary("main"); } catch(UnsatisfiedLinkError e) { System.err.println(e.getMessage()); mBrokenLibraries = true; @@ -229,12 +227,6 @@ public void onDestroy() { android.os.Process.killProcess(android.os.Process.myPid()); } - public void loadLibraries() { - String app_root = new String(getAppRoot()); - File app_root_file = new File(app_root); - PythonUtil.loadLibraries(app_root_file); - } - public void recursiveDelete(File f) { if (f.isDirectory()) { for (File r : f.listFiles()) {