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

Commit b5cd064a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Removing UiThreadHelper and moving code to corresponding classes" into...

Merge "Removing UiThreadHelper and moving code to corresponding classes" into tm-qpr-dev am: 22af7c2e am: 93d74aa4

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/19931705



Change-Id: I39c565b0ea40b4e1c1ed2b3b908837e04817ce64
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7ec80322 93d74aa4
Loading
Loading
Loading
Loading
+1 −9
Original line number Original line Diff line number Diff line
@@ -117,8 +117,6 @@ import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
import com.android.launcher3.util.TouchController;
import com.android.launcher3.util.TouchController;
import com.android.launcher3.util.UiThreadHelper;
import com.android.launcher3.util.UiThreadHelper.AsyncCommand;
import com.android.launcher3.util.ViewCapture;
import com.android.launcher3.util.ViewCapture;
import com.android.launcher3.widget.LauncherAppWidgetHost;
import com.android.launcher3.widget.LauncherAppWidgetHost;
import com.android.quickstep.OverviewCommandHelper;
import com.android.quickstep.OverviewCommandHelper;
@@ -160,11 +158,6 @@ public class QuickstepLauncher extends Launcher {
            SystemProperties.getBoolean("persist.wm.debug.enable_pip_keep_clear_algorithm", false);
            SystemProperties.getBoolean("persist.wm.debug.enable_pip_keep_clear_algorithm", false);


    public static final boolean GO_LOW_RAM_RECENTS_ENABLED = false;
    public static final boolean GO_LOW_RAM_RECENTS_ENABLED = false;
    /**
     * Reusable command for applying the shelf height on the background thread.
     */
    public static final AsyncCommand SET_SHELF_HEIGHT = (context, arg1, arg2) ->
            SystemUiProxy.INSTANCE.get(context).setShelfHeight(arg1 != 0, arg2);


    private FixedContainerItems mAllAppsPredictions;
    private FixedContainerItems mAllAppsPredictions;
    private HotseatPredictionController mHotseatPredictionController;
    private HotseatPredictionController mHotseatPredictionController;
@@ -349,8 +342,7 @@ public class QuickstepLauncher extends Launcher {
                boolean visible = (state == NORMAL || state == OVERVIEW)
                boolean visible = (state == NORMAL || state == OVERVIEW)
                        && (willUserBeActive || isUserActive())
                        && (willUserBeActive || isUserActive())
                        && !profile.isVerticalBarLayout();
                        && !profile.isVerticalBarLayout();
                UiThreadHelper.runAsyncCommand(this, SET_SHELF_HEIGHT, visible ? 1 : 0,
                SystemUiProxy.INSTANCE.get(this).setShelfHeight(visible, profile.hotseatBarSizePx);
                        profile.hotseatBarSizePx);
            }
            }
        }
        }
        if (state == NORMAL && !inTransition) {
        if (state == NORMAL && !inTransition) {
+31 −3
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.quickstep;
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;


import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;


import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.PendingIntent;
import android.app.PendingIntent;
@@ -31,8 +32,10 @@ import android.content.pm.ShortcutInfo;
import android.graphics.Insets;
import android.graphics.Insets;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
import android.os.IBinder.DeathRecipient;
import android.os.Message;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;
@@ -42,6 +45,8 @@ import android.view.RemoteAnimationTarget;
import android.view.SurfaceControl;
import android.view.SurfaceControl;
import android.window.IOnBackInvokedCallback;
import android.window.IOnBackInvokedCallback;


import androidx.annotation.WorkerThread;

import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.recents.ISystemUiProxy;
@@ -75,6 +80,8 @@ public class SystemUiProxy implements ISystemUiProxy {
    public static final MainThreadInitializedObject<SystemUiProxy> INSTANCE =
    public static final MainThreadInitializedObject<SystemUiProxy> INSTANCE =
            new MainThreadInitializedObject<>(SystemUiProxy::new);
            new MainThreadInitializedObject<>(SystemUiProxy::new);


    private static final int MSG_SET_SHELF_HEIGHT = 1;

    private ISystemUiProxy mSystemUiProxy;
    private ISystemUiProxy mSystemUiProxy;
    private IPip mPip;
    private IPip mPip;
    private ISysuiUnlockAnimationController mSysuiUnlockAnimationController;
    private ISysuiUnlockAnimationController mSysuiUnlockAnimationController;
@@ -104,13 +111,16 @@ public class SystemUiProxy implements ISystemUiProxy {
    // Used to dedupe calls to SystemUI
    // Used to dedupe calls to SystemUI
    private int mLastShelfHeight;
    private int mLastShelfHeight;
    private boolean mLastShelfVisible;
    private boolean mLastShelfVisible;
    private Context mContext;

    private final Context mContext;
    private final Handler mAsyncHandler;


    // TODO(141886704): Find a way to remove this
    // TODO(141886704): Find a way to remove this
    private int mLastSystemUiStateFlags;
    private int mLastSystemUiStateFlags;


    public SystemUiProxy(Context context) {
    public SystemUiProxy(Context context) {
        mContext = context;
        mContext = context;
        mAsyncHandler = new Handler(UI_HELPER_EXECUTOR.getLooper(), this::handleMessageAsync);
    }
    }


    @Override
    @Override
@@ -437,12 +447,20 @@ public class SystemUiProxy implements ISystemUiProxy {
     * Sets the shelf height.
     * Sets the shelf height.
     */
     */
    public void setShelfHeight(boolean visible, int shelfHeight) {
    public void setShelfHeight(boolean visible, int shelfHeight) {
        Message.obtain(mAsyncHandler, MSG_SET_SHELF_HEIGHT,
                visible ? 1 : 0 , shelfHeight).sendToTarget();
    }

    @WorkerThread
    private void setShelfHeightAsync(int visibleInt, int shelfHeight) {
        boolean visible = visibleInt != 0;
        boolean changed = visible != mLastShelfVisible || shelfHeight != mLastShelfHeight;
        boolean changed = visible != mLastShelfVisible || shelfHeight != mLastShelfHeight;
        if (mPip != null && changed) {
        IPip pip = mPip;
        if (pip != null && changed) {
            mLastShelfVisible = visible;
            mLastShelfVisible = visible;
            mLastShelfHeight = shelfHeight;
            mLastShelfHeight = shelfHeight;
            try {
            try {
                mPip.setShelfHeight(visible, shelfHeight);
                pip.setShelfHeight(visible, shelfHeight);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.w(TAG, "Failed call setShelfHeight visible: " + visible
                Log.w(TAG, "Failed call setShelfHeight visible: " + visible
                        + " height: " + shelfHeight, e);
                        + " height: " + shelfHeight, e);
@@ -902,4 +920,14 @@ public class SystemUiProxy implements ISystemUiProxy {
        }
        }
        return new ArrayList<>();
        return new ArrayList<>();
    }
    }

    private boolean handleMessageAsync(Message msg) {
        switch (msg.what) {
            case MSG_SET_SHELF_HEIGHT:
                setShelfHeightAsync(msg.arg1, msg.arg2);
                return true;
        }

        return false;
    }
}
}
+12 −4
Original line number Original line Diff line number Diff line
@@ -21,17 +21,19 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;


import static com.android.launcher3.Utilities.dpiFromPx;
import static com.android.launcher3.Utilities.dpiFromPx;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.window.WindowManagerProxy.MIN_TABLET_WIDTH;
import static com.android.launcher3.util.window.WindowManagerProxy.MIN_TABLET_WIDTH;


import android.content.Context;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Handler;
import android.os.Message;


import com.android.launcher3.BaseActivity;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.UiThreadHelper;


/**
/**
 * Utility class to manage launcher rotation
 * Utility class to manage launcher rotation
@@ -39,8 +41,6 @@ import com.android.launcher3.util.UiThreadHelper;
public class RotationHelper implements OnSharedPreferenceChangeListener,
public class RotationHelper implements OnSharedPreferenceChangeListener,
        DisplayController.DisplayInfoChangeListener {
        DisplayController.DisplayInfoChangeListener {


    private static final String TAG = "RotationHelper";

    public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
    public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";


    /**
    /**
@@ -60,6 +60,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,


    private BaseActivity mActivity;
    private BaseActivity mActivity;
    private SharedPreferences mSharedPrefs = null;
    private SharedPreferences mSharedPrefs = null;
    private final Handler mRequestOrientationHandler;


    private boolean mIgnoreAutoRotateSettings;
    private boolean mIgnoreAutoRotateSettings;
    private boolean mForceAllowRotationForTesting;
    private boolean mForceAllowRotationForTesting;
@@ -89,6 +90,8 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,


    public RotationHelper(BaseActivity activity) {
    public RotationHelper(BaseActivity activity) {
        mActivity = activity;
        mActivity = activity;
        mRequestOrientationHandler =
                new Handler(UI_HELPER_EXECUTOR.getLooper(), this::setOrientationAsync);
    }
    }


    private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings) {
    private void setIgnoreAutoRotateSettings(boolean ignoreAutoRotateSettings) {
@@ -202,8 +205,13 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
        }
        }
        if (activityFlags != mLastActivityFlags) {
        if (activityFlags != mLastActivityFlags) {
            mLastActivityFlags = activityFlags;
            mLastActivityFlags = activityFlags;
            UiThreadHelper.setOrientationAsync(mActivity, activityFlags);
            mRequestOrientationHandler.sendEmptyMessage(activityFlags);
        }
    }
    }

    private boolean setOrientationAsync(Message msg) {
        mActivity.setRequestedOrientation(msg.what);
        return true;
    }
    }


    /**
    /**
+0 −71
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3.util;

import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;

/**
 * Utility class for offloading some class from UI thread
 */
public class UiThreadHelper {

    private static final MainThreadInitializedObject<Handler> HANDLER =
            new MainThreadInitializedObject<>(
                    c -> new Handler(UI_HELPER_EXECUTOR.getLooper(), new UiCallbacks(c)));

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

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

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

    private static class UiCallbacks implements Handler.Callback {

        private final Context mContext;

        UiCallbacks(Context context) {
            mContext = context;
        }

        @Override
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case MSG_SET_ORIENTATION:
                    ((Activity) message.obj).setRequestedOrientation(message.arg1);
                    return true;
                case MSG_RUN_COMMAND:
                    ((AsyncCommand) message.obj).execute(mContext, message.arg1, message.arg2);
                    return true;
            }
            return false;
        }
    }

    public interface AsyncCommand {
        void execute(Context proxy, int arg1, int arg2);
    }
}