blob: 2ba4c763e1c835da74e4b687a8c4592eddc349f9 [file] [log] [blame]
Ruben Brunk99e69712015-05-26 17:25:07 -07001/*
2 * Copyright 2015, 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 MEDIA_BATTERY_NOTIFIER_H
18#define MEDIA_BATTERY_NOTIFIER_H
19
20#include <binder/IBatteryStats.h>
21#include <utils/Singleton.h>
22#include <utils/String8.h>
23
24#include <map>
25#include <utility>
26
27namespace android {
28
29/**
30 * Class used for logging battery life events in mediaserver.
31 */
32class BatteryNotifier : public Singleton<BatteryNotifier> {
33
34 friend class Singleton<BatteryNotifier>;
35 BatteryNotifier();
36
37public:
38 ~BatteryNotifier();
39
Wei Jiaf2ae3e12016-10-27 17:10:59 -070040 void noteStartVideo(int uid);
41 void noteStopVideo(int uid);
Ruben Brunk99e69712015-05-26 17:25:07 -070042 void noteResetVideo();
Wei Jiaf2ae3e12016-10-27 17:10:59 -070043 void noteStartAudio(int uid);
44 void noteStopAudio(int uid);
Ruben Brunk99e69712015-05-26 17:25:07 -070045 void noteResetAudio();
46 void noteFlashlightOn(const String8& id, int uid);
47 void noteFlashlightOff(const String8& id, int uid);
48 void noteResetFlashlight();
49 void noteStartCamera(const String8& id, int uid);
50 void noteStopCamera(const String8& id, int uid);
51 void noteResetCamera();
52
53private:
54 void onBatteryStatServiceDied();
55
56 class DeathNotifier : public IBinder::DeathRecipient {
57 virtual void binderDied(const wp<IBinder>& /*who*/);
58 };
59
60 Mutex mLock;
Wei Jiaf2ae3e12016-10-27 17:10:59 -070061 std::map<int, int> mVideoRefCounts;
62 std::map<int, int> mAudioRefCounts;
Ruben Brunk99e69712015-05-26 17:25:07 -070063 std::map<std::pair<String8, int>, bool> mFlashlightState;
64 std::map<std::pair<String8, int>, bool> mCameraState;
65 sp<IBatteryStats> mBatteryStatService;
66 sp<DeathNotifier> mDeathNotifier;
67
68 sp<IBatteryStats> getBatteryService_l();
69};
70
71} // namespace android
72
73#endif // MEDIA_BATTERY_NOTIFIER_H