• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.logging;
2 
3 import android.view.View;
4 import android.view.ViewParent;
5 
6 import com.android.launcher3.ItemInfo;
7 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
8 
9 import androidx.annotation.Nullable;
10 
11 
12 public class StatsLogUtils {
13 
14     // Defined in android.stats.launcher.nano
15     // As they cannot be linked in this file, defining again.
16     public final static int LAUNCHER_STATE_BACKGROUND = 0;
17     public final static int LAUNCHER_STATE_HOME = 1;
18     public final static int LAUNCHER_STATE_OVERVIEW = 2;
19     public final static int LAUNCHER_STATE_ALLAPPS = 3;
20 
21     private final static int MAXIMUM_VIEW_HIERARCHY_LEVEL = 5;
22 
23     public interface LogStateProvider {
getCurrentState()24         int getCurrentState();
25     }
26 
27     /**
28      * Implemented by containers to provide a container source for a given child.
29      *
30      * Currently,
31      */
32     public interface LogContainerProvider {
33 
34         /**
35          * Copies data from the source to the destination proto.
36          *
37          * @param v            source of the data
38          * @param info         source of the data
39          * @param target       dest of the data
40          * @param targetParent dest of the data
41          */
fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent)42         void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent);
43     }
44 
45     /**
46      * Recursively finds the parent of the given child which implements IconLogInfoProvider
47      */
getLaunchProviderRecursive(@ullable View v)48     public static LogContainerProvider getLaunchProviderRecursive(@Nullable View v) {
49         ViewParent parent;
50         if (v != null) {
51             parent = v.getParent();
52         } else {
53             return null;
54         }
55 
56         // Optimization to only check up to 5 parents.
57         int count = MAXIMUM_VIEW_HIERARCHY_LEVEL;
58         while (parent != null && count-- > 0) {
59             if (parent instanceof LogContainerProvider) {
60                 return (LogContainerProvider) parent;
61             } else {
62                 parent = parent.getParent();
63             }
64         }
65         return null;
66     }
67 }
68