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