自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Android 電源設定檔
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
電池用量資訊是根據電池用量統計資料和電源設定檔值得出。
電池用量統計資料
架構會追蹤裝置元件處於不同狀態的時間長度,自動判斷電池使用統計資料。當元件 (Wi-Fi 晶片組、行動電台、藍牙、GPS、螢幕、CPU) 狀態變更 (關閉/開啟、閒置/全電力、低亮度/高亮度等) 時,控制服務會向架構 BatteryStats 服務回報。BatteryStats 會隨時間收集資訊,並儲存這些資訊,以便在重新啟動時使用。這項服務不會直接追蹤電池電流消耗量,而是收集可用於估算不同元件電池消耗量的時間資訊。
架構會使用下列方法收集統計資料:
- 推送。瞭解元件變更的服務會將狀態變更推送至 BatteryStats 服務。
- 提取。針對應用程式 CPU 用量等元件,架構會在轉換點 (例如啟動或停止活動) 自動擷取資料,以便取得快照。
資源用量與使用資源的應用程式相關。當多個應用程式同時使用資源 (例如可防止系統暫停的喚醒鎖) 時,架構會將耗用量分散到這些應用程式,但不一定是平均分配。
為避免關機事件導致使用統計資料遺失,這可能表示電池耗電量問題 (也就是電池電量耗盡導致關機),因此架構會大約每 30 分鐘閃爍一次統計資料。
電池使用統計資料完全由架構處理,不需要原始設備製造商 (OEM) 修改。
電源設定檔值
注意:裝置製造商必須提供元件電源設定檔,定義元件的電流耗電量值,以及元件隨時間推移所造成的電池耗電量。這個設定檔是在 platform/frameworks/base/core/res/res/xml/power_profile.xml 中定義。如需這些設定的操作說明,請參閱「電源值」。
在電源設定檔中,耗電量會以毫安培 (mA) 的形式指定在額定電壓下所消耗的電流,也可以以微安培 (uA) 的形式指定小數值。這個值應為電池消耗的 mA,而非適用於電源軌的值,因為電源軌不一定與電池消耗的電流相符。
舉例來說,螢幕電源設定檔會指定在最低亮度和最高亮度下,維持螢幕開啟所需的 mA 電流。為了判斷保持螢幕開啟的電力成本 (即螢幕元件耗盡的電池電量),架構會追蹤各亮度等級的時間,然後將這些時間間隔乘以內插的螢幕亮度成本。
此架構也會將每個應用程式的 CPU 時間乘以以特定速度執行 CPU 所需的 mA。這項計算會建立比較排名,比較應用程式執行 CPU 程式碼時耗用多少電量 (前景應用程式時間和總時間 (包括背景活動) 會分別回報)。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Power profiles for Android\n\nBattery use information is derived from battery use statistics and power profile values.\n\nBattery use statistics\n----------------------\n\nThe framework automatically determines battery use statistics by tracking how long device\ncomponents spend in different states. As components (Wi-Fi chipset, cellular radio, Bluetooth, GPS,\ndisplay, CPU) change states (OFF/ON, idle/full power, low/high brightness, etc.), the controlling\nservice reports to the framework BatteryStats service. BatteryStats collects information over time\nand stores it for use across reboots. The service doesn't track battery current draw directly,\nbut instead collects timing information that can be used to approximate battery\nconsumption by different components.\n\nThe framework gathers statistics using the following methods:\n\n- **Push**. Services aware of component changes push state changes to the BatteryStats service.\n- **Pull**. For components such as the CPU use by apps, the framework automatically pulls the data at transition points (such as starting or stopping an activity) to take a snapshot.\n\nResource consumption is associated with the application using the resource. When multiple\napplications simultaneously use a resource (such as wakelocks that prevent the system from\nsuspending), the framework spreads consumption across those applications, although not necessarily\nequally.\n\nTo avoid losing use statistics for a shutdown event, which may indicate battery power\nconsumption problems (i.e. shutdown occurs because the battery reached zero remaining capacity),\nthe framework flashes statistics approximately every 30 minutes.\n\nBattery use statistics are handled entirely by the framework and do not require OEM\nmodifications.\n\nPower profile values\n--------------------\n\n**Caution:** Device manufacturers must provide a component power\nprofile that defines the current consumption value for the component and the approximate battery\ndrain caused by the component over time. This profile is defined in\n[platform/frameworks/base/core/res/res/xml/power_profile.xml](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/res/xml/power_profile.xml).\nFor guidance on these settings, see [Power Values](/docs/core/power/values).\n\nWithin a power profile, power consumption is specified in milliamps (mA) of current draw at a\nnominal voltage and can be a fractional value specified in microamps (uA). The value should be the\nmA consumed at the battery and not a value applicable to a power rail that does not correspond to\ncurrent consumed from the battery.\n\nFor example, a display power profile specifies the mA of current required to keep the display on\nat minimum brightness and at maximum brightness. To determine the power cost (i.e the battery\ndrained by the display component) of keeping the display on, the framework tracks the time spent at\neach brightness level, then multiplies those time intervals by an interpolated display brightness\ncost.\n\nThe framework also multiplies the CPU time for each application by the mA required to run the\nCPU at a specific speed. This calculation establishes a comparative ranking of how much battery an\napplication consumes by executing CPU code (time as the foreground app and total time including\nbackground activity are reported separately)."]]