Loading android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorService.java +19 −26 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.ParcelUuid; import android.os.RemoteException; import android.sysprop.BluetoothProperties; Loading Loading @@ -81,6 +83,8 @@ public class CsipSetCoordinatorService extends ProfileService { private static final int MAX_CSIS_STATE_MACHINES = 10; private static CsipSetCoordinatorService sCsipSetCoordinatorService; private Handler mHandler = null; private AdapterService mAdapterService; private LeAudioService mLeAudioService; private DatabaseManager mDatabaseManager; Loading @@ -107,7 +111,6 @@ public class CsipSetCoordinatorService extends ProfileService { new ConcurrentHashMap<>(); private BroadcastReceiver mBondStateChangedReceiver; private BroadcastReceiver mConnectionStateChangedReceiver; public static boolean isEnabled() { return BluetoothProperties.isProfileCsipSetCoordinatorEnabled().orElse(false); Loading Loading @@ -145,6 +148,9 @@ public class CsipSetCoordinatorService extends ProfileService { "CsipSetCoordinatorNativeInterface cannot be null when" .concat("CsipSetCoordinatorService starts")); // Setup Handler. mHandler = new Handler(Looper.getMainLooper()); // Get LE Audio service (can be null) mLeAudioService = mServiceFactory.getLeAudioService(); Loading @@ -159,11 +165,6 @@ public class CsipSetCoordinatorService extends ProfileService { filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mBondStateChangedReceiver = new BondStateChangedReceiver(); registerReceiver(mBondStateChangedReceiver, filter); filter = new IntentFilter(); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); filter.addAction(BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED); mConnectionStateChangedReceiver = new ConnectionStateChangedReceiver(); registerReceiver(mConnectionStateChangedReceiver, filter); // Mark service as started setCsipSetCoordinatorService(this); Loading Loading @@ -198,8 +199,6 @@ public class CsipSetCoordinatorService extends ProfileService { // Unregister broadcast receivers unregisterReceiver(mBondStateChangedReceiver); mBondStateChangedReceiver = null; unregisterReceiver(mConnectionStateChangedReceiver); mConnectionStateChangedReceiver = null; // Destroy state machines and stop handler thread synchronized (mStateMachines) { Loading Loading @@ -274,7 +273,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return true if connection is successful, false otherwise. */ public boolean connect(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "connect(): " + device); } Loading Loading @@ -309,7 +309,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return true if disconnect is successful, false otherwise. */ public boolean disconnect(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "disconnect(): " + device); } Loading Loading @@ -480,7 +481,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return true on success, otherwise false */ public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy); } Loading @@ -501,7 +503,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return connection policy of the specified device */ public int getConnectionPolicy(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); return mDatabaseManager.getProfileConnectionPolicy( device, BluetoothProfile.CSIP_SET_COORDINATOR); } Loading Loading @@ -1018,6 +1021,10 @@ public class CsipSetCoordinatorService extends ProfileService { } } void handleConnectionStateChanged(BluetoothDevice device, int fromState, int toState) { mHandler.post(() -> connectionStateChanged(device, fromState, toState)); } @VisibleForTesting synchronized void connectionStateChanged(BluetoothDevice device, int fromState, int toState) { if ((device == null) || (fromState == toState)) { Loading Loading @@ -1051,20 +1058,6 @@ public class CsipSetCoordinatorService extends ProfileService { } } private class ConnectionStateChangedReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (!BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED.equals( intent.getAction())) { return; } BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int toState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1); int fromState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1); connectionStateChanged(device, fromState, toState); } } /** * Binder object: must be a static class or memory leak may occur */ Loading android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachine.java +1 −0 Original line number Diff line number Diff line Loading @@ -516,6 +516,7 @@ public class CsipSetCoordinatorStateMachine extends StateMachine { private void csipConnectionState(int newState, int prevState) { log("Connection state " + mDevice + ": " + profileStateToString(prevState) + "->" + profileStateToString(newState)); mService.handleConnectionStateChanged(mDevice, prevState, newState); Intent intent = new Intent(BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED); Loading Loading
android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorService.java +19 −26 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.ParcelUuid; import android.os.RemoteException; import android.sysprop.BluetoothProperties; Loading Loading @@ -81,6 +83,8 @@ public class CsipSetCoordinatorService extends ProfileService { private static final int MAX_CSIS_STATE_MACHINES = 10; private static CsipSetCoordinatorService sCsipSetCoordinatorService; private Handler mHandler = null; private AdapterService mAdapterService; private LeAudioService mLeAudioService; private DatabaseManager mDatabaseManager; Loading @@ -107,7 +111,6 @@ public class CsipSetCoordinatorService extends ProfileService { new ConcurrentHashMap<>(); private BroadcastReceiver mBondStateChangedReceiver; private BroadcastReceiver mConnectionStateChangedReceiver; public static boolean isEnabled() { return BluetoothProperties.isProfileCsipSetCoordinatorEnabled().orElse(false); Loading Loading @@ -145,6 +148,9 @@ public class CsipSetCoordinatorService extends ProfileService { "CsipSetCoordinatorNativeInterface cannot be null when" .concat("CsipSetCoordinatorService starts")); // Setup Handler. mHandler = new Handler(Looper.getMainLooper()); // Get LE Audio service (can be null) mLeAudioService = mServiceFactory.getLeAudioService(); Loading @@ -159,11 +165,6 @@ public class CsipSetCoordinatorService extends ProfileService { filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mBondStateChangedReceiver = new BondStateChangedReceiver(); registerReceiver(mBondStateChangedReceiver, filter); filter = new IntentFilter(); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); filter.addAction(BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED); mConnectionStateChangedReceiver = new ConnectionStateChangedReceiver(); registerReceiver(mConnectionStateChangedReceiver, filter); // Mark service as started setCsipSetCoordinatorService(this); Loading Loading @@ -198,8 +199,6 @@ public class CsipSetCoordinatorService extends ProfileService { // Unregister broadcast receivers unregisterReceiver(mBondStateChangedReceiver); mBondStateChangedReceiver = null; unregisterReceiver(mConnectionStateChangedReceiver); mConnectionStateChangedReceiver = null; // Destroy state machines and stop handler thread synchronized (mStateMachines) { Loading Loading @@ -274,7 +273,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return true if connection is successful, false otherwise. */ public boolean connect(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "connect(): " + device); } Loading Loading @@ -309,7 +309,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return true if disconnect is successful, false otherwise. */ public boolean disconnect(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "disconnect(): " + device); } Loading Loading @@ -480,7 +481,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return true on success, otherwise false */ public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy); } Loading @@ -501,7 +503,8 @@ public class CsipSetCoordinatorService extends ProfileService { * @return connection policy of the specified device */ public int getConnectionPolicy(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); return mDatabaseManager.getProfileConnectionPolicy( device, BluetoothProfile.CSIP_SET_COORDINATOR); } Loading Loading @@ -1018,6 +1021,10 @@ public class CsipSetCoordinatorService extends ProfileService { } } void handleConnectionStateChanged(BluetoothDevice device, int fromState, int toState) { mHandler.post(() -> connectionStateChanged(device, fromState, toState)); } @VisibleForTesting synchronized void connectionStateChanged(BluetoothDevice device, int fromState, int toState) { if ((device == null) || (fromState == toState)) { Loading Loading @@ -1051,20 +1058,6 @@ public class CsipSetCoordinatorService extends ProfileService { } } private class ConnectionStateChangedReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (!BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED.equals( intent.getAction())) { return; } BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int toState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1); int fromState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1); connectionStateChanged(device, fromState, toState); } } /** * Binder object: must be a static class or memory leak may occur */ Loading
android/app/src/com/android/bluetooth/csip/CsipSetCoordinatorStateMachine.java +1 −0 Original line number Diff line number Diff line Loading @@ -516,6 +516,7 @@ public class CsipSetCoordinatorStateMachine extends StateMachine { private void csipConnectionState(int newState, int prevState) { log("Connection state " + mDevice + ": " + profileStateToString(prevState) + "->" + profileStateToString(newState)); mService.handleConnectionStateChanged(mDevice, prevState, newState); Intent intent = new Intent(BluetoothCsipSetCoordinator.ACTION_CSIS_CONNECTION_STATE_CHANGED); Loading