Skip to content

Commit

Permalink
android: save tool running state before onStop and restore onStart
Browse files Browse the repository at this point in the history
This prevents the app from acquiring data in the background

Signed-off-by: Adrian Suciu <[email protected]>
  • Loading branch information
adisuciu committed Apr 5, 2022
1 parent 64b5e20 commit 67cd6f0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
8 changes: 8 additions & 0 deletions android/src/org/adi/scopy/ScopyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
public class ScopyActivity extends QtActivity
{
public static native void saveSessionJavaHelper();
public static native void saveAndStopRunningToolsJNI();
public static native void restoreRunningToolsJNI();
boolean initialized;

@Override
Expand All @@ -50,13 +52,19 @@ protected void onStart()
{
System.out.println("-- ScopyActivity: onStart");
super.onStart();
if(initialized) {
restoreRunningToolsJNI();
}
}

@Override
protected void onStop()
{
System.out.println("-- ScopyActivity: onStop");
super.onStop();
if(initialized) {
saveAndStopRunningToolsJNI();
}
}

protected void onPause(){
Expand Down
50 changes: 48 additions & 2 deletions src/tool_launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,29 @@ bool ToolLauncher::loadDecoders(QString path)
return true;
}

void adiscope::ToolLauncher::saveRunningTools() {
for(auto &tool : toolList) {
if(tool->isRunning()) {
running_tools.push_back(tool);
}
}
}

void adiscope::ToolLauncher::stopRunningTools() {
for(auto &tool : running_tools) {
tool->stop();
}
}

void adiscope::ToolLauncher::restoreRunningTools() {
while(!running_tools.empty())
{
Tool* tool = running_tools.back();
running_tools.pop_back();
tool->run();
}
}


void adiscope::ToolLauncher::saveRunningToolsBeforeCalibration()
{
Expand Down Expand Up @@ -2063,7 +2086,7 @@ bool ToolLauncher::eventFilter(QObject *watched, QEvent *event)
#ifdef __ANDROID__

void ToolLauncher::saveSessionJavaHelper(JNIEnv *env, jobject /*thiz*/) {
qDebug()<<"-- Saving session";
qDebug()<<"-- Saving session JNI";
ToolLauncher* tl = getToolLauncherInstance();
if(tl)
{
Expand All @@ -2072,9 +2095,32 @@ void ToolLauncher::saveSessionJavaHelper(JNIEnv *env, jobject /*thiz*/) {
}
}


void ToolLauncher::saveAndStopRunningToolsJNI(JNIEnv *env, jobject /*thiz*/) {
qDebug()<<"-- Saving and stopping tools JNI";
ToolLauncher* tl = getToolLauncherInstance();
if(tl)
{
getToolLauncherInstance()->saveRunningTools();
getToolLauncherInstance()->stopRunningTools();
}
}

void ToolLauncher::restoreRunningToolsJNI(JNIEnv *env, jobject /*thiz*/) {
qDebug()<<"-- Saving and stopping tools JNI";
ToolLauncher* tl = getToolLauncherInstance();
if(tl)
{
getToolLauncherInstance()->restoreRunningTools();
}
}


void ToolLauncher::registerNativeMethods()
{
JNINativeMethod methods[] = {{"saveSessionJavaHelper", "()V", reinterpret_cast<void*>(saveSessionJavaHelper) }};
JNINativeMethod methods[] = {{"saveSessionJavaHelper", "()V", reinterpret_cast<void*>(saveSessionJavaHelper) },
{"saveAndStopRunningToolsJNI", "()V", reinterpret_cast<void*>(saveAndStopRunningToolsJNI) },
{"restoreRunningToolsJNI", "()V", reinterpret_cast<void*>(restoreRunningToolsJNI) }};

QAndroidJniObject activity = QtAndroid::androidActivity();
QAndroidJniEnvironment env;
Expand Down
7 changes: 7 additions & 0 deletions src/tool_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private Q_SLOTS:
void calibrationSuccessCallback();
void calibrationThreadWatcherFinished();
private:
QList<Tool*> running_tools;
QList<Tool*> calibration_saved_tools;
void loadToolTips(bool connected);
QVector<QString> searchDevices();
Expand Down Expand Up @@ -206,6 +207,8 @@ private Q_SLOTS:
#ifdef __ANDROID__
void registerNativeMethods();
static void saveSessionJavaHelper(JNIEnv *env, jobject /*thiz*/);
static void saveAndStopRunningToolsJNI(JNIEnv *env, jobject /*thiz*/);
static void restoreRunningToolsJNI(JNIEnv *env, jobject /*thiz*/);
#endif

private:
Expand Down Expand Up @@ -293,6 +296,10 @@ private Q_SLOTS:
void saveRunningToolsBeforeCalibration();
void stopToolsBeforeCalibration();

void saveRunningTools();
void restoreRunningTools();
void stopRunningTools();

QNetworkAccessManager* networkAccessManager;
PhoneHome* m_phoneHome;

Expand Down

0 comments on commit 67cd6f0

Please sign in to comment.