getUidRxBytes() and getUidTxBytes() always return 0 in Android 4.3

后端 未结 3 1168
长发绾君心
长发绾君心 2020-12-28 22:17

I feel like I am on crazy pills right now. A specific part of my application has been working just fine for several days, and today it just stopped working and I can not fi

3条回答
  •  盖世英雄少女心
    2020-12-28 23:10

    I have reported the issue to the AOSP issue tracker: here

    I have also created an alternate solution to the problem which I have pasted below:

    private Long getTotalBytesManual(int localUid){
    
    File dir = new File("/proc/uid_stat/");
    String[] children = dir.list();
    if(!Arrays.asList(children).contains(String.valueOf(localUid))){
        return 0L;
    }
    File uidFileDir = new File("/proc/uid_stat/"+String.valueOf(localUid));
    File uidActualFileReceived = new File(uidFileDir,"tcp_rcv");
    File uidActualFileSent = new File(uidFileDir,"tcp_snd");
    
     String textReceived = "0";
     String textSent = "0";
    
     try {
            BufferedReader brReceived = new BufferedReader(new FileReader(uidActualFileReceived));
            BufferedReader brSent = new BufferedReader(new FileReader(uidActualFileSent));
            String receivedLine;
            String sentLine;
    
            if ((receivedLine = brReceived.readLine()) != null) {
                textReceived = receivedLine;
            }
            if ((sentLine = brSent.readLine()) != null) {
                textSent = sentLine;
            }
    
        }
        catch (IOException e) {
    
        }
     return Long.valueOf(textReceived).longValue() + Long.valueOf(textReceived).longValue();
    
    }
    

提交回复
热议问题