Fixing potantial context leak code path
The javadoc in createUserEventDispatcher suggested that it can be used as a singleton. But it was being constructed as an inner class which would cause context leak when used as singleton Change-Id: I706018d4ab26b506ac936fe1a7304d9b530b820c
This commit is contained in:
@@ -150,7 +150,6 @@ public class Launcher extends Activity
|
||||
static final boolean DEBUG_WIDGETS = false;
|
||||
static final boolean DEBUG_STRICT_MODE = false;
|
||||
static final boolean DEBUG_RESUME_TIME = false;
|
||||
static final boolean DEBUG_LOGGING = false;
|
||||
|
||||
private static final int REQUEST_CREATE_SHORTCUT = 1;
|
||||
private static final int REQUEST_CREATE_APPWIDGET = 5;
|
||||
@@ -628,29 +627,6 @@ public class Launcher extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logger object is a singleton and does not have to be coupled with the foreground activity.
|
||||
* Since most user event logging is done on the UI, the object is retrieved from the
|
||||
* callback for convenience.
|
||||
*/
|
||||
private UserEventDispatcher createUserEventDispatcher() {
|
||||
return new UserEventDispatcher() {
|
||||
@Override
|
||||
public void dispatchUserEvent(LauncherLogProto.LauncherEvent ev, Intent intent) {
|
||||
if (!DEBUG_LOGGING) {
|
||||
return;
|
||||
}
|
||||
Log.d("UserEvent", String.format(Locale.US,
|
||||
"action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
|
||||
LoggerUtils.getActionStr(ev.action),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[0]),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[1]),
|
||||
ev.elapsedContainerMillis,
|
||||
ev.elapsedSessionMillis));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public UserEventDispatcher getUserEventDispatcher() {
|
||||
if (mLauncherCallbacks != null) {
|
||||
UserEventDispatcher dispatcher = mLauncherCallbacks.getUserEventDispatcher();
|
||||
@@ -659,8 +635,11 @@ public class Launcher extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
// Logger object is a singleton and does not have to be coupled with the foreground
|
||||
// activity. Since most user event logging is done on the UI, the object is retrieved
|
||||
// from the callback for convenience.
|
||||
if (mUserEventDispatcher == null) {
|
||||
mUserEventDispatcher = createUserEventDispatcher();
|
||||
mUserEventDispatcher = new UserEventDispatcher();
|
||||
}
|
||||
return mUserEventDispatcher;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.launcher3.logging;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
|
||||
@@ -28,11 +29,14 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Manages the creation of {@link LauncherEvent}.
|
||||
*/
|
||||
public abstract class UserEventDispatcher {
|
||||
public class UserEventDispatcher {
|
||||
|
||||
private static final boolean DEBUG_LOGGING = false;
|
||||
|
||||
private final static int MAXIMUM_VIEW_HIERARCHY_LEVEL = 5;
|
||||
/**
|
||||
@@ -155,7 +159,17 @@ public abstract class UserEventDispatcher {
|
||||
mActionDurationMillis = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public abstract void dispatchUserEvent(LauncherEvent ev, Intent intent);
|
||||
public void dispatchUserEvent(LauncherEvent ev, Intent intent) {
|
||||
if (DEBUG_LOGGING) {
|
||||
Log.d("UserEvent", String.format(Locale.US,
|
||||
"action:%s\nchild:%s\nparent:%s\nelapsed container %d ms session %d ms",
|
||||
LoggerUtils.getActionStr(ev.action),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[0]),
|
||||
LoggerUtils.getTargetStr(ev.srcTarget[1]),
|
||||
ev.elapsedContainerMillis,
|
||||
ev.elapsedSessionMillis));
|
||||
}
|
||||
}
|
||||
|
||||
public int getPredictedRank(ComponentKey key) {
|
||||
if (mPredictedApps == null) return -1;
|
||||
|
||||
Reference in New Issue
Block a user