diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-04-19 23:12:09 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-04-19 23:12:09 -0700 |
commit | d0d7503fd3e941113094532f28986f49b11b5fdb (patch) | |
tree | 98866f30fbc23eceb6e34cc93801c92c93d4c812 /core | |
parent | 5dd32fbcbf750b806175bc8648b6fae280dad576 (diff) | |
download | frameworks_base-d0d7503fd3e941113094532f28986f49b11b5fdb.zip frameworks_base-d0d7503fd3e941113094532f28986f49b11b5fdb.tar.gz frameworks_base-d0d7503fd3e941113094532f28986f49b11b5fdb.tar.bz2 |
Move handling of package changes to a background thread.
Helps get rid of some jank when installing applications.
Change-Id: I97d0022f82d67796e334d37086e5911dd6ca6b62
Diffstat (limited to 'core')
4 files changed, 35 insertions, 10 deletions
diff --git a/core/java/android/server/search/SearchManagerService.java b/core/java/android/server/search/SearchManagerService.java index d78bbbf..c783e6a 100644 --- a/core/java/android/server/search/SearchManagerService.java +++ b/core/java/android/server/search/SearchManagerService.java @@ -69,7 +69,7 @@ public class SearchManagerService extends ISearchManager.Stub { private synchronized Searchables getSearchables() { if (mSearchables == null) { Log.i(TAG, "Building list of searchable activities"); - new MyPackageMonitor().register(mContext, true); + new MyPackageMonitor().register(mContext, null, true); mSearchables = new Searchables(mContext); mSearchables.buildSearchableList(); } diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java index bc44521..c53b5f6 100644 --- a/core/java/android/widget/ActivityChooserModel.java +++ b/core/java/android/widget/ActivityChooserModel.java @@ -365,7 +365,7 @@ public class ActivityChooserModel extends DataSetObservable { } else { mHistoryFileName = historyFileName; } - mPackageMonitor.register(mContext, true); + mPackageMonitor.register(mContext, null, true); } /** diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index af722a8..5862d3e 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -99,7 +99,7 @@ public class ResolverActivity extends AlertActivity implements ap.mTitle = title; ap.mOnClickListener = this; - mPackageMonitor.register(this, false); + mPackageMonitor.register(this, getMainLooper(), false); if (alwaysUseOption) { LayoutInflater inflater = (LayoutInflater) getSystemService( @@ -135,7 +135,7 @@ public class ResolverActivity extends AlertActivity implements @Override protected void onRestart() { super.onRestart(); - mPackageMonitor.register(this, false); + mPackageMonitor.register(this, getMainLooper(), false); mAdapter.handlePackagesChanged(); } diff --git a/core/java/com/android/internal/content/PackageMonitor.java b/core/java/com/android/internal/content/PackageMonitor.java index 32d8641..f41fcc6 100644 --- a/core/java/com/android/internal/content/PackageMonitor.java +++ b/core/java/com/android/internal/content/PackageMonitor.java @@ -21,6 +21,9 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.Uri; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; import java.util.HashSet; @@ -32,7 +35,11 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { static final IntentFilter sPackageFilt = new IntentFilter(); static final IntentFilter sNonDataFilt = new IntentFilter(); static final IntentFilter sExternalFilt = new IntentFilter(); - + + static final Object sLock = new Object(); + static HandlerThread sBackgroundThread; + static Handler sBackgroundHandler; + static { sPackageFilt.addAction(Intent.ACTION_PACKAGE_ADDED); sPackageFilt.addAction(Intent.ACTION_PACKAGE_REMOVED); @@ -49,6 +56,7 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { final HashSet<String> mUpdatingPackages = new HashSet<String>(); Context mRegisteredContext; + Handler mRegisteredHandler; String[] mDisappearingPackages; String[] mAppearingPackages; String[] mModifiedPackages; @@ -57,18 +65,35 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver { String[] mTempArray = new String[1]; - public void register(Context context, boolean externalStorage) { + public void register(Context context, Looper thread, boolean externalStorage) { if (mRegisteredContext != null) { throw new IllegalStateException("Already registered"); } mRegisteredContext = context; - context.registerReceiver(this, sPackageFilt); - context.registerReceiver(this, sNonDataFilt); + if (thread == null) { + synchronized (sLock) { + if (sBackgroundThread == null) { + sBackgroundThread = new HandlerThread("PackageMonitor", + android.os.Process.THREAD_PRIORITY_BACKGROUND); + sBackgroundThread.start(); + sBackgroundHandler = new Handler(sBackgroundThread.getLooper()); + } + mRegisteredHandler = sBackgroundHandler; + } + } else { + mRegisteredHandler = new Handler(thread); + } + context.registerReceiver(this, sPackageFilt, null, mRegisteredHandler); + context.registerReceiver(this, sNonDataFilt, null, mRegisteredHandler); if (externalStorage) { - context.registerReceiver(this, sExternalFilt); + context.registerReceiver(this, sExternalFilt, null, mRegisteredHandler); } } - + + public Handler getRegisteredHandler() { + return mRegisteredHandler; + } + public void unregister() { if (mRegisteredContext == null) { throw new IllegalStateException("Not registered"); |