Loading apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java +14 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import android.content.pm.PackageManagerInternal; import android.database.ContentObserver; import android.net.Uri; import android.os.BatteryManager; import android.os.BatteryStatsInternal; import android.os.Binder; import android.os.Build; import android.os.Bundle; Loading Loading @@ -116,6 +117,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.EventLog; import android.util.IndentingPrintWriter; import android.util.IntArray; import android.util.Log; import android.util.LongArrayQueue; import android.util.Pair; Loading Loading @@ -249,6 +251,7 @@ public class AlarmManagerService extends SystemService { private ActivityManagerInternal mActivityManagerInternal; private final EconomyManagerInternal mEconomyManagerInternal; private PackageManagerInternal mPackageManagerInternal; private BatteryStatsInternal mBatteryStatsInternal; private RoleManager mRoleManager; private volatile PermissionManagerServiceInternal mLocalPermissionManager; Loading Loading @@ -2113,6 +2116,8 @@ public class AlarmManagerService extends SystemService { LocalServices.getService(AppStandbyInternal.class); appStandbyInternal.addListener(new AppStandbyTracker()); mBatteryStatsInternal = LocalServices.getService(BatteryStatsInternal.class); mRoleManager = getContext().getSystemService(RoleManager.class); mMetricsHelper.registerPuller(() -> mAlarmStore); Loading Loading @@ -4783,8 +4788,12 @@ public class AlarmManagerService extends SystemService { } final ArraySet<Pair<String, Integer>> triggerPackages = new ArraySet<>(); final IntArray wakeupUids = new IntArray(); for (int i = 0; i < triggerList.size(); i++) { final Alarm a = triggerList.get(i); if (a.wakeup) { wakeupUids.add(a.uid); } if (mConstants.USE_TARE_POLICY) { if (!isExemptFromTare(a)) { triggerPackages.add(Pair.create( Loading @@ -4796,6 +4805,11 @@ public class AlarmManagerService extends SystemService { a.sourcePackage, UserHandle.getUserId(a.creatorUid))); } } if (wakeupUids.size() > 0 && mBatteryStatsInternal != null) { mBatteryStatsInternal.noteCpuWakingActivity( BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_ALARM, nowELAPSED, wakeupUids.toArray()); } deliverAlarmsLocked(triggerList, nowELAPSED); mTemporaryQuotaReserve.cleanUpExpiredQuotas(nowELAPSED); if (mConstants.USE_TARE_POLICY) { Loading core/java/android/os/BatteryStats.java +1 −1 Original line number Diff line number Diff line Loading @@ -2017,7 +2017,7 @@ public abstract class BatteryStats { public static final int EVENT_PACKAGE_INSTALLED = 0x000b; // Event for a package being uninstalled. public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; // Event for a package being uninstalled. // Event for an alarm being sent out to an app. public static final int EVENT_ALARM = 0x000d; // Record that we have decided we need to collect new stats data. public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; Loading core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -1626,6 +1626,7 @@ <java-symbol type="xml" name="password_kbd_symbols_shift" /> <java-symbol type="xml" name="power_profile" /> <java-symbol type="xml" name="power_profile_test" /> <java-symbol type="xml" name="irq_device_map" /> <java-symbol type="xml" name="sms_short_codes" /> <java-symbol type="xml" name="audio_assets" /> <java-symbol type="xml" name="global_keys" /> Loading core/res/res/xml/irq_device_map.xml 0 → 100644 +50 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ** ** Copyright 2022, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License") ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ --> <irq-device-map> <!-- This file maps devices (chips) that can send IRQs to the CPU (and bring it out of sleep) to logical subsystems in userspace code. Since each Android device has its own uniquely designed chipset, this mapping is expected to be empty by default and should be overridden by device specific configs. This mapping helps the system to meaningfully attribute CPU wakeups to logical work that happened on the device. The devices are referred to by their names as defined in the kernel. Currently defined subsystems are: - Alarm: Use this to denote wakeup alarms requested by apps via the AlarmManager API. The overlay should use tags <device> and <subsystem> to describe this mapping in the following way: <irq-device-map> <device name="device_name_1"> <subsystem>Subsystem1</subsystem> <subsystem>Subsystem2</subsystem> : : </device> <device name="device_name_2"> : </device> : </irq-device-map> The tag <device> should have a "name" attribute specifying the kernel name of the device. Each <device> tag can then enclose multiple <subsystem> tags. Each <subsystem> tag should enclose the name of the logical subsystems (one of the ones defined above) as text. Undefined subsystem names will be ignored by the framework. --> </irq-device-map> No newline at end of file services/core/java/android/os/BatteryStatsInternal.java +29 −2 Original line number Diff line number Diff line Loading @@ -16,12 +16,18 @@ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import com.android.internal.os.BinderCallsStats; import com.android.server.power.stats.SystemServerCpuThreadReader.SystemServiceCpuThreadTimes; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Collection; import java.util.List; /** * Battery stats local system service interface. This is used to pass internal data out of * BatteryStatsImpl, as well as make unchecked calls into BatteryStatsImpl. Loading @@ -29,6 +35,19 @@ import java.util.List; * @hide Only for use within Android OS. */ public abstract class BatteryStatsInternal { public static final int CPU_WAKEUP_SUBSYSTEM_UNKNOWN = -1; public static final int CPU_WAKEUP_SUBSYSTEM_ALARM = 1; /** @hide */ @IntDef(prefix = {"CPU_WAKEUP_SUBSYSTEM_"}, value = { CPU_WAKEUP_SUBSYSTEM_UNKNOWN, CPU_WAKEUP_SUBSYSTEM_ALARM, }) @Retention(RetentionPolicy.SOURCE) @interface CpuWakeupSubsystem { } /** * Returns the wifi interfaces. */ Loading Loading @@ -56,6 +75,7 @@ public abstract class BatteryStatsInternal { /** * Inform battery stats how many deferred jobs existed when the app got launched and how * long ago was the last job execution for the app. * * @param uid the uid of the app. * @param numDeferred number of deferred jobs. * @param sinceLast how long in millis has it been since a job was run Loading @@ -72,4 +92,11 @@ public abstract class BatteryStatsInternal { * Informs battery stats of native thread IDs of threads taking incoming binder calls. */ public abstract void noteBinderThreadNativeIds(int[] binderThreadNativeTids); /** * Reports any activity that could potentially have caused the CPU to wake up. * Accepts a timestamp to allow the reporter to report it before or after the event. */ public abstract void noteCpuWakingActivity(@CpuWakeupSubsystem int subsystem, long elapsedMillis, @NonNull int... uids); } Loading
apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java +14 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import android.content.pm.PackageManagerInternal; import android.database.ContentObserver; import android.net.Uri; import android.os.BatteryManager; import android.os.BatteryStatsInternal; import android.os.Binder; import android.os.Build; import android.os.Bundle; Loading Loading @@ -116,6 +117,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.EventLog; import android.util.IndentingPrintWriter; import android.util.IntArray; import android.util.Log; import android.util.LongArrayQueue; import android.util.Pair; Loading Loading @@ -249,6 +251,7 @@ public class AlarmManagerService extends SystemService { private ActivityManagerInternal mActivityManagerInternal; private final EconomyManagerInternal mEconomyManagerInternal; private PackageManagerInternal mPackageManagerInternal; private BatteryStatsInternal mBatteryStatsInternal; private RoleManager mRoleManager; private volatile PermissionManagerServiceInternal mLocalPermissionManager; Loading Loading @@ -2113,6 +2116,8 @@ public class AlarmManagerService extends SystemService { LocalServices.getService(AppStandbyInternal.class); appStandbyInternal.addListener(new AppStandbyTracker()); mBatteryStatsInternal = LocalServices.getService(BatteryStatsInternal.class); mRoleManager = getContext().getSystemService(RoleManager.class); mMetricsHelper.registerPuller(() -> mAlarmStore); Loading Loading @@ -4783,8 +4788,12 @@ public class AlarmManagerService extends SystemService { } final ArraySet<Pair<String, Integer>> triggerPackages = new ArraySet<>(); final IntArray wakeupUids = new IntArray(); for (int i = 0; i < triggerList.size(); i++) { final Alarm a = triggerList.get(i); if (a.wakeup) { wakeupUids.add(a.uid); } if (mConstants.USE_TARE_POLICY) { if (!isExemptFromTare(a)) { triggerPackages.add(Pair.create( Loading @@ -4796,6 +4805,11 @@ public class AlarmManagerService extends SystemService { a.sourcePackage, UserHandle.getUserId(a.creatorUid))); } } if (wakeupUids.size() > 0 && mBatteryStatsInternal != null) { mBatteryStatsInternal.noteCpuWakingActivity( BatteryStatsInternal.CPU_WAKEUP_SUBSYSTEM_ALARM, nowELAPSED, wakeupUids.toArray()); } deliverAlarmsLocked(triggerList, nowELAPSED); mTemporaryQuotaReserve.cleanUpExpiredQuotas(nowELAPSED); if (mConstants.USE_TARE_POLICY) { Loading
core/java/android/os/BatteryStats.java +1 −1 Original line number Diff line number Diff line Loading @@ -2017,7 +2017,7 @@ public abstract class BatteryStats { public static final int EVENT_PACKAGE_INSTALLED = 0x000b; // Event for a package being uninstalled. public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; // Event for a package being uninstalled. // Event for an alarm being sent out to an app. public static final int EVENT_ALARM = 0x000d; // Record that we have decided we need to collect new stats data. public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; Loading
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -1626,6 +1626,7 @@ <java-symbol type="xml" name="password_kbd_symbols_shift" /> <java-symbol type="xml" name="power_profile" /> <java-symbol type="xml" name="power_profile_test" /> <java-symbol type="xml" name="irq_device_map" /> <java-symbol type="xml" name="sms_short_codes" /> <java-symbol type="xml" name="audio_assets" /> <java-symbol type="xml" name="global_keys" /> Loading
core/res/res/xml/irq_device_map.xml 0 → 100644 +50 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ** ** Copyright 2022, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License") ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ --> <irq-device-map> <!-- This file maps devices (chips) that can send IRQs to the CPU (and bring it out of sleep) to logical subsystems in userspace code. Since each Android device has its own uniquely designed chipset, this mapping is expected to be empty by default and should be overridden by device specific configs. This mapping helps the system to meaningfully attribute CPU wakeups to logical work that happened on the device. The devices are referred to by their names as defined in the kernel. Currently defined subsystems are: - Alarm: Use this to denote wakeup alarms requested by apps via the AlarmManager API. The overlay should use tags <device> and <subsystem> to describe this mapping in the following way: <irq-device-map> <device name="device_name_1"> <subsystem>Subsystem1</subsystem> <subsystem>Subsystem2</subsystem> : : </device> <device name="device_name_2"> : </device> : </irq-device-map> The tag <device> should have a "name" attribute specifying the kernel name of the device. Each <device> tag can then enclose multiple <subsystem> tags. Each <subsystem> tag should enclose the name of the logical subsystems (one of the ones defined above) as text. Undefined subsystem names will be ignored by the framework. --> </irq-device-map> No newline at end of file
services/core/java/android/os/BatteryStatsInternal.java +29 −2 Original line number Diff line number Diff line Loading @@ -16,12 +16,18 @@ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import com.android.internal.os.BinderCallsStats; import com.android.server.power.stats.SystemServerCpuThreadReader.SystemServiceCpuThreadTimes; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Collection; import java.util.List; /** * Battery stats local system service interface. This is used to pass internal data out of * BatteryStatsImpl, as well as make unchecked calls into BatteryStatsImpl. Loading @@ -29,6 +35,19 @@ import java.util.List; * @hide Only for use within Android OS. */ public abstract class BatteryStatsInternal { public static final int CPU_WAKEUP_SUBSYSTEM_UNKNOWN = -1; public static final int CPU_WAKEUP_SUBSYSTEM_ALARM = 1; /** @hide */ @IntDef(prefix = {"CPU_WAKEUP_SUBSYSTEM_"}, value = { CPU_WAKEUP_SUBSYSTEM_UNKNOWN, CPU_WAKEUP_SUBSYSTEM_ALARM, }) @Retention(RetentionPolicy.SOURCE) @interface CpuWakeupSubsystem { } /** * Returns the wifi interfaces. */ Loading Loading @@ -56,6 +75,7 @@ public abstract class BatteryStatsInternal { /** * Inform battery stats how many deferred jobs existed when the app got launched and how * long ago was the last job execution for the app. * * @param uid the uid of the app. * @param numDeferred number of deferred jobs. * @param sinceLast how long in millis has it been since a job was run Loading @@ -72,4 +92,11 @@ public abstract class BatteryStatsInternal { * Informs battery stats of native thread IDs of threads taking incoming binder calls. */ public abstract void noteBinderThreadNativeIds(int[] binderThreadNativeTids); /** * Reports any activity that could potentially have caused the CPU to wake up. * Accepts a timestamp to allow the reporter to report it before or after the event. */ public abstract void noteCpuWakingActivity(@CpuWakeupSubsystem int subsystem, long elapsedMillis, @NonNull int... uids); }