Commit 22b126ca by aquilescanta Committed by Oliver Woodman

Assign ERROR_CODE_IO_NO_PERMISSION to ErrnoException (EACCES)

PiperOrigin-RevId: 378134423
parent 14d101bb
...@@ -25,9 +25,13 @@ import android.os.Looper; ...@@ -25,9 +25,13 @@ import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.Process; import android.os.Process;
import android.os.SystemClock; import android.os.SystemClock;
import android.system.ErrnoException;
import android.system.OsConstants;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import androidx.annotation.DoNotInline;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.DefaultMediaClock.PlaybackParametersListener; import com.google.android.exoplayer2.DefaultMediaClock.PlaybackParametersListener;
import com.google.android.exoplayer2.Player.DiscontinuityReason; import com.google.android.exoplayer2.Player.DiscontinuityReason;
import com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason; import com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason;
...@@ -578,7 +582,11 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -578,7 +582,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
@Nullable Throwable cause = e.getCause(); @Nullable Throwable cause = e.getCause();
int errorCode = PlaybackException.ERROR_CODE_IO_UNSPECIFIED; int errorCode = PlaybackException.ERROR_CODE_IO_UNSPECIFIED;
if (cause instanceof FileNotFoundException) { if (cause instanceof FileNotFoundException) {
if (Util.SDK_INT >= 21 && ErrnoExceptionWrapperV21.isPermissionError(cause.getCause())) {
errorCode = PlaybackException.ERROR_CODE_IO_NO_PERMISSION;
} else {
errorCode = PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND; errorCode = PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND;
}
} else if (cause instanceof SecurityException) { } else if (cause instanceof SecurityException) {
errorCode = PlaybackException.ERROR_CODE_IO_NO_PERMISSION; errorCode = PlaybackException.ERROR_CODE_IO_NO_PERMISSION;
} }
...@@ -3026,4 +3034,13 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -3026,4 +3034,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
this.shuffleOrder = shuffleOrder; this.shuffleOrder = shuffleOrder;
} }
} }
@RequiresApi(21)
private static final class ErrnoExceptionWrapperV21 {
@DoNotInline
public static boolean isPermissionError(@Nullable Throwable e) {
return e instanceof ErrnoException && ((ErrnoException) e).errno == OsConstants.EACCES;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment