Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /** |
| 18 | * @addtogroup Thermal |
| 19 | * @{ |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @file thermal.h |
| 24 | */ |
| 25 | |
| 26 | #ifndef _ANDROID_THERMAL_H |
| 27 | #define _ANDROID_THERMAL_H |
| 28 | |
| 29 | #include <sys/cdefs.h> |
| 30 | |
| 31 | /****************************************************************** |
| 32 | * |
| 33 | * IMPORTANT NOTICE: |
| 34 | * |
| 35 | * This file is part of Android's set of stable system headers |
| 36 | * exposed by the Android NDK (Native Development Kit). |
| 37 | * |
| 38 | * Third-party source AND binary code relies on the definitions |
| 39 | * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. |
| 40 | * |
| 41 | * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) |
| 42 | * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS |
| 43 | * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY |
| 44 | * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES |
| 45 | */ |
| 46 | |
| 47 | /* |
| 48 | * Structures and functions to access thermal status and register/unregister |
| 49 | * thermal status listener in native code. |
| 50 | */ |
| 51 | |
| 52 | #include <stdint.h> |
| 53 | #include <sys/types.h> |
| 54 | |
| 55 | #if !defined(__INTRODUCED_IN) |
| 56 | #define __INTRODUCED_IN(30) /* Introduced in API level 30 */ |
| 57 | #endif |
| 58 | |
| 59 | #ifdef __cplusplus |
| 60 | extern "C" { |
| 61 | #endif |
| 62 | |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 63 | enum AThermalStatus { |
| 64 | /** Error in thermal status. */ |
| 65 | ATHERMAL_STATUS_ERROR = -1, |
| 66 | /** Not under throttling. */ |
| 67 | ATHERMAL_STATUS_NONE = 0, |
| 68 | /** Light throttling where UX is not impacted. */ |
| 69 | ATHERMAL_STATUS_LIGHT = 1, |
| 70 | /** Moderate throttling where UX is not largely impacted. */ |
| 71 | ATHERMAL_STATUS_MODERATE = 2, |
| 72 | /** Severe throttling where UX is largely impacted. */ |
| 73 | ATHERMAL_STATUS_SEVERE = 3, |
| 74 | /** Platform has done everything to reduce power. */ |
| 75 | ATHERMAL_STATUS_CRITICAL = 4, |
| 76 | /** |
| 77 | * Key components in platform are shutting down due to thermal condition. |
| 78 | * Device functionalities will be limited. |
| 79 | */ |
| 80 | ATHERMAL_STATUS_EMERGENCY = 5, |
| 81 | /** Need shutdown immediately. */ |
| 82 | ATHERMAL_STATUS_SHUTDOWN = 6, |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * An opaque type representing a handle to a thermal manager. |
| 87 | * An instance of thermal manager must be acquired prior to |
| 88 | * using thermal status APIs and must be released after use. |
| 89 | * |
| 90 | * <p>To use:<ul> |
| 91 | * <li>Create a new thermal manager instance by calling the |
| 92 | * {@link AThermal_acquireManager} function.</li> |
| 93 | * <li>Get current thermal status with |
| 94 | * {@link AThermal_getCurrentThermalStatus}.</li> |
| 95 | * <li>Register a thermal status listener with |
| 96 | * {@link AThermal_registerThermalStatusListener}.</li> |
| 97 | * <li>Unregister a thermal status listener with |
| 98 | * {@link AThermal_unregisterThermalStatusListener}.</li> |
| 99 | * <li>Release the thermal manager instance with |
| 100 | * {@link AThermal_releaseManager}.</li></ul></p> |
| 101 | * |
| 102 | */ |
| 103 | typedef struct AThermalManager AThermalManager; |
| 104 | |
| 105 | /** |
| 106 | * Prototype of the function that is called when thermal status changes. |
| 107 | * It's passed the updated thermal status as parameter, as well as the |
| 108 | * pointer provided by the client that registered a callback. |
| 109 | */ |
Chris Ye | 8e8cec4 | 2020-03-26 14:14:58 -0700 | [diff] [blame] | 110 | typedef void (*AThermal_StatusCallback)(void *data, AThermalStatus status); |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 111 | |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 112 | #if __ANDROID_API__ >= 30 |
| 113 | |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 114 | /** |
| 115 | * Acquire an instance of the thermal manager. This must be freed using |
| 116 | * {@link AThermal_releaseManager}. |
| 117 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 118 | * Available since API level 30. |
| 119 | * |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 120 | * @return manager instance on success, nullptr on failure. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 121 | */ |
| 122 | AThermalManager* AThermal_acquireManager() __INTRODUCED_IN(30); |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Release the thermal manager pointer acquired via |
| 126 | * {@link AThermal_acquireManager}. |
| 127 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 128 | * Available since API level 30. |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 129 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 130 | * @param manager The manager to be released. |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 131 | */ |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 132 | void AThermal_releaseManager(AThermalManager *manager) __INTRODUCED_IN(30); |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 133 | |
| 134 | /** |
| 135 | * Gets the current thermal status. |
| 136 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 137 | * Available since API level 30. |
| 138 | * |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 139 | * @param manager The manager instance to use to query the thermal status. |
| 140 | * Acquired via {@link AThermal_acquireManager}. |
| 141 | * |
| 142 | * @return current thermal status, ATHERMAL_STATUS_ERROR on failure. |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 143 | */ |
| 144 | AThermalStatus AThermal_getCurrentThermalStatus(AThermalManager *manager) __INTRODUCED_IN(30); |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Register the thermal status listener for thermal status change. |
| 148 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 149 | * Available since API level 30. |
| 150 | * |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 151 | * @param manager The manager instance to use to register. |
| 152 | * Acquired via {@link AThermal_acquireManager}. |
| 153 | * @param callback The callback function to be called when thermal status updated. |
| 154 | * @param data The data pointer to be passed when callback is called. |
| 155 | * |
| 156 | * @return 0 on success |
| 157 | * EINVAL if the listener and data pointer were previously added and not removed. |
| 158 | * EPERM if the required permission is not held. |
| 159 | * EPIPE if communication with the system service has failed. |
| 160 | */ |
| 161 | int AThermal_registerThermalStatusListener(AThermalManager *manager, |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 162 | AThermal_StatusCallback callback, void *data) __INTRODUCED_IN(30); |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * Unregister the thermal status listener previously resgistered. |
| 166 | * |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 167 | * Available since API level 30. |
| 168 | * |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 169 | * @param manager The manager instance to use to unregister. |
| 170 | * Acquired via {@link AThermal_acquireManager}. |
| 171 | * @param callback The callback function to be called when thermal status updated. |
| 172 | * @param data The data pointer to be passed when callback is called. |
| 173 | * |
| 174 | * @return 0 on success |
| 175 | * EINVAL if the listener and data pointer were not previously added. |
| 176 | * EPERM if the required permission is not held. |
| 177 | * EPIPE if communication with the system service has failed. |
| 178 | */ |
| 179 | int AThermal_unregisterThermalStatusListener(AThermalManager *manager, |
Elliott Hughes | 7be0e2d | 2020-06-02 13:05:04 -0700 | [diff] [blame^] | 180 | AThermal_StatusCallback callback, void *data) __INTRODUCED_IN(30); |
Chris Ye | 1a5a888 | 2020-01-15 10:51:47 -0800 | [diff] [blame] | 181 | |
| 182 | #endif // __ANDROID_API__ >= 30 |
| 183 | |
| 184 | #ifdef __cplusplus |
| 185 | } |
| 186 | #endif |
| 187 | |
| 188 | #endif // _ANDROID_THERMAL_H |
| 189 | |
| 190 | /** @} */ |