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

Commit a349d7a9 authored by Kihong Seong's avatar Kihong Seong
Browse files

Handle null identity address in BluetoothOppHandoverReceiver and

AdapterProperties

Change functions to use a Util method to accommodate the behavior
correction where identity address can be null

Bug: 317120534
Bug: 295907764
Test: m com.android.btservices
Change-Id: I449492400c2945ecdd7f0194596e220a7849c1a8
parent 8cf69e75
Loading
Loading
Loading
Loading
+26 −9
Original line number Original line Diff line number Diff line
@@ -62,6 +62,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.Utils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;
import com.android.bluetooth.flags.Flags;
import com.android.modules.utils.build.SdkLevel;
import com.android.modules.utils.build.SdkLevel;


import com.google.common.collect.EvictingQueue;
import com.google.common.collect.EvictingQueue;
@@ -671,16 +672,22 @@ class AdapterProperties {


    void cleanupPrevBondRecordsFor(BluetoothDevice currentDevice) {
    void cleanupPrevBondRecordsFor(BluetoothDevice currentDevice) {
        String currentAddress = currentDevice.getAddress();
        String currentAddress = currentDevice.getAddress();
        String currentIdentityAddress = mService.getIdentityAddress(currentAddress);
        String currentBrEdrAddress =
                Flags.identityAddressNullIfUnknown()
                        ? Utils.getBrEdrAddress(currentDevice)
                        : mService.getIdentityAddress(currentAddress);
        debugLog("cleanupPrevBondRecordsFor: " + currentDevice);
        debugLog("cleanupPrevBondRecordsFor: " + currentDevice);
        if (currentIdentityAddress == null) {
        if (currentBrEdrAddress == null) {
            return;
            return;
        }
        }


        for (BluetoothDevice device : mBondedDevices) {
        for (BluetoothDevice device : mBondedDevices) {
            String address = device.getAddress();
            String address = device.getAddress();
            String identityAddress = mService.getIdentityAddress(address);
            String brEdrAddress =
            if (currentIdentityAddress.equals(identityAddress) && !currentAddress.equals(address)) {
                    Flags.identityAddressNullIfUnknown()
                            ? Utils.getBrEdrAddress(device)
                            : mService.getIdentityAddress(address);
            if (currentBrEdrAddress.equals(brEdrAddress) && !currentAddress.equals(address)) {
                if (mService.getNative()
                if (mService.getNative()
                        .removeBond(Utils.getBytesFromAddress(device.getAddress()))) {
                        .removeBond(Utils.getBytesFromAddress(device.getAddress()))) {
                    mBondedDevices.remove(device);
                    mBondedDevices.remove(device);
@@ -1239,15 +1246,25 @@ class AdapterProperties {
        StringBuilder sb = new StringBuilder();
        StringBuilder sb = new StringBuilder();
        for (BluetoothDevice device : mBondedDevices) {
        for (BluetoothDevice device : mBondedDevices) {
            String address = device.getAddress();
            String address = device.getAddress();
            String identityAddress = mService.getIdentityAddress(address);
            String brEdrAddress =
            if (identityAddress.equals(address)) {
                    Flags.identityAddressNullIfUnknown()
                            ? Utils.getBrEdrAddress(device)
                            : mService.getIdentityAddress(address);
            if (brEdrAddress.equals(address)) {
                writer.println("    " + address
                writer.println("    " + address
                            + " [" + dumpDeviceType(device.getType()) + "] "
                            + " [" + dumpDeviceType(device.getType()) + "] "
                            + Utils.getName(device));
                            + Utils.getName(device));
            } else {
            } else {
                sb.append("    " + address + " => " + identityAddress
                sb.append(
                            + " [" + dumpDeviceType(device.getType()) + "] "
                        "    "
                            + Utils.getName(device) + "\n");
                                + address
                                + " => "
                                + brEdrAddress
                                + " ["
                                + dumpDeviceType(device.getType())
                                + "] "
                                + Utils.getName(device)
                                + "\n");
            }
            }
        }
        }
        writer.println(sb.toString());
        writer.println(sb.toString());
+8 −2
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@ import android.net.Uri;
import android.util.Log;
import android.util.Log;


import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.Utils;
import com.android.bluetooth.flags.Flags;


import java.util.ArrayList;
import java.util.ArrayList;


@@ -83,10 +85,14 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
            if (device == null) {
            if (device == null) {
                return;
                return;
            }
            }
            String brEdrAddress =
                    Flags.identityAddressNullIfUnknown()
                            ? Utils.getBrEdrAddress(device)
                            : device.getIdentityAddress();
            if (D) {
            if (D) {
                Log.d(TAG, "Adding " + device.getIdentityAddress() + " to acceptlist");
                Log.d(TAG, "Adding " + brEdrAddress + " to acceptlist");
            }
            }
            BluetoothOppManager.getInstance(context).addToAcceptlist(device.getIdentityAddress());
            BluetoothOppManager.getInstance(context).addToAcceptlist(brEdrAddress);
        } else if (action.equals(Constants.ACTION_STOP_HANDOVER)) {
        } else if (action.equals(Constants.ACTION_STOP_HANDOVER)) {
            int id = intent.getIntExtra(Constants.EXTRA_BT_OPP_TRANSFER_ID, -1);
            int id = intent.getIntExtra(Constants.EXTRA_BT_OPP_TRANSFER_ID, -1);
            if (id != -1) {
            if (id != -1) {