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

Commit c6cf95c0 authored by Nicolas Prevot's avatar Nicolas Prevot
Browse files

Making the content resolver work with result intents.

prepareToLeaveUser is called if necessary on result intents.
Adding the targetUserId to grantUriPermissionFromIntentLocked
This allows the GET_CONTENT intent to work across profiles.

Change-Id: Id81280c23247aeda7ad56e34af9b12a6f3a00a3c
parent 29fae7b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -308,7 +308,7 @@ public final class ActiveServices {
        }
        ServiceRecord r = res.record;
        NeededUriGrants neededGrants = mAm.checkGrantUriPermissionFromIntentLocked(
                callingUid, r.packageName, service, service.getFlags(), null);
                callingUid, r.packageName, service, service.getFlags(), null, r.userId);
        if (unscheduleServiceRestartLocked(r, callingUid, false)) {
            if (DEBUG_SERVICE) Slog.v(TAG, "START SERVICE WHILE RESTART PENDING: " + r);
        }
+25 −9
Original line number Diff line number Diff line
@@ -6380,7 +6380,7 @@ public final class ActivityManagerService extends ActivityManagerNative
     * Like checkGrantUriPermissionLocked, but takes an Intent.
     */
    NeededUriGrants checkGrantUriPermissionFromIntentLocked(int callingUid,
            String targetPkg, Intent intent, int mode, NeededUriGrants needed) {
            String targetPkg, Intent intent, int mode, NeededUriGrants needed, int targetUserId) {
        if (DEBUG_URI_PERMISSION) Slog.v(TAG,
                "Checking URI perm to data=" + (intent != null ? intent.getData() : null)
                + " clip=" + (intent != null ? intent.getClipData() : null)
@@ -6399,11 +6399,28 @@ public final class ActivityManagerService extends ActivityManagerNative
        if (data == null && clip == null) {
            return null;
        }
        final IPackageManager pm = AppGlobals.getPackageManager();
        int targetUid;
        if (needed != null) {
            targetUid = needed.targetUid;
        } else {
            try {
                targetUid = pm.getPackageUid(targetPkg, targetUserId);
            } catch (RemoteException ex) {
                return null;
            }
            if (targetUid < 0) {
                if (DEBUG_URI_PERMISSION) {
                    Slog.v(TAG, "Can't grant URI permission no uid for: " + targetPkg
                            + " on user " + targetUserId);
                }
                return null;
            }
        }
        if (data != null) {
            GrantUri grantUri = GrantUri.resolve(UserHandle.getUserId(callingUid), data);
            int targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, grantUri, mode,
                    needed != null ? needed.targetUid : -1);
            targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, grantUri, mode,
                    targetUid);
            if (targetUid > 0) {
                if (needed == null) {
                    needed = new NeededUriGrants(targetPkg, targetUid, mode);
@@ -6415,10 +6432,9 @@ public final class ActivityManagerService extends ActivityManagerNative
            for (int i=0; i<clip.getItemCount(); i++) {
                Uri uri = clip.getItemAt(i).getUri();
                if (uri != null) {
                    int targetUid = -1;
                    GrantUri grantUri = GrantUri.resolve(UserHandle.getUserId(callingUid), uri);
                    targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, grantUri, mode,
                            needed != null ? needed.targetUid : -1);
                            targetUid);
                    if (targetUid > 0) {
                        if (needed == null) {
                            needed = new NeededUriGrants(targetPkg, targetUid, mode);
@@ -6429,7 +6445,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    Intent clipIntent = clip.getItemAt(i).getIntent();
                    if (clipIntent != null) {
                        NeededUriGrants newNeeded = checkGrantUriPermissionFromIntentLocked(
                                callingUid, targetPkg, clipIntent, mode, needed);
                                callingUid, targetPkg, clipIntent, mode, needed, targetUserId);
                        if (newNeeded != null) {
                            needed = newNeeded;
                        }
@@ -6456,9 +6472,9 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    void grantUriPermissionFromIntentLocked(int callingUid,
            String targetPkg, Intent intent, UriPermissionOwner owner) {
            String targetPkg, Intent intent, UriPermissionOwner owner, int targetUserId) {
        NeededUriGrants needed = checkGrantUriPermissionFromIntentLocked(callingUid, targetPkg,
                intent, intent != null ? intent.getFlags() : 0, null);
                intent, intent != null ? intent.getFlags() : 0, null, targetUserId);
        if (needed == null) {
            return;
        }
+1 −1
Original line number Diff line number Diff line
@@ -635,7 +635,7 @@ final class ActivityRecord {
    final void deliverNewIntentLocked(int callingUid, Intent intent) {
        // The activity now gets access to the data associated with this Intent.
        service.grantUriPermissionFromIntentLocked(callingUid, packageName,
                intent, getUriPermissionsLocked());
                intent, getUriPermissionsLocked(), userId);
        // We want to immediately deliver the intent to the activity if
        // it is currently the top resumed activity...  however, if the
        // device is sleeping, then all activities are stopped, so in that
+5 −2
Original line number Diff line number Diff line
@@ -2331,7 +2331,7 @@ final class ActivityStack {

        if (callingUid > 0) {
            mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName,
                    data, r.getUriPermissionsLocked());
                    data, r.getUriPermissionsLocked(), r.userId);
        }

        if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r
@@ -2514,10 +2514,13 @@ final class ActivityStack {
            if (DEBUG_RESULTS) Slog.v(TAG, "Adding result to " + resultTo
                    + " who=" + r.resultWho + " req=" + r.requestCode
                    + " res=" + resultCode + " data=" + resultData);
            if (resultTo.userId != r.userId) {
                resultData.prepareToLeaveUser(r.userId);
            }
            if (r.info.applicationInfo.uid > 0) {
                mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid,
                        resultTo.packageName, resultData,
                        resultTo.getUriPermissionsLocked());
                        resultTo.getUriPermissionsLocked(), resultTo.userId);
            }
            resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode,
                                     resultData);
+1 −1
Original line number Diff line number Diff line
@@ -1930,7 +1930,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }

        mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName,
                intent, r.getUriPermissionsLocked());
                intent, r.getUriPermissionsLocked(), r.userId);

        if (newTask) {
            EventLog.writeEvent(EventLogTags.AM_CREATE_TASK, r.userId, r.task.taskId);