San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 19 | import android.annotation.BytesLong; |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Daniel Nishi | 690346b | 2016-06-17 10:21:48 -0700 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 25 | import android.annotation.SuppressLint; |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 26 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 27 | import android.annotation.SystemService; |
Jeff Sharkey | 10ec9d8 | 2018-11-28 14:52:45 -0700 | [diff] [blame] | 28 | import android.annotation.TestApi; |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 29 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 30 | import android.annotation.WorkerThread; |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 31 | import android.app.Activity; |
Svet Ganov | 6ee871e | 2015-07-10 14:29:33 -0700 | [diff] [blame] | 32 | import android.app.ActivityThread; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 33 | import android.content.ContentResolver; |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 34 | import android.content.Context; |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 35 | import android.content.Intent; |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 36 | import android.content.pm.ApplicationInfo; |
Jeff Sharkey | 275e3e4 | 2015-04-24 16:10:32 -0700 | [diff] [blame] | 37 | import android.content.pm.IPackageMoveObserver; |
| 38 | import android.content.pm.PackageManager; |
Sudheer Shanka | 25469aa | 2018-08-27 15:50:23 -0700 | [diff] [blame] | 39 | import android.content.res.ObbInfo; |
| 40 | import android.content.res.ObbScanner; |
Jeff Sharkey | f8fa940 | 2019-02-18 13:23:51 -0700 | [diff] [blame] | 41 | import android.net.Uri; |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 42 | import android.os.Binder; |
Mike Lockwood | cba928c | 2011-08-17 15:58:52 -0700 | [diff] [blame] | 43 | import android.os.Environment; |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 44 | import android.os.FileUtils; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 45 | import android.os.Handler; |
Jeff Sharkey | 4e7a765 | 2018-08-24 17:25:42 -0600 | [diff] [blame] | 46 | import android.os.IInstalld; |
Jeff Sharkey | 41cd681 | 2017-09-11 10:32:17 -0600 | [diff] [blame] | 47 | import android.os.IVold; |
Jeff Sharkey | 7e19f53 | 2017-11-06 13:54:11 -0700 | [diff] [blame] | 48 | import android.os.IVoldTaskListener; |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 49 | import android.os.Looper; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 50 | import android.os.Message; |
Daichi Hirono | 9e8d9e2 | 2015-11-13 14:37:00 +0900 | [diff] [blame] | 51 | import android.os.ParcelFileDescriptor; |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 52 | import android.os.ParcelableException; |
Jeff Sharkey | 7e19f53 | 2017-11-06 13:54:11 -0700 | [diff] [blame] | 53 | import android.os.PersistableBundle; |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 54 | import android.os.ProxyFileDescriptorCallback; |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 55 | import android.os.RemoteException; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 56 | import android.os.ServiceManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 57 | import android.os.ServiceManager.ServiceNotFoundException; |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 58 | import android.os.SystemProperties; |
Jeff Sharkey | f8fa940 | 2019-02-18 13:23:51 -0700 | [diff] [blame] | 59 | import android.provider.MediaStore; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Inseob Kim | c1246e6 | 2018-11-08 13:13:54 +0900 | [diff] [blame] | 61 | import android.sysprop.VoldProperties; |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 62 | import android.system.ErrnoException; |
| 63 | import android.system.Os; |
| 64 | import android.system.OsConstants; |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 65 | import android.text.TextUtils; |
Jeff Sharkey | 9f2dc05 | 2018-01-07 16:47:31 -0700 | [diff] [blame] | 66 | import android.util.DataUnit; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 67 | import android.util.Log; |
Felipe Leme | 281389a | 2016-10-10 17:12:20 -0700 | [diff] [blame] | 68 | import android.util.Pair; |
Jeff Sharkey | b42d694 | 2015-04-28 22:25:26 -0700 | [diff] [blame] | 69 | import android.util.Slog; |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 70 | import android.util.SparseArray; |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 71 | |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 72 | import com.android.internal.annotations.GuardedBy; |
| 73 | import com.android.internal.annotations.VisibleForTesting; |
Daichi Hirono | d61817e | 2017-02-13 10:37:11 +0900 | [diff] [blame] | 74 | import com.android.internal.logging.MetricsLogger; |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 75 | import com.android.internal.os.AppFuseMount; |
| 76 | import com.android.internal.os.FuseAppLoop; |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 77 | import com.android.internal.os.FuseUnavailableMountException; |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 78 | import com.android.internal.os.RoSystemProperties; |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 79 | import com.android.internal.os.SomeArgs; |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 80 | import com.android.internal.util.Preconditions; |
| 81 | |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 82 | import dalvik.system.BlockGuard; |
| 83 | |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 84 | import java.io.File; |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 85 | import java.io.FileDescriptor; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 86 | import java.io.FileNotFoundException; |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 87 | import java.io.IOException; |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 88 | import java.lang.annotation.Retention; |
| 89 | import java.lang.annotation.RetentionPolicy; |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 90 | import java.lang.ref.WeakReference; |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 91 | import java.nio.charset.StandardCharsets; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 92 | import java.util.ArrayList; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 93 | import java.util.Arrays; |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 94 | import java.util.Collections; |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 95 | import java.util.Iterator; |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 96 | import java.util.List; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 97 | import java.util.Objects; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 98 | import java.util.UUID; |
Jeff Sharkey | 7e19f53 | 2017-11-06 13:54:11 -0700 | [diff] [blame] | 99 | import java.util.concurrent.CompletableFuture; |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 100 | import java.util.concurrent.ThreadFactory; |
Jeff Sharkey | 7e19f53 | 2017-11-06 13:54:11 -0700 | [diff] [blame] | 101 | import java.util.concurrent.TimeUnit; |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 102 | import java.util.concurrent.atomic.AtomicInteger; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 103 | |
| 104 | /** |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 105 | * StorageManager is the interface to the systems storage service. The storage |
| 106 | * manager handles storage-related items such as Opaque Binary Blobs (OBBs). |
| 107 | * <p> |
| 108 | * OBBs contain a filesystem that maybe be encrypted on disk and mounted |
| 109 | * on-demand from an application. OBBs are a good way of providing large amounts |
| 110 | * of binary assets without packaging them into APKs as they may be multiple |
| 111 | * gigabytes in size. However, due to their size, they're most likely stored in |
| 112 | * a shared storage pool accessible from all programs. The system does not |
| 113 | * guarantee the security of the OBB file itself: if any program modifies the |
| 114 | * OBB, there is no guarantee that a read from that OBB will produce the |
| 115 | * expected output. |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 116 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 117 | @SystemService(Context.STORAGE_SERVICE) |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 118 | public class StorageManager { |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 119 | private static final String TAG = "StorageManager"; |
| 120 | |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 121 | /** {@hide} */ |
| 122 | public static final String PROP_PRIMARY_PHYSICAL = "ro.vold.primary_physical"; |
Jeff Sharkey | 74acbbb | 2015-04-21 12:14:03 -0700 | [diff] [blame] | 123 | /** {@hide} */ |
Jeff Sharkey | 0d838a0 | 2015-05-13 13:54:30 -0700 | [diff] [blame] | 124 | public static final String PROP_HAS_ADOPTABLE = "vold.has_adoptable"; |
| 125 | /** {@hide} */ |
Jeff Sharkey | 55fe0d0 | 2018-01-08 10:41:47 -0700 | [diff] [blame] | 126 | public static final String PROP_HAS_RESERVED = "vold.has_reserved"; |
| 127 | /** {@hide} */ |
Jeff Sharkey | 901c042 | 2018-04-20 13:11:20 -0600 | [diff] [blame] | 128 | public static final String PROP_ADOPTABLE = "persist.sys.adoptable"; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 129 | /** {@hide} */ |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 130 | public static final String PROP_EMULATE_FBE = "persist.sys.emulate_fbe"; |
Jeff Sharkey | 33dd156 | 2016-04-07 11:05:33 -0600 | [diff] [blame] | 131 | /** {@hide} */ |
| 132 | public static final String PROP_SDCARDFS = "persist.sys.sdcardfs"; |
Jeff Sharkey | e53e2d9 | 2017-03-25 23:14:06 -0600 | [diff] [blame] | 133 | /** {@hide} */ |
| 134 | public static final String PROP_VIRTUAL_DISK = "persist.sys.virtual_disk"; |
Jeff Sharkey | 4aacd8b | 2018-07-24 15:24:21 -0600 | [diff] [blame] | 135 | /** {@hide} */ |
| 136 | public static final String PROP_ISOLATED_STORAGE = "persist.sys.isolated_storage"; |
Jeff Sharkey | 342b4bf | 2018-12-18 11:12:40 -0700 | [diff] [blame] | 137 | /** {@hide} */ |
| 138 | public static final String PROP_ISOLATED_STORAGE_SNAPSHOT = "sys.isolated_storage_snapshot"; |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 139 | |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 140 | /** {@hide} */ |
Jeff Sharkey | 669e6b1 | 2018-10-27 17:58:44 -0600 | [diff] [blame] | 141 | public static final String PROP_FORCE_AUDIO = "persist.fw.force_audio"; |
| 142 | /** {@hide} */ |
| 143 | public static final String PROP_FORCE_VIDEO = "persist.fw.force_video"; |
| 144 | /** {@hide} */ |
| 145 | public static final String PROP_FORCE_IMAGES = "persist.fw.force_images"; |
Jeff Sharkey | 669e6b1 | 2018-10-27 17:58:44 -0600 | [diff] [blame] | 146 | |
| 147 | /** {@hide} */ |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 148 | public static final String UUID_PRIVATE_INTERNAL = null; |
| 149 | /** {@hide} */ |
| 150 | public static final String UUID_PRIMARY_PHYSICAL = "primary_physical"; |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 151 | /** {@hide} */ |
| 152 | public static final String UUID_SYSTEM = "system"; |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 153 | |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 154 | // NOTE: UUID constants below are namespaced |
| 155 | // uuid -v5 ad99aa3d-308e-4191-a200-ebcab371c0ad default |
| 156 | // uuid -v5 ad99aa3d-308e-4191-a200-ebcab371c0ad primary_physical |
| 157 | // uuid -v5 ad99aa3d-308e-4191-a200-ebcab371c0ad system |
Daniel Nishi | 690346b | 2016-06-17 10:21:48 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 160 | * UUID representing the default internal storage of this device which |
| 161 | * provides {@link Environment#getDataDirectory()}. |
Daniel Nishi | 690346b | 2016-06-17 10:21:48 -0700 | [diff] [blame] | 162 | * <p> |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 163 | * This value is constant across all devices and it will never change, and |
| 164 | * thus it cannot be used to uniquely identify a particular physical device. |
| 165 | * |
| 166 | * @see #getUuidForPath(File) |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 167 | * @see ApplicationInfo#storageUuid |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 168 | */ |
| 169 | public static final UUID UUID_DEFAULT = UUID |
| 170 | .fromString("41217664-9172-527a-b3d5-edabb50a7d69"); |
| 171 | |
| 172 | /** {@hide} */ |
| 173 | public static final UUID UUID_PRIMARY_PHYSICAL_ = UUID |
| 174 | .fromString("0f95a519-dae7-5abf-9519-fbd6209e05fd"); |
| 175 | |
| 176 | /** {@hide} */ |
| 177 | public static final UUID UUID_SYSTEM_ = UUID |
| 178 | .fromString("5d258386-e60d-59e3-826d-0089cdd42cc0"); |
| 179 | |
| 180 | /** |
| 181 | * Activity Action: Allows the user to manage their storage. This activity |
| 182 | * provides the ability to free up space on the device by deleting data such |
| 183 | * as apps. |
Daniel Nishi | 690346b | 2016-06-17 10:21:48 -0700 | [diff] [blame] | 184 | * <p> |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 185 | * If the sending application has a specific storage device or allocation |
| 186 | * size in mind, they can optionally define {@link #EXTRA_UUID} or |
| 187 | * {@link #EXTRA_REQUESTED_BYTES}, respectively. |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 188 | * <p> |
| 189 | * This intent should be launched using |
| 190 | * {@link Activity#startActivityForResult(Intent, int)} so that the user |
| 191 | * knows which app is requesting the storage space. The returned result will |
| 192 | * be {@link Activity#RESULT_OK} if the requested space was made available, |
| 193 | * or {@link Activity#RESULT_CANCELED} otherwise. |
Daniel Nishi | 690346b | 2016-06-17 10:21:48 -0700 | [diff] [blame] | 194 | */ |
| 195 | @SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION) |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 196 | public static final String ACTION_MANAGE_STORAGE = "android.os.storage.action.MANAGE_STORAGE"; |
| 197 | |
| 198 | /** |
| 199 | * Extra {@link UUID} used to indicate the storage volume where an |
| 200 | * application is interested in allocating or managing disk space. |
| 201 | * |
| 202 | * @see #ACTION_MANAGE_STORAGE |
| 203 | * @see #UUID_DEFAULT |
| 204 | * @see #getUuidForPath(File) |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 205 | * @see Intent#putExtra(String, java.io.Serializable) |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 206 | */ |
| 207 | public static final String EXTRA_UUID = "android.os.storage.extra.UUID"; |
| 208 | |
| 209 | /** |
| 210 | * Extra used to indicate the total size (in bytes) that an application is |
| 211 | * interested in allocating. |
| 212 | * <p> |
| 213 | * When defined, the management UI will help guide the user to free up |
| 214 | * enough disk space to reach this requested value. |
| 215 | * |
| 216 | * @see #ACTION_MANAGE_STORAGE |
| 217 | */ |
| 218 | public static final String EXTRA_REQUESTED_BYTES = "android.os.storage.extra.REQUESTED_BYTES"; |
Daniel Nishi | 690346b | 2016-06-17 10:21:48 -0700 | [diff] [blame] | 219 | |
Jeff Sharkey | 4c099d0 | 2015-05-15 13:45:00 -0700 | [diff] [blame] | 220 | /** {@hide} */ |
Jeff Sharkey | 901c042 | 2018-04-20 13:11:20 -0600 | [diff] [blame] | 221 | public static final int DEBUG_ADOPTABLE_FORCE_ON = 1 << 0; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 222 | /** {@hide} */ |
Jeff Sharkey | 901c042 | 2018-04-20 13:11:20 -0600 | [diff] [blame] | 223 | public static final int DEBUG_ADOPTABLE_FORCE_OFF = 1 << 1; |
Jeff Sharkey | 33dd156 | 2016-04-07 11:05:33 -0600 | [diff] [blame] | 224 | /** {@hide} */ |
Jeff Sharkey | 901c042 | 2018-04-20 13:11:20 -0600 | [diff] [blame] | 225 | public static final int DEBUG_EMULATE_FBE = 1 << 2; |
Jeff Sharkey | 33dd156 | 2016-04-07 11:05:33 -0600 | [diff] [blame] | 226 | /** {@hide} */ |
Jeff Sharkey | 901c042 | 2018-04-20 13:11:20 -0600 | [diff] [blame] | 227 | public static final int DEBUG_SDCARDFS_FORCE_ON = 1 << 3; |
Jeff Sharkey | e53e2d9 | 2017-03-25 23:14:06 -0600 | [diff] [blame] | 228 | /** {@hide} */ |
Jeff Sharkey | 901c042 | 2018-04-20 13:11:20 -0600 | [diff] [blame] | 229 | public static final int DEBUG_SDCARDFS_FORCE_OFF = 1 << 4; |
| 230 | /** {@hide} */ |
| 231 | public static final int DEBUG_VIRTUAL_DISK = 1 << 5; |
Sudheer Shanka | be0febe | 2018-11-07 18:24:37 -0800 | [diff] [blame] | 232 | /** {@hide} */ |
Jeff Sharkey | b0c363b2 | 2018-12-15 11:53:03 -0700 | [diff] [blame] | 233 | public static final int DEBUG_ISOLATED_STORAGE_FORCE_ON = 1 << 6; |
| 234 | /** {@hide} */ |
| 235 | public static final int DEBUG_ISOLATED_STORAGE_FORCE_OFF = 1 << 7; |
Jeff Sharkey | 4c099d0 | 2015-05-15 13:45:00 -0700 | [diff] [blame] | 236 | |
Jeff Sharkey | 4634987 | 2015-07-28 10:49:47 -0700 | [diff] [blame] | 237 | /** {@hide} */ |
Jeff Sharkey | 4e7a765 | 2018-08-24 17:25:42 -0600 | [diff] [blame] | 238 | public static final int FLAG_STORAGE_DE = IInstalld.FLAG_STORAGE_DE; |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 239 | /** {@hide} */ |
Jeff Sharkey | 4e7a765 | 2018-08-24 17:25:42 -0600 | [diff] [blame] | 240 | public static final int FLAG_STORAGE_CE = IInstalld.FLAG_STORAGE_CE; |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 241 | |
| 242 | /** {@hide} */ |
| 243 | public static final int FLAG_FOR_WRITE = 1 << 8; |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 244 | /** {@hide} */ |
| 245 | public static final int FLAG_REAL_STATE = 1 << 9; |
| 246 | /** {@hide} */ |
| 247 | public static final int FLAG_INCLUDE_INVISIBLE = 1 << 10; |
Jeff Sharkey | 4634987 | 2015-07-28 10:49:47 -0700 | [diff] [blame] | 248 | |
Jeff Sharkey | 31d0b70 | 2016-11-21 14:16:53 -0700 | [diff] [blame] | 249 | /** {@hide} */ |
Jeff Sharkey | 41cd681 | 2017-09-11 10:32:17 -0600 | [diff] [blame] | 250 | public static final int FSTRIM_FLAG_DEEP = IVold.FSTRIM_FLAG_DEEP_TRIM; |
Jeff Sharkey | 31d0b70 | 2016-11-21 14:16:53 -0700 | [diff] [blame] | 251 | |
Sudheer Shanka | f734114 | 2016-10-18 17:15:18 -0700 | [diff] [blame] | 252 | /** @hide The volume is not encrypted. */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 253 | @UnsupportedAppUsage |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 254 | public static final int ENCRYPTION_STATE_NONE = |
| 255 | IVold.ENCRYPTION_STATE_NONE; |
Sudheer Shanka | f734114 | 2016-10-18 17:15:18 -0700 | [diff] [blame] | 256 | |
| 257 | /** @hide The volume has been encrypted succesfully. */ |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 258 | public static final int ENCRYPTION_STATE_OK = |
| 259 | IVold.ENCRYPTION_STATE_OK; |
Sudheer Shanka | f734114 | 2016-10-18 17:15:18 -0700 | [diff] [blame] | 260 | |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 261 | /** @hide The volume is in a bad state. */ |
| 262 | public static final int ENCRYPTION_STATE_ERROR_UNKNOWN = |
| 263 | IVold.ENCRYPTION_STATE_ERROR_UNKNOWN; |
Sudheer Shanka | f734114 | 2016-10-18 17:15:18 -0700 | [diff] [blame] | 264 | |
| 265 | /** @hide Encryption is incomplete */ |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 266 | public static final int ENCRYPTION_STATE_ERROR_INCOMPLETE = |
| 267 | IVold.ENCRYPTION_STATE_ERROR_INCOMPLETE; |
Sudheer Shanka | f734114 | 2016-10-18 17:15:18 -0700 | [diff] [blame] | 268 | |
| 269 | /** @hide Encryption is incomplete and irrecoverable */ |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 270 | public static final int ENCRYPTION_STATE_ERROR_INCONSISTENT = |
| 271 | IVold.ENCRYPTION_STATE_ERROR_INCONSISTENT; |
Sudheer Shanka | f734114 | 2016-10-18 17:15:18 -0700 | [diff] [blame] | 272 | |
| 273 | /** @hide Underlying data is corrupt */ |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 274 | public static final int ENCRYPTION_STATE_ERROR_CORRUPT = |
| 275 | IVold.ENCRYPTION_STATE_ERROR_CORRUPT; |
Sudheer Shanka | f734114 | 2016-10-18 17:15:18 -0700 | [diff] [blame] | 276 | |
Sudheer Shanka | d68bd60 | 2018-11-13 17:43:39 -0800 | [diff] [blame] | 277 | /** @hide Prefix used in sandboxIds for apps with sharedUserIds */ |
| 278 | public static final String SHARED_SANDBOX_PREFIX = "shared-"; |
| 279 | |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 280 | private static volatile IStorageManager sStorageManager = null; |
Felipe Leme | 179923a | 2016-07-19 09:33:31 -0700 | [diff] [blame] | 281 | |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 282 | private final Context mContext; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 283 | private final ContentResolver mResolver; |
| 284 | |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 285 | private final IStorageManager mStorageManager; |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 286 | private final Looper mLooper; |
| 287 | private final AtomicInteger mNextNonce = new AtomicInteger(0); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 288 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 289 | private final ArrayList<StorageEventListenerDelegate> mDelegates = new ArrayList<>(); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 290 | |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 291 | private static class StorageEventListenerDelegate extends IStorageEventListener.Stub implements |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 292 | Handler.Callback { |
| 293 | private static final int MSG_STORAGE_STATE_CHANGED = 1; |
| 294 | private static final int MSG_VOLUME_STATE_CHANGED = 2; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 295 | private static final int MSG_VOLUME_RECORD_CHANGED = 3; |
| 296 | private static final int MSG_VOLUME_FORGOTTEN = 4; |
| 297 | private static final int MSG_DISK_SCANNED = 5; |
Makoto Onuki | 9dc575d | 2015-06-12 16:10:25 -0700 | [diff] [blame] | 298 | private static final int MSG_DISK_DESTROYED = 6; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 299 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 300 | final StorageEventListener mCallback; |
| 301 | final Handler mHandler; |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 302 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 303 | public StorageEventListenerDelegate(StorageEventListener callback, Looper looper) { |
| 304 | mCallback = callback; |
| 305 | mHandler = new Handler(looper, this); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 308 | @Override |
| 309 | public boolean handleMessage(Message msg) { |
| 310 | final SomeArgs args = (SomeArgs) msg.obj; |
| 311 | switch (msg.what) { |
| 312 | case MSG_STORAGE_STATE_CHANGED: |
| 313 | mCallback.onStorageStateChanged((String) args.arg1, (String) args.arg2, |
| 314 | (String) args.arg3); |
| 315 | args.recycle(); |
| 316 | return true; |
| 317 | case MSG_VOLUME_STATE_CHANGED: |
| 318 | mCallback.onVolumeStateChanged((VolumeInfo) args.arg1, args.argi2, args.argi3); |
| 319 | args.recycle(); |
| 320 | return true; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 321 | case MSG_VOLUME_RECORD_CHANGED: |
| 322 | mCallback.onVolumeRecordChanged((VolumeRecord) args.arg1); |
| 323 | args.recycle(); |
| 324 | return true; |
| 325 | case MSG_VOLUME_FORGOTTEN: |
| 326 | mCallback.onVolumeForgotten((String) args.arg1); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 327 | args.recycle(); |
| 328 | return true; |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 329 | case MSG_DISK_SCANNED: |
| 330 | mCallback.onDiskScanned((DiskInfo) args.arg1, args.argi2); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 331 | args.recycle(); |
| 332 | return true; |
Makoto Onuki | 9dc575d | 2015-06-12 16:10:25 -0700 | [diff] [blame] | 333 | case MSG_DISK_DESTROYED: |
| 334 | mCallback.onDiskDestroyed((DiskInfo) args.arg1); |
| 335 | args.recycle(); |
| 336 | return true; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 337 | } |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 338 | args.recycle(); |
| 339 | return false; |
| 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException { |
| 344 | // Ignored |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public void onStorageStateChanged(String path, String oldState, String newState) { |
| 349 | final SomeArgs args = SomeArgs.obtain(); |
| 350 | args.arg1 = path; |
| 351 | args.arg2 = oldState; |
| 352 | args.arg3 = newState; |
| 353 | mHandler.obtainMessage(MSG_STORAGE_STATE_CHANGED, args).sendToTarget(); |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) { |
| 358 | final SomeArgs args = SomeArgs.obtain(); |
| 359 | args.arg1 = vol; |
| 360 | args.argi2 = oldState; |
| 361 | args.argi3 = newState; |
| 362 | mHandler.obtainMessage(MSG_VOLUME_STATE_CHANGED, args).sendToTarget(); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 363 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 364 | |
| 365 | @Override |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 366 | public void onVolumeRecordChanged(VolumeRecord rec) { |
| 367 | final SomeArgs args = SomeArgs.obtain(); |
| 368 | args.arg1 = rec; |
| 369 | mHandler.obtainMessage(MSG_VOLUME_RECORD_CHANGED, args).sendToTarget(); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public void onVolumeForgotten(String fsUuid) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 374 | final SomeArgs args = SomeArgs.obtain(); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 375 | args.arg1 = fsUuid; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 376 | mHandler.obtainMessage(MSG_VOLUME_FORGOTTEN, args).sendToTarget(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 377 | } |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 378 | |
| 379 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 380 | public void onDiskScanned(DiskInfo disk, int volumeCount) { |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 381 | final SomeArgs args = SomeArgs.obtain(); |
| 382 | args.arg1 = disk; |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 383 | args.argi2 = volumeCount; |
| 384 | mHandler.obtainMessage(MSG_DISK_SCANNED, args).sendToTarget(); |
Jeff Sharkey | 7e92ef3 | 2015-04-17 17:35:07 -0700 | [diff] [blame] | 385 | } |
Makoto Onuki | 9dc575d | 2015-06-12 16:10:25 -0700 | [diff] [blame] | 386 | |
| 387 | @Override |
| 388 | public void onDiskDestroyed(DiskInfo disk) throws RemoteException { |
| 389 | final SomeArgs args = SomeArgs.obtain(); |
| 390 | args.arg1 = disk; |
| 391 | mHandler.obtainMessage(MSG_DISK_DESTROYED, args).sendToTarget(); |
| 392 | } |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /** |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 396 | * Binder listener for OBB action results. |
| 397 | */ |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 398 | private final ObbActionListener mObbActionListener = new ObbActionListener(); |
| 399 | |
| 400 | private class ObbActionListener extends IObbActionListener.Stub { |
Gilles Debunne | 37051cd | 2011-05-25 16:27:13 -0700 | [diff] [blame] | 401 | @SuppressWarnings("hiding") |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 402 | private SparseArray<ObbListenerDelegate> mListeners = new SparseArray<ObbListenerDelegate>(); |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 403 | |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 404 | @Override |
Gilles Debunne | 37051cd | 2011-05-25 16:27:13 -0700 | [diff] [blame] | 405 | public void onObbResult(String filename, int nonce, int status) { |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 406 | final ObbListenerDelegate delegate; |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 407 | synchronized (mListeners) { |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 408 | delegate = mListeners.get(nonce); |
| 409 | if (delegate != null) { |
| 410 | mListeners.remove(nonce); |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 413 | |
| 414 | if (delegate != null) { |
| 415 | delegate.sendObbStateChanged(filename, status); |
| 416 | } |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 419 | public int addListener(OnObbStateChangeListener listener) { |
| 420 | final ObbListenerDelegate delegate = new ObbListenerDelegate(listener); |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 421 | |
| 422 | synchronized (mListeners) { |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 423 | mListeners.put(delegate.nonce, delegate); |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 424 | } |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 425 | |
| 426 | return delegate.nonce; |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 430 | private int getNextNonce() { |
| 431 | return mNextNonce.getAndIncrement(); |
| 432 | } |
| 433 | |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 434 | /** |
| 435 | * Private class containing sender and receiver code for StorageEvents. |
| 436 | */ |
| 437 | private class ObbListenerDelegate { |
| 438 | private final WeakReference<OnObbStateChangeListener> mObbEventListenerRef; |
| 439 | private final Handler mHandler; |
| 440 | |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 441 | private final int nonce; |
| 442 | |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 443 | ObbListenerDelegate(OnObbStateChangeListener listener) { |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 444 | nonce = getNextNonce(); |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 445 | mObbEventListenerRef = new WeakReference<OnObbStateChangeListener>(listener); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 446 | mHandler = new Handler(mLooper) { |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 447 | @Override |
| 448 | public void handleMessage(Message msg) { |
Gilles Debunne | 37051cd | 2011-05-25 16:27:13 -0700 | [diff] [blame] | 449 | final OnObbStateChangeListener changeListener = getListener(); |
| 450 | if (changeListener == null) { |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 454 | changeListener.onObbStateChange((String) msg.obj, msg.arg1); |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 455 | } |
| 456 | }; |
| 457 | } |
| 458 | |
| 459 | OnObbStateChangeListener getListener() { |
| 460 | if (mObbEventListenerRef == null) { |
| 461 | return null; |
| 462 | } |
| 463 | return mObbEventListenerRef.get(); |
| 464 | } |
| 465 | |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 466 | void sendObbStateChanged(String path, int state) { |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 467 | mHandler.obtainMessage(0, state, 0, path).sendToTarget(); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 471 | /** {@hide} */ |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 472 | @Deprecated |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 473 | @UnsupportedAppUsage |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 474 | public static StorageManager from(Context context) { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 475 | return context.getSystemService(StorageManager.class); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 476 | } |
| 477 | |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 478 | /** |
| 479 | * Constructs a StorageManager object through which an application can |
| 480 | * can communicate with the systems mount service. |
Daichi Hirono | 9e8d9e2 | 2015-11-13 14:37:00 +0900 | [diff] [blame] | 481 | * |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 482 | * @param looper The {@link android.os.Looper} which events will be received on. |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 483 | * |
| 484 | * <p>Applications can get instance of this class by calling |
| 485 | * {@link android.content.Context#getSystemService(java.lang.String)} with an argument |
| 486 | * of {@link android.content.Context#STORAGE_SERVICE}. |
| 487 | * |
| 488 | * @hide |
| 489 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 490 | @UnsupportedAppUsage |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 491 | public StorageManager(Context context, Looper looper) throws ServiceNotFoundException { |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 492 | mContext = context; |
| 493 | mResolver = context.getContentResolver(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 494 | mLooper = looper; |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 495 | mStorageManager = IStorageManager.Stub.asInterface(ServiceManager.getServiceOrThrow("mount")); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 496 | } |
| 497 | |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 498 | /** |
| 499 | * Registers a {@link android.os.storage.StorageEventListener StorageEventListener}. |
| 500 | * |
| 501 | * @param listener A {@link android.os.storage.StorageEventListener StorageEventListener} object. |
| 502 | * |
Kenny Root | ec7c9ff | 2011-01-17 09:11:21 -0800 | [diff] [blame] | 503 | * @hide |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 504 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 505 | @UnsupportedAppUsage |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 506 | public void registerListener(StorageEventListener listener) { |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 507 | synchronized (mDelegates) { |
| 508 | final StorageEventListenerDelegate delegate = new StorageEventListenerDelegate(listener, |
| 509 | mLooper); |
| 510 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 511 | mStorageManager.registerListener(delegate); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 512 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 513 | throw e.rethrowFromSystemServer(); |
Chuanxia Dong | 6614bb6 | 2012-05-29 12:28:24 +0800 | [diff] [blame] | 514 | } |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 515 | mDelegates.add(delegate); |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Unregisters a {@link android.os.storage.StorageEventListener StorageEventListener}. |
| 521 | * |
| 522 | * @param listener A {@link android.os.storage.StorageEventListener StorageEventListener} object. |
| 523 | * |
Kenny Root | ec7c9ff | 2011-01-17 09:11:21 -0800 | [diff] [blame] | 524 | * @hide |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 525 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 526 | @UnsupportedAppUsage |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 527 | public void unregisterListener(StorageEventListener listener) { |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 528 | synchronized (mDelegates) { |
| 529 | for (Iterator<StorageEventListenerDelegate> i = mDelegates.iterator(); i.hasNext();) { |
| 530 | final StorageEventListenerDelegate delegate = i.next(); |
| 531 | if (delegate.mCallback == listener) { |
| 532 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 533 | mStorageManager.unregisterListener(delegate); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 534 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 535 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 536 | } |
| 537 | i.remove(); |
| 538 | } |
| 539 | } |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 540 | } |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Enables USB Mass Storage (UMS) on the device. |
Kenny Root | ec7c9ff | 2011-01-17 09:11:21 -0800 | [diff] [blame] | 545 | * |
| 546 | * @hide |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 547 | */ |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 548 | @Deprecated |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 549 | @UnsupportedAppUsage |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 550 | public void enableUsbMassStorage() { |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Disables USB Mass Storage (UMS) on the device. |
Kenny Root | ec7c9ff | 2011-01-17 09:11:21 -0800 | [diff] [blame] | 555 | * |
| 556 | * @hide |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 557 | */ |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 558 | @Deprecated |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 559 | @UnsupportedAppUsage |
Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 560 | public void disableUsbMassStorage() { |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Query if a USB Mass Storage (UMS) host is connected. |
| 565 | * @return true if UMS host is connected. |
Kenny Root | ec7c9ff | 2011-01-17 09:11:21 -0800 | [diff] [blame] | 566 | * |
| 567 | * @hide |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 568 | */ |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 569 | @Deprecated |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 570 | @UnsupportedAppUsage |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 571 | public boolean isUsbMassStorageConnected() { |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 572 | return false; |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Query if a USB Mass Storage (UMS) is enabled on the device. |
| 577 | * @return true if UMS host is enabled. |
Kenny Root | ec7c9ff | 2011-01-17 09:11:21 -0800 | [diff] [blame] | 578 | * |
| 579 | * @hide |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 580 | */ |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 581 | @Deprecated |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 582 | @UnsupportedAppUsage |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 583 | public boolean isUsbMassStorageEnabled() { |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 584 | return false; |
| 585 | } |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 586 | |
| 587 | /** |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 588 | * Mount an Opaque Binary Blob (OBB) file. If a <code>key</code> is |
| 589 | * specified, it is supplied to the mounting process to be used in any |
| 590 | * encryption used in the OBB. |
| 591 | * <p> |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 592 | * The OBB will remain mounted for as long as the StorageManager reference |
| 593 | * is held by the application. As soon as this reference is lost, the OBBs |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 594 | * in use will be unmounted. The {@link OnObbStateChangeListener} registered |
| 595 | * with this call will receive the success or failure of this operation. |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 596 | * <p> |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 597 | * <em>Note:</em> you can only mount OBB files for which the OBB tag on the |
| 598 | * file matches a package ID that is owned by the calling program's UID. |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 599 | * That is, shared UID applications can attempt to mount any other |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 600 | * application's OBB that shares its UID. |
Daichi Hirono | 9e8d9e2 | 2015-11-13 14:37:00 +0900 | [diff] [blame] | 601 | * |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 602 | * @param rawPath the path to the OBB file |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 603 | * @param key secret used to encrypt the OBB; may be <code>null</code> if no |
| 604 | * encryption was used on the OBB. |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 605 | * @param listener will receive the success or failure of the operation |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 606 | * @return whether the mount call was successfully queued or not |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 607 | */ |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 608 | public boolean mountObb(String rawPath, String key, OnObbStateChangeListener listener) { |
| 609 | Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); |
| 610 | Preconditions.checkNotNull(listener, "listener cannot be null"); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 611 | |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 612 | try { |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 613 | final String canonicalPath = new File(rawPath).getCanonicalPath(); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 614 | final int nonce = mObbActionListener.addListener(listener); |
Sudheer Shanka | 25469aa | 2018-08-27 15:50:23 -0700 | [diff] [blame] | 615 | mStorageManager.mountObb(rawPath, canonicalPath, key, mObbActionListener, nonce, |
| 616 | getObbInfo(canonicalPath)); |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 617 | return true; |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 618 | } catch (IOException e) { |
| 619 | throw new IllegalArgumentException("Failed to resolve path: " + rawPath, e); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 620 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 621 | throw e.rethrowFromSystemServer(); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 622 | } |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Sudheer Shanka | 25469aa | 2018-08-27 15:50:23 -0700 | [diff] [blame] | 625 | private ObbInfo getObbInfo(String canonicalPath) { |
| 626 | try { |
| 627 | final ObbInfo obbInfo = ObbScanner.getObbInfo(canonicalPath); |
| 628 | return obbInfo; |
| 629 | } catch (IOException e) { |
| 630 | throw new IllegalArgumentException("Couldn't get OBB info for " + canonicalPath, e); |
| 631 | } |
| 632 | } |
| 633 | |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 634 | /** |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 635 | * Unmount an Opaque Binary Blob (OBB) file asynchronously. If the |
| 636 | * <code>force</code> flag is true, it will kill any application needed to |
| 637 | * unmount the given OBB (even the calling application). |
| 638 | * <p> |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 639 | * The {@link OnObbStateChangeListener} registered with this call will |
| 640 | * receive the success or failure of this operation. |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 641 | * <p> |
| 642 | * <em>Note:</em> you can only mount OBB files for which the OBB tag on the |
| 643 | * file matches a package ID that is owned by the calling program's UID. |
| 644 | * That is, shared UID applications can obtain access to any other |
| 645 | * application's OBB that shares its UID. |
Kenny Root | 02ca31f | 2010-08-12 07:36:02 -0700 | [diff] [blame] | 646 | * <p> |
Daichi Hirono | 9e8d9e2 | 2015-11-13 14:37:00 +0900 | [diff] [blame] | 647 | * |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 648 | * @param rawPath path to the OBB file |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 649 | * @param force whether to kill any programs using this in order to unmount |
| 650 | * it |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 651 | * @param listener will receive the success or failure of the operation |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 652 | * @return whether the unmount call was successfully queued or not |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 653 | */ |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 654 | public boolean unmountObb(String rawPath, boolean force, OnObbStateChangeListener listener) { |
| 655 | Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); |
| 656 | Preconditions.checkNotNull(listener, "listener cannot be null"); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 657 | |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 658 | try { |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 659 | final int nonce = mObbActionListener.addListener(listener); |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 660 | mStorageManager.unmountObb(rawPath, force, mObbActionListener, nonce); |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 661 | return true; |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 662 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 663 | throw e.rethrowFromSystemServer(); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 664 | } |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 667 | /** |
| 668 | * Check whether an Opaque Binary Blob (OBB) is mounted or not. |
Daichi Hirono | 9e8d9e2 | 2015-11-13 14:37:00 +0900 | [diff] [blame] | 669 | * |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 670 | * @param rawPath path to OBB image |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 671 | * @return true if OBB is mounted; false if not mounted or on error |
| 672 | */ |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 673 | public boolean isObbMounted(String rawPath) { |
| 674 | Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 675 | |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 676 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 677 | return mStorageManager.isObbMounted(rawPath); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 678 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 679 | throw e.rethrowFromSystemServer(); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 680 | } |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /** |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 684 | * Check the mounted path of an Opaque Binary Blob (OBB) file. This will |
| 685 | * give you the path to where you can obtain access to the internals of the |
| 686 | * OBB. |
Daichi Hirono | 9e8d9e2 | 2015-11-13 14:37:00 +0900 | [diff] [blame] | 687 | * |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 688 | * @param rawPath path to OBB image |
Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 689 | * @return absolute path to mounted OBB image data or <code>null</code> if |
| 690 | * not mounted or exception encountered trying to read status |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 691 | */ |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 692 | public String getMountedObbPath(String rawPath) { |
| 693 | Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 694 | |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 695 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 696 | return mStorageManager.getMountedObbPath(rawPath); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 697 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 698 | throw e.rethrowFromSystemServer(); |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 699 | } |
Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 700 | } |
Mike Lockwood | d967f46 | 2011-03-24 08:12:30 -0700 | [diff] [blame] | 701 | |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 702 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 703 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 704 | public @NonNull List<DiskInfo> getDisks() { |
| 705 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 706 | return Arrays.asList(mStorageManager.getDisks()); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 707 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 708 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
| 712 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 713 | @UnsupportedAppUsage |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 714 | public @Nullable DiskInfo findDiskById(String id) { |
| 715 | Preconditions.checkNotNull(id); |
| 716 | // TODO; go directly to service to make this faster |
| 717 | for (DiskInfo disk : getDisks()) { |
| 718 | if (Objects.equals(disk.id, id)) { |
| 719 | return disk; |
| 720 | } |
| 721 | } |
| 722 | return null; |
| 723 | } |
| 724 | |
| 725 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 726 | @UnsupportedAppUsage |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 727 | public @Nullable VolumeInfo findVolumeById(String id) { |
| 728 | Preconditions.checkNotNull(id); |
| 729 | // TODO; go directly to service to make this faster |
| 730 | for (VolumeInfo vol : getVolumes()) { |
| 731 | if (Objects.equals(vol.id, id)) { |
| 732 | return vol; |
| 733 | } |
| 734 | } |
| 735 | return null; |
| 736 | } |
| 737 | |
| 738 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 739 | @UnsupportedAppUsage |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 740 | public @Nullable VolumeInfo findVolumeByUuid(String fsUuid) { |
| 741 | Preconditions.checkNotNull(fsUuid); |
| 742 | // TODO; go directly to service to make this faster |
| 743 | for (VolumeInfo vol : getVolumes()) { |
| 744 | if (Objects.equals(vol.fsUuid, fsUuid)) { |
| 745 | return vol; |
| 746 | } |
| 747 | } |
| 748 | return null; |
| 749 | } |
| 750 | |
| 751 | /** {@hide} */ |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 752 | public @Nullable VolumeRecord findRecordByUuid(String fsUuid) { |
| 753 | Preconditions.checkNotNull(fsUuid); |
| 754 | // TODO; go directly to service to make this faster |
| 755 | for (VolumeRecord rec : getVolumeRecords()) { |
| 756 | if (Objects.equals(rec.fsUuid, fsUuid)) { |
| 757 | return rec; |
| 758 | } |
| 759 | } |
| 760 | return null; |
| 761 | } |
| 762 | |
| 763 | /** {@hide} */ |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 764 | public @Nullable VolumeInfo findPrivateForEmulated(VolumeInfo emulatedVol) { |
Jeff Sharkey | ef10ee0 | 2015-07-05 14:17:27 -0700 | [diff] [blame] | 765 | if (emulatedVol != null) { |
| 766 | return findVolumeById(emulatedVol.getId().replace("emulated", "private")); |
| 767 | } else { |
| 768 | return null; |
| 769 | } |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 773 | @UnsupportedAppUsage |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 774 | public @Nullable VolumeInfo findEmulatedForPrivate(VolumeInfo privateVol) { |
Jeff Sharkey | ef10ee0 | 2015-07-05 14:17:27 -0700 | [diff] [blame] | 775 | if (privateVol != null) { |
| 776 | return findVolumeById(privateVol.getId().replace("private", "emulated")); |
| 777 | } else { |
| 778 | return null; |
| 779 | } |
Jeff Sharkey | 27de30d | 2015-04-18 16:20:27 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /** {@hide} */ |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 783 | public @Nullable VolumeInfo findVolumeByQualifiedUuid(String volumeUuid) { |
| 784 | if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, volumeUuid)) { |
| 785 | return findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL); |
| 786 | } else if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) { |
| 787 | return getPrimaryPhysicalVolume(); |
| 788 | } else { |
| 789 | return findVolumeByUuid(volumeUuid); |
| 790 | } |
| 791 | } |
| 792 | |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 793 | /** |
| 794 | * Return a UUID identifying the storage volume that hosts the given |
| 795 | * filesystem path. |
| 796 | * <p> |
| 797 | * If this path is hosted by the default internal storage of the device at |
| 798 | * {@link Environment#getDataDirectory()}, the returned value will be |
| 799 | * {@link #UUID_DEFAULT}. |
| 800 | * |
Jeff Sharkey | 4233f03 | 2017-07-15 12:58:38 -0600 | [diff] [blame] | 801 | * @throws IOException when the storage device hosting the given path isn't |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 802 | * present, or when it doesn't have a valid UUID. |
| 803 | */ |
| 804 | public @NonNull UUID getUuidForPath(@NonNull File path) throws IOException { |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 805 | Preconditions.checkNotNull(path); |
Jeff Sharkey | 0034788 | 2017-04-17 16:44:12 -0600 | [diff] [blame] | 806 | final String pathString = path.getCanonicalPath(); |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 807 | if (FileUtils.contains(Environment.getDataDirectory().getAbsolutePath(), pathString)) { |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 808 | return UUID_DEFAULT; |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 809 | } |
| 810 | try { |
| 811 | for (VolumeInfo vol : mStorageManager.getVolumes(0)) { |
Jeff Sharkey | 18f3250 | 2018-03-29 14:29:27 -0600 | [diff] [blame] | 812 | if (vol.path != null && FileUtils.contains(vol.path, pathString) |
Risan | 05c41e6 | 2018-10-29 08:57:43 +0900 | [diff] [blame] | 813 | && vol.type != VolumeInfo.TYPE_PUBLIC && vol.type != VolumeInfo.TYPE_STUB) { |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 814 | // TODO: verify that emulated adopted devices have UUID of |
| 815 | // underlying volume |
Jeff Sharkey | 18f3250 | 2018-03-29 14:29:27 -0600 | [diff] [blame] | 816 | try { |
| 817 | return convert(vol.fsUuid); |
| 818 | } catch (IllegalArgumentException e) { |
| 819 | continue; |
| 820 | } |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 821 | } |
| 822 | } |
| 823 | } catch (RemoteException e) { |
| 824 | throw e.rethrowFromSystemServer(); |
| 825 | } |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 826 | throw new FileNotFoundException("Failed to find a storage device for " + path); |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** {@hide} */ |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 830 | public @NonNull File findPathForUuid(String volumeUuid) throws FileNotFoundException { |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 831 | final VolumeInfo vol = findVolumeByQualifiedUuid(volumeUuid); |
| 832 | if (vol != null) { |
| 833 | return vol.getPath(); |
| 834 | } |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 835 | throw new FileNotFoundException("Failed to find a storage device for " + volumeUuid); |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Jeff Sharkey | 4233f03 | 2017-07-15 12:58:38 -0600 | [diff] [blame] | 838 | /** |
| 839 | * Test if the given file descriptor supports allocation of disk space using |
| 840 | * {@link #allocateBytes(FileDescriptor, long)}. |
| 841 | */ |
| 842 | public boolean isAllocationSupported(@NonNull FileDescriptor fd) { |
| 843 | try { |
| 844 | getUuidForPath(ParcelFileDescriptor.getFile(fd)); |
| 845 | return true; |
| 846 | } catch (IOException e) { |
| 847 | return false; |
| 848 | } |
| 849 | } |
| 850 | |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 851 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 852 | @UnsupportedAppUsage |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 853 | public @NonNull List<VolumeInfo> getVolumes() { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 854 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 855 | return Arrays.asList(mStorageManager.getVolumes(0)); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 856 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 857 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 858 | } |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | /** {@hide} */ |
Jeff Sharkey | 6dce496 | 2015-07-03 18:08:41 -0700 | [diff] [blame] | 862 | public @NonNull List<VolumeInfo> getWritablePrivateVolumes() { |
| 863 | try { |
| 864 | final ArrayList<VolumeInfo> res = new ArrayList<>(); |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 865 | for (VolumeInfo vol : mStorageManager.getVolumes(0)) { |
Jeff Sharkey | 6dce496 | 2015-07-03 18:08:41 -0700 | [diff] [blame] | 866 | if (vol.getType() == VolumeInfo.TYPE_PRIVATE && vol.isMountedWritable()) { |
| 867 | res.add(vol); |
| 868 | } |
| 869 | } |
| 870 | return res; |
| 871 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 872 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 6dce496 | 2015-07-03 18:08:41 -0700 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | |
| 876 | /** {@hide} */ |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 877 | public @NonNull List<VolumeRecord> getVolumeRecords() { |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 878 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 879 | return Arrays.asList(mStorageManager.getVolumeRecords(0)); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 880 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 881 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 1b8ef7e | 2015-04-03 17:14:45 -0700 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | |
| 885 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 886 | @UnsupportedAppUsage |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 887 | public @Nullable String getBestVolumeDescription(VolumeInfo vol) { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 888 | if (vol == null) return null; |
| 889 | |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 890 | // Nickname always takes precedence when defined |
| 891 | if (!TextUtils.isEmpty(vol.fsUuid)) { |
| 892 | final VolumeRecord rec = findRecordByUuid(vol.fsUuid); |
Jeff Sharkey | c840681 | 2015-05-04 12:04:09 -0700 | [diff] [blame] | 893 | if (rec != null && !TextUtils.isEmpty(rec.nickname)) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 894 | return rec.nickname; |
Jeff Sharkey | 56bd312 | 2015-04-14 10:30:34 -0700 | [diff] [blame] | 895 | } |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 896 | } |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 897 | |
| 898 | if (!TextUtils.isEmpty(vol.getDescription())) { |
| 899 | return vol.getDescription(); |
| 900 | } |
| 901 | |
| 902 | if (vol.disk != null) { |
| 903 | return vol.disk.getDescription(); |
| 904 | } |
| 905 | |
| 906 | return null; |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 910 | @UnsupportedAppUsage |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 911 | public @Nullable VolumeInfo getPrimaryPhysicalVolume() { |
| 912 | final List<VolumeInfo> vols = getVolumes(); |
| 913 | for (VolumeInfo vol : vols) { |
| 914 | if (vol.isPrimaryPhysical()) { |
| 915 | return vol; |
| 916 | } |
| 917 | } |
| 918 | return null; |
| 919 | } |
| 920 | |
| 921 | /** {@hide} */ |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 922 | public void mount(String volId) { |
| 923 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 924 | mStorageManager.mount(volId); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 925 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 926 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 931 | @UnsupportedAppUsage |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 932 | public void unmount(String volId) { |
| 933 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 934 | mStorageManager.unmount(volId); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 935 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 936 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
| 940 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 941 | @UnsupportedAppUsage |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 942 | public void format(String volId) { |
| 943 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 944 | mStorageManager.format(volId); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 945 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 946 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
| 950 | /** {@hide} */ |
Jeff Sharkey | 7e19f53 | 2017-11-06 13:54:11 -0700 | [diff] [blame] | 951 | @Deprecated |
Jeff Sharkey | 9756d75 | 2015-05-14 21:07:42 -0700 | [diff] [blame] | 952 | public long benchmark(String volId) { |
Jeff Sharkey | 7e19f53 | 2017-11-06 13:54:11 -0700 | [diff] [blame] | 953 | final CompletableFuture<PersistableBundle> result = new CompletableFuture<>(); |
| 954 | benchmark(volId, new IVoldTaskListener.Stub() { |
| 955 | @Override |
| 956 | public void onStatus(int status, PersistableBundle extras) { |
| 957 | // Ignored |
| 958 | } |
| 959 | |
| 960 | @Override |
| 961 | public void onFinished(int status, PersistableBundle extras) { |
| 962 | result.complete(extras); |
| 963 | } |
| 964 | }); |
Jeff Sharkey | 9756d75 | 2015-05-14 21:07:42 -0700 | [diff] [blame] | 965 | try { |
Jeff Sharkey | 7e19f53 | 2017-11-06 13:54:11 -0700 | [diff] [blame] | 966 | // Convert ms to ns |
| 967 | return result.get(3, TimeUnit.MINUTES).getLong("run", Long.MAX_VALUE) * 1000000; |
| 968 | } catch (Exception e) { |
| 969 | return Long.MAX_VALUE; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | /** {@hide} */ |
| 974 | public void benchmark(String volId, IVoldTaskListener listener) { |
| 975 | try { |
| 976 | mStorageManager.benchmark(volId, listener); |
Jeff Sharkey | 9756d75 | 2015-05-14 21:07:42 -0700 | [diff] [blame] | 977 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 978 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 9756d75 | 2015-05-14 21:07:42 -0700 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 983 | @UnsupportedAppUsage |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 984 | public void partitionPublic(String diskId) { |
| 985 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 986 | mStorageManager.partitionPublic(diskId); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 987 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 988 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
| 992 | /** {@hide} */ |
| 993 | public void partitionPrivate(String diskId) { |
| 994 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 995 | mStorageManager.partitionPrivate(diskId); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 996 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 997 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
| 1001 | /** {@hide} */ |
| 1002 | public void partitionMixed(String diskId, int ratio) { |
| 1003 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1004 | mStorageManager.partitionMixed(diskId, ratio); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 1005 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1006 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 7151a9a | 2015-04-04 15:22:37 -0700 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | /** {@hide} */ |
Jeff Sharkey | b42d694 | 2015-04-28 22:25:26 -0700 | [diff] [blame] | 1011 | public void wipeAdoptableDisks() { |
| 1012 | // We only wipe devices in "adoptable" locations, which are in a |
| 1013 | // long-term stable slot/location on the device, where apps have a |
| 1014 | // reasonable chance of storing sensitive data. (Apps need to go through |
| 1015 | // SAF to write to transient volumes.) |
| 1016 | final List<DiskInfo> disks = getDisks(); |
| 1017 | for (DiskInfo disk : disks) { |
| 1018 | final String diskId = disk.getId(); |
| 1019 | if (disk.isAdoptable()) { |
| 1020 | Slog.d(TAG, "Found adoptable " + diskId + "; wiping"); |
| 1021 | try { |
| 1022 | // TODO: switch to explicit wipe command when we have it, |
| 1023 | // for now rely on the fact that vfat format does a wipe |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1024 | mStorageManager.partitionPublic(diskId); |
Jeff Sharkey | b42d694 | 2015-04-28 22:25:26 -0700 | [diff] [blame] | 1025 | } catch (Exception e) { |
| 1026 | Slog.w(TAG, "Failed to wipe " + diskId + ", but soldiering onward", e); |
| 1027 | } |
| 1028 | } else { |
| 1029 | Slog.d(TAG, "Ignorning non-adoptable disk " + disk.getId()); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | /** {@hide} */ |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 1035 | public void setVolumeNickname(String fsUuid, String nickname) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1036 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1037 | mStorageManager.setVolumeNickname(fsUuid, nickname); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1038 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1039 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /** {@hide} */ |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 1044 | public void setVolumeInited(String fsUuid, boolean inited) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1045 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1046 | mStorageManager.setVolumeUserFlags(fsUuid, inited ? VolumeRecord.USER_FLAG_INITED : 0, |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 1047 | VolumeRecord.USER_FLAG_INITED); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1048 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1049 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | /** {@hide} */ |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 1054 | public void setVolumeSnoozed(String fsUuid, boolean snoozed) { |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1055 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1056 | mStorageManager.setVolumeUserFlags(fsUuid, snoozed ? VolumeRecord.USER_FLAG_SNOOZED : 0, |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 1057 | VolumeRecord.USER_FLAG_SNOOZED); |
| 1058 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1059 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | /** {@hide} */ |
| 1064 | public void forgetVolume(String fsUuid) { |
| 1065 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1066 | mStorageManager.forgetVolume(fsUuid); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1067 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1068 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | d95d3bf | 2015-04-14 21:39:44 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | |
Jeff Sharkey | 275e3e4 | 2015-04-24 16:10:32 -0700 | [diff] [blame] | 1072 | /** |
| 1073 | * This is not the API you're looking for. |
| 1074 | * |
| 1075 | * @see PackageManager#getPrimaryStorageCurrentVolume() |
| 1076 | * @hide |
| 1077 | */ |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1078 | public String getPrimaryStorageUuid() { |
| 1079 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1080 | return mStorageManager.getPrimaryStorageUuid(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1081 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1082 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | |
Jeff Sharkey | 275e3e4 | 2015-04-24 16:10:32 -0700 | [diff] [blame] | 1086 | /** |
| 1087 | * This is not the API you're looking for. |
| 1088 | * |
| 1089 | * @see PackageManager#movePrimaryStorage(VolumeInfo) |
| 1090 | * @hide |
| 1091 | */ |
| 1092 | public void setPrimaryStorageUuid(String volumeUuid, IPackageMoveObserver callback) { |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1093 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1094 | mStorageManager.setPrimaryStorageUuid(volumeUuid, callback); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1095 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1096 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
Felipe Leme | c250e45 | 2016-04-11 18:44:33 -0700 | [diff] [blame] | 1100 | /** |
Jeff Sharkey | f8fa940 | 2019-02-18 13:23:51 -0700 | [diff] [blame] | 1101 | * Return the {@link StorageVolume} that contains the given file, or |
| 1102 | * {@code null} if none. |
Felipe Leme | c250e45 | 2016-04-11 18:44:33 -0700 | [diff] [blame] | 1103 | */ |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1104 | public @Nullable StorageVolume getStorageVolume(File file) { |
| 1105 | return getStorageVolume(getVolumeList(), file); |
| 1106 | } |
| 1107 | |
Jeff Sharkey | f8fa940 | 2019-02-18 13:23:51 -0700 | [diff] [blame] | 1108 | /** |
| 1109 | * Return the {@link StorageVolume} that contains the given |
| 1110 | * {@link MediaStore} item. |
| 1111 | */ |
| 1112 | public @NonNull StorageVolume getStorageVolume(@NonNull Uri uri) { |
| 1113 | final String volumeName = MediaStore.getVolumeName(uri); |
| 1114 | switch (volumeName) { |
| 1115 | case MediaStore.VOLUME_EXTERNAL: |
| 1116 | return getPrimaryStorageVolume(); |
| 1117 | default: |
| 1118 | for (StorageVolume vol : getStorageVolumes()) { |
| 1119 | if (Objects.equals(vol.getNormalizedUuid(), volumeName)) { |
| 1120 | return vol; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | throw new IllegalStateException("Unknown volume for " + uri); |
| 1125 | } |
| 1126 | |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1127 | /** {@hide} */ |
| 1128 | public static @Nullable StorageVolume getStorageVolume(File file, int userId) { |
Jeff Sharkey | 4634987 | 2015-07-28 10:49:47 -0700 | [diff] [blame] | 1129 | return getStorageVolume(getVolumeList(userId, 0), file); |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1133 | @UnsupportedAppUsage |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1134 | private static @Nullable StorageVolume getStorageVolume(StorageVolume[] volumes, File file) { |
Felipe Leme | c250e45 | 2016-04-11 18:44:33 -0700 | [diff] [blame] | 1135 | if (file == null) { |
| 1136 | return null; |
| 1137 | } |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1138 | try { |
Jeff Sharkey | 98329459 | 2015-07-13 10:25:31 -0700 | [diff] [blame] | 1139 | file = file.getCanonicalFile(); |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1140 | } catch (IOException ignored) { |
Felipe Leme | c250e45 | 2016-04-11 18:44:33 -0700 | [diff] [blame] | 1141 | Slog.d(TAG, "Could not get canonical path for " + file); |
Jeff Sharkey | 98329459 | 2015-07-13 10:25:31 -0700 | [diff] [blame] | 1142 | return null; |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1143 | } |
| 1144 | for (StorageVolume volume : volumes) { |
Jeff Sharkey | 98329459 | 2015-07-13 10:25:31 -0700 | [diff] [blame] | 1145 | File volumeFile = volume.getPathFile(); |
| 1146 | try { |
| 1147 | volumeFile = volumeFile.getCanonicalFile(); |
| 1148 | } catch (IOException ignored) { |
| 1149 | continue; |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1150 | } |
Jeff Sharkey | 98329459 | 2015-07-13 10:25:31 -0700 | [diff] [blame] | 1151 | if (FileUtils.contains(volumeFile, file)) { |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1152 | return volume; |
| 1153 | } |
| 1154 | } |
| 1155 | return null; |
| 1156 | } |
| 1157 | |
Mike Lockwood | d967f46 | 2011-03-24 08:12:30 -0700 | [diff] [blame] | 1158 | /** |
| 1159 | * Gets the state of a volume via its mountpoint. |
| 1160 | * @hide |
| 1161 | */ |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1162 | @Deprecated |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1163 | @UnsupportedAppUsage |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1164 | public @NonNull String getVolumeState(String mountPoint) { |
| 1165 | final StorageVolume vol = getStorageVolume(new File(mountPoint)); |
| 1166 | if (vol != null) { |
| 1167 | return vol.getState(); |
| 1168 | } else { |
| 1169 | return Environment.MEDIA_UNKNOWN; |
Mike Lockwood | d967f46 | 2011-03-24 08:12:30 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
Felipe Leme | 04a5d40 | 2016-02-08 16:44:06 -0800 | [diff] [blame] | 1173 | /** |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 1174 | * Return the list of shared/external storage volumes available to the |
| 1175 | * current user. This includes both the primary shared storage device and |
| 1176 | * any attached external volumes including SD cards and USB drives. |
Felipe Leme | 04a5d40 | 2016-02-08 16:44:06 -0800 | [diff] [blame] | 1177 | * |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 1178 | * @see Environment#getExternalStorageDirectory() |
| 1179 | * @see StorageVolume#createAccessIntent(String) |
Felipe Leme | 04a5d40 | 2016-02-08 16:44:06 -0800 | [diff] [blame] | 1180 | */ |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 1181 | public @NonNull List<StorageVolume> getStorageVolumes() { |
| 1182 | final ArrayList<StorageVolume> res = new ArrayList<>(); |
| 1183 | Collections.addAll(res, |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 1184 | getVolumeList(mContext.getUserId(), FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE)); |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 1185 | return res; |
| 1186 | } |
| 1187 | |
| 1188 | /** |
| 1189 | * Return the primary shared/external storage volume available to the |
| 1190 | * current user. This volume is the same storage device returned by |
| 1191 | * {@link Environment#getExternalStorageDirectory()} and |
| 1192 | * {@link Context#getExternalFilesDir(String)}. |
| 1193 | */ |
| 1194 | public @NonNull StorageVolume getPrimaryStorageVolume() { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 1195 | return getVolumeList(mContext.getUserId(), FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE)[0]; |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 1196 | } |
| 1197 | |
Felipe Leme | 18202e00b | 2016-05-12 12:56:28 -0700 | [diff] [blame] | 1198 | /** {@hide} */ |
Felipe Leme | 281389a | 2016-10-10 17:12:20 -0700 | [diff] [blame] | 1199 | public static Pair<String, Long> getPrimaryStoragePathAndSize() { |
Jeff Sharkey | 24403ff | 2017-04-04 15:09:58 -0600 | [diff] [blame] | 1200 | return Pair.create(null, |
hj.seo | e82e89ef9 | 2017-12-20 09:39:47 +0900 | [diff] [blame] | 1201 | FileUtils.roundStorageSize(Environment.getDataDirectory().getTotalSpace() |
| 1202 | + Environment.getRootDirectory().getTotalSpace())); |
Felipe Leme | 18202e00b | 2016-05-12 12:56:28 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Felipe Leme | 281389a | 2016-10-10 17:12:20 -0700 | [diff] [blame] | 1205 | /** {@hide} */ |
| 1206 | public long getPrimaryStorageSize() { |
hj.seo | e82e89ef9 | 2017-12-20 09:39:47 +0900 | [diff] [blame] | 1207 | return FileUtils.roundStorageSize(Environment.getDataDirectory().getTotalSpace() |
| 1208 | + Environment.getRootDirectory().getTotalSpace()); |
Felipe Leme | 18202e00b | 2016-05-12 12:56:28 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Jeff Sharkey | ae26646 | 2017-11-27 13:32:24 -0700 | [diff] [blame] | 1211 | /** {@hide} */ |
| 1212 | public void mkdirs(File file) { |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 1213 | BlockGuard.getVmPolicy().onPathAccess(file.getAbsolutePath()); |
Jeff Sharkey | ae26646 | 2017-11-27 13:32:24 -0700 | [diff] [blame] | 1214 | try { |
| 1215 | mStorageManager.mkdirs(mContext.getOpPackageName(), file.getAbsolutePath()); |
| 1216 | } catch (RemoteException e) { |
| 1217 | throw e.rethrowFromSystemServer(); |
| 1218 | } |
| 1219 | } |
| 1220 | |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 1221 | /** @removed */ |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1222 | public @NonNull StorageVolume[] getVolumeList() { |
Jeff Sharkey | 4634987 | 2015-07-28 10:49:47 -0700 | [diff] [blame] | 1223 | return getVolumeList(mContext.getUserId(), 0); |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | /** {@hide} */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1227 | @UnsupportedAppUsage |
Jeff Sharkey | 4634987 | 2015-07-28 10:49:47 -0700 | [diff] [blame] | 1228 | public static @NonNull StorageVolume[] getVolumeList(int userId, int flags) { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1229 | final IStorageManager storageManager = IStorageManager.Stub.asInterface( |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1230 | ServiceManager.getService("mount")); |
| 1231 | try { |
Svetoslav | 7395cbf | 2015-07-15 15:58:01 -0700 | [diff] [blame] | 1232 | String packageName = ActivityThread.currentOpPackageName(); |
| 1233 | if (packageName == null) { |
| 1234 | // Package name can be null if the activity thread is running but the app |
| 1235 | // hasn't bound yet. In this case we fall back to the first package in the |
| 1236 | // current UID. This works for runtime permissions as permission state is |
| 1237 | // per UID and permission realted app ops are updated for all UID packages. |
| 1238 | String[] packageNames = ActivityThread.getPackageManager().getPackagesForUid( |
| 1239 | android.os.Process.myUid()); |
| 1240 | if (packageNames == null || packageNames.length <= 0) { |
| 1241 | return new StorageVolume[0]; |
| 1242 | } |
| 1243 | packageName = packageNames[0]; |
| 1244 | } |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 1245 | final int uid = ActivityThread.getPackageManager().getPackageUid(packageName, |
Jeff Sharkey | c5967e9 | 2016-01-07 18:50:29 -0700 | [diff] [blame] | 1246 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
Svetoslav | 7395cbf | 2015-07-15 15:58:01 -0700 | [diff] [blame] | 1247 | if (uid <= 0) { |
| 1248 | return new StorageVolume[0]; |
| 1249 | } |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1250 | return storageManager.getVolumeList(uid, packageName, flags); |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1251 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1252 | throw e.rethrowFromSystemServer(); |
Mike Lockwood | d967f46 | 2011-03-24 08:12:30 -0700 | [diff] [blame] | 1253 | } |
| 1254 | } |
Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1255 | |
| 1256 | /** |
| 1257 | * Returns list of paths for all mountable volumes. |
| 1258 | * @hide |
| 1259 | */ |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1260 | @Deprecated |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1261 | @UnsupportedAppUsage |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1262 | public @NonNull String[] getVolumePaths() { |
Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1263 | StorageVolume[] volumes = getVolumeList(); |
Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1264 | int count = volumes.length; |
| 1265 | String[] paths = new String[count]; |
| 1266 | for (int i = 0; i < count; i++) { |
| 1267 | paths[i] = volumes[i].getPath(); |
| 1268 | } |
| 1269 | return paths; |
| 1270 | } |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 1271 | |
Jeff Sharkey | c02bfae | 2016-03-27 15:06:53 -0600 | [diff] [blame] | 1272 | /** @removed */ |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1273 | public @NonNull StorageVolume getPrimaryVolume() { |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 1274 | return getPrimaryVolume(getVolumeList()); |
| 1275 | } |
| 1276 | |
| 1277 | /** {@hide} */ |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1278 | public static @NonNull StorageVolume getPrimaryVolume(StorageVolume[] volumes) { |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 1279 | for (StorageVolume volume : volumes) { |
| 1280 | if (volume.isPrimary()) { |
| 1281 | return volume; |
| 1282 | } |
| 1283 | } |
Jeff Sharkey | 4887789 | 2015-03-18 11:27:19 -0700 | [diff] [blame] | 1284 | throw new IllegalStateException("Missing primary storage"); |
Jeff Sharkey | b049e21 | 2012-09-07 23:16:01 -0700 | [diff] [blame] | 1285 | } |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 1286 | |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1287 | private static final int DEFAULT_THRESHOLD_PERCENTAGE = 5; |
Jeff Sharkey | 9f2dc05 | 2018-01-07 16:47:31 -0700 | [diff] [blame] | 1288 | private static final long DEFAULT_THRESHOLD_MAX_BYTES = DataUnit.MEBIBYTES.toBytes(500); |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1289 | |
| 1290 | private static final int DEFAULT_CACHE_PERCENTAGE = 10; |
Jeff Sharkey | 9f2dc05 | 2018-01-07 16:47:31 -0700 | [diff] [blame] | 1291 | private static final long DEFAULT_CACHE_MAX_BYTES = DataUnit.GIBIBYTES.toBytes(5); |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1292 | |
Jeff Sharkey | 9f2dc05 | 2018-01-07 16:47:31 -0700 | [diff] [blame] | 1293 | private static final long DEFAULT_FULL_THRESHOLD_BYTES = DataUnit.MEBIBYTES.toBytes(1); |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 1294 | |
| 1295 | /** |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 1296 | * Return the number of available bytes until the given path is considered |
| 1297 | * running low on storage. |
| 1298 | * |
| 1299 | * @hide |
| 1300 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1301 | @UnsupportedAppUsage |
Jeff Sharkey | 742e790 | 2014-08-16 19:09:13 -0700 | [diff] [blame] | 1302 | public long getStorageBytesUntilLow(File path) { |
| 1303 | return path.getUsableSpace() - getStorageFullBytes(path); |
| 1304 | } |
| 1305 | |
| 1306 | /** |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 1307 | * Return the number of available bytes at which the given path is |
| 1308 | * considered running low on storage. |
| 1309 | * |
| 1310 | * @hide |
| 1311 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1312 | @UnsupportedAppUsage |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 1313 | public long getStorageLowBytes(File path) { |
| 1314 | final long lowPercent = Settings.Global.getInt(mResolver, |
| 1315 | Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE, DEFAULT_THRESHOLD_PERCENTAGE); |
| 1316 | final long lowBytes = (path.getTotalSpace() * lowPercent) / 100; |
| 1317 | |
| 1318 | final long maxLowBytes = Settings.Global.getLong(mResolver, |
| 1319 | Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES, DEFAULT_THRESHOLD_MAX_BYTES); |
| 1320 | |
| 1321 | return Math.min(lowBytes, maxLowBytes); |
| 1322 | } |
| 1323 | |
| 1324 | /** |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1325 | * Return the minimum number of bytes of storage on the device that should |
| 1326 | * be reserved for cached data. |
| 1327 | * |
| 1328 | * @hide |
| 1329 | */ |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1330 | public long getStorageCacheBytes(File path, @AllocateFlags int flags) { |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1331 | final long cachePercent = Settings.Global.getInt(mResolver, |
| 1332 | Settings.Global.SYS_STORAGE_CACHE_PERCENTAGE, DEFAULT_CACHE_PERCENTAGE); |
| 1333 | final long cacheBytes = (path.getTotalSpace() * cachePercent) / 100; |
| 1334 | |
| 1335 | final long maxCacheBytes = Settings.Global.getLong(mResolver, |
| 1336 | Settings.Global.SYS_STORAGE_CACHE_MAX_BYTES, DEFAULT_CACHE_MAX_BYTES); |
| 1337 | |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1338 | final long result = Math.min(cacheBytes, maxCacheBytes); |
| 1339 | if ((flags & StorageManager.FLAG_ALLOCATE_AGGRESSIVE) != 0) { |
| 1340 | return 0; |
| 1341 | } else if ((flags & StorageManager.FLAG_ALLOCATE_DEFY_ALL_RESERVED) != 0) { |
| 1342 | return 0; |
| 1343 | } else if ((flags & StorageManager.FLAG_ALLOCATE_DEFY_HALF_RESERVED) != 0) { |
| 1344 | return result / 2; |
| 1345 | } else { |
| 1346 | return result; |
| 1347 | } |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /** |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 1351 | * Return the number of available bytes at which the given path is |
| 1352 | * considered full. |
| 1353 | * |
| 1354 | * @hide |
| 1355 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1356 | @UnsupportedAppUsage |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 1357 | public long getStorageFullBytes(File path) { |
| 1358 | return Settings.Global.getLong(mResolver, Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES, |
| 1359 | DEFAULT_FULL_THRESHOLD_BYTES); |
| 1360 | } |
Paul Lawrence | e8fdc54 | 2014-05-28 07:14:17 -0700 | [diff] [blame] | 1361 | |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 1362 | /** {@hide} */ |
Lenka Trochtova | c4dd021 | 2015-11-18 12:22:06 +0100 | [diff] [blame] | 1363 | public void createUserKey(int userId, int serialNumber, boolean ephemeral) { |
Paul Crowley | bcf48ed | 2015-04-22 13:36:59 +0100 | [diff] [blame] | 1364 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1365 | mStorageManager.createUserKey(userId, serialNumber, ephemeral); |
Paul Crowley | bcf48ed | 2015-04-22 13:36:59 +0100 | [diff] [blame] | 1366 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1367 | throw e.rethrowFromSystemServer(); |
Paul Crowley | bcf48ed | 2015-04-22 13:36:59 +0100 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | /** {@hide} */ |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1372 | public void destroyUserKey(int userId) { |
Paul Crowley | 7ec733f | 2015-05-19 12:42:00 +0100 | [diff] [blame] | 1373 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1374 | mStorageManager.destroyUserKey(userId); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1375 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1376 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | /** {@hide} */ |
Paul Crowley | faeb3eb | 2016-02-08 15:58:29 +0000 | [diff] [blame] | 1381 | public void unlockUserKey(int userId, int serialNumber, byte[] token, byte[] secret) { |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1382 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1383 | mStorageManager.unlockUserKey(userId, serialNumber, token, secret); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1384 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1385 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /** {@hide} */ |
| 1390 | public void lockUserKey(int userId) { |
| 1391 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1392 | mStorageManager.lockUserKey(userId); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1393 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1394 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | /** {@hide} */ |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 1399 | public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags) { |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1400 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1401 | mStorageManager.prepareUserStorage(volumeUuid, userId, serialNumber, flags); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1402 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1403 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | /** {@hide} */ |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 1408 | public void destroyUserStorage(String volumeUuid, int userId, int flags) { |
| 1409 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1410 | mStorageManager.destroyUserStorage(volumeUuid, userId, flags); |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 1411 | } catch (RemoteException e) { |
| 1412 | throw e.rethrowFromSystemServer(); |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | /** {@hide} */ |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1417 | public static boolean isUserKeyUnlocked(int userId) { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1418 | if (sStorageManager == null) { |
| 1419 | sStorageManager = IStorageManager.Stub |
Jeff Sharkey | 4815ed4 | 2016-05-26 09:31:04 -0600 | [diff] [blame] | 1420 | .asInterface(ServiceManager.getService("mount")); |
| 1421 | } |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1422 | if (sStorageManager == null) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1423 | Slog.w(TAG, "Early during boot, assuming locked"); |
| 1424 | return false; |
| 1425 | } |
| 1426 | final long token = Binder.clearCallingIdentity(); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 1427 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1428 | return sStorageManager.isUserKeyUnlocked(userId); |
Paul Crowley | 7ec733f | 2015-05-19 12:42:00 +0100 | [diff] [blame] | 1429 | } catch (RemoteException e) { |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 1430 | throw e.rethrowAsRuntimeException(); |
| 1431 | } finally { |
| 1432 | Binder.restoreCallingIdentity(token); |
Paul Crowley | 7ec733f | 2015-05-19 12:42:00 +0100 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 1436 | /** |
Jeff Sharkey | f82c2f0 | 2016-04-12 15:19:10 -0600 | [diff] [blame] | 1437 | * Return if data stored at or under the given path will be encrypted while |
| 1438 | * at rest. This can help apps avoid the overhead of double-encrypting data. |
Jeff Sharkey | cf3f0a1 | 2016-03-17 19:57:58 -0600 | [diff] [blame] | 1439 | */ |
| 1440 | public boolean isEncrypted(File file) { |
| 1441 | if (FileUtils.contains(Environment.getDataDirectory(), file)) { |
| 1442 | return isEncrypted(); |
| 1443 | } else if (FileUtils.contains(Environment.getExpandDirectory(), file)) { |
| 1444 | return true; |
| 1445 | } |
| 1446 | // TODO: extend to support shared storage |
| 1447 | return false; |
| 1448 | } |
| 1449 | |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1450 | /** {@hide} |
| 1451 | * Is this device encryptable or already encrypted? |
| 1452 | * @return true for encryptable or encrypted |
| 1453 | * false not encrypted and not encryptable |
| 1454 | */ |
| 1455 | public static boolean isEncryptable() { |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 1456 | return RoSystemProperties.CRYPTO_ENCRYPTABLE; |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | /** {@hide} |
| 1460 | * Is this device already encrypted? |
| 1461 | * @return true for encrypted. (Implies isEncryptable() == true) |
| 1462 | * false not encrypted |
| 1463 | */ |
| 1464 | public static boolean isEncrypted() { |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 1465 | return RoSystemProperties.CRYPTO_ENCRYPTED; |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /** {@hide} |
| 1469 | * Is this device file encrypted? |
| 1470 | * @return true for file encrypted. (Implies isEncrypted() == true) |
| 1471 | * false not encrypted or block encrypted |
| 1472 | */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 1473 | @UnsupportedAppUsage |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1474 | public static boolean isFileEncryptedNativeOnly() { |
| 1475 | if (!isEncrypted()) { |
| 1476 | return false; |
| 1477 | } |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 1478 | return RoSystemProperties.CRYPTO_FILE_ENCRYPTED; |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | /** {@hide} |
| 1482 | * Is this device block encrypted? |
| 1483 | * @return true for block encrypted. (Implies isEncrypted() == true) |
| 1484 | * false not encrypted or file encrypted |
| 1485 | */ |
| 1486 | public static boolean isBlockEncrypted() { |
| 1487 | if (!isEncrypted()) { |
| 1488 | return false; |
| 1489 | } |
John Reck | aa67f68 | 2016-09-20 14:24:21 -0700 | [diff] [blame] | 1490 | return RoSystemProperties.CRYPTO_BLOCK_ENCRYPTED; |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | /** {@hide} |
| 1494 | * Is this device block encrypted with credentials? |
| 1495 | * @return true for crediential block encrypted. |
| 1496 | * (Implies isBlockEncrypted() == true) |
| 1497 | * false not encrypted, file encrypted or default block encrypted |
| 1498 | */ |
| 1499 | public static boolean isNonDefaultBlockEncrypted() { |
| 1500 | if (!isBlockEncrypted()) { |
| 1501 | return false; |
| 1502 | } |
| 1503 | |
| 1504 | try { |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1505 | IStorageManager storageManager = IStorageManager.Stub.asInterface( |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1506 | ServiceManager.getService("mount")); |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 1507 | return storageManager.getPasswordType() != CRYPT_TYPE_DEFAULT; |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1508 | } catch (RemoteException e) { |
| 1509 | Log.e(TAG, "Error getting encryption type"); |
| 1510 | return false; |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | /** {@hide} |
| 1515 | * Is this device in the process of being block encrypted? |
| 1516 | * @return true for encrypting. |
| 1517 | * false otherwise |
| 1518 | * Whether device isEncrypted at this point is undefined |
| 1519 | * Note that only system services and CryptKeeper will ever see this return |
| 1520 | * true - no app will ever be launched in this state. |
| 1521 | * Also note that this state will not change without a teardown of the |
| 1522 | * framework, so no service needs to check for changes during their lifespan |
| 1523 | */ |
| 1524 | public static boolean isBlockEncrypting() { |
Inseob Kim | c1246e6 | 2018-11-08 13:13:54 +0900 | [diff] [blame] | 1525 | final String state = VoldProperties.encrypt_progress().orElse(""); |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1526 | return !"".equalsIgnoreCase(state); |
| 1527 | } |
| 1528 | |
| 1529 | /** {@hide} |
| 1530 | * Is this device non default block encrypted and in the process of |
| 1531 | * prompting for credentials? |
| 1532 | * @return true for prompting for credentials. |
| 1533 | * (Implies isNonDefaultBlockEncrypted() == true) |
| 1534 | * false otherwise |
| 1535 | * Note that only system services and CryptKeeper will ever see this return |
| 1536 | * true - no app will ever be launched in this state. |
| 1537 | * Also note that this state will not change without a teardown of the |
| 1538 | * framework, so no service needs to check for changes during their lifespan |
| 1539 | */ |
| 1540 | public static boolean inCryptKeeperBounce() { |
Inseob Kim | c1246e6 | 2018-11-08 13:13:54 +0900 | [diff] [blame] | 1541 | final String status = VoldProperties.decrypt().orElse(""); |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1542 | return "trigger_restart_min_framework".equals(status); |
Jeff Sharkey | ce14cd0 | 2015-12-07 15:35:42 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | /** {@hide} */ |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1546 | public static boolean isFileEncryptedEmulatedOnly() { |
Jeff Sharkey | ce14cd0 | 2015-12-07 15:35:42 -0700 | [diff] [blame] | 1547 | return SystemProperties.getBoolean(StorageManager.PROP_EMULATE_FBE, false); |
Clara Bayarri | 965da39 | 2015-10-28 17:53:53 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Paul Lawrence | 20be5d6 | 2016-02-26 13:51:17 -0800 | [diff] [blame] | 1550 | /** {@hide} |
| 1551 | * Is this device running in a file encrypted mode, either native or emulated? |
| 1552 | * @return true for file encrypted, false otherwise |
| 1553 | */ |
| 1554 | public static boolean isFileEncryptedNativeOrEmulated() { |
| 1555 | return isFileEncryptedNativeOnly() |
| 1556 | || isFileEncryptedEmulatedOnly(); |
| 1557 | } |
| 1558 | |
Clara Bayarri | 965da39 | 2015-10-28 17:53:53 +0000 | [diff] [blame] | 1559 | /** {@hide} */ |
Jeff Sharkey | 8eb783b | 2018-01-04 16:46:48 -0700 | [diff] [blame] | 1560 | public static boolean hasAdoptable() { |
| 1561 | return SystemProperties.getBoolean(PROP_HAS_ADOPTABLE, false); |
| 1562 | } |
| 1563 | |
Jeff Sharkey | b91eaa5 | 2019-02-19 11:09:13 -0700 | [diff] [blame] | 1564 | /** |
| 1565 | * Return if the currently booted device has the "isolated storage" feature |
| 1566 | * flag enabled. This will eventually be fully enabled in the final |
| 1567 | * {@link android.os.Build.VERSION_CODES#Q} release. |
| 1568 | * |
| 1569 | * @hide |
| 1570 | */ |
Jeff Sharkey | a1767a29 | 2019-01-05 12:59:04 -0700 | [diff] [blame] | 1571 | @SystemApi |
Jeff Sharkey | 10ec9d8 | 2018-11-28 14:52:45 -0700 | [diff] [blame] | 1572 | @TestApi |
| 1573 | public static boolean hasIsolatedStorage() { |
Jeff Sharkey | 342b4bf | 2018-12-18 11:12:40 -0700 | [diff] [blame] | 1574 | // Prefer to use snapshot for current boot when available |
| 1575 | return SystemProperties.getBoolean(PROP_ISOLATED_STORAGE_SNAPSHOT, |
Jeff Sharkey | 0637680 | 2019-02-11 12:20:02 -0700 | [diff] [blame] | 1576 | SystemProperties.getBoolean(PROP_ISOLATED_STORAGE, true)); |
Jeff Sharkey | 10ec9d8 | 2018-11-28 14:52:45 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Jeff Sharkey | 70eb34a | 2018-09-13 11:57:03 -0600 | [diff] [blame] | 1579 | /** |
| 1580 | * @deprecated disabled now that FUSE has been replaced by sdcardfs |
| 1581 | * @hide |
| 1582 | */ |
| 1583 | @Deprecated |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 1584 | public static File maybeTranslateEmulatedPathToInternal(File path) { |
Jeff Sharkey | 2063e4f | 2017-06-06 16:03:24 -0600 | [diff] [blame] | 1585 | // Disabled now that FUSE has been replaced by sdcardfs |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 1586 | return path; |
| 1587 | } |
| 1588 | |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 1589 | /** |
| 1590 | * Translate given shared storage path from a path in an app sandbox |
| 1591 | * namespace to a path in the system namespace. |
| 1592 | * |
| 1593 | * @hide |
| 1594 | */ |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 1595 | public File translateAppToSystem(File file, int pid, int uid) { |
Jeff Sharkey | d2b64d7 | 2018-10-19 15:40:03 -0600 | [diff] [blame] | 1596 | // We can only translate absolute paths |
| 1597 | if (!file.isAbsolute()) return file; |
| 1598 | |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 1599 | try { |
| 1600 | return new File(mStorageManager.translateAppToSystem(file.getAbsolutePath(), |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 1601 | pid, uid)); |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 1602 | } catch (RemoteException e) { |
| 1603 | throw e.rethrowFromSystemServer(); |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | /** |
| 1608 | * Translate given shared storage path from a path in the system namespace |
| 1609 | * to a path in an app sandbox namespace. |
| 1610 | * |
| 1611 | * @hide |
| 1612 | */ |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 1613 | public File translateSystemToApp(File file, int pid, int uid) { |
Jeff Sharkey | d2b64d7 | 2018-10-19 15:40:03 -0600 | [diff] [blame] | 1614 | // We can only translate absolute paths |
| 1615 | if (!file.isAbsolute()) return file; |
| 1616 | |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 1617 | try { |
| 1618 | return new File(mStorageManager.translateSystemToApp(file.getAbsolutePath(), |
Sudheer Shanka | 87915d6 | 2018-11-06 10:57:35 -0800 | [diff] [blame] | 1619 | pid, uid)); |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 1620 | } catch (RemoteException e) { |
| 1621 | throw e.rethrowFromSystemServer(); |
| 1622 | } |
| 1623 | } |
| 1624 | |
Daichi Hirono | 9e8d9e2 | 2015-11-13 14:37:00 +0900 | [diff] [blame] | 1625 | /** {@hide} */ |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1626 | @VisibleForTesting |
| 1627 | public @NonNull ParcelFileDescriptor openProxyFileDescriptor( |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1628 | int mode, ProxyFileDescriptorCallback callback, Handler handler, ThreadFactory factory) |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1629 | throws IOException { |
Daichi Hirono | 2443a09 | 2017-04-28 14:53:19 +0900 | [diff] [blame] | 1630 | Preconditions.checkNotNull(callback); |
Daichi Hirono | d61817e | 2017-02-13 10:37:11 +0900 | [diff] [blame] | 1631 | MetricsLogger.count(mContext, "storage_open_proxy_file_descriptor", 1); |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1632 | // Retry is needed because the mount point mFuseAppLoop is using may be unmounted before |
| 1633 | // invoking StorageManagerService#openProxyFileDescriptor. In this case, we need to re-mount |
| 1634 | // the bridge by calling mountProxyFileDescriptorBridge. |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1635 | while (true) { |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1636 | try { |
| 1637 | synchronized (mFuseAppLoopLock) { |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1638 | boolean newlyCreated = false; |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1639 | if (mFuseAppLoop == null) { |
| 1640 | final AppFuseMount mount = mStorageManager.mountProxyFileDescriptorBridge(); |
| 1641 | if (mount == null) { |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1642 | throw new IOException("Failed to mount proxy bridge"); |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1643 | } |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1644 | mFuseAppLoop = new FuseAppLoop(mount.mountPointId, mount.fd, factory); |
| 1645 | newlyCreated = true; |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1646 | } |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1647 | if (handler == null) { |
| 1648 | handler = new Handler(Looper.getMainLooper()); |
| 1649 | } |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1650 | try { |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1651 | final int fileId = mFuseAppLoop.registerCallback(callback, handler); |
| 1652 | final ParcelFileDescriptor pfd = mStorageManager.openProxyFileDescriptor( |
| 1653 | mFuseAppLoop.getMountPointId(), fileId, mode); |
| 1654 | if (pfd == null) { |
| 1655 | mFuseAppLoop.unregisterCallback(fileId); |
| 1656 | throw new FuseUnavailableMountException( |
| 1657 | mFuseAppLoop.getMountPointId()); |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1658 | } |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1659 | return pfd; |
| 1660 | } catch (FuseUnavailableMountException exception) { |
| 1661 | // The bridge is being unmounted. Tried to recreate it unless the bridge was |
| 1662 | // just created. |
| 1663 | if (newlyCreated) { |
| 1664 | throw new IOException(exception); |
| 1665 | } |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1666 | mFuseAppLoop = null; |
| 1667 | continue; |
| 1668 | } |
| 1669 | } |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1670 | } catch (RemoteException e) { |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1671 | // Cannot recover from remote exception. |
| 1672 | throw new IOException(e); |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1673 | } |
| 1674 | } |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1675 | } |
| 1676 | |
Daichi Hirono | 2443a09 | 2017-04-28 14:53:19 +0900 | [diff] [blame] | 1677 | /** {@hide} */ |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1678 | public @NonNull ParcelFileDescriptor openProxyFileDescriptor( |
| 1679 | int mode, ProxyFileDescriptorCallback callback) |
| 1680 | throws IOException { |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1681 | return openProxyFileDescriptor(mode, callback, null, null); |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1682 | } |
| 1683 | |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1684 | /** |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1685 | * Opens a seekable {@link ParcelFileDescriptor} that proxies all low-level |
| 1686 | * I/O requests back to the given {@link ProxyFileDescriptorCallback}. |
| 1687 | * <p> |
| 1688 | * This can be useful when you want to provide quick access to a large file |
| 1689 | * that isn't backed by a real file on disk, such as a file on a network |
| 1690 | * share, cloud storage service, etc. As an example, you could respond to a |
| 1691 | * {@link ContentResolver#openFileDescriptor(android.net.Uri, String)} |
| 1692 | * request by returning a {@link ParcelFileDescriptor} created with this |
| 1693 | * method, and then stream the content on-demand as requested. |
| 1694 | * <p> |
| 1695 | * Another useful example might be where you have an encrypted file that |
| 1696 | * you're willing to decrypt on-demand, but where you want to avoid |
| 1697 | * persisting the cleartext version. |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1698 | * |
| 1699 | * @param mode The desired access mode, must be one of |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1700 | * {@link ParcelFileDescriptor#MODE_READ_ONLY}, |
| 1701 | * {@link ParcelFileDescriptor#MODE_WRITE_ONLY}, or |
| 1702 | * {@link ParcelFileDescriptor#MODE_READ_WRITE} |
| 1703 | * @param callback Callback to process file operation requests issued on |
| 1704 | * returned file descriptor. |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1705 | * @param handler Handler that invokes callback methods. |
| 1706 | * @return Seekable ParcelFileDescriptor. |
| 1707 | * @throws IOException |
| 1708 | */ |
| 1709 | public @NonNull ParcelFileDescriptor openProxyFileDescriptor( |
| 1710 | int mode, ProxyFileDescriptorCallback callback, Handler handler) |
| 1711 | throws IOException { |
Daichi Hirono | 2443a09 | 2017-04-28 14:53:19 +0900 | [diff] [blame] | 1712 | Preconditions.checkNotNull(handler); |
Daichi Hirono | 812c95d | 2017-02-08 16:20:20 +0900 | [diff] [blame] | 1713 | return openProxyFileDescriptor(mode, callback, handler, null); |
| 1714 | } |
| 1715 | |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 1716 | /** {@hide} */ |
| 1717 | @VisibleForTesting |
| 1718 | public int getProxyFileDescriptorMountPointId() { |
| 1719 | synchronized (mFuseAppLoopLock) { |
| 1720 | return mFuseAppLoop != null ? mFuseAppLoop.getMountPointId() : -1; |
| 1721 | } |
| 1722 | } |
| 1723 | |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1724 | /** |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1725 | * Return quota size in bytes for all cached data belonging to the calling |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1726 | * app on the given storage volume. |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1727 | * <p> |
| 1728 | * If your app goes above this quota, your cached files will be some of the |
| 1729 | * first to be deleted when additional disk space is needed. Conversely, if |
| 1730 | * your app stays under this quota, your cached files will be some of the |
| 1731 | * last to be deleted when additional disk space is needed. |
| 1732 | * <p> |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1733 | * This quota will change over time depending on how frequently the user |
Jeff Sharkey | 60a82cd | 2017-04-18 18:19:16 -0600 | [diff] [blame] | 1734 | * interacts with your app, and depending on how much system-wide disk space |
| 1735 | * is used. |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1736 | * <p class="note"> |
| 1737 | * Note: if your app uses the {@code android:sharedUserId} manifest feature, |
| 1738 | * then cached data for all packages in your shared UID is tracked together |
| 1739 | * as a single unit. |
| 1740 | * </p> |
| 1741 | * |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1742 | * @param storageUuid the UUID of the storage volume that you're interested |
| 1743 | * in. The UUID for a specific path can be obtained using |
| 1744 | * {@link #getUuidForPath(File)}. |
| 1745 | * @throws IOException when the storage device isn't present, or when it |
| 1746 | * doesn't support cache quotas. |
| 1747 | * @see #getCacheSizeBytes(UUID) |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1748 | */ |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1749 | @WorkerThread |
| 1750 | public @BytesLong long getCacheQuotaBytes(@NonNull UUID storageUuid) throws IOException { |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1751 | try { |
| 1752 | final ApplicationInfo app = mContext.getApplicationInfo(); |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1753 | return mStorageManager.getCacheQuotaBytes(convert(storageUuid), app.uid); |
| 1754 | } catch (ParcelableException e) { |
| 1755 | e.maybeRethrow(IOException.class); |
| 1756 | throw new RuntimeException(e); |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1757 | } catch (RemoteException e) { |
| 1758 | throw e.rethrowFromSystemServer(); |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | /** |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1763 | * Return total size in bytes of all cached data belonging to the calling |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1764 | * app on the given storage volume. |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1765 | * <p> |
| 1766 | * Cached data tracked by this method always includes |
| 1767 | * {@link Context#getCacheDir()} and {@link Context#getCodeCacheDir()}, and |
| 1768 | * it also includes {@link Context#getExternalCacheDir()} if the primary |
| 1769 | * shared/external storage is hosted on the same storage device as your |
| 1770 | * private data. |
| 1771 | * <p class="note"> |
| 1772 | * Note: if your app uses the {@code android:sharedUserId} manifest feature, |
| 1773 | * then cached data for all packages in your shared UID is tracked together |
| 1774 | * as a single unit. |
| 1775 | * </p> |
| 1776 | * |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1777 | * @param storageUuid the UUID of the storage volume that you're interested |
| 1778 | * in. The UUID for a specific path can be obtained using |
| 1779 | * {@link #getUuidForPath(File)}. |
| 1780 | * @throws IOException when the storage device isn't present, or when it |
| 1781 | * doesn't support cache quotas. |
| 1782 | * @see #getCacheQuotaBytes(UUID) |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1783 | */ |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1784 | @WorkerThread |
| 1785 | public @BytesLong long getCacheSizeBytes(@NonNull UUID storageUuid) throws IOException { |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1786 | try { |
| 1787 | final ApplicationInfo app = mContext.getApplicationInfo(); |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1788 | return mStorageManager.getCacheSizeBytes(convert(storageUuid), app.uid); |
| 1789 | } catch (ParcelableException e) { |
| 1790 | e.maybeRethrow(IOException.class); |
| 1791 | throw new RuntimeException(e); |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 1792 | } catch (RemoteException e) { |
| 1793 | throw e.rethrowFromSystemServer(); |
| 1794 | } |
| 1795 | } |
| 1796 | |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1797 | /** |
| 1798 | * Flag indicating that a disk space allocation request should operate in an |
| 1799 | * aggressive mode. This flag should only be rarely used in situations that |
| 1800 | * are critical to system health or security. |
| 1801 | * <p> |
| 1802 | * When set, the system is more aggressive about the data that it considers |
| 1803 | * for possible deletion when allocating disk space. |
| 1804 | * <p class="note"> |
| 1805 | * Note: your app must hold the |
| 1806 | * {@link android.Manifest.permission#ALLOCATE_AGGRESSIVE} permission for |
| 1807 | * this flag to take effect. |
| 1808 | * </p> |
| 1809 | * |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1810 | * @see #getAllocatableBytes(UUID, int) |
| 1811 | * @see #allocateBytes(UUID, long, int) |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1812 | * @see #allocateBytes(FileDescriptor, long, int) |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1813 | * @hide |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1814 | */ |
| 1815 | @RequiresPermission(android.Manifest.permission.ALLOCATE_AGGRESSIVE) |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1816 | @SystemApi |
Jeff Sharkey | ddff807 | 2017-05-26 13:10:46 -0600 | [diff] [blame] | 1817 | public static final int FLAG_ALLOCATE_AGGRESSIVE = 1 << 0; |
| 1818 | |
| 1819 | /** |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1820 | * Flag indicating that a disk space allocation request should be allowed to |
| 1821 | * clear up to all reserved disk space. |
Jeff Sharkey | ddff807 | 2017-05-26 13:10:46 -0600 | [diff] [blame] | 1822 | * |
| 1823 | * @hide |
| 1824 | */ |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1825 | public static final int FLAG_ALLOCATE_DEFY_ALL_RESERVED = 1 << 1; |
| 1826 | |
| 1827 | /** |
| 1828 | * Flag indicating that a disk space allocation request should be allowed to |
| 1829 | * clear up to half of all reserved disk space. |
| 1830 | * |
| 1831 | * @hide |
| 1832 | */ |
| 1833 | public static final int FLAG_ALLOCATE_DEFY_HALF_RESERVED = 1 << 2; |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1834 | |
| 1835 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 1836 | @IntDef(flag = true, prefix = { "FLAG_ALLOCATE_" }, value = { |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1837 | FLAG_ALLOCATE_AGGRESSIVE, |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1838 | FLAG_ALLOCATE_DEFY_ALL_RESERVED, |
| 1839 | FLAG_ALLOCATE_DEFY_HALF_RESERVED, |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1840 | }) |
| 1841 | @Retention(RetentionPolicy.SOURCE) |
| 1842 | public @interface AllocateFlags {} |
| 1843 | |
| 1844 | /** |
| 1845 | * Return the maximum number of new bytes that your app can allocate for |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1846 | * itself on the given storage volume. This value is typically larger than |
| 1847 | * {@link File#getUsableSpace()}, since the system may be willing to delete |
| 1848 | * cached files to satisfy an allocation request. You can then allocate |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 1849 | * space for yourself using {@link #allocateBytes(UUID, long)} or |
| 1850 | * {@link #allocateBytes(FileDescriptor, long)}. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1851 | * <p> |
| 1852 | * This method is best used as a pre-flight check, such as deciding if there |
| 1853 | * is enough space to store an entire music album before you allocate space |
| 1854 | * for each audio file in the album. Attempts to allocate disk space beyond |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1855 | * the returned value will fail. |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1856 | * <p> |
| 1857 | * If the returned value is not large enough for the data you'd like to |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1858 | * persist, you can launch {@link #ACTION_MANAGE_STORAGE} with the |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1859 | * {@link #EXTRA_UUID} and {@link #EXTRA_REQUESTED_BYTES} options to help |
| 1860 | * involve the user in freeing up disk space. |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1861 | * <p> |
| 1862 | * If you're progressively allocating an unbounded amount of storage space |
| 1863 | * (such as when recording a video) you should avoid calling this method |
| 1864 | * more than once every 30 seconds. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1865 | * <p class="note"> |
| 1866 | * Note: if your app uses the {@code android:sharedUserId} manifest feature, |
| 1867 | * then allocatable space for all packages in your shared UID is tracked |
| 1868 | * together as a single unit. |
| 1869 | * </p> |
| 1870 | * |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1871 | * @param storageUuid the UUID of the storage volume where you're |
| 1872 | * considering allocating disk space, since allocatable space can |
| 1873 | * vary widely depending on the underlying storage device. The |
| 1874 | * UUID for a specific path can be obtained using |
| 1875 | * {@link #getUuidForPath(File)}. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1876 | * @return the maximum number of new bytes that the calling app can allocate |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 1877 | * using {@link #allocateBytes(UUID, long)} or |
| 1878 | * {@link #allocateBytes(FileDescriptor, long)}. |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1879 | * @throws IOException when the storage device isn't present, or when it |
| 1880 | * doesn't support allocating space. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1881 | */ |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1882 | @WorkerThread |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1883 | public @BytesLong long getAllocatableBytes(@NonNull UUID storageUuid) |
| 1884 | throws IOException { |
| 1885 | return getAllocatableBytes(storageUuid, 0); |
| 1886 | } |
| 1887 | |
| 1888 | /** @hide */ |
| 1889 | @SystemApi |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1890 | @WorkerThread |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 1891 | @SuppressLint("Doclava125") |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1892 | public long getAllocatableBytes(@NonNull UUID storageUuid, |
| 1893 | @RequiresPermission @AllocateFlags int flags) throws IOException { |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1894 | try { |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1895 | return mStorageManager.getAllocatableBytes(convert(storageUuid), flags, |
| 1896 | mContext.getOpPackageName()); |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1897 | } catch (ParcelableException e) { |
| 1898 | e.maybeRethrow(IOException.class); |
| 1899 | throw new RuntimeException(e); |
| 1900 | } catch (RemoteException e) { |
| 1901 | throw e.rethrowFromSystemServer(); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | /** |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1906 | * Allocate the requested number of bytes for your application to use on the |
| 1907 | * given storage volume. This will cause the system to delete any cached |
| 1908 | * files necessary to satisfy your request. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1909 | * <p> |
| 1910 | * Attempts to allocate disk space beyond the value returned by |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 1911 | * {@link #getAllocatableBytes(UUID)} will fail. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1912 | * <p> |
| 1913 | * Since multiple apps can be running simultaneously, this method may be |
| 1914 | * subject to race conditions. If possible, consider using |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 1915 | * {@link #allocateBytes(FileDescriptor, long)} which will guarantee |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1916 | * that bytes are allocated to an opened file. |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1917 | * <p> |
| 1918 | * If you're progressively allocating an unbounded amount of storage space |
| 1919 | * (such as when recording a video) you should avoid calling this method |
| 1920 | * more than once every 60 seconds. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1921 | * |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1922 | * @param storageUuid the UUID of the storage volume where you'd like to |
| 1923 | * allocate disk space. The UUID for a specific path can be |
| 1924 | * obtained using {@link #getUuidForPath(File)}. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1925 | * @param bytes the number of bytes to allocate. |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1926 | * @throws IOException when the storage device isn't present, or when it |
| 1927 | * doesn't support allocating space, or if the device had |
| 1928 | * trouble allocating the requested space. |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 1929 | * @see #getAllocatableBytes(UUID) |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1930 | */ |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1931 | @WorkerThread |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1932 | public void allocateBytes(@NonNull UUID storageUuid, @BytesLong long bytes) |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1933 | throws IOException { |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1934 | allocateBytes(storageUuid, bytes, 0); |
| 1935 | } |
| 1936 | |
| 1937 | /** @hide */ |
| 1938 | @SystemApi |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1939 | @WorkerThread |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 1940 | @SuppressLint("Doclava125") |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1941 | public void allocateBytes(@NonNull UUID storageUuid, @BytesLong long bytes, |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1942 | @RequiresPermission @AllocateFlags int flags) throws IOException { |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1943 | try { |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1944 | mStorageManager.allocateBytes(convert(storageUuid), bytes, flags, |
| 1945 | mContext.getOpPackageName()); |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1946 | } catch (ParcelableException e) { |
| 1947 | e.maybeRethrow(IOException.class); |
| 1948 | } catch (RemoteException e) { |
| 1949 | throw e.rethrowFromSystemServer(); |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | /** |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1954 | * Allocate the requested number of bytes for your application to use in the |
| 1955 | * given open file. This will cause the system to delete any cached files |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1956 | * necessary to satisfy your request. |
| 1957 | * <p> |
| 1958 | * Attempts to allocate disk space beyond the value returned by |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 1959 | * {@link #getAllocatableBytes(UUID)} will fail. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1960 | * <p> |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1961 | * This method guarantees that bytes have been allocated to the opened file, |
| 1962 | * otherwise it will throw if fast allocation is not possible. Fast |
| 1963 | * allocation is typically only supported in private app data directories, |
| 1964 | * and on shared/external storage devices which are emulated. |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1965 | * <p> |
| 1966 | * If you're progressively allocating an unbounded amount of storage space |
| 1967 | * (such as when recording a video) you should avoid calling this method |
| 1968 | * more than once every 60 seconds. |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1969 | * |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1970 | * @param fd the open file that you'd like to allocate disk space for. |
| 1971 | * @param bytes the number of bytes to allocate. This is the desired final |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1972 | * size of the open file. If the open file is smaller than this |
| 1973 | * requested size, it will be extended without modifying any |
| 1974 | * existing contents. If the open file is larger than this |
| 1975 | * requested size, it will be truncated. |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 1976 | * @throws IOException when the storage device isn't present, or when it |
| 1977 | * doesn't support allocating space, or if the device had |
| 1978 | * trouble allocating the requested space. |
Jeff Sharkey | 4233f03 | 2017-07-15 12:58:38 -0600 | [diff] [blame] | 1979 | * @see #isAllocationSupported(FileDescriptor) |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1980 | * @see Environment#isExternalStorageEmulated(File) |
| 1981 | */ |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1982 | @WorkerThread |
Jeff Sharkey | a4d34d9 | 2017-04-27 11:21:41 -0600 | [diff] [blame] | 1983 | public void allocateBytes(FileDescriptor fd, @BytesLong long bytes) throws IOException { |
| 1984 | allocateBytes(fd, bytes, 0); |
| 1985 | } |
| 1986 | |
| 1987 | /** @hide */ |
| 1988 | @SystemApi |
Jeff Sharkey | b31afd2 | 2017-06-12 14:17:10 -0600 | [diff] [blame] | 1989 | @WorkerThread |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 1990 | @SuppressLint("Doclava125") |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1991 | public void allocateBytes(FileDescriptor fd, @BytesLong long bytes, |
| 1992 | @RequiresPermission @AllocateFlags int flags) throws IOException { |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1993 | final File file = ParcelFileDescriptor.getFile(fd); |
Jeff Sharkey | 4233f03 | 2017-07-15 12:58:38 -0600 | [diff] [blame] | 1994 | final UUID uuid = getUuidForPath(file); |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1995 | for (int i = 0; i < 3; i++) { |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 1996 | try { |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 1997 | final long haveBytes = Os.fstat(fd).st_blocks * 512; |
| 1998 | final long needBytes = bytes - haveBytes; |
| 1999 | |
| 2000 | if (needBytes > 0) { |
Jeff Sharkey | 4233f03 | 2017-07-15 12:58:38 -0600 | [diff] [blame] | 2001 | allocateBytes(uuid, needBytes, flags); |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Jeff Sharkey | 4233f03 | 2017-07-15 12:58:38 -0600 | [diff] [blame] | 2004 | try { |
| 2005 | Os.posix_fallocate(fd, 0, bytes); |
| 2006 | return; |
| 2007 | } catch (ErrnoException e) { |
| 2008 | if (e.errno == OsConstants.ENOSYS || e.errno == OsConstants.ENOTSUP) { |
| 2009 | Log.w(TAG, "fallocate() not supported; falling back to ftruncate()"); |
| 2010 | Os.ftruncate(fd, bytes); |
| 2011 | return; |
| 2012 | } else { |
| 2013 | throw e; |
| 2014 | } |
| 2015 | } |
Jeff Sharkey | 500ce9e | 2017-02-12 02:39:24 -0700 | [diff] [blame] | 2016 | } catch (ErrnoException e) { |
| 2017 | if (e.errno == OsConstants.ENOSPC) { |
| 2018 | Log.w(TAG, "Odd, not enough space; let's try again?"); |
| 2019 | continue; |
| 2020 | } |
| 2021 | throw e.rethrowAsIOException(); |
| 2022 | } |
| 2023 | } |
| 2024 | throw new IOException( |
| 2025 | "Well this is embarassing; we can't allocate " + bytes + " for " + file); |
| 2026 | } |
| 2027 | |
Jeff Sharkey | b5a35b8 | 2017-03-22 21:30:19 -0600 | [diff] [blame] | 2028 | private static final String XATTR_CACHE_GROUP = "user.cache_group"; |
Jeff Sharkey | 458428e | 2017-02-22 11:47:15 -0700 | [diff] [blame] | 2029 | private static final String XATTR_CACHE_TOMBSTONE = "user.cache_tombstone"; |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 2030 | |
| 2031 | /** {@hide} */ |
| 2032 | private static void setCacheBehavior(File path, String name, boolean enabled) |
| 2033 | throws IOException { |
| 2034 | if (!path.isDirectory()) { |
| 2035 | throw new IOException("Cache behavior can only be set on directories"); |
| 2036 | } |
| 2037 | if (enabled) { |
| 2038 | try { |
| 2039 | Os.setxattr(path.getAbsolutePath(), name, |
| 2040 | "1".getBytes(StandardCharsets.UTF_8), 0); |
| 2041 | } catch (ErrnoException e) { |
| 2042 | throw e.rethrowAsIOException(); |
| 2043 | } |
| 2044 | } else { |
| 2045 | try { |
| 2046 | Os.removexattr(path.getAbsolutePath(), name); |
| 2047 | } catch (ErrnoException e) { |
| 2048 | if (e.errno != OsConstants.ENODATA) { |
| 2049 | throw e.rethrowAsIOException(); |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | /** {@hide} */ |
| 2056 | private static boolean isCacheBehavior(File path, String name) throws IOException { |
| 2057 | try { |
| 2058 | Os.getxattr(path.getAbsolutePath(), name); |
| 2059 | return true; |
| 2060 | } catch (ErrnoException e) { |
| 2061 | if (e.errno != OsConstants.ENODATA) { |
| 2062 | throw e.rethrowAsIOException(); |
| 2063 | } else { |
| 2064 | return false; |
| 2065 | } |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | /** |
| 2070 | * Enable or disable special cache behavior that treats this directory and |
Jeff Sharkey | b5a35b8 | 2017-03-22 21:30:19 -0600 | [diff] [blame] | 2071 | * its contents as an entire group. |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 2072 | * <p> |
| 2073 | * When enabled and this directory is considered for automatic deletion by |
| 2074 | * the OS, all contained files will either be deleted together, or not at |
| 2075 | * all. This is useful when you have a directory that contains several |
| 2076 | * related metadata files that depend on each other, such as movie file and |
| 2077 | * a subtitle file. |
| 2078 | * <p> |
| 2079 | * When enabled, the <em>newest</em> {@link File#lastModified()} value of |
| 2080 | * any contained files is considered the modified time of the entire |
| 2081 | * directory. |
| 2082 | * <p> |
| 2083 | * This behavior can only be set on a directory, and it applies recursively |
| 2084 | * to all contained files and directories. |
| 2085 | */ |
Jeff Sharkey | b5a35b8 | 2017-03-22 21:30:19 -0600 | [diff] [blame] | 2086 | public void setCacheBehaviorGroup(File path, boolean group) throws IOException { |
| 2087 | setCacheBehavior(path, XATTR_CACHE_GROUP, group); |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | /** |
| 2091 | * Read the current value set by |
Jeff Sharkey | b5a35b8 | 2017-03-22 21:30:19 -0600 | [diff] [blame] | 2092 | * {@link #setCacheBehaviorGroup(File, boolean)}. |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 2093 | */ |
Jeff Sharkey | b5a35b8 | 2017-03-22 21:30:19 -0600 | [diff] [blame] | 2094 | public boolean isCacheBehaviorGroup(File path) throws IOException { |
| 2095 | return isCacheBehavior(path, XATTR_CACHE_GROUP); |
| 2096 | } |
| 2097 | |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 2098 | /** |
| 2099 | * Enable or disable special cache behavior that leaves deleted cache files |
| 2100 | * intact as tombstones. |
| 2101 | * <p> |
| 2102 | * When enabled and a file contained in this directory is automatically |
| 2103 | * deleted by the OS, the file will be truncated to have a length of 0 bytes |
| 2104 | * instead of being fully deleted. This is useful if you need to distinguish |
| 2105 | * between a file that was deleted versus one that never existed. |
| 2106 | * <p> |
| 2107 | * This behavior can only be set on a directory, and it applies recursively |
| 2108 | * to all contained files and directories. |
| 2109 | * <p class="note"> |
| 2110 | * Note: this behavior is ignored completely if the user explicitly requests |
| 2111 | * that all cached data be cleared. |
| 2112 | * </p> |
| 2113 | */ |
| 2114 | public void setCacheBehaviorTombstone(File path, boolean tombstone) throws IOException { |
Jeff Sharkey | 458428e | 2017-02-22 11:47:15 -0700 | [diff] [blame] | 2115 | setCacheBehavior(path, XATTR_CACHE_TOMBSTONE, tombstone); |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | /** |
| 2119 | * Read the current value set by |
| 2120 | * {@link #setCacheBehaviorTombstone(File, boolean)}. |
| 2121 | */ |
| 2122 | public boolean isCacheBehaviorTombstone(File path) throws IOException { |
Jeff Sharkey | 458428e | 2017-02-22 11:47:15 -0700 | [diff] [blame] | 2123 | return isCacheBehavior(path, XATTR_CACHE_TOMBSTONE); |
Jeff Sharkey | 9bed070 | 2017-01-23 20:37:05 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
Jeff Sharkey | 789a8fc | 2017-04-16 13:18:35 -0600 | [diff] [blame] | 2126 | /** {@hide} */ |
| 2127 | public static UUID convert(String uuid) { |
| 2128 | if (Objects.equals(uuid, UUID_PRIVATE_INTERNAL)) { |
| 2129 | return UUID_DEFAULT; |
| 2130 | } else if (Objects.equals(uuid, UUID_PRIMARY_PHYSICAL)) { |
| 2131 | return UUID_PRIMARY_PHYSICAL_; |
| 2132 | } else if (Objects.equals(uuid, UUID_SYSTEM)) { |
| 2133 | return UUID_SYSTEM_; |
| 2134 | } else { |
| 2135 | return UUID.fromString(uuid); |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | /** {@hide} */ |
| 2140 | public static String convert(UUID storageUuid) { |
| 2141 | if (UUID_DEFAULT.equals(storageUuid)) { |
| 2142 | return UUID_PRIVATE_INTERNAL; |
| 2143 | } else if (UUID_PRIMARY_PHYSICAL_.equals(storageUuid)) { |
| 2144 | return UUID_PRIMARY_PHYSICAL; |
| 2145 | } else if (UUID_SYSTEM_.equals(storageUuid)) { |
| 2146 | return UUID_SYSTEM; |
| 2147 | } else { |
| 2148 | return storageUuid.toString(); |
| 2149 | } |
| 2150 | } |
| 2151 | |
Daichi Hirono | 9fb0018 | 2016-11-08 14:12:17 +0900 | [diff] [blame] | 2152 | private final Object mFuseAppLoopLock = new Object(); |
| 2153 | |
| 2154 | @GuardedBy("mFuseAppLoopLock") |
| 2155 | private @Nullable FuseAppLoop mFuseAppLoop = null; |
| 2156 | |
Paul Lawrence | e8fdc54 | 2014-05-28 07:14:17 -0700 | [diff] [blame] | 2157 | /// Consts to match the password types in cryptfs.h |
| 2158 | /** @hide */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 2159 | @UnsupportedAppUsage |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 2160 | public static final int CRYPT_TYPE_PASSWORD = IVold.PASSWORD_TYPE_PASSWORD; |
Paul Lawrence | e8fdc54 | 2014-05-28 07:14:17 -0700 | [diff] [blame] | 2161 | /** @hide */ |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 2162 | @UnsupportedAppUsage |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 2163 | public static final int CRYPT_TYPE_DEFAULT = IVold.PASSWORD_TYPE_DEFAULT; |
Paul Lawrence | e8fdc54 | 2014-05-28 07:14:17 -0700 | [diff] [blame] | 2164 | /** @hide */ |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 2165 | public static final int CRYPT_TYPE_PATTERN = IVold.PASSWORD_TYPE_PATTERN; |
Paul Lawrence | e8fdc54 | 2014-05-28 07:14:17 -0700 | [diff] [blame] | 2166 | /** @hide */ |
Jeff Sharkey | 43e1211 | 2017-09-12 16:31:45 -0600 | [diff] [blame] | 2167 | public static final int CRYPT_TYPE_PIN = IVold.PASSWORD_TYPE_PIN; |
Elliott Hughes | f839b4f | 2014-09-26 12:30:47 -0700 | [diff] [blame] | 2168 | |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 2169 | // Constants for the data available via StorageManagerService.getField. |
Elliott Hughes | f839b4f | 2014-09-26 12:30:47 -0700 | [diff] [blame] | 2170 | /** @hide */ |
| 2171 | public static final String SYSTEM_LOCALE_KEY = "SystemLocale"; |
| 2172 | /** @hide */ |
| 2173 | public static final String OWNER_INFO_KEY = "OwnerInfo"; |
| 2174 | /** @hide */ |
| 2175 | public static final String PATTERN_VISIBLE_KEY = "PatternVisible"; |
Paul Lawrence | d8fdb33 | 2015-05-18 13:26:11 -0700 | [diff] [blame] | 2176 | /** @hide */ |
| 2177 | public static final String PASSWORD_VISIBLE_KEY = "PasswordVisible"; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 2178 | } |