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

Commit d8485a0f authored by Fengjiang Li's avatar Fengjiang Li
Browse files

[Launcher Jank] Let RotationButtonController call IWindowManager binder call...

[Launcher Jank] Let RotationButtonController call IWindowManager binder call on ordered background thread

Bug: 338036218
Test: presubmit
Flag: NONE
Change-Id: I3f4471f36b2060405e1c434805e140329332b18b
parent e52a4ae5
Loading
Loading
Loading
Loading
+24 −23
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import com.android.systemui.shared.system.TaskStackChangeListeners;
import java.io.PrintWriter;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Supplier;

/**
@@ -198,6 +199,10 @@ public class RotationButtonController {
        return mContext;
    }

    /**
     * We should pass single threaded executor (rather than {@link ThreadPoolExecutor}) as we will
     * make binder calls on that executor and ordering is vital.
     */
    public void setBgExecutor(Executor bgExecutor) {
        mBgExecutor = bgExecutor;
    }
@@ -229,24 +234,21 @@ public class RotationButtonController {
        mListenersRegistered = true;

        mBgExecutor.execute(() -> {
            final Intent intent = mContext.registerReceiver(mDockedReceiver,
                    new IntentFilter(Intent.ACTION_DOCK_EVENT));
            mContext.getMainExecutor().execute(() -> updateDockedState(intent));
        });

            if (registerRotationWatcher) {
                try {
                    WindowManagerGlobal.getWindowManagerService()
                            .watchRotation(mRotationWatcher, DEFAULT_DISPLAY);
                    mRotationWatcherRegistered = true;
                } catch (IllegalArgumentException e) {
                mListenersRegistered = false;
                    Log.w(TAG, "RegisterListeners for the display failed", e);
                } catch (RemoteException e) {
                    Log.e(TAG, "RegisterListeners caught a RemoteException", e);
                return;
                }
            }
            final Intent intent = mContext.registerReceiver(mDockedReceiver,
                    new IntentFilter(Intent.ACTION_DOCK_EVENT));
            mContext.getMainExecutor().execute(() -> updateDockedState(intent));
        });

        TaskStackChangeListeners.getInstance().registerTaskStackListener(mTaskStackListener);
    }
@@ -264,7 +266,6 @@ public class RotationButtonController {
            } catch (IllegalArgumentException e) {
                Log.e(TAG, "Docked receiver already unregistered", e);
            }
        });

            if (mRotationWatcherRegistered) {
                try {
@@ -272,9 +273,9 @@ public class RotationButtonController {
                            mRotationWatcher);
                } catch (RemoteException e) {
                    Log.e(TAG, "UnregisterListeners caught a RemoteException", e);
                return;
                }
            }
        });

        TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener);
    }