Bluetooth: Ensure only desired intents are being handled

* Prevent arbitrary intents from making Bluetooth undiscoverable by only
  allowing DISCOVERABLE_TIMEOUT intent to be handled

Bug: 33058582
Test: make, test for Broadcast and Bluetooth scanning
Change-Id: Ib8b04dddf1610a082d167825253f3e1c968aaa14
This commit is contained in:
Jack He
2017-04-03 15:13:57 -07:00
parent d6f0b0fc4f
commit 42a25ba82e

View File

@@ -71,14 +71,15 @@ public class BluetoothDiscoverableTimeoutReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == null || !intent.getAction().equals(INTENT_DISCOVERABLE_TIMEOUT)) {
return;
}
LocalBluetoothAdapter localBluetoothAdapter = LocalBluetoothAdapter.getInstance();
if(localBluetoothAdapter != null &&
if(localBluetoothAdapter != null &&
localBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
Log.d(TAG, "Disable discoverable...");
localBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
} else {
} else {
Log.e(TAG, "localBluetoothAdapter is NULL!!");
}
}