mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-03-01 05:48:22 +03:00
BraveNewPipeLegacy: (Kitkat) use OsExt:osext-stat library within getFreeStorageSpace()
use OsExt:osext-stat which implements the missing (f)statvfs() methods on Kitkat
This commit is contained in:
parent
9b4bd562ab
commit
67be4f2938
2 changed files with 16 additions and 18 deletions
|
@ -115,6 +115,7 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'org.conscrypt:conscrypt-android:2.5.2'
|
implementation 'org.conscrypt:conscrypt-android:2.5.2'
|
||||||
|
implementation "com.github.evermind-zz.OsExt:osext-stat:1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package org.schabi.newpipe.streams.io;
|
package org.schabi.newpipe.streams.io;
|
||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.StatFs;
|
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
import android.system.Os;
|
import android.system.Os;
|
||||||
import android.system.StructStatVfs;
|
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
public final class BraveStoredDirectoryHelper {
|
public final class BraveStoredDirectoryHelper {
|
||||||
|
|
||||||
private BraveStoredDirectoryHelper() {
|
private BraveStoredDirectoryHelper() {
|
||||||
|
@ -16,25 +16,17 @@ public final class BraveStoredDirectoryHelper {
|
||||||
|
|
||||||
public static BraveStructStatVfs statvfs(final String path) throws ErrnoException {
|
public static BraveStructStatVfs statvfs(final String path) throws ErrnoException {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
final StructStatVfs stat = Os.statvfs(path);
|
return new BraveStructStatVfs(Os.statvfs(path));
|
||||||
return new BraveStructStatVfs(stat.f_bavail, stat.f_frsize);
|
|
||||||
} else {
|
} else {
|
||||||
final StatFs stat = new StatFs(path);
|
return new BraveStructStatVfs(com.github.evermindzz.osext.system.Os.statvfs(path));
|
||||||
return new BraveStructStatVfs(stat.getAvailableBlocksLong(),
|
|
||||||
stat.getBlockSizeLong()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BraveStructStatVfs fstatvfs(final FileDescriptor fd) throws ErrnoException {
|
public static BraveStructStatVfs fstatvfs(final FileDescriptor fd) throws ErrnoException {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
final StructStatVfs stat = Os.fstatvfs(fd);
|
return new BraveStructStatVfs(Os.fstatvfs(fd));
|
||||||
return new BraveStructStatVfs(stat.f_bavail, stat.f_frsize);
|
|
||||||
} else {
|
} else {
|
||||||
// TODO find a real solution for KitKat to determine the free fs on FileDescriptor
|
return new BraveStructStatVfs(com.github.evermindzz.osext.system.Os.fstatvfs(fd));
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +43,15 @@ public final class BraveStoredDirectoryHelper {
|
||||||
/**
|
/**
|
||||||
* @noinspection checkstyle:ParameterName
|
* @noinspection checkstyle:ParameterName
|
||||||
*/
|
*/
|
||||||
BraveStructStatVfs(final long f_bavail,
|
BraveStructStatVfs(final com.github.evermindzz.osext.system.StructStatVfs stat) {
|
||||||
final long f_frsize) {
|
this.f_bavail = stat.f_bavail;
|
||||||
this.f_bavail = f_bavail;
|
this.f_frsize = stat.f_frsize;
|
||||||
this.f_frsize = f_frsize;
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
BraveStructStatVfs(final android.system.StructStatVfs stat) {
|
||||||
|
this.f_bavail = stat.f_bavail;
|
||||||
|
this.f_frsize = stat.f_frsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue