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.Handler; 20 import android.os.RemoteException; 21 22 import java.util.List; 23 24 /** @hide */ 25 public class InternalDownloadSessionCallback extends IMbmsDownloadSessionCallback.Stub { 26 27 private final Handler mHandler; 28 private final MbmsDownloadSessionCallback mAppCallback; 29 private volatile boolean mIsStopped = false; 30 31 public InternalDownloadSessionCallback(MbmsDownloadSessionCallback appCallback, 32 Handler handler) { 33 mAppCallback = appCallback; 34 mHandler = handler; 35 } 36 37 @Override 38 public void onError(final int errorCode, final String message) throws RemoteException { 39 if (mIsStopped) { 40 return; 41 } 42 43 mHandler.post(new Runnable() { 44 @Override 45 public void run() { 46 mAppCallback.onError(errorCode, message); 47 } 48 }); 49 } 50 51 @Override 52 public void onFileServicesUpdated(final List<FileServiceInfo> services) throws RemoteException { 53 if (mIsStopped) { 54 return; 55 } 56 57 mHandler.post(new Runnable() { 58 @Override 59 public void run() { 60 mAppCallback.onFileServicesUpdated(services); 61 } 62 }); 63 } 64 65 @Override 66 public void onMiddlewareReady() throws RemoteException { 67 if (mIsStopped) { 68 return; 69 } 70 71 mHandler.post(new Runnable() { 72 @Override 73 public void run() { 74 mAppCallback.onMiddlewareReady(); 75 } 76 }); 77 } 78 79 public Handler getHandler() { 80 return mHandler; 81 } 82 83 public void stop() { 84 mIsStopped = true; 85 } 86 } 87