import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.IBluetoothHeadsetClient;
-import android.bluetooth.IBluetoothHeadsetClientController;
import android.content.BroadcastReceiver;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.ServiceConnection;
import android.media.AudioManager;
import android.os.Bundle;
-import android.os.IBinder;
import android.os.Message;
import android.provider.Settings;
-import android.text.TextUtils;
import android.util.Log;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.Utils;
import java.util.ArrayList;
import java.util.List;
-import com.android.bluetooth.R;
-
/**
* Provides Bluetooth Headset Client (HF Role) profile, as a service in the
* Bluetooth application.
private static final String TAG = "HeadsetClientService";
private HeadsetClientStateMachine mStateMachine;
-
private static HeadsetClientService sHeadsetClientService;
- private ServiceConnection mControllerConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName componentName, IBinder service) {
- mStateMachine.setClientController(
- IBluetoothHeadsetClientController.Stub.asInterface(service));
- }
-
- @Override
- public void onServiceDisconnected(ComponentName componentName) {
- mStateMachine.setClientController(null);
- }
- };
-
@Override
protected String getName() {
return TAG;
} catch (Exception e) {
Log.w(TAG, "Unable to register broadcat receiver", e);
}
-
- final String controllerComponent =
- getResources().getString(R.string.headset_client_controller_service);
-
- if (!TextUtils.isEmpty(controllerComponent)) {
- Intent intent = new Intent();
- intent.setComponent(ComponentName.unflattenFromString(controllerComponent));
- bindService(intent, mControllerConnection, Context.BIND_AUTO_CREATE);
- }
-
setHeadsetClientService(this);
-
return true;
}
if (mStateMachine.isAudioOn()) {
return false;
}
-
mStateMachine.sendMessage(HeadsetClientStateMachine.CONNECT_AUDIO);
return true;
}
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
-import android.bluetooth.IBluetoothHeadsetClientController;
import android.os.Bundle;
import android.os.Message;
import android.os.ParcelUuid;
-import android.os.RemoteException;
import android.util.Log;
import android.util.Pair;
import android.content.Context;
// indicator
private Pair<Integer, Object> mPendingAction;
- private IBluetoothHeadsetClientController mClientController;
private final AudioManager mAudioManager;
private int mAudioState;
private boolean mAudioWbs;
classInitNative();
}
- public void setClientController(IBluetoothHeadsetClientController clientController) {
- mClientController = clientController;
- }
-
public void dump(StringBuilder sb) {
ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice);
ProfileService.println(sb, "mAudioOn: " + mAudioOn);
mAudioWbs = true;
// fall through
case HeadsetClientHalConstants.AUDIO_STATE_CONNECTED:
- try {
- if (mClientController != null && !mClientController.allowAudioConnect()) {
- sendMessage(HeadsetClientStateMachine.DISCONNECT_AUDIO);
- break;
- }
- } catch (RemoteException remoteException) {
- Log.e(TAG, "ERROR: couldn't communicate with client controller");
- }
-
mAudioState = BluetoothHeadsetClient.STATE_AUDIO_CONNECTED;
// request audio focus for call
int newAudioMode = AudioManager.MODE_IN_CALL;