Merge "Moving methods which update internal sets on a separate thread" into ub-now-queens

This commit is contained in:
Sunny Goyal 2014-11-03 20:11:05 +00:00 committed by Android (Google) Code Review
commit 45634bf8fb
1 changed files with 24 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionCallback;
import android.content.pm.PackageInstaller.SessionInfo;
import android.os.Handler;
import android.util.Log;
import android.util.SparseArray;
@ -29,15 +30,18 @@ import com.android.launcher3.LauncherAppState;
import java.util.ArrayList;
import java.util.HashSet;
public class PackageInstallerCompatVL extends PackageInstallerCompat {
public class PackageInstallerCompatVL extends PackageInstallerCompat implements Runnable {
private static final String TAG = "PackageInstallerCompatVL";
private static final boolean DEBUG = false;
// All updates to these sets must happen on the {@link #mWorker} thread.
private final SparseArray<SessionInfo> mPendingReplays = new SparseArray<SessionInfo>();
private final HashSet<String> mPendingBadgeUpdates = new HashSet<String>();
private final PackageInstaller mInstaller;
private final IconCache mCache;
private final Handler mWorker;
private boolean mResumed;
private boolean mBound;
@ -46,16 +50,23 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
mInstaller = context.getPackageManager().getPackageInstaller();
LauncherAppState.setApplicationContext(context.getApplicationContext());
mCache = LauncherAppState.getInstance().getIconCache();
mWorker = new Handler();
mResumed = false;
mBound = false;
mInstaller.registerSessionCallback(mCallback);
mInstaller.registerSessionCallback(mCallback, mWorker);
// On start, send updates for all active sessions
for (SessionInfo info : mInstaller.getAllSessions()) {
mPendingReplays.append(info.getSessionId(), info);
}
mWorker.post(new Runnable() {
@Override
public void run() {
for (SessionInfo info : mInstaller.getAllSessions()) {
mPendingReplays.append(info.getSessionId(), info);
}
}
});
}
@Override
@ -87,7 +98,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
@Override
public void onFinishBind() {
mBound = true;
replayUpdates(null);
mWorker.post(this);
}
@Override
@ -98,7 +109,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
@Override
public void onResume() {
mResumed = true;
replayUpdates(null);
mWorker.post(this);
}
@Override
@ -106,6 +117,12 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
// No op
}
@Override
public void run() {
// Called on mWorker thread.
replayUpdates(null);
}
private void replayUpdates(PackageInstallInfo newInfo) {
if (DEBUG) Log.d(TAG, "updates resumed");
if (!mResumed || !mBound) {