Loading core/java/android/os/FileUtils.java +37 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,18 @@ package android.os; import static android.os.ParcelFileDescriptor.MODE_APPEND; import static android.os.ParcelFileDescriptor.MODE_CREATE; import static android.os.ParcelFileDescriptor.MODE_READ_ONLY; import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; import static android.os.ParcelFileDescriptor.MODE_TRUNCATE; import static android.os.ParcelFileDescriptor.MODE_WRITE_ONLY; import static android.system.OsConstants.O_APPEND; import static android.system.OsConstants.O_CREAT; import static android.system.OsConstants.O_RDONLY; import static android.system.OsConstants.O_RDWR; import static android.system.OsConstants.O_TRUNC; import static android.system.OsConstants.O_WRONLY; import static android.system.OsConstants.SPLICE_F_MORE; import static android.system.OsConstants.SPLICE_F_MOVE; import static android.system.OsConstants.S_ISFIFO; Loading Loading @@ -1050,6 +1062,30 @@ public class FileUtils { return val * pow; } /** {@hide} */ public static int translateModePfdToPosix(int mode) { int res = 0; if ((mode & MODE_READ_WRITE) == MODE_READ_WRITE) { res |= O_RDWR; } else if ((mode & MODE_WRITE_ONLY) == MODE_WRITE_ONLY) { res |= O_WRONLY; } else if ((mode & MODE_READ_ONLY) == MODE_READ_ONLY) { res |= O_RDONLY; } else { throw new IllegalArgumentException("Bad mode: " + mode); } if ((mode & MODE_CREATE) == MODE_CREATE) { res |= O_CREAT; } if ((mode & MODE_TRUNCATE) == MODE_TRUNCATE) { res |= O_TRUNC; } if ((mode & MODE_APPEND) == MODE_APPEND) { res |= O_APPEND; } return res; } @VisibleForTesting public static class MemoryPipe extends Thread implements AutoCloseable { private final FileDescriptor[] pipe; Loading Loading @@ -1115,3 +1151,4 @@ public class FileUtils { } } } services/core/java/com/android/server/StorageManagerService.java +17 −8 Original line number Diff line number Diff line Loading @@ -2602,24 +2602,35 @@ class StorageManagerService extends IStorageManager.Stub class AppFuseMountScope extends AppFuseBridge.MountScope { boolean opened = false; public AppFuseMountScope(int uid, int pid, int mountId) { super(uid, pid, mountId); public AppFuseMountScope(int uid, int mountId) { super(uid, mountId); } @Override public ParcelFileDescriptor open() throws NativeDaemonConnectorException { try { return new ParcelFileDescriptor( mVold.mountAppFuse(uid, Process.myPid(), mountId)); mVold.mountAppFuse(uid, 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, Process.myPid(), mountId); mVold.unmountAppFuse(uid, mountId); opened = false; } } Loading @@ -2629,7 +2640,6 @@ 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) { Loading @@ -2643,7 +2653,7 @@ class StorageManagerService extends IStorageManager.Stub final int name = mNextAppFuseName++; try { return new AppFuseMount( name, mAppFuseBridge.addBridge(new AppFuseMountScope(uid, pid, name))); name, mAppFuseBridge.addBridge(new AppFuseMountScope(uid, name))); } catch (FuseUnavailableMountException e) { if (newlyCreated) { // If newly created bridge fails, it's a real error. Loading @@ -2664,14 +2674,13 @@ 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(pid, mountId, fileId, mode); return mAppFuseBridge.openFile(mountId, fileId, mode); } } catch (FuseUnavailableMountException | InterruptedException error) { Slog.v(TAG, "The mount point has already been invalid", error); Loading services/core/java/com/android/server/storage/AppFuseBridge.java +8 −14 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.storage; import android.os.FileUtils; import android.os.ParcelFileDescriptor; import android.system.ErrnoException; import android.system.Os; Loading @@ -25,8 +26,6 @@ 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; /** Loading Loading @@ -87,7 +86,7 @@ public class AppFuseBridge implements Runnable { } } public ParcelFileDescriptor openFile(int pid, int mountId, int fileId, int mode) public ParcelFileDescriptor openFile(int mountId, int fileId, int mode) throws FuseUnavailableMountException, InterruptedException { final MountScope scope; synchronized (this) { Loading @@ -96,17 +95,14 @@ 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 { return ParcelFileDescriptor.open( new File(scope.mountPoint, String.valueOf(fileId)), mode); } catch (FileNotFoundException error) { int flags = FileUtils.translateModePfdToPosix(mode); return scope.openFile(mountId, fileId, flags); } catch (NativeDaemonConnectorException error) { throw new FuseUnavailableMountException(mountId); } } Loading @@ -131,17 +127,13 @@ 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 pid, int mountId) { public MountScope(int uid, 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") Loading @@ -159,6 +151,8 @@ 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(); Loading Loading
core/java/android/os/FileUtils.java +37 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,18 @@ package android.os; import static android.os.ParcelFileDescriptor.MODE_APPEND; import static android.os.ParcelFileDescriptor.MODE_CREATE; import static android.os.ParcelFileDescriptor.MODE_READ_ONLY; import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; import static android.os.ParcelFileDescriptor.MODE_TRUNCATE; import static android.os.ParcelFileDescriptor.MODE_WRITE_ONLY; import static android.system.OsConstants.O_APPEND; import static android.system.OsConstants.O_CREAT; import static android.system.OsConstants.O_RDONLY; import static android.system.OsConstants.O_RDWR; import static android.system.OsConstants.O_TRUNC; import static android.system.OsConstants.O_WRONLY; import static android.system.OsConstants.SPLICE_F_MORE; import static android.system.OsConstants.SPLICE_F_MOVE; import static android.system.OsConstants.S_ISFIFO; Loading Loading @@ -1050,6 +1062,30 @@ public class FileUtils { return val * pow; } /** {@hide} */ public static int translateModePfdToPosix(int mode) { int res = 0; if ((mode & MODE_READ_WRITE) == MODE_READ_WRITE) { res |= O_RDWR; } else if ((mode & MODE_WRITE_ONLY) == MODE_WRITE_ONLY) { res |= O_WRONLY; } else if ((mode & MODE_READ_ONLY) == MODE_READ_ONLY) { res |= O_RDONLY; } else { throw new IllegalArgumentException("Bad mode: " + mode); } if ((mode & MODE_CREATE) == MODE_CREATE) { res |= O_CREAT; } if ((mode & MODE_TRUNCATE) == MODE_TRUNCATE) { res |= O_TRUNC; } if ((mode & MODE_APPEND) == MODE_APPEND) { res |= O_APPEND; } return res; } @VisibleForTesting public static class MemoryPipe extends Thread implements AutoCloseable { private final FileDescriptor[] pipe; Loading Loading @@ -1115,3 +1151,4 @@ public class FileUtils { } } }
services/core/java/com/android/server/StorageManagerService.java +17 −8 Original line number Diff line number Diff line Loading @@ -2602,24 +2602,35 @@ class StorageManagerService extends IStorageManager.Stub class AppFuseMountScope extends AppFuseBridge.MountScope { boolean opened = false; public AppFuseMountScope(int uid, int pid, int mountId) { super(uid, pid, mountId); public AppFuseMountScope(int uid, int mountId) { super(uid, mountId); } @Override public ParcelFileDescriptor open() throws NativeDaemonConnectorException { try { return new ParcelFileDescriptor( mVold.mountAppFuse(uid, Process.myPid(), mountId)); mVold.mountAppFuse(uid, 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, Process.myPid(), mountId); mVold.unmountAppFuse(uid, mountId); opened = false; } } Loading @@ -2629,7 +2640,6 @@ 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) { Loading @@ -2643,7 +2653,7 @@ class StorageManagerService extends IStorageManager.Stub final int name = mNextAppFuseName++; try { return new AppFuseMount( name, mAppFuseBridge.addBridge(new AppFuseMountScope(uid, pid, name))); name, mAppFuseBridge.addBridge(new AppFuseMountScope(uid, name))); } catch (FuseUnavailableMountException e) { if (newlyCreated) { // If newly created bridge fails, it's a real error. Loading @@ -2664,14 +2674,13 @@ 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(pid, mountId, fileId, mode); return mAppFuseBridge.openFile(mountId, fileId, mode); } } catch (FuseUnavailableMountException | InterruptedException error) { Slog.v(TAG, "The mount point has already been invalid", error); Loading
services/core/java/com/android/server/storage/AppFuseBridge.java +8 −14 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.storage; import android.os.FileUtils; import android.os.ParcelFileDescriptor; import android.system.ErrnoException; import android.system.Os; Loading @@ -25,8 +26,6 @@ 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; /** Loading Loading @@ -87,7 +86,7 @@ public class AppFuseBridge implements Runnable { } } public ParcelFileDescriptor openFile(int pid, int mountId, int fileId, int mode) public ParcelFileDescriptor openFile(int mountId, int fileId, int mode) throws FuseUnavailableMountException, InterruptedException { final MountScope scope; synchronized (this) { Loading @@ -96,17 +95,14 @@ 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 { return ParcelFileDescriptor.open( new File(scope.mountPoint, String.valueOf(fileId)), mode); } catch (FileNotFoundException error) { int flags = FileUtils.translateModePfdToPosix(mode); return scope.openFile(mountId, fileId, flags); } catch (NativeDaemonConnectorException error) { throw new FuseUnavailableMountException(mountId); } } Loading @@ -131,17 +127,13 @@ 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 pid, int mountId) { public MountScope(int uid, 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") Loading @@ -159,6 +151,8 @@ 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(); Loading