diff options
author | linyuh <linyuh@google.com> | 2018-05-21 18:17:52 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-21 18:18:30 -0700 |
commit | fec2920572350518f9600ac1820abd76fb449a1c (patch) | |
tree | e67463f8bd281f2f196346d79d3313fe5d177d30 /java | |
parent | 4950fd587f2588e7958a84c5fcd814058bd2e1a3 (diff) |
Don't show "Add contact" and/or "Message" in the bottom sheet if corresponding permissions are not granted.
Bug: 80059644
Test: HistoryItemActionModulesBuilderTest, PermissionUtilTest
PiperOrigin-RevId: 197494701
Change-Id: I607ebd3079fa816b447fbff08cc28c96c55e22bb
Diffstat (limited to 'java')
-rw-r--r-- | java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java | 9 | ||||
-rw-r--r-- | java/com/android/dialer/util/PermissionsUtil.java | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java b/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java index a09f6e10b..0e78d70f5 100644 --- a/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java +++ b/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java @@ -32,6 +32,7 @@ import com.android.dialer.duo.DuoComponent; import com.android.dialer.logging.ReportingLocation; import com.android.dialer.spam.Spam; import com.android.dialer.util.CallUtil; +import com.android.dialer.util.PermissionsUtil; import com.android.dialer.util.UriUtils; import java.util.ArrayList; import java.util.List; @@ -179,6 +180,7 @@ public final class HistoryItemActionModulesBuilder { * <p>The method is a no-op if * * <ul> + * <li>the permission to send SMS is not granted, * <li>the call is one made to/received from an emergency number, * <li>the call is one made to a voicemail box, * <li>the number is blocked, or @@ -188,7 +190,8 @@ public final class HistoryItemActionModulesBuilder { public HistoryItemActionModulesBuilder addModuleForSendingTextMessage() { // TODO(zachh): There are other conditions where this module should not be shown // (e.g., business numbers). - if (moduleInfo.getIsEmergencyNumber() + if (!PermissionsUtil.hasSendSmsPermissions(context) + || moduleInfo.getIsEmergencyNumber() || moduleInfo.getIsVoicemailCall() || moduleInfo.getIsBlocked() || TextUtils.isEmpty(moduleInfo.getNormalizedNumber())) { @@ -220,6 +223,7 @@ public final class HistoryItemActionModulesBuilder { * <p>The method is a no-op if * * <ul> + * <li>the permission to write contacts is not granted, * <li>the call is one made to/received from an emergency number, * <li>the call is one made to a voicemail box, * <li>the call should be shown as spam, @@ -229,7 +233,8 @@ public final class HistoryItemActionModulesBuilder { * </ul> */ public HistoryItemActionModulesBuilder addModuleForAddingToContacts() { - if (moduleInfo.getIsEmergencyNumber() + if (!PermissionsUtil.hasContactsWritePermissions(context) + || moduleInfo.getIsEmergencyNumber() || moduleInfo.getIsVoicemailCall() || Spam.shouldShowAsSpam(moduleInfo.getIsSpam(), moduleInfo.getCallType()) || moduleInfo.getIsBlocked() diff --git a/java/com/android/dialer/util/PermissionsUtil.java b/java/com/android/dialer/util/PermissionsUtil.java index 09c2b7f42..7e8aae943 100644 --- a/java/com/android/dialer/util/PermissionsUtil.java +++ b/java/com/android/dialer/util/PermissionsUtil.java @@ -91,6 +91,10 @@ public class PermissionsUtil { return hasPermission(context, permission.READ_CONTACTS); } + public static boolean hasContactsWritePermissions(Context context) { + return hasPermission(context, permission.WRITE_CONTACTS); + } + public static boolean hasLocationPermissions(Context context) { return hasPermission(context, permission.ACCESS_FINE_LOCATION); } @@ -127,6 +131,10 @@ public class PermissionsUtil { return hasPermission(context, permission.ADD_VOICEMAIL); } + public static boolean hasSendSmsPermissions(Context context) { + return hasPermission(context, permission.SEND_SMS); + } + public static boolean hasPermission(Context context, String permission) { return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; |