Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.appwidget.AppWidgetManager
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothHeadset
import android.bluetooth.BluetoothManager
Expand Down Expand Up @@ -2353,8 +2354,12 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
}

private fun createBluetoothSocket(device: BluetoothDevice, uuid: ParcelUuid): BluetoothSocket {
val type = 3 // L2CAP
val type = BluetoothSocket.TYPE_L2CAP
val adapter = HiddenApiBypass.getInstanceFields(device.javaClass)
.firstOrNull { it.name == "mAdapter" }
?.run { isAccessible = true; get(device) as BluetoothAdapter }
val constructorSpecs = listOf(
arrayOf(adapter, device, type, true, true, 0x1001, uuid),
arrayOf(device, type, true, true, 0x1001, uuid),
arrayOf(device, type, 1, true, true, 0x1001, uuid),
arrayOf(type, 1, true, true, device, 0x1001, uuid),
Expand Down Expand Up @@ -2392,7 +2397,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
@SuppressLint("MissingPermission", "UnspecifiedRegisterReceiverFlag")
fun connectToSocket(device: BluetoothDevice, manual: Boolean = false) {
Log.d(TAG, "<LogCollector:Start> Connecting to socket")
HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;")
HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;", "Landroid/bluetooth/BluetoothDevice;")
val uuid: ParcelUuid = ParcelUuid.fromString("74ec2172-0bad-4d01-8f77-997b2be0722a")
if (!isConnectedLocally) {
socket = try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package me.kavishdevar.librepods.utils

import android.annotation.SuppressLint
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothSocket
import android.os.ParcelUuid
Expand Down Expand Up @@ -69,7 +70,7 @@ class ATTManager(private val device: BluetoothDevice) {

@SuppressLint("MissingPermission")
fun connect() {
HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;")
HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;", "Landroid/bluetooth/BluetoothDevice;")
val uuid = ParcelUuid.fromString("00000000-0000-0000-0000-000000000000")

socket = createBluetoothSocket(device, uuid)
Expand Down Expand Up @@ -196,8 +197,12 @@ class ATTManager(private val device: BluetoothDevice) {
}

private fun createBluetoothSocket(device: BluetoothDevice, uuid: ParcelUuid): BluetoothSocket {
val type = 3 // L2CAP
val type = BluetoothSocket.TYPE_L2CAP
val adapter = HiddenApiBypass.getInstanceFields(device.javaClass)
.firstOrNull { it.name == "mAdapter" }
?.run { isAccessible = true; get(device) as BluetoothAdapter }
val constructorSpecs = listOf(
arrayOf(adapter, device, type, true, true, 31, uuid),
arrayOf(device, type, true, true, 31, uuid),
arrayOf(device, type, 1, true, true, 31, uuid),
arrayOf(type, 1, true, true, device, 31, uuid),
Expand Down