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

Commit f4dc8d89 authored by Vlad Popa's avatar Vlad Popa
Browse files

CSD: Add way to set csd value with adb shell cmd

Add command line tool that can be used to test the calculation of sound
dose. This can be used to trigger the warnings without waiting until the
entire dosage accumulated.

Test: adb shell cmd audio <new-commands>
Bug: 302740451
Change-Id: I948e4f926e5c044bd8fc376c6bf58f0482126fc4
parent 1e08e96e
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -47,6 +47,12 @@ class AudioManagerShellCommand extends ShellCommand {
                return setEncodedSurroundMode();
            case "get-encoded-surround-mode":
                return getEncodedSurroundMode();
            case "set-sound-dose-value":
                return setSoundDoseValue();
            case "get-sound-dose-value":
                return getSoundDoseValue();
            case "reset-sound-dose-timeout":
                return resetSoundDoseTimeout();
        }
        return 0;
    }
@@ -66,6 +72,12 @@ class AudioManagerShellCommand extends ShellCommand {
        pw.println("    Sets the encoded surround sound mode to SURROUND_SOUND_MODE");
        pw.println("  get-encoded-surround-mode");
        pw.println("    Returns the encoded surround sound mode");
        pw.println("  set-sound-dose-value");
        pw.println("    Sets the current sound dose value");
        pw.println("  get-sound-dose-value");
        pw.println("    Returns the current sound dose value");
        pw.println("  reset-sound-dose-timeout");
        pw.println("    Resets the sound dose timeout used for momentary exposure");
    }

    private int setSurroundFormatEnabled() {
@@ -162,4 +174,46 @@ class AudioManagerShellCommand extends ShellCommand {
        getOutPrintWriter().println("Encoded surround mode: " + am.getEncodedSurroundMode());
        return 0;
    }

    private int setSoundDoseValue() {
        String soundDoseValueText = getNextArg();

        if (soundDoseValueText == null) {
            getErrPrintWriter().println("Error: no sound dose value specified");
            return 1;
        }

        float soundDoseValue = 0.f;
        try {
            soundDoseValue = Float.parseFloat(soundDoseValueText);
        } catch (NumberFormatException e) {
            getErrPrintWriter().println("Error: wrong format specified for sound dose");
            return 1;
        }

        if (soundDoseValue < 0) {
            getErrPrintWriter().println("Error: invalid value of sound dose");
            return 1;
        }

        final Context context = mService.mContext;
        final AudioManager am = context.getSystemService(AudioManager.class);
        am.setCsd(soundDoseValue);
        return 0;
    }

    private int getSoundDoseValue() {
        final Context context = mService.mContext;
        final AudioManager am = context.getSystemService(AudioManager.class);
        getOutPrintWriter().println("Sound dose value: " + am.getCsd());
        return 0;
    }

    private int resetSoundDoseTimeout() {
        final Context context = mService.mContext;
        final AudioManager am = context.getSystemService(AudioManager.class);
        am.setCsd(-1.f);
        getOutPrintWriter().println("Reset sound dose momentary exposure timeout");
        return 0;
    }
}