Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

didExitRegion called when goes to background in Google Pixel #509

Closed
kapilojha opened this issue May 12, 2017 · 17 comments
Closed

didExitRegion called when goes to background in Google Pixel #509

kapilojha opened this issue May 12, 2017 · 17 comments

Comments

@kapilojha
Copy link

kapilojha commented May 12, 2017

I am using AltBeacon library to use iBeacon in my Android application but getting an issue, explained below

@davidgyoung
Copy link
Member

Thanks for the report, @roshanparmar. Can you please attach a log with beaconManager.setDebug(true); that shows the exit event and prior 20 seconds?

@davidgyoung
Copy link
Member

davidgyoung commented May 12, 2017

By the way there were some changes in 2.10 to fix some edge cases with Android 7.0 blocking too many scans in a short period of time. The problem you describe might be intermittently triggered with 2.9.2 using the 1000ms on / 1000 ms off scan settings you have in your code. But I would not expect it to happen consistently. Regardless, it may be worth verifying it still happens with 2.10.

@davidgyoung
Copy link
Member

Sorry you are having trouble, @roshanparmar, and thank you for attaching the log.

The log shows no detections in the background at all, but indicates that beacons had been previously detected, perhaps in the foreground. A. few possible causes:

  1. The beacon you are using may not be matching the Bluetooth filter used in the background. This would happen if it uses a non-addictive manufacturer ID. If you can capture a short log segment showing a successful detection (perhaps in the foreground) I could confirm and offer a solution.

  2. The custom background scan periods may be interfering with the operating system's standard low power background scanning cycle. To confirm if this is the problem, you could try setting the background scan periods back to the defaults for testing purposes to see if it then detects:

      beaconManager.setBackgroundScanPeriod(10000L);
        beaconManager.setBackgroundBetweenScanPeriod(300000L);

It may be that setting a 1000 ms scan cycle may be too short to ever allow low power detections to succeed.

  1. There is a related bug discovered over the weekend in 2.10 (see didRangeBeaconsInRegion stops Firing after 30 minutes #506) that is now fixed in 2.11-beta1. Simply using this release may resolved the issue. https://github.com/AltBeacon/android-beacon-library/releases/tag/2.11-beta1

Please try the items above and let me know your findings so I may assist further.

@davidgyoung
Copy link
Member

@roshanparmar, I believe I see the issue from the latest log. See this:

05-15 19:17:52.050 14489-14528/com.app.dealer_app W/Binder: Binder call failed.
java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
at android.os.Parcel.readException(Parcel.java:1684)
at android.os.Parcel.readException(Parcel.java:1637)
at android.bluetooth.IBluetoothGatt$Stub$Proxy.startScan(IBluetoothGatt.java:678)
at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper.onClientRegistered(BluetoothLeScanner.java:367)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:56)
at android.os.Binder.execTransact(Binder.java:565)

That indicates the app has not gotten location permission needed to detect BLE devices. You can read more about how to do this here:

http://altbeacon.github.io/android-beacon-library/requesting_permission.html

On Android 6+, apps that target SDK 23+ but fail to get this permission can not scan for BLE devices at all. Apps that target SDKs less than 23 and fail to get this permission can only scan in the foreground. I believe this is the problem that is causing your failure to scan in the background.

@davidgyoung
Copy link
Member

2.11-beta1 is not on JCenter. You must download the binary manuallly, but it in a libs folder in your project and reference it that way. I will put up instructions in a bit and then review your latest logs.

@davidgyoung
Copy link
Member

Beta release updated with configuration instructions:

https://github.com/AltBeacon/android-beacon-library/releases/tag/2.11-beta1

@davidgyoung
Copy link
Member

@roshanparmar, a few more thoughts:

  • If using RegionBootstrap as shown in the code posted in this issue, you should not call beaconManager.bind(this), as it is done automatically inside RegionBootstrap.
  • Based on reviewing the latest log above, I do believe the 2.11-beta1 release will solve the region exit issue you are seeing. The log line below indicates that beacons were only detected in the first few seconds of the background scan cycle, which is the symptom fixed in 2.11-beta1.

05-16 10:31:50.247 29417-29417/com.app.dealer_app D/RegionMonitoringState: We are newly outside the region because the lastSeenTime of 84863358 was 16693 seconds ago, and that is over the expiration duration of 10000

@davidgyoung
Copy link
Member

Sorry, the string in the instructions was incorrect. Please replace the dash before the version number with a colon like this: 'android-beacon-library:2.11-beta1@aar'

@davidgyoung
Copy link
Member

If you can get this configured, please verify from the logs that you are using this version by looking for this line:

I/BeaconService: beaconService version 2.11-beta1 is starting up on the main process

@davidgyoung
Copy link
Member

@roshanparmar, can you please attache a log showing the prior 30 seconds before the unexpected region exit when running 2.11-beta1?

@davidgyoung
Copy link
Member

Troubleshooting errors on client devices where you don't have physical access is always really hard. The best thing I can suggest is to ask you client to send you a bug report, but this requires your client to turn on Developer tools on the Android device.

If developer tools are enabled, you can send a bug report by going to Settings -> Developer Options -> Take Bug Report.

After tapping this, there will be a delay of a few seconds to a few minutes (!) until it is ready at which time a notification will be sent. Tapping that notification will allow you to send the bug report via email.

The bug report includes recent logs as well as other state info about the Android device.

The trickiest part of doing this is getting your client to capture the bug report at the right time. If this is done too late, the logs won't show the desired information.

@davidgyoung
Copy link
Member

Yes, as discussed above, this is a known issue with 2.10 for an app in the background when beacons are continuously around. The fix is included in 2.11-beta1.

@davidgyoung
Copy link
Member

@roshanparmar, the logs indicate 2.10 is active:

05-15 19:17:40.730 14489-14489/com.app.dealer_app I/BeaconService: beaconService version 2.10 is starting up

@davidgyoung
Copy link
Member

@roshanparmar, sorry, this is getting confusing to follow. It's really important to focus on one issue at a time, so this thread doesn't go off track. Otherwise I cannot help.

This issue was opened about background region exits using:

regionBootstrap = new RegionBootstrap(this, region);

And not about using beaconManger.bind(...). If you need help on the latter means of using the library, please post a new question on StackOverflow.com, and I'll be happy to answer there.

Please only post logs in this thread that use this setup from the start of the question, otherwise I won't be able to understand what is going on:

        Identifier identifier = Identifier.parse("C48C6716-193F-477B-B73A-C550CE582A22");
        // wake up the app when a beacon is seen
        region = new Region("backgroundRegion",
                identifier, null, null);
        regionBootstrap = new RegionBootstrap(this, region);

For any log you post, I also need to know what library version was running. I can't tell that from the most recent Pixel log you posted above, as there is no log line that shows the version. Is one of these logs using only the regionBootstrap setup code described above and using version 2.11-beta1 of the library?

@davidgyoung
Copy link
Member

Looking at the latest log for the pixel that run from
00:00-00:48
and then from
01:22-01:42

I don't see any region exits in the log.

@davidgyoung
Copy link
Member

@roshanparmar, I have built a test case with steps to reproduce this problem and prove that it is fixed with 2.11-beta1. Details are in #512. Using the reference app to reproduce the problem allows us to have a test case that more than one person can run. If you think your problem reported here is not fixed as described in #512, please help create a reproducible test case with the reference app.

@davidgyoung
Copy link
Member

Sorry, @roshanparmar, I do not think I can help debug your app as I do not have the source code and many things can cause the symptoms you describe.

If you suspect the problem is with the library, please try to reproduce the problem with a minimal code example starting with the reference app. See here for my tests showing I do not get spurious region exits:

#512

Can you reproduce your problem with that reference project?

A couple of tips on your above comments:

  1. You cannot test in an emulator because you cannot get BLE callbacks.

  2. I still see permissions problems in the 5X logs posted earlier:

java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants