Source code
package android.support.v4.net;
import android.os.Build.VERSION;
import java.net.Socket;
import java.net.SocketException;
public class TrafficStatsCompat {
private static final TrafficStatsCompatImpl IMPL;
interface TrafficStatsCompatImpl {
void clearThreadStatsTag();
int getThreadStatsTag();
void incrementOperationCount(int i);
void incrementOperationCount(int i, int i2);
void setThreadStatsTag(int i);
void tagSocket(Socket socket) throws SocketException;
void untagSocket(Socket socket) throws SocketException;
}
static class BaseTrafficStatsCompatImpl implements TrafficStatsCompatImpl {
private ThreadLocal<SocketTags> mThreadSocketTags = new ThreadLocal<SocketTags>() {
protected SocketTags initialValue() {
return new SocketTags();
}
};
private static class SocketTags {
public int statsTag;
private SocketTags() {
this.statsTag = -1;
}
}
BaseTrafficStatsCompatImpl() {
}
public void clearThreadStatsTag() {
((SocketTags) this.mThreadSocketTags.get()).statsTag = -1;
}
public int getThreadStatsTag() {
return ((SocketTags) this.mThreadSocketTags.get()).statsTag;
}
public void incrementOperationCount(int operationCount) {
}
public void incrementOperationCount(int tag, int operationCount) {
}
public void setThreadStatsTag(int tag) {
((SocketTags) this.mThreadSocketTags.get()).statsTag = tag;
}
public void tagSocket(Socket socket) {
}
public void untagSocket(Socket socket) {
}
}
static class IcsTrafficStatsCompatImpl implements TrafficStatsCompatImpl {
IcsTrafficStatsCompatImpl() {
}
public void clearThreadStatsTag() {
TrafficStatsCompatIcs.clearThreadStatsTag();
}
public int getThreadStatsTag() {
return TrafficStatsCompatIcs.getThreadStatsTag();
}
public void incrementOperationCount(int operationCount) {
TrafficStatsCompatIcs.incrementOperationCount(operationCount);
}
public void incrementOperationCount(int tag, int operationCount) {
TrafficStatsCompatIcs.incrementOperationCount(tag, operationCount);
}
public void setThreadStatsTag(int tag) {
TrafficStatsCompatIcs.setThreadStatsTag(tag);
}
public void tagSocket(Socket socket) throws SocketException {
TrafficStatsCompatIcs.tagSocket(socket);
}
public void untagSocket(Socket socket) throws SocketException {
TrafficStatsCompatIcs.untagSocket(socket);
}
}
static {
if (VERSION.SDK_INT >= 14) {
IMPL = new IcsTrafficStatsCompatImpl();
} else {
IMPL = new BaseTrafficStatsCompatImpl();
}
}
public static void clearThreadStatsTag() {
IMPL.clearThreadStatsTag();
}
public static int getThreadStatsTag() {
return IMPL.getThreadStatsTag();
}
public static void incrementOperationCount(int operationCount) {
IMPL.incrementOperationCount(operationCount);
}
public static void incrementOperationCount(int tag, int operationCount) {
IMPL.incrementOperationCount(tag, operationCount);
}
public static void setThreadStatsTag(int tag) {
IMPL.setThreadStatsTag(tag);
}
public static void tagSocket(Socket socket) throws SocketException {
IMPL.tagSocket(socket);
}
public static void untagSocket(Socket socket) throws SocketException {
IMPL.untagSocket(socket);
}
}