1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.vauth.foxyvpn
import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.res.Configuration
import android.os.Build
import android.util.Log
import com.vauth.foxyvpn.data.CrashReporter
import com.vauth.foxyvpn.data.FxaAuthRepository
import com.vauth.foxyvpn.data.GuardianClient
import com.vauth.foxyvpn.data.ProxyStateStore
import com.vauth.foxyvpn.data.ServerListClient
import com.vauth.foxyvpn.data.SettingsStore
import com.vauth.foxyvpn.data.TokenStore
import com.vauth.foxyvpn.vpn.FoxyVpnService
import com.vauth.foxyvpn.vpn.upstream.NettyLoggingBridge
import com.vauth.foxyvpn.vpn.upstream.UpstreamTrust
import com.vauth.foxyvpn.widget.QuickConnectWidgetProvider
import org.conscrypt.Conscrypt
import java.security.Security
class FoxyVpnApp : Application() {
lateinit var tokenStore: TokenStore
lateinit var proxyStateStore: ProxyStateStore
lateinit var settingsStore: SettingsStore
lateinit var guardianClient: GuardianClient
lateinit var serverListClient: ServerListClient
lateinit var authRepository: FxaAuthRepository
override fun onCreate() {
super.onCreate()
CrashReporter.install(this)
CrashReporter.replayLastCrashIfAny(this)
NettyLoggingBridge.install()
installConscrypt()
UpstreamTrust.init(this)
tokenStore = TokenStore(this)
proxyStateStore = ProxyStateStore(this)
settingsStore = SettingsStore(this)
guardianClient = GuardianClient()
serverListClient = ServerListClient(this)
authRepository = FxaAuthRepository(tokenStore)
createNotificationChannel()
}
private fun installConscrypt() {
runCatching {
Security.insertProviderAt(Conscrypt.newProvider(), 1)
}.onFailure {
Log.w("FoxyVpnApp", "failed to install Conscrypt security provider", it)
}
}
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
val channel = NotificationChannel(
VPN_NOTIFICATION_CHANNEL_ID,
"VPN status",
NotificationManager.IMPORTANCE_LOW,
)
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
QuickConnectWidgetProvider.updateAll(this, FoxyVpnService.state.value)
}
companion object {
const val VPN_NOTIFICATION_CHANNEL_ID = "foxyvpn_status"
}
}