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

Commit dcca9929 authored by Kweku Adams's avatar Kweku Adams Committed by Automerger Merge Worker
Browse files

Merge "Allow package verifier to hide specific fgs notifications." into...

Merge "Allow package verifier to hide specific fgs notifications." into rvc-qpr-dev am: 1706f9c2 am: 769c4f68

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12378562

Change-Id: I38c2c79c41cb82c432fc904f3923625c1f4216c2
parents 617461b3 769c4f68
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -186,6 +186,16 @@ class ContextImpl extends Context {
    private static final String XATTR_INODE_CACHE = "user.inode_cache";
    private static final String XATTR_INODE_CODE_CACHE = "user.inode_code_cache";

    /**
     * Special intent extra that critical system apps can use to hide the notification for a
     * foreground service. This extra should be placed in the intent passed into {@link
     * #startForegroundService(Intent)}.
     *
     * @hide
     */
    private static final String EXTRA_HIDDEN_FOREGROUND_SERVICE =
            "android.intent.extra.HIDDEN_FOREGROUND_SERVICE";

    /**
     * Map from package name, to preference name, to cached preferences.
     */
@@ -1698,9 +1708,12 @@ class ContextImpl extends Context {
        try {
            validateServiceIntent(service);
            service.prepareToLeaveProcess(this);
            final boolean hideForegroundNotification = requireForeground
                    && service.getBooleanExtra(EXTRA_HIDDEN_FOREGROUND_SERVICE, false);
            ComponentName cn = ActivityManager.getService().startService(
                    mMainThread.getApplicationThread(), service,
                    service.resolveTypeIfNeeded(getContentResolver()), requireForeground,
                    hideForegroundNotification,
                    getOpPackageName(), getAttributionTag(), user.getIdentifier());
            if (cn != null) {
                if (cn.getPackageName().equals("!")) {
+2 −1
Original line number Diff line number Diff line
@@ -156,7 +156,8 @@ interface IActivityManager {
    boolean refContentProvider(in IBinder connection, int stableDelta, int unstableDelta);
    PendingIntent getRunningServiceControlPanel(in ComponentName service);
    ComponentName startService(in IApplicationThread caller, in Intent service,
            in String resolvedType, boolean requireForeground, in String callingPackage,
            in String resolvedType, boolean requireForeground,
            boolean hideForegroundNotification, in String callingPackage,
            in String callingFeatureId, int userId);
    @UnsupportedAppUsage
    int stopService(in IApplicationThread caller, in Intent service,
+6 −5
Original line number Diff line number Diff line
@@ -453,16 +453,16 @@ public final class ActiveServices {
    }

    ComponentName startServiceLocked(IApplicationThread caller, Intent service, String resolvedType,
            int callingPid, int callingUid, boolean fgRequired, String callingPackage,
            @Nullable String callingFeatureId, final int userId)
            int callingPid, int callingUid, boolean fgRequired, boolean hideFgNotification,
            String callingPackage, @Nullable String callingFeatureId, final int userId)
            throws TransactionTooLargeException {
        return startServiceLocked(caller, service, resolvedType, callingPid, callingUid, fgRequired,
                callingPackage, callingFeatureId, userId, false);
                hideFgNotification, callingPackage, callingFeatureId, userId, false);
    }

    ComponentName startServiceLocked(IApplicationThread caller, Intent service, String resolvedType,
            int callingPid, int callingUid, boolean fgRequired, String callingPackage,
            @Nullable String callingFeatureId, final int userId,
            int callingPid, int callingUid, boolean fgRequired, boolean hideFgNotification,
            String callingPackage, @Nullable String callingFeatureId, final int userId,
            boolean allowBackgroundActivityStarts) throws TransactionTooLargeException {
        if (DEBUG_DELAYED_STARTS) Slog.v(TAG_SERVICE, "startService: " + service
                + " type=" + resolvedType + " args=" + service.getExtras());
@@ -626,6 +626,7 @@ public final class ActiveServices {
        r.startRequested = true;
        r.delayedStop = false;
        r.fgRequired = fgRequired;
        r.hideFgNotification = hideFgNotification;
        r.pendingStarts.add(new ServiceRecord.StartItem(r, false, r.makeNextStartId(),
                service, neededGrants, callingUid));

+31 −5
Original line number Diff line number Diff line
@@ -1370,6 +1370,10 @@ public class ActivityManagerService extends IActivityManager.Stub
    final Injector mInjector;
    /** The package verifier app. */
    private String mPackageVerifier;
    private int mPackageVerifierUid = UserHandle.USER_NULL;
    static final class ProcessChangeItem {
        static final int CHANGE_ACTIVITIES = 1<<0;
        static final int CHANGE_FOREGROUND_SERVICES = 1<<1;
@@ -2246,6 +2250,18 @@ public class ActivityManagerService extends IActivityManager.Stub
            if (phase == PHASE_SYSTEM_SERVICES_READY) {
                mService.mBatteryStatsService.systemServicesReady();
                mService.mServices.systemServicesReady();
                mService.mPackageVerifier = ArrayUtils.firstOrNull(
                        LocalServices.getService(PackageManagerInternal.class).getKnownPackageNames(
                                PackageManagerInternal.PACKAGE_VERIFIER, UserHandle.USER_SYSTEM));
                if (mService.mPackageVerifier != null) {
                    try {
                        mService.mPackageVerifierUid =
                                getContext().getPackageManager().getPackageUid(
                                        mService.mPackageVerifier, UserHandle.USER_SYSTEM);
                    } catch (NameNotFoundException e) {
                        Slog.wtf(TAG, "Package manager couldn't get package verifier uid", e);
                    }
                }
            } else if (phase == PHASE_ACTIVITY_MANAGER_READY) {
                mService.startBroadcastObservers();
            } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
@@ -13263,8 +13279,8 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public ComponentName startService(IApplicationThread caller, Intent service,
            String resolvedType, boolean requireForeground, String callingPackage,
            String callingFeatureId, int userId)
            String resolvedType, boolean requireForeground, boolean hideForegroundNotification,
            String callingPackage, String callingFeatureId, int userId)
            throws TransactionTooLargeException {
        enforceNotIsolatedCaller("startService");
        // Refuse possible leaked file descriptors
@@ -13276,17 +13292,27 @@ public class ActivityManagerService extends IActivityManager.Stub
            throw new IllegalArgumentException("callingPackage cannot be null");
        }
        final int callingUid = Binder.getCallingUid();
        if (requireForeground && hideForegroundNotification) {
            if (!UserHandle.isSameApp(callingUid, mPackageVerifierUid)
                    || !callingPackage.equals(mPackageVerifier)) {
                throw new IllegalArgumentException(
                        "Only the package verifier can hide its foreground service notification");
            }
            Slog.i(TAG, "Foreground service notification hiding requested by " + callingPackage);
        }
        if (DEBUG_SERVICE) Slog.v(TAG_SERVICE,
                "*** startService: " + service + " type=" + resolvedType + " fg=" + requireForeground);
        synchronized(this) {
            final int callingPid = Binder.getCallingPid();
            final int callingUid = Binder.getCallingUid();
            final long origId = Binder.clearCallingIdentity();
            ComponentName res;
            try {
                res = mServices.startServiceLocked(caller, service,
                        resolvedType, callingPid, callingUid,
                        requireForeground, callingPackage, callingFeatureId, userId);
                        requireForeground, hideForegroundNotification,
                        callingPackage, callingFeatureId, userId);
            } finally {
                Binder.restoreCallingIdentity(origId);
            }
@@ -17670,7 +17696,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                ComponentName res;
                try {
                    res = mServices.startServiceLocked(null, service,
                            resolvedType, -1, uid, fgRequired, callingPackage,
                            resolvedType, -1, uid, fgRequired, false, callingPackage,
                            callingFeatureId, userId, allowBackgroundActivityStarts);
                } finally {
                    Binder.restoreCallingIdentity(origId);
+1 −1
Original line number Diff line number Diff line
@@ -654,7 +654,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
        pw.println("Starting service: " + intent);
        pw.flush();
        ComponentName cn = mInterface.startService(null, intent, intent.getType(),
                asForeground, SHELL_PACKAGE_NAME, null, mUserId);
                asForeground, false, SHELL_PACKAGE_NAME, null, mUserId);
        if (cn == null) {
            err.println("Error: Not found; no service started.");
            return -1;
Loading