Search in sources :

Example 1 with ITransaction

use of io.sentry.ITransaction in project cooee-android-sdk by letscooee.

the class CooeeFactory method init.

public static synchronized void init(Context context) {
    if (initialized) {
        return;
    }
    appInfo = AppInfo.getInstance(context);
    deviceInfo = DeviceInfo.getInstance(context);
    manifestReader = ManifestReader.getInstance(context);
    sentryHelper = new SentryHelper(context, appInfo, manifestReader);
    sentryHelper.init();
    // Sentry should be initialized first
    ITransaction transaction = Sentry.startTransaction("CooeeFactory.init()", "task");
    baseHTTPService = new BaseHTTPService(context);
    // This is required in PendingTaskService (ultimately). TODO make this a strong dependency
    deviceAuthService = new DeviceAuthService(context, sentryHelper, manifestReader);
    deviceAuthService.populateUserDataFromStorage();
    pendingTaskService = new PendingTaskService(context, sentryHelper);
    runtimeData = RuntimeData.getInstance(context);
    sessionManager = SessionManager.getInstance(context);
    safeHTTPService = new SafeHTTPService(context, pendingTaskService, sessionManager, runtimeData);
    transaction.finish();
    initialized = true;
}
Also used : SafeHTTPService(com.letscooee.network.SafeHTTPService) DeviceAuthService(com.letscooee.retrofit.DeviceAuthService) SentryHelper(com.letscooee.utils.SentryHelper) ITransaction(io.sentry.ITransaction) BaseHTTPService(com.letscooee.network.BaseHTTPService) PendingTaskService(com.letscooee.room.task.PendingTaskService)

Example 2 with ITransaction

use of io.sentry.ITransaction in project NextDNSManager by mtverlee.

the class FirebaseNotifications method onNewToken.

@Override
@AddTrace(name = "on_new_token", enabled = true)
public void onNewToken(String token) {
    ITransaction FirebaseNotifications_on_new_token_transaction = Sentry.startTransaction("onNewToken()", "FirebaseNotifications");
    try {
        super.onNewToken(token);
        getSharedPreferences("fcm", MODE_PRIVATE).edit().putString("fcm_token", token).apply();
        Log.e("Set FCM token: ", token);
        FirebaseCrashlytics.getInstance().log("Set FCM token: " + token);
        Sentry.addBreadcrumb("Set FCM token: " + token);
        Sentry.setTag("fcm_token_generated", "true");
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        Sentry.captureException(e);
    } finally {
        FirebaseNotifications_on_new_token_transaction.finish();
    }
}
Also used : ITransaction(io.sentry.ITransaction) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 3 with ITransaction

use of io.sentry.ITransaction in project NextDNSManager by mtverlee.

the class MainActivity method replaceCSS.

@AddTrace(name = "replace_css", enabled = true)
public void replaceCSS(String url, boolean isDarkThemeOn) {
    ITransaction replace_css_transaction = Sentry.startTransaction("replaceCSS()", "MainActivity");
    try {
        if (isDarkThemeOn) {
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public WebResourceResponse shouldInterceptRequest(final WebView view, String url) {
                    if (url.contains(".css")) {
                        return getCssWebResourceResponseFromAsset();
                    } else {
                        return super.shouldInterceptRequest(view, url);
                    }
                }

                private WebResourceResponse getCssWebResourceResponseFromAsset() {
                    try {
                        InputStream fileStream = new URL("https://nextdns.doubleangels.com/nextdns.css").openStream();
                        return getUtf8EncodedCssWebResourceResponse(fileStream);
                    } catch (Exception e) {
                        FirebaseCrashlytics.getInstance().recordException(e);
                        Sentry.captureException(e);
                        return null;
                    }
                }

                private WebResourceResponse getUtf8EncodedCssWebResourceResponse(InputStream fileStream) {
                    return new WebResourceResponse("text/css", "UTF-8", fileStream);
                }
            });
            webView.loadUrl(url);
        } else {
            webView.loadUrl(url);
        }
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        Sentry.captureException(e);
    } finally {
        replace_css_transaction.finish();
    }
}
Also used : WebResourceResponse(android.webkit.WebResourceResponse) InputStream(java.io.InputStream) ITransaction(io.sentry.ITransaction) WebView(android.webkit.WebView) URL(java.net.URL) WebViewClient(android.webkit.WebViewClient) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 4 with ITransaction

use of io.sentry.ITransaction in project NextDNSManager by mtverlee.

the class help method updateVisualIndicator.

@AddTrace(name = "update_visual_indicator", enabled = true)
public void updateVisualIndicator(LinkProperties linkProperties) {
    ITransaction update_visual_indicator_transaction = Sentry.startTransaction("updateVisualIndicator()", "help");
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    try {
        if (activeNetworkInfo.isConnected()) {
            if (linkProperties.isPrivateDnsActive()) {
                if (linkProperties.getPrivateDnsServerName() != null) {
                    if (linkProperties.getPrivateDnsServerName().contains("nextdns")) {
                        ImageView connectionStatus = (ImageView) findViewById(R.id.connectionStatus);
                        connectionStatus.setImageResource(R.drawable.success);
                        connectionStatus.setColorFilter(getResources().getColor(R.color.green));
                        FirebaseCrashlytics.getInstance().log("Set connection status to NextDNS.");
                        Sentry.addBreadcrumb("Set connection status to NextDNS.");
                        Sentry.setTag("private_dns", "nextdns");
                    } else {
                        ImageView connectionStatus = (ImageView) findViewById(R.id.connectionStatus);
                        connectionStatus.setImageResource(R.drawable.success);
                        connectionStatus.setColorFilter(getResources().getColor(R.color.yellow));
                        FirebaseCrashlytics.getInstance().log("Set connection status to private DNS.");
                        Sentry.addBreadcrumb("Set connection status to private DNS.");
                        Sentry.setTag("private_dns", "private");
                    }
                } else {
                    ImageView connectionStatus = (ImageView) findViewById(R.id.connectionStatus);
                    connectionStatus.setImageResource(R.drawable.success);
                    connectionStatus.setColorFilter(getResources().getColor(R.color.yellow));
                    FirebaseCrashlytics.getInstance().log("Set connection status to private DNS.");
                    Sentry.addBreadcrumb("Set connection status to private DNS.");
                    Sentry.setTag("private_dns", "private");
                }
            } else {
                ImageView connectionStatus = (ImageView) findViewById(R.id.connectionStatus);
                connectionStatus.setImageResource(R.drawable.failure);
                connectionStatus.setColorFilter(getResources().getColor(R.color.red));
                FirebaseCrashlytics.getInstance().log("Set connection status to insecure DNS.");
                Sentry.addBreadcrumb("Set connection status to insecure DNS.");
                Sentry.setTag("private_dns", "insecure");
            }
        } else {
            ImageView connectionStatus = (ImageView) findViewById(R.id.connectionStatus);
            connectionStatus.setImageResource(R.drawable.failure);
            connectionStatus.setColorFilter(getResources().getColor(R.color.red));
            FirebaseCrashlytics.getInstance().log("Set connection status to no connection.");
            Sentry.addBreadcrumb("Set connection status to no connection.");
            Sentry.setTag("private_dns", "no_connection");
        }
    } catch (NullPointerException e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        Sentry.captureException(e);
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        Sentry.captureException(e);
    } finally {
        update_visual_indicator_transaction.finish();
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) ITransaction(io.sentry.ITransaction) ImageView(android.widget.ImageView) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 5 with ITransaction

use of io.sentry.ITransaction in project NextDNSManager by mtverlee.

the class help method onCreate.

@Override
@AddTrace(name = "help_create", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
    ITransaction help_create_transaction = Sentry.startTransaction("onCreate()", "help");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_help);
    try {
        final SharedPreferences sharedPreferences = getSharedPreferences("publicResolverSharedPreferences", MODE_PRIVATE);
        isManualDisableAnalytics = sharedPreferences.getBoolean("manualDisableAnalytics", false);
        storedUniqueKey = sharedPreferences.getString("uuid", "defaultValue");
        if (storedUniqueKey.contains("defaultValue")) {
            uniqueKey = UUID.randomUUID().toString();
            sharedPreferences.edit().putString("uuid", uniqueKey).apply();
            FirebaseCrashlytics.getInstance().setUserId(uniqueKey);
            FirebaseCrashlytics.getInstance().log("Set UUID to: " + uniqueKey);
            Sentry.addBreadcrumb("Set UUID to: " + uniqueKey);
            Sentry.setTag("uuid_set", "true");
            Sentry.setTag("uuid_new", "true");
        } else {
            uniqueKey = sharedPreferences.getString("uuid", "defaultValue");
            FirebaseCrashlytics.getInstance().setUserId(uniqueKey);
            FirebaseCrashlytics.getInstance().log("Set UUID to: " + uniqueKey);
            Sentry.addBreadcrumb("Set UUID to: " + uniqueKey);
            Sentry.setTag("uuid_set", "true");
            Sentry.setTag("uuid_new", "false");
        }
        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        if (isManualDisableAnalytics) {
            mFirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(true);
        }
        Trace remoteConfigStartTrace = FirebasePerformance.getInstance().newTrace("remoteConfig_setup");
        remoteConfigStartTrace.start();
        mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(1800).build();
        mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
        mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
        remoteConfigStartTrace.stop();
        window = this.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        Trace remoteConfigFetchTrace = FirebasePerformance.getInstance().newTrace("remoteConfig_fetch");
        remoteConfigFetchTrace.start();
        mFirebaseRemoteConfig.fetchAndActivate().addOnCompleteListener(this, new OnCompleteListener<Boolean>() {

            @Override
            public void onComplete(@NonNull Task<Boolean> task) {
                if (task.isSuccessful()) {
                    boolean updated = task.getResult();
                    FirebaseCrashlytics.getInstance().log("Remote config fetch succeeded: " + updated);
                    Sentry.addBreadcrumb("Remote config fetch succeeded: " + updated);
                    if (updated) {
                        Sentry.setTag("remote_config_fetched", "true");
                    } else {
                        Sentry.setTag("remote_config_fetched", "false");
                    }
                    mFirebaseRemoteConfig.activate();
                }
            }
        });
        remoteConfigFetchTrace.stop();
        window.setStatusBarColor(ContextCompat.getColor(this, R.color.status_bar_background_color));
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.toolbar_background_color));
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        Network network = connectivityManager.getActiveNetwork();
        LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
        updateVisualIndicator(linkProperties);
        if (connectivityManager != null) {
            connectivityManager.registerNetworkCallback(new NetworkRequest.Builder().build(), new ConnectivityManager.NetworkCallback() {

                @Override
                public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
                    super.onLinkPropertiesChanged(network, linkProperties);
                    updateVisualIndicator(linkProperties);
                }
            });
        }
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        Sentry.captureException(e);
    } finally {
        help_create_transaction.finish();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) ConnectivityManager(android.net.ConnectivityManager) ITransaction(io.sentry.ITransaction) FirebaseRemoteConfigSettings(com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings) LinkProperties(android.net.LinkProperties) AddTrace(com.google.firebase.perf.metrics.AddTrace) Trace(com.google.firebase.perf.metrics.Trace) Network(android.net.Network) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Aggregations

ITransaction (io.sentry.ITransaction)29 AddTrace (com.google.firebase.perf.metrics.AddTrace)18 ConnectivityManager (android.net.ConnectivityManager)12 ImageView (android.widget.ImageView)11 Intent (android.content.Intent)6 SharedPreferences (android.content.SharedPreferences)6 LinkProperties (android.net.LinkProperties)6 Network (android.net.Network)6 NetworkInfo (android.net.NetworkInfo)6 Bundle (android.os.Bundle)6 Trace (com.google.firebase.perf.metrics.Trace)6 FirebaseRemoteConfigSettings (com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings)6 View (android.view.View)5 ISpan (io.sentry.ISpan)5 WebView (android.webkit.WebView)4 WebViewClient (android.webkit.WebViewClient)4 CookieManager (android.webkit.CookieManager)3 WebChromeClient (android.webkit.WebChromeClient)3 WebSettings (android.webkit.WebSettings)3 Activity (android.app.Activity)2