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

Commit 9aa56293 authored by William Escande's avatar William Escande
Browse files

ErrorProne: Enforce & fix NonCanonicalType

See https://errorprone.info/bugpattern/NonCanonicalType

Bug: 344658662
Test: m BluetoothInstrumentationTests
Flag: Exempt Build and test only
Change-Id: I6cc9d6d9b22959b5d35f1b90ff263b1b9f41709b
parent f2c264c3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -327,6 +327,7 @@ android_app {
            "-Xep:InvalidBlockTag:ERROR",
            "-Xep:InvalidParam:ERROR",
            "-Xep:MockNotUsedInProduction:ERROR",
            "-Xep:NonCanonicalType:ERROR",
            "-Xep:ReturnAtTheEndOfVoidFunction:ERROR",
            "-Xep:UnusedMethod:ERROR",
            "-Xep:UnusedVariable:ERROR",
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public class ContextMap<C, T> {
        /** Context information */
        public T info;

        /** Death receipient */
        /** Death recipient */
        private IBinder.DeathRecipient mDeathRecipient;

        /** Flag to signal that transport is congested */
+33 −33
Original line number Diff line number Diff line
@@ -1248,7 +1248,7 @@ public class GattService extends ProfileService {
            throws RemoteException {
        UUID uuid = new UUID(uuidMsb, uuidLsb);
        Log.d(TAG, "onClientRegistered() - UUID=" + uuid + ", clientIf=" + clientIf);
        ClientMap.App app = mClientMap.getByUuid(uuid);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByUuid(uuid);
        if (app != null) {
            if (status == 0) {
                app.id = clientIf;
@@ -1280,7 +1280,7 @@ public class GattService extends ProfileService {
            }
            connectionState = BluetoothProtoEnums.CONNECTION_STATE_CONNECTED;
        }
        ClientMap.App app = mClientMap.getById(clientIf);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getById(clientIf);
        if (app != null) {
            app.callback.onClientConnectionState(
                    status, clientIf, (status == BluetoothGatt.GATT_SUCCESS), address);
@@ -1301,7 +1301,7 @@ public class GattService extends ProfileService {
                        + address);

        mClientMap.removeConnection(clientIf, connId);
        ClientMap.App app = mClientMap.getById(clientIf);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getById(clientIf);

        if (Flags.gattCleanupRestrictedHandles()) {
            mRestrictedHandles.remove(connId);
@@ -1342,7 +1342,7 @@ public class GattService extends ProfileService {
            return;
        }

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1367,7 +1367,7 @@ public class GattService extends ProfileService {
            return;
        }

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1384,7 +1384,7 @@ public class GattService extends ProfileService {
            return;
        }

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1400,7 +1400,7 @@ public class GattService extends ProfileService {
            return;
        }

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1418,7 +1418,7 @@ public class GattService extends ProfileService {
            return;
        }

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1434,7 +1434,7 @@ public class GattService extends ProfileService {
            return;
        }

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1452,7 +1452,7 @@ public class GattService extends ProfileService {
            return;
        }

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1469,7 +1469,7 @@ public class GattService extends ProfileService {
            return;
        }

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1487,7 +1487,7 @@ public class GattService extends ProfileService {
            return;
        }

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1521,7 +1521,7 @@ public class GattService extends ProfileService {

        Log.d(TAG, "onGetGattDb() - address=" + address);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app == null || app.callback == null) {
            Log.e(TAG, "app or callback is null");
            return;
@@ -1631,7 +1631,7 @@ public class GattService extends ProfileService {
                        + ", length="
                        + data.length);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app != null) {
            try {
                permissionCheck(connId, handle);
@@ -1660,7 +1660,7 @@ public class GattService extends ProfileService {
                        + ", length="
                        + data.length);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app != null) {
            app.callback.onCharacteristicRead(address, status, handle, data);
        }
@@ -1683,7 +1683,7 @@ public class GattService extends ProfileService {
                        + ", length="
                        + data.length);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -1707,7 +1707,7 @@ public class GattService extends ProfileService {
        String address = mClientMap.addressByConnId(connId);
        Log.v(TAG, "onExecuteCompleted() - address=" + address + ", status=" + status);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app != null) {
            app.callback.onExecuteWrite(address, status);
        }
@@ -1725,7 +1725,7 @@ public class GattService extends ProfileService {
                        + ", length="
                        + data.length);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app != null) {
            app.callback.onDescriptorRead(address, status, handle, data);
        }
@@ -1743,7 +1743,7 @@ public class GattService extends ProfileService {
                        + ", length="
                        + data.length);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app != null) {
            app.callback.onDescriptorWrite(address, status, handle, data);
        }
@@ -1762,7 +1762,7 @@ public class GattService extends ProfileService {
                        + ", status="
                        + status);

        ClientMap.App app = mClientMap.getById(clientIf);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getById(clientIf);
        if (app != null) {
            app.callback.onReadRemoteRssi(address, rssi, status);
        }
@@ -1773,7 +1773,7 @@ public class GattService extends ProfileService {

        Log.d(TAG, "onConfigureMTU() address=" + address + ", status=" + status + ", mtu=" + mtu);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);
        if (app != null) {
            app.callback.onConfigureMTU(address, mtu, status);
        }
@@ -1782,7 +1782,7 @@ public class GattService extends ProfileService {
    void onClientCongestion(int connId, boolean congested) throws RemoteException {
        Log.v(TAG, "onClientCongestion() - connId=" + connId + ", congested=" + congested);

        ClientMap.App app = mClientMap.getByConnId(connId);
        ContextMap<IBluetoothGattCallback, Void>.App app = mClientMap.getByConnId(connId);

        if (app != null) {
            app.isCongested = congested;
@@ -2726,7 +2726,7 @@ public class GattService extends ProfileService {

        UUID uuid = new UUID(uuidMsb, uuidLsb);
        Log.d(TAG, "onServerRegistered() - UUID=" + uuid + ", serverIf=" + serverIf);
        ServerMap.App app = mServerMap.getByUuid(uuid);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByUuid(uuid);
        if (app != null) {
            app.id = serverIf;
            app.linkToDeath(new ServerDeathRecipient(serverIf, app.name));
@@ -2790,7 +2790,7 @@ public class GattService extends ProfileService {
        }
        mHandleMap.setStarted(serverIf, srvcHandle, true);

        ServerMap.App app = mServerMap.getById(serverIf);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getById(serverIf);
        if (app != null) {
            app.callback.onServiceAdded(status, svc);
        }
@@ -2821,7 +2821,7 @@ public class GattService extends ProfileService {
                        + ", connected="
                        + connected);

        ServerMap.App app = mServerMap.getById(serverIf);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getById(serverIf);
        if (app == null) {
            return;
        }
@@ -2873,7 +2873,7 @@ public class GattService extends ProfileService {

        mHandleMap.addRequest(transId, handle);

        ServerMap.App app = mServerMap.getById(entry.serverIf);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getById(entry.serverIf);
        if (app == null) {
            return;
        }
@@ -2904,7 +2904,7 @@ public class GattService extends ProfileService {

        mHandleMap.addRequest(transId, handle);

        ServerMap.App app = mServerMap.getById(entry.serverIf);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getById(entry.serverIf);
        if (app == null) {
            return;
        }
@@ -2945,7 +2945,7 @@ public class GattService extends ProfileService {

        mHandleMap.addRequest(transId, handle);

        ServerMap.App app = mServerMap.getById(entry.serverIf);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getById(entry.serverIf);
        if (app == null) {
            return;
        }
@@ -2987,7 +2987,7 @@ public class GattService extends ProfileService {

        mHandleMap.addRequest(transId, handle);

        ServerMap.App app = mServerMap.getById(entry.serverIf);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getById(entry.serverIf);
        if (app == null) {
            return;
        }
@@ -3007,7 +3007,7 @@ public class GattService extends ProfileService {
                        + ", transId="
                        + transId);

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -3027,7 +3027,7 @@ public class GattService extends ProfileService {
            return;
        }

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -3045,7 +3045,7 @@ public class GattService extends ProfileService {
    void onServerCongestion(int connId, boolean congested) throws RemoteException {
        Log.d(TAG, "onServerCongestion() - connId=" + connId + ", congested=" + congested);

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
@@ -3068,7 +3068,7 @@ public class GattService extends ProfileService {
            return;
        }

        ServerMap.App app = mServerMap.getByConnId(connId);
        ContextMap<IBluetoothGattServerCallback, Void>.App app = mServerMap.getByConnId(connId);
        if (app == null) {
            return;
        }
+13 −8
Original line number Diff line number Diff line
@@ -375,7 +375,8 @@ public class TransitionalScanHelper {
        byte[] legacyAdvData = Arrays.copyOfRange(advData, 0, 62);

        for (ScanClient client : mScanManager.getRegularScanQueue()) {
            ScannerMap.App app = mScannerMap.getById(client.scannerId);
            ContextMap<IScannerCallback, PendingIntentInfo>.App app =
                    mScannerMap.getById(client.scannerId);
            if (app == null) {
                Log.v(TAG, "App is null; skip.");
                continue;
@@ -523,7 +524,7 @@ public class TransitionalScanHelper {
                        + status);

        // First check the callback map
        ScannerMap.App cbApp = mScannerMap.getByUuid(uuid);
        ContextMap<IScannerCallback, PendingIntentInfo>.App cbApp = mScannerMap.getByUuid(uuid);
        if (cbApp != null) {
            if (status == 0) {
                cbApp.id = scannerId;
@@ -697,7 +698,8 @@ public class TransitionalScanHelper {
        Set<ScanResult> results = parseBatchScanResults(numRecords, reportType, recordData);
        if (reportType == ScanManager.SCAN_RESULT_TYPE_TRUNCATED) {
            // We only support single client for truncated mode.
            ScannerMap.App app = mScannerMap.getById(scannerId);
            ContextMap<IScannerCallback, PendingIntentInfo>.App app =
                    mScannerMap.getById(scannerId);
            if (app == null) {
                return;
            }
@@ -749,7 +751,9 @@ public class TransitionalScanHelper {
    }

    private void sendBatchScanResults(
            ScannerMap.App app, ScanClient client, ArrayList<ScanResult> results) {
            ContextMap<IScannerCallback, PendingIntentInfo>.App app,
            ScanClient client,
            ArrayList<ScanResult> results) {
        try {
            if (app.callback != null) {
                if (mScanManager.isAutoBatchScanClientEnabled(client)) {
@@ -960,8 +964,8 @@ public class TransitionalScanHelper {
                        + " adv_state = "
                        + trackingInfo.getAdvState());

        @SuppressWarnings("NonCanonicalType")
        ScannerMap.App app = mScannerMap.getById(trackingInfo.getClientIf());
        ContextMap<IScannerCallback, PendingIntentInfo>.App app =
                mScannerMap.getById(trackingInfo.getClientIf());
        if (app == null || (app.callback == null && app.info == null)) {
            Log.e(TAG, "app or callback is null");
            return;
@@ -1031,7 +1035,7 @@ public class TransitionalScanHelper {

    // callback from ScanManager for dispatch of errors apps.
    public void onScanManagerErrorCallback(int scannerId, int errorCode) throws RemoteException {
        ScannerMap.App app = mScannerMap.getById(scannerId);
        ContextMap<IScannerCallback, PendingIntentInfo>.App app = mScannerMap.getById(scannerId);
        if (app == null || (app.callback == null && app.info == null)) {
            Log.e(TAG, "App or callback is null");
            return;
@@ -1260,7 +1264,8 @@ public class TransitionalScanHelper {
        }
    }

    public void continuePiStartScan(int scannerId, ScannerMap.App app) {
    public void continuePiStartScan(
            int scannerId, ContextMap<IScannerCallback, PendingIntentInfo>.App app) {
        final PendingIntentInfo piInfo = app.info;
        final ScanClient scanClient =
                new ScanClient(scannerId, piInfo.settings, piInfo.filters, piInfo.callingUid);
+2 −1
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

class MapClientContent {
@@ -328,7 +329,7 @@ class MapClientContent {
                }
            }
        }
        for (HashMap.Entry record : duplicateUriToHandleMap.entrySet()) {
        for (Map.Entry record : duplicateUriToHandleMap.entrySet()) {
            verbose("Deleted " + ((MessageStatus) record.getValue()).mHandle);
            originalUriToHandleMap.remove(record.getKey());
            mCallbacks.onMessageStatusChanged(
Loading