Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback audio and data to http #1161

Merged
merged 1 commit into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
android:name=".QuranApplication"
android:allowBackup="true"
android:fullBackupContent="@xml/backup"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/Quran">
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import android.os.StatFs;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.quran.labs.androidquran.QuranApplication;
import com.quran.labs.androidquran.data.QuranInfo;
import com.quran.labs.androidquran.data.SuraAyah;
Expand All @@ -26,7 +28,6 @@
import com.quran.labs.androidquran.util.ZipUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -465,7 +466,13 @@ private boolean downloadFileWrapper(String urlString, String destination,
break;
}

String url = urlString;
if (i > 0) {
// let's try http instead of https?
if (urlString.contains("quran.com") || urlString.contains("quranicaudio.com")) {
url = urlString.replace("https://", "http://");
}

// want to wait before retrying again
try {
Thread.sleep(WAIT_TIME);
Expand All @@ -476,12 +483,15 @@ private boolean downloadFileWrapper(String urlString, String destination,
}

wifiLock.acquire();
res = startDownload(urlString, destination, outputFile, details);
res = startDownload(url, destination, outputFile, details);
if (wifiLock.isHeld()) {
wifiLock.release();
}

if (res == DOWNLOAD_SUCCESS) {
if (i > 0 && !url.contains("https://")) {
Answers.getInstance().logCustom(new CustomEvent("httpFallbackSuccess"));
}
return true;
} else if (res == QuranDownloadNotifier.ERROR_DISK_SPACE ||
res == QuranDownloadNotifier.ERROR_PERMISSIONS) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">quran.com</domain>
<domain includeSubdomains="true">quranicaudio.com</domain>
</domain-config>
</network-security-config>