Loading android/app/res/values/config.xml +3 −0 Original line number Original line Diff line number Diff line Loading @@ -41,4 +41,7 @@ <integer name="gatt_high_priority_max_interval">12</integer> <integer name="gatt_high_priority_max_interval">12</integer> <integer name="gatt_low_power_min_interval">80</integer> <integer name="gatt_low_power_min_interval">80</integer> <integer name="gatt_low_power_max_interval">100</integer> <integer name="gatt_low_power_max_interval">100</integer> <!-- Specifies the component name of the service to be bound to for controlling HF --> <string name="headset_client_controller_service"></string> </resources> </resources> android/app/src/com/android/bluetooth/hfpclient/HeadsetClientService.java +33 −0 Original line number Original line Diff line number Diff line Loading @@ -22,20 +22,27 @@ import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.IBluetoothHeadsetClient; import android.bluetooth.IBluetoothHeadsetClient; import android.bluetooth.IBluetoothHeadsetClientController; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.content.ServiceConnection; import android.media.AudioManager; import android.media.AudioManager; import android.os.Bundle; import android.os.Bundle; import android.os.IBinder; import android.os.Message; import android.os.Message; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import android.util.Log; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.Utils; import com.android.bluetooth.Utils; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; import java.util.List; import com.android.bluetooth.R; /** /** * Provides Bluetooth Headset Client (HF Role) profile, as a service in the * Provides Bluetooth Headset Client (HF Role) profile, as a service in the * Bluetooth application. * Bluetooth application. Loading @@ -47,8 +54,22 @@ public class HeadsetClientService extends ProfileService { private static final String TAG = "HeadsetClientService"; private static final String TAG = "HeadsetClientService"; private HeadsetClientStateMachine mStateMachine; private HeadsetClientStateMachine mStateMachine; private static HeadsetClientService sHeadsetClientService; 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 @Override protected String getName() { protected String getName() { return TAG; return TAG; Loading @@ -69,7 +90,18 @@ public class HeadsetClientService extends ProfileService { } catch (Exception e) { } catch (Exception e) { Log.w(TAG, "Unable to register broadcat receiver", 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); setHeadsetClientService(this); return true; return true; } } Loading Loading @@ -551,6 +583,7 @@ public class HeadsetClientService extends ProfileService { if (mStateMachine.isAudioOn()) { if (mStateMachine.isAudioOn()) { return false; return false; } } mStateMachine.sendMessage(HeadsetClientStateMachine.CONNECT_AUDIO); mStateMachine.sendMessage(HeadsetClientStateMachine.CONNECT_AUDIO); return true; return true; } } Loading android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +16 −0 Original line number Original line Diff line number Diff line Loading @@ -40,9 +40,11 @@ import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.BluetoothUuid; import android.bluetooth.IBluetoothHeadsetClientController; import android.os.Bundle; import android.os.Bundle; import android.os.Message; import android.os.Message; import android.os.ParcelUuid; import android.os.ParcelUuid; import android.os.RemoteException; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; import android.content.Context; import android.content.Context; Loading Loading @@ -140,6 +142,7 @@ final class HeadsetClientStateMachine extends StateMachine { // indicator // indicator private Pair<Integer, Object> mPendingAction; private Pair<Integer, Object> mPendingAction; private IBluetoothHeadsetClientController mClientController; private final AudioManager mAudioManager; private final AudioManager mAudioManager; private int mAudioState; private int mAudioState; private boolean mAudioWbs; private boolean mAudioWbs; Loading @@ -157,6 +160,10 @@ final class HeadsetClientStateMachine extends StateMachine { classInitNative(); classInitNative(); } } public void setClientController(IBluetoothHeadsetClientController clientController) { mClientController = clientController; } public void dump(StringBuilder sb) { public void dump(StringBuilder sb) { ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice); ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice); ProfileService.println(sb, "mAudioOn: " + mAudioOn); ProfileService.println(sb, "mAudioOn: " + mAudioOn); Loading Loading @@ -2016,6 +2023,15 @@ final class HeadsetClientStateMachine extends StateMachine { mAudioWbs = true; mAudioWbs = true; // fall through // fall through case HeadsetClientHalConstants.AUDIO_STATE_CONNECTED: 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; mAudioState = BluetoothHeadsetClient.STATE_AUDIO_CONNECTED; // request audio focus for call // request audio focus for call int newAudioMode = AudioManager.MODE_IN_CALL; int newAudioMode = AudioManager.MODE_IN_CALL; Loading Loading
android/app/res/values/config.xml +3 −0 Original line number Original line Diff line number Diff line Loading @@ -41,4 +41,7 @@ <integer name="gatt_high_priority_max_interval">12</integer> <integer name="gatt_high_priority_max_interval">12</integer> <integer name="gatt_low_power_min_interval">80</integer> <integer name="gatt_low_power_min_interval">80</integer> <integer name="gatt_low_power_max_interval">100</integer> <integer name="gatt_low_power_max_interval">100</integer> <!-- Specifies the component name of the service to be bound to for controlling HF --> <string name="headset_client_controller_service"></string> </resources> </resources>
android/app/src/com/android/bluetooth/hfpclient/HeadsetClientService.java +33 −0 Original line number Original line Diff line number Diff line Loading @@ -22,20 +22,27 @@ import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.IBluetoothHeadsetClient; import android.bluetooth.IBluetoothHeadsetClient; import android.bluetooth.IBluetoothHeadsetClientController; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.content.IntentFilter; import android.content.IntentFilter; import android.content.ServiceConnection; import android.media.AudioManager; import android.media.AudioManager; import android.os.Bundle; import android.os.Bundle; import android.os.IBinder; import android.os.Message; import android.os.Message; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import android.util.Log; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.Utils; import com.android.bluetooth.Utils; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; import java.util.List; import com.android.bluetooth.R; /** /** * Provides Bluetooth Headset Client (HF Role) profile, as a service in the * Provides Bluetooth Headset Client (HF Role) profile, as a service in the * Bluetooth application. * Bluetooth application. Loading @@ -47,8 +54,22 @@ public class HeadsetClientService extends ProfileService { private static final String TAG = "HeadsetClientService"; private static final String TAG = "HeadsetClientService"; private HeadsetClientStateMachine mStateMachine; private HeadsetClientStateMachine mStateMachine; private static HeadsetClientService sHeadsetClientService; 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 @Override protected String getName() { protected String getName() { return TAG; return TAG; Loading @@ -69,7 +90,18 @@ public class HeadsetClientService extends ProfileService { } catch (Exception e) { } catch (Exception e) { Log.w(TAG, "Unable to register broadcat receiver", 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); setHeadsetClientService(this); return true; return true; } } Loading Loading @@ -551,6 +583,7 @@ public class HeadsetClientService extends ProfileService { if (mStateMachine.isAudioOn()) { if (mStateMachine.isAudioOn()) { return false; return false; } } mStateMachine.sendMessage(HeadsetClientStateMachine.CONNECT_AUDIO); mStateMachine.sendMessage(HeadsetClientStateMachine.CONNECT_AUDIO); return true; return true; } } Loading
android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +16 −0 Original line number Original line Diff line number Diff line Loading @@ -40,9 +40,11 @@ import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.BluetoothUuid; import android.bluetooth.IBluetoothHeadsetClientController; import android.os.Bundle; import android.os.Bundle; import android.os.Message; import android.os.Message; import android.os.ParcelUuid; import android.os.ParcelUuid; import android.os.RemoteException; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; import android.content.Context; import android.content.Context; Loading Loading @@ -140,6 +142,7 @@ final class HeadsetClientStateMachine extends StateMachine { // indicator // indicator private Pair<Integer, Object> mPendingAction; private Pair<Integer, Object> mPendingAction; private IBluetoothHeadsetClientController mClientController; private final AudioManager mAudioManager; private final AudioManager mAudioManager; private int mAudioState; private int mAudioState; private boolean mAudioWbs; private boolean mAudioWbs; Loading @@ -157,6 +160,10 @@ final class HeadsetClientStateMachine extends StateMachine { classInitNative(); classInitNative(); } } public void setClientController(IBluetoothHeadsetClientController clientController) { mClientController = clientController; } public void dump(StringBuilder sb) { public void dump(StringBuilder sb) { ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice); ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice); ProfileService.println(sb, "mAudioOn: " + mAudioOn); ProfileService.println(sb, "mAudioOn: " + mAudioOn); Loading Loading @@ -2016,6 +2023,15 @@ final class HeadsetClientStateMachine extends StateMachine { mAudioWbs = true; mAudioWbs = true; // fall through // fall through case HeadsetClientHalConstants.AUDIO_STATE_CONNECTED: 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; mAudioState = BluetoothHeadsetClient.STATE_AUDIO_CONNECTED; // request audio focus for call // request audio focus for call int newAudioMode = AudioManager.MODE_IN_CALL; int newAudioMode = AudioManager.MODE_IN_CALL; Loading