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

Commit 53216dff authored by Budi Kusmiantoro's avatar Budi Kusmiantoro
Browse files

Only show AlarmActivity for firing alarms

Bug: 17746721

Also handle ALARM_DONE_ACTION to finish the activity.

Change-Id: Ice2e07a8dfe82be785622aa24f3ea0a655cd30f3
parent 5caf3c80
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ public class AlarmActivity extends Activity implements View.OnClickListener, Vie
    private boolean mAlarmHandled;
    private String mVolumeBehavior;
    private int mCurrentHourColor;
    private boolean mReceiverRegistered;

    private ViewGroup mContainerView;

@@ -138,15 +139,19 @@ public class AlarmActivity extends Activity implements View.OnClickListener, Vie

        final long instanceId = AlarmInstance.getId(getIntent().getData());
        mAlarmInstance = AlarmInstance.getInstance(getContentResolver(), instanceId);
        if (mAlarmInstance != null) {
            LogUtils.i(LOGTAG, "Displaying alarm for instance: %s", mAlarmInstance);
        } else {
        if (mAlarmInstance == null) {
            // The alarm got deleted before the activity got created, so just finish()
            LogUtils.e(LOGTAG, "Error displaying alarm for intent: %s", getIntent());
            finish();
            return;
        } else if (mAlarmInstance.mAlarmState != AlarmInstance.FIRED_STATE) {
            LogUtils.i(LOGTAG, "Skip displaying alarm for instance: %s", mAlarmInstance);
            finish();
            return;
        }

        LogUtils.i(LOGTAG, "Displaying alarm for instance: %s", mAlarmInstance);

        // Get the volume/camera button behavior setting
        mVolumeBehavior = PreferenceManager.getDefaultSharedPreferences(this)
                .getString(SettingsActivity.KEY_VOLUME_BEHAVIOR,
@@ -217,15 +222,15 @@ public class AlarmActivity extends Activity implements View.OnClickListener, Vie
        filter.addAction(ALARM_SNOOZE_ACTION);
        filter.addAction(ALARM_DISMISS_ACTION);
        registerReceiver(mReceiver, filter);
        mReceiverRegistered = true;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        // If the alarm instance is null the receiver was never registered and calling
        // unregisterReceiver will throw an exception.
        if (mAlarmInstance != null) {
        // Skip if register didn't happen to avoid IllegalArgumentException
        if (mReceiverRegistered) {
            unregisterReceiver(mReceiver);
        }
    }