mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06: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 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()
|
||||||
schemaInput.showSoftInputOnFocus = false
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
schemaInput.showSoftInputOnFocus = false
|
||||||
|
}
|
||||||
schemaInput.setOnFocusChangeListener { v, _ ->
|
schemaInput.setOnFocusChangeListener { v, _ ->
|
||||||
if(schemaInput.isFocused) {
|
if(schemaInput.isFocused) {
|
||||||
onClickSchemaList(v)
|
onClickSchemaList(v)
|
||||||
|
@ -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) {
|
||||||
.addAddress(address!!, 7)
|
Builder()
|
||||||
.allowFamily(OsConstants.AF_INET)
|
.addAddress(address!!, 7)
|
||||||
.allowBypass()
|
.allowFamily(OsConstants.AF_INET)
|
||||||
.setMtu(MAX_PACKET_SIZE)
|
.allowBypass()
|
||||||
|
.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,14 +271,17 @@ 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
|
||||||
val networks = cm.allNetworks
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
for (network in networks) {
|
val networks = cm.allNetworks
|
||||||
val linkProperties = cm.getLinkProperties(network)
|
|
||||||
if(linkProperties!=null) {
|
for (network in networks) {
|
||||||
val routes = linkProperties.routes
|
val linkProperties = cm.getLinkProperties(network)
|
||||||
for (route in routes) {
|
if(linkProperties!=null) {
|
||||||
if (route.isDefaultRoute && route.gateway is Inet6Address) {
|
val routes = linkProperties.routes
|
||||||
return true
|
for (route in routes) {
|
||||||
|
if (route.isDefaultRoute && route.gateway is Inet6Address) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,27 +289,29 @@ class YggdrasilTunService : VpnService() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun foregroundNotification(text: String): Notification? {
|
private fun foregroundNotification(FOREGROUND_ID: Int, text: String) {
|
||||||
val channelId =
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
val channelId =
|
||||||
createNotificationChannel(TAG, "Yggdrasil service")
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
} else {
|
createNotificationChannel(TAG, "Yggdrasil service")
|
||||||
// If earlier version channel ID is not used
|
} else {
|
||||||
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
// If earlier version channel ID is not used
|
||||||
""
|
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
||||||
}
|
""
|
||||||
var intent = Intent(this, MainActivity::class.java)
|
}
|
||||||
var stackBuilder = TaskStackBuilder.create(this)
|
var intent = Intent(this, MainActivity::class.java)
|
||||||
stackBuilder.addNextIntentWithParentStack(intent)
|
var stackBuilder = TaskStackBuilder.create(this)
|
||||||
var pi = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
|
stackBuilder.addNextIntentWithParentStack(intent)
|
||||||
val b = NotificationCompat.Builder(this, channelId)
|
var pi = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
b.setOngoing(true)
|
val b = NotificationCompat.Builder(this, channelId)
|
||||||
.setContentIntent(pi)
|
b.setOngoing(true)
|
||||||
.setContentTitle(getString(R.string.app_name))
|
.setContentIntent(pi)
|
||||||
.setContentText(text)
|
.setContentTitle(getString(R.string.app_name))
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setContentText(text)
|
||||||
.setTicker(text)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
return b.build()
|
.setTicker(text)
|
||||||
|
startForeground(FOREGROUND_ID, b.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user