use of com.google.firebase.perf.metrics.Trace in project NextDNSManager by mtverlee.
the class MainActivity method onCreate.
@Override
@AddTrace(name = "MainActivity_create", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
ITransaction MainActivity_create_transaction = Sentry.startTransaction("onCreate()", "MainActivity");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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);
Sentry.addBreadcrumb("Analytics collection enabled.");
}
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));
useCustomCSS = mFirebaseRemoteConfig.getBoolean("use_custom_css");
if (useCustomCSS) {
FirebaseCrashlytics.getInstance().setCustomKey("custom_css", true);
Sentry.setTag("custom_css", "true");
}
boolean isDarkThemeOnSub = (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
if (isDarkThemeOnSub) {
isDarkThemeOn = true;
} else {
isDarkThemeOn = false;
}
if (isDarkThemeOn) {
FirebaseCrashlytics.getInstance().setCustomKey("dark_mode_on", true);
Sentry.setTag("dark_mode_on", " true");
}
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);
}
});
}
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);
}
});
provisionWebView("https://my.nextdns.io/login", isDarkThemeOn, useCustomCSS);
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
Sentry.captureException(e);
} finally {
MainActivity_create_transaction.finish();
}
}
use of com.google.firebase.perf.metrics.Trace in project NextDNSManager by mtverlee.
the class ping method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
ITransaction ping_create_transaction = Sentry.startTransaction("onCreate()", "ping");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ping);
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));
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);
}
});
}
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);
}
});
provisionWebView("https://ping.nextdns.io");
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
Sentry.captureException(e);
} finally {
ping_create_transaction.finish();
}
}
use of com.google.firebase.perf.metrics.Trace in project NextDNSManager by mtverlee.
the class test method onCreate.
@Override
@AddTrace(name = "test_create", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
ITransaction test_create_transaction = Sentry.startTransaction("onCreate()", "test");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
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));
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);
}
});
}
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);
}
});
provisionWebView("https://test.nextdns.io");
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
Sentry.captureException(e);
} finally {
test_create_transaction.finish();
}
}
use of com.google.firebase.perf.metrics.Trace in project NextDNSManager by mtverlee.
the class troubleshooting method onCreate.
@Override
@AddTrace(name = "troubleshooting_create", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
ITransaction troubleshooting_create_transaction = Sentry.startTransaction("onCreate()", "troubleshooting");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_troubleshooting);
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));
ImageView troubleshootingGithub = (ImageView) findViewById(R.id.helpGithubImageView);
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);
}
});
}
statusIcon = (ImageView) findViewById(R.id.connectionStatus);
statusIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("id", "help");
mFirebaseAnalytics.logEvent("toolbar_action", bundle);
Intent helpIntent = new Intent(v.getContext(), help.class);
startActivity(helpIntent);
}
});
Button clearCacheButton = (Button) findViewById(R.id.clearCacheButton);
clearCacheButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
FirebaseCrashlytics.getInstance().log("Cleared app cache.");
Sentry.addBreadcrumb("Cleared app cache.");
Sentry.setTag("cleared_cache", "true");
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
});
troubleshootingGithub.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://github.com/mtverlee/NextDNSManager/issues"));
startActivity(intent);
}
});
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
Sentry.captureException(e);
} finally {
troubleshooting_create_transaction.finish();
}
}
use of com.google.firebase.perf.metrics.Trace in project capacitor-firebase by robingenz.
the class FirebasePerformance method stopTrace.
public void stopTrace(String traceName) {
Trace trace = this.traces.get(traceName);
trace.stop();
this.traces.remove(traceName);
}
Aggregations