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

Commit ce3f5d00 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added new AM method: updatePersistableUriPermission()"

parents f74309f5 7a429721
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.graphics.GraphicBuffer;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Build;
@@ -2749,6 +2750,30 @@ public class ActivityManager {
        }
    }

    /**
     * Updates (grants or revokes) a persitable URI permission.
     *
     * @param uri URI to be granted or revoked.
     * @param prefix if {@code false}, permission apply to this specific URI; if {@code true}, it
     * applies to all URIs that are prefixed by this URI.
     * @param packageName target package.
     * @param grant if {@code true} a new permission will be granted, otherwise an existing
     * permission will be revoked.
     *
     * @return whether or not the requested succeeded.
     *
     * @hide
     */
    public boolean updatePersistableUriPermission(Uri uri, boolean prefix, String packageName,
            boolean grant) {
        try {
            return getService().updatePersistableUriPermission(uri, prefix, packageName, grant,
                    UserHandle.myUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Information you can retrieve about any processes that are in an error condition.
     */
+2 −0
Original line number Diff line number Diff line
@@ -424,6 +424,8 @@ interface IActivityManager {
    void restart();
    void performIdleMaintenance();
    void takePersistableUriPermission(in Uri uri, int modeFlags, int userId);
    boolean updatePersistableUriPermission(in Uri uri, boolean prefix, String packageName,
                                           boolean grant, int userId);
    void releasePersistableUriPermission(in Uri uri, int modeFlags, int userId);
    ParceledListSlice getPersistedUriPermissions(in String packageName, boolean incoming);
    void appNotRespondingViaProvider(in IBinder connection);
+69 −0
Original line number Diff line number Diff line
@@ -10099,6 +10099,75 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    /**
     * Updates (grants or revokes) a persitable URI permission.
     *
     * @param uri URI to be granted or revoked.
     * @param prefix if {@code false}, permission apply to this specific URI; if {@code true}, it
     * applies to all URIs that are prefixed by this URI.
     * @param packageName target package.
     * @param grant if {@code true} a new permission will be granted, otherwise an existing
     * permission will be revoked.
     * @param userId user handle
     *
     * @return whether or not the requested succeeded.
     *
     * @deprecated TODO(b/72055774): caller should use takePersistableUriPermission() or
     * releasePersistableUriPermission() instead, but such change will be made in a separate CL
     * so it can be easily reverted if it breaks existing functionality.
     */
    @Deprecated // STOPSHIP if not removed
    @Override
    public boolean updatePersistableUriPermission(Uri uri, boolean prefix, String packageName,
            boolean grant, int userId) {
        enforceCallingPermission(android.Manifest.permission.GET_APP_GRANTED_URI_PERMISSIONS,
                "updatePersistableUriPermission");
        final int uid = mPackageManagerInt.getPackageUid(packageName, 0, userId);
        final GrantUri grantUri = new GrantUri(userId, uri, prefix);
        boolean persistChanged = false;
        synchronized (this) {
            if (grant) { // Grant
                final String authority = uri.getAuthority();
                final ProviderInfo pi = getProviderInfoLocked(authority, userId, 0);
                if (pi == null) {
                    Slog.w(TAG, "No content provider found for authority " + authority);
                    return false;
                }
                final UriPermission permission = findOrCreateUriPermissionLocked(pi.packageName,
                        packageName, uid, grantUri);
                if (permission.isNew()) {
                    final int modeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION
                            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
                    permission.initPersistedModes(modeFlags, System.currentTimeMillis());
                    persistChanged = true;
                } else {
                    // Caller should not try to grant permission that is already granted.
                    Slog.w(TAG_URI_PERMISSION,
                            "permission already granted for " + grantUri.toSafeString());
                    return false;
                }
                persistChanged |= maybePrunePersistedUriGrantsLocked(uid);
            } else { // Revoke
                final UriPermission permission = findUriPermissionLocked(uid, grantUri);
                if (permission == null) {
                    // Caller should not try to revoke permission that is not granted.
                    Slog.v(TAG_URI_PERMISSION, "no permission for " + grantUri.toSafeString());
                    return false;
                } else {
                    permission.modeFlags = 0;
                    removeUriPermissionIfNeededLocked(permission);
                    persistChanged = true;
                }
            }
            if (persistChanged) {
                schedulePersistUriGrants();
            }
        }
        return true;
    }
    /**
     * @param uri This uri must NOT contain an embedded userId.
     * @param userId The userId in which the uri is to be resolved.
+4 −0
Original line number Diff line number Diff line
@@ -124,6 +124,10 @@ final class UriPermission {
        updateModeFlags();
    }

    boolean isNew() {
        return persistedCreateTime == INVALID_TIME;
    }

    void grantModes(int modeFlags, UriPermissionOwner owner) {
        final boolean persistable = (modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0;
        modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION