Merge "Workaround an interpreter behavior to fix leak" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-04-28 14:29:06 +00:00
committed by Android (Google) Code Review

View File

@@ -161,50 +161,7 @@ class BackgroundTaskLoader implements Runnable {
// If we've stopped the loader, then fall through to the above logic to wait on
// the load thread
if (ssp != null) {
// Load the next item from the queue
final Task t = mLoadQueue.nextTask();
if (t != null) {
Drawable cachedIcon = mIconCache.get(t.key);
// Load the icon if it is stale or we haven't cached one yet
if (cachedIcon == null) {
cachedIcon = ssp.getBadgedTaskDescriptionIcon(t.taskDescription,
t.key.userId, mContext.getResources());
if (cachedIcon == null) {
ActivityInfo info = ssp.getActivityInfo(
t.key.getComponent(), t.key.userId);
if (info != null) {
if (DEBUG) Log.d(TAG, "Loading icon: " + t.key);
cachedIcon = ssp.getBadgedActivityIcon(info, t.key.userId);
}
}
if (cachedIcon == null) {
cachedIcon = mDefaultIcon;
}
// At this point, even if we can't load the icon, we will set the
// default icon.
mIconCache.put(t.key, cachedIcon);
}
if (DEBUG) Log.d(TAG, "Loading thumbnail: " + t.key);
ThumbnailData cachedThumbnailData = ssp.getTaskThumbnail(t.key.id,
true /* reducedResolution */);
if (cachedThumbnailData.thumbnail == null) {
cachedThumbnailData.thumbnail = mDefaultThumbnail;
}
if (!mCancelled) {
// Notify that the task data has changed
final Drawable newIcon = cachedIcon;
final ThumbnailData newThumbnailData = cachedThumbnailData;
mMainThreadHandler.post(
() -> t.notifyTaskDataLoaded(newThumbnailData, newIcon));
}
}
processLoadQueueItem(ssp);
}
// If there are no other items in the list, then just wait until something is added
@@ -222,6 +179,57 @@ class BackgroundTaskLoader implements Runnable {
}
}
}
/**
* This needs to be in a separate method to work around an surprising interpreter behavior:
* The register will keep the local reference to cachedThumbnailData even if it falls out of
* scope. Putting it into a method fixes this issue.
*/
private void processLoadQueueItem(SystemServicesProxy ssp) {
// Load the next item from the queue
final Task t = mLoadQueue.nextTask();
if (t != null) {
Drawable cachedIcon = mIconCache.get(t.key);
// Load the icon if it is stale or we haven't cached one yet
if (cachedIcon == null) {
cachedIcon = ssp.getBadgedTaskDescriptionIcon(t.taskDescription,
t.key.userId, mContext.getResources());
if (cachedIcon == null) {
ActivityInfo info = ssp.getActivityInfo(
t.key.getComponent(), t.key.userId);
if (info != null) {
if (DEBUG) Log.d(TAG, "Loading icon: " + t.key);
cachedIcon = ssp.getBadgedActivityIcon(info, t.key.userId);
}
}
if (cachedIcon == null) {
cachedIcon = mDefaultIcon;
}
// At this point, even if we can't load the icon, we will set the
// default icon.
mIconCache.put(t.key, cachedIcon);
}
if (DEBUG) Log.d(TAG, "Loading thumbnail: " + t.key);
final ThumbnailData cachedThumbnailData = ssp.getTaskThumbnail(t.key.id,
true /* reducedResolution */);
if (cachedThumbnailData.thumbnail == null) {
cachedThumbnailData.thumbnail = mDefaultThumbnail;
}
if (!mCancelled) {
// Notify that the task data has changed
final Drawable finalIcon = cachedIcon;
mMainThreadHandler.post(
() -> t.notifyTaskDataLoaded(cachedThumbnailData, finalIcon));
}
}
}
}
/**