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

Commit 4578f93a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Simplify haptic-only ringtone logic" into main

parents 42bec0bb edec916b
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -415,17 +415,9 @@ public class Ringer {
                        isVibratorEnabled, mIsHapticPlaybackSupportedByDevice);
            }
            // Defer ringtone creation to the async player thread.
            Supplier<Pair<Uri, Ringtone>> ringtoneInfoSupplier;
            Supplier<Pair<Uri, Ringtone>> ringtoneInfoSupplier = null;
            final boolean finalHapticChannelsMuted = hapticChannelsMuted;
            if (isHapticOnly) {
                if (hapticChannelsMuted) {
                    Log.i(this,
                            "want haptic only ringtone but haptics are muted, skip ringtone play");
                    ringtoneInfoSupplier = null;
                } else {
                    ringtoneInfoSupplier = mRingtoneFactory::getHapticOnlyRingtone;
                }
            } else {
            if (!isHapticOnly) {
                ringtoneInfoSupplier = () -> mRingtoneFactory.getRingtone(
                        foregroundCall, mVolumeShaperConfig, finalHapticChannelsMuted);
            }
+0 −18
Original line number Diff line number Diff line
@@ -127,24 +127,6 @@ public class RingtoneFactory {
            .build();
    }

    /** Returns a ringtone to be used when ringer is not audible for the incoming call. */
    @Nullable
    public Pair<Uri, Ringtone> getHapticOnlyRingtone() {
        // Initializing ringtones on the main thread can deadlock
        ThreadUtil.checkNotOnMainThread();
        Uri ringtoneUri = Uri.parse("file://" + mContext.getString(
                com.android.internal.R.string.config_defaultRingtoneVibrationSound));
        AudioAttributes audioAttrs = getDefaultRingtoneAudioAttributes(
            /* hapticChannelsMuted */ false);
        Ringtone ringtone = RingtoneManager.getRingtone(
                mContext, ringtoneUri, /* volumeShaperConfig */ null, audioAttrs);
        if (ringtone != null) {
            // Make sure the sound is muted.
            ringtone.setVolume(0);
        }
        return new Pair(ringtoneUri, ringtone);
    }

    private Context getWorkProfileContextForUser(UserHandle userHandle) {
        // UserManager.getUserProfiles returns the enabled profiles along with the context user's
        // handle itself (so we must filter out the user).
+0 −31
Original line number Diff line number Diff line
@@ -475,10 +475,6 @@ public class RingerTest extends TelecomTestCase {
        // Ensure no audible ringtone is played:
        assertFalse(startRingingAndWaitForAsync(mockCall2, false));
        verify(mockTonePlayer).stopTone();
        // Ensure a silent haptics only ringtone is played:
        verify(mockRingtoneFactory, atLeastOnce()).getHapticOnlyRingtone();
        verifyNoMoreInteractions(mockRingtoneFactory);
        verify(mockRingtone).play();

        // Ensure a vibration plays:
        verify(mockVibrator).vibrate(any(VibrationEffect.class), any(VibrationAttributes.class));
@@ -523,10 +519,6 @@ public class RingerTest extends TelecomTestCase {
        enableVibrationWhenRinging();
        assertFalse(startRingingAndWaitForAsync(mockCall2, false));
        verify(mockTonePlayer).stopTone();
        // Try to play a silent haptics ringtone
        verify(mockRingtoneFactory, atLeastOnce()).getHapticOnlyRingtone();
        verifyNoMoreInteractions(mockRingtoneFactory);
        verify(mockRingtone).play();

        // Play default vibration when future completes with no audio coupled haptics
        verify(mockVibrator).vibrate(eq(mRingerUnderTest.mDefaultVibrationEffect),
@@ -551,28 +543,6 @@ public class RingerTest extends TelecomTestCase {
                any(VibrationAttributes.class));
    }

    @SmallTest
    @Test
    public void testAudioCoupledHapticsForSilentRingtone() throws Exception {
        Ringtone mockRingtone = ensureRingtoneMocked();

        mRingerUnderTest.startCallWaiting(mockCall1);
        when(mockAudioManager.getRingerMode()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
        when(mockAudioManager.getStreamVolume(AudioManager.STREAM_RING)).thenReturn(0);
        setIsUsingHaptics(mockRingtone, true);
        enableVibrationWhenRinging();
        assertFalse(startRingingAndWaitForAsync(mockCall2, false));

        verify(mockRingtoneFactory, atLeastOnce()).getHapticOnlyRingtone();
        verifyNoMoreInteractions(mockRingtoneFactory);
        verify(mockTonePlayer).stopTone();
        // Try to play a silent haptics ringtone
        verify(mockRingtone).play();
        // Skip vibration for audio coupled haptics
        verify(mockVibrator, never()).vibrate(any(VibrationEffect.class),
                any(VibrationAttributes.class));
    }

    @SmallTest
    @Test
    public void testCustomVibrationForRingtone() throws Exception {
@@ -886,7 +856,6 @@ public class RingerTest extends TelecomTestCase {
        when(mockRingtoneFactory.getRingtone(
                any(Call.class), nullable(VolumeShaper.Configuration.class), anyBoolean()))
                .thenReturn(ringtoneInfo);
        when(mockRingtoneFactory.getHapticOnlyRingtone()).thenReturn(ringtoneInfo);
        return mockRingtone;
    }