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

Commit 0654b715 authored by Ganesh Ganapathi Batta's avatar Ganesh Ganapathi Batta Committed by Matthew Xie
Browse files

Remove Profile Auto connection specific logic

Remove  profile auto connection specific logic as it is not implemented in
Bluetooth app
Disconnect PBAP server connection  when user initiates device level disconnection

Change-Id: I381ed96f6b57f414bbaccd694f55d2b992e330a4
parent 9effd146
Loading
Loading
Loading
Loading
+4 −23
Original line number Diff line number Diff line
@@ -56,13 +56,11 @@ final class A2dpProfile implements LocalBluetoothProfile {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (V) Log.d(TAG,"Bluetooth service connected");
            mService = (BluetoothA2dp) proxy;
            mProfileManager.setA2dpServiceUp(true);
            mIsProfileReady=true;
        }

        public void onServiceDisconnected(int profile) {
            if (V) Log.d(TAG,"Bluetooth service disconnected");
            mProfileManager.setA2dpServiceUp(false);
            mIsProfileReady=false;
        }
    }
@@ -106,21 +104,11 @@ final class A2dpProfile implements LocalBluetoothProfile {

    public boolean disconnect(BluetoothDevice device) {
        if (mService == null) return false;
        return mService.disconnect(device);
    }

    // This function is added as the AUTO CONNECT priority could not be set by using setPreferred(),
    // as setPreferred() takes only boolean input but getPreferred() supports interger output.
    // Also this need not implemented by all profiles so this has been added here.
    public void enableAutoConnect(BluetoothDevice device, boolean enable) {
        if (mService == null) return;
        if (enable) {
             mService.setPriority(device, BluetoothProfile.PRIORITY_AUTO_CONNECT);
        } else {
        // Downgrade priority as user is disconnecting the headset.
        if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON){
            mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
        }
        }
        return mService.disconnect(device);
    }

    public int getConnectionStatus(BluetoothDevice device) {
@@ -150,13 +138,6 @@ final class A2dpProfile implements LocalBluetoothProfile {
            mService.setPriority(device, BluetoothProfile.PRIORITY_OFF);
        }
    }

    public void setUnbonded(BluetoothDevice device)
    {
        if (mService == null) return;
        mService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
    }

    boolean isA2dpPlaying() {
        if (mService == null) return false;
        List<BluetoothDevice> sinks = mService.getConnectedDevices();
+0 −10
Original line number Diff line number Diff line
@@ -101,9 +101,6 @@ 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);
    }

@@ -372,13 +369,6 @@ 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) {
+8 −36
Original line number Diff line number Diff line
@@ -119,30 +119,6 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
            Log.d(TAG, "onProfileStateChanged: profile " + profile +
                    " newProfileState " + newProfileState);
        }
        if (profile instanceof HeadsetProfile) {
            if (newProfileState == BluetoothProfile.STATE_CONNECTED) {
                if (BluetoothProfile.PRIORITY_AUTO_CONNECT != profile.getPreferred(mDevice))
                    mProfileManager.enableAutoConnectForHf(mDevice, true);
            } else if (newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
                // dont reset auto connect priority when bluetooth turned off
                if ((BluetoothAdapter.STATE_ON == mLocalAdapter.getBluetoothState())
                    || (BluetoothAdapter.STATE_TURNING_ON == mLocalAdapter.getBluetoothState())) {
                        mProfileManager.enableAutoConnectForHf(mDevice, false);
                }
            }
        } else if (profile instanceof A2dpProfile ) {
            if (newProfileState == BluetoothProfile.STATE_CONNECTED) {
                if (BluetoothProfile.PRIORITY_AUTO_CONNECT != profile.getPreferred(mDevice))
                    mProfileManager.enableAutoConnectForA2dp(mDevice,true);
            } else if (newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
                // dont reset auto connect priority when bluetooth turned off
                if ((BluetoothAdapter.STATE_ON == mLocalAdapter.getBluetoothState())
                    || (BluetoothAdapter.STATE_TURNING_ON == mLocalAdapter.getBluetoothState())) {
                        mProfileManager.enableAutoConnectForA2dp(mDevice, false);
                }
            }
        }

        mProfileConnectionState.put(profile, newProfileState);
        if (newProfileState == BluetoothProfile.STATE_CONNECTED) {
            if (!mProfiles.contains(profile)) {
@@ -180,6 +156,14 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
        for (LocalBluetoothProfile profile : mProfiles) {
            disconnect(profile);
        }
        // Disconnect  PBAP server in case its connected
        // This is to ensure all the profiles are disconnected as some CK/Hs do not
        // disconnect  PBAP connection when HF connection is brought down
        PbapServerProfile PbapProfile = mProfileManager.getPbapProfile();
        if (PbapProfile.getConnectionStatus(mDevice) == BluetoothProfile.STATE_CONNECTED)
        {
            PbapProfile.disconnect(mDevice);
        }
    }

    void disconnect(LocalBluetoothProfile profile) {
@@ -507,23 +491,11 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
                        .elapsedRealtime()) {
            connectWithoutResettingTimer(false);
        }
        // On an incoming pairing, set all the available profiles as preferred.
        for (LocalBluetoothProfile profile : mProfiles) {
                profile.setPreferred(mDevice, true);
        }
        dispatchAttributesChanged();
    }

    // Clear service priority of Hid, A2DP and Headset profiles on unbond
    private void clearProfilePriorities() {
        for (LocalBluetoothProfile profile : mProfiles) {
            profile.setUnbonded(mDevice);
        }
    }

    void onBondingStateChanged(int bondState) {
        if (bondState == BluetoothDevice.BOND_NONE) {
            clearProfilePriorities();
            mProfiles.clear();
            mConnectAfterPairing = false;  // cancel auto-connect
            setPhonebookPermissionChoice(PHONEBOOK_ACCESS_UNKNOWN);
+0 −23
Original line number Diff line number Diff line
@@ -78,14 +78,12 @@ final class HeadsetProfile implements LocalBluetoothProfile {
            }

            mProfileManager.callServiceConnectedListeners();
            mProfileManager.setHfServiceUp(true);
            mIsProfileReady=true;
        }

        public void onServiceDisconnected(int profile) {
            if (V) Log.d(TAG,"Bluetooth service disconnected");
            mProfileManager.callServiceDisconnectedListeners();
            mProfileManager.setHfServiceUp(false);
            mIsProfileReady=false;
        }
    }
@@ -167,12 +165,6 @@ final class HeadsetProfile implements LocalBluetoothProfile {
        }
    }

    public void setUnbonded(BluetoothDevice device)
    {
        if (mService == null) return;
        mService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
    }

    public List<BluetoothDevice> getConnectedDevices() {
        if (mService == null) return new ArrayList<BluetoothDevice>(0);
        return mService.getDevicesMatchingConnectionStates(
@@ -181,21 +173,6 @@ final class HeadsetProfile implements LocalBluetoothProfile {
                         BluetoothProfile.STATE_DISCONNECTING});
    }


    // This function is added as the AUTO CONNECT priority could not be set by using setPreferred(),
    // as setPreferred() takes only boolean input but getPreferred() supports interger output.
    // Also this need not implemented by all profiles so this has been added here.
    public void enableAutoConnect(BluetoothDevice device, boolean enable) {
        if (mService == null) return;
        if (enable) {
            mService.setPriority(device, BluetoothProfile.PRIORITY_AUTO_CONNECT);
        } else {
            if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
                mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
            }
        }
    }

    public String toString() {
        return NAME;
    }
+0 −6
Original line number Diff line number Diff line
@@ -118,12 +118,6 @@ final class HidProfile implements LocalBluetoothProfile {
        }
    }

    public void setUnbonded(BluetoothDevice device)
    {
        if (mService == null) return;
        mService.setPriority(device, BluetoothProfile.PRIORITY_UNDEFINED);
    }

    public String toString() {
        return NAME;
    }
Loading