@Override public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { Socket socket = mDefaultFactory.createSocket(address, port, localAddress, localPort); TrafficStats.setThreadStatsTag(1); return socket; } })
@Test public void allQueriesAreStubbed() throws Exception { int anything = -2; assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getThreadStatsTag()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getMobileTxPackets()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getMobileRxPackets()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getMobileTxBytes()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getMobileRxBytes()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getTotalTxPackets()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getTotalRxPackets()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getTotalTxBytes()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getTotalRxBytes()); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidTxBytes(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidRxBytes(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidTxPackets(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidRxPackets(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidTcpTxBytes(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidTcpRxBytes(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidUdpTxBytes(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidUdpRxBytes(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidTcpTxSegments(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidTcpRxSegments(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidUdpTxPackets(anything)); assertEquals(TrafficStats.UNSUPPORTED, TrafficStats.getUidUdpRxPackets(anything)); }
TrafficRecord(int uid, String tag) { tx=TrafficStats.getUidTxBytes(uid); rx=TrafficStats.getUidRxBytes(uid); this.tag=tag; } }
TrafficRecord() { tx=TrafficStats.getTotalTxBytes(); rx=TrafficStats.getTotalRxBytes(); }
@Override protected Object doInBackground(Void... params) { /* Do tag socket to avoid strict mode issue. */ TrafficStats.setThreadStatsTag(THREAD_STATS_TAG); try { return doHttpCall(); } catch (Exception e) { return e; } finally { TrafficStats.clearThreadStatsTag(); } }
private Socket configureSocket(Socket socket) { try { TrafficStats.setThreadStatsTag( Math.max(1, Math.min(0xFFFFFEFF, Thread.currentThread().hashCode()))); TrafficStats.tagSocket(socket); } catch (Throwable cause) { // Ignore for testing } return socket; } }
final long startBytes = TrafficStats.getTotalRxBytes(); okHttpResponse = request.getCall().execute(); Utils.saveFile(okHttpResponse, request.getDirPath(), request.getFileName()); final long timeTaken = System.currentTimeMillis() - startTime; if (okHttpResponse.cacheResponse() == null) { final long finalBytes = TrafficStats.getTotalRxBytes(); final long diffBytes; if (startBytes == TrafficStats.UNSUPPORTED || finalBytes == TrafficStats.UNSUPPORTED) {
@Override public void run() { long d_mobileRxBytes = TrafficStats.getMobileRxBytes() - mobileRxBytes; long d_mobileRxPackets = TrafficStats.getMobileRxPackets() - mobileRxPackets; long d_mobileTxBytes = TrafficStats.getMobileTxBytes() - mobileTxBytes; long d_mobileTxPackets = TrafficStats.getMobileTxPackets() - mobileTxPackets; long d_wifiRxBytes = (TrafficStats.getTotalRxBytes() - TrafficStats.getMobileRxBytes()) - wifiRxBytes; long d_wifiRxPackets = (TrafficStats.getTotalRxPackets() - TrafficStats.getMobileRxPackets()) - wifiRxPackets; long d_wifiTxBytes = (TrafficStats.getTotalTxBytes() - TrafficStats.getMobileTxBytes()) - wifiTxBytes; long d_wifiTxPackets = (TrafficStats.getTotalTxPackets() - TrafficStats.getMobileTxPackets()) - wifiTxPackets; mobileRxBytes = TrafficStats.getMobileRxBytes(); mobileRxPackets = TrafficStats.getMobileRxPackets(); mobileTxBytes = TrafficStats.getMobileTxBytes(); mobileTxPackets = TrafficStats.getMobileTxPackets(); wifiRxBytes = TrafficStats.getTotalRxBytes() - mobileRxBytes; wifiTxBytes = TrafficStats.getTotalTxBytes() - mobileTxBytes; wifiRxPackets = TrafficStats.getTotalRxPackets() - mobileRxPackets; wifiTxPackets = TrafficStats.getTotalTxPackets() - mobileTxPackets;
public long getDateSize() { long data = TrafficStats.getUidRxBytes(uid) == TrafficStats.UNSUPPORTED ? TrafficStats.getTotalRxBytes() : TrafficStats.getUidRxBytes(uid); return data - last_data; } }
/** * init data */ @Override protected void initData() { long totalRxBytes = TrafficStats.getTotalRxBytes(); long totalTxBytes = TrafficStats.getTotalTxBytes(); long mobileRxBytes = TrafficStats.getMobileRxBytes(); long mobileTxBytes = TrafficStats.getMobileTxBytes(); long totalBytes = totalRxBytes + totalTxBytes; long mobileBytes = mobileRxBytes + mobileTxBytes; tvTotalTrafficStatsSum.setText(getString(R.string.total_traffic_stats_sum, Formatter.formatFileSize(this, totalBytes))); tvMobileTrafficStatsSum.setText(getString(R.string.mobile_traffic_stats_sum, Formatter.formatFileSize(this, mobileBytes))); tvTotalTrafficStats.setText(getString(R.string.traffic_stats_upload_download, Formatter.formatFileSize(this, totalTxBytes), Formatter.formatFileSize(this, totalRxBytes))); tvMobileTrafficStats.setText(getString(R.string.traffic_stats_upload_download, Formatter.formatFileSize(this, mobileTxBytes), Formatter.formatFileSize(this, mobileRxBytes))); }
@Override public void onCreate() { super.onCreate(); AUTHORITY = Traffic_Provider.getAuthority(this); startTotalRxBytes = TrafficStats.getTotalRxBytes(); startTotalTxBytes = TrafficStats.getTotalTxBytes(); startTotalRxPackets = TrafficStats.getTotalRxPackets(); startTotalTxPackets = TrafficStats.getTotalTxPackets(); if (Aware.DEBUG) Log.d(TAG, "Traffic service created!"); }
public static long getAllRxBytesWifi() { return TrafficStats.getTotalRxBytes() - TrafficStats.getMobileRxBytes(); }
public static long getAllTxBytesWifi() { return TrafficStats.getTotalTxBytes() - TrafficStats.getMobileTxBytes(); }
public static long getAllTxBytes() { return TrafficStats.getTotalTxBytes(); }
public static long getPackageRxBytes(int uid) { return TrafficStats.getUidRxBytes(uid); }
public static long getPackageTxBytes(int uid) { return TrafficStats.getUidTxBytes(uid); } }
public static void clearThreadStatsTag() { TrafficStats.clearThreadStatsTag(); }
@Override protected Boolean doInBackground(Void... args) { HttpURLConnection connection = null; try { TrafficStats.setThreadStatsTag(Constants.THREAD_STATS_TAG); connection = makeRequest(mMode, mParams); connection.connect(); if (connection.getResponseCode() == 200) { String responseStr = getStringFromConnection(connection); if (!TextUtils.isEmpty(responseStr)) { return handleResponse(responseStr); } } } catch (IOException e) { HockeyLog.error("Failed to login", e); } finally { TrafficStats.clearThreadStatsTag(); if (connection != null) { connection.disconnect(); } } return false; }
public void setStartTotalBytes(long startTotalBytes) { if (startTotalBytes < TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes()) { this.startTotalBytes = startTotalBytes; } }
private Socket configureSocket(Socket socket) { try { TrafficStats.setThreadStatsTag( Math.max(1, Math.min(0xFFFFFEFF, Thread.currentThread().hashCode()))); TrafficStats.tagSocket(socket); } catch (Throwable cause) { // Ignore for testing } return socket; } }