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

Commit 3a1a0bbc authored by Nicolas Prevot's avatar Nicolas Prevot Committed by Alexandra Gherghina
Browse files

Add a cross-profile intent filter only if it wasn't previously added.

BUG: 17996284
Change-Id: I3d087767983928dfb13af9aedb37d29c9940ba36
parent 9710b04f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -141,4 +141,11 @@ class CrossProfileIntentFilter extends IntentFilter {
        return "CrossProfileIntentFilter{0x" + Integer.toHexString(System.identityHashCode(this))
                + " " + Integer.toString(mTargetUserId) + "}";
    }

    boolean equalsIgnoreFilter(CrossProfileIntentFilter other) {
        return mTargetUserId == other.mTargetUserId
                && mOwnerUserId == other.mOwnerUserId
                && mOwnerPackage.equals(other.mOwnerPackage)
                && mFlags == other.mFlags;
    }
}
+14 −2
Original line number Diff line number Diff line
@@ -11844,9 +11844,21 @@ public class PackageManagerService extends IPackageManager.Stub {
            return;
        }
        synchronized (mPackages) {
            CrossProfileIntentFilter filter = new CrossProfileIntentFilter(intentFilter,
            CrossProfileIntentFilter newFilter = new CrossProfileIntentFilter(intentFilter,
                    ownerPackage, UserHandle.getUserId(callingUid), targetUserId, flags);
            mSettings.editCrossProfileIntentResolverLPw(sourceUserId).addFilter(filter);
            CrossProfileIntentResolver resolver =
                    mSettings.editCrossProfileIntentResolverLPw(sourceUserId);
            ArrayList<CrossProfileIntentFilter> existing = resolver.findFilters(intentFilter);
            // We have all those whose filter is equal. Now checking if the rest is equal as well.
            if (existing != null) {
                int size = existing.size();
                for (int i = 0; i < size; i++) {
                    if (newFilter.equalsIgnoreFilter(existing.get(i))) {
                        return;
                    }
                }
            }
            resolver.addFilter(newFilter);
            scheduleWritePackageRestrictionsLocked(sourceUserId);
        }
    }