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

Commit 809f4336 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Suppress ringtone when the device is on ear

am: 5cfe2afa

Change-Id: I233dcbaad959e4c86b96d0e648280734c5013a8f
parents c469e854 5cfe2afa
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -60,4 +60,13 @@
         between repeats of the ringtone.
         When false, the ringtone will be looping with no pause. -->
    <bool name="should_pause_between_ringtone_repeats">true</bool>

    <!-- Threshold for the X+Y component of gravity needed for the device orientation to be
         classified as being on a user's ear. -->
    <item name="device_on_ear_xy_gravity_threshold" format="float" type="dimen">5.5</item>

    <!-- Lower threshold for the Y-component of gravity needed for the device orientation to be
         classified as being on a user's ear. If the Y-component is less than this negative value,
         the device is probably upside-down and therefore not on a ear -->
    <item name="device_on_ear_y_gravity_negative_threshold" format="float" type="dimen">-1</item>
</resources>
+2 −2
Original line number Diff line number Diff line
@@ -446,9 +446,9 @@ public class CallAudioManager extends CallsManagerListenerBase {
    }

    @VisibleForTesting
    public void startCallWaiting() {
    public void startCallWaiting(String reason) {
        if (mRingingCalls.size() == 1) {
            mRinger.startCallWaiting(mRingingCalls.iterator().next());
            mRinger.startCallWaiting(mRingingCalls.iterator().next(), reason);
        }
    }

+17 −7
Original line number Diff line number Diff line
@@ -30,8 +30,9 @@ import com.android.internal.util.StateMachine;

public class CallAudioModeStateMachine extends StateMachine {
    public static class Factory {
        public CallAudioModeStateMachine create(AudioManager am) {
            return new CallAudioModeStateMachine(am);
        public CallAudioModeStateMachine create(SystemStateHelper systemStateHelper,
                AudioManager am) {
            return new CallAudioModeStateMachine(systemStateHelper, am);
        }
    }

@@ -333,7 +334,7 @@ public class CallAudioModeStateMachine extends StateMachine {
                    return HANDLED;
                case NEW_RINGING_CALL:
                    // Don't make a call ring over an active call, but do play a call waiting tone.
                    mCallAudioManager.startCallWaiting();
                    mCallAudioManager.startCallWaiting("call already active");
                    return HANDLED;
                case NEW_HOLDING_CALL:
                    // Don't do anything now. Putting an active call on hold will be handled when
@@ -388,7 +389,7 @@ public class CallAudioModeStateMachine extends StateMachine {
                    return HANDLED;
                case NEW_RINGING_CALL:
                    // Don't make a call ring over an active call, but do play a call waiting tone.
                    mCallAudioManager.startCallWaiting();
                    mCallAudioManager.startCallWaiting("call already active");
                    return HANDLED;
                case NEW_HOLDING_CALL:
                    // Don't do anything now. Putting an active call on hold will be handled when
@@ -442,8 +443,14 @@ public class CallAudioModeStateMachine extends StateMachine {
                            ? mVoipCallFocusState : mSimCallFocusState);
                    return HANDLED;
                case NEW_RINGING_CALL:
                    // Apparently this is current behavior. Should this be the case?
                    // TODO: consider whether to move this into MessageArgs if more things start
                    // to use it.
                    if (args.hasHoldingCalls && mSystemStateHelper.isDeviceAtEar()) {
                        mCallAudioManager.startCallWaiting(
                                "Device is at ear with held call");
                    } else {
                        transitionTo(mRingingFocusState);
                    }
                    return HANDLED;
                case NEW_HOLDING_CALL:
                    // Do nothing.
@@ -470,14 +477,17 @@ public class CallAudioModeStateMachine extends StateMachine {
    private final BaseState mOtherFocusState = new OtherFocusState();

    private final AudioManager mAudioManager;
    private final SystemStateHelper mSystemStateHelper;
    private CallAudioManager mCallAudioManager;

    private int mMostRecentMode;
    private boolean mIsInitialized = false;

    public CallAudioModeStateMachine(AudioManager audioManager) {
    public CallAudioModeStateMachine(SystemStateHelper systemStateHelper,
            AudioManager audioManager) {
        super(CallAudioModeStateMachine.class.getSimpleName());
        mAudioManager = audioManager;
        mSystemStateHelper = systemStateHelper;
        mMostRecentMode = AudioManager.MODE_NORMAL;

        addState(mUnfocusedState);
+4 −4
Original line number Diff line number Diff line
@@ -360,7 +360,7 @@ public class CallsManager extends Call.ListenerBase
            CallAudioManager.AudioServiceFactory audioServiceFactory,
            BluetoothRouteManager bluetoothManager,
            WiredHeadsetManager wiredHeadsetManager,
            SystemStateProvider systemStateProvider,
            SystemStateHelper systemStateHelper,
            DefaultDialerCache defaultDialerCache,
            Timeouts.Adapter timeoutsAdapter,
            AsyncRingtonePlayer asyncRingtonePlayer,
@@ -422,7 +422,7 @@ public class CallsManager extends Call.ListenerBase
        RingtoneFactory ringtoneFactory = new RingtoneFactory(this, context);
        SystemVibrator systemVibrator = new SystemVibrator(context);
        mInCallController = inCallControllerFactory.create(context, mLock, this,
                systemStateProvider, defaultDialerCache, mTimeoutsAdapter,
                systemStateHelper, defaultDialerCache, mTimeoutsAdapter,
                emergencyCallHelper);
        mRinger = new Ringer(playerFactory, context, systemSettingsUtil, asyncRingtonePlayer,
                ringtoneFactory, systemVibrator,
@@ -430,8 +430,8 @@ public class CallsManager extends Call.ListenerBase
        mCallRecordingTonePlayer = new CallRecordingTonePlayer(mContext,
                (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE), mLock);
        mCallAudioManager = new CallAudioManager(callAudioRouteStateMachine,
                this, callAudioModeStateMachineFactory.create((AudioManager)
                        mContext.getSystemService(Context.AUDIO_SERVICE)),
                this, callAudioModeStateMachineFactory.create(systemStateHelper,
                (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)),
                playerFactory, mRinger, new RingbackPlayer(playerFactory),
                bluetoothStateReceiver, mDtmfLocalTonePlayer);

+6 −6
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ import com.android.internal.annotations.VisibleForTesting;
// TODO: Needed for move to system service: import com.android.internal.R;
import com.android.internal.telecom.IInCallService;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.telecom.SystemStateProvider.SystemStateListener;
import com.android.server.telecom.SystemStateHelper.SystemStateListener;

import java.util.ArrayList;
import java.util.Collection;
@@ -729,7 +729,7 @@ public class InCallController extends CallsManagerListenerBase {
    private final Context mContext;
    private final TelecomSystem.SyncRoot mLock;
    private final CallsManager mCallsManager;
    private final SystemStateProvider mSystemStateProvider;
    private final SystemStateHelper mSystemStateHelper;
    private final Timeouts.Adapter mTimeoutsAdapter;
    private final DefaultDialerCache mDefaultDialerCache;
    private final EmergencyCallHelper mEmergencyCallHelper;
@@ -737,13 +737,13 @@ public class InCallController extends CallsManagerListenerBase {
    private NonUIInCallServiceConnectionCollection mNonUIInCallServiceConnections;

    public InCallController(Context context, TelecomSystem.SyncRoot lock, CallsManager callsManager,
            SystemStateProvider systemStateProvider,
            SystemStateHelper systemStateHelper,
            DefaultDialerCache defaultDialerCache, Timeouts.Adapter timeoutsAdapter,
            EmergencyCallHelper emergencyCallHelper) {
        mContext = context;
        mLock = lock;
        mCallsManager = callsManager;
        mSystemStateProvider = systemStateProvider;
        mSystemStateHelper = systemStateHelper;
        mTimeoutsAdapter = timeoutsAdapter;
        mDefaultDialerCache = defaultDialerCache;
        mEmergencyCallHelper = emergencyCallHelper;
@@ -753,7 +753,7 @@ public class InCallController extends CallsManagerListenerBase {
                resources.getString(R.string.ui_default_package),
                resources.getString(R.string.incall_default_class));

        mSystemStateProvider.addListener(mSystemStateListener);
        mSystemStateHelper.addListener(mSystemStateListener);
    }

    @Override
@@ -1227,7 +1227,7 @@ public class InCallController extends CallsManagerListenerBase {
    }

    private boolean shouldUseCarModeUI() {
        return mSystemStateProvider.isCarMode();
        return mSystemStateHelper.isCarMode();
    }

    /**
Loading