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

Commit 62be696b authored by Sarup Dalwani's avatar Sarup Dalwani
Browse files

Not fetching MediaProvider from Clone Profile

Ideally clone profile should not have MediaProvider instance, even if
have the MediaProvider avoid fetching it and redirect to owner profile's
MediaProvider. This change is in reaction to bug where MediaProvider is
being installed in clone profile, adding this safe check so that even if
MediaProvider is installed in clone profile it is never used and
redirected to owner's MediaProvider. This check would be present to
ensure fallback from errors.

Test: atest CtsAppCloningHostTest:com.android.cts.appcloning.AppCloningHostTest#testCrossUserMediaAccess
Bug: 236121588
Bug: 254302429
Change-Id: I9d5bcb3dcbcbf1559b45841296566c900738bf1a
parent 16545e1c
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import com.android.internal.util.FrameworkStatsLog;
import com.android.server.LocalServices;
import com.android.server.RescueParty;
import com.android.server.pm.UserManagerInternal;
import com.android.server.pm.UserManagerService;
import com.android.server.pm.pkg.AndroidPackage;

import java.io.FileDescriptor;
@@ -163,7 +164,7 @@ public class ContentProviderHelper {
    private ContentProviderHolder getContentProviderImpl(IApplicationThread caller,
            String name, IBinder token, int callingUid, String callingPackage, String callingTag,
            boolean stable, int userId) {
        ContentProviderRecord cpr;
        ContentProviderRecord cpr = null;
        ContentProviderConnection conn = null;
        ProviderInfo cpi = null;
        boolean providerRunning = false;
@@ -185,8 +186,21 @@ public class ContentProviderHelper {

            checkTime(startTime, "getContentProviderImpl: getProviderByName");

            UserManagerService userManagerService = UserManagerService.getInstance();

            /*
             For clone user profile and allowed authority, skipping finding provider and redirecting
             it to owner profile. Ideally clone profile should not have MediaProvider instance
             installed and mProviderMap would not have entry for clone user. This is just fallback
             check to ensure even if MediaProvider is installed in Clone Profile, it should not be
             used and redirect to owner user's MediaProvider.
             */
            //todo(b/236121588) MediaProvider should not be installed in clone profile.
            if (!isAuthorityRedirectedForCloneProfile(name)
                    || !userManagerService.isMediaSharedWithParent(userId)) {
                // First check if this content provider has been published...
                cpr = mProviderMap.getProviderByName(name, userId);
            }
            // If that didn't work, check if it exists for user 0 and then
            // verify that it's a singleton provider before using it.
            if (cpr == null && userId != UserHandle.USER_SYSTEM) {
@@ -201,11 +215,9 @@ public class ContentProviderHelper {
                        userId = UserHandle.USER_SYSTEM;
                        checkCrossUser = false;
                    } else if (isAuthorityRedirectedForCloneProfile(name)) {
                        if (userManagerService.isMediaSharedWithParent(userId)) {
                            UserManagerInternal umInternal = LocalServices.getService(
                                    UserManagerInternal.class);
                        UserInfo userInfo = umInternal.getUserInfo(userId);

                        if (userInfo != null && userInfo.isCloneProfile()) {
                            userId = umInternal.getProfileParentId(userId);
                            checkCrossUser = false;
                        }