V4.0 Universal Embedded: 32/64 bit support, Embedded WireGuard, Auto-Launch XuperTV
This commit is contained in:
@@ -3,14 +3,15 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />
|
||||
|
||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
|
||||
|
||||
<application
|
||||
android:label="Xuper VPN Auto"
|
||||
android:label="Xuper VPN Universal"
|
||||
android:name="androidx.multidex.MultiDexApplication"
|
||||
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">
|
||||
|
||||
<activity android:name=".MainActivity"
|
||||
@@ -21,5 +22,16 @@
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Servicio VPN Embebido (Parcheado para Android 12+) -->
|
||||
<service android:name="com.wireguard.android.backend.GoBackend$VpnService"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||
tools:node="merge">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.VpnService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -6,19 +6,36 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.view.View;
|
||||
|
||||
// Imports del Motor Embebido
|
||||
import com.wireguard.android.backend.Backend;
|
||||
import com.wireguard.android.backend.GoBackend;
|
||||
import com.wireguard.android.backend.Tunnel;
|
||||
import com.wireguard.config.Config;
|
||||
import com.wireguard.config.Interface;
|
||||
import com.wireguard.config.Peer;
|
||||
import com.wireguard.config.InetEndpoint;
|
||||
import com.wireguard.config.InetNetwork;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
// --- CONFIGURACIÓN ---
|
||||
private static final String TUNNEL_NAME = "CasaTV"; // Nombre exacto en la app oficial
|
||||
private static final String WIREGUARD_PACKAGE = "com.wireguard.android";
|
||||
// --- CONFIGURACIÓN WIREGUARD ---
|
||||
private static final String CLIENT_PRIV_KEY = "ULfX2KspqzSv9cgfvYxGjbL/3FkOS27iCVCyL+LWGmE=";
|
||||
private static final String SERVER_PUB_KEY = "44dNaTOCc/nY6vkqy3fJ+L1RqWDqFqEaEq1IBL/InRM=";
|
||||
private static final String SERVER_ENDPOINT = "194.163.191.200:51820";
|
||||
private static final String CLIENT_IP = "10.66.66.2/32";
|
||||
|
||||
// --- CONFIGURACIÓN APP OBJETIVO ---
|
||||
private static final String TARGET_PACKAGE = "com.android.mgstv"; // XuperTV
|
||||
// ---------------------
|
||||
// ----------------------------------
|
||||
|
||||
private Backend backend;
|
||||
private Tunnel tunnel;
|
||||
private Config config;
|
||||
private TextView statusText;
|
||||
private Button connectBtn;
|
||||
private CountDownTimer timer;
|
||||
@@ -30,68 +47,114 @@ public class MainActivity extends Activity {
|
||||
|
||||
statusText = findViewById(R.id.statusText);
|
||||
connectBtn = findViewById(R.id.connectBtn);
|
||||
|
||||
// Inicializar texto
|
||||
connectBtn.setText("ACTIVAR Y ABRIR TV");
|
||||
|
||||
// Verificar si WireGuard está instalado
|
||||
if (!isPackageInstalled(WIREGUARD_PACKAGE)) {
|
||||
statusText.setText("ERROR: Instala la app oficial 'WireGuard' primero.");
|
||||
// 1. Inicializar Motor VPN
|
||||
try {
|
||||
backend = new GoBackend(getApplicationContext());
|
||||
tunnel = new SimpleTunnel("XuperVPN");
|
||||
config = createConfig();
|
||||
} catch (Exception e) {
|
||||
statusText.setText("Error Motor VPN: " + e.getMessage());
|
||||
connectBtn.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Verificar XuperTV
|
||||
if (!isPackageInstalled(TARGET_PACKAGE)) {
|
||||
Toast.makeText(this, "Aviso: XuperTV no detectada", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
connectBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startSequence();
|
||||
startVpnSequence();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startSequence() {
|
||||
connectBtn.setEnabled(false);
|
||||
statusText.setText("Enviando orden a WireGuard...");
|
||||
private Config createConfig() throws Exception {
|
||||
Interface.Builder interfaceBuilder = new Interface.Builder();
|
||||
interfaceBuilder.parsePrivateKey(CLIENT_PRIV_KEY);
|
||||
interfaceBuilder.parseAddresses(CLIENT_IP);
|
||||
interfaceBuilder.parseDnsServers("8.8.8.8");
|
||||
|
||||
// 1. Activar Túnel
|
||||
setTunnelState(true);
|
||||
Peer.Builder peerBuilder = new Peer.Builder();
|
||||
peerBuilder.parsePublicKey(SERVER_PUB_KEY);
|
||||
peerBuilder.parseEndpoint(SERVER_ENDPOINT);
|
||||
peerBuilder.parseAllowedIPs("0.0.0.0/0");
|
||||
|
||||
// 2. Esperar 2 segundos y lanzar TV
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launchTargetApp();
|
||||
startTimer();
|
||||
}
|
||||
}, 2000);
|
||||
return new Config.Builder()
|
||||
.setInterface(interfaceBuilder.build())
|
||||
.addPeer(peerBuilder.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void startTimer() {
|
||||
statusText.setText("VPN ACTIVA\nCerrando en 60s...");
|
||||
|
||||
timer = new CountDownTimer(60000, 1000) {
|
||||
public void onTick(long millisUntilFinished) {
|
||||
statusText.setText("VPN ACTIVA: " + millisUntilFinished / 1000 + "s");
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
setTunnelState(false);
|
||||
statusText.setText("DESCONECTADO.\nListo.");
|
||||
connectBtn.setEnabled(true);
|
||||
connectBtn.setText("REINICIAR");
|
||||
}
|
||||
}.start();
|
||||
private void startVpnSequence() {
|
||||
// Pedir permiso de VPN al sistema (Android dialog)
|
||||
Intent intent = GoBackend.VpnService.prepare(this);
|
||||
if (intent != null) {
|
||||
startActivityForResult(intent, 0);
|
||||
} else {
|
||||
onActivityResult(0, RESULT_OK, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTunnelState(boolean up) {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
connectTunnel();
|
||||
} else {
|
||||
statusText.setText("Permiso de VPN denegado");
|
||||
}
|
||||
}
|
||||
|
||||
private void connectTunnel() {
|
||||
try {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("com.wireguard.android.action.SET_TUNNEL_" + (up ? "UP" : "DOWN"));
|
||||
intent.setPackage(WIREGUARD_PACKAGE);
|
||||
intent.putExtra("tunnel", TUNNEL_NAME);
|
||||
sendBroadcast(intent);
|
||||
// Asegurar limpieza
|
||||
try { backend.setState(tunnel, Tunnel.State.DOWN, null); } catch (Exception e) {}
|
||||
|
||||
// CONECTAR
|
||||
backend.setState(tunnel, Tunnel.State.UP, config);
|
||||
|
||||
statusText.setText("CONECTADO.\nLanzando TV en 2s...");
|
||||
connectBtn.setEnabled(false);
|
||||
|
||||
// Auto-Launch XuperTV
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launchTargetApp();
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
// Temporizador 60s
|
||||
timer = new CountDownTimer(60000, 1000) {
|
||||
public void onTick(long millisUntilFinished) {
|
||||
statusText.setText("VPN ACTIVA: " + millisUntilFinished / 1000 + "s");
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
disconnectTunnel();
|
||||
}
|
||||
}.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "Error enviando comando: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
statusText.setText("Error Conexión: " + e.getMessage());
|
||||
connectBtn.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void disconnectTunnel() {
|
||||
try {
|
||||
if (backend != null) {
|
||||
backend.setState(tunnel, Tunnel.State.DOWN, null);
|
||||
}
|
||||
statusText.setText("DESCONECTADO.\nListo.");
|
||||
connectBtn.setEnabled(true);
|
||||
connectBtn.setText("REINICIAR");
|
||||
} catch (Exception e) {
|
||||
// Ignorar
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,11 +173,16 @@ public class MainActivity extends Activity {
|
||||
if (launchIntent != null) {
|
||||
startActivity(launchIntent);
|
||||
Toast.makeText(this, "Abriendo XuperTV...", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "XuperTV no instalada (" + TARGET_PACKAGE + ")", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Ignorar
|
||||
}
|
||||
}
|
||||
|
||||
private static class SimpleTunnel implements Tunnel {
|
||||
private final String name;
|
||||
SimpleTunnel(String name) { this.name = name; }
|
||||
@Override public String getName() { return name; }
|
||||
@Override public void onStateChange(State newState) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:padding="32dp"
|
||||
android:background="#121212">
|
||||
android:background="#222222">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/statusText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Listo para conectar"
|
||||
android:text="XUPER VPN UNIVERSAL"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
@@ -19,9 +19,10 @@
|
||||
|
||||
<Button
|
||||
android:id="@+id/connectBtn"
|
||||
android:layout_width="200dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ACTIVAR (60s)"
|
||||
android:padding="16dp"/>
|
||||
android:text="INICIAR"
|
||||
android:padding="20dp"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user