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

Commit 83a4c969 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "mainline_b3_m"

* changes:
  Broadcast ACL disconnected when adapter turned off
  Adds mAudioRouteAllowed to dump...
  Bring back support for [get|set]AudioRouteAllowed()
parents f5c0cf9d 479ce30c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ public class AdapterService extends Service {

    public static final String BLUETOOTH_PRIVILEGED =
            android.Manifest.permission.BLUETOOTH_PRIVILEGED;
    static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
    static final String LOCAL_MAC_ADDRESS_PERM = android.Manifest.permission.LOCAL_MAC_ADDRESS;
    static final String RECEIVE_MAP_PERM = android.Manifest.permission.RECEIVE_BLUETOOTH_MAP;

+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;

+20 −2
Original line number Diff line number Diff line
@@ -178,9 +178,27 @@ final class RemoteDevices {
            sSdpTracker.clear();
        }

        synchronized (mDevices) {
            if (mDevices != null) {
                debugLog("reset(): Broadcasting ACL_DISCONNECTED");

                mDevices.forEach((address, deviceProperties) -> {
                    BluetoothDevice bluetoothDevice = deviceProperties.getDevice();

                    debugLog("reset(): address=" + address + ", connected="
                            + bluetoothDevice.isConnected());

                    if (bluetoothDevice.isConnected()) {
                        Intent intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED);
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bluetoothDevice);
                        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                                | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                        sAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
                    }
                });
                mDevices.clear();
            }
        }

        if (mDualDevicesMap != null) {
            mDualDevicesMap.clear();
+25 −6
Original line number Diff line number Diff line
@@ -365,19 +365,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;
        }

@@ -731,6 +733,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) {
+22 −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;
@@ -210,6 +212,7 @@ public class HeadsetClientStateMachine extends StateMachine {
        ProfileService.println(sb, "  mIndicatorBatteryLevel: " + mIndicatorBatteryLevel);
        ProfileService.println(sb, "  mOperatorName: " + mOperatorName);
        ProfileService.println(sb, "  mSubscriberInfo: " + mSubscriberInfo);
        ProfileService.println(sb, "  mAudioRouteAllowed: " + mAudioRouteAllowed);

        ProfileService.println(sb, "  mCalls:");
        if (mCalls != null) {
@@ -775,6 +778,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 +1599,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 +1995,12 @@ public class HeadsetClientStateMachine extends StateMachine {
            Log.d(TAG, message);
        }
    }

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

    public boolean getAudioRouteAllowed() {
        return mAudioRouteAllowed;
    }
}