diff --git a/controller/app/src/main/java/org/iiab/controller/MainActivity.java b/controller/app/src/main/java/org/iiab/controller/MainActivity.java index d917e7e2..bb3211f2 100644 --- a/controller/app/src/main/java/org/iiab/controller/MainActivity.java +++ b/controller/app/src/main/java/org/iiab/controller/MainActivity.java @@ -59,8 +59,6 @@ import java.util.Map; import java.net.HttpURLConnection; import java.net.URL; -import java.net.Proxy; -import java.net.InetSocketAddress; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final String TAG = "IIAB-MainActivity"; @@ -641,21 +639,10 @@ private void initiatePermissionChain() { } } - private boolean pingUrl(String urlStr, boolean useProxy) { + private boolean pingUrl(String urlStr) { try { URL url = new URL(urlStr); - HttpURLConnection conn; - - if (useProxy) { - // We routed the request directly to the app's SOCKS proxy - int socksPort = prefs.getSocksPort(); // generally 1080 - Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", socksPort)); - conn = (HttpURLConnection) url.openConnection(proxy); - } else { - // Normal request (for localhost) - conn = (HttpURLConnection) url.openConnection(); - } - + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setConnectTimeout(1500); conn.setReadTimeout(1500); @@ -673,50 +660,13 @@ private void runNegotiationSequence() { }); AppExecutors.get().io().execute(() -> { - boolean boxAlive = false; - - // Attempt 1 (0 seconds) - boxAlive = pingUrl("http://box/home", true); - - // Attempt 2 (At 2 seconds) - if (!boxAlive) { - try { - Thread.sleep(2000); - } catch (InterruptedException ignored) { - } - boxAlive = pingUrl("http://box/home", true); - } - - // Attempt 3 (At 3 seconds) - if (!boxAlive) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignored) { - } - boxAlive = pingUrl("http://box/home", true); - } - - // We validate if localhost serves as a fallback. - boolean localAlive = pingUrl("http://localhost:8085/home", false); + // Native architecture: content is served locally at localhost:8085. + boolean localAlive = pingUrl("http://localhost:8085/home"); - // We evaluate the results isNegotiating = false; - updateServerAlive(boxAlive || localAlive); - - // If VPN is ON but box/proxy is dead, the tunnel is degraded (Orange). - if (prefs.getEnable()) { - isProxyDegraded = !boxAlive; - } else { - isProxyDegraded = false; - } - - if (boxAlive) { - currentTargetUrl = "http://box/home"; - } else if (localAlive) { - currentTargetUrl = "http://localhost:8085/home"; - } else { - currentTargetUrl = null; - } + updateServerAlive(localAlive); + isProxyDegraded = false; + currentTargetUrl = localAlive ? "http://localhost:8085/home" : null; runOnUiThread(this::updateUIColorsAndVisibility); }); @@ -1058,19 +1008,10 @@ private void checkServerStatus() { if (isNegotiating) return; AppExecutors.get().io().execute(() -> { - boolean localAlive = pingUrl("http://localhost:8085/home", false); - boolean vpnOn = prefs.getEnable(); - boolean boxAlive = false; - - if (vpnOn) { - // The passive radar must also use the proxy to test the tunnel. - boxAlive = pingUrl("http://box/home", true); - isProxyDegraded = !boxAlive; - } else { - isProxyDegraded = false; - } + boolean localAlive = pingUrl("http://localhost:8085/home"); + isProxyDegraded = false; - updateServerAlive(localAlive || boxAlive); + updateServerAlive(localAlive); // STATE MACHINE: Has the target state been reached? if (targetServerState != null && isServerAlive == targetServerState) { @@ -1079,13 +1020,7 @@ private void checkServerStatus() { if (usageFragment != null) runOnUiThread(() -> usageFragment.stopBtnProgress()); } - if (vpnOn && boxAlive) { - currentTargetUrl = "http://box/home"; - } else if (localAlive) { - currentTargetUrl = "http://localhost:8085/home"; - } else { - currentTargetUrl = null; - } + currentTargetUrl = localAlive ? "http://localhost:8085/home" : null; runOnUiThread(this::updateUIColorsAndVisibility); }); diff --git a/controller/app/src/main/java/org/iiab/controller/PortalActivity.java b/controller/app/src/main/java/org/iiab/controller/PortalActivity.java index 77fc3110..fa549f74 100644 --- a/controller/app/src/main/java/org/iiab/controller/PortalActivity.java +++ b/controller/app/src/main/java/org/iiab/controller/PortalActivity.java @@ -14,10 +14,8 @@ import android.webkit.WebViewClient; import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; -import java.util.concurrent.Executor; import android.graphics.Bitmap; import android.view.View; @@ -27,7 +25,6 @@ import android.os.Handler; import android.os.Looper; -import org.iiab.controller.portal.data.WebViewProxyConfigurator; import org.iiab.controller.portal.domain.NavigationPolicy; import org.iiab.controller.portal.presentation.GestureWebView; import org.iiab.controller.portal.presentation.PortalViewModel; @@ -122,9 +119,6 @@ protected void onCreate(Bundle savedInstanceState) { resetTimer.run(); }); - Preferences prefs = new Preferences(this); - boolean isVpnActive = prefs.getEnable(); - // Resolve the target URL once (domain), surviving rotation via the ViewModel. final String finalTargetUrl = vm.targetUrl(getIntent().getStringExtra("TARGET_URL")); @@ -256,27 +250,8 @@ public boolean onConsoleMessage(android.webkit.ConsoleMessage consoleMessage) { downloadServedApk(uri, contentDisposition, mimetype); }); - // Port and Mirror logic - int tempPort = prefs.getSocksPort(); - if (tempPort <= 0) tempPort = 1080; - final int finalProxyPort = tempPort; - - // Proxy block (ONLY IF VPN IS ACTIVE) - if (isVpnActive) { - if (WebViewProxyConfigurator.isSupported()) { - Executor executor = ContextCompat.getMainExecutor(this); - WebViewProxyConfigurator.applySocks(finalProxyPort, executor, () -> { - Log.d(TAG, "Proxy configured on port: " + finalProxyPort); - webView.loadUrl(finalTargetUrl); // load only when proxy is ready - }); - } else { - Log.w(TAG, "Proxy Override not supported"); - webView.loadUrl(finalTargetUrl); - } - } else { - // VPN is OFF. Load localhost directly. - webView.loadUrl(finalTargetUrl); - } + // Native architecture: content is served locally; load it directly. + webView.loadUrl(finalTargetUrl); } /** @@ -315,14 +290,6 @@ private void downloadServedApk(Uri uri, String contentDisposition, String mimety } } - @Override - protected void onDestroy() { - super.onDestroy(); - if (WebViewProxyConfigurator.isSupported()) { - WebViewProxyConfigurator.clear(() -> Log.d(TAG, "WebView proxy released")); - } - } - @Override public void onBackPressed() { if (webView.canGoBack()) { diff --git a/controller/app/src/main/java/org/iiab/controller/portal/data/WebViewProxyConfigurator.java b/controller/app/src/main/java/org/iiab/controller/portal/data/WebViewProxyConfigurator.java deleted file mode 100644 index 4c876bf8..00000000 --- a/controller/app/src/main/java/org/iiab/controller/portal/data/WebViewProxyConfigurator.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ============================================================================ - * Name : WebViewProxyConfigurator.java - * Author : AppDevForAll - * Copyright : Copyright (c) 2026 AppDevForAll - * Description : Wraps WebView SOCKS proxy override (VPN) behind a small adapter. - * ============================================================================ - */ -package org.iiab.controller.portal.data; - -import androidx.webkit.ProxyConfig; -import androidx.webkit.ProxyController; -import androidx.webkit.WebViewFeature; - -import java.util.concurrent.Executor; - -/** Thin adapter over androidx ProxyController for the portal's SOCKS proxy. */ -public final class WebViewProxyConfigurator { - - private WebViewProxyConfigurator() {} - - public static boolean isSupported() { - return WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE); - } - - /** Route WebView traffic through socks5://127.0.0.1:{port}; runs {@code onReady} when applied. */ - public static void applySocks(int port, Executor executor, Runnable onReady) { - ProxyConfig config = new ProxyConfig.Builder() - .addProxyRule("socks5://127.0.0.1:" + port) - .build(); - ProxyController.getInstance().setProxyOverride(config, executor, onReady); - } - - /** Remove any proxy override (call on teardown). */ - public static void clear(Runnable onCleared) { - ProxyController.getInstance().clearProxyOverride(Runnable::run, onCleared); - } -}