FileDocCategorySizeDatePackage
AlarmImpl.javaAPI DocAndroid 5.1 API2791Thu Mar 12 22:22:44 GMT 2015com.android.testing.alarmservice

AlarmImpl

public class AlarmImpl extends com.android.testing.alarmservice.Alarm.Stub

Fields Summary
private static final String
LOG_TAG
private android.content.Context
mContext
Constructors Summary
public AlarmImpl(android.content.Context context)


       
        super();
        mContext = context;
    
Methods Summary
public intdone()

        WakeUpController.getController().getWakeLock().release();
        return 0;
    
public intprepare()

        WakeUpController.getController().getWakeLock().acquire();
        Log.d(LOG_TAG, "AlarmService prepared, wake lock acquired");
        return 0;
    
public intsetAlarmAndWait(long timeoutMills)

        // 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;