mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 07:56:30 +00:00
1. API 15 support (Android 4.0.3)
This commit is contained in:
parent
707f332b10
commit
4b8c9235b4
@ -140,7 +140,9 @@ class PeerListActivity : AppCompatActivity() {
|
||||
var schemaInput = view.findViewById<TextView>(R.id.schemaInput)
|
||||
var ipInput = view.findViewById<TextView>(R.id.ipInput)
|
||||
ipInput.requestFocus()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
schemaInput.showSoftInputOnFocus = false
|
||||
}
|
||||
schemaInput.setOnFocusChangeListener { v, _ ->
|
||||
if(schemaInput.isFocused) {
|
||||
onClickSchemaList(v)
|
||||
|
@ -59,7 +59,7 @@ class YggdrasilTunService : VpnService() {
|
||||
when(intent?.getStringExtra(MainActivity.COMMAND)){
|
||||
MainActivity.STOP ->{
|
||||
stopVpn(pi)
|
||||
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service stopped"))
|
||||
foregroundNotification(FOREGROUND_ID, "Yggdrasil service stopped")
|
||||
}
|
||||
MainActivity.START ->{
|
||||
val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS))
|
||||
@ -67,7 +67,7 @@ class YggdrasilTunService : VpnService() {
|
||||
val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false)
|
||||
ygg = Yggdrasil()
|
||||
setupTunInterface(pi, peers, dns, staticIP)
|
||||
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service started"))
|
||||
foregroundNotification(FOREGROUND_ID, "Yggdrasil service started")
|
||||
}
|
||||
MainActivity.UPDATE_DNS ->{
|
||||
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS))
|
||||
@ -84,11 +84,17 @@ class YggdrasilTunService : VpnService() {
|
||||
private fun setupIOStreams(dns: MutableSet<DNSInfo>){
|
||||
address = ygg.addressString
|
||||
|
||||
var builder = Builder()
|
||||
var builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Builder()
|
||||
.addAddress(address!!, 7)
|
||||
.allowFamily(OsConstants.AF_INET)
|
||||
.allowBypass()
|
||||
.setMtu(MAX_PACKET_SIZE)
|
||||
} else {
|
||||
Builder()
|
||||
.addAddress(address!!, 7)
|
||||
.setMtu(MAX_PACKET_SIZE)
|
||||
}
|
||||
if (dns.size > 0) {
|
||||
for (d in dns) {
|
||||
builder.addDnsServer(d.address)
|
||||
@ -265,7 +271,9 @@ class YggdrasilTunService : VpnService() {
|
||||
private fun hasIpv6DefaultRoute(): Boolean {
|
||||
val cm =
|
||||
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
val networks = cm.allNetworks
|
||||
|
||||
for (network in networks) {
|
||||
val linkProperties = cm.getLinkProperties(network)
|
||||
if(linkProperties!=null) {
|
||||
@ -277,10 +285,12 @@ class YggdrasilTunService : VpnService() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun foregroundNotification(text: String): Notification? {
|
||||
private fun foregroundNotification(FOREGROUND_ID: Int, text: String) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
val channelId =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createNotificationChannel(TAG, "Yggdrasil service")
|
||||
@ -300,7 +310,8 @@ class YggdrasilTunService : VpnService() {
|
||||
.setContentText(text)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setTicker(text)
|
||||
return b.build()
|
||||
startForeground(FOREGROUND_ID, b.build())
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
|
Loading…
x
Reference in New Issue
Block a user