Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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.server.media; |
| 18 | |
Kyunglyul Hyun | 6c5d7dc | 2019-04-24 15:57:07 +0900 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.ServiceConnection; |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 24 | import android.media.IMediaRoute2ProviderService; |
| 25 | import android.media.IMediaRoute2ProviderServiceCallback; |
Kyunglyul Hyun | 3aedf02 | 2019-04-15 16:38:19 +0900 | [diff] [blame] | 26 | import android.media.MediaRoute2ProviderInfo; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 27 | import android.media.MediaRoute2ProviderService; |
Kyunglyul Hyun | 1866d8a | 2020-01-31 11:56:34 +0900 | [diff] [blame] | 28 | import android.media.RouteDiscoveryPreference; |
Hyundo Moon | f829e6f | 2020-01-11 19:31:35 +0900 | [diff] [blame] | 29 | import android.media.RoutingSessionInfo; |
Hyundo Moon | 84e027d | 2020-01-16 17:39:05 +0900 | [diff] [blame] | 30 | import android.os.Bundle; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 31 | import android.os.Handler; |
| 32 | import android.os.IBinder; |
| 33 | import android.os.IBinder.DeathRecipient; |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 34 | import android.os.Looper; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 35 | import android.os.RemoteException; |
| 36 | import android.os.UserHandle; |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 37 | import android.text.TextUtils; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 38 | import android.util.Log; |
| 39 | import android.util.Slog; |
| 40 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 41 | import com.android.internal.annotations.GuardedBy; |
| 42 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 43 | import java.io.PrintWriter; |
| 44 | import java.lang.ref.WeakReference; |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 45 | import java.util.ArrayList; |
| 46 | import java.util.List; |
Kyunglyul Hyun | 6c5d7dc | 2019-04-24 15:57:07 +0900 | [diff] [blame] | 47 | import java.util.Objects; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 48 | |
| 49 | /** |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 50 | * Maintains a connection to a particular {@link MediaRoute2ProviderService}. |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 51 | */ |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 52 | final class MediaRoute2ProviderServiceProxy extends MediaRoute2Provider |
| 53 | implements ServiceConnection { |
| 54 | private static final String TAG = "MR2ProviderSvcProxy"; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 55 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 56 | |
| 57 | private final Context mContext; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 58 | private final int mUserId; |
| 59 | private final Handler mHandler; |
| 60 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 61 | // Connection state |
| 62 | private boolean mRunning; |
| 63 | private boolean mBound; |
| 64 | private Connection mActiveConnection; |
| 65 | private boolean mConnectionReady; |
| 66 | |
Kyunglyul Hyun | f2b19c8b | 2020-05-18 18:29:11 +0900 | [diff] [blame] | 67 | private RouteDiscoveryPreference mLastDiscoveryPreference = null; |
Kyunglyul Hyun | bab0cda | 2020-03-10 20:59:49 +0900 | [diff] [blame] | 68 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 69 | @GuardedBy("mLock") |
| 70 | final List<RoutingSessionInfo> mReleasingSessions = new ArrayList<>(); |
| 71 | |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 72 | MediaRoute2ProviderServiceProxy(@NonNull Context context, @NonNull ComponentName componentName, |
Kyunglyul Hyun | 6c5d7dc | 2019-04-24 15:57:07 +0900 | [diff] [blame] | 73 | int userId) { |
Kyunglyul Hyun | 0332e9a2 | 2019-11-20 01:39:25 +0000 | [diff] [blame] | 74 | super(componentName); |
Kyunglyul Hyun | 6c5d7dc | 2019-04-24 15:57:07 +0900 | [diff] [blame] | 75 | mContext = Objects.requireNonNull(context, "Context must not be null."); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 76 | mUserId = userId; |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 77 | mHandler = new Handler(Looper.myLooper()); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | public void dump(PrintWriter pw, String prefix) { |
| 81 | pw.println(prefix + "Proxy"); |
| 82 | pw.println(prefix + " mUserId=" + mUserId); |
| 83 | pw.println(prefix + " mRunning=" + mRunning); |
| 84 | pw.println(prefix + " mBound=" + mBound); |
| 85 | pw.println(prefix + " mActiveConnection=" + mActiveConnection); |
| 86 | pw.println(prefix + " mConnectionReady=" + mConnectionReady); |
| 87 | } |
| 88 | |
Kyunglyul Hyun | 0332e9a2 | 2019-11-20 01:39:25 +0000 | [diff] [blame] | 89 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 90 | public void requestCreateSession(long requestId, String packageName, String routeId, |
Hyundo Moon | 84e027d | 2020-01-16 17:39:05 +0900 | [diff] [blame] | 91 | Bundle sessionHints) { |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 92 | if (mConnectionReady) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 93 | mActiveConnection.requestCreateSession(requestId, packageName, routeId, sessionHints); |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 94 | updateBinding(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 99 | public void releaseSession(long requestId, String sessionId) { |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 100 | if (mConnectionReady) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 101 | mActiveConnection.releaseSession(requestId, sessionId); |
Kyunglyul Hyun | a0d4741 | 2019-07-01 11:14:24 +0900 | [diff] [blame] | 102 | updateBinding(); |
| 103 | } |
| 104 | } |
| 105 | |
Kyunglyul Hyun | 0332e9a2 | 2019-11-20 01:39:25 +0000 | [diff] [blame] | 106 | @Override |
Kyunglyul Hyun | 1866d8a | 2020-01-31 11:56:34 +0900 | [diff] [blame] | 107 | public void updateDiscoveryPreference(RouteDiscoveryPreference discoveryPreference) { |
Kyunglyul Hyun | f2b19c8b | 2020-05-18 18:29:11 +0900 | [diff] [blame] | 108 | mLastDiscoveryPreference = discoveryPreference; |
Kyunglyul Hyun | 1866d8a | 2020-01-31 11:56:34 +0900 | [diff] [blame] | 109 | if (mConnectionReady) { |
| 110 | mActiveConnection.updateDiscoveryPreference(discoveryPreference); |
| 111 | updateBinding(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 116 | public void selectRoute(long requestId, String sessionId, String routeId) { |
Kyunglyul Hyun | a0d4741 | 2019-07-01 11:14:24 +0900 | [diff] [blame] | 117 | if (mConnectionReady) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 118 | mActiveConnection.selectRoute(requestId, sessionId, routeId); |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 123 | public void deselectRoute(long requestId, String sessionId, String routeId) { |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 124 | if (mConnectionReady) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 125 | mActiveConnection.deselectRoute(requestId, sessionId, routeId); |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 130 | public void transferToRoute(long requestId, String sessionId, String routeId) { |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 131 | if (mConnectionReady) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 132 | mActiveConnection.transferToRoute(requestId, sessionId, routeId); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Kyunglyul Hyun | 0332e9a2 | 2019-11-20 01:39:25 +0000 | [diff] [blame] | 136 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 137 | public void setRouteVolume(long requestId, String routeId, int volume) { |
Kyunglyul Hyun | 5a8dedc | 2019-10-10 14:09:44 +0900 | [diff] [blame] | 138 | if (mConnectionReady) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 139 | mActiveConnection.setRouteVolume(requestId, routeId, volume); |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 140 | updateBinding(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 145 | public void setSessionVolume(long requestId, String sessionId, int volume) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 146 | if (mConnectionReady) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 147 | mActiveConnection.setSessionVolume(requestId, sessionId, volume); |
Kyunglyul Hyun | 5a8dedc | 2019-10-10 14:09:44 +0900 | [diff] [blame] | 148 | updateBinding(); |
| 149 | } |
| 150 | } |
| 151 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 152 | @Override |
| 153 | public void prepareReleaseSession(@NonNull String sessionId) { |
| 154 | synchronized (mLock) { |
| 155 | for (RoutingSessionInfo session : mSessionInfos) { |
| 156 | if (TextUtils.equals(session.getId(), sessionId)) { |
| 157 | mSessionInfos.remove(session); |
| 158 | mReleasingSessions.add(session); |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 165 | public boolean hasComponentName(String packageName, String className) { |
| 166 | return mComponentName.getPackageName().equals(packageName) |
| 167 | && mComponentName.getClassName().equals(className); |
| 168 | } |
| 169 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 170 | public void start() { |
| 171 | if (!mRunning) { |
| 172 | if (DEBUG) { |
| 173 | Slog.d(TAG, this + ": Starting"); |
| 174 | } |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 175 | mRunning = true; |
| 176 | updateBinding(); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | public void stop() { |
| 181 | if (mRunning) { |
| 182 | if (DEBUG) { |
| 183 | Slog.d(TAG, this + ": Stopping"); |
| 184 | } |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 185 | mRunning = false; |
| 186 | updateBinding(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | public void rebindIfDisconnected() { |
Kyunglyul Hyun | 89e2ee9 | 2020-04-10 20:17:04 +0900 | [diff] [blame] | 191 | //TODO: When we are connecting to the service, calling this will unbind and bind again. |
| 192 | // We'd better not unbind if we are connecting. |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 193 | if (mActiveConnection == null && shouldBind()) { |
| 194 | unbind(); |
| 195 | bind(); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | private void updateBinding() { |
| 200 | if (shouldBind()) { |
| 201 | bind(); |
| 202 | } else { |
| 203 | unbind(); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | private boolean shouldBind() { |
Kyunglyul Hyun | 6c5d7dc | 2019-04-24 15:57:07 +0900 | [diff] [blame] | 208 | //TODO: Binding could be delayed until it's necessary. |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 209 | if (mRunning) { |
| 210 | return true; |
| 211 | } |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | private void bind() { |
| 216 | if (!mBound) { |
| 217 | if (DEBUG) { |
| 218 | Slog.d(TAG, this + ": Binding"); |
| 219 | } |
| 220 | |
| 221 | Intent service = new Intent(MediaRoute2ProviderService.SERVICE_INTERFACE); |
| 222 | service.setComponent(mComponentName); |
| 223 | try { |
| 224 | mBound = mContext.bindServiceAsUser(service, this, |
| 225 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, |
| 226 | new UserHandle(mUserId)); |
| 227 | if (!mBound && DEBUG) { |
| 228 | Slog.d(TAG, this + ": Bind failed"); |
| 229 | } |
| 230 | } catch (SecurityException ex) { |
| 231 | if (DEBUG) { |
| 232 | Slog.d(TAG, this + ": Bind failed", ex); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | private void unbind() { |
| 239 | if (mBound) { |
| 240 | if (DEBUG) { |
| 241 | Slog.d(TAG, this + ": Unbinding"); |
| 242 | } |
| 243 | |
| 244 | mBound = false; |
| 245 | disconnect(); |
| 246 | mContext.unbindService(this); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 252 | if (DEBUG) { |
| 253 | Slog.d(TAG, this + ": Connected"); |
| 254 | } |
| 255 | |
| 256 | if (mBound) { |
| 257 | disconnect(); |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 258 | IMediaRoute2ProviderService serviceBinder = |
| 259 | IMediaRoute2ProviderService.Stub.asInterface(service); |
| 260 | if (serviceBinder != null) { |
| 261 | Connection connection = new Connection(serviceBinder); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 262 | if (connection.register()) { |
| 263 | mActiveConnection = connection; |
| 264 | } else { |
| 265 | if (DEBUG) { |
| 266 | Slog.d(TAG, this + ": Registration failed"); |
| 267 | } |
| 268 | } |
| 269 | } else { |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 270 | Slog.e(TAG, this + ": Service returned invalid binder"); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public void onServiceDisconnected(ComponentName name) { |
| 277 | if (DEBUG) { |
| 278 | Slog.d(TAG, this + ": Service disconnected"); |
| 279 | } |
| 280 | disconnect(); |
| 281 | } |
| 282 | |
Hyundo Moon | 7294e5f | 2020-01-29 13:26:14 +0900 | [diff] [blame] | 283 | @Override |
| 284 | public void onBindingDied(ComponentName name) { |
| 285 | if (DEBUG) { |
| 286 | Slog.d(TAG, this + ": Service binding died"); |
| 287 | } |
Hyundo Moon | 7294e5f | 2020-01-29 13:26:14 +0900 | [diff] [blame] | 288 | if (shouldBind()) { |
| 289 | unbind(); |
| 290 | bind(); |
| 291 | } |
| 292 | } |
| 293 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 294 | private void onConnectionReady(Connection connection) { |
| 295 | if (mActiveConnection == connection) { |
| 296 | mConnectionReady = true; |
Kyunglyul Hyun | f2b19c8b | 2020-05-18 18:29:11 +0900 | [diff] [blame] | 297 | if (mLastDiscoveryPreference != null) { |
| 298 | updateDiscoveryPreference(mLastDiscoveryPreference); |
Kyunglyul Hyun | bab0cda | 2020-03-10 20:59:49 +0900 | [diff] [blame] | 299 | } |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
| 303 | private void onConnectionDied(Connection connection) { |
| 304 | if (mActiveConnection == connection) { |
| 305 | if (DEBUG) { |
| 306 | Slog.d(TAG, this + ": Service connection died"); |
| 307 | } |
| 308 | disconnect(); |
| 309 | } |
| 310 | } |
| 311 | |
Kyunglyul Hyun | efe4374 | 2019-12-31 18:32:28 +0900 | [diff] [blame] | 312 | private void onProviderStateUpdated(Connection connection, |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 313 | MediaRoute2ProviderInfo providerInfo) { |
Kyunglyul Hyun | 3aedf02 | 2019-04-15 16:38:19 +0900 | [diff] [blame] | 314 | if (mActiveConnection != connection) { |
| 315 | return; |
| 316 | } |
Kyunglyul Hyun | 3aedf02 | 2019-04-15 16:38:19 +0900 | [diff] [blame] | 317 | if (DEBUG) { |
| 318 | Slog.d(TAG, this + ": State changed "); |
| 319 | } |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 320 | setAndNotifyProviderState(providerInfo); |
Kyunglyul Hyun | 23b3aaa | 2019-08-06 11:17:16 +0900 | [diff] [blame] | 321 | } |
| 322 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 323 | private void onSessionCreated(Connection connection, long requestId, |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 324 | RoutingSessionInfo newSession) { |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 325 | if (mActiveConnection != connection) { |
| 326 | return; |
| 327 | } |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 328 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 329 | if (newSession == null) { |
| 330 | Slog.w(TAG, "onSessionCreated: Ignoring null session sent from " + mComponentName); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 331 | return; |
Kyunglyul Hyun | 138246e | 2020-01-02 18:19:52 +0900 | [diff] [blame] | 332 | } |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 333 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 334 | newSession = assignProviderIdForSession(newSession); |
| 335 | String newSessionId = newSession.getId(); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 336 | |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 337 | synchronized (mLock) { |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 338 | if (mSessionInfos.stream() |
| 339 | .anyMatch(session -> TextUtils.equals(session.getId(), newSessionId)) |
| 340 | || mReleasingSessions.stream() |
| 341 | .anyMatch(session -> TextUtils.equals(session.getId(), newSessionId))) { |
| 342 | Slog.w(TAG, "onSessionCreated: Duplicate session already exists. Ignoring."); |
| 343 | return; |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 344 | } |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 345 | mSessionInfos.add(newSession); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 346 | } |
| 347 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 348 | mCallback.onSessionCreated(this, requestId, newSession); |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 349 | } |
| 350 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 351 | private void onSessionUpdated(Connection connection, RoutingSessionInfo updatedSession) { |
Hyundo Moon | 0a92657 | 2019-12-28 15:01:21 +0900 | [diff] [blame] | 352 | if (mActiveConnection != connection) { |
| 353 | return; |
| 354 | } |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 355 | if (updatedSession == null) { |
| 356 | Slog.w(TAG, "onSessionUpdated: Ignoring null session sent from " |
Hyundo Moon | 0a92657 | 2019-12-28 15:01:21 +0900 | [diff] [blame] | 357 | + mComponentName); |
| 358 | return; |
| 359 | } |
Hyundo Moon | b26c4b2 | 2020-01-08 19:44:43 +0900 | [diff] [blame] | 360 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 361 | updatedSession = assignProviderIdForSession(updatedSession); |
Hyundo Moon | b26c4b2 | 2020-01-08 19:44:43 +0900 | [diff] [blame] | 362 | |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 363 | boolean found = false; |
| 364 | synchronized (mLock) { |
| 365 | for (int i = 0; i < mSessionInfos.size(); i++) { |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 366 | if (mSessionInfos.get(i).getId().equals(updatedSession.getId())) { |
| 367 | mSessionInfos.set(i, updatedSession); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 368 | found = true; |
| 369 | break; |
| 370 | } |
| 371 | } |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 372 | |
| 373 | if (!found) { |
| 374 | for (RoutingSessionInfo releasingSession : mReleasingSessions) { |
| 375 | if (TextUtils.equals(releasingSession.getId(), updatedSession.getId())) { |
| 376 | return; |
| 377 | } |
| 378 | } |
| 379 | Slog.w(TAG, "onSessionUpdated: Matching session info not found"); |
| 380 | return; |
| 381 | } |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 382 | } |
| 383 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 384 | mCallback.onSessionUpdated(this, updatedSession); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 385 | } |
| 386 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 387 | private void onSessionReleased(Connection connection, RoutingSessionInfo releaedSession) { |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 388 | if (mActiveConnection != connection) { |
| 389 | return; |
| 390 | } |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 391 | if (releaedSession == null) { |
| 392 | Slog.w(TAG, "onSessionReleased: Ignoring null session sent from " + mComponentName); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 396 | releaedSession = assignProviderIdForSession(releaedSession); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 397 | |
| 398 | boolean found = false; |
| 399 | synchronized (mLock) { |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 400 | for (RoutingSessionInfo session : mSessionInfos) { |
| 401 | if (TextUtils.equals(session.getId(), releaedSession.getId())) { |
| 402 | mSessionInfos.remove(session); |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 403 | found = true; |
| 404 | break; |
| 405 | } |
| 406 | } |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 407 | if (!found) { |
| 408 | for (RoutingSessionInfo session : mReleasingSessions) { |
| 409 | if (TextUtils.equals(session.getId(), releaedSession.getId())) { |
| 410 | mReleasingSessions.remove(session); |
| 411 | return; |
| 412 | } |
| 413 | } |
| 414 | } |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | if (!found) { |
| 418 | Slog.w(TAG, "onSessionReleased: Matching session info not found"); |
| 419 | return; |
| 420 | } |
| 421 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 422 | mCallback.onSessionReleased(this, releaedSession); |
Hyundo Moon | 0a92657 | 2019-12-28 15:01:21 +0900 | [diff] [blame] | 423 | } |
| 424 | |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 425 | private RoutingSessionInfo assignProviderIdForSession(RoutingSessionInfo sessionInfo) { |
Kyunglyul Hyun | e2dbbf7 | 2020-04-29 22:40:59 +0900 | [diff] [blame] | 426 | return new RoutingSessionInfo.Builder(sessionInfo) |
| 427 | .setOwnerPackageName(mComponentName.getPackageName()) |
| 428 | .setProviderId(getUniqueId()) |
| 429 | .build(); |
| 430 | } |
| 431 | |
Hyundo Moon | 0fa60e8 | 2020-02-14 11:44:45 +0900 | [diff] [blame] | 432 | private void onRequestFailed(Connection connection, long requestId, int reason) { |
| 433 | if (mActiveConnection != connection) { |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | if (requestId == MediaRoute2ProviderService.REQUEST_ID_NONE) { |
| 438 | Slog.w(TAG, "onRequestFailed: Ignoring requestId REQUEST_ID_NONE"); |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | mCallback.onRequestFailed(this, requestId, reason); |
| 443 | } |
| 444 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 445 | private void disconnect() { |
| 446 | if (mActiveConnection != null) { |
| 447 | mConnectionReady = false; |
| 448 | mActiveConnection.dispose(); |
| 449 | mActiveConnection = null; |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 450 | setAndNotifyProviderState(null); |
Kyunglyul Hyun | 47d289e | 2020-02-07 19:24:08 +0900 | [diff] [blame] | 451 | synchronized (mLock) { |
| 452 | for (RoutingSessionInfo sessionInfo : mSessionInfos) { |
| 453 | mCallback.onSessionReleased(this, sessionInfo); |
| 454 | } |
| 455 | mSessionInfos.clear(); |
Kyunglyul Hyun | 6a2f1d6 | 2020-05-19 23:00:17 +0900 | [diff] [blame] | 456 | mReleasingSessions.clear(); |
Kyunglyul Hyun | 47d289e | 2020-02-07 19:24:08 +0900 | [diff] [blame] | 457 | } |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
| 461 | @Override |
| 462 | public String toString() { |
| 463 | return "Service connection " + mComponentName.flattenToShortString(); |
| 464 | } |
| 465 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 466 | private final class Connection implements DeathRecipient { |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 467 | private final IMediaRoute2ProviderService mService; |
| 468 | private final ServiceCallbackStub mCallbackStub; |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 469 | |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 470 | Connection(IMediaRoute2ProviderService serviceBinder) { |
| 471 | mService = serviceBinder; |
| 472 | mCallbackStub = new ServiceCallbackStub(this); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | public boolean register() { |
| 476 | try { |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 477 | mService.asBinder().linkToDeath(this, 0); |
| 478 | mService.setCallback(mCallbackStub); |
Kyunglyul Hyun | a0d4741 | 2019-07-01 11:14:24 +0900 | [diff] [blame] | 479 | mHandler.post(() -> onConnectionReady(Connection.this)); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 480 | return true; |
| 481 | } catch (RemoteException ex) { |
| 482 | binderDied(); |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | public void dispose() { |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 488 | mService.asBinder().unlinkToDeath(this, 0); |
| 489 | mCallbackStub.dispose(); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 492 | public void requestCreateSession(long requestId, String packageName, String routeId, |
Hyundo Moon | 84e027d | 2020-01-16 17:39:05 +0900 | [diff] [blame] | 493 | Bundle sessionHints) { |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 494 | try { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 495 | mService.requestCreateSession(requestId, packageName, routeId, sessionHints); |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 496 | } catch (RemoteException ex) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 497 | Slog.e(TAG, "requestCreateSession: Failed to deliver request."); |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 501 | public void releaseSession(long requestId, String sessionId) { |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 502 | try { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 503 | mService.releaseSession(requestId, sessionId); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 504 | } catch (RemoteException ex) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 505 | Slog.e(TAG, "releaseSession: Failed to deliver request."); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Kyunglyul Hyun | 1866d8a | 2020-01-31 11:56:34 +0900 | [diff] [blame] | 509 | public void updateDiscoveryPreference(RouteDiscoveryPreference discoveryPreference) { |
| 510 | try { |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 511 | mService.updateDiscoveryPreference(discoveryPreference); |
Kyunglyul Hyun | 1866d8a | 2020-01-31 11:56:34 +0900 | [diff] [blame] | 512 | } catch (RemoteException ex) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 513 | Slog.e(TAG, "updateDiscoveryPreference: Failed to deliver request."); |
Kyunglyul Hyun | 1866d8a | 2020-01-31 11:56:34 +0900 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 517 | public void selectRoute(long requestId, String sessionId, String routeId) { |
Kyunglyul Hyun | caae8dc | 2019-04-29 15:45:23 +0900 | [diff] [blame] | 518 | try { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 519 | mService.selectRoute(requestId, sessionId, routeId); |
Kyunglyul Hyun | a0d4741 | 2019-07-01 11:14:24 +0900 | [diff] [blame] | 520 | } catch (RemoteException ex) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 521 | Slog.e(TAG, "selectRoute: Failed to deliver request.", ex); |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 525 | public void deselectRoute(long requestId, String sessionId, String routeId) { |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 526 | try { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 527 | mService.deselectRoute(requestId, sessionId, routeId); |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 528 | } catch (RemoteException ex) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 529 | Slog.e(TAG, "deselectRoute: Failed to deliver request.", ex); |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 533 | public void transferToRoute(long requestId, String sessionId, String routeId) { |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 534 | try { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 535 | mService.transferToRoute(requestId, sessionId, routeId); |
Kyunglyul Hyun | cb8894d | 2019-12-27 14:24:46 +0900 | [diff] [blame] | 536 | } catch (RemoteException ex) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 537 | Slog.e(TAG, "transferToRoute: Failed to deliver request.", ex); |
Kyunglyul Hyun | a0d4741 | 2019-07-01 11:14:24 +0900 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 541 | public void setRouteVolume(long requestId, String routeId, int volume) { |
Kyunglyul Hyun | 5a8dedc | 2019-10-10 14:09:44 +0900 | [diff] [blame] | 542 | try { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 543 | mService.setRouteVolume(requestId, routeId, volume); |
Kyunglyul Hyun | 5a8dedc | 2019-10-10 14:09:44 +0900 | [diff] [blame] | 544 | } catch (RemoteException ex) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 545 | Slog.e(TAG, "setRouteVolume: Failed to deliver request.", ex); |
| 546 | } |
| 547 | } |
| 548 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 549 | public void setSessionVolume(long requestId, String sessionId, int volume) { |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 550 | try { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 551 | mService.setSessionVolume(requestId, sessionId, volume); |
Kyunglyul Hyun | 5161b37 | 2020-02-05 18:45:35 +0900 | [diff] [blame] | 552 | } catch (RemoteException ex) { |
| 553 | Slog.e(TAG, "setSessionVolume: Failed to deliver request.", ex); |
Kyunglyul Hyun | 5a8dedc | 2019-10-10 14:09:44 +0900 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 557 | @Override |
| 558 | public void binderDied() { |
Kyunglyul Hyun | 3aedf02 | 2019-04-15 16:38:19 +0900 | [diff] [blame] | 559 | mHandler.post(() -> onConnectionDied(Connection.this)); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 562 | void postProviderStateUpdated(MediaRoute2ProviderInfo providerInfo) { |
| 563 | mHandler.post(() -> onProviderStateUpdated(Connection.this, providerInfo)); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 564 | } |
Kyunglyul Hyun | f7d5e04 | 2019-11-11 13:56:28 +0900 | [diff] [blame] | 565 | |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 566 | void postSessionCreated(long requestId, RoutingSessionInfo sessionInfo) { |
| 567 | mHandler.post(() -> onSessionCreated(Connection.this, requestId, sessionInfo)); |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 568 | } |
Hyundo Moon | 0a92657 | 2019-12-28 15:01:21 +0900 | [diff] [blame] | 569 | |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 570 | void postSessionUpdated(RoutingSessionInfo sessionInfo) { |
| 571 | mHandler.post(() -> onSessionUpdated(Connection.this, sessionInfo)); |
| 572 | } |
| 573 | |
| 574 | void postSessionReleased(RoutingSessionInfo sessionInfo) { |
| 575 | mHandler.post(() -> onSessionReleased(Connection.this, sessionInfo)); |
Hyundo Moon | 0a92657 | 2019-12-28 15:01:21 +0900 | [diff] [blame] | 576 | } |
Hyundo Moon | 0fa60e8 | 2020-02-14 11:44:45 +0900 | [diff] [blame] | 577 | |
Hyundo Moon | 7c2059c | 2020-02-27 19:01:52 +0900 | [diff] [blame] | 578 | void postRequestFailed(long requestId, int reason) { |
Hyundo Moon | 0fa60e8 | 2020-02-14 11:44:45 +0900 | [diff] [blame] | 579 | mHandler.post(() -> onRequestFailed(Connection.this, requestId, reason)); |
| 580 | } |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 583 | private static final class ServiceCallbackStub extends |
| 584 | IMediaRoute2ProviderServiceCallback.Stub { |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 585 | private final WeakReference<Connection> mConnectionRef; |
| 586 | |
Hyundo Moon | 5633749 | 2020-02-16 16:19:54 +0900 | [diff] [blame] | 587 | ServiceCallbackStub(Connection connection) { |
Kyunglyul Hyun | 3aedf02 | 2019-04-15 16:38:19 +0900 | [diff] [blame] | 588 | mConnectionRef = new WeakReference<>(connection); |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | public void dispose() { |
| 592 | mConnectionRef.clear(); |
| 593 | } |
| 594 | |
| 595 | @Override |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 596 | public void updateState(MediaRoute2ProviderInfo providerInfo) { |
Kyunglyul Hyun | 3aedf02 | 2019-04-15 16:38:19 +0900 | [diff] [blame] | 597 | Connection connection = mConnectionRef.get(); |
| 598 | if (connection != null) { |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 599 | connection.postProviderStateUpdated(providerInfo); |
Kyunglyul Hyun | 3aedf02 | 2019-04-15 16:38:19 +0900 | [diff] [blame] | 600 | } |
| 601 | } |
Kyunglyul Hyun | f7d5e04 | 2019-11-11 13:56:28 +0900 | [diff] [blame] | 602 | |
| 603 | @Override |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 604 | public void notifySessionCreated(long requestId, RoutingSessionInfo sessionInfo) { |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 605 | Connection connection = mConnectionRef.get(); |
| 606 | if (connection != null) { |
Hyundo Moon | f8e49f4b | 2020-03-06 17:19:42 +0900 | [diff] [blame] | 607 | connection.postSessionCreated(requestId, sessionInfo); |
Hyundo Moon | 63a0540 | 2019-12-19 20:13:56 +0900 | [diff] [blame] | 608 | } |
| 609 | } |
Hyundo Moon | 0a92657 | 2019-12-28 15:01:21 +0900 | [diff] [blame] | 610 | |
| 611 | @Override |
Hyundo Moon | 6e30f1b | 2020-01-13 19:50:27 +0900 | [diff] [blame] | 612 | public void notifySessionUpdated(RoutingSessionInfo sessionInfo) { |
| 613 | Connection connection = mConnectionRef.get(); |
| 614 | if (connection != null) { |
| 615 | connection.postSessionUpdated(sessionInfo); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public void notifySessionReleased(RoutingSessionInfo sessionInfo) { |
| 621 | Connection connection = mConnectionRef.get(); |
| 622 | if (connection != null) { |
| 623 | connection.postSessionReleased(sessionInfo); |
Hyundo Moon | 0a92657 | 2019-12-28 15:01:21 +0900 | [diff] [blame] | 624 | } |
| 625 | } |
Hyundo Moon | 0fa60e8 | 2020-02-14 11:44:45 +0900 | [diff] [blame] | 626 | |
| 627 | @Override |
| 628 | public void notifyRequestFailed(long requestId, int reason) { |
| 629 | Connection connection = mConnectionRef.get(); |
| 630 | if (connection != null) { |
Hyundo Moon | 7c2059c | 2020-02-27 19:01:52 +0900 | [diff] [blame] | 631 | connection.postRequestFailed(requestId, reason); |
Hyundo Moon | 0fa60e8 | 2020-02-14 11:44:45 +0900 | [diff] [blame] | 632 | } |
| 633 | } |
Kyunglyul Hyun | d51666d | 2019-04-11 04:08:40 +0000 | [diff] [blame] | 634 | } |
| 635 | } |