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

Commit e45a7adb authored by Sal Savage's avatar Sal Savage Committed by Automerger Merge Worker
Browse files

Merge "Refactor A2DP Source logging to be unguarded" into main am: ddf02df6 am: 0c0bec26

parents d7782164 0c0bec26
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
+5 −14
Original line number Diff line number Diff line
@@ -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;

@@ -200,9 +199,7 @@ public class A2dpNativeInterface {
        event.device = getDevice(address);
        event.valueInt = state;

        if (DBG) {
        Log.d(TAG, "onConnectionStateChanged: " + event);
        }
        sendMessageToService(event);
    }

@@ -211,9 +208,7 @@ public class A2dpNativeInterface {
        event.device = getDevice(address);
        event.valueInt = state;

        if (DBG) {
        Log.d(TAG, "onAudioStateChanged: " + event);
        }
        sendMessageToService(event);
    }

@@ -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);
    }

@@ -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 {
+24 −65
Original line number Diff line number Diff line
@@ -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;
@@ -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);
@@ -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");
@@ -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);
@@ -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) {
@@ -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: "
@@ -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);

@@ -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)) {
@@ -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) {
@@ -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;
@@ -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;
        }
@@ -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;
        }
@@ -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;
        }
@@ -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());
@@ -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;
                    }

@@ -1103,7 +1070,6 @@ public class A2dpService extends ProfileService {

                    mExposedActiveDevice = null;

                    if (DBG) {
                    Log.d(TAG, " onAudioDevicesRemoved: " + address + ", device type: "
                            + deviceInfo.getType()
                            + ", mActiveDevice: " + mActiveDevice);
@@ -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) {
@@ -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);
@@ -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;
+7 −8
Original line number Diff line number Diff line
@@ -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;
@@ -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 :
@@ -872,8 +873,6 @@ final class A2dpStateMachine extends StateMachine {

    @Override
    protected void log(String msg) {
        if (DBG) {
        super.log(msg);
    }
}
}