Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d325359 authored by Nikita Ioffe's avatar Nikita Ioffe
Browse files

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
parent 9727c058
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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() {