Add BLUETOOTH_PRIVILEGED permission

Required for reading bluetooth tethering state since May, 2020 security patch.

Related: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1253150
This commit is contained in:
Mygod
2020-05-23 07:03:36 +08:00
parent 6f94e31f51
commit 5a7ecb3245
2 changed files with 9 additions and 2 deletions

View File

@@ -26,6 +26,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

View File

@@ -9,6 +9,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.core.os.BuildCompat
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.net.TetheringManager
import be.mygod.vpnhotspot.util.broadcastReceiver
@@ -88,8 +89,12 @@ class BluetoothTethering(context: Context, val stateListener: (Int) -> Unit) :
*/
val active: Boolean? get() {
val pan = pan ?: return null
return BluetoothAdapter.getDefaultAdapter()?.state == BluetoothAdapter.STATE_ON &&
isTetheringOn.invoke(pan) as Boolean
return BluetoothAdapter.getDefaultAdapter()?.state == BluetoothAdapter.STATE_ON && try {
isTetheringOn.invoke(pan) as Boolean
} catch (e: InvocationTargetException) {
if (e.cause is SecurityException && BuildCompat.isAtLeastR()) Timber.d(e) else Timber.w(e)
return null
}
}
private val receiver = broadcastReceiver { _, intent -> stateListener(intent.bluetoothState) }