コード例 #1
0
 /** Retorna un diccionario con nombres de aplicaciones y numero de conexiones activas en UDP */
 public static HashMap<String, Integer> getUDPActiveAppsConnections(Context context) {
   HashMap<String, Integer> totals = new HashMap<String, Integer>();
   for (SystemSocket socket : SystemSockets.getUDPSockets()) {
     if (!totals.containsKey(socket.getAppName(context)))
       totals.put(socket.getAppName(context), 0);
     totals.put(socket.getAppName(context), totals.get(socket.getAppName(context)) + 1);
   }
   return totals;
 }
コード例 #2
0
  /**
   * @param path el path al archivo especifico del directorio /proc/net/ que se desea parsear
   * @param sockets ArrayList con objetos SystemSocket con información de las conexiones activas
   */
  private static void parseSocketTable(String path, ArrayList<SystemSocket> sockets) {
    String line;
    try {
      BufferedReader socketInfoReader = new BufferedReader(new FileReader(path));
      socketInfoReader.readLine(); // Skip header

      while ((line = socketInfoReader.readLine()) != null) {
        SystemSocket currentConnection =
            new SystemSocket(line, SystemSockets.getSocketTypeByPath(path));
        if (currentConnection.isOutsideActiveConnection()) {
          sockets.add(currentConnection);
        }
      }

      socketInfoReader.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }