OSDN Git Service

HearingAid RemoveDevice - don't crash when profile not enabled
authorJakub Pawlowski <jpawlowski@google.com>
Thu, 10 May 2018 13:42:43 +0000 (06:42 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 10 May 2018 13:44:31 +0000 (06:44 -0700)
Bug: 79468820
Test: Unbond non-hearing aid device when profile not enabled
Change-Id: I2a87f8725447045e7bc5b2a33facf1ce14b47c54

btif/src/btif_hearing_aid.cc

index d78725c..48aab95 100644 (file)
@@ -103,8 +103,13 @@ class HearingAidInterfaceImpl
 
   void RemoveDevice(const RawAddress& address) override {
     DVLOG(2) << __func__ << " address: " << address;
-    do_in_bta_thread(FROM_HERE, Bind(&HearingAid::Disconnect,
-                                     Unretained(HearingAid::Get()), address));
+
+    // RemoveDevice can be called on devices that don't have HA enabled
+    if (HearingAid::IsInitialized()) {
+      do_in_bta_thread(FROM_HERE, Bind(&HearingAid::Disconnect,
+                                       Unretained(HearingAid::Get()), address));
+    }
+
     do_in_jni_thread(FROM_HERE,
                      Bind(&btif_storage_remove_hearing_aid, address));
   }