1. API 15 support (Android 4.0.3)

This commit is contained in:
vadym 2020-08-03 06:57:10 -07:00
parent 707f332b10
commit 4b8c9235b4
2 changed files with 50 additions and 37 deletions

View File

@ -140,7 +140,9 @@ class PeerListActivity : AppCompatActivity() {
var schemaInput = view.findViewById<TextView>(R.id.schemaInput) var schemaInput = view.findViewById<TextView>(R.id.schemaInput)
var ipInput = view.findViewById<TextView>(R.id.ipInput) var ipInput = view.findViewById<TextView>(R.id.ipInput)
ipInput.requestFocus() ipInput.requestFocus()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
schemaInput.showSoftInputOnFocus = false schemaInput.showSoftInputOnFocus = false
}
schemaInput.setOnFocusChangeListener { v, _ -> schemaInput.setOnFocusChangeListener { v, _ ->
if(schemaInput.isFocused) { if(schemaInput.isFocused) {
onClickSchemaList(v) onClickSchemaList(v)

View File

@ -59,7 +59,7 @@ class YggdrasilTunService : VpnService() {
when(intent?.getStringExtra(MainActivity.COMMAND)){ when(intent?.getStringExtra(MainActivity.COMMAND)){
MainActivity.STOP ->{ MainActivity.STOP ->{
stopVpn(pi) stopVpn(pi)
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service stopped")) foregroundNotification(FOREGROUND_ID, "Yggdrasil service stopped")
} }
MainActivity.START ->{ MainActivity.START ->{
val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS)) val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS))
@ -67,7 +67,7 @@ class YggdrasilTunService : VpnService() {
val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false) val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false)
ygg = Yggdrasil() ygg = Yggdrasil()
setupTunInterface(pi, peers, dns, staticIP) setupTunInterface(pi, peers, dns, staticIP)
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service started")) foregroundNotification(FOREGROUND_ID, "Yggdrasil service started")
} }
MainActivity.UPDATE_DNS ->{ MainActivity.UPDATE_DNS ->{
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS)) val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS))
@ -84,11 +84,17 @@ class YggdrasilTunService : VpnService() {
private fun setupIOStreams(dns: MutableSet<DNSInfo>){ private fun setupIOStreams(dns: MutableSet<DNSInfo>){
address = ygg.addressString address = ygg.addressString
var builder = Builder() var builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Builder()
.addAddress(address!!, 7) .addAddress(address!!, 7)
.allowFamily(OsConstants.AF_INET) .allowFamily(OsConstants.AF_INET)
.allowBypass() .allowBypass()
.setMtu(MAX_PACKET_SIZE) .setMtu(MAX_PACKET_SIZE)
} else {
Builder()
.addAddress(address!!, 7)
.setMtu(MAX_PACKET_SIZE)
}
if (dns.size > 0) { if (dns.size > 0) {
for (d in dns) { for (d in dns) {
builder.addDnsServer(d.address) builder.addDnsServer(d.address)
@ -265,7 +271,9 @@ class YggdrasilTunService : VpnService() {
private fun hasIpv6DefaultRoute(): Boolean { private fun hasIpv6DefaultRoute(): Boolean {
val cm = val cm =
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val networks = cm.allNetworks val networks = cm.allNetworks
for (network in networks) { for (network in networks) {
val linkProperties = cm.getLinkProperties(network) val linkProperties = cm.getLinkProperties(network)
if(linkProperties!=null) { if(linkProperties!=null) {
@ -277,10 +285,12 @@ class YggdrasilTunService : VpnService() {
} }
} }
} }
}
return false 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 = val channelId =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(TAG, "Yggdrasil service") createNotificationChannel(TAG, "Yggdrasil service")
@ -300,7 +310,8 @@ class YggdrasilTunService : VpnService() {
.setContentText(text) .setContentText(text)
.setSmallIcon(R.mipmap.ic_launcher) .setSmallIcon(R.mipmap.ic_launcher)
.setTicker(text) .setTicker(text)
return b.build() startForeground(FOREGROUND_ID, b.build())
}
} }
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)