Loading packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java +38 −12 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.internal.annotations.GuardedBy; import java.io.PrintWriter; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; /** Basic fused location provider implementation. */ public class FusedLocationProvider extends LocationProviderBase { Loading @@ -68,6 +69,12 @@ public class FusedLocationProvider extends LocationProviderBase { private final ChildLocationListener mNetworkListener; private final BroadcastReceiver mUserChangeReceiver; @GuardedBy("mLock") boolean mGpsPresent; @GuardedBy("mLock") boolean mNlpPresent; @GuardedBy("mLock") private ProviderRequest mRequest; Loading Loading @@ -119,29 +126,48 @@ public class FusedLocationProvider extends LocationProviderBase { @Override public void onFlush(OnFlushCompleteCallback callback) { OnFlushCompleteCallback wrapper = new OnFlushCompleteCallback() { private int mFlushCount = 2; synchronized (mLock) { AtomicInteger flushCount = new AtomicInteger(0); if (mGpsPresent) { flushCount.incrementAndGet(); } if (mNlpPresent) { flushCount.incrementAndGet(); } @Override public void onFlushComplete() { if (--mFlushCount == 0) { OnFlushCompleteCallback wrapper = () -> { if (flushCount.decrementAndGet() == 0) { callback.onFlushComplete(); } } }; if (mGpsPresent) { mGpsListener.flush(wrapper); } if (mNlpPresent) { mNetworkListener.flush(wrapper); } } } @Override public void onSendExtraCommand(String command, @Nullable Bundle extras) {} @GuardedBy("mLock") private void updateRequirementsLocked() { long gpsInterval = mRequest.getQuality() < QUALITY_LOW_POWER ? mRequest.getIntervalMillis() : INTERVAL_DISABLED; long networkInterval = mRequest.getIntervalMillis(); // it's possible there might be race conditions on device start where a provider doesn't // appear to be present yet, but once a provider is present it shouldn't go away. if (!mGpsPresent) { mGpsPresent = mLocationManager.hasProvider(GPS_PROVIDER); } if (!mNlpPresent) { mNlpPresent = mLocationManager.hasProvider(NETWORK_PROVIDER); } long gpsInterval = mGpsPresent && (!mNlpPresent || mRequest.getQuality() < QUALITY_LOW_POWER) ? mRequest.getIntervalMillis() : INTERVAL_DISABLED; long networkInterval = mNlpPresent ? mRequest.getIntervalMillis() : INTERVAL_DISABLED; mGpsListener.resetProviderRequest(gpsInterval); mNetworkListener.resetProviderRequest(networkInterval); Loading Loading
packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java +38 −12 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.internal.annotations.GuardedBy; import java.io.PrintWriter; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; /** Basic fused location provider implementation. */ public class FusedLocationProvider extends LocationProviderBase { Loading @@ -68,6 +69,12 @@ public class FusedLocationProvider extends LocationProviderBase { private final ChildLocationListener mNetworkListener; private final BroadcastReceiver mUserChangeReceiver; @GuardedBy("mLock") boolean mGpsPresent; @GuardedBy("mLock") boolean mNlpPresent; @GuardedBy("mLock") private ProviderRequest mRequest; Loading Loading @@ -119,29 +126,48 @@ public class FusedLocationProvider extends LocationProviderBase { @Override public void onFlush(OnFlushCompleteCallback callback) { OnFlushCompleteCallback wrapper = new OnFlushCompleteCallback() { private int mFlushCount = 2; synchronized (mLock) { AtomicInteger flushCount = new AtomicInteger(0); if (mGpsPresent) { flushCount.incrementAndGet(); } if (mNlpPresent) { flushCount.incrementAndGet(); } @Override public void onFlushComplete() { if (--mFlushCount == 0) { OnFlushCompleteCallback wrapper = () -> { if (flushCount.decrementAndGet() == 0) { callback.onFlushComplete(); } } }; if (mGpsPresent) { mGpsListener.flush(wrapper); } if (mNlpPresent) { mNetworkListener.flush(wrapper); } } } @Override public void onSendExtraCommand(String command, @Nullable Bundle extras) {} @GuardedBy("mLock") private void updateRequirementsLocked() { long gpsInterval = mRequest.getQuality() < QUALITY_LOW_POWER ? mRequest.getIntervalMillis() : INTERVAL_DISABLED; long networkInterval = mRequest.getIntervalMillis(); // it's possible there might be race conditions on device start where a provider doesn't // appear to be present yet, but once a provider is present it shouldn't go away. if (!mGpsPresent) { mGpsPresent = mLocationManager.hasProvider(GPS_PROVIDER); } if (!mNlpPresent) { mNlpPresent = mLocationManager.hasProvider(NETWORK_PROVIDER); } long gpsInterval = mGpsPresent && (!mNlpPresent || mRequest.getQuality() < QUALITY_LOW_POWER) ? mRequest.getIntervalMillis() : INTERVAL_DISABLED; long networkInterval = mNlpPresent ? mRequest.getIntervalMillis() : INTERVAL_DISABLED; mGpsListener.resetProviderRequest(gpsInterval); mNetworkListener.resetProviderRequest(networkInterval); Loading