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

Unverified Commit 279740d2 authored by Varun Berry's avatar Varun Berry Committed by Kevin F. Haggerty
Browse files

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 a38caf0f)
Merged-In:Ib2ecf628db84425591d4cafcae9ab35b0be9943f
parent f1cf633f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -35,6 +35,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;

@@ -165,7 +166,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();
  }

  /**