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

Commit c5d22841 authored by Sindhu's avatar Sindhu
Browse files

Fix: ISliceManager.getPinnedSpecs::server blocked on the main thread during ufold

Bug: 322745650
Test: Manual test
Flag: NA

Change-Id: I3b765e92139f736a3c7dcb4acf776d62be5659fb
parent 0313890f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -430,6 +430,16 @@ flag {
   }
}

flag {
    name: "slice_manager_binder_call_background"
    namespace: "systemui"
    description: "Move the ISliceManager#getPinnedSpecs binder call to the background thread."
    bug: "322745650"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
   name: "register_new_wallet_card_in_background"
   namespace: "systemui"
+34 −14
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.slice.Slice.HINT_LIST_ITEM;

import android.app.PendingIntent;
import android.net.Uri;
import android.os.Handler;
import android.os.Trace;
import android.provider.Settings;
import android.util.Log;
@@ -39,6 +40,9 @@ import androidx.slice.widget.SliceLiveData;

import com.android.keyguard.dagger.KeyguardStatusViewScope;
import com.android.systemui.Dumpable;
import com.android.systemui.Flags;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.KeyguardSliceProvider;
import com.android.systemui.plugins.ActivityStarter;
@@ -60,6 +64,8 @@ public class KeyguardSliceViewController extends ViewController<KeyguardSliceVie
        Dumpable {
    private static final String TAG = "KeyguardSliceViewCtrl";

    private final Handler mHandler;
    private final Handler mBgHandler;
    private final ActivityStarter mActivityStarter;
    private final ConfigurationController mConfigurationController;
    private final TunerService mTunerService;
@@ -105,6 +111,8 @@ public class KeyguardSliceViewController extends ViewController<KeyguardSliceVie

    @Inject
    public KeyguardSliceViewController(
            @Main Handler handler,
            @Background Handler bgHandler,
            KeyguardSliceView keyguardSliceView,
            ActivityStarter activityStarter,
            ConfigurationController configurationController,
@@ -112,6 +120,8 @@ public class KeyguardSliceViewController extends ViewController<KeyguardSliceVie
            DumpManager dumpManager,
            DisplayTracker displayTracker) {
        super(keyguardSliceView);
        mHandler = handler;
        mBgHandler = bgHandler;
        mActivityStarter = activityStarter;
        mConfigurationController = configurationController;
        mTunerService = tunerService;
@@ -182,13 +192,20 @@ public class KeyguardSliceViewController extends ViewController<KeyguardSliceVie
     * Update contents of the view.
     */
    public void refresh() {
        Slice slice;

        Trace.beginSection("KeyguardSliceViewController#refresh");
        // We can optimize performance and avoid binder calls when we know that we're bound
        // to a Slice on the same process.
        try {
            Slice slice;
            if (KeyguardSliceProvider.KEYGUARD_SLICE_URI.equals(mKeyguardSliceUri.toString())) {
                KeyguardSliceProvider instance = KeyguardSliceProvider.getAttachedInstance();
                if (instance != null) {
                    if (Flags.sliceManagerBinderCallBackground()) {
                        mBgHandler.post(() -> {
                            Slice _slice = instance.onBindSlice(mKeyguardSliceUri);
                            mHandler.post(() -> mObserver.onChanged(_slice));
                        });
                        return;
                    }
                    slice = instance.onBindSlice(mKeyguardSliceUri);
                } else {
                    Log.w(TAG, "Keyguard slice not bound yet?");
@@ -196,11 +213,14 @@ public class KeyguardSliceViewController extends ViewController<KeyguardSliceVie
                }
            } else {
                // TODO: Make SliceViewManager injectable
            slice = SliceViewManager.getInstance(mView.getContext()).bindSlice(mKeyguardSliceUri);
                slice = SliceViewManager.getInstance(mView.getContext()).bindSlice(
                        mKeyguardSliceUri);
            }
            mObserver.onChanged(slice);
        } finally {
            Trace.endSection();
        }
    }

    void showSlice(Slice slice) {
        Trace.beginSection("KeyguardSliceViewController#showSlice");
+11 −4
Original line number Diff line number Diff line
@@ -22,8 +22,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.pm.PackageManager;
import android.os.Handler;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.View;

@@ -57,17 +59,22 @@ public class KeyguardSliceViewControllerTest extends SysuiTestCase {
    private ActivityStarter mActivityStarter;
    private FakeDisplayTracker mDisplayTracker = new FakeDisplayTracker(mContext);
    private DumpManager mDumpManager = new DumpManager();

    private Handler mHandler;
    private Handler mBgHandler;
    private KeyguardSliceViewController mController;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        TestableLooper testableLooper = TestableLooper.get(this);
        assert testableLooper != null;
        mHandler = new Handler(testableLooper.getLooper());
        mBgHandler = new Handler(testableLooper.getLooper());
        when(mView.isAttachedToWindow()).thenReturn(true);
        when(mView.getContext()).thenReturn(mContext);
        mController = new KeyguardSliceViewController(
                mView, mActivityStarter, mConfigurationController,
                mTunerService, mDumpManager, mDisplayTracker);
        mController = new KeyguardSliceViewController(mHandler, mBgHandler, mView,
                mActivityStarter, mConfigurationController, mTunerService, mDumpManager,
                mDisplayTracker);
        mController.setupUri(KeyguardSliceProvider.KEYGUARD_SLICE_URI);
    }