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

Commit a7d301c5 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #28001806: Background check is incorrectly restricting...

Merge "Fix issue #28001806: Background check is incorrectly restricting binding of services" into nyc-dev
parents 9d8ec0f1 4fb9c4af
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -343,6 +343,25 @@ public final class ActiveServices {
            return null;
        }

        if (!r.startRequested) {
            final long token = Binder.clearCallingIdentity();
            try {
                // Before going further -- if this app is not allowed to run in the
                // background, then at this point we aren't going to let it period.
                final int allowed = mAm.checkAllowBackgroundLocked(
                        r.appInfo.uid, r.packageName, callingPid, true);
                if (allowed != ActivityManager.APP_START_MODE_NORMAL) {
                    Slog.w(TAG, "Background start not allowed: service "
                            + service + " to " + r.name.flattenToShortString()
                            + " from pid=" + callingPid + " uid=" + callingUid
                            + " pkg=" + callingPackage);
                    return null;
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        NeededUriGrants neededGrants = mAm.checkGrantUriPermissionFromIntentLocked(
                callingUid, r.packageName, service, service.getFlags(), null, r.userId);

@@ -1274,23 +1293,6 @@ public final class ActiveServices {
                }
                r = smap.mServicesByName.get(name);
                if (r == null && createIfNeeded) {
                    final long token = Binder.clearCallingIdentity();
                    try {
                        // Before going further -- if this app is not allowed to run in the
                        // background, then at this point we aren't going to let it period.
                        final int allowed = mAm.checkAllowBackgroundLocked(
                                sInfo.applicationInfo.uid, sInfo.packageName, callingPid, true);
                        if (allowed != ActivityManager.APP_START_MODE_NORMAL) {
                            Slog.w(TAG, "Background execution not allowed: service "
                                    + service + " to " + name.flattenToShortString()
                                    + " from pid=" + callingPid + " uid=" + callingUid
                                    + " pkg=" + callingPackage);
                            return null;
                        }
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }

                    Intent.FilterComparison filter
                            = new Intent.FilterComparison(service.cloneFilter());
                    ServiceRestarter res = new ServiceRestarter();