Files
hardware_interfaces/health/utils/libhealthloop/Android.bp
Bart Van Assche 5c604b9a73 libhealthloop: Only wake up for power supply events
healthd receives power supply information as uevents and holds a
wakelock while receiving these uevents. Without uevent filter, suspend
is postponed indefinitely if a uevent is generated during suspend. Fix
this by attaching a BPF program to the uevent socket that filters out
all events that are not power supply events.

This CL replaces the following CLs:
* Lianwei Wang, healthd: Don't set all eventpoll wakeup-able,
  2015-07-09
  (https://android-review.googlesource.com/c/platform/system/core/+/158851).
* Stephane Lee, Add BPF filter to filter uevents for
  SUBSYSTEM=powersupply, 2022-05-06.

Multiple ideas and some code in this CL have been borrowed from
Stephane Lee's CL.

Bug: 139203596
Bug: 140330870
Bug: 203131934
Bug: 203229817
Bug: 203462310
Bug: 221725014
Test: Verified that a Pixel 2024 still wakes up if a USB cable is connected or disconnected.
Test: Verified that suspend and resume still works for a Pixel 2024 device.
Test: Verified that the following text appears in the Cuttlefish logcat output: "HealthLoop: Successfully attached BPF program to uevent socket"
Test: Verified as follows that recovery mode works fine with Cuttlefish: adb reboot recovery && adb root && adb shell dmesg | grep -E 'F DEBUG|HealthLoop'
Change-Id: I64446b103d660d220880461bdef7ef0f531e1734
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2024-08-05 15:56:25 -07:00

84 lines
2.4 KiB
Plaintext

// Copyright (C) 2019 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.
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "hardware_interfaces_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["hardware_interfaces_license"],
}
bpf {
name: "filterPowerSupplyEvents.o",
srcs: ["filterPowerSupplyEvents.c"],
// "vendor: true" because all binaries that use this BPF filter are vendor
// binaries.
vendor: true,
}
// Since "required" sections are ignored in static library definitions,
// filterPowerSupplyEvents.o has been added in
// build/make/target/product/base_vendor.mk.
cc_library_static {
name: "libhealthloop",
vendor_available: true,
recovery_available: true,
srcs: [
"HealthLoop.cpp",
"utils.cpp",
],
shared_libs: [
"libbase",
"libcutils",
],
header_libs: [
"bpf_headers",
"libbatteryservice_headers",
"libhealthd_headers",
"libutils_headers",
],
export_include_dirs: [
"include",
],
}
genrule {
name: "filterPowerSupplyEvents.h",
out: ["filterPowerSupplyEvents.h"],
srcs: [":filterPowerSupplyEvents.o"],
cmd: "cat $(in) | od -v -tx1 | cut -c9- | grep -v '^$$' | sed 's/^/0x/;s/ /, 0x/g;s/^, //;s/$$/,/' > $(out)",
}
cc_test_host {
name: "filterPowerSupplyEventsTest",
team: "trendy_team_pixel_system_sw_storage",
srcs: [
"filterPowerSupplyEventsTest.cpp",
],
shared_libs: [
"libbase",
"libbpf",
],
static_libs: [
"libgmock",
],
generated_headers: [
"filterPowerSupplyEvents.h",
"libbpf_headers",
],
compile_multilib: "64",
}