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

Commit dc8b02e0 authored by Laura Tsai's avatar Laura Tsai Committed by Automerger Merge Worker
Browse files

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

Revert "Hash ICC ID used in the notification tag for voicemail notifications." am: 6f32f84a am: cdd8f9d2 am: ae6c7fa9 am: 272c1b91

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

Change-Id: Ie3ee18b204abbb4ac2241c3ff806331917341dc1
parents 621dccdd 272c1b91
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ 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;
@@ -182,8 +181,7 @@ public final class LegacyVoicemailNotifier {
    if (context.getSystemService(TelephonyManager.class).getPhoneCount() <= 1) {
      return NOTIFICATION_TAG;
    }
    return NOTIFICATION_TAG_PREFIX
        + VoicemailChannelUtils.getHashedPhoneAccountId(phoneAccountHandle.getId());
    return NOTIFICATION_TAG_PREFIX + phoneAccountHandle.getId();
  }

  private LegacyVoicemailNotifier() {}
+2 −34
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

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;
@@ -40,35 +38,15 @@ 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)
public final class VoicemailChannelUtils {
/* package */ 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) {
@@ -146,17 +124,7 @@ public final class VoicemailChannelUtils {

  private static String getChannelIdForAccount(@NonNull PhoneAccountHandle handle) {
    Assert.isNotNull(handle);
    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();
    return PER_ACCOUNT_VOICEMAIL_CHANNEL_ID_PREFIX + ":" + handle.getId();
  }

  /**