[AA+] Log app launches from DeviceSearchResultContainer with instance ID.

This InstanceId is used to recreate the AA+ session on the server side.

Bug: 178562918
Change-Id: I1bba94417d3a142351e2470bb6153707d2cadb11
This commit is contained in:
thiruram
2021-01-27 19:05:12 -08:00
parent cbeb13d6c7
commit f4d19f4614
4 changed files with 32 additions and 4 deletions
@@ -149,7 +149,7 @@ public class SearchResultIcon extends BubbleTextView implements
// Workaround to log ItemInfo with DeviceSearchResultContainer without
// updating ItemInfo.container field.
@Override
protected ContainerInfo getContainerInfo() {
public ContainerInfo getContainerInfo() {
return buildDeviceSearchResultContainer();
}
};
@@ -257,7 +257,7 @@ public class SearchResultIcon extends BubbleTextView implements
// Workaround to log ItemInfo with DeviceSearchResultContainer without
// updating ItemInfo.container field.
@Override
protected ContainerInfo getContainerInfo() {
public ContainerInfo getContainerInfo() {
return buildDeviceSearchResultContainer();
}
};
@@ -275,7 +275,7 @@ public class SearchResultIcon extends BubbleTextView implements
// Workaround to log ItemInfo with DeviceSearchResultContainer without
// updating ItemInfo.container field.
@Override
protected ContainerInfo getContainerInfo() {
public ContainerInfo getContainerInfo() {
return buildDeviceSearchResultContainer();
}
};
@@ -24,6 +24,8 @@ import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.LauncherState.OVERVIEW_MODAL_TASK;
import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent;
import static com.android.launcher3.logger.LauncherAtom.ContainerInfo.ContainerCase.EXTENDED_CONTAINERS;
import static com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers.ContainerCase.DEVICE_SEARCH_RESULT_CONTAINER;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_APP_LAUNCH_TAP;
import static com.android.launcher3.testing.TestProtocol.HINT_STATE_ORDINAL;
import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL;
@@ -81,6 +83,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
public class QuickstepLauncher extends BaseQuickstepLauncher {
@@ -105,6 +108,15 @@ public class QuickstepLauncher extends BaseQuickstepLauncher {
@Override
protected void logAppLaunch(ItemInfo info, InstanceId instanceId) {
// If the app launch is from DeviceSearchResultContainer then add the InstanceId from
// LiveSearchManager to recreate the AllApps search session on the server side.
Optional<InstanceId> logInstanceId = this.getLiveSearchManager().getLogInstanceId();
if (info.getContainerInfo().getContainerCase() == EXTENDED_CONTAINERS
&& info.getContainerInfo().getExtendedContainers().getContainerCase()
== DEVICE_SEARCH_RESULT_CONTAINER && logInstanceId.isPresent()) {
instanceId = logInstanceId.get();
}
StatsLogger logger = getStatsLogManager()
.logger().withItemInfo(info).withInstanceId(instanceId);
@@ -33,10 +33,13 @@ import androidx.slice.widget.SliceLiveData;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceIdSequence;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import java.util.HashMap;
import java.util.Optional;
/**
* Manages Lifecycle for Live search results
@@ -51,6 +54,7 @@ public class LiveSearchManager {
new HashMap<>();
private final HashMap<Uri, LiveData<Slice>> mUriSliceMap = new HashMap<>();
private SearchWidgetHost mSearchWidgetHost;
private InstanceId mLogInstanceId;
public LiveSearchManager(Launcher launcher) {
mLauncher = launcher;
@@ -113,6 +117,7 @@ public class LiveSearchManager {
*/
public void start() {
stop();
mLogInstanceId = new InstanceIdSequence().newInstanceId();
mSearchWidgetHost = new SearchWidgetHost(mLauncher);
mSearchWidgetHost.startListening();
}
@@ -136,6 +141,14 @@ public class LiveSearchManager {
mUriSliceMap.clear();
}
/**
* Returns {@link InstanceId} that should be used for logging events within search session, if
* available.
*/
public Optional<InstanceId> getLogInstanceId() {
return Optional.ofNullable(mLogInstanceId);
}
static class SearchWidgetHost extends AppWidgetHost {
SearchWidgetHost(Context context) {
super(context, SEARCH_APPWIDGET_HOST_ID);
@@ -352,7 +352,10 @@ public class ItemInfo {
return itemBuilder;
}
protected ContainerInfo getContainerInfo() {
/**
* Returns {@link ContainerInfo} used when logging this item.
*/
public ContainerInfo getContainerInfo() {
switch (container) {
case CONTAINER_HOTSEAT:
return ContainerInfo.newBuilder()