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

Commit 6d8c9821 authored by William Escande's avatar William Escande
Browse files

Inline getCdmAssociations

Test: m .
Bug: 311772251
Flag: Exempt, Mechanical refactor
Change-Id: Iecf9e9e70143c43ac74b44a97cf2a1787827156d
parent f3adac7a
Loading
Loading
Loading
Loading
+12 −20
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ 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.ExecutorService;
@@ -472,39 +471,32 @@ public final class Utils {
                    + " is inaccurate for calling uid " + callingUid);
        }

        for (AssociationInfo association : getCdmAssociations(cdm)) {
        for (AssociationInfo association : cdm.getAllAssociations()) {
            if (association.getPackageName().equals(callingPackage)
                    && !association.isSelfManaged() && device.getAddress() != null
                    && !association.isSelfManaged()
                    && device.getAddress() != null
                    && association.getDeviceMacAddress() != null
                    && device.getAddress().equalsIgnoreCase(
                            association.getDeviceMacAddress().toString())) {
                    && device.getAddress()
                            .equalsIgnoreCase(association.getDeviceMacAddress().toString())) {
                return true;
            }
        }
        throw new SecurityException("The application with package name " + callingPackage
        throw new SecurityException(
                "The application with package name "
                        + callingPackage
                        + " 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")
    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
     * @param callingPackage the calling application package name
     * @param callingUid the calling application uid
     * @return {@code true} if the package name matches the calling app uid, {@code false} otherwise
     */
    public static boolean isPackageNameAccurate(Context context, String callingPackage,
            int callingUid) {
    public static boolean isPackageNameAccurate(
            Context context, String callingPackage, int callingUid) {
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);

        // Verifies the integrity of the calling package name
+1 −1
Original line number Diff line number Diff line
@@ -1097,7 +1097,7 @@ public class TransitionalScanHelper {

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