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

Commit 5d0642f5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I20238912,I1fe1eef4

* changes:
  InCallActivity#isDialpadVisible() now returns the correct value.
  BEGIN_PUBLIC Automated rollback of changelist 172505648
parents 888e6b14 d588387e
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -337,30 +337,30 @@ public class ContactInfoHelper {
      return ContactInfo.EMPTY;
    }

    try (Cursor phoneLookupCursor =
        mContext
            .getContentResolver()
            .query(uri, PhoneQuery.getPhoneLookupProjection(uri), null, null, null)) {
    Cursor phoneLookupCursor = null;
    try {
      String[] projection = PhoneQuery.getPhoneLookupProjection(uri);
      phoneLookupCursor = mContext.getContentResolver().query(uri, projection, null, null, null);
    } catch (NullPointerException e) {
      LogUtil.e("ContactInfoHelper.lookupContactFromUri", "phone lookup", e);
      // Trap NPE from pre-N CP2
      return null;
    }
    if (phoneLookupCursor == null) {
      LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null");
      return null;
    }

    try {
      if (!phoneLookupCursor.moveToFirst()) {
        return ContactInfo.EMPTY;
      }

      Cursor matchedCursor =
          PhoneNumberHelper.getCursorMatchForContactLookupUri(
              phoneLookupCursor, PhoneQuery.MATCHED_NUMBER, uri);
      if (matchedCursor == null) {
        return ContactInfo.EMPTY;
      }

      String lookupKey = matchedCursor.getString(PhoneQuery.LOOKUP_KEY);
      ContactInfo contactInfo = createPhoneLookupContactInfo(matchedCursor, lookupKey);
      String lookupKey = phoneLookupCursor.getString(PhoneQuery.LOOKUP_KEY);
      ContactInfo contactInfo = createPhoneLookupContactInfo(phoneLookupCursor, lookupKey);
      fillAdditionalContactInfo(mContext, contactInfo);
      return contactInfo;
    } finally {
      phoneLookupCursor.close();
    }
  }

+0 −75
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.dialer.phonenumberutil;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Trace;
import android.provider.CallLog;
import android.support.annotation.NonNull;
@@ -29,7 +27,6 @@ import android.telephony.TelephonyManager;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.compat.CompatUtils;
import com.android.dialer.compat.telephony.TelephonyManagerCompat;
@@ -52,78 +49,6 @@ public class PhoneNumberHelper {
        && !isLegacyUnknownNumbers(number);
  }

  /**
   * Find the cursor pointing to a number that matches the number in a contact lookup URI.
   *
   * <p>When determining whether two phone numbers are identical enough for caller ID purposes, the
   * Contacts Provider uses {@link PhoneNumberUtils#compare(String, String)}, which ignores special
   * dialable characters such as '#', '*', '+', etc. This makes it possible for the cursor returned
   * by the Contacts Provider to have multiple rows even when the URI asks for a specific number.
   *
   * <p>For example, suppose the user has two contacts whose numbers are "#123" and "123",
   * respectively. When the URI asks for number "123", both numbers will be returned. Therefore, the
   * following strategy is employed to find a match.
   *
   * <p>If the cursor points to a global phone number (i.e., a number that can be accepted by {@link
   * PhoneNumberUtils#isGlobalPhoneNumber(String)}) and the lookup number in the URI is a PARTIAL
   * match, return the cursor.
   *
   * <p>If the cursor points to a number that is not a global phone number, return the cursor iff
   * the lookup number in the URI is an EXACT match.
   *
   * <p>Return null in all other circumstances.
   *
   * @param cursor A cursor returned by the Contacts Provider.
   * @param columnIndexForNumber The index of the column where phone numbers are stored. It is the
   *     caller's responsibility to pass the correct column index.
   * @param contactLookupUri A URI used to retrieve a contact via the Contacts Provider. It is the
   *     caller's responsibility to ensure the URI is one that asks for a specific phone number.
   * @return The cursor considered as a match by the description above or null if no such cursor can
   *     be found.
   */
  public static Cursor getCursorMatchForContactLookupUri(
      Cursor cursor, int columnIndexForNumber, Uri contactLookupUri) {
    if (cursor == null || contactLookupUri == null) {
      return null;
    }

    if (!cursor.moveToFirst()) {
      return null;
    }

    Assert.checkArgument(
        0 <= columnIndexForNumber && columnIndexForNumber < cursor.getColumnCount());

    String lookupNumber = contactLookupUri.getLastPathSegment();
    if (lookupNumber == null) {
      return null;
    }

    boolean isMatchFound;
    do {
      // All undialable characters should be converted/removed before comparing the lookup number
      // and the existing contact number.
      String rawExistingContactNumber =
          PhoneNumberUtils.stripSeparators(
              PhoneNumberUtils.convertKeypadLettersToDigits(
                  cursor.getString(columnIndexForNumber)));
      String rawQueryNumber =
          PhoneNumberUtils.stripSeparators(
              PhoneNumberUtils.convertKeypadLettersToDigits(lookupNumber));

      isMatchFound =
          PhoneNumberUtils.isGlobalPhoneNumber(rawExistingContactNumber)
              ? rawExistingContactNumber.contains(rawQueryNumber)
              : rawExistingContactNumber.equals(rawQueryNumber);

      if (isMatchFound) {
        return cursor;
      }
    } while (cursor.moveToNext());

    return null;
  }

  /**
   * Returns true if the given number is the number of the configured voicemail. To be able to
   * mock-out this, it is not a static method.
+121 −126
Original line number Diff line number Diff line
@@ -192,30 +192,25 @@ public class CallerInfo {
   *
   * @param context the context used to retrieve string constants
   * @param contactRef the URI to attach to this CallerInfo object
   * @param cursor the first matching object in the cursor is used to build the CallerInfo object.
   * @param cursor the first object in the cursor is used to build the CallerInfo object.
   * @return the CallerInfo which contains the caller id for the given number. The returned
   *     CallerInfo is null if no number is supplied.
   */
  public static CallerInfo getCallerInfo(Context context, Uri contactRef, Cursor cursor) {
    CallerInfo info = new CallerInfo();
    info.photoResource = 0;
    info.phoneLabel = null;
    info.numberType = 0;
    info.numberLabel = null;
    info.cachedPhoto = null;
    info.contactExists = false;
    info.contactRefUri = contactRef;
    info.isCachedPhotoCurrent = false;
    info.name = null;
    info.needUpdate = false;
    info.numberLabel = null;
    info.numberType = 0;
    info.phoneLabel = null;
    info.photoResource = 0;
    info.contactExists = false;
    info.userType = ContactsUtils.USER_TYPE_CURRENT;

    Log.v(TAG, "getCallerInfo() based on cursor...");

    if (cursor == null || !cursor.moveToFirst()) {
      return info;
    }

    if (cursor != null) {
      if (cursor.moveToFirst()) {
        // TODO: photo_id is always available but not taken
        // care of here. Maybe we should store it in the
        // CallerInfo object as well.
@@ -223,22 +218,16 @@ public class CallerInfo {
        long contactId = 0L;
        int columnIndex;

    // If the cursor has the phone number column, find the one that matches the lookup number in the
    // URI.
    columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
    if (columnIndex != -1 && contactRef != null) {
      cursor = PhoneNumberHelper.getCursorMatchForContactLookupUri(cursor, columnIndex, contactRef);
      if (cursor != null) {
        info.phoneNumber = cursor.getString(columnIndex);
      } else {
        return info;
      }
    }

        // Look for the name
        columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
        if (columnIndex != -1) {
      info.name = normalize(cursor.getString(columnIndex));
          info.name = cursor.getString(columnIndex);
        }

        // Look for the number
        columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
        if (columnIndex != -1) {
          info.phoneNumber = cursor.getString(columnIndex);
        }

        // Look for the normalized number
@@ -272,7 +261,8 @@ public class CallerInfo {
          contactId = cursor.getLong(columnIndex);
          // QuickContacts in M doesn't support enterprise contact id
          if (contactId != 0
          && (VERSION.SDK_INT >= VERSION_CODES.N || !Contacts.isEnterpriseContactId(contactId))) {
              && (VERSION.SDK_INT >= VERSION_CODES.N
                  || !Contacts.isEnterpriseContactId(contactId))) {
            info.contactIdOrZero = contactId;
            Log.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero);
          }
@@ -330,7 +320,13 @@ public class CallerInfo {
        info.nameAlternative =
            ContactInfoHelper.lookUpDisplayNameAlternative(
                context, info.lookupKeyOrNull, info.userType, directoryId);
      }
      cursor.close();
    }

    info.needUpdate = false;
    info.name = normalize(info.name);
    info.contactRefUri = contactRef;

    return info;
  }
@@ -510,7 +506,6 @@ public class CallerInfo {
      Log.e(TAG, "Cannot access VoiceMail.", se);
    }
    // TODO: There is no voicemail picture?

    // photoResource = android.R.drawable.badge_voicemail;
    return this;
  }
+0 −9
Original line number Diff line number Diff line
@@ -202,15 +202,6 @@ public class DialpadFragment extends BaseFragment<DialpadPresenter, DialpadUi>
    mDtmfDialerField.setText(PhoneNumberUtilsCompat.createTtsSpannable(text));
  }

  @Override
  public void setVisible(boolean on) {
    if (on) {
      getView().setVisibility(View.VISIBLE);
    } else {
      getView().setVisibility(View.INVISIBLE);
    }
  }

  /** Starts the slide up animation for the Dialpad keys when the Dialpad is revealed. */
  public void animateShowDialpad() {
    final DialpadView dialpadView = (DialpadView) getView().findViewById(R.id.dialpad_view);
+0 −2
Original line number Diff line number Diff line
@@ -84,8 +84,6 @@ public class DialpadPresenter extends Presenter<DialpadUi>

  public interface DialpadUi extends Ui {

    void setVisible(boolean on);

    void appendDigitsToField(char digit);
  }
}
Loading