airsdk / Adobe-Runtime-Support

Report, track and discuss issues in Adobe AIR. Monitored by Adobe - and HARMAN - and maintained by the AIR community.
206 stars 11 forks source link

[Android 12+] `Geolocation::permissionStatus` returns `PermissionStatus.DENIED` when approximate location granted #2822

Open itlancer opened 1 year ago

itlancer commented 1 year ago

Problem Description

Geolocation::permissionStatus returns PermissionStatus.DENIED when approximate location granted for Android 12+ devices. So with AIR applications you cannot use location services for Android 12+ in approximate mode. But GeolocationEvent.UPDATE events will dispatches anyway.

Tested with latest AIR 50.2.3.4 and AIR 50.2.3.5 with different AIR applications and different Android 12+ devices with different architectures. Same problem in all cases. There is no such issue if "Precise" mode was selected. There is no such issue with Android 11 and below. Also there is no such issue with iOS.

Related issues: https://github.com/airsdk/Adobe-Runtime-Support/issues/2809 https://github.com/airsdk/Adobe-Runtime-Support/issues/2022

Steps to Reproduce

1) Launch application with code below with any Android 12+ device which has location services. 2) Click anywhere on stage. Geolocation permission grant popup will be shown. 3) Choose approximate accuracy and click "while using the app".

Application example with sources attached. android_geolocation_permissionstatus_approximate_accuracy_bug.zip

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.sensors.Geolocation;
    import flash.events.GeolocationEvent;
    import flash.events.StatusEvent;
    import flash.events.MouseEvent;
    import flash.permissions.PermissionStatus;
    import flash.events.PermissionEvent;

    public class AndroidGeolocationPermissionStatusApproximateAccuracyBug extends Sprite {
        private var geolocation:Geolocation;

        public function AndroidGeolocationPermissionStatusApproximateAccuracyBug() {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            stage.addEventListener(MouseEvent.CLICK, click);
        }

        private function locationUpdate(e:GeolocationEvent):void {
            trace("locationUpdate", e.latitude, e.longitude, e.horizontalAccuracy, Geolocation.permissionStatus);
        }

        private function statusChanged(e:StatusEvent):void {
            trace("statusChanged", geolocation.muted);
            startGeo();
        }

        private function geolocationPermissionStatusChanged(e:PermissionEvent):void {
            trace("geolocationPermissionStatusChanged", e.status, Geolocation.permissionStatus);//"denied"

            if (Geolocation.permissionStatus == PermissionStatus.GRANTED){//Permission granted
                startGeo();
            }
        }

        public function click(e:MouseEvent):void {
            if (Geolocation.isSupported){
                geolocation = new Geolocation();
                geolocation.locationAlwaysUsePermission = true;
                geolocation.addEventListener(GeolocationEvent.UPDATE, locationUpdate);
                geolocation.addEventListener(StatusEvent.STATUS, statusChanged);
                geolocation.addEventListener(PermissionEvent.PERMISSION_STATUS, geolocationPermissionStatusChanged);

                if (Geolocation.permissionStatus == PermissionStatus.GRANTED){//Permission granted
                    trace("permission granted");
                    startGeo();
                } else {//Permission not granted
                    trace("permission not granted: " + Geolocation.permissionStatus);
                    geolocation.requestPermission();
                }
            } else {
                trace("Geolocation not supported");
            }
        }

        public function startGeo():void {
            geolocation.desiredAccuracy = Geolocation.LOCATION_ACCURACY_BEST;
            geolocation.pausesLocationUpdatesAutomatically = false;
            geolocation.setRequestedUpdateInterval(5000);
        }
    }
}

Actual Result: AIR report that geolocation permission not granted. In traces you will see:

permission not granted: unknown
geolocationPermissionStatusChanged denied denied
locationUpdate 0.7027027027027 0.07215763452547 2000 denied

Expected Result: AIR report that geolocation permission granted. In traces you will see:

permission not granted: unknown
geolocationPermissionStatusChanged granted granted
locationUpdate 0.704985 0.0635457 12.593000411987305 granted

Known Workarounds

none

raresn commented 1 year ago

Could this be target sdk 33 related? maybe you can try with 32?

itlancer commented 1 year ago

@raresn Nope. The same issue using <uses-sdk android:targetSdkVersion="32" /> May be it could be solved using target Android SDK 30 (Android 11) but apps targeted for old Android SDK cannot be uploaded to Google Play.