From b9c6a35fe67ee65ece988f06f3cabda9fcb1d029 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 10 Dec 2021 17:10:14 +0100 Subject: work around potentials NullPointerException --- .../base/fragments/GatewaySelectionFragment.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 4e7bb6ab..f2c3b2d6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -176,10 +176,14 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } PreferenceHelper.setPreferredCity(context, preferredCity); EipCommand.startVPN(context, false); - Intent intent = new Intent(getContext(), MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.setAction(ACTION_SHOW_VPN_FRAGMENT); - startActivity(intent); + try { + Intent intent = new Intent(context, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.setAction(ACTION_SHOW_VPN_FRAGMENT); + context.startActivity(intent); + } catch (NullPointerException npe) { + npe.printStackTrace(); + } }).start(); } -- cgit v1.2.3 From 54a4934dc83b6d5753fb1ff367d1d60600e540bb Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 10 Dec 2021 17:12:17 +0100 Subject: always use application context in EipCommand to start eip service --- .../java/se/leap/bitmaskclient/base/BitmaskTileService.java | 4 ++-- .../main/java/se/leap/bitmaskclient/base/MainActivity.java | 6 +++--- .../main/java/se/leap/bitmaskclient/base/StartActivity.java | 6 +++--- .../se/leap/bitmaskclient/base/fragments/EipFragment.java | 4 ++-- app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java | 4 ++-- .../java/se/leap/bitmaskclient/eip/EipSetupObserver.java | 12 ++++++------ .../main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/BitmaskTileService.java b/app/src/main/java/se/leap/bitmaskclient/base/BitmaskTileService.java index 4a8b1236..65355a67 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/BitmaskTileService.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/BitmaskTileService.java @@ -43,9 +43,9 @@ public class BitmaskTileService extends TileService implements Observer { private void onTileTap() { EipStatus eipStatus = EipStatus.getInstance(); if (eipStatus.isConnecting() || eipStatus.isBlocking() || eipStatus.isConnected() || eipStatus.isReconnecting()) { - EipCommand.stopVPN(getApplicationContext()); + EipCommand.stopVPN(this); } else { - EipCommand.startVPN(getApplicationContext(), false); + EipCommand.startVPN(this, false); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java index 77743eac..aea397fb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java @@ -217,14 +217,14 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, switch (requestCode) { case REQUEST_CODE_SWITCH_PROVIDER: - EipCommand.stopVPN(this.getApplicationContext()); - EipCommand.startVPN(this.getApplicationContext(), false); + EipCommand.stopVPN(this); + EipCommand.startVPN(this, false); break; case REQUEST_CODE_CONFIGURE_LEAP: Log.d(TAG, "REQUEST_CODE_CONFIGURE_LEAP - onActivityResult - MainActivity"); break; case REQUEST_CODE_LOG_IN: - EipCommand.startVPN(this.getApplicationContext(), true); + EipCommand.startVPN(this, true); break; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java index 9d689e5d..1ea574ff 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java @@ -189,11 +189,11 @@ public class StartActivity extends Activity{ } else { Log.d(TAG, "vpn provider is configured"); if (getIntent() != null && getIntent().getBooleanExtra(EIP_RESTART_ON_BOOT, false)) { - EipCommand.startVPN(this.getApplicationContext(), true); + EipCommand.startVPN(this, true); finish(); } else if (PreferenceHelper.getRestartOnUpdate(this.getApplicationContext())) { PreferenceHelper.restartOnUpdate(this.getApplicationContext(), false); - EipCommand.startVPN(this.getApplicationContext(), false); + EipCommand.startVPN(this, false); showMainActivity(); finish(); } else { @@ -224,7 +224,7 @@ public class StartActivity extends Activity{ Provider provider = data.getParcelableExtra(Provider.KEY); storeProviderInPreferences(preferences, provider); ProviderObservable.getInstance().updateProvider(provider); - EipCommand.startVPN(this.getApplicationContext(), false); + EipCommand.startVPN(this, false); showMainActivity(); } else if (resultCode == RESULT_CANCELED) { finish(); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index 14673874..24b31108 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -338,7 +338,7 @@ public class EipFragment extends Fragment implements Observer { bundle.putBoolean(EIP_EARLY_ROUTES, false); ProviderAPICommand.execute(getContext().getApplicationContext(), DOWNLOAD_GEOIP_JSON, bundle, provider); } else { - EipCommand.startVPN(context.getApplicationContext(), false); + EipCommand.startVPN(context, false); } EipStatus.getInstance().updateState("UI_CONNECTING", "", 0, ConnectionStatus.LEVEL_START); } @@ -349,7 +349,7 @@ public class EipFragment extends Fragment implements Observer { Log.e(TAG, "context is null when trying to stop EIP"); return; } - EipCommand.stopVPN(context.getApplicationContext()); + EipCommand.stopVPN(context); } private void askPendingStartCancellation() { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java index 46704419..b5229b0a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java @@ -28,7 +28,7 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PROFILE; public class EipCommand { private static void execute(@NonNull Context context, @NonNull String action) { - execute(context.getApplicationContext(), action, null, null); + execute(context, action, null, null); } /** @@ -46,7 +46,7 @@ public class EipCommand { vpnIntent.setAction(action); if (resultReceiver != null) vpnIntent.putExtra(EIP_RECEIVER, resultReceiver); - EIP.enqueueWork(context, vpnIntent); + EIP.enqueueWork(context.getApplicationContext(), vpnIntent); } public static void startVPN(@NonNull Context context, boolean earlyRoutes) { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java index 4e5016f0..beed35d1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java @@ -193,14 +193,14 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta ProviderObservable.getInstance().updateProvider(provider); PreferenceHelper.storeProviderInPreferences(preferences, provider); if (EipStatus.getInstance().isDisconnected()) { - EipCommand.startVPN(context.getApplicationContext(), false); + EipCommand.startVPN(context, false); } break; case CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE: provider = resultData.getParcelable(PROVIDER_KEY); ProviderObservable.getInstance().updateProvider(provider); PreferenceHelper.storeProviderInPreferences(preferences, provider); - EipCommand.startVPN(context.getApplicationContext(), false); + EipCommand.startVPN(context, false); break; case CORRECTLY_DOWNLOADED_GEOIP_JSON: provider = resultData.getParcelable(PROVIDER_KEY); @@ -235,7 +235,7 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta private void maybeStartEipService(Bundle resultData) { if (resultData.getBoolean(EIP_ACTION_START)) { boolean earlyRoutes = resultData.getBoolean(EIP_EARLY_ROUTES); - EipCommand.startVPN(context.getApplicationContext(), earlyRoutes); + EipCommand.startVPN(context, earlyRoutes); } } @@ -262,7 +262,7 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta switch (error) { case NO_MORE_GATEWAYS: finishGatewaySetup(false); - EipCommand.startBlockingVPN(context.getApplicationContext()); + EipCommand.startBlockingVPN(context); break; case ERROR_INVALID_PROFILE: selectNextGateway(); @@ -364,7 +364,7 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta private void selectNextGateway() { changingGateway.set(true); reconnectTry.set(0); - EipCommand.startVPN(context.getApplicationContext(), false, setupNClosestGateway.get() + 1); + EipCommand.startVPN(context, false, setupNClosestGateway.get() + 1); } private void finishGatewaySetup(boolean changingGateway) { @@ -396,7 +396,7 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta case SHAPESHIFTER: VpnProfile profile = VpnStatus.getLastConnectedVpnProfile(); if (profile == null) { - EipCommand.startVPN(context.getApplicationContext(), false, 0); + EipCommand.startVPN(context, false, 0); } else { GatewaysManager gatewaysManager = new GatewaysManager(context.getApplicationContext()); int position = gatewaysManager.getPosition(profile); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index e2cd86b9..a8494e2b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -30,14 +30,14 @@ public class VoidVpnLauncher extends Activity { startActivityForResult(blockingIntent, VPN_USER_PERMISSION); } else { - EipCommand.startBlockingVPN(getApplicationContext()); + EipCommand.startBlockingVPN(this); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == VPN_USER_PERMISSION) { if (resultCode == RESULT_OK) { - EipCommand.launchVoidVPN(getApplicationContext()); + EipCommand.launchVoidVPN(this); } } finish(); -- cgit v1.2.3 From c6ae44acadb8c124633c09c0e74f93b72595ec12 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 10 Dec 2021 17:31:17 +0100 Subject: catch potential IllegalArgumentException when enqueuing intents for EIP and ProviderAPI Service --- app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 2 +- app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 4db8f0c2..cf4dc9bf 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -136,7 +136,7 @@ public final class EIP extends JobIntentService implements Observer { static void enqueueWork(Context context, Intent work) { try { enqueueWork(context, EIP.class, JOB_ID, work); - } catch (IllegalStateException e) { + } catch (IllegalStateException | IllegalArgumentException e) { e.printStackTrace(); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java index 709ca651..022ad040 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java @@ -117,7 +117,7 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB static void enqueueWork(Context context, Intent work) { try { ProviderAPI.enqueueWork(context, ProviderAPI.class, JOB_ID, work); - } catch (IllegalStateException e) { + } catch (IllegalStateException | IllegalArgumentException e) { e.printStackTrace(); } } -- cgit v1.2.3 From 4a549283b18d48138e2fa51d5be09e0688d65987 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 10 Dec 2021 17:32:27 +0100 Subject: use guaranteed non-null Context object to start provider API --- app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index 24b31108..07057d6e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -336,7 +336,7 @@ public class EipFragment extends Fragment implements Observer { Bundle bundle = new Bundle(); bundle.putBoolean(EIP_ACTION_START, true); bundle.putBoolean(EIP_EARLY_ROUTES, false); - ProviderAPICommand.execute(getContext().getApplicationContext(), DOWNLOAD_GEOIP_JSON, bundle, provider); + ProviderAPICommand.execute(context, DOWNLOAD_GEOIP_JSON, bundle, provider); } else { EipCommand.startVPN(context, false); } -- cgit v1.2.3 From 5ce549b5fa834283a82fd1e510f568aa0a8209ae Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 11 Dec 2021 01:18:25 +0100 Subject: revert disallowing android:extractNativeLibs, enableUncompressedNativeLibs = false seems to made the trick to ensure navive libs are extracted to the apk --- app/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2e9d2ade..75b166d9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,7 +35,7 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:extractNativeLibs="false" + android:extractNativeLibs="true" android:appCategory="productivity" android:logo="@mipmap/ic_launcher" android:theme="@style/BitmaskTheme"> -- cgit v1.2.3 From 6949fc419d56ff6f657c78da61ea1eeed2169bd0 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 11 Dec 2021 01:47:09 +0100 Subject: make trafficdata linked list in DevicecStateReceiver final and fix typo --- .../main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java b/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java index 13417a5a..2b0c785e 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java +++ b/app/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java @@ -45,7 +45,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL connectState userpause = connectState.SHOULDBECONNECTED; private String lastStateMsg = null; - private java.lang.Runnable mDelayDisconnectRunnable = new Runnable() { + private final java.lang.Runnable mDelayDisconnectRunnable = new Runnable() { @Override public void run() { if (!(network == connectState.PENDINGDISCONNECT)) @@ -83,7 +83,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL long data; } - private LinkedList trafficdata = new LinkedList<>(); + private final LinkedList trafficdata; @Override @@ -128,9 +128,10 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL } } - public DeviceStateReceiver(OpenVPNManagement magnagement) { + public DeviceStateReceiver(OpenVPNManagement management) { super(); - mManagement = magnagement; + trafficdata = new LinkedList<>(); + mManagement = management; mManagement.setPauseCallback(this); mDisconnectHandler = new Handler(); } -- cgit v1.2.3 From 1a20d1e035265fce6cd7a54e03e5a43885f50d50 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 11 Dec 2021 16:33:58 +0100 Subject: catch potential security exception when checking network capabilities --- .../java/de/blinkt/openvpn/core/NetworkUtils.java | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'app') diff --git a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java index a4f09806..5b11c0a0 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java +++ b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java @@ -27,28 +27,32 @@ public class NetworkUtils { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Network[] networks = conn.getAllNetworks(); for (Network network : networks) { - NetworkInfo ni = conn.getNetworkInfo(network); - LinkProperties li = conn.getLinkProperties(network); + try { + NetworkInfo ni = conn.getNetworkInfo(network); + LinkProperties li = conn.getLinkProperties(network); - NetworkCapabilities nc = conn.getNetworkCapabilities(network); + NetworkCapabilities nc = conn.getNetworkCapabilities(network); - if (nc == null) { - continue; - } + if (nc == null) { + continue; + } - // Skip VPN networks like ourselves - if (nc.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) - continue; + // Skip VPN networks like ourselves + if (nc.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) + continue; - // Also skip mobile networks - if (nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) - continue; + // Also skip mobile networks + if (nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) + continue; - for (LinkAddress la : li.getLinkAddresses()) { - if ((la.getAddress() instanceof Inet4Address && !ipv6) || - (la.getAddress() instanceof Inet6Address && ipv6)) - nets.add(la.toString()); + for (LinkAddress la : li.getLinkAddresses()) { + if ((la.getAddress() instanceof Inet4Address && !ipv6) || + (la.getAddress() instanceof Inet6Address && ipv6)) + nets.add(la.toString()); + } + } catch (SecurityException se) { + se.printStackTrace(); } } } else { -- cgit v1.2.3 From e7c09efba8a06bc7a000d525aff5ac027339023e Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 11 Dec 2021 17:07:39 +0100 Subject: fix class cast exception --- app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index ae38a59b..d624af80 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -410,7 +410,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // An old running VPN should now be exited mStarting = false; - if (mProfile.mUsePluggableTransports) { + if (mProfile.mUsePluggableTransports && connection instanceof Obfs4Connection) { Obfs4Connection obfs4Connection = (Obfs4Connection) connection; if (shapeshifter == null) { shapeshifter = new Shapeshifter(obfs4Connection.getDispatcherOptions()); -- cgit v1.2.3