1 package com.android.launcher3.logging; 2 3 import android.view.View; 4 import android.view.ViewParent; 5 6 import androidx.annotation.Nullable; 7 8 import com.android.launcher3.model.data.ItemInfo; 9 import com.android.launcher3.userevent.nano.LauncherLogProto.Target; 10 11 import java.util.ArrayList; 12 13 public class StatsLogUtils { 14 private final static int MAXIMUM_VIEW_HIERARCHY_LEVEL = 5; 15 16 /** 17 * Implemented by containers to provide a container source for a given child. 18 */ 19 public interface LogContainerProvider { 20 21 /** 22 * Populates parent container targets for an item 23 */ fillInLogContainerData(ItemInfo childInfo, Target child, ArrayList<Target> parents)24 void fillInLogContainerData(ItemInfo childInfo, Target child, ArrayList<Target> parents); 25 } 26 27 /** 28 * Recursively finds the parent of the given child which implements IconLogInfoProvider 29 */ getLaunchProviderRecursive(@ullable View v)30 public static LogContainerProvider getLaunchProviderRecursive(@Nullable View v) { 31 ViewParent parent; 32 if (v != null) { 33 parent = v.getParent(); 34 } else { 35 return null; 36 } 37 38 // Optimization to only check up to 5 parents. 39 int count = MAXIMUM_VIEW_HIERARCHY_LEVEL; 40 while (parent != null && count-- > 0) { 41 if (parent instanceof LogContainerProvider) { 42 return (LogContainerProvider) parent; 43 } else { 44 parent = parent.getParent(); 45 } 46 } 47 return null; 48 } 49 } 50