-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure sync thread is started #6884
Changes from all commits
ec3512f
4ffab7f
03d83b2
f5104c7
0b1b228
eeeb569
f75b2e6
fc4f4f7
015aaa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ensure SyncThread is started when the app is launched after a Push has been received. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rename `DebugService.logDbUsageInfo` (resp. `Session.logDbUsageInfo`) to `DebugService.getDbUsageInfo` (resp. `Session.getDbUsageInfo`) and return a String instead of logging. The caller may want to log the String. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import android.content.Context | |
import arrow.core.Option | ||
import im.vector.app.ActiveSessionDataSource | ||
import im.vector.app.core.extensions.configureAndStart | ||
import im.vector.app.core.extensions.startSyncing | ||
import im.vector.app.core.pushers.UnifiedPushHelper | ||
import im.vector.app.core.services.GuardServiceStarter | ||
import im.vector.app.features.call.webrtc.WebRtcCallManager | ||
|
@@ -100,10 +101,16 @@ class ActiveSessionHolder @Inject constructor( | |
} | ||
|
||
suspend fun getOrInitializeSession(startSync: Boolean): Session? { | ||
return activeSessionReference.get() ?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session -> | ||
setActiveSession(session) | ||
session.configureAndStart(applicationContext, startSyncing = startSync) | ||
} | ||
return activeSessionReference.get() | ||
?.also { | ||
if (startSync && !it.syncService().isSyncThreadAlive()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my understanding of the error scenario
the fix is to always start the sync (if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's it, sorry, the code is not crystal clear. |
||
it.startSyncing(applicationContext) | ||
} | ||
} | ||
?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session -> | ||
setActiveSession(session) | ||
session.configureAndStart(applicationContext, startSyncing = startSync) | ||
} | ||
} | ||
|
||
fun isWaitingForSessionInitialization() = activeSessionReference.get() == null && authenticationService.hasAuthenticatedSessions() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.rageshake | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Application | ||
import android.os.Build | ||
import android.os.Process | ||
import java.lang.reflect.Method | ||
import javax.inject.Inject | ||
|
||
class ProcessInfo @Inject constructor() { | ||
fun getInfo() = buildString { | ||
append("===========================================\n") | ||
append("* PROCESS INFO *\n") | ||
append("===========================================\n") | ||
val processId = Process.myPid() | ||
append("ProcessId: $processId\n") | ||
append("ProcessName: ${getProcessName()}\n") | ||
append(getThreadInfo()) | ||
append("===========================================\n") | ||
} | ||
|
||
@SuppressLint("PrivateApi") | ||
private fun getProcessName(): String? { | ||
return if (Build.VERSION.SDK_INT >= 28) { | ||
Application.getProcessName() | ||
} else { | ||
try { | ||
val activityThread = Class.forName("android.app.ActivityThread") | ||
val getProcessName: Method = activityThread.getDeclaredMethod("currentProcessName") | ||
getProcessName.invoke(null) as? String | ||
} catch (t: Throwable) { | ||
null | ||
} | ||
} | ||
} | ||
|
||
private fun getThreadInfo() = buildString { | ||
append("Thread activeCount: ${Thread.activeCount()}\n") | ||
Thread.getAllStackTraces().keys | ||
.sortedBy { it.name } | ||
.forEach { thread -> append(thread.getInfo()) } | ||
} | ||
} | ||
|
||
private fun Thread.getInfo() = buildString { | ||
append("Thread '$name':") | ||
append(" id: $id") | ||
append(" priority: $priority") | ||
append(" group name: ${threadGroup?.name ?: "null"}") | ||
append(" state: $state") | ||
append(" isAlive: $isAlive") | ||
append(" isDaemon: $isDaemon") | ||
append(" isInterrupted: $isInterrupted") | ||
append("\n") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be clashing with https://github.com/vector-im/element-android/blob/develop/vector/src/main/java/im/vector/app/VectorApplication.kt#L176
I've always wondered if we should stop syncing when entering the foreground 🤔
EDIT - I guess the difference is foreground sync thread vs background sync workers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in foreground we should always have sync polling. Did you mean 'background'?
Also in VectorApplication, the Session may not be restored yet.
I am still investigating, but I agree this code is quite tricky...