自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
应用后台行为跟踪器
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 13 引入了功耗跟踪器的概念,它是一个进程,用于监控应用的前台或后台电池用量以确定应用是否违反某些政策。Android 13 包含两个功耗跟踪器:前台服务跟踪器和后台电池用量跟踪器。我们建议您使用这些跟踪器来监控电池用量过高的情况并向用户发出提醒,而不是使用您自己的机制确定应用的电池滥用情况。
前台服务跟踪器
前台服务可以长时间运行和使用电池。如果某项前台服务已运行很长时间但不可见(例如,用户关闭了该服务的通知),前台服务跟踪器会向用户显示通知。当用户点击该通知时,系统会显示任务管理器,并允许用户停止前台服务。此跟踪器默认处于启用状态。
后台电池用量跟踪器
应用可能会在用户不知情的情况下在后台消耗电池电量。后台电池用量跟踪器会监控每个应用的电池用量。在这种情况下,电池用量由 3 个维度定义:位于顶层的前台应用、运行某种不可见作业的前台服务,以及应用的后台部分。如果应用电池用量的后台部分超过某个阈值,应用将被移至受限存储分区,仅允许其每天运行一个作业。此跟踪器默认处于停用状态。如需启用此跟踪器,请运行以下命令:
adb shell device_config put activity_manager bg_auto_restrict_abusive_apps 1
adb shell device_config put activity_manager bg_current_drain_auto_restrict_abusive_apps_enabled 1
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# App background behavior trackers\n\nAndroid 13 introduces the concept of a\n*power consumption tracker*, which is a process that monitors foreground or\nbackground battery usage by apps to determine if apps violate some policy.\nAndroid 13 contains two power consumption trackers:\nthe foreground service tracker and background battery usage tracker. As opposed\nto using your own mechanisms to determine battery abuse by apps, we\nrecommend using these trackers to monitor and alert users of excessive battery\nusage.\n\nForeground service tracker\n--------------------------\n\nForeground services can execute and use battery for an extended period of time.\nThe foreground service tracker displays a notification to users when a\nforeground service has been running for a long period of time but is invisible,\nsuch as when a user has dismissed the service's notification. If the user\nclicks the notification, the task manager is displayed and lets\nthe user stop the foreground service. This tracker is enabled by default.\n\nBackground battery usage tracker\n--------------------------------\n\nApps can drain battery in the background without the user being aware. The\nbackground battery tracker watches battery usage for each app. Battery usage\nin this context is defined by three dimensions: foreground app on top,\nforeground service running something that isn't visible, and background part of\napp. If the background portion of the app's battery usage crosses some threshold,\nthe app is moved into a restricted bucket limiting it to one job per day. This\ntracker is disabled by default. To enable this tracker, run the following\ncommands: \n\n adb shell device_config put activity_manager bg_auto_restrict_abusive_apps 1\n adb shell device_config put activity_manager bg_current_drain_auto_restrict_abusive_apps_enabled 1"]]