Import GingerCal 1.0 source
This commit is contained in:
commit
01f49852ab
116 files changed
+5079
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package org.gingercal;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PowerManager;
|
||||
|
||||
/** Boot, periodic-sync and reminder alarms all land here. */
|
||||
public class AlarmReceiver extends BroadcastReceiver {
|
||||
public static final String SYNC = "org.gingercal.SYNC";
|
||||
public static final String REMIND = "org.gingercal.REMIND";
|
||||
private static PowerManager.WakeLock lock;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context c, Intent i) {
|
||||
String a = i.getAction();
|
||||
if (REMIND.equals(a)) {
|
||||
Reminders.fire(c);
|
||||
} else if (SYNC.equals(a)) {
|
||||
acquire(c);
|
||||
App.requestSync(c, false, false);
|
||||
} else {
|
||||
// BOOT_COMPLETED / package replaced: alarms don't survive either
|
||||
App.scheduleSync(c);
|
||||
Reminders.schedule(c);
|
||||
}
|
||||
}
|
||||
|
||||
static synchronized void acquire(Context c) {
|
||||
if (lock == null) {
|
||||
PowerManager pm = (PowerManager) c.getApplicationContext().getSystemService("power");
|
||||
lock = pm.newWakeLock(1 /* PARTIAL_WAKE_LOCK */, "GingerCal sync");
|
||||
lock.setReferenceCounted(false);
|
||||
}
|
||||
lock.acquire(5 * 60 * 1000L);
|
||||
}
|
||||
|
||||
static synchronized void release() {
|
||||
if (lock != null && lock.isHeld()) lock.release();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user