}
@Override
+ public void setAudioRouteAllowed(boolean allowed) {
+ HeadsetClientService service = getService();
+ if (service != null) {
+ service.setAudioRouteAllowed(allowed);
+ }
+ }
+
+ @Override
+ public boolean getAudioRouteAllowed() {
+ HeadsetClientService service = getService();
+ if (service != null) {
+ return service.getAudioRouteAllowed();
+ }
+
+ return false;
+ }
+
+ @Override
public boolean connectAudio() {
HeadsetClientService service = getService();
if (service == null) {
return mStateMachine.getAudioState(device);
}
+ public void setAudioRouteAllowed(boolean allowed) {
+ mStateMachine.setAudioRouteAllowed(allowed);
+ }
+
+ public boolean getAudioRouteAllowed() {
+ return mStateMachine.getAudioRouteAllowed();
+ }
+
boolean connectAudio() {
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
if (!mStateMachine.isConnected()) {
import java.util.Queue;
import java.util.Set;
+import com.android.bluetooth.R;
+
final class HeadsetClientStateMachine extends StateMachine {
private static final String TAG = "HeadsetClientStateMachine";
private static final boolean DBG = false;
private final AudioManager mAudioManager;
private int mAudioState;
+ // Indicates whether audio can be routed to the device.
+ private boolean mAudioRouteAllowed;
private boolean mAudioWbs;
private final BluetoothAdapter mAdapter;
private boolean mNativeAvailable;
mAudioState = BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED;
mAudioWbs = false;
+ mAudioRouteAllowed = context.getResources().getBoolean(
+ R.bool.headset_client_initial_audio_route_allowed);
+
mIndicatorNetworkState = HeadsetClientHalConstants.NETWORK_STATE_NOT_AVAILABLE;
mIndicatorNetworkType = HeadsetClientHalConstants.SERVICE_TYPE_HOME;
mIndicatorNetworkSignal = 0;
mAudioWbs = true;
// fall through
case HeadsetClientHalConstants.AUDIO_STATE_CONNECTED:
+ if (!mAudioRouteAllowed) {
+ sendMessage(HeadsetClientStateMachine.DISCONNECT_AUDIO);
+ break;
+ }
+
mAudioState = BluetoothHeadsetClient.STATE_AUDIO_CONNECTED;
// request audio focus for call
int newAudioMode = AudioManager.MODE_IN_CALL;
return (getCurrentState() == mAudioOn);
}
+ public void setAudioRouteAllowed(boolean allowed) {
+ mAudioRouteAllowed = allowed;
+ }
+
+ public boolean getAudioRouteAllowed() {
+ return mAudioRouteAllowed;
+ }
+
synchronized int getAudioState(BluetoothDevice device) {
if (mCurrentDevice == null || !mCurrentDevice.equals(device)) {
return BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED;