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

Commit 7f7d8d59 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Handle Headset Client connection state broadcasts received by PBAP...

Merge "Handle Headset Client connection state broadcasts received by PBAP Client by direct call." into main
parents 6d0ddbf7 d7886d50
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.telecom.TelecomManager;
import android.util.Log;

import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.pbapclient.PbapClientService;

import java.util.Arrays;
import java.util.HashMap;
@@ -156,6 +157,10 @@ public class HfpClientConnectionService extends ConnectionService {
                    .getRemoteDevices()
                    .handleHeadsetClientConnectionStateChanged(device, oldState, newState);
        }
        if (PbapClientService.getPbapClientService() != null) {
            PbapClientService.getPbapClientService()
                    .handleHeadsetClientConnectionStateChanged(device, oldState, newState);
        }
    }

    private void onCallChangedInternal(BluetoothDevice device, HfpClientCall call) {
+17 −19
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothPbapClient;
import android.content.AttributionSource;
@@ -140,9 +139,6 @@ public class PbapClientService extends ProfileService {
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        // delay initial download until after the user is unlocked to add an account.
        filter.addAction(Intent.ACTION_USER_UNLOCKED);
        // To remove call logs when PBAP was never connected while calls were made,
        // we also listen for HFP to become disconnected.
        filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
        try {
            registerReceiver(mPbapBroadcastReceiver, filter);
        } catch (Exception e) {
@@ -316,22 +312,24 @@ public class PbapClientService extends ProfileService {
                for (PbapClientStateMachine stateMachine : mPbapClientStateMachineMap.values()) {
                    stateMachine.tryDownloadIfConnected();
                }
            } else if (action.equals(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED)) {
                // PbapClientConnectionHandler has code to remove calllogs when PBAP disconnects.
                // However, if PBAP was never connected/enabled in the first place, and calls are
                // made over HFP, these calllogs will not be removed when the device disconnects.
                // This code ensures callogs are still removed in this case.
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
            }
        }
    }

    /**
     * Ensure that after HFP disconnects, we remove call logs. This addresses the situation when
     * PBAP was never connected while calls were made. Ideally {@link PbapClientConnectionHandler}
     * has code to remove calllogs when PBAP disconnects.
     */
    public void handleHeadsetClientConnectionStateChanged(
            BluetoothDevice device, int oldState, int newState) {
        if (newState == BluetoothProfile.STATE_DISCONNECTED) {
            if (DBG) {
                Log.d(TAG, "Received intent to disconnect HFP with " + device);
            }
            // HFP client stores entries in calllog.db by BD_ADDR and component name
                    removeHfpCallLog(device.getAddress(), context);
                }
            }
            // Using the current Service as the context.
            removeHfpCallLog(device.getAddress(), this);
        }
    }

+5 −7
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.when;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
@@ -50,7 +49,6 @@ import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiv
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -366,14 +364,14 @@ public class PbapClientServiceTest {
    }

    @Test
    public void broadcastReceiver_withActionHeadsetClientConnectionStateChanged() {
    public void headsetClientConnectionStateChanged_hfpCallLogIsRemoved() {
        BluetoothMethodProxy methodProxy = spy(BluetoothMethodProxy.getInstance());
        BluetoothMethodProxy.setInstanceForTesting(methodProxy);

        Intent intent = new Intent(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevice);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_DISCONNECTED);
        mService.mPbapBroadcastReceiver.onReceive(mService, intent);
        mService.handleHeadsetClientConnectionStateChanged(
                mRemoteDevice,
                BluetoothProfile.STATE_CONNECTED,
                BluetoothProfile.STATE_DISCONNECTED);

        ArgumentCaptor<Object> selectionArgsCaptor = ArgumentCaptor.forClass(Object.class);
        verify(methodProxy).contentResolverDelete(any(), eq(CallLog.Calls.CONTENT_URI), any(),