Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #define LOG_TAG "IMountService" |
| 18 | |
| 19 | #include <storage/IMountService.h> |
| 20 | #include <binder/Parcel.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | enum { |
| 25 | TRANSACTION_registerListener = IBinder::FIRST_CALL_TRANSACTION, |
| 26 | TRANSACTION_unregisterListener, |
| 27 | TRANSACTION_isUsbMassStorageConnected, |
| 28 | TRANSACTION_setUsbMassStorageEnabled, |
| 29 | TRANSACTION_isUsbMassStorageEnabled, |
| 30 | TRANSACTION_mountVolume, |
| 31 | TRANSACTION_unmountVolume, |
| 32 | TRANSACTION_formatVolume, |
| 33 | TRANSACTION_getStorageUsers, |
| 34 | TRANSACTION_getVolumeState, |
| 35 | TRANSACTION_createSecureContainer, |
| 36 | TRANSACTION_finalizeSecureContainer, |
| 37 | TRANSACTION_destroySecureContainer, |
| 38 | TRANSACTION_mountSecureContainer, |
| 39 | TRANSACTION_unmountSecureContainer, |
| 40 | TRANSACTION_isSecureContainerMounted, |
| 41 | TRANSACTION_renameSecureContainer, |
| 42 | TRANSACTION_getSecureContainerPath, |
| 43 | TRANSACTION_getSecureContainerList, |
| 44 | TRANSACTION_shutdown, |
| 45 | TRANSACTION_finishMediaUpdate, |
| 46 | TRANSACTION_mountObb, |
| 47 | TRANSACTION_unmountObb, |
| 48 | TRANSACTION_isObbMounted, |
| 49 | TRANSACTION_getMountedObbPath, |
Kenny Root | e1ff214 | 2010-10-12 11:20:01 -0700 | [diff] [blame] | 50 | TRANSACTION_isExternalStorageEmulated, |
Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 51 | TRANSACTION_decryptStorage, |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 52 | TRANSACTION_encryptStorage, |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | class BpMountService: public BpInterface<IMountService> |
| 56 | { |
| 57 | public: |
| 58 | BpMountService(const sp<IBinder>& impl) |
| 59 | : BpInterface<IMountService>(impl) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | virtual void registerListener(const sp<IMountServiceListener>& listener) |
| 64 | { |
| 65 | Parcel data, reply; |
| 66 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 67 | data.writeStrongBinder(listener->asBinder()); |
| 68 | if (remote()->transact(TRANSACTION_registerListener, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 69 | ALOGD("registerListener could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 70 | return; |
| 71 | } |
| 72 | int32_t err = reply.readExceptionCode(); |
| 73 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 74 | ALOGD("registerListener caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 75 | return; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | virtual void unregisterListener(const sp<IMountServiceListener>& listener) |
| 80 | { |
| 81 | Parcel data, reply; |
| 82 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 83 | data.writeStrongBinder(listener->asBinder()); |
| 84 | if (remote()->transact(TRANSACTION_unregisterListener, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 85 | ALOGD("unregisterListener could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 86 | return; |
| 87 | } |
| 88 | int32_t err = reply.readExceptionCode(); |
| 89 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 90 | ALOGD("unregisterListener caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | virtual bool isUsbMassStorageConnected() |
| 96 | { |
| 97 | Parcel data, reply; |
| 98 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 99 | if (remote()->transact(TRANSACTION_isUsbMassStorageConnected, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 100 | ALOGD("isUsbMassStorageConnected could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 101 | return false; |
| 102 | } |
| 103 | int32_t err = reply.readExceptionCode(); |
| 104 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 105 | ALOGD("isUsbMassStorageConnected caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | return reply.readInt32() != 0; |
| 109 | } |
| 110 | |
| 111 | virtual void setUsbMassStorageEnabled(const bool enable) |
| 112 | { |
| 113 | Parcel data, reply; |
| 114 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 115 | data.writeInt32(enable != 0); |
| 116 | if (remote()->transact(TRANSACTION_setUsbMassStorageEnabled, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 117 | ALOGD("setUsbMassStorageEnabled could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | int32_t err = reply.readExceptionCode(); |
| 121 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 122 | ALOGD("setUsbMassStorageEnabled caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 123 | return; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | virtual bool isUsbMassStorageEnabled() |
| 128 | { |
| 129 | Parcel data, reply; |
| 130 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 131 | if (remote()->transact(TRANSACTION_isUsbMassStorageEnabled, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 132 | ALOGD("isUsbMassStorageEnabled could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 133 | return false; |
| 134 | } |
| 135 | int32_t err = reply.readExceptionCode(); |
| 136 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 137 | ALOGD("isUsbMassStorageEnabled caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | return reply.readInt32() != 0; |
| 141 | } |
| 142 | |
| 143 | int32_t mountVolume(const String16& mountPoint) |
| 144 | { |
| 145 | Parcel data, reply; |
| 146 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 147 | data.writeString16(mountPoint); |
| 148 | if (remote()->transact(TRANSACTION_mountVolume, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 149 | ALOGD("mountVolume could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 150 | return -1; |
| 151 | } |
| 152 | int32_t err = reply.readExceptionCode(); |
| 153 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 154 | ALOGD("mountVolume caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 155 | return err; |
| 156 | } |
| 157 | return reply.readInt32(); |
| 158 | } |
| 159 | |
Ben Komalo | 13c7197 | 2011-09-07 16:35:56 -0700 | [diff] [blame] | 160 | int32_t unmountVolume(const String16& mountPoint, const bool force, const bool removeEncryption) |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 161 | { |
| 162 | Parcel data, reply; |
| 163 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 164 | data.writeString16(mountPoint); |
| 165 | data.writeInt32(force ? 1 : 0); |
Ben Komalo | 13c7197 | 2011-09-07 16:35:56 -0700 | [diff] [blame] | 166 | data.writeInt32(removeEncryption ? 1 : 0); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 167 | if (remote()->transact(TRANSACTION_unmountVolume, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 168 | ALOGD("unmountVolume could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 169 | return -1; |
| 170 | } |
| 171 | int32_t err = reply.readExceptionCode(); |
| 172 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 173 | ALOGD("unmountVolume caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 174 | return err; |
| 175 | } |
| 176 | return reply.readInt32(); |
| 177 | } |
| 178 | |
| 179 | int32_t formatVolume(const String16& mountPoint) |
| 180 | { |
| 181 | Parcel data, reply; |
| 182 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 183 | data.writeString16(mountPoint); |
| 184 | if (remote()->transact(TRANSACTION_formatVolume, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 185 | ALOGD("formatVolume could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 186 | return -1; |
| 187 | } |
| 188 | int32_t err = reply.readExceptionCode(); |
| 189 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 190 | ALOGD("formatVolume caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 191 | return err; |
| 192 | } |
| 193 | return reply.readInt32(); |
| 194 | } |
| 195 | |
| 196 | int32_t getStorageUsers(const String16& mountPoint, int32_t** users) |
| 197 | { |
| 198 | Parcel data, reply; |
| 199 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 200 | data.writeString16(mountPoint); |
| 201 | if (remote()->transact(TRANSACTION_getStorageUsers, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 202 | ALOGD("getStorageUsers could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 203 | return -1; |
| 204 | } |
| 205 | int32_t err = reply.readExceptionCode(); |
| 206 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 207 | ALOGD("getStorageUsers caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 208 | return err; |
| 209 | } |
| 210 | const int32_t numUsers = reply.readInt32(); |
| 211 | *users = (int32_t*)malloc(sizeof(int32_t)*numUsers); |
| 212 | for (int i = 0; i < numUsers; i++) { |
| 213 | **users++ = reply.readInt32(); |
| 214 | } |
| 215 | return numUsers; |
| 216 | } |
| 217 | |
| 218 | int32_t getVolumeState(const String16& mountPoint) |
| 219 | { |
| 220 | Parcel data, reply; |
| 221 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 222 | data.writeString16(mountPoint); |
| 223 | if (remote()->transact(TRANSACTION_getVolumeState, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 224 | ALOGD("getVolumeState could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 225 | return -1; |
| 226 | } |
| 227 | int32_t err = reply.readExceptionCode(); |
| 228 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 229 | ALOGD("getVolumeState caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 230 | return err; |
| 231 | } |
| 232 | return reply.readInt32(); |
| 233 | } |
| 234 | |
| 235 | int32_t createSecureContainer(const String16& id, const int32_t sizeMb, const String16& fstype, |
| 236 | const String16& key, const int32_t ownerUid) |
| 237 | { |
| 238 | Parcel data, reply; |
| 239 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 240 | data.writeString16(id); |
| 241 | data.writeInt32(sizeMb); |
| 242 | data.writeString16(fstype); |
| 243 | data.writeString16(key); |
| 244 | data.writeInt32(ownerUid); |
| 245 | if (remote()->transact(TRANSACTION_createSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 246 | ALOGD("createSecureContainer could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 247 | return -1; |
| 248 | } |
| 249 | int32_t err = reply.readExceptionCode(); |
| 250 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 251 | ALOGD("createSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 252 | return err; |
| 253 | } |
| 254 | return reply.readInt32(); |
| 255 | } |
| 256 | |
| 257 | int32_t finalizeSecureContainer(const String16& id) |
| 258 | { |
| 259 | Parcel data, reply; |
| 260 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 261 | data.writeString16(id); |
| 262 | if (remote()->transact(TRANSACTION_finalizeSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 263 | ALOGD("finalizeSecureContainer couldn't call remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 264 | return -1; |
| 265 | } |
| 266 | int32_t err = reply.readExceptionCode(); |
| 267 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 268 | ALOGD("finalizeSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 269 | return err; |
| 270 | } |
| 271 | return reply.readInt32(); |
| 272 | } |
| 273 | |
| 274 | int32_t destroySecureContainer(const String16& id) |
| 275 | { |
| 276 | Parcel data, reply; |
| 277 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 278 | data.writeString16(id); |
| 279 | if (remote()->transact(TRANSACTION_destroySecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 280 | ALOGD("destroySecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 281 | return -1; |
| 282 | } |
| 283 | int32_t err = reply.readExceptionCode(); |
| 284 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 285 | ALOGD("destroySecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 286 | return err; |
| 287 | } |
| 288 | return reply.readInt32(); |
| 289 | } |
| 290 | |
| 291 | int32_t mountSecureContainer(const String16& id, const String16& key, const int32_t ownerUid) |
| 292 | { |
| 293 | Parcel data, reply; |
| 294 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 295 | data.writeString16(id); |
| 296 | data.writeString16(key); |
| 297 | data.writeInt32(ownerUid); |
| 298 | if (remote()->transact(TRANSACTION_mountSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 299 | ALOGD("mountSecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 300 | return -1; |
| 301 | } |
| 302 | int32_t err = reply.readExceptionCode(); // What to do... |
| 303 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 304 | ALOGD("mountSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 305 | return err; |
| 306 | } |
| 307 | return reply.readInt32(); |
| 308 | } |
| 309 | |
| 310 | int32_t unmountSecureContainer(const String16& id, const bool force) |
| 311 | { |
| 312 | Parcel data, reply; |
| 313 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 314 | data.writeString16(id); |
| 315 | data.writeInt32(force ? 1 : 0); |
| 316 | if (remote()->transact(TRANSACTION_getSecureContainerPath, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 317 | ALOGD("unmountSecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 318 | return -1; |
| 319 | } |
| 320 | int32_t err = reply.readExceptionCode(); // What to do... |
| 321 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 322 | ALOGD("unmountSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 323 | return err; |
| 324 | } |
| 325 | return reply.readInt32(); |
| 326 | } |
| 327 | |
| 328 | bool isSecureContainerMounted(const String16& id) |
| 329 | { |
| 330 | Parcel data, reply; |
| 331 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 332 | data.writeString16(id); |
| 333 | if (remote()->transact(TRANSACTION_isSecureContainerMounted, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 334 | ALOGD("isSecureContainerMounted couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 335 | return false; |
| 336 | } |
| 337 | int32_t err = reply.readExceptionCode(); // What to do... |
| 338 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 339 | ALOGD("isSecureContainerMounted caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 340 | return false; |
| 341 | } |
| 342 | return reply.readInt32() != 0; |
| 343 | } |
| 344 | |
| 345 | int32_t renameSecureContainer(const String16& oldId, const String16& newId) |
| 346 | { |
| 347 | Parcel data, reply; |
| 348 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 349 | data.writeString16(oldId); |
| 350 | data.writeString16(newId); |
| 351 | if (remote()->transact(TRANSACTION_renameSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 352 | ALOGD("renameSecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 353 | return -1; |
| 354 | } |
| 355 | int32_t err = reply.readExceptionCode(); // What to do... |
| 356 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 357 | ALOGD("renameSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 358 | return err; |
| 359 | } |
| 360 | return reply.readInt32(); |
| 361 | } |
| 362 | |
| 363 | bool getSecureContainerPath(const String16& id, String16& path) |
| 364 | { |
| 365 | Parcel data, reply; |
| 366 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 367 | data.writeString16(id); |
| 368 | if (remote()->transact(TRANSACTION_getSecureContainerPath, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 369 | ALOGD("getSecureContainerPath couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 370 | return false; |
| 371 | } |
| 372 | int32_t err = reply.readExceptionCode(); // What to do... |
| 373 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 374 | ALOGD("getSecureContainerPath caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | path = reply.readString16(); |
| 378 | return true; |
| 379 | } |
| 380 | |
| 381 | int32_t getSecureContainerList(const String16& id, String16*& containers) |
| 382 | { |
| 383 | Parcel data, reply; |
| 384 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 385 | data.writeString16(id); |
| 386 | if (remote()->transact(TRANSACTION_getSecureContainerList, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 387 | ALOGD("getSecureContainerList couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 388 | return -1; |
| 389 | } |
| 390 | int32_t err = reply.readExceptionCode(); |
| 391 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 392 | ALOGD("getSecureContainerList caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 393 | return err; |
| 394 | } |
| 395 | const int32_t numStrings = reply.readInt32(); |
| 396 | containers = new String16[numStrings]; |
| 397 | for (int i = 0; i < numStrings; i++) { |
| 398 | containers[i] = reply.readString16(); |
| 399 | } |
| 400 | return numStrings; |
| 401 | } |
| 402 | |
| 403 | void shutdown(const sp<IMountShutdownObserver>& observer) |
| 404 | { |
| 405 | Parcel data, reply; |
| 406 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 407 | data.writeStrongBinder(observer->asBinder()); |
| 408 | if (remote()->transact(TRANSACTION_shutdown, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 409 | ALOGD("shutdown could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 410 | return; |
| 411 | } |
| 412 | int32_t err = reply.readExceptionCode(); |
| 413 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 414 | ALOGD("shutdown caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 415 | return; |
| 416 | } |
| 417 | reply.readExceptionCode(); |
| 418 | } |
| 419 | |
| 420 | void finishMediaUpdate() |
| 421 | { |
| 422 | Parcel data, reply; |
| 423 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 424 | if (remote()->transact(TRANSACTION_finishMediaUpdate, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 425 | ALOGD("finishMediaUpdate could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 426 | return; |
| 427 | } |
| 428 | int32_t err = reply.readExceptionCode(); |
| 429 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 430 | ALOGD("finishMediaUpdate caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | reply.readExceptionCode(); |
| 434 | } |
| 435 | |
Kenny Root | 05105f7 | 2010-09-22 17:29:43 -0700 | [diff] [blame] | 436 | void mountObb(const String16& filename, const String16& key, |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 437 | const sp<IObbActionListener>& token, int32_t nonce) |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 438 | { |
| 439 | Parcel data, reply; |
| 440 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 441 | data.writeString16(filename); |
| 442 | data.writeString16(key); |
| 443 | data.writeStrongBinder(token->asBinder()); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 444 | data.writeInt32(nonce); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 445 | if (remote()->transact(TRANSACTION_mountObb, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 446 | ALOGD("mountObb could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 447 | return; |
| 448 | } |
| 449 | int32_t err = reply.readExceptionCode(); |
| 450 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 451 | ALOGD("mountObb caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 452 | return; |
| 453 | } |
| 454 | } |
| 455 | |
Kenny Root | 4a99ed8 | 2010-10-11 17:38:51 -0700 | [diff] [blame] | 456 | void unmountObb(const String16& filename, const bool force, |
| 457 | const sp<IObbActionListener>& token, const int32_t nonce) |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 458 | { |
| 459 | Parcel data, reply; |
| 460 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 461 | data.writeString16(filename); |
| 462 | data.writeInt32(force ? 1 : 0); |
Kenny Root | 4a99ed8 | 2010-10-11 17:38:51 -0700 | [diff] [blame] | 463 | data.writeStrongBinder(token->asBinder()); |
| 464 | data.writeInt32(nonce); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 465 | if (remote()->transact(TRANSACTION_unmountObb, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 466 | ALOGD("unmountObb could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 467 | return; |
| 468 | } |
| 469 | int32_t err = reply.readExceptionCode(); |
| 470 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 471 | ALOGD("unmountObb caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | bool isObbMounted(const String16& filename) |
| 477 | { |
| 478 | Parcel data, reply; |
| 479 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 480 | data.writeString16(filename); |
| 481 | if (remote()->transact(TRANSACTION_isObbMounted, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 482 | ALOGD("isObbMounted could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 483 | return false; |
| 484 | } |
| 485 | int32_t err = reply.readExceptionCode(); |
| 486 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 487 | ALOGD("isObbMounted caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 488 | return false; |
| 489 | } |
| 490 | return reply.readInt32() != 0; |
| 491 | } |
| 492 | |
| 493 | bool getMountedObbPath(const String16& filename, String16& path) |
| 494 | { |
| 495 | Parcel data, reply; |
| 496 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 497 | data.writeString16(filename); |
| 498 | if (remote()->transact(TRANSACTION_getMountedObbPath, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 499 | ALOGD("getMountedObbPath could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 500 | return false; |
| 501 | } |
| 502 | int32_t err = reply.readExceptionCode(); |
| 503 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 504 | ALOGD("getMountedObbPath caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 505 | return false; |
| 506 | } |
| 507 | path = reply.readString16(); |
| 508 | return true; |
| 509 | } |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 510 | |
Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 511 | int32_t decryptStorage(const String16& password) |
| 512 | { |
| 513 | Parcel data, reply; |
| 514 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 515 | data.writeString16(password); |
| 516 | if (remote()->transact(TRANSACTION_decryptStorage, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 517 | ALOGD("decryptStorage could not contact remote\n"); |
Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 518 | return -1; |
| 519 | } |
| 520 | int32_t err = reply.readExceptionCode(); |
| 521 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 522 | ALOGD("decryptStorage caught exception %d\n", err); |
Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 523 | return err; |
| 524 | } |
| 525 | return reply.readInt32(); |
| 526 | } |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 527 | |
| 528 | int32_t encryptStorage(const String16& password) |
| 529 | { |
| 530 | Parcel data, reply; |
| 531 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 532 | data.writeString16(password); |
| 533 | if (remote()->transact(TRANSACTION_encryptStorage, data, &reply) != NO_ERROR) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 534 | ALOGD("encryptStorage could not contact remote\n"); |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 535 | return -1; |
| 536 | } |
| 537 | int32_t err = reply.readExceptionCode(); |
| 538 | if (err < 0) { |
Steve Block | 1afd5ba | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 539 | ALOGD("encryptStorage caught exception %d\n", err); |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 540 | return err; |
| 541 | } |
| 542 | return reply.readInt32(); |
| 543 | } |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 544 | }; |
| 545 | |
| 546 | IMPLEMENT_META_INTERFACE(MountService, "IMountService"); |
| 547 | |
| 548 | // ---------------------------------------------------------------------- |
| 549 | |
| 550 | }; |