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