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

Commit 1b55a2a9 authored by Colin Cross's avatar Colin Cross
Browse files

Revert "Remove auto-DND while in call."

This reverts commit 6140bf27.

Broke errorprone build

Change-Id: I4188fff3edd95d47371bbd24fe8933d57c35dbe5
parent 6140bf27
Loading
Loading
Loading
Loading
+111 −0
Original line number Diff line number Diff line
@@ -18,7 +18,11 @@ package com.android.server.telecom;


import android.app.ActivityManager;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.media.AudioManager;
import android.media.IAudioService;
@@ -154,6 +158,49 @@ public class CallAudioRouteStateMachine extends StateMachine {
        put(RUN_RUNNABLE, "RUN_RUNNABLE");
    }};

    /**
     * BroadcastReceiver used to track changes in the notification interruption filter.  This
     * ensures changes to the notification interruption filter made by the user during a call are
     * respected when restoring the notification interruption filter state.
     */
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.startSession("CARSM.oR");
            try {
                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
                        // try to change it back if the audio route changes.
                        mAreNotificationSuppressed =
                                mInterruptionFilterProxy.getCurrentInterruptionFilter()
                                        == NotificationManager.INTERRUPTION_FILTER_ALARMS;
                        Log.i(this, "interruptionFilterChanged - changing to %b",
                                mAreNotificationSuppressed);
                    }
                }
            } finally {
                Log.endSession();
            }
        }
    };

    private static final String ACTIVE_EARPIECE_ROUTE_NAME = "ActiveEarpieceRoute";
    private static final String ACTIVE_BLUETOOTH_ROUTE_NAME = "ActiveBluetoothRoute";
    private static final String ACTIVE_SPEAKER_ROUTE_NAME = "ActiveSpeakerRoute";
@@ -268,12 +315,21 @@ public class CallAudioRouteStateMachine extends StateMachine {
            super.enter();
            setSpeakerphoneOn(false);
            setBluetoothOn(false);
            if (mAudioFocusType == ACTIVE_FOCUS) {
                setNotificationsSuppressed(true);
            }
            CallAudioState newState = new CallAudioState(mIsMuted, ROUTE_EARPIECE,
                    mAvailableRoutes);
            setSystemAudioState(newState, true);
            updateInternalCallAudioState();
        }

        @Override
        public void exit() {
            super.exit();
            setNotificationsSuppressed(false);
        }

        @Override
        public void updateSystemAudioState() {
            updateInternalCallAudioState();
@@ -312,6 +368,10 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    transitionTo(mActiveSpeakerRoute);
                    return HANDLED;
                case SWITCH_FOCUS:
                    if (msg.arg1 == ACTIVE_FOCUS) {
                        setNotificationsSuppressed(true);
                    }

                    if (msg.arg1 == NO_FOCUS) {
                        reinitialize();
                    }
@@ -1091,6 +1151,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
    private int mAudioFocusType;
    private boolean mWasOnSpeaker;
    private boolean mIsMuted;
    private boolean mAreNotificationSuppressed = false;

    private final Context mContext;
    private final CallsManager mCallsManager;
@@ -1099,6 +1160,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
    private final WiredHeadsetManager mWiredHeadsetManager;
    private final StatusBarNotifier mStatusBarNotifier;
    private final CallAudioManager.AudioServiceFactory mAudioServiceFactory;
    private final InterruptionFilterProxy mInterruptionFilterProxy;
    private final boolean mDoesDeviceSupportEarpieceRoute;
    private final TelecomSystem.SyncRoot mLock;
    private boolean mHasUserExplicitlyLeftBluetooth = false;
@@ -1118,6 +1180,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
            WiredHeadsetManager wiredHeadsetManager,
            StatusBarNotifier statusBarNotifier,
            CallAudioManager.AudioServiceFactory audioServiceFactory,
            InterruptionFilterProxy interruptionFilterProxy,
            boolean doesDeviceSupportEarpieceRoute) {
        super(NAME);
        addState(mActiveEarpieceRoute);
@@ -1137,6 +1200,11 @@ public class CallAudioRouteStateMachine extends StateMachine {
        mWiredHeadsetManager = wiredHeadsetManager;
        mStatusBarNotifier = statusBarNotifier;
        mAudioServiceFactory = audioServiceFactory;
        mInterruptionFilterProxy = interruptionFilterProxy;
        // Register for misc other intent broadcasts.
        IntentFilter intentFilter =
                new IntentFilter(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
        context.registerReceiver(mReceiver, intentFilter);
        mDoesDeviceSupportEarpieceRoute = doesDeviceSupportEarpieceRoute;
        mLock = callsManager.getLock();

@@ -1259,6 +1327,49 @@ public class CallAudioRouteStateMachine extends StateMachine {
        return mBluetoothRouteManager.isBluetoothAvailable();
    }

    /**
     * Sets whether notifications should be suppressed or not.  Used when in a call to ensure the
     * device will not vibrate due to notifications.
     * Alarm-only filtering is activated when
     *
     * @param on {@code true} when notification suppression should be activated, {@code false} when
     *                       it should be deactivated.
     */
    private void setNotificationsSuppressed(boolean on) {
        if (mInterruptionFilterProxy == null) {
            return;
        }

        Log.i(this, "setNotificationsSuppressed: on=%s; suppressed=%s", (on ? "yes" : "no"),
                (mAreNotificationSuppressed ? "yes" : "no"));
        if (on) {
            if (!mAreNotificationSuppressed) {
                // Enabling suppression of notifications.
                int interruptionFilter = mInterruptionFilterProxy.getCurrentInterruptionFilter();
                if (interruptionFilter == NotificationManager.INTERRUPTION_FILTER_ALL) {
                    // No interruption filter is specified, so suppress notifications by setting the
                    // current filter to alarms-only.
                    mAreNotificationSuppressed = true;
                    mInterruptionFilterProxy.setInterruptionFilter(
                            NotificationManager.INTERRUPTION_FILTER_ALARMS);
                } else {
                    // Interruption filter is already chosen by the user, so do not attempt to change
                    // it.
                    mAreNotificationSuppressed = false;
                }
            }
        } else {
            // Disabling suppression of notifications.
            if (mAreNotificationSuppressed) {
                // We have implemented the alarms-only policy and the user has not changed it since
                // we originally set it, so reset the notification filter.
                mInterruptionFilterProxy.setInterruptionFilter(
                        NotificationManager.INTERRUPTION_FILTER_ALL);
            }
            mAreNotificationSuppressed = false;
        }
    }

    private void setSpeakerphoneOn(boolean on) {
        if (mAudioManager.isSpeakerphoneOn() != on) {
            Log.i(this, "turning speaker phone %s", on);
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.telecom;

import android.app.ActivityManager;
import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.UserInfo;
import android.content.Intent;
@@ -250,6 +251,7 @@ public class CallsManager extends Call.ListenerBase
    private final DefaultDialerCache mDefaultDialerCache;
    private final Timeouts.Adapter mTimeoutsAdapter;
    private final PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter;
    private final NotificationManager mNotificationManager;
    private final Set<Call> mLocallyDisconnectingCalls = new HashSet<>();
    private final Set<Call> mPendingCallsToDisconnect = new HashSet<>();
    /* Handler tied to thread in which CallManager was initialized. */
@@ -298,6 +300,7 @@ public class CallsManager extends Call.ListenerBase
            Timeouts.Adapter timeoutsAdapter,
            AsyncRingtonePlayer asyncRingtonePlayer,
            PhoneNumberUtilsAdapter phoneNumberUtilsAdapter,
            InterruptionFilterProxy interruptionFilterProxy,
            EmergencyCallHelper emergencyCallHelper) {
        mContext = context;
        mLock = lock;
@@ -319,6 +322,8 @@ public class CallsManager extends Call.ListenerBase

        mDtmfLocalTonePlayer =
                new DtmfLocalTonePlayer(new DtmfLocalTonePlayer.ToneGeneratorProxy());
        mNotificationManager = (NotificationManager) context.getSystemService(
                Context.NOTIFICATION_SERVICE);
        CallAudioRouteStateMachine callAudioRouteStateMachine = new CallAudioRouteStateMachine(
                context,
                this,
@@ -326,6 +331,7 @@ public class CallsManager extends Call.ListenerBase
                wiredHeadsetManager,
                statusBarNotifier,
                audioServiceFactory,
                interruptionFilterProxy,
                CallAudioRouteStateMachine.doesDeviceSupportEarpieceRoute()
        );
        callAudioRouteStateMachine.initialize();
+2 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ public class TelecomSystem {
            Timeouts.Adapter timeoutsAdapter,
            AsyncRingtonePlayer asyncRingtonePlayer,
            PhoneNumberUtilsAdapter phoneNumberUtilsAdapter,
            InterruptionFilterProxy interruptionFilterProxy,
            IncomingCallNotifier incomingCallNotifier) {
        mContext = context.getApplicationContext();
        LogUtils.initLogging(mContext);
@@ -253,6 +254,7 @@ public class TelecomSystem {
                timeoutsAdapter,
                asyncRingtonePlayer,
                phoneNumberUtilsAdapter,
                interruptionFilterProxy,
                emergencyCallHelper);

        mIncomingCallNotifier = incomingCallNotifier;
+27 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.telecom.components;

import android.app.NotificationManager;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
@@ -24,7 +25,9 @@ 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 android.telecom.PhoneAccountHandle;

import com.android.internal.telephony.CallerInfoAsyncQuery;
import com.android.server.telecom.AsyncRingtonePlayer;
@@ -37,6 +40,7 @@ import com.android.server.telecom.HeadsetMediaButton;
import com.android.server.telecom.HeadsetMediaButtonFactory;
import com.android.server.telecom.InCallWakeLockControllerFactory;
import com.android.server.telecom.CallAudioManager;
import com.android.server.telecom.InterruptionFilterProxy;
import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
import com.android.server.telecom.ProximitySensorManagerFactory;
@@ -75,6 +79,9 @@ public class TelecomService extends Service implements TelecomSystem.Component {
     */
    static void initializeTelecomSystem(Context context) {
        if (TelecomSystem.getInstance() == null) {
            final NotificationManager notificationManager =
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

            NotificationChannelManager notificationChannelManager =
                    new NotificationChannelManager();
            notificationChannelManager.createChannels(context);
@@ -158,6 +165,26 @@ public class TelecomService extends Service implements TelecomSystem.Component {
                            new Timeouts.Adapter(),
                            new AsyncRingtonePlayer(),
                            new PhoneNumberUtilsAdapterImpl(),
                            new InterruptionFilterProxy() {
                                @Override
                                public void setInterruptionFilter(int interruptionFilter) {
                                    notificationManager.setInterruptionFilter(interruptionFilter);
                                }

                                @Override
                                public int getCurrentInterruptionFilter() {
                                    return notificationManager.getCurrentInterruptionFilter();
                                }

                                @Override
                                public String getInterruptionModeInitiator() {
                                    ZenModeConfig config = notificationManager.getZenModeConfig();
                                    if (config.manualRule != null) {
                                        return config.manualRule.enabler;
                                    }
                                    return null;
                                }
                            },
                            new IncomingCallNotifier(context)
                    ));
        }
Loading