Mention ad blockers on streaming error dialog as well

This commit is contained in:
ByteHamster 2021-11-14 13:12:24 +01:00
parent bae923d710
commit 92e7dbfa9e
4 changed files with 42 additions and 22 deletions

View File

@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import de.danoeh.antennapod.core.util.NetworkUtils;
import okhttp3.CacheControl;
import org.apache.commons.io.IOUtils;
@ -19,8 +20,6 @@ import java.net.URI;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.model.feed.FeedMedia;
@ -39,7 +38,6 @@ public class HttpDownloader extends Downloader {
private static final String TAG = "HttpDownloader";
private static final int BUFFER_SIZE = 8 * 1024;
private static final String REGEX_PATTERN_IP_ADDRESS = "([0-9]{1,3}[\\.]){3}[0-9]{1,3}";
public HttpDownloader(@NonNull DownloadRequest request) {
super(request);
@ -259,21 +257,14 @@ public class HttpDownloader extends Downloader {
onFail(DownloadError.ERROR_UNKNOWN_HOST, e.getMessage());
} catch (IOException e) {
e.printStackTrace();
if (NetworkUtils.wasDownloadBlocked(e)) {
onFail(DownloadError.ERROR_IO_BLOCKED, e.getMessage());
return;
}
String message = e.getMessage();
if (message != null) {
// Try to parse message for a more detailed error message
Pattern pattern = Pattern.compile(REGEX_PATTERN_IP_ADDRESS);
Matcher matcher = pattern.matcher(message);
if (matcher.find()) {
String ip = matcher.group();
if (ip.startsWith("127.") || ip.startsWith("0.")) {
onFail(DownloadError.ERROR_IO_BLOCKED, e.getMessage());
return;
}
} else if (message.contains("Trust anchor for certification path not found")) {
onFail(DownloadError.ERROR_CERTIFICATE, e.getMessage());
return;
}
if (message != null && message.contains("Trust anchor for certification path not found")) {
onFail(DownloadError.ERROR_CERTIFICATE, e.getMessage());
return;
}
onFail(DownloadError.ERROR_IO_ERROR, e.getMessage());
} catch (NullPointerException e) {

View File

@ -32,10 +32,13 @@ import com.google.android.exoplayer2.ui.TrackNameProvider;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.service.download.HttpDownloader;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.core.util.playback.IPlayer;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -102,9 +105,15 @@ public class ExoPlayerWrapper implements IPlayer {
@Override
public void onPlayerError(@NonNull ExoPlaybackException error) {
if (audioErrorListener != null) {
Throwable cause = error.getCause();
audioErrorListener.accept(cause != null
? cause.getLocalizedMessage() : error.getLocalizedMessage());
if (NetworkUtils.wasDownloadBlocked(error)) {
audioErrorListener.accept(context.getString(R.string.download_error_blocked));
} else {
Throwable cause = error.getCause();
if (cause instanceof HttpDataSource.HttpDataSourceException) {
cause = cause.getCause();
}
audioErrorListener.accept(cause != null ? cause.getMessage() : error.getMessage());
}
}
}

View File

@ -16,6 +16,8 @@ import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -30,6 +32,8 @@ import okhttp3.Request;
import okhttp3.Response;
public class NetworkUtils {
private static final String REGEX_PATTERN_IP_ADDRESS = "([0-9]{1,3}[\\.]){3}[0-9]{1,3}";
private NetworkUtils(){}
private static final String TAG = NetworkUtils.class.getSimpleName();
@ -142,6 +146,22 @@ public class NetworkUtils {
return null;
}
public static boolean wasDownloadBlocked(Throwable throwable) {
String message = throwable.getMessage();
if (message != null) {
Pattern pattern = Pattern.compile(REGEX_PATTERN_IP_ADDRESS);
Matcher matcher = pattern.matcher(message);
if (matcher.find()) {
String ip = matcher.group();
return ip.startsWith("127.") || ip.startsWith("0.");
}
}
if (throwable.getCause() != null) {
return wasDownloadBlocked(throwable.getCause());
}
return false;
}
public static Single<Long> getFeedMediaSizeObservable(FeedMedia media) {
return Single.create((SingleOnSubscribe<Long>) emitter -> {
if (!NetworkUtils.isEpisodeHeadDownloadAllowed()) {

View File

@ -263,8 +263,8 @@
<string name="download_error_forbidden">The podcast host\'s server refuses to respond.</string>
<string name="download_canceled_msg">Download canceled</string>
<string name="download_error_wrong_size">The server connection was lost before completing the download</string>
<string name="download_error_blocked">The download was blocked by another app on your device.</string>
<string name="download_error_certificate">Unable to establish a secure connection. This can mean that another app on your device blocked the download, or that something is wrong with the server certificates.</string>
<string name="download_error_blocked">The download was blocked by another app on your device (like a VPN or ad blocker).</string>
<string name="download_error_certificate">Unable to establish a secure connection. This can mean that another app on your device (like a VPN or an ad blocker) blocked the download, or that something is wrong with the server certificates.</string>
<string name="download_report_title">Downloads completed with error(s)</string>
<string name="auto_download_report_title">Auto-downloads completed</string>
<string name="download_error_io_error">IO Error</string>