summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2014-10-30 17:16:49 (GMT)
committerDanesh M <daneshm90@gmail.com>2015-09-28 02:00:37 (GMT)
commit7dfa47353bacd2149a61cc2261c9a60f2e22825f (patch)
tree4959da3c515cbe84100a939edd48b3b8740fa542
parent8c381f0d7a02b1702139248ec129ff6c3ced3ee3 (diff)
downloadandroid_packages_apps_Trebuchet-7dfa47353bacd2149a61cc2261c9a60f2e22825f.zip
android_packages_apps_Trebuchet-7dfa47353bacd2149a61cc2261c9a60f2e22825f.tar.gz
android_packages_apps_Trebuchet-7dfa47353bacd2149a61cc2261c9a60f2e22825f.tar.bz2
Moving methods which update internal sets on a separate thread
Bug: 18152117 Change-Id: I5fccd203b5fe65e79dcc5aead6cb1cb6c3b622fe
-rw-r--r--src/com/android/launcher3/compat/PackageInstallerCompatVL.java31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
index 16ad379..ccfac9a 100644
--- a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
+++ b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
@@ -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
@@ -86,7 +97,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
@Override
public void onFinishBind() {
mBound = true;
- replayUpdates(null);
+ mWorker.post(this);
}
@Override
@@ -97,7 +108,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
@Override
public void onResume() {
mResumed = true;
- replayUpdates(null);
+ mWorker.post(this);
}
@Override
@@ -105,6 +116,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) {