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

Commit 7859d637 authored by Arne Coucheron's avatar Arne Coucheron
Browse files

Revert "Fix alarm not firing in memory-pressure situations"

I have two different devices, both of which are experiencing issues
with randomly missed alarms in N. I can see in the logs that the
device wakes up in time, and it's aware that it has to fire an
alarm. So it gives the order to fire, but the order never reaches the
firing squad.

Testing this revert, both by myself and users, shows that not a single
alarm is missed. It wakes up and fires the alarm as it should every
time.

Note: CAF hijacked some of the code that Google removed in the patch,
and modified it for their own use, so I had to slightly adapt the
revert to that.

This reverts commit b76aa50f.

Change-Id: I3eeb85dec208cd0022c3d037a403bbe1a5d86e28
parent 3f87ce61
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@

package com.android.deskclock;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.VoiceInteractor;
import android.os.Build;

/**
 * Notifies Voice Interactor about whether the action
@@ -36,10 +34,6 @@ public final class Voice {
        sDelegate = delegate;
    }

    public static Delegate getDelegate() {
        return sDelegate;
    }

    public static void notifySuccess(Activity activity, String message) {
        if (Utils.isMOrLater()) {
            sDelegate.notifySuccess(activity.getVoiceInteractor(), message);
@@ -58,7 +52,6 @@ public final class Voice {
        void notifyFailure(VoiceInteractor vi, String message);
    }

    @TargetApi(Build.VERSION_CODES.M)
    private static class VoiceInteractorDelegate implements Delegate {
        @Override
        public void notifySuccess(VoiceInteractor vi, String message) {
+7 −7
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public final class AlarmNotifications {
        Intent hideIntent = AlarmStateManager.createStateChangeIntent(context,
                AlarmStateManager.ALARM_DELETE_TAG, instance,
                AlarmInstance.HIDE_NOTIFICATION_STATE);
        notification.setDeleteIntent(PendingIntent.getService(context, instance.hashCode(),
        notification.setDeleteIntent(PendingIntent.getBroadcast(context, instance.hashCode(),
                hideIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        // Setup up dismiss action
@@ -61,7 +61,7 @@ public final class AlarmNotifications {
                AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE);
        notification.addAction(R.drawable.ic_alarm_off_24dp,
                context.getString(R.string.alarm_alert_dismiss_now_text),
                PendingIntent.getService(context, instance.hashCode(),
                PendingIntent.getBroadcast(context, instance.hashCode(),
                        dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        // Setup content action if instance is owned by alarm
@@ -95,7 +95,7 @@ public final class AlarmNotifications {
                AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE);
        notification.addAction(R.drawable.ic_alarm_off_24dp,
                context.getString(R.string.alarm_alert_dismiss_now_text),
                PendingIntent.getService(context, instance.hashCode(),
                PendingIntent.getBroadcast(context, instance.hashCode(),
                        dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        // Setup content action if instance is owned by alarm
@@ -127,7 +127,7 @@ public final class AlarmNotifications {
                AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE);
        notification.addAction(R.drawable.ic_alarm_off_24dp,
                context.getString(R.string.alarm_alert_dismiss_text),
                PendingIntent.getService(context, instance.hashCode(),
                PendingIntent.getBroadcast(context, instance.hashCode(),
                        dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        // Setup content action if instance is owned by alarm
@@ -159,7 +159,7 @@ public final class AlarmNotifications {
        // Setup dismiss intent
        Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
                AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE);
        notification.setDeleteIntent(PendingIntent.getService(context, hashCode,
        notification.setDeleteIntent(PendingIntent.getBroadcast(context, hashCode,
                dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        // Setup content intent
@@ -194,7 +194,7 @@ public final class AlarmNotifications {
        Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(service,
                AlarmStateManager.ALARM_SNOOZE_TAG, instance, AlarmInstance.SNOOZE_STATE);
        snoozeIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true);
        PendingIntent snoozePendingIntent = PendingIntent.getService(service, instance.hashCode(),
        PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(service, instance.hashCode(),
                snoozeIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.addAction(R.drawable.ic_snooze_24dp,
@@ -204,7 +204,7 @@ public final class AlarmNotifications {
        Intent dismissIntent = AlarmStateManager.createStateChangeIntent(service,
                AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE);
        dismissIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true);
        PendingIntent dismissPendingIntent = PendingIntent.getService(service,
        PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(service,
                instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.addAction(R.drawable.ic_alarm_off_24dp,
                resources.getString(R.string.alarm_alert_dismiss_text),
+16 −20
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class AlarmService extends Service {
            }

            if (state != TelephonyManager.CALL_STATE_IDLE && state != mInitialCallState) {
                startService(AlarmStateManager.createStateChangeIntent(AlarmService.this,
                sendBroadcast(AlarmStateManager.createStateChangeIntent(AlarmService.this,
                        "AlarmService", mCurrentAlarm, AlarmInstance.MISSED_STATE));
            }
        }
@@ -158,6 +158,8 @@ public class AlarmService extends Service {

        AlarmAlertWakeLock.acquireCpuWakeLock(this);

        Events.sendEvent(R.string.category_alarm, R.string.action_fire, 0);

        mCurrentAlarm = instance;
        if (AlarmStateManager.isAlarmBoot()) {
            Intent alarmIntent = AlarmInstance.createIntent(this, AlarmActivity.class,
@@ -266,11 +268,6 @@ public class AlarmService extends Service {
        final long instanceId = AlarmInstance.getId(intent.getData());
        switch (intent.getAction()) {
            case AlarmStateManager.CHANGE_STATE_ACTION:
                AlarmStateManager.handleIntent(this, intent);

                // If state is changed to firing, actually fire the alarm!
                final int alarmState = intent.getIntExtra(AlarmStateManager.ALARM_STATE_EXTRA, -1);
                if (alarmState == AlarmInstance.FIRED_STATE) {
                final ContentResolver cr = this.getContentResolver();
                final AlarmInstance instance = AlarmInstance.getInstance(cr, instanceId);
                if (instance == null) {
@@ -287,7 +284,6 @@ public class AlarmService extends Service {
                    break;
                }
                startAlarm(instance);
                }
                break;
            case STOP_ALARM_ACTION:
                if (mCurrentAlarm != null && mCurrentAlarm.mId != instanceId) {
+6 −11
Original line number Diff line number Diff line
@@ -329,13 +329,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
     */
    public static Intent createStateChangeIntent(Context context, String tag,
            AlarmInstance instance, Integer state) {
        // This intent is directed to AlarmService, though the actual handling of it occurs here
        // in AlarmStateManager. The reason is that evidence exists showing the jump between the
        // broadcast receiver (AlarmStateManager) and service (AlarmService) can be thwarted by the
        // Out Of Memory killer. If clock is killed during that jump, firing an alarm can fail to
        // occur. To be safer, the call begins in AlarmService, which has the power to display the
        // firing alarm if needed, so no jump is needed.
        Intent intent = AlarmInstance.createIntent(context, AlarmService.class, instance.mId);
        Intent intent = AlarmInstance.createIntent(context, AlarmStateManager.class, instance.mId);
        intent.setAction(CHANGE_STATE_ACTION);
        intent.addCategory(tag);
        intent.putExtra(ALARM_GLOBAL_ID_EXTRA, getGlobalIntentId(context));
@@ -489,7 +483,8 @@ public final class AlarmStateManager extends BroadcastReceiver {
                    instance.mId);
        }

        Events.sendAlarmEvent(R.string.action_fire, 0);
        // Start the alarm and schedule timeout timer for it
        AlarmService.startAlarm(context, instance);

        Calendar timeout = instance.getTimeout(context);
        if (timeout != null) {
@@ -939,7 +934,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
        });
    }

    public static void handleIntent(Context context, Intent intent) {
    private void handleIntent(Context context, Intent intent) {
        final String action = intent.getAction();
        LogUtils.v("AlarmStateManager received intent " + intent);
        if (CHANGE_STATE_ACTION.equals(action)) {
@@ -1059,7 +1054,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
                    createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, newState);
            // Treat alarm state change as high priority, use foreground broadcasts
            stateChangeIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
            PendingIntent pendingIntent = PendingIntent.getService(context, instance.hashCode(),
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(),
                    stateChangeIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
@@ -1071,7 +1066,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
            LogUtils.v("Canceling instance " + instance.mId + " timers");

            // Create a PendingIntent that will match any one set for this instance
            PendingIntent pendingIntent = PendingIntent.getService(context, instance.hashCode(),
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(),
                    createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null),
                    PendingIntent.FLAG_NO_CREATE);

+1 −1
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ public final class AlarmTimeClickHandler {
        final Intent dismissIntent = AlarmStateManager.createStateChangeIntent(
                context, AlarmStateManager.ALARM_DISMISS_TAG, alarmInstance,
                AlarmInstance.PREDISMISSED_STATE);
        context.startService(dismissIntent);
        context.sendBroadcast(dismissIntent);
        mAlarmUpdateHandler.showPredismissToast(alarmInstance);
    }

Loading