Loading services/core/java/com/android/server/StorageManagerService.java +17 −8 Original line number Diff line number Diff line Loading @@ -2686,24 +2686,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 @@ -2713,7 +2724,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 @@ -2727,7 +2737,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 @@ -2748,14 +2758,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
services/core/java/com/android/server/StorageManagerService.java +17 −8 Original line number Diff line number Diff line Loading @@ -2686,24 +2686,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 @@ -2713,7 +2724,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 @@ -2727,7 +2737,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 @@ -2748,14 +2758,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