FileDocCategorySizeDatePackage
NetworkManagementSocketTagger.javaAPI DocAndroid 5.1 API5173Thu Mar 12 22:22:10 GMT 2015com.android.server

NetworkManagementSocketTagger

public final class NetworkManagementSocketTagger extends dalvik.system.SocketTagger
Assigns tags to sockets for traffic stats.

Fields Summary
private static final String
TAG
private static final boolean
LOGD
public static final String
PROP_QTAGUID_ENABLED
{@link SystemProperties} key that indicates if {@code qtaguid} bandwidth controls have been enabled.
private static ThreadLocal
threadSocketTags
Constructors Summary
Methods Summary
public static intgetThreadSocketStatsTag()

        return threadSocketTags.get().statsTag;
    
public static voidinstall()


        
        SocketTagger.set(new NetworkManagementSocketTagger());
    
public static intkernelToTag(java.lang.String string)
Convert {@code /proc/} tag format to {@link Integer}. Assumes incoming format like {@code 0x7fffffff00000000}.

        int length = string.length();
        if (length > 10) {
            return Long.decode(string.substring(0, length - 8)).intValue();
        } else {
            return 0;
        }
    
private static native intnative_deleteTagData(int tag, int uid)

private static native intnative_setCounterSet(int uid, int counterSetNum)

private static native intnative_tagSocketFd(java.io.FileDescriptor fd, int tag, int uid)

private static native intnative_untagSocketFd(java.io.FileDescriptor fd)

public static voidresetKernelUidStats(int uid)

        if (SystemProperties.getBoolean(PROP_QTAGUID_ENABLED, false)) {
            int errno = native_deleteTagData(0, uid);
            if (errno < 0) {
                Slog.w(TAG, "problem clearing counters for uid " + uid + " : errno " + errno);
            }
        }
    
public static voidsetKernelCounterSet(int uid, int counterSet)

    

           
        if (SystemProperties.getBoolean(PROP_QTAGUID_ENABLED, false)) {
            final int errno = native_setCounterSet(counterSet, uid);
            if (errno < 0) {
                Log.w(TAG, "setKernelCountSet(" + uid + ", " + counterSet + ") failed with errno "
                        + errno);
            }
        }
    
public static voidsetThreadSocketStatsTag(int tag)

        threadSocketTags.get().statsTag = tag;
    
public static voidsetThreadSocketStatsUid(int uid)

        threadSocketTags.get().statsUid = uid;
    
public voidtag(java.io.FileDescriptor fd)

        final SocketTags options = threadSocketTags.get();
        if (LOGD) {
            Log.d(TAG, "tagSocket(" + fd.getInt$() + ") with statsTag=0x"
                    + Integer.toHexString(options.statsTag) + ", statsUid=" + options.statsUid);
        }
        // TODO: skip tagging when options would be no-op
        tagSocketFd(fd, options.statsTag, options.statsUid);
    
private voidtagSocketFd(java.io.FileDescriptor fd, int tag, int uid)

        if (tag == -1 && uid == -1) return;

        if (SystemProperties.getBoolean(PROP_QTAGUID_ENABLED, false)) {
            final int errno = native_tagSocketFd(fd, tag, uid);
            if (errno < 0) {
                Log.i(TAG, "tagSocketFd(" + fd.getInt$() + ", "
                      + tag + ", " +
                      + uid + ") failed with errno" + errno);
            }
        }
    
private voidunTagSocketFd(java.io.FileDescriptor fd)

        final SocketTags options = threadSocketTags.get();
        if (options.statsTag == -1 && options.statsUid == -1) return;

        if (SystemProperties.getBoolean(PROP_QTAGUID_ENABLED, false)) {
            final int errno = native_untagSocketFd(fd);
            if (errno < 0) {
                Log.w(TAG, "untagSocket(" + fd.getInt$() + ") failed with errno " + errno);
            }
        }
    
public voiduntag(java.io.FileDescriptor fd)

        if (LOGD) {
            Log.i(TAG, "untagSocket(" + fd.getInt$() + ")");
        }
        unTagSocketFd(fd);