1
2
3
4
5
6
7
8
9
10
11
|
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(
"com.android.settings.action.REQUEST_POWER_OFF");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
|
1
2
3
|
Intent newIntent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(newIntent);
|
1
2
3
4
5
6
7
8
9
|
#define ANDROID_ALARM_GET_TIME(type) ALARM_IOW(4, type, struct timespec)
#define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec)
/* we define ANDROID_RTC_ALARM_SET for auto power off */
#define ANDROID_RTC_ALARM_SET _IOW('a', 7, int)
#define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0)))
b) bionic/libc/kernel/common/linux/android_alarm.h
#define ANDROID_RTC_ALARM_SET _IOW('a', 7, int)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
case ANDROID_RTC_ALARM_SET:
{
unsigned int rtc_alarm_time;
struct rtc_time rtc_now;
if (copy_from_user(&rtc_alarm_time, (void __user *)arg,
sizeof(rtc_alarm_time))) {
rv = -EFAULT;
goto err1;
}
if (pmic_rtc_get_time(&rtc_now) < 0) {
rtc_now.sec = 0;
if (pmic_rtc_start(&rtc_now) < 0) {
printk("get and set rtc info failed\n");
break;
}
}
pmic_rtc_disable_alarm(PM_RTC_ALARM_1);
rtc_now.sec += rtc_alarm_time;
pmic_rtc_enable_alarm(PM_RTC_ALARM_1, &rtc_now);
break;
}
|
1
|
#include <mach/pmic.h>
|
1
2
3
4
5
6
7
8
9
10
11
|
static void android_server_AlarmManagerService_updateRtcAlarm(JNIEnv* env, jobject obj, jint fd, jint seconds)
{
#if HAVE_ANDROID_OS
int result = ioctl(fd, ANDROID_RTC_ALARM_SET, &seconds);
LOGE("set rtc alarm to %d later: %s\n", seconds, strerror(errno));
if (result < 0)
{
LOGE("Unable to set rtc alarm to %d later: %s\n", seconds, strerror(errno));
}
#endif
}
|
1
|
{"updateRtcAlarm", "(II)V", (void*)android_server_AlarmManagerService_updateRtcAlarm},
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
public void setRepeating(int type, long triggerAtTime, long interval,
PendingIntent operation) {
if (operation == null) {
Slog.w(TAG, "set/setRepeating ignored because there is no intent");
return;
}
synchronized (mLock) {
Alarm alarm = new Alarm();
alarm.type = type;
alarm.when = triggerAtTime;
alarm.repeatInterval = interval;
alarm.operation = operation;
// Remove this alarm if already scheduled.
removeLocked(operation);
if (localLOGV) Slog.v(TAG, "set: " + alarm);
int index = addAlarmLocked(alarm);
if (index == 0) {
setLocked(alarm);
}
// Start to setup auto power on alarm
if ((alarm.type == AlarmManager.ELAPSED_REALTIME_WAKEUP) &&
alarm.operation.getTargetPackage().equals("com.android.settings")) {
updateRtcAlarm(mDescriptor, (int)((alarm.when - System.currentTimeMillis()) / 1000));
}
// End to setup auto power on alarm
}
}
|
1
2
3
4
5
6
7
8
9
|
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(
"com.android.settings.action.REQUEST_POWER_ON");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, time, pendingIntent);
|