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

Commit 6b8a2726 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Call audio routing performance improvment

Move the call audio routing handler to the main looper instead of a
handler thread to improve performance with handling messages from the
message queue. From manual verification, I'm seeing roughly a 4x
improvement in time taken for messages to be processed.

Bug: 383466267
Flag: com.android.server.telecom.flags.call_audio_routing_performance_improvemenent
Test: Manual test verification with comparing how long it takes for
route controller to process active focus with and without change (4x
improvment)
Test: atest TelecomUnitTests

Change-Id: If3edb28af5709c4797d46fe9908364a22d8ae61c
parent 321a6ac4
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -195,3 +195,14 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

# OWNER=pmadapurmath TARGET=25Q3
flag {
  name: "call_audio_routing_performance_improvemenent"
  namespace: "telecom"
  description: "Change the handler to use the main looper to improve performance with processing messages from the message queue"
  bug: "383466267"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+8 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.media.IAudioService;
import android.media.audiopolicy.AudioProductStrategy;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.telecom.CallAudioState;
@@ -213,7 +214,9 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {

        mTelecomLock = callsManager.getLock();
        HandlerThread handlerThread = new HandlerThread(this.getClass().getSimpleName());
        if (!mFeatureFlags.callAudioRoutingPerformanceImprovemenent()) {
            handlerThread.start();
        }

        // Register broadcast receivers
        if (!mFeatureFlags.newAudioPathSpeakerBroadcastAndUnfocusedRouting()) {
@@ -253,8 +256,11 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
            }
        };

        Looper looper = mFeatureFlags.callAudioRoutingPerformanceImprovemenent()
                ? Looper.getMainLooper()
                : handlerThread.getLooper();
        // Create handler
        mHandler = new Handler(handlerThread.getLooper()) {
        mHandler = new Handler(looper) {
            @Override
            public void handleMessage(@NonNull Message msg) {
                synchronized (this) {
+7 −2
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.IAudioService;
import android.media.audiopolicy.AudioProductStrategy;
import android.os.Looper;
import android.os.UserHandle;
import android.telecom.CallAudioState;
import android.telecom.VideoProfile;
@@ -216,13 +217,17 @@ public class CallAudioRouteControllerTest extends TelecomTestCase {
        when(mFeatureFlags.resolveActiveBtRoutingAndBtTimingIssue()).thenReturn(false);
        when(mFeatureFlags.newAudioPathSpeakerBroadcastAndUnfocusedRouting()).thenReturn(false);
        when(mFeatureFlags.fixUserRequestBaselineRouteVideoCall()).thenReturn(false);
        when(mFeatureFlags.callAudioRoutingPerformanceImprovemenent()).thenReturn(true);
        BLUETOOTH_DEVICES.add(BLUETOOTH_DEVICE_1);
    }

    @After
    public void tearDown() throws Exception {
        Looper looper = mController.getAdapterHandler().getLooper();
        if (looper != Looper.getMainLooper()) {
            mController.getAdapterHandler().getLooper().quit();
            mController.getAdapterHandler().getLooper().getThread().join();
        }
        BLUETOOTH_DEVICES.clear();
        super.tearDown();
    }