summaryrefslogtreecommitdiff
path: root/ipscrambling/src/main/java
diff options
context:
space:
mode:
authorGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-09-12 06:17:39 +0000
committerGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-09-12 06:17:39 +0000
commita38472602d259b6c265660bf3b0ba472f20c6a7f (patch)
tree59c58e58cfef0e370f39bd9c150e36c6dfcb50c0 /ipscrambling/src/main/java
parent1a77e3924bc78eabca7b859ef62be30bbf2476ad (diff)
parent53f4a9ce311d612d43fa770cf7e8f8e98fbb43a0 (diff)
Merge branch '2-privacymodules_to_clean_archi' into 'main'
2: organise module with clean archi, use Koin for injection. See merge request e/os/advanced-privacy!144
Diffstat (limited to 'ipscrambling/src/main/java')
-rw-r--r--ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/IpScramblerModule.kt (renamed from ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IpScramblerModule.kt)41
-rw-r--r--ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt8
-rw-r--r--ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt54
3 files changed, 32 insertions, 71 deletions
diff --git a/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IpScramblerModule.kt b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/IpScramblerModule.kt
index 1c39330..d1f01a0 100644
--- a/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IpScramblerModule.kt
+++ b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/IpScramblerModule.kt
@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-package foundation.e.privacymodules.ipscrambler
+package foundation.e.advancedprivacy.ipscrambler
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
@@ -29,8 +29,6 @@ import android.os.Looper
import android.os.Message
import android.util.Log
import androidx.localbroadcastmanager.content.LocalBroadcastManager
-import foundation.e.privacymodules.ipscrambler.IIpScramblerModule.Listener
-import foundation.e.privacymodules.ipscrambler.IIpScramblerModule.Status
import org.torproject.android.service.OrbotConstants
import org.torproject.android.service.OrbotConstants.ACTION_STOP_FOREGROUND_TASK
import org.torproject.android.service.OrbotService
@@ -38,7 +36,16 @@ import org.torproject.android.service.util.Prefs
import java.security.InvalidParameterException
@SuppressLint("CommitPrefEdits")
-class IpScramblerModule(private val context: Context) : IIpScramblerModule {
+class IpScramblerModule(private val context: Context) {
+ interface Listener {
+ fun onStatusChanged(newStatus: Status)
+ fun log(message: String)
+ fun onTrafficUpdate(upload: Long, download: Long, read: Long, write: Long)
+ }
+
+ enum class Status {
+ OFF, ON, STARTING, STOPPING, START_DISABLED
+ }
companion object {
const val TAG = "IpScramblerModule"
@@ -221,11 +228,11 @@ class IpScramblerModule(private val context: Context) : IIpScramblerModule {
return if (raw.isEmpty()) raw else raw.slice(1..2)
}
- override fun prepareAndroidVpn(): Intent? {
+ fun prepareAndroidVpn(): Intent? {
return VpnService.prepare(context)
}
- override fun start(enableNotification: Boolean) {
+ fun start(enableNotification: Boolean) {
Prefs.enableNotification(enableNotification)
Prefs.putUseVpn(true)
Prefs.putStartOnBoot(true)
@@ -234,7 +241,7 @@ class IpScramblerModule(private val context: Context) : IIpScramblerModule {
sendIntentToService(OrbotConstants.ACTION_START_VPN)
}
- override fun stop() {
+ fun stop() {
updateStatus(Status.STOPPING)
Prefs.putUseVpn(false)
@@ -261,7 +268,7 @@ class IpScramblerModule(private val context: Context) : IIpScramblerModule {
)
}
- override fun requestStatus() {
+ fun requestStatus() {
if (isServiceRunning()) {
sendIntentToService(OrbotConstants.ACTION_STATUS)
} else {
@@ -269,33 +276,33 @@ class IpScramblerModule(private val context: Context) : IIpScramblerModule {
}
}
- override var appList: Set<String>
+ var appList: Set<String>
get() = getTorifiedApps()
set(value) = saveTorifiedApps(value)
- override var exitCountry: String
+ var exitCountry: String
get() = getExitCountryCode()
set(value) = setExitCountryCode(value)
- override fun getAvailablesLocations(): Set<String> = EXIT_COUNTRY_CODES
+ fun getAvailablesLocations(): Set<String> = EXIT_COUNTRY_CODES
- override var httpProxyPort: Int = -1
+ var httpProxyPort: Int = -1
private set
- override var socksProxyPort: Int = -1
+ var socksProxyPort: Int = -1
private set
- override fun addListener(listener: Listener) {
+ fun addListener(listener: Listener) {
listeners.add(listener)
}
- override fun removeListener(listener: Listener) {
+ fun removeListener(listener: Listener) {
listeners.remove(listener)
}
- override fun clearListeners() {
+ fun clearListeners() {
listeners.clear()
}
- override fun onCleared() {
+ fun onCleared() {
LocalBroadcastManager.getInstance(context).unregisterReceiver(localBroadcastReceiver)
}
}
diff --git a/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt
new file mode 100644
index 0000000..4f80ef4
--- /dev/null
+++ b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt
@@ -0,0 +1,8 @@
+package foundation.e.advancedprivacy.ipscrambler
+
+import org.koin.core.module.dsl.singleOf
+import org.koin.dsl.module
+
+val ipScramblerModule = module {
+ singleOf(::IpScramblerModule)
+}
diff --git a/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt b/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt
deleted file mode 100644
index 859319a..0000000
--- a/ipscrambling/src/main/java/foundation/e/privacymodules/ipscrambler/IIpScramblerModule.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2021 E FOUNDATION
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacymodules.ipscrambler
-
-import android.content.Intent
-
-interface IIpScramblerModule {
- fun prepareAndroidVpn(): Intent?
-
- fun start(enableNotification: Boolean = true)
-
- fun stop()
-
- fun requestStatus()
-
- var appList: Set<String>
-
- var exitCountry: String
- fun getAvailablesLocations(): Set<String>
-
- val httpProxyPort: Int
- val socksProxyPort: Int
-
- fun addListener(listener: Listener)
- fun removeListener(listener: Listener)
- fun clearListeners()
-
- fun onCleared()
-
- interface Listener {
- fun onStatusChanged(newStatus: Status)
- fun log(message: String)
- fun onTrafficUpdate(upload: Long, download: Long, read: Long, write: Long)
- }
-
- enum class Status {
- OFF, ON, STARTING, STOPPING, START_DISABLED
- }
-}