Skip to content

Commit 0479a67

Browse files
pramod kotreshappaMocaRafee
authored andcommitted
Add broadcast profile id
- Add broadcast profile id - Add support for broadcast api CRs-fixed: 2856233 Change-Id: If229688ecd0ad4c2ca3d058b4ebf69b19dede6b2
1 parent d5b58f6 commit 0479a67

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

core/java/android/bluetooth/BluetoothAdapter.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

core/java/android/bluetooth/BluetoothProfile.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,19 @@ public interface BluetoothProfile {
223223
*/
224224
public static final int CC_SERVER = 26;
225225

226+
/**
227+
* Broadcast
228+
* @hide
229+
*/
230+
public static final int BROADCAST = 27;
231+
226232
/**
227233
* Max profile ID. This value should be updated whenever a new profile is added to match
228234
* the largest value assigned to a profile.
229235
*
230236
* @hide
231237
*/
232-
int MAX_PROFILE_ID = 26;
238+
int MAX_PROFILE_ID = 27;
233239

234240
/**
235241
* Default priority for devices that we try to auto-connect to and
@@ -428,6 +434,8 @@ static String getProfileName(int profile) {
428434
return "OPP";
429435
case HEARING_AID:
430436
return "HEARING_AID";
437+
case BROADCAST:
438+
return "BROADCAST";
431439
default:
432440
return "UNKNOWN_PROFILE";
433441
}

services/core/java/com/android/server/BluetoothAirplaneModeListener.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ public void onServiceDisconnected(int profile) {
198198

199199
@VisibleForTesting
200200
public boolean isA2dpOrHearingAidConnected() {
201-
return isA2dpConnected() || isHearingAidConnected();
201+
return isA2dpConnected() || isHearingAidConnected() ||
202+
isBroadcastActive();
202203
}
203204

204205
@VisibleForTesting
@@ -256,5 +257,11 @@ private boolean isHearingAidConnected() {
256257
}
257258
return hearingAid.getConnectedDevices().size() > 0;
258259
}
260+
261+
private boolean isBroadcastActive() {
262+
boolean ret = false;
263+
ret = mAdapter.isBroadcastActive();
264+
return ret;
265+
}
259266
};
260267
}

0 commit comments

Comments
 (0)