Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase analytics #53

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
plugins {
id 'com.android.application'
id 'com.google.firebase.firebase-perf'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
Expand Down Expand Up @@ -30,11 +32,17 @@ android {
}

dependencies {

implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.google.firebase:firebase-analytics:19.0.0'
implementation 'com.google.firebase:firebase-inappmessaging-display:20.0.0'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.google.firebase:firebase-crashlytics:18.0.0'
implementation 'com.google.firebase:firebase-analytics'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.exoplayer:exoplayer:2.13.3'
implementation 'com.google.firebase:firebase-perf:20.0.0'

testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
39 changes: 39 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "1098951021382",
"project_id": "fpvout",
"storage_bucket": "fpvout.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1098951021382:android:0e42e902c98c2d6deb4b47",
"android_client_info": {
"package_name": "com.fpvout.digiview"
}
},
"oauth_client": [
{
"client_id": "1098951021382-lge70n5fif1csdumcuk86omabtgvsems.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDRfdW_nEkshiKZnlUiTY7Ww5R3Ne0Fgog"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how this is handled in open-source projects but I'd suggest to not publish the googles-services.json since somebody knowing these keys can spam firebase with arbitrary events...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question ... it is bound to the package. So in the store its not really possible, but I must admit apps not installed from the play store can spam into the account (but why should they do it :-D )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a quick research it turned out to be okay to put the google-service.json into the public repository since the keys can be extracted easily from the APK itself. But it is possible to restrict the API access to correctly signed APKs only.
Take a look at: https://stackoverflow.com/a/57067722/6843341

}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1098951021382-lge70n5fif1csdumcuk86omabtgvsems.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fpvout.digiview">

<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/com/fpvout/digiview/logging/CustomLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.fpvout.digiview.logging;

import android.util.Log;


import com.google.firebase.crashlytics.FirebaseCrashlytics;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;


public final class CustomLogger{
public static final void i(String tag, String message){
Log.i(tag,message);
sendToCrashlytics(tag,message,null);
}

public static final void d(String tag, String message){
Log.d(tag,message);
sendToCrashlytics(tag,message,null);
}

public static final void d(String tag, String message,Throwable ex){
Log.d(tag,message,ex);
sendToCrashlytics(tag,message,ex);
}

public static final void e(String tag, String message){
Log.e(tag,message);
sendToCrashlytics(tag,message,null);
}

public static final void e(String tag, String message,Throwable ex){
Log.e(tag,message,ex);
sendToCrashlytics(tag,message,ex);
}

public static final void wtf(String tag, String message){
Log.wtf(tag,message);
sendToCrashlytics(tag,message,null);
}

public static final void v(String tag, String message){
Log.v(tag,message);
sendToCrashlytics(tag,message,null);
}

private static void sendToCrashlytics(String tag, String message, Throwable ex){
try {
FirebaseCrashlytics.getInstance().log(new Date().getTime() + ": Thread:<" + Thread.currentThread().getName() + "> " + tag + " : " + message);
if (ex != null) {
FirebaseCrashlytics.getInstance().recordException(ex);
}
}catch (Exception ex2){
try {
FirebaseCrashlytics.getInstance().recordException(ex2);
}catch (Exception ex3){
//keep the APP from crashing
}
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>

</network-security-config>
11 changes: 10 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'

}
google()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath 'com.google.gms:google-services:4.3.8'
classpath 'com.google.firebase:perf-plugin:1.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down