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

Commit 6a356199 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Gerrit Code Review
Browse files

Merge "leaudio: Allow to disable inband ringtone"

parents ea976048 5fad8228
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public class LeAudioService extends ProfileService {

    LeAudioNativeInterface mLeAudioNativeInterface;
    boolean mLeAudioNativeIsInitialized = false;
    boolean mLeAudioInbandRingtoneSupportedByPlatform = true;
    boolean mBluetoothEnabled = false;
    BluetoothDevice mHfpHandoverDevice = null;
    LeAudioBroadcasterNativeInterface mLeAudioBroadcasterNativeInterface = null;
@@ -2009,6 +2010,17 @@ public class LeAudioService extends ProfileService {
        return descriptor.mSinkAudioLocation;
    }

    /**
     * Check if inband ringtone is enabled by the LE Audio group.
     * Group id for the device can be found with {@link BluetoothLeAudio#getGroupId}.
     * @param groupId LE Audio group id
     * @return true if inband ringtone is enabled, false otherwise
     */
    public boolean isInbandRingtoneEnabled(int groupId) {
        /* TODO Take into account device available context type */
        return mLeAudioInbandRingtoneSupportedByPlatform;
    }

    /**
     * Set In Call state
     * @param inCall True if device in call (any state), false otherwise.
@@ -2806,6 +2818,25 @@ public class LeAudioService extends ProfileService {
            }
        }

        @Override
        public void isInbandRingtoneEnabled(AttributionSource source,
                SynchronousResultReceiver receiver, int groupId) {
            try {
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                LeAudioService service = getService(source);
                boolean result = false;
                if (service != null) {
                    enforceBluetoothPrivilegedPermission(service);
                    result = service.isInbandRingtoneEnabled(groupId);
                }
                receiver.send(result);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
        public void setConnectionPolicy(BluetoothDevice device, int connectionPolicy,
                AttributionSource source, SynchronousResultReceiver receiver) {
+1 −0
Original line number Diff line number Diff line
@@ -405,6 +405,7 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getAudioLocation(@NonNull android.bluetooth.BluetoothDevice);
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public android.bluetooth.BluetoothLeAudioCodecStatus getCodecStatus(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean isInbandRingtoneEnabled(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothLeAudio.Callback);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setCodecConfigPreference(int, @NonNull android.bluetooth.BluetoothLeAudioCodecConfig, @NonNull android.bluetooth.BluetoothLeAudioCodecConfig);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
+37 −0
Original line number Diff line number Diff line
@@ -1266,6 +1266,43 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
        return defaultLocation;
    }

    /**
     * Check if inband ringtone is enabled by the LE Audio group.
     * Group id for the device can be found with  {@link BluetoothLeAudio#getGroupId}.
     *
     * @param groupId LE Audio group id
     * @return {@code true} if inband ringtone is enabled, {@code false} otherwise
     * @hide
     */
    @RequiresPermission(allOf = {android.Manifest.permission.BLUETOOTH_CONNECT,
                                android.Manifest.permission.BLUETOOTH_PRIVILEGED})
    @SystemApi
    public boolean isInbandRingtoneEnabled(int groupId) {
        if (VDBG) {
            log("isInbandRingtoneEnabled(), groupId: " + groupId);
        }
        final IBluetoothLeAudio service = getService();
        final boolean defaultValue = false;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) {
                log(Log.getStackTraceString(new Throwable()));
            }
        } else if (mAdapter.isEnabled()) {
            try {
                final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get();
                service.isInbandRingtoneEnabled(mAttributionSource, recv, groupId);
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
            } catch (TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                e.rethrowFromSystemServer();
            }
        }
        return defaultValue;
    }

    /**
     * Set connection policy of the profile
     *
+2 −0
Original line number Diff line number Diff line
@@ -94,6 +94,8 @@ oneway interface IBluetoothLeAudio {
    void groupRemoveNode(int group_id, in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void getAudioLocation(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void isInbandRingtoneEnabled(in AttributionSource attributionSource, in SynchronousResultReceiver receiver, int groupId);

    // Broadcaster API
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")