thaliproject / Thali_CordovaPlugin

Thali p2p plugin
MIT License
226 stars 44 forks source link

Dealing with Doze and Standby in Android Marshmallow #413

Open yaronyg opened 8 years ago

yaronyg commented 8 years ago

NOTE: We have tested this manually on the only Marshmallow devices we have but we need to test on more devices and we need to upgrade CI so that it has a new version of ADB build for our ARM environment on the Raspberry PIs that will allow us to automatically grant permissions.

When an App is put into Doze or Standby mode in Marshmallow it isn't allowed to connect to the network or to run or do anything. Now it's unclear what this means if one is trying to do things like run a BLE scanner or BLE beacon in the background. Also there is a special permission that the user has to approve in order to get around these restrictions.

We need answers to the following questions:

How does Doze and Standby affect services? Do they only apply to the app's foreground or to its services as well?

If Doze and Standby affect services then we need to know:

While our app is in Doze or Standby mode can we still be a BLE beacon? While our app is in Doze or Standby mode can we still scan for BLE beacons?

If the answer to the two questions above is yes then we need to figure out if receiving an incoming BLE connection or discovering a remote BLE beacon will give us the ability to wake out of Doze/Standby and establish a BLE transfer and then establish a Bluetooth connection?

Separately we also need to figure out what we can do about WiFi. If local WiFi supports multicasting and direct connections then we will want to regularly ping the local AP (if there is one) to see if there is anyone around who wants to exchange information. It sounds like all WiFi gets turned off, so what can do we to make it go on?

Maybe we can do what we already are doing? If not then we have to investigate the feature they added to get white listed as an application that is exempted from Doze and Standby. Exempted apps still have limitations so we have to figure out if our BLE and Bluetooth functionality will continue to work right under those exemptions.

tompaana commented 8 years ago

Tested with Nexus 6 (Android version 6.0.1).

Test results:

Doze:

Standby:

tompaana commented 8 years ago

How to reproduce the test scenario:

  1. Get the modified Native Test app for the first device. The version used for testing was this commit.
    • In Settings tab of the Native test app clear the peer name (set it empty) - this will utilize the simplified handshake message used by the Cordova Plug-in.
  2. Implement the following changes in ConnectionHelper class of this project:
    • The same UUID for both ConnectionManager and DiscoveryManager:
private static final String SERVICE_UUID_AS_STRING = "b6a44ad1-d319-4b3a-815d-8b805a47fb51"; //"fa87c0d0-afac-11de-8a39-0800200c9a66";
private static final String BLE_SERVICE_UUID_AS_STRING = "b6a44ad1-d319-4b3a-815d-8b805a47fb51";
yaronyg commented 8 years ago
  1. Please test on your remaining devices
  2. Please put the info on how to repro the tests into the test readme
tompaana commented 8 years ago
  1. We (@juhanak, @vjrantal and I) have no other Marshmallow devices than Nexus 6s so no remaining devices to test with
  2. Done - PR ready