Merge branch 'v2.4' into q-beta
This commit is contained in:
10
README.md
10
README.md
@@ -126,6 +126,9 @@ Undocumented API list:
|
|||||||
* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringFailed()V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122392)
|
* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringFailed()V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122392)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringStarted()V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122393)
|
* (since API 24) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringStarted()V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122393)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122588)
|
* (since API 24) [`Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122588)
|
||||||
|
* [`Landroid/net/ConnectivityManager;->getTetherableBluetoothRegexs()[Ljava/lang/String;,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122608)
|
||||||
|
* [`Landroid/net/ConnectivityManager;->getTetherableUsbRegexs()[Ljava/lang/String;,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122610)
|
||||||
|
* [`Landroid/net/ConnectivityManager;->getTetherableWifiRegexs()[Ljava/lang/String;,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122611)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager;->startTethering(IZLandroid/net/ConnectivityManager$OnStartTetheringCallback;Landroid/os/Handler;)V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122683)
|
* (since API 24) [`Landroid/net/ConnectivityManager;->startTethering(IZLandroid/net/ConnectivityManager$OnStartTetheringCallback;Landroid/os/Handler;)V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122683)
|
||||||
* (since API 24) [`Landroid/net/ConnectivityManager;->stopTethering(I)V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122685)
|
* (since API 24) [`Landroid/net/ConnectivityManager;->stopTethering(I)V,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#122685)
|
||||||
* (since API 23) [`Landroid/net/wifi/WifiConfiguration;->apBand:I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#131003)
|
* (since API 23) [`Landroid/net/wifi/WifiConfiguration;->apBand:I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#131003)
|
||||||
@@ -141,13 +144,6 @@ Undocumented API list:
|
|||||||
* [`Landroid/net/wifi/p2p/WifiP2pManager;->startWps(Landroid/net/wifi/p2p/WifiP2pManager$Channel;Landroid/net/wifi/WpsInfo;Landroid/net/wifi/p2p/WifiP2pManager$ActionListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#134176)
|
* [`Landroid/net/wifi/p2p/WifiP2pManager;->startWps(Landroid/net/wifi/p2p/WifiP2pManager$Channel;Landroid/net/wifi/WpsInfo;Landroid/net/wifi/p2p/WifiP2pManager$ActionListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#134176)
|
||||||
* (prior to API Q) [`Ljava/net/InetAddress;->parseNumericAddress(Ljava/lang/String;)Ljava/net/InetAddress;,core-platform-api,greylist-max-p`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#332821)
|
* (prior to API Q) [`Ljava/net/InetAddress;->parseNumericAddress(Ljava/lang/String;)Ljava/net/InetAddress;,core-platform-api,greylist-max-p`](https://android.googlesource.com/platform/prebuilts/runtime/+/7cb2ccf/appcompat/hiddenapi-flags.csv#332821)
|
||||||
|
|
||||||
Undocumented system configurations:
|
|
||||||
|
|
||||||
* `@android:array/config_tether_usb_regexs`
|
|
||||||
* `@android:array/config_tether_wifi_regexs`
|
|
||||||
* `@android:array/config_tether_wimax_regexs`
|
|
||||||
* `@android:array/config_tether_bluetooth_regexs`
|
|
||||||
|
|
||||||
Other:
|
Other:
|
||||||
|
|
||||||
* (since API 29) `android.net.wifi.p2p.WifiP2pConfig` needs to be parcelized in a very specific order.
|
* (since API 29) `android.net.wifi.p2p.WifiP2pConfig` needs to be parcelized in a very specific order.
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ android {
|
|||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
resConfigs "ru", "zh-rCN"
|
resConfigs "ru", "zh-rCN"
|
||||||
versionCode 201
|
versionCode 202
|
||||||
versionName "2.4.1"
|
versionName "2.4.2"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
javaCompileOptions {
|
javaCompileOptions {
|
||||||
annotationProcessorOptions {
|
annotationProcessorOptions {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import be.mygod.vpnhotspot.util.broadcastReceiver
|
|||||||
|
|
||||||
@RequiresApi(24)
|
@RequiresApi(24)
|
||||||
abstract class TetherListeningTileService : KillableTileService() {
|
abstract class TetherListeningTileService : KillableTileService() {
|
||||||
protected var tethered: List<String> = emptyList()
|
protected var tethered: List<String>? = null
|
||||||
|
|
||||||
private val receiver = broadcastReceiver { _, intent ->
|
private val receiver = broadcastReceiver { _, intent ->
|
||||||
tethered = intent.tetheredIfaces ?: return@broadcastReceiver
|
tethered = intent.tetheredIfaces ?: return@broadcastReceiver
|
||||||
@@ -18,9 +18,9 @@ abstract class TetherListeningTileService : KillableTileService() {
|
|||||||
|
|
||||||
override fun onStartListening() {
|
override fun onStartListening() {
|
||||||
super.onStartListening()
|
super.onStartListening()
|
||||||
registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))?.tetheredIfaces?.let {
|
tethered = registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
||||||
tethered = it
|
?.tetheredIfaces
|
||||||
}
|
updateTile()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStopListening() {
|
override fun onStopListening() {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
protected abstract val labelString: Int
|
protected abstract val labelString: Int
|
||||||
protected abstract val tetherType: TetherType
|
protected abstract val tetherType: TetherType
|
||||||
protected open val icon get() = tetherType.icon
|
protected open val icon get() = tetherType.icon
|
||||||
protected val interested get() = tethered.filter { TetherType.ofInterface(it) == tetherType }
|
protected val interested get() = tethered?.filter { TetherType.ofInterface(it) == tetherType }
|
||||||
protected var binder: TetheringService.Binder? = null
|
protected var binder: TetheringService.Binder? = null
|
||||||
|
|
||||||
protected abstract fun start()
|
protected abstract fun start()
|
||||||
@@ -52,19 +52,27 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName?) {
|
override fun onServiceDisconnected(name: ComponentName?) {
|
||||||
|
binder?.routingsChanged?.remove(this)
|
||||||
binder = null
|
binder = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateTile() {
|
override fun updateTile() {
|
||||||
qsTile?.run {
|
qsTile?.run {
|
||||||
val interested = interested
|
val interested = interested
|
||||||
if (interested.isEmpty()) {
|
when {
|
||||||
state = Tile.STATE_INACTIVE
|
interested == null -> {
|
||||||
icon = tileOff
|
state = Tile.STATE_UNAVAILABLE
|
||||||
} else {
|
icon = tileOff
|
||||||
val binder = binder ?: return
|
}
|
||||||
state = Tile.STATE_ACTIVE
|
interested.isEmpty() -> {
|
||||||
icon = if (interested.all(binder::isActive)) tileOn else tileOff
|
state = Tile.STATE_INACTIVE
|
||||||
|
icon = tileOff
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val binder = binder ?: return
|
||||||
|
state = Tile.STATE_ACTIVE
|
||||||
|
icon = if (interested.all(binder::isActive)) tileOn else tileOff
|
||||||
|
}
|
||||||
}
|
}
|
||||||
label = getText(labelString)
|
label = getText(labelString)
|
||||||
updateTile()
|
updateTile()
|
||||||
@@ -88,7 +96,7 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun onClick() {
|
override fun onClick() {
|
||||||
val interested = interested
|
val interested = interested ?: return
|
||||||
if (interested.isEmpty()) safeInvoker { start() } else {
|
if (interested.isEmpty()) safeInvoker { start() } else {
|
||||||
val binder = binder
|
val binder = binder
|
||||||
if (binder == null) tapPending = true else {
|
if (binder == null) tapPending = true else {
|
||||||
@@ -146,11 +154,14 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
|
|
||||||
override fun updateTile() {
|
override fun updateTile() {
|
||||||
qsTile?.run {
|
qsTile?.run {
|
||||||
when (tethering?.active) {
|
val interested = interested
|
||||||
|
if (interested == null) {
|
||||||
|
state = Tile.STATE_UNAVAILABLE
|
||||||
|
icon = tileOff
|
||||||
|
} else when (tethering?.active) {
|
||||||
true -> {
|
true -> {
|
||||||
val binder = binder ?: return
|
val binder = binder ?: return
|
||||||
state = Tile.STATE_ACTIVE
|
state = Tile.STATE_ACTIVE
|
||||||
val interested = interested
|
|
||||||
icon = if (interested.isNotEmpty() && interested.all(binder::isActive)) tileOn else tileOff
|
icon = if (interested.isNotEmpty() && interested.all(binder::isActive)) tileOn else tileOff
|
||||||
}
|
}
|
||||||
false -> {
|
false -> {
|
||||||
@@ -164,18 +175,20 @@ sealed class TetheringTileService : TetherListeningTileService(), TetheringManag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick() = when (tethering?.active) {
|
override fun onClick() {
|
||||||
true -> {
|
when (tethering?.active) {
|
||||||
val binder = binder
|
true -> {
|
||||||
if (binder == null) tapPending = true else {
|
val binder = binder
|
||||||
val inactive = interested.filterNot(binder::isActive)
|
if (binder == null) tapPending = true else {
|
||||||
if (inactive.isEmpty()) safeInvoker { stop() }
|
val inactive = (interested ?: return).filterNot(binder::isActive)
|
||||||
else ContextCompat.startForegroundService(this, Intent(this, TetheringService::class.java)
|
if (inactive.isEmpty()) safeInvoker { stop() }
|
||||||
.putExtra(TetheringService.EXTRA_ADD_INTERFACES, inactive.toTypedArray()))
|
else ContextCompat.startForegroundService(this, Intent(this, TetheringService::class.java)
|
||||||
|
.putExtra(TetheringService.EXTRA_ADD_INTERFACES, inactive.toTypedArray()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
false -> safeInvoker { start() }
|
||||||
|
else -> tapPending = true
|
||||||
}
|
}
|
||||||
false -> safeInvoker { start() }
|
|
||||||
else -> tapPending = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +1,25 @@
|
|||||||
package be.mygod.vpnhotspot.net
|
package be.mygod.vpnhotspot.net
|
||||||
|
|
||||||
import android.content.res.Resources
|
import android.net.ConnectivityManager
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
enum class TetherType {
|
enum class TetherType(val icon: Int, val isWifi: Boolean = false) {
|
||||||
NONE, WIFI_P2P, USB, WIFI, WIMAX, BLUETOOTH;
|
NONE(R.drawable.ic_device_wifi_tethering),
|
||||||
|
WIFI_P2P(R.drawable.ic_action_settings_input_antenna, true),
|
||||||
val icon get() = when (this) {
|
USB(R.drawable.ic_device_usb),
|
||||||
USB -> R.drawable.ic_device_usb
|
WIFI(R.drawable.ic_device_network_wifi, true),
|
||||||
WIFI_P2P -> R.drawable.ic_action_settings_input_antenna
|
BLUETOOTH(R.drawable.ic_device_bluetooth);
|
||||||
WIFI, WIMAX -> R.drawable.ic_device_network_wifi
|
|
||||||
BLUETOOTH -> R.drawable.ic_device_bluetooth
|
|
||||||
else -> R.drawable.ic_device_wifi_tethering
|
|
||||||
}
|
|
||||||
val isWifi get() = when (this) {
|
|
||||||
WIFI_P2P, WIFI, WIMAX -> true
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val usbRegexs: List<Pattern>
|
private fun getRegexs(type: String) =
|
||||||
private val wifiRegexs: List<Pattern>
|
(ConnectivityManager::class.java.getDeclaredMethod("getTetherable${type}Regexs")
|
||||||
private val wimaxRegexs: List<Pattern>
|
.invoke(app.connectivity) as Array<String?>)
|
||||||
private val bluetoothRegexs: List<Pattern>
|
.filterNotNull()
|
||||||
|
.map { it.toPattern() }
|
||||||
/**
|
private val usbRegexs = getRegexs("Usb")
|
||||||
* Source: https://android.googlesource.com/platform/frameworks/base/+/61fa313/core/res/res/values/config.xml#328
|
private val wifiRegexs = getRegexs("Wifi")
|
||||||
*/
|
private val bluetoothRegexs = getRegexs("Bluetooth")
|
||||||
init {
|
|
||||||
val appRes = app.resources
|
|
||||||
val sysRes = Resources.getSystem()
|
|
||||||
usbRegexs = appRes.getStringArray(sysRes
|
|
||||||
.getIdentifier("config_tether_usb_regexs", "array", "android"))
|
|
||||||
.filterNotNull()
|
|
||||||
.map { it.toPattern() }
|
|
||||||
wifiRegexs = appRes.getStringArray(sysRes
|
|
||||||
.getIdentifier("config_tether_wifi_regexs", "array", "android"))
|
|
||||||
.filterNotNull()
|
|
||||||
.map { it.toPattern() }
|
|
||||||
wimaxRegexs = appRes.getStringArray(sysRes
|
|
||||||
.getIdentifier("config_tether_wimax_regexs", "array", "android"))
|
|
||||||
.filterNotNull()
|
|
||||||
.map { it.toPattern() }
|
|
||||||
bluetoothRegexs = appRes.getStringArray(sysRes
|
|
||||||
.getIdentifier("config_tether_bluetooth_regexs", "array", "android"))
|
|
||||||
.filterNotNull()
|
|
||||||
.map { it.toPattern() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Based on: https://android.googlesource.com/platform/frameworks/base/+/0e3d092/services/core/java/com/android/server/connectivity/Tethering.java#311
|
* Based on: https://android.googlesource.com/platform/frameworks/base/+/0e3d092/services/core/java/com/android/server/connectivity/Tethering.java#311
|
||||||
@@ -59,7 +30,6 @@ enum class TetherType {
|
|||||||
wifiRegexs.any { it.matcher(iface).matches() } -> WIFI
|
wifiRegexs.any { it.matcher(iface).matches() } -> WIFI
|
||||||
usbRegexs.any { it.matcher(iface).matches() } -> USB
|
usbRegexs.any { it.matcher(iface).matches() } -> USB
|
||||||
bluetoothRegexs.any { it.matcher(iface).matches() } -> BLUETOOTH
|
bluetoothRegexs.any { it.matcher(iface).matches() } -> BLUETOOTH
|
||||||
wimaxRegexs.any { it.matcher(iface).matches() } -> WIMAX
|
|
||||||
else -> NONE
|
else -> NONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user