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

Commit fec29205 authored by linyuh's avatar linyuh Committed by Copybara-Service
Browse files

Don't show "Add contact" and/or "Message" in the bottom sheet if corresponding...

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
parent 4950fd58
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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()
+8 −0
Original line number Diff line number Diff line
@@ -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;