2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
電池非搭載デバイスをサポートする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このページでは、取り外し可能な電池を使用する製品または内蔵電池がない製品に Android がどのように対応するかについて説明します。内蔵電池がないデバイスは、AC 電源コンセントや別のデバイスの USB ポートなどの外部電源に接続されます。
電池の有無
アプリケーションで次のコードを使用すると、デバイスに電池が存在するかどうかを検出できます。
```
final Intent batteryInfo = registerReceiver(null, new
IntentFilter(Intent.ACTION_BATTERY_CHANGED));
return batteryInfo.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
```
電池非搭載デバイスの動作
Android が製品の電池デバイスを検出しなかった場合、電池に関する次のデフォルト値が使用されます。Android 9 リリースではデフォルトが変更されていることにご注意ください。変更点を次の表に示します。
電池の状態
|
Android 9 以上
|
Android 8.1 以下
|
存在するか
|
false
|
true
|
ステータス
|
不明
|
充電中
|
残量
|
0
|
100%
|
健全性
|
不明
|
良好
|
AC 充電器のオンライン ステータス
|
変更なし
|
強制的に true
|
メーカーは、カーネルの power_supply ドライバまたは Health HAL を使用してデフォルト設定を変更できます。
Android 9 以上
Android 9 では、電池非搭載デバイス用のいくつかの古いコードが削除されました。それらのコードは、デフォルトでは、電池が存在し、100% 充電されており、健全性は良好でサーミスタで読み取られた温度が正常であると見なしていました。
この情報を取り扱うほとんどの Android フレームワーク API は、引き続き以前と同様に一般的な状況を処理します。システムは充電中(つまり、電池の電力で作動していない)と見なされ、電池残量が少ないとは見なされません。ユーザー インターフェースで電池アイコンが描画される場合は、感嘆符付きで表示され、電池残量のパーセンテージは 0% と表示されます。ただし、電池残量の少なさが原因でデバイスがシャットダウンすることはなく、充電または良好な電池を必要とするジョブがスケジュールされます。
Android 8.1 以下
電池のステータスが不明であるため、Android フレームワーク API はシステムが充電中である(つまり、電池の電力で作動していない)と見なし、電池残量が少ないとは見なしません。ユーザー インターフェースで電池アイコンがレンダリングされる場合は、感嘆符付きで表示され、電池残量のパーセンテージは 0% と表示されます。ただし、電池残量の少なさが原因でデバイスがシャットダウンすることはなく、充電または良好な電池を必要とするジョブがスケジュールされます。
実装
Android 9 のデフォルトのコードはお使いのデバイスで正しく動作する可能性がありますが、お使いの製品で上記のような電源と電池の状態を正確に反映するには、カーネルまたは HAL を変更することをおすすめします。Android 9 以上で Linux 電力供給クラスの充電デバイスが検出されない場合、デフォルトではすべての充電器タイプ(AC、USB、ワイヤレス)のステータスが「オフライン」になります。すべての充電器がオフラインであるにもかかわらず電池デバイスが検出されない場合、前述のように電池ではなく外部電源の電力で作動しているという意味において、システムは充電中であると見なされます。
製品に電池が搭載されておらず、常に電源に接続されている場合は、Linux カーネルの power_supply クラスの charger ドライバを実装することをおすすめします。このドライバは AC 電源または USB 電源用で、オンラインの sysfs
属性を true
に設定します。または、デバイスの Health HAL で AC 充電器のオンライン プロパティを設定することもできます。設定するには、Health 2.0 の実装の説明に沿って Health HAL を実装します。
このカスタム Health HAL は、Health::getHealthInfo()
の値を変更する BatteryProperties.chargerAcOnline = true
のカスタム バージョンを実装します。
開始するには、お持ちの Health HAL 実装にファイル hardware/interfaces/health/2.0/default/Health.cpp
をコピーし、Health 2.0 の READMEに沿ってファイルを変更します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-26 UTC。
[[["わかりやすい","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-03-26 UTC。"],[],[],null,["# Support batteryless devices\n\nThis page describes how Android handles products that have either removable\nbatteries or no internal batteries. The latter devices are instead connected to\nan external power source, such as an AC power outlet or USB port on another\ndevice.\n\nIs a battery present?\n---------------------\n\nThe following code may be used by applications to detect whether the device has\na battery present: \n\n ```\n final Intent batteryInfo = registerReceiver(null, new\n IntentFilter(Intent.ACTION_BATTERY_CHANGED));\n\n return batteryInfo.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);\n ```\n\nBatteryless device behavior\n---------------------------\n\nIf Android does not detect a battery device for your product, then the following\nbattery-related default values are used. Note the defaults have changed in the\nAndroid 9 release. This table shows the differences.\n\n| Battery state | Android 9 and higher | Android 8.1 and lower |\n|----------------------------|----------------------|-----------------------|\n| *Present* | false | true |\n| *Status* | unknown | charging |\n| *Remaining capacity* | 0 | 100% |\n| *Health* | unknown | good |\n| *AC charger online status* | not modified | forced to true |\n\nManufacturers may alter the default settings using a kernel\n[power_supply](https://www.kernel.org/doc/Documentation/power/power_supply_class.txt)\ndriver or [Health HAL](/docs/core/perf/health).\n\n### Android 9 and higher\n\nAndroid 9 removes some previous code for batteryless\ndevices that by default pretended a battery was present, was being charged at\n100%, and was in good health with a normal temperature reading on its\nthermistor.\n\nMost framework APIs that deal with this information continue to handle common\nsituations the same as previously: the system is considered to be\n*charging* (that is, not running on battery power), and won't be considered\nto have a low battery. If the user interface draws the battery icon, it will\nappear with an exclamation point, and battery percentage is shown as 0%.\nBut the device won't shut down due to low battery, and jobs that require\ncharging or good battery are scheduled.\n\n### Android 8.1 and lower\n\nBecause the battery status is unknown, the Android framework APIs will consider\nthe system to be *charging* (or, not running on battery power) and won't be\nconsidered to have a low battery. If the user interface renders the battery\nicon, it will appear with an exclamation point, and battery percentage is\nshown as 0%. But the device won't shut down due to low battery, and jobs that\nrequire charging or good battery are scheduled.\n\nImplementation\n--------------\n\nThe Android 9 default code may work properly for your\ndevice, but it's recommended to make either a kernel or a HAL change to\naccurately reflect the power and battery state for your product, as described\npreviously. If Android 9 and higher doesn't detect a [Linux power supply\nclass](https://www.kernel.org/doc/Documentation/power/power_supply_class.txt)\ncharger device, then by default all charger types (AC, USB, Wireless) will have\nstatus *offline*. If all chargers are offline but there is no battery device\ndetected, the system will still be considered to be charging in the sense that\nit is running on external, not battery power, as described previously.\n\nIf your product doesn't have a battery and is always connected to a power\nsource, it's best to implement a Linux kernel power_supply class *charger*\ndriver for the AC or USB power source that sets its *online* `sysfs` attribute\nto `true`. Or you can configure the AC charger online property in a Health HAL\nfor your device. To configure the AC charger online property in a Health HAL,\nrefer to [Health AIDL HAL](https://android.googlesource.com/platform/hardware/interfaces/+/main/health/aidl/README.md).\n\nThis custom Health HAL implements a custom version of `Health::getHealthInfo()`\nthat modifies the value of `BatteryProperties.chargerAcOnline = true`.\n\nTo get started, copy file\n[`hardware/interfaces/health/aidl/default/Health.cpp`](https://android.googlesource.com/platform/hardware/interfaces/+/main/health/aidl/default/Health.cpp)\nto your own Health HAL implementation and modify it according to the\n[Health AIDL HAL](https://android.googlesource.com/platform/hardware/interfaces/+/main/health/aidl/README.md)."]]