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