add cross device stuff (screenshots) in readme

This commit is contained in:
Kavish Devar
2025-01-31 03:37:02 +05:30
parent de53e840ed
commit c7ef31cba6
9 changed files with 80 additions and 42 deletions

View File

@@ -797,6 +797,8 @@ class AirPodsService : Service() {
Log.d("AirPodsService", "Taking over audio")
CrossDevice.sendRemotePacket(CrossDevicePackets.REQUEST_DISCONNECT.packet)
Log.d("AirPodsService", macAddress)
CrossDevice.isAvailable = false
sharedPreferences.edit { putBoolean("CrossDeviceIsAvailable", false) }
device = getSystemService<BluetoothManager>(BluetoothManager::class.java).adapter.bondedDevices.find {
it.address == macAddress
}
@@ -823,9 +825,7 @@ class AirPodsService : Service() {
0x1001,
uuid
) as BluetoothSocket
} catch (
e: Exception
) {
} catch (e: Exception) {
e.printStackTrace()
try {
socket = HiddenApiBypass.newInstance(
@@ -838,9 +838,7 @@ class AirPodsService : Service() {
0x1001,
uuid
) as BluetoothSocket
} catch (
e: Exception
) {
} catch (e: Exception) {
e.printStackTrace()
}
}
@@ -850,10 +848,6 @@ class AirPodsService : Service() {
this@AirPodsService.device = device
isConnectedLocally = true
socket.let { it ->
// sometimes doesn't work ;-;
// i though i move it to the coroutine
// but, the socket sometimes disconnects if i don't send a packet outside of the routine first
// so, sending *again*, with a delay, in the coroutine
it.outputStream.write(Enums.HANDSHAKE.value)
it.outputStream.flush()
it.outputStream.write(Enums.SET_SPECIFIC_FEATURES.value)
@@ -861,7 +855,6 @@ class AirPodsService : Service() {
it.outputStream.write(Enums.REQUEST_NOTIFICATIONS.value)
it.outputStream.flush()
CoroutineScope(Dispatchers.IO).launch {
// this is so stupid, why does it disconnect if i don't send a packet outside of the coroutine first
it.outputStream.write(Enums.HANDSHAKE.value)
it.outputStream.flush()
delay(200)
@@ -871,7 +864,6 @@ class AirPodsService : Service() {
it.outputStream.write(Enums.REQUEST_NOTIFICATIONS.value)
it.outputStream.flush()
delay(200)
// just in case this doesn't work, send all three after 5 seconds again
Handler(Looper.getMainLooper()).postDelayed({
it.outputStream.write(Enums.HANDSHAKE.value)
it.outputStream.flush()
@@ -898,6 +890,11 @@ class AirPodsService : Service() {
val bytes = buffer.copyOfRange(0, bytesRead)
val formattedHex = bytes.joinToString(" ") { "%02X".format(it) }
CrossDevice.sendReceivedPacket(bytes)
updateNotificationContent(
true,
sharedPreferences.getString("name", device.name),
batteryNotification.getBattery()
)
Log.d("AirPods Data", "Data received: $formattedHex")
} else if (bytesRead == -1) {
Log.d("AirPods Service", "Socket closed (bytesRead = -1)")

View File

@@ -84,6 +84,7 @@ object CrossDevice {
@SuppressLint("MissingPermission")
private fun startServer() {
CoroutineScope(Dispatchers.IO).launch {
if (!bluetoothAdapter.isEnabled) return@launch
serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord("ALNCrossDevice", uuid)
Log.d("CrossDevice", "Server started")
while (serverSocket != null) {
@@ -237,4 +238,4 @@ object CrossDevice {
logPacket(byteArray, "Sent")
Log.d("CrossDevice", "Sent packet to remote device")
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.