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

Commit 26f52024 authored by zachh's avatar zachh Committed by Copybara-Service
Browse files

Reworked the internals of DialerPhoneNumber.

It turns out the storing the libphonenumber representation of the number is not particularly useful because even formatting these objects cannot be done on the main thread. Rather than propagate the requirement of using PhoneNumberUtil (and background threads by extension) in the call log UI, we now just store a dialer-normalized version of the number which contains all information required by the UI in a way that allows us to avoid any background work in the UI code.

Bug: 72563861
Test: existing
PiperOrigin-RevId: 183463907
Change-Id: I4bdadaccb7a84033b3c72c54fe3833064f587ee3
parent 29be3926
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;
import com.android.dialer.CoalescedIds;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.assisteddialing.ui.AssistedDialingSettingActivity;
import com.android.dialer.calldetails.CallDetailsEntries.CallDetailsEntry;
import com.android.dialer.callintent.CallInitiationType;
@@ -65,13 +64,14 @@ import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.logging.UiAction;
import com.android.dialer.performancereport.PerformanceReport;
import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil;
import com.android.dialer.postcall.PostCall;
import com.android.dialer.precall.PreCall;
import com.android.dialer.protos.ProtoParsers;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
@@ -441,10 +441,17 @@ public class CallDetailsActivity extends AppCompatActivity {

    @Override
    public Integer doInBackground(@NonNull String phoneNumber) {
      DialerPhoneNumberUtil dialerPhoneNumberUtil =
          new DialerPhoneNumberUtil(PhoneNumberUtil.getInstance());
      DialerPhoneNumber parsedNumber = dialerPhoneNumberUtil.parse(phoneNumber, null);
      return parsedNumber.getDialerInternalPhoneNumber().getCountryCode();
      PhoneNumber parsedNumber = null;
      try {
        parsedNumber = PhoneNumberUtil.getInstance().parse(phoneNumber, null);
      } catch (NumberParseException e) {
        LogUtil.w(
            "AssistedDialingNumberParseWorker.doInBackground",
            "couldn't parse phone number: " + LogUtil.sanitizePii(phoneNumber),
            e);
        return 0;
      }
      return parsedNumber.getCountryCode();
    }
  }

+2 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
@@ -77,7 +78,7 @@ public final class RealtimeRowProcessor {
  private final Map<DialerPhoneNumber, PhoneLookupInfo> cache = new ArrayMap<>();

  private final Map<DialerPhoneNumber, PhoneLookupInfo> queuedPhoneLookupHistoryWrites =
      new ArrayMap<>();
      new LinkedHashMap<>(); // Keep the order so the most recent looked up value always wins
  private final Runnable writePhoneLookupHistoryRunnable = this::writePhoneLookupHistory;

  @Inject
+2 −4
Original line number Diff line number Diff line
@@ -46,8 +46,7 @@ final class Modules {
    // Conditionally add each module, which are items in the bottom sheet's menu.
    List<ContactActionModule> modules = new ArrayList<>();

    // TODO(zach): Don't use raw input.
    String normalizedNumber = row.number().getRawInput().getNumber();
    String normalizedNumber = row.number().getNormalizedNumber();
    boolean canPlaceCalls =
        PhoneNumberHelper.canPlaceCallsTo(normalizedNumber, row.numberPresentation());

@@ -138,8 +137,7 @@ final class Modules {
          .build();
    }

    // TODO(zachh): Don't use raw input.
    String normalizedNumber = row.number().getRawInput().getNumber();
    String normalizedNumber = row.number().getNormalizedNumber();
    DialerContact.Builder dialerContactBuilder =
        DialerContact.newBuilder()
            .setNumber(normalizedNumber)
+1 −2
Original line number Diff line number Diff line
@@ -39,8 +39,7 @@ public final class CallLogIntents {
   */
  @Nullable
  public static Intent getCallBackIntent(Context context, CoalescedRow row) {
    // TODO(zachh): Don't use raw input.
    String normalizedNumber = row.number().getRawInput().getNumber();
    String normalizedNumber = row.number().getNormalizedNumber();
    if (!PhoneNumberHelper.canPlaceCallsTo(normalizedNumber, row.numberPresentation())) {
      return null;
    }
+3 −3
Original line number Diff line number Diff line
@@ -48,14 +48,14 @@ public class SharedModules {
    }

    // Skip showing the menu item if there is no number.
    String originalNumber = number.getRawInput().getNumber();
    if (TextUtils.isEmpty(originalNumber)) {
    String normalizedNumber = number.getNormalizedNumber();
    if (TextUtils.isEmpty(normalizedNumber)) {
      return;
    }

    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    intent.putExtra(ContactsContract.Intents.Insert.PHONE, originalNumber);
    intent.putExtra(ContactsContract.Intents.Insert.PHONE, normalizedNumber);

    if (!TextUtils.isEmpty(name)) {
      intent.putExtra(ContactsContract.Intents.Insert.NAME, name);
Loading