mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-05-01 12:26:26 +00:00
Reworked a few things to speed up app cold startup
This commit is contained in:
parent
1734d11639
commit
52e7acb4ee
10 changed files with 32 additions and 35 deletions
|
|
@ -58,6 +58,7 @@ import org.linphone.utils.AppUtils
|
||||||
import org.linphone.utils.ImageUtils
|
import org.linphone.utils.ImageUtils
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
import org.linphone.utils.PhoneNumberUtils
|
import org.linphone.utils.PhoneNumberUtils
|
||||||
|
import org.linphone.utils.ShortcutUtils
|
||||||
|
|
||||||
class ContactsManager @UiThread constructor() {
|
class ContactsManager @UiThread constructor() {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -174,6 +175,9 @@ class ContactsManager @UiThread constructor() {
|
||||||
conferenceAvatarMap.clear()
|
conferenceAvatarMap.clear()
|
||||||
|
|
||||||
notifyContactsListChanged()
|
notifyContactsListChanged()
|
||||||
|
|
||||||
|
Log.i("$TAG Native contacts have been loaded, creating chat rooms shortcuts")
|
||||||
|
ShortcutUtils.createShortcutsToChatRooms(coreContext.context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
|
|
@ -343,6 +347,16 @@ class ContactsManager @UiThread constructor() {
|
||||||
for (list in core.friendsLists) {
|
for (list in core.friendsLists) {
|
||||||
list.addListener(friendListListener)
|
list.addListener(friendListListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val context = coreContext.context
|
||||||
|
if (ActivityCompat.checkSelfPermission(
|
||||||
|
context,
|
||||||
|
Manifest.permission.READ_CONTACTS
|
||||||
|
) != PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
Log.w("$TAG READ_CONTACTS permission was denied, creating chat rooms shortcuts")
|
||||||
|
ShortcutUtils.createShortcutsToChatRooms(context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
|
|
|
||||||
|
|
@ -236,12 +236,20 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
||||||
core.isAutoIterateEnabled = true
|
core.isAutoIterateEnabled = true
|
||||||
core.addListener(coreListener)
|
core.addListener(coreListener)
|
||||||
|
|
||||||
|
coreThread.postDelayed({ startCore() }, 50)
|
||||||
|
|
||||||
|
Looper.loop()
|
||||||
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
fun startCore() {
|
||||||
|
Log.i("$TAG Configuring Core")
|
||||||
core.videoCodecPriorityPolicy = CodecPriorityPolicy.Auto
|
core.videoCodecPriorityPolicy = CodecPriorityPolicy.Auto
|
||||||
|
|
||||||
updateFriendListsSubscriptionDependingOnDefaultAccount()
|
updateFriendListsSubscriptionDependingOnDefaultAccount()
|
||||||
|
|
||||||
computeUserAgent()
|
computeUserAgent()
|
||||||
Log.i("$TAG Core has been created with user-agent [${core.userAgent}], starting it")
|
Log.i("$TAG Core has been configured with user-agent [${core.userAgent}], starting it")
|
||||||
core.start()
|
core.start()
|
||||||
|
|
||||||
contactsManager.onCoreStarted(core)
|
contactsManager.onCoreStarted(core)
|
||||||
|
|
@ -252,7 +260,6 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
||||||
audioManager.registerAudioDeviceCallback(audioDeviceCallback, coreThread)
|
audioManager.registerAudioDeviceCallback(audioDeviceCallback, coreThread)
|
||||||
|
|
||||||
Log.i("$TAG Report Core created and started")
|
Log.i("$TAG Report Core created and started")
|
||||||
Looper.loop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
|
|
|
||||||
|
|
@ -379,8 +379,6 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
||||||
fun onCoreStarted(core: Core) {
|
fun onCoreStarted(core: Core) {
|
||||||
Log.i("$TAG Core has been started")
|
Log.i("$TAG Core has been started")
|
||||||
core.addListener(coreListener)
|
core.addListener(coreListener)
|
||||||
|
|
||||||
ShortcutUtils.createShortcutsToChatRooms(context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,6 @@ class AssistantActivity : GenericActivity() {
|
||||||
binding = DataBindingUtil.setContentView(this, R.layout.assistant_activity)
|
binding = DataBindingUtil.setContentView(this, R.layout.assistant_activity)
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
while (!coreContext.isReady()) {
|
|
||||||
Thread.sleep(20)
|
|
||||||
}
|
|
||||||
|
|
||||||
coreContext.postOnCoreThread { core ->
|
coreContext.postOnCoreThread { core ->
|
||||||
if (core.accountList.isEmpty()) {
|
if (core.accountList.isEmpty()) {
|
||||||
Log.i("$TAG No account configured, disabling back gesture")
|
Log.i("$TAG No account configured, disabling back gesture")
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,12 @@ import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewTreeObserver
|
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
import androidx.annotation.UiThread
|
import androidx.annotation.UiThread
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
|
import androidx.core.view.doOnAttach
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
|
@ -91,7 +91,7 @@ class MainActivity : GenericActivity() {
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
while (!coreContext.isReady()) {
|
while (!coreContext.isReady()) {
|
||||||
Thread.sleep(20)
|
Thread.sleep(50)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
if (checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
|
@ -158,25 +158,14 @@ class MainActivity : GenericActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for fragment to be displayed before hiding the splashscreen
|
binding.root.doOnAttach {
|
||||||
binding.root.viewTreeObserver.addOnPreDrawListener(
|
Log.i("$TAG Report UI has been fully drawn (TTFD)")
|
||||||
object : ViewTreeObserver.OnPreDrawListener {
|
try {
|
||||||
override fun onPreDraw(): Boolean {
|
reportFullyDrawn()
|
||||||
return if (sharedViewModel.isFirstFragmentReady) {
|
} catch (se: SecurityException) {
|
||||||
Log.i("$TAG Report UI has been fully drawn (TTFD)")
|
Log.e("$TAG Security exception when doing reportFullyDrawn(): $se")
|
||||||
try {
|
|
||||||
reportFullyDrawn()
|
|
||||||
} catch (se: SecurityException) {
|
|
||||||
Log.e("$TAG Security exception when doing reportFullyDrawn(): $se")
|
|
||||||
}
|
|
||||||
binding.root.viewTreeObserver.removeOnPreDrawListener(this)
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,6 @@ class ConversationsListFragment : AbstractTopBarFragment() {
|
||||||
|
|
||||||
(view.parent as? ViewGroup)?.doOnPreDraw {
|
(view.parent as? ViewGroup)?.doOnPreDraw {
|
||||||
startPostponedEnterTransition()
|
startPostponedEnterTransition()
|
||||||
sharedViewModel.isFirstFragmentReady = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,6 @@ class ContactsListFragment : AbstractTopBarFragment() {
|
||||||
|
|
||||||
(view.parent as? ViewGroup)?.doOnPreDraw {
|
(view.parent as? ViewGroup)?.doOnPreDraw {
|
||||||
startPostponedEnterTransition()
|
startPostponedEnterTransition()
|
||||||
sharedViewModel.isFirstFragmentReady = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,6 @@ class HistoryListFragment : AbstractTopBarFragment() {
|
||||||
|
|
||||||
(view.parent as? ViewGroup)?.doOnPreDraw {
|
(view.parent as? ViewGroup)?.doOnPreDraw {
|
||||||
startPostponedEnterTransition()
|
startPostponedEnterTransition()
|
||||||
sharedViewModel.isFirstFragmentReady = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,6 @@ class MeetingsListFragment : AbstractTopBarFragment() {
|
||||||
|
|
||||||
(view.parent as? ViewGroup)?.doOnPreDraw {
|
(view.parent as? ViewGroup)?.doOnPreDraw {
|
||||||
startPostponedEnterTransition()
|
startPostponedEnterTransition()
|
||||||
sharedViewModel.isFirstFragmentReady = true
|
|
||||||
|
|
||||||
if (currentCount < newCount) {
|
if (currentCount < newCount) {
|
||||||
scrollToToday()
|
scrollToToday()
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,6 @@ import org.linphone.ui.main.chat.model.MessageModel
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
|
||||||
class SharedMainViewModel @UiThread constructor() : ViewModel() {
|
class SharedMainViewModel @UiThread constructor() : ViewModel() {
|
||||||
// When set to true, it will hide the splashscreen
|
|
||||||
var isFirstFragmentReady: Boolean = false
|
|
||||||
|
|
||||||
/* Sliding Pane & navigation related */
|
/* Sliding Pane & navigation related */
|
||||||
|
|
||||||
val isSlidingPaneSlideable = MutableLiveData<Boolean>()
|
val isSlidingPaneSlideable = MutableLiveData<Boolean>()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue