为什么 isMultipleAdvertisementSupported() returns false,当 getBluetoothLeAdvertiser returns 一个对象?

Why isMultipleAdvertisementSupported() returns false, when getBluetoothLeAdvertiser returns an object?

我正在尝试在我的设备上使用 BLE 传输。

这是我使用的代码和输出:

// check BLE support
Log.i(TAG, "BLE supported: " + getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)); // true

// check BLE transmission support
final BluetoothManager bluetoothManager =
        (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();

Log.i(TAG, "isMultipleAdvertisementSupported: " + mBluetoothAdapter.isMultipleAdvertisementSupported()); // false
Log.i(TAG, "isOffloadedFilteringSupported: " + mBluetoothAdapter.isOffloadedFilteringSupported()); // false
Log.i(TAG, "isOffloadedScanBatchingSupported: " + mBluetoothAdapter.isOffloadedScanBatchingSupported()); // false

BluetoothLeAdvertiser mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
Log.i(TAG, mBluetoothLeAdvertiser.toString()); //android.bluetooth.le.BluetoothLeAdvertiser@1c51f789

// check BLE transmission support
// android-beacon-library, https://github.com/AltBeacon/android-beacon-library
int result = BeaconTransmitter.checkTransmissionSupported(getApplicationContext());
Log.i(TAG, "ABL checkTransmissionSupported: " + result); // 0

我无法理解为什么 mBluetoothLeAdvertiser 不是 null,因为 mBluetoothLeAdvertiser 验证它不是 false:

package android.bluetooth;
// ...

public BluetoothLeAdvertiser getBluetoothLeAdvertiser() {
    if (getState() != STATE_ON) {
        return null;
    }
    if (!isMultipleAdvertisementSupported()) {
        return null;
    }
    synchronized(mLock) {
        if (sBluetoothLeAdvertiser == null) {
            sBluetoothLeAdvertiser = new BluetoothLeAdvertiser(mManagerService);
        }
    }
    return sBluetoothLeAdvertiser;
}

// ...

public boolean isMultipleAdvertisementSupported() {
    if (getState() != STATE_ON) return false;
    try {
        return mService.isMultiAdvertisementSupported();
    } catch (RemoteException e) {
        Log.e(TAG, "failed to get isMultipleAdvertisementSupported, error: ", e);
    }
    return false;
}

欢迎来到Android的世界,它既开源又封闭源代码!您对上述开源 BluetoothLeAdvertiser 代码的分析是正确的。如果该代码在您的移动设备上是 运行,您将看不到顶部代码片段中的测试显示的输出。 结论:第二个片段中显示的代码一定不是设备上的代码。

Android 设备 OEM 可以自由分叉源代码并修改它以使其与他们的硬件一起工作。在这种情况下,我知道摩托罗拉在这段代码中为他们的 Moto X 和 Moto G 设备做了同样的事情。这些设备 return 和 BluetoothLeAdvertiser 尽管 isMultipleAdvertisementSupported() return 是错误的。一位摩托罗拉工程师向我解释说,他们改变了这一点,因为他们想要支持广告,尽管使用一次只能支持一个广告的 BLE 芯片。事实上,我已经验证了摩托罗拉设备可以做广告,但是如果你试图让两个广告同时播放,它就会失败。