diff options
author | Kai Shi <kaishi@google.com> | 2019-12-14 08:32:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-14 08:32:25 +0000 |
commit | 5738726d065a9665dd78489114d3f607b7dc5c96 (patch) | |
tree | b0da0ed7fb02e6c7a5caee1876094f96879bcfc1 /service | |
parent | ffb79a8b7811dda7f21cc1253d77395f29642f6f (diff) | |
parent | e0bb3496767a74b7de8b106fc4811dd5edd312fd (diff) |
Merge "Wifi: bug fix of BT connection active signal."
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/ClientModeImpl.java | 43 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 5 |
2 files changed, 43 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index fcd124c80..bfc1acdb0 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -432,8 +432,10 @@ public class ClientModeImpl extends StateMachine { /* The base for wifi message types */ static final int BASE = Protocol.BASE_WIFI; - + /* BT state change, e.g., on or off */ static final int CMD_BLUETOOTH_ADAPTER_STATE_CHANGE = BASE + 31; + /* BT connection state change, e.g., connected or disconnected */ + static final int CMD_BLUETOOTH_ADAPTER_CONNECTION_STATE_CHANGE = BASE + 32; /* Get adaptors */ static final int CMD_GET_SUPPORTED_FEATURES = BASE + 61; @@ -1677,13 +1679,22 @@ public class ClientModeImpl extends StateMachine { } /** - * Send a message indicating bluetooth adapter connection state changed + * Send a message indicating bluetooth adapter state changed, e.g., turn on or ff */ public void sendBluetoothAdapterStateChange(int state) { sendMessage(CMD_BLUETOOTH_ADAPTER_STATE_CHANGE, state, 0); } /** + * Send a message indicating bluetooth adapter connection state changed, e.g., connected + * or disconnected. Note that turning off BT after pairing success keeps connection state in + * connected state. + */ + public void sendBluetoothAdapterConnectionStateChange(int state) { + sendMessage(CMD_BLUETOOTH_ADAPTER_CONNECTION_STATE_CHANGE, state, 0); + } + + /** * Trigger dump on the class IpClient object. */ public void dumpIpClient(FileDescriptor fd, PrintWriter pw, String[] args) { @@ -3088,8 +3099,18 @@ public class ClientModeImpl extends StateMachine { break; } case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE: + // If BT was connected and then turned off, there is no CONNECTION_STATE_CHANGE + // message. So we need to rely on STATE_CHANGE message to detect on->off + // transition and update mBluetoothConnectionActive status correctly. + mBluetoothConnectionActive = mBluetoothConnectionActive + && message.arg1 != BluetoothAdapter.STATE_OFF; + mWifiConnectivityManager.setBluetoothConnected(mBluetoothConnectionActive); + break; + case CMD_BLUETOOTH_ADAPTER_CONNECTION_STATE_CHANGE: + // Transition to a non-disconnected state does correctly + // indicate BT is connected or being connected. mBluetoothConnectionActive = - (message.arg1 != BluetoothAdapter.STATE_DISCONNECTED); + message.arg1 != BluetoothAdapter.STATE_DISCONNECTED; mWifiConnectivityManager.setBluetoothConnected(mBluetoothConnectionActive); break; case CMD_ENABLE_RSSI_POLL: @@ -3934,8 +3955,20 @@ public class ClientModeImpl extends StateMachine { } break; case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE: - mBluetoothConnectionActive = (message.arg1 - != BluetoothAdapter.STATE_DISCONNECTED); + // If BT was connected and then turned off, there is no CONNECTION_STATE_CHANGE + // message. So we need to rely on STATE_CHANGE message to detect on->off + // transition and update mBluetoothConnectionActive status correctly. + mBluetoothConnectionActive = mBluetoothConnectionActive + && message.arg1 != BluetoothAdapter.STATE_OFF; + mWifiNative.setBluetoothCoexistenceScanMode( + mInterfaceName, mBluetoothConnectionActive); + mWifiConnectivityManager.setBluetoothConnected(mBluetoothConnectionActive); + break; + case CMD_BLUETOOTH_ADAPTER_CONNECTION_STATE_CHANGE: + // Transition to a non-disconnected state does correctly + // indicate BT is connected or being connected. + mBluetoothConnectionActive = + message.arg1 != BluetoothAdapter.STATE_DISCONNECTED; mWifiNative.setBluetoothCoexistenceScanMode( mInterfaceName, mBluetoothConnectionActive); mWifiConnectivityManager.setBluetoothConnected(mBluetoothConnectionActive); diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index e74da3aeb..afea1d0a8 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -363,6 +363,7 @@ public class WifiServiceImpl extends BaseWifiService { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_USER_REMOVED); intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); + intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); boolean trackEmergencyCallState = mContext.getResources().getBoolean( @@ -2599,6 +2600,10 @@ public class WifiServiceImpl extends BaseWifiService { } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, BluetoothAdapter.STATE_DISCONNECTED); + mClientModeImpl.sendBluetoothAdapterConnectionStateChange(state); + } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { + int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, + BluetoothAdapter.STATE_OFF); mClientModeImpl.sendBluetoothAdapterStateChange(state); } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) { boolean emergencyMode = |