ProxyDataTrackerpublic class ProxyDataTracker extends BaseNetworkStateTracker A data tracker responsible for bringing up and tearing down the system proxy server.
{@hide} |
Fields Summary |
---|
private static final String | TAG | private static final String | NETWORK_TYPE | private static final String | DNS1 | private static final String | DNS2 | private static final String | INTERFACE_NAME | private static final String | REASON_ENABLED | private static final String | REASON_DISABLED | private static final String | REASON_PROXY_DOWN | private static final int | MSG_TEAR_DOWN_REQUEST | private static final int | MSG_SETUP_REQUEST | private static final String | PERMISSION_PROXY_STATUS_SENDER | private static final String | ACTION_PROXY_STATUS_CHANGE | private static final String | KEY_IS_PROXY_AVAILABLE | private static final String | KEY_REPLY_TO_MESSENGER_BINDER | private static final String | KEY_REPLY_TO_MESSENGER_BINDER_BUNDLE | private android.os.Handler | mTarget | private android.os.Messenger | mProxyStatusService | private AtomicBoolean | mReconnectRequested | private AtomicBoolean | mIsProxyAvailable | private final AtomicInteger | mDefaultGatewayAddr | private final android.content.BroadcastReceiver | mProxyStatusServiceListener |
Constructors Summary |
---|
public ProxyDataTracker()Create a new ProxyDataTracker
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_PROXY, 0, NETWORK_TYPE, "");
mLinkProperties = new LinkProperties();
mNetworkCapabilities = new NetworkCapabilities();
mNetworkInfo.setIsAvailable(true);
try {
mLinkProperties.addDnsServer(InetAddress.getByName(DNS1));
mLinkProperties.addDnsServer(InetAddress.getByName(DNS2));
mLinkProperties.setInterfaceName(INTERFACE_NAME);
} catch (UnknownHostException e) {
Log.e(TAG, "Could not add DNS address", e);
}
|
Methods Summary |
---|
public java.lang.Object | clone()
throw new CloneNotSupportedException();
| public int | getDefaultGatewayAddr()Fetch default gateway address for the network
return mDefaultGatewayAddr.get();
| public java.lang.String | getTcpBufferSizesPropName()Return the system properties name associated with the tcp buffer sizes
for this network.
return "net.tcp.buffersize.wifi";
| public boolean | reconnect()Re-enable proxy data connectivity after a {@link #teardown()}.
mReconnectRequested.set(true);
setTeardownRequested(false);
if (!mIsProxyAvailable.get()) {
Log.w(TAG, "Reconnect requested even though proxy service is not up. Bailing.");
return false;
}
setDetailedState(NetworkInfo.DetailedState.CONNECTING, REASON_ENABLED, null);
try {
mProxyStatusService.send(Message.obtain(null, MSG_SETUP_REQUEST));
} catch (RemoteException e) {
Log.e(TAG, "Unable to connect to proxy status service", e);
setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, REASON_PROXY_DOWN, null);
return false;
}
// We'll assume proxy is set up successfully. If not, a status change broadcast will be
// received afterwards to indicate any failure.
setDetailedState(NetworkInfo.DetailedState.CONNECTED, REASON_ENABLED, null);
return true;
| private void | setDetailedState(NetworkInfo.DetailedState state, java.lang.String reason, java.lang.String extraInfo)Record the detailed state of a network, and if it is a
change from the previous state, send a notification to
any listeners.
mNetworkInfo.setDetailedState(state, reason, extraInfo);
Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
msg.sendToTarget();
| public void | startMonitoring(android.content.Context context, android.os.Handler target)
mContext = context;
mTarget = target;
mContext.registerReceiver(mProxyStatusServiceListener,
new IntentFilter(ACTION_PROXY_STATUS_CHANGE),
PERMISSION_PROXY_STATUS_SENDER,
null);
| public boolean | teardown()Disable connectivity to the network.
setTeardownRequested(true);
mReconnectRequested.set(false);
try {
if (mIsProxyAvailable.get() && mProxyStatusService != null) {
mProxyStatusService.send(Message.obtain(null, MSG_TEAR_DOWN_REQUEST));
}
} catch (RemoteException e) {
Log.e(TAG, "Unable to connect to proxy status service", e);
return false;
}
setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, REASON_DISABLED, null);
return true;
|
|