15
15
*/
16
16
17
17
#include " app/src/invites/android/invites_android_helper.h"
18
+
18
19
#include < assert.h>
19
20
#include < string.h>
21
+
20
22
#include " app/invites_resources.h"
21
23
#include " app/src/invites/receiver_interface.h"
22
24
#include " app/src/invites/sender_receiver_interface.h"
@@ -31,27 +33,16 @@ Mutex AndroidHelper::init_mutex_; // NOLINT
31
33
int AndroidHelper::initialize_count_ = 0 ;
32
34
33
35
METHOD_LOOKUP_DEFINITION (
34
- invite, " com/google/firebase/invites/internal/cpp/AppInviteNativeWrapper" ,
35
- INVITE_METHODS)
36
+ dynamic_links_native_wrapper,
37
+ " com/google/firebase/dynamiclinks/internal/cpp/DynamicLinksNativeWrapper" ,
38
+ DYNAMIC_LINKS_NATIVE_WRAPPER_METHODS)
36
39
37
40
extern " C" {
38
41
39
42
JNIEXPORT void JNICALL
40
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_receivedInviteCallback (
41
- JNIEnv* env, jclass clazz, jlong data_ptr, jstring invitation_id_java,
42
- jstring deep_link_url_java, jint result, jstring error_string_java);
43
- JNIEXPORT void JNICALL
44
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_convertedInviteCallback (
45
- JNIEnv* env, jclass clazz, jlong data_ptr, jstring invitation_id_java,
43
+ Java_com_google_firebase_dynamiclinks_internal_cpp_DynamicLinksNativeWrapper_receivedDynamicLinkCallback (
44
+ JNIEnv* env, jclass clazz, jlong data_ptr, jstring deep_link_url_java,
46
45
jint result, jstring error_string_java);
47
- JNIEXPORT void JNICALL
48
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_sentInviteCallback (
49
- JNIEnv* env, jclass clazz, jlong data_ptr,
50
- jobjectArray invitation_ids_array, jint result, jstring error_string_java);
51
- JNIEXPORT void JNICALL
52
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_connectionFailedCallback (
53
- JNIEnv* env, jclass clazz, jlong data_ptr, jint error_code,
54
- jstring error_message);
55
46
56
47
} // extern "C"
57
48
@@ -68,20 +59,10 @@ AndroidHelper::AndroidHelper(const ::firebase::App& app,
68
59
}
69
60
70
61
static const JNINativeMethod kNativeMethods [] = {
71
- {" receivedInviteCallback" ,
72
- " (JLjava/lang/String;Ljava/lang/String;ILjava/lang/String;)V" ,
73
- reinterpret_cast <void *>(
74
- &Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_receivedInviteCallback)}, // NOLINT
75
- {" convertedInviteCallback" ,
62
+ {" receivedDynamicLinkCallback" ,
76
63
" (JLjava/lang/String;ILjava/lang/String;)V" ,
77
64
reinterpret_cast <void *>(
78
- &Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_convertedInviteCallback)}, // NOLINT
79
- {" sentInviteCallback" , " (J[Ljava/lang/String;ILjava/lang/String;)V" ,
80
- reinterpret_cast <void *>(
81
- &Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_sentInviteCallback)}, // NOLINT
82
- {" connectionFailedCallback" , " (JILjava/lang/String;)V" ,
83
- reinterpret_cast <void *>(
84
- &Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_connectionFailedCallback)}, // NOLINT
65
+ &Java_com_google_firebase_dynamiclinks_internal_cpp_DynamicLinksNativeWrapper_receivedDynamicLinkCallback)} // NOLINT
85
66
};
86
67
const std::vector<util::EmbeddedFile> embedded_files =
87
68
util::CacheEmbeddedFiles (
@@ -90,16 +71,15 @@ AndroidHelper::AndroidHelper(const ::firebase::App& app,
90
71
firebase_invites::invites_resources_filename,
91
72
firebase_invites::invites_resources_data,
92
73
firebase_invites::invites_resources_size));
93
- if (!(invite::CacheClassFromFiles (env, app_->activity (),
94
- &embedded_files) &&
95
- // Prepare to instantiate the AppInviteNativeWrapper Java class,
96
- // which
97
- // we will use to talk to the Firebase Invites Java library. Note
98
- // that
99
- // we need global references to everything because, again, we may be
100
- // running from different threads.
101
- invite::CacheMethodIds (env, app_->activity ()) &&
102
- invite::RegisterNatives (
74
+ if (!(dynamic_links_native_wrapper::CacheClassFromFiles (
75
+ env, app_->activity (), &embedded_files) &&
76
+ // Prepare to instantiate the DynamicLinksNativeWrapper Java class,
77
+ // which we will use to talk to the Firebase Dynamic Links Java
78
+ // library. Note that we need global references to everything
79
+ // because, again, we may be running from different threads.
80
+ dynamic_links_native_wrapper::CacheMethodIds (env,
81
+ app_->activity ()) &&
82
+ dynamic_links_native_wrapper::RegisterNatives (
103
83
env, kNativeMethods ,
104
84
sizeof (kNativeMethods ) / sizeof (kNativeMethods [0 ])))) {
105
85
util::Terminate (env);
@@ -109,7 +89,7 @@ AndroidHelper::AndroidHelper(const ::firebase::App& app,
109
89
}
110
90
initialize_count_++;
111
91
}
112
- // Actually create the AppInviteNativeWrapper object now.
92
+ // Actually create the DynamicLinksNativeWrapper object now.
113
93
CreateWrapperObject (sender_receiver);
114
94
}
115
95
@@ -118,7 +98,7 @@ AndroidHelper::~AndroidHelper() {
118
98
if (app_ == nullptr ) return ;
119
99
120
100
// Ensure that no further JNI callbacks refer to deleted instances.
121
- CallMethod (invite ::kDiscardNativePointer );
101
+ CallMethod (dynamic_links_native_wrapper ::kDiscardNativePointer );
122
102
123
103
JNIEnv* env = app_->GetJNIEnv ();
124
104
env->DeleteGlobalRef (wrapper_obj_);
@@ -129,7 +109,7 @@ AndroidHelper::~AndroidHelper() {
129
109
initialize_count_--;
130
110
if (initialize_count_ == 0 ) {
131
111
util::Terminate (env);
132
- invite ::ReleaseClass (env);
112
+ dynamic_links_native_wrapper ::ReleaseClass (env);
133
113
}
134
114
}
135
115
app_ = nullptr ;
@@ -138,59 +118,64 @@ AndroidHelper::~AndroidHelper() {
138
118
void AndroidHelper::CreateWrapperObject (
139
119
SenderReceiverInterface* sender_receiver) {
140
120
JNIEnv* env = app_->GetJNIEnv ();
141
- jobject obj = env->NewObject (
142
- invite::g_class, invite::GetMethodId (invite::kConstructor ),
143
- reinterpret_cast <jlong>(sender_receiver), app_->activity (), nullptr );
121
+ jobject obj = env->NewObject (dynamic_links_native_wrapper::g_class,
122
+ dynamic_links_native_wrapper::GetMethodId (
123
+ dynamic_links_native_wrapper::kConstructor ),
124
+ reinterpret_cast <jlong>(sender_receiver),
125
+ app_->activity (), nullptr );
144
126
CheckJNIException ();
145
127
wrapper_obj_ = env->NewGlobalRef (obj);
146
128
env->DeleteLocalRef (obj);
147
129
}
148
130
149
- bool AndroidHelper::CallBooleanMethod (invite::Method method) {
131
+ bool AndroidHelper::CallBooleanMethod (
132
+ dynamic_links_native_wrapper::Method method) {
150
133
JNIEnv* env = app_->GetJNIEnv ();
151
- jboolean result =
152
- env-> CallBooleanMethod ( wrapper_obj (), invite ::GetMethodId (method));
134
+ jboolean result = env-> CallBooleanMethod (
135
+ wrapper_obj (), dynamic_links_native_wrapper ::GetMethodId (method));
153
136
CheckJNIException ();
154
137
return (result != JNI_FALSE);
155
138
}
156
139
157
- bool AndroidHelper::CallBooleanMethodString (invite::Method method,
158
- const char * strparam) {
140
+ bool AndroidHelper::CallBooleanMethodString (
141
+ dynamic_links_native_wrapper::Method method, const char * strparam) {
159
142
JNIEnv* env = app_->GetJNIEnv ();
160
143
jstring param = env->NewStringUTF (strparam);
161
- jboolean result =
162
- env-> CallBooleanMethod ( wrapper_obj (), invite ::GetMethodId (method), param);
144
+ jboolean result = env-> CallBooleanMethod (
145
+ wrapper_obj (), dynamic_links_native_wrapper ::GetMethodId (method), param);
163
146
CheckJNIException ();
164
147
env->DeleteLocalRef (param);
165
148
166
149
return (result != JNI_FALSE);
167
150
}
168
151
169
- int AndroidHelper::CallIntMethodString (invite::Method method,
170
- const char * strparam) {
152
+ int AndroidHelper::CallIntMethodString (
153
+ dynamic_links_native_wrapper::Method method, const char * strparam) {
171
154
JNIEnv* env = app_->GetJNIEnv ();
172
155
jstring param = env->NewStringUTF (strparam);
173
- jint result =
174
- env-> CallBooleanMethod ( wrapper_obj (), invite ::GetMethodId (method), param);
156
+ jint result = env-> CallBooleanMethod (
157
+ wrapper_obj (), dynamic_links_native_wrapper ::GetMethodId (method), param);
175
158
CheckJNIException ();
176
159
env->DeleteLocalRef (param);
177
160
178
161
return result;
179
162
}
180
163
181
- void AndroidHelper::CallMethod (invite ::Method method) {
164
+ void AndroidHelper::CallMethod (dynamic_links_native_wrapper ::Method method) {
182
165
JNIEnv* env = app_->GetJNIEnv ();
183
- env->CallVoidMethod (wrapper_obj (), invite::GetMethodId (method));
166
+ env->CallVoidMethod (wrapper_obj (),
167
+ dynamic_links_native_wrapper::GetMethodId (method));
184
168
CheckJNIException ();
185
169
}
186
170
187
- void AndroidHelper::CallMethodStringString (invite::Method method,
188
- const char * strparam1,
189
- const char * strparam2) {
171
+ void AndroidHelper::CallMethodStringString (
172
+ dynamic_links_native_wrapper::Method method, const char * strparam1,
173
+ const char * strparam2) {
190
174
JNIEnv* env = app_->GetJNIEnv ();
191
175
jstring param1 = env->NewStringUTF (strparam1);
192
176
jstring param2 = env->NewStringUTF (strparam2);
193
- env->CallVoidMethod (wrapper_obj (), invite::GetMethodId (method), param1,
177
+ env->CallVoidMethod (wrapper_obj (),
178
+ dynamic_links_native_wrapper::GetMethodId (method), param1,
194
179
param2);
195
180
CheckJNIException ();
196
181
@@ -232,90 +217,23 @@ void AndroidHelper::ConnectionFailedCallback(int error_code) {
232
217
233
218
extern " C" {
234
219
235
- // A function that receives the callback from the Java side. The
236
- // "data_ptr" parameter is actually a pointer to our the AndroidHelper
237
- // instance, so we can call the proper ConnectionFailed method.
238
- JNIEXPORT void JNICALL
239
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_connectionFailedCallback (
240
- JNIEnv* env, jclass clazz, jlong data_ptr, jint error_code,
241
- jstring error_message) {
242
- if (data_ptr == 0 ) return ; // test call only
243
-
244
- // Be careful - we are in a different thread now. No JNI calls are allowed
245
- // except on the JNIEnv we were passed, and we have to take care changing the
246
- // InvitesReceiverInternal data -- anything we touch needs a lock.
247
- firebase::invites::internal::AndroidHelper* instance =
248
- reinterpret_cast <firebase::invites::internal::AndroidHelper*>(data_ptr);
249
-
250
- instance->ConnectionFailedCallback (error_code);
251
- }
252
-
253
- // A function that receives the callback from the Java side. The
254
- // "data_ptr" parameter is actually a pointer to our instance of
255
- // InviteSenderInternalAndroid, so we can call the proper
256
- // SentInviteCallback method.
257
-
258
- JNIEXPORT void JNICALL
259
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_sentInviteCallback (
260
- JNIEnv* env, jclass clazz, jlong data_ptr,
261
- jobjectArray invitation_ids_array, jint result, jstring error_string_java) {
262
- if (data_ptr == 0 ) return ; // Test call to ensure JNI is hooked up.
263
-
264
- // Be careful - we are in a different thread now. No JNI calls are allowed
265
- // except on the JNIEnv we were passed, and we have to take care changing the
266
- // AppInvitesSenderInternal data -- anything we touch needs a lock.
267
- std::vector<std::string> invitation_ids;
268
- std::string error_string;
269
- if (result == 0 ) {
270
- if (invitation_ids_array != nullptr ) {
271
- size_t num_ids =
272
- static_cast <size_t >(env->GetArrayLength (invitation_ids_array));
273
- invitation_ids.reserve (num_ids);
274
- for (int i = 0 ; i < num_ids; i++) {
275
- jstring id = static_cast <jstring>(
276
- env->GetObjectArrayElement (invitation_ids_array, i));
277
- const char * chars = env->GetStringUTFChars (id, nullptr );
278
- invitation_ids.push_back (std::string (chars));
279
- env->ReleaseStringUTFChars (id, chars);
280
- env->DeleteLocalRef (id);
281
- }
282
- }
283
- } else {
284
- // result != 0
285
- if (error_string_java != nullptr ) {
286
- const char * chars = env->GetStringUTFChars (error_string_java, nullptr );
287
- error_string = chars;
288
- env->ReleaseStringUTFChars (error_string_java, chars);
289
- }
290
- }
291
- firebase::invites::internal::SenderReceiverInterface* sender_receiver =
292
- reinterpret_cast <firebase::invites::internal::SenderReceiverInterface*>(
293
- data_ptr);
294
- sender_receiver->SentInviteCallback (invitation_ids, result, error_string);
295
- }
296
-
297
220
// A function that receives the callback from the Java side. The
298
221
// "data_ptr" parameter is actually a pointer to our instance of
299
222
// InviteReceiverInternalAndroid, so we can call the proper
300
223
// ReceivedInviteCallback method.
301
224
JNIEXPORT void JNICALL
302
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_receivedInviteCallback (
303
- JNIEnv* env, jclass clazz, jlong data_ptr, jstring invitation_id_java ,
304
- jstring deep_link_url_java, jint result, jstring error_string_java) {
225
+ Java_com_google_firebase_dynamiclinks_internal_cpp_DynamicLinksNativeWrapper_receivedDynamicLinkCallback (
226
+ JNIEnv* env, jclass clazz, jlong data_ptr, jstring deep_link_url_java ,
227
+ jint result, jstring error_string_java) {
305
228
if (data_ptr == 0 ) return ; // test call only
306
229
307
230
// Be careful - we are in a different thread now. No JNI calls are allowed
308
231
// except on the JNIEnv we were passed, and we have to take care changing the
309
232
// InvitesReceiverInternal data -- anything we touch needs a lock.
310
- std::string invitation_id;
233
+ std::string invitation_id; // Will remain empty.
311
234
std::string deep_link_url;
312
235
std::string error_string;
313
236
if (result == 0 ) {
314
- if (invitation_id_java != nullptr ) {
315
- const char * chars = env->GetStringUTFChars (invitation_id_java, nullptr );
316
- invitation_id = chars;
317
- env->ReleaseStringUTFChars (invitation_id_java, chars);
318
- }
319
237
if (deep_link_url_java != nullptr ) {
320
238
const char * chars = env->GetStringUTFChars (deep_link_url_java, nullptr );
321
239
deep_link_url = chars;
@@ -339,43 +257,6 @@ Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_receivedInv
339
257
result, error_string);
340
258
}
341
259
342
- // A function that receives the callback from the Java side. The
343
- // "data_ptr" parameter is actually a pointer to our instance of
344
- // InviteReceiverInternalAndroid, so we can call the proper
345
- // ConvertedInviteCallback method.
346
- JNIEXPORT void JNICALL
347
- Java_com_google_firebase_invites_internal_cpp_AppInviteNativeWrapper_convertedInviteCallback (
348
- JNIEnv* env, jclass clazz, jlong data_ptr, jstring invitation_id_java,
349
- jint result, jstring error_string_java) {
350
- if (data_ptr == 0 ) return ; // test call only
351
-
352
- // Be careful - we are in a different thread now. No JNI calls are allowed
353
- // except on the JNIEnv we were passed, and we have to take care changing the
354
- // InvitesReceiverInternal data -- anything we touch needs a lock.
355
- std::string invitation_id;
356
- std::string error_string;
357
- if (result == 0 ) {
358
- if (invitation_id_java != nullptr ) {
359
- const char * chars = env->GetStringUTFChars (invitation_id_java, nullptr );
360
- invitation_id = chars;
361
- env->ReleaseStringUTFChars (invitation_id_java, chars);
362
- }
363
- } else {
364
- // result != 0
365
- if (error_string_java != nullptr ) {
366
- const char * chars = env->GetStringUTFChars (error_string_java, nullptr );
367
- error_string = chars;
368
- env->ReleaseStringUTFChars (error_string_java, chars);
369
- }
370
- }
371
-
372
- firebase::invites::internal::SenderReceiverInterface* sender_receiver =
373
- reinterpret_cast <firebase::invites::internal::SenderReceiverInterface*>(
374
- data_ptr);
375
-
376
- sender_receiver->ConvertedInviteCallback (invitation_id, result, error_string);
377
- }
378
-
379
260
} // extern "C"
380
261
381
262
} // namespace internal
0 commit comments