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

Commit 9d3c13d7 authored by Risan's avatar Risan
Browse files

Revert "cheets: Delegate openAppFuseFile operation to vold"

This reverts commit 70ee4328.

Test: presubmit
Change-Id: Ifb7dff3d6a2530e6bf4c5e8b841600012f1bc14d
parent e45aae69
Loading
Loading
Loading
Loading
+8 −17
Original line number Diff line number Diff line
@@ -2687,35 +2687,24 @@ class StorageManagerService extends IStorageManager.Stub
    class AppFuseMountScope extends AppFuseBridge.MountScope {
        boolean opened = false;

        public AppFuseMountScope(int uid, int mountId) {
            super(uid, mountId);
        public AppFuseMountScope(int uid, int pid, int mountId) {
            super(uid, pid, mountId);
        }

        @Override
        public ParcelFileDescriptor open() throws NativeDaemonConnectorException {
            try {
                return new ParcelFileDescriptor(
                        mVold.mountAppFuse(uid, mountId));
                        mVold.mountAppFuse(uid, Process.myPid(), mountId));
            } catch (Exception e) {
                throw new NativeDaemonConnectorException("Failed to mount", e);
            }
        }

        @Override
        public ParcelFileDescriptor openFile(int mountId, int fileId, int flags)
                throws NativeDaemonConnectorException {
            try {
                return new ParcelFileDescriptor(
                        mVold.openAppFuseFile(uid, mountId, fileId, flags));
            } catch (Exception e) {
                throw new NativeDaemonConnectorException("Failed to open", e);
            }
        }

        @Override
        public void close() throws Exception {
            if (opened) {
                mVold.unmountAppFuse(uid, mountId);
                mVold.unmountAppFuse(uid, Process.myPid(), mountId);
                opened = false;
            }
        }
@@ -2725,6 +2714,7 @@ class StorageManagerService extends IStorageManager.Stub
    public @Nullable AppFuseMount mountProxyFileDescriptorBridge() {
        Slog.v(TAG, "mountProxyFileDescriptorBridge");
        final int uid = Binder.getCallingUid();
        final int pid = Binder.getCallingPid();

        while (true) {
            synchronized (mAppFuseLock) {
@@ -2738,7 +2728,7 @@ class StorageManagerService extends IStorageManager.Stub
                    final int name = mNextAppFuseName++;
                    try {
                        return new AppFuseMount(
                            name, mAppFuseBridge.addBridge(new AppFuseMountScope(uid, name)));
                            name, mAppFuseBridge.addBridge(new AppFuseMountScope(uid, pid, name)));
                    } catch (FuseUnavailableMountException e) {
                        if (newlyCreated) {
                            // If newly created bridge fails, it's a real error.
@@ -2759,13 +2749,14 @@ class StorageManagerService extends IStorageManager.Stub
    public @Nullable ParcelFileDescriptor openProxyFileDescriptor(
            int mountId, int fileId, int mode) {
        Slog.v(TAG, "mountProxyFileDescriptor");
        final int pid = Binder.getCallingPid();
        try {
            synchronized (mAppFuseLock) {
                if (mAppFuseBridge == null) {
                    Slog.e(TAG, "FuseBridge has not been created");
                    return null;
                }
                return mAppFuseBridge.openFile(mountId, fileId, mode);
                return mAppFuseBridge.openFile(pid, mountId, fileId, mode);
            }
        } catch (FuseUnavailableMountException | InterruptedException error) {
            Slog.v(TAG, "The mount point has already been invalid", error);
+14 −8
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.server.storage;

import android.os.FileUtils;
import android.os.ParcelFileDescriptor;
import android.system.ErrnoException;
import android.system.Os;
@@ -26,6 +25,8 @@ import com.android.internal.os.FuseUnavailableMountException;
import com.android.internal.util.Preconditions;
import com.android.server.NativeDaemonConnectorException;
import libcore.io.IoUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.concurrent.CountDownLatch;

/**
@@ -86,7 +87,7 @@ public class AppFuseBridge implements Runnable {
        }
    }

    public ParcelFileDescriptor openFile(int mountId, int fileId, int mode)
    public ParcelFileDescriptor openFile(int pid, int mountId, int fileId, int mode)
            throws FuseUnavailableMountException, InterruptedException {
        final MountScope scope;
        synchronized (this) {
@@ -95,14 +96,17 @@ public class AppFuseBridge implements Runnable {
                throw new FuseUnavailableMountException(mountId);
            }
        }
        if (scope.pid != pid) {
            throw new SecurityException("PID does not match");
        }
        final boolean result = scope.waitForMount();
        if (result == false) {
            throw new FuseUnavailableMountException(mountId);
        }
        try {
            int flags = FileUtils.translateModePfdToPosix(mode);
            return scope.openFile(mountId, fileId, flags);
        } catch (NativeDaemonConnectorException error) {
            return ParcelFileDescriptor.open(
                    new File(scope.mountPoint, String.valueOf(fileId)), mode);
        } catch (FileNotFoundException error) {
            throw new FuseUnavailableMountException(mountId);
        }
    }
@@ -127,13 +131,17 @@ public class AppFuseBridge implements Runnable {

    public static abstract class MountScope implements AutoCloseable {
        public final int uid;
        public final int pid;
        public final int mountId;
        public final File mountPoint;
        private final CountDownLatch mMounted = new CountDownLatch(1);
        private boolean mMountResult = false;

        public MountScope(int uid, int mountId) {
        public MountScope(int uid, int pid, int mountId) {
            this.uid = uid;
            this.pid = pid;
            this.mountId = mountId;
            this.mountPoint = new File(String.format(APPFUSE_MOUNT_NAME_TEMPLATE,  uid, mountId));
        }

        @GuardedBy("AppFuseBridge.this")
@@ -151,8 +159,6 @@ public class AppFuseBridge implements Runnable {
        }

        public abstract ParcelFileDescriptor open() throws NativeDaemonConnectorException;
        public abstract ParcelFileDescriptor openFile(int mountId, int fileId, int flags)
                throws NativeDaemonConnectorException;
    }

    private native long native_new();