From 033df22b9238e4e713a393c467f209ce30558078 Mon Sep 17 00:00:00 2001 From: Girish Suragani Date: Fri, 8 Sep 2023 19:35:19 +0530 Subject: [PATCH 01/44] Alfred sdk integration --- App.tsx | 2 ++ android/app/build.gradle | 1 + .../src/main/java/com/avapp/DeviceUtilsModule.java | 8 ++++++++ .../app/src/main/java/com/avapp/MainActivity.java | 8 +++++++- .../src/main/java/com/avapp/MainApplication.java | 7 +++++-- android/build.gradle | 14 ++++++++++++++ src/components/utlis/DeviceUtils.ts | 4 ++++ 7 files changed, 41 insertions(+), 3 deletions(-) diff --git a/App.tsx b/App.tsx index 07a85922..32ad2867 100644 --- a/App.tsx +++ b/App.tsx @@ -38,6 +38,7 @@ import { import usePolling from './src/hooks/usePolling'; import { MILLISECONDS_IN_A_SECOND } from './RN-UI-LIB/src/utlis/common'; import analytics from '@react-native-firebase/analytics'; +import { blah } from './src/components/utlis/DeviceUtils'; initSentry(); @@ -113,6 +114,7 @@ function App() { }); React.useEffect(() => { + blah(); askForPermissions(); const appStateChange = AppState.addEventListener('change', async (change) => { handleAppStateChange(change); diff --git a/android/app/build.gradle b/android/app/build.gradle index 848437fe..416e6e9f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -264,6 +264,7 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "com.navi.medici:alfred:navi_v1.0.0-20230908.112959-9" //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules diff --git a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java index 56c69465..6d4fbded 100644 --- a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java +++ b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java @@ -14,7 +14,10 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import com.navi.alfred.AlfredManager; + import android.content.pm.PackageInfo; +import android.view.View; import org.json.JSONArray; import org.json.JSONObject; @@ -77,4 +80,9 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule implements Act promise.reject( err); } } + + @ReactMethod + public void startRecording(View rootView) { + AlfredManager.INSTANCE.startRecording(RNContext, rootView, "", "", null); + } } diff --git a/android/app/src/main/java/com/avapp/MainActivity.java b/android/app/src/main/java/com/avapp/MainActivity.java index 9ac0a557..984dc8a7 100644 --- a/android/app/src/main/java/com/avapp/MainActivity.java +++ b/android/app/src/main/java/com/avapp/MainActivity.java @@ -3,6 +3,8 @@ package com.avapp; import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; import com.facebook.react.ReactRootView; +import com.navi.alfred.AlfredManager; + import android.os.Bundle; public class MainActivity extends ReactActivity { @@ -23,7 +25,11 @@ public class MainActivity extends ReactActivity { super.onCreate(null); } - + @Override + protected void onResume() { + super.onResume(); + AlfredManager.INSTANCE.startRecording(getApplicationContext(), getWindow().getDecorView().getRootView(), "", "", null); + } /** * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index 809273f1..280f9485 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -15,6 +15,9 @@ import com.avapp.newarchitecture.MainApplicationReactNativeHost; import java.lang.reflect.InvocationTargetException; import java.util.List; import com.microsoft.codepush.react.CodePush; +import com.navi.alfred.AlfredConfig; +import com.navi.alfred.AlfredManager; + import android.database.CursorWindow; import java.lang.reflect.Field; @@ -70,8 +73,8 @@ public class MainApplication extends Application implements ReactApplication { SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - - + AlfredConfig alfredConfig = new AlfredConfig(); + AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext()); // https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066 try { diff --git a/android/build.gradle b/android/build.gradle index 09f999b2..0486ddbb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -42,6 +42,20 @@ allprojects { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } + maven { + url 'https://nexus.cmd.navi-tech.in/repository/maven-snapshots' + credentials { + username 'nexus-user' + password 'nexus-user' + } + } + maven { + url 'https://nexus.cmd.navi-tech.in/repository/maven-releases' + credentials { + username 'nexus-user' + password 'nexus-user' + } + } mavenCentral { // We don't want to fetch react-native from Maven Central as there are // older versions over there. diff --git a/src/components/utlis/DeviceUtils.ts b/src/components/utlis/DeviceUtils.ts index 5443d7d7..58cd7edc 100644 --- a/src/components/utlis/DeviceUtils.ts +++ b/src/components/utlis/DeviceUtils.ts @@ -7,3 +7,7 @@ export const locationEnabled = (): Promise => DeviceUtilsModule.isLocat // returns array of all the installed packages. export const getAllInstalledApp = (): Promise => DeviceUtilsModule.getAllInstalledApp(); + +export const blah = () => { + DeviceUtilsModule.startRecording(); +}; From e3ae160ffd079f7b66620f33bf85e6cb3c22ec5a Mon Sep 17 00:00:00 2001 From: Sayed Owais Ali Date: Mon, 11 Sep 2023 19:01:59 +0530 Subject: [PATCH 02/44] added start and stop recording code --- android/app/build.gradle | 3 ++- .../src/main/java/com/avapp/DeviceUtilsModule.java | 4 ++-- android/app/src/main/java/com/avapp/MainActivity.java | 11 ++++++++++- .../app/src/main/java/com/avapp/MainApplication.java | 2 +- src/screens/auth/AuthRouter.tsx | 4 ++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 416e6e9f..fdb05f7d 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -264,7 +264,7 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "com.navi.medici:alfred:navi_v1.0.0-20230908.112959-9" + implementation 'com.navi.medici:alfred:navi_v1.0.0-20230911.101354-15' //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules @@ -328,3 +328,4 @@ def isNewArchitectureEnabled() { } apply plugin: 'com.google.gms.google-services' + diff --git a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java index 6d4fbded..0752423a 100644 --- a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java +++ b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java @@ -82,7 +82,7 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule implements Act } @ReactMethod - public void startRecording(View rootView) { - AlfredManager.INSTANCE.startRecording(RNContext, rootView, "", "", null); + public void startRecording() { +// AlfredManager.INSTANCE.startRecording(RNContext, rootView, "", "", null); } } diff --git a/android/app/src/main/java/com/avapp/MainActivity.java b/android/app/src/main/java/com/avapp/MainActivity.java index 984dc8a7..6769893a 100644 --- a/android/app/src/main/java/com/avapp/MainActivity.java +++ b/android/app/src/main/java/com/avapp/MainActivity.java @@ -28,9 +28,18 @@ public class MainActivity extends ReactActivity { @Override protected void onResume() { super.onResume(); - AlfredManager.INSTANCE.startRecording(getApplicationContext(), getWindow().getDecorView().getRootView(), "", "", null); + AlfredManager.config.setEnableRecordingStatus(true); + AlfredManager.config.setAlfredStatus(true); + AlfredManager.INSTANCE.startRecording(this, getWindow().getDecorView().getRootView(), "cosmos", "cosmos", null); } + @Override + protected void onStop() { + super.onStop(); + AlfredManager.INSTANCE.stopRecording(this.getWindow().getDecorView().getRootView()); + } + + /** * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index 280f9485..9253788a 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -73,7 +73,7 @@ public class MainApplication extends Application implements ReactApplication { SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - AlfredConfig alfredConfig = new AlfredConfig(); + AlfredConfig alfredConfig = new AlfredConfig("Cosmos", "336", "4.0.0","qa"); AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext()); // https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066 diff --git a/src/screens/auth/AuthRouter.tsx b/src/screens/auth/AuthRouter.tsx index 2c342ac2..1484db39 100644 --- a/src/screens/auth/AuthRouter.tsx +++ b/src/screens/auth/AuthRouter.tsx @@ -62,11 +62,11 @@ const AuthRouter = () => { useFCM(); return isLoggedIn ? ( - + // - + // ) : ( ); From 2c58afcb27ee34bdef2e739a9d5829dde82eed60 Mon Sep 17 00:00:00 2001 From: Sayed Owais Ali Date: Tue, 12 Sep 2023 17:07:18 +0530 Subject: [PATCH 03/44] added crash, anr, background screens. added anr watchdog --- android/app/build.gradle | 2 + .../java/com/avapp/DeviceUtilsModule.java | 5 +++ .../src/main/java/com/avapp/MainActivity.java | 14 +++++-- .../main/java/com/avapp/MainApplication.java | 40 +++++++++++++++++-- .../app/src/main/res/layout/anr_screen.xml | 27 +++++++++++++ .../main/res/layout/app_background_screen.xml | 28 +++++++++++++ .../app/src/main/res/layout/crash_screen.xml | 27 +++++++++++++ 7 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 android/app/src/main/res/layout/anr_screen.xml create mode 100644 android/app/src/main/res/layout/app_background_screen.xml create mode 100644 android/app/src/main/res/layout/crash_screen.xml diff --git a/android/app/build.gradle b/android/app/build.gradle index fdb05f7d..538fa791 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -264,6 +264,8 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "com.github.anrwatchdog:anrwatchdog:1.4.0" + implementation 'com.navi.medici:alfred:navi_v1.0.0-20230911.101354-15' //noinspection GradleDynamicVersion diff --git a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java index 0752423a..aae1903b 100644 --- a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java +++ b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java @@ -85,4 +85,9 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule implements Act public void startRecording() { // AlfredManager.INSTANCE.startRecording(RNContext, rootView, "", "", null); } + + @ReactMethod + public void setUserId(String userId) { + AlfredManager.config.setUserId(userId); + } } diff --git a/android/app/src/main/java/com/avapp/MainActivity.java b/android/app/src/main/java/com/avapp/MainActivity.java index 6769893a..f10a80be 100644 --- a/android/app/src/main/java/com/avapp/MainActivity.java +++ b/android/app/src/main/java/com/avapp/MainActivity.java @@ -6,6 +6,14 @@ import com.facebook.react.ReactRootView; import com.navi.alfred.AlfredManager; import android.os.Bundle; +import android.provider.Settings; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import kotlinx.coroutines.AwaitKt; +import timber.log.Timber; public class MainActivity extends ReactActivity { @@ -28,15 +36,15 @@ public class MainActivity extends ReactActivity { @Override protected void onResume() { super.onResume(); - AlfredManager.config.setEnableRecordingStatus(true); - AlfredManager.config.setAlfredStatus(true); AlfredManager.INSTANCE.startRecording(this, getWindow().getDecorView().getRootView(), "cosmos", "cosmos", null); } @Override protected void onStop() { super.onStop(); - AlfredManager.INSTANCE.stopRecording(this.getWindow().getDecorView().getRootView()); + View appBackgroundView = LayoutInflater.from(this).inflate(R.layout.app_background_screen, null); + AlfredManager.INSTANCE.measureInflatedView(appBackgroundView); + AlfredManager.INSTANCE.stopRecording(appBackgroundView); } diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index 9253788a..41ad9459 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -1,6 +1,6 @@ package com.avapp; - +import static com.google.firebase.analytics.FirebaseAnalytics.Param.SCREEN_NAME; import android.app.Application; import android.content.Context; @@ -13,15 +13,22 @@ import com.facebook.react.config.ReactFeatureFlags; import com.facebook.soloader.SoLoader; import com.avapp.newarchitecture.MainApplicationReactNativeHost; 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; import com.navi.alfred.AlfredManager; import android.database.CursorWindow; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; + import java.lang.reflect.Field; - - +import java.util.Map; public class MainApplication extends Application implements ReactApplication { @@ -75,6 +82,33 @@ public class MainApplication extends Application implements ReactApplication { AlfredConfig alfredConfig = new AlfredConfig("Cosmos", "336", "4.0.0","qa"); AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext()); + alfredConfig.setEnableRecordingStatus(true); + alfredConfig.setAlfredStatus(true); + + new ANRWatchDog() + .setIgnoreDebugger(true) + .setReportMainThreadOnly() + .setANRListener(new ANRWatchDog.ANRListener() { + public void onAppNotResponding(ANRError error) { + if (error.getCause().getStackTrace().length == 0) { + return; + } + + String className = error.getCause().getStackTrace()[0].getClassName(); + Map anrEventProperties = new HashMap<>(); + //anrEventProperties.put(SCREEN_NAME, NaviTrackEvent.getCurrentScreenName() != null ? NaviTrackEvent.getCurrentScreenName() : className); + //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(isAppInForeground(MainApplication.this))); + + 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); + } + } + }).start(); // https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066 try { diff --git a/android/app/src/main/res/layout/anr_screen.xml b/android/app/src/main/res/layout/anr_screen.xml new file mode 100644 index 00000000..3915625a --- /dev/null +++ b/android/app/src/main/res/layout/anr_screen.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/app_background_screen.xml b/android/app/src/main/res/layout/app_background_screen.xml new file mode 100644 index 00000000..c6c6a45c --- /dev/null +++ b/android/app/src/main/res/layout/app_background_screen.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/crash_screen.xml b/android/app/src/main/res/layout/crash_screen.xml new file mode 100644 index 00000000..01e20ac6 --- /dev/null +++ b/android/app/src/main/res/layout/crash_screen.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + \ No newline at end of file From a67e1acee89a5d5fe11e47db33bddbcbbb3d55b8 Mon Sep 17 00:00:00 2001 From: Girish Suragani Date: Tue, 12 Sep 2023 17:18:46 +0530 Subject: [PATCH 04/44] Added alfred enable check --- android/app/build.gradle | 2 +- .../src/main/java/com/avapp/MainActivity.java | 18 +++++++++++++++--- .../main/java/com/avapp/MainApplication.java | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index fdb05f7d..ee9c932a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -264,7 +264,7 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation 'com.navi.medici:alfred:navi_v1.0.0-20230911.101354-15' + implementation 'com.navi.medici:alfred:navi_v1.0.0-20230912.094041-16' //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules diff --git a/android/app/src/main/java/com/avapp/MainActivity.java b/android/app/src/main/java/com/avapp/MainActivity.java index 6769893a..87333193 100644 --- a/android/app/src/main/java/com/avapp/MainActivity.java +++ b/android/app/src/main/java/com/avapp/MainActivity.java @@ -4,6 +4,7 @@ import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; import com.facebook.react.ReactRootView; import com.navi.alfred.AlfredManager; +import com.navi.alfred.utils.UtilsKt; import android.os.Bundle; @@ -28,15 +29,26 @@ public class MainActivity extends ReactActivity { @Override protected void onResume() { super.onResume(); - AlfredManager.config.setEnableRecordingStatus(true); - AlfredManager.config.setAlfredStatus(true); - AlfredManager.INSTANCE.startRecording(this, getWindow().getDecorView().getRootView(), "cosmos", "cosmos", null); + if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) { + try { + AlfredManager.INSTANCE.startRecording( + this, + getWindow().getDecorView().getRootView(), + "cosmos", + "cosmos", + null); + } catch (Exception e) { + UtilsKt.log(e); + } + } } @Override protected void onStop() { super.onStop(); + if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) { AlfredManager.INSTANCE.stopRecording(this.getWindow().getDecorView().getRootView()); + } } diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index 9253788a..9905a20d 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -73,7 +73,8 @@ public class MainApplication extends Application implements ReactApplication { SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - AlfredConfig alfredConfig = new AlfredConfig("Cosmos", "336", "4.0.0","qa"); +// AlfredConfig alfredConfig = new AlfredConfig("AVAPP", BuildConfig.VERSION_CODE.toString(), BuildConfig.VERSION_NAME, BuildConfig.BUILD_TYPE); + AlfredConfig alfredConfig = new AlfredConfig("AVAPP", "336", "4.0.0","qa"); AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext()); // https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066 From 48666a4d40b1dfec445b893d0577e398c1f82609 Mon Sep 17 00:00:00 2001 From: Sayed Owais Ali Date: Tue, 12 Sep 2023 18:23:21 +0530 Subject: [PATCH 05/44] fixed error in anr, background, crash screens --- .../java/com/avapp/DeviceUtilsModule.java | 1 - .../app/src/main/res/layout/anr_screen.xml | 15 +++---- .../main/res/layout/app_background_screen.xml | 40 ++++++++----------- .../app/src/main/res/layout/crash_screen.xml | 15 +++---- 4 files changed, 26 insertions(+), 45 deletions(-) diff --git a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java index aae1903b..f4cb80dc 100644 --- a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java +++ b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java @@ -17,7 +17,6 @@ import com.facebook.react.bridge.ReactMethod; import com.navi.alfred.AlfredManager; import android.content.pm.PackageInfo; -import android.view.View; import org.json.JSONArray; import org.json.JSONObject; diff --git a/android/app/src/main/res/layout/anr_screen.xml b/android/app/src/main/res/layout/anr_screen.xml index 3915625a..2ca593bd 100644 --- a/android/app/src/main/res/layout/anr_screen.xml +++ b/android/app/src/main/res/layout/anr_screen.xml @@ -1,14 +1,11 @@ - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/android/app/src/main/res/layout/app_background_screen.xml b/android/app/src/main/res/layout/app_background_screen.xml index c6c6a45c..498acdce 100644 --- a/android/app/src/main/res/layout/app_background_screen.xml +++ b/android/app/src/main/res/layout/app_background_screen.xml @@ -1,28 +1,20 @@ - + - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/android/app/src/main/res/layout/crash_screen.xml b/android/app/src/main/res/layout/crash_screen.xml index 01e20ac6..851e3f58 100644 --- a/android/app/src/main/res/layout/crash_screen.xml +++ b/android/app/src/main/res/layout/crash_screen.xml @@ -1,14 +1,11 @@ - - - - - - - \ No newline at end of file + \ No newline at end of file From ed393ea67190dac6dc2550587406a7825619b883 Mon Sep 17 00:00:00 2001 From: Sayed Owais Ali Date: Tue, 12 Sep 2023 18:52:10 +0530 Subject: [PATCH 06/44] added sww layout and bridges for sww and crash --- .../java/com/avapp/DeviceUtilsModule.java | 16 ++++++++++++++ .../app/src/main/res/layout/sww_screen.xml | 22 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 android/app/src/main/res/layout/sww_screen.xml diff --git a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java index f4cb80dc..687f518d 100644 --- a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java +++ b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java @@ -17,6 +17,8 @@ import com.facebook.react.bridge.ReactMethod; import com.navi.alfred.AlfredManager; import android.content.pm.PackageInfo; +import android.view.LayoutInflater; +import android.view.View; import org.json.JSONArray; import org.json.JSONObject; @@ -89,4 +91,18 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule implements Act public void setUserId(String userId) { AlfredManager.config.setUserId(userId); } + + @ReactMethod + public void handleCrashEvent(Context context) { + View appCrashView = LayoutInflater.from(context).inflate(R.layout.crash_screen, null); + AlfredManager.INSTANCE.measureInflatedView(appCrashView); + AlfredManager.INSTANCE.stopRecording(appCrashView); + } + + @ReactMethod + public void handleSwwEvent(Context context) { + View appSwwView = LayoutInflater.from(context).inflate(R.layout.sww_screen, null); + AlfredManager.INSTANCE.measureInflatedView(appSwwView); + AlfredManager.INSTANCE.stopRecording(appSwwView); + } } diff --git a/android/app/src/main/res/layout/sww_screen.xml b/android/app/src/main/res/layout/sww_screen.xml new file mode 100644 index 00000000..607c46e7 --- /dev/null +++ b/android/app/src/main/res/layout/sww_screen.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file From 25b75d1b8462bf5a7150eca3e54ea341ab21fa88 Mon Sep 17 00:00:00 2001 From: Girish Suragani Date: Wed, 13 Sep 2023 17:45:11 +0530 Subject: [PATCH 07/44] Added bridges, anr, crash, touch events --- App.tsx | 2 - android/app/build.gradle | 3 +- .../java/com/avapp/DeviceUtilsModule.java | 18 ++--- .../src/main/java/com/avapp/MainActivity.java | 37 +++++++--- .../main/java/com/avapp/MainApplication.java | 74 ++++++++++++++----- src/screens/allCases/index.tsx | 20 ++++- 6 files changed, 104 insertions(+), 50 deletions(-) diff --git a/App.tsx b/App.tsx index 32ad2867..07a85922 100644 --- a/App.tsx +++ b/App.tsx @@ -38,7 +38,6 @@ import { import usePolling from './src/hooks/usePolling'; import { MILLISECONDS_IN_A_SECOND } from './RN-UI-LIB/src/utlis/common'; import analytics from '@react-native-firebase/analytics'; -import { blah } from './src/components/utlis/DeviceUtils'; initSentry(); @@ -114,7 +113,6 @@ function App() { }); React.useEffect(() => { - blah(); askForPermissions(); const appStateChange = AppState.addEventListener('change', async (change) => { handleAppStateChange(change); diff --git a/android/app/build.gradle b/android/app/build.gradle index 58c97d4c..9a3df4c4 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -266,7 +266,8 @@ dependencies { implementation "com.github.anrwatchdog:anrwatchdog:1.4.0" - implementation 'com.navi.medici:alfred:navi_v1.0.0-20230912.094041-16' + + implementation 'com.navi.medici:alfred:navi_v1.0.0-20230913.074237-18' //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules diff --git a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java index 687f518d..e9d3c2a5 100644 --- a/android/app/src/main/java/com/avapp/DeviceUtilsModule.java +++ b/android/app/src/main/java/com/avapp/DeviceUtilsModule.java @@ -17,12 +17,12 @@ import com.facebook.react.bridge.ReactMethod; import com.navi.alfred.AlfredManager; import android.content.pm.PackageInfo; -import android.view.LayoutInflater; -import android.view.View; +import android.util.Log; import org.json.JSONArray; import org.json.JSONObject; +import java.util.HashMap; import java.util.List; public class DeviceUtilsModule extends ReactContextBaseJavaModule implements ActivityEventListener { @@ -92,17 +92,11 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule implements Act AlfredManager.config.setUserId(userId); } - @ReactMethod - public void handleCrashEvent(Context context) { - View appCrashView = LayoutInflater.from(context).inflate(R.layout.crash_screen, null); - AlfredManager.INSTANCE.measureInflatedView(appCrashView); - AlfredManager.INSTANCE.stopRecording(appCrashView); - } @ReactMethod - public void handleSwwEvent(Context context) { - View appSwwView = LayoutInflater.from(context).inflate(R.layout.sww_screen, null); - AlfredManager.INSTANCE.measureInflatedView(appSwwView); - AlfredManager.INSTANCE.stopRecording(appSwwView); + public void handleSWWEvent() { + HashMap h = new HashMap(); + Log.d("TAG","properties :" + "aman"); + AlfredManager.INSTANCE.handleSWWEvent("Cosmos", h); } } diff --git a/android/app/src/main/java/com/avapp/MainActivity.java b/android/app/src/main/java/com/avapp/MainActivity.java index abd8d494..2e8f43a3 100644 --- a/android/app/src/main/java/com/avapp/MainActivity.java +++ b/android/app/src/main/java/com/avapp/MainActivity.java @@ -7,7 +7,9 @@ import com.navi.alfred.AlfredManager; import com.navi.alfred.utils.UtilsKt; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; public class MainActivity extends ReactActivity { @@ -28,21 +30,32 @@ public class MainActivity extends ReactActivity { super.onCreate(null); } + @Override + public boolean onTouchEvent(MotionEvent event) { + AlfredManager.INSTANCE.handleTouchEvent(event, "Cosmos", "Cosmos"); + return super.onTouchEvent(event); + } + @Override protected void onResume() { super.onResume(); - if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) { - try { - 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.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; + }); } @Override @@ -51,7 +64,7 @@ public class MainActivity extends ReactActivity { 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(this.getWindow().getDecorView().getRootView()); + AlfredManager.INSTANCE.stopRecording(appBackgroundView); } } diff --git a/android/app/src/main/java/com/avapp/MainApplication.java b/android/app/src/main/java/com/avapp/MainApplication.java index f866b577..7fc8eec9 100644 --- a/android/app/src/main/java/com/avapp/MainApplication.java +++ b/android/app/src/main/java/com/avapp/MainApplication.java @@ -80,37 +80,71 @@ public class MainApplication extends Application implements ReactApplication { SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); -// AlfredConfig alfredConfig = new AlfredConfig("AVAPP", BuildConfig.VERSION_CODE.toString(), BuildConfig.VERSION_NAME, BuildConfig.BUILD_TYPE); +// AlfredConfig alfredConfig = new AlfredConfig("AVAPP", BuildConfig.VERSION_CODE, BuildConfig.VERSION_NAME, BuildConfig.BUILD_TYPE); AlfredConfig alfredConfig = new AlfredConfig("AVAPP", "336", "4.0.0","qa"); AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext()); - alfredConfig.setEnableRecordingStatus(true); - alfredConfig.setAlfredStatus(true); new ANRWatchDog() .setIgnoreDebugger(true) .setReportMainThreadOnly() - .setANRListener(new ANRWatchDog.ANRListener() { - public void onAppNotResponding(ANRError error) { - if (error.getCause().getStackTrace().length == 0) { - return; - } + .setANRListener(error -> { + if (error.getCause().getStackTrace().length == 0) { + return; + } - String className = error.getCause().getStackTrace()[0].getClassName(); - Map anrEventProperties = new HashMap<>(); - //anrEventProperties.put(SCREEN_NAME, NaviTrackEvent.getCurrentScreenName() != null ? NaviTrackEvent.getCurrentScreenName() : className); - //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(isAppInForeground(MainApplication.this))); + String className = error.getCause().getStackTrace()[0].getClassName(); + Map 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.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); - } + 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); } }).start(); + + // Crash Reporting to backend + Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread thread, Throwable exception) { + if ((exception.getStackTrace() == null) || (exception.getStackTrace().length == 0)) { + if (defaultHandler != null) { + defaultHandler.uncaughtException(thread, exception); + } + return; + } + try { + Map 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()); + } + + 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 { Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize"); diff --git a/src/screens/allCases/index.tsx b/src/screens/allCases/index.tsx index 8046653a..a05e519a 100644 --- a/src/screens/allCases/index.tsx +++ b/src/screens/allCases/index.tsx @@ -22,6 +22,10 @@ import { addClickstreamEvent } from '../../services/clickstreamEventService'; import { CLICKSTREAM_EVENT_NAMES } from '../../common/Constants'; import { BOTTOM_TAB_ROUTES } from './constants'; import { getSelfieDocument } from '../../action/profileActions'; +import Button from '../../../RN-UI-LIB/src/components/Button'; +import EmptyList from './EmptyList'; +import { handleSwwEvent } from '../../components/utlis/DeviceUtils'; +import { data } from '../../../RN-UI-LIB/src/data'; const AllCasesMain = () => { const { pendingList, pinnedList, completedList, loading } = useAppSelector( @@ -71,15 +75,25 @@ const AllCasesMain = () => { dispatch(resetSelectedTodoList()); }, []); + const triggerWhileLoop = () => { + while (true) { + console.warn('while loop'); + } + }; + return ( - onTabPressHandler(e)} - /> - + /> */} + {/* */} + +