Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java +47 −5 Original line number Original line Diff line number Diff line Loading @@ -195,8 +195,10 @@ public class LocalBluetoothProfileManager { if (DEBUG) Log.d(TAG, "Adding local HEADSET profile"); if (DEBUG) Log.d(TAG, "Adding local HEADSET profile"); mHeadsetProfile = new HeadsetProfile(mContext, mLocalAdapter, mHeadsetProfile = new HeadsetProfile(mContext, mLocalAdapter, mDeviceManager, this); mDeviceManager, this); addProfile(mHeadsetProfile, HeadsetProfile.NAME, addHeadsetProfile(mHeadsetProfile, HeadsetProfile.NAME, BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED, BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED, BluetoothHeadset.STATE_AUDIO_DISCONNECTED); } } } else if (mHeadsetProfile != null) { } else if (mHeadsetProfile != null) { Log.w(TAG, "Warning: HEADSET profile was previously added but the UUID is now missing."); Log.w(TAG, "Warning: HEADSET profile was previously added but the UUID is now missing."); Loading @@ -208,8 +210,10 @@ public class LocalBluetoothProfileManager { if(DEBUG) Log.d(TAG, "Adding local HfpClient profile"); if(DEBUG) Log.d(TAG, "Adding local HfpClient profile"); mHfpClientProfile = mHfpClientProfile = new HfpClientProfile(mContext, mLocalAdapter, mDeviceManager, this); new HfpClientProfile(mContext, mLocalAdapter, mDeviceManager, this); addProfile(mHfpClientProfile, HfpClientProfile.NAME, addHeadsetProfile(mHfpClientProfile, HfpClientProfile.NAME, BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED); BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED, BluetoothHeadsetClient.ACTION_AUDIO_STATE_CHANGED, BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED); } } } else if (mHfpClientProfile != null) { } else if (mHfpClientProfile != null) { Log.w(TAG, Log.w(TAG, Loading Loading @@ -277,6 +281,15 @@ public class LocalBluetoothProfileManager { // There is no local SDP record for HID and Settings app doesn't control PBAP Server. // There is no local SDP record for HID and Settings app doesn't control PBAP Server. } } private void addHeadsetProfile(LocalBluetoothProfile profile, String profileName, String stateChangedAction, String audioStateChangedAction, int audioDisconnectedState) { BluetoothEventManager.Handler handler = new HeadsetStateChangeHandler( profile, audioStateChangedAction, audioDisconnectedState); mEventManager.addProfileHandler(stateChangedAction, handler); mEventManager.addProfileHandler(audioStateChangedAction, handler); mProfileNameMap.put(profileName, profile); } private final Collection<ServiceListener> mServiceListeners = private final Collection<ServiceListener> mServiceListeners = new ArrayList<ServiceListener>(); new ArrayList<ServiceListener>(); Loading Loading @@ -323,18 +336,47 @@ public class LocalBluetoothProfileManager { cachedDevice = mDeviceManager.addDevice(mLocalAdapter, cachedDevice = mDeviceManager.addDevice(mLocalAdapter, LocalBluetoothProfileManager.this, device); LocalBluetoothProfileManager.this, device); } } onReceiveInternal(intent, cachedDevice); } protected void onReceiveInternal(Intent intent, CachedBluetoothDevice cachedDevice) { int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0); int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0); if (newState == BluetoothProfile.STATE_DISCONNECTED && if (newState == BluetoothProfile.STATE_DISCONNECTED && oldState == BluetoothProfile.STATE_CONNECTING) { oldState == BluetoothProfile.STATE_CONNECTING) { Log.i(TAG, "Failed to connect " + mProfile + " device"); Log.i(TAG, "Failed to connect " + mProfile + " device"); } } cachedDevice.onProfileStateChanged(mProfile, newState); cachedDevice.onProfileStateChanged(mProfile, newState); cachedDevice.refresh(); cachedDevice.refresh(); } } } } /** Connectivity and audio state change handler for headset profiles. */ private class HeadsetStateChangeHandler extends StateChangedHandler { private final String mAudioChangeAction; private final int mAudioDisconnectedState; HeadsetStateChangeHandler(LocalBluetoothProfile profile, String audioChangeAction, int audioDisconnectedState) { super(profile); mAudioChangeAction = audioChangeAction; mAudioDisconnectedState = audioDisconnectedState; } @Override public void onReceiveInternal(Intent intent, CachedBluetoothDevice cachedDevice) { if (mAudioChangeAction.equals(intent.getAction())) { int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); if (newState != mAudioDisconnectedState) { cachedDevice.onProfileStateChanged(mProfile, BluetoothProfile.STATE_CONNECTED); } cachedDevice.refresh(); } else { super.onReceiveInternal(intent, cachedDevice); } } } /** State change handler for NAP and PANU profiles. */ /** State change handler for NAP and PANU profiles. */ private class PanStateChangedHandler extends StateChangedHandler { private class PanStateChangedHandler extends StateChangedHandler { Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java +47 −5 Original line number Original line Diff line number Diff line Loading @@ -195,8 +195,10 @@ public class LocalBluetoothProfileManager { if (DEBUG) Log.d(TAG, "Adding local HEADSET profile"); if (DEBUG) Log.d(TAG, "Adding local HEADSET profile"); mHeadsetProfile = new HeadsetProfile(mContext, mLocalAdapter, mHeadsetProfile = new HeadsetProfile(mContext, mLocalAdapter, mDeviceManager, this); mDeviceManager, this); addProfile(mHeadsetProfile, HeadsetProfile.NAME, addHeadsetProfile(mHeadsetProfile, HeadsetProfile.NAME, BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED, BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED, BluetoothHeadset.STATE_AUDIO_DISCONNECTED); } } } else if (mHeadsetProfile != null) { } else if (mHeadsetProfile != null) { Log.w(TAG, "Warning: HEADSET profile was previously added but the UUID is now missing."); Log.w(TAG, "Warning: HEADSET profile was previously added but the UUID is now missing."); Loading @@ -208,8 +210,10 @@ public class LocalBluetoothProfileManager { if(DEBUG) Log.d(TAG, "Adding local HfpClient profile"); if(DEBUG) Log.d(TAG, "Adding local HfpClient profile"); mHfpClientProfile = mHfpClientProfile = new HfpClientProfile(mContext, mLocalAdapter, mDeviceManager, this); new HfpClientProfile(mContext, mLocalAdapter, mDeviceManager, this); addProfile(mHfpClientProfile, HfpClientProfile.NAME, addHeadsetProfile(mHfpClientProfile, HfpClientProfile.NAME, BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED); BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED, BluetoothHeadsetClient.ACTION_AUDIO_STATE_CHANGED, BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED); } } } else if (mHfpClientProfile != null) { } else if (mHfpClientProfile != null) { Log.w(TAG, Log.w(TAG, Loading Loading @@ -277,6 +281,15 @@ public class LocalBluetoothProfileManager { // There is no local SDP record for HID and Settings app doesn't control PBAP Server. // There is no local SDP record for HID and Settings app doesn't control PBAP Server. } } private void addHeadsetProfile(LocalBluetoothProfile profile, String profileName, String stateChangedAction, String audioStateChangedAction, int audioDisconnectedState) { BluetoothEventManager.Handler handler = new HeadsetStateChangeHandler( profile, audioStateChangedAction, audioDisconnectedState); mEventManager.addProfileHandler(stateChangedAction, handler); mEventManager.addProfileHandler(audioStateChangedAction, handler); mProfileNameMap.put(profileName, profile); } private final Collection<ServiceListener> mServiceListeners = private final Collection<ServiceListener> mServiceListeners = new ArrayList<ServiceListener>(); new ArrayList<ServiceListener>(); Loading Loading @@ -323,18 +336,47 @@ public class LocalBluetoothProfileManager { cachedDevice = mDeviceManager.addDevice(mLocalAdapter, cachedDevice = mDeviceManager.addDevice(mLocalAdapter, LocalBluetoothProfileManager.this, device); LocalBluetoothProfileManager.this, device); } } onReceiveInternal(intent, cachedDevice); } protected void onReceiveInternal(Intent intent, CachedBluetoothDevice cachedDevice) { int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0); int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0); if (newState == BluetoothProfile.STATE_DISCONNECTED && if (newState == BluetoothProfile.STATE_DISCONNECTED && oldState == BluetoothProfile.STATE_CONNECTING) { oldState == BluetoothProfile.STATE_CONNECTING) { Log.i(TAG, "Failed to connect " + mProfile + " device"); Log.i(TAG, "Failed to connect " + mProfile + " device"); } } cachedDevice.onProfileStateChanged(mProfile, newState); cachedDevice.onProfileStateChanged(mProfile, newState); cachedDevice.refresh(); cachedDevice.refresh(); } } } } /** Connectivity and audio state change handler for headset profiles. */ private class HeadsetStateChangeHandler extends StateChangedHandler { private final String mAudioChangeAction; private final int mAudioDisconnectedState; HeadsetStateChangeHandler(LocalBluetoothProfile profile, String audioChangeAction, int audioDisconnectedState) { super(profile); mAudioChangeAction = audioChangeAction; mAudioDisconnectedState = audioDisconnectedState; } @Override public void onReceiveInternal(Intent intent, CachedBluetoothDevice cachedDevice) { if (mAudioChangeAction.equals(intent.getAction())) { int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); if (newState != mAudioDisconnectedState) { cachedDevice.onProfileStateChanged(mProfile, BluetoothProfile.STATE_CONNECTED); } cachedDevice.refresh(); } else { super.onReceiveInternal(intent, cachedDevice); } } } /** State change handler for NAP and PANU profiles. */ /** State change handler for NAP and PANU profiles. */ private class PanStateChangedHandler extends StateChangedHandler { private class PanStateChangedHandler extends StateChangedHandler { Loading