aboutsummaryrefslogtreecommitdiff
path: root/java/com
diff options
context:
space:
mode:
authorVarun Berry <vberry@google.com>2021-12-13 22:08:05 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-12-13 22:08:05 +0000
commit3cfadda6b5f65e28227a3e21b59e2452e2052343 (patch)
tree2c763fafd8908d2e485b83ac32c020633ca6e23a /java/com
parent0fcdd23673f4e55d2fd589f68598cb2351a9285f (diff)
parent769ca0c78ea7f936ff9bf353b7d0f1d2501212d5 (diff)
downloadDialer-3cfadda6b5f65e28227a3e21b59e2452e2052343.tar.gz
Hash ICC ID used in the notification tag for voicemail notifications. am: a38caf0ff6 am: 11e2957db2 am: 236ad00472 am: 032fee5a51 am: c87a21ea28 am: e1e0e83416 am: 769ca0c78e
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Dialer/+/16243879 Change-Id: Ia6dbb527b03d9e702091209d669ad5687c75badb
Diffstat (limited to 'java/com')
-rw-r--r--java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java4
-rw-r--r--java/com/android/dialer/notification/VoicemailChannelUtils.java36
2 files changed, 37 insertions, 3 deletions
diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
index 31e9edc6a..1388f43a5 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.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() {}
diff --git a/java/com/android/dialer/notification/VoicemailChannelUtils.java b/java/com/android/dialer/notification/VoicemailChannelUtils.java
index ddc0f773c..83bda0f18 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 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();
}
/**