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

Commit ceb9a695 authored by Nathan Harold's avatar Nathan Harold
Browse files

Move Work Back to Individual Threads

As part of an effort to remove a variety of threads,
a few very sluggish operations have been identified that
would block a shared worker thread for multiple seconds,
in particular binding to an ImsService and doing a full
query of the LPA status.

As a temporary measure, move these operations back onto
bespoke worker threads as part of the ongoing evaluation
of how we can safely reduce the thread count in telephony.

In addition, there is a 5-way deadlock that occurs when
the ImsResolver is on the WorkerThread. While this is possible
anyway, it is much rarer without the blocking on this thread.
(ref b/398985346 and ref b/393048045).

Bug: 390244513
Test: atest FrameworksTelephonyTests
Flag: com.android.internal.telephony.flags.thread_shred
Change-Id: I84ef38269936968492c43c11c6e7b4077cba3228
parent 0161cf4e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -140,6 +140,8 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
    // Delay between dynamic ImsService queries.
    private static final int DELAY_DYNAMIC_QUERY_MS = 5000;

    // Compile-time debug flag for controlling worker thread behavior
    private static final boolean USE_WORKER_THREAD = false;
    private static HandlerThread sHandlerThread;

    private static ImsResolver sInstance;
@@ -151,7 +153,7 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
            String defaultRcsPackageName, int numSlots, ImsFeatureBinderRepository repo,
            FeatureFlags featureFlags) {
        if (sInstance == null) {
            if (featureFlags.threadShred()) {
            if (featureFlags.threadShred() && USE_WORKER_THREAD) {
                sInstance = new ImsResolver(context, defaultMmTelPackageName, defaultRcsPackageName,
                        numSlots, repo, WorkerThread.get().getLooper(), featureFlags);
            } else {
+5 −1
Original line number Diff line number Diff line
@@ -266,7 +266,11 @@ public class ImsServiceController {
    // Enable ImsServiceControllerTest and SipDelegateManagerTest cases if this is re-enabled.
    private static final boolean ENFORCE_SINGLE_SERVICE_FOR_SIP_TRANSPORT = false;
    private final ComponentName mComponentName;

    // Compile-time debug flag for controlling worker thread behavior
    private static final boolean USE_WORKER_THREAD = false;
    private final HandlerThread mHandlerThread;

    private final Handler mHandler;
    private final LegacyPermissionManager mPermissionManager;
    private final FeatureFlags mFeatureFlags;
@@ -365,7 +369,7 @@ public class ImsServiceController {
        mComponentName = componentName;
        mCallbacks = callbacks;
        Looper looper;
        if (featureFlags.threadShred()) {
        if (featureFlags.threadShred() && USE_WORKER_THREAD) {
            mHandlerThread = null;
            mHandler = new Handler(WorkerThread.get().getLooper());
            looper = WorkerThread.get().getLooper();
+7 −1
Original line number Diff line number Diff line
@@ -159,6 +159,12 @@ public class SubscriptionManagerService extends ISub.Stub {
    private static final int CHECK_BOOTSTRAP_TIMER_IN_MS = 20 * 60 * 1000; // 20 minutes
    private static CountDownTimer bootstrapProvisioningTimer;

    /** Whether enabling verbose debugging message or not. */
    private static final boolean VDBG = false;

    // Compile-time debug flag for controlling worker thread behavior
    private static final boolean USE_WORKER_THREAD = false;

    /**
     * The columns in {@link SimInfo} table that can be directly accessed through
     * {@link #getSubscriptionProperty(int, String, String, String)} or
@@ -572,7 +578,7 @@ public class SubscriptionManagerService extends ISub.Stub {

        Looper dbLooper = null;

        if (mFeatureFlags.threadShred()) {
        if (mFeatureFlags.threadShred() && SubscriptionManagerService.USE_WORKER_THREAD) {
            dbLooper = WorkerThread.get().getLooper();
        } else {
            // Create a separate thread for subscription database manager.