diff --git a/services/core/java/com/android/server/AppFuseMountException.java b/services/core/java/com/android/server/AppFuseMountException.java new file mode 100644 index 0000000000000..9a9379e4a1c72 --- /dev/null +++ b/services/core/java/com/android/server/AppFuseMountException.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server; + +import android.os.Parcel; + +/** + * An exception that indicates there was an error with a + * app fuse mount operation. + */ +public class AppFuseMountException extends Exception { + public AppFuseMountException(String detailMessage) { + super(detailMessage); + } + + public AppFuseMountException(String detailMessage, Throwable throwable) { + super(detailMessage, throwable); + } + + /** + * Rethrow as a {@link RuntimeException} subclass that is handled by + * {@link Parcel#writeException(Exception)}. + */ + public IllegalArgumentException rethrowAsParcelableException() { + throw new IllegalStateException(getMessage(), this); + } +} diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index 69c29269b7a99..59bbb0d90076c 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -3560,24 +3560,24 @@ class StorageManagerService extends IStorageManager.Stub } @Override - public ParcelFileDescriptor open() throws NativeDaemonConnectorException { + public ParcelFileDescriptor open() throws AppFuseMountException { try { final FileDescriptor fd = mVold.mountAppFuse(uid, mountId); mMounted = true; return new ParcelFileDescriptor(fd); } catch (Exception e) { - throw new NativeDaemonConnectorException("Failed to mount", e); + throw new AppFuseMountException("Failed to mount", e); } } @Override public ParcelFileDescriptor openFile(int mountId, int fileId, int flags) - throws NativeDaemonConnectorException { + throws AppFuseMountException { try { return new ParcelFileDescriptor( mVold.openAppFuseFile(uid, mountId, fileId, flags)); } catch (Exception e) { - throw new NativeDaemonConnectorException("Failed to open", e); + throw new AppFuseMountException("Failed to open", e); } } @@ -3617,7 +3617,7 @@ class StorageManagerService extends IStorageManager.Stub // It seems the thread of mAppFuseBridge has already been terminated. mAppFuseBridge = null; } - } catch (NativeDaemonConnectorException e) { + } catch (AppFuseMountException e) { throw e.rethrowAsParcelableException(); } } diff --git a/services/core/java/com/android/server/storage/AppFuseBridge.java b/services/core/java/com/android/server/storage/AppFuseBridge.java index b00540fd2a529..292314840efbc 100644 --- a/services/core/java/com/android/server/storage/AppFuseBridge.java +++ b/services/core/java/com/android/server/storage/AppFuseBridge.java @@ -24,7 +24,7 @@ import android.util.SparseArray; import com.android.internal.annotations.GuardedBy; import com.android.internal.os.FuseUnavailableMountException; import com.android.internal.util.Preconditions; -import com.android.server.NativeDaemonConnectorException; +import com.android.server.AppFuseMountException; import libcore.io.IoUtils; import java.util.concurrent.CountDownLatch; @@ -55,7 +55,7 @@ public class AppFuseBridge implements Runnable { } public ParcelFileDescriptor addBridge(MountScope mountScope) - throws FuseUnavailableMountException, NativeDaemonConnectorException { + throws FuseUnavailableMountException, AppFuseMountException { /* ** Dead Lock between Java lock (AppFuseBridge.java) and Native lock (FuseBridgeLoop.cc) ** @@ -112,7 +112,7 @@ public class AppFuseBridge implements Runnable { try { int flags = FileUtils.translateModePfdToPosix(mode); return scope.openFile(mountId, fileId, flags); - } catch (NativeDaemonConnectorException error) { + } catch (AppFuseMountException error) { throw new FuseUnavailableMountException(mountId); } } @@ -160,9 +160,9 @@ public class AppFuseBridge implements Runnable { return mMountResult; } - public abstract ParcelFileDescriptor open() throws NativeDaemonConnectorException; + public abstract ParcelFileDescriptor open() throws AppFuseMountException; public abstract ParcelFileDescriptor openFile(int mountId, int fileId, int flags) - throws NativeDaemonConnectorException; + throws AppFuseMountException; } private native long native_new();