Added firebase remote config
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
apply plugin: "com.android.application"
|
||||
apply plugin: "com.google.gms.google-services"
|
||||
apply plugin: "com.google.firebase.crashlytics"
|
||||
import com.android.build.OutputFile
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
@@ -307,10 +308,14 @@ dependencies {
|
||||
|
||||
implementation 'com.navi.medici:alfred:navi_v1.0.0-20230913.133908-19'
|
||||
|
||||
implementation(platform("com.google.firebase:firebase-bom:32.2.3"))
|
||||
|
||||
//noinspection GradleDynamicVersion
|
||||
implementation "com.facebook.react:react-native:+" // From node_modules
|
||||
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
||||
implementation("com.google.firebase:firebase-config-ktx")
|
||||
implementation("com.google.firebase:firebase-analytics-ktx")
|
||||
|
||||
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
|
||||
exclude group:'com.facebook.fbjni'
|
||||
|
||||
@@ -39,33 +39,33 @@ public class MainActivity extends ReactActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
AlfredManager.INSTANCE.getAlfredCruiseInfo(() -> {
|
||||
Log.d("alfred", "Alfred onResume getAlfredCruiseInfo successful");
|
||||
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
|
||||
try {
|
||||
Log.d("alfred", "Alfred onResume startRecording started");
|
||||
AlfredManager.INSTANCE.startRecording(
|
||||
this,
|
||||
getWindow().getDecorView().getRootView(),
|
||||
"cosmos",
|
||||
"cosmos",
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
UtilsKt.log(e);
|
||||
AlfredManager.INSTANCE.getAlfredCruiseInfo(() -> {
|
||||
Log.d("alfred", "Alfred onResume getAlfredCruiseInfo successful");
|
||||
if (AlfredManager.config != null && AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
|
||||
try {
|
||||
Log.d("alfred", "Alfred onResume startRecording started");
|
||||
AlfredManager.INSTANCE.startRecording(
|
||||
this,
|
||||
getWindow().getDecorView().getRootView(),
|
||||
"cosmos",
|
||||
"cosmos",
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
UtilsKt.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
|
||||
View appBackgroundView = LayoutInflater.from(this).inflate(R.layout.app_background_screen, null);
|
||||
AlfredManager.INSTANCE.measureInflatedView(appBackgroundView);
|
||||
AlfredManager.INSTANCE.stopRecording(appBackgroundView);
|
||||
}
|
||||
if (AlfredManager.config != null && AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
|
||||
View appBackgroundView = LayoutInflater.from(this).inflate(R.layout.app_background_screen, null);
|
||||
AlfredManager.INSTANCE.measureInflatedView(appBackgroundView);
|
||||
AlfredManager.INSTANCE.stopRecording(appBackgroundView);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import static com.google.firebase.analytics.FirebaseAnalytics.Param.SCREEN_NAME;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.avapp.utils.FirebaseRemoteConfigHelper;
|
||||
import com.facebook.react.PackageList;
|
||||
import com.facebook.react.ReactApplication;
|
||||
import com.facebook.react.ReactInstanceManager;
|
||||
@@ -16,7 +18,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.anrwatchdog.ANRError;
|
||||
import com.github.anrwatchdog.ANRWatchDog;
|
||||
import com.microsoft.codepush.react.CodePush;
|
||||
import com.navi.alfred.AlfredConfig;
|
||||
@@ -77,69 +78,71 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
super.onCreate();
|
||||
// If you opted-in for the New Architecture, we enable the TurboModule system
|
||||
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
||||
FirebaseRemoteConfigHelper.init();
|
||||
SoLoader.init(this, /* native exopackage */ false);
|
||||
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
||||
|
||||
Log.d("Alfred", "FirebaseRemoteConfigHelper Alfred enabled");
|
||||
// AlfredConfig alfredConfig = new AlfredConfig("Cosmos", String.valueOf(BuildConfig.VERSION_CODE), BuildConfig.VERSION_NAME, BuildConfig.BUILD_FLAVOR);
|
||||
AlfredConfig alfredConfig = new AlfredConfig("AVAPP", "336", "4.0.0","qa");
|
||||
AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext());
|
||||
AlfredConfig alfredConfig = new AlfredConfig("AVAPP", "336", "4.0.0", "qa");
|
||||
AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext());
|
||||
|
||||
new ANRWatchDog()
|
||||
.setIgnoreDebugger(true)
|
||||
.setReportMainThreadOnly()
|
||||
.setANRListener(error -> {
|
||||
if (error.getCause().getStackTrace().length == 0) {
|
||||
return;
|
||||
new ANRWatchDog()
|
||||
.setIgnoreDebugger(true)
|
||||
.setReportMainThreadOnly()
|
||||
.setANRListener(error -> {
|
||||
if (error.getCause().getStackTrace().length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
String className = error.getCause().getStackTrace()[0].getClassName();
|
||||
Map<String, String> anrEventProperties = new HashMap<>();
|
||||
anrEventProperties.put(SCREEN_NAME, "Cosmos");
|
||||
anrEventProperties.put("METHOD_NAME", error.getCause().getStackTrace()[0].getMethodName());
|
||||
anrEventProperties.put("LINE_NUMBER", String.valueOf(error.getCause().getStackTrace()[0].getLineNumber()));
|
||||
anrEventProperties.put("APP_IN_FOREGROUND", String.valueOf(1));
|
||||
|
||||
if (AlfredManager.config != null && AlfredManager.config.getAlfredStatus() && AlfredManager.config.getAnrEnableStatus()) {
|
||||
anrEventProperties.put("STACK_TRACE", error.getCause().getStackTrace()[0].toString());
|
||||
View anrView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.anr_screen, null);
|
||||
AlfredManager.INSTANCE.measureInflatedView(anrView);
|
||||
AlfredManager.INSTANCE.handleAnrEvent(anrEventProperties, anrView, SCREEN_NAME);
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
// Crash Reporting to backend
|
||||
Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> {
|
||||
if ((exception.getStackTrace() == null) || (exception.getStackTrace().length == 0)) {
|
||||
if (defaultHandler != null) {
|
||||
defaultHandler.uncaughtException(thread, exception);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Map<String, String> crashEventProperties = new HashMap<>();
|
||||
crashEventProperties.put("SCREEN_NAME", "Cosmos");
|
||||
crashEventProperties.put("METHOD_NAME", exception.getStackTrace()[0].getMethodName());
|
||||
crashEventProperties.put("LINE_NUMBER", String.valueOf(exception.getStackTrace()[0].getLineNumber()));
|
||||
crashEventProperties.put("APP_IN_FOREGROUND", String.valueOf(1));
|
||||
|
||||
String className = error.getCause().getStackTrace()[0].getClassName();
|
||||
Map<String, String> anrEventProperties = new HashMap<>();
|
||||
anrEventProperties.put("SCREEN_NAME", "Cosmos");
|
||||
anrEventProperties.put("METHOD_NAME", error.getCause().getStackTrace()[0].getMethodName());
|
||||
anrEventProperties.put("LINE_NUMBER", String.valueOf(error.getCause().getStackTrace()[0].getLineNumber()));
|
||||
anrEventProperties.put("APP_IN_FOREGROUND", String.valueOf(1));
|
||||
if ((AlfredManager.config != null && AlfredManager.config.getAlfredStatus() && AlfredManager.config.getCrashEnableStatus())) {
|
||||
StackTraceElement stackTraceElement = exception.getStackTrace()[0];
|
||||
if (stackTraceElement != null) {
|
||||
crashEventProperties.put("STACK_TRACE", stackTraceElement.toString());
|
||||
}
|
||||
|
||||
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getAnrEnableStatus()) {
|
||||
anrEventProperties.put("STACK_TRACE", error.getCause().getStackTrace()[0].toString());
|
||||
View anrView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.anr_screen, null);
|
||||
AlfredManager.INSTANCE.measureInflatedView(anrView);
|
||||
AlfredManager.INSTANCE.handleAnrEvent(anrEventProperties, anrView, SCREEN_NAME);
|
||||
View crashView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.crash_screen, null);
|
||||
AlfredManager.INSTANCE.measureInflatedView(crashView);
|
||||
AlfredManager.INSTANCE.handleCrashEvent(crashEventProperties, crashView.getRootView(), "Cosmos");
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
// Crash Reporting to backend
|
||||
Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> {
|
||||
if ((exception.getStackTrace() == null) || (exception.getStackTrace().length == 0)) {
|
||||
if (defaultHandler != null) {
|
||||
defaultHandler.uncaughtException(thread, exception);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Map<String, String> crashEventProperties = new HashMap<>();
|
||||
crashEventProperties.put("SCREEN_NAME", "Cosmos");
|
||||
crashEventProperties.put("METHOD_NAME", exception.getStackTrace()[0].getMethodName());
|
||||
crashEventProperties.put("LINE_NUMBER", String.valueOf(exception.getStackTrace()[0].getLineNumber()));
|
||||
crashEventProperties.put("APP_IN_FOREGROUND", String.valueOf(1));
|
||||
|
||||
if ((AlfredManager.config.getAlfredStatus() && AlfredManager.config.getCrashEnableStatus())) {
|
||||
StackTraceElement stackTraceElement = exception.getStackTrace()[0];
|
||||
if (stackTraceElement != null) {
|
||||
crashEventProperties.put("STACK_TRACE", stackTraceElement.toString());
|
||||
} finally {
|
||||
if (defaultHandler != null) {
|
||||
defaultHandler.uncaughtException(thread, exception);
|
||||
}
|
||||
|
||||
View crashView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.crash_screen, null);
|
||||
AlfredManager.INSTANCE.measureInflatedView(crashView);
|
||||
AlfredManager.INSTANCE.handleCrashEvent(crashEventProperties, crashView.getRootView(), "Cosmos");
|
||||
}
|
||||
} finally {
|
||||
if (defaultHandler != null) {
|
||||
defaultHandler.uncaughtException(thread, exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066
|
||||
try {
|
||||
|
||||
5
android/app/src/main/java/com/avapp/utils/Constants.java
Normal file
5
android/app/src/main/java/com/avapp/utils/Constants.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package com.avapp.utils;
|
||||
|
||||
public class Constants {
|
||||
public static final String SCREEN_NAME = "SCREEN_NAME";
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.avapp.utils;
|
||||
|
||||
import com.avapp.BuildConfig;
|
||||
import com.avapp.R;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
|
||||
|
||||
public class FirebaseRemoteConfigHelper {
|
||||
|
||||
private static FirebaseRemoteConfig remoteConfig;
|
||||
private static final long CONFIG_SYNC_INTERVAL = 60 * 60;
|
||||
|
||||
public static final String DISABLE_ALFRED_LOGS = "DISABLE_ALFRED_LOGS";
|
||||
|
||||
public static void init() {
|
||||
remoteConfig = getFirebaseRemoteConfig();
|
||||
}
|
||||
|
||||
private static FirebaseRemoteConfig getFirebaseRemoteConfig() {
|
||||
FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();
|
||||
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(BuildConfig.DEBUG ? 0 : CONFIG_SYNC_INTERVAL).build();
|
||||
remoteConfig.setConfigSettingsAsync(configSettings);
|
||||
remoteConfig.setDefaultsAsync(R.xml.default_remote_config);
|
||||
remoteConfig.fetchAndActivate().addOnCompleteListener(task -> {
|
||||
});
|
||||
return remoteConfig;
|
||||
}
|
||||
|
||||
private static FirebaseRemoteConfigValue getRawValue(String key) {
|
||||
try {
|
||||
FirebaseRemoteConfigValue rawValue = remoteConfig.getValue(key);
|
||||
return rawValue.getSource() == FirebaseRemoteConfig.VALUE_SOURCE_STATIC ? null : rawValue;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean getRawBoolean(String key) {
|
||||
FirebaseRemoteConfigValue rawValue = getRawValue(key);
|
||||
return rawValue != null ? rawValue.asBoolean() : null;
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return remoteConfig.getString(key);
|
||||
} catch (Exception e) {
|
||||
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_STRING;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getBoolean(String key) {
|
||||
try {
|
||||
return remoteConfig.getBoolean(key);
|
||||
} catch (Exception e) {
|
||||
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_BOOLEAN;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDouble(String key) {
|
||||
try {
|
||||
return remoteConfig.getDouble(key);
|
||||
} catch (Exception e) {
|
||||
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
|
||||
}
|
||||
}
|
||||
|
||||
public static long getLong(String key) {
|
||||
try {
|
||||
return remoteConfig.getLong(key);
|
||||
} catch (Exception e) {
|
||||
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_LONG;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
android/app/src/main/res/xml/default_remote_config.xml
Normal file
15
android/app/src/main/res/xml/default_remote_config.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~
|
||||
~ * Copyright © 2019-2023 by Navi Technologies Limited
|
||||
~ * All rights reserved. Strictly confidential
|
||||
~
|
||||
-->
|
||||
|
||||
<defaultsMap>
|
||||
<entry>
|
||||
<key>ALFRED_ENABLED</key>
|
||||
<value>true</value>
|
||||
</entry>
|
||||
</defaultsMap>
|
||||
Reference in New Issue
Block a user