Merge "Fixes duplicate logging for LAUNCHER_ALLAPPS_KEYBOARD_CLOSED events." into sc-dev am: ea95f88361 am: 1789b00e50

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

Change-Id: I54fb3b4dcfd164e860dea59b6a56bcfb6664a2bf
This commit is contained in:
TreeHugger Robot
2021-06-17 06:32:31 +00:00
committed by Automerger Merge Worker
@@ -21,6 +21,7 @@ import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message; import android.os.Message;
@@ -42,15 +43,30 @@ public class UiThreadHelper {
private static final int MSG_HIDE_KEYBOARD = 1; private static final int MSG_HIDE_KEYBOARD = 1;
private static final int MSG_SET_ORIENTATION = 2; private static final int MSG_SET_ORIENTATION = 2;
private static final int MSG_RUN_COMMAND = 3; private static final int MSG_RUN_COMMAND = 3;
private static final String STATS_LOGGER_KEY = "STATS_LOGGER_KEY";
@SuppressLint("NewApi") @SuppressLint("NewApi")
public static void hideKeyboardAsync(ActivityContext activityContext, IBinder token) { public static void hideKeyboardAsync(ActivityContext activityContext, IBinder token) {
View root = activityContext.getDragLayer(); View root = activityContext.getDragLayer();
Message.obtain(HANDLER.get(root.getContext()), // Since the launcher context cannot be accessed directly from callback, adding secondary
MSG_HIDE_KEYBOARD, token).sendToTarget(); // message to log keyboard close event asynchronously.
Launcher.cast(activityContext).getStatsLogManager().logger().log( Bundle mHideKeyboardLoggerMsg = new Bundle();
LAUNCHER_ALLAPPS_KEYBOARD_CLOSED); 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) { public static void setOrientationAsync(Activity activity, int orientation) {
@@ -81,7 +97,11 @@ public class UiThreadHelper {
public boolean handleMessage(Message message) { public boolean handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case MSG_HIDE_KEYBOARD: 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; return true;
case MSG_SET_ORIENTATION: case MSG_SET_ORIENTATION:
((Activity) message.obj).setRequestedOrientation(message.arg1); ((Activity) message.obj).setRequestedOrientation(message.arg1);