Merge branch 'dev' into dl-last-features
This commit is contained in:
parent
f62a7919a5
commit
ea1be11a80
|
@ -1,6 +1,9 @@
|
|||
package us.shandian.giga.get;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.OsConstants;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -35,9 +38,6 @@ public class DownloadMission extends Mission {
|
|||
static final int BUFFER_SIZE = 64 * 1024;
|
||||
static final int BLOCK_SIZE = 512 * 1024;
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
private static final String INSUFFICIENT_STORAGE = "ENOSPC";
|
||||
|
||||
private static final String TAG = "DownloadMission";
|
||||
|
||||
public static final int ERROR_NOTHING = -1;
|
||||
|
@ -315,13 +315,29 @@ public class DownloadMission extends Mission {
|
|||
|
||||
public synchronized void notifyError(int code, Exception err) {
|
||||
Log.e(TAG, "notifyError() code = " + code, err);
|
||||
if (err instanceof IOException) {
|
||||
if (!storage.canWrite() || err.getMessage().contains("Permission denied")) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (err.getCause() instanceof ErrnoException) {
|
||||
int errno = ((ErrnoException) err.getCause()).errno;
|
||||
if (errno == OsConstants.ENOSPC) {
|
||||
code = ERROR_INSUFFICIENT_STORAGE;
|
||||
err = null;
|
||||
} else if (errno == OsConstants.EACCES) {
|
||||
code = ERROR_PERMISSION_DENIED;
|
||||
err = null;
|
||||
} else if (err.getMessage().contains(INSUFFICIENT_STORAGE)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (err instanceof IOException) {
|
||||
if (err.getMessage().contains("Permission denied")) {
|
||||
code = ERROR_PERMISSION_DENIED;
|
||||
err = null;
|
||||
} else if (err.getMessage().contains("ENOSPC")) {
|
||||
code = ERROR_INSUFFICIENT_STORAGE;
|
||||
err = null;
|
||||
} else if (!storage.canWrite()) {
|
||||
code = ERROR_FILE_CREATION;
|
||||
err = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue