Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c947366 authored by Yash Garg's avatar Yash Garg 💬 Committed by Nishith Khanna
Browse files

refactor: add sentry integration and replace logging with Timber

parent b6bb2467
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -9,10 +9,13 @@ package foundation.e.bliss.utils

import android.util.Log as AndroidLog
import com.android.launcher3.BuildConfig
import timber.log.Timber

object Logger {
    private val isDebug = BuildConfig.DEBUG

    @JvmStatic fun plant() = Timber.plant(Timber.DebugTree())

    private fun log(
        tag: String,
        msg: String,
+3 −0
Original line number Diff line number Diff line
@@ -209,6 +209,7 @@ android {
        configureEach {
            resValue("string", "quickstep_component", "${applicationId}/com.android.launcher3.uioverrides.QuickstepLauncher")
            resValue("string", "launcher_component", "${applicationId}/com.android.launcher3.Launcher")
            buildConfigField("String", "SENTRY_DSN", "\"${System.getenv("SENTRY_DSN")}\"")
        }
    }

@@ -276,6 +277,8 @@ android {
        }
    }

    lintOptions { disable "LogNotTimber" }
    
    addFrameworkJar('framework-14.jar')
}

+32 −15
Original line number Diff line number Diff line
@@ -291,6 +291,8 @@ import foundation.e.bliss.multimode.MultiModeController;
import foundation.e.bliss.utils.Logger;
import foundation.e.bliss.widgets.RoundedWidgetView;
import foundation.e.bliss.widgets.WidgetsDbHelper;
import foundation.e.lib.telemetry.Telemetry;
import timber.log.Timber;

/**
 * Default launcher application.
@@ -442,6 +444,16 @@ public class Launcher extends StatefulActivity<LauncherState>
    @Override
    @TargetApi(Build.VERSION_CODES.S)
    protected void onCreate(Bundle savedInstanceState) {
        Logger.plant();

        if (!BuildConfig.DEBUG) {
            try {
                Telemetry.init(BuildConfig.SENTRY_DSN, getApplication(), true);
            } catch (Exception e) {
                Logger.e(TAG, "Failed to initialize Sentry");
            }
        }
        
        mStartupLatencyLogger = createStartupLatencyLogger(
                sIsNewProcess
                        ? LockedUserState.get(this).isUserUnlockedAtLauncherStartup()
@@ -483,7 +495,7 @@ public class Launcher extends StatefulActivity<LauncherState>
                    .build());
        }

        if (Utilities.IS_DEBUG_DEVICE && FeatureFlags.NOTIFY_CRASHES.get()) {
        if (FeatureFlags.NOTIFY_CRASHES.get()) {
            final String notificationChannelId = "com.android.launcher3.Debug";
            final String notificationChannelName = "Debug";
            final String notificationTag = "Debug";
@@ -497,6 +509,7 @@ public class Launcher extends StatefulActivity<LauncherState>
            Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
                String stackTrace = Log.getStackTraceString(throwable);

                if (Utilities.IS_DEBUG_DEVICE) {
                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, stackTrace);
@@ -510,7 +523,11 @@ public class Launcher extends StatefulActivity<LauncherState>
                            .setStyle(new Notification.BigTextStyle().bigText(stackTrace))
                            .addAction(android.R.drawable.ic_menu_share, "Share", sharePendingIntent)
                            .build();

                    notificationManager.notify(notificationTag, notificationId, notification);
                } else {
                    Timber.tag(TAG).e(throwable);
                }

                Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler =
                        Thread.getDefaultUncaughtExceptionHandler();