diff --git a/go/quickstep/res/values/override.xml b/go/quickstep/res/values/override.xml index 7636fb30b4..bb267a3920 100644 --- a/go/quickstep/res/values/override.xml +++ b/go/quickstep/res/values/override.xml @@ -22,5 +22,7 @@ com.android.quickstep.InstantAppResolverImpl com.android.quickstep.QuickstepProcessInitializer + + com.android.quickstep.logging.UserEventDispatcherExtension diff --git a/quickstep/recents_ui_overrides/res/values/override.xml b/quickstep/recents_ui_overrides/res/values/override.xml index 1ddd3f594f..ed3ba929a8 100644 --- a/quickstep/recents_ui_overrides/res/values/override.xml +++ b/quickstep/recents_ui_overrides/res/values/override.xml @@ -24,5 +24,7 @@ com.android.launcher3.appprediction.PredictionAppTracker com.android.quickstep.QuickstepProcessInitializer + + com.android.quickstep.logging.UserEventDispatcherAppPredictionExtension diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java index 1a59770a02..9c661074e5 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java @@ -25,12 +25,16 @@ import android.app.prediction.AppTarget; import android.content.ComponentName; import android.content.Context; +import androidx.annotation.NonNull; + import com.android.launcher3.AppInfo; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.InvariantDeviceProfile.OnIDPChangeListener; +import com.android.launcher3.ItemInfo; import com.android.launcher3.ItemInfoWithIcon; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.LauncherSettings; import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherStateManager.StateListener; import com.android.launcher3.Utilities; @@ -39,12 +43,14 @@ import com.android.launcher3.allapps.AllAppsStore.OnUpdateListener; import com.android.launcher3.icons.IconCache; import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver; import com.android.launcher3.shortcuts.ShortcutKey; +import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.MainThreadInitializedObject; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.IntStream; /** * Handler responsible to updating the UI due to predicted apps changes. Operations: @@ -322,6 +328,30 @@ public class PredictionUiStateManager implements StateListener, ItemInfoUpdateRe return mCurrentState; } + /** + * Fill in predicted_rank field based on app prediction. + * Only applicable when {@link ItemInfo#itemType} is one of the followings: + * {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION}, + * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT}, + * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT} + */ + public static void fillInPredictedRank( + @NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target) { + final PredictionUiStateManager manager = PredictionUiStateManager.INSTANCE.getNoCreate(); + if (manager == null || itemInfo.getTargetComponent() == null || itemInfo.user == null + || (itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION + && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT + && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)) { + return; + } + final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user); + final List predictedApps = manager.getCurrentState().apps; + IntStream.range(0, predictedApps.size()) + .filter((i) -> k.equals(predictedApps.get(i).getComponentKey())) + .findFirst() + .ifPresent((rank) -> target.predictedRank = rank); + } + public static class PredictionState { public boolean isEnabled; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/logging/UserEventDispatcherAppPredictionExtension.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/logging/UserEventDispatcherAppPredictionExtension.java new file mode 100644 index 0000000000..b251f9e697 --- /dev/null +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/logging/UserEventDispatcherAppPredictionExtension.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2018 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.quickstep.logging; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.android.launcher3.ItemInfo; +import com.android.launcher3.appprediction.PredictionUiStateManager; +import com.android.launcher3.userevent.nano.LauncherLogProto; + +/** + * This class handles AOSP MetricsLogger function calls and logging around + * quickstep interactions and app launches. + */ +@SuppressWarnings("unused") +public class UserEventDispatcherAppPredictionExtension extends UserEventDispatcherExtension { + + public static final int ALL_APPS_PREDICTION_TIPS = 2; + + private static final String TAG = "UserEventDispatcher"; + + public UserEventDispatcherAppPredictionExtension(Context context) { + super(context); + } + + @Override + protected void onFillInLogContainerData( + @NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target, + @NonNull LauncherLogProto.Target targetParent) { + PredictionUiStateManager.fillInPredictedRank(itemInfo, target); + } +} diff --git a/quickstep/res/values/config.xml b/quickstep/res/values/config.xml index 5c4d6d869f..292eaaa996 100644 --- a/quickstep/res/values/config.xml +++ b/quickstep/res/values/config.xml @@ -21,8 +21,6 @@ - com.android.quickstep.logging.UserEventDispatcherExtension - com.android.quickstep.logging.StatsLogCompatManager com.android.quickstep.QuickstepTestInformationHandler diff --git a/quickstep/src/com/android/quickstep/logging/UserEventDispatcherExtension.java b/quickstep/src/com/android/quickstep/logging/UserEventDispatcherExtension.java index 4a11601bbb..9ca7f234e7 100644 --- a/quickstep/src/com/android/quickstep/logging/UserEventDispatcherExtension.java +++ b/quickstep/src/com/android/quickstep/logging/UserEventDispatcherExtension.java @@ -20,10 +20,10 @@ import android.util.Log; import static com.android.launcher3.logging.LoggerUtils.newLauncherEvent; import static com.android.launcher3.userevent.nano.LauncherLogProto.ControlType.CANCEL_TARGET; -import static com.android.systemui.shared.system.LauncherEventUtil.VISIBLE; import static com.android.systemui.shared.system.LauncherEventUtil.DISMISS; import static com.android.systemui.shared.system.LauncherEventUtil.RECENTS_QUICK_SCRUB_ONBOARDING_TIP; import static com.android.systemui.shared.system.LauncherEventUtil.RECENTS_SWIPE_UP_ONBOARDING_TIP; +import static com.android.systemui.shared.system.LauncherEventUtil.VISIBLE; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.userevent.nano.LauncherLogProto; diff --git a/src/com/android/launcher3/logging/LoggerUtils.java b/src/com/android/launcher3/logging/LoggerUtils.java index 9b75b43b4a..ed08c026b9 100644 --- a/src/com/android/launcher3/logging/LoggerUtils.java +++ b/src/com/android/launcher3/logging/LoggerUtils.java @@ -44,6 +44,7 @@ import java.lang.reflect.Modifier; public class LoggerUtils { private static final ArrayMap> sNameCache = new ArrayMap<>(); private static final String UNKNOWN = "UNKNOWN"; + private static final int DEFAULT_PREDICTED_RANK = -100; public static String getFieldName(int value, Class c) { SparseArray cache; @@ -168,17 +169,17 @@ public class LoggerUtils { public static Target newItemTarget(ItemInfo info, InstantAppResolver instantAppResolver) { Target t = newTarget(Target.Type.ITEM); - switch (info.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: t.itemType = (instantAppResolver != null && info instanceof AppInfo && instantAppResolver.isInstantApp(((AppInfo) info)) ) ? ItemType.WEB_APP : ItemType.APP_ICON; - t.predictedRank = -100; // Never assigned + t.predictedRank = DEFAULT_PREDICTED_RANK; break; case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: t.itemType = ItemType.SHORTCUT; + t.predictedRank = DEFAULT_PREDICTED_RANK; break; case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: t.itemType = ItemType.FOLDER_ICON; @@ -188,6 +189,7 @@ public class LoggerUtils { break; case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: t.itemType = ItemType.DEEPSHORTCUT; + t.predictedRank = DEFAULT_PREDICTED_RANK; break; } return t; diff --git a/src/com/android/launcher3/logging/UserEventDispatcher.java b/src/com/android/launcher3/logging/UserEventDispatcher.java index 21ca74e12b..7b06d3ba96 100644 --- a/src/com/android/launcher3/logging/UserEventDispatcher.java +++ b/src/com/android/launcher3/logging/UserEventDispatcher.java @@ -35,6 +35,7 @@ import android.os.SystemClock; import android.util.Log; import android.view.View; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.DropTarget; @@ -96,17 +97,23 @@ public class UserEventDispatcher implements ResourceBasedOverride { * Fills in the container data on the given event if the given view is not null. * @return whether container data was added. */ - public static boolean fillInLogContainerData(LauncherLogProto.LauncherEvent event, @Nullable View v) { + public boolean fillInLogContainerData(LauncherLogProto.LauncherEvent event, @Nullable View v) { // Fill in grid(x,y), pageIndex of the child and container type of the parent LogContainerProvider provider = StatsLogUtils.getLaunchProviderRecursive(v); if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) { return false; } - ItemInfo itemInfo = (ItemInfo) v.getTag(); - provider.fillInLogContainerData(v, itemInfo, event.srcTarget[0], event.srcTarget[1]); + final ItemInfo itemInfo = (ItemInfo) v.getTag(); + final Target target = event.srcTarget[0]; + final Target targetParent = event.srcTarget[1]; + onFillInLogContainerData(itemInfo, target, targetParent); + provider.fillInLogContainerData(v, itemInfo, target, targetParent); return true; } + protected void onFillInLogContainerData( + @NonNull ItemInfo itemInfo, @NonNull Target target, @NonNull Target targetParent) { } + private boolean mSessionStarted; private long mElapsedContainerMillis; private long mElapsedSessionMillis;