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

Commit 3127dfd2 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Allow shell uid without checking the package name." into tm-dev am:...

Merge "Allow shell uid without checking the package name." into tm-dev am: 5caf3932 am: f9d1137b

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



Change-Id: Iba84f5b7156acbe129cb4d5b6890b3c03d7a49ce
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 87ec3d74 f9d1137b
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.media.AudioManager;
import android.media.AudioPlaybackConfiguration;
import android.media.AudioSystem;
@@ -85,6 +86,7 @@ import android.view.ViewConfiguration;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.server.LocalManagerRegistry;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.Watchdog;
import com.android.server.Watchdog.Monitor;
@@ -540,14 +542,19 @@ public class MediaSessionService extends SystemService implements Monitor {
        if (TextUtils.isEmpty(packageName)) {
            throw new IllegalArgumentException("packageName may not be empty");
        }
        String[] packages = mContext.getPackageManager().getPackagesForUid(uid);
        final int packageCount = packages.length;
        for (int i = 0; i < packageCount; i++) {
            if (packageName.equals(packages[i])) {
        if (uid == Process.ROOT_UID || uid == Process.SHELL_UID) {
            // If the caller is shell, then trust the packageName given and allow it
            // to proceed.
            return;
        }
        final PackageManagerInternal packageManagerInternal =
                LocalServices.getService(PackageManagerInternal.class);
        final int actualUid = packageManagerInternal.getPackageUid(
                packageName, 0 /* flags */, UserHandle.getUserId(uid));
        if (!UserHandle.isSameApp(uid, actualUid)) {
            throw new IllegalArgumentException("packageName does not belong to the calling uid; "
                    + "pkg=" + packageName + ", uid=" + uid);
        }
        throw new IllegalArgumentException("packageName is not owned by the calling process");
    }

    void tempAllowlistTargetPkgIfPossible(int targetUid, String targetPackage,