Hardware Properties HAL: header file and default implementation
Added methods on Hardware Properties HAL:
getCpuTemperatures, getGpuTemperatures, getBatteryTemperautres,
getCpuUsages, getFanSpeeds and default/legacy empty implementations
(return empty lists by default).
Bug: 22407109
Change-Id: I3e0e74527cf759cc717ab03ea8e7184da5bea1e6
diff --git a/include/hardware/hardware_properties.h b/include/hardware/hardware_properties.h
new file mode 100644
index 0000000..7c9bd4e
--- /dev/null
+++ b/include/hardware/hardware_properties.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#ifndef ANDROID_INCLUDE_HARDWARE_HARDWAREPROPERTIES_H
+#define ANDROID_INCLUDE_HARDWARE_HARDWAREPROPERTIES_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define HARDWARE_PROPERTIES_HARDWARE_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+
+/**
+ * The id of this module
+ */
+#define HARDWARE_PROPERTIES_HARDWARE_MODULE_ID "hardware_properties"
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct hardware_properties_module {
+ struct hw_module_t common;
+
+ /*
+ * (*getCpuTemperatures) is called to get CPU temperatures in Celsius of
+ * each core.
+ *
+ * Returns number of cores or negative value on error.
+ *
+ */
+ ssize_t (*getCpuTemperatures)(struct hardware_properties_module *module, float **temps);
+
+ /*
+ * (*getGpuTemperatures) is called to get GPU temperatures in Celsius of
+ * each GPU.
+ *
+ * Returns number of GPUs or negative value on error.
+ *
+ */
+ ssize_t (*getGpuTemperatures)(struct hardware_properties_module *module, float **temps);
+
+ /*
+ * (*getBatteryTemperatures) is called to get battery temperatures in
+ * Celsius.
+ *
+ * Returns number of battery temperatures or negative value on error.
+ *
+ */
+ ssize_t (*getBatteryTemperatures)(struct hardware_properties_module *module, float **temps);
+
+ /*
+ * (*getCpuUsages) is called to get CPU usage information of each core:
+ * active and total times in ms since first boot.
+ *
+ * Returns number of cores or negative value on error.
+ *
+ */
+ ssize_t (*getCpuUsages)(struct hardware_properties_module *module,
+ int64_t **active_times, int64_t **total_times);
+
+ /*
+ * (*getFanSpeeds) is called to get the fan speeds in RPM of each fan.
+ *
+ * Returns number of fans or negative value on error.
+ *
+ */
+ ssize_t (*getFanSpeeds)(struct hardware_properties_module *module,
+ float **fan_speeds);
+} hardware_properties_module_t;
+
+__END_DECLS
+
+#endif // ANDROID_INCLUDE_HARDWARE_HARDWAREPROPERTIES_H
diff --git a/modules/Android.mk b/modules/Android.mk
index 4f30d3c..a77188d 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,4 +1,4 @@
hardware_modules := gralloc hwcomposer audio nfc nfc-nci local_time \
power usbaudio audio_remote_submix camera usbcamera consumerir sensors vibrator \
- tv_input fingerprint input vehicle
+ tv_input fingerprint input vehicle hardware_properties
include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/hardware_properties/Android.mk b/modules/hardware_properties/Android.mk
new file mode 100644
index 0000000..41c02ea
--- /dev/null
+++ b/modules/hardware_properties/Android.mk
@@ -0,0 +1,25 @@
+# Copyright (C) 2015 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := hardware_properties.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := hardware_properties.c
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/hardware_properties/hardware_properties.c b/modules/hardware_properties/hardware_properties.c
new file mode 100644
index 0000000..d8bf037
--- /dev/null
+++ b/modules/hardware_properties/hardware_properties.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+#include <hardware/hardware.h>
+#include <hardware/hardware_properties.h>
+
+static ssize_t get_device_temperatures(
+ struct hardware_properties_module *module, float **temps) {
+ *temps = NULL;
+ errno = ENOSYS;
+ ALOGE("getDeviceTemperatures: %s", strerror(errno));
+ return -1;
+}
+
+static ssize_t get_cpu_usages(struct hardware_properties_module *module,
+ int64_t **active_times, int64_t **total_times) {
+ *active_times = NULL;
+ *total_times = NULL;
+ errno = ENOSYS;
+ ALOGE("getCpuUsages: %s", strerror(errno));
+ return -1;
+}
+
+static ssize_t get_fan_speeds(struct hardware_properties_module *module,
+ float **fan_speeds) {
+ *fan_speeds = NULL;
+ errno = ENOSYS;
+ ALOGE("getFanSpeeds: %s", strerror(errno));
+ return -1;
+}
+
+static struct hw_module_methods_t hardware_properties_module_methods = {
+ .open = NULL,
+};
+
+struct hardware_properties_module HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = HARDWARE_PROPERTIES_HARDWARE_MODULE_API_VERSION_0_1,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = HARDWARE_PROPERTIES_HARDWARE_MODULE_ID,
+ .name = "Default Hardware Properties HAL",
+ .author = "The Android Open Source Project",
+ .methods = &hardware_properties_module_methods,
+ },
+
+ .getCpuTemperatures = get_device_temperatures,
+ .getGpuTemperatures = get_device_temperatures,
+ .getBatteryTemperatures = get_device_temperatures,
+ .getCpuUsages = get_cpu_usages,
+ .getFanSpeeds = get_fan_speeds,
+};