mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-04-29 14:59:50 +00:00
Neapolitan ice cream
This commit is contained in:
parent
2f774f3d7c
commit
aab61cd7b9
10 changed files with 91 additions and 19 deletions
|
|
@ -2,6 +2,8 @@ package com.vectras.vm;
|
|||
|
||||
import static android.content.Intent.ACTION_OPEN_DOCUMENT;
|
||||
|
||||
import static com.vectras.vm.VectrasApp.isFileExists;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
|
|
@ -683,6 +685,7 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
protected void onActivityResult(int requestCode, int resultCode, Intent ReturnedIntent) {
|
||||
super.onActivityResult(requestCode, resultCode, ReturnedIntent);
|
||||
|
||||
checkVMID();
|
||||
File romDir = new File(AppConfig.vmFolder + vmID);
|
||||
romDir.mkdirs();
|
||||
|
||||
|
|
@ -1086,6 +1089,7 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void importCVBI(String _filepath, String _filename) {
|
||||
checkVMID();
|
||||
LinearLayout custom = findViewById(R.id.custom);
|
||||
ImageView ivIcon = findViewById(R.id.ivIcon);
|
||||
if (_filepath.endsWith(".cvbi") || _filepath.endsWith(".cvbi.zip")) {
|
||||
|
|
@ -1468,4 +1472,11 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
ivAddThubnail.setImageResource(R.drawable.round_add_24);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkVMID() {
|
||||
if (isFileExists(AppConfig.maindirpath + "/roms/" + vmID) || vmID.isEmpty()) {
|
||||
vmID = VMManager.idGenerator();
|
||||
port = VMManager.startRandomPort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
app/src/main/java/com/vectras/vm/IOApplication.java
Normal file
23
app/src/main/java/com/vectras/vm/IOApplication.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
public class IOApplication {
|
||||
public static boolean isPortOpen(String host, int port, int timeout) {
|
||||
Socket socket = new Socket();
|
||||
try {
|
||||
socket.connect(new InetSocketAddress(host, port), timeout);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false; // Either timeout or unreachable or refused connection.
|
||||
} finally {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// Handle close exception, or ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import static com.vectras.vm.VectrasApp.getAppInfo;
|
|||
import static com.vectras.vm.utils.LibraryChecker.isPackageInstalled2;
|
||||
import static com.vectras.vm.utils.UIUtils.UIAlert;
|
||||
|
||||
import android.androidVNC.androidVNC;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Dialog;
|
||||
import android.app.NotificationManager;
|
||||
|
|
@ -29,6 +30,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.Settings;
|
||||
import android.text.Html;
|
||||
|
|
@ -1127,8 +1129,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
//TEMPORARY FIX FOR VNC CLOSES
|
||||
//TODO: FIND FIX FOR CRASHING
|
||||
if (MainSettingsManager.getVmUi(activity).equals("VNC") && MainVNCActivity.started && VectrasApp.isQemuRunning())
|
||||
startActivity(new Intent(activity, MainVNCActivity.class));
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||
StrictMode.setThreadPolicy(policy);
|
||||
//if (MainSettingsManager.getVmUi(activity).equals("VNC") && IOApplication.isPortOpen("127.0.0.1", Config.QMPPort, 100) && MainVNCActivity.started)
|
||||
//startActivity(new Intent(activity, MainVNCActivity.class));
|
||||
}
|
||||
|
||||
public static boolean isServiceRunning(Class<?> serviceClass, Context context) {
|
||||
|
|
@ -1509,13 +1513,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
});
|
||||
alertDialog.show();
|
||||
} else if (item.getItemId() == R.id.backtothedisplay) {
|
||||
if (VectrasApp.isQemuRunning()) {
|
||||
if (MainSettingsManager.getVmUi(activity).equals("VNC"))
|
||||
activity.startActivity(new Intent(activity, MainVNCActivity.class));
|
||||
else if (MainSettingsManager.getVmUi(activity).equals("X11"))
|
||||
activity.startActivity(new Intent(activity, X11Activity.class));
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), activity.getResources().getString(R.string.there_is_nothing_here_because_there_is_no_vm_running), Toast.LENGTH_LONG).show();
|
||||
|
||||
if (MainSettingsManager.getVmUi(activity).equals("VNC")) {
|
||||
activity.startActivity(new Intent(activity, MainVNCActivity.class));
|
||||
} else if (MainSettingsManager.getVmUi(activity).equals("X11")) {
|
||||
activity.startActivity(new Intent(activity, X11Activity.class));
|
||||
}
|
||||
} else if (item.getItemId() == R.id.importrom) {
|
||||
Intent intent = new Intent();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import static com.vectras.vm.VectrasApp.isFileExists;
|
||||
import static com.vectras.vm.VectrasApp.readFile;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
|
|
@ -199,14 +200,22 @@ public class VMManager {
|
|||
} else if (randomAbc == 11) {
|
||||
addAdb = "l";
|
||||
}
|
||||
return addAdb + String.valueOf((long)(random.nextInt(10001)));
|
||||
return addAdb + String.valueOf((long)(random.nextInt(65535)));
|
||||
}
|
||||
|
||||
public static int startRandomPort() {
|
||||
int _result;
|
||||
Random _random = new Random();
|
||||
int _min = 10000;
|
||||
int _max = 65535;
|
||||
return _random.nextInt(_max - _min + 1) + _min;
|
||||
_result = _random.nextInt(_max - _min + 1) + _min;
|
||||
if (readFile(AppConfig.romsdatajson).contains("\"qmpPort\":" + _result)) {
|
||||
_result = _random.nextInt(_max - _min + 1) + _min;
|
||||
}
|
||||
if (readFile(AppConfig.romsdatajson).contains("\"qmpPort\":" + _result)) {
|
||||
_result = _random.nextInt(_max - _min + 1) + _min;
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
public static void deleteVM() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue