From 05e0051d1d3000525a12f555c59097201487fad8 Mon Sep 17 00:00:00 2001 From: Jan Althaus Date: Fri, 2 Feb 2018 15:28:34 +0100 Subject: [PATCH] Make phone number actions dependent on user privileges Bug: 69000125 Test: Tested following the instructions on the bug Change-Id: I60e927b32df76e328edb8666c9c8fd3dde46064d --- .../textclassifier/TextClassifierImpl.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/core/java/android/view/textclassifier/TextClassifierImpl.java b/core/java/android/view/textclassifier/TextClassifierImpl.java index 9f389ba0c1402..af76a7fa4c7d4 100644 --- a/core/java/android/view/textclassifier/TextClassifierImpl.java +++ b/core/java/android/view/textclassifier/TextClassifierImpl.java @@ -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,15 +575,23 @@ public final class TextClassifierImpl implements TextClassifier { } @NonNull - private static List 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) - .setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE) - .putExtra(ContactsContract.Intents.Insert.PHONE, text), - new Intent(Intent.ACTION_SENDTO) - .setData(Uri.parse(String.format("smsto:%s", text)))); + private static List createForPhone(Context context, String text) { + final List 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)); + 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