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

Commit 95b09f90 authored by Thiru Ramasamy's avatar Thiru Ramasamy
Browse files

Fixes duplicate logging for LAUNCHER_ALLAPPS_KEYBOARD_CLOSED events.

Bug: 178562918
Test: Manual
Change-Id: Id32b621c0f506bba4378f6f6b81d7cfece3cb373
parent 3a37543f
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@@ -42,15 +43,30 @@ public class UiThreadHelper {
    private static final int MSG_HIDE_KEYBOARD = 1;
    private static final int MSG_SET_ORIENTATION = 2;
    private static final int MSG_RUN_COMMAND = 3;
    private static final String STATS_LOGGER_KEY = "STATS_LOGGER_KEY";

    @SuppressLint("NewApi")
    public static void hideKeyboardAsync(ActivityContext activityContext, IBinder token) {
        View root = activityContext.getDragLayer();

        Message.obtain(HANDLER.get(root.getContext()),
                MSG_HIDE_KEYBOARD, token).sendToTarget();
        Launcher.cast(activityContext).getStatsLogManager().logger().log(
                LAUNCHER_ALLAPPS_KEYBOARD_CLOSED);
        // Since the launcher context cannot be accessed directly from callback, adding secondary
        // message to log keyboard close event asynchronously.
        Bundle mHideKeyboardLoggerMsg = new Bundle();
        mHideKeyboardLoggerMsg.putParcelable(
                STATS_LOGGER_KEY,
                Message.obtain(
                        HANDLER.get(root.getContext()),
                        () -> Launcher.cast(activityContext)
                                .getStatsLogManager()
                                .logger()
                                .log(LAUNCHER_ALLAPPS_KEYBOARD_CLOSED)
                )
        );

        Message mHideKeyboardMsg = Message.obtain(HANDLER.get(root.getContext()), MSG_HIDE_KEYBOARD,
                token);
        mHideKeyboardMsg.setData(mHideKeyboardLoggerMsg);
        mHideKeyboardMsg.sendToTarget();
    }

    public static void setOrientationAsync(Activity activity, int orientation) {
@@ -81,7 +97,11 @@ public class UiThreadHelper {
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case MSG_HIDE_KEYBOARD:
                    mIMM.hideSoftInputFromWindow((IBinder) message.obj, 0);
                    if (mIMM.hideSoftInputFromWindow((IBinder) message.obj, 0)) {
                        // log keyboard close event only when keyboard is actually closed
                        ((Message) message.getData().getParcelable(STATS_LOGGER_KEY))
                                .sendToTarget();
                    }
                    return true;
                case MSG_SET_ORIENTATION:
                    ((Activity) message.obj).setRequestedOrientation(message.arg1);