Skip to content

红米2和华为荣耀流量不好使 #40

@salomon1184

Description

@salomon1184

public long getTrafficInfo() {

    RandomAccessFile rafTaffic = null;
    long traffic = 0;

    try {
        rafTaffic = new RandomAccessFile("/proc/net/xt_qtaguid/stats", "r");
        Log.i(LOG_TAG, "get traffic information");

        String line = "";
        while ((line = rafTaffic.readLine()) != null) {
            Log.d(LOG_TAG, "line===" + line);
            String[] linesplits = line.split(" ");
            Log.d(LOG_TAG, "uid===" + uid);
            Log.d(LOG_TAG, linesplits[3]);
            if (linesplits[3].endsWith(uid)) {
                traffic = traffic + Long.parseLong(linesplits[5])
                        + Long.parseLong(linesplits[7]);
            }
        }

    } catch (FileNotFoundException e) {
        traffic = -1;

    } catch (NumberFormatException e) {
        Log.e(LOG_TAG, "NumberFormatException: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(LOG_TAG, "IOException: " + e.getMessage());
        e.printStackTrace();
    } finally {
        try {
            if (rafTaffic != null)
                rafTaffic.close();
        } catch (IOException e) {
            Log.i(LOG_TAG,
                    "close randomAccessFile exception: " + e.getMessage());
        }
    }

    Log.d(LOG_TAG, "Traffic===" + traffic);
    return traffic;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions