Skip to content

Commit

Permalink
re-enable with extra permission
Browse files Browse the repository at this point in the history
  • Loading branch information
eycorsican committed Jan 2, 2019
1 parent a63cc15 commit 785bf16
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
package="fun.kitsunebi.kitsunebi4android">

<uses-permission android:name="android.permission.INTERNET"/>
<!--<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />-->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ open class KitsunebiVpnService: VpnService() {
private var buffer = ByteBuffer.allocate(1501)
var isStopped = false

// private val cm by lazy { this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }
//
// @TargetApi(28)
// private var underlyingNetwork: Network? = null
// @TargetApi(28)
// set(value) {
// setUnderlyingNetworks(if (value == null) null else arrayOf(value))
// field = value
// }
//
// companion object {
// @TargetApi(28)
// private val defaultNetworkRequest = NetworkRequest.Builder()
// .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
// .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
// .build()
// }
//
// @TargetApi(28)
// private val defaultNetworkCallback = object : ConnectivityManager.NetworkCallback() {
// override fun onAvailable(network: Network) {
// underlyingNetwork = network
// }
// override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities?) {
// underlyingNetwork = network
// }
// override fun onLost(network: Network) {
// underlyingNetwork = null
// }
// }
private val cm by lazy { this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }

@TargetApi(28)
private var underlyingNetwork: Network? = null
@TargetApi(28)
set(value) {
setUnderlyingNetworks(if (value == null) null else arrayOf(value))
field = value
}

companion object {
@TargetApi(28)
private val defaultNetworkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
.build()
}

@TargetApi(28)
private val defaultNetworkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
underlyingNetwork = network
}
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities?) {
underlyingNetwork = network
}
override fun onLost(network: Network) {
underlyingNetwork = null
}
}

data class Config(val outbounds: List<Outbound>? = null,
val outboundDetour: List<Outbound>? = null,
Expand Down Expand Up @@ -112,7 +112,7 @@ open class KitsunebiVpnService: VpnService() {
n?.let { it } ?: return
if (n > 0) {
buffer.limit(n)
tun2socks.Tun2socks.inputPacket(buffer.array())
Tun2socks.inputPacket(buffer.array())
buffer.clear()
}
}
Expand Down Expand Up @@ -169,9 +169,9 @@ open class KitsunebiVpnService: VpnService() {
return@thread
}

// if (Build.VERSION.SDK_INT >= 28) {
// cm.requestNetwork(defaultNetworkRequest, defaultNetworkCallback)
// }
if (Build.VERSION.SDK_INT >= 28) {
cm.requestNetwork(defaultNetworkRequest, defaultNetworkCallback)
}

inputStream = FileInputStream(pfd!!.fileDescriptor)
outputStream = FileOutputStream(pfd!!.fileDescriptor)
Expand Down

0 comments on commit 785bf16

Please sign in to comment.