1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.deskclock; 18 19import android.content.Context; 20import android.content.Intent; 21import android.content.BroadcastReceiver; 22import android.os.PowerManager.WakeLock; 23 24public class AlarmInitReceiver extends BroadcastReceiver { 25 26 /** 27 * Sets alarm on ACTION_BOOT_COMPLETED. Resets alarm on 28 * TIME_SET, TIMEZONE_CHANGED 29 */ 30 @Override 31 public void onReceive(final Context context, Intent intent) { 32 final String action = intent.getAction(); 33 if (Log.LOGV) Log.v("AlarmInitReceiver" + action); 34 35 final PendingResult result = goAsync(); 36 final WakeLock wl = AlarmAlertWakeLock.createPartialWakeLock(context); 37 wl.acquire(); 38 AsyncHandler.post(new Runnable() { 39 @Override public void run() { 40 // Remove the snooze alarm after a boot. 41 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { 42 Alarms.saveSnoozeAlert(context, Alarms.INVALID_ALARM_ID, -1); 43 } 44 45 Alarms.disableExpiredAlarms(context); 46 Alarms.setNextAlert(context); 47 result.finish(); 48 Log.v("AlarmInitReceiver finished"); 49 wl.release(); 50 } 51 }); 52 } 53} 54