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

Commit 3ff4daa7 authored by Igor Chernyshev's avatar Igor Chernyshev
Browse files

Ignore incorrect NewApi Lint warning for CDM getAllAssociations()

CDM.getAllAssociations() is made public (was SystemApi)
and linter will wrongly flag it as [NewApi] so we have to
update the RequireApi and add a SuppressLint.

Bug: 245972418
Bug: 193460475

Tag: #feature

Test: atest FrameworkBluetoothTests

Change-Id: I6fda55ee223db8c0e80b50e53b05fd7b8cd4eb37
parent 0eddf9d8
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ import android.provider.DeviceConfig;
import android.provider.Telephony;
import android.util.Log;

import androidx.annotation.RequiresApi;

import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;

@@ -76,6 +78,7 @@ import java.nio.charset.CharsetDecoder;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -350,7 +353,7 @@ public final class Utils {
                    + " is inaccurate for calling uid " + callingUid);
        }

        for (AssociationInfo association : cdm.getAllAssociations()) {
        for (AssociationInfo association : getCdmAssociations(cdm)) {
            if (association.getPackageName().equals(callingPackage)
                    && !association.isSelfManaged() && device.getAddress() != null
                    && association.getDeviceMacAddress() != null
@@ -363,6 +366,22 @@ public final class Utils {
                + " does not have a CDM association with the Bluetooth Device");
    }

    /**
     * Obtains the complete list of registered CDM associations.
     *
     * @param cdm the CompanionDeviceManager object
     * @return the list of AssociationInfo objects
     */
    @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES")
    @RequiresApi(Build.VERSION_CODES.TIRAMISU)
    // TODO(b/193460475): Android Lint handles change from SystemApi to public incorrectly.
    // CompanionDeviceManager#getAllAssociations() is public in U,
    // but existed in T as an identical SystemApi.
    @SuppressLint("NewApi")
    public static List<AssociationInfo> getCdmAssociations(CompanionDeviceManager cdm) {
        return cdm.getAllAssociations();
    }

    /**
     * Verifies whether the calling package name matches the calling app uid
     * @param context the Bluetooth AdapterService context
+1 −1
Original line number Diff line number Diff line
@@ -2967,7 +2967,7 @@ public class GattService extends ProfileService {

        final long identity = Binder.clearCallingIdentity();
        try {
            for (AssociationInfo info : mCompanionManager.getAllAssociations()) {
            for (AssociationInfo info : Utils.getCdmAssociations(mCompanionManager)) {
                if (info.getPackageName().equals(callingPackage) && !info.isSelfManaged()
                    && info.getDeviceMacAddress() != null) {
                    macAddresses.add(info.getDeviceMacAddress().toString());