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

Commit 14d462f7 authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Introduce a new API to fetch contentProviders based on callingUid

This API will take a caller's UID to fetch content providers available
to it. This will be used to prevent cross user access to content
providers.

Bug: 334024639
Test: atest CtsContentProviderMultiUserTest
Flag: android.content.pm.uid_based_provider_lookup
Change-Id: I430d87629a198a3e9dfe19f6ae1b7e01d4005e6d
parent 75d3ee72
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -360,6 +360,7 @@ package android {
    field @Deprecated public static final String REQUEST_NETWORK_SCORES = "android.permission.REQUEST_NETWORK_SCORES";
    field public static final String REQUEST_NOTIFICATION_ASSISTANT_SERVICE = "android.permission.REQUEST_NOTIFICATION_ASSISTANT_SERVICE";
    field public static final String RESET_PASSWORD = "android.permission.RESET_PASSWORD";
    field @FlaggedApi("android.content.pm.uid_based_provider_lookup") public static final String RESOLVE_COMPONENT_FOR_UID = "android.permission.RESOLVE_COMPONENT_FOR_UID";
    field public static final String RESTART_WIFI_SUBSYSTEM = "android.permission.RESTART_WIFI_SUBSYSTEM";
    field @FlaggedApi("android.permission.flags.health_connect_backup_restore_permission_enabled") public static final String RESTORE_HEALTH_CONNECT_DATA_AND_SETTINGS = "android.permission.RESTORE_HEALTH_CONNECT_DATA_AND_SETTINGS";
    field public static final String RESTORE_RUNTIME_PERMISSIONS = "android.permission.RESTORE_RUNTIME_PERMISSIONS";
@@ -4241,6 +4242,7 @@ package android.content.pm {
    method public abstract void registerDexModule(@NonNull String, @Nullable android.content.pm.PackageManager.DexModuleRegisterCallback);
    method @RequiresPermission("android.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS") public abstract void removeOnPermissionsChangeListener(@NonNull android.content.pm.PackageManager.OnPermissionsChangedListener);
    method public void replacePreferredActivity(@NonNull android.content.IntentFilter, int, @NonNull java.util.List<android.content.ComponentName>, @NonNull android.content.ComponentName);
    method @FlaggedApi("android.content.pm.uid_based_provider_lookup") @Nullable @RequiresPermission(android.Manifest.permission.RESOLVE_COMPONENT_FOR_UID) public android.content.pm.ProviderInfo resolveContentProviderForUid(@NonNull String, @NonNull android.content.pm.PackageManager.ComponentInfoFlags, int);
    method @RequiresPermission(android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS) public abstract void revokeRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission(android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS) public void revokeRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle, @NonNull String);
    method public void sendDeviceCustomizationReadyBroadcast();
+13 −0
Original line number Diff line number Diff line
@@ -1751,6 +1751,19 @@ public class ApplicationPackageManager extends PackageManager {
        }
    }

    /** @hide **/
    @Override
    public ProviderInfo resolveContentProviderForUid(@NonNull String authority,
            ComponentInfoFlags flags, int callingUid) {
        try {
            return mPM.resolveContentProviderForUid(authority,
                updateFlagsForComponent(flags.getValue(), getUserId(), null), getUserId(),
                callingUid);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    @Override
    public List<ProviderInfo> queryContentProviders(String processName, int uid, int flags) {
        return queryContentProviders(processName, uid, ComponentInfoFlags.of(flags));
+15 −0
Original line number Diff line number Diff line
@@ -195,6 +195,21 @@ interface IPackageManager {

    ProviderInfo resolveContentProvider(String name, long flags, int userId);

    /**
     * Resolve content providers with a given authority, for a specific
     * callingUid.
     *
     * @param authority Authority of the content provider
     * @param flags Additional option flags to modify the data returned.
     * @param userId Current user ID
     * @param callingUid UID of the caller who's access to the content provider
              is to be checked
     *
     *  @return ProviderInfo of the resolved content provider. May return null
    */
    ProviderInfo resolveContentProviderForUid(String authority, long flags,
      int userId, int callingUid);

    /**
     * Retrieve sync information for all content providers.
     *
+19 −0
Original line number Diff line number Diff line
@@ -8348,6 +8348,25 @@ public abstract class PackageManager {
                "resolveContentProviderAsUser not implemented in subclass");
    }

    /**
     * Resolve content providers with a given authority, for a specific callingUid.
     * @param authority Authority of the content provider
     * @param flags Additional option flags to modify the data returned.
     * @param callingUid UID of the caller who's access to the content provider is to be checked

     * @return ProviderInfo of the resolved content provider.
     * @hide
     */
    @Nullable
    @FlaggedApi(android.content.pm.Flags.FLAG_UID_BASED_PROVIDER_LOOKUP)
    @RequiresPermission(Manifest.permission.RESOLVE_COMPONENT_FOR_UID)
    @SystemApi
    public ProviderInfo resolveContentProviderForUid(@NonNull String authority,
        @NonNull ComponentInfoFlags flags, int callingUid) {
        throw new UnsupportedOperationException(
            "resolveContentProviderForUid not implemented in subclass");
    }

    /**
     * Retrieve content provider information.
     * <p>
+8 −0
Original line number Diff line number Diff line
@@ -368,3 +368,11 @@ flag {
    description: "Feature flag to remove the consumption of the hidden module status (ModuleInfo#IsHidden) in the Android source tree."
    bug: "363952383"
}

flag {
    name: "uid_based_provider_lookup"
    is_exported: true
    namespace: "package_manager_service"
    bug: "334024639"
    description: "Feature flag to check whether a given UID can access a content provider"
}
Loading