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

Commit 65402207 authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Fix Java style in LeAudioService.java

Bug: 238062347
Tag: #refactor
Test: none
Change-Id: If7f3c4a306fdae4983adbe8dd59185e067c5e288
parent 792d7f32
Loading
Loading
Loading
Loading
+106 −113
Original line number Original line Diff line number Diff line
@@ -155,8 +155,7 @@ public class LeAudioService extends ProfileService {
    private final Map<BluetoothDevice, Integer> mDeviceAudioLocationMap = new ConcurrentHashMap<>();
    private final Map<BluetoothDevice, Integer> mDeviceAudioLocationMap = new ConcurrentHashMap<>();


    private final int mContextSupportingInputAudio =
    private final int mContextSupportingInputAudio =
            BluetoothLeAudio.CONTEXT_TYPE_COMMUNICATION |
            BluetoothLeAudio.CONTEXT_TYPE_COMMUNICATION | BluetoothLeAudio.CONTEXT_TYPE_MAN_MACHINE;
            BluetoothLeAudio.CONTEXT_TYPE_MAN_MACHINE;


    private final int mContextSupportingOutputAudio = BluetoothLeAudio.CONTEXT_TYPE_COMMUNICATION |
    private final int mContextSupportingOutputAudio = BluetoothLeAudio.CONTEXT_TYPE_COMMUNICATION |
            BluetoothLeAudio.CONTEXT_TYPE_MEDIA |
            BluetoothLeAudio.CONTEXT_TYPE_MEDIA |
@@ -768,8 +767,7 @@ public class LeAudioService extends ProfileService {
    }
    }


    private boolean updateActiveInDevice(BluetoothDevice device, Integer groupId,
    private boolean updateActiveInDevice(BluetoothDevice device, Integer groupId,
                                            Integer oldActiveContexts,
            Integer oldActiveContexts, Integer newActiveContexts) {
                                            Integer newActiveContexts) {
        Integer oldSupportedAudioDirections =
        Integer oldSupportedAudioDirections =
                getAudioDirectionsFromActiveContextsMap(oldActiveContexts);
                getAudioDirectionsFromActiveContextsMap(oldActiveContexts);
        Integer newSupportedAudioDirections =
        Integer newSupportedAudioDirections =
@@ -833,8 +831,7 @@ public class LeAudioService extends ProfileService {
    }
    }


    private boolean updateActiveOutDevice(BluetoothDevice device, Integer groupId,
    private boolean updateActiveOutDevice(BluetoothDevice device, Integer groupId,
                                       Integer oldActiveContexts,
            Integer oldActiveContexts, Integer newActiveContexts) {
                                       Integer newActiveContexts) {
        Integer oldSupportedAudioDirections =
        Integer oldSupportedAudioDirections =
                getAudioDirectionsFromActiveContextsMap(oldActiveContexts);
                getAudioDirectionsFromActiveContextsMap(oldActiveContexts);
        Integer newSupportedAudioDirections =
        Integer newSupportedAudioDirections =
@@ -1079,9 +1076,9 @@ public class LeAudioService extends ProfileService {
                     * To improve scenario when lead Le Audio device is disconnected for the
                     * To improve scenario when lead Le Audio device is disconnected for the
                     * streaming group, while there are still other devices streaming,
                     * streaming group, while there are still other devices streaming,
                     * LeAudioService will not notify audio framework or other users about
                     * LeAudioService will not notify audio framework or other users about
                    * Le Audio lead device disconnection. Instead we try to reconnect under the hood
                     * Le Audio lead device disconnection. Instead we try to reconnect under
                    * and keep using lead device as a audio device indetifier in the audio framework
                     * the hood and keep using lead device as a audio device indetifier in
                    * in order to not stop the stream.
                     * the audio framework in order to not stop the stream.
                     */
                     */
                    int groupId = getGroupId(device);
                    int groupId = getGroupId(device);
                    synchronized (mGroupLock) {
                    synchronized (mGroupLock) {
@@ -1222,8 +1219,7 @@ public class LeAudioService extends ProfileService {
                    if (descriptor != null) {
                    if (descriptor != null) {
                        if (!descriptor.mIsActive) {
                        if (!descriptor.mIsActive) {
                            descriptor.mIsActive = updateActiveDevices(groupId,
                            descriptor.mIsActive = updateActiveDevices(groupId,
                                                ACTIVE_CONTEXTS_NONE,
                                    ACTIVE_CONTEXTS_NONE, descriptor.mActiveContexts, true);
                                                descriptor.mActiveContexts, true);
                            notifyGroupStatus = descriptor.mIsActive;
                            notifyGroupStatus = descriptor.mIsActive;
                        }
                        }
                    } else {
                    } else {
@@ -1472,8 +1468,7 @@ public class LeAudioService extends ProfileService {
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    synchronized void connectionStateChanged(BluetoothDevice device, int fromState,
    synchronized void connectionStateChanged(BluetoothDevice device, int fromState, int toState) {
                                                     int toState) {
        if ((device == null) || (fromState == toState)) {
        if ((device == null) || (fromState == toState)) {
            Log.e(TAG, "connectionStateChanged: unexpected invocation. device=" + device
            Log.e(TAG, "connectionStateChanged: unexpected invocation. device=" + device
                    + " fromState=" + fromState + " toState=" + toState);
                    + " fromState=" + fromState + " toState=" + toState);
@@ -1529,9 +1524,8 @@ public class LeAudioService extends ProfileService {


            List<BluetoothDevice> connectedDevices = getConnectedPeerDevices(myGroupId);
            List<BluetoothDevice> connectedDevices = getConnectedPeerDevices(myGroupId);
            /* Let's check if the last connected device is really connected */
            /* Let's check if the last connected device is really connected */
            if (connectedDevices.size() == 1
            if (connectedDevices.size() == 1 && Objects.equals(
                    && Objects.equals(connectedDevices.get(0),
                    connectedDevices.get(0), descriptor.mLostLeadDeviceWhileStreaming)) {
                            descriptor.mLostLeadDeviceWhileStreaming)) {
                clearLostDevicesWhileStreaming(descriptor);
                clearLostDevicesWhileStreaming(descriptor);
                return;
                return;
            }
            }
@@ -1825,8 +1819,7 @@ public class LeAudioService extends ProfileService {
        }
        }
    }
    }


    private void notifyUnicastCodecConfigChanged(int groupId,
    private void notifyUnicastCodecConfigChanged(int groupId, BluetoothLeAudioCodecStatus status) {
                                                 BluetoothLeAudioCodecStatus status) {
        if (mLeAudioCallbacks != null) {
        if (mLeAudioCallbacks != null) {
            int n = mLeAudioCallbacks.beginBroadcast();
            int n = mLeAudioCallbacks.beginBroadcast();
            for (int i = 0; i < n; i++) {
            for (int i = 0; i < n; i++) {
@@ -2033,8 +2026,8 @@ public class LeAudioService extends ProfileService {
            return;
            return;
        }
        }


        mLeAudioNativeInterface.setCodecConfigPreference(groupId,
        mLeAudioNativeInterface.setCodecConfigPreference(
                                inputCodecConfig, outputCodecConfig);
                groupId, inputCodecConfig, outputCodecConfig);
    }
    }


    /**
    /**
@@ -2073,11 +2066,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                boolean defaultValue = false;
                boolean result = false;
                if (service != null) {
                if (service != null) {
                    defaultValue = service.connect(device);
                    result = service.connect(device);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2092,11 +2085,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                boolean defaultValue = false;
                boolean result = false;
                if (service != null) {
                if (service != null) {
                    defaultValue = service.disconnect(device);
                    result = service.disconnect(device);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2110,11 +2103,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<>(0);
                List<BluetoothDevice> result = new ArrayList<>(0);
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getConnectedDevices();
                    result = service.getConnectedDevices();
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2128,11 +2121,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                BluetoothDevice defaultValue = null;
                BluetoothDevice result = null;
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getConnectedGroupLeadDevice(groupId);
                    result = service.getConnectedGroupLeadDevice(groupId);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2146,11 +2139,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<>(0);
                List<BluetoothDevice> result = new ArrayList<>(0);
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getDevicesMatchingConnectionStates(states);
                    result = service.getDevicesMatchingConnectionStates(states);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2165,11 +2158,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                int defaultValue = BluetoothProfile.STATE_DISCONNECTED;
                int result = BluetoothProfile.STATE_DISCONNECTED;
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getConnectionState(device);
                    result = service.getConnectionState(device);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2184,11 +2177,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                boolean defaultValue = false;
                boolean result = false;
                if (service != null) {
                if (service != null) {
                    defaultValue = service.setActiveDevice(device);
                    result = service.setActiveDevice(device);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2201,11 +2194,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<>();
                List<BluetoothDevice> result = new ArrayList<>();
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getActiveDevices();
                    result = service.getActiveDevices();
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2220,11 +2213,11 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                int defaultValue = BluetoothLeAudio.AUDIO_LOCATION_INVALID;
                int result = BluetoothLeAudio.AUDIO_LOCATION_INVALID;
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getAudioLocation(device);
                    result = service.getAudioLocation(device);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2239,11 +2232,11 @@ public class LeAudioService extends ProfileService {


            try {
            try {
                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                boolean defaultValue = false;
                boolean result = false;
                if (service != null) {
                if (service != null) {
                    defaultValue = service.setConnectionPolicy(device, connectionPolicy);
                    result = service.setConnectionPolicy(device, connectionPolicy);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2258,13 +2251,13 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                int defaultValue = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
                int result = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
                if (service == null) {
                if (service == null) {
                    throw new IllegalStateException("service is null");
                    throw new IllegalStateException("service is null");
                }
                }
                enforceBluetoothPrivilegedPermission(service);
                enforceBluetoothPrivilegedPermission(service);
                defaultValue = service.getConnectionPolicy(device);
                result = service.getConnectionPolicy(device);
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2300,13 +2293,13 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                int defaultValue = LE_AUDIO_GROUP_ID_INVALID;
                int result = LE_AUDIO_GROUP_ID_INVALID;
                if (service == null) {
                if (service == null) {
                    throw new IllegalStateException("service is null");
                    throw new IllegalStateException("service is null");
                }
                }
                enforceBluetoothPrivilegedPermission(service);
                enforceBluetoothPrivilegedPermission(service);
                defaultValue = service.getGroupId(device);
                result = service.getGroupId(device);
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2321,13 +2314,13 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                boolean defaultValue = false;
                boolean result = false;
                if (service == null) {
                if (service == null) {
                    throw new IllegalStateException("service is null");
                    throw new IllegalStateException("service is null");
                }
                }
                enforceBluetoothPrivilegedPermission(service);
                enforceBluetoothPrivilegedPermission(service);
                defaultValue = service.groupAddNode(group_id, device);
                result = service.groupAddNode(group_id, device);
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2342,13 +2335,13 @@ public class LeAudioService extends ProfileService {
                Objects.requireNonNull(receiver, "receiver cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");


                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                boolean defaultValue = false;
                boolean result = false;
                if (service == null) {
                if (service == null) {
                    throw new IllegalStateException("service is null");
                    throw new IllegalStateException("service is null");
                }
                }
                enforceBluetoothPrivilegedPermission(service);
                enforceBluetoothPrivilegedPermission(service);
                defaultValue = service.groupRemoveNode(groupId, device);
                result = service.groupRemoveNode(groupId, device);
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2489,12 +2482,12 @@ public class LeAudioService extends ProfileService {
        public void isPlaying(int broadcastId, AttributionSource source,
        public void isPlaying(int broadcastId, AttributionSource source,
                SynchronousResultReceiver receiver) {
                SynchronousResultReceiver receiver) {
            try {
            try {
                boolean defaultValue = false;
                boolean result = false;
                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                if (service != null) {
                if (service != null) {
                    defaultValue = service.isPlaying(broadcastId);
                    result = service.isPlaying(broadcastId);
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2504,12 +2497,12 @@ public class LeAudioService extends ProfileService {
        public void getAllBroadcastMetadata(AttributionSource source,
        public void getAllBroadcastMetadata(AttributionSource source,
                SynchronousResultReceiver receiver) {
                SynchronousResultReceiver receiver) {
            try {
            try {
                List<BluetoothLeBroadcastMetadata> defaultValue = new ArrayList<>();
                List<BluetoothLeBroadcastMetadata> result = new ArrayList<>();
                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getAllBroadcastMetadata();
                    result = service.getAllBroadcastMetadata();
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }
@@ -2519,12 +2512,12 @@ public class LeAudioService extends ProfileService {
        public void getMaximumNumberOfBroadcasts(AttributionSource source,
        public void getMaximumNumberOfBroadcasts(AttributionSource source,
                SynchronousResultReceiver receiver) {
                SynchronousResultReceiver receiver) {
            try {
            try {
                int defaultValue = 0;
                int result = 0;
                LeAudioService service = getService(source);
                LeAudioService service = getService(source);
                if (service != null) {
                if (service != null) {
                    defaultValue = service.getMaximumNumberOfBroadcasts();
                    result = service.getMaximumNumberOfBroadcasts();
                }
                }
                receiver.send(defaultValue);
                receiver.send(result);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
                receiver.propagateException(e);
                receiver.propagateException(e);
            }
            }