Fix VpnSettings.StatusChecker.start()

to avoid multiple threads checking status at the same time.
This commit is contained in:
Hung-ying Tyan
2009-07-13 17:23:32 +08:00
parent 1ddccd07f7
commit fe0b0178cb
2 changed files with 5 additions and 4 deletions

View File

@@ -195,8 +195,8 @@ public class AuthenticationActor implements VpnProfileActor {
if (bindService(c)) { if (bindService(c)) {
// wait for a second, let status propagate // wait for a second, let status propagate
wait(c, ONE_SECOND); wait(c, ONE_SECOND);
mContext.unbindService(c);
} }
mContext.unbindService(c);
} }
private boolean bindService(ServiceConnection c) { private boolean bindService(ServiceConnection c) {

View File

@@ -932,7 +932,7 @@ public class VpnSettings extends PreferenceActivity implements
// managing status check in a background thread // managing status check in a background thread
private class StatusChecker { private class StatusChecker {
private Set<VpnProfile> mQueue = new HashSet<VpnProfile>(); private Set<VpnProfile> mQueue = new HashSet<VpnProfile>();
private boolean mPaused; private boolean mPaused = true;
private ConditionVariable mThreadCv = new ConditionVariable(); private ConditionVariable mThreadCv = new ConditionVariable();
void onPause() { void onPause() {
@@ -941,7 +941,6 @@ public class VpnSettings extends PreferenceActivity implements
} }
synchronized void onResume() { synchronized void onResume() {
mPaused = false;
start(); start();
} }
@@ -961,7 +960,9 @@ public class VpnSettings extends PreferenceActivity implements
return p; return p;
} }
private void start() { private synchronized void start() {
if (!mPaused) return;
mPaused = false;
mThreadCv.close(); mThreadCv.close();
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {