Loading services/core/java/com/android/server/media/AudioManagerRouteController.java +0 −4 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import android.util.SparseArray; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.server.media.BluetoothRouteController.NoOpBluetoothRouteController; import java.util.Arrays; import java.util.Collections; Loading @@ -62,9 +61,6 @@ import java.util.concurrent.CopyOnWriteArrayList; /** * Maintains a list of all available routes and supports transfers to any of them. * * <p>This implementation is intended for use in conjunction with {@link * NoOpBluetoothRouteController}, as it manages bluetooth devices directly. * * <p>This implementation obtains and manages all routes via {@link AudioManager}, with the * exception of {@link AudioManager#handleBluetoothActiveDeviceChanged inactive bluetooth} routes * which are managed by {@link BluetoothDeviceRoutesManager}, which depends on the bluetooth stack Loading services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java +10 −4 Original line number Diff line number Diff line Loading @@ -65,6 +65,13 @@ import java.util.stream.Collectors; private static final String HEARING_AID_ROUTE_ID_PREFIX = "HEARING_AID_"; private static final String LE_AUDIO_ROUTE_ID_PREFIX = "LE_AUDIO_"; /** Interface for receiving events about Bluetooth routes changes. */ interface BluetoothRoutesUpdatedListener { /** Called when Bluetooth routes have changed. */ void onBluetoothRoutesUpdated(); } @NonNull private final AdapterStateChangedReceiver mAdapterStateChangedReceiver = new AdapterStateChangedReceiver(); Loading @@ -80,8 +87,7 @@ import java.util.stream.Collectors; private final Context mContext; @NonNull private final Handler mHandler; @NonNull private final BluetoothAdapter mBluetoothAdapter; @NonNull private final BluetoothRouteController.BluetoothRoutesUpdatedListener mListener; @NonNull private final BluetoothRoutesUpdatedListener mListener; @NonNull private final BluetoothProfileMonitor mBluetoothProfileMonitor; Loading @@ -89,7 +95,7 @@ import java.util.stream.Collectors; @NonNull Context context, @NonNull Handler handler, @NonNull BluetoothAdapter bluetoothAdapter, @NonNull BluetoothRouteController.BluetoothRoutesUpdatedListener listener) { @NonNull BluetoothRoutesUpdatedListener listener) { this( context, handler, Loading @@ -104,7 +110,7 @@ import java.util.stream.Collectors; @NonNull Handler handler, @NonNull BluetoothAdapter bluetoothAdapter, @NonNull BluetoothProfileMonitor bluetoothProfileMonitor, @NonNull BluetoothRouteController.BluetoothRoutesUpdatedListener listener) { @NonNull BluetoothRoutesUpdatedListener listener) { mContext = Objects.requireNonNull(context); mHandler = handler; mBluetoothAdapter = Objects.requireNonNull(bluetoothAdapter); Loading services/core/java/com/android/server/media/BluetoothRouteController.javadeleted 100644 → 0 +0 −170 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.media; import android.annotation.NonNull; import android.annotation.Nullable; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothManager; import android.content.Context; import android.media.MediaRoute2Info; import android.os.UserHandle; import com.android.media.flags.Flags; import java.util.Collections; import java.util.List; import java.util.Objects; /** * Provides control over bluetooth routes. */ /* package */ interface BluetoothRouteController { /** * Returns a new instance of {@link LegacyBluetoothRouteController}. * * <p>It may return {@link NoOpBluetoothRouteController} if Bluetooth is not supported on this * hardware platform. */ @NonNull static BluetoothRouteController createInstance(@NonNull Context context, @NonNull BluetoothRouteController.BluetoothRoutesUpdatedListener listener) { Objects.requireNonNull(listener); BluetoothAdapter btAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); if (btAdapter == null || Flags.enableAudioPoliciesDeviceAndBluetoothController()) { return new NoOpBluetoothRouteController(); } else { return new LegacyBluetoothRouteController(context, btAdapter, listener); } } /** * Makes the controller to listen to events from Bluetooth stack. * * @param userHandle is needed to subscribe for broadcasts on user's behalf. */ void start(@NonNull UserHandle userHandle); /** * Stops the controller from listening to any Bluetooth events. */ void stop(); /** * Transfers Bluetooth output to the given route. * * <p>If the route is {@code null} then active route will be deactivated. * * @param routeId to switch to or {@code null} to unset the active device. */ void transferTo(@Nullable String routeId); /** * Returns currently selected Bluetooth route. * * @return the selected route or {@code null} if there are no active routes. */ @Nullable MediaRoute2Info getSelectedRoute(); /** * Returns transferable routes. * * <p>A route is considered to be transferable if the bluetooth device is connected but not * considered as selected. * * @return list of transferable routes or an empty list. */ @NonNull List<MediaRoute2Info> getTransferableRoutes(); /** * Provides all connected Bluetooth routes. * * @return list of Bluetooth routes or an empty list. */ @NonNull List<MediaRoute2Info> getAllBluetoothRoutes(); /** * Updates the volume for all Bluetooth devices for the given profile. * * @param devices specifies the profile, may be, {@link android.bluetooth.BluetoothA2dp}, {@link * android.bluetooth.BluetoothLeAudio}, or {@link android.bluetooth.BluetoothHearingAid} * @param volume the specific volume value for the given devices or 0 if unknown. * @return {@code true} if updated successfully and {@code false} otherwise. */ boolean updateVolumeForDevices(int devices, int volume); /** * Interface for receiving events about Bluetooth routes changes. */ interface BluetoothRoutesUpdatedListener { /** Called when Bluetooth routes have changed. */ void onBluetoothRoutesUpdated(); } /** * No-op implementation of {@link BluetoothRouteController}. * * <p>Useful if the device does not support Bluetooth. */ class NoOpBluetoothRouteController implements BluetoothRouteController { @Override public void start(UserHandle userHandle) { // no op } @Override public void stop() { // no op } @Override public void transferTo(String routeId) { // no op } @Override public MediaRoute2Info getSelectedRoute() { // no op return null; } @Override public List<MediaRoute2Info> getTransferableRoutes() { // no op return Collections.emptyList(); } @Override public List<MediaRoute2Info> getAllBluetoothRoutes() { // no op return Collections.emptyList(); } @Override public boolean updateVolumeForDevices(int devices, int volume) { // no op return false; } } } services/core/java/com/android/server/media/DeviceRouteController.java +1 −3 Original line number Diff line number Diff line Loading @@ -63,9 +63,7 @@ import java.util.List; // bluetooth adapter or a strategy for media. If no strategy for media is available we can // disallow media router transfers, and without a bluetooth adapter we can remove support // for transfers to inactive bluetooth routes. if (strategyForMedia != null && btAdapter != null && Flags.enableAudioPoliciesDeviceAndBluetoothController()) { if (strategyForMedia != null && btAdapter != null) { AudioManagerRouteController controller = AudioManagerRouteController.getInstance( context, audioManager, looper, strategyForMedia, btAdapter); Loading services/core/java/com/android/server/media/LegacyBluetoothRouteController.javadeleted 100644 → 0 +0 −577 File deleted.Preview size limit exceeded, changes collapsed. Show changes Loading
services/core/java/com/android/server/media/AudioManagerRouteController.java +0 −4 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import android.util.SparseArray; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.server.media.BluetoothRouteController.NoOpBluetoothRouteController; import java.util.Arrays; import java.util.Collections; Loading @@ -62,9 +61,6 @@ import java.util.concurrent.CopyOnWriteArrayList; /** * Maintains a list of all available routes and supports transfers to any of them. * * <p>This implementation is intended for use in conjunction with {@link * NoOpBluetoothRouteController}, as it manages bluetooth devices directly. * * <p>This implementation obtains and manages all routes via {@link AudioManager}, with the * exception of {@link AudioManager#handleBluetoothActiveDeviceChanged inactive bluetooth} routes * which are managed by {@link BluetoothDeviceRoutesManager}, which depends on the bluetooth stack Loading
services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java +10 −4 Original line number Diff line number Diff line Loading @@ -65,6 +65,13 @@ import java.util.stream.Collectors; private static final String HEARING_AID_ROUTE_ID_PREFIX = "HEARING_AID_"; private static final String LE_AUDIO_ROUTE_ID_PREFIX = "LE_AUDIO_"; /** Interface for receiving events about Bluetooth routes changes. */ interface BluetoothRoutesUpdatedListener { /** Called when Bluetooth routes have changed. */ void onBluetoothRoutesUpdated(); } @NonNull private final AdapterStateChangedReceiver mAdapterStateChangedReceiver = new AdapterStateChangedReceiver(); Loading @@ -80,8 +87,7 @@ import java.util.stream.Collectors; private final Context mContext; @NonNull private final Handler mHandler; @NonNull private final BluetoothAdapter mBluetoothAdapter; @NonNull private final BluetoothRouteController.BluetoothRoutesUpdatedListener mListener; @NonNull private final BluetoothRoutesUpdatedListener mListener; @NonNull private final BluetoothProfileMonitor mBluetoothProfileMonitor; Loading @@ -89,7 +95,7 @@ import java.util.stream.Collectors; @NonNull Context context, @NonNull Handler handler, @NonNull BluetoothAdapter bluetoothAdapter, @NonNull BluetoothRouteController.BluetoothRoutesUpdatedListener listener) { @NonNull BluetoothRoutesUpdatedListener listener) { this( context, handler, Loading @@ -104,7 +110,7 @@ import java.util.stream.Collectors; @NonNull Handler handler, @NonNull BluetoothAdapter bluetoothAdapter, @NonNull BluetoothProfileMonitor bluetoothProfileMonitor, @NonNull BluetoothRouteController.BluetoothRoutesUpdatedListener listener) { @NonNull BluetoothRoutesUpdatedListener listener) { mContext = Objects.requireNonNull(context); mHandler = handler; mBluetoothAdapter = Objects.requireNonNull(bluetoothAdapter); Loading
services/core/java/com/android/server/media/BluetoothRouteController.javadeleted 100644 → 0 +0 −170 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.media; import android.annotation.NonNull; import android.annotation.Nullable; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothManager; import android.content.Context; import android.media.MediaRoute2Info; import android.os.UserHandle; import com.android.media.flags.Flags; import java.util.Collections; import java.util.List; import java.util.Objects; /** * Provides control over bluetooth routes. */ /* package */ interface BluetoothRouteController { /** * Returns a new instance of {@link LegacyBluetoothRouteController}. * * <p>It may return {@link NoOpBluetoothRouteController} if Bluetooth is not supported on this * hardware platform. */ @NonNull static BluetoothRouteController createInstance(@NonNull Context context, @NonNull BluetoothRouteController.BluetoothRoutesUpdatedListener listener) { Objects.requireNonNull(listener); BluetoothAdapter btAdapter = context.getSystemService(BluetoothManager.class).getAdapter(); if (btAdapter == null || Flags.enableAudioPoliciesDeviceAndBluetoothController()) { return new NoOpBluetoothRouteController(); } else { return new LegacyBluetoothRouteController(context, btAdapter, listener); } } /** * Makes the controller to listen to events from Bluetooth stack. * * @param userHandle is needed to subscribe for broadcasts on user's behalf. */ void start(@NonNull UserHandle userHandle); /** * Stops the controller from listening to any Bluetooth events. */ void stop(); /** * Transfers Bluetooth output to the given route. * * <p>If the route is {@code null} then active route will be deactivated. * * @param routeId to switch to or {@code null} to unset the active device. */ void transferTo(@Nullable String routeId); /** * Returns currently selected Bluetooth route. * * @return the selected route or {@code null} if there are no active routes. */ @Nullable MediaRoute2Info getSelectedRoute(); /** * Returns transferable routes. * * <p>A route is considered to be transferable if the bluetooth device is connected but not * considered as selected. * * @return list of transferable routes or an empty list. */ @NonNull List<MediaRoute2Info> getTransferableRoutes(); /** * Provides all connected Bluetooth routes. * * @return list of Bluetooth routes or an empty list. */ @NonNull List<MediaRoute2Info> getAllBluetoothRoutes(); /** * Updates the volume for all Bluetooth devices for the given profile. * * @param devices specifies the profile, may be, {@link android.bluetooth.BluetoothA2dp}, {@link * android.bluetooth.BluetoothLeAudio}, or {@link android.bluetooth.BluetoothHearingAid} * @param volume the specific volume value for the given devices or 0 if unknown. * @return {@code true} if updated successfully and {@code false} otherwise. */ boolean updateVolumeForDevices(int devices, int volume); /** * Interface for receiving events about Bluetooth routes changes. */ interface BluetoothRoutesUpdatedListener { /** Called when Bluetooth routes have changed. */ void onBluetoothRoutesUpdated(); } /** * No-op implementation of {@link BluetoothRouteController}. * * <p>Useful if the device does not support Bluetooth. */ class NoOpBluetoothRouteController implements BluetoothRouteController { @Override public void start(UserHandle userHandle) { // no op } @Override public void stop() { // no op } @Override public void transferTo(String routeId) { // no op } @Override public MediaRoute2Info getSelectedRoute() { // no op return null; } @Override public List<MediaRoute2Info> getTransferableRoutes() { // no op return Collections.emptyList(); } @Override public List<MediaRoute2Info> getAllBluetoothRoutes() { // no op return Collections.emptyList(); } @Override public boolean updateVolumeForDevices(int devices, int volume) { // no op return false; } } }
services/core/java/com/android/server/media/DeviceRouteController.java +1 −3 Original line number Diff line number Diff line Loading @@ -63,9 +63,7 @@ import java.util.List; // bluetooth adapter or a strategy for media. If no strategy for media is available we can // disallow media router transfers, and without a bluetooth adapter we can remove support // for transfers to inactive bluetooth routes. if (strategyForMedia != null && btAdapter != null && Flags.enableAudioPoliciesDeviceAndBluetoothController()) { if (strategyForMedia != null && btAdapter != null) { AudioManagerRouteController controller = AudioManagerRouteController.getInstance( context, audioManager, looper, strategyForMedia, btAdapter); Loading
services/core/java/com/android/server/media/LegacyBluetoothRouteController.javadeleted 100644 → 0 +0 −577 File deleted.Preview size limit exceeded, changes collapsed. Show changes