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

Commit 65a8c78b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Removing Telecom hidden API usage" am: 12c022f2

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

Change-Id: I9e7ede8ccab17e409973cc5dabda4b650fe0a95f
parents 0372040d 12c022f2
Loading
Loading
Loading
Loading
+17 −27
Original line number Diff line number Diff line
@@ -150,22 +150,6 @@ public class BluetoothCall {
        mCall.stopRtt();
    }

    public void putExtras(Bundle extras) {
        mCall.putExtras(extras);
    }

    public void putExtra(String key, boolean value) {
        mCall.putExtra(key, value);
    }

    public void putExtra(String key, int value) {
        mCall.putExtra(key, value);
    }

    public void putExtra(String key, String value) {
        mCall.putExtra(key, value);
    }

    public void removeExtras(List<String> keys) {
        mCall.removeExtras(keys);
    }
@@ -174,19 +158,22 @@ public class BluetoothCall {
        mCall.removeExtras(keys);
    }

    public String getParentId() {
    /**
     * Returns the parent Call id.
     */
    public Integer getParentId() {
        Call parent = mCall.getParent();
        if (parent != null) {
            return parent.getDetails().getTelecomCallId();
            return System.identityHashCode(parent);
        }
        return null;
    }

    public List<String> getChildrenIds() {
    public List<Integer> getChildrenIds() {
        return getIds(mCall.getChildren());
    }

    public List<String> getConferenceableCalls() {
    public List<Integer> getConferenceableCalls() {
        return getIds(mCall.getConferenceableCalls());
    }

@@ -239,8 +226,8 @@ public class BluetoothCall {
        mCall.removeListener(listener);
    }

    public String getGenericConferenceActiveChildCallId() {
        return mCall.getGenericConferenceActiveChildCall().getDetails().getTelecomCallId();
    public int getGenericConferenceActiveChildCallId() {
        return System.identityHashCode(mCall.getGenericConferenceActiveChildCall());
    }

    public String getContactDisplayName() {
@@ -297,8 +284,8 @@ public class BluetoothCall {
        return getDetails().hasProperty(Call.Details.PROPERTY_IS_EXTERNAL_CALL);
    }

    public String getTelecomCallId() {
        return getDetails().getTelecomCallId();
    public int getId() {
        return System.identityHashCode(mCall);
    }

    public boolean wasConferencePreviouslyMerged() {
@@ -306,11 +293,14 @@ public class BluetoothCall {
                !can(Call.Details.CAPABILITY_MERGE_CONFERENCE);
    }

    public static List<String> getIds(List<Call> calls) {
        List<String> result = new ArrayList<>();
    /**
     * Returns the list of ids of corresponding Call List.
     */
    public static List<Integer> getIds(List<Call> calls) {
        List<Integer> result = new ArrayList<>();
        for (Call call : calls) {
            if (call != null) {
                result.add(call.getDetails().getTelecomCallId());
                result.add(System.identityHashCode(call));
            }
        }
        return result;
+20 −21
Original line number Diff line number Diff line
@@ -43,11 +43,10 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.android.bluetooth.hfp.BluetoothHeadsetProxy;
import com.android.bluetooth.hfp.HeadsetService;

import androidx.annotation.VisibleForTesting;

import com.android.bluetooth.hfp.BluetoothHeadsetProxy;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -108,10 +107,10 @@ public class BluetoothInCallService extends InCallService {
    public TelecomManager mTelecomManager;

    @VisibleForTesting
    public final HashMap<String, CallStateCallback> mCallbacks = new HashMap<>();
    public final HashMap<Integer, CallStateCallback> mCallbacks = new HashMap<>();

    @VisibleForTesting
    public final HashMap<String, BluetoothCall> mBluetoothCallHashMap = new HashMap<>();
    public final HashMap<Integer, BluetoothCall> mBluetoothCallHashMap = new HashMap<>();

    // A map from Calls to indexes used to identify calls for CLCC (C* List Current Calls).
    private final Map<BluetoothCall, Integer> mClccIndexMap = new HashMap<>();
@@ -220,7 +219,7 @@ public class BluetoothInCallService extends InCallService {
        @Override
        public void onStateChanged(Call call, int state) {
            super.onStateChanged(call, state);
            onStateChanged(getBluetoothCallById(call.getDetails().getTelecomCallId()), state);
            onStateChanged(getBluetoothCallById(System.identityHashCode(call)), state);
        }

        public void onDetailsChanged(BluetoothCall call, Call.Details details) {
@@ -237,7 +236,7 @@ public class BluetoothInCallService extends InCallService {
        @Override
        public void onDetailsChanged(Call call, Call.Details details) {
            super.onDetailsChanged(call, details);
            onDetailsChanged(getBluetoothCallById(call.getDetails().getTelecomCallId()), details);
            onDetailsChanged(getBluetoothCallById(System.identityHashCode(call)), details);
        }

        public void onParentChanged(BluetoothCall call) {
@@ -258,7 +257,7 @@ public class BluetoothInCallService extends InCallService {
        public void onParentChanged(Call call, Call parent) {
            super.onParentChanged(call, parent);
            onParentChanged(
                    getBluetoothCallById(call.getDetails().getTelecomCallId()));
                    getBluetoothCallById(System.identityHashCode(call)));
        }

        public void onChildrenChanged(BluetoothCall call, List<BluetoothCall> children) {
@@ -281,7 +280,7 @@ public class BluetoothInCallService extends InCallService {
        public void onChildrenChanged(Call call, List<Call> children) {
            super.onChildrenChanged(call, children);
            onChildrenChanged(
                    getBluetoothCallById(call.getDetails().getTelecomCallId()),
                    getBluetoothCallById(System.identityHashCode(call)),
                    getBluetoothCallsByIds(BluetoothCall.getIds(children)));
        }
    }
@@ -452,13 +451,13 @@ public class BluetoothInCallService extends InCallService {
        if (call.isExternalCall()) {
            return;
        }
        if (!mBluetoothCallHashMap.containsKey(call.getTelecomCallId())) {
        if (!mBluetoothCallHashMap.containsKey(call.getId())) {
            Log.d(TAG, "onCallAdded");
            CallStateCallback callback = new CallStateCallback(call.getState());
            mCallbacks.put(call.getTelecomCallId(), callback);
            mCallbacks.put(call.getId(), callback);
            call.registerCallback(callback);

            mBluetoothCallHashMap.put(call.getTelecomCallId(), call);
            mBluetoothCallHashMap.put(call.getId(), call);
            updateHeadsetWithCallState(false /* force */);
        }
    }
@@ -507,8 +506,8 @@ public class BluetoothInCallService extends InCallService {
            call.unregisterCallback(callback);
        }

        if (mBluetoothCallHashMap.containsKey(call.getTelecomCallId())) {
            mBluetoothCallHashMap.remove(call.getTelecomCallId());
        if (mBluetoothCallHashMap.containsKey(call.getId())) {
            mBluetoothCallHashMap.remove(call.getId());
        }

        mClccIndexMap.remove(call);
@@ -518,7 +517,7 @@ public class BluetoothInCallService extends InCallService {
    @Override
    public void onCallRemoved(Call call) {
        super.onCallRemoved(call);
        BluetoothCall bluetoothCall = getBluetoothCallById(call.getDetails().getTelecomCallId());
        BluetoothCall bluetoothCall = getBluetoothCallById(System.identityHashCode(call));
        if (bluetoothCall == null) {
            Log.w(TAG, "onCallRemoved, BluetoothCall is removed before registered");
            return;
@@ -833,11 +832,11 @@ public class BluetoothInCallService extends InCallService {
                numHeldCalls = 1;  // Merge is available, so expose via numHeldCalls.
            }

            for (String id : activeCall.getChildrenIds()) {
            for (int id : activeCall.getChildrenIds()) {
                // Held BluetoothCall has changed due to it being combined into a CDMA conference.
                // Keep track of this and ignore any future update since it doesn't really count
                // as a BluetoothCall change.
                if (mOldHeldCall != null && mOldHeldCall.getTelecomCallId() == id) {
                if (mOldHeldCall != null && mOldHeldCall.getId() == id) {
                    ignoreHeldCallChange = true;
                    break;
                }
@@ -970,7 +969,7 @@ public class BluetoothInCallService extends InCallService {

    @VisibleForTesting
    public CallStateCallback getCallback(BluetoothCall call) {
        return mCallbacks.get(call.getTelecomCallId());
        return mCallbacks.get(call.getId());
    }

    @VisibleForTesting
@@ -979,7 +978,7 @@ public class BluetoothInCallService extends InCallService {
    }

    @VisibleForTesting
    public BluetoothCall getBluetoothCallById(String id) {
    public BluetoothCall getBluetoothCallById(int id) {
        if (mBluetoothCallHashMap.containsKey(id)) {
            return mBluetoothCallHashMap.get(id);
        }
@@ -987,9 +986,9 @@ public class BluetoothInCallService extends InCallService {
    }

    @VisibleForTesting
    public List<BluetoothCall> getBluetoothCallsByIds(List<String> ids) {
    public List<BluetoothCall> getBluetoothCallsByIds(List<Integer> ids) {
        List<BluetoothCall> calls = new ArrayList<>();
        for (String id : ids) {
        for (int id : ids) {
            BluetoothCall call = getBluetoothCallById(id);
            if (!mCallInfo.isNullCall(call)) {
                calls.add(call);
+38 −39
Original line number Diff line number Diff line
@@ -16,21 +16,11 @@

package com.android.bluetooth.telephony;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import android.bluetooth.BluetoothAdapter;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
@@ -47,12 +37,21 @@ import android.telephony.TelephonyManager;
import android.util.Log;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.rule.ServiceTestRule;
import androidx.test.filters.MediumTest;
import androidx.test.rule.ServiceTestRule;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.hfp.BluetoothHeadsetProxy;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -308,15 +307,15 @@ public class BluetoothInCallServiceTest {
        addCallCapability(parentCall, Connection.CAPABILITY_MERGE_CONFERENCE);
        addCallCapability(parentCall, Connection.CAPABILITY_SWAP_CONFERENCE);
        removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
        String confCall1Id = confCall1.getTelecomCallId();
        int confCall1Id = confCall1.getId();
        when(parentCall.getGenericConferenceActiveChildCallId())
                .thenReturn(confCall1Id);
        when(parentCall.isConference()).thenReturn(true);
        List<String> childrenIds = Arrays.asList(confCall1.getTelecomCallId(),
                confCall2.getTelecomCallId());
        List<Integer> childrenIds = Arrays.asList(confCall1.getId(),
                confCall2.getId());
        when(parentCall.getChildrenIds()).thenReturn(childrenIds);
        //Add links from child calls to parent
        String parentId = parentCall.getTelecomCallId();
        int parentId = parentCall.getId();
        when(confCall1.getParentId()).thenReturn(parentId);
        when(confCall2.getParentId()).thenReturn(parentId);

@@ -370,14 +369,14 @@ public class BluetoothInCallServiceTest {
        addCallCapability(parentCall, Connection.CAPABILITY_SWAP_CONFERENCE);
        removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);

        String foregroundCallId = foregroundCall.getTelecomCallId();
        int foregroundCallId = foregroundCall.getId();
        when(parentCall.getGenericConferenceActiveChildCallId()).thenReturn(foregroundCallId);
        when(parentCall.isConference()).thenReturn(true);
        List<String> childrenIds = Arrays.asList(foregroundCall.getTelecomCallId(),
                heldCall.getTelecomCallId());
        List<Integer> childrenIds = Arrays.asList(foregroundCall.getId(),
                heldCall.getId());
        when(parentCall.getChildrenIds()).thenReturn(childrenIds);
        //Add links from child calls to parent
        String parentId = parentCall.getTelecomCallId();
        int parentId = parentCall.getId();
        when(foregroundCall.getParentId()).thenReturn(parentId);
        when(heldCall.getParentId()).thenReturn(parentId);

@@ -419,11 +418,11 @@ public class BluetoothInCallServiceTest {
        when(parentCall.wasConferencePreviouslyMerged()).thenReturn(true);
        //when(parentCall.getConferenceLevelActiveCall()).thenReturn(confCall1);
        when(parentCall.isConference()).thenReturn(true);
        List<String> childrenIds = Arrays.asList(confCall1.getTelecomCallId(),
            confCall2.getTelecomCallId());
        List<Integer> childrenIds = Arrays.asList(confCall1.getId(),
                confCall2.getId());
        when(parentCall.getChildrenIds()).thenReturn(childrenIds);
        //Add links from child calls to parent
        String parentId = parentCall.getTelecomCallId();
        int parentId = parentCall.getId();
        when(confCall1.getParentId()).thenReturn(parentId);
        when(confCall2.getParentId()).thenReturn(parentId);

@@ -635,7 +634,7 @@ public class BluetoothInCallServiceTest {
        mBluetoothInCallService.onCallAdded(childCall2);

        addCallCapability(parentCall, Connection.CAPABILITY_MANAGE_CONFERENCE);
        String parentId = parentCall.getTelecomCallId();
        int parentId = parentCall.getId();
        when(childCall1.getParentId()).thenReturn(parentId);
        when(childCall2.getParentId()).thenReturn(parentId);

@@ -681,8 +680,8 @@ public class BluetoothInCallServiceTest {
        removeCallCapability(parentConfCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
        when(parentConfCall.wasConferencePreviouslyMerged()).thenReturn(true);
        when(parentConfCall.isConference()).thenReturn(true);
        List<String> childrenIds = Arrays.asList(confCall1.getTelecomCallId(),
                confCall2.getTelecomCallId());
        List<Integer> childrenIds = Arrays.asList(confCall1.getId(),
                confCall2.getId());
        when(parentConfCall.getChildrenIds()).thenReturn(childrenIds);

        clearInvocations(mMockBluetoothHeadset);
@@ -788,8 +787,8 @@ public class BluetoothInCallServiceTest {
        BluetoothCall activeCall = createActiveCall();
        removeCallCapability(activeCall, Connection.CAPABILITY_MERGE_CONFERENCE);
        BluetoothCall conferenceableCall = getMockCall();
        ArrayList<String> conferenceableCalls = new ArrayList<>();
        conferenceableCalls.add(conferenceableCall.getTelecomCallId());
        ArrayList<Integer> conferenceableCalls = new ArrayList<>();
        conferenceableCalls.add(conferenceableCall.getId());
        mBluetoothInCallService.onCallAdded(conferenceableCall);

        when(activeCall.getConferenceableCalls()).thenReturn(conferenceableCalls);
@@ -811,8 +810,8 @@ public class BluetoothInCallServiceTest {
        removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
        when(parentCall.isConference()).thenReturn(true);
        when(parentCall.wasConferencePreviouslyMerged()).thenReturn(false);
        List<String> childrenIds = Arrays.asList(foregroundCall.getTelecomCallId(),
                heldCall.getTelecomCallId());
        List<Integer> childrenIds = Arrays.asList(foregroundCall.getId(),
                heldCall.getId());
        when(parentCall.getChildrenIds()).thenReturn(childrenIds);

        clearInvocations(mMockBluetoothHeadset);
@@ -858,8 +857,8 @@ public class BluetoothInCallServiceTest {
        addCallCapability(parentCall, Connection.CAPABILITY_MERGE_CONFERENCE);
        removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
        when(parentCall.isConference()).thenReturn(true);
        List<String> childrenIds = Arrays.asList(foregroundCall.getTelecomCallId(),
                heldCall.getTelecomCallId());
        List<Integer> childrenIds = Arrays.asList(foregroundCall.getId(),
                heldCall.getId());
        when(parentCall.getChildrenIds()).thenReturn(childrenIds);

        mBluetoothInCallService.onCallAdded(parentCall);
@@ -960,9 +959,9 @@ public class BluetoothInCallServiceTest {
        BluetoothInCallService.CallStateCallback callback =
                mBluetoothInCallService.new CallStateCallback(Call.STATE_CONNECTING);
        mBluetoothInCallService.mCallbacks.put(
                activeCall.getTelecomCallId(), callback);
                activeCall.getId(), callback);

        mBluetoothInCallService.mCallbacks.get(activeCall.getTelecomCallId())
        mBluetoothInCallService.mCallbacks.get(activeCall.getId())
                .onStateChanged(activeCall, Call.STATE_DIALING);

        verify(mMockBluetoothHeadset, never()).phoneStateChanged(anyInt(), anyInt(), anyInt(),
@@ -1039,12 +1038,12 @@ public class BluetoothInCallServiceTest {
        mBluetoothInCallService.onCallAdded(parentCall);
        mBluetoothInCallService.onCallAdded(activeCall);
        mBluetoothInCallService.onCallAdded(heldCall);
        String parentId = parentCall.getTelecomCallId();
        int parentId = parentCall.getId();
        when(activeCall.getParentId()).thenReturn(parentId);
        when(heldCall.getParentId()).thenReturn(parentId);

        ArrayList<String> calls = new ArrayList<>();
        calls.add(activeCall.getTelecomCallId());
        ArrayList<Integer> calls = new ArrayList<>();
        calls.add(activeCall.getId());

        when(parentCall.getChildrenIds()).thenReturn(calls);
        when(parentCall.isConference()).thenReturn(true);
@@ -1071,7 +1070,7 @@ public class BluetoothInCallServiceTest {
        verify(mMockBluetoothHeadset, never()).phoneStateChanged(anyInt(), anyInt(), anyInt(),
                anyString(), anyInt(), nullable(String.class));

        calls.add(heldCall.getTelecomCallId());
        calls.add(heldCall.getId());
        mBluetoothInCallService.onCallAdded(heldCall);
        mBluetoothInCallService.getCallback(parentCall)
                .onChildrenChanged(
@@ -1169,8 +1168,8 @@ public class BluetoothInCallServiceTest {

    private BluetoothCall getMockCall() {
        BluetoothCall call = mock(com.android.bluetooth.telephony.BluetoothCall.class);
        String uuid = UUID.randomUUID().toString();
        when(call.getTelecomCallId()).thenReturn(uuid);
        int uuid = UUID.randomUUID().hashCode();
        when(call.getId()).thenReturn(uuid);
        return call;
    }
}