@Test public void testWakeupAttribution() throws JSONException { AppWakeupMetrics metrics = new AppWakeupMetrics(); metrics.appWakeups.put( "wakeup", new AppWakeupMetrics.WakeupDetails(AppWakeupMetrics.WakeupReason.ALARM, 1L, 100L)); JSONArray json = metrics.toJSON(); assertThat(json.length()).isEqualTo(1); JSONObject wakeup = json.getJSONObject(0); assertThat(wakeup.getInt("time_ms")).isEqualTo(100); assertThat(wakeup.getInt("count")).isEqualTo(1); assertThat(wakeup.getString("type")).isEqualTo("ALARM"); assertThat(wakeup.getString("key")).isEqualTo("wakeup"); }
public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; }
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; } }
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; }  }
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; }  @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); }
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; }  @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); public SimpleArrayMap<String, WakeupDetails> appWakeups; }