1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.os; 18 19 import android.annotation.IntDef; 20 import android.net.Network; 21 22 import com.android.internal.os.BinderCallsStats; 23 import com.android.server.power.stats.SystemServerCpuThreadReader.SystemServiceCpuThreadTimes; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.util.Collection; 28 import java.util.List; 29 30 /** 31 * Battery stats local system service interface. This is used to pass internal data out of 32 * BatteryStatsImpl, as well as make unchecked calls into BatteryStatsImpl. 33 * 34 * @hide Only for use within Android OS. 35 */ 36 public abstract class BatteryStatsInternal { 37 38 public static final int CPU_WAKEUP_SUBSYSTEM_UNKNOWN = -1; 39 public static final int CPU_WAKEUP_SUBSYSTEM_ALARM = 1; 40 public static final int CPU_WAKEUP_SUBSYSTEM_WIFI = 2; 41 public static final int CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER = 3; 42 public static final int CPU_WAKEUP_SUBSYSTEM_SENSOR = 4; 43 public static final int CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA = 5; 44 45 /** @hide */ 46 @IntDef(prefix = {"CPU_WAKEUP_SUBSYSTEM_"}, value = { 47 CPU_WAKEUP_SUBSYSTEM_UNKNOWN, 48 CPU_WAKEUP_SUBSYSTEM_ALARM, 49 CPU_WAKEUP_SUBSYSTEM_WIFI, 50 CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER, 51 CPU_WAKEUP_SUBSYSTEM_SENSOR, 52 CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA, 53 }) 54 @Retention(RetentionPolicy.SOURCE) 55 public @interface CpuWakeupSubsystem { 56 } 57 58 /** 59 * Returns the wifi interfaces. 60 */ getWifiIfaces()61 public abstract String[] getWifiIfaces(); 62 63 /** 64 * Returns the mobile data interfaces. 65 */ getMobileIfaces()66 public abstract String[] getMobileIfaces(); 67 68 /** Returns CPU times for system server thread groups. */ getSystemServiceCpuThreadTimes()69 public abstract SystemServiceCpuThreadTimes getSystemServiceCpuThreadTimes(); 70 71 /** 72 * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem 73 * and per-UID basis. 74 * 75 * <p> 76 * Note: This is a slow running method and should be called from non-blocking threads only. 77 * </p> 78 */ getBatteryUsageStats( List<BatteryUsageStatsQuery> queries)79 public abstract List<BatteryUsageStats> getBatteryUsageStats( 80 List<BatteryUsageStatsQuery> queries); 81 82 /** 83 * Inform battery stats how many deferred jobs existed when the app got launched and how 84 * long ago was the last job execution for the app. 85 * 86 * @param uid the uid of the app. 87 * @param numDeferred number of deferred jobs. 88 * @param sinceLast how long in millis has it been since a job was run 89 */ noteJobsDeferred(int uid, int numDeferred, long sinceLast)90 public abstract void noteJobsDeferred(int uid, int numDeferred, long sinceLast); 91 92 /** 93 * Informs battery stats of a data packet that woke up the CPU. 94 * 95 * @param network The network over which the packet arrived. 96 * @param elapsedMillis The time of the packet's arrival in elapsed timebase. 97 * @param uid The uid that received the packet. 98 */ noteCpuWakingNetworkPacket(Network network, long elapsedMillis, int uid)99 public abstract void noteCpuWakingNetworkPacket(Network network, long elapsedMillis, int uid); 100 101 /** 102 * Informs battery stats of binder stats for the given work source UID. 103 */ noteBinderCallStats(int workSourceUid, long incrementalBinderCallCount, Collection<BinderCallsStats.CallStat> callStats)104 public abstract void noteBinderCallStats(int workSourceUid, long incrementalBinderCallCount, 105 Collection<BinderCallsStats.CallStat> callStats); 106 107 /** 108 * Informs battery stats of native thread IDs of threads taking incoming binder calls. 109 */ noteBinderThreadNativeIds(int[] binderThreadNativeTids)110 public abstract void noteBinderThreadNativeIds(int[] binderThreadNativeTids); 111 112 /** 113 * Reports a sound trigger recognition event that may have woken up the CPU. 114 * @param elapsedMillis The time when the event happened in the elapsed timebase. 115 * @param uid The uid that requested this trigger. 116 */ noteWakingSoundTrigger(long elapsedMillis, int uid)117 public abstract void noteWakingSoundTrigger(long elapsedMillis, int uid); 118 119 /** 120 * Reports an alarm batch that would have woken up the CPU. 121 * @param elapsedMillis The time at which this alarm batch was scheduled to go off. 122 * @param uids the uids of all apps that have any alarm in this batch. 123 */ noteWakingAlarmBatch(long elapsedMillis, int... uids)124 public abstract void noteWakingAlarmBatch(long elapsedMillis, int... uids); 125 } 126