让Android进入休眠的C代码:
static void gotoSleep()
{
//echo standby >/sys/android_power/request_state
char *standby="standby" ;
int fd = open("/sys/android_power/request_state", O_WRONLY, 0);
if (fd == -1) {
perror("Could not open /sys/android_power/request_state\n");
return ;
}
write(fd, standby, strlen(standby));
close(fd);
}
static void wakeUp()
{
char *wake="wake";
int fd = open("/sys/android_power/request_state", O_WRONLY, 0);
if (fd == -1) {
perror("Could not open /sys/android_power/request_state\n");
return ;
}
write(fd, wake, strlen(wake));
close(fd);
}