• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
InternalDownloadSessionCallback(MbmsDownloadSessionCallback appCallback, Executor executor)31     public InternalDownloadSessionCallback(MbmsDownloadSessionCallback 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) {
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
onFileServicesUpdated(final List<FileServiceInfo> services)57     public void onFileServicesUpdated(final List<FileServiceInfo> services) {
58         if (mIsStopped) {
59             return;
60         }
61 
62         final long token = Binder.clearCallingIdentity();
63         try {
64             mExecutor.execute(new Runnable() {
65                 @Override
66                 public void run() {
67                     mAppCallback.onFileServicesUpdated(services);
68                 }
69             });
70         } finally {
71             Binder.restoreCallingIdentity(token);
72         }
73     }
74 
75     @Override
onMiddlewareReady()76     public void onMiddlewareReady() {
77         if (mIsStopped) {
78             return;
79         }
80 
81         final long token = Binder.clearCallingIdentity();
82         try {
83             mExecutor.execute(new Runnable() {
84                 @Override
85                 public void run() {
86                     mAppCallback.onMiddlewareReady();
87                 }
88             });
89         } finally {
90             Binder.restoreCallingIdentity(token);
91         }
92     }
93 
stop()94     public void stop() {
95         mIsStopped = true;
96     }
97 }
98