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

Commit 5becd423 authored by Daichi Hirono's avatar Daichi Hirono Committed by Android (Google) Code Review
Browse files

Merge "Fix race in AppFuseTest."

parents 78cea814 e6054c0f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -379,7 +379,7 @@ private:

jboolean com_android_mtp_AppFuse_start_app_fuse_loop(
        JNIEnv* env, jobject self, jint jfd) {
    ScopedFd fd(dup(static_cast<int>(jfd)));
    ScopedFd fd(static_cast<int>(jfd));
    AppFuse appfuse(env, self);

    ALOGD("Start fuse loop.");
+23 −9
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.Process;
import android.os.storage.StorageManager;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
import com.android.mtp.annotations.UsedByNative;
import java.io.File;
import java.io.FileNotFoundException;
@@ -39,22 +40,18 @@ public class AppFuse {

    private final String mName;
    private final Callback mCallback;
    private final Thread mMessageThread;
    private Thread mMessageThread;
    private ParcelFileDescriptor mDeviceFd;

    AppFuse(String name, Callback callback) {
        mName = name;
        mCallback = callback;
        mMessageThread = new Thread(new Runnable() {
            @Override
            public void run() {
                native_start_app_fuse_loop(mDeviceFd.getFd());
            }
        });
    }

    void mount(StorageManager storageManager) {
    void mount(StorageManager storageManager) throws IOException {
        Preconditions.checkState(mDeviceFd == null);
        mDeviceFd = storageManager.mountAppFuse(mName);
        mMessageThread = new AppFuseMessageThread(mDeviceFd.dup().detachFd());
        mMessageThread.start();
    }

@@ -80,7 +77,6 @@ public class AppFuse {
                ParcelFileDescriptor.MODE_READ_ONLY);
    }

    @VisibleForTesting
    File getMountPoint() {
        return new File("/mnt/appfuse/" + Process.myUid() + "_" + mName);
    }
@@ -112,4 +108,22 @@ public class AppFuse {
    }

    private native boolean native_start_app_fuse_loop(int fd);

    private class AppFuseMessageThread extends Thread {
        /**
         * File descriptor used by native loop.
         * It's owned by native loop and does not need to close here.
         */
        private final int mRawFd;

        AppFuseMessageThread(int fd) {
            super("AppFuseMessageThread");
            mRawFd = fd;
        }

        @Override
        public void run() {
            native_start_app_fuse_loop(mRawFd);
        }
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -92,7 +92,12 @@ public class MtpDocumentsProvider extends DocumentsProvider {
        mRootScanner = new RootScanner(mResolver, mResources, mMtpManager, mDatabase);
        mAppFuse = new AppFuse(TAG, new AppFuseCallback());
        // TODO: Mount AppFuse on demands.
        try {
            mAppFuse.mount(getContext().getSystemService(StorageManager.class));
        } catch (IOException e) {
            Log.e(TAG, "Failed to start app fuse.", e);
            return false;
        }
        resume();
        return true;
    }
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import java.util.Arrays;

@MediumTest
public class AppFuseTest extends AndroidTestCase {
    public void testMount() throws ErrnoException {
    public void testMount() throws ErrnoException, IOException {
        final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
        final AppFuse appFuse = new AppFuse("test", new TestCallback());
        appFuse.mount(storageManager);
@@ -61,7 +61,7 @@ public class AppFuseTest extends AndroidTestCase {
        appFuse.close();
    }

    public void testOpenFile_error() {
    public void testOpenFile_fileNotFound() throws IOException {
        final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
        final int INODE = 10;
        final AppFuse appFuse = new AppFuse("test", new TestCallback());