Limit launcher snapshot logging once per day. am: a4661192ff

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/12213196

Change-Id: I5bf5ca36fe730a9ffb024a5d94640182d5078683
This commit is contained in:
thiruram
2020-07-23 03:26:54 +00:00
committed by Automerger Merge Worker
@@ -16,6 +16,10 @@
package com.android.quickstep.logging;
import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static android.text.format.DateUtils.formatElapsedTime;
import static com.android.launcher3.Utilities.getDevicePrefs;
import static com.android.launcher3.logger.LauncherAtom.ContainerInfo.ContainerCase.FOLDER;
import static com.android.launcher3.logger.LauncherAtom.ContainerInfo.ContainerCase.SEARCH_RESULT_CONTAINER;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WORKSPACE_SNAPSHOT;
@@ -24,6 +28,8 @@ import static com.android.systemui.shared.system.SysUiStatsLog.LAUNCHER_UICHANGE
import static com.android.systemui.shared.system.SysUiStatsLog.LAUNCHER_UICHANGED__DST_STATE__HOME;
import static com.android.systemui.shared.system.SysUiStatsLog.LAUNCHER_UICHANGED__DST_STATE__OVERVIEW;
import static java.lang.System.currentTimeMillis;
import android.content.Context;
import android.util.Log;
@@ -71,8 +77,7 @@ public class StatsLogCompatManager extends StatsLogManager {
private static final String TAG = "StatsLog";
private static final boolean IS_VERBOSE = Utilities.isPropertyEnabled(LogConfig.STATSLOG);
private static Context sContext;
private static final String LAST_SNAPSHOT_TIME_MILLIS = "LAST_SNAPSHOT_TIME_MILLIS";
private static final InstanceId DEFAULT_INSTANCE_ID = InstanceId.fakeInstanceId(0);
// LauncherAtom.ItemInfo.getDefaultInstance() should be used but until launcher proto migrates
// from nano to lite, bake constant to prevent robo test failure.
@@ -80,8 +85,10 @@ public class StatsLogCompatManager extends StatsLogManager {
private static final int FOLDER_HIERARCHY_OFFSET = 100;
private static final int SEARCH_RESULT_HIERARCHY_OFFSET = 200;
private final Context mContext;
public StatsLogCompatManager(Context context) {
sContext = context;
mContext = context;
}
@Override
@@ -107,7 +114,7 @@ public class StatsLogCompatManager extends StatsLogManager {
*/
@Override
public void logSnapshot() {
LauncherAppState.getInstance(sContext).getModel().enqueueModelUpdateTask(
LauncherAppState.getInstance(mContext).getModel().enqueueModelUpdateTask(
new SnapshotWorker());
}
@@ -122,6 +129,20 @@ public class StatsLogCompatManager extends StatsLogManager {
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
long lastSnapshotTimeMillis = getDevicePrefs(mContext)
.getLong(LAST_SNAPSHOT_TIME_MILLIS, 0);
// Log snapshot only if previous snapshot was older than a day
if (currentTimeMillis() - lastSnapshotTimeMillis < DAY_IN_MILLIS) {
if (IS_VERBOSE) {
String elapsedTime = formatElapsedTime(
(currentTimeMillis() - lastSnapshotTimeMillis) / 1000);
Log.d(TAG, String.format(
"Skipped snapshot logging since previous snapshot was %s old.",
elapsedTime));
}
return;
}
IntSparseArrayMap<FolderInfo> folders = dataModel.folders.clone();
ArrayList<ItemInfo> workspaceItems = (ArrayList) dataModel.workspaceItems.clone();
ArrayList<LauncherAppWidgetInfo> appWidgets = (ArrayList) dataModel.appWidgets.clone();
@@ -144,10 +165,12 @@ public class StatsLogCompatManager extends StatsLogManager {
LauncherAtom.ItemInfo atomInfo = info.buildProto(null);
writeSnapshot(atomInfo, mInstanceId);
}
getDevicePrefs(mContext).edit()
.putLong(LAST_SNAPSHOT_TIME_MILLIS, currentTimeMillis()).apply();
}
}
private static void writeSnapshot(LauncherAtom.ItemInfo info, InstanceId instanceId) {
private void writeSnapshot(LauncherAtom.ItemInfo info, InstanceId instanceId) {
if (IS_VERBOSE) {
Log.d(TAG, String.format("\nwriteSnapshot(%d):\n%s", instanceId.getId(), info));
}
@@ -266,7 +289,7 @@ public class StatsLogCompatManager extends StatsLogManager {
} else {
// Item is inside the folder, fetch folder info in a BG thread
// and then write to StatsLog.
LauncherAppState.getInstance(sContext).getModel().enqueueModelUpdateTask(
LauncherAppState.getInstanceNoCreate().getModel().enqueueModelUpdateTask(
new BaseModelUpdateTask() {
@Override
public void execute(LauncherAppState app, BgDataModel dataModel,