1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settingslib.media; 18 19 import android.content.Context; 20 import android.media.MediaRoute2Info; 21 import android.media.RouteListingPreference; 22 import android.media.RoutingSessionInfo; 23 import android.media.session.MediaController; 24 import android.os.UserHandle; 25 26 import androidx.annotation.NonNull; 27 import androidx.annotation.Nullable; 28 29 import com.android.settingslib.bluetooth.LocalBluetoothManager; 30 31 import java.util.Collections; 32 import java.util.List; 33 34 /** 35 * No-op implementation of {@link InfoMediaManager}. 36 * 37 * <p>This implementation is used when {@link RouterInfoMediaManager} throws a {@link 38 * InfoMediaManager.PackageNotAvailableException}. 39 */ 40 // TODO - b/293578081: Remove once PackageNotAvailableException is propagated to library clients. 41 /* package */ final class NoOpInfoMediaManager extends InfoMediaManager { 42 /** 43 * Placeholder routing session to return as active session of {@link NoOpInfoMediaManager}. 44 * 45 * <p>Returning this routing session avoids crashes in {@link InfoMediaManager} and maintains 46 * the same client-facing behaviour as if no routing session was found for the target package 47 * name. 48 * 49 * <p>Volume and max volume are set to {@code -1} to emulate a non-existing routing session in 50 * {@link #getSessionVolume()} and {@link #getSessionVolumeMax()}. 51 */ 52 private static final RoutingSessionInfo PLACEHOLDER_SESSION = 53 new RoutingSessionInfo.Builder( 54 /* id */ "FAKE_ROUTING_SESSION", /* clientPackageName */ "") 55 .addSelectedRoute(/* routeId */ "FAKE_SELECTED_ROUTE_ID") 56 .setVolumeMax(-1) 57 .setVolume(-1) 58 .build(); 59 NoOpInfoMediaManager( Context context, @NonNull String packageName, @NonNull UserHandle userHandle, LocalBluetoothManager localBluetoothManager, @Nullable MediaController mediaController)60 NoOpInfoMediaManager( 61 Context context, 62 @NonNull String packageName, 63 @NonNull UserHandle userHandle, 64 LocalBluetoothManager localBluetoothManager, 65 @Nullable MediaController mediaController) { 66 super(context, packageName, userHandle, localBluetoothManager, mediaController); 67 } 68 69 @Override startScanOnRouter()70 protected void startScanOnRouter() { 71 // Do nothing. 72 } 73 74 @Override registerRouter()75 protected void registerRouter() { 76 // Do nothing. 77 } 78 79 @Override stopScanOnRouter()80 protected void stopScanOnRouter() { 81 // Do nothing. 82 } 83 84 @Override unregisterRouter()85 protected void unregisterRouter() { 86 // Do nothing. 87 } 88 89 @Override transferToRoute(@onNull MediaRoute2Info route)90 protected void transferToRoute(@NonNull MediaRoute2Info route) { 91 // Do nothing. 92 } 93 94 @Override selectRoute(@onNull MediaRoute2Info route, @NonNull RoutingSessionInfo info)95 protected void selectRoute(@NonNull MediaRoute2Info route, @NonNull RoutingSessionInfo info) { 96 // Do nothing. 97 } 98 99 @Override deselectRoute(@onNull MediaRoute2Info route, @NonNull RoutingSessionInfo info)100 protected void deselectRoute(@NonNull MediaRoute2Info route, @NonNull RoutingSessionInfo info) { 101 // Do nothing. 102 } 103 104 @Override releaseSession(@onNull RoutingSessionInfo sessionInfo)105 protected void releaseSession(@NonNull RoutingSessionInfo sessionInfo) { 106 // Do nothing. 107 } 108 109 @NonNull 110 @Override getSelectableRoutes(@onNull RoutingSessionInfo info)111 protected List<MediaRoute2Info> getSelectableRoutes(@NonNull RoutingSessionInfo info) { 112 return Collections.emptyList(); 113 } 114 115 @NonNull 116 @Override getDeselectableRoutes(@onNull RoutingSessionInfo info)117 protected List<MediaRoute2Info> getDeselectableRoutes(@NonNull RoutingSessionInfo info) { 118 return Collections.emptyList(); 119 } 120 121 @NonNull 122 @Override getSelectedRoutes(@onNull RoutingSessionInfo info)123 protected List<MediaRoute2Info> getSelectedRoutes(@NonNull RoutingSessionInfo info) { 124 return Collections.emptyList(); 125 } 126 127 @Override setSessionVolume(@onNull RoutingSessionInfo info, int volume)128 protected void setSessionVolume(@NonNull RoutingSessionInfo info, int volume) { 129 // Do nothing. 130 } 131 132 @Override setRouteVolume(@onNull MediaRoute2Info route, int volume)133 protected void setRouteVolume(@NonNull MediaRoute2Info route, int volume) { 134 // Do nothing. 135 } 136 137 @Nullable 138 @Override getRouteListingPreference()139 protected RouteListingPreference getRouteListingPreference() { 140 return null; 141 } 142 143 @NonNull 144 @Override getRemoteSessions()145 protected List<RoutingSessionInfo> getRemoteSessions() { 146 return Collections.emptyList(); 147 } 148 149 @NonNull 150 @Override getRoutingSessionsForPackage()151 protected List<RoutingSessionInfo> getRoutingSessionsForPackage() { 152 return List.of(PLACEHOLDER_SESSION); 153 } 154 155 @Nullable 156 @Override getRoutingSessionById(@onNull String sessionId)157 protected RoutingSessionInfo getRoutingSessionById(@NonNull String sessionId) { 158 return null; 159 } 160 161 @NonNull 162 @Override getAvailableRoutesFromRouter()163 protected List<MediaRoute2Info> getAvailableRoutesFromRouter() { 164 return Collections.emptyList(); 165 } 166 167 @NonNull 168 @Override getTransferableRoutes(@onNull String packageName)169 protected List<MediaRoute2Info> getTransferableRoutes(@NonNull String packageName) { 170 return Collections.emptyList(); 171 } 172 } 173