Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0aa685bb authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Android (Google) Code Review
Browse files

Merge "Launcher dump proto that will be used for:" into ub-launcher3-dorval

parents 830cca66 e295acae
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
syntax = "proto2";

option java_package = "com.android.launcher3.model";
option java_outer_classname = "LauncherDumpProto";

package model;

message DumpTarget {
  enum Type {
    NONE = 0;
    ITEM = 1;
    CONTAINER = 2;
  }

  optional Type type = 1;
  optional int32 page_id = 2;
  optional int32 grid_x = 3;
  optional int32 grid_y = 4;

  // For container types only
  optional ContainerType container_type = 5;

  // For item types only
  optional ItemType item_type = 6;

  optional string package_name = 7; // All ItemTypes except UNKNOWN type
  optional string component = 8;   // All ItemTypes except UNKNOWN type
  optional string item_id = 9; // For Pinned Shortcuts and appWidgetId

  optional int32 span_x = 10 [default = 1];// Used for ItemType.WIDGET
  optional int32 span_y = 11 [default = 1];// Used for ItemType.WIDGET
  optional UserType user_type = 12;
}

// Used to define what type of item a Target would represent.
enum ItemType {
  UNKNOWN_ITEMTYPE = 0;  // Launcher specific items
  APP_ICON = 1; // Regular app icons
  WIDGET = 2;   // Elements from AppWidgetManager
  SHORTCUT = 3; // ShortcutManager
}

// Used to define what type of container a Target would represent.
enum ContainerType {
  UNKNOWN_CONTAINERTYPE = 0;
  WORKSPACE = 1;
  HOTSEAT = 2;
  FOLDER = 3;
}

// Used to define what type of control a Target would represent.
enum UserType {
  DEFAULT = 0;
  WORK = 1;
}

// Main message;
message LauncherImpression {
  repeated DumpTarget targets = 1;
}
+5 −0
Original line number Diff line number Diff line
@@ -129,6 +129,11 @@ public class LauncherModel extends BroadcastReceiver
    // our monitoring of the package manager provides all updates and we never
    // need to do a requery. This is only ever touched from the loader thread.
    private boolean mModelLoaded;
    public boolean isModelLoaded() {
        synchronized (mLock) {
            return mModelLoaded && mLoaderTask == null;
        }
    }

    /**
     * Set of runnables to be called on the background thread after the workspace binding
+15 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.ViewGroup;

import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
import com.android.launcher3.LauncherSettings.Favorites;
@@ -64,6 +65,8 @@ import com.android.launcher3.util.NoLocaleSqliteContext;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Thunk;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
@@ -86,6 +89,18 @@ public class LauncherProvider extends ContentProvider {

    protected DatabaseHelper mOpenHelper;

    /**
     * $ adb shell dumpsys activity provider com.android.launcher3
     */
    @Override
    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
        if (appState == null || !appState.getModel().isModelLoaded()) {
            return;
        }
        appState.getModel().dumpState("", fd, writer, args);
    }

    @Override
    public boolean onCreate() {
        if (ProviderConfig.IS_DOGFOOD_BUILD) {
+149 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3.logging;

import android.os.Process;
import android.text.TextUtils;

import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherSettings;
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.model.nano.LauncherDumpProto.UserType;

import java.util.ArrayList;
import java.util.List;

/**
 * This class can be used when proto definition doesn't support nesting.
 */
public class DumpTargetWrapper {
    DumpTarget node;
    ArrayList<DumpTargetWrapper> children;

    public DumpTargetWrapper() {
        children = new ArrayList<>();
    }

    public DumpTargetWrapper(DumpTarget t) {
        this();
        node = t;
    }

    public DumpTargetWrapper(int containerType, int id) {
        this();
        node = newContainerTarget(containerType, id);
    }

    public DumpTargetWrapper(ItemInfo info) {
        this();
        node = newItemTarget(info);
    }

    public DumpTarget getDumpTarget() {
        return node;
    }

    public void add(DumpTargetWrapper child) {
        children.add(child);
    }

    public List<DumpTarget> getFlattenedList() {
        ArrayList<DumpTarget> list = new ArrayList<>();
        list.add(node);
        if (!children.isEmpty()) {
            for(DumpTargetWrapper t: children) {
                list.addAll(t.getFlattenedList());
            }
            list.add(node); // add a delimiter empty object
        }
        return list;
    }
    public DumpTarget newItemTarget(ItemInfo info) {
        DumpTarget dt = new DumpTarget();
        dt.type = DumpTarget.Type.ITEM;

        switch (info.itemType) {
            case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
                dt.itemType = ItemType.APP_ICON;
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
                dt.itemType = ItemType.UNKNOWN_ITEMTYPE;
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
                dt.itemType = ItemType.WIDGET;
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                dt.itemType = ItemType.SHORTCUT;
                break;
        }
        return dt;
    }

    public DumpTarget newContainerTarget(int type, int id) {
        DumpTarget dt = new DumpTarget();
        dt.type = DumpTarget.Type.CONTAINER;
        dt.containerType = type;
        dt.pageId = id;
        return dt;
    }

    public static String getDumpTargetStr(DumpTarget t) {
        if (t == null){
            return "";
        }
        switch (t.type) {
            case LauncherDumpProto.DumpTarget.Type.ITEM:
                return getItemStr(t);
            case LauncherDumpProto.DumpTarget.Type.CONTAINER:
                String str = LoggerUtils.getFieldName(t.containerType, ContainerType.class);
                if (t.containerType == ContainerType.WORKSPACE) {
                    str += " id=" + t.pageId;
                } else if (t.containerType == ContainerType.FOLDER) {
                    str += " grid(" + t.gridX + "," + t.gridY+ ")";
                }
                return str;
            default:
                return "UNKNOWN TARGET TYPE";
        }
    }

    private static String getItemStr(DumpTarget t) {
        String typeStr = LoggerUtils.getFieldName(t.itemType, ItemType.class);
        if (!TextUtils.isEmpty(t.packageName)) {
            typeStr += ", package=" + t.packageName;
        }
        if (!TextUtils.isEmpty(t.component)) {
            typeStr += ", component=" + t.component;
        }
        return typeStr + ", grid(" + t.gridX + "," + t.gridY + "), span(" + t.spanX + "," + t.spanY
                + "), pageIdx=" + t.pageId + " user=" + t.userType;
    }

    public DumpTarget writeToDumpTarget(ItemInfo info) {
        node.component = info.getTargetComponent() == null? "":
                info.getTargetComponent().flattenToString();
        node.packageName = info.getIntent() == null? "": info.getIntent().getPackage();
        node.gridX = info.cellX;
        node.gridY = info.cellY;
        node.spanX = info.spanX;
        node.spanY = info.spanY;
        node.userType = (info.user.equals(Process.myUserHandle()))? UserType.DEFAULT : UserType.WORK;
        return node;
    }
}
+26 −7
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3.logging;

import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.SparseArray;
import android.view.View;
@@ -27,7 +43,7 @@ public class LoggerUtils {
    private static final ArrayMap<Class, SparseArray<String>> sNameCache = new ArrayMap<>();
    private static final String UNKNOWN = "UNKNOWN";

    private static String getFieldName(int value, Class c) {
    public static String getFieldName(int value, Class c) {
        SparseArray<String> cache;
        synchronized (sNameCache) {
            cache = sNameCache.get(c);
@@ -68,8 +84,13 @@ public class LoggerUtils {
            case Target.Type.CONTROL:
                return getFieldName(t.controlType, ControlType.class);
            case Target.Type.CONTAINER:
                return getFieldName(t.containerType, ContainerType.class)
                        + " id=" + t.pageIndex;
                String str = getFieldName(t.containerType, ContainerType.class);
                if (t.containerType == ContainerType.WORKSPACE) {
                    str += " id=" + t.pageIndex;
                } else if (t.containerType == ContainerType.FOLDER) {
                    str += " grid(" + t.gridX + "," + t.gridY+ ")";
                }
                return str;
            default:
                return "UNKNOWN TARGET TYPE";
        }
@@ -86,10 +107,8 @@ public class LoggerUtils {
        if (t.intentHash != 0) {
            typeStr += ", intentHash=" + t.intentHash;
        }
        if (t.spanX != 0) {
            typeStr += ", spanX=" + t.spanX;
        }
        return typeStr + ", grid=(" + t.gridX + "," + t.gridY + "), id=" + t.pageIndex;
        return typeStr + ", grid(" + t.gridX + "," + t.gridY + "), span(" + t.spanX + "," + t.spanY
                + "), pageIdx=" + t.pageIndex;
    }

    public static Target newItemTarget(View v) {
Loading