Fixed handling of tel and sip schemed URI + added missing sips scheme support

This commit is contained in:
Sylvain Berfini 2020-11-03 10:19:03 +01:00
parent e12df37d2d
commit a4e3abd4c4
4 changed files with 45 additions and 35 deletions

View file

@ -79,11 +79,14 @@
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" /> <action android:name="android.intent.action.DIAL" />
<action android:name="android.intent.action.CALL" /> <action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" /> <data android:scheme="tel" />
<data android:scheme="sip" /> <data android:scheme="sip" />
<data android:scheme="sips" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>

View file

@ -189,38 +189,26 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
} }
} }
Intent.ACTION_VIEW -> { Intent.ACTION_VIEW -> {
val uri = intent.data
if (intent.type == AppUtils.getString(R.string.linphone_address_mime_type)) { if (intent.type == AppUtils.getString(R.string.linphone_address_mime_type)) {
val contactUri = intent.data if (uri != null) {
if (contactUri != null) { val contactId = coreContext.contactsManager.getAndroidContactIdFromUri(uri)
val contactId = coreContext.contactsManager.getAndroidContactIdFromUri(contactUri)
if (contactId != null) { if (contactId != null) {
val deepLink = "linphone-android://contact/view/$contactId" val deepLink = "linphone-android://contact/view/$contactId"
Log.i("[Main Activity] Found contact URI parameter in intent: $contactUri, starting deep link: $deepLink") Log.i("[Main Activity] Found contact URI parameter in intent: $uri, starting deep link: $deepLink")
findNavController(R.id.nav_host_fragment).navigate(Uri.parse(deepLink)) findNavController(R.id.nav_host_fragment).navigate(Uri.parse(deepLink))
} }
} }
} else {
if (uri != null) {
handleTelOrSipUri(uri)
}
} }
} }
Intent.ACTION_DIAL, Intent.ACTION_CALL -> { Intent.ACTION_DIAL, Intent.ACTION_CALL -> {
val uri = intent.data val uri = intent.data
if (uri != null) { if (uri != null) {
Log.i("[Main Activity] Found uri: $uri to call") handleTelOrSipUri(uri)
val stringUri = uri.toString()
var addressToCall: String = stringUri
try {
addressToCall = URLDecoder.decode(stringUri, "UTF-8")
} catch (e: UnsupportedEncodingException) { }
if (addressToCall.startsWith("sip:")) {
addressToCall = addressToCall.substring("sip:".length)
} else if (addressToCall.startsWith("tel:")) {
addressToCall = addressToCall.substring("tel:".length)
}
Log.i("[Main Activity] Starting dialer with pre-filled URI $addressToCall")
val args = Bundle()
args.putString("URI", addressToCall)
navigateToDialer(args)
} }
} }
else -> { else -> {
@ -254,6 +242,25 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
} }
} }
private fun handleTelOrSipUri(uri: Uri) {
Log.i("[Main Activity] Found uri: $uri to call")
val stringUri = uri.toString()
var addressToCall: String = stringUri
try {
addressToCall = URLDecoder.decode(stringUri, "UTF-8")
} catch (e: UnsupportedEncodingException) { }
if (addressToCall.startsWith("tel:")) {
Log.i("[Main Activity] Removing tel: prefix")
addressToCall = addressToCall.substring("tel:".length)
}
Log.i("[Main Activity] Starting dialer with pre-filled URI $addressToCall")
val args = Bundle()
args.putString("URI", addressToCall)
navigateToDialer(args)
}
private fun handleSendText(intent: Intent) { private fun handleSendText(intent: Intent) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
sharedViewModel.textToShare.value = it sharedViewModel.textToShare.value = it

View file

@ -255,7 +255,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
core.zrtpSecretsFile = corePreferences.zrtpSecretsPath core.zrtpSecretsFile = corePreferences.zrtpSecretsPath
core.callLogsDatabasePath = corePreferences.callHistoryDatabasePath core.callLogsDatabasePath = corePreferences.callHistoryDatabasePath
core.staticPicture = corePreferences.staticPicture core.staticPicture = corePreferences.staticPicturePath
initUserCertificates() initUserCertificates()

View file

@ -253,6 +253,12 @@ class CorePreferences constructor(private val context: Context) {
config.setBool("net", "use_legacy_push_notification_params", value) config.setBool("net", "use_legacy_push_notification_params", value)
} }
var defaultAccountAvatarPath: String?
get() = config.getString("app", "default_avatar_path", null)
set(value) {
config.setString("app", "default_avatar_path", value)
}
/* Read only application settings, some were previously in non_localizable_custom */ /* Read only application settings, some were previously in non_localizable_custom */
val defaultDomain: String val defaultDomain: String
@ -289,7 +295,7 @@ class CorePreferences constructor(private val context: Context) {
get() = config.getBool("app", "show_border_on_big_contact_avatar", true) get() = config.getBool("app", "show_border_on_big_contact_avatar", true)
val checkIfUpdateAvailableUrl: String? val checkIfUpdateAvailableUrl: String?
get() = config.getString("misc", "version_check_url_root", null) get() = config.getString("misc", "version_check_url_root", "https://linphone.org/releases/android/RELEASE")
val checkUpdateAvailableInterval: Int val checkUpdateAvailableInterval: Int
get() = config.getInt("app", "version_check_interval", 86400000) get() = config.getInt("app", "version_check_interval", 86400000)
@ -321,12 +327,6 @@ class CorePreferences constructor(private val context: Context) {
/* Side Menu */ /* Side Menu */
var defaultAccountAvatarPath: String?
get() = config.getString("app", "default_avatar_path", null)
set(value) {
config.setString("app", "default_avatar_path", value)
}
val showAccountsInSideMenu: Boolean val showAccountsInSideMenu: Boolean
get() = config.getBool("app", "side_menu_accounts", true) get() = config.getBool("app", "side_menu_accounts", true)
@ -374,11 +374,6 @@ class CorePreferences constructor(private val context: Context) {
val showAdvancedSettings: Boolean val showAdvancedSettings: Boolean
get() = config.getBool("app", "settings_advanced", true) get() = config.getBool("app", "settings_advanced", true)
/* Other stuff */
private val darkModeAllowed: Boolean
get() = config.getBool("app", "dark_mode_allowed", true)
/* Assets stuff */ /* Assets stuff */
val configPath: String val configPath: String
@ -405,9 +400,14 @@ class CorePreferences constructor(private val context: Context) {
val callHistoryDatabasePath: String val callHistoryDatabasePath: String
get() = context.filesDir.absolutePath + "/linphone-log-history.db" get() = context.filesDir.absolutePath + "/linphone-log-history.db"
val staticPicture: String val staticPicturePath: String
get() = context.filesDir.absolutePath + "/share/images/nowebcamcif.jpg" get() = context.filesDir.absolutePath + "/share/images/nowebcamcif.jpg"
/* Other stuff */
private val darkModeAllowed: Boolean
get() = config.getBool("app", "dark_mode_allowed", true)
fun copyAssetsFromPackage() { fun copyAssetsFromPackage() {
copy("linphonerc_default", configPath) copy("linphonerc_default", configPath)
copy("linphonerc_factory", factoryConfigPath, true) copy("linphonerc_factory", factoryConfigPath, true)