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

Commit d82082c2 authored by Sumedh Sen's avatar Sumedh Sen Committed by Android (Google) Code Review
Browse files

Merge changes from topic "parse-authority-tm_dev" into tm-dev

* changes:
  [RESTRICT AUTOMERGE] Parse authority to separate userId and non-user parts of it
  [RESTRICT AUTOMERGE] Check cross user permissions for a given UID
parents c9bac9e1 9f9a68e9
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -619,11 +620,11 @@ public class ComputerEngine implements Computer {
            String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, int userId,
            int callingUid, boolean includeInstantApps) {
        if (!mUserManager.exists(userId)) return Collections.emptyList();
        enforceCrossUserOrProfilePermission(callingUid,
        enforceCrossUserOrProfilePermission(Binder.getCallingUid(),
                userId,
                false /*requireFullPermission*/,
                false /*checkShell*/,
                "query intent receivers");
                "query intent services");
        final String instantAppPkgName = getInstantAppPackageName(callingUid);
        flags = updateFlagsForResolve(flags, userId, callingUid, includeInstantApps,
                false /* isImplicitImageCaptureIntentAndNotSetByDpc */);
@@ -2426,10 +2427,10 @@ public class ComputerEngine implements Computer {
            return true;
        }
        if (requireFullPermission) {
            return hasPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL);
            return hasPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, callingUid);
        }
        return hasPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
                || hasPermission(Manifest.permission.INTERACT_ACROSS_USERS);
        return hasPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, callingUid)
            || hasPermission(Manifest.permission.INTERACT_ACROSS_USERS, callingUid);
    }

    /**
@@ -2445,6 +2446,11 @@ public class ComputerEngine implements Computer {
                == PackageManager.PERMISSION_GRANTED;
    }

    private boolean hasPermission(String permission, int uid) {
        return mContext.checkPermission(permission, /* pid= */ -1, uid)
                == PackageManager.PERMISSION_GRANTED;
    }

    public final boolean isCallerSameApp(String packageName, int uid) {
        if (Process.isSdkSandboxUid(uid)) {
            return (packageName != null
@@ -4684,7 +4690,7 @@ public class ComputerEngine implements Computer {
        final boolean listUninstalled = (flags & MATCH_KNOWN_PACKAGES) != 0;

        enforceCrossUserPermission(
                callingUid,
                Binder.getCallingUid(),
                userId,
                false /* requireFullPermission */,
                false /* checkShell */,
@@ -4755,8 +4761,14 @@ public class ComputerEngine implements Computer {
            int callingUid) {
        if (!mUserManager.exists(userId)) return null;
        flags = updateFlagsForComponent(flags, userId);
        final ProviderInfo providerInfo = mComponentResolver.queryProvider(this, name, flags,
                userId);

        // Callers of this API may not always separate the userID and authority. Let's parse it
        // before resolving
        String authorityWithoutUserId = ContentProvider.getAuthorityWithoutUserId(name);
        userId = ContentProvider.getUserIdFromAuthority(name, userId);

        final ProviderInfo providerInfo = mComponentResolver.queryProvider(this,
                authorityWithoutUserId, flags, userId);
        boolean checkedGrants = false;
        if (providerInfo != null) {
            // Looking for cross-user grants before enforcing the typical cross-users permissions
@@ -4770,7 +4782,7 @@ public class ComputerEngine implements Computer {
        if (!checkedGrants) {
            boolean enforceCrossUser = true;

            if (isAuthorityRedirectedForCloneProfile(name)) {
            if (isAuthorityRedirectedForCloneProfile(authorityWithoutUserId)) {
                final UserManagerInternal umInternal = mInjector.getUserManagerInternal();

                UserInfo userInfo = umInternal.getUserInfo(UserHandle.getUserId(callingUid));
@@ -5208,7 +5220,7 @@ public class ComputerEngine implements Computer {
    @Override
    public int getComponentEnabledSetting(@NonNull ComponentName component, int callingUid,
            @UserIdInt int userId) {
        enforceCrossUserPermission(callingUid, userId, false /*requireFullPermission*/,
        enforceCrossUserPermission(Binder.getCallingUid(), userId, false /*requireFullPermission*/,
                false /*checkShell*/, "getComponentEnabled");
        return getComponentEnabledSettingInternal(component, callingUid, userId);
    }
+5 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.any
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.doReturn
@@ -374,6 +375,10 @@ class PackageManagerComponentLabelIconOverrideTest {
                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)) {
                PackageManager.PERMISSION_GRANTED
            }
            whenever(this.checkPermission(
                eq(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL), anyInt(), anyInt())) {
                PackageManager.PERMISSION_GRANTED
            }
        }
        val mockSharedLibrariesImpl: SharedLibrariesImpl = mock {
            whenever(this.snapshot()) { this@mock }