@@ -505,6 +505,15 @@ public boolean setActiveDevice(BluetoothDevice device) {
505505            Long  deviceHiSyncId  = mDeviceHiSyncIdMap .getOrDefault (device ,
506506                    BluetoothHearingAid .HI_SYNC_ID_INVALID );
507507            if  (deviceHiSyncId  != mActiveDeviceHiSyncId ) {
508+                 // Give an early notification to A2DP that active device is being switched 
509+                 // to Hearing Aids before the Audio Service. 
510+                 final  A2dpService  a2dpService  = mFactory .getA2dpService ();
511+                 if  (a2dpService  != null ) {
512+                     if  (DBG ) {
513+                         Log .d (TAG , "earlyNotifyHearingAidActive for "  + device );
514+                     }
515+                     a2dpService .earlyNotifyHearingAidActive ();
516+                 }
508517                mActiveDeviceHiSyncId  = deviceHiSyncId ;
509518                reportActiveDevice (device );
510519            }
@@ -519,7 +528,7 @@ public boolean setActiveDevice(BluetoothDevice device) {
519528     * device; the second element is the right active device. If either or both side 
520529     * is not active, it will be null on that position 
521530     */ 
522-     List <BluetoothDevice > getActiveDevices () {
531+     public   List <BluetoothDevice > getActiveDevices () {
523532        if  (DBG ) {
524533            Log .d (TAG , "getActiveDevices" );
525534        }
@@ -625,18 +634,6 @@ private void reportActiveDevice(BluetoothDevice device) {
625634        StatsLog .write (StatsLog .BLUETOOTH_ACTIVE_DEVICE_CHANGED , BluetoothProfile .HEARING_AID ,
626635                mAdapterService .obfuscateAddress (device ));
627636
628-         if  (device  != null ) {
629-             // Give an early notification to A2DP that active device is being switched 
630-             // to Hearing Aids before the Audio Service. 
631-             final  A2dpService  a2dpService  = mFactory .getA2dpService ();
632-             if  (a2dpService  != null ) {
633-                 if  (DBG ) {
634-                     Log .d (TAG , "earlyNotifyHearingAidActive for "  + device );
635-                 }
636-                 a2dpService .earlyNotifyHearingAidActive ();
637-             }
638-         }
639- 
640637        Intent  intent  = new  Intent (BluetoothHearingAid .ACTION_ACTIVE_DEVICE_CHANGED );
641638        intent .putExtra (BluetoothDevice .EXTRA_DEVICE , device );
642639        intent .addFlags (Intent .FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT 
0 commit comments