Exemplo n.º 1
0
  /**
   * 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);

    Intent intent = new Intent(ALARM_ALERT_ACTION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // 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.RTC, atTimeInMillis, sender);

    // am.set(4, atTimeInMillis, sender);

    // setStatusBarIcon(context, true);

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(atTimeInMillis);
    String timeString = formatDayAndTime(context, c);
    saveNextAlarm(context, timeString);
  }
Exemplo n.º 2
0
  /**
   * 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);
  }