question: public void startScan ( BluetoothAdapter adapter ) { int mask = BluetoothReceiver . DISCOVERY_STARTED_FLAG ; if ( ! adapter . isEnabled ( ) ) { fail ( "startScan() bluetooth not enabled" ) ; } if ( adapter . isDiscovering ( ) ) { return ; } BluetoothReceiver receiver = getBluetoothReceiver ( mask ) ; long start = System . currentTimeMillis ( ) ; assertTrue ( adapter . startDiscovery ( ) ) ; while ( System . currentTimeMillis ( ) - start < START_STOP_SCAN_TIMEOUT ) { if ( adapter . isDiscovering ( ) && ( ( receiver . getFiredFlags ( ) & mask ) == mask ) ) { writeOutput ( String . format ( "startScan() completed in %d ms" , ( receiver . getCompletedTime ( ) - start ) ) ) ; removeReceiver ( receiver ) ; return ; } sleep ( POLL_TIME ) ; } int firedFlags = receiver . getFiredFlags ( ) ; removeReceiver ( receiver ) ; fail ( String . format ( "startScan() timeout: isDiscovering=%b, flags=0x%x (expected 0x%x)" , adapter . isDiscovering ( ) , firedFlags , mask ) ) ; }
target:  Starts a scan for remote devices and checks to make sure that the local device is scanning and that the correct actions were broadcast.