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

Commit 6c42faf0 authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Pipe down preferred audio profiles to the native layer

Bug: 265077412
Test: Manual
Change-Id: I6f490e16f2141740f5d78bd19d073b4dfd088172
parent 120a65d0
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -542,6 +542,19 @@ static void setInCallNative(JNIEnv* env, jobject object, jboolean inCall) {
  sLeAudioClientInterface->SetInCall(inCall);
}

static void sendAudioProfilePreferencesNative(
    JNIEnv* env, jint groupId, jboolean isOutputPreferenceLeAudio,
    jboolean isDuplexPreferenceLeAudio) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sLeAudioClientInterface) {
    LOG(ERROR) << __func__ << ": Failed to get the Bluetooth LeAudio Interface";
    return;
  }

  sLeAudioClientInterface->SendAudioProfilePreferences(
      groupId, isOutputPreferenceLeAudio, isDuplexPreferenceLeAudio);
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "([Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
@@ -558,6 +571,8 @@ static JNINativeMethod sMethods[] = {
     (void*)setCodecConfigPreferenceNative},
    {"setCcidInformationNative", "(II)V", (void*)setCcidInformationNative},
    {"setInCallNative", "(Z)V", (void*)setInCallNative},
    {"sendAudioProfilePreferencesNative", "(IZZ)V",
     (void*)sendAudioProfilePreferencesNative},
};

/* Le Audio Broadcaster */
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public final class Utils {
    private static final String ENABLE_DUAL_MODE_AUDIO =
            "persist.bluetooth.enable_dual_mode_audio";
    private static boolean sDualModeEnabled =
            SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false);;
            SystemProperties.getBoolean(ENABLE_DUAL_MODE_AUDIO, false);

    private static final String KEY_TEMP_ALLOW_LIST_DURATION_MS = "temp_allow_list_duration_ms";
    private static final long DEFAULT_TEMP_ALLOW_LIST_DURATION_MS = 20_000;
+15 −0
Original line number Diff line number Diff line
@@ -4959,6 +4959,21 @@ public class AdapterService extends Service {
                return dbResult;
            }

            int outputOnlyPreference = strippedPreferences.getInt(
                    BluetoothAdapter.AUDIO_MODE_OUTPUT_ONLY);
            if (outputOnlyPreference == 0) {
                outputOnlyPreference = previousPreferences.getInt(
                        BluetoothAdapter.AUDIO_MODE_OUTPUT_ONLY);
            }
            int duplexPreference = strippedPreferences.getInt(BluetoothAdapter.AUDIO_MODE_DUPLEX);
            if (duplexPreference == 0) {
                duplexPreference = previousPreferences.getInt(BluetoothAdapter.AUDIO_MODE_DUPLEX);
            }

            mLeAudioService.sendAudioProfilePreferencesToNative(groupId,
                    outputOnlyPreference == BluetoothProfile.LE_AUDIO,
                    duplexPreference == BluetoothProfile.LE_AUDIO);

            /* Populates the HashMap to hold requests on the groupId. We will update
            numRequestsToAudioFramework after we make requests to the audio framework */
            PendingAudioProfilePreferenceRequest holdRequest =
+21 −0
Original line number Diff line number Diff line
@@ -316,6 +316,24 @@ public class LeAudioNativeInterface {
        setInCallNative(inCall);
    }

    /**
     * Sends the audio preferences for the groupId to the native stack.
     *
     * @param groupId is the groupId corresponding to the preferences
     * @param isOutputPreferenceLeAudio whether LEA is preferred for OUTPUT_ONLY
     * @param isDuplexPreferenceLeAudio whether LEA is preferred for DUPLEX
     */
    public void sendAudioProfilePreferences(int groupId, boolean isOutputPreferenceLeAudio,
            boolean isDuplexPreferenceLeAudio) {
        if (DBG) {
            Log.d(TAG, "sendAudioProfilePreferences groupId=" + groupId
                    + ", isOutputPreferenceLeAudio=" + isOutputPreferenceLeAudio
                    + ", isDuplexPreferenceLeAudio=" + isDuplexPreferenceLeAudio);
        }
        sendAudioProfilePreferencesNative(groupId, isOutputPreferenceLeAudio,
                isDuplexPreferenceLeAudio);
    }

    // Native methods that call into the JNI interface
    private static native void classInitNative();
    private native void initNative(BluetoothLeAudioCodecConfig[] codecConfigOffloading);
@@ -330,4 +348,7 @@ public class LeAudioNativeInterface {
            BluetoothLeAudioCodecConfig outputCodecConfig);
    private native void setCcidInformationNative(int ccid, int contextType);
    private native void setInCallNative(boolean inCall);
    /*package*/
    private native void sendAudioProfilePreferencesNative(int groupId,
            boolean isOutputPreferenceLeAudio, boolean isDuplexPreferenceLeAudio);
}
+21 −0
Original line number Diff line number Diff line
@@ -2222,6 +2222,27 @@ public class LeAudioService extends ProfileService {
        mLeAudioNativeInterface.setInCall(inCall);
    }

    /**
     * Sends the preferred audio profiles for a dual mode audio device to the native stack.
     *
     * @param groupId is the group id of the device which had a preference change
     * @param isOutputPreferenceLeAudio {@code true} if {@link BluetoothProfile#LE_AUDIO} is
     * preferred for {@link BluetoothAdapter#AUDIO_MODE_OUTPUT_ONLY}, {@code false} if it is
     * {@link BluetoothProfile#A2DP}
     * @param isDuplexPreferenceLeAudio {@code true} if {@link BluetoothProfile#LE_AUDIO} is
     * preferred for {@link BluetoothAdapter#AUDIO_MODE_DUPLEX}, {@code false} if it is
     * {@link BluetoothProfile#HEADSET}
     */
    public void sendAudioProfilePreferencesToNative(int groupId, boolean isOutputPreferenceLeAudio,
            boolean isDuplexPreferenceLeAudio) {
        if (!mLeAudioNativeIsInitialized) {
            Log.e(TAG, "Le Audio not initialized properly.");
            return;
        }
        mLeAudioNativeInterface.sendAudioProfilePreferences(groupId, isOutputPreferenceLeAudio,
                isDuplexPreferenceLeAudio);
    }

    /**
     * Set Inactive by HFP during handover
     */
Loading