summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java9
-rw-r--r--java/com/android/dialer/util/PermissionsUtil.java8
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;