@@ -1870,6 +1870,22 @@ public boolean setActiveDevice(@NonNull BluetoothDevice device,
18701870 return false ;
18711871 }
18721872
1873+ /** @hide */
1874+ @ RequiresPermission (Manifest .permission .BLUETOOTH )
1875+ public boolean isBroadcastActive () {
1876+ try {
1877+ mServiceLock .readLock ().lock ();
1878+ if (mService != null ) {
1879+ return mService .isBroadcastActive ();
1880+ }
1881+ } catch (RemoteException e ) {
1882+ Log .e (TAG , "" , e );
1883+ } finally {
1884+ mServiceLock .readLock ().unlock ();
1885+ }
1886+ return false ;
1887+ }
1888+
18731889 /**
18741890 * Connects all enabled and supported bluetooth profiles between the local and remote device.
18751891 * Connection is asynchronous and you should listen to each profile's broadcast intent
@@ -2935,6 +2951,8 @@ public boolean getProfileProxy(Context context, BluetoothProfile.ServiceListener
29352951 return true ;
29362952 } else if (profile == BluetoothProfile .BC_PROFILE ) {
29372953 return getBCProfile (context , listener );
2954+ } else if (profile == BluetoothProfile .BROADCAST ) {
2955+ return getBroadcastProfile (context , listener );
29382956 } else if (profile == BluetoothProfile .HEARING_AID ) {
29392957 if (isHearingAidProfileSupported ()) {
29402958 BluetoothHearingAid hearingAid = new BluetoothHearingAid (context , listener );
@@ -3025,12 +3043,73 @@ public void closeProfileProxy(int profile, BluetoothProfile proxy) {
30253043 case BluetoothProfile .BC_PROFILE :
30263044 closeBCProfile (proxy );
30273045 break ;
3046+ case BluetoothProfile .BROADCAST :
3047+ closeBroadcastProfile (proxy );
3048+ break ;
30283049 case BluetoothProfile .HEARING_AID :
30293050 BluetoothHearingAid hearingAid = (BluetoothHearingAid ) proxy ;
30303051 hearingAid .close ();
30313052 }
30323053 }
30333054
3055+ private boolean getBroadcastProfile (Context context ,
3056+ BluetoothProfile .ServiceListener listener ) {
3057+ boolean ret = true ;
3058+ Class <?> broadcastClass = null ;
3059+ Constructor bcastConstructor = null ;
3060+ Object broadcastObj = null ;
3061+ try {
3062+ broadcastClass = Class .forName ("android.bluetooth.BluetoothBroadcast" );
3063+ } catch (ClassNotFoundException ex ) {
3064+ Log .e (TAG , "no BluetoothBroadcast: exists" );
3065+ }
3066+ if (broadcastClass != null ) {
3067+ try {
3068+ bcastConstructor =
3069+ broadcastClass .getDeclaredConstructor (new Class []{Context .class ,
3070+ BluetoothProfile .ServiceListener .class });
3071+ } catch (NoSuchMethodException ex ) {
3072+ Log .e (TAG , "bcastConstructor: NoSuchMethodException: gdm" + ex );
3073+ }
3074+ }
3075+ if (bcastConstructor != null ) {
3076+ try {
3077+ broadcastObj = bcastConstructor .newInstance (context , listener );
3078+ } catch (InstantiationException | IllegalAccessException |
3079+ InvocationTargetException ex ) {
3080+ ex .printStackTrace ();
3081+ }
3082+ }
3083+ if (broadcastObj == null ) {
3084+ return false ;
3085+ }
3086+ return true ;
3087+ }
3088+
3089+ private void closeBroadcastProfile (BluetoothProfile proxy ) {
3090+ Class <?> broadcastClass = null ;
3091+ Method broadcastClose = null ;
3092+ try {
3093+ broadcastClass = Class .forName ("android.bluetooth.BluetootBroadcast" );
3094+ } catch (ClassNotFoundException ex ) {
3095+ Log .e (TAG , "no BluetoothBroadcast: exists" );
3096+ }
3097+ if (broadcastClass != null ) {
3098+ try {
3099+ broadcastClose = broadcastClass .getDeclaredMethod ("close" , null );
3100+ } catch (NoSuchMethodException e ) {
3101+ Log .e (TAG , "no Broadcast:close method exists" );
3102+ }
3103+ if (broadcastClose != null ) {
3104+ try {
3105+ broadcastClose .invoke (proxy , null );
3106+ } catch (IllegalAccessException | InvocationTargetException ex ) {
3107+ ex .printStackTrace ();
3108+ }
3109+ }
3110+ }
3111+ }
3112+
30343113 private final IBluetoothManagerCallback mManagerCallback =
30353114 new IBluetoothManagerCallback .Stub () {
30363115 public void onBluetoothServiceUp (IBluetooth bluetoothService ) {
0 commit comments