Adds withPackageName to StatsLogger creation
This lets you specify a package name which will be logged by the returned StatsLogger (rather than retrieving from the ItemInfo). Bug: 292227499 Test: Manual with other change in topic Change-Id: I3650f9f02f6cbe560e1c21262ba1cb893702a49e
This commit is contained in:
@@ -32,6 +32,7 @@ import static com.android.systemui.shared.system.SysUiStatsLog.LAUNCHER_UICHANGE
|
||||
import static com.android.systemui.shared.system.SysUiStatsLog.LAUNCHER_UICHANGED__DST_STATE__OVERVIEW;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.StatsEvent;
|
||||
import android.view.View;
|
||||
@@ -227,6 +228,7 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
private Optional<Integer> mCardinality = Optional.empty();
|
||||
private int mInputType = SysUiStatsLog.LAUNCHER_UICHANGED__INPUT_TYPE__UNKNOWN;
|
||||
private Optional<Integer> mFeatures = Optional.empty();
|
||||
private Optional<String> mPackageName = Optional.empty();
|
||||
|
||||
StatsCompatLogger(Context context, ActivityContext activityContext) {
|
||||
mContext = context;
|
||||
@@ -331,6 +333,12 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatsLogger withPackageName(@Nullable String packageName) {
|
||||
mPackageName = Optional.ofNullable(packageName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(EventEnum event) {
|
||||
if (!Utilities.ATLEAST_R) {
|
||||
@@ -431,6 +439,7 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
int srcState = mSrcState;
|
||||
int dstState = mDstState;
|
||||
int inputType = mInputType;
|
||||
String packageName = mPackageName.orElseGet(() -> getPackageName(atomInfo));
|
||||
if (IS_VERBOSE) {
|
||||
String name = (event instanceof Enum) ? ((Enum) event).name() :
|
||||
event.getId() + "";
|
||||
@@ -448,6 +457,9 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
if (atomInfo.hasContainerInfo()) {
|
||||
logStringBuilder.append("\n").append(atomInfo);
|
||||
}
|
||||
if (!TextUtils.isEmpty(packageName)) {
|
||||
logStringBuilder.append(String.format("\nPackage name: %s", packageName));
|
||||
}
|
||||
Log.d(TAG, logStringBuilder.toString());
|
||||
}
|
||||
|
||||
@@ -472,7 +484,7 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
atomInfo.getItemCase().getNumber() /* target_id */,
|
||||
instanceId.getId() /* instance_id TODO */,
|
||||
0 /* uid TODO */,
|
||||
getPackageName(atomInfo) /* package_name */,
|
||||
packageName /* package_name */,
|
||||
getComponentName(atomInfo) /* component_name */,
|
||||
getGridX(atomInfo, false) /* grid_x */,
|
||||
getGridY(atomInfo, false) /* grid_y */,
|
||||
|
||||
@@ -838,6 +838,13 @@ public class StatsLogManager implements ResourceBasedOverride {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the package name of the log message.
|
||||
*/
|
||||
default StatsLogger withPackageName(@Nullable String packageName) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the final message and logs it as {@link EventEnum}.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user