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

Commit 738471a9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make phone number actions dependent on user privileges"

parents 705c01a5 05e0051d
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -27,8 +27,10 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.ParcelFileDescriptor;
import android.os.UserManager;
import android.provider.Browser;
import android.provider.CalendarContract;
import android.provider.ContactsContract;
@@ -541,7 +543,7 @@ public final class TextClassifierImpl implements TextClassifier {
                case TextClassifier.TYPE_EMAIL:
                    return createForEmail(text);
                case TextClassifier.TYPE_PHONE:
                    return createForPhone(text);
                    return createForPhone(context, text);
                case TextClassifier.TYPE_ADDRESS:
                    return createForAddress(text);
                case TextClassifier.TYPE_URL:
@@ -573,16 +575,24 @@ public final class TextClassifierImpl implements TextClassifier {
        }

        @NonNull
        private static List<Intent> createForPhone(String text) {
            return Arrays.asList(
                    new Intent(Intent.ACTION_DIAL)
                            .setData(Uri.parse(String.format("tel:%s", text))),
                    new Intent(Intent.ACTION_INSERT_OR_EDIT)
        private static List<Intent> createForPhone(Context context, String text) {
            final List<Intent> intents = new ArrayList<>();
            final UserManager userManager = context.getSystemService(UserManager.class);
            final Bundle userRestrictions = userManager != null
                    ? userManager.getUserRestrictions() : new Bundle();
            if (!userRestrictions.getBoolean(UserManager.DISALLOW_OUTGOING_CALLS, false)) {
                intents.add(new Intent(Intent.ACTION_DIAL)
                        .setData(Uri.parse(String.format("tel:%s", text))));
            }
            intents.add(new Intent(Intent.ACTION_INSERT_OR_EDIT)
                    .setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE)
                            .putExtra(ContactsContract.Intents.Insert.PHONE, text),
                    new Intent(Intent.ACTION_SENDTO)
                    .putExtra(ContactsContract.Intents.Insert.PHONE, text));
            if (!userRestrictions.getBoolean(UserManager.DISALLOW_SMS, false)) {
                intents.add(new Intent(Intent.ACTION_SENDTO)
                        .setData(Uri.parse(String.format("smsto:%s", text))));
            }
            return intents;
        }

        @NonNull
        private static List<Intent> createForAddress(String text) {