title: Android 6.0.1 on Samsung: BLE discovery scan stops when phone is locked
body: <p>I have developed an application that needs to run a continuous BLE scanning, because it has to check that all the surrounding peripherals are transmitting.
  When one or more of them stop transmitting, my app must raise an alert.
  I've tested it on some phones:</p>
  
  <p>1 - Samsung Note 4 with Android 5.1.1
  2 - Honor 8 with Android 6.0
  3 - LG Nexus 5 with Android 6.0.1
  4 - Samsung Note 4 with Android 6.0.1
  5 - Samsung J5 with Android 6.0.1</p>
  
  <p>ONLY ON PHONES 4 and 5, the discovery of BLE peripherals seems to behave differently when the device is "awake" compared to when it's locked.
  In particular, when I press the power button and the device goes to locked state, the phone stops discovering my peripherals - or at least, discovery is triggered at a very low frequency. When I press the power button again (going back to unlocked mode by entering a pin), BLE discovery starts again and runs continuously.</p>
  
  <p>The service that operates the scan is perfectly alive and running, but simply it does not perform the scan.</p>
  
  <p>This strange behaviour is only happening on phones 4 and 5 (Samsung with Android 6.0.1). Same phone with different android version, and same android version on different phones seem not to be affected.</p>
  
  <p>I've tried various workarounds, without success:</p>
  
  <ul>
  <li>Disable Android Doze Mode for my application, both from Android Settings and from source code in my app</li>
  <li>Using various ScanSettings options: ScanMode, NumOfMatches, MatchMode…</li>
  <li>Giving the scan service a high wake-lock level</li>
  </ul>
  
  <p>Has anybody ever had the same problem?</p>
  
  <p><em>EDIT: tested and ok also on Samsung Note 2 with Android 4.4.2</em></p>