OSDN Git Service

Bluetooth: report proper advertiser status on error
authorJakub Pawlowski <jpawlowski@google.com>
Tue, 22 Nov 2016 20:44:22 +0000 (12:44 -0800)
committerJakub Pawlowski <jpawlowski@google.com>
Tue, 22 Nov 2016 21:38:15 +0000 (13:38 -0800)
When advertiser is not started because too many advertisers are
registered, return proper error code.

Bug: 30622771
Test: sl4a ConcurrentBleAdvertisingTest
Change-Id: I57384ff30132e9a7ee17dcf191ff89baa7abf1ef

core/java/android/bluetooth/le/BluetoothLeAdvertiser.java

index 5d27662..94d03e5 100644 (file)
@@ -235,6 +235,7 @@ public final class BluetoothLeAdvertiser {
         // >=0: registered and advertising started
         private int mAdvertiserId;
         private boolean mIsAdvertising = false;
+        private int registrationError = AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR;
 
         public AdvertiseCallbackWrapper(AdvertiseCallback advertiseCallback,
                 AdvertiseData advertiseData, AdvertiseData scanResponse,
@@ -262,12 +263,11 @@ public final class BluetoothLeAdvertiser {
                     mLeAdvertisers.put(mAdvertiseCallback, this);
                 } else if (mAdvertiserId < 0) {
 
-                    // Registration timeout, reset mClientIf to -1 so no subsequent operations can
+                    // Registration timeout, reset mClientIf to -2 so no subsequent operations can
                     // proceed.
-                    if (mAdvertiserId == 0) mAdvertiserId = -2;
+                    if (mAdvertiserId == -1) mAdvertiserId = -2;
                     // Post internal error if registration failed.
-                    postStartFailure(mAdvertiseCallback,
-                            AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
+                    postStartFailure(mAdvertiseCallback, registrationError);
                 } else {
                     // Unregister application if it's already registered but advertise failed.
                     try {
@@ -318,6 +318,8 @@ public final class BluetoothLeAdvertiser {
                     } catch (RemoteException e) {
                         Log.e(TAG, "failed to start advertising", e);
                     }
+                } else if (status == AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS) {
+                    registrationError = status;
                 }
                 // Registration failed.
                 mAdvertiserId = -2;