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 public static final int CPU_WAKEUP_SUBSYSTEM_BLUETOOTH = 6; 45 46 /** @hide */ 47 @IntDef(prefix = {"CPU_WAKEUP_SUBSYSTEM_"}, value = { 48 CPU_WAKEUP_SUBSYSTEM_UNKNOWN, 49 CPU_WAKEUP_SUBSYSTEM_ALARM, 50 CPU_WAKEUP_SUBSYSTEM_WIFI, 51 CPU_WAKEUP_SUBSYSTEM_SOUND_TRIGGER, 52 CPU_WAKEUP_SUBSYSTEM_SENSOR, 53 CPU_WAKEUP_SUBSYSTEM_CELLULAR_DATA, 54 CPU_WAKEUP_SUBSYSTEM_BLUETOOTH, 55 }) 56 @Retention(RetentionPolicy.SOURCE) 57 public @interface CpuWakeupSubsystem { 58 } 59 60 /** 61 * Returns the wifi interfaces. 62 */ getWifiIfaces()63 public abstract String[] getWifiIfaces(); 64 65 /** 66 * Returns the mobile data interfaces. 67 */ getMobileIfaces()68 public abstract String[] getMobileIfaces(); 69 70 /** Returns CPU times for system server thread groups. */ getSystemServiceCpuThreadTimes()71 public abstract SystemServiceCpuThreadTimes getSystemServiceCpuThreadTimes(); 72 73 /** 74 * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem 75 * and per-UID basis. 76 * 77 * <p> 78 * Note: This is a slow running method and should be called from non-blocking threads only. 79 * </p> 80 */ getBatteryUsageStats( List<BatteryUsageStatsQuery> queries)81 public abstract List<BatteryUsageStats> getBatteryUsageStats( 82 List<BatteryUsageStatsQuery> queries); 83 84 /** 85 * Inform battery stats how many deferred jobs existed when the app got launched and how 86 * long ago was the last job execution for the app. 87 * 88 * @param uid the uid of the app. 89 * @param numDeferred number of deferred jobs. 90 * @param sinceLast how long in millis has it been since a job was run 91 */ noteJobsDeferred(int uid, int numDeferred, long sinceLast)92 public abstract void noteJobsDeferred(int uid, int numDeferred, long sinceLast); 93 94 /** 95 * Informs battery stats of a data packet that woke up the CPU. 96 * 97 * @param network The network over which the packet arrived. 98 * @param elapsedMillis The time of the packet's arrival in elapsed timebase. 99 * @param uid The uid that received the packet. 100 */ noteCpuWakingNetworkPacket(Network network, long elapsedMillis, int uid)101 public abstract void noteCpuWakingNetworkPacket(Network network, long elapsedMillis, int uid); 102 103 /** 104 * Informs battery stats of a sysproxy packet that woke up the CPU 105 * 106 * @param uid The uid that received the packet. 107 * @param elapsedMillis The time of the packet's arrival in elapsed timebase. 108 */ noteCpuWakingBluetoothProxyPacket(int uid, long elapsedMillis)109 public abstract void noteCpuWakingBluetoothProxyPacket(int uid, long elapsedMillis); 110 111 /** 112 * Informs battery stats of binder stats for the given work source UID. 113 */ noteBinderCallStats(int workSourceUid, long incrementalBinderCallCount, Collection<BinderCallsStats.CallStat> callStats)114 public abstract void noteBinderCallStats(int workSourceUid, long incrementalBinderCallCount, 115 Collection<BinderCallsStats.CallStat> callStats); 116 117 /** 118 * Informs battery stats of native thread IDs of threads taking incoming binder calls. 119 */ noteBinderThreadNativeIds(int[] binderThreadNativeTids)120 public abstract void noteBinderThreadNativeIds(int[] binderThreadNativeTids); 121 122 /** 123 * Reports a sound trigger recognition event that may have woken up the CPU. 124 * @param elapsedMillis The time when the event happened in the elapsed timebase. 125 * @param uid The uid that requested this trigger. 126 */ noteWakingSoundTrigger(long elapsedMillis, int uid)127 public abstract void noteWakingSoundTrigger(long elapsedMillis, int uid); 128 129 /** 130 * Reports an alarm batch that would have woken up the CPU. 131 * @param elapsedMillis The time at which this alarm batch was scheduled to go off. 132 * @param uids the uids of all apps that have any alarm in this batch. 133 */ noteWakingAlarmBatch(long elapsedMillis, int... uids)134 public abstract void noteWakingAlarmBatch(long elapsedMillis, int... uids); 135 136 /** See PowerStatsUidResolver.mapUid(). */ getOwnerUid(int uid)137 public abstract int getOwnerUid(int uid); 138 } 139