mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-17 01:28:21 +00:00
Implement LauncherLayoutSnapshot pulled atom callback.
This change will pull only the workspace items but not the launcher settings such as grid layout etc. Future CLs will address it. Bug: 181703659 Test: Manual-`statsd_testdrive 10108` http://gpaste/4894958784872448 Change-Id: I0e7d7da62034c411edb26ff9205a81b0e2e891a0
This commit is contained in:
@@ -25,7 +25,9 @@ import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICA
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
|
||||
import static com.android.launcher3.Utilities.getDevicePrefs;
|
||||
import static com.android.launcher3.hybridhotseat.HotseatPredictionModel.convertDataModelToAppTargetBundle;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
import android.app.StatsManager;
|
||||
import android.app.prediction.AppPredictionContext;
|
||||
import android.app.prediction.AppPredictionManager;
|
||||
import android.app.prediction.AppPredictor;
|
||||
@@ -39,12 +41,14 @@ import android.content.pm.LauncherApps;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
import android.util.StatsEvent;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.logger.LauncherAtom;
|
||||
import com.android.launcher3.logging.InstanceId;
|
||||
import com.android.launcher3.logging.InstanceIdSequence;
|
||||
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
@@ -53,10 +57,10 @@ import com.android.launcher3.model.data.FolderInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.shortcuts.ShortcutKey;
|
||||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.IntSparseArrayMap;
|
||||
import com.android.launcher3.util.PersistedItemArray;
|
||||
import com.android.quickstep.logging.StatsLogCompatManager;
|
||||
import com.android.systemui.shared.system.SysUiStatsLog;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -85,6 +89,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
|
||||
private final InvariantDeviceProfile mIDP;
|
||||
private final AppEventProducer mAppEventProducer;
|
||||
private final StatsManager mStatsManager;
|
||||
|
||||
protected boolean mActive = false;
|
||||
|
||||
@@ -93,6 +98,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
|
||||
mIDP = InvariantDeviceProfile.INSTANCE.get(context);
|
||||
StatsLogCompatManager.LOGS_CONSUMER.add(mAppEventProducer);
|
||||
mStatsManager = context.getSystemService(StatsManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,10 +161,60 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
additionalSnapshotEvents(instanceId);
|
||||
prefs.edit().putLong(LAST_SNAPSHOT_TIME_MILLIS, now).apply();
|
||||
}
|
||||
|
||||
// Only register for launcher snapshot logging if this is the primary ModelDelegate
|
||||
// instance, as there will be additional instances that may be destroyed at any time.
|
||||
if (mIsPrimaryInstance) {
|
||||
registerSnapshotLoggingCallback();
|
||||
}
|
||||
}
|
||||
|
||||
protected void additionalSnapshotEvents(InstanceId snapshotInstanceId){}
|
||||
|
||||
/**
|
||||
* Registers a callback to log launcher workspace layout using Statsd pulled atom.
|
||||
*/
|
||||
protected void registerSnapshotLoggingCallback() {
|
||||
if (mStatsManager == null) {
|
||||
Log.d(TAG, "Failed to get StatsManager");
|
||||
}
|
||||
|
||||
try {
|
||||
mStatsManager.setPullAtomCallback(
|
||||
SysUiStatsLog.LAUNCHER_LAYOUT_SNAPSHOT,
|
||||
null /* PullAtomMetadata */,
|
||||
MODEL_EXECUTOR,
|
||||
(i, eventList) -> {
|
||||
InstanceId instanceId = new InstanceIdSequence().newInstanceId();
|
||||
IntSparseArrayMap<ItemInfo> itemsIdMap;
|
||||
synchronized (mDataModel) {
|
||||
itemsIdMap = mDataModel.itemsIdMap.clone();
|
||||
}
|
||||
|
||||
for (ItemInfo info : itemsIdMap) {
|
||||
FolderInfo parent = info.container > 0
|
||||
? (FolderInfo) itemsIdMap.get(info.container) : null;
|
||||
LauncherAtom.ItemInfo itemInfo = info.buildProto(parent);
|
||||
Log.d(TAG, itemInfo.toString());
|
||||
StatsEvent statsEvent = StatsLogCompatManager.buildStatsEvent(itemInfo,
|
||||
instanceId);
|
||||
eventList.add(statsEvent);
|
||||
}
|
||||
Log.d(TAG,
|
||||
String.format(
|
||||
"Successfully logged %d workspace items with instanceId=%d",
|
||||
itemsIdMap.size(), instanceId.getId()));
|
||||
additionalSnapshotEvents(instanceId);
|
||||
return StatsManager.PULL_SUCCESS;
|
||||
}
|
||||
);
|
||||
Log.d(TAG, "Successfully registered for launcher snapshot logging!");
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "Failed to register launcher snapshot logging callback with StatsManager",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateData() {
|
||||
super.validateData();
|
||||
@@ -175,7 +231,9 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
super.destroy();
|
||||
mActive = false;
|
||||
StatsLogCompatManager.LOGS_CONSUMER.remove(mAppEventProducer);
|
||||
|
||||
if (mIsPrimaryInstance) {
|
||||
mStatsManager.clearPullAtomCallback(SysUiStatsLog.LAUNCHER_LAYOUT_SNAPSHOT);
|
||||
}
|
||||
destroyPredictors();
|
||||
}
|
||||
|
||||
@@ -221,7 +279,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
private void registerPredictor(PredictorState state, AppPredictor predictor) {
|
||||
state.predictor = predictor;
|
||||
state.predictor.registerPredictionUpdates(
|
||||
Executors.MODEL_EXECUTOR, t -> handleUpdate(state, t));
|
||||
MODEL_EXECUTOR, t -> handleUpdate(state, t));
|
||||
state.predictor.requestPredictionUpdate();
|
||||
}
|
||||
|
||||
@@ -236,7 +294,7 @@ public class QuickstepModelDelegate extends ModelDelegate {
|
||||
private void registerWidgetsPredictor(AppPredictor predictor) {
|
||||
mWidgetsRecommendationState.predictor = predictor;
|
||||
mWidgetsRecommendationState.predictor.registerPredictionUpdates(
|
||||
Executors.MODEL_EXECUTOR, targets -> {
|
||||
MODEL_EXECUTOR, targets -> {
|
||||
if (mWidgetsRecommendationState.setTargets(targets)) {
|
||||
// No diff, skip
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user