Initial commit: Xuper VPN Launcher source code
This commit is contained in:
25
app/src/main/AndroidManifest.xml
Normal file
25
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<!-- Declarar soporte para TV (Leanback) -->
|
||||
<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"
|
||||
|
||||
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">
|
||||
|
||||
<activity android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
150
app/src/main/java/com/cbcren/vpn/MainActivity.java
Normal file
150
app/src/main/java/com/cbcren/vpn/MainActivity.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package com.cbcren.vpn;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.content.Intent;
|
||||
|
||||
// Imports de WireGuard
|
||||
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;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
private TextView statusText;
|
||||
private Button connectBtn;
|
||||
private Backend backend;
|
||||
private Config config;
|
||||
private Tunnel tunnel;
|
||||
private CountDownTimer timer;
|
||||
|
||||
// --- CONFIGURACIÓN QUEMADA ---
|
||||
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";
|
||||
// -----------------------------
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
statusText = findViewById(R.id.statusText);
|
||||
connectBtn = findViewById(R.id.connectBtn);
|
||||
|
||||
// Inicializar Backend
|
||||
try {
|
||||
backend = new GoBackend(getApplicationContext());
|
||||
tunnel = new SimpleTunnel("XuperTunnel");
|
||||
config = createConfig();
|
||||
} catch (Exception e) {
|
||||
statusText.setText("Error Init: " + e.getMessage());
|
||||
}
|
||||
|
||||
connectBtn.setOnClickListener(v -> startVpnSequence());
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
Peer.Builder peerBuilder = new Peer.Builder();
|
||||
peerBuilder.parsePublicKey(SERVER_PUB_KEY);
|
||||
peerBuilder.parseEndpoint(SERVER_ENDPOINT);
|
||||
peerBuilder.parseAllowedIPs("0.0.0.0/0"); // Todo por el tunel
|
||||
|
||||
return new Config.Builder()
|
||||
.setInterface(interfaceBuilder.build())
|
||||
.addPeer(peerBuilder.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void startVpnSequence() {
|
||||
if (backend == null) return;
|
||||
|
||||
connectBtn.setEnabled(false);
|
||||
statusText.setText("Conectando...");
|
||||
|
||||
// Lanzar Intent de VPN (El sistema pedirá permiso la primera vez)
|
||||
Intent intent = GoBackend.VpnService.prepare(this);
|
||||
if (intent != null) {
|
||||
startActivityForResult(intent, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
connectTunnel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
connectTunnel();
|
||||
} else {
|
||||
statusText.setText("Permiso denegado");
|
||||
connectBtn.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void connectTunnel() {
|
||||
try {
|
||||
// Si ya está corriendo, apagar primero
|
||||
backend.setState(tunnel, Tunnel.State.DOWN, null);
|
||||
|
||||
// Encender
|
||||
backend.setState(tunnel, Tunnel.State.UP, config);
|
||||
|
||||
startTimer();
|
||||
} catch (Exception e) {
|
||||
statusText.setText("Error Conexión: " + e.getMessage());
|
||||
connectBtn.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void startTimer() {
|
||||
timer = new CountDownTimer(60000, 1000) {
|
||||
public void onTick(long millisUntilFinished) {
|
||||
statusText.setText("VPN ACTIVA\n" + (millisUntilFinished / 1000) + " segundos");
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
disconnectTunnel();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void disconnectTunnel() {
|
||||
try {
|
||||
if (backend != null) {
|
||||
backend.setState(tunnel, Tunnel.State.DOWN, null);
|
||||
}
|
||||
statusText.setText("Desconectado.\nAbre XuperTV.");
|
||||
connectBtn.setEnabled(true);
|
||||
connectBtn.setText("RECONECTAR");
|
||||
} catch (Exception e) {
|
||||
// Ignorar
|
||||
}
|
||||
}
|
||||
|
||||
// Clase auxiliar simple para identificar el tunel
|
||||
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) {}
|
||||
}
|
||||
}
|
||||
7
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
7
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:fillColor="#3DDC84" android:pathData="M0,0h108v108h-108z"/>
|
||||
</vector>
|
||||
27
app/src/main/res/layout/activity_main.xml
Normal file
27
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:padding="32dp"
|
||||
android:background="#121212">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/statusText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Listo para conectar"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="32dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/connectBtn"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ACTIVAR (60s)"
|
||||
android:padding="16dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@android:color/white"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
Reference in New Issue
Block a user