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, |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | class BpMountService: public BpInterface<IMountService> |
| 54 | { |
| 55 | public: |
Chih-Hung Hsieh | c6baf56 | 2016-04-27 11:29:23 -0700 | [diff] [blame] | 56 | explicit BpMountService(const sp<IBinder>& impl) |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 57 | : BpInterface<IMountService>(impl) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | virtual void registerListener(const sp<IMountServiceListener>& listener) |
| 62 | { |
| 63 | Parcel data, reply; |
| 64 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
Marco Nelissen | dce9740 | 2014-11-14 08:00:42 -0800 | [diff] [blame] | 65 | data.writeStrongBinder(IInterface::asBinder(listener)); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 66 | if (remote()->transact(TRANSACTION_registerListener, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 67 | ALOGD("registerListener could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 68 | return; |
| 69 | } |
| 70 | int32_t err = reply.readExceptionCode(); |
| 71 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 72 | ALOGD("registerListener caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | virtual void unregisterListener(const sp<IMountServiceListener>& listener) |
| 78 | { |
| 79 | Parcel data, reply; |
| 80 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
Marco Nelissen | dce9740 | 2014-11-14 08:00:42 -0800 | [diff] [blame] | 81 | data.writeStrongBinder(IInterface::asBinder(listener)); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 82 | if (remote()->transact(TRANSACTION_unregisterListener, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 83 | ALOGD("unregisterListener could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | int32_t err = reply.readExceptionCode(); |
| 87 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 88 | ALOGD("unregisterListener caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 89 | return; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | virtual bool isUsbMassStorageConnected() |
| 94 | { |
| 95 | Parcel data, reply; |
| 96 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 97 | if (remote()->transact(TRANSACTION_isUsbMassStorageConnected, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 98 | ALOGD("isUsbMassStorageConnected could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 99 | return false; |
| 100 | } |
| 101 | int32_t err = reply.readExceptionCode(); |
| 102 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 103 | ALOGD("isUsbMassStorageConnected caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | return reply.readInt32() != 0; |
| 107 | } |
| 108 | |
| 109 | virtual void setUsbMassStorageEnabled(const bool enable) |
| 110 | { |
| 111 | Parcel data, reply; |
| 112 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 113 | data.writeInt32(enable != 0); |
| 114 | if (remote()->transact(TRANSACTION_setUsbMassStorageEnabled, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 115 | ALOGD("setUsbMassStorageEnabled could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | int32_t err = reply.readExceptionCode(); |
| 119 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 120 | ALOGD("setUsbMassStorageEnabled caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 121 | return; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | virtual bool isUsbMassStorageEnabled() |
| 126 | { |
| 127 | Parcel data, reply; |
| 128 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 129 | if (remote()->transact(TRANSACTION_isUsbMassStorageEnabled, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 130 | ALOGD("isUsbMassStorageEnabled could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 131 | return false; |
| 132 | } |
| 133 | int32_t err = reply.readExceptionCode(); |
| 134 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 135 | ALOGD("isUsbMassStorageEnabled caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 136 | return false; |
| 137 | } |
| 138 | return reply.readInt32() != 0; |
| 139 | } |
| 140 | |
| 141 | int32_t mountVolume(const String16& mountPoint) |
| 142 | { |
| 143 | Parcel data, reply; |
| 144 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 145 | data.writeString16(mountPoint); |
| 146 | if (remote()->transact(TRANSACTION_mountVolume, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 147 | ALOGD("mountVolume could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 148 | return -1; |
| 149 | } |
| 150 | int32_t err = reply.readExceptionCode(); |
| 151 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 152 | ALOGD("mountVolume caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 153 | return err; |
| 154 | } |
| 155 | return reply.readInt32(); |
| 156 | } |
| 157 | |
Ben Komalo | 13c7197 | 2011-09-07 16:35:56 -0700 | [diff] [blame] | 158 | int32_t unmountVolume(const String16& mountPoint, const bool force, const bool removeEncryption) |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 159 | { |
| 160 | Parcel data, reply; |
| 161 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 162 | data.writeString16(mountPoint); |
| 163 | data.writeInt32(force ? 1 : 0); |
Ben Komalo | 13c7197 | 2011-09-07 16:35:56 -0700 | [diff] [blame] | 164 | data.writeInt32(removeEncryption ? 1 : 0); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 165 | if (remote()->transact(TRANSACTION_unmountVolume, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 166 | ALOGD("unmountVolume could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 167 | return -1; |
| 168 | } |
| 169 | int32_t err = reply.readExceptionCode(); |
| 170 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 171 | ALOGD("unmountVolume caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 172 | return err; |
| 173 | } |
| 174 | return reply.readInt32(); |
| 175 | } |
| 176 | |
| 177 | int32_t formatVolume(const String16& mountPoint) |
| 178 | { |
| 179 | Parcel data, reply; |
| 180 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 181 | data.writeString16(mountPoint); |
| 182 | if (remote()->transact(TRANSACTION_formatVolume, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 183 | ALOGD("formatVolume could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 184 | return -1; |
| 185 | } |
| 186 | int32_t err = reply.readExceptionCode(); |
| 187 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 188 | ALOGD("formatVolume caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 189 | return err; |
| 190 | } |
| 191 | return reply.readInt32(); |
| 192 | } |
| 193 | |
| 194 | int32_t getStorageUsers(const String16& mountPoint, int32_t** users) |
| 195 | { |
| 196 | Parcel data, reply; |
| 197 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 198 | data.writeString16(mountPoint); |
| 199 | if (remote()->transact(TRANSACTION_getStorageUsers, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 200 | ALOGD("getStorageUsers could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 201 | return -1; |
| 202 | } |
| 203 | int32_t err = reply.readExceptionCode(); |
| 204 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 205 | ALOGD("getStorageUsers caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 206 | return err; |
| 207 | } |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame] | 208 | int32_t numUsersI = reply.readInt32(); |
| 209 | uint32_t numUsers; |
| 210 | if (numUsersI < 0) { |
| 211 | ALOGW("Number of users is negative: %d\n", numUsersI); |
| 212 | numUsers = 0; |
| 213 | } else { |
| 214 | numUsers = static_cast<uint32_t>(numUsersI); |
| 215 | } |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 216 | *users = (int32_t*)malloc(sizeof(int32_t)*numUsers); |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame] | 217 | for (size_t i = 0; i < numUsers; i++) { |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 218 | **users++ = reply.readInt32(); |
| 219 | } |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame] | 220 | return static_cast<int32_t>(numUsers); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | int32_t getVolumeState(const String16& mountPoint) |
| 224 | { |
| 225 | Parcel data, reply; |
| 226 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 227 | data.writeString16(mountPoint); |
| 228 | if (remote()->transact(TRANSACTION_getVolumeState, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 229 | ALOGD("getVolumeState could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 230 | return -1; |
| 231 | } |
| 232 | int32_t err = reply.readExceptionCode(); |
| 233 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 234 | ALOGD("getVolumeState caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 235 | return err; |
| 236 | } |
| 237 | return reply.readInt32(); |
| 238 | } |
| 239 | |
| 240 | int32_t createSecureContainer(const String16& id, const int32_t sizeMb, const String16& fstype, |
| 241 | const String16& key, const int32_t ownerUid) |
| 242 | { |
| 243 | Parcel data, reply; |
| 244 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 245 | data.writeString16(id); |
| 246 | data.writeInt32(sizeMb); |
| 247 | data.writeString16(fstype); |
| 248 | data.writeString16(key); |
| 249 | data.writeInt32(ownerUid); |
| 250 | if (remote()->transact(TRANSACTION_createSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 251 | ALOGD("createSecureContainer could not contact remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 252 | return -1; |
| 253 | } |
| 254 | int32_t err = reply.readExceptionCode(); |
| 255 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 256 | ALOGD("createSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 257 | return err; |
| 258 | } |
| 259 | return reply.readInt32(); |
| 260 | } |
| 261 | |
| 262 | int32_t finalizeSecureContainer(const String16& id) |
| 263 | { |
| 264 | Parcel data, reply; |
| 265 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 266 | data.writeString16(id); |
| 267 | if (remote()->transact(TRANSACTION_finalizeSecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 268 | ALOGD("finalizeSecureContainer couldn't call remote\n"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 269 | return -1; |
| 270 | } |
| 271 | int32_t err = reply.readExceptionCode(); |
| 272 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 273 | ALOGD("finalizeSecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 274 | return err; |
| 275 | } |
| 276 | return reply.readInt32(); |
| 277 | } |
| 278 | |
| 279 | int32_t destroySecureContainer(const String16& id) |
| 280 | { |
| 281 | Parcel data, reply; |
| 282 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 283 | data.writeString16(id); |
| 284 | if (remote()->transact(TRANSACTION_destroySecureContainer, data, &reply) != NO_ERROR) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 285 | ALOGD("destroySecureContainer couldn't call remote"); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 286 | return -1; |
| 287 | } |
| 288 | int32_t err = reply.readExceptionCode(); |
| 289 | if (err < 0) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 290 | ALOGD("destroySecureContainer caught exception %d\n", err); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 291 | return err; |
| 292 | } |
| 293 | return reply.readInt32(); |
| 294 | } |
| 295 | |
| 296 | int32_t mountSecureContainer(const String16& id, const String16& key, const int32_t ownerUid) |
| 297 | { |
| 298 | Parcel data, reply; |
| 299 | data.writeInterfaceToken(IMountService::getInterfaceDescriptor()); |
| 300 | data.writeString16(id); |
| 301 | data.writeString16(key); |
| 302 | data.writeInt32(ownerUid); |
Jeff Sharkey | 941a8ba | 2014-08-20 16:26:32 -0700 | [diff] [blame] | 303 | // Assume read-only |
| 304 | data.writeInt32(1); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 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()); |
Marco Nelissen | dce9740 | 2014-11-14 08:00:42 -0800 | [diff] [blame] | 414 | data.writeStrongBinder(IInterface::asBinder(observer)); |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 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 | |
Eric Biggers | 8bc9340b | 2022-03-01 21:19:10 +0000 | [diff] [blame] | 443 | void mountObb(const String16& rawPath, const String16& canonicalPath, |
Sudheer Shanka | 25469aa | 2018-08-27 15:50:23 -0700 | [diff] [blame] | 444 | const sp<IObbActionListener>& token, int32_t nonce, const sp<ObbInfo>& obbInfo) |
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); |
Marco Nelissen | dce9740 | 2014-11-14 08:00:42 -0800 | [diff] [blame] | 450 | data.writeStrongBinder(IInterface::asBinder(token)); |
Kenny Root | af9d667 | 2010-10-08 09:21:39 -0700 | [diff] [blame] | 451 | data.writeInt32(nonce); |
Sudheer Shanka | 25469aa | 2018-08-27 15:50:23 -0700 | [diff] [blame] | 452 | obbInfo->writeToParcel(&data); |
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); |
Marco Nelissen | dce9740 | 2014-11-14 08:00:42 -0800 | [diff] [blame] | 471 | data.writeStrongBinder(IInterface::asBinder(token)); |
Kenny Root | 4a99ed8 | 2010-10-11 17:38:51 -0700 | [diff] [blame] | 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 | } |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 518 | }; |
| 519 | |
Sudheer Shanka | 2250d56 | 2016-11-07 15:41:02 -0800 | [diff] [blame] | 520 | IMPLEMENT_META_INTERFACE(MountService, "android.os.storage.IStorageManager") |
Kenny Root | be857d4 | 2010-08-18 15:59:25 -0700 | [diff] [blame] | 521 | |
| 522 | // ---------------------------------------------------------------------- |
| 523 | |
Andreas Gampe | 2b3a8cd | 2014-10-21 23:38:52 -0700 | [diff] [blame] | 524 | } |