@Test public void testAttributionToJSONObject() throws JSONException { WakeLockMetrics metrics = new WakeLockMetrics(); metrics.isAttributionEnabled = true; metrics.acquiredCount = 2; metrics.heldTimeMs = 400; metrics.tagTimeMs.put("Test", 100l); JSONObject attribution = metrics.attributionToJSONObject(); assertThat(attribution.length()).isEqualTo(1); assertThat(attribution.has("Test")).isTrue(); assertThat(attribution.getLong("Test")).isEqualTo(100); }
public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; }
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } }
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } WakeLockMetrics();  WakeLockMetrics(boolean isAttributionEnabled); }
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } WakeLockMetrics();  WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); }
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } WakeLockMetrics();  WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); public boolean isAttributionEnabled; final SimpleArrayMap<String, Long> tagTimeMs; public long heldTimeMs; public long acquiredCount; }