Skip to content

Commit

Permalink
Merge pull request TeamNewPipe#7482 from TeamNewPipe/unify-error-repo…
Browse files Browse the repository at this point in the history
…rting

Unify error reporting and add error notification
  • Loading branch information
litetex authored Dec 14, 2021
2 parents dd9772c + bb49b1c commit 4058277
Show file tree
Hide file tree
Showing 36 changed files with 349 additions and 401 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import androidx.preference.Preference;

import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.util.PicassoHelper;

import leakcanary.LeakCanary;
Expand All @@ -20,10 +23,16 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
= findPreference(getString(R.string.show_image_indicators_key));
final Preference crashTheAppPreference
= findPreference(getString(R.string.crash_the_app_key));
final Preference showErrorSnackbarPreference
= findPreference(getString(R.string.show_error_snackbar_key));
final Preference createErrorNotificationPreference
= findPreference(getString(R.string.create_error_notification_key));

assert showMemoryLeaksPreference != null;
assert showImageIndicatorsPreference != null;
assert crashTheAppPreference != null;
assert showErrorSnackbarPreference != null;
assert createErrorNotificationPreference != null;

showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
startActivity(LeakCanary.INSTANCE.newLeakDisplayActivityIntent());
Expand All @@ -38,5 +47,17 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
crashTheAppPreference.setOnPreferenceClickListener(preference -> {
throw new RuntimeException();
});

showErrorSnackbarPreference.setOnPreferenceClickListener(preference -> {
ErrorUtil.showUiErrorSnackbar(DebugSettingsFragment.this,
"Dummy", new RuntimeException("Dummy"));
return true;
});

createErrorNotificationPreference.setOnPreferenceClickListener(preference -> {
ErrorUtil.createNotification(requireContext(),
new ErrorInfo(new RuntimeException("Dummy"), UserAction.UI_ERROR, "Dummy"));
return true;
});
}
}
19 changes: 13 additions & 6 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.acra.config.ACRAConfigurationException;
import org.acra.config.CoreConfiguration;
import org.acra.config.CoreConfigurationBuilder;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.ReCaptchaActivity;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.NewPipe;
Expand Down Expand Up @@ -217,7 +217,7 @@ protected void initACRA() {
ACRA.init(this, acraConfig);
} catch (final ACRAConfigurationException exception) {
exception.printStackTrace();
ErrorActivity.reportError(this, new ErrorInfo(exception,
ErrorUtil.openActivity(this, new ErrorInfo(exception,
UserAction.SOMETHING_ELSE, "Could not initialize ACRA crash report"));
}
}
Expand All @@ -227,28 +227,35 @@ private void initNotificationChannels() {
// the main and update channels
final NotificationChannelCompat mainChannel = new NotificationChannelCompat
.Builder(getString(R.string.notification_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.notification_channel_name))
.setDescription(getString(R.string.notification_channel_description))
.build();

final NotificationChannelCompat appUpdateChannel = new NotificationChannelCompat
.Builder(getString(R.string.app_update_notification_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.app_update_notification_channel_name))
.setDescription(getString(R.string.app_update_notification_channel_description))
.build();

final NotificationChannelCompat hashChannel = new NotificationChannelCompat
.Builder(getString(R.string.hash_channel_id),
NotificationManagerCompat.IMPORTANCE_HIGH)
NotificationManagerCompat.IMPORTANCE_HIGH)
.setName(getString(R.string.hash_channel_name))
.setDescription(getString(R.string.hash_channel_description))
.build();

final NotificationChannelCompat errorReportChannel = new NotificationChannelCompat
.Builder(getString(R.string.error_report_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.error_report_channel_name))
.setDescription(getString(R.string.error_report_channel_description))
.build();

final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.createNotificationChannelsCompat(Arrays.asList(mainChannel,
appUpdateChannel, hashChannel));
appUpdateChannel, hashChannel, errorReportChannel));
}

protected boolean isDisposedRxExceptionsReported() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;

import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
Expand Down Expand Up @@ -64,7 +64,7 @@ private static String getCertificateSHA1Fingerprint(@NonNull final Application a
signatures = PackageInfoCompat.getSignatures(application.getPackageManager(),
application.getPackageName());
} catch (final PackageManager.NameNotFoundException e) {
ErrorActivity.reportError(application, new ErrorInfo(e,
ErrorUtil.createNotification(application, new ErrorInfo(e,
UserAction.CHECK_FOR_NEW_APP_VERSION, "Could not find package info"));
return "";
}
Expand All @@ -79,7 +79,7 @@ private static String getCertificateSHA1Fingerprint(@NonNull final Application a
final CertificateFactory cf = CertificateFactory.getInstance("X509");
c = (X509Certificate) cf.generateCertificate(input);
} catch (final CertificateException e) {
ErrorActivity.reportError(application, new ErrorInfo(e,
ErrorUtil.createNotification(application, new ErrorInfo(e,
UserAction.CHECK_FOR_NEW_APP_VERSION, "Certificate error"));
return "";
}
Expand All @@ -89,7 +89,7 @@ private static String getCertificateSHA1Fingerprint(@NonNull final Application a
final byte[] publicKey = md.digest(c.getEncoded());
return byte2HexFormatted(publicKey);
} catch (NoSuchAlgorithmException | CertificateEncodingException e) {
ErrorActivity.reportError(application, new ErrorInfo(e,
ErrorUtil.createNotification(application, new ErrorInfo(e,
UserAction.CHECK_FOR_NEW_APP_VERSION, "Could not retrieve SHA1 key"));
return "";
}
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import org.schabi.newpipe.databinding.DrawerLayoutBinding;
import org.schabi.newpipe.databinding.InstanceSpinnerLayoutBinding;
import org.schabi.newpipe.databinding.ToolbarLayoutBinding;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
Expand Down Expand Up @@ -157,7 +157,7 @@ protected void onCreate(final Bundle savedInstanceState) {
try {
setupDrawer();
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Setting up drawer", e);
ErrorUtil.showUiErrorSnackbar(this, "Setting up drawer", e);
}

if (DeviceUtils.isTv(this)) {
Expand Down Expand Up @@ -214,7 +214,7 @@ public void onDrawerClosed(final View drawerView) {
/**
* Builds the drawer menu for the current service.
*
* @throws ExtractionException
* @throws ExtractionException if the service didn't provide available kiosks
*/
private void addDrawerMenuForCurrentService() throws ExtractionException {
//Tabs
Expand Down Expand Up @@ -266,7 +266,7 @@ private boolean drawerItemSelected(final MenuItem item) {
try {
tabSelected(item);
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Selecting main page tab", e);
ErrorUtil.showUiErrorSnackbar(this, "Selecting main page tab", e);
}
break;
case R.id.menu_options_about_group:
Expand Down Expand Up @@ -372,7 +372,7 @@ private void toggleServices() {
try {
addDrawerMenuForCurrentService();
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Showing main page tabs", e);
ErrorUtil.showUiErrorSnackbar(this, "Showing main page tabs", e);
}
}
}
Expand Down Expand Up @@ -475,7 +475,7 @@ protected void onResume() {
drawerHeaderBinding.drawerHeaderActionButton.setContentDescription(
getString(R.string.drawer_header_description) + selectedServiceName);
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Setting up service toggle", e);
ErrorUtil.showUiErrorSnackbar(this, "Setting up service toggle", e);
}

final SharedPreferences sharedPreferences
Expand Down Expand Up @@ -785,7 +785,7 @@ private void handleIntent(final Intent intent) {
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
}
} catch (final Exception e) {
ErrorActivity.reportUiErrorInSnackbar(this, "Handling intent", e);
ErrorUtil.showUiErrorSnackbar(this, "Handling intent", e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import org.schabi.newpipe.databinding.ListRadioIconItemBinding;
import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding;
import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.ReCaptchaActivity;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.Info;
Expand Down Expand Up @@ -231,7 +231,7 @@ private static void handleError(final Context context, final ErrorInfo errorInfo
} else if (errorInfo.getThrowable() instanceof ContentNotSupportedException) {
Toast.makeText(context, R.string.content_not_supported, Toast.LENGTH_LONG).show();
} else {
ErrorActivity.reportError(context, errorInfo);
ErrorUtil.createNotification(context, errorInfo);
}

if (context instanceof RouterActivity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.DownloadDialogBinding;
import org.schabi.newpipe.error.ErrorActivity;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe;
Expand Down Expand Up @@ -402,7 +402,7 @@ private void fetchStreamsSize() {
== R.id.video_button) {
setupVideoSpinner();
}
}, throwable -> ErrorActivity.reportErrorInSnackbar(context,
}, throwable -> ErrorUtil.showSnackbar(context,
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
"Downloading video stream size",
currentInfo.getServiceId()))));
Expand All @@ -412,7 +412,7 @@ private void fetchStreamsSize() {
== R.id.audio_button) {
setupAudioSpinner();
}
}, throwable -> ErrorActivity.reportErrorInSnackbar(context,
}, throwable -> ErrorUtil.showSnackbar(context,
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
"Downloading audio stream size",
currentInfo.getServiceId()))));
Expand All @@ -422,7 +422,7 @@ private void fetchStreamsSize() {
== R.id.subtitle_button) {
setupSubtitleSpinner();
}
}, throwable -> ErrorActivity.reportErrorInSnackbar(context,
}, throwable -> ErrorUtil.showSnackbar(context,
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
"Downloading subtitle stream size",
currentInfo.getServiceId()))));
Expand Down Expand Up @@ -799,7 +799,7 @@ private void checkSelectedDownload(final StoredDirectoryHelper mainStorage,
mainStorage.getTag());
}
} catch (final Exception e) {
ErrorActivity.reportErrorInSnackbar(this,
ErrorUtil.createNotification(requireContext(),
new ErrorInfo(e, UserAction.DOWNLOAD_FAILED, "Getting storage"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public class AcraReportSender implements ReportSender {

@Override
public void send(@NonNull final Context context, @NonNull final CrashReportData report) {
ErrorActivity.reportError(context, new ErrorInfo(
ErrorUtil.openActivity(context, new ErrorInfo(
new String[]{report.getString(ReportField.STACK_TRACE)},
UserAction.UI_ERROR,
ErrorInfo.SERVICE_NONE,
"ACRA report",
R.string.app_ui_crash,
null));
R.string.app_ui_crash));
}
}

This file was deleted.

Loading

0 comments on commit 4058277

Please sign in to comment.