Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes and minor improvements #428

Merged
merged 9 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ android {
// thus resulting in a crash.
ndk {
abiFilters 'arm64-v8a', 'x86', 'x86_64', 'armeabi-v7a'
debugSymbolLevel 'full'
}
bundle {
abi { enableSplit = false }
}
buildFeatures {
dataBinding = true
}
packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import nl.eduvpn.app.entity.AuthorizationType;
Expand All @@ -57,20 +54,6 @@ public void before() {
_serializerService = new SerializerService();
}

@Test
public void testAppSettingsSerialization() throws SerializerService.UnknownFormatException {
Settings settings = new Settings(true, true);
JSONObject jsonObject = _serializerService.serializeAppSettings(settings);
Settings deserializedSettings = _serializerService.deserializeAppSettings(jsonObject);
assertEquals(settings.preferTcp(), deserializedSettings.preferTcp());
assertEquals(settings.useCustomTabs(), deserializedSettings.useCustomTabs());
settings = new Settings(false, false);
jsonObject = _serializerService.serializeAppSettings(settings);
deserializedSettings = _serializerService.deserializeAppSettings(jsonObject);
assertEquals(settings.preferTcp(), deserializedSettings.preferTcp());
assertEquals(settings.useCustomTabs(), deserializedSettings.useCustomTabs());
}

@Test
public void testInstanceSerialization() throws SerializerService.UnknownFormatException {
Instance instance = new Instance("baseUri", new TranslatableString("displayName"), new TranslatableString("konijn"), "logoUri", AuthorizationType.Distributed, "HU", true, null, Arrays.asList("mailto:[email protected]", "tel:+0011223344659898"));
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/nl/eduvpn/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import kotlinx.coroutines.withContext
import nl.eduvpn.app.base.BaseActivity
import nl.eduvpn.app.databinding.ActivityMainBinding
import nl.eduvpn.app.entity.AddedServer
import nl.eduvpn.app.entity.Instance
import nl.eduvpn.app.entity.exception.CommonException
import nl.eduvpn.app.fragment.AddServerFragment
import nl.eduvpn.app.fragment.ConnectionStatusFragment
Expand Down Expand Up @@ -190,13 +189,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
show(this, ex)
return
}
if (viewModel.useCustomTabs()) {
val intent = CustomTabsIntent.Builder().build()
intent.launchUrl(this@MainActivity, oAuthUri)
} else {
val intent = Intent(Intent.ACTION_VIEW, oAuthUri)
startActivity(intent)
}
val intent = CustomTabsIntent.Builder().build()
intent.launchUrl(this@MainActivity, oAuthUri)
}

override fun onResume() {
Expand Down
45 changes: 0 additions & 45 deletions app/src/main/java/nl/eduvpn/app/entity/Settings.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.core.view.postDelayed
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.asLiveData
Expand All @@ -46,6 +47,7 @@ import nl.eduvpn.app.utils.ErrorDialog
import nl.eduvpn.app.utils.FormattingUtils
import nl.eduvpn.app.viewmodel.BaseConnectionViewModel
import nl.eduvpn.app.viewmodel.ConnectionStatusViewModel
import org.eduvpn.common.Protocol

/**
* The fragment which displays the status of the current connection.
Expand All @@ -64,6 +66,7 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
super.onViewCreated(view, savedInstanceState)
EduVPNApplication.get(view.context).component().inject(this)
binding.viewModel = viewModel
binding.isTcp = viewModel.isCurrentProtocolUsingTcp()
binding.secondsConnected = viewModel.connectionTimeLiveData.map { secondsConnected ->
val context = [email protected] ?: return@map null
FormattingUtils.formatDurationSeconds(
Expand All @@ -85,7 +88,7 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
bc?.bytesOut
)
}.asLiveData()
binding.protocol = viewModel.protocol
binding.protocolName = getProtocolName(viewModel.protocol)
binding.ips = viewModel.ipFLow.asLiveData()
binding.connectionSwitch.setOnCheckedChangeListener { _, isChecked ->
if (isAutomaticCheckChange) {
Expand All @@ -95,7 +98,7 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
viewModel.disconnect(activity)
} else {
// Get the config again, and connect again
viewModel.reconnectWithCurrentProfile()
viewModel.reconnectWithCurrentProfile(viewModel.isCurrentProtocolUsingTcp())
}
}
binding.connectionInfoDropdown.setOnClickListener {
Expand Down Expand Up @@ -134,6 +137,16 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
viewModel.disconnect(activity)
viewModel.renewSession()
}
binding.reconnectTcpButton.setOnClickListener { button ->
activity?.let {
viewModel.disconnect(it)
}
button.postDelayed(100) {
viewModel.enableTcp()
binding.isTcp = true
viewModel.reconnectWithCurrentProfile(preferTcp = true)
}
}
viewModel.connectionParentAction.observe(viewLifecycleOwner) { parentAction ->
when (parentAction) {
ConnectionStatusViewModel.ParentAction.SessionExpired -> {
Expand Down Expand Up @@ -235,6 +248,16 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
}
}

private fun getProtocolName(protocol: Protocol): String? {
return when(protocol) {
Protocol.OpenVPN -> getString(R.string.connection_info_protocol_name_openvpn)
Protocol.WireGuard -> getString(R.string.connection_info_protocol_name_wireguard)
Protocol.WireGuardWithTCP -> getString(R.string.connection_info_protocol_name_wireguard_with_tcp)
Protocol.OpenVPNWithTCP -> getString(R.string.connection_info_protocol_name_openvpn_with_tcp)
Protocol.Unknown -> null
}
}

private fun setToggleCheckedWithoutAction(isChecked: Boolean) {
isAutomaticCheckChange = true
binding.connectionSwitch.isChecked = isChecked
Expand All @@ -261,15 +284,15 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
}

fun reconnectToInstance() {
viewModel.reconnectWithCurrentProfile()
viewModel.reconnectWithCurrentProfile(viewModel.isCurrentProtocolUsingTcp())
}

private fun connectToProfile(profile: Profile) {
skipNextDisconnect = true
viewModel.isInDisconnectMode.value = false
setToggleCheckedWithoutAction(true)
viewModel.viewModelScope.launch(Dispatchers.IO) {
viewModel.selectProfileToConnectTo(profile).onFailure { thr ->
viewModel.selectProfileToConnectTo(profile, preferTcp = false).onFailure { thr ->
withContext(Dispatchers.Main) {
setToggleCheckedWithoutAction(false)
viewModel.isInDisconnectMode.value = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.observeOn
import kotlinx.coroutines.launch
import nl.eduvpn.app.EduVPNApplication
import nl.eduvpn.app.R
Expand Down Expand Up @@ -137,6 +140,13 @@ class OrganizationSelectionFragment : BaseFragment<FragmentOrganizationSelection
}
}
}
viewModel.viewModelScope.launch {
viewModel.error.collectLatest { exception ->
if (exception != null) {
ErrorDialog.show(requireActivity(), exception)
}
}
}
binding.search.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
viewModel.artworkVisible.value = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ProfileSelectionFragment : BaseFragment<FragmentProfileSelectionBinding>()

private fun selectProfileToConnectTo(profile: Profile) {
viewModel.viewModelScope.launch {
viewModel.selectProfileToConnectTo(profile).onFailure { thr ->
viewModel.selectProfileToConnectTo(profile, preferTcp = false).onFailure { thr ->
withContext(Dispatchers.Main) {
ErrorDialog.show(requireActivity(), thr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class ServerSelectionFragment : BaseFragment<FragmentServerSelectionBinding>() {
val item = adapter.getItem(position)
if (item is OrganizationAdapter.OrganizationAdapterItem.SecureInternet) {
viewModel.connectingTo.value = item.server
viewModel.getProfiles(item.server)
viewModel.getProfiles(item.server, preferTcp = false)
} else if (item is OrganizationAdapter.OrganizationAdapterItem.InstituteAccess) {
viewModel.connectingTo.value = item.server
viewModel.getProfiles(item.server)
viewModel.getProfiles(item.server, preferTcp = false)
}
}.setOnItemLongClickListener { _, position, _ ->
if (position < 0 || position >= adapter.itemCount) {
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/java/nl/eduvpn/app/fragment/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import nl.eduvpn.app.R
import nl.eduvpn.app.SettingsActivity
import nl.eduvpn.app.base.BaseFragment
import nl.eduvpn.app.databinding.FragmentSettingsBinding
import nl.eduvpn.app.entity.Settings
import nl.eduvpn.app.viewmodel.SettingsViewModel

/**
Expand All @@ -48,11 +47,6 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
EduVPNApplication.get(view.context).component().inject(this)
val originalSettings = viewModel.appSettings
binding.useCustomTabsSwitch.isChecked = originalSettings.useCustomTabs()
binding.preferTcpSwitch.isChecked = originalSettings.preferTcp()
binding.useCustomTabsSwitch.setOnClickListener { saveSettings() }
binding.preferTcpSwitch.setOnClickListener { saveSettings() }
binding.licensesButton.setOnClickListener {
startActivity(
Intent(
Expand Down Expand Up @@ -108,10 +102,4 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>() {
warningDialog.show()
}
}

private fun saveSettings() {
val useCustomTabs = binding.useCustomTabsSwitch.isChecked
val preferTcp = binding.preferTcpSwitch.isChecked
viewModel.storeAppSettings(Settings(useCustomTabs, preferTcp))
}
}
7 changes: 3 additions & 4 deletions app/src/main/java/nl/eduvpn/app/inject/ApplicationModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ class ApplicationModule(private val application: EduVPNApplication) {
@Singleton
fun provideEduOpenVPNService(
context: Context,
preferencesService: PreferencesService?,
ipLiveData: IPLiveData,
): EduVPNOpenVPNService {
return EduVPNOpenVPNService(context, preferencesService, ipLiveData)
return EduVPNOpenVPNService(context, ipLiveData)
}

@Provides
Expand All @@ -148,8 +147,8 @@ class ApplicationModule(private val application: EduVPNApplication) {
wireGuardServiceProvider: Provider<WireGuardService>
): Optional<VPNService> {
return when (preferencesService.getCurrentProtocol()) {
Protocol.OpenVPN.nativeValue -> Optional.of(eduOpenVPNServiceProvider.get())
Protocol.WireGuard.nativeValue, Protocol.WireGuardWithProxyGuard.nativeValue -> Optional.of(wireGuardServiceProvider.get())
Protocol.OpenVPN.nativeValue, Protocol.OpenVPNWithTCP.nativeValue -> Optional.of(eduOpenVPNServiceProvider.get())
Protocol.WireGuard.nativeValue, Protocol.WireGuardWithTCP.nativeValue -> Optional.of(wireGuardServiceProvider.get())
else -> Optional.empty()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public class EduVPNOpenVPNService extends VPNService implements VpnStatus.StateL
private static final String TAG = EduVPNOpenVPNService.class.getName();

private final Context _context;
private final PreferencesService _preferencesService;

// Stores the current VPN status.
private ConnectionStatus _connectionStatus = ConnectionStatus.LEVEL_NOTCONNECTED;
Expand Down Expand Up @@ -101,9 +100,8 @@ public void onServiceDisconnected(ComponentName arg0) {
*
* @param context The application or activity context.
*/
public EduVPNOpenVPNService(Context context, PreferencesService preferencesService, IPLiveData ipLiveData) {
public EduVPNOpenVPNService(Context context, IPLiveData ipLiveData) {
_context = context;
_preferencesService = preferencesService;
_ipLiveData = ipLiveData;
_byteCountLiveData = UnlessDisconnectedLiveData.INSTANCE.create(new ByteCountLiveData(), this);
}
Expand Down Expand Up @@ -197,10 +195,9 @@ public VpnProfile importConfig(String configString, String preferredName) {
* @param activity The current activity, required for providing a context.
* @param vpnProfile The profile to connect to.
*/
public void connect(@NonNull Activity activity, @NonNull VpnProfile vpnProfile) {
public void connect(@NonNull Activity activity, @NonNull VpnProfile vpnProfile, Boolean preferTcp) {
Log.i(TAG, "Initiating connection with profile:" + vpnProfile.getUUIDString());
boolean preferTcp = _preferencesService.getAppSettings().preferTcp();
Log.i(TAG, "Prefet TCP: " + preferTcp);
Log.i(TAG, "Prefer TCP: " + preferTcp);
// If force TCP is enabled, disable the UDP connections
for (Connection connection : vpnProfile.mConnections) {
if (connection.mUseUdp) {
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/nl/eduvpn/app/service/OrganizationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ class OrganizationService(
private val backendService: BackendService
) {


suspend fun fetchServerList(searchFilter: String) : ServerList = withContext(Dispatchers.IO) {
val serverListString = backendService.discoverServers(searchFilter)
serializerService.deserializeServerList(serverListString)
suspend fun fetchServerList(searchFilter: String) : Result<ServerList> = withContext(Dispatchers.IO) {
try {
val serverListString = backendService.discoverServers(searchFilter)
val result = serializerService.deserializeServerList(serverListString)
return@withContext Result.success(result)
} catch (throwable: Throwable) {
return@withContext Result.failure(throwable)
}
}

suspend fun fetchOrganizations(searchFilter: String): OrganizationList = withContext(Dispatchers.IO) {
Expand Down
Loading
Loading