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

Commit d6d50382 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Moving some system calls off the main thread

Bug: 122345781
Change-Id: I7ab364ac62ea56b7355b86cae3d8d731cc9b2506
parent ea3ff5e3
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.TouchController;
import com.android.launcher3.util.UiThreadHelper;
import com.android.launcher3.util.UiThreadHelper.AsyncCommand;
import com.android.quickstep.OverviewInteractionState;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.util.RemoteFadeOutAnimationListener;
@@ -58,6 +60,9 @@ import java.util.zip.Deflater;

public class UiFactory {

    private static final AsyncCommand SET_SHELF_HEIGHT_CMD = (visible, height) ->
            WindowManagerWrapper.getInstance().setShelfHeight(visible != 0, height);

    public static TouchController[] createTouchControllers(Launcher launcher) {
        boolean swipeUpEnabled = OverviewInteractionState.INSTANCE.get(launcher)
                .isSwipeUpGestureEnabled();
@@ -175,10 +180,10 @@ public class UiFactory {
        LauncherState state = launcher.getStateManager().getState();
        if (!OverviewInteractionState.INSTANCE.get(launcher).swipeGestureInitializing()) {
            DeviceProfile profile = launcher.getDeviceProfile();
            WindowManagerWrapper.getInstance().setShelfHeight(
                    (state == NORMAL || state == OVERVIEW) && launcher.isUserActive()
                            && !profile.isVerticalBarLayout(),
                    profile.hotseatBarSizePx);
            boolean visible = (state == NORMAL || state == OVERVIEW) && launcher.isUserActive()
                    && !profile.isVerticalBarLayout();
            UiThreadHelper.runAsyncCommand(launcher, SET_SHELF_HEIGHT_CMD,
                    visible ? 1 : 0, profile.hotseatBarSizePx);
        }

        if (state == NORMAL) {
+2 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.res.Resources;

import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.UiThreadHelper;

/**
 * Utility class to manage launcher rotation
@@ -154,7 +155,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
        }
        if (activityFlags != mLastActivityFlags) {
            mLastActivityFlags = activityFlags;
            mActivity.setRequestedOrientation(activityFlags);
            UiThreadHelper.setOrientationAsync(mActivity, activityFlags);
        }
    }

+23 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.util;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
@@ -33,6 +34,8 @@ public class UiThreadHelper {
    private static Handler sHandler;

    private static final int MSG_HIDE_KEYBOARD = 1;
    private static final int MSG_SET_ORIENTATION = 2;
    private static final int MSG_RUN_COMMAND = 3;

    public static Looper getBackgroundLooper() {
        if (sHandlerThread == null) {
@@ -55,6 +58,15 @@ public class UiThreadHelper {
        Message.obtain(getHandler(context), MSG_HIDE_KEYBOARD, token).sendToTarget();
    }

    public static void setOrientationAsync(Activity activity, int orientation) {
        Message.obtain(getHandler(activity), MSG_SET_ORIENTATION, orientation, 0, activity)
                .sendToTarget();
    }

    public static void runAsyncCommand(Context context, AsyncCommand command, int arg1, int arg2) {
        Message.obtain(getHandler(context), MSG_RUN_COMMAND, arg1, arg2, command).sendToTarget();
    }

    private static class UiCallbacks implements Handler.Callback {

        private final InputMethodManager mIMM;
@@ -69,8 +81,19 @@ public class UiThreadHelper {
                case MSG_HIDE_KEYBOARD:
                    mIMM.hideSoftInputFromWindow((IBinder) message.obj, 0);
                    return true;
                case MSG_SET_ORIENTATION:
                    ((Activity) message.obj).setRequestedOrientation(message.arg1);
                    return true;
                case MSG_RUN_COMMAND:
                    ((AsyncCommand) message.obj).execute(message.arg1, message.arg2);
                    return true;
            }
            return false;
        }
    }

    public interface AsyncCommand {

        void execute(int arg1, int arg2);
    }
}