1 /* 2 * Copyright (C) 2017 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 android.telephony.mbms; 18 19 import android.os.Binder; 20 import android.os.RemoteException; 21 22 import java.util.List; 23 import java.util.concurrent.Executor; 24 25 /** @hide */ 26 public class InternalStreamingSessionCallback extends IMbmsStreamingSessionCallback.Stub { 27 private final Executor mExecutor; 28 private final MbmsStreamingSessionCallback mAppCallback; 29 private volatile boolean mIsStopped = false; 30 InternalStreamingSessionCallback(MbmsStreamingSessionCallback appCallback, Executor executor)31 public InternalStreamingSessionCallback(MbmsStreamingSessionCallback appCallback, 32 Executor executor) { 33 mAppCallback = appCallback; 34 mExecutor = executor; 35 } 36 37 @Override onError(final int errorCode, final String message)38 public void onError(final int errorCode, final String message) throws RemoteException { 39 if (mIsStopped) { 40 return; 41 } 42 43 final long token = Binder.clearCallingIdentity(); 44 try { 45 mExecutor.execute(new Runnable() { 46 @Override 47 public void run() { 48 mAppCallback.onError(errorCode, message); 49 } 50 }); 51 } finally { 52 Binder.restoreCallingIdentity(token); 53 } 54 } 55 56 @Override onStreamingServicesUpdated(final List<StreamingServiceInfo> services)57 public void onStreamingServicesUpdated(final List<StreamingServiceInfo> services) 58 throws RemoteException { 59 if (mIsStopped) { 60 return; 61 } 62 63 final long token = Binder.clearCallingIdentity(); 64 try { 65 mExecutor.execute(new Runnable() { 66 @Override 67 public void run() { 68 mAppCallback.onStreamingServicesUpdated(services); 69 } 70 }); 71 } finally { 72 Binder.restoreCallingIdentity(token); 73 } 74 } 75 76 @Override onMiddlewareReady()77 public void onMiddlewareReady() throws RemoteException { 78 if (mIsStopped) { 79 return; 80 } 81 82 final long token = Binder.clearCallingIdentity(); 83 try { 84 mExecutor.execute(new Runnable() { 85 @Override 86 public void run() { 87 mAppCallback.onMiddlewareReady(); 88 } 89 }); 90 } finally { 91 Binder.restoreCallingIdentity(token); 92 } 93 } 94 stop()95 public void stop() { 96 mIsStopped = true; 97 } 98 } 99