|
8 | 8 | import androidx.annotation.NonNull; |
9 | 9 | import androidx.annotation.Nullable; |
10 | 10 | import com.google.android.gms.tasks.Task; |
| 11 | +import com.google.android.gms.tasks.TaskCompletionSource; |
11 | 12 | import com.google.android.gms.tasks.Tasks; |
12 | 13 | import com.google.firebase.FirebaseApp; |
13 | 14 | import com.google.firebase.functions.FirebaseFunctions; |
@@ -60,31 +61,40 @@ private FirebaseFunctions getFunctions(Map<String, Object> arguments) { |
60 | 61 | } |
61 | 62 |
|
62 | 63 | private Task<Object> httpsFunctionCall(Map<String, Object> arguments) { |
63 | | - return Tasks.call( |
64 | | - cachedThreadPool, |
| 64 | + TaskCompletionSource<Object> taskCompletionSource = new TaskCompletionSource<>(); |
| 65 | + |
| 66 | + cachedThreadPool.execute( |
65 | 67 | () -> { |
66 | | - FirebaseFunctions firebaseFunctions = getFunctions(arguments); |
| 68 | + try { |
67 | 69 |
|
68 | | - String functionName = (String) Objects.requireNonNull(arguments.get("functionName")); |
69 | | - String origin = (String) arguments.get("origin"); |
70 | | - Integer timeout = (Integer) arguments.get("timeout"); |
71 | | - Object parameters = arguments.get("parameters"); |
| 70 | + FirebaseFunctions firebaseFunctions = getFunctions(arguments); |
72 | 71 |
|
73 | | - if (origin != null) { |
74 | | - Uri originUri = Uri.parse(origin); |
75 | | - firebaseFunctions.useEmulator(originUri.getHost(), originUri.getPort()); |
76 | | - } |
| 72 | + String functionName = (String) Objects.requireNonNull(arguments.get("functionName")); |
| 73 | + String origin = (String) arguments.get("origin"); |
| 74 | + Integer timeout = (Integer) arguments.get("timeout"); |
| 75 | + Object parameters = arguments.get("parameters"); |
77 | 76 |
|
78 | | - HttpsCallableReference httpsCallableReference = |
79 | | - firebaseFunctions.getHttpsCallable(functionName); |
| 77 | + if (origin != null) { |
| 78 | + Uri originUri = Uri.parse(origin); |
| 79 | + firebaseFunctions.useEmulator(originUri.getHost(), originUri.getPort()); |
| 80 | + } |
80 | 81 |
|
81 | | - if (timeout != null) { |
82 | | - httpsCallableReference.setTimeout(timeout.longValue(), TimeUnit.MILLISECONDS); |
83 | | - } |
| 82 | + HttpsCallableReference httpsCallableReference = |
| 83 | + firebaseFunctions.getHttpsCallable(functionName); |
84 | 84 |
|
85 | | - HttpsCallableResult result = Tasks.await(httpsCallableReference.call(parameters)); |
86 | | - return result.getData(); |
| 85 | + if (timeout != null) { |
| 86 | + httpsCallableReference.setTimeout(timeout.longValue(), TimeUnit.MILLISECONDS); |
| 87 | + } |
| 88 | + |
| 89 | + HttpsCallableResult result = Tasks.await(httpsCallableReference.call(parameters)); |
| 90 | + taskCompletionSource.setResult(result.getData()); |
| 91 | + |
| 92 | + } catch (Exception e) { |
| 93 | + taskCompletionSource.setException(e); |
| 94 | + } |
87 | 95 | }); |
| 96 | + |
| 97 | + return taskCompletionSource.getTask(); |
88 | 98 | } |
89 | 99 |
|
90 | 100 | @Override |
@@ -156,11 +166,19 @@ private Map<String, Object> getExceptionDetails(@Nullable Exception exception) { |
156 | 166 |
|
157 | 167 | @Override |
158 | 168 | public Task<Map<String, Object>> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) { |
159 | | - return Tasks.call(() -> null); |
| 169 | + TaskCompletionSource<Map<String, Object>> taskCompletionSource = new TaskCompletionSource<>(); |
| 170 | + |
| 171 | + cachedThreadPool.execute(() -> taskCompletionSource.setResult(null)); |
| 172 | + |
| 173 | + return taskCompletionSource.getTask(); |
160 | 174 | } |
161 | 175 |
|
162 | 176 | @Override |
163 | 177 | public Task<Void> didReinitializeFirebaseCore() { |
164 | | - return Tasks.call(() -> null); |
| 178 | + TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>(); |
| 179 | + |
| 180 | + cachedThreadPool.execute(() -> taskCompletionSource.setResult(null)); |
| 181 | + |
| 182 | + return taskCompletionSource.getTask(); |
165 | 183 | } |
166 | 184 | } |
0 commit comments