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