summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Murray2016-11-02 15:23:25 -0500
committerTim Murray2016-11-02 17:49:56 -0500
commit021d60be98ca2eb72b2c63e3b1fea2169b7c2b69 (patch)
tree5c83e1015f24d2f3835cbf3c9e29beeea9fa190a /libsuspend
parentcd629590f2672d4b22915ffb5fcde533eae0b11f (diff)
downloadplatform-system-core-021d60be98ca2eb72b2c63e3b1fea2169b7c2b69.tar.gz
platform-system-core-021d60be98ca2eb72b2c63e3b1fea2169b7c2b69.tar.xz
platform-system-core-021d60be98ca2eb72b2c63e3b1fea2169b7c2b69.zip
libsuspend: remove autosleep and earlysuspend
autosleep and earlysuspend are long-deprecated, so remove them to make libsuspend slightly more comprehensible. Test: builds and still suspends on marlin bug 32621856 Change-Id: I66a904c3fce0111fb5e9d1ab9d205c97617ae210
Diffstat (limited to 'libsuspend')
-rw-r--r--libsuspend/Android.bp2
-rw-r--r--libsuspend/autosuspend.c13
-rw-r--r--libsuspend/autosuspend_autosleep.c102
-rw-r--r--libsuspend/autosuspend_earlysuspend.c219
4 files changed, 0 insertions, 336 deletions
diff --git a/libsuspend/Android.bp b/libsuspend/Android.bp
index d27ceea68..d442c9433 100644
--- a/libsuspend/Android.bp
+++ b/libsuspend/Android.bp
@@ -4,8 +4,6 @@ cc_library {
4 name: "libsuspend", 4 name: "libsuspend",
5 srcs: [ 5 srcs: [
6 "autosuspend.c", 6 "autosuspend.c",
7 "autosuspend_autosleep.c",
8 "autosuspend_earlysuspend.c",
9 "autosuspend_wakeup_count.c", 7 "autosuspend_wakeup_count.c",
10 ], 8 ],
11 export_include_dirs: ["include"], 9 export_include_dirs: ["include"],
diff --git a/libsuspend/autosuspend.c b/libsuspend/autosuspend.c
index 64d1bfc74..2e1983acb 100644
--- a/libsuspend/autosuspend.c
+++ b/libsuspend/autosuspend.c
@@ -34,19 +34,6 @@ static int autosuspend_init(void)
34 return 0; 34 return 0;
35 } 35 }
36 36
37 autosuspend_ops = autosuspend_earlysuspend_init();
38 if (autosuspend_ops) {
39 goto out;
40 }
41
42/* Remove autosleep so userspace can manager suspend/resume and keep stats */
43#if 0
44 autosuspend_ops = autosuspend_autosleep_init();
45 if (autosuspend_ops) {
46 goto out;
47 }
48#endif
49
50 autosuspend_ops = autosuspend_wakeup_count_init(); 37 autosuspend_ops = autosuspend_wakeup_count_init();
51 if (autosuspend_ops) { 38 if (autosuspend_ops) {
52 goto out; 39 goto out;
diff --git a/libsuspend/autosuspend_autosleep.c b/libsuspend/autosuspend_autosleep.c
deleted file mode 100644
index 97109ac2c..000000000
--- a/libsuspend/autosuspend_autosleep.c
+++ /dev/null
@@ -1,102 +0,0 @@
1/*
2 * Copyright (C) 2012 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#define LOG_TAG "libsuspend"
18
19#include <errno.h>
20#include <fcntl.h>
21#include <stddef.h>
22#include <string.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <unistd.h>
26
27#include <android/log.h>
28
29#include "autosuspend_ops.h"
30
31#define SYS_POWER_AUTOSLEEP "/sys/power/autosleep"
32
33static int autosleep_fd;
34static const char *sleep_state = "mem";
35static const char *on_state = "off";
36
37static int autosuspend_autosleep_enable(void)
38{
39 char buf[80];
40 int ret;
41
42 ALOGV("autosuspend_autosleep_enable\n");
43
44 ret = TEMP_FAILURE_RETRY(write(autosleep_fd, sleep_state, strlen(sleep_state)));
45 if (ret < 0) {
46 strerror_r(errno, buf, sizeof(buf));
47 ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
48 goto err;
49 }
50
51 ALOGV("autosuspend_autosleep_enable done\n");
52
53 return 0;
54
55err:
56 return ret;
57}
58
59static int autosuspend_autosleep_disable(void)
60{
61 char buf[80];
62 int ret;
63
64 ALOGV("autosuspend_autosleep_disable\n");
65
66 ret = TEMP_FAILURE_RETRY(write(autosleep_fd, on_state, strlen(on_state)));
67 if (ret < 0) {
68 strerror_r(errno, buf, sizeof(buf));
69 ALOGE("Error writing to %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
70 goto err;
71 }
72
73 ALOGV("autosuspend_autosleep_disable done\n");
74
75 return 0;
76
77err:
78 return ret;
79}
80
81struct autosuspend_ops autosuspend_autosleep_ops = {
82 .enable = autosuspend_autosleep_enable,
83 .disable = autosuspend_autosleep_disable,
84};
85
86struct autosuspend_ops *autosuspend_autosleep_init(void)
87{
88 char buf[80];
89
90 autosleep_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_AUTOSLEEP, O_WRONLY));
91 if (autosleep_fd < 0) {
92 strerror_r(errno, buf, sizeof(buf));
93 ALOGE("Error opening %s: %s\n", SYS_POWER_AUTOSLEEP, buf);
94 return NULL;
95 }
96
97 ALOGI("Selected autosleep\n");
98
99 autosuspend_autosleep_disable();
100
101 return &autosuspend_autosleep_ops;
102}
diff --git a/libsuspend/autosuspend_earlysuspend.c b/libsuspend/autosuspend_earlysuspend.c
deleted file mode 100644
index 9519e51ea..000000000
--- a/libsuspend/autosuspend_earlysuspend.c
+++ /dev/null
@@ -1,219 +0,0 @@
1/*
2 * Copyright (C) 2012 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#define LOG_TAG "libsuspend"
18
19#include <errno.h>
20#include <fcntl.h>
21#include <pthread.h>
22#include <stdbool.h>
23#include <stddef.h>
24#include <string.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27#include <unistd.h>
28
29#include <android/log.h>
30
31#include "autosuspend_ops.h"
32
33#define EARLYSUSPEND_SYS_POWER_STATE "/sys/power/state"
34#define EARLYSUSPEND_WAIT_FOR_FB_SLEEP "/sys/power/wait_for_fb_sleep"
35#define EARLYSUSPEND_WAIT_FOR_FB_WAKE "/sys/power/wait_for_fb_wake"
36
37static int sPowerStatefd;
38static const char *pwr_state_mem = "mem";
39static const char *pwr_state_on = "on";
40static pthread_t earlysuspend_thread;
41static pthread_mutex_t earlysuspend_mutex = PTHREAD_MUTEX_INITIALIZER;
42static pthread_cond_t earlysuspend_cond = PTHREAD_COND_INITIALIZER;
43static bool wait_for_earlysuspend;
44static enum {
45 EARLYSUSPEND_ON,
46 EARLYSUSPEND_MEM,
47} earlysuspend_state = EARLYSUSPEND_ON;
48
49int wait_for_fb_wake(void)
50{
51 int err = 0;
52 char buf;
53 int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_WAKE, O_RDONLY, 0));
54 // if the file doesn't exist, the error will be caught in read() below
55 err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
56 ALOGE_IF(err < 0,
57 "*** ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno));
58 close(fd);
59 return err < 0 ? err : 0;
60}
61
62static int wait_for_fb_sleep(void)
63{
64 int err = 0;
65 char buf;
66 int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, O_RDONLY, 0));
67 // if the file doesn't exist, the error will be caught in read() below
68 err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
69 ALOGE_IF(err < 0,
70 "*** ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno));
71 close(fd);
72 return err < 0 ? err : 0;
73}
74
75static void *earlysuspend_thread_func(void __unused *arg)
76{
77 while (1) {
78 if (wait_for_fb_sleep()) {
79 ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread\n");
80 return NULL;
81 }
82 pthread_mutex_lock(&earlysuspend_mutex);
83 earlysuspend_state = EARLYSUSPEND_MEM;
84 pthread_cond_signal(&earlysuspend_cond);
85 pthread_mutex_unlock(&earlysuspend_mutex);
86
87 if (wait_for_fb_wake()) {
88 ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread\n");
89 return NULL;
90 }
91 pthread_mutex_lock(&earlysuspend_mutex);
92 earlysuspend_state = EARLYSUSPEND_ON;
93 pthread_cond_signal(&earlysuspend_cond);
94 pthread_mutex_unlock(&earlysuspend_mutex);
95 }
96}
97static int autosuspend_earlysuspend_enable(void)
98{
99 char buf[80];
100 int ret;
101
102 ALOGV("autosuspend_earlysuspend_enable\n");
103
104 ret = write(sPowerStatefd, pwr_state_mem, strlen(pwr_state_mem));
105 if (ret < 0) {
106 strerror_r(errno, buf, sizeof(buf));
107 ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
108 goto err;
109 }
110
111 if (wait_for_earlysuspend) {
112 pthread_mutex_lock(&earlysuspend_mutex);
113 while (earlysuspend_state != EARLYSUSPEND_MEM) {
114 pthread_cond_wait(&earlysuspend_cond, &earlysuspend_mutex);
115 }
116 pthread_mutex_unlock(&earlysuspend_mutex);
117 }
118
119 ALOGV("autosuspend_earlysuspend_enable done\n");
120
121 return 0;
122
123err:
124 return ret;
125}
126
127static int autosuspend_earlysuspend_disable(void)
128{
129 char buf[80];
130 int ret;
131
132 ALOGV("autosuspend_earlysuspend_disable\n");
133
134 ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, pwr_state_on, strlen(pwr_state_on)));
135 if (ret < 0) {
136 strerror_r(errno, buf, sizeof(buf));
137 ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
138 goto err;
139 }
140
141 if (wait_for_earlysuspend) {
142 pthread_mutex_lock(&earlysuspend_mutex);
143 while (earlysuspend_state != EARLYSUSPEND_ON) {
144 pthread_cond_wait(&earlysuspend_cond, &earlysuspend_mutex);
145 }
146 pthread_mutex_unlock(&earlysuspend_mutex);
147 }
148
149 ALOGV("autosuspend_earlysuspend_disable done\n");
150
151 return 0;
152
153err:
154 return ret;
155}
156
157struct autosuspend_ops autosuspend_earlysuspend_ops = {
158 .enable = autosuspend_earlysuspend_enable,
159 .disable = autosuspend_earlysuspend_disable,
160};
161
162void start_earlysuspend_thread(void)
163{
164 char buf[80];
165 int ret;
166
167 ret = access(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, F_OK);
168 if (ret < 0) {
169 return;
170 }
171
172 ret = access(EARLYSUSPEND_WAIT_FOR_FB_WAKE, F_OK);
173 if (ret < 0) {
174 return;
175 }
176
177 wait_for_fb_wake();
178
179 ALOGI("Starting early suspend unblocker thread\n");
180 ret = pthread_create(&earlysuspend_thread, NULL, earlysuspend_thread_func, NULL);
181 if (ret) {
182 strerror_r(errno, buf, sizeof(buf));
183 ALOGE("Error creating thread: %s\n", buf);
184 return;
185 }
186
187 wait_for_earlysuspend = true;
188}
189
190struct autosuspend_ops *autosuspend_earlysuspend_init(void)
191{
192 char buf[80];
193 int ret;
194
195 sPowerStatefd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR));
196
197 if (sPowerStatefd < 0) {
198 strerror_r(errno, buf, sizeof(buf));
199 ALOGW("Error opening %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
200 return NULL;
201 }
202
203 ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, "on", 2));
204 if (ret < 0) {
205 strerror_r(errno, buf, sizeof(buf));
206 ALOGW("Error writing 'on' to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
207 goto err_write;
208 }
209
210 ALOGI("Selected early suspend\n");
211
212 start_earlysuspend_thread();
213
214 return &autosuspend_earlysuspend_ops;
215
216err_write:
217 close(sPowerStatefd);
218 return NULL;
219}