| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 com.android.server; |
| 18 | |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 19 | import com.android.internal.app.IMediaContainerService; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 20 | import com.android.internal.util.XmlUtils; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 21 | import com.android.server.am.ActivityManagerService; |
| Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 22 | import com.android.server.pm.PackageManagerService; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 23 | |
| Jason parks | 8888c59 | 2011-01-20 22:46:41 -0600 | [diff] [blame] | 24 | import android.Manifest; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.content.IntentFilter; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 30 | import android.content.ServiceConnection; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 32 | import android.content.res.ObbInfo; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
| 34 | import android.content.res.TypedArray; |
| 35 | import android.content.res.XmlResourceParser; |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 36 | import android.hardware.usb.UsbManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.net.Uri; |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 38 | import android.os.Binder; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 39 | import android.os.Environment; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 40 | import android.os.Handler; |
| Daniel Sandler | 5f27ef4 | 2010-03-16 15:42:02 -0400 | [diff] [blame] | 41 | import android.os.HandlerThread; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 42 | import android.os.IBinder; |
| Daniel Sandler | 5f27ef4 | 2010-03-16 15:42:02 -0400 | [diff] [blame] | 43 | import android.os.Looper; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 44 | import android.os.Message; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 45 | import android.os.Parcelable; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 46 | import android.os.RemoteException; |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 47 | import android.os.ServiceManager; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 48 | import android.os.SystemClock; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.os.SystemProperties; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 50 | import android.os.storage.IMountService; |
| 51 | import android.os.storage.IMountServiceListener; |
| 52 | import android.os.storage.IMountShutdownObserver; |
| 53 | import android.os.storage.IObbActionListener; |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 54 | import android.os.storage.OnObbStateChangeListener; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 55 | import android.os.storage.StorageResultCode; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 56 | import android.os.storage.StorageVolume; |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 57 | import android.text.TextUtils; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 58 | import android.util.AttributeSet; |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 59 | import android.util.Slog; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 60 | import android.util.Xml; |
| 61 | |
| 62 | import org.xmlpull.v1.XmlPullParser; |
| 63 | import org.xmlpull.v1.XmlPullParserException; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 64 | |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 65 | import java.io.FileDescriptor; |
| Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 66 | import java.io.IOException; |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 67 | import java.io.PrintWriter; |
| Kenny Root | 3b1abba | 2010-10-13 15:00:07 -0700 | [diff] [blame] | 68 | import java.math.BigInteger; |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 69 | import java.security.NoSuchAlgorithmException; |
| Kenny Root | 3b1abba | 2010-10-13 15:00:07 -0700 | [diff] [blame] | 70 | import java.security.spec.InvalidKeySpecException; |
| 71 | import java.security.spec.KeySpec; |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 72 | import java.util.ArrayList; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 73 | import java.util.HashMap; |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 74 | import java.util.HashSet; |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 75 | import java.util.Iterator; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 76 | import java.util.LinkedList; |
| 77 | import java.util.List; |
| 78 | import java.util.Map; |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 79 | import java.util.Map.Entry; |
| Mike Lockwood | 8fa5f80 | 2011-03-24 08:12:30 -0700 | [diff] [blame] | 80 | import java.util.Set; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
| Kenny Root | 3b1abba | 2010-10-13 15:00:07 -0700 | [diff] [blame] | 82 | import javax.crypto.SecretKey; |
| 83 | import javax.crypto.SecretKeyFactory; |
| 84 | import javax.crypto.spec.PBEKeySpec; |
| 85 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | /** |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 87 | * MountService implements back-end services for platform storage |
| 88 | * management. |
| 89 | * @hide - Applications should use android.os.storage.StorageManager |
| 90 | * to access the MountService. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | */ |
| Jeff Sharkey | fa23c5a | 2011-08-09 21:44:24 -0700 | [diff] [blame] | 92 | class MountService extends IMountService.Stub |
| 93 | implements INativeDaemonConnectorCallbacks, Watchdog.Monitor { |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 94 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 95 | private static final boolean LOCAL_LOGD = false; |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 96 | private static final boolean DEBUG_UNMOUNT = false; |
| 97 | private static final boolean DEBUG_EVENTS = false; |
| Kenny Root | b7db272 | 2011-01-25 16:39:35 -0800 | [diff] [blame] | 98 | private static final boolean DEBUG_OBB = false; |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 99 | |
| Kenny Root | 07714d4 | 2011-08-17 17:49:28 -0700 | [diff] [blame] | 100 | // Disable this since it messes up long-running cryptfs operations. |
| 101 | private static final boolean WATCHDOG_ENABLE = false; |
| 102 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | private static final String TAG = "MountService"; |
| 104 | |
| Kenny Root | 305bcbf | 2010-09-03 07:56:38 -0700 | [diff] [blame] | 105 | private static final String VOLD_TAG = "VoldConnector"; |
| 106 | |
| Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 107 | /** Maximum number of ASEC containers allowed to be mounted. */ |
| 108 | private static final int MAX_CONTAINERS = 250; |
| 109 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 110 | /* |
| 111 | * Internal vold volume state constants |
| 112 | */ |
| San Mehat | 7fd0fee | 2009-12-17 07:12:23 -0800 | [diff] [blame] | 113 | class VolumeState { |
| 114 | public static final int Init = -1; |
| 115 | public static final int NoMedia = 0; |
| 116 | public static final int Idle = 1; |
| 117 | public static final int Pending = 2; |
| 118 | public static final int Checking = 3; |
| 119 | public static final int Mounted = 4; |
| 120 | public static final int Unmounting = 5; |
| 121 | public static final int Formatting = 6; |
| 122 | public static final int Shared = 7; |
| 123 | public static final int SharedMnt = 8; |
| 124 | } |
| 125 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 126 | /* |
| 127 | * Internal vold response code constants |
| 128 | */ |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 129 | class VoldResponseCode { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 130 | /* |
| 131 | * 100 series - Requestion action was initiated; expect another reply |
| 132 | * before proceeding with a new command. |
| 133 | */ |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 134 | public static final int VolumeListResult = 110; |
| 135 | public static final int AsecListResult = 111; |
| San Mehat | c1b4ce9 | 2010-02-16 17:13:03 -0800 | [diff] [blame] | 136 | public static final int StorageUsersListResult = 112; |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 137 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 138 | /* |
| 139 | * 200 series - Requestion action has been successfully completed. |
| 140 | */ |
| 141 | public static final int ShareStatusResult = 210; |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 142 | public static final int AsecPathResult = 211; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 143 | public static final int ShareEnabledResult = 212; |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 144 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 145 | /* |
| 146 | * 400 series - Command was accepted, but the requested action |
| 147 | * did not take place. |
| 148 | */ |
| 149 | public static final int OpFailedNoMedia = 401; |
| 150 | public static final int OpFailedMediaBlank = 402; |
| 151 | public static final int OpFailedMediaCorrupt = 403; |
| 152 | public static final int OpFailedVolNotMounted = 404; |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 153 | public static final int OpFailedStorageBusy = 405; |
| San Mehat | 2d66cef | 2010-03-23 11:12:52 -0700 | [diff] [blame] | 154 | public static final int OpFailedStorageNotFound = 406; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * 600 series - Unsolicited broadcasts. |
| 158 | */ |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 159 | public static final int VolumeStateChange = 605; |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 160 | public static final int VolumeDiskInserted = 630; |
| 161 | public static final int VolumeDiskRemoved = 631; |
| 162 | public static final int VolumeBadRemoval = 632; |
| 163 | } |
| 164 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 165 | private Context mContext; |
| 166 | private NativeDaemonConnector mConnector; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 167 | private final ArrayList<StorageVolume> mVolumes = new ArrayList<StorageVolume>(); |
| 168 | private StorageVolume mPrimaryVolume; |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 169 | private final HashMap<String, String> mVolumeStates = new HashMap<String, String>(); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 170 | private final HashMap<String, StorageVolume> mVolumeMap = new HashMap<String, StorageVolume>(); |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 171 | private String mExternalStoragePath; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 172 | private PackageManagerService mPms; |
| 173 | private boolean mUmsEnabling; |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 174 | private boolean mUmsAvailable = false; |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 175 | // Used as a lock for methods that register/unregister listeners. |
| 176 | final private ArrayList<MountServiceBinderListener> mListeners = |
| 177 | new ArrayList<MountServiceBinderListener>(); |
| San Mehat | 6a965af2 | 2010-02-24 17:47:30 -0800 | [diff] [blame] | 178 | private boolean mBooted = false; |
| 179 | private boolean mReady = false; |
| 180 | private boolean mSendUmsConnectedOnBoot = false; |
| Mike Lockwood | 0355975 | 2010-07-19 18:25:03 -0400 | [diff] [blame] | 181 | // true if we should fake MEDIA_MOUNTED state for external storage |
| 182 | private boolean mEmulateExternalStorage = false; |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 183 | |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 184 | /** |
| 185 | * Private hash of currently mounted secure containers. |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 186 | * Used as a lock in methods to manipulate secure containers. |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 187 | */ |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 188 | final private HashSet<String> mAsecMountSet = new HashSet<String>(); |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 189 | |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 190 | /** |
| Kenny Root | 3b1abba | 2010-10-13 15:00:07 -0700 | [diff] [blame] | 191 | * The size of the crypto algorithm key in bits for OBB files. Currently |
| 192 | * Twofish is used which takes 128-bit keys. |
| 193 | */ |
| 194 | private static final int CRYPTO_ALGORITHM_KEY_SIZE = 128; |
| 195 | |
| 196 | /** |
| 197 | * The number of times to run SHA1 in the PBKDF2 function for OBB files. |
| 198 | * 1024 is reasonably secure and not too slow. |
| 199 | */ |
| 200 | private static final int PBKDF2_HASH_ROUNDS = 1024; |
| 201 | |
| 202 | /** |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 203 | * Mounted OBB tracking information. Used to track the current state of all |
| 204 | * OBBs. |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 205 | */ |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 206 | final private Map<IBinder, List<ObbState>> mObbMounts = new HashMap<IBinder, List<ObbState>>(); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 207 | final private Map<String, ObbState> mObbPathToStateMap = new HashMap<String, ObbState>(); |
| 208 | |
| 209 | class ObbState implements IBinder.DeathRecipient { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 210 | public ObbState(String filename, int callerUid, IObbActionListener token, int nonce) |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 211 | throws RemoteException { |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 212 | this.filename = filename; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 213 | this.callerUid = callerUid; |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 214 | this.token = token; |
| 215 | this.nonce = nonce; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | // OBB source filename |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 219 | String filename; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 220 | |
| 221 | // Binder.callingUid() |
| Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 222 | final public int callerUid; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 223 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 224 | // Token of remote Binder caller |
| 225 | final IObbActionListener token; |
| 226 | |
| 227 | // Identifier to pass back to the token |
| 228 | final int nonce; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 229 | |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 230 | public IBinder getBinder() { |
| 231 | return token.asBinder(); |
| 232 | } |
| 233 | |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 234 | @Override |
| 235 | public void binderDied() { |
| 236 | ObbAction action = new UnmountObbAction(this, true); |
| 237 | mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 238 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 239 | |
| Kenny Root | 5919ac6 | 2010-10-05 09:49:40 -0700 | [diff] [blame] | 240 | public void link() throws RemoteException { |
| 241 | getBinder().linkToDeath(this, 0); |
| 242 | } |
| 243 | |
| 244 | public void unlink() { |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 245 | getBinder().unlinkToDeath(this, 0); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 246 | } |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 247 | |
| 248 | @Override |
| 249 | public String toString() { |
| 250 | StringBuilder sb = new StringBuilder("ObbState{"); |
| 251 | sb.append("filename="); |
| 252 | sb.append(filename); |
| 253 | sb.append(",token="); |
| 254 | sb.append(token.toString()); |
| 255 | sb.append(",callerUid="); |
| 256 | sb.append(callerUid); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 257 | sb.append('}'); |
| 258 | return sb.toString(); |
| 259 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // OBB Action Handler |
| 263 | final private ObbActionHandler mObbActionHandler; |
| 264 | |
| 265 | // OBB action handler messages |
| 266 | private static final int OBB_RUN_ACTION = 1; |
| 267 | private static final int OBB_MCS_BOUND = 2; |
| 268 | private static final int OBB_MCS_UNBIND = 3; |
| 269 | private static final int OBB_MCS_RECONNECT = 4; |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 270 | private static final int OBB_FLUSH_MOUNT_STATE = 5; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * Default Container Service information |
| 274 | */ |
| 275 | static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName( |
| 276 | "com.android.defcontainer", "com.android.defcontainer.DefaultContainerService"); |
| 277 | |
| 278 | final private DefaultContainerConnection mDefContainerConn = new DefaultContainerConnection(); |
| 279 | |
| 280 | class DefaultContainerConnection implements ServiceConnection { |
| 281 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 282 | if (DEBUG_OBB) |
| 283 | Slog.i(TAG, "onServiceConnected"); |
| 284 | IMediaContainerService imcs = IMediaContainerService.Stub.asInterface(service); |
| 285 | mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_MCS_BOUND, imcs)); |
| 286 | } |
| 287 | |
| 288 | public void onServiceDisconnected(ComponentName name) { |
| 289 | if (DEBUG_OBB) |
| 290 | Slog.i(TAG, "onServiceDisconnected"); |
| 291 | } |
| 292 | }; |
| 293 | |
| 294 | // Used in the ObbActionHandler |
| 295 | private IMediaContainerService mContainerService = null; |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 296 | |
| 297 | // Handler messages |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 298 | private static final int H_UNMOUNT_PM_UPDATE = 1; |
| 299 | private static final int H_UNMOUNT_PM_DONE = 2; |
| 300 | private static final int H_UNMOUNT_MS = 3; |
| 301 | private static final int RETRY_UNMOUNT_DELAY = 30; // in ms |
| 302 | private static final int MAX_UNMOUNT_RETRIES = 4; |
| 303 | |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 304 | class UnmountCallBack { |
| Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 305 | final String path; |
| 306 | final boolean force; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 307 | int retries; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 308 | |
| 309 | UnmountCallBack(String path, boolean force) { |
| 310 | retries = 0; |
| 311 | this.path = path; |
| 312 | this.force = force; |
| 313 | } |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 314 | |
| 315 | void handleFinished() { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 316 | if (DEBUG_UNMOUNT) Slog.i(TAG, "Unmounting " + path); |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 317 | doUnmountVolume(path, true); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | class UmsEnableCallBack extends UnmountCallBack { |
| Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 322 | final String method; |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 323 | |
| 324 | UmsEnableCallBack(String path, String method, boolean force) { |
| 325 | super(path, force); |
| 326 | this.method = method; |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | void handleFinished() { |
| 331 | super.handleFinished(); |
| 332 | doShareUnshareVolume(path, method, true); |
| 333 | } |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 334 | } |
| 335 | |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 336 | class ShutdownCallBack extends UnmountCallBack { |
| 337 | IMountShutdownObserver observer; |
| 338 | ShutdownCallBack(String path, IMountShutdownObserver observer) { |
| 339 | super(path, true); |
| 340 | this.observer = observer; |
| 341 | } |
| 342 | |
| 343 | @Override |
| 344 | void handleFinished() { |
| 345 | int ret = doUnmountVolume(path, true); |
| 346 | if (observer != null) { |
| 347 | try { |
| 348 | observer.onShutDownComplete(ret); |
| 349 | } catch (RemoteException e) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 350 | Slog.w(TAG, "RemoteException when shutting down"); |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| Daniel Sandler | 5f27ef4 | 2010-03-16 15:42:02 -0400 | [diff] [blame] | 356 | class MountServiceHandler extends Handler { |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 357 | ArrayList<UnmountCallBack> mForceUnmounts = new ArrayList<UnmountCallBack>(); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 358 | boolean mUpdatingStatus = false; |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 359 | |
| Daniel Sandler | 5f27ef4 | 2010-03-16 15:42:02 -0400 | [diff] [blame] | 360 | MountServiceHandler(Looper l) { |
| 361 | super(l); |
| 362 | } |
| 363 | |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 364 | @Override |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 365 | public void handleMessage(Message msg) { |
| 366 | switch (msg.what) { |
| 367 | case H_UNMOUNT_PM_UPDATE: { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 368 | if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_UPDATE"); |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 369 | UnmountCallBack ucb = (UnmountCallBack) msg.obj; |
| 370 | mForceUnmounts.add(ucb); |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 371 | if (DEBUG_UNMOUNT) Slog.i(TAG, " registered = " + mUpdatingStatus); |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 372 | // Register only if needed. |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 373 | if (!mUpdatingStatus) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 374 | if (DEBUG_UNMOUNT) Slog.i(TAG, "Updating external media status on PackageManager"); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 375 | mUpdatingStatus = true; |
| 376 | mPms.updateExternalMediaStatus(false, true); |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 377 | } |
| 378 | break; |
| 379 | } |
| 380 | case H_UNMOUNT_PM_DONE: { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 381 | if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_DONE"); |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 382 | if (DEBUG_UNMOUNT) Slog.i(TAG, "Updated status. Processing requests"); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 383 | mUpdatingStatus = false; |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 384 | int size = mForceUnmounts.size(); |
| 385 | int sizeArr[] = new int[size]; |
| 386 | int sizeArrN = 0; |
| Suchi Amalapurapu | 7af074a | 2010-04-05 16:46:32 -0700 | [diff] [blame] | 387 | // Kill processes holding references first |
| 388 | ActivityManagerService ams = (ActivityManagerService) |
| 389 | ServiceManager.getService("activity"); |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 390 | for (int i = 0; i < size; i++) { |
| 391 | UnmountCallBack ucb = mForceUnmounts.get(i); |
| 392 | String path = ucb.path; |
| 393 | boolean done = false; |
| 394 | if (!ucb.force) { |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 395 | done = true; |
| 396 | } else { |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 397 | int pids[] = getStorageUsers(path); |
| 398 | if (pids == null || pids.length == 0) { |
| 399 | done = true; |
| 400 | } else { |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 401 | // Eliminate system process here? |
| Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 402 | ams.killPids(pids, "unmount media", true); |
| Suchi Amalapurapu | 7af074a | 2010-04-05 16:46:32 -0700 | [diff] [blame] | 403 | // Confirm if file references have been freed. |
| 404 | pids = getStorageUsers(path); |
| 405 | if (pids == null || pids.length == 0) { |
| 406 | done = true; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | } |
| Suchi Amalapurapu | 7af074a | 2010-04-05 16:46:32 -0700 | [diff] [blame] | 410 | if (!done && (ucb.retries < MAX_UNMOUNT_RETRIES)) { |
| 411 | // Retry again |
| 412 | Slog.i(TAG, "Retrying to kill storage users again"); |
| 413 | mHandler.sendMessageDelayed( |
| 414 | mHandler.obtainMessage(H_UNMOUNT_PM_DONE, |
| 415 | ucb.retries++), |
| 416 | RETRY_UNMOUNT_DELAY); |
| 417 | } else { |
| 418 | if (ucb.retries >= MAX_UNMOUNT_RETRIES) { |
| 419 | Slog.i(TAG, "Failed to unmount media inspite of " + |
| 420 | MAX_UNMOUNT_RETRIES + " retries. Forcibly killing processes now"); |
| 421 | } |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 422 | sizeArr[sizeArrN++] = i; |
| 423 | mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_MS, |
| 424 | ucb)); |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 425 | } |
| 426 | } |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 427 | // Remove already processed elements from list. |
| 428 | for (int i = (sizeArrN-1); i >= 0; i--) { |
| 429 | mForceUnmounts.remove(sizeArr[i]); |
| 430 | } |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 431 | break; |
| 432 | } |
| 433 | case H_UNMOUNT_MS : { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 434 | if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_MS"); |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 435 | UnmountCallBack ucb = (UnmountCallBack) msg.obj; |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 436 | ucb.handleFinished(); |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 437 | break; |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | }; |
| Daniel Sandler | 5f27ef4 | 2010-03-16 15:42:02 -0400 | [diff] [blame] | 442 | final private HandlerThread mHandlerThread; |
| 443 | final private Handler mHandler; |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 444 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 445 | private void waitForReady() { |
| 446 | while (mReady == false) { |
| 447 | for (int retries = 5; retries > 0; retries--) { |
| 448 | if (mReady) { |
| 449 | return; |
| 450 | } |
| 451 | SystemClock.sleep(1000); |
| 452 | } |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 453 | Slog.w(TAG, "Waiting too long for mReady!"); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 454 | } |
| San Mehat | 1f6301e | 2010-01-07 22:40:27 -0800 | [diff] [blame] | 455 | } |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 456 | |
| Ben Komalo | 444eca2 | 2011-09-01 15:17:44 -0700 | [diff] [blame^] | 457 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 458 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | public void onReceive(Context context, Intent intent) { |
| San Mehat | 91c7761 | 2010-01-07 10:39:41 -0800 | [diff] [blame] | 460 | String action = intent.getAction(); |
| 461 | |
| 462 | if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 463 | mBooted = true; |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 464 | |
| Marco Nelissen | c34ebce | 2010-02-18 13:39:41 -0800 | [diff] [blame] | 465 | /* |
| 466 | * In the simulator, we need to broadcast a volume mounted event |
| 467 | * to make the media scanner run. |
| 468 | */ |
| 469 | if ("simulator".equals(SystemProperties.get("ro.product.device"))) { |
| Mike Lockwood | 84338c4 | 2011-04-05 10:05:47 -0400 | [diff] [blame] | 470 | notifyVolumeStateChange(null, "/sdcard", VolumeState.NoMedia, |
| 471 | VolumeState.Mounted); |
| Marco Nelissen | c34ebce | 2010-02-18 13:39:41 -0800 | [diff] [blame] | 472 | return; |
| 473 | } |
| San Mehat | fafb041 | 2010-02-18 19:40:04 -0800 | [diff] [blame] | 474 | new Thread() { |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 475 | @Override |
| San Mehat | fafb041 | 2010-02-18 19:40:04 -0800 | [diff] [blame] | 476 | public void run() { |
| 477 | try { |
| Mike Lockwood | 84338c4 | 2011-04-05 10:05:47 -0400 | [diff] [blame] | 478 | // it is not safe to call vold with mVolumeStates locked |
| 479 | // so we make a copy of the paths and states and process them |
| 480 | // outside the lock |
| Jeff Sharkey | fa23c5a | 2011-08-09 21:44:24 -0700 | [diff] [blame] | 481 | String[] paths; |
| 482 | String[] states; |
| Mike Lockwood | 84338c4 | 2011-04-05 10:05:47 -0400 | [diff] [blame] | 483 | int count; |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 484 | synchronized (mVolumeStates) { |
| Mike Lockwood | 84338c4 | 2011-04-05 10:05:47 -0400 | [diff] [blame] | 485 | Set<String> keys = mVolumeStates.keySet(); |
| 486 | count = keys.size(); |
| Ben Komalo | 444eca2 | 2011-09-01 15:17:44 -0700 | [diff] [blame^] | 487 | paths = keys.toArray(new String[count]); |
| Mike Lockwood | 84338c4 | 2011-04-05 10:05:47 -0400 | [diff] [blame] | 488 | states = new String[count]; |
| 489 | for (int i = 0; i < count; i++) { |
| 490 | states[i] = mVolumeStates.get(paths[i]); |
| 491 | } |
| 492 | } |
| San Mehat | 6a25440 | 2010-03-22 10:21:00 -0700 | [diff] [blame] | 493 | |
| Mike Lockwood | 84338c4 | 2011-04-05 10:05:47 -0400 | [diff] [blame] | 494 | for (int i = 0; i < count; i++) { |
| 495 | String path = paths[i]; |
| 496 | String state = states[i]; |
| 497 | |
| 498 | if (state.equals(Environment.MEDIA_UNMOUNTED)) { |
| 499 | int rc = doMountVolume(path); |
| 500 | if (rc != StorageResultCode.OperationSucceeded) { |
| 501 | Slog.e(TAG, String.format("Boot-time mount failed (%d)", |
| 502 | rc)); |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 503 | } |
| Mike Lockwood | 84338c4 | 2011-04-05 10:05:47 -0400 | [diff] [blame] | 504 | } else if (state.equals(Environment.MEDIA_SHARED)) { |
| 505 | /* |
| 506 | * Bootstrap UMS enabled state since vold indicates |
| 507 | * the volume is shared (runtime restart while ums enabled) |
| 508 | */ |
| 509 | notifyVolumeStateChange(null, path, VolumeState.NoMedia, |
| 510 | VolumeState.Shared); |
| San Mehat | fafb041 | 2010-02-18 19:40:04 -0800 | [diff] [blame] | 511 | } |
| 512 | } |
| San Mehat | 6a25440 | 2010-03-22 10:21:00 -0700 | [diff] [blame] | 513 | |
| Mike Lockwood | 80e0a41 | 2011-04-05 10:21:51 -0400 | [diff] [blame] | 514 | /* notify external storage has mounted to trigger media scanner */ |
| 515 | if (mEmulateExternalStorage) { |
| 516 | notifyVolumeStateChange(null, |
| 517 | Environment.getExternalStorageDirectory().getPath(), |
| 518 | VolumeState.NoMedia, VolumeState.Mounted); |
| 519 | } |
| 520 | |
| San Mehat | 6a965af2 | 2010-02-24 17:47:30 -0800 | [diff] [blame] | 521 | /* |
| San Mehat | 6a25440 | 2010-03-22 10:21:00 -0700 | [diff] [blame] | 522 | * If UMS was connected on boot, send the connected event |
| San Mehat | 6a965af2 | 2010-02-24 17:47:30 -0800 | [diff] [blame] | 523 | * now that we're up. |
| 524 | */ |
| 525 | if (mSendUmsConnectedOnBoot) { |
| 526 | sendUmsIntent(true); |
| 527 | mSendUmsConnectedOnBoot = false; |
| 528 | } |
| San Mehat | fafb041 | 2010-02-18 19:40:04 -0800 | [diff] [blame] | 529 | } catch (Exception ex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 530 | Slog.e(TAG, "Boot-time mount exception", ex); |
| San Mehat | fafb041 | 2010-02-18 19:40:04 -0800 | [diff] [blame] | 531 | } |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 532 | } |
| San Mehat | fafb041 | 2010-02-18 19:40:04 -0800 | [diff] [blame] | 533 | }.start(); |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 534 | } else if (action.equals(UsbManager.ACTION_USB_STATE)) { |
| 535 | boolean available = (intent.getBooleanExtra(UsbManager.USB_CONNECTED, false) && |
| 536 | intent.getBooleanExtra(UsbManager.USB_FUNCTION_MASS_STORAGE, false)); |
| 537 | notifyShareAvailabilityChange(available); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | }; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 541 | private final class MountServiceBinderListener implements IBinder.DeathRecipient { |
| 542 | final IMountServiceListener mListener; |
| 543 | |
| 544 | MountServiceBinderListener(IMountServiceListener listener) { |
| 545 | mListener = listener; |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 546 | |
| San Mehat | 91c7761 | 2010-01-07 10:39:41 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 549 | public void binderDied() { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 550 | if (LOCAL_LOGD) Slog.d(TAG, "An IMountServiceListener has died!"); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 551 | synchronized (mListeners) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 552 | mListeners.remove(this); |
| 553 | mListener.asBinder().unlinkToDeath(this, 0); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 558 | private void doShareUnshareVolume(String path, String method, boolean enable) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 559 | // TODO: Add support for multiple share methods |
| 560 | if (!method.equals("ums")) { |
| 561 | throw new IllegalArgumentException(String.format("Method %s not supported", method)); |
| 562 | } |
| 563 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 564 | try { |
| 565 | mConnector.doCommand(String.format( |
| 566 | "volume %sshare %s %s", (enable ? "" : "un"), path, method)); |
| 567 | } catch (NativeDaemonConnectorException e) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 568 | Slog.e(TAG, "Failed to share/unshare", e); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 569 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 572 | private void updatePublicVolumeState(String path, String state) { |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 573 | String oldState; |
| 574 | synchronized(mVolumeStates) { |
| 575 | oldState = mVolumeStates.put(path, state); |
| 576 | } |
| 577 | if (state.equals(oldState)) { |
| 578 | Slog.w(TAG, String.format("Duplicate state transition (%s -> %s) for %s", |
| 579 | state, state, path)); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 580 | return; |
| 581 | } |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 582 | |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 583 | Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")"); |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 584 | |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 585 | if (path.equals(mExternalStoragePath)) { |
| 586 | // Update state on PackageManager, but only of real events |
| 587 | if (!mEmulateExternalStorage) { |
| 588 | if (Environment.MEDIA_UNMOUNTED.equals(state)) { |
| 589 | mPms.updateExternalMediaStatus(false, false); |
| 590 | |
| 591 | /* |
| 592 | * Some OBBs might have been unmounted when this volume was |
| 593 | * unmounted, so send a message to the handler to let it know to |
| 594 | * remove those from the list of mounted OBBS. |
| 595 | */ |
| 596 | mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage( |
| 597 | OBB_FLUSH_MOUNT_STATE, path)); |
| 598 | } else if (Environment.MEDIA_MOUNTED.equals(state)) { |
| 599 | mPms.updateExternalMediaStatus(true, false); |
| 600 | } |
| Mike Lockwood | 0355975 | 2010-07-19 18:25:03 -0400 | [diff] [blame] | 601 | } |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 602 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 603 | synchronized (mListeners) { |
| 604 | for (int i = mListeners.size() -1; i >= 0; i--) { |
| 605 | MountServiceBinderListener bl = mListeners.get(i); |
| 606 | try { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 607 | bl.mListener.onStorageStateChanged(path, oldState, state); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 608 | } catch (RemoteException rex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 609 | Slog.e(TAG, "Listener dead"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 610 | mListeners.remove(i); |
| 611 | } catch (Exception ex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 612 | Slog.e(TAG, "Listener failed", ex); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | /** |
| 619 | * |
| 620 | * Callback from NativeDaemonConnector |
| 621 | */ |
| 622 | public void onDaemonConnected() { |
| 623 | /* |
| 624 | * Since we'll be calling back into the NativeDaemonConnector, |
| 625 | * we need to do our work in a new thread. |
| 626 | */ |
| 627 | new Thread() { |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 628 | @Override |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 629 | public void run() { |
| 630 | /** |
| 631 | * Determine media state and UMS detection status |
| 632 | */ |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 633 | try { |
| 634 | String[] vols = mConnector.doListCommand( |
| 635 | "volume list", VoldResponseCode.VolumeListResult); |
| 636 | for (String volstr : vols) { |
| 637 | String[] tok = volstr.split(" "); |
| 638 | // FMT: <label> <mountpoint> <state> |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 639 | String path = tok[1]; |
| 640 | String state = Environment.MEDIA_REMOVED; |
| 641 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 642 | int st = Integer.parseInt(tok[2]); |
| 643 | if (st == VolumeState.NoMedia) { |
| 644 | state = Environment.MEDIA_REMOVED; |
| 645 | } else if (st == VolumeState.Idle) { |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 646 | state = Environment.MEDIA_UNMOUNTED; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 647 | } else if (st == VolumeState.Mounted) { |
| 648 | state = Environment.MEDIA_MOUNTED; |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 649 | Slog.i(TAG, "Media already mounted on daemon connection"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 650 | } else if (st == VolumeState.Shared) { |
| 651 | state = Environment.MEDIA_SHARED; |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 652 | Slog.i(TAG, "Media shared on daemon connection"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 653 | } else { |
| 654 | throw new Exception(String.format("Unexpected state %d", st)); |
| 655 | } |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 656 | |
| 657 | if (state != null) { |
| 658 | if (DEBUG_EVENTS) Slog.i(TAG, "Updating valid state " + state); |
| 659 | updatePublicVolumeState(path, state); |
| 660 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 661 | } |
| 662 | } catch (Exception e) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 663 | Slog.e(TAG, "Error processing initial volume state", e); |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 664 | updatePublicVolumeState(mExternalStoragePath, Environment.MEDIA_REMOVED); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 667 | /* |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 668 | * Now that we've done our initialization, release |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 669 | * the hounds! |
| 670 | */ |
| 671 | mReady = true; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 672 | } |
| 673 | }.start(); |
| 674 | } |
| 675 | |
| 676 | /** |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 677 | * Callback from NativeDaemonConnector |
| 678 | */ |
| 679 | public boolean onEvent(int code, String raw, String[] cooked) { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 680 | if (DEBUG_EVENTS) { |
| 681 | StringBuilder builder = new StringBuilder(); |
| 682 | builder.append("onEvent::"); |
| 683 | builder.append(" raw= " + raw); |
| 684 | if (cooked != null) { |
| 685 | builder.append(" cooked = " ); |
| 686 | for (String str : cooked) { |
| 687 | builder.append(" " + str); |
| 688 | } |
| 689 | } |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 690 | Slog.i(TAG, builder.toString()); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 691 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 692 | if (code == VoldResponseCode.VolumeStateChange) { |
| 693 | /* |
| 694 | * One of the volumes we're managing has changed state. |
| 695 | * Format: "NNN Volume <label> <path> state changed |
| 696 | * from <old_#> (<old_str>) to <new_#> (<new_str>)" |
| 697 | */ |
| 698 | notifyVolumeStateChange( |
| 699 | cooked[2], cooked[3], Integer.parseInt(cooked[7]), |
| 700 | Integer.parseInt(cooked[10])); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 701 | } else if ((code == VoldResponseCode.VolumeDiskInserted) || |
| 702 | (code == VoldResponseCode.VolumeDiskRemoved) || |
| 703 | (code == VoldResponseCode.VolumeBadRemoval)) { |
| 704 | // FMT: NNN Volume <label> <mountpoint> disk inserted (<major>:<minor>) |
| 705 | // FMT: NNN Volume <label> <mountpoint> disk removed (<major>:<minor>) |
| 706 | // FMT: NNN Volume <label> <mountpoint> bad removal (<major>:<minor>) |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 707 | String action = null; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 708 | final String label = cooked[2]; |
| 709 | final String path = cooked[3]; |
| 710 | int major = -1; |
| 711 | int minor = -1; |
| 712 | |
| 713 | try { |
| 714 | String devComp = cooked[6].substring(1, cooked[6].length() -1); |
| 715 | String[] devTok = devComp.split(":"); |
| 716 | major = Integer.parseInt(devTok[0]); |
| 717 | minor = Integer.parseInt(devTok[1]); |
| 718 | } catch (Exception ex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 719 | Slog.e(TAG, "Failed to parse major/minor", ex); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 720 | } |
| 721 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 722 | if (code == VoldResponseCode.VolumeDiskInserted) { |
| 723 | new Thread() { |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 724 | @Override |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 725 | public void run() { |
| 726 | try { |
| 727 | int rc; |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 728 | if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 729 | Slog.w(TAG, String.format("Insertion mount failed (%d)", rc)); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 730 | } |
| 731 | } catch (Exception ex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 732 | Slog.w(TAG, "Failed to mount media on insertion", ex); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | }.start(); |
| 736 | } else if (code == VoldResponseCode.VolumeDiskRemoved) { |
| 737 | /* |
| 738 | * This event gets trumped if we're already in BAD_REMOVAL state |
| 739 | */ |
| 740 | if (getVolumeState(path).equals(Environment.MEDIA_BAD_REMOVAL)) { |
| 741 | return true; |
| 742 | } |
| 743 | /* Send the media unmounted event first */ |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 744 | if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 745 | updatePublicVolumeState(path, Environment.MEDIA_UNMOUNTED); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 746 | sendStorageIntent(Environment.MEDIA_UNMOUNTED, path); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 747 | |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 748 | if (DEBUG_EVENTS) Slog.i(TAG, "Sending media removed"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 749 | updatePublicVolumeState(path, Environment.MEDIA_REMOVED); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 750 | action = Intent.ACTION_MEDIA_REMOVED; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 751 | } else if (code == VoldResponseCode.VolumeBadRemoval) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 752 | if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 753 | /* Send the media unmounted event first */ |
| 754 | updatePublicVolumeState(path, Environment.MEDIA_UNMOUNTED); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 755 | action = Intent.ACTION_MEDIA_UNMOUNTED; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 756 | |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 757 | if (DEBUG_EVENTS) Slog.i(TAG, "Sending media bad removal"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 758 | updatePublicVolumeState(path, Environment.MEDIA_BAD_REMOVAL); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 759 | action = Intent.ACTION_MEDIA_BAD_REMOVAL; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 760 | } else { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 761 | Slog.e(TAG, String.format("Unknown code {%d}", code)); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 762 | } |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 763 | |
| 764 | if (action != null) { |
| 765 | sendStorageIntent(action, path); |
| 766 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 767 | } else { |
| 768 | return false; |
| 769 | } |
| 770 | |
| Daniel Sandler | 5f27ef4 | 2010-03-16 15:42:02 -0400 | [diff] [blame] | 771 | return true; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 772 | } |
| 773 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 774 | private void notifyVolumeStateChange(String label, String path, int oldState, int newState) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 775 | String vs = getVolumeState(path); |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 776 | if (DEBUG_EVENTS) Slog.i(TAG, "notifyVolumeStateChanged::" + vs); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 777 | |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 778 | String action = null; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 779 | |
| Mike Lockwood | bf2dd44 | 2010-03-03 06:16:52 -0500 | [diff] [blame] | 780 | if (oldState == VolumeState.Shared && newState != oldState) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 781 | if (LOCAL_LOGD) Slog.d(TAG, "Sending ACTION_MEDIA_UNSHARED intent"); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 782 | sendStorageIntent(Intent.ACTION_MEDIA_UNSHARED, path); |
| Mike Lockwood | bf2dd44 | 2010-03-03 06:16:52 -0500 | [diff] [blame] | 783 | } |
| 784 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 785 | if (newState == VolumeState.Init) { |
| 786 | } else if (newState == VolumeState.NoMedia) { |
| 787 | // NoMedia is handled via Disk Remove events |
| 788 | } else if (newState == VolumeState.Idle) { |
| 789 | /* |
| 790 | * Don't notify if we're in BAD_REMOVAL, NOFS, UNMOUNTABLE, or |
| 791 | * if we're in the process of enabling UMS |
| 792 | */ |
| 793 | if (!vs.equals( |
| 794 | Environment.MEDIA_BAD_REMOVAL) && !vs.equals( |
| 795 | Environment.MEDIA_NOFS) && !vs.equals( |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 796 | Environment.MEDIA_UNMOUNTABLE) && !getUmsEnabling()) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 797 | if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state for media bad removal nofs and unmountable"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 798 | updatePublicVolumeState(path, Environment.MEDIA_UNMOUNTED); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 799 | action = Intent.ACTION_MEDIA_UNMOUNTED; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 800 | } |
| 801 | } else if (newState == VolumeState.Pending) { |
| 802 | } else if (newState == VolumeState.Checking) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 803 | if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state checking"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 804 | updatePublicVolumeState(path, Environment.MEDIA_CHECKING); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 805 | action = Intent.ACTION_MEDIA_CHECKING; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 806 | } else if (newState == VolumeState.Mounted) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 807 | if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state mounted"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 808 | updatePublicVolumeState(path, Environment.MEDIA_MOUNTED); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 809 | action = Intent.ACTION_MEDIA_MOUNTED; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 810 | } else if (newState == VolumeState.Unmounting) { |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 811 | action = Intent.ACTION_MEDIA_EJECT; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 812 | } else if (newState == VolumeState.Formatting) { |
| 813 | } else if (newState == VolumeState.Shared) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 814 | if (DEBUG_EVENTS) Slog.i(TAG, "Updating volume state media mounted"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 815 | /* Send the media unmounted event first */ |
| 816 | updatePublicVolumeState(path, Environment.MEDIA_UNMOUNTED); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 817 | sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, path); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 818 | |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 819 | if (DEBUG_EVENTS) Slog.i(TAG, "Updating media shared"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 820 | updatePublicVolumeState(path, Environment.MEDIA_SHARED); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 821 | action = Intent.ACTION_MEDIA_SHARED; |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 822 | if (LOCAL_LOGD) Slog.d(TAG, "Sending ACTION_MEDIA_SHARED intent"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 823 | } else if (newState == VolumeState.SharedMnt) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 824 | Slog.e(TAG, "Live shared mounts not supported yet!"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 825 | return; |
| 826 | } else { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 827 | Slog.e(TAG, "Unhandled VolumeState {" + newState + "}"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 830 | if (action != null) { |
| 831 | sendStorageIntent(action, path); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 835 | private int doMountVolume(String path) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 836 | int rc = StorageResultCode.OperationSucceeded; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 837 | |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 838 | if (DEBUG_EVENTS) Slog.i(TAG, "doMountVolume: Mouting " + path); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 839 | try { |
| 840 | mConnector.doCommand(String.format("volume mount %s", path)); |
| 841 | } catch (NativeDaemonConnectorException e) { |
| 842 | /* |
| 843 | * Mount failed for some reason |
| 844 | */ |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 845 | String action = null; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 846 | int code = e.getCode(); |
| 847 | if (code == VoldResponseCode.OpFailedNoMedia) { |
| 848 | /* |
| 849 | * Attempt to mount but no media inserted |
| 850 | */ |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 851 | rc = StorageResultCode.OperationFailedNoMedia; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 852 | } else if (code == VoldResponseCode.OpFailedMediaBlank) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 853 | if (DEBUG_EVENTS) Slog.i(TAG, " updating volume state :: media nofs"); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 854 | /* |
| 855 | * Media is blank or does not contain a supported filesystem |
| 856 | */ |
| 857 | updatePublicVolumeState(path, Environment.MEDIA_NOFS); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 858 | action = Intent.ACTION_MEDIA_NOFS; |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 859 | rc = StorageResultCode.OperationFailedMediaBlank; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 860 | } else if (code == VoldResponseCode.OpFailedMediaCorrupt) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 861 | if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state media corrupt"); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 862 | /* |
| 863 | * Volume consistency check failed |
| 864 | */ |
| 865 | updatePublicVolumeState(path, Environment.MEDIA_UNMOUNTABLE); |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 866 | action = Intent.ACTION_MEDIA_UNMOUNTABLE; |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 867 | rc = StorageResultCode.OperationFailedMediaCorrupt; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 868 | } else { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 869 | rc = StorageResultCode.OperationFailedInternalError; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | /* |
| 873 | * Send broadcast intent (if required for the failure) |
| 874 | */ |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 875 | if (action != null) { |
| 876 | sendStorageIntent(action, path); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | return rc; |
| 881 | } |
| 882 | |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 883 | /* |
| 884 | * If force is not set, we do not unmount if there are |
| 885 | * processes holding references to the volume about to be unmounted. |
| 886 | * If force is set, all the processes holding references need to be |
| 887 | * killed via the ActivityManager before actually unmounting the volume. |
| 888 | * This might even take a while and might be retried after timed delays |
| 889 | * to make sure we dont end up in an instable state and kill some core |
| 890 | * processes. |
| 891 | */ |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 892 | private int doUnmountVolume(String path, boolean force) { |
| San Mehat | 59443a6 | 2010-02-09 13:28:45 -0800 | [diff] [blame] | 893 | if (!getVolumeState(path).equals(Environment.MEDIA_MOUNTED)) { |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 894 | return VoldResponseCode.OpFailedVolNotMounted; |
| 895 | } |
| Kenny Root | aa48540 | 2010-09-14 14:49:41 -0700 | [diff] [blame] | 896 | |
| 897 | /* |
| 898 | * Force a GC to make sure AssetManagers in other threads of the |
| 899 | * system_server are cleaned up. We have to do this since AssetManager |
| 900 | * instances are kept as a WeakReference and it's possible we have files |
| 901 | * open on the external storage. |
| 902 | */ |
| 903 | Runtime.getRuntime().gc(); |
| 904 | |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 905 | // Redundant probably. But no harm in updating state again. |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 906 | mPms.updateExternalMediaStatus(false, false); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 907 | try { |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 908 | mConnector.doCommand(String.format( |
| 909 | "volume unmount %s%s", path, (force ? " force" : ""))); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 910 | // We unmounted the volume. None of the asec containers are available now. |
| 911 | synchronized (mAsecMountSet) { |
| 912 | mAsecMountSet.clear(); |
| 913 | } |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 914 | return StorageResultCode.OperationSucceeded; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 915 | } catch (NativeDaemonConnectorException e) { |
| 916 | // Don't worry about mismatch in PackageManager since the |
| 917 | // call back will handle the status changes any way. |
| 918 | int code = e.getCode(); |
| 919 | if (code == VoldResponseCode.OpFailedVolNotMounted) { |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 920 | return StorageResultCode.OperationFailedStorageNotMounted; |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 921 | } else if (code == VoldResponseCode.OpFailedStorageBusy) { |
| 922 | return StorageResultCode.OperationFailedStorageBusy; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 923 | } else { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 924 | return StorageResultCode.OperationFailedInternalError; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | private int doFormatVolume(String path) { |
| 930 | try { |
| 931 | String cmd = String.format("volume format %s", path); |
| 932 | mConnector.doCommand(cmd); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 933 | return StorageResultCode.OperationSucceeded; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 934 | } catch (NativeDaemonConnectorException e) { |
| 935 | int code = e.getCode(); |
| 936 | if (code == VoldResponseCode.OpFailedNoMedia) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 937 | return StorageResultCode.OperationFailedNoMedia; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 938 | } else if (code == VoldResponseCode.OpFailedMediaCorrupt) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 939 | return StorageResultCode.OperationFailedMediaCorrupt; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 940 | } else { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 941 | return StorageResultCode.OperationFailedInternalError; |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 946 | private boolean doGetVolumeShared(String path, String method) { |
| 947 | String cmd = String.format("volume shared %s %s", path, method); |
| Kenny Root | a80ce06 | 2010-06-01 13:23:53 -0700 | [diff] [blame] | 948 | ArrayList<String> rsp; |
| 949 | |
| 950 | try { |
| 951 | rsp = mConnector.doCommand(cmd); |
| 952 | } catch (NativeDaemonConnectorException ex) { |
| 953 | Slog.e(TAG, "Failed to read response to volume shared " + path + " " + method); |
| 954 | return false; |
| 955 | } |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 956 | |
| 957 | for (String line : rsp) { |
| Kenny Root | a80ce06 | 2010-06-01 13:23:53 -0700 | [diff] [blame] | 958 | String[] tok = line.split(" "); |
| 959 | if (tok.length < 3) { |
| 960 | Slog.e(TAG, "Malformed response to volume shared " + path + " " + method + " command"); |
| 961 | return false; |
| 962 | } |
| 963 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 964 | int code; |
| 965 | try { |
| 966 | code = Integer.parseInt(tok[0]); |
| 967 | } catch (NumberFormatException nfe) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 968 | Slog.e(TAG, String.format("Error parsing code %s", tok[0])); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 969 | return false; |
| 970 | } |
| 971 | if (code == VoldResponseCode.ShareEnabledResult) { |
| Kenny Root | a80ce06 | 2010-06-01 13:23:53 -0700 | [diff] [blame] | 972 | return "enabled".equals(tok[2]); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 973 | } else { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 974 | Slog.e(TAG, String.format("Unexpected response code %d", code)); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 975 | return false; |
| 976 | } |
| 977 | } |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 978 | Slog.e(TAG, "Got an empty response"); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 979 | return false; |
| 980 | } |
| 981 | |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 982 | private void notifyShareAvailabilityChange(final boolean avail) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 983 | synchronized (mListeners) { |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 984 | mUmsAvailable = avail; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 985 | for (int i = mListeners.size() -1; i >= 0; i--) { |
| 986 | MountServiceBinderListener bl = mListeners.get(i); |
| 987 | try { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 988 | bl.mListener.onUsbMassStorageConnectionChanged(avail); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 989 | } catch (RemoteException rex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 990 | Slog.e(TAG, "Listener dead"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 991 | mListeners.remove(i); |
| 992 | } catch (Exception ex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 993 | Slog.e(TAG, "Listener failed", ex); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | } |
| 997 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 998 | if (mBooted == true) { |
| San Mehat | 6a965af2 | 2010-02-24 17:47:30 -0800 | [diff] [blame] | 999 | sendUmsIntent(avail); |
| 1000 | } else { |
| 1001 | mSendUmsConnectedOnBoot = avail; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1002 | } |
| San Mehat | 2fe718a | 2010-03-11 12:01:49 -0800 | [diff] [blame] | 1003 | |
| 1004 | final String path = Environment.getExternalStorageDirectory().getPath(); |
| 1005 | if (avail == false && getVolumeState(path).equals(Environment.MEDIA_SHARED)) { |
| 1006 | /* |
| 1007 | * USB mass storage disconnected while enabled |
| 1008 | */ |
| 1009 | new Thread() { |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 1010 | @Override |
| San Mehat | 2fe718a | 2010-03-11 12:01:49 -0800 | [diff] [blame] | 1011 | public void run() { |
| 1012 | try { |
| 1013 | int rc; |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1014 | Slog.w(TAG, "Disabling UMS after cable disconnect"); |
| San Mehat | 2fe718a | 2010-03-11 12:01:49 -0800 | [diff] [blame] | 1015 | doShareUnshareVolume(path, "ums", false); |
| 1016 | if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1017 | Slog.e(TAG, String.format( |
| San Mehat | 2fe718a | 2010-03-11 12:01:49 -0800 | [diff] [blame] | 1018 | "Failed to remount {%s} on UMS enabled-disconnect (%d)", |
| 1019 | path, rc)); |
| 1020 | } |
| 1021 | } catch (Exception ex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1022 | Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex); |
| San Mehat | 2fe718a | 2010-03-11 12:01:49 -0800 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | }.start(); |
| 1026 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 1029 | private void sendStorageIntent(String action, String path) { |
| 1030 | Intent intent = new Intent(action, Uri.parse("file://" + path)); |
| 1031 | // add StorageVolume extra |
| 1032 | intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mVolumeMap.get(path)); |
| 1033 | Slog.d(TAG, "sendStorageIntent " + intent); |
| 1034 | mContext.sendBroadcast(intent); |
| 1035 | } |
| 1036 | |
| San Mehat | 6a965af2 | 2010-02-24 17:47:30 -0800 | [diff] [blame] | 1037 | private void sendUmsIntent(boolean c) { |
| 1038 | mContext.sendBroadcast( |
| 1039 | new Intent((c ? Intent.ACTION_UMS_CONNECTED : Intent.ACTION_UMS_DISCONNECTED))); |
| 1040 | } |
| 1041 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1042 | private void validatePermission(String perm) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1043 | if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) { |
| 1044 | throw new SecurityException(String.format("Requires %s permission", perm)); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1048 | // Storage list XML tags |
| 1049 | private static final String TAG_STORAGE_LIST = "StorageList"; |
| 1050 | private static final String TAG_STORAGE = "storage"; |
| 1051 | |
| 1052 | private void readStorageList(Resources resources) { |
| 1053 | int id = com.android.internal.R.xml.storage_list; |
| 1054 | XmlResourceParser parser = resources.getXml(id); |
| 1055 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| 1056 | |
| 1057 | try { |
| 1058 | XmlUtils.beginDocument(parser, TAG_STORAGE_LIST); |
| 1059 | while (true) { |
| 1060 | XmlUtils.nextElement(parser); |
| 1061 | |
| 1062 | String element = parser.getName(); |
| 1063 | if (element == null) break; |
| 1064 | |
| 1065 | if (TAG_STORAGE.equals(element)) { |
| 1066 | TypedArray a = resources.obtainAttributes(attrs, |
| 1067 | com.android.internal.R.styleable.Storage); |
| 1068 | |
| 1069 | CharSequence path = a.getText( |
| 1070 | com.android.internal.R.styleable.Storage_mountPoint); |
| 1071 | CharSequence description = a.getText( |
| 1072 | com.android.internal.R.styleable.Storage_storageDescription); |
| 1073 | boolean primary = a.getBoolean( |
| 1074 | com.android.internal.R.styleable.Storage_primary, false); |
| 1075 | boolean removable = a.getBoolean( |
| 1076 | com.android.internal.R.styleable.Storage_removable, false); |
| 1077 | boolean emulated = a.getBoolean( |
| 1078 | com.android.internal.R.styleable.Storage_emulated, false); |
| 1079 | int mtpReserve = a.getInt( |
| 1080 | com.android.internal.R.styleable.Storage_mtpReserve, 0); |
| Mike Lockwood | 8e8b280 | 2011-06-07 08:03:33 -0700 | [diff] [blame] | 1081 | boolean allowMassStorage = a.getBoolean( |
| 1082 | com.android.internal.R.styleable.Storage_allowMassStorage, false); |
| Mike Lockwood | 7a59dd2 | 2011-07-11 09:18:03 -0400 | [diff] [blame] | 1083 | // resource parser does not support longs, so XML value is in megabytes |
| 1084 | long maxFileSize = a.getInt( |
| 1085 | com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L * 1024L; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1086 | |
| 1087 | Slog.d(TAG, "got storage path: " + path + " description: " + description + |
| 1088 | " primary: " + primary + " removable: " + removable + |
| Mike Lockwood | 8e8b280 | 2011-06-07 08:03:33 -0700 | [diff] [blame] | 1089 | " emulated: " + emulated + " mtpReserve: " + mtpReserve + |
| Mike Lockwood | 7a59dd2 | 2011-07-11 09:18:03 -0400 | [diff] [blame] | 1090 | " allowMassStorage: " + allowMassStorage + |
| 1091 | " maxFileSize: " + maxFileSize); |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1092 | if (path == null || description == null) { |
| 1093 | Slog.e(TAG, "path or description is null in readStorageList"); |
| 1094 | } else { |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 1095 | String pathString = path.toString(); |
| 1096 | StorageVolume volume = new StorageVolume(pathString, |
| Mike Lockwood | 8e8b280 | 2011-06-07 08:03:33 -0700 | [diff] [blame] | 1097 | description.toString(), removable, emulated, |
| Mike Lockwood | 7a59dd2 | 2011-07-11 09:18:03 -0400 | [diff] [blame] | 1098 | mtpReserve, allowMassStorage, maxFileSize); |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1099 | if (primary) { |
| 1100 | if (mPrimaryVolume == null) { |
| 1101 | mPrimaryVolume = volume; |
| 1102 | } else { |
| 1103 | Slog.e(TAG, "multiple primary volumes in storage list"); |
| 1104 | } |
| 1105 | } |
| 1106 | if (mPrimaryVolume == volume) { |
| 1107 | // primay volume must be first |
| 1108 | mVolumes.add(0, volume); |
| 1109 | } else { |
| 1110 | mVolumes.add(volume); |
| 1111 | } |
| Mike Lockwood | a5250c9 | 2011-05-23 13:44:04 -0400 | [diff] [blame] | 1112 | mVolumeMap.put(pathString, volume); |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1113 | } |
| 1114 | a.recycle(); |
| 1115 | } |
| 1116 | } |
| 1117 | } catch (XmlPullParserException e) { |
| 1118 | throw new RuntimeException(e); |
| 1119 | } catch (IOException e) { |
| 1120 | throw new RuntimeException(e); |
| 1121 | } finally { |
| Mike Lockwood | fbfe555 | 2011-05-17 17:19:37 -0400 | [diff] [blame] | 1122 | // compute storage ID for each volume |
| 1123 | int length = mVolumes.size(); |
| 1124 | for (int i = 0; i < length; i++) { |
| 1125 | mVolumes.get(i).setStorageId(i); |
| 1126 | } |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1127 | parser.close(); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1131 | /** |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1132 | * Constructs a new MountService instance |
| 1133 | * |
| 1134 | * @param context Binder context for this service |
| 1135 | */ |
| 1136 | public MountService(Context context) { |
| 1137 | mContext = context; |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1138 | Resources resources = context.getResources(); |
| 1139 | readStorageList(resources); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1140 | |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1141 | if (mPrimaryVolume != null) { |
| 1142 | mExternalStoragePath = mPrimaryVolume.getPath(); |
| 1143 | mEmulateExternalStorage = mPrimaryVolume.isEmulated(); |
| 1144 | if (mEmulateExternalStorage) { |
| 1145 | Slog.d(TAG, "using emulated external storage"); |
| 1146 | mVolumeStates.put(mExternalStoragePath, Environment.MEDIA_MOUNTED); |
| 1147 | } |
| Mike Lockwood | 0355975 | 2010-07-19 18:25:03 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1150 | // XXX: This will go away soon in favor of IMountServiceObserver |
| 1151 | mPms = (PackageManagerService) ServiceManager.getService("package"); |
| 1152 | |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 1153 | IntentFilter filter = new IntentFilter(); |
| 1154 | filter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 1155 | // don't bother monitoring USB if mass storage is not supported on our primary volume |
| 1156 | if (mPrimaryVolume != null && mPrimaryVolume.allowMassStorage()) { |
| 1157 | filter.addAction(UsbManager.ACTION_USB_STATE); |
| 1158 | } |
| 1159 | mContext.registerReceiver(mBroadcastReceiver, filter, null, null); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1160 | |
| Daniel Sandler | 5f27ef4 | 2010-03-16 15:42:02 -0400 | [diff] [blame] | 1161 | mHandlerThread = new HandlerThread("MountService"); |
| 1162 | mHandlerThread.start(); |
| 1163 | mHandler = new MountServiceHandler(mHandlerThread.getLooper()); |
| 1164 | |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1165 | // Add OBB Action Handler to MountService thread. |
| 1166 | mObbActionHandler = new ObbActionHandler(mHandlerThread.getLooper()); |
| 1167 | |
| Marco Nelissen | c34ebce | 2010-02-18 13:39:41 -0800 | [diff] [blame] | 1168 | /* |
| 1169 | * Vold does not run in the simulator, so pretend the connector thread |
| 1170 | * ran and did its thing. |
| 1171 | */ |
| 1172 | if ("simulator".equals(SystemProperties.get("ro.product.device"))) { |
| 1173 | mReady = true; |
| 1174 | mUmsEnabling = true; |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| Kenny Root | 305bcbf | 2010-09-03 07:56:38 -0700 | [diff] [blame] | 1178 | /* |
| 1179 | * Create the connection to vold with a maximum queue of twice the |
| 1180 | * amount of containers we'd ever expect to have. This keeps an |
| 1181 | * "asec list" from blocking a thread repeatedly. |
| 1182 | */ |
| Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 1183 | mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1184 | mReady = false; |
| Kenny Root | 305bcbf | 2010-09-03 07:56:38 -0700 | [diff] [blame] | 1185 | Thread thread = new Thread(mConnector, VOLD_TAG); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1186 | thread.start(); |
| Jeff Sharkey | fa23c5a | 2011-08-09 21:44:24 -0700 | [diff] [blame] | 1187 | |
| Kenny Root | 07714d4 | 2011-08-17 17:49:28 -0700 | [diff] [blame] | 1188 | // Add ourself to the Watchdog monitors if enabled. |
| 1189 | if (WATCHDOG_ENABLE) { |
| 1190 | Watchdog.getInstance().addMonitor(this); |
| 1191 | } |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /** |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1195 | * Exposed API calls below here |
| 1196 | */ |
| 1197 | |
| 1198 | public void registerListener(IMountServiceListener listener) { |
| 1199 | synchronized (mListeners) { |
| 1200 | MountServiceBinderListener bl = new MountServiceBinderListener(listener); |
| 1201 | try { |
| 1202 | listener.asBinder().linkToDeath(bl, 0); |
| 1203 | mListeners.add(bl); |
| 1204 | } catch (RemoteException rex) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1205 | Slog.e(TAG, "Failed to link to listener death"); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | public void unregisterListener(IMountServiceListener listener) { |
| 1211 | synchronized (mListeners) { |
| 1212 | for(MountServiceBinderListener bl : mListeners) { |
| 1213 | if (bl.mListener == listener) { |
| 1214 | mListeners.remove(mListeners.indexOf(bl)); |
| 1215 | return; |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | |
| Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 1221 | public void shutdown(final IMountShutdownObserver observer) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1222 | validatePermission(android.Manifest.permission.SHUTDOWN); |
| 1223 | |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1224 | Slog.i(TAG, "Shutting down"); |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 1225 | synchronized (mVolumeStates) { |
| 1226 | for (String path : mVolumeStates.keySet()) { |
| 1227 | String state = mVolumeStates.get(path); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1228 | |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 1229 | if (state.equals(Environment.MEDIA_SHARED)) { |
| 1230 | /* |
| 1231 | * If the media is currently shared, unshare it. |
| 1232 | * XXX: This is still dangerous!. We should not |
| 1233 | * be rebooting at *all* if UMS is enabled, since |
| 1234 | * the UMS host could have dirty FAT cache entries |
| 1235 | * yet to flush. |
| 1236 | */ |
| 1237 | setUsbMassStorageEnabled(false); |
| 1238 | } else if (state.equals(Environment.MEDIA_CHECKING)) { |
| 1239 | /* |
| 1240 | * If the media is being checked, then we need to wait for |
| 1241 | * it to complete before being able to proceed. |
| 1242 | */ |
| 1243 | // XXX: @hackbod - Should we disable the ANR timer here? |
| 1244 | int retries = 30; |
| 1245 | while (state.equals(Environment.MEDIA_CHECKING) && (retries-- >=0)) { |
| 1246 | try { |
| 1247 | Thread.sleep(1000); |
| 1248 | } catch (InterruptedException iex) { |
| 1249 | Slog.e(TAG, "Interrupted while waiting for media", iex); |
| 1250 | break; |
| 1251 | } |
| 1252 | state = Environment.getExternalStorageState(); |
| 1253 | } |
| 1254 | if (retries == 0) { |
| 1255 | Slog.e(TAG, "Timed out waiting for media to check"); |
| 1256 | } |
| San Mehat | 91c7761 | 2010-01-07 10:39:41 -0800 | [diff] [blame] | 1257 | } |
| San Mehat | 91c7761 | 2010-01-07 10:39:41 -0800 | [diff] [blame] | 1258 | |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 1259 | if (state.equals(Environment.MEDIA_MOUNTED)) { |
| 1260 | // Post a unmount message. |
| 1261 | ShutdownCallBack ucb = new ShutdownCallBack(path, observer); |
| 1262 | mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb)); |
| 1263 | } else if (observer != null) { |
| 1264 | /* |
| 1265 | * Observer is waiting for onShutDownComplete when we are done. |
| 1266 | * Since nothing will be done send notification directly so shutdown |
| 1267 | * sequence can continue. |
| 1268 | */ |
| 1269 | try { |
| 1270 | observer.onShutDownComplete(StorageResultCode.OperationSucceeded); |
| 1271 | } catch (RemoteException e) { |
| 1272 | Slog.w(TAG, "RemoteException when shutting down"); |
| 1273 | } |
| 1274 | } |
| Johan Alfven | 5d0db4d | 2010-11-09 10:32:25 +0100 | [diff] [blame] | 1275 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 1279 | private boolean getUmsEnabling() { |
| 1280 | synchronized (mListeners) { |
| 1281 | return mUmsEnabling; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | private void setUmsEnabling(boolean enable) { |
| 1286 | synchronized (mListeners) { |
| Tony Wu | fc71125 | 2010-08-09 16:49:19 +0800 | [diff] [blame] | 1287 | mUmsEnabling = enable; |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 1288 | } |
| 1289 | } |
| 1290 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1291 | public boolean isUsbMassStorageConnected() { |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1292 | waitForReady(); |
| San Mehat | 91c7761 | 2010-01-07 10:39:41 -0800 | [diff] [blame] | 1293 | |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 1294 | if (getUmsEnabling()) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1295 | return true; |
| San Mehat | 7fd0fee | 2009-12-17 07:12:23 -0800 | [diff] [blame] | 1296 | } |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 1297 | synchronized (mListeners) { |
| 1298 | return mUmsAvailable; |
| 1299 | } |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1300 | } |
| 1301 | |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 1302 | public void setUsbMassStorageEnabled(boolean enable) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1303 | waitForReady(); |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 1304 | validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1305 | |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 1306 | // TODO: Add support for multiple share methods |
| 1307 | |
| 1308 | /* |
| 1309 | * If the volume is mounted and we're enabling then unmount it |
| 1310 | */ |
| 1311 | String path = Environment.getExternalStorageDirectory().getPath(); |
| 1312 | String vs = getVolumeState(path); |
| 1313 | String method = "ums"; |
| 1314 | if (enable && vs.equals(Environment.MEDIA_MOUNTED)) { |
| 1315 | // Override for isUsbMassStorageEnabled() |
| 1316 | setUmsEnabling(enable); |
| 1317 | UmsEnableCallBack umscb = new UmsEnableCallBack(path, method, true); |
| 1318 | mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, umscb)); |
| 1319 | // Clear override |
| 1320 | setUmsEnabling(false); |
| 1321 | } |
| 1322 | /* |
| 1323 | * If we disabled UMS then mount the volume |
| 1324 | */ |
| 1325 | if (!enable) { |
| 1326 | doShareUnshareVolume(path, method, enable); |
| 1327 | if (doMountVolume(path) != StorageResultCode.OperationSucceeded) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1328 | Slog.e(TAG, "Failed to remount " + path + |
| Suchi Amalapurapu | 0eec21d | 2010-02-25 17:07:14 -0800 | [diff] [blame] | 1329 | " after disabling share method " + method); |
| 1330 | /* |
| 1331 | * Even though the mount failed, the unshare didn't so don't indicate an error. |
| 1332 | * The mountVolume() call will have set the storage state and sent the necessary |
| 1333 | * broadcasts. |
| 1334 | */ |
| 1335 | } |
| 1336 | } |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | public boolean isUsbMassStorageEnabled() { |
| 1340 | waitForReady(); |
| 1341 | return doGetVolumeShared(Environment.getExternalStorageDirectory().getPath(), "ums"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | } |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1343 | |
| San Mehat | 7fd0fee | 2009-12-17 07:12:23 -0800 | [diff] [blame] | 1344 | /** |
| 1345 | * @return state of the volume at the specified mount point |
| 1346 | */ |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1347 | public String getVolumeState(String mountPoint) { |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 1348 | synchronized (mVolumeStates) { |
| 1349 | String state = mVolumeStates.get(mountPoint); |
| 1350 | if (state == null) { |
| 1351 | Slog.w(TAG, "getVolumeState(" + mountPoint + "): Unknown volume"); |
| Ken Sumrall | 18db5c5 | 2011-07-14 11:35:06 -0700 | [diff] [blame] | 1352 | if (SystemProperties.get("vold.encrypt_progress").length() != 0) { |
| 1353 | state = Environment.MEDIA_REMOVED; |
| 1354 | } else { |
| 1355 | throw new IllegalArgumentException(); |
| 1356 | } |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 1357 | } |
| San Mehat | 7fd0fee | 2009-12-17 07:12:23 -0800 | [diff] [blame] | 1358 | |
| Mike Lockwood | 7fa24aa | 2011-03-23 14:52:34 -0400 | [diff] [blame] | 1359 | return state; |
| 1360 | } |
| San Mehat | 7fd0fee | 2009-12-17 07:12:23 -0800 | [diff] [blame] | 1361 | } |
| 1362 | |
| Kenny Root | e1ff214 | 2010-10-12 11:20:01 -0700 | [diff] [blame] | 1363 | public boolean isExternalStorageEmulated() { |
| 1364 | return mEmulateExternalStorage; |
| 1365 | } |
| 1366 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1367 | public int mountVolume(String path) { |
| 1368 | validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1369 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1370 | waitForReady(); |
| 1371 | return doMountVolume(path); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1372 | } |
| 1373 | |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 1374 | public void unmountVolume(String path, boolean force) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1375 | validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1376 | waitForReady(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 1378 | String volState = getVolumeState(path); |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1379 | if (DEBUG_UNMOUNT) Slog.i(TAG, "Unmounting " + path + " force = " + force); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 1380 | if (Environment.MEDIA_UNMOUNTED.equals(volState) || |
| 1381 | Environment.MEDIA_REMOVED.equals(volState) || |
| 1382 | Environment.MEDIA_SHARED.equals(volState) || |
| 1383 | Environment.MEDIA_UNMOUNTABLE.equals(volState)) { |
| 1384 | // Media already unmounted or cannot be unmounted. |
| 1385 | // TODO return valid return code when adding observer call back. |
| 1386 | return; |
| 1387 | } |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 1388 | UnmountCallBack ucb = new UnmountCallBack(path, force); |
| 1389 | mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | } |
| 1391 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1392 | public int formatVolume(String path) { |
| 1393 | validatePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1394 | waitForReady(); |
| San Mehat | 5b77dab | 2010-01-26 13:28:50 -0800 | [diff] [blame] | 1395 | |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1396 | return doFormatVolume(path); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | } |
| 1398 | |
| Mike Lockwood | ecedfdc | 2011-06-08 15:11:59 -0700 | [diff] [blame] | 1399 | public int[] getStorageUsers(String path) { |
| San Mehat | c1b4ce9 | 2010-02-16 17:13:03 -0800 | [diff] [blame] | 1400 | validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); |
| 1401 | waitForReady(); |
| 1402 | try { |
| 1403 | String[] r = mConnector.doListCommand( |
| 1404 | String.format("storage users %s", path), |
| 1405 | VoldResponseCode.StorageUsersListResult); |
| 1406 | // FMT: <pid> <process name> |
| 1407 | int[] data = new int[r.length]; |
| 1408 | for (int i = 0; i < r.length; i++) { |
| 1409 | String []tok = r[i].split(" "); |
| 1410 | try { |
| 1411 | data[i] = Integer.parseInt(tok[0]); |
| 1412 | } catch (NumberFormatException nfe) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1413 | Slog.e(TAG, String.format("Error parsing pid %s", tok[0])); |
| San Mehat | c1b4ce9 | 2010-02-16 17:13:03 -0800 | [diff] [blame] | 1414 | return new int[0]; |
| 1415 | } |
| 1416 | } |
| 1417 | return data; |
| 1418 | } catch (NativeDaemonConnectorException e) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1419 | Slog.e(TAG, "Failed to retrieve storage users list", e); |
| San Mehat | c1b4ce9 | 2010-02-16 17:13:03 -0800 | [diff] [blame] | 1420 | return new int[0]; |
| 1421 | } |
| 1422 | } |
| 1423 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1424 | private void warnOnNotMounted() { |
| 1425 | if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { |
| San Mehat | a507859 | 2010-03-25 09:36:54 -0700 | [diff] [blame] | 1426 | Slog.w(TAG, "getSecureContainerList() called when storage not mounted"); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1430 | public String[] getSecureContainerList() { |
| 1431 | validatePermission(android.Manifest.permission.ASEC_ACCESS); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1432 | waitForReady(); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1433 | warnOnNotMounted(); |
| San Mehat | f919cd02 | 2010-02-04 15:10:38 -0800 | [diff] [blame] | 1434 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1435 | try { |
| 1436 | return mConnector.doListCommand("asec list", VoldResponseCode.AsecListResult); |
| 1437 | } catch (NativeDaemonConnectorException e) { |
| 1438 | return new String[0]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | } |
| 1440 | } |
| San Mehat | 3697229 | 2010-01-06 11:06:32 -0800 | [diff] [blame] | 1441 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1442 | public int createSecureContainer(String id, int sizeMb, String fstype, |
| 1443 | String key, int ownerUid) { |
| 1444 | validatePermission(android.Manifest.permission.ASEC_CREATE); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1445 | waitForReady(); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1446 | warnOnNotMounted(); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1447 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1448 | int rc = StorageResultCode.OperationSucceeded; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1449 | String cmd = String.format("asec create %s %d %s %s %d", id, sizeMb, fstype, key, ownerUid); |
| 1450 | try { |
| 1451 | mConnector.doCommand(cmd); |
| 1452 | } catch (NativeDaemonConnectorException e) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1453 | rc = StorageResultCode.OperationFailedInternalError; |
| San Mehat | 02735bc | 2010-01-26 15:18:08 -0800 | [diff] [blame] | 1454 | } |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1455 | |
| 1456 | if (rc == StorageResultCode.OperationSucceeded) { |
| 1457 | synchronized (mAsecMountSet) { |
| 1458 | mAsecMountSet.add(id); |
| 1459 | } |
| 1460 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1461 | return rc; |
| San Mehat | 3697229 | 2010-01-06 11:06:32 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1464 | public int finalizeSecureContainer(String id) { |
| 1465 | validatePermission(android.Manifest.permission.ASEC_CREATE); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1466 | warnOnNotMounted(); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1467 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1468 | int rc = StorageResultCode.OperationSucceeded; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1469 | try { |
| 1470 | mConnector.doCommand(String.format("asec finalize %s", id)); |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1471 | /* |
| 1472 | * Finalization does a remount, so no need |
| 1473 | * to update mAsecMountSet |
| 1474 | */ |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1475 | } catch (NativeDaemonConnectorException e) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1476 | rc = StorageResultCode.OperationFailedInternalError; |
| San Mehat | 02735bc | 2010-01-26 15:18:08 -0800 | [diff] [blame] | 1477 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1478 | return rc; |
| San Mehat | 3697229 | 2010-01-06 11:06:32 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 1481 | public int destroySecureContainer(String id, boolean force) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1482 | validatePermission(android.Manifest.permission.ASEC_DESTROY); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1483 | waitForReady(); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1484 | warnOnNotMounted(); |
| San Mehat | f919cd02 | 2010-02-04 15:10:38 -0800 | [diff] [blame] | 1485 | |
| Kenny Root | aa48540 | 2010-09-14 14:49:41 -0700 | [diff] [blame] | 1486 | /* |
| 1487 | * Force a GC to make sure AssetManagers in other threads of the |
| 1488 | * system_server are cleaned up. We have to do this since AssetManager |
| 1489 | * instances are kept as a WeakReference and it's possible we have files |
| 1490 | * open on the external storage. |
| 1491 | */ |
| 1492 | Runtime.getRuntime().gc(); |
| 1493 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1494 | int rc = StorageResultCode.OperationSucceeded; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1495 | try { |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 1496 | mConnector.doCommand(String.format("asec destroy %s%s", id, (force ? " force" : ""))); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1497 | } catch (NativeDaemonConnectorException e) { |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 1498 | int code = e.getCode(); |
| 1499 | if (code == VoldResponseCode.OpFailedStorageBusy) { |
| 1500 | rc = StorageResultCode.OperationFailedStorageBusy; |
| 1501 | } else { |
| 1502 | rc = StorageResultCode.OperationFailedInternalError; |
| 1503 | } |
| San Mehat | 02735bc | 2010-01-26 15:18:08 -0800 | [diff] [blame] | 1504 | } |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1505 | |
| 1506 | if (rc == StorageResultCode.OperationSucceeded) { |
| 1507 | synchronized (mAsecMountSet) { |
| 1508 | if (mAsecMountSet.contains(id)) { |
| 1509 | mAsecMountSet.remove(id); |
| 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1514 | return rc; |
| San Mehat | 3697229 | 2010-01-06 11:06:32 -0800 | [diff] [blame] | 1515 | } |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1516 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1517 | public int mountSecureContainer(String id, String key, int ownerUid) { |
| 1518 | validatePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1519 | waitForReady(); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1520 | warnOnNotMounted(); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1521 | |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1522 | synchronized (mAsecMountSet) { |
| 1523 | if (mAsecMountSet.contains(id)) { |
| 1524 | return StorageResultCode.OperationFailedStorageMounted; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1528 | int rc = StorageResultCode.OperationSucceeded; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1529 | String cmd = String.format("asec mount %s %s %d", id, key, ownerUid); |
| 1530 | try { |
| 1531 | mConnector.doCommand(cmd); |
| 1532 | } catch (NativeDaemonConnectorException e) { |
| Kenny Root | f030462 | 2010-03-19 19:20:42 -0700 | [diff] [blame] | 1533 | int code = e.getCode(); |
| 1534 | if (code != VoldResponseCode.OpFailedStorageBusy) { |
| 1535 | rc = StorageResultCode.OperationFailedInternalError; |
| 1536 | } |
| San Mehat | 02735bc | 2010-01-26 15:18:08 -0800 | [diff] [blame] | 1537 | } |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 1538 | |
| 1539 | if (rc == StorageResultCode.OperationSucceeded) { |
| 1540 | synchronized (mAsecMountSet) { |
| 1541 | mAsecMountSet.add(id); |
| 1542 | } |
| 1543 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1544 | return rc; |
| San Mehat | 3697229 | 2010-01-06 11:06:32 -0800 | [diff] [blame] | 1545 | } |
| 1546 | |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 1547 | public int unmountSecureContainer(String id, boolean force) { |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1548 | validatePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1549 | waitForReady(); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1550 | warnOnNotMounted(); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1551 | |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 1552 | synchronized (mAsecMountSet) { |
| 1553 | if (!mAsecMountSet.contains(id)) { |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1554 | return StorageResultCode.OperationFailedStorageNotMounted; |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
| Kenny Root | aa48540 | 2010-09-14 14:49:41 -0700 | [diff] [blame] | 1558 | /* |
| 1559 | * Force a GC to make sure AssetManagers in other threads of the |
| 1560 | * system_server are cleaned up. We have to do this since AssetManager |
| 1561 | * instances are kept as a WeakReference and it's possible we have files |
| 1562 | * open on the external storage. |
| 1563 | */ |
| 1564 | Runtime.getRuntime().gc(); |
| 1565 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1566 | int rc = StorageResultCode.OperationSucceeded; |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 1567 | String cmd = String.format("asec unmount %s%s", id, (force ? " force" : "")); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1568 | try { |
| 1569 | mConnector.doCommand(cmd); |
| 1570 | } catch (NativeDaemonConnectorException e) { |
| San Mehat | d970998 | 2010-02-18 11:43:03 -0800 | [diff] [blame] | 1571 | int code = e.getCode(); |
| 1572 | if (code == VoldResponseCode.OpFailedStorageBusy) { |
| 1573 | rc = StorageResultCode.OperationFailedStorageBusy; |
| 1574 | } else { |
| 1575 | rc = StorageResultCode.OperationFailedInternalError; |
| 1576 | } |
| San Mehat | 02735bc | 2010-01-26 15:18:08 -0800 | [diff] [blame] | 1577 | } |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 1578 | |
| 1579 | if (rc == StorageResultCode.OperationSucceeded) { |
| 1580 | synchronized (mAsecMountSet) { |
| 1581 | mAsecMountSet.remove(id); |
| 1582 | } |
| 1583 | } |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1584 | return rc; |
| San Mehat | 9dba709 | 2010-01-18 06:47:41 -0800 | [diff] [blame] | 1585 | } |
| 1586 | |
| San Mehat | 6cdd9c0 | 2010-02-09 14:45:20 -0800 | [diff] [blame] | 1587 | public boolean isSecureContainerMounted(String id) { |
| 1588 | validatePermission(android.Manifest.permission.ASEC_ACCESS); |
| 1589 | waitForReady(); |
| 1590 | warnOnNotMounted(); |
| 1591 | |
| 1592 | synchronized (mAsecMountSet) { |
| 1593 | return mAsecMountSet.contains(id); |
| 1594 | } |
| 1595 | } |
| 1596 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1597 | public int renameSecureContainer(String oldId, String newId) { |
| 1598 | validatePermission(android.Manifest.permission.ASEC_RENAME); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1599 | waitForReady(); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1600 | warnOnNotMounted(); |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1601 | |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1602 | synchronized (mAsecMountSet) { |
| San Mehat | 85451ee | 2010-02-24 08:54:18 -0800 | [diff] [blame] | 1603 | /* |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1604 | * Because a mounted container has active internal state which cannot be |
| San Mehat | 85451ee | 2010-02-24 08:54:18 -0800 | [diff] [blame] | 1605 | * changed while active, we must ensure both ids are not currently mounted. |
| 1606 | */ |
| 1607 | if (mAsecMountSet.contains(oldId) || mAsecMountSet.contains(newId)) { |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1608 | return StorageResultCode.OperationFailedStorageMounted; |
| 1609 | } |
| 1610 | } |
| 1611 | |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1612 | int rc = StorageResultCode.OperationSucceeded; |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1613 | String cmd = String.format("asec rename %s %s", oldId, newId); |
| 1614 | try { |
| 1615 | mConnector.doCommand(cmd); |
| 1616 | } catch (NativeDaemonConnectorException e) { |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1617 | rc = StorageResultCode.OperationFailedInternalError; |
| San Mehat | 02735bc | 2010-01-26 15:18:08 -0800 | [diff] [blame] | 1618 | } |
| San Mehat | a181b21 | 2010-02-11 06:50:20 -0800 | [diff] [blame] | 1619 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1620 | return rc; |
| San Mehat | 45f6104 | 2010-01-23 08:12:43 -0800 | [diff] [blame] | 1621 | } |
| 1622 | |
| San Mehat | 4270e1e | 2010-01-29 05:32:19 -0800 | [diff] [blame] | 1623 | public String getSecureContainerPath(String id) { |
| 1624 | validatePermission(android.Manifest.permission.ASEC_ACCESS); |
| San Mehat | 207e538 | 2010-02-04 20:46:54 -0800 | [diff] [blame] | 1625 | waitForReady(); |
| San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 1626 | warnOnNotMounted(); |
| San Mehat | f919cd02 | 2010-02-04 15:10:38 -0800 | [diff] [blame] | 1627 | |
| San Mehat | 2d66cef | 2010-03-23 11:12:52 -0700 | [diff] [blame] | 1628 | try { |
| 1629 | ArrayList<String> rsp = mConnector.doCommand(String.format("asec path %s", id)); |
| 1630 | String []tok = rsp.get(0).split(" "); |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 1631 | int code = Integer.parseInt(tok[0]); |
| San Mehat | 2d66cef | 2010-03-23 11:12:52 -0700 | [diff] [blame] | 1632 | if (code != VoldResponseCode.AsecPathResult) { |
| 1633 | throw new IllegalStateException(String.format("Unexpected response code %d", code)); |
| 1634 | } |
| 1635 | return tok[1]; |
| 1636 | } catch (NativeDaemonConnectorException e) { |
| 1637 | int code = e.getCode(); |
| 1638 | if (code == VoldResponseCode.OpFailedStorageNotFound) { |
| Fredrik Helmer | a20c8ef | 2011-02-09 16:16:10 +0100 | [diff] [blame] | 1639 | Slog.i(TAG, String.format("Container '%s' not found", id)); |
| 1640 | return null; |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 1641 | } else { |
| San Mehat | 2d66cef | 2010-03-23 11:12:52 -0700 | [diff] [blame] | 1642 | throw new IllegalStateException(String.format("Unexpected response code %d", code)); |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 1643 | } |
| 1644 | } |
| San Mehat | 22dd86e | 2010-01-12 12:21:18 -0800 | [diff] [blame] | 1645 | } |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 1646 | |
| Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 1647 | public String getSecureContainerFilesystemPath(String id) { |
| 1648 | validatePermission(android.Manifest.permission.ASEC_ACCESS); |
| 1649 | waitForReady(); |
| 1650 | warnOnNotMounted(); |
| 1651 | |
| 1652 | try { |
| 1653 | ArrayList<String> rsp = mConnector.doCommand(String.format("asec fspath %s", id)); |
| 1654 | String []tok = rsp.get(0).split(" "); |
| 1655 | int code = Integer.parseInt(tok[0]); |
| 1656 | if (code != VoldResponseCode.AsecPathResult) { |
| 1657 | throw new IllegalStateException(String.format("Unexpected response code %d", code)); |
| 1658 | } |
| 1659 | return tok[1]; |
| 1660 | } catch (NativeDaemonConnectorException e) { |
| 1661 | int code = e.getCode(); |
| 1662 | if (code == VoldResponseCode.OpFailedStorageNotFound) { |
| 1663 | Slog.i(TAG, String.format("Container '%s' not found", id)); |
| 1664 | return null; |
| 1665 | } else { |
| 1666 | throw new IllegalStateException(String.format("Unexpected response code %d", code)); |
| 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 1671 | public void finishMediaUpdate() { |
| 1672 | mHandler.sendEmptyMessage(H_UNMOUNT_PM_DONE); |
| 1673 | } |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1674 | |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1675 | private boolean isUidOwnerOfPackageOrSystem(String packageName, int callerUid) { |
| 1676 | if (callerUid == android.os.Process.SYSTEM_UID) { |
| 1677 | return true; |
| 1678 | } |
| 1679 | |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1680 | if (packageName == null) { |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
| 1684 | final int packageUid = mPms.getPackageUid(packageName); |
| 1685 | |
| 1686 | if (DEBUG_OBB) { |
| 1687 | Slog.d(TAG, "packageName = " + packageName + ", packageUid = " + |
| 1688 | packageUid + ", callerUid = " + callerUid); |
| 1689 | } |
| 1690 | |
| 1691 | return callerUid == packageUid; |
| 1692 | } |
| 1693 | |
| 1694 | public String getMountedObbPath(String filename) { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1695 | if (filename == null) { |
| 1696 | throw new IllegalArgumentException("filename cannot be null"); |
| 1697 | } |
| 1698 | |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1699 | waitForReady(); |
| 1700 | warnOnNotMounted(); |
| 1701 | |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1702 | try { |
| 1703 | ArrayList<String> rsp = mConnector.doCommand(String.format("obb path %s", filename)); |
| 1704 | String []tok = rsp.get(0).split(" "); |
| 1705 | int code = Integer.parseInt(tok[0]); |
| 1706 | if (code != VoldResponseCode.AsecPathResult) { |
| 1707 | throw new IllegalStateException(String.format("Unexpected response code %d", code)); |
| 1708 | } |
| 1709 | return tok[1]; |
| 1710 | } catch (NativeDaemonConnectorException e) { |
| 1711 | int code = e.getCode(); |
| 1712 | if (code == VoldResponseCode.OpFailedStorageNotFound) { |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1713 | return null; |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1714 | } else { |
| 1715 | throw new IllegalStateException(String.format("Unexpected response code %d", code)); |
| 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | public boolean isObbMounted(String filename) { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1721 | if (filename == null) { |
| 1722 | throw new IllegalArgumentException("filename cannot be null"); |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1723 | } |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1724 | |
| 1725 | synchronized (mObbMounts) { |
| 1726 | return mObbPathToStateMap.containsKey(filename); |
| 1727 | } |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1730 | public void mountObb(String filename, String key, IObbActionListener token, int nonce) |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 1731 | throws RemoteException { |
| Kenny Root | f1121dc | 2010-09-29 07:30:53 -0700 | [diff] [blame] | 1732 | if (filename == null) { |
| 1733 | throw new IllegalArgumentException("filename cannot be null"); |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | if (token == null) { |
| Kenny Root | f1121dc | 2010-09-29 07:30:53 -0700 | [diff] [blame] | 1737 | throw new IllegalArgumentException("token cannot be null"); |
| 1738 | } |
| 1739 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1740 | final int callerUid = Binder.getCallingUid(); |
| 1741 | final ObbState obbState = new ObbState(filename, callerUid, token, nonce); |
| 1742 | final ObbAction action = new MountObbAction(obbState, key); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1743 | mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); |
| 1744 | |
| 1745 | if (DEBUG_OBB) |
| 1746 | Slog.i(TAG, "Send to OBB handler: " + action.toString()); |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1749 | public void unmountObb(String filename, boolean force, IObbActionListener token, int nonce) |
| 1750 | throws RemoteException { |
| Kenny Root | f1121dc | 2010-09-29 07:30:53 -0700 | [diff] [blame] | 1751 | if (filename == null) { |
| 1752 | throw new IllegalArgumentException("filename cannot be null"); |
| Kenny Root | f1121dc | 2010-09-29 07:30:53 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1755 | final int callerUid = Binder.getCallingUid(); |
| 1756 | final ObbState obbState = new ObbState(filename, callerUid, token, nonce); |
| 1757 | final ObbAction action = new UnmountObbAction(obbState, force); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1758 | mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 1759 | |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1760 | if (DEBUG_OBB) |
| 1761 | Slog.i(TAG, "Send to OBB handler: " + action.toString()); |
| 1762 | } |
| 1763 | |
| Ben Komalo | 444eca2 | 2011-09-01 15:17:44 -0700 | [diff] [blame^] | 1764 | @Override |
| 1765 | public int getEncryptionState() { |
| 1766 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, |
| 1767 | "no permission to access the crypt keeper"); |
| 1768 | |
| 1769 | waitForReady(); |
| 1770 | |
| 1771 | try { |
| 1772 | ArrayList<String> rsp = mConnector.doCommand("cryptfs cryptocomplete"); |
| 1773 | String[] tokens = rsp.get(0).split(" "); |
| 1774 | |
| 1775 | if (tokens == null || tokens.length != 2) { |
| 1776 | // Unexpected. |
| 1777 | Slog.w(TAG, "Unexpected result from cryptfs cryptocomplete"); |
| 1778 | return ENCRYPTION_STATE_ERROR_UNKNOWN; |
| 1779 | } |
| 1780 | |
| 1781 | return Integer.parseInt(tokens[1]); |
| 1782 | |
| 1783 | } catch (NumberFormatException e) { |
| 1784 | // Bad result - unexpected. |
| 1785 | Slog.w(TAG, "Unable to parse result from cryptfs cryptocomplete"); |
| 1786 | return ENCRYPTION_STATE_ERROR_UNKNOWN; |
| 1787 | } catch (NativeDaemonConnectorException e) { |
| 1788 | // Something bad happened. |
| 1789 | Slog.w(TAG, "Error in communicating with cryptfs in validating"); |
| 1790 | return ENCRYPTION_STATE_ERROR_UNKNOWN; |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | @Override |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 1795 | public int decryptStorage(String password) { |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 1796 | if (TextUtils.isEmpty(password)) { |
| 1797 | throw new IllegalArgumentException("password cannot be empty"); |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 1798 | } |
| 1799 | |
| Jason parks | 8888c59 | 2011-01-20 22:46:41 -0600 | [diff] [blame] | 1800 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, |
| 1801 | "no permission to access the crypt keeper"); |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 1802 | |
| 1803 | waitForReady(); |
| 1804 | |
| 1805 | if (DEBUG_EVENTS) { |
| 1806 | Slog.i(TAG, "decrypting storage..."); |
| 1807 | } |
| 1808 | |
| 1809 | try { |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1810 | ArrayList<String> rsp = mConnector.doCommand("cryptfs checkpw " + password); |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 1811 | String[] tokens = rsp.get(0).split(" "); |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1812 | |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 1813 | if (tokens == null || tokens.length != 2) { |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1814 | return -1; |
| 1815 | } |
| 1816 | |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 1817 | int code = Integer.parseInt(tokens[1]); |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1818 | |
| 1819 | if (code == 0) { |
| 1820 | // Decrypt was successful. Post a delayed message before restarting in order |
| 1821 | // to let the UI to clear itself |
| 1822 | mHandler.postDelayed(new Runnable() { |
| 1823 | public void run() { |
| 1824 | mConnector.doCommand(String.format("cryptfs restart")); |
| 1825 | } |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 1826 | }, 1000); // 1 second |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | return code; |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 1830 | } catch (NativeDaemonConnectorException e) { |
| 1831 | // Decryption failed |
| 1832 | return e.getCode(); |
| 1833 | } |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 1834 | } |
| 1835 | |
| Jason parks | 56aa532 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 1836 | public int encryptStorage(String password) { |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 1837 | if (TextUtils.isEmpty(password)) { |
| 1838 | throw new IllegalArgumentException("password cannot be empty"); |
| Jason parks | 56aa532 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 1839 | } |
| 1840 | |
| Jason parks | 8888c59 | 2011-01-20 22:46:41 -0600 | [diff] [blame] | 1841 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, |
| 1842 | "no permission to access the crypt keeper"); |
| Jason parks | 56aa532 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 1843 | |
| 1844 | waitForReady(); |
| 1845 | |
| 1846 | if (DEBUG_EVENTS) { |
| Jason parks | 8888c59 | 2011-01-20 22:46:41 -0600 | [diff] [blame] | 1847 | Slog.i(TAG, "encrypting storage..."); |
| Jason parks | 56aa532 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | try { |
| Jason parks | 9ed98bc | 2011-01-17 09:58:35 -0600 | [diff] [blame] | 1851 | mConnector.doCommand(String.format("cryptfs enablecrypto inplace %s", password)); |
| Jason parks | 56aa532 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 1852 | } catch (NativeDaemonConnectorException e) { |
| 1853 | // Encryption failed |
| 1854 | return e.getCode(); |
| 1855 | } |
| 1856 | |
| 1857 | return 0; |
| 1858 | } |
| 1859 | |
| Jason parks | f7b3cd4 | 2011-01-27 09:28:25 -0600 | [diff] [blame] | 1860 | public int changeEncryptionPassword(String password) { |
| 1861 | if (TextUtils.isEmpty(password)) { |
| 1862 | throw new IllegalArgumentException("password cannot be empty"); |
| 1863 | } |
| 1864 | |
| 1865 | mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER, |
| 1866 | "no permission to access the crypt keeper"); |
| 1867 | |
| 1868 | waitForReady(); |
| 1869 | |
| 1870 | if (DEBUG_EVENTS) { |
| 1871 | Slog.i(TAG, "changing encryption password..."); |
| 1872 | } |
| 1873 | |
| 1874 | try { |
| 1875 | ArrayList<String> response = mConnector.doCommand("cryptfs changepw " + password); |
| 1876 | |
| 1877 | String[] tokens = response.get(0).split(" "); |
| 1878 | |
| 1879 | if (tokens == null || tokens.length != 2) { |
| 1880 | return -1; |
| 1881 | } |
| 1882 | |
| 1883 | return Integer.parseInt(tokens[1]); |
| 1884 | } catch (NativeDaemonConnectorException e) { |
| 1885 | // Encryption failed |
| 1886 | return e.getCode(); |
| 1887 | } |
| 1888 | } |
| 1889 | |
| Mike Lockwood | 2f6a388 | 2011-05-09 19:08:06 -0700 | [diff] [blame] | 1890 | public Parcelable[] getVolumeList() { |
| 1891 | synchronized(mVolumes) { |
| 1892 | int size = mVolumes.size(); |
| 1893 | Parcelable[] result = new Parcelable[size]; |
| 1894 | for (int i = 0; i < size; i++) { |
| 1895 | result[i] = mVolumes.get(i); |
| Mike Lockwood | 8fa5f80 | 2011-03-24 08:12:30 -0700 | [diff] [blame] | 1896 | } |
| 1897 | return result; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1901 | private void addObbStateLocked(ObbState obbState) throws RemoteException { |
| 1902 | final IBinder binder = obbState.getBinder(); |
| 1903 | List<ObbState> obbStates = mObbMounts.get(binder); |
| Kenny Root | 5919ac6 | 2010-10-05 09:49:40 -0700 | [diff] [blame] | 1904 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1905 | if (obbStates == null) { |
| 1906 | obbStates = new ArrayList<ObbState>(); |
| 1907 | mObbMounts.put(binder, obbStates); |
| 1908 | } else { |
| 1909 | for (final ObbState o : obbStates) { |
| 1910 | if (o.filename.equals(obbState.filename)) { |
| 1911 | throw new IllegalStateException("Attempt to add ObbState twice. " |
| 1912 | + "This indicates an error in the MountService logic."); |
| Kenny Root | 5919ac6 | 2010-10-05 09:49:40 -0700 | [diff] [blame] | 1913 | } |
| 1914 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1915 | } |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1916 | |
| 1917 | obbStates.add(obbState); |
| 1918 | try { |
| 1919 | obbState.link(); |
| 1920 | } catch (RemoteException e) { |
| 1921 | /* |
| 1922 | * The binder died before we could link it, so clean up our state |
| 1923 | * and return failure. |
| 1924 | */ |
| 1925 | obbStates.remove(obbState); |
| 1926 | if (obbStates.isEmpty()) { |
| 1927 | mObbMounts.remove(binder); |
| 1928 | } |
| 1929 | |
| 1930 | // Rethrow the error so mountObb can get it |
| 1931 | throw e; |
| 1932 | } |
| 1933 | |
| 1934 | mObbPathToStateMap.put(obbState.filename, obbState); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1937 | private void removeObbStateLocked(ObbState obbState) { |
| 1938 | final IBinder binder = obbState.getBinder(); |
| 1939 | final List<ObbState> obbStates = mObbMounts.get(binder); |
| 1940 | if (obbStates != null) { |
| 1941 | if (obbStates.remove(obbState)) { |
| 1942 | obbState.unlink(); |
| Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 1943 | } |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1944 | if (obbStates.isEmpty()) { |
| 1945 | mObbMounts.remove(binder); |
| 1946 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1947 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1948 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 1949 | mObbPathToStateMap.remove(obbState.filename); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1952 | private class ObbActionHandler extends Handler { |
| 1953 | private boolean mBound = false; |
| Kenny Root | 480afe7 | 2010-10-07 10:17:50 -0700 | [diff] [blame] | 1954 | private final List<ObbAction> mActions = new LinkedList<ObbAction>(); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1955 | |
| 1956 | ObbActionHandler(Looper l) { |
| 1957 | super(l); |
| 1958 | } |
| 1959 | |
| 1960 | @Override |
| 1961 | public void handleMessage(Message msg) { |
| 1962 | switch (msg.what) { |
| 1963 | case OBB_RUN_ACTION: { |
| Kenny Root | 480afe7 | 2010-10-07 10:17:50 -0700 | [diff] [blame] | 1964 | final ObbAction action = (ObbAction) msg.obj; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1965 | |
| 1966 | if (DEBUG_OBB) |
| 1967 | Slog.i(TAG, "OBB_RUN_ACTION: " + action.toString()); |
| 1968 | |
| 1969 | // If a bind was already initiated we don't really |
| 1970 | // need to do anything. The pending install |
| 1971 | // will be processed later on. |
| 1972 | if (!mBound) { |
| 1973 | // If this is the only one pending we might |
| 1974 | // have to bind to the service again. |
| 1975 | if (!connectToService()) { |
| 1976 | Slog.e(TAG, "Failed to bind to media container service"); |
| 1977 | action.handleError(); |
| 1978 | return; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1979 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1980 | } |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 1981 | |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 1982 | mActions.add(action); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 1983 | break; |
| 1984 | } |
| 1985 | case OBB_MCS_BOUND: { |
| 1986 | if (DEBUG_OBB) |
| 1987 | Slog.i(TAG, "OBB_MCS_BOUND"); |
| 1988 | if (msg.obj != null) { |
| 1989 | mContainerService = (IMediaContainerService) msg.obj; |
| 1990 | } |
| 1991 | if (mContainerService == null) { |
| 1992 | // Something seriously wrong. Bail out |
| 1993 | Slog.e(TAG, "Cannot bind to media container service"); |
| 1994 | for (ObbAction action : mActions) { |
| 1995 | // Indicate service bind error |
| 1996 | action.handleError(); |
| 1997 | } |
| 1998 | mActions.clear(); |
| 1999 | } else if (mActions.size() > 0) { |
| Kenny Root | 480afe7 | 2010-10-07 10:17:50 -0700 | [diff] [blame] | 2000 | final ObbAction action = mActions.get(0); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2001 | if (action != null) { |
| 2002 | action.execute(this); |
| 2003 | } |
| 2004 | } else { |
| 2005 | // Should never happen ideally. |
| 2006 | Slog.w(TAG, "Empty queue"); |
| 2007 | } |
| 2008 | break; |
| 2009 | } |
| 2010 | case OBB_MCS_RECONNECT: { |
| 2011 | if (DEBUG_OBB) |
| 2012 | Slog.i(TAG, "OBB_MCS_RECONNECT"); |
| 2013 | if (mActions.size() > 0) { |
| 2014 | if (mBound) { |
| 2015 | disconnectService(); |
| 2016 | } |
| 2017 | if (!connectToService()) { |
| 2018 | Slog.e(TAG, "Failed to bind to media container service"); |
| 2019 | for (ObbAction action : mActions) { |
| 2020 | // Indicate service bind error |
| 2021 | action.handleError(); |
| 2022 | } |
| 2023 | mActions.clear(); |
| 2024 | } |
| 2025 | } |
| 2026 | break; |
| 2027 | } |
| 2028 | case OBB_MCS_UNBIND: { |
| 2029 | if (DEBUG_OBB) |
| 2030 | Slog.i(TAG, "OBB_MCS_UNBIND"); |
| 2031 | |
| 2032 | // Delete pending install |
| 2033 | if (mActions.size() > 0) { |
| 2034 | mActions.remove(0); |
| 2035 | } |
| 2036 | if (mActions.size() == 0) { |
| 2037 | if (mBound) { |
| 2038 | disconnectService(); |
| 2039 | } |
| 2040 | } else { |
| 2041 | // There are more pending requests in queue. |
| 2042 | // Just post MCS_BOUND message to trigger processing |
| 2043 | // of next pending install. |
| 2044 | mObbActionHandler.sendEmptyMessage(OBB_MCS_BOUND); |
| 2045 | } |
| 2046 | break; |
| 2047 | } |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2048 | case OBB_FLUSH_MOUNT_STATE: { |
| 2049 | final String path = (String) msg.obj; |
| 2050 | |
| 2051 | if (DEBUG_OBB) |
| 2052 | Slog.i(TAG, "Flushing all OBB state for path " + path); |
| 2053 | |
| 2054 | synchronized (mObbMounts) { |
| 2055 | final List<ObbState> obbStatesToRemove = new LinkedList<ObbState>(); |
| 2056 | |
| 2057 | final Iterator<Entry<String, ObbState>> i = |
| 2058 | mObbPathToStateMap.entrySet().iterator(); |
| 2059 | while (i.hasNext()) { |
| 2060 | final Entry<String, ObbState> obbEntry = i.next(); |
| 2061 | |
| 2062 | /* |
| 2063 | * If this entry's source file is in the volume path |
| 2064 | * that got unmounted, remove it because it's no |
| 2065 | * longer valid. |
| 2066 | */ |
| 2067 | if (obbEntry.getKey().startsWith(path)) { |
| 2068 | obbStatesToRemove.add(obbEntry.getValue()); |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | for (final ObbState obbState : obbStatesToRemove) { |
| 2073 | if (DEBUG_OBB) |
| 2074 | Slog.i(TAG, "Removing state for " + obbState.filename); |
| 2075 | |
| 2076 | removeObbStateLocked(obbState); |
| 2077 | |
| 2078 | try { |
| 2079 | obbState.token.onObbResult(obbState.filename, obbState.nonce, |
| 2080 | OnObbStateChangeListener.UNMOUNTED); |
| 2081 | } catch (RemoteException e) { |
| 2082 | Slog.i(TAG, "Couldn't send unmount notification for OBB: " |
| 2083 | + obbState.filename); |
| 2084 | } |
| 2085 | } |
| 2086 | } |
| 2087 | break; |
| 2088 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | private boolean connectToService() { |
| 2093 | if (DEBUG_OBB) |
| 2094 | Slog.i(TAG, "Trying to bind to DefaultContainerService"); |
| 2095 | |
| 2096 | Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT); |
| 2097 | if (mContext.bindService(service, mDefContainerConn, Context.BIND_AUTO_CREATE)) { |
| 2098 | mBound = true; |
| 2099 | return true; |
| 2100 | } |
| 2101 | return false; |
| 2102 | } |
| 2103 | |
| 2104 | private void disconnectService() { |
| 2105 | mContainerService = null; |
| 2106 | mBound = false; |
| 2107 | mContext.unbindService(mDefContainerConn); |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | abstract class ObbAction { |
| 2112 | private static final int MAX_RETRIES = 3; |
| 2113 | private int mRetries; |
| 2114 | |
| 2115 | ObbState mObbState; |
| 2116 | |
| 2117 | ObbAction(ObbState obbState) { |
| 2118 | mObbState = obbState; |
| 2119 | } |
| 2120 | |
| 2121 | public void execute(ObbActionHandler handler) { |
| 2122 | try { |
| 2123 | if (DEBUG_OBB) |
| Ben Komalo | 444eca2 | 2011-09-01 15:17:44 -0700 | [diff] [blame^] | 2124 | Slog.i(TAG, "Starting to execute action: " + toString()); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2125 | mRetries++; |
| 2126 | if (mRetries > MAX_RETRIES) { |
| 2127 | Slog.w(TAG, "Failed to invoke remote methods on default container service. Giving up"); |
| Kenny Root | 480afe7 | 2010-10-07 10:17:50 -0700 | [diff] [blame] | 2128 | mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2129 | handleError(); |
| 2130 | return; |
| 2131 | } else { |
| 2132 | handleExecute(); |
| 2133 | if (DEBUG_OBB) |
| 2134 | Slog.i(TAG, "Posting install MCS_UNBIND"); |
| 2135 | mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND); |
| 2136 | } |
| 2137 | } catch (RemoteException e) { |
| 2138 | if (DEBUG_OBB) |
| 2139 | Slog.i(TAG, "Posting install MCS_RECONNECT"); |
| 2140 | mObbActionHandler.sendEmptyMessage(OBB_MCS_RECONNECT); |
| 2141 | } catch (Exception e) { |
| 2142 | if (DEBUG_OBB) |
| 2143 | Slog.d(TAG, "Error handling OBB action", e); |
| 2144 | handleError(); |
| Kenny Root | 17eb6fb | 2010-10-06 15:02:52 -0700 | [diff] [blame] | 2145 | mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | |
| Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 2149 | abstract void handleExecute() throws RemoteException, IOException; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2150 | abstract void handleError(); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2151 | |
| 2152 | protected ObbInfo getObbInfo() throws IOException { |
| 2153 | ObbInfo obbInfo; |
| 2154 | try { |
| 2155 | obbInfo = mContainerService.getObbInfo(mObbState.filename); |
| 2156 | } catch (RemoteException e) { |
| 2157 | Slog.d(TAG, "Couldn't call DefaultContainerService to fetch OBB info for " |
| 2158 | + mObbState.filename); |
| 2159 | obbInfo = null; |
| 2160 | } |
| 2161 | if (obbInfo == null) { |
| 2162 | throw new IOException("Couldn't read OBB file: " + mObbState.filename); |
| 2163 | } |
| 2164 | return obbInfo; |
| 2165 | } |
| 2166 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2167 | protected void sendNewStatusOrIgnore(int status) { |
| 2168 | if (mObbState == null || mObbState.token == null) { |
| 2169 | return; |
| 2170 | } |
| 2171 | |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2172 | try { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2173 | mObbState.token.onObbResult(mObbState.filename, mObbState.nonce, status); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2174 | } catch (RemoteException e) { |
| 2175 | Slog.w(TAG, "MountServiceListener went away while calling onObbStateChanged"); |
| 2176 | } |
| 2177 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | class MountObbAction extends ObbAction { |
| Ben Komalo | 444eca2 | 2011-09-01 15:17:44 -0700 | [diff] [blame^] | 2181 | private final String mKey; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2182 | |
| 2183 | MountObbAction(ObbState obbState, String key) { |
| 2184 | super(obbState); |
| 2185 | mKey = key; |
| 2186 | } |
| 2187 | |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 2188 | @Override |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 2189 | public void handleExecute() throws IOException, RemoteException { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2190 | waitForReady(); |
| 2191 | warnOnNotMounted(); |
| 2192 | |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2193 | final ObbInfo obbInfo = getObbInfo(); |
| 2194 | |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2195 | if (!isUidOwnerOfPackageOrSystem(obbInfo.packageName, mObbState.callerUid)) { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2196 | Slog.w(TAG, "Denied attempt to mount OBB " + obbInfo.filename |
| 2197 | + " which is owned by " + obbInfo.packageName); |
| 2198 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_PERMISSION_DENIED); |
| 2199 | return; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2202 | final boolean isMounted; |
| 2203 | synchronized (mObbMounts) { |
| 2204 | isMounted = mObbPathToStateMap.containsKey(obbInfo.filename); |
| 2205 | } |
| 2206 | if (isMounted) { |
| 2207 | Slog.w(TAG, "Attempt to mount OBB which is already mounted: " + obbInfo.filename); |
| 2208 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_ALREADY_MOUNTED); |
| 2209 | return; |
| 2210 | } |
| 2211 | |
| 2212 | /* |
| 2213 | * The filename passed in might not be the canonical name, so just |
| 2214 | * set the filename to the canonicalized version. |
| 2215 | */ |
| 2216 | mObbState.filename = obbInfo.filename; |
| 2217 | |
| 2218 | final String hashedKey; |
| 2219 | if (mKey == null) { |
| 2220 | hashedKey = "none"; |
| 2221 | } else { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2222 | try { |
| Kenny Root | 3b1abba | 2010-10-13 15:00:07 -0700 | [diff] [blame] | 2223 | SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); |
| 2224 | |
| 2225 | KeySpec ks = new PBEKeySpec(mKey.toCharArray(), obbInfo.salt, |
| 2226 | PBKDF2_HASH_ROUNDS, CRYPTO_ALGORITHM_KEY_SIZE); |
| 2227 | SecretKey key = factory.generateSecret(ks); |
| 2228 | BigInteger bi = new BigInteger(key.getEncoded()); |
| 2229 | hashedKey = bi.toString(16); |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2230 | } catch (NoSuchAlgorithmException e) { |
| Kenny Root | 3b1abba | 2010-10-13 15:00:07 -0700 | [diff] [blame] | 2231 | Slog.e(TAG, "Could not load PBKDF2 algorithm", e); |
| 2232 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL); |
| 2233 | return; |
| 2234 | } catch (InvalidKeySpecException e) { |
| 2235 | Slog.e(TAG, "Invalid key spec when loading PBKDF2 algorithm", e); |
| 2236 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2237 | return; |
| 2238 | } |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2239 | } |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2240 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2241 | int rc = StorageResultCode.OperationSucceeded; |
| 2242 | String cmd = String.format("obb mount %s %s %d", mObbState.filename, hashedKey, |
| 2243 | mObbState.callerUid); |
| 2244 | try { |
| 2245 | mConnector.doCommand(cmd); |
| 2246 | } catch (NativeDaemonConnectorException e) { |
| 2247 | int code = e.getCode(); |
| 2248 | if (code != VoldResponseCode.OpFailedStorageBusy) { |
| 2249 | rc = StorageResultCode.OperationFailedInternalError; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2253 | if (rc == StorageResultCode.OperationSucceeded) { |
| 2254 | if (DEBUG_OBB) |
| 2255 | Slog.d(TAG, "Successfully mounted OBB " + mObbState.filename); |
| 2256 | |
| 2257 | synchronized (mObbMounts) { |
| 2258 | addObbStateLocked(mObbState); |
| 2259 | } |
| 2260 | |
| 2261 | sendNewStatusOrIgnore(OnObbStateChangeListener.MOUNTED); |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 2262 | } else { |
| Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 2263 | Slog.e(TAG, "Couldn't mount OBB file: " + rc); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2264 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2265 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT); |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 2266 | } |
| 2267 | } |
| 2268 | |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 2269 | @Override |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2270 | public void handleError() { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2271 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL); |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 2272 | } |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2273 | |
| 2274 | @Override |
| 2275 | public String toString() { |
| 2276 | StringBuilder sb = new StringBuilder(); |
| 2277 | sb.append("MountObbAction{"); |
| 2278 | sb.append("filename="); |
| 2279 | sb.append(mObbState.filename); |
| 2280 | sb.append(",callerUid="); |
| 2281 | sb.append(mObbState.callerUid); |
| 2282 | sb.append(",token="); |
| 2283 | sb.append(mObbState.token != null ? mObbState.token.toString() : "NULL"); |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2284 | sb.append(",binder="); |
| 2285 | sb.append(mObbState.token != null ? mObbState.getBinder().toString() : "null"); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2286 | sb.append('}'); |
| 2287 | return sb.toString(); |
| 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | class UnmountObbAction extends ObbAction { |
| Ben Komalo | 444eca2 | 2011-09-01 15:17:44 -0700 | [diff] [blame^] | 2292 | private final boolean mForceUnmount; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2293 | |
| 2294 | UnmountObbAction(ObbState obbState, boolean force) { |
| 2295 | super(obbState); |
| 2296 | mForceUnmount = force; |
| 2297 | } |
| 2298 | |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 2299 | @Override |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2300 | public void handleExecute() throws IOException { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2301 | waitForReady(); |
| 2302 | warnOnNotMounted(); |
| 2303 | |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2304 | final ObbInfo obbInfo = getObbInfo(); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2305 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2306 | final ObbState obbState; |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2307 | synchronized (mObbMounts) { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2308 | obbState = mObbPathToStateMap.get(obbInfo.filename); |
| 2309 | } |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2310 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2311 | if (obbState == null) { |
| 2312 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_NOT_MOUNTED); |
| 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | if (obbState.callerUid != mObbState.callerUid) { |
| 2317 | Slog.w(TAG, "Permission denied attempting to unmount OBB " + obbInfo.filename |
| 2318 | + " (owned by " + obbInfo.packageName + ")"); |
| 2319 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_PERMISSION_DENIED); |
| 2320 | return; |
| 2321 | } |
| 2322 | |
| 2323 | mObbState.filename = obbInfo.filename; |
| 2324 | |
| 2325 | int rc = StorageResultCode.OperationSucceeded; |
| 2326 | String cmd = String.format("obb unmount %s%s", mObbState.filename, |
| 2327 | (mForceUnmount ? " force" : "")); |
| 2328 | try { |
| 2329 | mConnector.doCommand(cmd); |
| 2330 | } catch (NativeDaemonConnectorException e) { |
| 2331 | int code = e.getCode(); |
| 2332 | if (code == VoldResponseCode.OpFailedStorageBusy) { |
| 2333 | rc = StorageResultCode.OperationFailedStorageBusy; |
| 2334 | } else if (code == VoldResponseCode.OpFailedStorageNotFound) { |
| 2335 | // If it's not mounted then we've already won. |
| 2336 | rc = StorageResultCode.OperationSucceeded; |
| 2337 | } else { |
| 2338 | rc = StorageResultCode.OperationFailedInternalError; |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2342 | if (rc == StorageResultCode.OperationSucceeded) { |
| 2343 | synchronized (mObbMounts) { |
| 2344 | removeObbStateLocked(obbState); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2347 | sendNewStatusOrIgnore(OnObbStateChangeListener.UNMOUNTED); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2348 | } else { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2349 | Slog.w(TAG, "Could not mount OBB: " + mObbState.filename); |
| 2350 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_COULD_NOT_UNMOUNT); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
| Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 2354 | @Override |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2355 | public void handleError() { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2356 | sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | @Override |
| 2360 | public String toString() { |
| 2361 | StringBuilder sb = new StringBuilder(); |
| 2362 | sb.append("UnmountObbAction{"); |
| 2363 | sb.append("filename="); |
| 2364 | sb.append(mObbState.filename != null ? mObbState.filename : "null"); |
| 2365 | sb.append(",force="); |
| 2366 | sb.append(mForceUnmount); |
| 2367 | sb.append(",callerUid="); |
| 2368 | sb.append(mObbState.callerUid); |
| 2369 | sb.append(",token="); |
| 2370 | sb.append(mObbState.token != null ? mObbState.token.toString() : "null"); |
| Kenny Root | 735de3b | 2010-09-30 14:11:39 -0700 | [diff] [blame] | 2371 | sb.append(",binder="); |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2372 | sb.append(mObbState.token != null ? mObbState.getBinder().toString() : "null"); |
| Kenny Root | a02b8b0 | 2010-08-05 16:14:17 -0700 | [diff] [blame] | 2373 | sb.append('}'); |
| 2374 | return sb.toString(); |
| 2375 | } |
| Kenny Root | 02c8730 | 2010-07-01 08:10:18 -0700 | [diff] [blame] | 2376 | } |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2377 | |
| 2378 | @Override |
| 2379 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2380 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { |
| 2381 | pw.println("Permission Denial: can't dump ActivityManager from from pid=" |
| 2382 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() |
| 2383 | + " without permission " + android.Manifest.permission.DUMP); |
| 2384 | return; |
| 2385 | } |
| 2386 | |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2387 | synchronized (mObbMounts) { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2388 | pw.println(" mObbMounts:"); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2389 | |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2390 | final Iterator<Entry<IBinder, List<ObbState>>> binders = mObbMounts.entrySet().iterator(); |
| 2391 | while (binders.hasNext()) { |
| 2392 | Entry<IBinder, List<ObbState>> e = binders.next(); |
| 2393 | pw.print(" Key="); pw.println(e.getKey().toString()); |
| 2394 | final List<ObbState> obbStates = e.getValue(); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2395 | for (final ObbState obbState : obbStates) { |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2396 | pw.print(" "); pw.println(obbState.toString()); |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2397 | } |
| 2398 | } |
| Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 2399 | |
| 2400 | pw.println(""); |
| 2401 | pw.println(" mObbPathToStateMap:"); |
| 2402 | final Iterator<Entry<String, ObbState>> maps = mObbPathToStateMap.entrySet().iterator(); |
| 2403 | while (maps.hasNext()) { |
| 2404 | final Entry<String, ObbState> e = maps.next(); |
| 2405 | pw.print(" "); pw.print(e.getKey()); |
| 2406 | pw.print(" -> "); pw.println(e.getValue().toString()); |
| 2407 | } |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2408 | } |
| Kenny Root | 4161f9b | 2011-07-13 09:48:33 -0700 | [diff] [blame] | 2409 | |
| 2410 | pw.println(""); |
| 2411 | |
| 2412 | synchronized (mVolumes) { |
| 2413 | pw.println(" mVolumes:"); |
| 2414 | |
| 2415 | final int N = mVolumes.size(); |
| 2416 | for (int i = 0; i < N; i++) { |
| 2417 | final StorageVolume v = mVolumes.get(i); |
| 2418 | pw.print(" "); |
| 2419 | pw.println(v.toString()); |
| 2420 | } |
| 2421 | } |
| Kenny Root | 38cf886 | 2010-09-26 14:18:51 -0700 | [diff] [blame] | 2422 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | |
| Jeff Sharkey | fa23c5a | 2011-08-09 21:44:24 -0700 | [diff] [blame] | 2424 | /** {@inheritDoc} */ |
| 2425 | public void monitor() { |
| 2426 | if (mConnector != null) { |
| 2427 | mConnector.monitor(); |
| 2428 | } |
| 2429 | } |
| 2430 | } |