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

Commit 4621e9bd authored by Hall Liu's avatar Hall Liu
Browse files

Further fixes to telecom unit tests

Fix unsynchronized access to CS focus manager
Delete phone account cache in unit test setup
Add more wait-for-handler-actions

Test: unit tests
Change-Id: I0ca0fb5a35e97d2b8b0471f0ebafc8e9ece34f10
Merged-In: I0ca0fb5a35e97d2b8b0471f0ebafc8e9ece34f10
parent 546e3e02
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ public class CallerInfoLookupHelper {
            }
        }

        mHandler.post(new Runnable("CILH.sL", mLock) {
        mHandler.post(new Runnable("CILH.sL", null) {
            @Override
            public void loggedRun() {
                Session continuedSession = Log.createSubsession();
@@ -171,7 +171,7 @@ public class CallerInfoLookupHelper {
    }

    private void startPhotoLookup(final Uri handle, final Uri contactPhotoUri) {
        mHandler.post(new Runnable("CILH.sPL", mLock) {
        mHandler.post(new Runnable("CILH.sPL", null) {
            @Override
            public void loggedRun() {
                Session continuedSession = Log.createSubsession();
+31 −2
Original line number Diff line number Diff line
@@ -30,10 +30,15 @@ import com.android.internal.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class ConnectionServiceFocusManager {
    private static final String TAG = "ConnectionSvrFocusMgr";
    private static final int GET_CURRENT_FOCUS_TIMEOUT_MILLIS = 1000;

    /** Factory interface used to create the {@link ConnectionServiceFocusManager} instance. */
    public interface ConnectionServiceFocusManagerFactory {
@@ -298,9 +303,33 @@ public class ConnectionServiceFocusManager {
     * call is the current connection service focus. Also the state of the focus call must be one
     * of {@link #PRIORITY_FOCUS_CALL_STATE}.
     */
    public CallFocus getCurrentFocusCall() {
    public @Nullable CallFocus getCurrentFocusCall() {
        if (mEventHandler.getLooper().isCurrentThread()) {
            // return synchronously if we're on the same thread.
            return mCurrentFocusCall;
        }
        final BlockingQueue<Optional<CallFocus>> currentFocusedCallQueue =
                new LinkedBlockingQueue<>(1);
        mEventHandler.post(() -> {
            currentFocusedCallQueue.offer(
                    mCurrentFocusCall == null ? Optional.empty() : Optional.of(mCurrentFocusCall));
        });
        try {
            Optional<CallFocus> syncCallFocus = currentFocusedCallQueue.poll(
                    GET_CURRENT_FOCUS_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
            if (syncCallFocus != null) {
                return syncCallFocus.orElse(null);
            } else {
                Log.w(TAG, "Timed out waiting for synchronous current focus. Returning possibly"
                        + " inaccurate result");
                return mCurrentFocusCall;
            }
        } catch (InterruptedException e) {
            Log.w(TAG, "Interrupted when waiting for synchronous current focus."
                    + " Returning possibly inaccurate result.");
            return mCurrentFocusCall;
        }
    }

    /** Returns the current connection service focus. */
    public ConnectionServiceFocus getCurrentFocusConnectionService() {
+1 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class PhoneAccountRegistrar {
        CharSequence getAppLabel(String packageName);
    }

    private static final String FILE_NAME = "phone-account-registrar-state.xml";
    public static final String FILE_NAME = "phone-account-registrar-state.xml";
    @VisibleForTesting
    public static final int EXPECTED_STATE_VERSION = 9;

+1 −1
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ public class TelecomSystem {
                    }
                });
        BluetoothDeviceManager bluetoothDeviceManager = new BluetoothDeviceManager(mContext,
                new BluetoothAdapterProxy(), mLock);
                new BluetoothAdapterProxy());
        BluetoothRouteManager bluetoothRouteManager = new BluetoothRouteManager(mContext, mLock,
                bluetoothDeviceManager, new Timeouts.Adapter());
        BluetoothStateReceiver bluetoothStateReceiver = new BluetoothStateReceiver(
+4 −4
Original line number Diff line number Diff line
@@ -82,14 +82,14 @@ public class BluetoothDeviceManager {

    private final LinkedHashMap<String, BluetoothDevice> mConnectedDevicesByAddress =
            new LinkedHashMap<>();
    private final TelecomSystem.SyncRoot mLock;

    // This lock only protects internal state -- it doesn't lock on anything going into Telecom.
    private final Object mLock = new Object();

    private BluetoothRouteManager mBluetoothRouteManager;
    private BluetoothHeadsetProxy mBluetoothHeadsetService;

    public BluetoothDeviceManager(Context context, BluetoothAdapterProxy bluetoothAdapter,
            TelecomSystem.SyncRoot lock) {
        mLock = lock;
    public BluetoothDeviceManager(Context context, BluetoothAdapterProxy bluetoothAdapter) {

        if (bluetoothAdapter != null) {
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
Loading