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

Commit 05e0051d authored by Jan Althaus's avatar Jan Althaus
Browse files

Make phone number actions dependent on user privileges

Bug: 69000125
Test: Tested following the instructions on the bug
Change-Id: I60e927b32df76e328edb8666c9c8fd3dde46064d
parent 928835eb
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) {