Launcher dump proto that will be used for:

$ adb shell dumpsys activity provider com.android.launcher3/com.android.launcher3.LauncherProvider
To see how the proto is filled: go/launcher-proto-dump

b/31772480

Change-Id: I8e0f1e5e38148a3dfeabd2fc057392193b2625dd
This commit is contained in:
Hyunyoung Song
2017-02-06 10:46:24 -08:00
parent d8745db015
commit 6aa3729e98
6 changed files with 376 additions and 13 deletions

View File

@@ -24,19 +24,27 @@ import android.util.MutableInt;
import com.android.launcher3.FolderInfo;
import com.android.launcher3.InstallShortcutReceiver;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.logging.LoggerUtils;
import com.android.launcher3.logging.DumpTargetWrapper;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.model.nano.LauncherDumpProto;
import com.android.launcher3.model.nano.LauncherDumpProto.ContainerType;
import com.android.launcher3.model.nano.LauncherDumpProto.DumpTarget;
import com.android.launcher3.model.nano.LauncherDumpProto.ItemType;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.MultiHashMap;
import com.google.protobuf.nano.MessageNano;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -102,21 +110,31 @@ public class BgDataModel {
deepShortcutMap.clear();
}
// TODO: current dump is very cryptic and hard to understand. Make it more legible.
public synchronized void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
writer.println(prefix + "Data Model:");
for (int i = 0; i < workspaceScreens.size(); i++) {
writer.println(prefix + "\tIndex of workspaceScreens:" + workspaceScreens.get(i).toString());
public synchronized void dump(String prefix, FileDescriptor fd, PrintWriter writer,
String[] args) {
if (args.length > 0 && TextUtils.equals(args[0], "--proto")) {
dumpProto(prefix, fd, writer, args);
return;
}
writer.println(prefix + "Data Model:");
writer.print(prefix + " ---- workspace screens: ");
for (int i = 0; i < workspaceScreens.size(); i++) {
writer.print(" " + workspaceScreens.get(i).toString());
}
writer.println();
writer.println(prefix + " ---- workspace items ");
for (int i = 0; i < workspaceItems.size(); i++) {
writer.println(prefix + '\t' + workspaceItems.get(i).toString());
}
writer.println(prefix + " ---- appwidget items ");
for (int i = 0; i < appWidgets.size(); i++) {
writer.println(prefix + '\t' + appWidgets.get(i).toString());
}
writer.println(prefix + " ---- folder items ");
for (int i = 0; i< folders.size(); i++) {
writer.println(prefix + '\t' + folders.valueAt(i).toString());
}
writer.println(prefix + " ---- items id map ");
for (int i = 0; i< itemsIdMap.size(); i++) {
writer.println(prefix + '\t' + itemsIdMap.valueAt(i).toString());
}
@@ -133,6 +151,88 @@ public class BgDataModel {
}
}
private synchronized void dumpProto(String prefix, FileDescriptor fd, PrintWriter writer,
String[] args) {
// Add top parent nodes. (L1)
DumpTargetWrapper hotseat = new DumpTargetWrapper(ContainerType.HOTSEAT, 0);
LongArrayMap<DumpTargetWrapper> workspaces = new LongArrayMap<>();
for (int i = 0; i < workspaceScreens.size(); i++) {
workspaces.put(new Long(workspaceScreens.get(i)),
new DumpTargetWrapper(ContainerType.WORKSPACE, i));
}
DumpTargetWrapper dtw;
// Add non leaf / non top nodes (L2)
for (int i = 0; i < folders.size(); i++) {
FolderInfo fInfo = folders.valueAt(i);
dtw = new DumpTargetWrapper(ContainerType.FOLDER, folders.size());
dtw.writeToDumpTarget(fInfo);
for(ShortcutInfo sInfo: fInfo.contents) {
DumpTargetWrapper child = new DumpTargetWrapper(sInfo);
child.writeToDumpTarget(sInfo);
dtw.add(child);
}
if (fInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
hotseat.add(dtw);
} else if (fInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
workspaces.get(new Long(fInfo.screenId)).add(dtw);
}
}
// Add leaf nodes (L3): *Info
for (int i = 0; i < workspaceItems.size(); i++) {
ItemInfo info = workspaceItems.get(i);
if (info instanceof FolderInfo) {
continue;
}
dtw = new DumpTargetWrapper(info);
dtw.writeToDumpTarget(info);
if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
hotseat.add(dtw);
} else if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
workspaces.get(new Long(info.screenId)).add(dtw);
}
}
for (int i = 0; i < appWidgets.size(); i++) {
ItemInfo info = appWidgets.get(i);
dtw = new DumpTargetWrapper(info);
dtw.writeToDumpTarget(info);
if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
hotseat.add(dtw);
} else if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
workspaces.get(new Long(info.screenId)).add(dtw);
}
}
// Traverse target wrapper
ArrayList<DumpTarget> targetList = new ArrayList<>();
targetList.addAll(hotseat.getFlattenedList());
for (int i = 0; i < workspaces.size(); i++) {
targetList.addAll(workspaces.valueAt(i).getFlattenedList());
}
if (args.length > 1 && TextUtils.equals(args[1], "--debug")) {
for (int i = 0; i < targetList.size(); i++) {
writer.println(prefix + DumpTargetWrapper.getDumpTargetStr(targetList.get(i)));
}
return;
} else {
LauncherDumpProto.LauncherImpression proto = new LauncherDumpProto.LauncherImpression();
proto.targets = new DumpTarget[targetList.size()];
for (int i = 0; i < targetList.size(); i++) {
proto.targets[i] = targetList.get(i);
}
FileOutputStream fos = new FileOutputStream(fd);
try {
fos.write(MessageNano.toByteArray(proto));
Log.d(TAG, MessageNano.toByteArray(proto).length + "Bytes");
} catch (IOException e) {
Log.e(TAG, "Exception writing dumpsys --proto", e);
}
}
}
public synchronized void removeItem(Context context, ItemInfo... items) {
removeItem(context, Arrays.asList(items));
}