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

Commit 2c4533dc authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fix phone number is not displayed on the car kit."

parents 892c00b2 318c24b2
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1676,11 +1676,12 @@ public class HeadsetStateMachine extends StateMachine {
        if (number != null) {
            mNativeInterface.atResponseString(device,
                    "+CNUM: ,\"" + number + "\"," + PhoneNumberUtils.toaFromString(number) + ",,4");
            mNativeInterface.atResponseCode(device, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        } else {
            Log.e(TAG, "getSubscriberNumber returns null");
            mNativeInterface.atResponseCode(device, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
            Log.e(TAG, "getSubscriberNumber returns null, no subscriber number can reply");
        }

        // Based on spec, if subscriber number is empty, we should still return OK response.
        mNativeInterface.atResponseCode(device, HeadsetHalConstants.AT_RESPONSE_OK, 0);
    }

    private void processAtCind(BluetoothDevice device) {
+46 −1
Original line number Diff line number Diff line
@@ -27,7 +27,12 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.media.AudioManager;
import android.net.Uri;
import android.os.PowerManager;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.android.bluetooth.telephony.BluetoothInCallService;
@@ -48,6 +53,8 @@ public class HeadsetSystemInterface {
    private final AudioManager mAudioManager;
    private final HeadsetPhoneState mHeadsetPhoneState;
    private PowerManager.WakeLock mVoiceRecognitionWakeLock;
    private final TelephonyManager mTelephonyManager;
    private final TelecomManager mTelecomManager;

    HeadsetSystemInterface(HeadsetService headsetService) {
        if (headsetService == null) {
@@ -60,6 +67,8 @@ public class HeadsetSystemInterface {
                powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG + ":VoiceRecognition");
        mVoiceRecognitionWakeLock.setReferenceCounted(false);
        mHeadsetPhoneState = new com.android.bluetooth.hfp.HeadsetPhoneState(mHeadsetService);
        mTelephonyManager = mHeadsetService.getSystemService(TelephonyManager.class);
        mTelecomManager = mHeadsetService.getSystemService(TelecomManager.class);
    }

    private BluetoothInCallService getBluetoothInCallServiceInstance() {
@@ -235,6 +244,41 @@ public class HeadsetSystemInterface {
        return bluetoothInCallService.getNetworkOperator();
    }

    /**
     * Get the phone number of this device without incall service
     *
     * @return emptry if unavailable
     */
    private String getNumberWithoutInCallService() {
        PhoneAccount account = null;
        String address = "";

        // Get the label for the default Phone Account.
        List<PhoneAccountHandle> handles =
                mTelecomManager.getPhoneAccountsSupportingScheme(PhoneAccount.SCHEME_TEL);
        while (handles.iterator().hasNext()) {
            account = mTelecomManager.getPhoneAccount(handles.iterator().next());
            break;
        }

        if (account != null) {
            Uri addressUri = account.getAddress();

            if (addressUri != null) {
                address = addressUri.getSchemeSpecificPart();
            }
        }

        if (address.isEmpty()) {
            address = mTelephonyManager.getLine1Number();
            if (address == null) address = "";
        }

        Log.i(TAG, String.format("get phone number -> '%s'", address));

        return address;
    }

    /**
     * Get the phone number of this device
     *
@@ -245,7 +289,8 @@ public class HeadsetSystemInterface {
        BluetoothInCallService bluetoothInCallService = getBluetoothInCallServiceInstance();
        if (bluetoothInCallService == null) {
            Log.e(TAG, "getSubscriberNumber() failed: mBluetoothInCallService is null");
            return null;
            Log.i(TAG, "Try to get phone number without mBluetoothInCallService.");
            return getNumberWithoutInCallService();
        }
        return bluetoothInCallService.getSubscriberNumber();
    }