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

Commit e2af21c9 authored by William Escande's avatar William Escande
Browse files

Errorprone fix & enforce MixedMutabilityReturnType

Bug: 344658662
Test: m Bluetooth
Flag: Exempt: addressing warning only
Change-Id: I391c752eeb5ce6127992e2cb5bb85a29995f4ea4
parent f078dac3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -342,6 +342,7 @@ android_app {
            "-Xep:InvalidParam:ERROR",
            "-Xep:LoopOverCharArray:ERROR",
            "-Xep:MissingCasesInEnumSwitch:ERROR",
            "-Xep:MixedMutabilityReturnType:ERROR",
            "-Xep:MockNotUsedInProduction:ERROR",
            "-Xep:ModifyCollectionInEnhancedForLoop:ERROR",
            "-Xep:NarrowCalculation:ERROR",
+4 −8
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ import java.util.Optional;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/** Broadcast Assistant Scan Service */
public class BassClientService extends ProfileService {
@@ -3059,14 +3060,9 @@ public class BassClientService extends ProfileService {
                log("stateMachine is null");
                return Collections.emptyList();
            }
            List<BluetoothLeBroadcastReceiveState> recvStates =
                    new ArrayList<BluetoothLeBroadcastReceiveState>();
            for (BluetoothLeBroadcastReceiveState rs : stateMachine.getAllSources()) {
                if (!isEmptyBluetoothDevice(rs.getSourceDevice())) {
                    recvStates.add(rs);
                }
            }
            return recvStates;
            return stateMachine.getAllSources().stream()
                    .filter(rs -> !isEmptyBluetoothDevice(rs.getSourceDevice()))
                    .collect(Collectors.toList());
        }
    }

+3 −2
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.util.proto.ProtoOutputStream;

import androidx.annotation.RequiresApi;

import com.android.bluetooth.bass_client.BassConstants;
import com.android.bluetooth.BluetoothMetricsProto.BluetoothLog;
import com.android.bluetooth.BluetoothMetricsProto.BluetoothRemoteDeviceInformation;
import com.android.bluetooth.BluetoothMetricsProto.ProfileConnectionStats;
@@ -36,6 +35,7 @@ import com.android.bluetooth.BluetoothMetricsProto.ProfileId;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.BtRestrictedStatsLog;
import com.android.bluetooth.Utils;
import com.android.bluetooth.bass_client.BassConstants;
import com.android.modules.utils.build.SdkLevel;

import com.google.common.annotations.VisibleForTesting;
@@ -411,7 +411,8 @@ public class MetricsLogger {
            }
        }

        return wordBreakdownList;
        // Prevent returning a mutable list
        return Collections.unmodifiableList(wordBreakdownList);
    }

    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
+14 −22
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/** Provides Bluetooth Gatt profile, as a service in the Bluetooth application. */
public class GattService extends ProfileService {
@@ -1872,18 +1874,10 @@ public class GattService extends ProfileService {
        }

        // Create matching device sub-set

        List<BluetoothDevice> deviceList = new ArrayList<>();

        for (Map.Entry<BluetoothDevice, Integer> entry : deviceStates.entrySet()) {
            for (int state : states) {
                if (entry.getValue() == state) {
                    deviceList.add(entry.getKey());
                }
            }
        }

        return deviceList;
        return deviceStates.entrySet().stream()
                .filter(e -> Arrays.stream(states).anyMatch(s -> s == e.getValue()))
                .map(Map.Entry::getKey)
                .collect(Collectors.toList());
    }

    @RequiresPermission(BLUETOOTH_CONNECT)
@@ -2213,11 +2207,9 @@ public class GattService extends ProfileService {
                this, attributionSource, "GattService getRegisteredServiceUuids")) {
            return Collections.emptyList();
        }
        List<ParcelUuid> serviceUuids = new ArrayList<>();
        for (HandleMap.Entry entry : mHandleMap.getEntries()) {
            serviceUuids.add(new ParcelUuid(entry.uuid));
        }
        return serviceUuids;
        return mHandleMap.getEntries().stream()
                .map(entry -> new ParcelUuid(entry.uuid))
                .collect(Collectors.toList());
    }

    @RequiresPermission(BLUETOOTH_CONNECT)
@@ -2227,11 +2219,11 @@ public class GattService extends ProfileService {
            return Collections.emptyList();
        }

        Set<String> connectedDevAddress = new HashSet<>();
        connectedDevAddress.addAll(mClientMap.getConnectedDevices());
        connectedDevAddress.addAll(mServerMap.getConnectedDevices());
        List<String> connectedDeviceList = new ArrayList<>(connectedDevAddress);
        return connectedDeviceList;
        return Stream.concat(
                        mClientMap.getConnectedDevices().stream(),
                        mServerMap.getConnectedDevices().stream())
                .distinct()
                .collect(Collectors.toList());
    }

    @RequiresPermission(BLUETOOTH_CONNECT)
+11 −10
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * A helper class which contains all scan related functions extracted from {@link
@@ -1107,17 +1108,17 @@ public class TransitionalScanHelper {
            return Collections.emptyList();
        }

        List<String> macAddresses = new ArrayList();

        final long identity = Binder.clearCallingIdentity();
        try {
            for (AssociationInfo info : mCompanionManager.getAllAssociations()) {
                if (info.getPackageName().equals(callingPackage)
            return mCompanionManager.getAllAssociations().stream()
                    .filter(
                            info ->
                                    info.getPackageName().equals(callingPackage)
                                            && !info.isSelfManaged()
                        && info.getDeviceMacAddress() != null) {
                    macAddresses.add(info.getDeviceMacAddress().toString());
                }
            }
                                            && info.getDeviceMacAddress() != null)
                    .map(AssociationInfo::getDeviceMacAddress)
                    .map(MacAddress::toString)
                    .collect(Collectors.toList());
        } catch (SecurityException se) {
            // Not an app with associated devices
        } catch (Exception e) {
@@ -1125,7 +1126,7 @@ public class TransitionalScanHelper {
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
        return macAddresses;
        return Collections.emptyList();
    }

    @RequiresPermission(BLUETOOTH_SCAN)