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

Commit 032fee5a authored by Varun Berry's avatar Varun Berry Committed by Automerger Merge Worker
Browse files

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

Hash ICC ID used in the notification tag for voicemail notifications. am: a38caf0f am: 11e2957d am: 236ad004

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Dialer/+/16243879

Change-Id: I9f8aa35715826eb0fc2ca57d72a55714007771cd
parents 26e4876c 236ad004
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.dialer.common.LogUtil;
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 @@ public final class LegacyVoicemailNotifier {
    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() {}
+34 −2
Original line number Diff line number Diff line
@@ -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 android.util.ArraySet;
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 @@ import java.util.Set;

  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();
  }

  /**