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

Commit ba9ab183 authored by Bernd Holzhey's avatar Bernd Holzhey
Browse files

Fix: Retrieval of location to caclulate twilight

The provider determined by getBestProvider may not have a LastKnownLocation and
therefore the system might use a fake location, even if one provider will have
a location.

Change-Id: Iec4a377b141b0260af5611f51affa5f0c4a84ed2
parent a028a4b5
Loading
Loading
Loading
Loading
+37 −32
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.util.Slog;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Iterator;

import com.android.internal.R;
import com.android.internal.app.DisableCarModeActivity;
@@ -609,14 +610,18 @@ class UiModeManagerService extends IUiModeManager.Stub {
        }

        private void retrieveLocation() {
            Location location;
            Criteria criteria = new Criteria();
            criteria.setSpeedRequired(false);
            criteria.setAltitudeRequired(false);
            criteria.setBearingRequired(false);
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            final String bestProvider = mLocationManager.getBestProvider(criteria, true);
            location = mLocationManager.getLastKnownLocation(bestProvider);
            Location location = null;
            final Iterator<String> providers =
                    mLocationManager.getProviders(new Criteria(), true).iterator();
            while (providers.hasNext()) {
                final Location lastKnownLocation =
                        mLocationManager.getLastKnownLocation(providers.next());
                // pick the most recent location
                if (location == null || (lastKnownLocation != null &&
                        location.getTime() < lastKnownLocation.getTime())) {
                    location = lastKnownLocation;
                }
            }
            // In the case there is no location available (e.g. GPS fix or network location
            // is not available yet), the longitude of the location is estimated using the timezone,
            // latitude and accuracy are set to get a good average.