1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.os;
18
19import android.os.Parcel;
20import android.os.ParcelFileDescriptor;
21import android.os.Parcelable;
22import android.os.storage.IStorageManager;
23import com.android.internal.util.Preconditions;
24
25/**
26 * Parcelable class representing AppFuse mount.
27 * This conveys the result for IStorageManager#openProxyFileDescriptor.
28 * @see IStorageManager#openProxyFileDescriptor
29 */
30public class AppFuseMount implements Parcelable {
31    final public int mountPointId;
32    final public ParcelFileDescriptor fd;
33
34    /**
35     * @param mountPointId Integer number for mount point that is unique in the lifetime of
36     *     StorageManagerService.
37     * @param fd File descriptor pointing /dev/fuse and tagged with the mount point.
38     */
39    public AppFuseMount(int mountPointId, ParcelFileDescriptor fd) {
40        Preconditions.checkNotNull(fd);
41        this.mountPointId = mountPointId;
42        this.fd = fd;
43    }
44
45    @Override
46    public int describeContents() {
47        return 0;
48    }
49
50    @Override
51    public void writeToParcel(Parcel dest, int flags) {
52        dest.writeInt(this.mountPointId);
53        dest.writeParcelable(fd, flags);
54    }
55
56    public static final Parcelable.Creator<AppFuseMount> CREATOR =
57            new Parcelable.Creator<AppFuseMount>() {
58        @Override
59        public AppFuseMount createFromParcel(Parcel in) {
60            return new AppFuseMount(in.readInt(), in.readParcelable(null));
61        }
62
63        @Override
64        public AppFuseMount[] newArray(int size) {
65            return new AppFuseMount[size];
66        }
67    };
68}
69