Recreate libchildprocess after apk upgrade also when device has non-typical internal data dir

This commit is contained in:
Deve 2018-08-23 22:41:52 +02:00
parent 35b167a824
commit ad8b30b5d3
5 changed files with 49 additions and 26 deletions

View File

@ -1478,11 +1478,12 @@ void CIrrDeviceAndroid::readApplicationInfo(ANativeActivity* activity)
}
}
const AndroidApplicationInfo& CIrrDeviceAndroid::getApplicationInfo()
const AndroidApplicationInfo& CIrrDeviceAndroid::getApplicationInfo(
ANativeActivity* activity)
{
if (Android != NULL && ApplicationInfo.initialized == false)
if (activity != NULL && ApplicationInfo.initialized == false)
{
readApplicationInfo(Android->activity);
readApplicationInfo(activity);
}
return ApplicationInfo;

View File

@ -74,7 +74,6 @@ namespace irr
virtual bool isGyroscopeActive();
virtual bool isGyroscopeAvailable();
virtual void setTextInputEnabled(bool enabled) {TextInputEnabled = enabled;}
virtual const AndroidApplicationInfo& getApplicationInfo();
class CCursorControl : public gui::ICursorControl
{
@ -115,6 +114,8 @@ namespace irr
};
static void onCreate();
static const AndroidApplicationInfo& getApplicationInfo(
ANativeActivity* activity);
private:
android_app* Android;

View File

@ -28,6 +28,8 @@
#ifdef ANDROID
#include <android/asset_manager.h>
#include <sys/statfs.h>
#include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h"
#endif
//-----------------------------------------------------------------------------
@ -488,7 +490,7 @@ void AssetsAndroid::removeData()
if (file == m_stk_dir + "/.nomedia")
continue;
Log::info("AssetsAndroid", "Deleting file: %s\n", file.c_str());
Log::info("AssetsAndroid", "Deleting file: %s", file.c_str());
if (m_file_manager->isDirectory(file))
{
@ -499,13 +501,19 @@ void AssetsAndroid::removeData()
m_file_manager->removeFile(file);
}
}
std::string data_path = getDataPath();
const std::string data_path = "/data/data/" ANDROID_PACKAGE_NAME;
const std::string child_path = data_path + "/files/libchildprocess.so";
if (m_file_manager->fileExists(child_path))
if (!data_path.empty())
{
m_file_manager->removeFile(child_path);
const std::string child_path = data_path + "/files/libchildprocess.so";
if (m_file_manager->fileExists(child_path))
{
Log::info("AssetsAndroid", "Deleting old libchildprocess: %s",
child_path.c_str());
m_file_manager->removeFile(child_path);
}
}
#endif
}
@ -595,3 +603,27 @@ std::string AssetsAndroid::getPreferredPath(const std::vector<std::string>&
}
//-----------------------------------------------------------------------------
/** Get a path for internal data directory
* \return Path for internal data directory or empty string when failed
*/
std::string AssetsAndroid::getDataPath()
{
std::string data_path = "/data/data/" ANDROID_PACKAGE_NAME;
if (access(data_path.c_str(), R_OK) != 0)
{
Log::warn("AssetsAndroid", "Cannot use standard data dir");
AndroidApplicationInfo application_info =
CIrrDeviceAndroid::getApplicationInfo(global_android_app->activity);
data_path = application_info.data_dir;
}
if (access(data_path.c_str(), R_OK) != 0)
{
data_path = "";
}
return data_path;
}

View File

@ -42,6 +42,7 @@ public:
~AssetsAndroid() {};
void init();
static std::string getDataPath();
};

View File

@ -38,8 +38,7 @@
#include <dlfcn.h>
#include <fstream>
#include "graphics/irr_driver.hpp"
#include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h"
#include "io/assets_android.hpp"
#endif
// ----------------------------------------------------------------------------
@ -283,21 +282,8 @@ bool SeparateProcess::createChildProcess(const std::string& exe,
return false;
}
std::string data_path = "/data/data/" ANDROID_PACKAGE_NAME;
std::string data_path = AssetsAndroid::getDataPath();
std::string main_path = data_path + "/lib/libmain.so";
if (access(main_path.c_str(), R_OK) != 0)
{
Log::warn("SeparateProcess", "Cannot use standard data dir");
CIrrDeviceAndroid* device = dynamic_cast<CIrrDeviceAndroid*>(
irr_driver->getDevice());
AndroidApplicationInfo application_info = device->getApplicationInfo();
data_path = application_info.data_dir;
main_path = data_path + "/lib/libmain.so";
}
if (data_path.empty() || access(main_path.c_str(), R_OK) != 0)
{
@ -311,6 +297,8 @@ bool SeparateProcess::createChildProcess(const std::string& exe,
if (access(child_path.c_str(), R_OK) != 0)
{
Log::info("SeparateProcess", "Creating libchildprocess.so");
std::ifstream src(main_path, std::ios::binary);
if (!src.good())