Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be452965 authored by Robyn Coultas's avatar Robyn Coultas Committed by Isaac Katzenelson
Browse files

Distinguish replacing alarm from dismiss

Bug: 7565654

AlarmAlertFullScreen was doing a finish on the signal from AlarmKlaxon,
so the simultaneous new intent from AlarmReceiver was not processed.

Change-Id: Ia681dfa2986a98e522ca6f0590a731a03497f9f4
parent f40eb1de
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -80,11 +80,12 @@ public class AlarmAlertFullScreen extends Activity implements GlowPadView.OnTrig
            if (action.equals(Alarms.ALARM_SNOOZE_ACTION)) {
                snooze();
            } else if (action.equals(Alarms.ALARM_DISMISS_ACTION)) {
                dismiss(false);
                dismiss(false, false);
            } else {
                Alarm alarm = intent.getParcelableExtra(Alarms.ALARM_INTENT_EXTRA);
                boolean replaced = intent.getBooleanExtra(Alarms.ALARM_REPLACED, false);
                if (alarm != null && mAlarm.id == alarm.id) {
                    dismiss(true);
                    dismiss(true, replaced);
                }
            }
        }
@@ -255,12 +256,12 @@ public class AlarmAlertFullScreen extends Activity implements GlowPadView.OnTrig
    }

    // Dismiss the alarm.
    private void dismiss(boolean killed) {
    private void dismiss(boolean killed, boolean replaced) {
        if (LOG) {
            Log.v("AlarmAlertFullScreen - dismiss");
        }

        Log.i(killed ? "Alarm killed" : "Alarm dismissed by user");
        Log.i("Alarm id=" + mAlarm.id + (killed ? (replaced ? " replaced" : " killed") : " dismissed by user"));
        // The service told us that the alarm has been killed, do not modify
        // the notification or stop the service.
        if (!killed) {
@@ -269,8 +270,10 @@ public class AlarmAlertFullScreen extends Activity implements GlowPadView.OnTrig
            nm.cancel(mAlarm.id);
            stopService(new Intent(Alarms.ALARM_ALERT_ACTION));
        }
        if (!replaced) {
            finish();
        }
    }

    /**
     * this is called when a second alarm is triggered while a
@@ -345,7 +348,7 @@ public class AlarmAlertFullScreen extends Activity implements GlowPadView.OnTrig
                            break;

                        case 2:
                            dismiss(false);
                            dismiss(false, false);
                            break;

                        default:
@@ -390,7 +393,7 @@ public class AlarmAlertFullScreen extends Activity implements GlowPadView.OnTrig
                break;

            case R.drawable.ic_alarm_alert_dismiss:
                dismiss(false);
                dismiss(false, false);
                break;
            default:
                // Code should never reach here.
+8 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.format.DateUtils;

/**
 * Manages alarms and vibe. Runs as a service so that it can continue to play
@@ -62,7 +63,7 @@ public class AlarmKlaxon extends Service {
                    if (Log.LOGV) {
                        Log.v("*********** Alarm killer triggered ***********");
                    }
                    sendKillBroadcast((Alarm) msg.obj);
                    sendKillBroadcast((Alarm) msg.obj, false);
                    stopSelf();
                    break;
            }
@@ -78,7 +79,7 @@ public class AlarmKlaxon extends Service {
            // we don't kill the alarm during a call.
            if (state != TelephonyManager.CALL_STATE_IDLE
                    && state != mInitialCallState) {
                sendKillBroadcast(mCurrentAlarm);
                sendKillBroadcast(mCurrentAlarm, false);
                stopSelf();
            }
        }
@@ -129,7 +130,7 @@ public class AlarmKlaxon extends Service {
        }

        if (mCurrentAlarm != null) {
            sendKillBroadcast(mCurrentAlarm);
            sendKillBroadcast(mCurrentAlarm, true);
        }

        play(alarm);
@@ -141,12 +142,13 @@ public class AlarmKlaxon extends Service {
        return START_STICKY;
    }

    private void sendKillBroadcast(Alarm alarm) {
    private void sendKillBroadcast(Alarm alarm, boolean replaced) {
        long millis = System.currentTimeMillis() - mStartTime;
        int minutes = (int) Math.round(millis / 60000.0);
        int minutes = (int) Math.round(millis / (double)DateUtils.MINUTE_IN_MILLIS);
        Intent alarmKilled = new Intent(Alarms.ALARM_KILLED);
        alarmKilled.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
        alarmKilled.putExtra(Alarms.ALARM_KILLED_TIMEOUT, minutes);
        alarmKilled.putExtra(Alarms.ALARM_REPLACED, replaced);
        sendBroadcast(alarmKilled);
    }

@@ -291,7 +293,7 @@ public class AlarmKlaxon extends Service {
        int autoSnoozeMinutes = Integer.parseInt(autoSnooze);
        if (autoSnoozeMinutes != -1) {
            mHandler.sendMessageDelayed(mHandler.obtainMessage(KILLER, alarm),
                    1000 * autoSnoozeMinutes * 60);
                    autoSnoozeMinutes * DateUtils.MINUTE_IN_MILLIS);
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class AlarmReceiver extends BroadcastReceiver {
        // Intentionally verbose: always log the alarm time to provide useful
        // information in bug reports.
        long now = System.currentTimeMillis();
        Log.v("Received alarm set for " + Log.formatTime(alarm.time));
        Log.v("Received alarm set for id=" + alarm.id + " " + Log.formatTime(alarm.time));

        // Always verbose to track down time change problems.
        if (now > alarm.time + STALE_WINDOW) {
+3 −0
Original line number Diff line number Diff line
@@ -76,6 +76,9 @@ public class Alarms {
    // alarm played before being killed.
    public static final String ALARM_KILLED_TIMEOUT = "alarm_killed_timeout";

    // Extra in the ALARM_KILLED intent to indicate when alarm was replaced
    public static final String ALARM_REPLACED = "alarm_replaced";

    // This string is used to indicate a silent alarm in the db.
    public static final String ALARM_ALERT_SILENT = "silent";