diff options
author | cyberta <cyberta@riseup.net> | 2023-11-01 03:52:50 +0000 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2023-11-01 03:52:50 +0000 |
commit | 85eb52e62b55d4fbe9434b250f3a6cecc70d77ec (patch) | |
tree | e320ddae310ea2fea65f563205e9d75e3839858d /app/src/main/java | |
parent | d173064257b150b3ac344c2e0fd1f892e85edbbc (diff) | |
parent | cdd18e62f6a6fa0821445068049cb0b1de9e00f9 (diff) |
Merge branch 'last_tweaks_before_release' into 'master'
Last tweaks before release
See merge request leap/bitmask_android!262
Diffstat (limited to 'app/src/main/java')
4 files changed, 45 insertions, 35 deletions
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 575f1f59..b38eeb14 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -277,6 +277,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // Always show notification here to avoid problem with startForeground timeout notificationManager.createOpenVpnNotificationChannel(); notificationManager.buildForegroundServiceNotification(EipStatus.getInstance().getLevel(), this::onNotificationBuild); + notificationManager.cancelVoidVpnServiceNotifications(); } @Override @@ -329,7 +330,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac updateShortCutUsage(mProfile); } VpnStatus.setAlwaysOn(false); - + notificationManager.cancelVoidVpnServiceNotifications(); } else { /* The intent is null when we are set as always-on or the service has been restarted. */ Log.d(TAG, "Starting VPN due to isAlwaysOn system settings or app crash."); 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 c500b55b..f4e09e62 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 @@ -171,11 +171,16 @@ public class EipFragment extends Fragment implements Observer { } restoreFromSavedInstance(savedInstanceState); - locationButton.setOnClickListener(v -> { + if (provider != null && provider.hasGatewaysInDifferentLocations()) { + locationButton.setOnClickListener(v -> { FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); Fragment fragment = new GatewaySelectionFragment(); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); - }); + }); + locationButton.setEnabled(true); + } else { + locationButton.setEnabled(false); + } mainButton.setOnClickListener(v -> { handleIcon(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 53781f52..b32671ae 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -26,6 +26,8 @@ import android.content.Intent; import android.net.VpnService; import android.os.Binder; import android.os.Build; +import android.os.Handler; +import android.os.HandlerThread; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.system.OsConstants; @@ -44,15 +46,17 @@ import se.leap.bitmaskclient.base.utils.PreferenceHelper; public class VoidVpnService extends VpnService implements Observer, VpnNotificationManager.VpnServiceCallback { static final String TAG = VoidVpnService.class.getSimpleName(); - static ParcelFileDescriptor fd; - static Thread thread; + private ParcelFileDescriptor fd; private final int ALWAYS_ON_MIN_API_LEVEL = Build.VERSION_CODES.N; private static final String STATE_ESTABLISH = "ESTABLISHVOIDVPN"; public static final String NOTIFICATION_CHANNEL_NEWSTATUS_ID = "bitmask_void_vpn_news"; private EipStatus eipStatus; private VpnNotificationManager notificationManager; + private HandlerThread handlerThread; + private Handler handler; private final IBinder binder = new VoidVpnServiceBinder(); + public class VoidVpnServiceBinder extends Binder { VoidVpnService getService() { // Return this instance of LocalService so clients can call public methods @@ -73,33 +77,31 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat eipStatus = EipStatus.getInstance(); eipStatus.addObserver(this); notificationManager = new VpnNotificationManager(this); + handlerThread = new HandlerThread("VoidVpnServiceHandlerThread", Thread.NORM_PRIORITY); + handlerThread.start(); + handler = new Handler(handlerThread.getLooper()); } @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = intent != null ? intent.getAction() : ""; - if (action.equals(EIP_ACTION_START_BLOCKING_VPN)) { - thread = new Thread(new Runnable() { - public void run() { - establishBlockingVpn(); - PreferenceHelper.isAlwaysOnSync(false); - Log.d(TAG, "start blocking vpn profile - always on = false"); - } + handler.removeCallbacksAndMessages(null); + if (EIP_ACTION_START_BLOCKING_VPN.equals(action)) { + handler.post(() -> { + establishBlockingVpn(); + PreferenceHelper.isAlwaysOnSync(false); + Log.d(TAG, "start blocking vpn profile - always on = false"); }); - thread.run(); - } else if (intent == null || action.equals("android.net.VpnService") && Build.VERSION.SDK_INT >= ALWAYS_ON_MIN_API_LEVEL) { + } else if (intent == null || "android.net.VpnService".equals(action) && Build.VERSION.SDK_INT >= ALWAYS_ON_MIN_API_LEVEL) { //only always-on feature triggers this startWithForegroundNotification(); - thread = new Thread(new Runnable() { - public void run() { - establishBlockingVpn(); - PreferenceHelper.isAlwaysOnSync(true); - requestVpnWithLastSelectedProfile(); - Log.d(TAG, "start blocking vpn profile - always on = true"); - } + handler.post(() -> { + establishBlockingVpn(); + PreferenceHelper.isAlwaysOnSync(true); + requestVpnWithLastSelectedProfile(); + Log.d(TAG, "start blocking vpn profile - always on = true"); }); - thread.run(); - } else if (action.equals(EIP_ACTION_STOP_BLOCKING_VPN)) { + } else if (EIP_ACTION_STOP_BLOCKING_VPN.equals(action)) { stop(); } return START_STICKY; @@ -108,32 +110,31 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat @Override public void onRevoke() { super.onRevoke(); - closeFd(); + stop(); } @Override public void onDestroy() { + Log.d(TAG, "onDestroy"); super.onDestroy(); notificationManager.cancelAll(); + eipStatus.deleteObserver(this); } private void stop() { - if (thread != null) { - thread.interrupt(); - } + handlerThread.interrupt(); closeFd(); VpnStatus.updateStateString("NOPROCESS", "BLOCKING VPN STOPPED", R.string.state_noprocess, ConnectionStatus.LEVEL_NOTCONNECTED); stopForeground(true); + stopSelf(); } - public static boolean isRunning() throws NullPointerException { - return thread.isAlive() && fd != null; - } - - private static void closeFd() { + private void closeFd() { try { - if (fd != null) + if (fd != null) { fd.close(); + fd = null; + } } catch (IOException e) { e.printStackTrace(); } @@ -187,8 +188,7 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat if (observable instanceof EipStatus) { eipStatus = (EipStatus) observable; } - - if (thread == null) { + if (handlerThread.isInterrupted() || !handlerThread.isAlive()) { return; } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java index b4d11f26..f32dc240 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java @@ -200,6 +200,10 @@ public class VpnNotificationManager { compatNotificationManager.cancel(VoidVpnService.NOTIFICATION_CHANNEL_NEWSTATUS_ID.hashCode()); } + public void cancelVoidVpnServiceNotifications() { + compatNotificationManager.cancel(VoidVpnService.NOTIFICATION_CHANNEL_NEWSTATUS_ID.hashCode()); + } + @TargetApi(O) public void createVoidVpnNotificationChannel() { |