NTP-28342 | Alfred Version Bump (#1073)

This commit is contained in:
Mantri Ramkishor
2025-02-05 16:41:39 +05:30
committed by GitHub
parent 53c8664ebc
commit d127a61046
5 changed files with 87 additions and 87 deletions

View File

@@ -214,7 +214,7 @@ dependencies {
implementation "com.github.anrwatchdog:anrwatchdog:1.4.0"
implementation 'com.google.android.gms:play-services-location:21.3.0'
implementation 'com.navi.android:alfred:1.15.0-20240905.065147-1'
implementation 'com.navi.android:alfred:2.1.2-cosmos'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation(platform("com.google.firebase:firebase-bom:32.7.0"))

View File

@@ -2,13 +2,11 @@ package com.avapp;
import static com.avapp.MainApplication.isAlfredEnabledFromFirebase;
import com.avapp.utils.AlfredFirebaseHelper;
import com.avapp.utils.FirebaseRemoteConfigHelper;
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.CommonUtilsKt;
import android.os.Bundle;
@@ -17,11 +15,7 @@ import android.view.MotionEvent;
import androidx.core.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity implements AlfredFirebaseHelper {
private static int appInForegroundCounter = 0;
private boolean cruiseApiCalled = false;
public static boolean hasAlfredRecordingStarted = false;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
@@ -36,7 +30,6 @@ public class MainActivity extends ReactActivity implements AlfredFirebaseHelper
protected void onCreate(Bundle savedInstanceState) {
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
super.onCreate(null);
FirebaseRemoteConfigHelper.setAlfredFirebaseHelper(this);
}
/**
@@ -72,68 +65,9 @@ public class MainActivity extends ReactActivity implements AlfredFirebaseHelper
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (isAlfredEnabledFromFirebase && AlfredManager.INSTANCE.isAlfredRecordingEnabled() && cruiseApiCalled) {
if (isAlfredEnabledFromFirebase) {
AlfredManager.INSTANCE.handleTouchEvent(ev, BuildConfig.APP_NAME, BuildConfig.APP_NAME);
}
return super.dispatchTouchEvent(ev);
}
@Override
protected void onStart() {
super.onStart();
appInForegroundCounter++;
}
@Override
protected void onResume() {
super.onResume();
if (isAlfredEnabledFromFirebase && !hasAlfredRecordingStarted) {
callCruiseAndStartAlfredRecording();
}
}
@Override
protected void onStop() {
super.onStop();
appInForegroundCounter--;
if (isAlfredEnabledFromFirebase && AlfredManager.INSTANCE.isAlfredRecordingEnabled() && cruiseApiCalled) {
if (!isAppInForeground()) {
AlfredManager.INSTANCE.stopRecording();
hasAlfredRecordingStarted = false;
}
}
}
public static Boolean isAppInForeground() {
return appInForegroundCounter >= 1;
}
@Override
public void callCruiseAndStartAlfredRecording() {
if (cruiseApiCalled) {
startAlfredRecording();
} else {
AlfredManager.INSTANCE.getAlfredCruiseInfo(response -> {
cruiseApiCalled = true;
startAlfredRecording();
return null;
});
}
}
public void startAlfredRecording() {
if (AlfredManager.INSTANCE.isAlfredRecordingEnabled() && !hasAlfredRecordingStarted) {
try {
AlfredManager.INSTANCE.onActivityResumed(
BuildConfig.APP_NAME,
BuildConfig.APP_NAME,
this,
this.getApplicationContext()
);
hasAlfredRecordingStarted = true;
} catch (Exception e) {
CommonUtilsKt.log(e);
}
}
}
}

View File

@@ -6,6 +6,7 @@ import static com.avapp.utils.Constants.METHOD_NAME;
import static com.avapp.utils.Constants.STACK_TRACE;
import static com.google.firebase.analytics.FirebaseAnalytics.Param.SCREEN_NAME;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
@@ -34,18 +35,20 @@ import com.microsoft.codepush.react.CodePush;
import com.navi.alfred.AlfredConfig;
import com.navi.alfred.AlfredManager;
import com.navi.alfred.network.AlfredApiLogsManager;
import com.navi.alfred.utils.CommonUtilsKt;
import com.navi.pulse.PulseManager;
import com.navi.pulse.PulseSDKConfig;
import android.database.CursorWindow;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.Map;
public class MainApplication extends Application implements ReactApplication {
public class MainApplication extends Application implements ReactApplication, Application.ActivityLifecycleCallbacks {
public static boolean isAlfredEnabledFromFirebase = false;
public static int appForegroundCounter = 0;
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
@@ -100,6 +103,7 @@ public class MainApplication extends Application implements ReactApplication {
@Override
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(this);
// If you opted-in for the New Architecture, we enable the TurboModule system
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
FirebaseRemoteConfigHelper.init();
@@ -111,6 +115,11 @@ public class MainApplication extends Application implements ReactApplication {
alfredConfig.enablePixelCopy(false);
AlfredManager.INSTANCE.init(alfredConfig, this, 27, "Critical Journey is active");
AlfredApiLogsManager.INSTANCE.init(new AlfredApiLogsProviderImpl());
if (isAlfredEnabledFromFirebase) {
AlfredManager.INSTANCE.getAlfredCruiseInfo(response -> {
return null;
});
}
PulseSDKConfig.Configuration pulseConfig = new PulseSDKConfig.Configuration.Builder()
.setAppName("collections-agent-app")
.setAppVersion(String.valueOf(BuildConfig.VERSION_CODE))
@@ -165,11 +174,11 @@ public class MainApplication extends Application implements ReactApplication {
anrEventProperties.put(SCREEN_NAME, BuildConfig.APP_NAME);
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, MainActivity.isAppInForeground().toString());
anrEventProperties.put(APP_IN_FOREGROUND, String.valueOf(isAppInForeground()));
if (isAlfredEnabledFromFirebase && AlfredManager.INSTANCE.isAlfredRecordingEnabled()
&& alfredConfig.getAnrEnableStatus() && MainActivity.isAppInForeground()) {
anrEventProperties.put(STACK_TRACE, error.getCause().getStackTrace()[0].toString());
&& alfredConfig.getAnrEnableStatus() && isAppInForeground()) {
anrEventProperties.put(STACK_TRACE, "ANR_OCCURRED");
if ("release".equals(BuildConfig.BUILD_TYPE)) {
PulseManager.INSTANCE.trackEvent("COSMOS_ANR", anrEventProperties);
}
@@ -192,10 +201,10 @@ public class MainApplication extends Application implements ReactApplication {
crashEventProperties.put(SCREEN_NAME, BuildConfig.APP_NAME);
crashEventProperties.put(METHOD_NAME, exception.getStackTrace()[0].getMethodName());
crashEventProperties.put(LINE_NUMBER, String.valueOf(exception.getStackTrace()[0].getLineNumber()));
crashEventProperties.put(APP_IN_FOREGROUND, MainActivity.isAppInForeground().toString());
crashEventProperties.put(APP_IN_FOREGROUND, String.valueOf(isAppInForeground()));
if (isAlfredEnabledFromFirebase && AlfredManager.INSTANCE.isAlfredRecordingEnabled()
&& alfredConfig.getCrashEnableStatus() && MainActivity.isAppInForeground()) {
&& alfredConfig.getCrashEnableStatus() && isAppInForeground()) {
StackTraceElement stackTraceElement = exception.getStackTrace()[0];
if (stackTraceElement != null) {
crashEventProperties.put(STACK_TRACE, stackTraceElement.toString());
@@ -212,4 +221,63 @@ public class MainApplication extends Application implements ReactApplication {
}
});
}
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
}
@Override
public void onActivityStarted(@NonNull Activity activity) {
appForegroundCounter++;
}
@Override
public void onActivityResumed(@NonNull Activity activity) {
if (isAppInForeground() && isAlfredEnabledFromFirebase) {
alfredOnActivityResumed(activity);
}
}
private void alfredOnActivityResumed(Activity activity) {
if(isAlfredEnabledFromFirebase) {
try {
AlfredManager.INSTANCE.onActivityResumed(
BuildConfig.APP_NAME,
BuildConfig.APP_NAME,
activity,
getApplicationContext()
);
} catch (Exception e) {
CommonUtilsKt.log(e);
}
}
}
private static boolean isAppInForeground() {
return appForegroundCounter >= 1;
}
@Override
public void onActivityPaused(@NonNull Activity activity) {
}
@Override
public void onActivityStopped(@NonNull Activity activity) {
appForegroundCounter--;
if (appForegroundCounter == 0 && isAlfredEnabledFromFirebase) {
AlfredManager.INSTANCE.stopRecording();
}
}
@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
}
@Override
public void onActivityDestroyed(@NonNull Activity activity) {
}
}

View File

@@ -1,5 +1,5 @@
package com.avapp.utils;
public interface AlfredFirebaseHelper {
void callCruiseAndStartAlfredRecording();
void startAlfredRecording();
}

View File

@@ -1,6 +1,5 @@
package com.avapp.utils;
import static com.avapp.MainActivity.hasAlfredRecordingStarted;
import static com.avapp.MainApplication.isAlfredEnabledFromFirebase;
@@ -9,17 +8,14 @@ import com.avapp.R;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
import com.navi.alfred.AlfredManager;
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 final String ALFRED_ENABLED = "ALFRED_ENABLED";
public static final String IS_IMAGE_SYNCING_REQUIRED = "IS_IMAGE_SYNCING_REQUIRED";
private static AlfredFirebaseHelper alfredFirebaseHelper;
public static void setAlfredFirebaseHelper(AlfredFirebaseHelper alfredFirebaseHelper) {
@@ -37,9 +33,11 @@ public class FirebaseRemoteConfigHelper {
remoteConfig.setDefaultsAsync(R.xml.default_xml_config);
remoteConfig.fetchAndActivate().addOnCompleteListener(task -> {
isAlfredEnabledFromFirebase = FirebaseRemoteConfigHelper.getBoolean(ALFRED_ENABLED);
if (alfredFirebaseHelper != null && isAlfredEnabledFromFirebase && !hasAlfredRecordingStarted) {
alfredFirebaseHelper.callCruiseAndStartAlfredRecording();
}
if (isAlfredEnabledFromFirebase) {
AlfredManager.INSTANCE.getAlfredCruiseInfo(response -> {
return null;
});
}
});
return remoteConfig;
}