forked from TeamNewPipe/NewPipe
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BraveNewPipeLegacy: (Kitkat) fix getFreeStorageSpace()
use available methods on Kitkat to getFreeStorageSpace() or in case of using SAF just assume there is enough space as the Os.fstatvfs() is not available and there is no quick solution.
- Loading branch information
1 parent
ffded76
commit 12eca05
Showing
2 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
app/src/braveLegacy/java/org/schabi/newpipe/streams/io/BraveStoredDirectoryHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.schabi.newpipe.streams.io; | ||
|
||
import android.os.Build; | ||
import android.os.StatFs; | ||
import android.system.ErrnoException; | ||
import android.system.Os; | ||
import android.system.StructStatVfs; | ||
|
||
import java.io.FileDescriptor; | ||
|
||
public final class BraveStoredDirectoryHelper { | ||
|
||
private BraveStoredDirectoryHelper() { | ||
|
||
} | ||
|
||
public static BraveStructStatVfs statvfs(final String path) throws ErrnoException { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
final StructStatVfs stat = Os.statvfs(path); | ||
return new BraveStructStatVfs(stat.f_bavail, stat.f_frsize); | ||
} else { | ||
final StatFs stat = new StatFs(path); | ||
return new BraveStructStatVfs(stat.getAvailableBlocksLong(), | ||
stat.getBlockSizeLong() | ||
); | ||
} | ||
} | ||
|
||
public static BraveStructStatVfs fstatvfs(final FileDescriptor fd) throws ErrnoException { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
final StructStatVfs stat = Os.fstatvfs(fd); | ||
return new BraveStructStatVfs(stat.f_bavail, stat.f_frsize); | ||
} else { | ||
// TODO find a real solution for KitKat to determine the free fs on FileDescriptor | ||
// return just a fake value. '1' is just used to not exceed Long.MAX_VALUE as both | ||
// values are multiplied by the caller | ||
return new BraveStructStatVfs(Long.MAX_VALUE, 1); | ||
} | ||
} | ||
|
||
public static class BraveStructStatVfs { | ||
/** | ||
* @noinspection checkstyle:MemberName | ||
*/ | ||
public final long f_bavail; | ||
/** | ||
* @noinspection checkstyle:MemberName | ||
*/ | ||
public final long f_frsize; | ||
|
||
/** | ||
* @noinspection checkstyle:ParameterName | ||
*/ | ||
BraveStructStatVfs(final long f_bavail, | ||
final long f_frsize) { | ||
this.f_bavail = f_bavail; | ||
this.f_frsize = f_frsize; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters