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

Commit 5cb063e4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix phone number is not displayed on the car kit." into sc-dev am: fe568c4a

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/15283196

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

        // 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) {
    private void processAtCind(BluetoothDevice device) {
+48 −1
Original line number Original line Diff line number Diff line
@@ -28,7 +28,12 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.media.AudioManager;
import android.media.AudioManager;
import android.net.Uri;
import android.os.PowerManager;
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 android.util.Log;


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


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


    private BluetoothInCallService getBluetoothInCallServiceInstance() {
    private BluetoothInCallService getBluetoothInCallServiceInstance() {
@@ -241,6 +250,42 @@ public class HeadsetSystemInterface {
        return bluetoothInCallService.getNetworkOperator();
        return bluetoothInCallService.getNetworkOperator();
    }
    }


    /**
     * Get the phone number of this device without incall service
     *
     * @return emptry if unavailable
     */
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    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
     * Get the phone number of this device
     *
     *
@@ -252,7 +297,9 @@ public class HeadsetSystemInterface {
        BluetoothInCallService bluetoothInCallService = getBluetoothInCallServiceInstance();
        BluetoothInCallService bluetoothInCallService = getBluetoothInCallServiceInstance();
        if (bluetoothInCallService == null) {
        if (bluetoothInCallService == null) {
            Log.e(TAG, "getSubscriberNumber() failed: mBluetoothInCallService is 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();
        return bluetoothInCallService.getSubscriberNumber();
    }
    }