• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 ANDROID_SYSTEM_SYSTEM_SUSPEND_CONTROL_SERVICE_H
18 #define ANDROID_SYSTEM_SYSTEM_SUSPEND_CONTROL_SERVICE_H
19 
20 #include <android/system/suspend/BnSuspendControlService.h>
21 
22 using ::android::system::suspend::BnSuspendControlService;
23 using ::android::system::suspend::ISuspendCallback;
24 
25 namespace android {
26 namespace system {
27 namespace suspend {
28 namespace V1_0 {
29 
30 class SystemSuspend;
31 
32 class SuspendControlService : public BnSuspendControlService,
33                               public virtual IBinder::DeathRecipient {
34    public:
35     SuspendControlService() = default;
36     ~SuspendControlService() override = default;
37 
38     binder::Status enableAutosuspend(bool* _aidl_return) override;
39     binder::Status registerCallback(const sp<ISuspendCallback>& callback,
40                                     bool* _aidl_return) override;
41     binder::Status forceSuspend(bool* _aidl_return) override;
42     void binderDied(const wp<IBinder>& who) override;
43 
44     void setSuspendService(const wp<SystemSuspend>& suspend);
45     void notifyWakeup(bool success);
46 
47    private:
48     wp<SystemSuspend> mSuspend;
49 
50     std::mutex mCallbackLock;
51     std::vector<sp<ISuspendCallback> > mCallbacks;
findCb(const wp<IBinder> & cb)52     std::vector<sp<ISuspendCallback> >::iterator findCb(const wp<IBinder>& cb) {
53         return std::find_if(
54             mCallbacks.begin(), mCallbacks.end(),
55             [&cb](const sp<ISuspendCallback> i) { return cb == IInterface::asBinder(i); });
56     }
57 };
58 
59 }  // namespace V1_0
60 }  // namespace suspend
61 }  // namespace system
62 }  // namespace android
63 
64 #endif  // ANDROID_SYSTEM_SYSTEM_SUSPEND_CONTROL_SERVICE_H
65