@Test public void testBroadcastNetworkChanges() throws Exception { ShadowTrafficStats.setUidRxBytes(10000); ShadowTrafficStats.setUidTxBytes(20000); TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); assertThat(collector.getTotalBytes(mBytes)).isTrue(); ShadowTrafficStats.setUidRxBytes(11000); ShadowTrafficStats.setUidTxBytes(22000); ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE); ShadowConnectivityManager shadowConnectivityManager = Shadows.shadowOf(connectivityManager); NetworkInfo networkInfo = ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true); shadowConnectivityManager.setActiveNetworkInfo(networkInfo); collector.mReceiver.onReceive(null, null); ShadowTrafficStats.setUidRxBytes(11100); ShadowTrafficStats.setUidTxBytes(22200); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes[RX | MOBILE]).isEqualTo(11000); assertThat(mBytes[TX | MOBILE]).isEqualTo(22000); assertThat(mBytes[RX | WIFI]).isEqualTo(100); assertThat(mBytes[TX | WIFI]).isEqualTo(200); }
@Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; }
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } }
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); }
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes);  }