Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 4a0560c

Browse files
committed
fix api installer
1 parent e2e8373 commit 4a0560c

File tree

7 files changed

+78
-98
lines changed

7 files changed

+78
-98
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15
1+
16
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15
1+
16

HMCLPE/src/main/java/com/tungsten/hmclpe/launcher/download/ApiService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
import com.tungsten.hmclpe.manifest.AppManifest;
99

10+
import net.kdt.pojavlaunch.PojavApiService;
11+
1012
import java.net.DatagramPacket;
1113
import java.net.DatagramSocket;
1214
import java.net.InetSocketAddress;
1315
import java.util.ArrayList;
1416

15-
import cosine.boat.BoatApiService;
16-
17-
public class ApiService extends BoatApiService {
17+
public class ApiService extends PojavApiService {
1818

1919
public static final int API_SERVICE_PORT = 6868;
2020

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package net.kdt.pojavlaunch;
2+
3+
import android.app.Service;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.os.IBinder;
7+
8+
import androidx.annotation.Nullable;
9+
10+
import net.kdt.pojavlaunch.function.ApiInstallerCallback;
11+
import net.kdt.pojavlaunch.utils.JREUtils;
12+
13+
import java.util.ArrayList;
14+
15+
public class PojavApiService extends Service {
16+
17+
public ApiInstallerCallback callback;
18+
19+
@Nullable
20+
@Override
21+
public IBinder onBind(Intent intent) {
22+
return null;
23+
}
24+
25+
public void startApiInstaller(String javaPath, ArrayList<String> commands, String debugDir, ApiInstallerCallback callback) {
26+
this.callback = callback;
27+
new Thread(() -> {
28+
int exitCode = JREUtils.launchAPIInstaller(getApplicationContext(), javaPath, commands, debugDir);
29+
onExit(PojavApiService.this,exitCode);
30+
}).start();
31+
}
32+
33+
public static void onExit(Context context, int exitCode) {
34+
((PojavApiService) context).callback.onExit(exitCode);
35+
((PojavApiService) context).stopSelf();
36+
}
37+
38+
@Override
39+
public void onDestroy() {
40+
android.os.Process.killProcess(android.os.Process.myPid());
41+
super.onDestroy();
42+
}
43+
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package net.kdt.pojavlaunch.function;
2+
3+
public interface ApiInstallerCallback {
4+
void onExit(int code);
5+
}

PojavLauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java

Lines changed: 7 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -272,25 +272,25 @@ public static int launchJavaVM(final Activity activity,String javaPath,String ho
272272
return exitCode;
273273
}
274274

275-
public static int launchAPIInstaller(Activity activity,String javaPath, Vector<String> args, String home) {
275+
public static int launchAPIInstaller(Context context,String javaPath, ArrayList<String> args, String home) {
276276
try {
277-
redirectAndPrintJRELog(activity);
278-
relocateLibPath(activity,javaPath);
277+
args.remove(0);
278+
redirectAndPrintJRELog(context);
279+
relocateLibPath(context,javaPath);
279280
Os.setenv("HOME", home, true);
280281
Os.setenv("JAVA_HOME" , javaPath, true);
281282
File serverFile = new File(javaPath + "/lib/server/libjvm.so");
282283
jvmLibraryPath = javaPath + "/lib/" + (serverFile.exists() ? "server" : "client");
283284
Log.d("DynamicLoader","Base LD_LIBRARY_PATH: " + LD_LIBRARY_PATH);
284285
Log.d("DynamicLoader","Internal LD_LIBRARY_PATH: " + jvmLibraryPath + ":" + LD_LIBRARY_PATH);
285286
setLdLibraryPath(jvmLibraryPath + ":" + LD_LIBRARY_PATH);
286-
List<String> userArgs = new ArrayList<>();
287-
userArgs.addAll(args);
287+
List<String> userArgs = new ArrayList<>(args);
288288
initJavaRuntime(javaPath);
289-
setupExitTrap(activity.getApplication());
289+
setupExitTrap(context);
290290
chdir(home);
291291
userArgs.add(0,"java");
292292
final int exitCode = VMLauncher.launchJVM((String[]) userArgs.toArray(new String[0]));
293-
Logger.getInstance(activity).appendToLog("Java Exit code: " + exitCode);
293+
Logger.getInstance(context).appendToLog("Java Exit code: " + exitCode);
294294
return exitCode;
295295
} catch (ErrnoException | IOException e) {
296296
e.printStackTrace();
@@ -391,92 +391,6 @@ public static String findInLdLibPath(String libName) {
391391
return libName;
392392
}
393393

394-
/**
395-
* Remove the argument from the list, if it exists
396-
* If the argument exists multiple times, they will all be removed.
397-
* @param argList The argument list to purge
398-
* @param argStart The argument to purge from the list.
399-
*/
400-
private static void purgeArg(List<String> argList, String argStart) {
401-
for(int i = 0; i < argList.size(); i++) {
402-
final String arg = argList.get(i);
403-
if(arg.startsWith(argStart)) {
404-
argList.remove(i);
405-
}
406-
}
407-
}
408-
private static final int EGL_OPENGL_ES_BIT = 0x0001;
409-
private static final int EGL_OPENGL_ES2_BIT = 0x0004;
410-
private static final int EGL_OPENGL_ES3_BIT_KHR = 0x0040;
411-
private static boolean hasExtension(String extensions, String name) {
412-
int start = extensions.indexOf(name);
413-
while (start >= 0) {
414-
// check that we didn't find a prefix of a longer extension name
415-
int end = start + name.length();
416-
if (end == extensions.length() || extensions.charAt(end) == ' ') {
417-
return true;
418-
}
419-
start = extensions.indexOf(name, end);
420-
}
421-
return false;
422-
}
423-
private static int getDetectedVersion() {
424-
/*
425-
* Get all the device configurations and check the EGL_RENDERABLE_TYPE attribute
426-
* to determine the highest ES version supported by any config. The
427-
* EGL_KHR_create_context extension is required to check for ES3 support; if the
428-
* extension is not present this test will fail to detect ES3 support. This
429-
* effectively makes the extension mandatory for ES3-capable devices.
430-
*/
431-
EGL10 egl = (EGL10) EGLContext.getEGL();
432-
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
433-
int[] numConfigs = new int[1];
434-
if (egl.eglInitialize(display, null)) {
435-
try {
436-
boolean checkES3 = hasExtension(egl.eglQueryString(display, EGL10.EGL_EXTENSIONS),
437-
"EGL_KHR_create_context");
438-
if (egl.eglGetConfigs(display, null, 0, numConfigs)) {
439-
EGLConfig[] configs = new EGLConfig[numConfigs[0]];
440-
if (egl.eglGetConfigs(display, configs, numConfigs[0], numConfigs)) {
441-
int highestEsVersion = 0;
442-
int[] value = new int[1];
443-
for (int i = 0; i < numConfigs[0]; i++) {
444-
if (egl.eglGetConfigAttrib(display, configs[i],
445-
EGL10.EGL_RENDERABLE_TYPE, value)) {
446-
if (checkES3 && ((value[0] & EGL_OPENGL_ES3_BIT_KHR) ==
447-
EGL_OPENGL_ES3_BIT_KHR)) {
448-
if (highestEsVersion < 3) highestEsVersion = 3;
449-
} else if ((value[0] & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT) {
450-
if (highestEsVersion < 2) highestEsVersion = 2;
451-
} else if ((value[0] & EGL_OPENGL_ES_BIT) == EGL_OPENGL_ES_BIT) {
452-
if (highestEsVersion < 1) highestEsVersion = 1;
453-
}
454-
} else {
455-
Log.w("glesDetect", "Getting config attribute with "
456-
+ "EGL10#eglGetConfigAttrib failed "
457-
+ "(" + i + "/" + numConfigs[0] + "): "
458-
+ egl.eglGetError());
459-
}
460-
}
461-
return highestEsVersion;
462-
} else {
463-
Log.e("glesDetect", "Getting configs with EGL10#eglGetConfigs failed: "
464-
+ egl.eglGetError());
465-
return -1;
466-
}
467-
} else {
468-
Log.e("glesDetect", "Getting number of configs with EGL10#eglGetConfigs failed: "
469-
+ egl.eglGetError());
470-
return -2;
471-
}
472-
} finally {
473-
egl.eglTerminate(display);
474-
}
475-
} else {
476-
Log.e("glesDetect", "Couldn't initialize EGL.");
477-
return -3;
478-
}
479-
}
480394
public static native int chdir(String path);
481395
public static native void logToLogger(final Logger logger);
482396
public static native boolean dlopen(String libPath);

0 commit comments

Comments
 (0)