Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 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 | |
| 17 | package android.os.storage; |
| 18 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 24 | import android.content.res.Resources; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 25 | import android.net.Uri; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 26 | import android.os.Environment; |
Jeff Sharkey | ace874b | 2017-09-07 15:27:33 -0600 | [diff] [blame] | 27 | import android.os.IVold; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 28 | import android.os.Parcel; |
| 29 | import android.os.Parcelable; |
| 30 | import android.os.UserHandle; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 31 | import android.provider.DocumentsContract; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 32 | import android.text.TextUtils; |
| 33 | import android.util.ArrayMap; |
| 34 | import android.util.DebugUtils; |
| 35 | import android.util.SparseArray; |
Jeff Sharkey | 5fc2473 | 2015-06-10 14:21:27 -0700 | [diff] [blame] | 36 | import android.util.SparseIntArray; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 37 | |
Jeff Sharkey | 5fc2473 | 2015-06-10 14:21:27 -0700 | [diff] [blame] | 38 | import com.android.internal.R; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 39 | import com.android.internal.util.IndentingPrintWriter; |
| 40 | import com.android.internal.util.Preconditions; |
| 41 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 42 | import java.io.CharArrayWriter; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 43 | import java.io.File; |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 44 | import java.util.Comparator; |
Jeff Sharkey | 3f64ec5 | 2019-01-22 13:19:40 -0700 | [diff] [blame] | 45 | import java.util.Locale; |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 46 | import java.util.Objects; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Information about a storage volume that may be mounted. A volume may be a |
| 50 | * partition on a physical {@link DiskInfo}, an emulated volume above some other |
| 51 | * storage medium, or a standalone container like an ASEC or OBB. |
Jeff Sharkey | 4634987 | 2015-07-28 10:49:47 -0700 | [diff] [blame] | 52 | * <p> |
| 53 | * Volumes may be mounted with various flags: |
| 54 | * <ul> |
| 55 | * <li>{@link #MOUNT_FLAG_PRIMARY} means the volume provides primary external |
| 56 | * storage, historically found at {@code /sdcard}. |
| 57 | * <li>{@link #MOUNT_FLAG_VISIBLE} means the volume is visible to third-party |
| 58 | * apps for direct filesystem access. The system should send out relevant |
| 59 | * storage broadcasts and index any media on visible volumes. Visible volumes |
| 60 | * are considered a more stable part of the device, which is why we take the |
| 61 | * time to index them. In particular, transient volumes like USB OTG devices |
| 62 | * <em>should not</em> be marked as visible; their contents should be surfaced |
| 63 | * to apps through the Storage Access Framework. |
| 64 | * </ul> |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 65 | * |
| 66 | * @hide |
| 67 | */ |
| 68 | public class VolumeInfo implements Parcelable { |
Jeff Sharkey | e6c04f9 | 2015-04-18 21:38:05 -0700 | [diff] [blame] | 69 | public static final String ACTION_VOLUME_STATE_CHANGED = |
| 70 | "android.os.storage.action.VOLUME_STATE_CHANGED"; |
| 71 | public static final String EXTRA_VOLUME_ID = |
| 72 | "android.os.storage.extra.VOLUME_ID"; |
Jeff Sharkey | c7acac6 | 2015-06-12 16:16:56 -0700 | [diff] [blame] | 73 | public static final String EXTRA_VOLUME_STATE = |
| 74 | "android.os.storage.extra.VOLUME_STATE"; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 75 | |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 76 | /** Stub volume representing internal private storage */ |
| 77 | public static final String ID_PRIVATE_INTERNAL = "private"; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 78 | /** Real volume representing internal emulated storage */ |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 79 | public static final String ID_EMULATED_INTERNAL = "emulated"; |
| 80 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 81 | @UnsupportedAppUsage |
Jeff Sharkey | 8058fe6 | 2017-09-13 11:50:33 -0600 | [diff] [blame] | 82 | public static final int TYPE_PUBLIC = IVold.VOLUME_TYPE_PUBLIC; |
| 83 | public static final int TYPE_PRIVATE = IVold.VOLUME_TYPE_PRIVATE; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 84 | @UnsupportedAppUsage |
Jeff Sharkey | 8058fe6 | 2017-09-13 11:50:33 -0600 | [diff] [blame] | 85 | public static final int TYPE_EMULATED = IVold.VOLUME_TYPE_EMULATED; |
| 86 | public static final int TYPE_ASEC = IVold.VOLUME_TYPE_ASEC; |
| 87 | public static final int TYPE_OBB = IVold.VOLUME_TYPE_OBB; |
Risan | 05c41e6 | 2018-10-29 08:57:43 +0900 | [diff] [blame] | 88 | public static final int TYPE_STUB = IVold.VOLUME_TYPE_STUB; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 89 | |
Jeff Sharkey | 8058fe6 | 2017-09-13 11:50:33 -0600 | [diff] [blame] | 90 | public static final int STATE_UNMOUNTED = IVold.VOLUME_STATE_UNMOUNTED; |
| 91 | public static final int STATE_CHECKING = IVold.VOLUME_STATE_CHECKING; |
| 92 | public static final int STATE_MOUNTED = IVold.VOLUME_STATE_MOUNTED; |
| 93 | public static final int STATE_MOUNTED_READ_ONLY = IVold.VOLUME_STATE_MOUNTED_READ_ONLY; |
| 94 | public static final int STATE_FORMATTING = IVold.VOLUME_STATE_FORMATTING; |
| 95 | public static final int STATE_EJECTING = IVold.VOLUME_STATE_EJECTING; |
| 96 | public static final int STATE_UNMOUNTABLE = IVold.VOLUME_STATE_UNMOUNTABLE; |
| 97 | public static final int STATE_REMOVED = IVold.VOLUME_STATE_REMOVED; |
| 98 | public static final int STATE_BAD_REMOVAL = IVold.VOLUME_STATE_BAD_REMOVAL; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 99 | |
Jeff Sharkey | ace874b | 2017-09-07 15:27:33 -0600 | [diff] [blame] | 100 | public static final int MOUNT_FLAG_PRIMARY = IVold.MOUNT_FLAG_PRIMARY; |
| 101 | public static final int MOUNT_FLAG_VISIBLE = IVold.MOUNT_FLAG_VISIBLE; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 102 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 103 | private static SparseArray<String> sStateToEnvironment = new SparseArray<>(); |
| 104 | private static ArrayMap<String, String> sEnvironmentToBroadcast = new ArrayMap<>(); |
Jeff Sharkey | 5fc2473 | 2015-06-10 14:21:27 -0700 | [diff] [blame] | 105 | private static SparseIntArray sStateToDescrip = new SparseIntArray(); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 106 | |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 107 | private static final Comparator<VolumeInfo> |
| 108 | sDescriptionComparator = new Comparator<VolumeInfo>() { |
| 109 | @Override |
| 110 | public int compare(VolumeInfo lhs, VolumeInfo rhs) { |
| 111 | if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(lhs.getId())) { |
| 112 | return -1; |
| 113 | } else if (lhs.getDescription() == null) { |
| 114 | return 1; |
| 115 | } else if (rhs.getDescription() == null) { |
| 116 | return -1; |
| 117 | } else { |
| 118 | return lhs.getDescription().compareTo(rhs.getDescription()); |
| 119 | } |
| 120 | } |
| 121 | }; |
| 122 | |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 123 | static { |
| 124 | sStateToEnvironment.put(VolumeInfo.STATE_UNMOUNTED, Environment.MEDIA_UNMOUNTED); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 125 | sStateToEnvironment.put(VolumeInfo.STATE_CHECKING, Environment.MEDIA_CHECKING); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 126 | sStateToEnvironment.put(VolumeInfo.STATE_MOUNTED, Environment.MEDIA_MOUNTED); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 127 | sStateToEnvironment.put(VolumeInfo.STATE_MOUNTED_READ_ONLY, Environment.MEDIA_MOUNTED_READ_ONLY); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 128 | sStateToEnvironment.put(VolumeInfo.STATE_FORMATTING, Environment.MEDIA_UNMOUNTED); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 129 | sStateToEnvironment.put(VolumeInfo.STATE_EJECTING, Environment.MEDIA_EJECTING); |
Jeff Sharkey | 16c9c24 | 2015-04-04 21:37:20 -0700 | [diff] [blame] | 130 | sStateToEnvironment.put(VolumeInfo.STATE_UNMOUNTABLE, Environment.MEDIA_UNMOUNTABLE); |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 131 | sStateToEnvironment.put(VolumeInfo.STATE_REMOVED, Environment.MEDIA_REMOVED); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 132 | sStateToEnvironment.put(VolumeInfo.STATE_BAD_REMOVAL, Environment.MEDIA_BAD_REMOVAL); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 133 | |
| 134 | sEnvironmentToBroadcast.put(Environment.MEDIA_UNMOUNTED, Intent.ACTION_MEDIA_UNMOUNTED); |
| 135 | sEnvironmentToBroadcast.put(Environment.MEDIA_CHECKING, Intent.ACTION_MEDIA_CHECKING); |
| 136 | sEnvironmentToBroadcast.put(Environment.MEDIA_MOUNTED, Intent.ACTION_MEDIA_MOUNTED); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 137 | sEnvironmentToBroadcast.put(Environment.MEDIA_MOUNTED_READ_ONLY, Intent.ACTION_MEDIA_MOUNTED); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 138 | sEnvironmentToBroadcast.put(Environment.MEDIA_EJECTING, Intent.ACTION_MEDIA_EJECT); |
Jeff Sharkey | 16c9c24 | 2015-04-04 21:37:20 -0700 | [diff] [blame] | 139 | sEnvironmentToBroadcast.put(Environment.MEDIA_UNMOUNTABLE, Intent.ACTION_MEDIA_UNMOUNTABLE); |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 140 | sEnvironmentToBroadcast.put(Environment.MEDIA_REMOVED, Intent.ACTION_MEDIA_REMOVED); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 141 | sEnvironmentToBroadcast.put(Environment.MEDIA_BAD_REMOVAL, Intent.ACTION_MEDIA_BAD_REMOVAL); |
Jeff Sharkey | 5fc2473 | 2015-06-10 14:21:27 -0700 | [diff] [blame] | 142 | |
| 143 | sStateToDescrip.put(VolumeInfo.STATE_UNMOUNTED, R.string.ext_media_status_unmounted); |
| 144 | sStateToDescrip.put(VolumeInfo.STATE_CHECKING, R.string.ext_media_status_checking); |
| 145 | sStateToDescrip.put(VolumeInfo.STATE_MOUNTED, R.string.ext_media_status_mounted); |
| 146 | sStateToDescrip.put(VolumeInfo.STATE_MOUNTED_READ_ONLY, R.string.ext_media_status_mounted_ro); |
| 147 | sStateToDescrip.put(VolumeInfo.STATE_FORMATTING, R.string.ext_media_status_formatting); |
| 148 | sStateToDescrip.put(VolumeInfo.STATE_EJECTING, R.string.ext_media_status_ejecting); |
| 149 | sStateToDescrip.put(VolumeInfo.STATE_UNMOUNTABLE, R.string.ext_media_status_unmountable); |
| 150 | sStateToDescrip.put(VolumeInfo.STATE_REMOVED, R.string.ext_media_status_removed); |
| 151 | sStateToDescrip.put(VolumeInfo.STATE_BAD_REMOVAL, R.string.ext_media_status_bad_removal); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** vold state */ |
| 155 | public final String id; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 156 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 157 | public final int type; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 158 | @UnsupportedAppUsage |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 159 | public final DiskInfo disk; |
Jeff Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 160 | public final String partGuid; |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 161 | public int mountFlags = 0; |
Sudheer Shanka | 3f0645b | 2018-09-18 13:07:59 -0700 | [diff] [blame] | 162 | public int mountUserId = UserHandle.USER_NULL; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 163 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 164 | public int state = STATE_UNMOUNTED; |
| 165 | public String fsType; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 166 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 167 | public String fsUuid; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 168 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 169 | public String fsLabel; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 170 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 171 | public String path; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 172 | @UnsupportedAppUsage |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 173 | public String internalPath; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 174 | |
Jeff Sharkey | 5af1835d | 2015-07-07 17:26:59 -0700 | [diff] [blame] | 175 | public VolumeInfo(String id, int type, DiskInfo disk, String partGuid) { |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 176 | this.id = Preconditions.checkNotNull(id); |
| 177 | this.type = type; |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 178 | this.disk = disk; |
Jeff Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 179 | this.partGuid = partGuid; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 182 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 183 | public VolumeInfo(Parcel parcel) { |
| 184 | id = parcel.readString(); |
| 185 | type = parcel.readInt(); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 186 | if (parcel.readInt() != 0) { |
| 187 | disk = DiskInfo.CREATOR.createFromParcel(parcel); |
| 188 | } else { |
| 189 | disk = null; |
| 190 | } |
Jeff Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 191 | partGuid = parcel.readString(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 192 | mountFlags = parcel.readInt(); |
| 193 | mountUserId = parcel.readInt(); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 194 | state = parcel.readInt(); |
| 195 | fsType = parcel.readString(); |
| 196 | fsUuid = parcel.readString(); |
| 197 | fsLabel = parcel.readString(); |
| 198 | path = parcel.readString(); |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 199 | internalPath = parcel.readString(); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 202 | @UnsupportedAppUsage |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 203 | public static @NonNull String getEnvironmentForState(int state) { |
| 204 | final String envState = sStateToEnvironment.get(state); |
| 205 | if (envState != null) { |
| 206 | return envState; |
| 207 | } else { |
| 208 | return Environment.MEDIA_UNKNOWN; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | public static @Nullable String getBroadcastForEnvironment(String envState) { |
| 213 | return sEnvironmentToBroadcast.get(envState); |
| 214 | } |
| 215 | |
| 216 | public static @Nullable String getBroadcastForState(int state) { |
| 217 | return getBroadcastForEnvironment(getEnvironmentForState(state)); |
| 218 | } |
| 219 | |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 220 | public static @NonNull Comparator<VolumeInfo> getDescriptionComparator() { |
| 221 | return sDescriptionComparator; |
| 222 | } |
| 223 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 224 | @UnsupportedAppUsage |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 225 | public @NonNull String getId() { |
| 226 | return id; |
| 227 | } |
| 228 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 229 | @UnsupportedAppUsage |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 230 | public @Nullable DiskInfo getDisk() { |
| 231 | return disk; |
| 232 | } |
| 233 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 234 | @UnsupportedAppUsage |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 235 | public @Nullable String getDiskId() { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 236 | return (disk != null) ? disk.id : null; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 239 | @UnsupportedAppUsage |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 240 | public int getType() { |
| 241 | return type; |
| 242 | } |
| 243 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 244 | @UnsupportedAppUsage |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 245 | public int getState() { |
| 246 | return state; |
| 247 | } |
| 248 | |
Jeff Sharkey | 5fc2473 | 2015-06-10 14:21:27 -0700 | [diff] [blame] | 249 | public int getStateDescription() { |
| 250 | return sStateToDescrip.get(state, 0); |
| 251 | } |
| 252 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 253 | @UnsupportedAppUsage |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 254 | public @Nullable String getFsUuid() { |
| 255 | return fsUuid; |
| 256 | } |
| 257 | |
Jeff Sharkey | 3f64ec5 | 2019-01-22 13:19:40 -0700 | [diff] [blame] | 258 | public @Nullable String getNormalizedFsUuid() { |
| 259 | return fsUuid != null ? fsUuid.toLowerCase(Locale.US) : null; |
| 260 | } |
| 261 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 262 | @UnsupportedAppUsage |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 263 | public int getMountUserId() { |
| 264 | return mountUserId; |
| 265 | } |
| 266 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 267 | @UnsupportedAppUsage |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 268 | public @Nullable String getDescription() { |
Zim | 17be6f9 | 2019-09-25 14:37:55 +0100 | [diff] [blame] | 269 | if (ID_PRIVATE_INTERNAL.equals(id) || id.startsWith(ID_EMULATED_INTERNAL + ";")) { |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 270 | return Resources.getSystem().getString(com.android.internal.R.string.storage_internal); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 271 | } else if (!TextUtils.isEmpty(fsLabel)) { |
| 272 | return fsLabel; |
| 273 | } else { |
| 274 | return null; |
| 275 | } |
| 276 | } |
| 277 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 278 | @UnsupportedAppUsage |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 279 | public boolean isMountedReadable() { |
| 280 | return state == STATE_MOUNTED || state == STATE_MOUNTED_READ_ONLY; |
| 281 | } |
| 282 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 283 | @UnsupportedAppUsage |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 284 | public boolean isMountedWritable() { |
| 285 | return state == STATE_MOUNTED; |
| 286 | } |
| 287 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 288 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 289 | public boolean isPrimary() { |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 290 | return (mountFlags & MOUNT_FLAG_PRIMARY) != 0; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 293 | @UnsupportedAppUsage |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 294 | public boolean isPrimaryPhysical() { |
| 295 | return isPrimary() && (getType() == TYPE_PUBLIC); |
| 296 | } |
| 297 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 298 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 299 | public boolean isVisible() { |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 300 | return (mountFlags & MOUNT_FLAG_VISIBLE) != 0; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jeff Sharkey | d125746 | 2018-03-27 11:30:53 -0600 | [diff] [blame] | 303 | public boolean isVisibleForUser(int userId) { |
Zim | 17be6f9 | 2019-09-25 14:37:55 +0100 | [diff] [blame] | 304 | if ((type == TYPE_PUBLIC || type == TYPE_STUB || type == TYPE_EMULATED) |
| 305 | && mountUserId == userId) { |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 306 | return isVisible(); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 307 | } |
Zim | 17be6f9 | 2019-09-25 14:37:55 +0100 | [diff] [blame] | 308 | return false; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Returns {@code true} if this volume is the primary emulated volume for {@code userId}, |
| 313 | * {@code false} otherwise. |
| 314 | */ |
| 315 | @UnsupportedAppUsage |
| 316 | public boolean isPrimaryEmulatedForUser(int userId) { |
| 317 | return id.equals(ID_EMULATED_INTERNAL + ";" + userId); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Jeff Sharkey | d125746 | 2018-03-27 11:30:53 -0600 | [diff] [blame] | 320 | public boolean isVisibleForRead(int userId) { |
| 321 | return isVisibleForUser(userId); |
| 322 | } |
| 323 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 324 | @UnsupportedAppUsage |
Jeff Sharkey | d125746 | 2018-03-27 11:30:53 -0600 | [diff] [blame] | 325 | public boolean isVisibleForWrite(int userId) { |
| 326 | return isVisibleForUser(userId); |
| 327 | } |
| 328 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 329 | @UnsupportedAppUsage |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 330 | public File getPath() { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 331 | return (path != null) ? new File(path) : null; |
| 332 | } |
| 333 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 334 | @UnsupportedAppUsage |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 335 | public File getInternalPath() { |
| 336 | return (internalPath != null) ? new File(internalPath) : null; |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 339 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 340 | public File getPathForUser(int userId) { |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 341 | if (path == null) { |
| 342 | return null; |
Risan | 05c41e6 | 2018-10-29 08:57:43 +0900 | [diff] [blame] | 343 | } else if (type == TYPE_PUBLIC || type == TYPE_STUB) { |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 344 | return new File(path); |
| 345 | } else if (type == TYPE_EMULATED) { |
| 346 | return new File(path, Integer.toString(userId)); |
| 347 | } else { |
| 348 | return null; |
| 349 | } |
| 350 | } |
| 351 | |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 352 | /** |
| 353 | * Path which is accessible to apps holding |
| 354 | * {@link android.Manifest.permission#WRITE_MEDIA_STORAGE}. |
| 355 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 356 | @UnsupportedAppUsage |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 357 | public File getInternalPathForUser(int userId) { |
Jerry Zhang | 6f6154b | 2018-06-06 11:04:46 -0700 | [diff] [blame] | 358 | if (path == null) { |
| 359 | return null; |
Risan | 05c41e6 | 2018-10-29 08:57:43 +0900 | [diff] [blame] | 360 | } else if (type == TYPE_PUBLIC || type == TYPE_STUB) { |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 361 | // TODO: plumb through cleaner path from vold |
| 362 | return new File(path.replace("/storage/", "/mnt/media_rw/")); |
| 363 | } else { |
| 364 | return getPathForUser(userId); |
| 365 | } |
| 366 | } |
| 367 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 368 | @UnsupportedAppUsage |
Svet Ganov | 6ee871e | 2015-07-10 14:29:33 -0700 | [diff] [blame] | 369 | public StorageVolume buildStorageVolume(Context context, int userId, boolean reportUnmounted) { |
Jeff Sharkey | a83bf19 | 2015-07-08 09:18:20 -0700 | [diff] [blame] | 370 | final StorageManager storage = context.getSystemService(StorageManager.class); |
| 371 | |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 372 | final boolean removable; |
| 373 | final boolean emulated; |
| 374 | final boolean allowMassStorage = false; |
Svet Ganov | 6ee871e | 2015-07-10 14:29:33 -0700 | [diff] [blame] | 375 | final String envState = reportUnmounted |
| 376 | ? Environment.MEDIA_UNMOUNTED : getEnvironmentForState(state); |
Jeff Sharkey | 4634987 | 2015-07-28 10:49:47 -0700 | [diff] [blame] | 377 | |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 378 | File userPath = getPathForUser(userId); |
| 379 | if (userPath == null) { |
| 380 | userPath = new File("/dev/null"); |
| 381 | } |
Jerry Zhang | 71938e1 | 2018-05-10 18:28:29 -0700 | [diff] [blame] | 382 | File internalPath = getInternalPathForUser(userId); |
| 383 | if (internalPath == null) { |
| 384 | internalPath = new File("/dev/null"); |
| 385 | } |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 386 | |
Jeff Sharkey | a83bf19 | 2015-07-08 09:18:20 -0700 | [diff] [blame] | 387 | String description = null; |
Jeff Sharkey | 8e2ea2a | 2015-08-19 14:15:33 -0700 | [diff] [blame] | 388 | String derivedFsUuid = fsUuid; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 389 | long maxFileSize = 0; |
| 390 | |
| 391 | if (type == TYPE_EMULATED) { |
| 392 | emulated = true; |
Jeff Sharkey | 5af1835d | 2015-07-07 17:26:59 -0700 | [diff] [blame] | 393 | |
Jeff Sharkey | a83bf19 | 2015-07-08 09:18:20 -0700 | [diff] [blame] | 394 | final VolumeInfo privateVol = storage.findPrivateForEmulated(this); |
| 395 | if (privateVol != null) { |
| 396 | description = storage.getBestVolumeDescription(privateVol); |
Jeff Sharkey | 8e2ea2a | 2015-08-19 14:15:33 -0700 | [diff] [blame] | 397 | derivedFsUuid = privateVol.fsUuid; |
Jeff Sharkey | a83bf19 | 2015-07-08 09:18:20 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Zim | 17be6f9 | 2019-09-25 14:37:55 +0100 | [diff] [blame] | 400 | if (isPrimaryEmulatedForUser(userId)) { |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 401 | removable = false; |
| 402 | } else { |
| 403 | removable = true; |
| 404 | } |
| 405 | |
Risan | 05c41e6 | 2018-10-29 08:57:43 +0900 | [diff] [blame] | 406 | } else if (type == TYPE_PUBLIC || type == TYPE_STUB) { |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 407 | emulated = false; |
| 408 | removable = true; |
| 409 | |
Jeff Sharkey | a83bf19 | 2015-07-08 09:18:20 -0700 | [diff] [blame] | 410 | description = storage.getBestVolumeDescription(this); |
| 411 | |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 412 | if ("vfat".equals(fsType)) { |
| 413 | maxFileSize = 4294967295L; |
| 414 | } |
| 415 | |
| 416 | } else { |
| 417 | throw new IllegalStateException("Unexpected volume type " + type); |
| 418 | } |
| 419 | |
Jeff Sharkey | a83bf19 | 2015-07-08 09:18:20 -0700 | [diff] [blame] | 420 | if (description == null) { |
| 421 | description = context.getString(android.R.string.unknownName); |
| 422 | } |
| 423 | |
Jerry Zhang | 71938e1 | 2018-05-10 18:28:29 -0700 | [diff] [blame] | 424 | return new StorageVolume(id, userPath, internalPath, description, isPrimary(), removable, |
Jerry Zhang | f9c5c25 | 2017-08-16 18:07:51 -0700 | [diff] [blame] | 425 | emulated, allowMassStorage, maxFileSize, new UserHandle(userId), |
Jeff Sharkey | 8e2ea2a | 2015-08-19 14:15:33 -0700 | [diff] [blame] | 426 | derivedFsUuid, envState); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 429 | @UnsupportedAppUsage |
Jeff Sharkey | 5af1835d | 2015-07-07 17:26:59 -0700 | [diff] [blame] | 430 | public static int buildStableMtpStorageId(String fsUuid) { |
| 431 | if (TextUtils.isEmpty(fsUuid)) { |
| 432 | return StorageVolume.STORAGE_ID_INVALID; |
| 433 | } else { |
| 434 | int hash = 0; |
| 435 | for (int i = 0; i < fsUuid.length(); ++i) { |
| 436 | hash = 31 * hash + fsUuid.charAt(i); |
| 437 | } |
| 438 | hash = (hash ^ (hash << 16)) & 0xffff0000; |
| 439 | // Work around values that the spec doesn't allow, or that we've |
| 440 | // reserved for primary |
| 441 | if (hash == 0x00000000) hash = 0x00020000; |
| 442 | if (hash == 0x00010000) hash = 0x00020000; |
| 443 | if (hash == 0xffff0000) hash = 0xfffe0000; |
| 444 | return hash | 0x0001; |
| 445 | } |
| 446 | } |
| 447 | |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 448 | // TODO: avoid this layering violation |
| 449 | private static final String DOCUMENT_AUTHORITY = "com.android.externalstorage.documents"; |
| 450 | private static final String DOCUMENT_ROOT_PRIMARY_EMULATED = "primary"; |
| 451 | |
| 452 | /** |
| 453 | * Build an intent to browse the contents of this volume. Only valid for |
| 454 | * {@link #TYPE_EMULATED} or {@link #TYPE_PUBLIC}. |
| 455 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 456 | @UnsupportedAppUsage |
Jeff Sharkey | 0000d8a | 2018-03-27 11:35:32 -0600 | [diff] [blame] | 457 | public @Nullable Intent buildBrowseIntent() { |
Jeff Sharkey | b4ee5d7 | 2018-05-22 12:01:31 -0600 | [diff] [blame] | 458 | return buildBrowseIntentForUser(UserHandle.myUserId()); |
| 459 | } |
| 460 | |
| 461 | public @Nullable Intent buildBrowseIntentForUser(int userId) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 462 | final Uri uri; |
Risan | 05c41e6 | 2018-10-29 08:57:43 +0900 | [diff] [blame] | 463 | if ((type == VolumeInfo.TYPE_PUBLIC || type == VolumeInfo.TYPE_STUB) |
| 464 | && mountUserId == userId) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 465 | uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, fsUuid); |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 466 | } else if (type == VolumeInfo.TYPE_EMULATED && isPrimary()) { |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 467 | uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, |
| 468 | DOCUMENT_ROOT_PRIMARY_EMULATED); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 469 | } else { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 470 | return null; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Garfield Tan | 5d3b37b | 2017-03-01 11:01:05 -0800 | [diff] [blame] | 473 | final Intent intent = new Intent(Intent.ACTION_VIEW); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 474 | intent.addCategory(Intent.CATEGORY_DEFAULT); |
Jeff Sharkey | 42a4aaa | 2016-10-10 15:26:14 -0600 | [diff] [blame] | 475 | intent.setDataAndType(uri, DocumentsContract.Root.MIME_TYPE_ITEM); |
Aga Wronska | 1719b35 | 2016-03-21 11:28:03 -0700 | [diff] [blame] | 476 | |
| 477 | // note that docsui treats this as *force* show advanced. So sending |
| 478 | // false permits advanced to be shown based on user preferences. |
| 479 | intent.putExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, isPrimary()); |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 480 | return intent; |
| 481 | } |
| 482 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 483 | @Override |
| 484 | public String toString() { |
| 485 | final CharArrayWriter writer = new CharArrayWriter(); |
| 486 | dump(new IndentingPrintWriter(writer, " ", 80)); |
| 487 | return writer.toString(); |
| 488 | } |
| 489 | |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 490 | public void dump(IndentingPrintWriter pw) { |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 491 | pw.println("VolumeInfo{" + id + "}:"); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 492 | pw.increaseIndent(); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 493 | pw.printPair("type", DebugUtils.valueToString(getClass(), "TYPE_", type)); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 494 | pw.printPair("diskId", getDiskId()); |
Jeff Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 495 | pw.printPair("partGuid", partGuid); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 496 | pw.printPair("mountFlags", DebugUtils.flagsToString(getClass(), "MOUNT_FLAG_", mountFlags)); |
| 497 | pw.printPair("mountUserId", mountUserId); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 498 | pw.printPair("state", DebugUtils.valueToString(getClass(), "STATE_", state)); |
| 499 | pw.println(); |
| 500 | pw.printPair("fsType", fsType); |
| 501 | pw.printPair("fsUuid", fsUuid); |
| 502 | pw.printPair("fsLabel", fsLabel); |
| 503 | pw.println(); |
| 504 | pw.printPair("path", path); |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 505 | pw.printPair("internalPath", internalPath); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 506 | pw.decreaseIndent(); |
| 507 | pw.println(); |
| 508 | } |
| 509 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 510 | @Override |
| 511 | public VolumeInfo clone() { |
| 512 | final Parcel temp = Parcel.obtain(); |
| 513 | try { |
| 514 | writeToParcel(temp, 0); |
| 515 | temp.setDataPosition(0); |
| 516 | return CREATOR.createFromParcel(temp); |
| 517 | } finally { |
| 518 | temp.recycle(); |
| 519 | } |
| 520 | } |
| 521 | |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 522 | @Override |
| 523 | public boolean equals(Object o) { |
| 524 | if (o instanceof VolumeInfo) { |
| 525 | return Objects.equals(id, ((VolumeInfo) o).id); |
| 526 | } else { |
| 527 | return false; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public int hashCode() { |
| 533 | return id.hashCode(); |
| 534 | } |
| 535 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 536 | @UnsupportedAppUsage |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 537 | public static final @android.annotation.NonNull Creator<VolumeInfo> CREATOR = new Creator<VolumeInfo>() { |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 538 | @Override |
| 539 | public VolumeInfo createFromParcel(Parcel in) { |
| 540 | return new VolumeInfo(in); |
| 541 | } |
| 542 | |
| 543 | @Override |
| 544 | public VolumeInfo[] newArray(int size) { |
| 545 | return new VolumeInfo[size]; |
| 546 | } |
| 547 | }; |
| 548 | |
| 549 | @Override |
| 550 | public int describeContents() { |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | @Override |
| 555 | public void writeToParcel(Parcel parcel, int flags) { |
| 556 | parcel.writeString(id); |
| 557 | parcel.writeInt(type); |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 558 | if (disk != null) { |
| 559 | parcel.writeInt(1); |
| 560 | disk.writeToParcel(parcel, flags); |
| 561 | } else { |
| 562 | parcel.writeInt(0); |
| 563 | } |
Jeff Sharkey | 5cc0df2 | 2015-06-17 19:44:05 -0700 | [diff] [blame] | 564 | parcel.writeString(partGuid); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 565 | parcel.writeInt(mountFlags); |
| 566 | parcel.writeInt(mountUserId); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 567 | parcel.writeInt(state); |
| 568 | parcel.writeString(fsType); |
| 569 | parcel.writeString(fsUuid); |
| 570 | parcel.writeString(fsLabel); |
| 571 | parcel.writeString(path); |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 572 | parcel.writeString(internalPath); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 573 | } |
| 574 | } |