Skip to content

Commit

Permalink
New PreyFirebaseCrashlytics
Browse files Browse the repository at this point in the history
New PreyFirebaseCrashlytics
  • Loading branch information
oaliaga committed Jul 20, 2023
1 parent b0eb3c3 commit 8c9bacf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
15 changes: 5 additions & 10 deletions app/src/main/java/com/prey/actions/picture/PictureUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@

import androidx.core.app.ActivityCompat;

import com.google.firebase.FirebaseApp;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.prey.PreyConfig;
import com.prey.PreyLogger;
import com.prey.actions.HttpDataService;
import com.prey.actions.camera.CameraAction;
import com.prey.activities.CheckPasswordHtmlActivity;
import com.prey.activities.SimpleCameraActivity;
import com.prey.exceptions.PreyFirebaseCrashlytics;
import com.prey.net.http.EntityFile;

public class PictureUtil {
Expand All @@ -45,10 +44,6 @@ public static HttpDataService getPicture(Context ctx) {
HttpDataService data = null;
int currentVolume = 0;
AudioManager mgr = null;
FirebaseApp.initializeApp(ctx);
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
crashlytics.setCustomKey("devicekey", PreyConfig.getPreyConfig(ctx).getDeviceId());
crashlytics.setCustomKey("apikey", PreyConfig.getPreyConfig(ctx).getApiKey());
try {
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmZ");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
Expand Down Expand Up @@ -83,7 +78,7 @@ public static HttpDataService getPicture(Context ctx) {
}
} catch (Exception e) {
PreyLogger.e("report error:" + e.getMessage(), e);
crashlytics.recordException(e);
PreyFirebaseCrashlytics.getInstance(ctx).recordException(e);
}
attempts++;
} while (attempts < maximum);
Expand Down Expand Up @@ -111,7 +106,7 @@ public static HttpDataService getPicture(Context ctx) {
}
} catch (Exception e) {
PreyLogger.e("report error:" + attempts, e);
crashlytics.recordException(e);
PreyFirebaseCrashlytics.getInstance(ctx).recordException(e);
}
attempts++;
} while (attempts < maximum);
Expand All @@ -126,7 +121,7 @@ public static HttpDataService getPicture(Context ctx) {
ctx.sendBroadcast(new Intent(CheckPasswordHtmlActivity.CLOSE_PREY));
} catch (Exception e) {
PreyLogger.e("report error:" + e.getMessage(), e);
crashlytics.recordException(e);
PreyFirebaseCrashlytics.getInstance(ctx).recordException(e);
} finally {
try {
currentVolume = PreyConfig.getPreyConfig(ctx).getVolume();
Expand All @@ -136,7 +131,7 @@ public static HttpDataService getPicture(Context ctx) {
}
} catch (Exception e) {
PreyLogger.e("report error:" + e.getMessage(), e);
crashlytics.recordException(e);
PreyFirebaseCrashlytics.getInstance(ctx).recordException(e);
}
}
return data;
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/com/prey/exceptions/PreyFirebaseCrashlytics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Created by Orlando Aliaga
* Copyright 2023 Prey Inc. All rights reserved.
* License: GPLv3
* Full license at "/LICENSE"
******************************************************************************/
package com.prey.exceptions;

import android.content.Context;

import androidx.annotation.NonNull;

import com.google.firebase.FirebaseApp;
import com.google.firebase.crashlytics.FirebaseCrashlytics;

import com.prey.PreyConfig;

public class PreyFirebaseCrashlytics {

private static PreyFirebaseCrashlytics instance = null;
private FirebaseCrashlytics crashlytics = null;

private PreyFirebaseCrashlytics(Context ctx) {
//initialize FirebaseCrashlytics
FirebaseApp.initializeApp(ctx);
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
crashlytics.setCustomKey("devicekey", PreyConfig.getPreyConfig(ctx).getDeviceId());
crashlytics.setCustomKey("apikey", PreyConfig.getPreyConfig(ctx).getApiKey());
}

public static PreyFirebaseCrashlytics getInstance(Context ctx) {
if (instance == null)
instance = new PreyFirebaseCrashlytics(ctx);
return instance;
}

/**
* Method to report an exception
*/
public void recordException(@NonNull Throwable throwable) {
crashlytics.recordException(throwable);
}
}

0 comments on commit 8c9bacf

Please sign in to comment.