1
0
mirror of https://github.com/PurpleI2P/i2pd-android.git synced 2025-01-13 00:08:08 +00:00

set datadir in daemon before init

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2022-04-09 20:11:16 +03:00
parent 578a97f549
commit 4be1d99e8f
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
4 changed files with 33 additions and 29 deletions

View File

@ -35,40 +35,30 @@ namespace android
bool DaemonAndroidImpl::init(int argc, char* argv[]) bool DaemonAndroidImpl::init(int argc, char* argv[])
{ {
// make sure assets are ready before proceed
i2p::fs::DetectDataDir(dataDir, false);
int numAttempts = 0;
do
{
if (i2p::fs::Exists (i2p::fs::DataDirPath("assets.ready"))) break; // assets ready
numAttempts++;
std::this_thread::sleep_for (std::chrono::seconds(1)); // otherwise wait for 1 more second
}
while (numAttempts <= 10); // 10 seconds max
return Daemon.init(argc, argv); return Daemon.init(argc, argv);
} }
void DaemonAndroidImpl::start() void DaemonAndroidImpl::start()
{ {
//QMutexLocker locker(mutex);
//setRunning(true);
Daemon.start(); Daemon.start();
} }
void DaemonAndroidImpl::stop() void DaemonAndroidImpl::stop()
{ {
//QMutexLocker locker(mutex);
Daemon.stop(); Daemon.stop();
//setRunning(false);
} }
void DaemonAndroidImpl::restart() void DaemonAndroidImpl::restart()
{ {
//QMutexLocker locker(mutex);
stop(); stop();
start(); start();
} }
void DaemonAndroidImpl::setDataDir(std::string path)
{
Daemon.setDataDir(path);
}
static DaemonAndroidImpl daemon; static DaemonAndroidImpl daemon;
static char* argv[1]={strdup("tmp")}; static char* argv[1]={strdup("tmp")};
/** /**
@ -80,7 +70,20 @@ namespace android
try try
{ {
{ {
//Log.d(TAG"Initialising the daemon..."); // make sure assets are ready before proceed
i2p::fs::DetectDataDir(dataDir, false);
int numAttempts = 0;
do
{
if (i2p::fs::Exists (i2p::fs::DataDirPath("assets.ready"))) break; // assets ready
numAttempts++;
std::this_thread::sleep_for (std::chrono::seconds(1)); // otherwise wait for 1 more second
}
while (numAttempts <= 10); // 10 seconds max
// Set application directory
daemon.setDataDir(dataDir);
bool daemonInitSuccess = daemon.init(1, argv); bool daemonInitSuccess = daemon.init(1, argv);
if(!daemonInitSuccess) if(!daemonInitSuccess)
{ {

View File

@ -25,26 +25,28 @@ namespace android
/** /**
* @return success * @return success
*/ */
bool init(int argc, char* argv[]); bool init (int argc, char* argv[]);
void start(); void start ();
void stop(); void stop ();
void restart(); void restart ();
void setDataDir (std::string path);
}; };
/** /**
* returns "ok" if daemon init failed * returns "ok" if daemon init failed
* returns errinfo if daemon initialized and started okay * returns errinfo if daemon initialized and started okay
*/ */
std::string start(); std::string start ();
void stop(); void stop ();
// set datadir received from jni // set datadir received from jni
void SetDataDir(std::string jdataDir); void SetDataDir (std::string jdataDir);
// get datadir // get datadir
std::string GetDataDir(void); std::string GetDataDir (void);
// set webconsole language // set webconsole language
void SetLanguage(std::string jlanguage); void SetLanguage (std::string jlanguage);
} }
} }

@ -1 +1 @@
Subproject commit 207b13dcabbd0e49b26ceddc94d30a51ecb13f52 Subproject commit 2f10decf567a77cbb5a84fc1c7304eab91a1487f

View File

@ -24,7 +24,7 @@ public class SettingsActivity extends Activity {
//protected IniEditor iniedit = new IniEditor(); //protected IniEditor iniedit = new IniEditor();
private String TAG = "i2pdSrvcSettings"; private String TAG = "i2pdSrvcSettings";
private File cacheDir; private File cacheDir;
public static String onBootFileName="/onBoot"; // just file, empty, if exist the do autostart, if not then no. public static String onBootFileName = "/onBoot"; // just file, empty, if exist the do autostart, if not then no.
//https://gist.github.com/chandruark/3165a5ee3452f2b9ec7736cf1b4c5ea6 //https://gist.github.com/chandruark/3165a5ee3452f2b9ec7736cf1b4c5ea6
private void addAutoStartupSwitch() { private void addAutoStartupSwitch() {
@ -81,11 +81,10 @@ public class SettingsActivity extends Activity {
Log.i(TAG, "onCreate"); Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings); setContentView(R.layout.activity_settings);
Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true); Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
Switch autostart_switch = findViewById(R.id.autostart_enable);
cacheDir = getApplicationContext().getCacheDir(); cacheDir = getApplicationContext().getCacheDir();
Switch autostart_switch = findViewById(R.id.autostart_enable);
File onBoot = new File(cacheDir.getAbsolutePath() + onBootFileName); File onBoot = new File(cacheDir.getAbsolutePath() + onBootFileName);
autostart_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { autostart_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {