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

Commit 20867a77 authored by Ganesh Ganapathi Batta's avatar Ganesh Ganapathi Batta Committed by Matthew Xie
Browse files

Auto connection/disconnection related changes

Remove ACTION_CONNECT_OTHER_PROFILES as it is no longer used
Allow only PRIORITY_ON and PRIORTY_OFF  as priority params for SetPriority()
API in BluetoothA2DP and BluetoothHeadset
BluetoothPBAP: Pass on proxy object as part of Service Connected callback

Change-Id: Ida00fc2b7d1dcb91b01f7ddd2cea482367a3b334
parent 0d6d9f87
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -337,9 +337,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
        if (mService != null && isEnabled()
            && isValidDevice(device)) {
            if (priority != BluetoothProfile.PRIORITY_OFF &&
                priority != BluetoothProfile.PRIORITY_ON &&
                priority != BluetoothProfile.PRIORITY_UNDEFINED &&
                priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) {
                priority != BluetoothProfile.PRIORITY_ON){
              return false;
            }
            try {
+1 −3
Original line number Diff line number Diff line
@@ -455,9 +455,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
        if (mService != null && isEnabled() &&
            isValidDevice(device)) {
            if (priority != BluetoothProfile.PRIORITY_OFF &&
                priority != BluetoothProfile.PRIORITY_ON &&
                priority != BluetoothProfile.PRIORITY_UNDEFINED &&
                priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) {
                priority != BluetoothProfile.PRIORITY_ON) {
              return false;
            }
            try {
+64 −5
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ public class BluetoothPbap {
    private IBluetoothPbap mService;
    private final Context mContext;
    private ServiceListener mServiceListener;
    private BluetoothAdapter mAdapter;

    /** There was an error trying to obtain the state */
    public static final int STATE_ERROR        = -1;
@@ -96,7 +97,7 @@ public class BluetoothPbap {
         * this callback before making IPC calls on the BluetoothPbap
         * service.
         */
        public void onServiceConnected();
        public void onServiceConnected(BluetoothPbap proxy);

        /**
         * Called to notify the client that this proxy object has been
@@ -108,12 +109,54 @@ public class BluetoothPbap {
        public void onServiceDisconnected();
    }

    final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
            new IBluetoothStateChangeCallback.Stub() {
                public void onBluetoothStateChange(boolean up) {
                    if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
                    if (!up) {
                        if (DBG) Log.d(TAG,"Unbinding service...");
                        synchronized (mConnection) {
                            try {
                                mService = null;
                                mContext.unbindService(mConnection);
                            } catch (Exception re) {
                                Log.e(TAG,"",re);
                            }
                        }
                    } else {
                        synchronized (mConnection) {
                            try {
                                if (mService == null) {
                                    if (DBG) Log.d(TAG,"Binding service...");
                                    if (!mContext.bindService(
                                                        new Intent(IBluetoothPbap.class.getName()),
                                                        mConnection, 0)) {
                                        Log.e(TAG, "Could not bind to Bluetooth PBAP Service");
                                    }
                                }
                            } catch (Exception re) {
                                Log.e(TAG,"",re);
                            }
                        }
                    }
                }
        };

    /**
     * Create a BluetoothPbap proxy object.
     */
    public BluetoothPbap(Context context, ServiceListener l) {
        mContext = context;
        mServiceListener = l;
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        IBluetoothManager mgr = mAdapter.getBluetoothManager();
        if (mgr != null) {
            try {
                mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
            } catch (RemoteException e) {
                Log.e(TAG,"",e);
            }
        }
        if (!context.bindService(new Intent(IBluetoothPbap.class.getName()), mConnection, 0)) {
            Log.e(TAG, "Could not bind to Bluetooth Pbap Service");
        }
@@ -134,9 +177,25 @@ public class BluetoothPbap {
     * are ok.
     */
    public synchronized void close() {
        if (mConnection != null) {
        IBluetoothManager mgr = mAdapter.getBluetoothManager();
        if (mgr != null) {
            try {
                mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
            } catch (Exception e) {
                Log.e(TAG,"",e);
            }
        }

        synchronized (mConnection) {
            if (mService != null) {
                try {
                    mService = null;
                    mContext.unbindService(mConnection);
                    mConnection = null;
                } catch (Exception re) {
                    Log.e(TAG,"",re);
                }
            }
        }
        mServiceListener = null;
    }
@@ -240,7 +299,7 @@ public class BluetoothPbap {
            if (DBG) log("Proxy object connected");
            mService = IBluetoothPbap.Stub.asInterface(service);
            if (mServiceListener != null) {
                mServiceListener.onServiceConnected();
                mServiceListener.onServiceConnected(BluetoothPbap.this);
            }
        }
        public void onServiceDisconnected(ComponentName className) {
+0 −7
Original line number Diff line number Diff line
@@ -114,13 +114,6 @@ public interface BluetoothProfile {
     * */
    public static final int PRIORITY_UNDEFINED = -1;

    /**
     * This Intent is sent to initiate the other  profile connections which are enabled
     * @hide
     **/
    public static final String ACTION_CONNECT_OTHER_PROFILES =
                            "android.bluetooth.profile.CONNECT_OTHER_PROFILES";

    /**
     * Get connected devices for this specific profile.
     *