ApexManager: Post populateAllPackagesCacheIfNeeded to a background thread

populateAllPackagesCacheIfNeeded is rather expensive method and
shouldn't be run in broadcast handler thread (it was my mistake to
suggest this in ag/9204784).

It's fine to use background thread to execute
populateAllPackagesCacheIfNeeded because components that need
to match APEX are not doing it on user critical path.

Bug: 138460874
Test: adb shell pm list packages --apex-only --show-versioncode
Change-Id: Ib17fadb978f112c26c113e3bc42b9edaeeefca8a
This commit is contained in:
Nikita Ioffe
2019-08-23 18:26:31 +01:00
parent 9727c0581a
commit 8d3253599b

View File

@@ -261,11 +261,12 @@ abstract class ApexManager {
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
populateAllPackagesCacheIfNeeded();
// Post populateAllPackagesCacheIfNeeded to a background thread, since it's
// expensive to run it in broadcast handler thread.
BackgroundThread.getHandler().post(() -> populateAllPackagesCacheIfNeeded());
mContext.unregisterReceiver(this);
}
}, new IntentFilter(Intent.ACTION_BOOT_COMPLETED), /* broadcastPermission */ null,
BackgroundThread.getHandler());
}, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
}
private void populateAllPackagesCacheIfNeeded() {