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

Commit b45e3c8f authored by Swaminatha Balaji's avatar Swaminatha Balaji Committed by Matthew Xie
Browse files

Fix for When Hf is rejected the device should initiate A2dp if a2dp is enabled

Change-Id: I0716782a5308cc45297a30d0a7371286c75bfa52
parent 802956ec
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import com.android.settings.R;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -99,6 +100,10 @@ final class BluetoothEventManager {

        // Dock event broadcasts
        addHandler(Intent.ACTION_DOCK_EVENT, new DockEventHandler());

        // Connect other profiles broadcast
        addHandler(BluetoothProfile.ACTION_CONNECT_OTHER_PROFILES, new ConnectOtherProfilesHandler());

        mContext.registerReceiver(mBroadcastReceiver, mAdapterIntentFilter);
    }

@@ -368,6 +373,12 @@ final class BluetoothEventManager {
        }
    }

    private class ConnectOtherProfilesHandler implements Handler {
        public void onReceive(Context context, Intent intent, BluetoothDevice device) {
            mProfileManager.handleConnectOtherProfiles(device);
        }
    }

    boolean readPairedDevices() {
        Set<BluetoothDevice> bondedDevices = mLocalAdapter.getBondedDevices();
        if (bondedDevices == null) {
+38 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import java.util.List;
final class LocalBluetoothProfileManager {
    private static final String TAG = "LocalBluetoothProfileManager";
    private static final int CONNECT_HF_OR_A2DP = 1;
    private static final int CONNECT_OTHER_PROFILES = 2;
    // If either a2dp or hf is connected and if the other profile conneciton is not
    // happening with the timeout , the other profile(a2dp or hf) will be inititate connection.
    // Give reasonable timeout for the device to initiate the other profile connection.
@@ -105,6 +106,30 @@ final class LocalBluetoothProfileManager {
    }
};

        private final Handler connectOtherProfilesHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
            synchronized (this) {
                // Connect all the profiles which are enabled
                // Right now hf/a2dp profiles connect is handled here
                List<BluetoothDevice> hfConnDevList= mHeadsetProfile.getConnectedDevices();

                if (hfConnDevList.isEmpty() && mHeadsetProfile.isPreferred((BluetoothDevice)msg.obj))
                    mHeadsetProfile.connect((BluetoothDevice)msg.obj);
                else
                    Log.d(TAG,"Hf device is not preferred or already Hf connected device exist");

                List<BluetoothDevice> a2dpConnDevList= mA2dpProfile.getConnectedDevices();

                if (a2dpConnDevList.isEmpty() && mA2dpProfile.isPreferred((BluetoothDevice)msg.obj))
                    mA2dpProfile.connect((BluetoothDevice)msg.obj);
                else
                    Log.d(TAG,"A2dp device is not preferred or already a2dp connected device exist");

            }
        }
    };

    /**
     * Mapping from profile name, e.g. "HEADSET" to profile object.
     */
@@ -353,6 +378,19 @@ final class LocalBluetoothProfileManager {
        mA2dpProfile.enableAutoConnect(device,enable);
    }

    public void handleConnectOtherProfiles(BluetoothDevice device) {
        if (device != null){
            // Remove previous messages if any
            connectOtherProfilesHandler.removeMessages(CONNECT_OTHER_PROFILES);
            Message mes = connectOtherProfilesHandler.obtainMessage(CONNECT_OTHER_PROFILES);
            mes.obj = device;
            connectOtherProfilesHandler.sendMessageDelayed(mes,CONNECT_HF_OR_A2DP_TIMEOUT);
            Log.i(TAG,"Message posted for connection other Profiles ");
        } else {
            Log.e(TAG,"Device = Null received in handleConnectOtherProfiles ");
        }
    }

    // This is called by DockService, so check Headset and A2DP.
    public synchronized boolean isManagerReady() {
        // Getting just the headset profile is fine for now. Will need to deal with A2DP