From f5b1c1d045b77bc2ba00ecc3ca5e029388b7d8e9 Mon Sep 17 00:00:00 2001 From: Chienyuan Date: Wed, 5 Sep 2018 17:03:20 +0800 Subject: [PATCH] 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 --- .../settingslib/bluetooth/MapProfile.java | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/MapProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/MapProfile.java index aa7a7af582a75..511c4ce678e25 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/MapProfile.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/MapProfile.java @@ -32,11 +32,10 @@ import java.util.ArrayList; import java.util.List; /** - * MapProfile handles Bluetooth MAP profile. + * MapProfile handles the Bluetooth MAP MSE role */ public class MapProfile implements LocalBluetoothProfile { private static final String TAG = "MapProfile"; - private static boolean V = true; private BluetoothMap mService; private boolean mIsProfileReady; @@ -60,7 +59,7 @@ public class MapProfile implements LocalBluetoothProfile { implements BluetoothProfile.ServiceListener { public void onServiceConnected(int profile, BluetoothProfile proxy) { - if (V) Log.d(TAG,"Bluetooth service connected"); + Log.d(TAG, "Bluetooth service connected"); mService = (BluetoothMap) proxy; // We just bound to the service, so refresh the UI for any connected MAP devices. List deviceList = mService.getConnectedDevices(); @@ -82,14 +81,14 @@ public class MapProfile implements LocalBluetoothProfile { } public void onServiceDisconnected(int profile) { - if (V) Log.d(TAG,"Bluetooth service disconnected"); + Log.d(TAG, "Bluetooth service disconnected"); mProfileManager.callServiceDisconnectedListeners(); mIsProfileReady=false; } } public boolean isProfileReady() { - if(V) Log.d(TAG,"isProfileReady(): "+ mIsProfileReady); + Log.d(TAG, "isProfileReady(): " + mIsProfileReady); return mIsProfileReady; } @@ -117,45 +116,45 @@ public class MapProfile implements LocalBluetoothProfile { } 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 } public boolean disconnect(BluetoothDevice device) { - if (mService == null) return false; - List deviceList = mService.getConnectedDevices(); - if (!deviceList.isEmpty() && deviceList.get(0).equals(device)) { - if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) { - mService.setPriority(device, BluetoothProfile.PRIORITY_ON); - } - return mService.disconnect(device); - } else { + if (mService == null) { return false; } + if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) { + mService.setPriority(device, BluetoothProfile.PRIORITY_ON); + } + return mService.disconnect(device); } public int getConnectionStatus(BluetoothDevice device) { - if (mService == null) return BluetoothProfile.STATE_DISCONNECTED; - List deviceList = mService.getConnectedDevices(); - if(V) Log.d(TAG,"getConnectionStatus: status is: "+ mService.getConnectionState(device)); - - return !deviceList.isEmpty() && deviceList.get(0).equals(device) - ? mService.getConnectionState(device) - : BluetoothProfile.STATE_DISCONNECTED; + if (mService == null) { + return BluetoothProfile.STATE_DISCONNECTED; + } + return mService.getConnectionState(device); } public boolean isPreferred(BluetoothDevice device) { - if (mService == null) return false; + if (mService == null) { + return false; + } return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF; } public int getPreferred(BluetoothDevice device) { - if (mService == null) return BluetoothProfile.PRIORITY_OFF; + if (mService == null) { + return BluetoothProfile.PRIORITY_OFF; + } return mService.getPriority(device); } public void setPreferred(BluetoothDevice device, boolean preferred) { - if (mService == null) return; + if (mService == null) { + return; + } if (preferred) { if (mService.getPriority(device) < BluetoothProfile.PRIORITY_ON) { mService.setPriority(device, BluetoothProfile.PRIORITY_ON); @@ -166,7 +165,9 @@ public class MapProfile implements LocalBluetoothProfile { } public List getConnectedDevices() { - if (mService == null) return new ArrayList(0); + if (mService == null) { + return new ArrayList(0); + } return mService.getDevicesMatchingConnectionStates( new int[] {BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_CONNECTING, @@ -204,7 +205,7 @@ public class MapProfile implements LocalBluetoothProfile { } protected void finalize() { - if (V) Log.d(TAG, "finalize()"); + Log.d(TAG, "finalize()"); if (mService != null) { try { BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.MAP,