Add AppFuseMountException

StorageManagerService and AppFuseBridge are used
NativeDaemonConnectorException to represent app fuse mount
failure. But NativeDaemonConnectorException is part of NSD
module files and it will be moved to the Connectivity module.
Thus, create AppFuseMountException to separate the usage and
make the exception more precisely.

Bug: 206702844
Test: m
Change-Id: I8b0224ce8894bc68b082dcdba054e2ccc22869ef
This commit is contained in:
paulhu
2021-11-17 18:24:24 +08:00
parent e53d334d7f
commit e765374142
3 changed files with 51 additions and 10 deletions

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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();