1787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian/*
2787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * Copyright (C) 2012 The Android Open Source Project
3787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian *
4787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * you may not use this file except in compliance with the License.
6787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * You may obtain a copy of the License at
7787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian *
8787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian *
10787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * Unless required by applicable law or agreed to in writing, software
11787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * See the License for the specific language governing permissions and
14787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian * limitations under the License.
15787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian */
16787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
17787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian#include <stdint.h>
18787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian#include <sys/types.h>
19787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
2063ff1c644f785c78adbf65b9abf6b998cee2c7a1Mike Lockwood#include <binder/IBatteryStats.h>
21787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian#include <utils/Singleton.h>
22787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
23787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopiannamespace android {
24787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian// ---------------------------------------------------------------------------
25787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
26787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopianclass BatteryService : public Singleton<BatteryService> {
27787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
28787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    friend class Singleton<BatteryService>;
2963ff1c644f785c78adbf65b9abf6b998cee2c7a1Mike Lockwood    sp<IBatteryStats> mBatteryStatService;
30787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
31787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    BatteryService();
32787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
33787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    void enableSensorImpl(uid_t uid, int handle);
34787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    void disableSensorImpl(uid_t uid, int handle);
35787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    void cleanupImpl(uid_t uid);
36787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
37787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    struct Info {
38787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        uid_t uid;
39787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        int handle;
40787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        int32_t count;
41787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        Info()  : uid(0), handle(0), count(0) { }
42787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        Info(uid_t uid, int handle) : uid(uid), handle(handle), count(0) { }
43787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        bool operator < (const Info& rhs) const {
44787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian            return (uid == rhs.uid) ? (handle < rhs.handle) :  (uid < rhs.uid);
45787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        }
46787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    };
47787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
48787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    Mutex mActivationsLock;
49787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    SortedVector<Info> mActivations;
50787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    bool addSensor(uid_t uid, int handle);
51787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    bool removeSensor(uid_t uid, int handle);
52787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
53787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopianpublic:
54787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    static void enableSensor(uid_t uid, int handle) {
55787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        BatteryService::getInstance().enableSensorImpl(uid, handle);
56787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    }
57787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    static void disableSensor(uid_t uid, int handle) {
58787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        BatteryService::getInstance().disableSensorImpl(uid, handle);
59787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    }
60787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    static void cleanup(uid_t uid) {
61787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian        BatteryService::getInstance().cleanupImpl(uid);
62787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian    }
63787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian};
64787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
65787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian// ---------------------------------------------------------------------------
66787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian}; // namespace android
67787ac1b388f144f5e6dd38f8b807866a5256dafcMathias Agopian
68