android.os.health.UidHealthStats Java Examples
The following examples show how to use
android.os.health.UidHealthStats.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BatteryDataStatsAggregator.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.N) @SuppressWarnings("CatchGeneralException") // because takeMyUidSnapshot wraps RemoteException in a RuntimeException private void snapshotAndLogMetrics() { if (healthManager == null || mainHandler == null || !FitbitGatt.atLeastSDK(Build.VERSION_CODES.N)) { Timber.v("Heath logging not enabled."); return; } HealthStats currentStats = null; try { currentStats = healthManager.takeMyUidSnapshot(); } catch (RuntimeException e) { Timber.tag(TAG).e(e, "Couldn't snapshot"); } if (currentStats == null) { Timber.tag(TAG).w("Couldn't log snapshot"); return; } long oldTxBytes = btTxBytes.getAndSet(currentStats.getMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_BYTES)); long oldRxBytes = btRxBytes.getAndSet(currentStats.getMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_BYTES)); long oldMamsValue = bluetoothPowerMilliampMilliseconds.getAndAdd(currentStats.getMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_POWER_MAMS)); float oldMah = ((((float) oldMamsValue / 1000) * 60) * 60); float newMah = ((((float) bluetoothPowerMilliampMilliseconds.get() / 1000) * 60) * 60); mainHandler.postDelayed(this::snapshotAndLogMetrics, SNAPSHOT_INTERVAL); Timber .tag(TAG) .i("Old BTLE TX: %d, new BTLE TX: %d. Old BTLE RX: %d, new BTLE RX: %d. Old BTLE mAh: %f, new BTLE mAh: %f", oldTxBytes, btTxBytes.get(), oldRxBytes, btRxBytes.get(), oldMah, newMah); }
Example #2
Source File: BatteryStatsService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Gets a HealthStatsParceler for the given uid. You should probably call * updateExternalStatsSync first. */ HealthStatsParceler getHealthStatsForUidLocked(int requestUid) { final HealthStatsBatteryStatsWriter writer = new HealthStatsBatteryStatsWriter(); final HealthStatsWriter uidWriter = new HealthStatsWriter(UidHealthStats.CONSTANTS); final BatteryStats.Uid uid = mStats.getUidStats().get(requestUid); if (uid != null) { writer.writeUid(uidWriter, mStats, uid); } return new HealthStatsParceler(uidWriter); }
Example #3
Source File: HealthStatsMetrics.java From Battery-Metrics with MIT License | 5 votes |
private static void readKeyNames() { try { Class[] healthStatsClasses = { UidHealthStats.class, PidHealthStats.class, ProcessHealthStats.class, PackageHealthStats.class, ServiceHealthStats.class }; Class annotationClass = Class.forName("android.os.health.HealthKeys$Constant"); for (Class clazz : healthStatsClasses) { Field[] fields = clazz.getFields(); for (Field field : fields) { if (field.isAnnotationPresent(annotationClass)) { sKeyNames.put(field.getInt(null), field.getName()); } } } return; } catch (IllegalAccessException iae) { SystemMetricsLogger.wtf(TAG, "Unable to read constant names", iae); } catch (ClassNotFoundException cnfe) { SystemMetricsLogger.wtf(TAG, "Unable to find constant annotation", cnfe); } // Mark as attempted and invalid sKeyNames.put(-1, "Unable to read"); }
Example #4
Source File: HealthStatsMetricsTest.java From Battery-Metrics with MIT License | 5 votes |
@Test public void testDiffWithReset() { HealthStatsMetrics a = createTestMetrics(); a.measurement.put(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, 100L); HealthStatsMetrics b = createTestMetrics(); b.measurement.put(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, 200L); HealthStatsMetrics output = a.diff(b, null); HealthStatsMetrics expectedOutput = createTestMetrics(); expectedOutput.measurement.put(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, 100L); assertThat(output).isEqualTo(expectedOutput); }
Example #5
Source File: HealthStatsMetrics.java From Battery-Metrics with MIT License | 4 votes |
/** Checks the age difference of snapshots, similar to String comparisons. */ private static long compareSnapshotAge(HealthStatsMetrics a, HealthStatsMetrics b) { long aRealtimeBatteryMs = a.measurement.get(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, 0L); long bRealtimeBatteryMs = b.measurement.get(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, 0L); return aRealtimeBatteryMs - bRealtimeBatteryMs; }