Merge pull request #13431 from Cristo86/android_stop_downloads_bg

Android - Prevent pending downloads to happen when going back to home
This commit is contained in:
Sam Gondelman 2018-07-12 15:22:56 -07:00 committed by GitHub
commit b53772f9ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 0 deletions

View file

@ -304,6 +304,11 @@ Java_io_highfidelity_hifiinterface_MainActivity_nativeGetDisplayName(JNIEnv *env
return env->NewStringUTF(username.toLatin1().data()); return env->NewStringUTF(username.toLatin1().data());
} }
JNIEXPORT void JNICALL
Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeBeforeEnterBackground(JNIEnv *env, jobject obj) {
AndroidHelper::instance().notifyBeforeEnterBackground();
}
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeEnterBackground(JNIEnv *env, jobject obj) { Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeEnterBackground(JNIEnv *env, jobject obj) {
AndroidHelper::instance().notifyEnterBackground(); AndroidHelper::instance().notifyEnterBackground();

View file

@ -59,6 +59,7 @@ public class InterfaceActivity extends QtActivity implements WebViewFragment.OnW
private native long nativeOnCreate(InterfaceActivity instance, AssetManager assetManager); private native long nativeOnCreate(InterfaceActivity instance, AssetManager assetManager);
private native void nativeOnDestroy(); private native void nativeOnDestroy();
private native void nativeGotoUrl(String url); private native void nativeGotoUrl(String url);
private native void nativeBeforeEnterBackground();
private native void nativeEnterBackground(); private native void nativeEnterBackground();
private native void nativeEnterForeground(); private native void nativeEnterForeground();
private native long nativeOnExitVr(); private native long nativeOnExitVr();
@ -291,6 +292,7 @@ public class InterfaceActivity extends QtActivity implements WebViewFragment.OnW
case "Home": case "Home":
case "Privacy Policy": case "Privacy Policy":
case "Login": { case "Login": {
nativeBeforeEnterBackground();
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_FRAGMENT, activityName); intent.putExtra(MainActivity.EXTRA_FRAGMENT, activityName);
intent.putExtra(MainActivity.EXTRA_BACK_TO_SCENE, backToScene); intent.putExtra(MainActivity.EXTRA_BACK_TO_SCENE, backToScene);

View file

@ -35,6 +35,10 @@ void AndroidHelper::notifyEnterForeground() {
emit enterForeground(); emit enterForeground();
} }
void AndroidHelper::notifyBeforeEnterBackground() {
emit beforeEnterBackground();
}
void AndroidHelper::notifyEnterBackground() { void AndroidHelper::notifyEnterBackground() {
emit enterBackground(); emit enterBackground();
} }

View file

@ -24,6 +24,7 @@ public:
void requestActivity(const QString &activityName, const bool backToScene, QList<QString> args = QList<QString>()); void requestActivity(const QString &activityName, const bool backToScene, QList<QString> args = QList<QString>());
void notifyLoadComplete(); void notifyLoadComplete();
void notifyEnterForeground(); void notifyEnterForeground();
void notifyBeforeEnterBackground();
void notifyEnterBackground(); void notifyEnterBackground();
void performHapticFeedback(int duration); void performHapticFeedback(int duration);
@ -39,6 +40,7 @@ signals:
void androidActivityRequested(const QString &activityName, const bool backToScene, QList<QString> args = QList<QString>()); void androidActivityRequested(const QString &activityName, const bool backToScene, QList<QString> args = QList<QString>());
void qtAppLoadComplete(); void qtAppLoadComplete();
void enterForeground(); void enterForeground();
void beforeEnterBackground();
void enterBackground(); void enterBackground();
void hapticFeedbackRequested(int duration); void hapticFeedbackRequested(int duration);

View file

@ -2258,6 +2258,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
qCDebug(interfaceapp) << "Metaverse session ID is" << uuidStringWithoutCurlyBraces(accountManager->getSessionID()); qCDebug(interfaceapp) << "Metaverse session ID is" << uuidStringWithoutCurlyBraces(accountManager->getSessionID());
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
connect(&AndroidHelper::instance(), &AndroidHelper::beforeEnterBackground, this, &Application::beforeEnterBackground);
connect(&AndroidHelper::instance(), &AndroidHelper::enterBackground, this, &Application::enterBackground); connect(&AndroidHelper::instance(), &AndroidHelper::enterBackground, this, &Application::enterBackground);
connect(&AndroidHelper::instance(), &AndroidHelper::enterForeground, this, &Application::enterForeground); connect(&AndroidHelper::instance(), &AndroidHelper::enterForeground, this, &Application::enterForeground);
AndroidHelper::instance().notifyLoadComplete(); AndroidHelper::instance().notifyLoadComplete();
@ -8342,6 +8343,13 @@ void Application::copyToClipboard(const QString& text) {
} }
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
void Application::beforeEnterBackground() {
auto nodeList = DependencyManager::get<NodeList>();
nodeList->setSendDomainServerCheckInEnabled(false);
nodeList->reset(true);
clearDomainOctreeDetails();
}
void Application::enterBackground() { void Application::enterBackground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection); "stop", Qt::BlockingQueuedConnection);
@ -8356,6 +8364,8 @@ void Application::enterForeground() {
if (!getActiveDisplayPlugin() || getActiveDisplayPlugin()->isActive() || !getActiveDisplayPlugin()->activate()) { if (!getActiveDisplayPlugin() || getActiveDisplayPlugin()->isActive() || !getActiveDisplayPlugin()->activate()) {
qWarning() << "Could not re-activate display plugin"; qWarning() << "Could not re-activate display plugin";
} }
auto nodeList = DependencyManager::get<NodeList>();
nodeList->setSendDomainServerCheckInEnabled(true);
} }
#endif #endif

View file

@ -313,6 +313,7 @@ public:
Q_INVOKABLE void copyToClipboard(const QString& text); Q_INVOKABLE void copyToClipboard(const QString& text);
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
void beforeEnterBackground();
void enterBackground(); void enterBackground();
void enterForeground(); void enterForeground();
#endif #endif

View file

@ -289,6 +289,12 @@ void NodeList::addSetOfNodeTypesToNodeInterestSet(const NodeSet& setOfNodeTypes)
} }
void NodeList::sendDomainServerCheckIn() { void NodeList::sendDomainServerCheckIn() {
if (!_sendDomainServerCheckInEnabled) {
qCDebug(networking) << "Refusing to send a domain-server check in while it is disabled.";
return;
}
if (thread() != QThread::currentThread()) { if (thread() != QThread::currentThread()) {
QMetaObject::invokeMethod(this, "sendDomainServerCheckIn", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "sendDomainServerCheckIn", Qt::QueuedConnection);
return; return;

View file

@ -90,6 +90,9 @@ public:
bool getRequestsDomainListData() { return _requestsDomainListData; } bool getRequestsDomainListData() { return _requestsDomainListData; }
void setRequestsDomainListData(bool isRequesting); void setRequestsDomainListData(bool isRequesting);
bool getSendDomainServerCheckInEnabled() { return _sendDomainServerCheckInEnabled; }
void setSendDomainServerCheckInEnabled(bool enabled) { _sendDomainServerCheckInEnabled = enabled; }
void removeFromIgnoreMuteSets(const QUuid& nodeID); void removeFromIgnoreMuteSets(const QUuid& nodeID);
virtual bool isDomainServer() const override { return false; } virtual bool isDomainServer() const override { return false; }
@ -169,6 +172,8 @@ private:
QTimer _keepAlivePingTimer; QTimer _keepAlivePingTimer;
bool _requestsDomainListData { false }; bool _requestsDomainListData { false };
bool _sendDomainServerCheckInEnabled { true };
mutable QReadWriteLock _ignoredSetLock; mutable QReadWriteLock _ignoredSetLock;
tbb::concurrent_unordered_set<QUuid, UUIDHasher> _ignoredNodeIDs; tbb::concurrent_unordered_set<QUuid, UUIDHasher> _ignoredNodeIDs;
mutable QReadWriteLock _personalMutedSetLock; mutable QReadWriteLock _personalMutedSetLock;