Loading android/app/src/com/android/bluetooth/a2dp/A2dpCodecConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ import java.util.Objects; * A2DP Codec Configuration setup. */ class A2dpCodecConfig { private static final String TAG = "A2dpCodecConfig"; private static final String TAG = A2dpCodecConfig.class.getSimpleName(); private Context mContext; private A2dpNativeInterface mA2dpNativeInterface; Loading android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java +5 −14 Original line number Diff line number Diff line Loading @@ -43,8 +43,7 @@ import java.util.Objects; * A2DP Native Interface to/from JNI. */ public class A2dpNativeInterface { private static final String TAG = "A2dpNativeInterface"; private static final boolean DBG = true; private static final String TAG = A2dpNativeInterface.class.getSimpleName(); private BluetoothAdapter mAdapter; private AdapterService mAdapterService; Loading Loading @@ -200,9 +199,7 @@ public class A2dpNativeInterface { event.device = getDevice(address); event.valueInt = state; if (DBG) { Log.d(TAG, "onConnectionStateChanged: " + event); } sendMessageToService(event); } Loading @@ -211,9 +208,7 @@ public class A2dpNativeInterface { event.device = getDevice(address); event.valueInt = state; if (DBG) { Log.d(TAG, "onAudioStateChanged: " + event); } sendMessageToService(event); } Loading @@ -226,9 +221,7 @@ public class A2dpNativeInterface { event.codecStatus = new BluetoothCodecStatus(newCodecConfig, Arrays.asList(codecsLocalCapabilities), Arrays.asList(codecsSelectableCapabilities)); if (DBG) { Log.d(TAG, "onCodecConfigChanged: " + event); } sendMessageToService(event); } Loading @@ -236,9 +229,7 @@ public class A2dpNativeInterface { A2dpService service = A2dpService.getA2dpService(); if (service != null) { int enabled = service.getOptionalCodecsEnabled(getDevice(address)); if (DBG) { Log.d(TAG, "isMandatoryCodecPreferred: optional preference " + enabled); } // Optional codecs are more preferred if possible return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; } else { Loading android/app/src/com/android/bluetooth/a2dp/A2dpService.java +24 −65 Original line number Diff line number Diff line Loading @@ -82,7 +82,6 @@ import java.util.concurrent.ConcurrentMap; */ public class A2dpService extends ProfileService { private static final String TAG = A2dpService.class.getSimpleName(); private static final boolean DBG = true; // TODO(b/240635097): remove in U private static final int SOURCE_CODEC_TYPE_OPUS = 6; Loading Loading @@ -183,9 +182,7 @@ public class A2dpService extends ProfileService { // Step 6: Check if A2DP is in offload mode mA2dpOffloadEnabled = mAdapterService.isA2dpOffloadEnabled(); if (DBG) { Log.d(TAG, "A2DP offload flag set to " + mA2dpOffloadEnabled); } // Step 7: Register Audio Device callback mAudioManager.registerAudioDeviceCallback(mAudioManagerAudioDeviceCallback, mHandler); Loading Loading @@ -265,16 +262,12 @@ public class A2dpService extends ProfileService { } private static synchronized void setA2dpService(A2dpService instance) { if (DBG) { Log.d(TAG, "setA2dpService(): set to: " + instance); } sA2dpService = instance; } public boolean connect(BluetoothDevice device) { if (DBG) { Log.d(TAG, "connect(): " + device); } if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { Log.e(TAG, "Cannot connect to " + device + " : CONNECTION_POLICY_FORBIDDEN"); Loading Loading @@ -323,9 +316,7 @@ public class A2dpService extends ProfileService { * @return true if profile disconnected, false if device not connected over a2dp */ public boolean disconnect(BluetoothDevice device) { if (DBG) { Log.d(TAG, "disconnect(): " + device); } synchronized (mStateMachines) { A2dpStateMachine sm = mStateMachines.get(device); Loading Loading @@ -525,9 +516,7 @@ public class A2dpService extends ProfileService { */ @VisibleForTesting public boolean setSilenceMode(@NonNull BluetoothDevice device, boolean silence) { if (DBG) { Log.d(TAG, "setSilenceMode(" + device + "): " + silence); } if (silence && Objects.equals(mActiveDevice, device)) { removeActiveDevice(true); } else if (!silence && mActiveDevice == null) { Loading Loading @@ -563,9 +552,7 @@ public class A2dpService extends ProfileService { // returns true since the device is activated even double attempted return true; } if (DBG) { Log.d(TAG, "setActiveDevice(" + device + "): current is " + mActiveDevice); } sm = mStateMachines.get(device); if (sm == null) { Log.e(TAG, "setActiveDevice(" + device + "): Cannot set as active: " Loading @@ -582,9 +569,7 @@ public class A2dpService extends ProfileService { } // Switch from one A2DP to another A2DP device if (DBG) { Log.d(TAG, "Switch A2DP devices to " + device + " from " + previousActiveDevice); } updateLowLatencyAudioSupport(device); Loading Loading @@ -658,9 +643,7 @@ public class A2dpService extends ProfileService { public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy); } if (!mDatabaseManager.setProfileConnectionPolicy(device, BluetoothProfile.A2DP, connectionPolicy)) { Loading Loading @@ -698,9 +681,7 @@ public class A2dpService extends ProfileService { } boolean isA2dpPlaying(BluetoothDevice device) { if (DBG) { Log.d(TAG, "isA2dpPlaying(" + device + ")"); } synchronized (mStateMachines) { A2dpStateMachine sm = mStateMachines.get(device); if (sm == null) { Loading @@ -724,9 +705,7 @@ public class A2dpService extends ProfileService { * @return the current codec status */ public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) { if (DBG) { Log.d(TAG, "getCodecStatus(" + device + ")"); } synchronized (mStateMachines) { if (device == null) { device = mActiveDevice; Loading @@ -751,10 +730,8 @@ public class A2dpService extends ProfileService { */ public void setCodecConfigPreference(BluetoothDevice device, BluetoothCodecConfig codecConfig) { if (DBG) { Log.d(TAG, "setCodecConfigPreference(" + device + "): " + Objects.toString(codecConfig)); } if (device == null) { device = mActiveDevice; } Loading @@ -781,9 +758,7 @@ public class A2dpService extends ProfileService { * active A2DP Bluetooth device. */ public void enableOptionalCodecs(BluetoothDevice device) { if (DBG) { Log.d(TAG, "enableOptionalCodecs(" + device + ")"); } if (device == null) { device = mActiveDevice; } Loading Loading @@ -811,9 +786,7 @@ public class A2dpService extends ProfileService { * active A2DP Bluetooth device. */ public void disableOptionalCodecs(BluetoothDevice device) { if (DBG) { Log.d(TAG, "disableOptionalCodecs(" + device + ")"); } if (device == null) { device = mActiveDevice; } Loading Loading @@ -1021,9 +994,7 @@ public class A2dpService extends ProfileService { + MAX_A2DP_STATE_MACHINES); return null; } if (DBG) { Log.d(TAG, "Creating a new state machine for " + device); } sm = A2dpStateMachine.make( device, this, mNativeInterface, mStateMachinesThread.getLooper()); Loading Loading @@ -1055,16 +1026,12 @@ public class A2dpService extends ProfileService { byte[] addressBytes = Utils.getBytesFromAddress(address); BluetoothDevice device = mAdapterService.getDeviceFromByte(addressBytes); if (DBG) { Log.d(TAG, " onAudioDevicesAdded: " + device + ", device type: " + deviceInfo.getType()); } /* Don't expose already exposed active device */ if (device.equals(mExposedActiveDevice)) { if (DBG) { Log.d(TAG, " onAudioDevicesAdded: " + device + " is already exposed"); } return; } Loading Loading @@ -1103,7 +1070,6 @@ public class A2dpService extends ProfileService { mExposedActiveDevice = null; if (DBG) { Log.d(TAG, " onAudioDevicesRemoved: " + address + ", device type: " + deviceInfo.getType() + ", mActiveDevice: " + mActiveDevice); Loading @@ -1111,13 +1077,10 @@ public class A2dpService extends ProfileService { } } } } @VisibleForTesting void updateAndBroadcastActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "updateAndBroadcastActiveDevice(" + device + ")"); } // Make sure volume has been store before device been remove from active. if (mFactory.getAvrcpTargetService() != null) { Loading @@ -1139,9 +1102,7 @@ public class A2dpService extends ProfileService { } private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { if (DBG) { Log.d(TAG, "broadcastCodecConfig(" + device + "): " + codecStatus); } Intent intent = new Intent(BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED); intent.putExtra(BluetoothCodecStatus.EXTRA_CODEC_STATUS, codecStatus); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); Loading @@ -1166,9 +1127,7 @@ public class A2dpService extends ProfileService { */ @VisibleForTesting void bondStateChanged(BluetoothDevice device, int bondState) { if (DBG) { Log.d(TAG, "Bond state changed for device: " + device + " state: " + bondState); } // Remove state machine if the bonding for a device is removed if (bondState != BluetoothDevice.BOND_NONE) { return; Loading android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +7 −8 Original line number Diff line number Diff line Loading @@ -74,8 +74,7 @@ import java.util.Objects; import java.util.Scanner; final class A2dpStateMachine extends StateMachine { private static final boolean DBG = true; private static final String TAG = "A2dpStateMachine"; private static final String TAG = A2dpStateMachine.class.getSimpleName(); static final int CONNECT = 1; static final int DISCONNECT = 2; Loading Loading @@ -675,7 +674,9 @@ final class A2dpStateMachine extends StateMachine { mCodecStatus = newCodecStatus; } if (DBG) { // The following is a large enough debug operation such that we want to guard it was an // isLoggable check if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "A2DP Codec Config: " + prevCodecConfig + "->" + newCodecStatus.getCodecConfig()); for (BluetoothCodecConfig codecConfig : Loading Loading @@ -872,8 +873,6 @@ final class A2dpStateMachine extends StateMachine { @Override protected void log(String msg) { if (DBG) { super.log(msg); } } } Loading
android/app/src/com/android/bluetooth/a2dp/A2dpCodecConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ import java.util.Objects; * A2DP Codec Configuration setup. */ class A2dpCodecConfig { private static final String TAG = "A2dpCodecConfig"; private static final String TAG = A2dpCodecConfig.class.getSimpleName(); private Context mContext; private A2dpNativeInterface mA2dpNativeInterface; Loading
android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java +5 −14 Original line number Diff line number Diff line Loading @@ -43,8 +43,7 @@ import java.util.Objects; * A2DP Native Interface to/from JNI. */ public class A2dpNativeInterface { private static final String TAG = "A2dpNativeInterface"; private static final boolean DBG = true; private static final String TAG = A2dpNativeInterface.class.getSimpleName(); private BluetoothAdapter mAdapter; private AdapterService mAdapterService; Loading Loading @@ -200,9 +199,7 @@ public class A2dpNativeInterface { event.device = getDevice(address); event.valueInt = state; if (DBG) { Log.d(TAG, "onConnectionStateChanged: " + event); } sendMessageToService(event); } Loading @@ -211,9 +208,7 @@ public class A2dpNativeInterface { event.device = getDevice(address); event.valueInt = state; if (DBG) { Log.d(TAG, "onAudioStateChanged: " + event); } sendMessageToService(event); } Loading @@ -226,9 +221,7 @@ public class A2dpNativeInterface { event.codecStatus = new BluetoothCodecStatus(newCodecConfig, Arrays.asList(codecsLocalCapabilities), Arrays.asList(codecsSelectableCapabilities)); if (DBG) { Log.d(TAG, "onCodecConfigChanged: " + event); } sendMessageToService(event); } Loading @@ -236,9 +229,7 @@ public class A2dpNativeInterface { A2dpService service = A2dpService.getA2dpService(); if (service != null) { int enabled = service.getOptionalCodecsEnabled(getDevice(address)); if (DBG) { Log.d(TAG, "isMandatoryCodecPreferred: optional preference " + enabled); } // Optional codecs are more preferred if possible return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED; } else { Loading
android/app/src/com/android/bluetooth/a2dp/A2dpService.java +24 −65 Original line number Diff line number Diff line Loading @@ -82,7 +82,6 @@ import java.util.concurrent.ConcurrentMap; */ public class A2dpService extends ProfileService { private static final String TAG = A2dpService.class.getSimpleName(); private static final boolean DBG = true; // TODO(b/240635097): remove in U private static final int SOURCE_CODEC_TYPE_OPUS = 6; Loading Loading @@ -183,9 +182,7 @@ public class A2dpService extends ProfileService { // Step 6: Check if A2DP is in offload mode mA2dpOffloadEnabled = mAdapterService.isA2dpOffloadEnabled(); if (DBG) { Log.d(TAG, "A2DP offload flag set to " + mA2dpOffloadEnabled); } // Step 7: Register Audio Device callback mAudioManager.registerAudioDeviceCallback(mAudioManagerAudioDeviceCallback, mHandler); Loading Loading @@ -265,16 +262,12 @@ public class A2dpService extends ProfileService { } private static synchronized void setA2dpService(A2dpService instance) { if (DBG) { Log.d(TAG, "setA2dpService(): set to: " + instance); } sA2dpService = instance; } public boolean connect(BluetoothDevice device) { if (DBG) { Log.d(TAG, "connect(): " + device); } if (getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { Log.e(TAG, "Cannot connect to " + device + " : CONNECTION_POLICY_FORBIDDEN"); Loading Loading @@ -323,9 +316,7 @@ public class A2dpService extends ProfileService { * @return true if profile disconnected, false if device not connected over a2dp */ public boolean disconnect(BluetoothDevice device) { if (DBG) { Log.d(TAG, "disconnect(): " + device); } synchronized (mStateMachines) { A2dpStateMachine sm = mStateMachines.get(device); Loading Loading @@ -525,9 +516,7 @@ public class A2dpService extends ProfileService { */ @VisibleForTesting public boolean setSilenceMode(@NonNull BluetoothDevice device, boolean silence) { if (DBG) { Log.d(TAG, "setSilenceMode(" + device + "): " + silence); } if (silence && Objects.equals(mActiveDevice, device)) { removeActiveDevice(true); } else if (!silence && mActiveDevice == null) { Loading Loading @@ -563,9 +552,7 @@ public class A2dpService extends ProfileService { // returns true since the device is activated even double attempted return true; } if (DBG) { Log.d(TAG, "setActiveDevice(" + device + "): current is " + mActiveDevice); } sm = mStateMachines.get(device); if (sm == null) { Log.e(TAG, "setActiveDevice(" + device + "): Cannot set as active: " Loading @@ -582,9 +569,7 @@ public class A2dpService extends ProfileService { } // Switch from one A2DP to another A2DP device if (DBG) { Log.d(TAG, "Switch A2DP devices to " + device + " from " + previousActiveDevice); } updateLowLatencyAudioSupport(device); Loading Loading @@ -658,9 +643,7 @@ public class A2dpService extends ProfileService { public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) { enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); if (DBG) { Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy); } if (!mDatabaseManager.setProfileConnectionPolicy(device, BluetoothProfile.A2DP, connectionPolicy)) { Loading Loading @@ -698,9 +681,7 @@ public class A2dpService extends ProfileService { } boolean isA2dpPlaying(BluetoothDevice device) { if (DBG) { Log.d(TAG, "isA2dpPlaying(" + device + ")"); } synchronized (mStateMachines) { A2dpStateMachine sm = mStateMachines.get(device); if (sm == null) { Loading @@ -724,9 +705,7 @@ public class A2dpService extends ProfileService { * @return the current codec status */ public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) { if (DBG) { Log.d(TAG, "getCodecStatus(" + device + ")"); } synchronized (mStateMachines) { if (device == null) { device = mActiveDevice; Loading @@ -751,10 +730,8 @@ public class A2dpService extends ProfileService { */ public void setCodecConfigPreference(BluetoothDevice device, BluetoothCodecConfig codecConfig) { if (DBG) { Log.d(TAG, "setCodecConfigPreference(" + device + "): " + Objects.toString(codecConfig)); } if (device == null) { device = mActiveDevice; } Loading @@ -781,9 +758,7 @@ public class A2dpService extends ProfileService { * active A2DP Bluetooth device. */ public void enableOptionalCodecs(BluetoothDevice device) { if (DBG) { Log.d(TAG, "enableOptionalCodecs(" + device + ")"); } if (device == null) { device = mActiveDevice; } Loading Loading @@ -811,9 +786,7 @@ public class A2dpService extends ProfileService { * active A2DP Bluetooth device. */ public void disableOptionalCodecs(BluetoothDevice device) { if (DBG) { Log.d(TAG, "disableOptionalCodecs(" + device + ")"); } if (device == null) { device = mActiveDevice; } Loading Loading @@ -1021,9 +994,7 @@ public class A2dpService extends ProfileService { + MAX_A2DP_STATE_MACHINES); return null; } if (DBG) { Log.d(TAG, "Creating a new state machine for " + device); } sm = A2dpStateMachine.make( device, this, mNativeInterface, mStateMachinesThread.getLooper()); Loading Loading @@ -1055,16 +1026,12 @@ public class A2dpService extends ProfileService { byte[] addressBytes = Utils.getBytesFromAddress(address); BluetoothDevice device = mAdapterService.getDeviceFromByte(addressBytes); if (DBG) { Log.d(TAG, " onAudioDevicesAdded: " + device + ", device type: " + deviceInfo.getType()); } /* Don't expose already exposed active device */ if (device.equals(mExposedActiveDevice)) { if (DBG) { Log.d(TAG, " onAudioDevicesAdded: " + device + " is already exposed"); } return; } Loading Loading @@ -1103,7 +1070,6 @@ public class A2dpService extends ProfileService { mExposedActiveDevice = null; if (DBG) { Log.d(TAG, " onAudioDevicesRemoved: " + address + ", device type: " + deviceInfo.getType() + ", mActiveDevice: " + mActiveDevice); Loading @@ -1111,13 +1077,10 @@ public class A2dpService extends ProfileService { } } } } @VisibleForTesting void updateAndBroadcastActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "updateAndBroadcastActiveDevice(" + device + ")"); } // Make sure volume has been store before device been remove from active. if (mFactory.getAvrcpTargetService() != null) { Loading @@ -1139,9 +1102,7 @@ public class A2dpService extends ProfileService { } private void broadcastCodecConfig(BluetoothDevice device, BluetoothCodecStatus codecStatus) { if (DBG) { Log.d(TAG, "broadcastCodecConfig(" + device + "): " + codecStatus); } Intent intent = new Intent(BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED); intent.putExtra(BluetoothCodecStatus.EXTRA_CODEC_STATUS, codecStatus); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); Loading @@ -1166,9 +1127,7 @@ public class A2dpService extends ProfileService { */ @VisibleForTesting void bondStateChanged(BluetoothDevice device, int bondState) { if (DBG) { Log.d(TAG, "Bond state changed for device: " + device + " state: " + bondState); } // Remove state machine if the bonding for a device is removed if (bondState != BluetoothDevice.BOND_NONE) { return; Loading
android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +7 −8 Original line number Diff line number Diff line Loading @@ -74,8 +74,7 @@ import java.util.Objects; import java.util.Scanner; final class A2dpStateMachine extends StateMachine { private static final boolean DBG = true; private static final String TAG = "A2dpStateMachine"; private static final String TAG = A2dpStateMachine.class.getSimpleName(); static final int CONNECT = 1; static final int DISCONNECT = 2; Loading Loading @@ -675,7 +674,9 @@ final class A2dpStateMachine extends StateMachine { mCodecStatus = newCodecStatus; } if (DBG) { // The following is a large enough debug operation such that we want to guard it was an // isLoggable check if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "A2DP Codec Config: " + prevCodecConfig + "->" + newCodecStatus.getCodecConfig()); for (BluetoothCodecConfig codecConfig : Loading Loading @@ -872,8 +873,6 @@ final class A2dpStateMachine extends StateMachine { @Override protected void log(String msg) { if (DBG) { super.log(msg); } } }