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

Commit e7653741 authored by paulhu's avatar paulhu
Browse files

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
parent e53d334d
Loading
Loading
Loading
Loading
+41 −0
Original line number Original line Diff line number Diff line
/*
 * 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);
    }
}
+5 −5
Original line number Original line Diff line number Diff line
@@ -3560,24 +3560,24 @@ class StorageManagerService extends IStorageManager.Stub
        }
        }


        @Override
        @Override
        public ParcelFileDescriptor open() throws NativeDaemonConnectorException {
        public ParcelFileDescriptor open() throws AppFuseMountException {
            try {
            try {
                final FileDescriptor fd = mVold.mountAppFuse(uid, mountId);
                final FileDescriptor fd = mVold.mountAppFuse(uid, mountId);
                mMounted = true;
                mMounted = true;
                return new ParcelFileDescriptor(fd);
                return new ParcelFileDescriptor(fd);
            } catch (Exception e) {
            } catch (Exception e) {
                throw new NativeDaemonConnectorException("Failed to mount", e);
                throw new AppFuseMountException("Failed to mount", e);
            }
            }
        }
        }


        @Override
        @Override
        public ParcelFileDescriptor openFile(int mountId, int fileId, int flags)
        public ParcelFileDescriptor openFile(int mountId, int fileId, int flags)
                throws NativeDaemonConnectorException {
                throws AppFuseMountException {
            try {
            try {
                return new ParcelFileDescriptor(
                return new ParcelFileDescriptor(
                        mVold.openAppFuseFile(uid, mountId, fileId, flags));
                        mVold.openAppFuseFile(uid, mountId, fileId, flags));
            } catch (Exception e) {
            } 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.
                        // It seems the thread of mAppFuseBridge has already been terminated.
                        mAppFuseBridge = null;
                        mAppFuseBridge = null;
                    }
                    }
                } catch (NativeDaemonConnectorException e) {
                } catch (AppFuseMountException e) {
                    throw e.rethrowAsParcelableException();
                    throw e.rethrowAsParcelableException();
                }
                }
            }
            }
+5 −5
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.FuseUnavailableMountException;
import com.android.internal.os.FuseUnavailableMountException;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;
import com.android.server.NativeDaemonConnectorException;
import com.android.server.AppFuseMountException;
import libcore.io.IoUtils;
import libcore.io.IoUtils;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CountDownLatch;


@@ -55,7 +55,7 @@ public class AppFuseBridge implements Runnable {
    }
    }


    public ParcelFileDescriptor addBridge(MountScope mountScope)
    public ParcelFileDescriptor addBridge(MountScope mountScope)
            throws FuseUnavailableMountException, NativeDaemonConnectorException {
            throws FuseUnavailableMountException, AppFuseMountException {
        /*
        /*
        ** Dead Lock between Java lock (AppFuseBridge.java) and Native lock (FuseBridgeLoop.cc)
        ** Dead Lock between Java lock (AppFuseBridge.java) and Native lock (FuseBridgeLoop.cc)
        **
        **
@@ -112,7 +112,7 @@ public class AppFuseBridge implements Runnable {
        try {
        try {
            int flags = FileUtils.translateModePfdToPosix(mode);
            int flags = FileUtils.translateModePfdToPosix(mode);
            return scope.openFile(mountId, fileId, flags);
            return scope.openFile(mountId, fileId, flags);
        } catch (NativeDaemonConnectorException error) {
        } catch (AppFuseMountException error) {
            throw new FuseUnavailableMountException(mountId);
            throw new FuseUnavailableMountException(mountId);
        }
        }
    }
    }
@@ -160,9 +160,9 @@ public class AppFuseBridge implements Runnable {
            return mMountResult;
            return mMountResult;
        }
        }


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


    private native long native_new();
    private native long native_new();