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

Commit 75dfd6b3 authored by Nitin Arora's avatar Nitin Arora Committed by Andre Eisenbach
Browse files

DO NOT MERGE Bluetooth: Ensure Bluetooth interface handle is valid

This change adds null checks to Bluetooth interface handle to prevent
using null references when BluetoothService is not up. Also removed
the callbacks for the intermediate state removed for now as they are
not being used.

Change-Id: I4c4a406c99a51e0759d9163f7d658d64dee11ad9
parent 93bbf277
Loading
Loading
Loading
Loading
+12 −17
Original line number Original line Diff line number Diff line
@@ -503,7 +503,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    private void onBluetoothGattServiceUp() {
    private void onBluetoothGattServiceUp() {
        if (DBG) Log.d(TAG,"BluetoothGatt Service is Up");
        if (DBG) Log.d(TAG,"BluetoothGatt Service is Up");
        try{
        try{
            if (isBleAppPresent() == false && mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) {
            if (isBleAppPresent() == false && mBluetooth != null
                  && mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) {
                mBluetooth.onLeServiceUp();
                mBluetooth.onLeServiceUp();


                // waive WRITE_SECURE_SETTINGS permission check
                // waive WRITE_SECURE_SETTINGS permission check
@@ -522,32 +523,26 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
     */
     */
    private void sendBrEdrDownCallback() {
    private void sendBrEdrDownCallback() {
        if (DBG) Log.d(TAG,"Calling sendBrEdrDownCallback callbacks");
        if (DBG) Log.d(TAG,"Calling sendBrEdrDownCallback callbacks");
        int n = mCallbacks.beginBroadcast();

        if(mBluetooth == null) {
            Log.w(TAG, "Bluetooth handle is null");
            return;
        }


        if (isBleAppPresent() == false) {
        if (isBleAppPresent() == false) {
            try {
            try {
                mBluetooth.onBrEdrDown();
                mBluetooth.onBrEdrDown();
            } catch(RemoteException e) {
            } catch(RemoteException e) {
                Log.e(TAG,"Unable to call onBrEdrDown", e);
                Log.e(TAG, "Call to onBrEdrDown() failed.", e);
            }
            }
        }
        } else {
        else{//need to stay at BLE ON. disconnect all Gatt connections
            // Need to stay at BLE ON. Disconnect all Gatt connections
            try{
                mBluetoothGatt.unregAll();//disconnectAll();
            } catch(RemoteException e) {
                Log.e(TAG,"Unable to disconn all", e);
            }
        }

        Log.d(TAG,"Broadcasting onBrEdrDown() to " + n + " receivers.");
        for (int i=0; i <n; i++) {
            try{
            try{
                mCallbacks.getBroadcastItem(i).onBrEdrDown();
                mBluetoothGatt.unregAll();
            } catch(RemoteException e) {
            } catch(RemoteException e) {
                Log.e(TAG, "Unable to call sendBrEdrDownCallback() on callback #" + i, e);
                Log.e(TAG, "Unable to disconnect all apps.", e);
            }
            }
        }
        }
        mCallbacks.finishBroadcast();
    }
    }


    /** @hide*/
    /** @hide*/