diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-22 00:13:42 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-22 00:13:42 -0800 |
commit | f1e484acb594a726fb57ad0ae4cfe902c7f35858 (patch) | |
tree | 99d2b34512f0dc2ae67666e756c1cfcd331e5fe3 /location | |
parent | 22f7dfd23490a3de2f21ff96949ba47003aac8f8 (diff) | |
download | frameworks_base-f1e484acb594a726fb57ad0ae4cfe902c7f35858.zip frameworks_base-f1e484acb594a726fb57ad0ae4cfe902c7f35858.tar.gz frameworks_base-f1e484acb594a726fb57ad0ae4cfe902c7f35858.tar.bz2 |
auto import from //branches/cupcake/...@127436
Diffstat (limited to 'location')
-rw-r--r-- | location/java/com/android/internal/location/GpsLocationProvider.java | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index 3d4d4a2..c6f13c9 100644 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -155,6 +155,7 @@ public class GpsLocationProvider extends LocationProviderImpl { private ArrayList<Listener> mListeners = new ArrayList<Listener>(); private GpsEventThread mEventThread; private GpsNetworkThread mNetworkThread; + private Object mNetworkThreadLock = new Object(); // how often to request NTP time, in milliseconds // current setting 4 hours @@ -301,8 +302,9 @@ public class GpsLocationProvider extends LocationProviderImpl { * when the provider is enabled. */ @Override - public void enable() { + public synchronized void enable() { if (Config.LOGD) Log.d(TAG, "enable"); + if (mEnabled) return; mEnabled = native_init(); if (mEnabled) { @@ -330,8 +332,10 @@ public class GpsLocationProvider extends LocationProviderImpl { * down while the provider is disabled. */ @Override - public void disable() { + public synchronized void disable() { if (Config.LOGD) Log.d(TAG, "disable"); + if (!mEnabled) return; + mEnabled = false; stopNavigating(); native_disable(); @@ -346,6 +350,11 @@ public class GpsLocationProvider extends LocationProviderImpl { mEventThread = null; } + if (mNetworkThread != null) { + mNetworkThread.setDone(); + mNetworkThread = null; + } + native_cleanup(); } @@ -745,12 +754,21 @@ public class GpsLocationProvider extends LocationProviderImpl { private long mNextNtpTime = 0; private long mNextXtraTime = 0; private boolean mXtraDownloadRequested = false; + private boolean mDone = false; public GpsNetworkThread() { super("GpsNetworkThread"); } public void run() { + synchronized (mNetworkThreadLock) { + if (!mDone) { + runLocked(); + } + } + } + + public void runLocked() { if (Config.LOGD) Log.d(TAG, "NetworkThread starting"); SntpClient client = new SntpClient(); @@ -761,7 +779,7 @@ public class GpsLocationProvider extends LocationProviderImpl { } // thread exits after disable() is called - while (mEnabled) { + while (!mDone) { long waitTime = getWaitTime(); do { synchronized (this) { @@ -784,11 +802,11 @@ public class GpsLocationProvider extends LocationProviderImpl { } } waitTime = getWaitTime(); - } while (mEnabled && ((!mXtraDownloadRequested && waitTime > 0) + } while (!mDone && ((!mXtraDownloadRequested && waitTime > 0) || !mNetworkAvailable)); if (Config.LOGD) Log.d(TAG, "NetworkThread out of wake loop"); - if (mEnabled) { + if (!mDone) { if (mNtpServer != null && mNextNtpTime <= System.currentTimeMillis()) { if (Config.LOGD) { @@ -840,6 +858,12 @@ public class GpsLocationProvider extends LocationProviderImpl { notify(); } + synchronized void setDone() { + if (Config.LOGD) Log.d(TAG, "stopping NetworkThread"); + mDone = true; + notify(); + } + private long getWaitTime() { long now = System.currentTimeMillis(); long waitTime = Long.MAX_VALUE; |