Skip to content

Commit

Permalink
Merge pull request #115 from AnBui2004/master
Browse files Browse the repository at this point in the history
Kill Qemu process
  • Loading branch information
xoureldeen authored Sep 16, 2024
2 parents d1ad13d + 6ca0279 commit cac0979
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 0 deletions.
318 changes: 318 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/main/java/com/vectras/qemu/MainVNCActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ public void onClick(DialogInterface dialog, int which) {
// Stop the service
MainService.stopService();
Terminal.killQemuProcess();
VectrasApp.killcurrentqemuprocess(getApplicationContext());
finish();
}

})
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/vectras/vm/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,18 @@ public boolean onOptionsItemSelected(MenuItem item) {

} else if (id == R.id.arch) {
startActivity(new Intent(activity, SetArchActivity.class));
} else if (id == R.id.shutdown) {
AlertDialog alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
alertDialog.setTitle("Do you want to kill all Qemu processes?");
alertDialog.setMessage("All running VMs will be forcibly shut down.");
alertDialog.setCancelable(true);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Kill all", (dialog, which) -> {
VectrasApp.killallqemuprocesses(getApplicationContext());
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", (dialog, which) -> {

});
alertDialog.show();
}

return super.onOptionsItemSelected(item);
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/vectras/vm/VectrasApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.google.android.material.color.DynamicColors;
import com.vectras.qemu.MainSettingsManager;
import com.vectras.vterm.Terminal;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -408,4 +409,32 @@ public void onBackPressed() {
restart();
}
}

public static void killallqemuprocesses(Context context) {
Terminal vterm = new Terminal(context);
vterm.executeShellCommand("killall -9 qemu-system-i386", false, MainActivity.activity);
vterm.executeShellCommand("killall -9 qemu-system-x86_64", false, MainActivity.activity);
vterm.executeShellCommand("killall -9 qemu-system-aarch64", false, MainActivity.activity);
vterm.executeShellCommand("killall -9 qemu-system-ppc", false, MainActivity.activity);
}

public static void killcurrentqemuprocess(Context context) {
Terminal vterm = new Terminal(context);
String env = "killall -9 ";
switch (MainSettingsManager.getArch(MainActivity.activity)) {
case "ARM64":
env += "qemu-system-aarch64";
break;
case "PPC":
env += "qemu-system-ppc";
break;
case "I386":
env += "qemu-system-i386";
break;
default:
env += "qemu-system-x86_64";
break;
}
vterm.executeShellCommand(env, false, MainActivity.activity);
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/power_settings_new_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,396 111.5,323.5Q143,251 197,197L253,253Q209,297 184.5,355Q160,413 160,480Q160,614 253,707Q346,800 480,800Q614,800 707,707Q800,614 800,480Q800,413 775.5,355Q751,297 707,253L763,197Q817,251 848.5,323.5Q880,396 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM440,520L440,80L520,80L520,520L440,520Z"/>
</vector>
Loading

0 comments on commit cac0979

Please sign in to comment.