Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #ifndef HEALTHD_BATTERYPROPERTIES_REGISTRAR_H |
| 18 | #define HEALTHD_BATTERYPROPERTIES_REGISTRAR_H |
| 19 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 20 | #include <binder/IBinder.h> |
| 21 | #include <utils/Mutex.h> |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 22 | #include <utils/String16.h> |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 23 | #include <utils/Vector.h> |
| 24 | #include <batteryservice/BatteryService.h> |
| 25 | #include <batteryservice/IBatteryPropertiesListener.h> |
| 26 | #include <batteryservice/IBatteryPropertiesRegistrar.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 30 | class BatteryPropertiesRegistrar : public BnBatteryPropertiesRegistrar, |
| 31 | public IBinder::DeathRecipient { |
| 32 | public: |
Todd Poynor | e553564 | 2016-01-05 19:41:34 -0800 | [diff] [blame] | 33 | void publish(const sp<BatteryPropertiesRegistrar>& service); |
Chih-Hung Hsieh | 4df1056 | 2016-07-27 16:05:50 -0700 | [diff] [blame] | 34 | void notifyListeners(const struct BatteryProperties& props); |
Adam Lesinski | 3dec1aa | 2017-02-15 18:49:00 -0800 | [diff] [blame] | 35 | void scheduleUpdate(); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 36 | |
| 37 | private: |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 38 | Mutex mRegistrationLock; |
| 39 | Vector<sp<IBatteryPropertiesListener> > mListeners; |
| 40 | |
| 41 | void registerListener(const sp<IBatteryPropertiesListener>& listener); |
| 42 | void unregisterListener(const sp<IBatteryPropertiesListener>& listener); |
Todd Poynor | c133b71 | 2013-08-14 17:39:13 -0700 | [diff] [blame] | 43 | status_t getProperty(int id, struct BatteryProperty *val); |
Todd Poynor | 020369d | 2013-09-18 20:09:33 -0700 | [diff] [blame] | 44 | status_t dump(int fd, const Vector<String16>& args); |
Todd Poynor | 752faf2 | 2013-06-12 13:25:59 -0700 | [diff] [blame] | 45 | void binderDied(const wp<IBinder>& who); |
| 46 | }; |
| 47 | |
| 48 | }; // namespace android |
| 49 | |
| 50 | #endif // HEALTHD_BATTERYPROPERTIES_REGISTRAR_H |