Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f279858a authored by Jack Yu's avatar Jack Yu
Browse files

DO NOT MERGE - Request location from all available providers

Request location from both network (e.g. cell, wifi) and
GPS provider. Previously we only rely on network provider
if it's available. GPS will only be used when network
provider is not available.

Bug: 144728828
Test: Manual
Change-Id: I1a53760d2adc365d23f8fa98409bd07f6ea7050b
parent 78e766ac
Loading
Loading
Loading
Loading
+30 −21
Original line number Diff line number Diff line
@@ -297,13 +297,13 @@ public class CellBroadcastHandler extends WakeLockStateMachine {
    }

    private static final class LocationRequester {
        private static final String TAG = LocationRequester.class.getSimpleName();
        private static final String TAG = CellBroadcastHandler.class.getSimpleName();

        /**
         * Use as the default maximum wait time if the cell broadcast doesn't specify the value.
         * Most of the location request should be responded within 20 seconds.
         * Most of the location request should be responded within 30 seconds.
         */
        private static final int DEFAULT_MAXIMUM_WAIT_TIME_SEC = 20;
        private static final int DEFAULT_MAXIMUM_WAIT_TIME_SEC = 30;

        /**
         * Trigger this event when the {@link LocationManager} is not responded within the given
@@ -355,6 +355,11 @@ public class CellBroadcastHandler extends WakeLockStateMachine {
                callback.onLocationUpdate(location);
            }
            mCallbacks.clear();

            for (LocationListener listener : mLocationListenerList) {
                mLocationManager.removeUpdates(listener);
            }
            mLocationListenerList.clear();
        }

        private void requestLocationUpdateInternal(@NonNull LocationUpdateCallback callback,
@@ -381,8 +386,27 @@ public class CellBroadcastHandler extends WakeLockStateMachine {

            for (String provider : LOCATION_PROVIDERS) {
                if (mLocationManager.isProviderEnabled(provider)) {
                    mLocationManager.requestSingleUpdate(provider, mLocationListener, mLooper);
                    break;
                    LocationListener listener = new LocationListener() {
                        @Override
                        public void onLocationChanged(Location location) {
                            mLocationListenerList.remove(this);
                            mLocationHandler.removeMessages(EVENT_LOCATION_REQUEST_TIMEOUT);
                            onLocationUpdate(new LatLng(location.getLatitude(),
                                    location.getLongitude()));
                        }

                        @Override
                        public void onStatusChanged(String provider, int status, Bundle extras) {}

                        @Override
                        public void onProviderEnabled(String provider) {}

                        @Override
                        public void onProviderDisabled(String provider) {}
                    };
                    mLocationListenerList.add(listener);
                    Log.d(TAG, "Request location single update from " + provider);
                    mLocationManager.requestSingleUpdate(provider, listener, mLooper);
                }
            }
        }
@@ -401,22 +425,7 @@ public class CellBroadcastHandler extends WakeLockStateMachine {
                    permission) == PERMISSION_GRANTED;
        }

        private final LocationListener mLocationListener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                mLocationHandler.removeMessages(EVENT_LOCATION_REQUEST_TIMEOUT);
                onLocationUpdate(new LatLng(location.getLatitude(), location.getLongitude()));
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {}

            @Override
            public void onProviderEnabled(String provider) {}

            @Override
            public void onProviderDisabled(String provider) {}
        };
        private final List<LocationListener> mLocationListenerList = new ArrayList<>();

        private final class LocationHandler extends Handler {
            LocationHandler(Looper looper) {