// calculate when device should be waken up
long atTime = SystemClock.elapsedRealtime() + timeoutMills;
AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
Intent wakupIntent = new Intent(WakeUpCall.WAKEUP_CALL);
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, wakupIntent, 0);
// set alarm, which will be delivered in form of the wakeupIntent
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, atTime, pi);
Log.d(LOG_TAG, String.format("Alarm set: %d, giving up wake lock", atTime));
Object lock = WakeUpController.getController().getWakeSync();
// release wakelock and wait for the lock to be poked from the broadcast receiver
WakeUpController.getController().getWakeLock().release();
// does not really matter if device enters suspend before we start waiting on lock
synchronized (lock) {
try {
lock.wait();
} catch (InterruptedException e) {
}
}
Log.d(LOG_TAG, String.format("Alarm triggered, done waiting"));
return 0;