mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-04-28 22:39:50 +00:00
- Fixed VNC Server could fail to connect from another device. - Added no more update prompts for an updated version. - Fixed missing package check could give wrong results for 32bit only devices. - Fixed VM not being created when ignoring warnings. - Termux:X11 startup command now only runs for Android 13 and below. - Added check if cache folder was created successfully when running VM. - Added VNC Server running notification dialog after successful VM launch. - New Home interface. - Rom store has been integrated in Home. - New System monitor. - Updated update notification dialog interface. - New update checker. - Reduced time on startup screen. - Fixed issue with virtual machine list data fixer.
150 lines
No EOL
6.8 KiB
Java
150 lines
No EOL
6.8 KiB
Java
package com.vectras.vm;
|
|
|
|
import android.Manifest;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.provider.Settings;
|
|
import android.util.Log;
|
|
import android.widget.Button;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.vectras.vm.home.HomeActivity;
|
|
import com.vectras.vm.utils.FileUtils;
|
|
import com.vectras.vm.utils.JSONUtils;
|
|
import com.vectras.vm.utils.PermissionUtils;
|
|
import com.vectras.vm.utils.UIUtils;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Objects;
|
|
|
|
public class CqcmActivity extends AppCompatActivity {
|
|
|
|
private Intent gotoActivity = new Intent();
|
|
private Intent openURL = new Intent();
|
|
private Button buttonallow;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if(!PermissionUtils.storagepermission(this,false)) {
|
|
UIUtils.edgeToEdge(this);
|
|
setContentView(R.layout.activity_cqcm);
|
|
UIUtils.setOnApplyWindowInsetsListener(findViewById(R.id.main));
|
|
buttonallow = findViewById(R.id.buttonallow);
|
|
buttonallow.setOnClickListener(v -> {
|
|
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
intent.setData(Uri.parse("package:" + getPackageName()));
|
|
startActivity(intent);
|
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.find_and_allow_access_to_storage_in_settings), Toast.LENGTH_LONG).show();
|
|
} else {
|
|
ActivityCompat.requestPermissions(CqcmActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1000);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
Log.i("CqcmActivity", "Checking access to storage...");
|
|
if(PermissionUtils.storagepermission(this,false)) {
|
|
if (getIntent().hasExtra("command")) {
|
|
runCommand(getIntent().getStringExtra("command"));
|
|
} else {
|
|
startAdd();
|
|
}
|
|
}
|
|
|
|
}
|
|
private void startAdd() {
|
|
HashMap<String, Object> mapForCreateNewVM = new HashMap<>();
|
|
String _map;
|
|
String imgName = "";
|
|
String imgIcon = "";
|
|
String imgPath = "";
|
|
String imgArch = "";
|
|
String imgCdrom = "";
|
|
String imgExtra = "";
|
|
String vmID = VMManager.idGenerator();
|
|
|
|
if (!FileUtils.isFileExists(AppConfig.romsdatajson)) {
|
|
FileUtils.writeToFile(AppConfig.maindirpath, "roms-data.json", "[]");
|
|
}
|
|
|
|
if (JSONUtils.isValidFromFile(AppConfig.romsdatajson)) {
|
|
if (getIntent().hasExtra("content")) {
|
|
if (Objects.requireNonNull(getIntent().getStringExtra("content")).endsWith("}]")) {
|
|
_map = Objects.requireNonNull(getIntent().getStringExtra("content")).substring((int) 0, (int)(Objects.requireNonNull(getIntent().getStringExtra("content")).length() - 1));
|
|
} else {
|
|
_map = Objects.requireNonNull(getIntent().getStringExtra("content"));
|
|
}
|
|
if (JSONUtils.isValidFromString(_map)) {
|
|
mapForCreateNewVM = new Gson().fromJson(_map, new TypeToken<HashMap<String, Object>>(){}.getType());
|
|
if (mapForCreateNewVM.containsKey("imgName")) {
|
|
imgName = Objects.requireNonNull(mapForCreateNewVM.get("imgName")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgIcon")) {
|
|
imgIcon = Objects.requireNonNull(mapForCreateNewVM.get("imgIcon")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgPath")) {
|
|
imgPath = Objects.requireNonNull(mapForCreateNewVM.get("imgPath")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgArch")) {
|
|
imgArch = Objects.requireNonNull(mapForCreateNewVM.get("imgArch")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgCdrom")) {
|
|
imgCdrom = Objects.requireNonNull(mapForCreateNewVM.get("imgCdrom")).toString();
|
|
}
|
|
if (mapForCreateNewVM.containsKey("imgExtra")) {
|
|
imgExtra = Objects.requireNonNull(mapForCreateNewVM.get("imgExtra")).toString();
|
|
}
|
|
VMManager.createNewVM(imgName, imgIcon, imgPath, imgArch, imgCdrom, imgExtra, vmID, VMManager.startRandomPort());
|
|
} else {
|
|
Toast.makeText(getApplicationContext(), "The data for the new virtual machine is corrupted and cannot be created.", Toast.LENGTH_LONG).show();
|
|
}
|
|
} else {
|
|
Toast.makeText(getApplicationContext(), "There is no data about the new virtual machine to create.", Toast.LENGTH_LONG).show();
|
|
}
|
|
} else {
|
|
Toast.makeText(getApplicationContext(), "The virtual machine list data is corrupted and new virtual machines cannot be added right now.", Toast.LENGTH_LONG).show();
|
|
}
|
|
if(!HomeActivity.isActivate) {
|
|
Log.i("CqcmActivity", "Vectras VM is not opening.");
|
|
gotoActivity.setClass(getApplicationContext(), SplashActivity.class);
|
|
startActivity(gotoActivity);
|
|
Log.i("CqcmActivity", "Opened SplashActivity");
|
|
} else {
|
|
Log.i("CqcmActivity", "Vectras VM is opening.");
|
|
openURL.setAction(Intent.ACTION_VIEW);
|
|
openURL.setData(Uri.parse("android-app://com.vectras.vm"));
|
|
startActivity(openURL);
|
|
Log.i("CqcmActivity", "Opened Vectras VM using URL.");
|
|
}
|
|
finish();
|
|
}
|
|
|
|
private void runCommand(String _command) {
|
|
AppConfig.pendingCommand = _command;
|
|
|
|
if(!HomeActivity.isActivate) {
|
|
Log.i("CqcmActivity", "Vectras VM is not opening.");
|
|
gotoActivity.setClass(getApplicationContext(), SplashActivity.class);
|
|
startActivity(gotoActivity);
|
|
Log.i("CqcmActivity", "Opened SplashActivity");
|
|
} else {
|
|
Log.i("CqcmActivity", "Vectras VM is opening.");
|
|
openURL.setAction(Intent.ACTION_VIEW);
|
|
openURL.setData(Uri.parse("android-app://com.vectras.vm"));
|
|
startActivity(openURL);
|
|
Log.i("CqcmActivity", "Opened Vectras VM using URL.");
|
|
}
|
|
finish();
|
|
}
|
|
} |