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

Commit a4745bdd authored by twyen's avatar twyen Committed by Copybara-Service
Browse files

Move TelecomCallUtil to com.android.dialer

Since PhoneLookup exposes Call, more common access to the utility is required.

Bug: 70355819
Test: TelecomCallUtilTest
PiperOrigin-RevId: 178847628
Change-Id: I6cf55ad4e3566596b7b2e8cffb5a1614e6640a8b
parent 19be6707
Loading
Loading
Loading
Loading
+106 −0
Original line number Diff line number Diff line
@@ -14,11 +14,22 @@
 * limitations under the License.
 */

package com.android.incallui.util;
package com.android.dialer.telecom;

import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.telecom.Call;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
import android.telephony.SubscriptionInfo;
import android.text.TextUtils;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.google.common.base.Optional;
import java.util.Locale;

/**
 * Class to provide a standard interface for obtaining information from the underlying
@@ -28,13 +39,19 @@ import android.telephony.PhoneNumberUtils;
 */
public class TelecomCallUtil {

  // Whether the call handle is an emergency number.
  public static boolean isEmergencyCall(Call call) {
  /** Returns Whether the call handle is an emergency number. */
  public static boolean isEmergencyCall(@NonNull Call call) {
    Assert.isNotNull(call);
    Uri handle = call.getDetails().getHandle();
    return PhoneNumberUtils.isEmergencyNumber(handle == null ? "" : handle.getSchemeSpecificPart());
  }

  public static String getNumber(Call call) {
  /**
   * Returns The phone number which the {@code Call} is currently connected, or {@code null} if the
   * number is not available.
   */
  @Nullable
  public static String getNumber(@Nullable Call call) {
    if (call == null) {
      return null;
    }
@@ -45,7 +62,45 @@ public class TelecomCallUtil {
    return handle == null ? null : handle.getSchemeSpecificPart();
  }

  public static Uri getHandle(Call call) {
  /**
   * Returns The handle (e.g., phone number) to which the {@code Call} is currently connected, or
   * {@code null} if the number is not available.
   */
  @Nullable
  public static Uri getHandle(@Nullable Call call) {
    return call == null ? null : call.getDetails().getHandle();
  }

  /**
   * Normalizes the number of the {@code call} to E.164. If the country code is missing in the
   * number the SIM's country will be used. Only removes non-dialable digits if the country code is
   * missing.
   */
  @WorkerThread
  public static Optional<String> getNormalizedNumber(Context appContext, Call call) {
    Assert.isWorkerThread();
    PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle();
    Optional<SubscriptionInfo> subscriptionInfo =
        TelecomUtil.getSubscriptionInfo(appContext, phoneAccountHandle);
    String rawNumber = getNumber(call);
    if (TextUtils.isEmpty(rawNumber)) {
      return Optional.absent();
    }
    String normalizedNumber = PhoneNumberUtils.normalizeNumber(rawNumber);
    if (TextUtils.isEmpty(normalizedNumber)) {
      return Optional.absent();
    }
    String countryCode =
        subscriptionInfo.isPresent() ? subscriptionInfo.get().getCountryIso() : null;
    if (countryCode == null) {
      LogUtil.w(
          "PhoneLookupHistoryRecorder.getNormalizedNumber",
          "couldn't find a country code for call");
      return Optional.of(normalizedNumber);
    }

    String e164Number =
        PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US));
    return e164Number == null ? Optional.of(normalizedNumber) : Optional.of(e164Number);
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -44,11 +44,11 @@ import com.android.dialer.common.Assert;
import com.android.dialer.contactphoto.BitmapUtil;
import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.notification.NotificationChannelId;
import com.android.dialer.telecom.TelecomCallUtil;
import com.android.incallui.call.DialerCall;
import com.android.incallui.call.DialerCallDelegate;
import com.android.incallui.call.ExternalCallList;
import com.android.incallui.latencyreport.LatencyReport;
import com.android.incallui.util.TelecomCallUtil;
import java.util.Map;

/**
+2 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.dialer.location.GeoUtil;
import com.android.dialer.logging.InteractionEvent;
import com.android.dialer.logging.Logger;
import com.android.dialer.postcall.PostCall;
import com.android.dialer.telecom.TelecomCallUtil;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.TouchPointManager;
import com.android.incallui.InCallOrientationEventListener.ScreenOrientation;
@@ -66,7 +67,6 @@ import com.android.incallui.incalluilock.InCallUiLock;
import com.android.incallui.latencyreport.LatencyReport;
import com.android.incallui.legacyblocking.BlockedNumberContentObserver;
import com.android.incallui.spam.SpamCallListListener;
import com.android.incallui.util.TelecomCallUtil;
import com.android.incallui.videosurface.bindings.VideoSurfaceBindings;
import com.android.incallui.videosurface.protocol.VideoSurfaceTexture;
import com.android.incallui.videotech.utils.VideoUtils;
+3 −32
Original line number Diff line number Diff line
@@ -19,25 +19,18 @@ import android.content.ContentValues;
import android.content.Context;
import android.support.annotation.Nullable;
import android.telecom.Call;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
import android.telephony.SubscriptionInfo;
import android.text.TextUtils;
import com.android.dialer.buildtype.BuildType;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.DialerExecutors;
import com.android.dialer.location.CountryDetector;
import com.android.dialer.phonelookup.PhoneLookupComponent;
import com.android.dialer.phonelookup.PhoneLookupInfo;
import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory;
import com.android.dialer.telecom.TelecomUtil;
import com.android.incallui.util.TelecomCallUtil;
import com.android.dialer.telecom.TelecomCallUtil;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Locale;

/**
 * Fetches the current {@link PhoneLookupInfo} for the provided call and writes it to the
@@ -61,7 +54,8 @@ final class PhoneLookupHistoryRecorder {
          @Override
          public void onSuccess(@Nullable PhoneLookupInfo result) {
            Assert.checkArgument(result != null);
            Optional<String> normalizedNumber = getNormalizedNumber(appContext, call);
            Optional<String> normalizedNumber =
                TelecomCallUtil.getNormalizedNumber(appContext, call);
            if (!normalizedNumber.isPresent()) {
              LogUtil.w("PhoneLookupHistoryRecorder.onSuccess", "couldn't get a number");
              return;
@@ -90,27 +84,4 @@ final class PhoneLookupHistoryRecorder {
        },
        DialerExecutors.getLowPriorityThreadPool(appContext));
  }

  private static Optional<String> getNormalizedNumber(Context appContext, Call call) {
    PhoneAccountHandle phoneAccountHandle = call.getDetails().getAccountHandle();
    Optional<SubscriptionInfo> subscriptionInfo =
        TelecomUtil.getSubscriptionInfo(appContext, phoneAccountHandle);
    String countryCode =
        subscriptionInfo.isPresent()
            ? subscriptionInfo.get().getCountryIso()
            : CountryDetector.getInstance(appContext).getCurrentCountryIso();
    if (countryCode == null) {
      LogUtil.w(
          "PhoneLookupHistoryRecorder.getNormalizedNumber",
          "couldn't find a country code for call");
      countryCode = "US";
    }
    String rawNumber = TelecomCallUtil.getNumber(call);
    if (TextUtils.isEmpty(rawNumber)) {
      return Optional.absent();
    }
    String normalizedNumber =
        PhoneNumberUtils.formatNumberToE164(rawNumber, countryCode.toUpperCase(Locale.US));
    return normalizedNumber == null ? Optional.of(rawNumber) : Optional.of(normalizedNumber);
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -40,9 +40,9 @@ import com.android.dialer.logging.LoggingBindings;
import com.android.dialer.shortcuts.ShortcutUsageReporter;
import com.android.dialer.spam.Spam;
import com.android.dialer.spam.SpamComponent;
import com.android.dialer.telecom.TelecomCallUtil;
import com.android.incallui.call.DialerCall.State;
import com.android.incallui.latencyreport.LatencyReport;
import com.android.incallui.util.TelecomCallUtil;
import com.android.incallui.videotech.utils.SessionModificationState;
import java.util.Collection;
import java.util.Collections;
Loading