Intercept DIAL and CALL to tel: and rewrite to cheogram

Stephen Paul Weber created

This is a proof of concept.  It catches tel: from browser, but also taps on call
button in contacts, etc, and rewrites to a Cheogram JID.  It does not query the
user's roster for gateway options, or ask the gateways to convert the URI, but
simply assumes Cheogram format and jams it in.  It also does not initiate a
call, but simply uses the default XmppUri action which will be to either add to
roster or open conversation.

Change summary

src/main/AndroidManifest.xml                                    | 8 +++
src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java | 2 
src/main/java/eu/siacs/conversations/utils/XmppUri.java         | 2 
3 files changed, 12 insertions(+)

Detailed changes

src/main/AndroidManifest.xml 🔗

@@ -144,6 +144,14 @@
                 <data android:scheme="imto" />
                 <data android:host="jabber" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <action android:name="android.intent.action.CALL" />
+                <action android:name="android.intent.action.DIAL" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <data android:scheme="tel" />
+            </intent-filter>
         </activity>
         <activity
             android:name=".ui.StartConversationActivity"

src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java 🔗

@@ -205,6 +205,8 @@ public class UriHandlerActivity extends AppCompatActivity {
         switch (data.getAction()) {
             case Intent.ACTION_VIEW:
             case Intent.ACTION_SENDTO:
+            case Intent.ACTION_DIAL:
+            case Intent.ACTION_CALL:
                 handleUri(data.getData());
                 break;
             case ACTION_SCAN_QR_CODE:

src/main/java/eu/siacs/conversations/utils/XmppUri.java 🔗

@@ -174,6 +174,8 @@ public class XmppUri {
             } catch (final UnsupportedEncodingException ignored) {
                 jid = null;
             }
+        } else if ("tel".equalsIgnoreCase(scheme)) {
+            jid = uri.getSchemeSpecificPart().replaceAll("[^\\d\\+]+", "") + "@cheogram.com";
         } else {
             jid = null;
         }