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

Commit 4192dd7b authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix issue where the dnd mode remains on after a call terminates.

There is a potential race condition when handling the
ACTION_INTERRUPTION_FILTER_CHANGED broadcast.  Since we're setting the
interruption mode ourselves, we also get this broadcast.  Most of the time
the broadcast is processed first and everything works.  However, it looks
like there are cases where the broadcast receiver processes AFTER we have
updated mAreNotificationSuppressed to true.  Thus, when we try to turn
off DND later on we assume that the user had initiated the request to turn
off DND and don't bother to do so.

The fix is to check who initiated the manual DND rule.  If its telecom,
we can ignore the broadcast.

Test: Manual
Bug: 33340277
Merged-In: I42b78fd27fe9814c4f8e29afc8937c3b41f51e50
Change-Id: I42b78fd27fe9814c4f8e29afc8937c3b41f51e50
parent 5ce1a784
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ import java.util.HashMap;
 * mIsMuted: a boolean indicating whether the audio is muted
 */
public class CallAudioRouteStateMachine extends StateMachine {
    private static final String TELECOM_PACKAGE =
            CallAudioRouteStateMachine.class.getPackage().getName();

    /** Direct the audio stream through the device's earpiece. */
    public static final int ROUTE_EARPIECE      = CallAudioState.ROUTE_EARPIECE;

@@ -167,6 +170,19 @@ public class CallAudioRouteStateMachine extends StateMachine {
                String action = intent.getAction();

                if (action.equals(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED)) {
                    // We get an this broadcast any time the notification filter is changed, even if
                    // we are the initiator of the change.
                    // So, we'll look at who the initiator of the manual zen rule is in the
                    // notification manager.  If its us, then we can just exit now.
                    String initiator =
                            mInterruptionFilterProxy.getInterruptionModeInitiator();

                    if (TELECOM_PACKAGE.equals(initiator)) {
                        // We are the initiator of this change, so ignore it.
                        Log.i(this, "interruptionFilterChanged - ignoring own change");
                        return;
                    }

                    if (mAreNotificationSuppressed) {
                        // If we've already set the interruption filter, and the user changes it to
                        // something other than INTERRUPTION_FILTER_ALARMS, assume we will no longer
@@ -174,6 +190,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                        mAreNotificationSuppressed =
                                mInterruptionFilterProxy.getCurrentInterruptionFilter()
                                        == NotificationManager.INTERRUPTION_FILTER_ALARMS;
                        Log.i(this, "interruptionFilterChanged - changing to %b",
                                mAreNotificationSuppressed);
                    }
                }
            } finally {
+1 −0
Original line number Diff line number Diff line
@@ -24,4 +24,5 @@ package com.android.server.telecom;
public interface InterruptionFilterProxy {
    void setInterruptionFilter(int interruptionFilter);
    int getCurrentInterruptionFilter();
    String getInterruptionModeInitiator();
}
+10 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.media.IAudioService;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.ServiceManager;
import android.service.notification.ZenModeConfig;
import android.telecom.Log;

import com.android.internal.telephony.CallerInfoAsyncQuery;
@@ -170,6 +171,15 @@ public class TelecomService extends Service implements TelecomSystem.Component {
                                public int getCurrentInterruptionFilter() {
                                    return notificationManager.getCurrentInterruptionFilter();
                                }

                                @Override
                                public String getInterruptionModeInitiator() {
                                    ZenModeConfig config = notificationManager.getZenModeConfig();
                                    if (config.manualRule != null) {
                                        return config.manualRule.enabler;
                                    }
                                    return null;
                                }
                            }
                    ));
        }
+5 −0
Original line number Diff line number Diff line
@@ -181,6 +181,11 @@ public class TelecomSystemTest extends TelecomTestCase {
        public int getCurrentInterruptionFilter() {
            return mInterruptionFilter;
        }

        @Override
        public String getInterruptionModeInitiator() {
            return "com.android.server.telecom";
        }
    }
    @Mock HeadsetMediaButton mHeadsetMediaButton;
    @Mock ProximitySensorManager mProximitySensorManager;