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

Commit f7909e2d authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "audioservice: detect bluetooth adapter turning off."

parents 37015370 b70b78a2
Loading
Loading
Loading
Loading
+71 −44
Original line number Diff line number Diff line
@@ -689,6 +689,7 @@ public class AudioService extends IAudioService.Stub {
        intentFilter.addAction(Intent.ACTION_USER_BACKGROUND);
        intentFilter.addAction(Intent.ACTION_USER_FOREGROUND);
        intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

        intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        // TODO merge orientation and rotation
@@ -3164,11 +3165,36 @@ public class AudioService extends IAudioService.Stub {
            }
        }
        public void onServiceDisconnected(int profile) {
            ArraySet<String> toRemove = null;

            switch (profile) {
            case BluetoothProfile.A2DP:
                disconnectA2dp();
                break;

            case BluetoothProfile.A2DP_SINK:
                disconnectA2dpSink();
                break;

            case BluetoothProfile.HEADSET:
                disconnectHeadset();
                break;

            default:
                break;
            }
        }
    };

    void disconnectAllBluetoothProfiles() {
        disconnectA2dp();
        disconnectA2dpSink();
        disconnectHeadset();
    }

    void disconnectA2dp() {
        synchronized (mConnectedDevices) {
            synchronized (mA2dpAvrcpLock) {
                ArraySet<String> toRemove = null;
                // Disconnect ALL DEVICE_OUT_BLUETOOTH_A2DP devices
                for (int i = 0; i < mConnectedDevices.size(); i++) {
                    DeviceListSpec deviceSpec = mConnectedDevices.valueAt(i);
@@ -3187,10 +3213,11 @@ public class AudioService extends IAudioService.Stub {
                }
            }
        }
                break;
    }

            case BluetoothProfile.A2DP_SINK:
    void disconnectA2dpSink() {
        synchronized (mConnectedDevices) {
            ArraySet<String> toRemove = null;
            // Disconnect ALL DEVICE_IN_BLUETOOTH_A2DP devices
            for(int i = 0; i < mConnectedDevices.size(); i++) {
                DeviceListSpec deviceSpec = mConnectedDevices.valueAt(i);
@@ -3205,9 +3232,9 @@ public class AudioService extends IAudioService.Stub {
                }
            }
        }
                break;
    }

            case BluetoothProfile.HEADSET:
    void disconnectHeadset() {
        synchronized (mScoClients) {
            if (mBluetoothHeadsetDevice != null) {
                setBtScoDeviceConnectionState(mBluetoothHeadsetDevice,
@@ -3215,13 +3242,7 @@ public class AudioService extends IAudioService.Stub {
            }
            mBluetoothHeadset = null;
        }
                break;

            default:
                break;
            }
    }
    };

    private void onCheckMusicActive(String caller) {
        synchronized (mSafeMediaVolumeState) {
@@ -5228,6 +5249,12 @@ public class AudioService extends IAudioService.Stub {
                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                UserManagerService.getInstance().setUserRestriction(
                        UserManager.DISALLOW_RECORD_AUDIO, false, userId);
            } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
                state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
                if (state == BluetoothAdapter.STATE_OFF ||
                        state == BluetoothAdapter.STATE_TURNING_OFF) {
                    disconnectAllBluetoothProfiles();
                }
            }
        }
    } // end class AudioServiceBroadcastReceiver