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

Commit a27780e0 authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Use self-locking for mAvailableFeatures

mAvailableFeatures is read-only and set in the constructor. Calls to
hasSystemFeature are often blocked if PM is busy with other operations.

Test: manual - device boots without errors
Bug: 33199244
Change-Id: I5ce0fa7af37e95ac64afb11a1022a27e37c67703
parent b3f0849c
Loading
Loading
Loading
Loading
+27 −23
Original line number Diff line number Diff line
@@ -712,6 +712,7 @@ public class PackageManagerService extends IPackageManager.Stub {
    // System configuration read by SystemConfig.
    final int[] mGlobalGids;
    final SparseArray<ArraySet<String>> mSystemPermissions;
    @GuardedBy("mAvailableFeatures")
    final ArrayMap<String, FeatureInfo> mAvailableFeatures;
    // If mac_permissions.xml was found for seinfo labeling.
@@ -4215,9 +4216,11 @@ public class PackageManagerService extends IPackageManager.Stub {
    @Override
    public @NonNull ParceledListSlice<FeatureInfo> getSystemAvailableFeatures() {
        synchronized (mPackages) {
            final ArrayList<FeatureInfo> res = new ArrayList<>(mAvailableFeatures.values());
        ArrayList<FeatureInfo> res;
        synchronized (mAvailableFeatures) {
            res = new ArrayList<>(mAvailableFeatures.size() + 1);
            res.addAll(mAvailableFeatures.values());
        }
        final FeatureInfo fi = new FeatureInfo();
        fi.reqGlEsVersion = SystemProperties.getInt("ro.opengles.version",
                FeatureInfo.GL_ES_VERSION_UNDEFINED);
@@ -4225,11 +4228,10 @@ public class PackageManagerService extends IPackageManager.Stub {
        return new ParceledListSlice<>(res);
    }
    }
    @Override
    public boolean hasSystemFeature(String name, int version) {
        synchronized (mPackages) {
        synchronized (mAvailableFeatures) {
            final FeatureInfo feat = mAvailableFeatures.get(name);
            if (feat == null) {
                return false;
@@ -20379,6 +20381,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
                    pw.println("Features:");
                }
                synchronized (mAvailableFeatures) {
                    for (FeatureInfo feat : mAvailableFeatures.values()) {
                        if (checkin) {
                            pw.print("feat,");
@@ -20396,6 +20399,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
                        }
                    }
                }
            }
            if (!checkin && dumpState.isDumping(DumpState.DUMP_ACTIVITY_RESOLVERS)) {
                if (mActivities.dump(pw, dumpState.getTitlePrinted() ? "\nActivity Resolver Table:"