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

Commit e3d7ba1f authored by Martin Brabham's avatar Martin Brabham Committed by Md Shahriar Hossain Sajib
Browse files

Bring back support for [get|set]AudioRouteAllowed()

Bug: 64586891
Bug: 36601991
Bug: 79683308
Bug: 199827901
Test: IOP and BCST
Tag: #feature

(Cherry picked from commit I44ab03b5802f8d6d061fa0d1bf61f10ffa3fed09)
(cherry picked from commit 2591d1eecfc0c21232b89b022ba7fa7c4afdcae4)
Change-Id: I62e15ecab1448a70291557d61e121c01859f85d0
parent fa973a92
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ import com.android.bluetooth.BluetoothMetricsProto;
public abstract class ProfileService extends Service {
    private static final boolean DBG = false;

    public static final String BLUETOOTH_PERM =
            android.Manifest.permission.BLUETOOTH;
    public static final String BLUETOOTH_PRIVILEGED =
            android.Manifest.permission.BLUETOOTH_PRIVILEGED;

+25 −6
Original line number Diff line number Diff line
@@ -359,19 +359,21 @@ public class HeadsetClientService extends ProfileService {
        public void setAudioRouteAllowed(BluetoothDevice device, boolean allowed,
                AttributionSource source) {
            HeadsetClientService service = getService(source);
            if (service == null) {
                return;
            if (service != null) {
                service.setAudioRouteAllowed(device, allowed);
            } else {
                Log.w(TAG, "Service handle is null for setAudioRouteAllowed!");
            }
            Log.e(TAG, "setAudioRouteAllowed API not supported");
        }

        @Override
        public boolean getAudioRouteAllowed(BluetoothDevice device, AttributionSource source) {
            HeadsetClientService service = getService(source);
            if (service == null) {
                return false;
            if (service != null) {
                return service.getAudioRouteAllowed(device);
            } else {
                Log.w(TAG, "Service handle is null for getAudioRouteAllowed!");
            }
            Log.e(TAG, "getAudioRouteAllowed API not supported");
            return false;
        }

@@ -725,6 +727,23 @@ public class HeadsetClientService extends ProfileService {
        return sm.getAudioState(device);
    }

    public void setAudioRouteAllowed(BluetoothDevice device, boolean allowed) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        HeadsetClientStateMachine sm = mStateMachineMap.get(device);
        if (sm != null) {
            sm.setAudioRouteAllowed(allowed);
        }
    }

    public boolean getAudioRouteAllowed(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        HeadsetClientStateMachine sm = mStateMachineMap.get(device);
        if (sm != null) {
            return sm.getAudioRouteAllowed();
        }
        return false;
    }

    boolean connectAudio(BluetoothDevice device) {
        HeadsetClientStateMachine sm = getStateMachine(device);
        if (sm == null) {
+21 −0
Original line number Diff line number Diff line
@@ -168,6 +168,8 @@ public class HeadsetClientStateMachine extends StateMachine {
    private Pair<Integer, Object> mPendingAction;

    private int mAudioState;
    // Indicates whether audio can be routed to the device
    private boolean mAudioRouteAllowed;
    private boolean mAudioWbs;
    private int mVoiceRecognitionActive;
    private final BluetoothAdapter mAdapter;
@@ -775,6 +777,9 @@ public class HeadsetClientStateMachine extends StateMachine {
        mAudioWbs = false;
        mVoiceRecognitionActive = HeadsetClientHalConstants.VR_STATE_STOPPED;

        mAudioRouteAllowed = context.getResources().getBoolean(
            R.bool.headset_client_initial_audio_route_allowed);

        mIndicatorNetworkState = HeadsetClientHalConstants.NETWORK_STATE_NOT_AVAILABLE;
        mIndicatorNetworkType = HeadsetClientHalConstants.SERVICE_TYPE_HOME;
        mIndicatorNetworkSignal = 0;
@@ -1593,6 +1598,14 @@ public class HeadsetClientStateMachine extends StateMachine {
                    mAudioWbs = true;
                    // fall through
                case HeadsetClientHalConstants.AUDIO_STATE_CONNECTED:
                    if (DBG) {
                        Log.d(TAG, "mAudioRouteAllowed=" + mAudioRouteAllowed);
                    }
                    if (!mAudioRouteAllowed) {
                        sendMessage(HeadsetClientStateMachine.DISCONNECT_AUDIO);
                        break;
                    }

                    // Audio state is split in two parts, the audio focus is maintained by the
                    // entity exercising this service (typically the Telecom stack) and audio
                    // routing is handled by the bluetooth stack itself. The only reason to do so is
@@ -1981,4 +1994,12 @@ public class HeadsetClientStateMachine extends StateMachine {
            Log.d(TAG, message);
        }
    }

    public void setAudioRouteAllowed(boolean allowed) {
        mAudioRouteAllowed = allowed;
    }

    public boolean getAudioRouteAllowed() {
        return mAudioRouteAllowed;
    }
}