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

Commit daa4373b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix passive+coarse location bug"

parents d9150257 5dfcc21c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -491,7 +491,7 @@ class LocationProviderManager extends
                    builder.setIntervalMillis(MIN_COARSE_INTERVAL_MS);
                }
                if (baseRequest.getMinUpdateIntervalMillis() < MIN_COARSE_INTERVAL_MS) {
                    builder.clearMinUpdateIntervalMillis();
                    builder.setMinUpdateIntervalMillis(MIN_COARSE_INTERVAL_MS);
                }
            }

+33 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.AppOpsManager.OP_MONITOR_LOCATION;
import static android.location.Criteria.ACCURACY_COARSE;
import static android.location.Criteria.ACCURACY_FINE;
import static android.location.Criteria.POWER_HIGH;
import static android.location.LocationRequest.PASSIVE_INTERVAL;
import static android.os.PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF;

import static androidx.test.ext.truth.location.LocationSubject.assertThat;
@@ -597,6 +598,38 @@ public class LocationProviderManagerTest {
        verify(mWakeLock, timeout(TIMEOUT_MS)).release();
    }

    @Test
    public void testRegisterListener_Coarse() throws Exception {
        ILocationListener listener = createMockLocationListener();
        mManager.registerLocationRequest(
                new LocationRequest.Builder(0).setWorkSource(WORK_SOURCE).build(),
                IDENTITY,
                PERMISSION_COARSE,
                listener);

        mProvider.setProviderLocation(createLocation(NAME, mRandom));
        mProvider.setProviderLocation(createLocation(NAME, mRandom));
        verify(listener, times(1))
                .onLocationChanged(any(Location.class), nullable(IRemoteCallback.class));
    }

    @Test
    public void testRegisterListener_Coarse_Passive() throws Exception {
        ILocationListener listener = createMockLocationListener();
        mManager.registerLocationRequest(
                new LocationRequest.Builder(PASSIVE_INTERVAL)
                        .setMinUpdateIntervalMillis(0)
                        .setWorkSource(WORK_SOURCE).build(),
                IDENTITY,
                PERMISSION_COARSE,
                listener);

        mProvider.setProviderLocation(createLocation(NAME, mRandom));
        mProvider.setProviderLocation(createLocation(NAME, mRandom));
        verify(listener, times(1))
                .onLocationChanged(any(Location.class), nullable(IRemoteCallback.class));
    }

    @Test
    public void testGetCurrentLocation() throws Exception {
        ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);