diff options
author | Arne Schwabe <arne@rfc2549.org> | 2023-07-11 16:59:30 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2023-07-13 16:11:23 +0200 |
commit | 40eb1a83cdcde7c0178428ecb0ad880a363a97a3 (patch) | |
tree | e203766ff955d264e795c06f6d1f9478f13c70b5 /main/src | |
parent | 959cb04640e90c35fe424d30f45867ac6626981b (diff) |
Fix some ANRs
Diffstat (limited to 'main/src')
4 files changed, 27 insertions, 15 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 39aaef57..edc36e9a 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -220,7 +220,9 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac @Override public void onRevoke() { VpnStatus.logError(R.string.permission_revoked); - mManagement.stopVPN(false); + final OpenVPNManagement managment = mManagement; + mCommandHandler.post(() -> managment.stopVPN(false)); + endVpnService(); } @@ -612,8 +614,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // Set a flag that we are starting a new VPN mStarting = true; // Stop the previous session by interrupting the thread. - - stopOldOpenVPNProcess(); + stopOldOpenVPNProcess(mManagement, mOpenVPNThread); // An old running VPN should now be exited mStarting = false; @@ -672,11 +673,12 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac } - private void stopOldOpenVPNProcess() { - if (mManagement != null) { - if (mOpenVPNThread != null) - ((OpenVPNThread) mOpenVPNThread).setReplaceConnection(); - if (mManagement.stopVPN(true)) { + private void stopOldOpenVPNProcess(OpenVPNManagement management, + Runnable mamanagmentThread) { + if (management != null) { + if (mamanagmentThread != null) + ((OpenVPNThread) mamanagmentThread).setReplaceConnection(); + if (management.stopVPN(true)) { // an old was asked to exit, wait 1s try { Thread.sleep(1000); diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java index 11b2608b..5d4486b9 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java @@ -47,12 +47,12 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { private pauseReason lastPauseReason = pauseReason.noNetwork;
private PausedStateCallback mPauseCallback;
private boolean mShuttingDown;
- private Runnable mResumeHoldRunnable = () -> {
+ private final Runnable mResumeHoldRunnable = () -> {
if (shouldBeRunning()) {
releaseHoldCmd();
}
};
- private Runnable orbotStatusTimeOutRunnable = new Runnable() {
+ private final Runnable orbotStatusTimeOutRunnable = new Runnable() {
@Override
public void run() {
sendProxyCMD(Connection.ProxyType.SOCKS5, "127.0.0.1", Integer.toString(OrbotHelper.SOCKS_PROXY_PORT_DEFAULT), false);
@@ -148,8 +148,6 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { VpnStatus.logException(e);
}
return false;
-
-
}
/**
@@ -402,7 +400,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { if (waittime > 1)
VpnStatus.updateStateString("CONNECTRETRY", String.valueOf(waittime),
R.string.state_waitconnectretry, ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET);
- mResumeHandler.postDelayed(mResumeHoldRunnable, waittime * 1000);
+ mResumeHandler.postDelayed(mResumeHoldRunnable, waittime * 1000L);
if (waittime > 5)
VpnStatus.logInfo(R.string.state_waitconnectretry, String.valueOf(waittime));
else
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java b/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java index a3c19955..802e0b49 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/OpenVpnPreferencesFragment.java @@ -46,7 +46,6 @@ public abstract class OpenVpnPreferencesFragment extends PreferenceFragmentCompa String profileUUID = savedInstanceState.getString(VpnProfile.EXTRA_PROFILEUUID); mProfile = ProfileManager.get(getActivity(), profileUUID); loadSettings(); - } } diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt index 27e6854f..fa7e6f55 100644 --- a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt +++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_IP.kt @@ -5,6 +5,7 @@ package de.blinkt.openvpn.fragments import android.os.Bundle +import android.view.View import androidx.preference.* import de.blinkt.openvpn.R import de.blinkt.openvpn.fragments.OpenVpnPreferencesFragment @@ -33,6 +34,19 @@ class Settings_IP : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeL // Load the preferences from an XML resource addPreferencesFromResource(R.xml.vpn_ipsettings) + bindPreferences() + loadSettings() + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + /* Bind the preferences early to avoid loadingSetting which is called + * from the superclass to access an uninitialised earlyinit property + */ + bindPreferences() + super.onViewCreated(view, savedInstanceState) + } + + private fun bindPreferences() { mIPv4 = findPreference("ipv4_address")!! mIPv6 = findPreference("ipv6_address")!! mUsePull = findPreference("usePull")!! @@ -45,7 +59,6 @@ class Settings_IP : OpenVpnPreferencesFragment(), Preference.OnPreferenceChangeL mNobind = findPreference("nobind")!! mUsePull.onPreferenceChangeListener = this mOverrideDNS.onPreferenceChangeListener = this - loadSettings() } |