[MOD-2419] Android: Ti.Geofence module's "enterregions" event does not execute at the entry point but a few minutes later on Android.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Not Our Bug |
Resolution Date | 2018-12-05T11:26:26.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Geofence |
Labels | escalation |
Reporter | Jebun Naher |
Assignee | Yordan Banev |
Created | 2018-05-07T07:59:15.000+0000 |
Updated | 2020-01-19T14:34:53.000+0000 |
Description
*Issue overview:*
I implemented the ti.geofence modules for some features of automatic opening of gates while you are driving, so from app closed or in the background. In the implementation for iOS the functionality works well.
For Android, the "enterregions" event of the module is executed not at the entry point but a few minutes later, when you are already closer to the coordinates of the center of the region. I am using version 3.0.0 of the ti.geofence module with Titanium SDK 7.1.0.
*Test Code:*
var Geofence = require("ti.geofence");
//Set the latitude and longitude here
var lat = 23.802592;
var lon = 90.361040;
var window = Ti.UI.createWindow({
backgroundColor: 'white'
});
var titleInWinA = Ti.UI.createLabel({
left: 70,
top: 100,
text: "Initializing test-case ..."
});
window.add(titleInWinA);
window.addEventListener("open", function() {
checkLocationPermissions();
});
function checkLocationPermissions() {
if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS)) {
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
if (!e.success) {
Ti.API.error("Error requesting location permissions: " + e.error);
return;
}
Enterregions();
});
} else {
Enterregions();
}
}
function getCurrentPosition() {
Ti.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
alert('Error: ' + e.error);
} else {
Enterregions(e.coords.latitude, e.coords.longitude);
}
});
}
function Enterregions(l) {
var newRegion = Geofence.createRegion({
center: {
latitude: lat,
longitude: lon
},
radius: 500,
identifier: 'Grameen'
});
Geofence.startMonitoringForRegions([newRegion]);
Geofence.addEventListener("enterregions", function(e) {
Ti.API.info('####### enterregion #######: ' + JSON.stringify(e));
titleInWinA.setText(titleInWinA.text+"\n"+"enter region fired!");
alert('enter region fired');
});
Geofence.addEventListener("exitregions", function(e) {
Ti.API.info('####### exitregion #######: ' + JSON.stringify(e));
titleInWinA.setText(titleInWinA.text+"\n"+"exit region fired!");
alert('exit region fired');
});
Geofence.addEventListener("monitorregions", function(e) {
Ti.API.info('####### monitorregions #######: ' + JSON.stringify(e));
titleInWinA.setText(titleInWinA.text+"\n"+"monitoring regions");
});
}
window.open();
*Steps to reproduce:*
1. Set the latitude and longitude in the sample code.
2. Run the code and observe that when entering the area, enterregions event for Android runs in delay.
*Expected:*
The enterregions for android should fire at the entry point.
*Actual:*
It fires a few minutes later, not at the entry point.
Hello Additional note: the enterregions event is fired immediately on Android at the time when a region is added and it is already within it.
The following error is often reported in the logs: [ERROR] LocationManager: [LGNSS] Disable_PrivacyLocation_Information [tOperator : OPEN ] , [privacy_check : NA] Localization settings are High Accuracy: GPS + Cellular + WiFi
[~jnaher] On a physical device (Samsung S7 with Android 7.0), SDK 7.1.0.GA and module version 3.0.0 with mocking location updates I am getting the events almost immediately after entering the region. The delay was about 1-2 seconds no matter if I mock the center of the region or a point near the end. One thing that could help me continue with the troubleshooting is if we know whether the device is locked or not when entering the regions. Using mockup GPS keeps the device unlocked, so this may be a difference between my setup and the reported case. [~gmathews] and [~jquick], do you have some input and/or suggestions here ( I haven't dealt with ti.geofences before )?
Do we know which Android OS versions this issue is happening on? [~jnaher], can you ask the customer if this issue is only happening on Android 8.0 and newer OS versions please? I suspect that this is not an issue on older Android OS versions. And also ask if this is only happening while the app is backgrounded. [~ybanev], Google has imposed a new limitation on Android 8.0 where GPS data is only reported to backgrounded apps a few times an hour. I'm curious if this is happening with geofencing APIs too. Can you verify this please? Do you have an Android 8 device to test with? https://developer.android.com/about/versions/oreo/background-location-limits If this is the case, then the solution is to implement support for
Context.startForegroundService()
. We already have a feature request ticket written up for it here: [TIMOB-16066] The plan is to implement this in Titanium 7.3.0.Hello I asked for assistance on the geofencing of android. The devices on which we tested the sample code we received to try are the following: Samsung J5 2015 (SM-J500FN) (Android 6.0.1) LG K8 2017 (LG-M200) (Android 7.0)
Hello Are there any updates for the problem? My company purchased the Pro plan primarily to access geofencing modules. Our client for whom we are developing the app with geofencing has waited a lot, we need to solve the problem in a short time. If you need more information about it let me know. My client is doing other tests with other devices. Can the geofencing function be influenced by the hardware or the device brand? Thank you
[~sandrolain] Hello! Sorry for the late answer. Once again I was no successful in reproducing the issue on the Android versions you mentioned. In order to be able to determine whether I can do something on Titanium side about the delay in receiving the event it would be helpful to know some details of the application's/device's state: - is the application in the foreground/background? - was the application removed from the task manager before expecting the event? - is the device locked or not? - by any chance are there any battery saving/memory optimizing modes set or application running on the device? These are things that may affect the update rate of the location of the device and will help me continue troubleshooting the problem.
Hello I report here the use case of the app for its function: - The geofencing of the app must take place in the background, but in several tests we have carried out it does not even work in the foreground - The application has never been removed from the task manager in out tests - We have tried both with active screen and locked - In the devices used there are no apps or features that clean the memory or optimize the use of the battery In addition to the already reported devices with which I have personally tested, my client uses the following: Asus Zenfone 3 ZE520KL - Android 8.0.0 Samsung Galaxy A3 2017 - Android 8.0.0 Huawei Mediapad M3 Lite 10 - Android 7.0 As a comparison order, I configured geofencing notifications in the IFTTT app. With the IFTTT app the results are as follows: - Asus: IFTTT geofencing does not work - Samsung: IFTTT geofencing takes place 15 minutes after entering the region - Huawei: IFTTT geofencing takes place immediately upon entry into the region. In this case the ti.geofence module did not report entry into the region The ti.geofence module sometimes executes the entry event in the region when regions are added when I'am already inside them. To verify that the configuration of the ranges occurred correctly, I have added calls to a my webservice to record when regions are removed, regions are updated, and regions have entered. The regions are configured correctly, in the same way as the iOS app, but unlike this, the entry events in the range do not happen.
Hello Thanks for the support. From the indicated link I can not download the zip with the 7.1.2 trial version, dropbox returns not found.
In some tests I've done today (at the moment without the recommended changes), I get these debug and error messages: [DEBUG] GeofenceRemover: CONNECTED to Location Services [DEBUG] GeofenceRequester: Connected to GoogleApiClient [DEBUG] GeofenceRemover: Remove GeoFence intent SUCCESS [ERROR] GeofenceRequester: Add Geofence result FAILURE with code: 1000 [DEBUG] GeofenceModule: (main) [100,112615] GeofenceLocalBroadcastReceiver ACTION_GEOFENCES_REMOVED [DEBUG] GeofenceModule: (main) [0,112615] GeofenceLocalBroadcastReceiver ACTION_GEOFENCE_ERROR [ERROR] GeofenceModule: (main) [0,112615] Add Geofence result FAILURE with code: 1000
[~sandrolain], Regarding this log message... {quote}[ERROR] GeofenceRequester: Add Geofence result FAILURE with code: 1000{quote} An error code of
1000
is aGEOFENCE_NOT_AVAILABLE
error... https://developers.google.com/android/reference/com/google/android/gms/location/LocationStatusCodes.html#GEOFENCE_NOT_AVAILABLE This can happen if "Location Services" is disabled on the device. So, you'll need to go to your device's "Settings->Location" screen and make sure location services is enabled. I suspect this might be the cause of the error. In Titanium, you can double check if this is enabled by reading theTi.Geolocation.locationServicesEnabled
property. If it'sfalse
, then you may need to display a warning to the end-user to enable it for this feature to work. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-property-locationServicesEnabled You should also double check that your app has been granted location permissions. On Android 6.0 and above, the end-user has to grant the app permission. You can enable this yourself under Settings->Apps. But the best solution is to use ourTi.Geolocation.requestLocationPermissions()
API as documented here... https://docs.appcelerator.com/platform/latest/#!/api/Titanium.GeolocationHello I tried to verify Ti.Geolocation.locationServicesEnabled. Ti.Geolocation.locationServicesEnabled is TRUE if I first request location permissions, while FALSE is the one I check before requesting location permissions. In the first case, Ti.Geolocation.requestLocationPermissions is SUCCESS, and Ti.Geolocation.locationServicesEnabled is TRUE, and I get to create the regions. In the device in use, the localization services are active in "High accuracy (GPS and networks)" mode, but the error message 1000 appears as shown. Before each check, the following error message always appears: [ERROR] LocationManager: [LGNSS] Disable_PrivacyLocation_Information [tOperator : OPEN ] , [privacy_check : NA]
The error and the enabling of the services I previously reported refer to an LG device with Android 7.0. I then tried with another Samsung device with Android 6.0.1, always with permissions enabled, Ti.Geolocation.locationServicesEnabled = TRUE. The last reported error does not appear, the regions are added, but the enterregions event is not executed.
Hello everyone The problem could be due to limitations or other issues with Goole Play Services?
[~sandrolain] There is a chance it can cause the problem, yes? Can you share details what limitations or issues you have observed? You can now get an SDK with the "Foreground Service" support merged from our pre-built SDK list: http://builds.appcelerator.com/#master Also you mentioned that you have personally tested the sample code with some of the devices. Can you share details about your set up? Were you using mocking locations or physically moved to the regions defined? If the former - any specifics about the setting up the mocking location can come in hand. Did you notice any relation between the region's size and position, and the different results you got from the module?
Hello everyone I resumed today tests on this app, with the release of SDK 7.3.0 and now on two devices Samsung with Android 5 and 7 geofencing seems to work. In the LG device that I mentioned previously, I still find the error: [ERROR] GeofenceRequester: Add Geofence result FAILURE with code: 1000 ... The tests I carried out are all on the field with real simulations (moving with my car).
[~sandrolain] According to these status codes: https://developers.google.com/android/reference/com/google/android/gms/location/GeofenceStatusCodes.html#GEOFENCE_NOT_AVAILABLE that value may be received due to location access not being enabled. Is there a chance this may be the case with this device?
Location access is enabled on device (GPS + mobile + wifi) and permissions are enabled for the app. I think at this point it may be a system problem. I will reset the phone and then I will let you know.
Hello I was able to reset the LG phone to factory and now the geofencing seems to work properly. I could verify that with Android 5.0 - 7.0 the operation happens both foreground and background, while with Android 8.0 it seems not to work in the background. I have seen that it is necessary to implement a foreground service but I have difficulty understanding which is the correct way. Is there any example? Thank you
[~sandrolain] In the PR for the foreground support there is a sample app demonstrating foreground service with device's location. Check the *Test:* paragraph: https://github.com/appcelerator/titanium_mobile/pull/10076 It has a list of steps and code samples for a working example.
Just to make sure that people will perhaps find a solution when finding this older ticket: *About the FAILURE 1000:* I had the same and everything was setup correctly (Android 10). BUT I've disabled this setting on my phone because I don't want to send my location to google: !https://www.androidpolice.com/wp-content/uploads/2018/03/nexus2cee_android-p-location-settings.png! (Location accuracy improvements) Turns out: it is needed to use geofencing! That's why the user above had it working when the phone was reseted. As soons as I turn it back on the failure code 1000 is gone and my fence is found.