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

Commit 77f8ec25 authored by Wilson Wu's avatar Wilson Wu Committed by Android (Google) Code Review
Browse files

Merge "Refine the haptic channel mute condition" into main

parents 64f03b74 fa1ef406
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * RingtoneManager provides access to ringtones, notification, and other types
@@ -810,9 +811,7 @@ public class RingtoneManager {
        // Don't set the stream type
        Ringtone ringtone = getRingtone(context, ringtoneUri, -1 /* streamType */,
                volumeShaperConfig, false);
        if (Flags.enableRingtoneHapticsCustomization()
                && Utils.isRingtoneVibrationSettingsSupported(context)
                && Utils.hasVibration(ringtoneUri) && hasHapticChannels(ringtoneUri)) {
        if (muteHapticChannelForVibration(context, ringtoneUri)) {
            audioAttributes = new AudioAttributes.Builder(
                    audioAttributes).setHapticChannelsMuted(true).build();
        }
@@ -1305,4 +1304,19 @@ public class RingtoneManager {
            default: throw new IllegalArgumentException();
        }
    }

    private static boolean muteHapticChannelForVibration(Context context, Uri ringtoneUri) {
        final Uri vibrationUri = Utils.getVibrationUri(ringtoneUri);
        // No vibration is specified
        if (vibrationUri == null) {
            return false;
        }
        // The user specified the synchronized pattern
        if (Objects.equals(vibrationUri.toString(), Utils.SYNCHRONIZED_VIBRATION)) {
            return false;
        }
        return Flags.enableRingtoneHapticsCustomization()
                && Utils.isRingtoneVibrationSettingsSupported(context)
                && hasHapticChannels(ringtoneUri);
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public class Utils {

    public static final String VIBRATION_URI_PARAM = "vibration_uri";

    public static final String SYNCHRONIZED_VIBRATION = "synchronized";

    /**
     * Sorts distinct (non-intersecting) range array in ascending order.
     * @throws java.lang.IllegalArgumentException if ranges are not distinct
@@ -757,8 +759,8 @@ public class Utils {
            return null;
        }
        String filePath = vibrationUri.getPath();
        if (filePath == null) {
            Log.w(TAG, "The file path is null.");
        if (filePath == null || filePath.equals(Utils.SYNCHRONIZED_VIBRATION)) {
            Log.w(TAG, "Ignore the vibration parsing for file:" + filePath);
            return null;
        }
        File vibrationFile = new File(filePath);