Loading services/core/java/com/android/server/connectivity/PacManager.java +22 −19 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ */ package com.android.server.connectivity; package com.android.server.connectivity; import android.annotation.WorkerThread; import android.app.AlarmManager; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; Loading Loading @@ -74,7 +75,7 @@ public class PacManager { public static final String KEY_PROXY = "keyProxy"; public static final String KEY_PROXY = "keyProxy"; private String mCurrentPac; private String mCurrentPac; @GuardedBy("mProxyLock") @GuardedBy("mProxyLock") private Uri mPacUrl = Uri.EMPTY; private volatile Uri mPacUrl = Uri.EMPTY; private AlarmManager mAlarmManager; private AlarmManager mAlarmManager; @GuardedBy("mProxyLock") @GuardedBy("mProxyLock") Loading @@ -87,34 +88,38 @@ public class PacManager { private int mCurrentDelay; private int mCurrentDelay; private int mLastPort; private int mLastPort; private boolean mHasSentBroadcast; private volatile boolean mHasSentBroadcast; private boolean mHasDownloaded; private volatile boolean mHasDownloaded; private Handler mConnectivityHandler; private Handler mConnectivityHandler; private int mProxyMessage; private int mProxyMessage; /** /** * Used for locking when setting mProxyService and all references to mPacUrl or mCurrentPac. * Used for locking when setting mProxyService and all references to mCurrentPac. */ */ private final Object mProxyLock = new Object(); private final Object mProxyLock = new Object(); /** * Runnable to download PAC script. * The behavior relies on the assamption it always run on mNetThread to guarantee that the * latest data fetched from mPacUrl is stored in mProxyService. */ private Runnable mPacDownloader = new Runnable() { private Runnable mPacDownloader = new Runnable() { @Override @Override @WorkerThread public void run() { public void run() { String file; String file; synchronized (mProxyLock) { final Uri pacUrl = mPacUrl; if (Uri.EMPTY.equals(mPacUrl)) return; if (Uri.EMPTY.equals(pacUrl)) return; final int oldTag = TrafficStats final int oldTag = TrafficStats.getAndSetThreadStatsTag(TrafficStats.TAG_SYSTEM_PAC); .getAndSetThreadStatsTag(TrafficStats.TAG_SYSTEM_PAC); try { try { file = get(mPacUrl); file = get(pacUrl); } catch (IOException ioe) { } catch (IOException ioe) { file = null; file = null; Log.w(TAG, "Failed to load PAC file: " + ioe); Log.w(TAG, "Failed to load PAC file: " + ioe); } finally { } finally { TrafficStats.setThreadStatsTag(oldTag); TrafficStats.setThreadStatsTag(oldTag); } } } if (file != null) { if (file != null) { synchronized (mProxyLock) { synchronized (mProxyLock) { if (!file.equals(mCurrentPac)) { if (!file.equals(mCurrentPac)) { Loading Loading @@ -176,9 +181,7 @@ public class PacManager { // Allow to send broadcast, nothing to do. // Allow to send broadcast, nothing to do. return false; return false; } } synchronized (mProxyLock) { mPacUrl = proxy.getPacFileUrl(); mPacUrl = proxy.getPacFileUrl(); } mCurrentDelay = DELAY_1; mCurrentDelay = DELAY_1; mHasSentBroadcast = false; mHasSentBroadcast = false; mHasDownloaded = false; mHasDownloaded = false; Loading Loading
services/core/java/com/android/server/connectivity/PacManager.java +22 −19 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ */ package com.android.server.connectivity; package com.android.server.connectivity; import android.annotation.WorkerThread; import android.app.AlarmManager; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.BroadcastReceiver; Loading Loading @@ -74,7 +75,7 @@ public class PacManager { public static final String KEY_PROXY = "keyProxy"; public static final String KEY_PROXY = "keyProxy"; private String mCurrentPac; private String mCurrentPac; @GuardedBy("mProxyLock") @GuardedBy("mProxyLock") private Uri mPacUrl = Uri.EMPTY; private volatile Uri mPacUrl = Uri.EMPTY; private AlarmManager mAlarmManager; private AlarmManager mAlarmManager; @GuardedBy("mProxyLock") @GuardedBy("mProxyLock") Loading @@ -87,34 +88,38 @@ public class PacManager { private int mCurrentDelay; private int mCurrentDelay; private int mLastPort; private int mLastPort; private boolean mHasSentBroadcast; private volatile boolean mHasSentBroadcast; private boolean mHasDownloaded; private volatile boolean mHasDownloaded; private Handler mConnectivityHandler; private Handler mConnectivityHandler; private int mProxyMessage; private int mProxyMessage; /** /** * Used for locking when setting mProxyService and all references to mPacUrl or mCurrentPac. * Used for locking when setting mProxyService and all references to mCurrentPac. */ */ private final Object mProxyLock = new Object(); private final Object mProxyLock = new Object(); /** * Runnable to download PAC script. * The behavior relies on the assamption it always run on mNetThread to guarantee that the * latest data fetched from mPacUrl is stored in mProxyService. */ private Runnable mPacDownloader = new Runnable() { private Runnable mPacDownloader = new Runnable() { @Override @Override @WorkerThread public void run() { public void run() { String file; String file; synchronized (mProxyLock) { final Uri pacUrl = mPacUrl; if (Uri.EMPTY.equals(mPacUrl)) return; if (Uri.EMPTY.equals(pacUrl)) return; final int oldTag = TrafficStats final int oldTag = TrafficStats.getAndSetThreadStatsTag(TrafficStats.TAG_SYSTEM_PAC); .getAndSetThreadStatsTag(TrafficStats.TAG_SYSTEM_PAC); try { try { file = get(mPacUrl); file = get(pacUrl); } catch (IOException ioe) { } catch (IOException ioe) { file = null; file = null; Log.w(TAG, "Failed to load PAC file: " + ioe); Log.w(TAG, "Failed to load PAC file: " + ioe); } finally { } finally { TrafficStats.setThreadStatsTag(oldTag); TrafficStats.setThreadStatsTag(oldTag); } } } if (file != null) { if (file != null) { synchronized (mProxyLock) { synchronized (mProxyLock) { if (!file.equals(mCurrentPac)) { if (!file.equals(mCurrentPac)) { Loading Loading @@ -176,9 +181,7 @@ public class PacManager { // Allow to send broadcast, nothing to do. // Allow to send broadcast, nothing to do. return false; return false; } } synchronized (mProxyLock) { mPacUrl = proxy.getPacFileUrl(); mPacUrl = proxy.getPacFileUrl(); } mCurrentDelay = DELAY_1; mCurrentDelay = DELAY_1; mHasSentBroadcast = false; mHasSentBroadcast = false; mHasDownloaded = false; mHasDownloaded = false; Loading