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

Commit 4380adab authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

DO NOT MERGE - Request location from all available providers

am: f279858a

Change-Id: I55c48e3f9e6c4949fd53f911291e593752efbb33
parents 1ff76445 f279858a
Loading
Loading
Loading
Loading
+30 −21
Original line number Diff line number Diff line
@@ -298,13 +298,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
@@ -356,6 +356,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,
@@ -382,8 +387,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);
                }
            }
        }
@@ -402,22 +426,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) {