Use Android 5.0 APIs

This commit is contained in:
khanhduytran0 2020-10-08 09:58:10 +07:00
parent 62533deb39
commit 27c2cbc2b1
3 changed files with 5 additions and 45 deletions

View File

@ -101,7 +101,7 @@ public class JREUtils
setEnvironment(launchType, "LIBGL_MIPMAP", "3");
setEnvironment(launchType, "MESA_GLSL_CACHE_DIR", ctx.getCacheDir().getAbsolutePath());
setEnvironment(launchType, "LD_LIBRARY_PATH", ldLibraryPath);
setEnvironment(launchType, "PATH", Tools.homeJreDir + "/bin:" + getBridgeOs("getenv", "PATH"));
setEnvironment(launchType, "PATH", Tools.homeJreDir + "/bin:" + Os.getenv("PATH"));
setEnvironment(launchType, "REGAL_GL_VENDOR", "Android");
setEnvironment(launchType, "REGAL_GL_RENDERER", "Regal");
@ -121,35 +121,7 @@ public class JREUtils
if (launchType == Tools.LTYPE_PROCESS) {
Tools.mLaunchShell.writeToProcess("export " + name + "=" + value);
} else {
// Libcore one support all Android versions
getBridgeOs("setenv", name, value, true);
// Class.forName("libcore.io.Os").getMethod("setenv", String.class, String.class, boolean.class).invoke(null, name, value, true);
/*
if (Build.VERSION.SDK_INT < 21) {
Class.forName("libcore.io.Os").getMethod("setenv").invoke(null, name, value, true);
} else {
Class.forName("android.system.Os").getMethod("setenv").invoke(null, name, value, true);
}
*/
}
}
public static Object getBridgeOs(String methodName, Object... objs) throws Throwable {
Class[] classes = new Class[objs.length];
for (int i = 0; i < classes.length; i++) {
if (objs[i] instanceof Boolean) {
classes[i] = boolean.class;
} else {
classes[i] = objs[i].getClass();
}
}
if (Build.VERSION.SDK_INT < 21) {
Class libcoreClass = Class.forName("libcore.io.Libcore");
Object libcoreOs = libcoreClass.getField("os").get(null);
return Class.forName("libcore.io.Os").getMethod(methodName, classes).invoke(libcoreOs, objs);
} else {
// Avoid Android < 5 get ClassNotFoundException
return Class.forName("android.system.Os").getMethod(methodName, classes).invoke(null, objs);
Os.setenv(name, value, true);
}
}

View File

@ -23,6 +23,7 @@ import org.apache.commons.compress.compressors.xz.*;
import org.apache.commons.io.*;
import android.support.v7.app.AlertDialog;
import android.system.*;
public class PojavLoginActivity extends AppCompatActivity
// MineActivity
@ -441,7 +442,7 @@ public class PojavLoginActivity extends AppCompatActivity
try {
// android.system.Os
// Libcore one support all Android versions
JREUtils.getBridgeOs("symlink", tarEntry.getName(), tarEntry.getLinkName());
Os.symlink(tarEntry.getName(), tarEntry.getLinkName());
} catch (Throwable e) {
e.printStackTrace();
}

View File

@ -1,13 +0,0 @@
package net.kdt.pojavlaunch;
import android.support.v7.app.*;
import android.os.*;
public class V3LauncherActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}