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

Commit 41febcaf authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add delivery group policy for PACKAGE_CHANGED broadcast to allow...

Merge "Add delivery group policy for PACKAGE_CHANGED broadcast to allow merging broadcasts" into main
parents a99aee7a 1bf1b80c
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -288,6 +288,17 @@
                   "exclude-annotation":"org.junit.Ignore"
               }
            ]
        },
        {
            "name": "CtsPackageManagerBroadcastTestCases",
            "options":[
                {
                    "exclude-annotation":"androidx.test.filters.FlakyTest"
                },
                {
                    "exclude-annotation":"org.junit.Ignore"
                }
            ]
        }
    ],
    "presubmit-large":[
@@ -523,6 +534,17 @@
                   "exclude-annotation":"org.junit.Ignore"
               }
            ]
        },
        {
            "name": "CtsPackageManagerBroadcastTestCases",
            "options":[
                {
                    "exclude-annotation":"androidx.test.filters.FlakyTest"
                },
                {
                    "exclude-annotation":"org.junit.Ignore"
                }
            ]
        }
    ]
}
+8 −0
Original line number Diff line number Diff line
@@ -338,3 +338,11 @@ flag {
    description: "Feature flag to enable protecting Supervision packages."
    bug: "404779514"
}

flag {
    name: "merge_package_changed_broadcast"
    namespace: "package_manager_service"
    description: "Feature flag to add delivery group policy for PACKAGE_CHANGED broadcast to allow merging broadcasts."
    bug: "381949725"
    is_fixed_read_only: true
}
+32 −13
Original line number Diff line number Diff line
@@ -362,17 +362,35 @@ public final class BroadcastHelper {
        final boolean isForWholeApp = componentNames.contains(packageName);
        final String callingPackageNameForTrace = mContext.getPackageManager().getNameForUid(
                callingUidForTrace);
        if (isForWholeApp || !android.content.pm.Flags.reduceBroadcastsForComponentStateChanges()) {
            tracePackageChangedBroadcastEvent(
                    android.content.pm.Flags.reduceBroadcastsForComponentStateChanges(),
                    reasonForTrace, packageName, "<implicit>" /* targetPackageName */,
                    "whole" /* targetComponent */, componentNames.size(),
                    callingPackageNameForTrace);
        if (!android.content.pm.Flags.reduceBroadcastsForComponentStateChanges()) {
            tracePackageChangedBroadcastEvent(false /* applyFlag */, reasonForTrace, packageName,
                    "<implicit>" /* targetPackageName */, "whole" /* targetComponent */,
                    componentNames.size(), callingPackageNameForTrace);
            sendPackageChangedBroadcastWithPermissions(packageName, dontKillApp, componentNames,
                    packageUid, reason, userIds, instantUserIds, broadcastAllowList,
                    null /* targetPackageName */, null /* requiredPermissions */);
                    null /* targetPackageName */, null /* requiredPermissions */,
                    null /* bOptions */);
            return;
        }

        if (isForWholeApp) {
            tracePackageChangedBroadcastEvent(true /* applyFlag */, reasonForTrace, packageName,
                    "<implicit>" /* targetPackageName */, "whole" /* targetComponent */,
                    componentNames.size(), callingPackageNameForTrace);
            Bundle bOptions = null;
            if (android.content.pm.Flags.mergePackageChangedBroadcast()) {
                bOptions = new BroadcastOptions()
                        .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
                        .setDeliveryGroupMatchingKey(Intent.ACTION_PACKAGE_CHANGED,
                                packageName + "-" + packageUid)
                        .toBundle();
            }
            sendPackageChangedBroadcastWithPermissions(packageName, dontKillApp, componentNames,
                    packageUid, reason, userIds, instantUserIds, broadcastAllowList,
                    null /* targetPackageName */, null /* requiredPermissions */, bOptions);
            return;
        }

        // Currently only these four components of activity, receiver, provider and service are
        // considered to send only the broadcast to the system and the application itself when the
        // component is not exported. In order to avoid losing to send the broadcast for other
@@ -395,7 +413,7 @@ public final class BroadcastHelper {
                sendPackageChangedBroadcastWithPermissions(packageName, dontKillApp,
                        notExportedComponentNames, packageUid, reason, userIds, instantUserIds,
                        broadcastAllowList, "android" /* targetPackageName */,
                        null /* requiredPermissions */);
                        null /* requiredPermissions */, null /* bOptions */);
            }

            // Second, send the PACKAGE_CHANGED broadcast to the application itself.
@@ -405,7 +423,7 @@ public final class BroadcastHelper {
            sendPackageChangedBroadcastWithPermissions(packageName, dontKillApp,
                    notExportedComponentNames, packageUid, reason, userIds, instantUserIds,
                    broadcastAllowList, packageName /* targetPackageName */,
                    null /* requiredPermissions */);
                    null /* requiredPermissions */, null /* bOptions */);

            // Third, send the PACKAGE_CHANGED broadcast to the applications with the same UID.
            for (int i = 0; i < sharedUidPackages.length; i++) {
@@ -419,7 +437,7 @@ public final class BroadcastHelper {
                sendPackageChangedBroadcastWithPermissions(packageName, dontKillApp,
                        notExportedComponentNames, packageUid, reason, userIds, instantUserIds,
                        broadcastAllowList, sharedPackage /* targetPackageName */,
                        null /* requiredPermissions */);
                        null /* requiredPermissions */, null /* bOptions */);
            }

        }
@@ -431,7 +449,7 @@ public final class BroadcastHelper {
            sendPackageChangedBroadcastWithPermissions(packageName, dontKillApp,
                    exportedComponentNames, packageUid, reason, userIds, instantUserIds,
                    broadcastAllowList, null /* targetPackageName */,
                    null /* requiredPermissions */);
                    null /* requiredPermissions */, null /* bOptions */);
        }
    }

@@ -444,7 +462,8 @@ public final class BroadcastHelper {
            @Nullable int[] instantUserIds,
            @Nullable SparseArray<int[]> broadcastAllowList,
            @Nullable String targetPackageName,
            @Nullable String[] requiredPermissions) {
            @Nullable String[] requiredPermissions,
            @Nullable Bundle bOptions) {
        if (DEBUG_INSTALL) {
            Log.v(TAG, "Sending package changed: package=" + packageName + " components="
                    + componentNames);
@@ -466,7 +485,7 @@ public final class BroadcastHelper {
                ? Intent.FLAG_RECEIVER_REGISTERED_ONLY : 0;
        sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, flags,
                targetPackageName, null /* finishedReceiver */, userIds, instantUserIds,
                broadcastAllowList, null /* filterExtrasForReceiver */, null /* bOptions */,
                broadcastAllowList, null /* filterExtrasForReceiver */, bOptions,
                requiredPermissions);
    }

+22 −0
Original line number Diff line number Diff line
@@ -355,6 +355,17 @@
              "exclude-annotation":"org.junit.Ignore"
          }
      ]
    },
    {
      "name": "CtsPackageManagerBroadcastTestCases",
      "options":[
        {
          "exclude-annotation":"androidx.test.filters.FlakyTest"
        },
        {
          "exclude-annotation":"org.junit.Ignore"
        }
      ]
    }
  ],
  "presubmit-large":[
@@ -670,6 +681,17 @@
              "exclude-annotation":"org.junit.Ignore"
          }
      ]
    },
    {
      "name": "CtsPackageManagerBroadcastTestCases",
      "options":[
        {
          "exclude-annotation":"androidx.test.filters.FlakyTest"
        },
        {
          "exclude-annotation":"org.junit.Ignore"
        }
      ]
    }
  ],
  "imports": [