mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-03-11 08:42:59 +00:00
fix typo in rename packet in definitions.md
This commit is contained in:
@@ -162,7 +162,7 @@ The airpods will respond with the same packet after the mode has been changed.
|
|||||||
We can send a packet to rename the AirPods. The packet format is as follows:
|
We can send a packet to rename the AirPods. The packet format is as follows:
|
||||||
|
|
||||||
```plaintext
|
```plaintext
|
||||||
04 00 04 00 1A 01 [size] 00 [name]
|
04 00 04 00 1A 00 01 [size] 00 [name]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Toggle case charging sounds
|
## Toggle case charging sounds
|
||||||
@@ -326,4 +326,4 @@ Example packet
|
|||||||
|
|
||||||
```plaintext
|
```plaintext
|
||||||
04 00 04 00 17 00 00 00 10 00 11 00 08 7E 10 02 42 0B 08 4E 10 02 1A 05 01 00 00 00 00
|
04 00 04 00 17 00 00 00 10 00 11 00 08 7E 10 02 42 0B 08 4E 10 02 1A 05 01 00 00 00 00
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package me.kavishdevar.aln
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.bluetooth.BluetoothAdapter
|
||||||
|
import android.bluetooth.BluetoothDevice
|
||||||
|
import android.bluetooth.BluetoothProfile
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.ParcelUuid
|
||||||
|
|
||||||
|
class StartupReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val PodsUUIDS: Set<ParcelUuid> = setOf(
|
||||||
|
ParcelUuid.fromString("74ec2172-0bad-4d01-8f77-997b2be0722a"),
|
||||||
|
ParcelUuid.fromString("2a72e02b-7b99-778f-014d-ad0b7221ec74")
|
||||||
|
)
|
||||||
|
|
||||||
|
val btActions: Set<String> = setOf(
|
||||||
|
BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED,
|
||||||
|
BluetoothDevice.ACTION_ACL_CONNECTED,
|
||||||
|
BluetoothDevice.ACTION_ACL_DISCONNECTED,
|
||||||
|
BluetoothDevice.ACTION_BOND_STATE_CHANGED,
|
||||||
|
BluetoothDevice.ACTION_NAME_CHANGED
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
if (intent == null || context == null) return
|
||||||
|
|
||||||
|
intent.action?.let { action ->
|
||||||
|
if (btActions.contains(action)) {
|
||||||
|
try {
|
||||||
|
val state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, BluetoothAdapter.ERROR)
|
||||||
|
val device: BluetoothDevice? = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
|
||||||
|
device?.let {
|
||||||
|
btProfileChanges(context, state, it)
|
||||||
|
}
|
||||||
|
} catch (e: NullPointerException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
private fun isPods(device: BluetoothDevice): Boolean {
|
||||||
|
device.uuids?.forEach { uuid ->
|
||||||
|
if (PodsUUIDS.contains(uuid)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startPodsService(context: Context, device: BluetoothDevice) {
|
||||||
|
if (!isPods(device)) return
|
||||||
|
val intent = Intent(context, AirPodsService::class.java).apply {
|
||||||
|
putExtra(BluetoothDevice.EXTRA_DEVICE, device)
|
||||||
|
}
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopPodsService(context: Context) {
|
||||||
|
context.stopService(Intent(context, AirPodsService::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun btProfileChanges(context: Context, state: Int, device: BluetoothDevice) {
|
||||||
|
when (state) {
|
||||||
|
BluetoothProfile.STATE_CONNECTED -> startPodsService(context, device)
|
||||||
|
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_DISCONNECTING -> stopPodsService(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user