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

Commit dd45d829 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "Add master audio balance"

parents 2929e7c7 35c292f5
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -3535,6 +3535,16 @@ public final class Settings {
        private static final Validator MASTER_MONO_VALIDATOR = BOOLEAN_VALIDATOR;
        /**
         * Master balance (float -1.f = 100% left, 0.f = dead center, 1.f = 100% right).
         *
         * @hide
         */
        public static final String MASTER_BALANCE = "master_balance";
        private static final Validator MASTER_BALANCE_VALIDATOR =
                new SettingsValidators.InclusiveFloatRangeValidator(-1.f, 1.f);
        /**
         * Whether the notifications should use the ring volume (value of 1) or
         * a separate notification volume (value of 0). In most cases, users
@@ -4288,6 +4298,7 @@ public final class Settings {
            HEARING_AID,
            TTY_MODE,
            MASTER_MONO,
            MASTER_BALANCE,
            SOUND_EFFECTS_ENABLED,
            HAPTIC_FEEDBACK_ENABLED,
            POWER_SOUNDS_ENABLED,       // moved to global
@@ -4395,6 +4406,7 @@ public final class Settings {
            PRIVATE_SETTINGS.add(VIBRATE_INPUT_DEVICES);
            PRIVATE_SETTINGS.add(VOLUME_MASTER);
            PRIVATE_SETTINGS.add(MASTER_MONO);
            PRIVATE_SETTINGS.add(MASTER_BALANCE);
            PRIVATE_SETTINGS.add(NOTIFICATIONS_USE_RING_VOLUME);
            PRIVATE_SETTINGS.add(VIBRATE_IN_SILENT);
            PRIVATE_SETTINGS.add(MEDIA_BUTTON_RECEIVER);
@@ -4488,6 +4500,7 @@ public final class Settings {
            VALIDATORS.put(SCREEN_AUTO_BRIGHTNESS_ADJ, SCREEN_AUTO_BRIGHTNESS_ADJ_VALIDATOR);
            VALIDATORS.put(VIBRATE_INPUT_DEVICES, VIBRATE_INPUT_DEVICES_VALIDATOR);
            VALIDATORS.put(MASTER_MONO, MASTER_MONO_VALIDATOR);
            VALIDATORS.put(MASTER_BALANCE, MASTER_BALANCE_VALIDATOR);
            VALIDATORS.put(NOTIFICATIONS_USE_RING_VOLUME, NOTIFICATIONS_USE_RING_VOLUME_VALIDATOR);
            VALIDATORS.put(VIBRATE_IN_SILENT, VIBRATE_IN_SILENT_VALIDATOR);
            VALIDATORS.put(MEDIA_BUTTON_RECEIVER, MEDIA_BUTTON_RECEIVER_VALIDATOR);
+20 −0
Original line number Diff line number Diff line
@@ -620,6 +620,24 @@ android_media_AudioSystem_getMasterMono(JNIEnv *env, jobject thiz)
    return mono;
}

static jint
android_media_AudioSystem_setMasterBalance(JNIEnv *env, jobject thiz, jfloat balance)
{
    return (jint) check_AudioSystem_Command(AudioSystem::setMasterBalance(balance));
}

static jfloat
android_media_AudioSystem_getMasterBalance(JNIEnv *env, jobject thiz)
{
    float balance;
    const status_t status = AudioSystem::getMasterBalance(&balance);
    if (status != NO_ERROR) {
        ALOGW("%s getMasterBalance error %d, returning 0.f, audioserver down?", __func__, status);
        balance = 0.f;
    }
    return balance;
}

static jint
android_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint stream)
{
@@ -2160,6 +2178,8 @@ static const JNINativeMethod gMethods[] = {
    {"getMasterMute",       "()Z",      (void *)android_media_AudioSystem_getMasterMute},
    {"setMasterMono",       "(Z)I",     (void *)android_media_AudioSystem_setMasterMono},
    {"getMasterMono",       "()Z",      (void *)android_media_AudioSystem_getMasterMono},
    {"setMasterBalance",    "(F)I",     (void *)android_media_AudioSystem_setMasterBalance},
    {"getMasterBalance",    "()F",      (void *)android_media_AudioSystem_getMasterBalance},
    {"getDevicesForStream", "(I)I",     (void *)android_media_AudioSystem_getDevicesForStream},
    {"getPrimaryOutputSamplingRate", "()I", (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
    {"getPrimaryOutputFrameCount",   "()I", (void *)android_media_AudioSystem_getPrimaryOutputFrameCount},
+2 −0
Original line number Diff line number Diff line
@@ -232,6 +232,8 @@ message SystemSettingsProto {
        // Which streams are affected by mute. The stream type's bit should be set
        // to 1 if it should be muted when a mute request is received.
        optional SettingProto mute_streams_affected = 12 [ (android.privacy).dest = DEST_AUTOMATIC ];
        // Master balance (float -1.f = 100% left, 0.f = dead center, 1.f = 100% right).
        optional SettingProto master_balance = 13 [ (android.privacy).dest = DEST_AUTOMATIC ];
    }
    optional Volume volume = 33;

+1 −0
Original line number Diff line number Diff line
@@ -274,6 +274,7 @@
    <protected-broadcast android:name="android.media.MASTER_VOLUME_CHANGED_ACTION" />
    <protected-broadcast android:name="android.media.MASTER_MUTE_CHANGED_ACTION" />
    <protected-broadcast android:name="android.media.MASTER_MONO_CHANGED_ACTION" />
    <protected-broadcast android:name="android.media.MASTER_BALANCE_CHANGED_ACTION" />
    <protected-broadcast android:name="android.media.SCO_AUDIO_STATE_CHANGED" />
    <protected-broadcast android:name="android.media.ACTION_SCO_AUDIO_STATE_UPDATED" />

+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.media;

import android.annotation.NonNull;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.bluetooth.BluetoothCodecConfig;
import android.content.Context;
@@ -933,6 +934,13 @@ public class AudioSystem
    /** @hide enables or disables the master mono mode. */
    public static native int setMasterMono(boolean mono);

    /** @hide returns master balance value in range -1.f -> 1.f, where 0.f is dead center. */
    @TestApi
    public static native float getMasterBalance();
    /** @hide changes the audio balance of the device. */
    @TestApi
    public static native int setMasterBalance(float balance);

    // helpers for android.media.AudioManager.getProperty(), see description there for meaning
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 112561552)
    public static native int getPrimaryOutputSamplingRate();
Loading