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

Commit fa1ef406 authored by Wilson Wu's avatar Wilson Wu
Browse files

Refine the haptic channel mute condition

Adopt the haptics customization only if the user
choose a vibration in settings after OTA.

-. Not mute the haptic channel if the vibration uri
   is a explicit synchronized pattern.
-. Not parse the vibration effect for synchronized

Flag: android.media.audio.enable_ringtone_haptics_customization
Bug: 394231980
Test: atest RingtoneManagerTest
Test: atest Ringertest
Change-Id: I2736d05dc1f52506055fcc7bf31726be7b9db3cc
parent c10218e7
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);