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

Commit 907a6ddb authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge changes Ice096f0c,Ic576c05f,I29459364,I175affe1,Ia42b2651, ... into main am: 8c5a9ea8

parents 59686ee7 8c5a9ea8
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -16,11 +16,10 @@

package com.android.bluetooth.hfp;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;

import java.util.List;

@@ -39,11 +38,8 @@ public class BluetoothHeadsetProxy {
        mBluetoothHeadset = headset;
    }

    public void closeBluetoothHeadsetProxy(Context context) {
        final BluetoothManager btManager = context.getSystemService(BluetoothManager.class);
        if (btManager != null) {
            btManager.getAdapter().closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
        }
    public void closeBluetoothHeadsetProxy(BluetoothAdapter adapter) {
        adapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
    }

    public void clccResponse(
+3 −9
Original line number Diff line number Diff line
@@ -17,11 +17,10 @@

package com.android.bluetooth.tbs;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothLeCall;
import android.bluetooth.BluetoothLeCallControl;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;

import java.util.List;
import java.util.UUID;
@@ -52,13 +51,8 @@ public class BluetoothLeCallControlProxy {
        mBluetoothLeCallControl = tbs;
    }

    public void closeBluetoothLeCallControlProxy(Context context) {
        final BluetoothManager btManager = context.getSystemService(BluetoothManager.class);
        if (btManager != null) {
            btManager
                    .getAdapter()
                    .closeProfileProxy(BluetoothProfile.LE_CALL_CONTROL, mBluetoothLeCallControl);
        }
    public void closeBluetoothLeCallControlProxy(BluetoothAdapter adapter) {
        adapter.closeProfileProxy(BluetoothProfile.LE_CALL_CONTROL, mBluetoothLeCallControl);
    }

    public boolean registerBearer(
+50 −65
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package com.android.bluetooth.telephony;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothLeCall;
import android.bluetooth.BluetoothLeCallControl;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -53,7 +56,6 @@ import com.android.bluetooth.tbs.BluetoothLeCallControlProxy;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
@@ -120,9 +122,8 @@ public class BluetoothInCallService extends InCallService {
    @VisibleForTesting BluetoothLeCallControlProxy mBluetoothLeCallControl;
    private ExecutorService mExecutor;

    @VisibleForTesting public TelephonyManager mTelephonyManager;

    @VisibleForTesting public TelecomManager mTelecomManager;
    private TelephonyManager mTelephonyManager;
    private TelecomManager mTelecomManager;

    @VisibleForTesting
    public final HashMap<Integer, CallStateCallback> mCallbacks = new HashMap<>();
@@ -138,30 +139,34 @@ public class BluetoothInCallService extends InCallService {

    private static BluetoothInCallService sInstance = null;

    public CallInfo mCallInfo = new CallInfo();
    private final CallInfo mCallInfo;

    protected boolean mOnCreateCalled = false;

    private int mMaxNumberOfCalls = 0;

    /**
     * Listens to connections and disconnections of bluetooth headsets. We need to save the current
     * bluetooth headset so that we know where to send BluetoothCall updates.
     */
    @VisibleForTesting
    public BluetoothProfile.ServiceListener mProfileListener =
    private BluetoothAdapter mAdapter = null;

    private final BluetoothProfile.ServiceListener mProfileListener =
            new BluetoothProfile.ServiceListener() {
                @Override
                public void onServiceConnected(int profile, BluetoothProfile proxy) {
                    synchronized (LOCK) {
                        if (profile == BluetoothProfile.HEADSET) {
                            setBluetoothHeadset(
                                    new BluetoothHeadsetProxy((BluetoothHeadset) proxy));
                            mBluetoothHeadset = new BluetoothHeadsetProxy((BluetoothHeadset) proxy);
                            updateHeadsetWithCallState(true /* force */);
                        } else {
                            setBluetoothLeCallControl(
                                    new BluetoothLeCallControlProxy(
                                            (BluetoothLeCallControl) proxy));
                            mBluetoothLeCallControl =
                                    new BluetoothLeCallControlProxy((BluetoothLeCallControl) proxy);

                            mBluetoothLeCallControl.registerBearer(
                                    TAG,
                                    List.of("tel"),
                                    BluetoothLeCallControl.CAPABILITY_HOLD_CALL,
                                    getNetworkOperator(),
                                    getBearerTechnology(),
                                    mExecutor,
                                    mBluetoothLeCallControlCallback);
                            sendTbsCurrentCallsList();
                        }
                    }
@@ -171,9 +176,9 @@ public class BluetoothInCallService extends InCallService {
                public void onServiceDisconnected(int profile) {
                    synchronized (LOCK) {
                        if (profile == BluetoothProfile.HEADSET) {
                            setBluetoothHeadset(null);
                            mBluetoothHeadset = null;
                        } else {
                            setBluetoothLeCallControl(null);
                            mBluetoothLeCallControl = null;
                        }
                    }
                }
@@ -335,10 +340,7 @@ public class BluetoothInCallService extends InCallService {
    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "onBind. Intent: " + intent);
        IBinder binder = super.onBind(intent);
        mTelephonyManager = getSystemService(TelephonyManager.class);
        mTelecomManager = getSystemService(TelecomManager.class);
        return binder;
        return super.onBind(intent);
    }

    @Override
@@ -347,12 +349,29 @@ public class BluetoothInCallService extends InCallService {
        return super.onUnbind(intent);
    }

    public BluetoothInCallService() {
    private BluetoothInCallService(CallInfo callInfo) {
        Log.i(TAG, "BluetoothInCallService is created");
        mCallInfo = Objects.requireNonNullElse(callInfo, new CallInfo());
        sInstance = this;
        mExecutor = Executors.newSingleThreadExecutor();
    }

    public BluetoothInCallService() {
        this(null);
    }

    @VisibleForTesting
    BluetoothInCallService(
            Context context,
            CallInfo callInfo,
            BluetoothHeadsetProxy headset,
            BluetoothLeCallControlProxy leCallControl) {
        this(callInfo);
        mBluetoothHeadset = headset;
        mBluetoothLeCallControl = leCallControl;
        attachBaseContext(context);
    }

    public static BluetoothInCallService getInstance() {
        return sInstance;
    }
@@ -502,11 +521,7 @@ public class BluetoothInCallService extends InCallService {
                }
            }
            if (TextUtils.isEmpty(address)) {
                if (mTelephonyManager == null) {
                    address = null;
                } else {
                address = mTelephonyManager.getLine1Number();
                }
                if (address == null) address = "";
            }
            return address;
@@ -717,10 +732,11 @@ public class BluetoothInCallService extends InCallService {
    public void onCreate() {
        Log.d(TAG, "onCreate");
        super.onCreate();
        BluetoothAdapter.getDefaultAdapter()
                .getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET);
        BluetoothAdapter.getDefaultAdapter()
                .getProfileProxy(this, mProfileListener, BluetoothProfile.LE_CALL_CONTROL);
        mAdapter = requireNonNull(getSystemService(BluetoothManager.class)).getAdapter();
        mTelephonyManager = requireNonNull(getSystemService(TelephonyManager.class));
        mTelecomManager = requireNonNull(getSystemService(TelecomManager.class));
        mAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET);
        mAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.LE_CALL_CONTROL);
        mBluetoothAdapterReceiver = new BluetoothAdapterReceiver();
        IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
@@ -750,14 +766,13 @@ public class BluetoothInCallService extends InCallService {
            mBluetoothAdapterReceiver = null;
        }
        if (mBluetoothHeadset != null) {
            mBluetoothHeadset.closeBluetoothHeadsetProxy(this);
            mBluetoothHeadset.closeBluetoothHeadsetProxy(mAdapter);
            mBluetoothHeadset = null;
        }
        if (mBluetoothLeCallControl != null) {
            mBluetoothLeCallControl.unregisterBearer();
            mBluetoothLeCallControl.closeBluetoothLeCallControlProxy(this);
            mBluetoothLeCallControl.closeBluetoothLeCallControlProxy(mAdapter);
        }
        mProfileListener = null;
        sInstance = null;
        mCallbacks.clear();
        mBluetoothCallHashMap.clear();
@@ -816,10 +831,6 @@ public class BluetoothInCallService extends InCallService {
                        Log.w(TAG, "call id: " + bluetoothCall.getId() + " handle is null");
                        continue;
                    }
                    if (mTelephonyManager == null) {
                        Log.w(TAG, "mTelephonyManager is null");
                        continue;
                    }
                    boolean isSame =
                            PhoneNumberUtils.areSamePhoneNumber(
                                    bluetoothCall.getHandle().toString(),
@@ -1373,11 +1384,6 @@ public class BluetoothInCallService extends InCallService {
        return mCallbacks.get(call.getId());
    }

    @VisibleForTesting
    public void setBluetoothHeadset(BluetoothHeadsetProxy bluetoothHeadset) {
        mBluetoothHeadset = bluetoothHeadset;
    }

    @VisibleForTesting
    public BluetoothCall getBluetoothCallById(Integer id) {
        if (mBluetoothCallHashMap.containsKey(id)) {
@@ -1521,10 +1527,6 @@ public class BluetoothInCallService extends InCallService {

            if (account == null) {
                // Second, Try to get the label for the default Phone Account.
                if (mTelecomManager == null) {
                    Log.w(TAG, "mTelecomManager is null");
                    return null;
                }
                List<PhoneAccountHandle> handles =
                        mTelecomManager.getPhoneAccountsSupportingScheme(PhoneAccount.SCHEME_TEL);
                while (handles.iterator().hasNext()) {
@@ -1552,23 +1554,6 @@ public class BluetoothInCallService extends InCallService {
            return null;
        }
    }
    ;

    @VisibleForTesting
    public void setBluetoothLeCallControl(BluetoothLeCallControlProxy bluetoothTbs) {
        mBluetoothLeCallControl = bluetoothTbs;

        if ((mBluetoothLeCallControl) != null && (mTelecomManager != null)) {
            mBluetoothLeCallControl.registerBearer(
                    TAG,
                    new ArrayList<String>(Arrays.asList("tel")),
                    BluetoothLeCallControl.CAPABILITY_HOLD_CALL,
                    getNetworkOperator(),
                    getBearerTechnology(),
                    mExecutor,
                    mBluetoothLeCallControlCallback);
        }
    }

    private Integer getTbsCallState(BluetoothCall call) {
        switch (call.getState()) {
+416 −586

File changed.

Preview size limit exceeded, changes collapsed.

+13 −4
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
import android.net.Uri;
import android.os.Process;
import android.telecom.Call;
@@ -31,15 +33,17 @@ import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.TestUtils;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

@@ -57,15 +61,21 @@ public class CallInfoTest {

    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();

    @Mock private TelecomManager mMockTelecomManager;
    private TelecomManager mMockTelecomManager;

    private BluetoothInCallService mBluetoothInCallService;
    private BluetoothInCallService.CallInfo mMockCallInfo;

    @Before
    public void setUp() throws Exception {
        Context spiedContext = spy(new ContextWrapper(ApplicationProvider.getApplicationContext()));
        mMockTelecomManager =
                TestUtils.mockGetSystemService(
                        spiedContext, Context.TELECOM_SERVICE, TelecomManager.class);

        mBluetoothInCallService = new BluetoothInCallService(spiedContext, null, null, null);
        mBluetoothInCallService.onCreate();

        mBluetoothInCallService = new BluetoothInCallService();
        mMockCallInfo = spy(mBluetoothInCallService.new CallInfo());
    }

@@ -273,7 +283,6 @@ public class CallInfoTest {

        PhoneAccount fakePhoneAccount = makeQuickAccount(testId, TEST_ACCOUNT_INDEX);
        when(mMockTelecomManager.getPhoneAccount(testHandle)).thenReturn(fakePhoneAccount);
        mBluetoothInCallService.mTelecomManager = mMockTelecomManager;

        assertThat(mMockCallInfo.getBestPhoneAccount()).isEqualTo(fakePhoneAccount);
    }