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

Commit 13fabc31 authored by Jack Yu's avatar Jack Yu
Browse files

Run embbeded subscription update in background thread

Same as the pre-U behavior, update the embedded subscriptions
on background thread.

Bug: 239607619
Test: Manual + atest SubscriptionManagerServiceTest
Change-Id: I819fe44b4eba6c9d4b15d2d42c622a5e78ed3411
parent c65219aa
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -195,10 +195,19 @@ public class SubscriptionManagerService extends ISub.Stub {
    @Nullable
    private EuiccController mEuiccController;

    /** The main handler of subscription manager service. */
    /**
     * The main handler of subscription manager service. This is running on phone process's main
     * thread.
     */
    @NonNull
    private final Handler mHandler;

    /**
     * The background handler. This is running on a separate thread.
     */
    @NonNull
    private final Handler mBackgroundHandler;

    /** Local log for most important debug messages. */
    @NonNull
    private final LocalLog mLocalLog = new LocalLog(128);
@@ -373,6 +382,12 @@ public class SubscriptionManagerService extends ISub.Stub {

        mUiccController = UiccController.getInstance();
        mHandler = new Handler(looper);

        HandlerThread backgroundThread = new HandlerThread(LOG_TAG);
        backgroundThread.start();

        mBackgroundHandler = new Handler(backgroundThread.getLooper());

        TelephonyServiceManager.ServiceRegisterer subscriptionServiceRegisterer =
                TelephonyFrameworkInitializer
                        .getTelephonyServiceManager()
@@ -907,7 +922,8 @@ public class SubscriptionManagerService extends ISub.Stub {
     */
    public void updateEmbeddedSubscriptions(@NonNull List<Integer> cardIds,
            @Nullable Runnable callback) {
        mHandler.post(() -> {
        // Run this on a background thread.
        mBackgroundHandler.post(() -> {
            // Do nothing if eUICCs are disabled. (Previous entries may remain in the cache, but
            // they are filtered out of list calls as long as EuiccManager.isEnabled returns false).
            if (mEuiccManager == null || !mEuiccManager.isEnabled()) {
+1 −1
Original line number Diff line number Diff line
@@ -1141,7 +1141,7 @@ public abstract class TelephonyTest {
     * Remove a TestableLooper from the list of monitored loopers
     * @param looper removed if it does exist
     */
    public void unmonitorTestableLooper(TestableLooper looper) {
    private void unmonitorTestableLooper(TestableLooper looper) {
        if (mTestableLoopers.contains(looper)) {
            mTestableLoopers.remove(looper);
        }
+10 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelUuid;
import android.os.UserHandle;
@@ -148,6 +149,8 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                Telephony.Carriers.CONTENT_URI.getAuthority(), mSubscriptionProvider);
        mSubscriptionManagerServiceUT = new SubscriptionManagerService(mContext, Looper.myLooper());

        monitorTestableLooper(new TestableLooper(getBackgroundHandler().getLooper()));

        doAnswer(invocation -> {
            ((Runnable) invocation.getArguments()[0]).run();
            return null;
@@ -182,6 +185,13 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        super.tearDown();
    }

    private Handler getBackgroundHandler() throws Exception {
        Field field = SubscriptionManagerService.class.getDeclaredField(
                "mBackgroundHandler");
        field.setAccessible(true);
        return (Handler) field.get(mSubscriptionManagerServiceUT);
    }

    /**
     * Insert the subscription info to the database.
     *