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

Commit 152f0a85 authored by Iván Budnik's avatar Iván Budnik
Browse files

Log package name of calling uid when throwing

Test: Manual
Bug: 296168940
Change-Id: I0696007bc68e56723a5728cd7b0d733c12cc0c70
parent 209062be
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -313,7 +313,7 @@ class MediaRouter2ServiceImpl {
        if (linkedItemLandingComponent != null) {
            int callingUid = Binder.getCallingUid();
            MediaServerUtils.enforcePackageName(
                    linkedItemLandingComponent.getPackageName(), callingUid);
                    mContext, linkedItemLandingComponent.getPackageName(), callingUid);
            if (!MediaServerUtils.isValidActivityComponentName(
                    mContext,
                    linkedItemLandingComponent,
+8 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.text.TextUtils;
import com.android.server.LocalServices;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;

/** Util class for media server. */
@@ -63,7 +64,8 @@ import java.util.List;
     * @throws IllegalArgumentException If the given {@code packageName} does not correspond to the
     *     given {@code uid}, and {@code uid} is not the root uid, or the shell uid.
     */
    public static void enforcePackageName(String packageName, int uid) {
    public static void enforcePackageName(
            @NonNull Context context, @NonNull String packageName, int uid) {
        if (uid == Process.ROOT_UID || uid == Process.SHELL_UID) {
            return;
        }
@@ -76,12 +78,16 @@ import java.util.List;
                packageManagerInternal.getPackageUid(
                        packageName, 0 /* flags */, UserHandle.getUserId(uid));
        if (!UserHandle.isSameApp(uid, actualUid)) {
            String[] uidPackages = context.getPackageManager().getPackagesForUid(uid);
            throw new IllegalArgumentException(
                    "packageName does not belong to the calling uid; "
                            + "pkg="
                            + packageName
                            + ", uid="
                            + uid);
                            + uid
                            + " ("
                            + Arrays.toString(uidPackages)
                            + ")");
        }
    }

+6 −6
Original line number Diff line number Diff line
@@ -542,7 +542,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            int callingPid, int callingUid, String callingPackage, String reason) {
        final long token = Binder.clearCallingIdentity();
        try {
            MediaServerUtils.enforcePackageName(callingPackage, callingUid);
            MediaServerUtils.enforcePackageName(mContext, callingPackage, callingUid);
            if (targetUid != callingUid) {
                boolean canAllowWhileInUse = mActivityManagerLocal
                        .canAllowWhileInUsePermissionInFgs(callingPid, callingUid, callingPackage);
@@ -1187,7 +1187,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            final int uid = Binder.getCallingUid();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaServerUtils.enforcePackageName(packageName, uid);
                MediaServerUtils.enforcePackageName(mContext, packageName, uid);
                int resolvedUserId = handleIncomingUser(pid, uid, userId, packageName);
                if (cb == null) {
                    throw new IllegalArgumentException("Controller callback cannot be null");
@@ -1239,7 +1239,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            final int userId = userHandle.getIdentifier();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaServerUtils.enforcePackageName(packageName, uid);
                MediaServerUtils.enforcePackageName(mContext, packageName, uid);
                enforceMediaPermissions(packageName, pid, uid, userId);

                MediaSessionRecordImpl record;
@@ -1270,7 +1270,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            final int userId = userHandle.getIdentifier();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaServerUtils.enforcePackageName(packageName, uid);
                MediaServerUtils.enforcePackageName(mContext, packageName, uid);
                enforceMediaPermissions(packageName, pid, uid, userId);

                MediaSessionRecordImpl record;
@@ -1596,7 +1596,7 @@ public class MediaSessionService extends SystemService implements Monitor {
            final int userId = userHandle.getIdentifier();
            final long token = Binder.clearCallingIdentity();
            try {
                MediaServerUtils.enforcePackageName(packageName, uid);
                MediaServerUtils.enforcePackageName(mContext, packageName, uid);
                enforceMediaPermissions(packageName, pid, uid, userId);

                synchronized (mLock) {
@@ -2110,7 +2110,7 @@ public class MediaSessionService extends SystemService implements Monitor {
                // If they gave us a component name verify they own the
                // package
                packageName = componentName.getPackageName();
                MediaServerUtils.enforcePackageName(packageName, uid);
                MediaServerUtils.enforcePackageName(mContext, packageName, uid);
            }
            // Check that they can make calls on behalf of the user and get the final user id
            int resolvedUserId = handleIncomingUser(pid, uid, userId, packageName);