Search in sources :

Example 1 with Trace

use of com.google.firebase.perf.metrics.Trace 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)

Example 2 with Trace

use of com.google.firebase.perf.metrics.Trace in project NextDNSManager by mtverlee.

the class settings method onCreate.

@Override
@AddTrace(name = "settings_create", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
    ITransaction settings_create_transaction = Sentry.startTransaction("onCreate()", "settings");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    try {
        final SharedPreferences sharedPreferences = getSharedPreferences("mainSharedPreferences", 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);
        } else {
            uniqueKey = sharedPreferences.getString("uuid", "defaultValue");
            FirebaseCrashlytics.getInstance().setUserId(uniqueKey);
            FirebaseCrashlytics.getInstance().log("Set UUID to: " + uniqueKey);
            Sentry.addBreadcrumb("Set UUID to: " + uniqueKey);
        }
        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));
        Switch manualDisableAnalytics = (Switch) findViewById(R.id.manual_disable_analytics);
        versionNumber = (TextView) findViewById(R.id.versionNumberTextView);
        versionNumber.setText(BuildConfig.VERSION_NAME);
        ImageView whitelist = (ImageView) findViewById(R.id.whitelistImageView);
        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);
                }
            });
        }
        if (isManualDisableAnalytics) {
            manualDisableAnalytics.setChecked(true);
        } else {
            manualDisableAnalytics.setChecked(false);
        }
        manualDisableAnalytics.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPreferences.edit().putBoolean("manualDisableAnalytics", true).apply();
                    FirebaseCrashlytics.getInstance().log("Changed analytics to enabled.");
                    Sentry.addBreadcrumb("Changed analytics to enabled.");
                    Sentry.setTag("analytics_manual_control", "enabled");
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putString("id", "set_manual_disable_analytics");
                    mFirebaseAnalytics.logEvent("manual_disable_analytics", bundle);
                    sharedPreferences.edit().putBoolean("manualDisableAnalytics", false).apply();
                    FirebaseCrashlytics.getInstance().log("Changed analytics to disabled.");
                    Sentry.addBreadcrumb("Canged analytics to disabled.");
                    Sentry.setTag("analytics_manual_control", "disabled");
                    Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_SHORT).show();
                }
            }
        });
        statusIcon = (ImageView) findViewById(R.id.connectionStatus);
        statusIcon.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "help_icon");
                mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
                Intent helpIntent = new Intent(v.getContext(), help.class);
                startActivity(helpIntent);
            }
        });
        whitelist.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                intent.setData(Uri.parse("https://nextdns-management.firebaseapp.com/whitelist.txt"));
                startActivity(intent);
            }
        });
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        Sentry.captureException(e);
    } finally {
        settings_create_transaction.finish();
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) ConnectivityManager(android.net.ConnectivityManager) Bundle(android.os.Bundle) ITransaction(io.sentry.ITransaction) Intent(android.content.Intent) FirebaseRemoteConfigSettings(com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings) LinkProperties(android.net.LinkProperties) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AddTrace(com.google.firebase.perf.metrics.AddTrace) Trace(com.google.firebase.perf.metrics.Trace) Switch(android.widget.Switch) Network(android.net.Network) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 3 with Trace

use of com.google.firebase.perf.metrics.Trace in project capacitor-firebase by robingenz.

the class FirebasePerformance method startTrace.

public void startTrace(String traceName) {
    Trace trace = this.getFirebasePerformanceInstance().newTrace(traceName);
    trace.start();
    this.traces.put(traceName, trace);
}
Also used : Trace(com.google.firebase.perf.metrics.Trace)

Example 4 with Trace

use of com.google.firebase.perf.metrics.Trace in project capacitor-firebase by robingenz.

the class FirebasePerformancePlugin method stopTrace.

@PluginMethod
public void stopTrace(PluginCall call) {
    String traceName = call.getString("traceName");
    if (traceName == null) {
        call.reject(ERROR_TRACE_NAME_MISSING);
        return;
    }
    Trace trace = implementation.getTraceByName(traceName);
    if (trace == null) {
        call.reject(ERROR_TRACE_NOT_FOUND);
        return;
    }
    implementation.stopTrace(traceName);
    call.resolve();
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) PluginMethod(com.getcapacitor.PluginMethod)

Example 5 with Trace

use of com.google.firebase.perf.metrics.Trace in project snippets-android by firebase.

the class MainActivity method traceCustomAttributes.

public void traceCustomAttributes() {
    // [START perf_trace_custom_attrs]
    Trace trace = FirebasePerformance.getInstance().newTrace("test_trace");
    // Update scenario.
    trace.putAttribute("experiment", "A");
    // Reading scenario.
    String experimentValue = trace.getAttribute("experiment");
    // Delete scenario.
    trace.removeAttribute("experiment");
    // Read attributes.
    Map<String, String> traceAttributes = trace.getAttributes();
// [END perf_trace_custom_attrs]
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Aggregations

Trace (com.google.firebase.perf.metrics.Trace)25 AddTrace (com.google.firebase.perf.metrics.AddTrace)11 SharedPreferences (android.content.SharedPreferences)6 ConnectivityManager (android.net.ConnectivityManager)6 LinkProperties (android.net.LinkProperties)6 Network (android.net.Network)6 FirebaseRemoteConfigSettings (com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings)6 ITransaction (io.sentry.ITransaction)6 Intent (android.content.Intent)5 Bundle (android.os.Bundle)5 View (android.view.View)5 ImageView (android.widget.ImageView)5 WebView (android.webkit.WebView)3 PluginMethod (com.getcapacitor.PluginMethod)3 PerfFrameMetrics (com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)2 TraceMetric (com.google.firebase.perf.v1.TraceMetric)2 Test (org.junit.Test)2 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1