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