@Test public void testBlank() throws Exception { QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile(HEADERS + "\n")); boolean result = collector.getTotalBytes(mBytes); assertThat(result).isTrue(); assertThat(mBytes).isEqualTo(new long[8]); }
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }  }
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }  @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }  @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes);  }