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

Commit 2303698c authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Android (Google) Code Review
Browse files

Merge "Update Vibration XML Parser API name" into main

parents 95137e48 24ccf632
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.UserManager;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.os.vibrator.persistence.ParsedVibration;
import android.os.vibrator.persistence.VibrationXmlParser;
import android.telecom.Log;
import android.telecom.TelecomManager;
@@ -779,14 +780,20 @@ public class Ringer {
    }

    @Nullable
    private static VibrationEffect loadSerializedDefaultRingVibration(Resources resources) {

    private static VibrationEffect loadSerializedDefaultRingVibration(
            Resources resources, Vibrator vibrator) {
        try {
            InputStream vibrationInputStream =
                    resources.openRawResource(
                            com.android.internal.R.raw.default_ringtone_vibration_effect);
            return VibrationXmlParser.parse(
            ParsedVibration parsedVibration = VibrationXmlParser
                    .parseDocument(
                            new InputStreamReader(vibrationInputStream, StandardCharsets.UTF_8));
            if (parsedVibration == null) {
                Log.w(TAG, "Got null parsed default ring vibration effect.");
                return null;
            }
            return parsedVibration.resolve(vibrator);
        } catch (IOException | Resources.NotFoundException e) {
            Log.e(TAG, e, "Error parsing default ring vibration effect.");
            return null;
@@ -806,8 +813,8 @@ public class Ringer {
        }

        if (featureFlags.useDeviceProvidedSerializedRingerVibration()) {
            VibrationEffect parsedEffect = loadSerializedDefaultRingVibration(resources);
            if (parsedEffect != null && vibrator.areVibrationFeaturesSupported(parsedEffect)) {
            VibrationEffect parsedEffect = loadSerializedDefaultRingVibration(resources, vibrator);
            if (parsedEffect != null) {
                Log.i(TAG, "Using parsed default ring vibration.");
                // Make the parsed effect repeating to make it vibrate continuously during ring.
                // If the effect is already repeating, this API call is a no-op.
+10 −7
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.vibrator.persistence.VibrationXmlParser;
import android.os.Vibrator;
import android.os.VibratorInfo;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.telecom.PhoneAccountHandle;
@@ -109,6 +110,7 @@ public class RingerTest extends TelecomTestCase {
    @Mock SystemSettingsUtil mockSystemSettingsUtil;
    @Mock RingtoneFactory mockRingtoneFactory;
    @Mock Vibrator mockVibrator;
    @Mock VibratorInfo mockVibratorInfo;
    @Mock InCallController mockInCallController;
    @Mock NotificationManager mockNotificationManager;
    @Mock Ringer.AccessibilityManagerAdapter mockAccessibilityManagerAdapter;
@@ -139,6 +141,7 @@ public class RingerTest extends TelecomTestCase {
        when(mockPlayerFactory.createPlayer(anyInt())).thenReturn(mockTonePlayer);
        mockAudioManager = mContext.getSystemService(AudioManager.class);
        when(mockAudioManager.getRingerMode()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
        when(mockVibrator.getInfo()).thenReturn(mockVibratorInfo);
        when(mockSystemSettingsUtil.isHapticPlaybackSupported(any(Context.class)))
                .thenAnswer((invocation) -> mIsHapticPlaybackSupported);
        mockNotificationManager =mContext.getSystemService(NotificationManager.class);
@@ -187,7 +190,7 @@ public class RingerTest extends TelecomTestCase {
                    </vibration>
                """,
                /* useSimpleVibration= */ true);
        when(mockVibrator.areVibrationFeaturesSupported(any())).thenReturn(true);
        when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);

        createRingerUnderTest();

@@ -212,7 +215,7 @@ public class RingerTest extends TelecomTestCase {
                    </vibration>
                """,
                /* useSimpleVibration= */ false);
        when(mockVibrator.areVibrationFeaturesSupported(any())).thenReturn(true);
        when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);

        createRingerUnderTest();

@@ -236,7 +239,7 @@ public class RingerTest extends TelecomTestCase {
                    </vibration>
                """,
                /* useSimpleVibration= */ false);
        when(mockVibrator.areVibrationFeaturesSupported(any())).thenReturn(true);
        when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);

        createRingerUnderTest();

@@ -256,7 +259,7 @@ public class RingerTest extends TelecomTestCase {
                    </vibration>
                """,
                /* useSimpleVibration= */ false);
        when(mockVibrator.areVibrationFeaturesSupported(any())).thenReturn(true);
        when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);

        createRingerUnderTest();

@@ -285,7 +288,7 @@ public class RingerTest extends TelecomTestCase {
                    </vibration>
                """,
                /* useSimpleVibration= */ false);
        when(mockVibrator.areVibrationFeaturesSupported(
        when(mockVibratorInfo.areVibrationFeaturesSupported(
                eq(VibrationEffect.createPredefined(EFFECT_CLICK)))).thenReturn(false);

        createRingerUnderTest();
@@ -300,7 +303,7 @@ public class RingerTest extends TelecomTestCase {
        mockVibrationResourceValues(
                /* defaultVibrationContent= */ "bad serialization",
                /* useSimpleVibration= */ false);
        when(mockVibrator.areVibrationFeaturesSupported(any())).thenReturn(true);
        when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);

        createRingerUnderTest();

@@ -313,7 +316,7 @@ public class RingerTest extends TelecomTestCase {
        when(mFeatureFlags.useDeviceProvidedSerializedRingerVibration()).thenReturn(true);
        mockVibrationResourceValues(
                /* defaultVibrationContent= */ "", /* useSimpleVibration= */ false);
        when(mockVibrator.areVibrationFeaturesSupported(any())).thenReturn(true);
        when(mockVibratorInfo.areVibrationFeaturesSupported(any())).thenReturn(true);

        createRingerUnderTest();