DiskInfo.java revision 1b8ef7e3165ff9aa52a4905dafc8d0f83e7403f9
1/*
2 * Copyright (C) 2015 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 android.os.storage;
18
19import android.content.Context;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.util.DebugUtils;
23
24import com.android.internal.util.IndentingPrintWriter;
25import com.android.internal.util.Preconditions;
26
27/**
28 * Information about a physical disk which may contain one or more
29 * {@link VolumeInfo}.
30 *
31 * @hide
32 */
33public class DiskInfo implements Parcelable {
34    public static final int FLAG_ADOPTABLE = 1 << 0;
35    public static final int FLAG_DEFAULT_PRIMARY = 1 << 1;
36    public static final int FLAG_SD = 1 << 2;
37    public static final int FLAG_USB = 1 << 3;
38
39    public final String id;
40    public final int flags;
41    public long size;
42    public String label;
43    public String[] volumes;
44
45    public DiskInfo(String id, int flags) {
46        this.id = Preconditions.checkNotNull(id);
47        this.flags = flags;
48    }
49
50    public DiskInfo(Parcel parcel) {
51        id = parcel.readString();
52        flags = parcel.readInt();
53        size = parcel.readLong();
54        label = parcel.readString();
55        volumes = parcel.readStringArray();
56    }
57
58    public String getDescription(Context context) {
59        // TODO: splice vendor label into these strings
60        if ((flags & FLAG_SD) != 0) {
61            return context.getString(com.android.internal.R.string.storage_sd_card);
62        } else if ((flags & FLAG_USB) != 0) {
63            return context.getString(com.android.internal.R.string.storage_usb);
64        } else {
65            return null;
66        }
67    }
68
69//    public void partitionPublic() throws NativeDaemonConnectorException {
70//        mConnector.execute("volume", "partition", id, "public");
71//    }
72//
73//    public void partitionPrivate() throws NativeDaemonConnectorException {
74//        mConnector.execute("volume", "partition", id, "private");
75//    }
76//
77//    public void partitionMixed(int frac) throws NativeDaemonConnectorException {
78//        mConnector.execute("volume", "partition", id, "mixed", frac);
79//    }
80
81    public void dump(IndentingPrintWriter pw) {
82        pw.println("DiskInfo:");
83        pw.increaseIndent();
84        pw.printPair("id", id);
85        pw.printPair("flags", DebugUtils.flagsToString(getClass(), "FLAG_", flags));
86        pw.printPair("size", size);
87        pw.printPair("label", label);
88        pw.printPair("volumes", volumes);
89        pw.decreaseIndent();
90        pw.println();
91    }
92
93    public static final Creator<DiskInfo> CREATOR = new Creator<DiskInfo>() {
94        @Override
95        public DiskInfo createFromParcel(Parcel in) {
96            return new DiskInfo(in);
97        }
98
99        @Override
100        public DiskInfo[] newArray(int size) {
101            return new DiskInfo[size];
102        }
103    };
104
105    @Override
106    public int describeContents() {
107        return 0;
108    }
109
110    @Override
111    public void writeToParcel(Parcel parcel, int flags) {
112        parcel.writeString(id);
113        parcel.writeInt(flags);
114        parcel.writeLong(size);
115        parcel.writeString(label);
116        parcel.writeStringArray(volumes);
117    }
118}
119