Skip to content

Commit

Permalink
fix: call System.exit()
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Feb 20, 2024
1 parent 4477c13 commit d156f8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 14 additions & 7 deletions app/src/main/java/xtr/keymapper/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.annotation.NonNull;

import com.topjohnwu.superuser.CallbackList;
import com.topjohnwu.superuser.Shell;

Expand All @@ -23,6 +25,15 @@ public class Server {
public File script;
public MainActivity.Callback mCallback;

static {
// Set settings before the main shell can be created
Shell.enableVerboseLogging = false;
Shell.setDefaultBuilder(Shell.Builder.create()
.setFlags(Shell.FLAG_REDIRECT_STDERR)
.setTimeout(10)
);
}

private void writeScript(ApplicationInfo ai) throws IOException, InterruptedException {
final String className = RemoteService.class.getName();

Expand Down Expand Up @@ -64,15 +75,11 @@ public void onAddElement(String line) {

public void startServer() {
mCallback.updateCmdView1("exec sh " + script.getPath() + "\n");
try {
if (Shell.getCachedShell() != null)
Shell.getCachedShell().close();
} catch (IOException ignored) {
}
Shell.getShell(shell -> {
if (!shell.isRoot()) mCallback.alertRootAccessNotFound();
try {
Shell.cmd(new FileInputStream(script)).to(callbackList).submit();
else try {
Shell.cmd(new FileInputStream(script)).to(callbackList)
.submit(out -> System.exit(1));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/xtr/keymapper/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public void alertRootAccessNotFound() {
.setPositiveButton("OK", (dialog, which) -> {
Intent launchIntent = MainActivity.this.getPackageManager().getLaunchIntentForPackage("me.weishu.kernelsu");
if (launchIntent != null) startActivity(launchIntent);
finishAffinity();
System.exit(0);
});
runOnUiThread(() -> builder.create().show());
}
Expand Down

0 comments on commit d156f8a

Please sign in to comment.