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

Commit 44ada184 authored by Matthew Xie's avatar Matthew Xie Committed by Android Git Automerger
Browse files

am 5a8ad071: am a303f0ec: Merge "Send CONNECT_OTHER_PROFILE to Device profile...

am 5a8ad071: am a303f0ec: Merge "Send CONNECT_OTHER_PROFILE to Device profile for hfp and a2dp incoming connect" into ics-mr1

* commit '5a8ad071':
  Send CONNECT_OTHER_PROFILE to Device profile for hfp and a2dp incoming connect
parents 6c934436 5a8ad071
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -86,7 +86,7 @@ public final class BluetoothDeviceProfileState extends StateMachine {
    private static final int CONNECTION_ACCESS_REQUEST_REPLY = 104;
    private static final int CONNECTION_ACCESS_REQUEST_REPLY = 104;
    private static final int CONNECTION_ACCESS_REQUEST_EXPIRY = 105;
    private static final int CONNECTION_ACCESS_REQUEST_EXPIRY = 105;


    private static final int CONNECT_OTHER_PROFILES_DELAY = 4000; // 4 secs
    public static final int CONNECT_OTHER_PROFILES_DELAY = 4000; // 4 secs
    private static final int CONNECTION_ACCESS_REQUEST_EXPIRY_TIMEOUT = 7000; // 7 secs
    private static final int CONNECTION_ACCESS_REQUEST_EXPIRY_TIMEOUT = 7000; // 7 secs
    private static final int CONNECTION_ACCESS_UNDEFINED = -1;
    private static final int CONNECTION_ACCESS_UNDEFINED = -1;
    private static final long INIT_INCOMING_REJECT_TIMER = 1000; // 1 sec
    private static final long INIT_INCOMING_REJECT_TIMER = 1000; // 1 sec
+1 −1
Original line number Original line Diff line number Diff line
@@ -90,7 +90,7 @@ interface IBluetooth


    boolean connectHeadset(String address);
    boolean connectHeadset(String address);
    boolean disconnectHeadset(String address);
    boolean disconnectHeadset(String address);
    boolean notifyIncomingConnection(String address);
    boolean notifyIncomingConnection(String address, boolean rejected);


    // HID profile APIs
    // HID profile APIs
    boolean connectInputDevice(in BluetoothDevice device);
    boolean connectInputDevice(in BluetoothDevice device);
+2 −1
Original line number Original line Diff line number Diff line
@@ -784,11 +784,12 @@ class BluetoothEventLoop {
                // machine.  We don't handle AVCTP signals currently. We only send
                // machine.  We don't handle AVCTP signals currently. We only send
                // intents for AVDTP state changes. We need to handle both of them in
                // intents for AVDTP state changes. We need to handle both of them in
                // some cases. For now, just don't move to incoming state in this case.
                // some cases. For now, just don't move to incoming state in this case.
                mBluetoothService.notifyIncomingA2dpConnection(address);
                mBluetoothService.notifyIncomingA2dpConnection(address, true);
            } else {
            } else {
                Log.i(TAG, "" + authorized +
                Log.i(TAG, "" + authorized +
                      "Incoming A2DP / AVRCP connection from " + address);
                      "Incoming A2DP / AVRCP connection from " + address);
                mA2dp.allowIncomingConnect(device, authorized);
                mA2dp.allowIncomingConnect(device, authorized);
                mBluetoothService.notifyIncomingA2dpConnection(address, false);
            }
            }
        } else if (BluetoothUuid.isInputDevice(uuid)) {
        } else if (BluetoothUuid.isInputDevice(uuid)) {
            // We can have more than 1 input device connected.
            // We can have more than 1 input device connected.
+43 −22
Original line number Original line Diff line number Diff line
@@ -89,7 +89,7 @@ public class BluetoothService extends IBluetooth.Stub {


    private int mNativeData;
    private int mNativeData;
    private BluetoothEventLoop mEventLoop;
    private BluetoothEventLoop mEventLoop;
    private BluetoothHeadset mBluetoothHeadset;
    private BluetoothHeadset mHeadsetProxy;
    private BluetoothInputDevice mInputDevice;
    private BluetoothInputDevice mInputDevice;
    private BluetoothPan mPan;
    private BluetoothPan mPan;
    private boolean mIsAirplaneSensitive;
    private boolean mIsAirplaneSensitive;
@@ -605,6 +605,7 @@ public class BluetoothService extends IBluetooth.Stub {
        }
        }
        mBondState.initBondState();
        mBondState.initBondState();
        initProfileState();
        initProfileState();
        getProfileProxy();
    }
    }


    /**
    /**
@@ -1766,8 +1767,8 @@ public class BluetoothService extends IBluetooth.Stub {


    private void dumpHeadsetService(PrintWriter pw) {
    private void dumpHeadsetService(PrintWriter pw) {
        pw.println("\n--Headset Service--");
        pw.println("\n--Headset Service--");
        if (mBluetoothHeadset != null) {
        if (mHeadsetProxy != null) {
            List<BluetoothDevice> deviceList = mBluetoothHeadset.getConnectedDevices();
            List<BluetoothDevice> deviceList = mHeadsetProxy.getConnectedDevices();
            if (deviceList.size() == 0) {
            if (deviceList.size() == 0) {
                pw.println("No headsets connected");
                pw.println("No headsets connected");
            } else {
            } else {
@@ -1775,21 +1776,20 @@ public class BluetoothService extends IBluetooth.Stub {
                pw.println("\ngetConnectedDevices[0] = " + device);
                pw.println("\ngetConnectedDevices[0] = " + device);
                dumpHeadsetConnectionState(pw, device);
                dumpHeadsetConnectionState(pw, device);
                pw.println("getBatteryUsageHint() = " +
                pw.println("getBatteryUsageHint() = " +
                             mBluetoothHeadset.getBatteryUsageHint(device));
                             mHeadsetProxy.getBatteryUsageHint(device));
            }
            }


            deviceList.clear();
            deviceList.clear();
            deviceList = mBluetoothHeadset.getDevicesMatchingConnectionStates(new int[] {
            deviceList = mHeadsetProxy.getDevicesMatchingConnectionStates(new int[] {
                     BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_DISCONNECTED});
                     BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_DISCONNECTED});
            pw.println("--Connected and Disconnected Headsets");
            pw.println("--Connected and Disconnected Headsets");
            for (BluetoothDevice device: deviceList) {
            for (BluetoothDevice device: deviceList) {
                pw.println(device);
                pw.println(device);
                if (mBluetoothHeadset.isAudioConnected(device)) {
                if (mHeadsetProxy.isAudioConnected(device)) {
                    pw.println("SCO audio connected to device:" + device);
                    pw.println("SCO audio connected to device:" + device);
                }
                }
            }
            }
        }
        }
        mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
    }
    }


    private void dumpInputDeviceProfile(PrintWriter pw) {
    private void dumpInputDeviceProfile(PrintWriter pw) {
@@ -1824,7 +1824,6 @@ public class BluetoothService extends IBluetooth.Stub {
                pw.println(device);
                pw.println(device);
            }
            }
        }
        }
        mAdapter.closeProfileProxy(BluetoothProfile.INPUT_DEVICE, mBluetoothHeadset);
    }
    }


    private void dumpPanProfile(PrintWriter pw) {
    private void dumpPanProfile(PrintWriter pw) {
@@ -1862,7 +1861,7 @@ public class BluetoothService extends IBluetooth.Stub {


    private void dumpHeadsetConnectionState(PrintWriter pw,
    private void dumpHeadsetConnectionState(PrintWriter pw,
            BluetoothDevice device) {
            BluetoothDevice device) {
        switch (mBluetoothHeadset.getConnectionState(device)) {
        switch (mHeadsetProxy.getConnectionState(device)) {
            case BluetoothHeadset.STATE_CONNECTING:
            case BluetoothHeadset.STATE_CONNECTING:
                pw.println("getConnectionState() = STATE_CONNECTING");
                pw.println("getConnectionState() = STATE_CONNECTING");
                break;
                break;
@@ -1884,7 +1883,6 @@ public class BluetoothService extends IBluetooth.Stub {
            Integer pid = mServiceRecordToPid.get(handle).first;
            Integer pid = mServiceRecordToPid.get(handle).first;
            pw.println("\tpid " + pid + " handle " + Integer.toHexString(handle));
            pw.println("\tpid " + pid + " handle " + Integer.toHexString(handle));
        }
        }
        mAdapter.closeProfileProxy(BluetoothProfile.PAN, mBluetoothHeadset);
    }
    }


    private void dumpAclConnectedDevices(PrintWriter pw) {
    private void dumpAclConnectedDevices(PrintWriter pw) {
@@ -1927,11 +1925,16 @@ public class BluetoothService extends IBluetooth.Stub {
        }
        }
    }
    }


    private void getProfileProxy() {
        mAdapter.getProfileProxy(mContext,
                                 mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
    }

    private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
    private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
        new BluetoothProfile.ServiceListener() {
        new BluetoothProfile.ServiceListener() {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (profile == BluetoothProfile.HEADSET) {
            if (profile == BluetoothProfile.HEADSET) {
                mBluetoothHeadset = (BluetoothHeadset) proxy;
                mHeadsetProxy = (BluetoothHeadset) proxy;
            } else if (profile == BluetoothProfile.INPUT_DEVICE) {
            } else if (profile == BluetoothProfile.INPUT_DEVICE) {
                mInputDevice = (BluetoothInputDevice) proxy;
                mInputDevice = (BluetoothInputDevice) proxy;
            } else if (profile == BluetoothProfile.PAN) {
            } else if (profile == BluetoothProfile.PAN) {
@@ -1940,7 +1943,7 @@ public class BluetoothService extends IBluetooth.Stub {
        }
        }
        public void onServiceDisconnected(int profile) {
        public void onServiceDisconnected(int profile) {
            if (profile == BluetoothProfile.HEADSET) {
            if (profile == BluetoothProfile.HEADSET) {
                mBluetoothHeadset = null;
                mHeadsetProxy = null;
            } else if (profile == BluetoothProfile.INPUT_DEVICE) {
            } else if (profile == BluetoothProfile.INPUT_DEVICE) {
                mInputDevice = null;
                mInputDevice = null;
            } else if (profile == BluetoothProfile.PAN) {
            } else if (profile == BluetoothProfile.PAN) {
@@ -2424,25 +2427,43 @@ public class BluetoothService extends IBluetooth.Stub {
        }
        }
    }
    }


    public boolean notifyIncomingConnection(String address) {
    public boolean notifyIncomingConnection(String address, boolean rejected) {
        BluetoothDeviceProfileState state =
        BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
             mDeviceProfileState.get(address);
        if (state != null) {
        if (state != null) {
            Message msg = new Message();
            Message msg = new Message();
            if (rejected) {
                if (mA2dpService.getPriority(getRemoteDevice(address)) >=
                    BluetoothProfile.PRIORITY_ON) {
                    msg.what = BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES;
                    msg.arg1 = BluetoothDeviceProfileState.CONNECT_A2DP_OUTGOING;
                    state.sendMessageDelayed(msg,
                        BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES_DELAY);
                }
            } else {
                msg.what = BluetoothDeviceProfileState.CONNECT_HFP_INCOMING;
                msg.what = BluetoothDeviceProfileState.CONNECT_HFP_INCOMING;
                state.sendMessage(msg);
                state.sendMessage(msg);
            }
            return true;
            return true;
        }
        }
        return false;
        return false;
    }
    }


    /*package*/ boolean notifyIncomingA2dpConnection(String address) {
    /*package*/ boolean notifyIncomingA2dpConnection(String address, boolean rejected) {
       BluetoothDeviceProfileState state =
       BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
            mDeviceProfileState.get(address);
       if (state != null) {
       if (state != null) {
           Message msg = new Message();
           Message msg = new Message();
           if (rejected) {
               if (mHeadsetProxy.getPriority(getRemoteDevice(address)) >=
                   BluetoothProfile.PRIORITY_ON) {
                   msg.what = BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES;
                   msg.arg1 = BluetoothDeviceProfileState.CONNECT_HFP_OUTGOING;
                   state.sendMessageDelayed(msg,
                             BluetoothDeviceProfileState.CONNECT_OTHER_PROFILES_DELAY);
               }
           } else {
               msg.what = BluetoothDeviceProfileState.CONNECT_A2DP_INCOMING;
               msg.what = BluetoothDeviceProfileState.CONNECT_A2DP_INCOMING;
               state.sendMessage(msg);
               state.sendMessage(msg);
           }
           return true;
           return true;
       }
       }
       return false;
       return false;