/** * Disables alert in AlarmManger and StatusBar. * * @param id Alarm ID. */ static void disableAlert(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent sender = PendingIntent.getBroadcast( context, 0, new Intent(ALARM_ALERT_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); // am.cancel(sender); am.cancelAlarm(sender); alarm_flag_cancel(); setStatusBarIcon(context, false); saveNextAlarm(context, ""); }
/** * Disables alert in AlarmManager and StatusBar. * * @param context The context */ static void disableAlert(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent sender = PendingIntent.getBroadcast( context, 0, new Intent(ALARM_ALERT_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(sender); // am.cancelPoweroffAlarm(context.getPackageName()); setStatusBarIcon(context, false); // Intentionally verbose: always log the lack of a next alarm to provide useful // information in bug reports. Log.v("No next alarm"); saveNextAlarm(context, ""); }
/** * Sets alert in AlarmManger and StatusBar. This is what will actually launch the alert when the * alarm triggers. * * @param alarm Alarm. * @param atTimeInMillis milliseconds since epoch */ private static void enableAlert( Context context, final Alarm alarm, final long atTimeInMillis, boolean disablePoweroffAlarm) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Intentionally verbose: always log the alarm time to provide useful // information in bug reports. Log.v("Alarm set for id=" + alarm.id + " " + Log.formatTime(atTimeInMillis)); Intent intent = new Intent(ALARM_ALERT_ACTION); // XXX: This is a slight hack to avoid an exception in the remote // AlarmManagerService process. The AlarmManager adds extra data to // this Intent which causes it to inflate. Since the remote process // does not know about the Alarm class, it throws a // ClassNotFoundException. // // To avoid this, we marshall the data ourselves and then parcel a plain // byte[] array. The AlarmReceiver class knows to build the Alarm // object from the byte[] array. Parcel out = Parcel.obtain(); alarm.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(ALARM_RAW_DATA, out.marshall()); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // changed by MTK start // disable power-off alarm when device encrypted. if (!disablePoweroffAlarm && "unencrypted".equals(SystemProperties.get("ro.crypto.state"))) { // not enabled device encrypt, enable power-off alarm am.set(POWER_OFF_WAKE_UP, atTimeInMillis, sender); } else { // enabled device encrypt, use google default design am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); } // changed by MTK end storeNearestAlarm(context, alarm); // am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); setStatusBarIcon(context, true); Calendar c = Calendar.getInstance(); c.setTimeInMillis(atTimeInMillis); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); }
/** * Sets alert in AlarmManger and StatusBar. This is what will actually launch the alert when the * alarm triggers. * * @param alarm Alarm. * @param atTimeInMillis milliseconds since epoch */ private static void enableAlert(Context context, final Alarm alarm, final long atTimeInMillis) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Log.LOGV) { Log.v("** setAlert id " + alarm.id + " atTime " + atTimeInMillis); } Intent intent = new Intent(ALARM_ALERT_ACTION); // XXX: This is a slight hack to avoid an exception in the remote // AlarmManagerService process. The AlarmManager adds extra data to // this Intent which causes it to inflate. Since the remote process // does not know about the Alarm class, it throws a // ClassNotFoundException. // // To avoid this, we marshall the data ourselves and then parcel a plain // byte[] array. The AlarmReceiver class knows to build the Alarm // object from the byte[] array. Parcel out = Parcel.obtain(); alarm.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(ALARM_RAW_DATA, out.marshall()); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.POWER_OFF_WAKEUP, atTimeInMillis, sender); alarm_flag_setup(context, atTimeInMillis, alarm); setStatusBarIcon(context, true); Calendar c = Calendar.getInstance(); c.setTimeInMillis(atTimeInMillis); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); }