Skip to content

ANR (Application Not Responding) error #5

Open
@shepeliev

Description

@shepeliev

We are using the BlueParrot Android SDK in one of our projects and recently encountered multiple ANR (Application Not Responding) reports related to the SDK’s code:

Screenshot 2024-12-14 at 10 50 45

Unfortunately, the lib code is obfuscated, but I can see the potential problem. Here is a decompiled code fragment:

    private void a(int var1) {
        long var2 = System.currentTimeMillis();
        boolean var4 = false;

        while(!var4 && System.currentTimeMillis() - var2 < 8000L) {
            BluetoothAdapter var5;
            if ((var5 = BluetoothAdapter.getDefaultAdapter()) != null) {
                if (2 == var5.getProfileConnectionState(1)) {
                    var4 = true;
                } else {
                    var4 = false;
                }
            }

            if (!var4) {
                try {
                    Thread.sleep(100L);
                } catch (InterruptedException var6) {
                    var6.printStackTrace();
                }
            }
        }

        // the rest of code 

    }

This function contains a blocking Thread.sleep() call within a loop, which can potentially block the calling thread for up to 8 seconds.

The issue arises because this blocking function is invoked from the main thread, as shown below:

(new Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
                public void run() {
                    BPHeadsetImpl.this.a(var1);
                }
            }, 1L);

This causes the main thread may be blocked for up to 8 seconds while waiting for the Bluetooth adapter to become available, resulting in an ANR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions