### Java Connection State Enumeration and Usage Source: https://context7.com/bepass-org/oblivion/llms.txt Defines the ConnectionState enum for VPN connection status (CONNECTING, CONNECTED, DISCONNECTED) with helper methods. Includes an example of how to use these states in Android UI code to manage button visibility and status text. ```java public enum ConnectionState { CONNECTING, // VPN is establishing connection CONNECTED, // VPN is fully connected DISCONNECTED; // VPN is not connected public boolean isDisconnected() { return this == DISCONNECTED; } public boolean isConnecting() { return this == CONNECTING; } } public void handleConnectionState(ConnectionState state) { if (state.isDisconnected()) { // Show connect button, hide disconnect connectButton.setVisibility(View.VISIBLE); statusText.setText("Not Connected"); } else if (state.isConnecting()) { // Show progress indicator progressBar.setVisibility(View.VISIBLE); statusText.setText("Connecting..."); } else { // state == CONNECTED disconnectButton.setVisibility(View.VISIBLE); statusText.setText("Connected"); } } ``` -------------------------------- ### Initialize LWIP Network Stack in Go Source: https://context7.com/bepass-org/oblivion/llms.txt Provides the low-level network stack implementation for TCP/UDP proxying and DNS management. It requires a TUN file descriptor and proxy server address to function. ```go package main import ( "tun2socks/lwip" ) func startLwipStack() { options := &lwip.Tun2socksStartOptions{ TunFd: 42, Socks5Server: "127.0.0.1:8086", FakeIPRange: "24.0.0.0/8", MTU: 0, EnableIPv6: true, AllowLan: true, } result := lwip.Start(options) if result != 0 { panic("Failed to start LWIP stack") } } func stopLwipStack() { lwip.Stop() } ``` -------------------------------- ### Manage VPN Settings with FileManager in Java Source: https://context7.com/bepass-org/oblivion/llms.txt This Java code illustrates how to use the FileManager class for thread-safe, persistent storage of VPN settings using MMKV. It covers initialization, setting various types of preferences (strings, booleans, integers, sets), reading them back, and resetting all settings to their defaults. The FileManager must be initialized once at app startup. ```java public class SettingsExample { public void initializeSettings(Context context) { // Must be called once at app startup (typically in Application class) FileManager.initialize(context); } public void configureVpnSettings() { // Store endpoint configuration FileManager.set("USERSETTING_endpoint", "engage.cloudflareclient.com:2408"); FileManager.set("USERSETTING_port", "8086"); // Configure operating mode FileManager.set("USERSETTING_proxymode", false); // VPN mode vs SOCKS5 proxy FileManager.set("USERSETTING_lan", false); // Allow LAN access // Configure tunneling options FileManager.set("USERSETTING_gool", false); // Warp-in-Warp mode FileManager.set("USERSETTING_psiphon", false); // Psiphon tunneling FileManager.set("USERSETTING_country", "US"); // Country for Psiphon // Endpoint type: 0=Auto, 1=IPv4 only, 2=IPv6 only FileManager.set("USERSETTING_endpoint_type", 0); // Optional Warp license key FileManager.set("USERSETTING_license", "your-license-key"); } public void readSettings() { // Retrieve stored settings String endpoint = FileManager.getString("USERSETTING_endpoint"); String port = FileManager.getString("USERSETTING_port", "8086"); // with default boolean psiphonEnabled = FileManager.getBoolean("USERSETTING_psiphon"); int endpointType = FileManager.getInt("USERSETTING_endpoint_type"); // Get split tunnel apps (returns empty set if not set) Set splitApps = FileManager.getStringSet("splitTunnelApps", new HashSet<>()); } public void resetToDefaults() { // Reset all settings to defaults FileManager.resetToDefault(); } } ``` -------------------------------- ### Manage VPN Service Lifecycle in Android Source: https://context7.com/bepass-org/oblivion/llms.txt This snippet demonstrates how to initiate and terminate the OblivionVpnService. It includes checking for VPN permissions, configuring connection parameters via intent extras, and triggering the foreground service. ```java public class VpnController { public void startVpn(Context context) { // Check if VPN permission is already granted Intent vpnIntent = OblivionVpnService.prepare(context); if (vpnIntent != null) { // Permission not granted - launch permission dialog ((Activity) context).startActivityForResult(vpnIntent, VPN_REQUEST_CODE); } else { // Permission granted - start VPN service directly Intent serviceIntent = new Intent(context, OblivionVpnService.class); // Configure VPN settings via intent extras serviceIntent.putExtra("USERSETTING_proxymode", false); serviceIntent.putExtra("USERSETTING_license", ""); serviceIntent.putExtra("USERSETTING_endpoint_type", 0); // 0=Auto, 1=IPv4, 2=IPv6 serviceIntent.putExtra("USERSETTING_psiphon", false); serviceIntent.putExtra("USERSETTING_country", ""); serviceIntent.putExtra("USERSETTING_gool", false); // Warp-in-Warp mode serviceIntent.putExtra("USERSETTING_endpoint", "engage.cloudflareclient.com:2408"); serviceIntent.putExtra("USERSETTING_port", "8086"); serviceIntent.putExtra("USERSETTING_lan", false); // Set action and start foreground service serviceIntent.setAction(OblivionVpnService.FLAG_VPN_START); ContextCompat.startForegroundService(context, serviceIntent); } } public void stopVpn(Context context) { // Stop VPN service OblivionVpnService.stopVpnService(context); } } ``` -------------------------------- ### Initialize and Bind Gomobile for Android Source: https://github.com/bepass-org/oblivion/blob/main/tun2socks/README.md Initializes the gomobile environment and binds the Go package into an Android Archive (AAR) file. This process requires Go 1.22 due to specific psiphon library dependencies and targets Android API level 21. ```sh go run golang.org/x/mobile/cmd/gomobile init go run golang.org/x/mobile/cmd/gomobile bind -ldflags="-w -s" -target=android -androidapi=21 -o=tun2socks.aar . ``` -------------------------------- ### Implement Quick Settings Tile Service Source: https://context7.com/bepass-org/oblivion/llms.txt Provides a implementation of a TileService for Android to control VPN connectivity directly from the notification shade. It manages service binding, lifecycle events, and toggles the VPN state based on user interaction. ```java @RequiresApi(api = Build.VERSION_CODES.N) public class QuickStartService extends TileService { private static final String OBSERVER_KEY = "quickstartToggleButton"; private Messenger serviceMessenger; private boolean isBound; @Override public void onStartListening() { bindService(new Intent(this, OblivionVpnService.class), connection, Context.BIND_AUTO_CREATE); } @Override public void onStopListening() { if (isBound) { OblivionVpnService.unregisterConnectionStateObserver( OBSERVER_KEY, serviceMessenger); unbindService(connection); isBound = false; } } @Override public void onClick() { Tile tile = getQsTile(); if (tile == null) return; if (tile.getState() == Tile.STATE_ACTIVE) { OblivionVpnService.stopVpnService(this); } else { if (OblivionVpnService.prepare(this) != null) { Toast.makeText(this, "Please connect via app first", Toast.LENGTH_LONG).show(); return; } Intent vpnIntent = new Intent(this, OblivionVpnService.class); MainActivity.startVpnService(this, vpnIntent); } } } ``` -------------------------------- ### Fetch Public IP Details with PublicIPUtils Source: https://context7.com/bepass-org/oblivion/llms.txt Demonstrates how to retrieve the user's public IP address, country code, and flag emoji using the PublicIPUtils utility class. This implementation uses an asynchronous callback pattern to handle network requests and update the UI accordingly. ```java public class IpCheckExample { public void checkPublicIp() { PublicIPUtils ipUtils = PublicIPUtils.getInstance(); ipUtils.getIPDetails(details -> { if (details.ip != null) { String ip = details.ip; String country = details.country; String flag = details.flag; String displayText = ip + " " + flag; updateLocationDisplay(displayText); } else { showError("Could not determine public IP"); } }); } } public class IPDetails { public String ip; public String country; public String flag; } ``` -------------------------------- ### Observe VPN Connection State Changes in Java Source: https://context7.com/bepass-org/oblivion/llms.txt This Java code demonstrates how to register an observer to receive real-time updates on the VPN connection state (DISCONNECTED, CONNECTING, CONNECTED). It involves binding to the VPN service, registering a listener, and unregistering when the component is stopped. Dependencies include Android Activity and Context. ```java public class MyActivity extends Activity implements ConnectionStateChangeListener { private Messenger serviceMessenger; private boolean isBound = false; private ServiceConnection connection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder service) { serviceMessenger = new Messenger(service); isBound = true; // Register as a connection state observer OblivionVpnService.registerConnectionStateObserver( "myActivityObserver", // Unique key for this observer serviceMessenger, state -> { // Handle state changes switch (state) { case DISCONNECTED: updateUI("Not Connected"); break; case CONNECTING: updateUI("Connecting..."); break; case CONNECTED: updateUI("Connected"); break; } } ); } @Override public void onServiceDisconnected(ComponentName arg0) { serviceMessenger = null; isBound = false; } }; @Override protected void onStart() { super.onStart(); bindService(new Intent(this, OblivionVpnService.class), connection, Context.BIND_AUTO_CREATE); } @Override protected void onStop() { super.onStop(); if (isBound) { OblivionVpnService.unregisterConnectionStateObserver( "myActivityObserver", serviceMessenger); unbindService(connection); isBound = false; } } @Override public void onChange(ConnectionState state) { runOnUiThread(() -> updateUI(state.toString())); } } ``` -------------------------------- ### Configure Split Tunneling in Java Source: https://context7.com/bepass-org/oblivion/llms.txt Allows users to exclude specific applications from the VPN tunnel using a blacklist mode. It manages the persistence of excluded package names and the current tunnel mode via a file manager. ```java public class SplitTunnelConfig { public void enableSplitTunnel(Set excludedApps) { FileManager.set("splitTunnelMode", SplitTunnelMode.BLACKLIST.toString()); Set apps = new HashSet<>(); apps.add("com.example.browser"); apps.add("com.example.streaming"); FileManager.set("splitTunnelApps", apps); } public void disableSplitTunnel() { FileManager.set("splitTunnelMode", SplitTunnelMode.DISABLED.toString()); } public SplitTunnelMode getCurrentMode() { return SplitTunnelMode.getSplitTunnelMode(); } public Set getExcludedApps() { return FileManager.getStringSet("splitTunnelApps", new HashSet<>()); } } public enum SplitTunnelMode { DISABLED, BLACKLIST; public static SplitTunnelMode getSplitTunnelMode() { try { return SplitTunnelMode.valueOf(FileManager.getString("splitTunnelMode", DISABLED.toString())); } catch (Exception e) { return DISABLED; } } } ``` -------------------------------- ### Manage Network Tunneling with tun2socks in Go Source: https://context7.com/bepass-org/oblivion/llms.txt Handles low-level network tunneling by redirecting traffic from a TUN interface through a SOCKS5 proxy. It supports Cloudflare Warp integration, custom DNS, and Psiphon tunneling options. ```go package main import ( "tun2socks" ) func startTunnel() { options := &tun2socks.StartOptions{ TunFd: 42, Path: "/data/data/org.bepass.oblivion/files", BindAddress: "127.0.0.1:8086", Endpoint: "engage.cloudflareclient.com:2408", License: "", DNS: "1.1.1.1", Verbose: true, EndpointType: 0, PsiphonEnabled: false, Country: "US", Gool: false, } tun2socks.Start(options) } func stopTunnel() { tun2socks.Stop() } func getLogs() string { return tun2socks.GetLogMessages() } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.