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

Commit f5b1c1d0 authored by Chienyuan's avatar Chienyuan Committed by Chienyuan Huang
Browse files

Simplify logic for disconnect and getConnectionStatus in MapProfile

* disconnect: remove connected device check logic. BluetoothMapService
  will check it.
* getConnectionStatus: remove connected device check logic.
  BluetoothMapService will check it.
* Rewrite the annotation about this class.
* Remove member variable V and related checks.
* wrap if/else statement in curly brackets.

Bug: 111812003
Test: manual - disconnect MAP from Settings UI
Change-Id: I2469821f0ae2e3f384844326b30c7d3c4c88ab63
parent 90d5e7b1
Loading
Loading
Loading
Loading
+27 −26
Original line number Original line Diff line number Diff line
@@ -32,11 +32,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.List;


/**
/**
 * MapProfile handles Bluetooth MAP profile.
 * MapProfile handles the Bluetooth MAP MSE role
 */
 */
public class MapProfile implements LocalBluetoothProfile {
public class MapProfile implements LocalBluetoothProfile {
    private static final String TAG = "MapProfile";
    private static final String TAG = "MapProfile";
    private static boolean V = true;


    private BluetoothMap mService;
    private BluetoothMap mService;
    private boolean mIsProfileReady;
    private boolean mIsProfileReady;
@@ -60,7 +59,7 @@ public class MapProfile implements LocalBluetoothProfile {
            implements BluetoothProfile.ServiceListener {
            implements BluetoothProfile.ServiceListener {


        public void onServiceConnected(int profile, BluetoothProfile proxy) {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (V) Log.d(TAG,"Bluetooth service connected");
            Log.d(TAG, "Bluetooth service connected");
            mService = (BluetoothMap) proxy;
            mService = (BluetoothMap) proxy;
            // We just bound to the service, so refresh the UI for any connected MAP devices.
            // We just bound to the service, so refresh the UI for any connected MAP devices.
            List<BluetoothDevice> deviceList = mService.getConnectedDevices();
            List<BluetoothDevice> deviceList = mService.getConnectedDevices();
@@ -82,14 +81,14 @@ public class MapProfile implements LocalBluetoothProfile {
        }
        }


        public void onServiceDisconnected(int profile) {
        public void onServiceDisconnected(int profile) {
            if (V) Log.d(TAG,"Bluetooth service disconnected");
            Log.d(TAG, "Bluetooth service disconnected");
            mProfileManager.callServiceDisconnectedListeners();
            mProfileManager.callServiceDisconnectedListeners();
            mIsProfileReady=false;
            mIsProfileReady=false;
        }
        }
    }
    }


    public boolean isProfileReady() {
    public boolean isProfileReady() {
        if(V) Log.d(TAG,"isProfileReady(): "+ mIsProfileReady);
        Log.d(TAG, "isProfileReady(): " + mIsProfileReady);
        return mIsProfileReady;
        return mIsProfileReady;
    }
    }


@@ -117,45 +116,45 @@ public class MapProfile implements LocalBluetoothProfile {
    }
    }


    public boolean connect(BluetoothDevice device) {
    public boolean connect(BluetoothDevice device) {
        if(V)Log.d(TAG,"connect() - should not get called");
        Log.d(TAG, "connect() - should not get called");
        return false; // MAP never connects out
        return false; // MAP never connects out
    }
    }


    public boolean disconnect(BluetoothDevice device) {
    public boolean disconnect(BluetoothDevice device) {
        if (mService == null) return false;
        if (mService == null) {
        List<BluetoothDevice> deviceList = mService.getConnectedDevices();
            return false;
        if (!deviceList.isEmpty() && deviceList.get(0).equals(device)) {
        }
        if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
        if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
            mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
            mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
        }
        }
        return mService.disconnect(device);
        return mService.disconnect(device);
        } else {
            return false;
        }
    }
    }


    public int getConnectionStatus(BluetoothDevice device) {
    public int getConnectionStatus(BluetoothDevice device) {
        if (mService == null) return BluetoothProfile.STATE_DISCONNECTED;
        if (mService == null) {
        List<BluetoothDevice> deviceList = mService.getConnectedDevices();
            return BluetoothProfile.STATE_DISCONNECTED;
        if(V) Log.d(TAG,"getConnectionStatus: status is: "+ mService.getConnectionState(device));
        }

        return mService.getConnectionState(device);
        return !deviceList.isEmpty() && deviceList.get(0).equals(device)
                ? mService.getConnectionState(device)
                : BluetoothProfile.STATE_DISCONNECTED;
    }
    }


    public boolean isPreferred(BluetoothDevice device) {
    public boolean isPreferred(BluetoothDevice device) {
        if (mService == null) return false;
        if (mService == null) {
            return false;
        }
        return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
        return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
    }
    }


    public int getPreferred(BluetoothDevice device) {
    public int getPreferred(BluetoothDevice device) {
        if (mService == null) return BluetoothProfile.PRIORITY_OFF;
        if (mService == null) {
            return BluetoothProfile.PRIORITY_OFF;
        }
        return mService.getPriority(device);
        return mService.getPriority(device);
    }
    }


    public void setPreferred(BluetoothDevice device, boolean preferred) {
    public void setPreferred(BluetoothDevice device, boolean preferred) {
        if (mService == null) return;
        if (mService == null) {
            return;
        }
        if (preferred) {
        if (preferred) {
            if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) {
            if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) {
                mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
                mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
@@ -166,7 +165,9 @@ public class MapProfile implements LocalBluetoothProfile {
    }
    }


    public List<BluetoothDevice> getConnectedDevices() {
    public List<BluetoothDevice> getConnectedDevices() {
        if (mService == null) return new ArrayList<BluetoothDevice>(0);
        if (mService == null) {
            return new ArrayList<BluetoothDevice>(0);
        }
        return mService.getDevicesMatchingConnectionStates(
        return mService.getDevicesMatchingConnectionStates(
              new int[] {BluetoothProfile.STATE_CONNECTED,
              new int[] {BluetoothProfile.STATE_CONNECTED,
                         BluetoothProfile.STATE_CONNECTING,
                         BluetoothProfile.STATE_CONNECTING,
@@ -204,7 +205,7 @@ public class MapProfile implements LocalBluetoothProfile {
    }
    }


    protected void finalize() {
    protected void finalize() {
        if (V) Log.d(TAG, "finalize()");
        Log.d(TAG, "finalize()");
        if (mService != null) {
        if (mService != null) {
            try {
            try {
                BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.MAP,
                BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.MAP,