Android - Rollback pause/resume mechanism. Stop server checkIns, reset nodeList before entering background

This commit is contained in:
Cristian Luis Duarte 2018-07-06 20:43:52 -03:00
parent a878ad5a33
commit be8351dc0d
10 changed files with 36 additions and 23 deletions

View file

@ -285,6 +285,11 @@ Java_io_highfidelity_hifiinterface_MainActivity_nativeGetDisplayName(JNIEnv *env
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
Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeEnterBackground(JNIEnv *env, jobject obj) {
AndroidHelper::instance().notifyEnterBackground();

View file

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

View file

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

View file

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

View file

@ -2259,6 +2259,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
qCDebug(interfaceapp) << "Metaverse session ID is" << uuidStringWithoutCurlyBraces(accountManager->getSessionID());
#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::enterForeground, this, &Application::enterForeground);
AndroidHelper::instance().notifyLoadComplete();
@ -8299,14 +8300,19 @@ void Application::saveNextPhysicsStats(QString filename) {
}
#if defined(Q_OS_ANDROID)
void Application::beforeEnterBackground() {
auto nodeList = DependencyManager::get<NodeList>();
nodeList->setSendDomainServerCheckInEnabled(false);
nodeList->reset(true);
clearDomainOctreeDetails();
}
void Application::enterBackground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection);
if (getActiveDisplayPlugin()->isActive()) {
getActiveDisplayPlugin()->deactivate();
}
DependencyManager::get<ResourceCacheSharedItems>()->pausePendingRequests();
clearDomainOctreeDetails();
}
void Application::enterForeground() {
@ -8315,7 +8321,8 @@ void Application::enterForeground() {
if (!getActiveDisplayPlugin() || getActiveDisplayPlugin()->isActive() || !getActiveDisplayPlugin()->activate()) {
qWarning() << "Could not re-activate display plugin";
}
DependencyManager::get<ResourceCacheSharedItems>()->resumePendingRequests();
auto nodeList = DependencyManager::get<NodeList>();
nodeList->setSendDomainServerCheckInEnabled(true);
}
#endif

View file

@ -311,6 +311,7 @@ public:
void unloadAvatarScripts();
#if defined(Q_OS_ANDROID)
void beforeEnterBackground();
void enterBackground();
void enterForeground();
#endif

View file

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

View file

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

View file

@ -95,14 +95,6 @@ void ResourceCacheSharedItems::removeRequest(QWeakPointer<Resource> resource) {
}
}
void ResourceCacheSharedItems::pausePendingRequests() {
_pendingRequestsPaused = true;
}
void ResourceCacheSharedItems::resumePendingRequests() {
_pendingRequestsPaused = false;
}
QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
// look for the highest priority pending request
int highestIndex = -1;
@ -502,9 +494,7 @@ void ResourceCache::requestCompleted(QWeakPointer<Resource> resource) {
sharedItems->removeRequest(resource);
--_requestsActive;
if (!sharedItems->pendingRequestsPaused()) {
attemptHighestPriorityRequest();
}
attemptHighestPriorityRequest();
}
bool ResourceCache::attemptHighestPriorityRequest() {

View file

@ -71,24 +71,16 @@ public:
void removeRequest(QWeakPointer<Resource> doneRequest);
QList<QSharedPointer<Resource>> getPendingRequests();
uint32_t getPendingRequestsCount() const;
void pausePendingRequests();
void resumePendingRequests();
QList<QSharedPointer<Resource>> getLoadingRequests();
QSharedPointer<Resource> getHighestPendingRequest();
uint32_t getLoadingRequestsCount() const;
bool pendingRequestsPaused() { return _pendingRequestsPaused; }
private:
ResourceCacheSharedItems() = default;
mutable Mutex _mutex;
QList<QWeakPointer<Resource>> _pendingRequests;
QList<QWeakPointer<Resource>> _loadingRequests;
bool _pendingRequestsPaused { false };
};
/// Wrapper to expose resources to JS/QML
@ -488,7 +480,6 @@ public slots:
private:
friend class ResourceCache;
friend class ScriptableResource;
friend class ResourceCacheSharedItems;
void setLRUKey(int lruKey) { _lruKey = lruKey; }