Unibozu opened a new issue #141: Denying Android location permission triggers 
pause/resume cycle
URL: https://github.com/apache/cordova-plugin-geolocation/issues/141
 
 
   Hi,
   
   The geolocation plugin triggers a `pause` and `resume` event when you deny 
the location permission multiple time and then tick "Do not ask me again". This 
doesn't happen if you remove `cordova-plugin-geolocation` but the permission is 
not requested.
   
   I would not expect these events to be triggered all the time, as it can have 
some annoying side effects in the application.
   
   Example: we use an interval to manually request a new location every few 
seconds when using the app, `geolocation.getCurrentPosition` is called when the 
timer is fired, which can actually happen when the app is in background (I'm 
thinking to ask more about this on the **cordova-android** repo as this is 
unexpected). Generally not a problem, however with `cordova-plugin-geolocation` 
triggering its own `resume` event when the app is in the background, the app is 
re-opened automatically. We're looking at changing the implementation to 
manually stop all timeout and interval when the app is paused, which will fix 
the issue, however I think it's worth looking into `cordova-plugin-geolocation` 
to fix or document this behaviour.
   
   ### POC
   
   ```
   cordova create test-geolocation && cd test-geolocation
   cordova platform add android
   corvova plugin add cordova-plugin-geolocation
   ```
   
   Replace `www/index.html` with the one provided
   
   ```html
   <!DOCTYPE html>
   <html>
   
   <head>
       <meta name="format-detection" content="telephone=no">
       <meta name="msapplication-tap-highlight" content="no">
       <meta name="viewport" content="user-scalable=no, initial-scale=1, 
maximum-scale=1, minimum-scale=1, width=device-width">
       <link rel="stylesheet" type="text/css" href="css/index.css">
       <title>Hello World</title>
   
       <style>
           #log {height: 300px;overflow-x:auto;font-family: 
monospace;font-size: 12px;margin: 10px;padding:10px;border: 1px solid 
#999;text-transform:none;}
           #log div {padding: 3px 0;border-bottom: 1px solid #ccc;}
       </style>
   </head>
   
   <body>
       <div>
           <h1>Geolocation background test</h1>
   
           <button onclick="$log.innerHTML = '';" style="float: right;">clear 
log</button>
   
           <button onclick="request()">request()</button>
           <br>
           <div id="log"></div>
       </div>
       <script type="text/javascript" src="cordova.js"></script>
       <script>
           const $log = document.getElementById('log');
           function log(...args) {
               args.map(function (line) {
                   const div = document.createElement('div');
                   div.innerText = new Date().toISOString().replace(/^.+T/g, 
'') + ' - ' + line;
                   $log.prepend(div);
               });
               console.log.apply(console, args);
           };
   
           document.addEventListener('resume', () => log('event received: 
resume'));
           document.addEventListener('pause', () => log('event received: 
pause'));
   
           requestWrappedInTimeout();
   
           function request() {
               log('request()');
   
               log('geolocation.getCurrentPosition()');
               navigator.geolocation.getCurrentPosition(
                   (res) => log('geolocation response  -  ' + 
JSON.stringify(res)),
                   (err) => log('geolocation error' + JSON.stringify(err)));
           }
       </script>
   </body>
   </html>
   ```
   
   Run on a device (I have not tested with an emulator) `cordova run android 
--device`. Tap on the "request" button, then deny the permission, check "do not 
ask again" and keep tapping on "request()" you will be able to see "pause" and 
"resume" events around the geolocation error callback.
   
   Confirmed on a Samsun Galaxy S7 running Android 7.0, and a OnePlus 6T 
running Android 9.0.11, and a few customers had the same issue too.
   
   If you want to trigger the app taking focus of the screen, redo the steps 
totick "do not ask again", add `setTimeout(() => request(), 10000)` and go back 
to the homescreen. The app will reappear automatically after 10 seconds.
   
   ADB logs
   
   ```
   01-16 14:25:19.572 26914 26914 I chromium: [INFO:CONSOLE(48)] 
"geolocation.getCurrentPosition()", source: 
file:///android_asset/www/index.html (48)
   01-16 14:25:19.652 26914 26914 I chromium: [INFO:CONSOLE(48)] "event 
received: pause", source: file:///android_asset/www/index.html (48)
   01-16 14:25:19.785 26914 26914 I chromium: [INFO:CONSOLE(48)] "geolocation 
error{"code":1,"message":"Illegal Access"}", source: 
file:///android_asset/www/index.html (48)
   01-16 14:25:19.786 26914 26914 I chromium: [INFO:CONSOLE(48)] "event 
received: resume", source: file:///android_asset/www/index.html (48)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to