Add ImpressionLogger to StatsLogManager
go/toast-search-impression-logging Bug: 204781396 Test: Manual Change-Id: If00027581000d315590ce2fac46428cbf173da49
This commit is contained in:
@@ -62,11 +62,14 @@ import com.android.launcher3.model.BgDataModel;
|
||||
import com.android.launcher3.model.data.FolderInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.LogConfig;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
|
||||
import com.android.systemui.shared.system.SysUiStatsLog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -85,6 +88,7 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
|
||||
private static final String TAG = "StatsLog";
|
||||
private static final String LATENCY_TAG = "StatsLatencyLog";
|
||||
private static final String IMPRESSION_TAG = "StatsImpressionLog";
|
||||
private static final boolean IS_VERBOSE = Utilities.isPropertyEnabled(LogConfig.STATSLOG);
|
||||
private static final InstanceId DEFAULT_INSTANCE_ID = InstanceId.fakeInstanceId(0);
|
||||
// LauncherAtom.ItemInfo.getDefaultInstance() should be used but until launcher proto migrates
|
||||
@@ -119,7 +123,12 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
|
||||
@Override
|
||||
protected StatsLatencyLogger createLatencyLogger() {
|
||||
return new StatsCompatLatencyLogger(mContext, mActivityContext);
|
||||
return new StatsCompatLatencyLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StatsImpressionLogger createImpressionLogger() {
|
||||
return new StatsCompatImpressionLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,8 +475,6 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
* Helps to construct and log statsd compatible latency events.
|
||||
*/
|
||||
private static class StatsCompatLatencyLogger implements StatsLatencyLogger {
|
||||
private final Context mContext;
|
||||
private final Optional<ActivityContext> mActivityContext;
|
||||
private InstanceId mInstanceId = DEFAULT_INSTANCE_ID;
|
||||
private LatencyType mType = LatencyType.UNKNOWN;
|
||||
private int mPackageId = 0;
|
||||
@@ -475,11 +482,6 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
private int mQueryLength = -1;
|
||||
private int mSubEventType = 0;
|
||||
|
||||
StatsCompatLatencyLogger(Context context, ActivityContext activityContext) {
|
||||
mContext = context;
|
||||
mActivityContext = Optional.ofNullable(activityContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatsLatencyLogger withInstanceId(InstanceId instanceId) {
|
||||
this.mInstanceId = instanceId;
|
||||
@@ -539,6 +541,96 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps to construct and log statsd compatible impression events.
|
||||
*/
|
||||
private static class StatsCompatImpressionLogger implements StatsImpressionLogger {
|
||||
private final IntArray mResultTypeList = new IntArray();
|
||||
private final IntArray mResultCountList = new IntArray();
|
||||
private final List<Boolean> mAboveKeyboardList = new ArrayList<>();
|
||||
private InstanceId mInstanceId = DEFAULT_INSTANCE_ID;
|
||||
private State mLauncherState = State.UNKNOWN;
|
||||
private int mQueryLength = -1;
|
||||
|
||||
@Override
|
||||
public StatsImpressionLogger withInstanceId(InstanceId instanceId) {
|
||||
this.mInstanceId = instanceId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatsImpressionLogger withState(State state) {
|
||||
this.mLauncherState = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatsImpressionLogger withQueryLength(int queryLength) {
|
||||
this.mQueryLength = queryLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatsImpressionLogger withResultType(IntArray resultType) {
|
||||
this.mResultTypeList.clear();
|
||||
this.mResultTypeList.addAll(resultType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatsImpressionLogger withResultCount(IntArray resultCount) {
|
||||
this.mResultCountList.clear();
|
||||
this.mResultCountList.addAll(resultCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatsImpressionLogger withAboveKeyboard(List<Boolean> aboveKeyboard) {
|
||||
this.mAboveKeyboardList.clear();
|
||||
this.mAboveKeyboardList.addAll(aboveKeyboard);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(EventEnum event) {
|
||||
boolean [] mAboveKeyboard = new boolean[mAboveKeyboardList.size()];
|
||||
for (int i = 0; i < mAboveKeyboardList.size(); i++) {
|
||||
mAboveKeyboard[i] = mAboveKeyboardList.get(i);
|
||||
}
|
||||
if (IS_VERBOSE) {
|
||||
String name = (event instanceof Enum) ? ((Enum) event).name() :
|
||||
event.getId() + "";
|
||||
StringBuilder logStringBuilder = new StringBuilder("\n");
|
||||
logStringBuilder.append(String.format("InstanceId:%s ", mInstanceId));
|
||||
logStringBuilder.append(String.format("ImpressionEvent:%s ", name));
|
||||
logStringBuilder.append(String.format("LauncherState = %s ", mLauncherState));
|
||||
logStringBuilder.append(String.format("QueryLength = %s ", mQueryLength));
|
||||
for (int i = 0; i < mResultTypeList.size(); i++) {
|
||||
logStringBuilder.append(String.format(
|
||||
"\n ResultType = %s with ResultCount = %s with is_above_keyboard = %s",
|
||||
mResultTypeList.get(i), mResultCountList.get(i),
|
||||
mAboveKeyboard[i]));
|
||||
}
|
||||
Log.d(IMPRESSION_TAG, logStringBuilder.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_IMPRESSION_EVENT,
|
||||
event.getId(), // event_id
|
||||
mInstanceId.getId(), // instance_id
|
||||
mLauncherState.getLauncherState(), // state
|
||||
mQueryLength, // query_length
|
||||
//result type list
|
||||
mResultTypeList.toArray(),
|
||||
// result count list
|
||||
mResultCountList.toArray(),
|
||||
// above keyboard list
|
||||
mAboveKeyboard
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static int getCardinality(LauncherAtom.ItemInfo info) {
|
||||
if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user