# Keep rules for the BLE stack.
#
# Every class below is reached only from Rust, over JNI, by name. R8 sees no
# reference to any of it and would strip or rename the lot — and the failure is
# invisible until the first scan on a *release* build, where btleplug's
# `platform::init` throws ClassNotFound and the app finds no trainer. Debug
# builds are unminified, so this cannot be caught by testing locally.

# btleplug's Android backend. `register_native_methods` binds by exact method
# name and signature, and the exception classes are looked up so the Rust side
# can map them onto btleplug::Error.
-keep class com.nonpolynomial.btleplug.** { *; }

# jni-utils: the Future/Stream/Waker plumbing btleplug's Java calls back into.
-keep class io.github.gedgygedgy.rust.** { *; }

# The Rust side calls these on the Android framework classes it is handed.
-keepclassmembers class * extends android.bluetooth.BluetoothGattCallback { *; }
-keepclassmembers class * extends android.bluetooth.le.ScanCallback { *; }

# Our own JNI entry points, called from MainActivity as `external fun`.
-keepclasseswithmembernames class paris.tourolle.bikecontrol.MainActivity {
    native <methods>;
}

# The one call that goes the other way. Rust resolves it by name and signature
# at runtime, so R8 renaming it would leave the "turn Bluetooth on" button doing
# nothing in release builds and working perfectly in debug ones.
-keepclassmembers class paris.tourolle.bikecontrol.MainActivity {
    public void requestBluetoothEnable();
}
