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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | 5baa3a6 | 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 | } |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame^] | 210 | int32_t numUsersI = reply.readInt32(); |
| 211 | uint32_t numUsers; |
| 212 | if (numUsersI < 0) { |
| 213 | ALOGW("Number of users is negative: %d\n", numUsersI); |
| 214 | numUsers = 0; |
| 215 | } else { |
| 216 | numUsers = static_cast<uint32_t>(numUsersI); |
| 217 | } |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 218 | *users = (int32_t*)malloc(sizeof(int32_t)*numUsers); |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame^] | 219 | for (size_t i = 0; i < numUsers; i++) { |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 220 | **users++ = reply.readInt32(); |
| 221 | } |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame^] | 222 | return static_cast<int32_t>(numUsers); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | int32_t getVolumeState(const String16& mountPoint) |
| 226 | { |
| 227 | Parcel data, reply; |
| 228 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 229 | data.writeString16(mountPoint); |
| 230 | if (remote()->transact(TRANSACTION_getVolumeState, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 231 | ALOGD("getVolumeState could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 232 | return -1; |
| 233 | } |
| 234 | int32_t err = reply.readExceptionCode(); |
| 235 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 236 | ALOGD("getVolumeState caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 237 | return err; |
| 238 | } |
| 239 | return reply.readInt32(); |
| 240 | } |
| 241 | |
| 242 | int32_t createSecureContainer(const String16& id, const int32_t sizeMb, const String16& fstype, |
| 243 | const String16& key, const int32_t ownerUid) |
| 244 | { |
| 245 | Parcel data, reply; |
| 246 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 247 | data.writeString16(id); |
| 248 | data.writeInt32(sizeMb); |
| 249 | data.writeString16(fstype); |
| 250 | data.writeString16(key); |
| 251 | data.writeInt32(ownerUid); |
| 252 | if (remote()->transact(TRANSACTION_createSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 253 | ALOGD("createSecureContainer could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 254 | return -1; |
| 255 | } |
| 256 | int32_t err = reply.readExceptionCode(); |
| 257 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 258 | ALOGD("createSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 259 | return err; |
| 260 | } |
| 261 | return reply.readInt32(); |
| 262 | } |
| 263 | |
| 264 | int32_t finalizeSecureContainer(const String16& id) |
| 265 | { |
| 266 | Parcel data, reply; |
| 267 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 268 | data.writeString16(id); |
| 269 | if (remote()->transact(TRANSACTION_finalizeSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 270 | ALOGD("finalizeSecureContainer couldn't call remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 271 | return -1; |
| 272 | } |
| 273 | int32_t err = reply.readExceptionCode(); |
| 274 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 275 | ALOGD("finalizeSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 276 | return err; |
| 277 | } |
| 278 | return reply.readInt32(); |
| 279 | } |
| 280 | |
| 281 | int32_t destroySecureContainer(const String16& id) |
| 282 | { |
| 283 | Parcel data, reply; |
| 284 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 285 | data.writeString16(id); |
| 286 | if (remote()->transact(TRANSACTION_destroySecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 287 | ALOGD("destroySecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 288 | return -1; |
| 289 | } |
| 290 | int32_t err = reply.readExceptionCode(); |
| 291 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 292 | ALOGD("destroySecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 293 | return err; |
| 294 | } |
| 295 | return reply.readInt32(); |
| 296 | } |
| 297 | |
| 298 | int32_t mountSecureContainer(const String16& id, const String16& key, const int32_t ownerUid) |
| 299 | { |
| 300 | Parcel data, reply; |
| 301 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 302 | data.writeString16(id); |
| 303 | data.writeString16(key); |
| 304 | data.writeInt32(ownerUid); |
| 305 | if (remote()->transact(TRANSACTION_mountSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 306 | ALOGD("mountSecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 307 | return -1; |
| 308 | } |
| 309 | int32_t err = reply.readExceptionCode(); // What to do... |
| 310 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 311 | ALOGD("mountSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 312 | return err; |
| 313 | } |
| 314 | return reply.readInt32(); |
| 315 | } |
| 316 | |
| 317 | int32_t unmountSecureContainer(const String16& id, const bool force) |
| 318 | { |
| 319 | Parcel data, reply; |
| 320 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 321 | data.writeString16(id); |
| 322 | data.writeInt32(force ? 1 : 0); |
| 323 | if (remote()->transact(TRANSACTION_getSecureContainerPath, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 324 | ALOGD("unmountSecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 325 | return -1; |
| 326 | } |
| 327 | int32_t err = reply.readExceptionCode(); // What to do... |
| 328 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 329 | ALOGD("unmountSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 330 | return err; |
| 331 | } |
| 332 | return reply.readInt32(); |
| 333 | } |
| 334 | |
| 335 | bool isSecureContainerMounted(const String16& id) |
| 336 | { |
| 337 | Parcel data, reply; |
| 338 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 339 | data.writeString16(id); |
| 340 | if (remote()->transact(TRANSACTION_isSecureContainerMounted, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 341 | ALOGD("isSecureContainerMounted couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 342 | return false; |
| 343 | } |
| 344 | int32_t err = reply.readExceptionCode(); // What to do... |
| 345 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 346 | ALOGD("isSecureContainerMounted caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 347 | return false; |
| 348 | } |
| 349 | return reply.readInt32() != 0; |
| 350 | } |
| 351 | |
| 352 | int32_t renameSecureContainer(const String16& oldId, const String16& newId) |
| 353 | { |
| 354 | Parcel data, reply; |
| 355 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 356 | data.writeString16(oldId); |
| 357 | data.writeString16(newId); |
| 358 | if (remote()->transact(TRANSACTION_renameSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 359 | ALOGD("renameSecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 360 | return -1; |
| 361 | } |
| 362 | int32_t err = reply.readExceptionCode(); // What to do... |
| 363 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 364 | ALOGD("renameSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 365 | return err; |
| 366 | } |
| 367 | return reply.readInt32(); |
| 368 | } |
| 369 | |
| 370 | bool getSecureContainerPath(const String16& id, String16& path) |
| 371 | { |
| 372 | Parcel data, reply; |
| 373 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 374 | data.writeString16(id); |
| 375 | if (remote()->transact(TRANSACTION_getSecureContainerPath, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 376 | ALOGD("getSecureContainerPath couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 377 | return false; |
| 378 | } |
| 379 | int32_t err = reply.readExceptionCode(); // What to do... |
| 380 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 381 | ALOGD("getSecureContainerPath caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 382 | return false; |
| 383 | } |
| 384 | path = reply.readString16(); |
| 385 | return true; |
| 386 | } |
| 387 | |
| 388 | int32_t getSecureContainerList(const String16& id, String16*& containers) |
| 389 | { |
| 390 | Parcel data, reply; |
| 391 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 392 | data.writeString16(id); |
| 393 | if (remote()->transact(TRANSACTION_getSecureContainerList, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 394 | ALOGD("getSecureContainerList couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 395 | return -1; |
| 396 | } |
| 397 | int32_t err = reply.readExceptionCode(); |
| 398 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 399 | ALOGD("getSecureContainerList caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 400 | return err; |
| 401 | } |
| 402 | const int32_t numStrings = reply.readInt32(); |
| 403 | containers = new String16[numStrings]; |
| 404 | for (int i = 0; i < numStrings; i++) { |
| 405 | containers[i] = reply.readString16(); |
| 406 | } |
| 407 | return numStrings; |
| 408 | } |
| 409 | |
| 410 | void shutdown(const sp<IMountShutdownObserver>& observer) |
| 411 | { |
| 412 | Parcel data, reply; |
| 413 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 414 | data.writeStrongBinder(observer->asBinder()); |
| 415 | if (remote()->transact(TRANSACTION_shutdown, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 416 | ALOGD("shutdown could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 417 | return; |
| 418 | } |
| 419 | int32_t err = reply.readExceptionCode(); |
| 420 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 421 | ALOGD("shutdown caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 422 | return; |
| 423 | } |
| 424 | reply.readExceptionCode(); |
| 425 | } |
| 426 | |
| 427 | void finishMediaUpdate() |
| 428 | { |
| 429 | Parcel data, reply; |
| 430 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 431 | if (remote()->transact(TRANSACTION_finishMediaUpdate, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 432 | ALOGD("finishMediaUpdate could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 433 | return; |
| 434 | } |
| 435 | int32_t err = reply.readExceptionCode(); |
| 436 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 437 | ALOGD("finishMediaUpdate caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 438 | return; |
| 439 | } |
| 440 | reply.readExceptionCode(); |
| 441 | } |
| 442 | |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 443 | void mountObb(const String16& rawPath, const String16& canonicalPath, const String16& key, |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 444 | const sp<IObbActionListener>& token, int32_t nonce) |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 445 | { |
| 446 | Parcel data, reply; |
| 447 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
Jeff Sharkey | 4fbbda4 | 2012-09-24 18:34:07 -0700 | [diff] [blame] | 448 | data.writeString16(rawPath); |
| 449 | data.writeString16(canonicalPath); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 450 | data.writeString16(key); |
| 451 | data.writeStrongBinder(token->asBinder()); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 452 | data.writeInt32(nonce); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 453 | if (remote()->transact(TRANSACTION_mountObb, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 454 | ALOGD("mountObb could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 455 | return; |
| 456 | } |
| 457 | int32_t err = reply.readExceptionCode(); |
| 458 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 459 | ALOGD("mountObb caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 460 | return; |
| 461 | } |
| 462 | } |
| 463 | |
Kenny Root | 4a99ed8 | 2010-10-11 17:38:51 -0700 | [diff] [blame] | 464 | void unmountObb(const String16& filename, const bool force, |
| 465 | const sp<IObbActionListener>& token, const int32_t nonce) |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 466 | { |
| 467 | Parcel data, reply; |
| 468 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 469 | data.writeString16(filename); |
| 470 | data.writeInt32(force ? 1 : 0); |
Kenny Root | 4a99ed8 | 2010-10-11 17:38:51 -0700 | [diff] [blame] | 471 | data.writeStrongBinder(token->asBinder()); |
| 472 | data.writeInt32(nonce); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 473 | if (remote()->transact(TRANSACTION_unmountObb, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 474 | ALOGD("unmountObb could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 475 | return; |
| 476 | } |
| 477 | int32_t err = reply.readExceptionCode(); |
| 478 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 479 | ALOGD("unmountObb caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | bool isObbMounted(const String16& filename) |
| 485 | { |
| 486 | Parcel data, reply; |
| 487 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 488 | data.writeString16(filename); |
| 489 | if (remote()->transact(TRANSACTION_isObbMounted, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 490 | ALOGD("isObbMounted could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 491 | return false; |
| 492 | } |
| 493 | int32_t err = reply.readExceptionCode(); |
| 494 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 495 | ALOGD("isObbMounted caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 496 | return false; |
| 497 | } |
| 498 | return reply.readInt32() != 0; |
| 499 | } |
| 500 | |
| 501 | bool getMountedObbPath(const String16& filename, String16& path) |
| 502 | { |
| 503 | Parcel data, reply; |
| 504 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 505 | data.writeString16(filename); |
| 506 | if (remote()->transact(TRANSACTION_getMountedObbPath, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 507 | ALOGD("getMountedObbPath could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 508 | return false; |
| 509 | } |
| 510 | int32_t err = reply.readExceptionCode(); |
| 511 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 512 | ALOGD("getMountedObbPath caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 513 | return false; |
| 514 | } |
| 515 | path = reply.readString16(); |
| 516 | return true; |
| 517 | } |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 518 | |
Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 519 | int32_t decryptStorage(const String16& password) |
| 520 | { |
| 521 | Parcel data, reply; |
| 522 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 523 | data.writeString16(password); |
| 524 | if (remote()->transact(TRANSACTION_decryptStorage, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 525 | ALOGD("decryptStorage could not contact remote\n"); |
Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 526 | return -1; |
| 527 | } |
| 528 | int32_t err = reply.readExceptionCode(); |
| 529 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 530 | ALOGD("decryptStorage caught exception %d\n", err); |
Jason parks | 5af0b91 | 2010-11-29 09:05:25 -0600 | [diff] [blame] | 531 | return err; |
| 532 | } |
| 533 | return reply.readInt32(); |
| 534 | } |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 535 | |
| 536 | int32_t encryptStorage(const String16& password) |
| 537 | { |
| 538 | Parcel data, reply; |
| 539 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 540 | data.writeString16(password); |
| 541 | if (remote()->transact(TRANSACTION_encryptStorage, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 542 | ALOGD("encryptStorage could not contact remote\n"); |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 543 | return -1; |
| 544 | } |
| 545 | int32_t err = reply.readExceptionCode(); |
| 546 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 547 | ALOGD("encryptStorage caught exception %d\n", err); |
Jason parks | d633255 | 2011-01-07 09:01:15 -0600 | [diff] [blame] | 548 | return err; |
| 549 | } |
| 550 | return reply.readInt32(); |
| 551 | } |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 552 | }; |
| 553 | |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame^] | 554 | IMPLEMENT_META_INTERFACE(MountService, "IMountService") |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 555 | |
| 556 | // ---------------------------------------------------------------------- |
| 557 | |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame^] | 558 | } |