Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76de0fad authored by David Braun's avatar David Braun
Browse files

Update People app to direct SMS SEND_TO only to the default SMS app.

In KLP we have added the concept of a default SMS app to the platform. Only
this application has write permission to the SMS database. To help ensure
a better user experience we will always direct "send to sms" in the people
app to the app that the user has selected as their default SMS app.

Bug: 10870624 System should direct "SENDTO" intent with "sms" and "mms" schemes to the default SMS app
Change-Id: Ic35282b52d0f12baa11b57dc1b3ae8556ecb9a5a
parent 30a2c4ab
Loading
Loading
Loading
Loading
+16 −25
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.contacts.detail;
import android.app.Activity;
import android.app.Fragment;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
@@ -168,21 +169,6 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
            new AddToMyContactsQuickFix()
    };

    /**
     * Device capability: Set during buildEntries and used in the long-press context menu
     */
    private boolean mHasPhone;

    /**
     * Device capability: Set during buildEntries and used in the long-press context menu
     */
    private boolean mHasSms;

    /**
     * Device capability: Set during buildEntries and used in the long-press context menu
     */
    private boolean mHasSip;

    /**
     * The view shown if the detail list is empty.
     * We set this to the list view when first bind the adapter, so that it won't be shown while
@@ -533,9 +519,10 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
     * Build up the entries to display on the screen.
     */
    private final void buildEntries() {
        mHasPhone = PhoneCapabilityTester.isPhone(mContext);
        mHasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext);
        mHasSip = PhoneCapabilityTester.isSipPhone(mContext);
        final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext);
        final ComponentName smsComponent = PhoneCapabilityTester.getSmsComponent(getContext());
        final boolean hasSms = (smsComponent != null);
        final boolean hasSip = PhoneCapabilityTester.isSipPhone(mContext);

        // Clear out the old entries
        mAllEntries.clear();
@@ -583,21 +570,25 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
                    PhoneDataItem phone = (PhoneDataItem) dataItem;
                    // Build phone entries
                    entry.data = phone.getFormattedPhoneNumber();
                    final Intent phoneIntent = mHasPhone ?
                    final Intent phoneIntent = hasPhone ?
                            CallUtil.getCallIntent(entry.data) : null;
                    final Intent smsIntent = mHasSms ? new Intent(Intent.ACTION_SENDTO,
                            Uri.fromParts(CallUtil.SCHEME_SMSTO, entry.data, null)) : null;
                    Intent smsIntent = null;
                    if (hasSms) {
                        smsIntent = new Intent(Intent.ACTION_SENDTO,
                                Uri.fromParts(CallUtil.SCHEME_SMSTO, entry.data, null));
                        smsIntent.setComponent(smsComponent);
                    }

                    // Configure Icons and Intents.
                    if (mHasPhone && mHasSms) {
                    if (hasPhone && hasSms) {
                        entry.intent = phoneIntent;
                        entry.secondaryIntent = smsIntent;
                        entry.secondaryActionIcon = kind.iconAltRes;
                        entry.secondaryActionDescription =
                            ContactDisplayUtils.getSmsLabelResourceId(entry.type);
                    } else if (mHasPhone) {
                    } else if (hasPhone) {
                        entry.intent = phoneIntent;
                    } else if (mHasSms) {
                    } else if (hasSms) {
                        entry.intent = smsIntent;
                    } else {
                        entry.intent = null;
@@ -694,7 +685,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
                } else if (dataItem instanceof SipAddressDataItem && hasData) {
                    // Build SipAddress entries
                    entry.uri = null;
                    if (mHasSip) {
                    if (hasSip) {
                        entry.intent = CallUtil.getCallIntent(
                                Uri.fromParts(CallUtil.SCHEME_SIP, entry.data, null));
                    } else {
+9 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.contacts.quickcontact;

import android.content.ComponentName;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
@@ -102,7 +103,8 @@ public class DataAction implements Action {
        mDataUri = ContentUris.withAppendedId(Data.CONTENT_URI, mDataId);

        final boolean hasPhone = PhoneCapabilityTester.isPhone(mContext);
        final boolean hasSms = PhoneCapabilityTester.isSmsIntentRegistered(mContext);
        final ComponentName smsComponent = PhoneCapabilityTester.getSmsComponent(mContext);
        final boolean hasSms = (smsComponent != null);

        // Handle well-known MIME-types with special care
        if (item instanceof PhoneDataItem) {
@@ -113,8 +115,12 @@ public class DataAction implements Action {

                    final Intent phoneIntent = hasPhone ? CallUtil.getCallIntent(number)
                            : null;
                    final Intent smsIntent = hasSms ? new Intent(Intent.ACTION_SENDTO,
                            Uri.fromParts(CallUtil.SCHEME_SMSTO, number, null)) : null;
                    Intent smsIntent = null;
                    if (hasSms) {
                        smsIntent = new Intent(Intent.ACTION_SENDTO,
                                Uri.fromParts(CallUtil.SCHEME_SMSTO, number, null));
                        smsIntent.setComponent(smsComponent);
                    }

                    // Configure Icons and Intents. Notice actionIcon is already set to the phone
                    if (hasPhone && hasSms) {
+17 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.contacts.util;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -23,6 +24,7 @@ import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.net.sip.SipManager;
import android.provider.MediaStore;
import android.provider.Telephony;
import android.telephony.TelephonyManager;

import com.android.contacts.common.CallUtil;
@@ -75,13 +77,22 @@ public final class PhoneCapabilityTester {
    }

    /**
     * Returns true if the device has an SMS application installed.
     * Returns the component name to use for sending to sms or null.
     */
    public static boolean isSmsIntentRegistered(Context context) {
        // Don't cache the result as the user might install third party apps to send SMS
    public static ComponentName getSmsComponent(Context context) {
        String smsPackage = Telephony.Sms.getDefaultSmsPackage(context);
        if (smsPackage != null) {
            final PackageManager packageManager = context.getPackageManager();
            final Intent intent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts(CallUtil.SCHEME_SMSTO, "", null));
        return isIntentRegistered(context, intent);
            final List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0);
            for (ResolveInfo resolveInfo : resolveInfos) {
                if (smsPackage.equals(resolveInfo.activityInfo.packageName)) {
                    return new ComponentName(smsPackage, resolveInfo.activityInfo.name);
                }
            }
        }
        return null;
    }

    /**