Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolnai committed Jun 6, 2024
1 parent d8b6509 commit fce85c9
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,4 @@ class PreferencesServiceTest {
retrievedInstance.authenticationUrlTemplate
)
}

@Test
fun testLastKnownOrganizationListVersionSave() {
val version = 121_323L
_preferencesService.setLastKnownOrganizationListVersion(version)
val retrievedVersion = _preferencesService.getLastKnownOrganizationListVersion()
Assert.assertEquals(version, retrievedVersion)
}

@Test
fun testLastKnownServerListVersionSave() {
val version = 8_982_398L
_preferencesService.setLastKnownServerListVersion(version)
val retrievedVersion = _preferencesService.getLastKnownServerListVersion()
Assert.assertEquals(version, retrievedVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,6 @@ public void testInstanceSerialization() throws SerializerService.UnknownFormatEx
assertEquals(instance.getSupportContact(), deserializedInstance.getSupportContact());
}

@Test
public void testOrganizationListSerialization() throws SerializerService.UnknownFormatException {
Map<String, String> keywordsMap = new HashMap<>();
keywordsMap.put("en", "english keyword");
keywordsMap.put("de", "german keyword");
keywordsMap.put("nl", "dutch keyword");
Organization organization1 = new Organization("orgid-1", new TranslatableString("display name - 1"), new TranslatableString(keywordsMap), "https://server.info/url");
Organization organization2 = new Organization("orgid-2", new TranslatableString("display name - 2"), new TranslatableString("notthesamekeyword"), "https://server.info2/url");
Organization organization3 = new Organization("orgid-3", new TranslatableString("display name - 3"), new TranslatableString(), "http://server.info/url3");
List<Organization> organizations = Arrays.asList(organization1, organization2, organization3);
OrganizationList organizationList = new OrganizationList(12345L, organizations);
JSONObject serializedOrganizationList = _serializerService.serializeOrganizationList(organizationList);
OrganizationList deserializedOrganizationList = _serializerService.deserializeOrganizationList(serializedOrganizationList);
for (int i = 0; i < organizations.size(); ++i) {
assertEquals(organizations.get(i).getDisplayName(), deserializedOrganizationList.getOrganizationList().get(i).getDisplayName());
assertEquals(organizations.get(i).getKeywordList(), deserializedOrganizationList.getOrganizationList().get(i).getKeywordList());
assertEquals(organizations.get(i).getOrgId(), deserializedOrganizationList.getOrganizationList().get(i).getOrgId());
assertEquals(organizations.get(i).getSecureInternetHome(), deserializedOrganizationList.getOrganizationList().get(i).getSecureInternetHome());
assertEquals(organizationList.getVersion(), deserializedOrganizationList.getVersion());
}
}

/**
* Removes the milliseconds from a date. Required because the parser does not care about milliseconds.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ package nl.eduvpn.app.fragment
import android.app.NotificationManager
import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.viewModels
Expand All @@ -44,14 +41,11 @@ import nl.eduvpn.app.databinding.FragmentConnectionStatusBinding
import nl.eduvpn.app.entity.Profile
import nl.eduvpn.app.fragment.ServerSelectionFragment.Companion.newInstance
import nl.eduvpn.app.service.VPNConnectionService
import nl.eduvpn.app.service.VPNService
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 javax.inject.Inject

/**
* The fragment which displays the status of the current connection.
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/java/nl/eduvpn/app/service/BackendService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import org.eduvpn.common.GoBackend
import org.eduvpn.common.GoBackend.Callback
import org.eduvpn.common.ServerType
import java.io.File
import java.io.FileDescriptor
import java.net.InetAddress
import java.net.NetworkInterface
import java.util.Collections
import java.util.Locale


class BackendService(
Expand All @@ -52,8 +48,6 @@ class BackendService(
private val goBackend = GoBackend()
private var pendingOAuthCookie: Int? = null
private var pendingProfileSelectionCookie: Int? = null
var lastSelectedProfile: String? = null
private set

private var onConfigReady: ((SerializedVpnConfig, Boolean) -> Unit)? = null

Expand Down Expand Up @@ -266,7 +260,6 @@ class BackendService(

@kotlin.jvm.Throws(CommonException::class)
suspend fun selectProfile(profile: Profile, preferTcp: Boolean) {
lastSelectedProfile = profile.profileId
val cookie = pendingProfileSelectionCookie
if (cookie != null) {
val result = goBackend.selectProfile(cookie, profile.profileId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class HistoryService {

private final BackendService _backendService;

private List<Listener> _listeners = new LinkedList<>();
private final List<Listener> _listeners = new LinkedList<>();

/**
* Constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import nl.eduvpn.app.entity.OrganizationList
import nl.eduvpn.app.entity.ServerList
import org.json.JSONObject

/**
* Service which provides the configurations for organization related data model.
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/nl/eduvpn/app/service/PreferencesService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package nl.eduvpn.app.service


import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
Expand All @@ -35,7 +34,6 @@ import org.json.JSONObject
import java.io.File
import java.io.IOException


/**
* This service is used to save temporary data
* Created by Daniel Zolnai on 2016-10-11.
Expand Down Expand Up @@ -70,9 +68,6 @@ class PreferencesService(
const val KEY_INSTANCE_LIST_INSTITUTE_ACCESS =
KEY_INSTANCE_LIST_PREFIX + "institute_access"

const val KEY_SAVED_KEY_PAIRS = "saved_key_pairs"
const val KEY_PREFERRED_COUNTRY = "preferred_country"

const val KEY_STORAGE_VERSION = "storage_version"
}

Expand Down
22 changes: 0 additions & 22 deletions app/src/main/java/nl/eduvpn/app/service/SerializerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package nl.eduvpn.app.service

import kotlinx.serialization.SerializationException
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import nl.eduvpn.app.entity.AddedServers
import nl.eduvpn.app.entity.CertExpiryTimes
Expand All @@ -26,20 +25,12 @@ import nl.eduvpn.app.entity.CookieAndStringArrayData
import nl.eduvpn.app.entity.CookieAndStringData
import nl.eduvpn.app.entity.CurrentServer
import nl.eduvpn.app.entity.Instance
import nl.eduvpn.app.entity.Organization
import nl.eduvpn.app.entity.OrganizationList
import nl.eduvpn.app.entity.Profile
import nl.eduvpn.app.entity.SerializedVpnConfig
import nl.eduvpn.app.entity.ServerList
import nl.eduvpn.app.entity.Settings
import nl.eduvpn.app.entity.TranslatableString
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.TimeZone

/**
* This service is responsible for (de)serializing objects used in the app.
Expand All @@ -48,15 +39,6 @@ import java.util.TimeZone
class SerializerService {
class UnknownFormatException internal constructor(throwable: Throwable?) : Exception(throwable)

@Throws(UnknownFormatException::class)
fun deserializeProfileList(json: String?): List<Profile> {
return try {
jsonSerializer.decodeFromString(ListSerializer(Profile.serializer()), json!!)
} catch (ex: SerializationException) {
throw UnknownFormatException(ex)
}
}

/**
* Serializes an instance to a JSON format.
*
Expand Down Expand Up @@ -228,10 +210,6 @@ class SerializerService {
}

companion object {
private val API_DATE_FORMAT: DateFormat =
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).apply {
timeZone = TimeZone.getTimeZone("UTC")
}
private val jsonSerializer: Json = Json {
ignoreUnknownKeys = true
coerceInputValues = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.core.app.NotificationCompat
import androidx.lifecycle.Observer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import nl.eduvpn.app.Constants
import nl.eduvpn.app.DisconnectVPNBroadcastReceiver
Expand All @@ -20,7 +19,6 @@ import nl.eduvpn.app.utils.FormattingUtils
import nl.eduvpn.app.utils.Log
import nl.eduvpn.app.utils.pendingIntentImmutableFlag
import org.eduvpn.common.Protocol
import java.lang.reflect.InvocationTargetException

class VPNConnectionService(
private val preferencesService: PreferencesService,
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/nl/eduvpn/app/service/WireGuardService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nl.eduvpn.app.service
import android.app.Activity
import android.app.Notification
import android.content.Context
import android.os.ParcelFileDescriptor
import com.wireguard.android.backend.BackendException
import com.wireguard.android.backend.GoBackend
import com.wireguard.android.backend.Tunnel
Expand All @@ -13,7 +12,6 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.lifecycle.asFlow
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import nl.eduvpn.app.CertExpiredBroadcastReceiver
import nl.eduvpn.app.R
Expand All @@ -44,7 +43,6 @@ import nl.eduvpn.app.service.*
import nl.eduvpn.app.utils.Log
import nl.eduvpn.app.utils.pendingIntentImmutableFlag
import nl.eduvpn.app.utils.toSingleEvent
import java.util.*
import javax.inject.Inject
import javax.inject.Named

Expand Down

0 comments on commit fce85c9

Please sign in to comment.