Hash ICC ID used in the notification tag for voicemail notifications.

Bug: 186026746
Test: manual.
Merged-In: I6ed0f6b7d0f2c286eb2437a29b0913fd38bcc2af
Change-Id: Ib2ecf628db84425591d4cafcae9ab35b0be9943f
(cherry picked from commit a38caf0ff62e0b3c8a7710c44277607244149fed)
Merged-In:Ib2ecf628db84425591d4cafcae9ab35b0be9943f
diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
index 31e9edc..1388f43 100644
--- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
+++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
@@ -36,6 +36,7 @@
 import com.android.dialer.location.GeoUtil;
 import com.android.dialer.notification.DialerNotificationManager;
 import com.android.dialer.notification.NotificationChannelManager;
+import com.android.dialer.notification.VoicemailChannelUtils;
 import com.android.dialer.phonenumberutil.PhoneNumberHelper;
 import com.android.dialer.telecom.TelecomUtil;
 import com.android.dialer.theme.base.ThemeComponent;
@@ -181,7 +182,8 @@
     if (context.getSystemService(TelephonyManager.class).getPhoneCount() <= 1) {
       return NOTIFICATION_TAG;
     }
-    return NOTIFICATION_TAG_PREFIX + phoneAccountHandle.getId();
+    return NOTIFICATION_TAG_PREFIX
+        + VoicemailChannelUtils.getHashedPhoneAccountId(phoneAccountHandle);
   }
 
   private LegacyVoicemailNotifier() {}
diff --git a/java/com/android/dialer/notification/VoicemailChannelUtils.java b/java/com/android/dialer/notification/VoicemailChannelUtils.java
index ddc0f77..83bda0f 100644
--- a/java/com/android/dialer/notification/VoicemailChannelUtils.java
+++ b/java/com/android/dialer/notification/VoicemailChannelUtils.java
@@ -16,6 +16,8 @@
 
 package com.android.dialer.notification;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import android.Manifest.permission;
 import android.annotation.TargetApi;
 import android.app.NotificationChannel;
@@ -38,15 +40,35 @@
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
 import com.android.dialer.util.PermissionsUtil;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
 /** Utilities for working with voicemail channels. */
 @TargetApi(VERSION_CODES.O)
-/* package */ final class VoicemailChannelUtils {
+public final class VoicemailChannelUtils {
   @VisibleForTesting static final String GLOBAL_VOICEMAIL_CHANNEL_ID = "phone_voicemail";
   private static final String PER_ACCOUNT_VOICEMAIL_CHANNEL_ID_PREFIX = "phone_voicemail_account_";
+  private static final char[] hexDigits = "0123456789abcdef".toCharArray();
+
+  /**
+   * Returns a String representation of the hashed value of the PhoneAccountHandle's id (the
+   * Sim ICC ID).
+   * In case it fails to hash the id it will return an empty string.
+   */
+  public static String getHashedPhoneAccountId(@NonNull PhoneAccountHandle handle) {
+    byte[] handleBytes = handle.getId().getBytes(UTF_8);
+    try {
+      byte[] hashedBytes = MessageDigest.getInstance("SHA-256").digest(handleBytes);
+      return byteArrayToHexString(hashedBytes);
+    } catch (NoSuchAlgorithmException e) {
+      LogUtil.e("VoicemailChannelUtils.getHashedPhoneAccountId",
+          "NoSuchAlgorithmException throw! Returning empty string!");
+      return "";
+    }
+  }
 
   @SuppressWarnings("MissingPermission") // isSingleSimDevice() returns true if no permission
   static Set<String> getAllChannelIds(@NonNull Context context) {
@@ -124,7 +146,17 @@
 
   private static String getChannelIdForAccount(@NonNull PhoneAccountHandle handle) {
     Assert.isNotNull(handle);
-    return PER_ACCOUNT_VOICEMAIL_CHANNEL_ID_PREFIX + ":" + handle.getId();
+    return PER_ACCOUNT_VOICEMAIL_CHANNEL_ID_PREFIX
+        + ":"
+        + getHashedPhoneAccountId(handle);
+  }
+
+  private static String byteArrayToHexString(byte[] bytes) {
+    StringBuilder sb = new StringBuilder(2 * bytes.length);
+    for (byte b : bytes) {
+      sb.append(hexDigits[(b >> 4) & 0xf]).append(hexDigits[b & 0xf]);
+    }
+    return sb.toString();
   }
 
   /**