From 2f2dea0e9a1d9bc14f6c9bc5d585d51d7bee5a0e Mon Sep 17 00:00:00 2001 From: Ahsan Ayaz Date: Mon, 19 Nov 2018 13:11:11 +0500 Subject: [PATCH] feat(crashlytics): Test Crash Implemented --- src/android/FirebasePlugin.java | 22 ++- src/ios/FirebasePlugin.h | 85 ++++----- src/ios/FirebasePlugin.m | 5 + www/firebase-browser.js | 324 ++++++++++++++++---------------- www/firebase.js | 6 +- 5 files changed, 237 insertions(+), 205 deletions(-) diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index 2ba645835..07962854f 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -134,6 +134,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo }else if(action.equals("setCrashlyticsUserId")){ this.setCrashlyticsUserId(callbackContext, args.getString(0)); return true; + }else if(action.equals("testCrash")){ + this.testCrash(callbackContext); + return true; } else if (action.equals("setScreenName")) { this.setScreenName(callbackContext, args.getString(0)); return true; @@ -513,6 +516,19 @@ public void run() { }); } + private void crashTest(final CallbackContext callbackContext) { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + Crashlytics.getInstance().crash(); // Force a crash + } catch (Exception e) { + Crashlytics.logException(e); + callbackContext.error(e.getMessage()); + } + } + }); + } + private void setScreenName(final CallbackContext callbackContext, final String name) { // This must be called on the main thread cordova.getActivity().runOnUiThread(new Runnable() { @@ -747,7 +763,7 @@ public void onVerificationCompleted(PhoneAuthCredential credential) { try { String verificationId = null; String code = null; - + Field[] fields = credential.getClass().getDeclaredFields(); for (Field field : fields) { Class type = field.getType(); @@ -814,7 +830,7 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo callbackContext.sendPluginResult(pluginresult); } }; - + PhoneAuthProvider.getInstance().verifyPhoneNumber(number, // Phone number to verify timeOutDuration, // Timeout duration TimeUnit.SECONDS, // Unit of timeout @@ -827,7 +843,7 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo } }); } - + private static String getPrivateField(PhoneAuthCredential credential, Field field) { try { field.setAccessible(true); diff --git a/src/ios/FirebasePlugin.h b/src/ios/FirebasePlugin.h index f7d081016..661b2940f 100755 --- a/src/ios/FirebasePlugin.h +++ b/src/ios/FirebasePlugin.h @@ -1,42 +1,43 @@ -#import -#import "AppDelegate.h" - -@interface FirebasePlugin : CDVPlugin -+ (FirebasePlugin *) firebasePlugin; -- (void)getVerificationID:(CDVInvokedUrlCommand*)command; -- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command; -- (void)getInstanceId:(CDVInvokedUrlCommand*)command; -- (void)getId:(CDVInvokedUrlCommand*)command; -- (void)getToken:(CDVInvokedUrlCommand*)command; -- (void)grantPermission:(CDVInvokedUrlCommand*)command; -- (void)hasPermission:(CDVInvokedUrlCommand*)command; -- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command; -- (void)getBadgeNumber:(CDVInvokedUrlCommand*)command; -- (void)subscribe:(CDVInvokedUrlCommand*)command; -- (void)unsubscribe:(CDVInvokedUrlCommand*)command; -- (void)unregister:(CDVInvokedUrlCommand*)command; -- (void)onNotificationOpen:(CDVInvokedUrlCommand*)command; -- (void)onTokenRefresh:(CDVInvokedUrlCommand*)command; -- (void)sendNotification:(NSDictionary*)userInfo; -- (void)sendToken:(NSString*)token; -- (void)logEvent:(CDVInvokedUrlCommand*)command; -- (void)logError:(CDVInvokedUrlCommand*)command; -- (void)setCrashlyticsUserId:(CDVInvokedUrlCommand*)command; -- (void)setScreenName:(CDVInvokedUrlCommand*)command; -- (void)setUserId:(CDVInvokedUrlCommand*)command; -- (void)setUserProperty:(CDVInvokedUrlCommand*)command; -- (void)fetch:(CDVInvokedUrlCommand*)command; -- (void)activateFetched:(CDVInvokedUrlCommand*)command; -- (void)getValue:(CDVInvokedUrlCommand*)command; -- (void)startTrace:(CDVInvokedUrlCommand*)command; -- (void)incrementCounter:(CDVInvokedUrlCommand*)command; -- (void)stopTrace:(CDVInvokedUrlCommand*)command; -- (void)setAnalyticsCollectionEnabled:(CDVInvokedUrlCommand*)command; -- (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command; -- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command; -@property (nonatomic, copy) NSString *notificationCallbackId; -@property (nonatomic, copy) NSString *tokenRefreshCallbackId; -@property (nonatomic, retain) NSMutableArray *notificationStack; -@property (nonatomic, readwrite) NSMutableDictionary* traces; - -@end +#import +#import "AppDelegate.h" + +@interface FirebasePlugin : CDVPlugin ++ (FirebasePlugin *) firebasePlugin; +- (void)getVerificationID:(CDVInvokedUrlCommand*)command; +- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command; +- (void)getInstanceId:(CDVInvokedUrlCommand*)command; +- (void)getId:(CDVInvokedUrlCommand*)command; +- (void)getToken:(CDVInvokedUrlCommand*)command; +- (void)grantPermission:(CDVInvokedUrlCommand*)command; +- (void)hasPermission:(CDVInvokedUrlCommand*)command; +- (void)setBadgeNumber:(CDVInvokedUrlCommand*)command; +- (void)getBadgeNumber:(CDVInvokedUrlCommand*)command; +- (void)subscribe:(CDVInvokedUrlCommand*)command; +- (void)unsubscribe:(CDVInvokedUrlCommand*)command; +- (void)unregister:(CDVInvokedUrlCommand*)command; +- (void)onNotificationOpen:(CDVInvokedUrlCommand*)command; +- (void)onTokenRefresh:(CDVInvokedUrlCommand*)command; +- (void)sendNotification:(NSDictionary*)userInfo; +- (void)sendToken:(NSString*)token; +- (void)logEvent:(CDVInvokedUrlCommand*)command; +- (void)logError:(CDVInvokedUrlCommand*)command; +- (void)setCrashlyticsUserId:(CDVInvokedUrlCommand*)command; +- (void)testCrash:(CDVInvokedUrlCommand*)command; +- (void)setScreenName:(CDVInvokedUrlCommand*)command; +- (void)setUserId:(CDVInvokedUrlCommand*)command; +- (void)setUserProperty:(CDVInvokedUrlCommand*)command; +- (void)fetch:(CDVInvokedUrlCommand*)command; +- (void)activateFetched:(CDVInvokedUrlCommand*)command; +- (void)getValue:(CDVInvokedUrlCommand*)command; +- (void)startTrace:(CDVInvokedUrlCommand*)command; +- (void)incrementCounter:(CDVInvokedUrlCommand*)command; +- (void)stopTrace:(CDVInvokedUrlCommand*)command; +- (void)setAnalyticsCollectionEnabled:(CDVInvokedUrlCommand*)command; +- (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command; +- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command; +@property (nonatomic, copy) NSString *notificationCallbackId; +@property (nonatomic, copy) NSString *tokenRefreshCallbackId; +@property (nonatomic, retain) NSMutableArray *notificationStack; +@property (nonatomic, readwrite) NSMutableDictionary* traces; + +@end diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index df0c79167..1aec5f425 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -301,6 +301,11 @@ - (void)setCrashlyticsUserId:(CDVInvokedUrlCommand *)command { [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } +- (void)crashTest: (CDVInvokedUrlCommand *)command { + [[Crashlytics sharedInstance] crash]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + - (void)setScreenName:(CDVInvokedUrlCommand *)command { NSString* name = [command.arguments objectAtIndex:0]; diff --git a/www/firebase-browser.js b/www/firebase-browser.js index 10426bb49..b0dc8f0a9 100755 --- a/www/firebase-browser.js +++ b/www/firebase-browser.js @@ -1,159 +1,165 @@ -exports.getVerificationID = function (number, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.getInstanceId = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.getToken = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.getId = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.onNotificationOpen = function (success, error) {}; - -exports.onTokenRefresh = function (success, error) {}; - -exports.grantPermission = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setBadgeNumber = function (number, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.getBadgeNumber = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.subscribe = function (topic, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.unsubscribe = function (topic, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.logEvent = function (name, params, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.logError = function (message, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setCrashlyticsUserId = function (userId, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setScreenName = function (name, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setUserId = function (id, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setUserProperty = function (name, value, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.activateFetched = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.fetch = function (cacheExpirationSeconds, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.getByteArray = function (key, namespace, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.getValue = function (key, namespace, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.getInfo = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setConfigSettings = function (settings, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setDefaults = function (defaults, namespace, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.verifyPhoneNumber = function (number, timeOutDuration, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setAnalyticsCollectionEnabled = function (enabled, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.setPerformanceCollectionEnabled = function (enabled, success, error) { - if (typeof success === 'function') { - success(); - } -}; - -exports.clearAllNotifications = function (success, error) { - if (typeof success === 'function') { - success(); - } -}; \ No newline at end of file +exports.getVerificationID = function (number, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.getInstanceId = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.getToken = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.getId = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.onNotificationOpen = function (success, error) {}; + +exports.onTokenRefresh = function (success, error) {}; + +exports.grantPermission = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setBadgeNumber = function (number, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.getBadgeNumber = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.subscribe = function (topic, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.unsubscribe = function (topic, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.logEvent = function (name, params, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.logError = function (message, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setCrashlyticsUserId = function (userId, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.testCrash = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setScreenName = function (name, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setUserId = function (id, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setUserProperty = function (name, value, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.activateFetched = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.fetch = function (cacheExpirationSeconds, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.getByteArray = function (key, namespace, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.getValue = function (key, namespace, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.getInfo = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setConfigSettings = function (settings, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setDefaults = function (defaults, namespace, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.verifyPhoneNumber = function (number, timeOutDuration, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setAnalyticsCollectionEnabled = function (enabled, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.setPerformanceCollectionEnabled = function (enabled, success, error) { + if (typeof success === 'function') { + success(); + } +}; + +exports.clearAllNotifications = function (success, error) { + if (typeof success === 'function') { + success(); + } +}; diff --git a/www/firebase.js b/www/firebase.js index 0e4330a69..61d425b4a 100644 --- a/www/firebase.js +++ b/www/firebase.js @@ -64,6 +64,10 @@ exports.setCrashlyticsUserId = function (userId, success, error) { exec(success, error, "FirebasePlugin", "setCrashlyticsUserId", [userId]); }; +exports.testCrash = function (success, error) { + exec(success, error, "FirebasePlugin", "testCrash", []); +}; + exports.setScreenName = function (name, success, error) { exec(success, error, "FirebasePlugin", "setScreenName", [name]); }; @@ -166,4 +170,4 @@ exports.verifyPhoneNumber = function (number, timeOutDuration, success, error) { exports.clearAllNotifications = function (success, error) { exec(success, error, "FirebasePlugin", "clearAllNotifications", []); -}; \ No newline at end of file +};