forked from httptoolkit/httptoolkit-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionStatusView.kt
More file actions
108 lines (96 loc) · 4.1 KB
/
ConnectionStatusView.kt
File metadata and controls
108 lines (96 loc) · 4.1 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package tech.httptoolkit.android
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.TextView
import com.google.android.material.card.MaterialCardView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import androidx.core.net.toUri
private val isLineageOs = Build.HOST.startsWith("lineage")
class ConnectionStatusView(
context: Context,
proxyConfig: ProxyConfig,
totalAppCount: Int,
interceptedAppCount: Int,
changeApps: () -> Unit,
interceptedPorts: Set<Int>,
changePorts: () -> Unit
) : LinearLayout(context) {
init {
val layout = when (whereIsCertTrusted(proxyConfig)) {
"user" ->
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
R.layout.connection_status_pre_v7
else
R.layout.connection_status_user
"system" -> R.layout.connection_status_system
else -> R.layout.connection_status_none
}
LayoutInflater.from(context).inflate(layout, this, true)
if (layout == R.layout.connection_status_user) {
// Make inline links clickable:
val statusText = findViewById<TextView>(R.id.connectionStatusText)
if (statusText != null) statusText.movementMethod = LinkMovementMethod.getInstance()
}
val connectedToText = findViewById<TextView>(R.id.connectedTo)
connectedToText.text = if (proxyConfig.ip == "127.0.0.1") {
context.getString(R.string.connected_tunnel_details)
} else {
context.getString(
R.string.connected_details,
proxyConfig.ip,
proxyConfig.port
)
}
val appInterceptionStatus = findViewById<MaterialCardView>(R.id.interceptedAppsButton)
appInterceptionStatus.setOnClickListener { _ ->
if (!isLineageOs) {
changeApps()
} else {
MaterialAlertDialogBuilder(context)
.setTitle("Not available")
.setIcon(R.drawable.ic_exclamation_triangle)
.setMessage(
"""
Per-app filtering is not possible on LineageOS, due to a bug in Lineage's VPN implementation.
If you'd like this fixed, please upvote the bug in their issue tracker.
""".trimIndent()
)
.setNegativeButton("Cancel") { _, _ -> }
.setPositiveButton("View the bug") { _, _ ->
context.startActivity(Intent(
Intent.ACTION_VIEW,
"https://gitlab.com/LineageOS/issues/android/-/issues/1706".toUri()
))
}
.show()
}
}
val appInterceptionStatusText = findViewById<TextView>(R.id.interceptedAppsStatus)
appInterceptionStatusText.text = context.getString(
when {
totalAppCount == interceptedAppCount -> R.string.all_apps
interceptedAppCount > 10 -> R.string.selected_apps
else -> R.string.few_apps
},
interceptedAppCount,
if (interceptedAppCount != 1) "s" else ""
)
val portInterceptionStatus = findViewById<MaterialCardView>(R.id.interceptedPortsButton)
portInterceptionStatus.setOnClickListener { _ -> changePorts() }
val portInterceptionStatusText = findViewById<TextView>(R.id.interceptedPortsStatus)
portInterceptionStatusText.text = context.getString(
when {
(interceptedPorts == DEFAULT_PORTS) -> R.string.default_ports
interceptedPorts.size > 10 -> R.string.selected_ports
else -> R.string.few_ports
},
interceptedPorts.size,
if (interceptedPorts.size != 1) "s" else ""
)
}
}