diff --git a/src/main/java/com/faendir/rhino_android/AndroidContextFactory.java b/src/main/java/com/faendir/rhino_android/AndroidContextFactory.java index dcc385a..348db6a 100644 --- a/src/main/java/com/faendir/rhino_android/AndroidContextFactory.java +++ b/src/main/java/com/faendir/rhino_android/AndroidContextFactory.java @@ -29,7 +29,6 @@ * @author F43nd1r * @since 11.01.2016 */ -@VisibleForTesting public class AndroidContextFactory extends ContextFactory { private final File cacheDirectory; @@ -50,9 +49,8 @@ public AndroidContextFactory(File cacheDirectory) { * @param parent the parent of the create classloader * @return a new ClassLoader */ - @VisibleForTesting @Override - public BaseAndroidClassLoader createClassLoader(ClassLoader parent) { + protected BaseAndroidClassLoader createClassLoader(ClassLoader parent) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return new InMemoryAndroidClassLoader(parent); } diff --git a/src/main/java/com/faendir/rhino_android/RhinoAndroidHelper.java b/src/main/java/com/faendir/rhino_android/RhinoAndroidHelper.java index 26722e9..235095d 100644 --- a/src/main/java/com/faendir/rhino_android/RhinoAndroidHelper.java +++ b/src/main/java/com/faendir/rhino_android/RhinoAndroidHelper.java @@ -16,7 +16,6 @@ package com.faendir.rhino_android; -import androidx.annotation.VisibleForTesting; import org.mozilla.javascript.Context; import org.mozilla.javascript.ContextFactory; import org.mozilla.javascript.SecurityController; @@ -35,8 +34,10 @@ public class RhinoAndroidHelper { /** * Constructs a new helper using the default temporary directory. - * Note: It is recommended to use a custom directory, so no permission problems occur. + * + * @deprecated permission issues may occur. */ + @Deprecated public RhinoAndroidHelper() { this(new File(System.getProperty("java.io.tmpdir", "."), "classes")); } @@ -59,6 +60,15 @@ public RhinoAndroidHelper(File cacheDirectory) { this.cacheDirectory = cacheDirectory; } + /** + * @return a context prepared for android + * @deprecated use {@link #enterContext()} instead + */ + @Deprecated + public static Context prepareContext() { + return new RhinoAndroidHelper().enterContext(); + } + /** * call this instead of {@link Context#enter()} * @@ -73,26 +83,25 @@ public Context enterContext() { /** * @return The Context factory which has to be used on android. */ - @VisibleForTesting public AndroidContextFactory getContextFactory() { AndroidContextFactory factory; if (!ContextFactory.hasExplicitGlobal()) { - factory = new AndroidContextFactory(cacheDirectory); + factory = createAndroidContextFactory(cacheDirectory); ContextFactory.getGlobalSetter().setContextFactoryGlobal(factory); } else if (!(ContextFactory.getGlobal() instanceof AndroidContextFactory)) { throw new IllegalStateException("Cannot initialize factory for Android Rhino: There is already another factory"); } else { - factory = (AndroidContextFactory) ContextFactory.getGlobal(); + factory = (AndroidContextFactory)ContextFactory.getGlobal(); } return factory; } /** - * @return a context prepared for android - * @deprecated use {@link #enterContext()} instead + * Override this to modify the context factory. + * + * @return a new {@link AndroidContextFactory} */ - @Deprecated - public static Context prepareContext() { - return new RhinoAndroidHelper().enterContext(); + protected AndroidContextFactory createAndroidContextFactory(File cacheDirectory) { + return new AndroidContextFactory(cacheDirectory); } }