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

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

Merge "Check if the uri is opaque when createVibrationEffectFromSoundUri and...

Merge "Check if the uri is opaque when createVibrationEffectFromSoundUri and catch exceptions to avoid other failed cases" into main
parents 33e71f72 561d7591
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -218,10 +218,16 @@ public final class VibratorHelper {
     * @param uri {@code Uri} an uri including query parameter "vibraiton_uri"
     */
    public @Nullable VibrationEffect createVibrationEffectFromSoundUri(Uri uri) {
        if (uri == null) {
        if (uri == null || uri.isOpaque()) {
            return null;
        }

        try {
            return Utils.parseVibrationEffect(mVibrator, Utils.getVibrationUri(uri));
        } catch (Exception e) {
            Slog.e(TAG, "Failed to get vibration effect: ", e);
        }
        return null;
    }

    /** Returns if a given vibration can be played by the vibrator that does notification buzz. */
+6 −0
Original line number Diff line number Diff line
@@ -103,6 +103,12 @@ public class VibratorHelperTest extends UiServiceTestCase {
        assertNull(mVibratorHelper.createVibrationEffectFromSoundUri(Uri.EMPTY));
    }

    @Test
    public void createVibrationEffectFromSoundUri_opaqueUri() {
        Uri uri = Uri.parse("a:b#c");
        assertNull(mVibratorHelper.createVibrationEffectFromSoundUri(uri));
    }

    @Test
    public void createVibrationEffectFromSoundUri_uriWithoutRequiredQueryParameter() {
        Uri uri = Settings.System.DEFAULT_NOTIFICATION_URI;