Platform Compatibility

Android 17 (API 37) Compatibility

Important

Starting from V1.15.0, the compileSdk of JL_Watch / jl_rcsp / jl_bluetooth_connect is upgraded to 37 (Android 17), and the Java compilation version is upgraded to 11.
The integrator’s compileSdk must not be lower than the SDK’s compileSdk, and it is recommended to set sourceCompatibility / targetCompatibility to VERSION_11.

Handling of SPP read returning -1

Starting from Android 17 (targetSdk 37), RFCOMM InputStream.read() returns -1 when the connection is disconnected, instead of throwing an exception.

Old code usually handles it like this:

int len = inputStream.read(buffer);
if (len <= 0) { //No data read, delay processing
    Thread.sleep(30);
    continue;
}

On Android 17, -1 enters the continue branch, causing the thread to spin forever and fail to exit.

The SDK has been fixed as follows:

int len = inputStream.read(buffer);
if (len < 0) { //Read exception, exit
    exitReason = EXIT_REASON_IO_EXCEPTION;
    break;
}
if (len == 0) { //No data read, delay processing
    Thread.sleep(30);
    continue;
}

Warning

If the application implements its own SPP data reading thread, update the judgment logic for the read() return value accordingly; otherwise, on Android 17 the SPP thread may fail to exit and fail to reconnect.

SPP Abnormal Disconnection Handling

Android 17 manages Bluetooth connection states more strictly. An SPP connection may become invalid without receiving a normal disconnection callback.

The SDK adds handling for abnormal SPP disconnection:

  1. When the data reading thread exits, report the connection state based on the exit reason

  2. On IO exception, report CONNECTION_DISCONNECT directly to avoid continuing to use an invalid connection

  3. When active disconnection fails, also report the disconnected state so that upper-layer services can be notified

Note

After the device is disconnected, destroy the corresponding function objects in time and reinitialize after reconnecting.

System Automatic Re-pairing

Android 17 introduces system automatic re-pairing: when the bond is lost, the system can automatically rebuild the bond in the background, without the user needing to unpair and re-pair in system settings.

Related broadcasts:

  • ACTION_PAIRING_REQUEST and ACTION_BOND_STATE_CHANGED carry EXTRA_PAIRING_CONTEXT

  • PAIRING_CONTEXT_REPAIRING indicates system automatic re-pairing

  • Starting from Android 17, ACTION_KEY_MISSING is broadcast only when automatic re-pairing fails

The SDK handles the above broadcasts as follows:

  1. Read EXTRA_PAIRING_CONTEXT only on Android 17 and above to avoid default values on lower versions

  2. During system automatic re-pairing, increase the log level for easier troubleshooting

  3. Distinguish the semantics of ACTION_KEY_MISSING before and after Android 17 to avoid misjudgment

Note

After successful system automatic re-pairing, ACTION_KEY_MISSING is not broadcast, so the absence of this event in logs does not mean that bond loss did not occur.

Other Notes

Change

Description

Suggestion

Background audio

Background playback/volume APIs may fail silently

Use a foreground service for background playback

App memory

App memory is limited by device memory

Release audio/video buffers in time

Implicit URI

Enforced in Android 18; StrictMode can detect in Android 17

Adapt sharing/camera flows early

Certificate transparency (CT)

Enabled by default

Ensure HTTPS domains are in CT logs

Note

The above are general application-level impacts of Android 17. The SDK has completed Bluetooth-related compatibility handling, but the application layer still needs to adapt according to its own services.