mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 13:21:50 +01:00
Adds Tor
This commit is contained in:
parent
8ede4eb3d6
commit
8841aa9a10
@ -288,6 +288,9 @@ dependencies {
|
||||
// Cbor for cashuB format
|
||||
implementation libs.kotlinx.serialization.cbor
|
||||
|
||||
implementation libs.tor.android
|
||||
implementation libs.jtorctl
|
||||
|
||||
testImplementation libs.junit
|
||||
testImplementation libs.mockk
|
||||
|
||||
|
@ -21,14 +21,18 @@
|
||||
package com.vitorpamplona.amethyst.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Network
|
||||
import android.net.NetworkCapabilities
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@ -63,6 +67,8 @@ import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.torproject.jni.TorService
|
||||
import org.torproject.jni.TorService.LocalBinder
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.Timer
|
||||
@ -133,6 +139,34 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// resets state until next External Signer Call
|
||||
Timer().schedule(350) { shouldPauseService = true }
|
||||
|
||||
bindService(
|
||||
Intent(this, TorService::class.java),
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(
|
||||
name: ComponentName,
|
||||
service: IBinder,
|
||||
) {
|
||||
// moved torService to a local variable, since we only need it once
|
||||
|
||||
val torService = (service as LocalBinder).service
|
||||
|
||||
while (torService.torControlConnection == null) {
|
||||
try {
|
||||
Thread.sleep(500)
|
||||
} catch (e: InterruptedException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
Toast.makeText(this@MainActivity, "Got Tor control connection", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName) {
|
||||
}
|
||||
},
|
||||
BIND_AUTO_CREATE,
|
||||
)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -155,6 +189,8 @@ class MainActivity : AppCompatActivity() {
|
||||
(getSystemService(ConnectivityManager::class.java) as ConnectivityManager)
|
||||
.unregisterNetworkCallback(networkCallback)
|
||||
|
||||
stopService(Intent(baseContext, TorService::class.java))
|
||||
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ fragmentKtx = "1.8.3"
|
||||
gms = "4.4.2"
|
||||
jacksonModuleKotlin = "2.17.2"
|
||||
jna = "5.14.0"
|
||||
jtorctl = "0.4.5.7"
|
||||
junit = "4.13.2"
|
||||
kotlin = "2.0.0"
|
||||
kotlinxCollectionsImmutable = "0.3.7"
|
||||
@ -41,6 +42,7 @@ rfc3986 = "0.1.0"
|
||||
secp256k1KmpJniAndroid = "0.15.0"
|
||||
securityCryptoKtx = "1.1.0-alpha06"
|
||||
spotless = "6.25.0"
|
||||
torAndroid = "0.4.8.12"
|
||||
translate = "17.0.3"
|
||||
unifiedpush = "2.3.1"
|
||||
urlDetector = "0.1.23"
|
||||
@ -99,6 +101,7 @@ google-mlkit-language-id = { group = "com.google.mlkit", name = "language-id", v
|
||||
google-mlkit-translate = { group = "com.google.mlkit", name = "translate", version.ref = "translate" }
|
||||
jackson-module-kotlin = { group = "com.fasterxml.jackson.module", name = "jackson-module-kotlin", version.ref = "jacksonModuleKotlin" }
|
||||
jna = { group = "net.java.dev.jna", name = "jna", version.ref = "jna" }
|
||||
jtorctl = { module = "info.guardianproject:jtorctl", version.ref = "jtorctl" }
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
kotlinx-collections-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "kotlinxCollectionsImmutable" }
|
||||
kotlinx-serialization-cbor = { module = "org.jetbrains.kotlinx:kotlinx-serialization-cbor", version.ref = "kotlinxSerialization" }
|
||||
@ -110,6 +113,7 @@ mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
|
||||
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
|
||||
rfc3986-normalizer = { group = "org.czeal", name = "rfc3986", version.ref = "rfc3986" }
|
||||
secp256k1-kmp-jni-android = { group = "fr.acinq.secp256k1", name = "secp256k1-kmp-jni-android", version.ref = "secp256k1KmpJniAndroid" }
|
||||
tor-android = { module = "info.guardianproject:tor-android", version.ref = "torAndroid" }
|
||||
trbl-blurhash = { group = "io.trbl", name = "blurhash", version.ref = "blurhash" }
|
||||
unifiedpush = { group = "com.github.UnifiedPush", name = "android-connector", version.ref = "unifiedpush" }
|
||||
url-detector = { group = "io.github.url-detector", name = "url-detector", version.ref = "urlDetector" }
|
||||
|
@ -24,6 +24,7 @@ dependencyResolutionManagement {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url "https://raw.githubusercontent.com/guardianproject/gpmaven/master" }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user