1 /*
2  * Copyright (C) 2017 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 CHRE_PLATFORM_POWER_CONTROL_UTIL_H
18 #define CHRE_PLATFORM_POWER_CONTROL_UTIL_H
19 
20 extern "C" {
21 
22 #include "qurt_island.h"
23 
24 }  // extern "C"
25 
26 #include "chre/core/event_loop_manager.h"
27 #include "chre/platform/slpi/uimg_util.h"
28 
29 namespace chre {
30 
31 /**
32  * @return true if we're currently running in micro-image, aka island mode.
33  */
slpiInUImage()34 inline bool slpiInUImage() {
35   return (qurt_island_get_status() == 1);
36 }
37 
38 /**
39  * @return true if the successfully made a micro to big image transition.
40  */
slpiForceBigImage()41 inline bool slpiForceBigImage() {
42   bool success = false;
43   if (isSlpiUimgSupported() && slpiInUImage()) {
44     success = EventLoopManagerSingleton::get()
45                   ->getEventLoop()
46                   .getPowerControlManager()
47                   .voteBigImage(true);
48   }
49 
50   return success;
51 }
52 
53 /**
54  * Removes a big image vote from CHRE. Should only be called when the system is
55  * idle.
56  *
57  * @return true if the vote succeeds.
58  */
slpiRemoveBigImageVote()59 inline bool slpiRemoveBigImageVote() {
60   return EventLoopManagerSingleton::get()
61       ->getEventLoop()
62       .getPowerControlManager()
63       .voteBigImage(false);
64 }
65 
66 }  // namespace chre
67 
68 #endif  // CHRE_PLATFORM_POWER_CONTROL_UTIL_H
69