Merge "Add StatsLog*Manager for logging. Bug: 113043444" into ub-launcher3-master

This commit is contained in:
Hyunyoung Song 2018-11-05 20:04:59 +00:00 committed by Android (Google) Code Review
commit 08584e18d6
16 changed files with 271 additions and 66 deletions

Binary file not shown.

View File

@ -20,6 +20,8 @@
<string name="user_event_dispatcher_class" translatable="false">com.android.quickstep.logging.UserEventDispatcherExtension</string>
<string name="stats_log_manager_class" translatable="false">com.android.quickstep.logging.StatsLogCompatManager</string>
<!-- The number of thumbnails and icons to keep in the cache. The thumbnail cache size also
determines how many thumbnails will be fetched in the background. -->
<integer name="recentsThumbnailCacheSize">3</integer>

View File

@ -0,0 +1,105 @@
/*
* Copyright (C) 2018 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.quickstep.logging;
import android.content.Context;
import android.content.Intent;
import android.stats.launcher.nano.LauncherExtension;
import android.stats.launcher.nano.LauncherTarget;
import static android.stats.launcher.nano.Launcher.ALLAPPS;
import static android.stats.launcher.nano.Launcher.HOME;
import static android.stats.launcher.nano.Launcher.LAUNCH_APP;
import static android.stats.launcher.nano.Launcher.LAUNCH_TASK;
import static android.stats.launcher.nano.Launcher.BACKGROUND;
import static android.stats.launcher.nano.Launcher.OVERVIEW;
import android.view.View;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.logging.StatsLogUtils;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ComponentKey;
import com.android.systemui.shared.system.StatsLogCompat;
import com.google.protobuf.nano.MessageNano;
import androidx.annotation.Nullable;
/**
* This method calls the StatsLog hidden method until they are made available public.
*
* To see if the logs are properly sent to statsd, execute following command.
* $ adb root && adb shell statsd
* $ adb shell cmd stats print-logs
* $ adb logcat | grep statsd OR $ adb logcat -b stats
*/
public class StatsLogCompatManager extends StatsLogManager {
private static final int SUPPORTED_TARGET_DEPTH = 2;
public StatsLogCompatManager(Context context) { }
@Override
public void logAppLaunch(View v, Intent intent) {
LauncherExtension ext = new LauncherExtension();
ext.srcTarget = new LauncherTarget[SUPPORTED_TARGET_DEPTH];
int srcState = mStateProvider.getCurrentState();
fillInLauncherExtension(v, ext);
StatsLogCompat.write(LAUNCH_APP, srcState, BACKGROUND /* dstState */,
MessageNano.toByteArray(ext), true);
}
@Override
public void logTaskLaunch(View v, ComponentKey componentKey) {
LauncherExtension ext = new LauncherExtension();
ext.srcTarget = new LauncherTarget[SUPPORTED_TARGET_DEPTH];
int srcState = OVERVIEW;
fillInLauncherExtension(v, ext);
StatsLogCompat.write(LAUNCH_TASK, srcState, BACKGROUND /* dstState */,
MessageNano.toByteArray(ext), true);
}
public static boolean fillInLauncherExtension(View v, LauncherExtension extension) {
StatsLogUtils.LogContainerProvider provider = StatsLogUtils.getLaunchProviderRecursive(v);
if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
return false;
}
ItemInfo itemInfo = (ItemInfo) v.getTag();
Target child = new Target();
Target parent = new Target();
provider.fillInLogContainerData(v, itemInfo, child, parent);
copy(child, extension.srcTarget[0]);
copy(parent, extension.srcTarget[1]);
return true;
}
private static void copy(Target src, LauncherTarget dst) {
// fill in
}
@Override
public void verify() {
if(!(StatsLogUtils.LAUNCHER_STATE_ALLAPPS == ALLAPPS &&
StatsLogUtils.LAUNCHER_STATE_BACKGROUND == BACKGROUND &&
StatsLogUtils.LAUNCHER_STATE_OVERVIEW == OVERVIEW &&
StatsLogUtils.LAUNCHER_STATE_HOME == HOME)) {
throw new IllegalStateException(
"StatsLogUtil constants doesn't match enums in launcher.proto");
}
}
}

View File

@ -34,6 +34,7 @@ import com.android.systemui.shared.system.MetricsLoggerCompat;
* quickstep interactions.
*/
@SuppressWarnings("unused")
@Deprecated
public class UserEventDispatcherExtension extends UserEventDispatcher {
private static final String TAG = "UserEventDispatcher";

View File

@ -168,9 +168,12 @@ public class TaskView extends FrameLayout implements PageCallbacks {
return;
}
launchTask(true /* animate */);
fromContext(context).getUserEventDispatcher().logTaskLaunchOrDismiss(
Touch.TAP, Direction.NONE, getRecentsView().indexOfChild(this),
TaskUtils.getLaunchComponentKeyForTask(getTask().key));
fromContext(context).getStatsLogManager().logTaskLaunch(getRecentsView(),
TaskUtils.getLaunchComponentKeyForTask(getTask().key));
});
setOutlineProvider(new TaskOutlineProvider(getResources()));
}

View File

@ -84,6 +84,7 @@
<string name="icon_provider_class" translatable="false"></string>
<string name="drawable_factory_class" translatable="false"></string>
<string name="user_event_dispatcher_class" translatable="false"></string>
<string name="stats_log_manager_class" translatable="false"></string>
<string name="app_transition_manager_class" translatable="false"></string>
<string name="instant_app_resolver_class" translatable="false"></string>
<string name="main_process_initializer_class" translatable="false"></string>

View File

@ -28,6 +28,9 @@ import android.view.ContextThemeWrapper;
import android.view.View.AccessibilityDelegate;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.logging.StatsLogUtils;
import com.android.launcher3.logging.StatsLogUtils.LogStateProvider;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
import com.android.launcher3.uioverrides.UiFactory;
@ -41,7 +44,7 @@ import java.util.ArrayList;
import androidx.annotation.IntDef;
public abstract class BaseActivity extends Activity implements UserEventDelegate{
public abstract class BaseActivity extends Activity implements UserEventDelegate, LogStateProvider{
public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0;
public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1;
@ -72,6 +75,7 @@ public abstract class BaseActivity extends Activity implements UserEventDelegate
protected DeviceProfile mDeviceProfile;
protected UserEventDispatcher mUserEventDispatcher;
protected StatsLogManager mStatsLogManager;
protected SystemUiController mSystemUiController;
private static final int ACTIVITY_STATE_STARTED = 1 << 0;
@ -104,8 +108,17 @@ public abstract class BaseActivity extends Activity implements UserEventDelegate
return null;
}
public int getCurrentState() { return StatsLogUtils.LAUNCHER_STATE_BACKGROUND; }
public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {}
public final StatsLogManager getStatsLogManager() {
if (mStatsLogManager == null) {
mStatsLogManager = StatsLogManager.newInstance(this, this);
}
return mStatsLogManager;
}
public final UserEventDispatcher getUserEventDispatcher() {
if (mUserEventDispatcher == null) {
mUserEventDispatcher = UserEventDispatcher.newInstance(this, this);

View File

@ -200,6 +200,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
}
getUserEventDispatcher().logAppLaunch(v, intent);
getStatsLogManager().logAppLaunch(v, intent);
return true;
} catch (ActivityNotFoundException|SecurityException e) {
Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();

View File

@ -19,7 +19,7 @@ package com.android.launcher3;
import android.view.View;
import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider;
import com.android.launcher3.logging.StatsLogUtils.LogContainerProvider;
/**
* Interface defining an object that can originate a drag.

View File

@ -26,7 +26,7 @@ import android.view.ViewDebug;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider;
import com.android.launcher3.logging.StatsLogUtils.LogContainerProvider;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;

View File

@ -91,6 +91,7 @@ import com.android.launcher3.icons.IconCache;
import com.android.launcher3.keyboard.CustomActionsPopup;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.logging.StatsLogUtils;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
import com.android.launcher3.model.ModelWriter;
@ -1609,6 +1610,16 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
}
@Override
public int getCurrentState() {
if(mStateManager.getState() == LauncherState.ALL_APPS) {
return StatsLogUtils.LAUNCHER_STATE_ALLAPPS;
} else if (mStateManager.getState() == LauncherState.OVERVIEW) {
return StatsLogUtils.LAUNCHER_STATE_OVERVIEW;
}
return StatsLogUtils.LAUNCHER_STATE_BACKGROUND;
}
@Override
public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {
if (event.srcTarget != null && event.srcTarget.length > 0 &&

View File

@ -33,7 +33,7 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider;
import com.android.launcher3.logging.StatsLogUtils.LogContainerProvider;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.views.RecyclerViewFastScroller;

View File

@ -40,6 +40,7 @@ import java.lang.reflect.Modifier;
/**
* Helper methods for logging.
*/
@Deprecated
public class LoggerUtils {
private static final ArrayMap<Class, SparseArray<String>> sNameCache = new ArrayMap<>();
private static final String UNKNOWN = "UNKNOWN";

View File

@ -0,0 +1,46 @@
/*
* Copyright (C) 2018 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.content.Context;
import android.content.Intent;
import android.view.View;
import com.android.launcher3.R;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ResourceBasedOverride;
import com.android.launcher3.logging.StatsLogUtils.LogStateProvider;
/**
* Handles the user event logging in Q.
* Since the AOSP Launcher3 doesn't take part in the StatsLog logging, the class
* itself is abstract.
*/
public abstract class StatsLogManager implements ResourceBasedOverride {
protected LogStateProvider mStateProvider;
public static StatsLogManager newInstance(Context context, LogStateProvider stateProvider) {
StatsLogManager mgr = Overrides.getObject(StatsLogManager.class,
context.getApplicationContext(), R.string.stats_log_manager_class);
mgr.mStateProvider = stateProvider;
mgr.verify();
return mgr;
}
public void logAppLaunch(View v, Intent intent) { }
public void logTaskLaunch(View v, ComponentKey key) { }
public void verify() {} // TODO: should move into robo tests
}

View File

@ -0,0 +1,67 @@
package com.android.launcher3.logging;
import android.view.View;
import android.view.ViewParent;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import androidx.annotation.Nullable;
public class StatsLogUtils {
// Defined in android.stats.launcher.nano
// As they cannot be linked in this file, defining again.
public final static int LAUNCHER_STATE_BACKGROUND = 0;
public final static int LAUNCHER_STATE_HOME = 1;
public final static int LAUNCHER_STATE_OVERVIEW = 2;
public final static int LAUNCHER_STATE_ALLAPPS = 3;
private final static int MAXIMUM_VIEW_HIERARCHY_LEVEL = 5;
public interface LogStateProvider {
int getCurrentState();
}
/**
* Implemented by containers to provide a container source for a given child.
*
* Currently,
*/
public interface LogContainerProvider {
/**
* Copies data from the source to the destination proto.
*
* @param v source of the data
* @param info source of the data
* @param target dest of the data
* @param targetParent dest of the data
*/
void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent);
}
/**
* Recursively finds the parent of the given child which implements IconLogInfoProvider
*/
public static LogContainerProvider getLaunchProviderRecursive(@Nullable View v) {
ViewParent parent;
if (v != null) {
parent = v.getParent();
} else {
return null;
}
// Optimization to only check up to 5 parents.
int count = MAXIMUM_VIEW_HIERARCHY_LEVEL;
while (parent != null && count-- > 0) {
if (parent instanceof LogContainerProvider) {
return (LogContainerProvider) parent;
} else {
parent = parent.getParent();
}
}
return null;
}
}

View File

@ -41,9 +41,9 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.logging.StatsLogUtils.LogContainerProvider;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ComponentKey;
@ -62,10 +62,9 @@ import androidx.annotation.Nullable;
*
* $ adb shell setprop log.tag.UserEvent VERBOSE
*/
@Deprecated
public class UserEventDispatcher implements ResourceBasedOverride {
private final static int MAXIMUM_VIEW_HIERARCHY_LEVEL = 5;
private static final String TAG = "UserEvent";
private static final boolean IS_VERBOSE =
FeatureFlags.IS_DOGFOOD_BUILD && Utilities.isPropertyEnabled(LogConfig.USEREVENT);
@ -96,42 +95,19 @@ public class UserEventDispatcher implements ResourceBasedOverride {
}
/**
* Implemented by containers to provide a container source for a given child.
* Fills in the container data on the given event if the given view is not null.
* @return whether container data was added.
*/
public interface LogContainerProvider {
/**
* Copies data from the source to the destination proto.
*
* @param v source of the data
* @param info source of the data
* @param target dest of the data
* @param targetParent dest of the data
*/
void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent);
}
/**
* Recursively finds the parent of the given child which implements IconLogInfoProvider
*/
public static LogContainerProvider getLaunchProviderRecursive(@Nullable View v) {
ViewParent parent;
if (v != null) {
parent = v.getParent();
} else {
return null;
@Deprecated
public static boolean fillInLogContainerData(LauncherLogProto.LauncherEvent event, @Nullable View v) {
// Fill in grid(x,y), pageIndex of the child and container type of the parent
LogContainerProvider provider = StatsLogUtils.getLaunchProviderRecursive(v);
if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
return false;
}
// Optimization to only check up to 5 parents.
int count = MAXIMUM_VIEW_HIERARCHY_LEVEL;
while (parent != null && count-- > 0) {
if (parent instanceof LogContainerProvider) {
return (LogContainerProvider) parent;
} else {
parent = parent.getParent();
}
}
return null;
ItemInfo itemInfo = (ItemInfo) v.getTag();
provider.fillInLogContainerData(v, itemInfo, event.srcTarget[0], event.srcTarget[1]);
return true;
}
private boolean mSessionStarted;
@ -150,21 +126,7 @@ public class UserEventDispatcher implements ResourceBasedOverride {
// intentHash required
// --------------------------------------------------------------
/**
* Fills in the container data on the given event if the given view is not null.
* @return whether container data was added.
*/
protected boolean fillInLogContainerData(LauncherEvent event, @Nullable View v) {
// Fill in grid(x,y), pageIndex of the child and container type of the parent
LogContainerProvider provider = getLaunchProviderRecursive(v);
if (v == null || !(v.getTag() instanceof ItemInfo) || provider == null) {
return false;
}
ItemInfo itemInfo = (ItemInfo) v.getTag();
provider.fillInLogContainerData(v, itemInfo, event.srcTarget[0], event.srcTarget[1]);
return true;
}
@Deprecated
public void logAppLaunch(View v, Intent intent) {
LauncherEvent event = newLauncherEvent(newTouchAction(Action.Touch.TAP),
newItemTarget(v, mInstantAppResolver), newTarget(Target.Type.CONTAINER));
@ -181,6 +143,7 @@ public class UserEventDispatcher implements ResourceBasedOverride {
public void logActionTip(int actionType, int viewType) { }
@Deprecated
public void logTaskLaunchOrDismiss(int action, int direction, int taskIndex,
ComponentKey componentKey) {
LauncherEvent event = newLauncherEvent(newTouchAction(action), // TAP or SWIPE or FLING
@ -363,7 +326,7 @@ public class UserEventDispatcher implements ResourceBasedOverride {
}
public void logDeepShortcutsOpen(View icon) {
LogContainerProvider provider = getLaunchProviderRecursive(icon);
LogContainerProvider provider = StatsLogUtils.getLaunchProviderRecursive(icon);
if (icon == null || !(icon.getTag() instanceof ItemInfo)) {
return;
}
@ -376,15 +339,6 @@ public class UserEventDispatcher implements ResourceBasedOverride {
resetElapsedContainerMillis("deep shortcut open");
}
/* Currently we are only interested in whether this event happens or not and don't
* care about which screen moves to where. */
public void logOverviewReorder() {
LauncherEvent event = newLauncherEvent(newTouchAction(Action.Touch.DRAGDROP),
newContainerTarget(ContainerType.WORKSPACE),
newContainerTarget(ContainerType.OVERVIEW));
dispatchUserEvent(event, null);
}
public void logDragNDrop(DropTarget.DragObject dragObj, View dropTargetAsView) {
LauncherEvent event = newLauncherEvent(newTouchAction(Action.Touch.DRAGDROP),
newItemTarget(dragObj.originalDragInfo, mInstantAppResolver),