Add wakeup alarm anomaly detector
Wakeup alarm count frequent is calculated by a / b, where 1. a: the total wakeup alarm count since the last full charge 2. b: total time running since last full charge (include sleeping time) This cl also has the following changes: 1. Move bunch of methods to BatteryUtils 2. Create type WAKEUP_ALARM 3. Add and update tests Upcoming cl will make sure we get the threshold from AnomalyDetectionPolicy Bug: 36921529 Test: RunSettingsRoboTests Change-Id: I4f7b85606df68b6057f6c7d3f3be7f9a9a747f1d
This commit is contained in:
@@ -27,6 +27,8 @@ import android.util.Log;
|
||||
import android.util.SparseLongArray;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -213,6 +215,38 @@ public class BatteryUtils {
|
||||
return (powerUsageMah / (totalPowerMah - hiddenPowerMah)) * dischargeAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the whole running time in the state {@code statsType}
|
||||
*
|
||||
* @param batteryStatsHelper utility class that contains the data
|
||||
* @param statsType state that we want to calculate the time for
|
||||
* @return the running time in millis
|
||||
*/
|
||||
public long calculateRunningTimeBasedOnStatsType(BatteryStatsHelper batteryStatsHelper,
|
||||
int statsType) {
|
||||
final long elapsedRealtimeUs = convertMsToUs(SystemClock.elapsedRealtime());
|
||||
// Return the battery time (millisecond) on status mStatsType
|
||||
return convertUsToMs(
|
||||
batteryStatsHelper.getStats().computeBatteryRealtime(elapsedRealtimeUs, statsType));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the package name for a {@link android.os.BatteryStats.Uid}
|
||||
*
|
||||
* @param uid id to get the package name
|
||||
* @return the package name. If there are multiple packages related to
|
||||
* given id, return the first one. Or return null if there are no known
|
||||
* packages with the given id
|
||||
*
|
||||
* @see PackageManager#getPackagesForUid(int)
|
||||
*/
|
||||
public String getPackageName(int uid) {
|
||||
final String[] packageNames = mPackageManager.getPackagesForUid(uid);
|
||||
|
||||
return ArrayUtils.isEmpty(packageNames) ? null : packageNames[0];
|
||||
}
|
||||
|
||||
private long convertUsToMs(long timeUs) {
|
||||
return timeUs / 1000;
|
||||
}
|
||||
|
Reference in New Issue
Block a user