mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 11:18:21 +00:00
Merge "Add ImpressionLogger to StatsLogManager" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c2f03ae080
@@ -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;
|
||||
|
||||
@@ -47,7 +47,6 @@ public final class InstanceId implements Parcelable {
|
||||
this(in.readInt());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public int getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,12 @@ import com.android.launcher3.logger.LauncherAtom.ContainerInfo;
|
||||
import com.android.launcher3.logger.LauncherAtom.FromState;
|
||||
import com.android.launcher3.logger.LauncherAtom.ToState;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.ResourceBasedOverride;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Handles the user event logging in R+.
|
||||
*
|
||||
@@ -838,6 +841,77 @@ public class StatsLogManager implements ResourceBasedOverride {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps to construct and log impression event.
|
||||
*/
|
||||
public interface StatsImpressionLogger {
|
||||
|
||||
enum State {
|
||||
UNKNOWN(0),
|
||||
ALLAPPS(1),
|
||||
SEARCHBOX_WIDGET(2);
|
||||
private final int mLauncherState;
|
||||
|
||||
State(int id) {
|
||||
this.mLauncherState = id;
|
||||
}
|
||||
|
||||
public int getLauncherState() {
|
||||
return mLauncherState;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets {@link InstanceId} of log message.
|
||||
*/
|
||||
default StatsImpressionLogger withInstanceId(InstanceId instanceId) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets {@link State} of impression event.
|
||||
*/
|
||||
default StatsImpressionLogger withState(State state) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets query length of the event.
|
||||
*/
|
||||
default StatsImpressionLogger withQueryLength(int queryLength) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets list of {@link com.android.app.search.ResultType} for the impression event.
|
||||
*/
|
||||
default StatsImpressionLogger withResultType(IntArray resultType) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets list of count for each of {@link com.android.app.search.ResultType} for the
|
||||
* impression event.
|
||||
*/
|
||||
default StatsImpressionLogger withResultCount(IntArray resultCount) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets list of boolean for each of {@link com.android.app.search.ResultType} that indicates
|
||||
* if this result is above keyboard or not for the impression event.
|
||||
*/
|
||||
default StatsImpressionLogger withAboveKeyboard(List<Boolean> aboveKeyboard) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the final message and logs it as {@link EventEnum}.
|
||||
*/
|
||||
default void log(EventEnum event) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new logger object.
|
||||
*/
|
||||
@@ -860,6 +934,17 @@ public class StatsLogManager implements ResourceBasedOverride {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new impression logger object.
|
||||
*/
|
||||
public StatsImpressionLogger impressionLogger() {
|
||||
StatsImpressionLogger logger = createImpressionLogger();
|
||||
if (mInstanceId != null) {
|
||||
logger.withInstanceId(mInstanceId);
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a singleton KeyboardStateManager.
|
||||
*/
|
||||
@@ -880,6 +965,11 @@ public class StatsLogManager implements ResourceBasedOverride {
|
||||
};
|
||||
}
|
||||
|
||||
protected StatsImpressionLogger createImpressionLogger() {
|
||||
return new StatsImpressionLogger() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets InstanceId to every new {@link StatsLogger} object returned by {@link #logger()} when
|
||||
* not-null.
|
||||
|
||||
Reference in New Issue
Block a user