Merge pull request #44215 from Faless/fix/fa_buffered_remove_android

Remove unused FileAccessJAndroid.
This commit is contained in:
Rémi Verschelde 2020-12-09 11:59:28 +01:00 committed by GitHub
commit deba274ad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3 additions and 294 deletions

View File

@ -6,7 +6,6 @@ android_files = [
"os_android.cpp",
"file_access_android.cpp",
"audio_driver_opensl.cpp",
"file_access_jandroid.cpp",
"dir_access_jandroid.cpp",
"thread_jandroid.cpp",
"net_socket_android.cpp",

View File

@ -30,7 +30,7 @@
#include "dir_access_jandroid.h"
#include "core/string/print_string.h"
#include "file_access_jandroid.h"
#include "file_access_android.h"
#include "string_android.h"
#include "thread_jandroid.h"
@ -146,7 +146,7 @@ bool DirAccessJAndroid::file_exists(String p_file) {
else
sd = current_dir.plus_file(p_file);
FileAccessJAndroid *f = memnew(FileAccessJAndroid);
FileAccessAndroid *f = memnew(FileAccessAndroid);
bool exists = f->file_exists(sd);
memdelete(f);

View File

@ -1,197 +0,0 @@
/*************************************************************************/
/* file_access_jandroid.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "file_access_jandroid.h"
#include "core/os/os.h"
#include "thread_jandroid.h"
#include <unistd.h>
jobject FileAccessJAndroid::io = nullptr;
jclass FileAccessJAndroid::cls;
jmethodID FileAccessJAndroid::_file_open = 0;
jmethodID FileAccessJAndroid::_file_get_size = 0;
jmethodID FileAccessJAndroid::_file_seek = 0;
jmethodID FileAccessJAndroid::_file_read = 0;
jmethodID FileAccessJAndroid::_file_tell = 0;
jmethodID FileAccessJAndroid::_file_eof = 0;
jmethodID FileAccessJAndroid::_file_close = 0;
FileAccess *FileAccessJAndroid::create_jandroid() {
return memnew(FileAccessJAndroid);
}
Error FileAccessJAndroid::_open(const String &p_path, int p_mode_flags) {
if (is_open())
close();
String path = fix_path(p_path).simplify_path();
if (path.begins_with("/"))
path = path.substr(1, path.length());
else if (path.begins_with("res://"))
path = path.substr(6, path.length());
JNIEnv *env = ThreadAndroid::get_env();
jstring js = env->NewStringUTF(path.utf8().get_data());
int res = env->CallIntMethod(io, _file_open, js, (p_mode_flags & WRITE) ? true : false);
env->DeleteLocalRef(js);
OS::get_singleton()->print("fopen: '%s' ret %i\n", path.utf8().get_data(), res);
if (res <= 0)
return ERR_FILE_CANT_OPEN;
id = res;
return OK;
}
void FileAccessJAndroid::close() {
if (!is_open())
return;
JNIEnv *env = ThreadAndroid::get_env();
env->CallVoidMethod(io, _file_close, id);
id = 0;
}
bool FileAccessJAndroid::is_open() const {
return id != 0;
}
void FileAccessJAndroid::seek(size_t p_position) {
JNIEnv *env = ThreadAndroid::get_env();
ERR_FAIL_COND_MSG(!is_open(), "File must be opened before use.");
env->CallVoidMethod(io, _file_seek, id, p_position);
}
void FileAccessJAndroid::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!is_open(), "File must be opened before use.");
seek(get_len());
}
size_t FileAccessJAndroid::get_position() const {
JNIEnv *env = ThreadAndroid::get_env();
ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use.");
return env->CallIntMethod(io, _file_tell, id);
}
size_t FileAccessJAndroid::get_len() const {
JNIEnv *env = ThreadAndroid::get_env();
ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use.");
return env->CallIntMethod(io, _file_get_size, id);
}
bool FileAccessJAndroid::eof_reached() const {
JNIEnv *env = ThreadAndroid::get_env();
ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use.");
return env->CallIntMethod(io, _file_eof, id);
}
uint8_t FileAccessJAndroid::get_8() const {
ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use.");
uint8_t byte;
get_buffer(&byte, 1);
return byte;
}
int FileAccessJAndroid::get_buffer(uint8_t *p_dst, int p_length) const {
ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use.");
if (p_length == 0)
return 0;
JNIEnv *env = ThreadAndroid::get_env();
jbyteArray jca = (jbyteArray)env->CallObjectMethod(io, _file_read, id, p_length);
int len = env->GetArrayLength(jca);
env->GetByteArrayRegion(jca, 0, len, (jbyte *)p_dst);
env->DeleteLocalRef((jobject)jca);
return len;
}
Error FileAccessJAndroid::get_error() const {
if (eof_reached())
return ERR_FILE_EOF;
return OK;
}
void FileAccessJAndroid::flush() {
}
void FileAccessJAndroid::store_8(uint8_t p_dest) {
}
bool FileAccessJAndroid::file_exists(const String &p_path) {
JNIEnv *env = ThreadAndroid::get_env();
String path = fix_path(p_path).simplify_path();
if (path.begins_with("/"))
path = path.substr(1, path.length());
else if (path.begins_with("res://"))
path = path.substr(6, path.length());
jstring js = env->NewStringUTF(path.utf8().get_data());
int res = env->CallIntMethod(io, _file_open, js, false);
if (res <= 0) {
env->DeleteLocalRef(js);
return false;
}
env->CallVoidMethod(io, _file_close, res);
env->DeleteLocalRef(js);
return true;
}
void FileAccessJAndroid::setup(jobject p_io) {
io = p_io;
JNIEnv *env = ThreadAndroid::get_env();
jclass c = env->GetObjectClass(io);
cls = (jclass)env->NewGlobalRef(c);
_file_open = env->GetMethodID(cls, "file_open", "(Ljava/lang/String;Z)I");
_file_get_size = env->GetMethodID(cls, "file_get_size", "(I)I");
_file_tell = env->GetMethodID(cls, "file_tell", "(I)I");
_file_eof = env->GetMethodID(cls, "file_eof", "(I)Z");
_file_seek = env->GetMethodID(cls, "file_seek", "(II)V");
_file_read = env->GetMethodID(cls, "file_read", "(II)[B");
_file_close = env->GetMethodID(cls, "file_close", "(I)V");
}
FileAccessJAndroid::FileAccessJAndroid() {
id = 0;
}
FileAccessJAndroid::~FileAccessJAndroid() {
if (is_open())
close();
}

View File

@ -1,83 +0,0 @@
/*************************************************************************/
/* file_access_jandroid.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef FILE_ACCESS_JANDROID_H
#define FILE_ACCESS_JANDROID_H
#include "core/os/file_access.h"
#include "java_godot_lib_jni.h"
class FileAccessJAndroid : public FileAccess {
static jobject io;
static jclass cls;
static jmethodID _file_open;
static jmethodID _file_get_size;
static jmethodID _file_seek;
static jmethodID _file_tell;
static jmethodID _file_eof;
static jmethodID _file_read;
static jmethodID _file_close;
int id;
static FileAccess *create_jandroid();
public:
virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
virtual int get_buffer(uint8_t *p_dst, int p_length) const;
virtual Error get_error() const; ///< get last error
virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte
virtual bool file_exists(const String &p_path); ///< return true if a file exists
static void setup(jobject p_io);
virtual uint64_t _get_modified_time(const String &p_file) { return 0; }
virtual uint32_t _get_unix_permissions(const String &p_file) { return 0; }
virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) { return FAILED; }
FileAccessJAndroid();
~FileAccessJAndroid();
};
#endif // FILE_ACCESS_JANDROID_H

View File

@ -43,7 +43,6 @@
#include "dir_access_jandroid.h"
#include "display_server_android.h"
#include "file_access_android.h"
#include "file_access_jandroid.h"
#include "jni_utils.h"
#include "main/main.h"
#include "net_socket_android.h"
@ -89,14 +88,10 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
godot_io_java = new GodotIOJavaWrapper(env, godot_java->get_member_object("io", "Lorg/godotengine/godot/GodotIO;", env));
ThreadAndroid::make_default(jvm);
#ifdef USE_JAVA_FILE_ACCESS
FileAccessJAndroid::setup(godot_io_java->get_instance());
#else
jobject amgr = env->NewGlobalRef(p_asset_manager);
FileAccessAndroid::asset_manager = AAssetManager_fromJava(env, amgr);
#endif
DirAccessJAndroid::setup(godot_io_java->get_instance());
AudioDriverAndroid::setup(godot_io_java->get_instance());

View File

@ -33,12 +33,11 @@
#include "core/config/project_settings.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "file_access_android.h"
#include "main/main.h"
#include "platform/android/display_server_android.h"
#include "dir_access_jandroid.h"
#include "file_access_jandroid.h"
#include "file_access_android.h"
#include "net_socket_android.h"
#include <dlfcn.h>
@ -61,11 +60,7 @@ void OS_Android::initialize_core() {
if (use_apk_expansion)
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
else {
#ifdef USE_JAVA_FILE_ACCESS
FileAccess::make_default<FileAccessJAndroid>(FileAccess::ACCESS_RESOURCES);
#else
FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
#endif
}
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);