mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 10:01:08 +08:00
fix(android): prevent errors on filesystem operations while using "content://" uris (#10461)
This commit is contained in:
@ -602,12 +602,17 @@ public class Async {
|
||||
public static class File {
|
||||
|
||||
static void updateValue(Context context, Uri uri) {
|
||||
try {
|
||||
ContentValues values = new ContentValues();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
context.getContentResolver().update(uri, values, null);
|
||||
} else {
|
||||
context.getContentResolver().update(uri, values, null, null);
|
||||
}
|
||||
} catch (Exception exception){
|
||||
Log.e(TAG, "Failed to updateValue: " + exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void append(final String path, final byte[] content, final CompleteCallback callback, final Object context) {
|
||||
|
@ -11,6 +11,7 @@ import android.os.Looper;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
@ -34,6 +35,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class FileHelper {
|
||||
static final String TAG = "FileHelper";
|
||||
private Uri uri;
|
||||
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
private final Handler handler;
|
||||
@ -566,7 +568,11 @@ public class FileHelper {
|
||||
os.write(content, 0, content.length);
|
||||
os.flush();
|
||||
os.close();
|
||||
try {
|
||||
updateInternal(context);
|
||||
} catch (Exception exception){
|
||||
Log.e(TAG, "Failed to updateValue: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeBufferSyncInternal(Context context, ByteBuffer content) throws Exception {
|
||||
@ -579,7 +585,11 @@ public class FileHelper {
|
||||
channel.write(content);
|
||||
os.flush();
|
||||
os.close();
|
||||
try {
|
||||
updateInternal(context);
|
||||
} catch (Exception exception){
|
||||
Log.e(TAG, "Failed to updateValue: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void writeSync(Context context, byte[] content, @Nullable Callback callback) {
|
||||
@ -638,7 +648,11 @@ public class FileHelper {
|
||||
osw.write(content);
|
||||
osw.flush();
|
||||
osw.close();
|
||||
try {
|
||||
updateInternal(context);
|
||||
} catch (Exception exception){
|
||||
Log.e(TAG, "Failed to updateValue: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTextSync(Context context, String content, @Nullable String encoding, @Nullable Callback callback) {
|
||||
@ -764,14 +778,17 @@ public class FileHelper {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
context.getContentResolver().update(uri, values, null);
|
||||
} else {
|
||||
context.getContentResolver().update(uri, values, null, null);
|
||||
}
|
||||
|
||||
updateInternal(context, false);
|
||||
} catch (Exception exception){
|
||||
Log.e(TAG, "Failed to updateValue: " + exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void renameSync(Context context, String newName, @Nullable Callback callback) {
|
||||
|
Reference in New Issue
Block a user