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

Commit 9d1ee9af authored by Christine Hallstrom's avatar Christine Hallstrom Committed by Kihong Seong
Browse files

Handle null identity address in BluetoothOppManager

Add helper method to call into for profiles that connect over BR/EDR
transport, to accommodate the behavior correction where identity address
can be null. The helper method takes in a BluetoothDevice object and
returns the correct device address in String.

Bug: 317120534
Bug: 295907764
Test: m com.android.btservices
Change-Id: I3a4eaf882efda964f42479bf24b6435ea60448c6
parent 14c5f38c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -189,6 +189,20 @@ public final class Utils {
        return String.format("XX:XX:XX:XX:%02X:%02X", address[4], address[5]);
    }

    /**
     * Returns the correct device address to be used for connections over BR/EDR transport.
     *
     * @param device the device for which to obtain the connection address
     * @return either identity address or device address in String format
     */
    public static String getBrEdrAddress(BluetoothDevice device) {
        String address = device.getIdentityAddress();
        if (address == null) {
            address = device.getAddress();
        }
        return address;
    }

    /**
     * Returns the correct device address to be used for connections over BR/EDR transport.
     *
+12 −2
Original line number Diff line number Diff line
@@ -51,7 +51,9 @@ import android.util.Pair;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.VisibleForTesting;

import java.util.ArrayList;
@@ -502,7 +504,11 @@ public class BluetoothOppManager {
                }

                values.put(BluetoothShare.MIMETYPE, contentType);
                values.put(BluetoothShare.DESTINATION, mRemoteDevice.getIdentityAddress());
                values.put(
                        BluetoothShare.DESTINATION,
                        Flags.identityAddressNullIfUnknown()
                                ? Utils.getBrEdrAddress(mRemoteDevice)
                                : mRemoteDevice.getIdentityAddress());
                values.put(BluetoothShare.TIMESTAMP, ts);
                if (mIsHandoverInitiated) {
                    values.put(BluetoothShare.USER_CONFIRMATION,
@@ -524,7 +530,11 @@ public class BluetoothOppManager {
            ContentValues values = new ContentValues();
            values.put(BluetoothShare.URI, mUri);
            values.put(BluetoothShare.MIMETYPE, mTypeOfSingleFile);
            values.put(BluetoothShare.DESTINATION, mRemoteDevice.getIdentityAddress());
            values.put(
                    BluetoothShare.DESTINATION,
                    Flags.identityAddressNullIfUnknown()
                            ? Utils.getBrEdrAddress(mRemoteDevice)
                            : mRemoteDevice.getIdentityAddress());
            if (mIsHandoverInitiated) {
                values.put(BluetoothShare.USER_CONFIRMATION,
                        BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED);