[automerger skipped] Merge "Remove PhoneAccountHandle when building the intent to call Voicemail." into qt-dev am: 91bd209066 am: ef8a5e99e8 am: f2b7f43ab4 am: 421fa54f2c am: d60f44ee15 am: 7d69257347 am: f3b828e47e am: 8b732e98b5 -s ours

am skip reason: Merged-In If4463a24af2feb23d033190236e314b535d10fd6 with SHA-1 360d2eb8d9 is already in history

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

Change-Id: Id1c9639bb60e78d52028015190146d8dae87893e
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f48c425..891aa8a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -23,6 +23,8 @@
     android:minSdkVersion="24"
     android:targetSdkVersion="30"/>
 
+
+  <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
   <uses-permission android:name="android.permission.CALL_PHONE"/>
   <uses-permission android:name="android.permission.READ_CONTACTS"/>
   <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
diff --git a/java/com/android/contacts/common/model/ContactLoader.java b/java/com/android/contacts/common/model/ContactLoader.java
index 12cca4f..a3a3b9d 100644
--- a/java/com/android/contacts/common/model/ContactLoader.java
+++ b/java/com/android/contacts/common/model/ContactLoader.java
@@ -39,6 +39,7 @@
 import com.android.contacts.common.GroupMetaData;
 import com.android.contacts.common.model.account.AccountType;
 import com.android.contacts.common.model.account.AccountTypeWithDataSet;
+import com.android.contacts.common.model.account.GoogleAccountType;
 import com.android.contacts.common.model.dataitem.DataItem;
 import com.android.contacts.common.model.dataitem.PhoneDataItem;
 import com.android.contacts.common.model.dataitem.PhotoDataItem;
@@ -727,6 +728,10 @@
       final String servicePackageName = accountType.getViewContactNotifyServicePackageName();
       if (!TextUtils.isEmpty(serviceName) && !TextUtils.isEmpty(servicePackageName)) {
         final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
+        if (accountType instanceof GoogleAccountType) {
+          ((GoogleAccountType) accountType).handleRawContactViewed(context, uri);
+          continue;
+        }
         final Intent intent = new Intent();
         intent.setClassName(servicePackageName, serviceName);
         intent.setAction(Intent.ACTION_VIEW);
diff --git a/java/com/android/contacts/common/model/account/GoogleAccountType.java b/java/com/android/contacts/common/model/account/GoogleAccountType.java
index a25544b..e10ade4 100644
--- a/java/com/android/contacts/common/model/account/GoogleAccountType.java
+++ b/java/com/android/contacts/common/model/account/GoogleAccountType.java
@@ -18,6 +18,8 @@
 
 import android.content.ContentValues;
 import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
 import android.provider.ContactsContract.CommonDataKinds.Email;
 import android.provider.ContactsContract.CommonDataKinds.Event;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -196,11 +198,28 @@
 
   @Override
   public String getViewContactNotifyServiceClassName() {
-    return "com.google.android.syncadapters.contacts." + "SyncHighResPhotoIntentService";
+    return PLUS_EXTENSION_PACKAGE_NAME + ".people.sync.focus.SyncHighResPhotoIntentOperation";
   }
 
   @Override
   public String getViewContactNotifyServicePackageName() {
-    return "com.google.android.syncadapters.contacts";
+    return PLUS_EXTENSION_PACKAGE_NAME;
+  }
+
+  /**
+   * Sends a broadcast to the sync adapter to trigger a high res photo sync for the contact which
+   * was viewed
+   * @param context context to send broadcast in
+   * @param rawContactUri Uri of the raw contact viewed
+   */
+  public void handleRawContactViewed(Context context, Uri rawContactUri) {
+    final Intent intent = new Intent();
+    intent.setData(rawContactUri);
+    // New broadcast for syncing high res photo.
+    intent.setPackage(GoogleAccountType.PLUS_EXTENSION_PACKAGE_NAME);
+    intent.setAction(
+        "com.google.android.gms.people.sync.focus.SYNC_HIGH_RES_PHOTO");
+
+    context.sendBroadcast(intent);
   }
 }
diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
index 1388f43..62ae748 100644
--- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
+++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
@@ -36,7 +36,6 @@
 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,8 @@
     if (context.getSystemService(TelephonyManager.class).getPhoneCount() <= 1) {
       return NOTIFICATION_TAG;
     }
-    return NOTIFICATION_TAG_PREFIX
-        + VoicemailChannelUtils.getHashedPhoneAccountId(phoneAccountHandle);
+
+    return NOTIFICATION_TAG_PREFIX + phoneAccountHandle.getId();
   }
 
   private LegacyVoicemailNotifier() {}
diff --git a/java/com/android/dialer/commandline/impl/CallCommand.java b/java/com/android/dialer/commandline/impl/CallCommand.java
index 5bcf785..d0008a3 100644
--- a/java/com/android/dialer/commandline/impl/CallCommand.java
+++ b/java/com/android/dialer/commandline/impl/CallCommand.java
@@ -19,8 +19,6 @@
 import android.content.Context;
 import android.content.Intent;
 import android.support.annotation.NonNull;
-import android.telecom.PhoneAccount;
-import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
 import com.android.dialer.buildtype.BuildType;
 import com.android.dialer.buildtype.BuildType.Type;
@@ -67,8 +65,6 @@
     }
     String number = args.expectPositional(0, "number");
     TelecomManager telecomManager = appContext.getSystemService(TelecomManager.class);
-    PhoneAccountHandle phoneAccountHandle =
-        telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL);
     CallIntentBuilder callIntentBuilder;
     if ("voicemail".equals(number)) {
       callIntentBuilder =
diff --git a/java/com/android/dialer/contacts/hiresphoto/HighResolutionPhotoRequesterImpl.java b/java/com/android/dialer/contacts/hiresphoto/HighResolutionPhotoRequesterImpl.java
index 9201604..0c14613 100644
--- a/java/com/android/dialer/contacts/hiresphoto/HighResolutionPhotoRequesterImpl.java
+++ b/java/com/android/dialer/contacts/hiresphoto/HighResolutionPhotoRequesterImpl.java
@@ -51,8 +51,8 @@
   @VisibleForTesting
   static final ComponentName SYNC_HIGH_RESOLUTION_PHOTO_SERVICE =
       new ComponentName(
-          "com.google.android.syncadapters.contacts",
-          "com.google.android.syncadapters.contacts.SyncHighResPhotoIntentService");
+          "com.google.android.gms",
+          "com.google.android.gms.people.sync.focus.SyncHighResPhotoIntentOperation");
 
   private final Context appContext;
   private final ListeningExecutorService backgroundExecutor;
@@ -81,7 +81,8 @@
   private void requestInternal(Uri contactUri) throws RequestFailedException {
     for (Long rawContactId : getGoogleRawContactIds(getContactId(contactUri))) {
       Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
-      Intent intent = new Intent(Intent.ACTION_VIEW);
+      Intent intent = new Intent();
+      intent.setAction("com.google.android.gms.people.sync.focus.SYNC_HIGH_RES_PHOTO");
       intent.setComponent(SYNC_HIGH_RESOLUTION_PHOTO_SERVICE);
       intent.setDataAndType(rawContactUri, RawContacts.CONTENT_ITEM_TYPE);
       intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
@@ -89,7 +90,7 @@
         LogUtil.i(
             "HighResolutionPhotoRequesterImpl.requestInternal",
             "requesting photo for " + rawContactUri);
-        appContext.startService(intent);
+        appContext.sendBroadcast(intent);
       } catch (IllegalStateException | SecurityException e) {
         throw new RequestFailedException("unable to start sync adapter", e);
       }
diff --git a/java/com/android/dialer/notification/VoicemailChannelUtils.java b/java/com/android/dialer/notification/VoicemailChannelUtils.java
index 83bda0f..ddc0f77 100644
--- a/java/com/android/dialer/notification/VoicemailChannelUtils.java
+++ b/java/com/android/dialer/notification/VoicemailChannelUtils.java
@@ -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 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 @@
 
   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();
   }
 
   /**
diff --git a/java/com/android/voicemail/impl/sms/StatusSmsFetcher.java b/java/com/android/voicemail/impl/sms/StatusSmsFetcher.java
index 335ec3e..dd945e9 100644
--- a/java/com/android/voicemail/impl/sms/StatusSmsFetcher.java
+++ b/java/com/android/voicemail/impl/sms/StatusSmsFetcher.java
@@ -54,7 +54,7 @@
   private static final long STATUS_SMS_TIMEOUT_MILLIS = 60_000;
 
   private static final String PERMISSION_DIALER_ORIGIN =
-    "com.android.dialer.permission.DIALER_ORIGIN";
+      "com.android.dialer.permission.DIALER_ORIGIN";
 
   private static final String ACTION_REQUEST_SENT_INTENT =
       "com.android.voicemailomtp.sms.REQUEST_SENT";