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

Commit b7c3f048 authored by Atneya Nair's avatar Atneya Nair
Browse files

Move AudioService recv off of main thread

Some of the calls in the AudioService broadcast receiver are expensive,
and posting them to the main thread can lead to slow-down/ANR.
Additionally, there is no need to handle these events on the main
thread.

Move the receiver to a dedicated handler thread. Eventually, this should
be combined with the handler we already have for events.

Test: Smoke test (bt connect)
Fixes: 335457435
Change-Id: Ibc6b95f7bd628a63c565adfa7f5d52cdcda9fb1b
parent 373fd733
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -176,6 +176,7 @@ import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.HwBinder;
import android.os.IBinder;
import android.os.Looper;
@@ -686,6 +687,9 @@ public class AudioService extends IAudioService.Stub
    private static final VibrationAttributes TOUCH_VIBRATION_ATTRIBUTES =
            VibrationAttributes.createForUsage(VibrationAttributes.USAGE_TOUCH);
    // Handler for broadcast receiver
    // TODO(b/335513647) combine handlers
    private final HandlerThread mBroadcastHandlerThread;
    // Broadcast receiver for device connections intent broadcasts
    private final BroadcastReceiver mReceiver = new AudioServiceBroadcastReceiver();
@@ -1121,6 +1125,9 @@ public class AudioService extends IAudioService.Stub
        mAudioPolicy = audioPolicy;
        mPlatformType = AudioSystem.getPlatformType(context);
        mBroadcastHandlerThread = new HandlerThread("AudioService Broadcast");
        mBroadcastHandlerThread.start();
        mDeviceBroker = new AudioDeviceBroker(mContext, this, mAudioSystem);
        mIsSingleVolume = AudioSystem.isSingleVolume(context);
@@ -1507,7 +1514,8 @@ public class AudioService extends IAudioService.Stub
        intentFilter.addAction(ACTION_CHECK_MUSIC_ACTIVE);
        intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, intentFilter, null, null,
        mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, intentFilter, null,
                mBroadcastHandlerThread.getThreadHandler(),
                Context.RECEIVER_EXPORTED);
        SubscriptionManager subscriptionManager = mContext.getSystemService(