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

Update WireGuard, common, ics-openvpn dependencies, crash fixes #431

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 3 additions & 18 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,10 @@
</intent-filter>
</activity>

<activity-alias
android:name="${applicationId}.activities.LogWindow"
android:targetActivity="de.blinkt.openvpn.activities.LogWindow" />

<activity
android:name="de.blinkt.openvpn.activities.LogWindow"
android:allowTaskReparenting="true"
android:label="@string/openvpn_log"
<activity android:name=".OpenVpnLogsActivity"
android:launchMode="singleTask"
android:parentActivityName=".MainActivity"
android:theme="@style/StyledVpn"
tools:ignore="UnusedAttribute">

<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />

</activity>
android:exported="false"
android:theme="@style/AppTheme.NoActionBar" />

<activity android:name=".ApiLogsActivity"
android:launchMode="singleTask"
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/nl/eduvpn/app/OpenVpnLogsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package nl.eduvpn.app

import android.os.Bundle
import android.view.MenuItem
import androidx.activity.viewModels
import androidx.core.view.isVisible
import de.blinkt.openvpn.fragments.LogFragment
import nl.eduvpn.app.base.BaseActivity
import nl.eduvpn.app.databinding.ActivityApiLogsBinding
import nl.eduvpn.app.databinding.ActivityOpenvpnLogsBinding
import nl.eduvpn.app.viewmodel.ApiLogsViewModel
import nl.eduvpn.app.viewmodel.ViewModelFactory
import javax.inject.Inject

class OpenVpnLogsActivity : BaseActivity<ActivityOpenvpnLogsBinding>() {

override val layout = R.layout.activity_openvpn_logs

@Inject
protected lateinit var viewModelFactory: ViewModelFactory

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
EduVPNApplication.get(this).component().inject(this)
setSupportActionBar(binding.toolbar.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
binding.toolbar.settingsButton.isVisible = false
supportFragmentManager.beginTransaction()
.add(binding.fragmentContainer.id, LogFragment())
.commit()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) {
onBackPressedDispatcher.onBackPressed()
true
} else {
super.onOptionsItemSelected(item)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ import nl.eduvpn.app.service.VPNConnectionService
import nl.eduvpn.app.service.VPNService.VPNStatus
import nl.eduvpn.app.utils.ErrorDialog
import nl.eduvpn.app.utils.FormattingUtils
import nl.eduvpn.app.utils.Log
import nl.eduvpn.app.viewmodel.BaseConnectionViewModel
import nl.eduvpn.app.viewmodel.ConnectionStatusViewModel
import nl.eduvpn.app.viewmodel.MainViewModel
import org.eduvpn.common.Protocol
import java.util.logging.Logger

/**
* The fragment which displays the status of the current connection.
Expand All @@ -74,10 +76,11 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
binding.failoverNeeded = mainViewModel.failoverResult.value ?: false
binding.secondsConnected = viewModel.connectionTimeLiveData.map { secondsConnected ->
val context = [email protected] ?: return@map null
FormattingUtils.formatDurationSeconds(
context,
secondsConnected
)
if (secondsConnected < 0) {
FormattingUtils.formatDurationSeconds(context, null)
} else {
FormattingUtils.formatDurationSeconds(context, secondsConnected)
}
}
binding.bytesDownloaded = viewModel.byteCountFlow.map { bc ->
val context = [email protected] ?: return@map null
Expand Down Expand Up @@ -300,18 +303,29 @@ class ConnectionStatusFragment : BaseFragment<FragmentConnectionStatusBinding>()
viewModel.isInDisconnectMode.value = false
setToggleCheckedWithoutAction(true)
viewModel.viewModelScope.launch(Dispatchers.IO) {
viewModel.selectProfileToConnectTo(profile, preferTcp = false).onFailure { thr ->
withContext(Dispatchers.Main) {
setToggleCheckedWithoutAction(false)
viewModel.isInDisconnectMode.value = true
ErrorDialog.show(requireActivity(), thr)
try {
viewModel.selectProfileToConnectTo(profile, preferTcp = false).onFailure { thr ->
withContext(Dispatchers.Main) {
setToggleCheckedWithoutAction(false)
viewModel.isInDisconnectMode.value = true
ErrorDialog.show(requireActivity(), thr)
}
}.onSuccess {
// Relaunch this fragment. This is required, because in some cases, the backend
// implementation (WireGuard vs OpenVPN) might be different, and we would be connected
// to the incorrect one.
(activity as? MainActivity)?.openFragment(ConnectionStatusFragment(), openOnTop = false)
}
} catch (ex: Exception) {
Log.w(TAG, "Could not select profile to connect to!", ex)
activity?.let {
ErrorDialog.show(it, ex)
}
}.onSuccess {
// Relaunch this fragment. This is required, because in some cases, the backend
// implementation (WireGuard vs OpenVPN) might be different, and we would be connected
// to the incorrect one.
(activity as? MainActivity)?.openFragment(ConnectionStatusFragment(), openOnTop = false)
}
}
}

companion object {
private val TAG = ConnectionStatusFragment::class.java.name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ class OrganizationSelectionFragment : BaseFragment<FragmentOrganizationSelection
viewModel.parentAction.observe(viewLifecycleOwner) { parentAction ->
when (parentAction) {
is BaseConnectionViewModel.ParentAction.DisplayError -> {
ErrorDialog.show(requireActivity(), parentAction.title, parentAction.message)
activity?.let { activity ->
ErrorDialog.show(activity, parentAction.title, parentAction.message)
}
}
is BaseConnectionViewModel.ParentAction.ShowContextCanceledToast -> {
Snackbar.make(view, parentAction.message, Snackbar.LENGTH_LONG).show()
Expand All @@ -143,7 +145,9 @@ class OrganizationSelectionFragment : BaseFragment<FragmentOrganizationSelection
viewModel.viewModelScope.launch {
viewModel.error.collectLatest { exception ->
if (exception != null) {
ErrorDialog.show(requireActivity(), exception)
activity?.let { activity ->
ErrorDialog.show(activity, exception)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ProfileSelectionFragment : BaseFragment<FragmentProfileSelectionBinding>()
}

private fun selectProfileToConnectTo(profile: Profile) {
viewModel.viewModelScope.launch {
viewModel.viewModelScope.launch(Dispatchers.IO) {
viewModel.selectProfileToConnectTo(profile, preferTcp = false).onFailure { thr ->
withContext(Dispatchers.Main) {
ErrorDialog.show(requireActivity(), thr)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/nl/eduvpn/app/fragment/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import nl.eduvpn.app.ApiLogsActivity
import nl.eduvpn.app.BuildConfig
import nl.eduvpn.app.EduVPNApplication
import nl.eduvpn.app.LicenseActivity
import nl.eduvpn.app.OpenVpnLogsActivity
import nl.eduvpn.app.R
import nl.eduvpn.app.SettingsActivity
import nl.eduvpn.app.base.BaseFragment
Expand Down Expand Up @@ -57,7 +58,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>() {
}
binding.resetDataButton.setOnClickListener { onResetDataClicked() }
binding.viewOpenvpnLogsButton.setOnClickListener {
val intent = Intent(activity, LogWindow::class.java)
val intent = Intent(activity, OpenVpnLogsActivity::class.java)
startActivity(intent)
}
binding.viewApiLogsButton.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ApplicationModule(private val application: EduVPNApplication) {
fun provideConnectionTimeLiveData(
vpnService: VPNService,
@Named("timer") timer: LiveData<Unit>
): LiveData<Long?> {
): LiveData<Long> {
return ConnectionTimeLiveData.create(vpnService, timer)
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/nl/eduvpn/app/inject/EduVPNComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import nl.eduvpn.app.CertExpiredBroadcastReceiver
import nl.eduvpn.app.DisconnectVPNBroadcastReceiver
import nl.eduvpn.app.EduVPNApplication
import nl.eduvpn.app.MainActivity
import nl.eduvpn.app.OpenVpnLogsActivity
import nl.eduvpn.app.fragment.*
import javax.inject.Singleton

Expand All @@ -43,6 +44,7 @@ interface EduVPNComponent {
fun inject(organizationSelectionFragment: OrganizationSelectionFragment)
fun inject(mainActivity: MainActivity)
fun inject(apiLogsActivity: ApiLogsActivity)
fun inject(apiLogsActivity: OpenVpnLogsActivity)
fun inject(connectionStatusFragment: ConnectionStatusFragment)
fun inject(homeFragment: ProfileSelectionFragment)
fun inject(settingsFragment: SettingsFragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ object ConnectionTimeLiveData {
fun create(
vpnStatusLiveData: LiveData<VPNService.VPNStatus>,
timer: LiveData<Unit>
): LiveData<Long?> {
): LiveData<Long> {
var connectionTime = 0L

val connectionTimeLiveData = MediatorLiveData<Long?>()
val connectionTimeLiveData = MediatorLiveData<Long>()

val update = {
connectionTimeLiveData.value = (System.currentTimeMillis() - connectionTime) / 1000L
Expand All @@ -52,7 +52,7 @@ object ConnectionTimeLiveData {
}
} else if (vpnStatus == VPNService.VPNStatus.DISCONNECTED) {
connectionTimeLiveData.removeSource(timer)
connectionTimeLiveData.value = null
connectionTimeLiveData.value = -1
}
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/nl/eduvpn/app/service/BackendService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class BackendService(
}

@kotlin.jvm.Throws(CommonException::class)
suspend fun addServer(instance: Instance) {
fun addServer(instance: Instance) {
val errorString = goBackend.addServer(
instance.authorizationType.toNativeServerType().nativeValue,
instance.baseURI
Expand Down Expand Up @@ -233,7 +233,6 @@ class BackendService(
return true
}

@kotlin.jvm.Throws(CommonException::class, UnknownFormatException::class)
fun getAddedServers(): AddedServers {
val dataErrorTuple = goBackend.addedServers
if (dataErrorTuple.isError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,17 @@ public void startForeground(int id, @NonNull Notification notification) {
*/
public void disconnect() {
try {
_openVPNService.stopVPN(false);
if (_openVPNService == null) {
ConnectionStatus previousStatus = _connectionStatus;
_connectionStatus = ConnectionStatus.LEVEL_NOTCONNECTED;
if (previousStatus != _connectionStatus) {
_updatesHandler.post(() -> {
setValue(connectionStatusToVPNStatus(_connectionStatus));
});
}
} else {
_openVPNService.stopVPN(false);
}
} catch (RemoteException ex) {
Log.e(TAG, "Exception when trying to stop connection. Connection might not be closed!", ex);
}
Expand Down
Loading
Loading