14
14
* limitations under the License.
15
15
*/
16
16
17
+ #include < assert.h>
17
18
#include < jni.h>
18
19
19
20
#include " app/src/assert.h"
@@ -86,7 +87,8 @@ METHOD_LOOKUP_DEFINITION(signinmethodquery,
86
87
87
88
// clang-format off
88
89
#define JNI_LISTENER_CALLBACK_METHODS (X ) \
89
- X (Constructor, " <init>" , " (J)V" )
90
+ X (Constructor, " <init>" , " (J)V" ), \
91
+ X (Disconnect, " disconnect" , " ()V" )
90
92
// clang-format on
91
93
METHOD_LOOKUP_DECLARATION (jnilistener, JNI_LISTENER_CALLBACK_METHODS)
92
94
METHOD_LOOKUP_DEFINITION (
@@ -95,7 +97,8 @@ METHOD_LOOKUP_DEFINITION(
95
97
96
98
// clang-format off
97
99
#define JNI_ID_TOKEN_LISTENER_CALLBACK_METHODS (X ) \
98
- X (Constructor, " <init>" , " (J)V" )
100
+ X (Constructor, " <init>" , " (J)V" ), \
101
+ X (Disconnect, " disconnect" , " ()V" )
99
102
// clang-format on
100
103
METHOD_LOOKUP_DECLARATION (jni_id_token_listener,
101
104
JNI_ID_TOKEN_LISTENER_CALLBACK_METHODS)
@@ -217,6 +220,7 @@ void* CreatePlatformAuth(App* app, void* app_impl) {
217
220
// Create the FirebaseAuth class in Java.
218
221
jobject j_auth_impl = env->CallStaticObjectMethod (
219
222
auth::GetClass (), auth::GetMethodId (auth::kGetInstance ), j_app);
223
+ assert (env->ExceptionCheck () == false );
220
224
221
225
// Ensure the reference hangs around.
222
226
void * auth_impl = nullptr ;
@@ -237,6 +241,7 @@ void Auth::InitPlatformAuth(AuthData* auth_data) {
237
241
env->CallVoidMethod (AuthImpl (auth_data),
238
242
auth::GetMethodId (auth::kAddAuthStateListener ),
239
243
j_listener);
244
+ assert (env->ExceptionCheck () == false );
240
245
// Convert listener from local to global ref, so it stays around.
241
246
SetImplFromLocalRef (env, j_listener, &auth_data->listener_impl );
242
247
@@ -250,6 +255,7 @@ void Auth::InitPlatformAuth(AuthData* auth_data) {
250
255
env->CallVoidMethod (AuthImpl (auth_data),
251
256
auth::GetMethodId (auth::kAddIdTokenListener ),
252
257
j_id_token_listener);
258
+ assert (env->ExceptionCheck () == false );
253
259
// Convert listener from local to global ref, so it stays around.
254
260
SetImplFromLocalRef (env, j_id_token_listener,
255
261
&auth_data->id_token_listener_impl );
@@ -266,12 +272,21 @@ void Auth::DestroyPlatformAuth(AuthData* auth_data) {
266
272
267
273
// Unregister the JniAuthStateListener and IdTokenListener from the
268
274
// FirebaseAuth class.
275
+ env->CallVoidMethod (static_cast <jobject>(auth_data->listener_impl ),
276
+ jnilistener::GetMethodId (jnilistener::kDisconnect ));
277
+ assert (env->ExceptionCheck () == false );
269
278
env->CallVoidMethod (AuthImpl (auth_data),
270
279
auth::GetMethodId (auth::kRemoveAuthStateListener ),
271
280
static_cast <jobject>(auth_data->listener_impl ));
281
+ assert (env->ExceptionCheck () == false );
282
+ env->CallVoidMethod (static_cast <jobject>(auth_data->id_token_listener_impl ),
283
+ jni_id_token_listener::GetMethodId (
284
+ jni_id_token_listener::kDisconnect ));
285
+ assert (env->ExceptionCheck () == false );
272
286
env->CallVoidMethod (AuthImpl (auth_data),
273
287
auth::GetMethodId (auth::kRemoveIdTokenListener ),
274
288
static_cast <jobject>(auth_data->id_token_listener_impl ));
289
+ assert (env->ExceptionCheck () == false );
275
290
276
291
// Deleting our global references should trigger the FirebaseAuth class and
277
292
// FirebaseUser Java objects to be deleted.
@@ -327,12 +342,14 @@ static void ReadProviderResult(
327
342
if (list != nullptr ) {
328
343
const int num_providers =
329
344
env->CallIntMethod (list, util::list::GetMethodId (util::list::kSize ));
345
+ assert (env->ExceptionCheck () == false );
330
346
data->providers .resize (num_providers);
331
347
332
348
for (int i = 0 ; i < num_providers; ++i) {
333
349
// provider local reference is released in JniStringToString().
334
350
jstring provider = static_cast <jstring>(env->CallObjectMethod (
335
351
list, util::list::GetMethodId (util::list::kGet ), i));
352
+ assert (env->ExceptionCheck () == false );
336
353
data->providers [i] = JniStringToString (env, provider);
337
354
}
338
355
env->DeleteLocalRef (list);
0 commit comments