Prevent LIME X3DH server URL & friends lists RLS URI to be set for non sip.linphone.org accounts

This commit is contained in:
Sylvain Berfini 2022-04-20 10:48:02 +02:00
parent 595510028d
commit e8ad1e039b
13 changed files with 57 additions and 54 deletions

View file

@ -24,6 +24,9 @@
<entry name="stun_server" overwrite="true"></entry>
<entry name="protocols" overwrite="true"></entry>
</section>
<section name="net">
<entry name="friendlist_subscription_enabled" overwrite="true">0</entry>
</section>
<section name="assistant">
<entry name="domain" overwrite="true"></entry>
<entry name="algorithm" overwrite="true">MD5</entry>

View file

@ -24,11 +24,8 @@
<entry name="stun_server" overwrite="true">stun.linphone.org</entry>
<entry name="protocols" overwrite="true">stun,ice</entry>
</section>
<section name="sip">
<entry name="rls_uri" overwrite="true">sips:rls@sip.linphone.org</entry>
</section>
<section name="lime">
<entry name="x3dh_server_url" overwrite="true">https://lime.linphone.org/lime-server/lime-server.php</entry>
<section name="net">
<entry name="friendlist_subscription_enabled" overwrite="true">1</entry>
</section>
<section name="assistant">
<entry name="domain" overwrite="true">sip.linphone.org</entry>

View file

@ -93,7 +93,7 @@ class AccountLoginFragment : AbstractPhoneFragment<AssistantAccountLoginFragment
viewLifecycleOwner
) {
it.consume {
coreContext.contactsManager.updateLocalContacts()
coreContext.newAccountConfigured(true)
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()

View file

@ -52,7 +52,7 @@ class EmailAccountValidationFragment : GenericFragment<AssistantEmailAccountVali
viewLifecycleOwner
) {
it.consume {
coreContext.contactsManager.updateLocalContacts()
coreContext.newAccountConfigured(true)
val args = Bundle()
args.putBoolean("AllowSkip", true)

View file

@ -24,6 +24,7 @@ import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
import org.linphone.activities.GenericFragment
import org.linphone.activities.assistant.AssistantActivity
@ -57,7 +58,8 @@ class GenericAccountLoginFragment : GenericFragment<AssistantGenericAccountLogin
viewLifecycleOwner
) {
it.consume {
coreContext.contactsManager.updateLocalContacts()
val isLinphoneAccount = viewModel.domain.value.orEmpty() == corePreferences.defaultDomain
coreContext.newAccountConfigured(isLinphoneAccount)
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()

View file

@ -64,7 +64,7 @@ class PhoneAccountValidationFragment : GenericFragment<AssistantPhoneAccountVali
it.consume {
when {
viewModel.isLogin.value == true || viewModel.isCreation.value == true -> {
coreContext.contactsManager.updateLocalContacts()
coreContext.newAccountConfigured(true)
if (coreContext.core.isEchoCancellerCalibrationRequired) {
navigateToEchoCancellerCalibration()

View file

@ -24,7 +24,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.core.*
import org.linphone.core.tools.Log
import org.linphone.utils.Event
@ -141,13 +140,6 @@ class GenericLoginViewModel(private val accountCreator: AccountCreator) : ViewMo
}
Log.i("[Assistant] [Generic Login] Proxy config created")
// The following is required to keep the app alive
// and be able to receive calls while in background
if (domain.value.orEmpty() != corePreferences.defaultDomain) {
Log.i("[Assistant] [Generic Login] Background mode with foreground service automatically enabled")
corePreferences.keepServiceAlive = true
coreContext.notificationsManager.startForeground()
}
}
private fun isLoginButtonEnabled(): Boolean {

View file

@ -328,17 +328,14 @@ class DialerFragment : SecureFragment<DialerFragmentBinding>() {
}
private fun checkForUpdate() {
val url: String? = corePreferences.checkIfUpdateAvailableUrl
if (url != null && url.isNotEmpty()) {
val lastTimestamp: Int = corePreferences.lastUpdateAvailableCheckTimestamp
val currentTimeStamp = System.currentTimeMillis().toInt()
val interval: Int = corePreferences.checkUpdateAvailableInterval
if (lastTimestamp == 0 || currentTimeStamp - lastTimestamp >= interval) {
val currentVersion = BuildConfig.VERSION_NAME
Log.i("[Dialer] Checking for update using url [$url] and current version [$currentVersion]")
coreContext.core.checkForUpdate(currentVersion)
corePreferences.lastUpdateAvailableCheckTimestamp = currentTimeStamp
}
val lastTimestamp: Int = corePreferences.lastUpdateAvailableCheckTimestamp
val currentTimeStamp = System.currentTimeMillis().toInt()
val interval: Int = corePreferences.checkUpdateAvailableInterval
if (lastTimestamp == 0 || currentTimeStamp - lastTimestamp >= interval) {
val currentVersion = BuildConfig.VERSION_NAME
Log.i("[Dialer] Checking for update using current version [$currentVersion]")
coreContext.core.checkForUpdate(currentVersion)
corePreferences.lastUpdateAvailableCheckTimestamp = currentTimeStamp
}
}

View file

@ -38,6 +38,7 @@ class ContactsSettingsViewModel : GenericSettingsViewModel() {
}
}
val friendListSubscribe = MutableLiveData<Boolean>()
val rlsAddressAvailable = MutableLiveData<Boolean>()
val showNewContactAccountDialogListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
@ -95,6 +96,7 @@ class ContactsSettingsViewModel : GenericSettingsViewModel() {
readContactsPermissionGranted.value = PermissionHelper.get().hasReadContactsPermission()
friendListSubscribe.value = core.isFriendListSubscriptionEnabled
rlsAddressAvailable.value = core.defaultFriendList?.rlsAddress?.asStringUriOnly().orEmpty().isNotEmpty()
showNewContactAccountDialog.value = prefs.showNewContactAccountDialog
nativePresence.value = prefs.storePresenceInNativeContact
showOrganization.value = prefs.displayOrganization

View file

@ -61,11 +61,18 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
Log.i("[Contacts Loader] Loader created")
coreContext.contactsManager.fetchInProgress.value = true
val selection = if (corePreferences.fetchContactsFromDefaultDirectory) {
ContactsContract.Data.IN_DEFAULT_DIRECTORY + " == 1"
} else {
null
}
return CursorLoader(
coreContext.context,
ContactsContract.Data.CONTENT_URI,
projection,
ContactsContract.Data.IN_DEFAULT_DIRECTORY + " == 1",
selection,
null,
null
)

View file

@ -425,16 +425,6 @@ class CoreContext(val context: Context, coreConfig: Config) : LifecycleOwner, Vi
Log.i("[Context] Account params have been updated, apply changes")
account.params = params
}
// Ensure LIME server URL is set if at least one sip.linphone.org proxy
if (core.limeX3DhAvailable()) {
var url: String? = core.limeX3DhServerUrl
if (url == null || url.isEmpty()) {
url = corePreferences.limeX3dhServerUrl
Log.i("[Context] Setting LIME X3Dh server url to default value: $url")
core.limeX3DhServerUrl = url
}
}
}
}
@ -470,6 +460,30 @@ class CoreContext(val context: Context, coreConfig: Config) : LifecycleOwner, Vi
}
}
fun newAccountConfigured(isLinphoneAccount: Boolean) {
Log.i("[Context] A new ${if (isLinphoneAccount) AppUtils.getString(R.string.app_name) else "third-party"} account has been configured")
if (isLinphoneAccount) {
core.config.setString("sip", "rls_uri", corePreferences.defaultRlsUri)
val rlsAddress = core.interpretUrl(corePreferences.defaultRlsUri)
if (rlsAddress != null) {
for (friendList in core.friendsLists) {
friendList.rlsAddress = rlsAddress
}
}
if (core.limeX3DhAvailable()) {
core.limeX3DhServerUrl = corePreferences.defaultLimeServerUrl
}
} else {
Log.i("[Context] Background mode with foreground service automatically enabled")
corePreferences.keepServiceAlive = true
notificationsManager.startForeground()
}
contactsManager.updateLocalContacts()
}
/* Call related functions */
fun initPhoneStateListener() {

View file

@ -474,6 +474,9 @@ class CorePreferences constructor(private val context: Context) {
val defaultRlsUri: String
get() = config.getString("sip", "rls_uri", "sips:rls@sip.linphone.org")!!
val defaultLimeServerUrl: String
get() = config.getString("lime", "lime_server_url", "https://lime.linphone.org/lime-server/lime-server.php")!!
val debugPopupCode: String
get() = config.getString("app", "debug_popup_magic", "#1234#")!!
@ -495,20 +498,6 @@ class CorePreferences constructor(private val context: Context) {
""
)!!
val limeX3dhServerUrl: String
get() = config.getString(
"app",
"default_lime_x3dh_server_url",
"https://lime.linphone.org/lime-server/lime-server.php"
)!!
val checkIfUpdateAvailableUrl: String?
get() = config.getString(
"misc",
"version_check_url_root",
"https://linphone.org/releases/android/RELEASE"
)
val checkUpdateAvailableInterval: Int
get() = config.getInt("app", "version_check_interval", 86400000)

View file

@ -73,7 +73,7 @@
linphone:title="@{@string/contacts_settings_friendlist_subscribe_title}"
linphone:listener="@{viewModel.friendListSubscribeListener}"
linphone:checked="@={viewModel.friendListSubscribe}"
linphone:enabled="@{viewModel.readContactsPermissionGranted}"/>
linphone:enabled="@{viewModel.readContactsPermissionGranted &amp;&amp; viewModel.rlsAddressAvailable}"/>
<include
layout="@layout/settings_widget_switch"