Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 073ec6ee authored by Hemant Gupta's avatar Hemant Gupta Committed by Andre Eisenbach
Browse files

SAP : Prevent crash during turn on Airplane mode

Use Case:
1. Initiate SAP connection from Remote Device.
2. Turn on Airplane mode to disable BT when SAP Client
   is connected on DUT.
3. Repeat steps 1 and 2.

Error log :

Line 16: 03-13 13:57:31.559  3368  3569 V SapServer: in sendDisconnectInd()
Line 17: 03-13 13:57:31.559  3368  3569 D SapServer: Cleaning up before force disconnecting rfcomm
Line 19: 03-13 13:57:31.559  3368  3569 D SapServer: Waiting for deinit to complete
Line 20: 03-13 13:57:31.563  3368  3386 W BluetoothAdapterService: setProfileServiceState() -
Stopping service com.android.bluetooth.sap.SapService
Line 33: 03-13 13:57:31.936  3368  3368 W BluetoothAdapterService: onProfileServiceStateChange() -
Profile still running: com.android.bluetooth.sap.SapService
Line 34: 03-13 13:57:31.937  3368  3368 W BluetoothAdapterService: onProfileServiceStateChange()
serviceName=com.android.bluetooth.sap.SapService, state=10, doUpdate=true
Line 42: 03-13 13:57:32.310  3368  3569 E AndroidRuntime: java.lang.IllegalArgumentException:
Receiver not registered: com.android.bluetooth.sap.SapServer$1@dbf974b
Line 46: 03-13 13:57:32.310  3368  3569 E AndroidRuntime:    at com.android.bluetooth.sap.
SapServer.run(SapServer.java:463)
Line 46: 03-13 13:57:32.310  3368  3569 E AndroidRuntime:    at com.android.bluetooth.sap.
SapServer.run(SapServer.java:463)
Line 46: 03-13 13:57:32.310  3368  3569 E AndroidRuntime:    at com.android.bluetooth.sap.
SapServer.run(SapServer.java:463)

Failure:
"Unfortunately, Bluetooth share has stopped" error comes.

Root cause :
RIL Deinit is not completed because of un-expected turn of BT.

Fix:
Decrement the count of the latch, to release all waiting threads
when BT is turned off during active sap connection.

Test: Checked manually if no crash in BT as per above usecase.

Bug: 62411305
Change-Id: Ib36430c56935efa9de5ce7f8b18eddc9cea47662
parent d792efd9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothSap;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -450,6 +451,12 @@ public class SapServer extends Thread implements Callback {
            /* TODO: Change to the needed Exception types when done testing */
            Log.w(TAG, e);
        } finally {
            BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
            int state = (adapter != null) ? adapter.getState() : -1;
            if (state != BluetoothAdapter.STATE_ON) {
                if (DEBUG) Log.d(TAG, "BT State :" + state);
                mDeinitSignal.countDown();
            }
            // Do cleanup even if an exception occurs
            stopDisconnectTimer();
            /* In case of e.g. a RFCOMM close while connected: