tools/android/appstats.py
def QueryNetwork(adb, userid):
    """Queries the device for network information about the application with a
    user id of |userid|.  It will return a list of values:
    [ Download Background, Upload Background, Download Foreground, Upload
    Foreground ].  If the application is not found it will return
    [ 0, 0, 0, 0 ]."""
    results = [0, 0, 0, 0]

    if not userid:
      return results

    try:
      # Parsing indices for scanning a row from /proc/net/xt_qtaguid/stats.
      # The application id
      userid_idx = 3

      # Whether or not the transmission happened with the application in the
      # background (0) or foreground (1).
      bg_or_fg_idx = 4

      # The number of bytes received.
      rx_idx = 5

      # The number of bytes sent.
      tx_idx = 7

      net_lines = adb.ReadFile('/proc/net/xt_qtaguid/stats').splitlines()
      net_lines = Utils.FindLines(net_lines, userid)
      for line in net_lines:
        data = re.split('\s+', line.strip())
        if data[userid_idx] != userid:
          continue

        dst_idx_offset = None
        if data[bg_or_fg_idx] == '0':
          dst_idx_offset = 0
        elif data[bg_or_fg_idx] == '1':
          dst_idx_offset = 2

        if dst_idx_offset is None:
          continue

        results[dst_idx_offset] = round(float(data[rx_idx]) / 1000.0, 2)
        results[dst_idx_offset + 1] = round(float(data[tx_idx]) / 1000.0, 2)
    except device_errors.AdbShellCommandFailedError:
      pass
    return results
Queries the device for network information about the application with a
    user id of |userid|.  It will return a list of values:
    [ Download Background, Upload Background, Download Foreground, Upload
    Foreground ].  If the application is not found it will return
    [ 0, 0, 0, 0 ].
Queries the device for network information about the application with a
user id of |userid|.  It will return a list of values:
[ Download Background, Upload Background, Download Foreground, Upload
Foreground ].
Queries the device for network information about the application with a user id of |userid| . It will return a list of values : [ Download Background Upload Background Download Foreground Upload Foreground ] .
def QueryNetwork(adb, userid):
    results = [0, 0, 0, 0]
    if not userid:
      return results
    try:
      userid_idx = 3
      bg_or_fg_idx = 4
      rx_idx = 5
      tx_idx = 7
      net_lines = adb.ReadFile('/proc/net/xt_qtaguid/stats').splitlines()
      net_lines = Utils.FindLines(net_lines, userid)
      for line in net_lines:
        data = re.split('\s+', line.strip())
        if data[userid_idx] != userid:
          continue
        dst_idx_offset = None
        if data[bg_or_fg_idx] == '0':
          dst_idx_offset = 0
        elif data[bg_or_fg_idx] == '1':
          dst_idx_offset = 2
        if dst_idx_offset is None:
          continue
        results[dst_idx_offset] = round(float(data[rx_idx]) / 1000.0, 2)
        results[dst_idx_offset + 1] = round(float(data[tx_idx]) / 1000.0, 2)
    except device_errors.AdbShellCommandFailedError:
      pass
    return results
def QueryNetwork ( adb , userid ) : results = [ 0 , 0 , 0 , 0 ] if not userid : return results try : userid_idx = 3 bg_or_fg_idx = 4 rx_idx = 5 tx_idx = 7 net_lines = adb . ReadFile ( '/proc/net/xt_qtaguid/stats' ) . splitlines ( ) net_lines = Utils . FindLines ( net_lines , userid ) for line in net_lines : data = re . split ( '\s+' , line . strip ( ) ) if data [ userid_idx ] != userid : continue dst_idx_offset = None if data [ bg_or_fg_idx ] == '0' : dst_idx_offset = 0 elif data [ bg_or_fg_idx ] == '1' : dst_idx_offset = 2 if dst_idx_offset is None : continue results [ dst_idx_offset ] = round ( float ( data [ rx_idx ] ) / 1000.0 , 2 ) results [ dst_idx_offset + 1 ] = round ( float ( data [ tx_idx ] ) / 1000.0 , 2 ) except device_errors . AdbShellCommandFailedError : pass return results
Queries the device for network information about the application with a
user id of |userid|.
Queries the device for network information about the application with a user id of |userid| .
"""Queries the device for network information about the application with a
    user id of |userid|.  It will return a list of values:
    [ Download Background, Upload Background, Download Foreground, Upload
    Foreground ].  If the application is not found it will return
    [ 0, 0, 0, 0 ].""" # Parsing indices for scanning a row from /proc/net/xt_qtaguid/stats. # The application id # Whether or not the transmission happened with the application in the # background (0) or foreground (1). # The number of bytes received. # The number of bytes sent.
adb
userid