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

Commit 8333c34a authored by Sanket Agarwal's avatar Sanket Agarwal Committed by Gerrit Code Review
Browse files

Merge "Normalize the number before inserting into list of calls in connectionservice"

parents ece26fef f0e12179
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.bluetooth.hfpclient.connserv;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.net.Uri;
import android.telecom.PhoneAccount;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;

/* Matching a call to internal state requires understanding of the ph number and the state of the
 * remote itself. The best way to associate a call with remote is to use the Call IDs that are
@@ -31,14 +33,28 @@ class ConnectionKey {
    public static final int INVALID_ID = -1;

    private final int mId;
    private final Uri mPhoneNumber;
    private final String mPhoneNumber;

    ConnectionKey(int id, Uri phoneNumber) {
        if (id == INVALID_ID && phoneNumber == null) {
            throw new IllegalStateException("invalid id and phone number");
        }
        mId = id;
        mPhoneNumber = phoneNumber;
        mPhoneNumber = normalizePhoneUri(phoneNumber);
    }

    private static String normalizePhoneUri(Uri phoneNumber) {
        // Sometimes the number can be rewritten with brackets and such, we normalize to take that
        // factor out.
        String schemeSpecificPart = phoneNumber.getSchemeSpecificPart();
        if (!TextUtils.isEmpty(schemeSpecificPart)) {
            if (schemeSpecificPart.startsWith("+")) {
                schemeSpecificPart = schemeSpecificPart.substring(1);
            }

            schemeSpecificPart = PhoneNumberUtils.normalizeNumber(schemeSpecificPart);
        }
        return schemeSpecificPart;
    }

    public static ConnectionKey getKey(BluetoothHeadsetClientCall call) {
@@ -56,7 +72,7 @@ class ConnectionKey {
        return mId;
    }

    public Uri getPhoneNumber() {
    public String getPhoneNumber() {
        return mPhoneNumber;
    }