IMountService.java revision 13c7197da8a16f77f6398708a6314c80cb01e0d1
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
17package android.os.storage;
18
19import android.os.Binder;
20import android.os.IBinder;
21import android.os.IInterface;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.os.RemoteException;
25import android.os.storage.StorageVolume;
26
27/**
28 * WARNING! Update IMountService.h and IMountService.cpp if you change this
29 * file. In particular, the ordering of the methods below must match the
30 * _TRANSACTION enum in IMountService.cpp
31 *
32 * @hide - Applications should use android.os.storage.StorageManager to access
33 *       storage functions.
34 */
35public interface IMountService extends IInterface {
36    /** Local-side IPC implementation stub class. */
37    public static abstract class Stub extends Binder implements IMountService {
38        private static class Proxy implements IMountService {
39            private final IBinder mRemote;
40
41            Proxy(IBinder remote) {
42                mRemote = remote;
43            }
44
45            public IBinder asBinder() {
46                return mRemote;
47            }
48
49            public String getInterfaceDescriptor() {
50                return DESCRIPTOR;
51            }
52
53            /**
54             * Registers an IMountServiceListener for receiving async
55             * notifications.
56             */
57            public void registerListener(IMountServiceListener listener) throws RemoteException {
58                Parcel _data = Parcel.obtain();
59                Parcel _reply = Parcel.obtain();
60                try {
61                    _data.writeInterfaceToken(DESCRIPTOR);
62                    _data.writeStrongBinder((listener != null ? listener.asBinder() : null));
63                    mRemote.transact(Stub.TRANSACTION_registerListener, _data, _reply, 0);
64                    _reply.readException();
65                } finally {
66                    _reply.recycle();
67                    _data.recycle();
68                }
69            }
70
71            /**
72             * Unregisters an IMountServiceListener
73             */
74            public void unregisterListener(IMountServiceListener listener) throws RemoteException {
75                Parcel _data = Parcel.obtain();
76                Parcel _reply = Parcel.obtain();
77                try {
78                    _data.writeInterfaceToken(DESCRIPTOR);
79                    _data.writeStrongBinder((listener != null ? listener.asBinder() : null));
80                    mRemote.transact(Stub.TRANSACTION_unregisterListener, _data, _reply, 0);
81                    _reply.readException();
82                } finally {
83                    _reply.recycle();
84                    _data.recycle();
85                }
86            }
87
88            /**
89             * Returns true if a USB mass storage host is connected
90             */
91            public boolean isUsbMassStorageConnected() throws RemoteException {
92                Parcel _data = Parcel.obtain();
93                Parcel _reply = Parcel.obtain();
94                boolean _result;
95                try {
96                    _data.writeInterfaceToken(DESCRIPTOR);
97                    mRemote.transact(Stub.TRANSACTION_isUsbMassStorageConnected, _data, _reply, 0);
98                    _reply.readException();
99                    _result = 0 != _reply.readInt();
100                } finally {
101                    _reply.recycle();
102                    _data.recycle();
103                }
104                return _result;
105            }
106
107            /**
108             * Enables / disables USB mass storage. The caller should check
109             * actual status of enabling/disabling USB mass storage via
110             * StorageEventListener.
111             */
112            public void setUsbMassStorageEnabled(boolean enable) throws RemoteException {
113                Parcel _data = Parcel.obtain();
114                Parcel _reply = Parcel.obtain();
115                try {
116                    _data.writeInterfaceToken(DESCRIPTOR);
117                    _data.writeInt((enable ? 1 : 0));
118                    mRemote.transact(Stub.TRANSACTION_setUsbMassStorageEnabled, _data, _reply, 0);
119                    _reply.readException();
120                } finally {
121                    _reply.recycle();
122                    _data.recycle();
123                }
124            }
125
126            /**
127             * Returns true if a USB mass storage host is enabled (media is
128             * shared)
129             */
130            public boolean isUsbMassStorageEnabled() throws RemoteException {
131                Parcel _data = Parcel.obtain();
132                Parcel _reply = Parcel.obtain();
133                boolean _result;
134                try {
135                    _data.writeInterfaceToken(DESCRIPTOR);
136                    mRemote.transact(Stub.TRANSACTION_isUsbMassStorageEnabled, _data, _reply, 0);
137                    _reply.readException();
138                    _result = 0 != _reply.readInt();
139                } finally {
140                    _reply.recycle();
141                    _data.recycle();
142                }
143                return _result;
144            }
145
146            /**
147             * Mount external storage at given mount point. Returns an int
148             * consistent with MountServiceResultCode
149             */
150            public int mountVolume(String mountPoint) throws RemoteException {
151                Parcel _data = Parcel.obtain();
152                Parcel _reply = Parcel.obtain();
153                int _result;
154                try {
155                    _data.writeInterfaceToken(DESCRIPTOR);
156                    _data.writeString(mountPoint);
157                    mRemote.transact(Stub.TRANSACTION_mountVolume, _data, _reply, 0);
158                    _reply.readException();
159                    _result = _reply.readInt();
160                } finally {
161                    _reply.recycle();
162                    _data.recycle();
163                }
164                return _result;
165            }
166
167            /**
168             * Safely unmount external storage at given mount point. The unmount
169             * is an asynchronous operation. Applications should register
170             * StorageEventListener for storage related status changes.
171             */
172            public void unmountVolume(String mountPoint, boolean force, boolean removeEncryption)
173                    throws RemoteException {
174                Parcel _data = Parcel.obtain();
175                Parcel _reply = Parcel.obtain();
176                try {
177                    _data.writeInterfaceToken(DESCRIPTOR);
178                    _data.writeString(mountPoint);
179                    _data.writeInt((force ? 1 : 0));
180                    _data.writeInt((removeEncryption ? 1 : 0));
181                    mRemote.transact(Stub.TRANSACTION_unmountVolume, _data, _reply, 0);
182                    _reply.readException();
183                } finally {
184                    _reply.recycle();
185                    _data.recycle();
186                }
187            }
188
189            /**
190             * Format external storage given a mount point. Returns an int
191             * consistent with MountServiceResultCode
192             */
193            public int formatVolume(String mountPoint) throws RemoteException {
194                Parcel _data = Parcel.obtain();
195                Parcel _reply = Parcel.obtain();
196                int _result;
197                try {
198                    _data.writeInterfaceToken(DESCRIPTOR);
199                    _data.writeString(mountPoint);
200                    mRemote.transact(Stub.TRANSACTION_formatVolume, _data, _reply, 0);
201                    _reply.readException();
202                    _result = _reply.readInt();
203                } finally {
204                    _reply.recycle();
205                    _data.recycle();
206                }
207                return _result;
208            }
209
210            /**
211             * Returns an array of pids with open files on the specified path.
212             */
213            public int[] getStorageUsers(String path) throws RemoteException {
214                Parcel _data = Parcel.obtain();
215                Parcel _reply = Parcel.obtain();
216                int[] _result;
217                try {
218                    _data.writeInterfaceToken(DESCRIPTOR);
219                    _data.writeString(path);
220                    mRemote.transact(Stub.TRANSACTION_getStorageUsers, _data, _reply, 0);
221                    _reply.readException();
222                    _result = _reply.createIntArray();
223                } finally {
224                    _reply.recycle();
225                    _data.recycle();
226                }
227                return _result;
228            }
229
230            /**
231             * Gets the state of a volume via its mountpoint.
232             */
233            public String getVolumeState(String mountPoint) throws RemoteException {
234                Parcel _data = Parcel.obtain();
235                Parcel _reply = Parcel.obtain();
236                String _result;
237                try {
238                    _data.writeInterfaceToken(DESCRIPTOR);
239                    _data.writeString(mountPoint);
240                    mRemote.transact(Stub.TRANSACTION_getVolumeState, _data, _reply, 0);
241                    _reply.readException();
242                    _result = _reply.readString();
243                } finally {
244                    _reply.recycle();
245                    _data.recycle();
246                }
247                return _result;
248            }
249
250            /*
251             * Creates a secure container with the specified parameters. Returns
252             * an int consistent with MountServiceResultCode
253             */
254            public int createSecureContainer(String id, int sizeMb, String fstype, String key,
255                    int ownerUid) throws RemoteException {
256                Parcel _data = Parcel.obtain();
257                Parcel _reply = Parcel.obtain();
258                int _result;
259                try {
260                    _data.writeInterfaceToken(DESCRIPTOR);
261                    _data.writeString(id);
262                    _data.writeInt(sizeMb);
263                    _data.writeString(fstype);
264                    _data.writeString(key);
265                    _data.writeInt(ownerUid);
266                    mRemote.transact(Stub.TRANSACTION_createSecureContainer, _data, _reply, 0);
267                    _reply.readException();
268                    _result = _reply.readInt();
269                } finally {
270                    _reply.recycle();
271                    _data.recycle();
272                }
273                return _result;
274            }
275
276            /*
277             * Destroy a secure container, and free up all resources associated
278             * with it. NOTE: Ensure all references are released prior to
279             * deleting. Returns an int consistent with MountServiceResultCode
280             */
281            public int destroySecureContainer(String id, boolean force) throws RemoteException {
282                Parcel _data = Parcel.obtain();
283                Parcel _reply = Parcel.obtain();
284                int _result;
285                try {
286                    _data.writeInterfaceToken(DESCRIPTOR);
287                    _data.writeString(id);
288                    _data.writeInt((force ? 1 : 0));
289                    mRemote.transact(Stub.TRANSACTION_destroySecureContainer, _data, _reply, 0);
290                    _reply.readException();
291                    _result = _reply.readInt();
292                } finally {
293                    _reply.recycle();
294                    _data.recycle();
295                }
296                return _result;
297            }
298
299            /*
300             * Finalize a container which has just been created and populated.
301             * After finalization, the container is immutable. Returns an int
302             * consistent with MountServiceResultCode
303             */
304            public int finalizeSecureContainer(String id) throws RemoteException {
305                Parcel _data = Parcel.obtain();
306                Parcel _reply = Parcel.obtain();
307                int _result;
308                try {
309                    _data.writeInterfaceToken(DESCRIPTOR);
310                    _data.writeString(id);
311                    mRemote.transact(Stub.TRANSACTION_finalizeSecureContainer, _data, _reply, 0);
312                    _reply.readException();
313                    _result = _reply.readInt();
314                } finally {
315                    _reply.recycle();
316                    _data.recycle();
317                }
318                return _result;
319            }
320
321            /*
322             * Mount a secure container with the specified key and owner UID.
323             * Returns an int consistent with MountServiceResultCode
324             */
325            public int mountSecureContainer(String id, String key, int ownerUid)
326                    throws RemoteException {
327                Parcel _data = Parcel.obtain();
328                Parcel _reply = Parcel.obtain();
329                int _result;
330                try {
331                    _data.writeInterfaceToken(DESCRIPTOR);
332                    _data.writeString(id);
333                    _data.writeString(key);
334                    _data.writeInt(ownerUid);
335                    mRemote.transact(Stub.TRANSACTION_mountSecureContainer, _data, _reply, 0);
336                    _reply.readException();
337                    _result = _reply.readInt();
338                } finally {
339                    _reply.recycle();
340                    _data.recycle();
341                }
342                return _result;
343            }
344
345            /*
346             * Unount a secure container. Returns an int consistent with
347             * MountServiceResultCode
348             */
349            public int unmountSecureContainer(String id, boolean force) throws RemoteException {
350                Parcel _data = Parcel.obtain();
351                Parcel _reply = Parcel.obtain();
352                int _result;
353                try {
354                    _data.writeInterfaceToken(DESCRIPTOR);
355                    _data.writeString(id);
356                    _data.writeInt((force ? 1 : 0));
357                    mRemote.transact(Stub.TRANSACTION_unmountSecureContainer, _data, _reply, 0);
358                    _reply.readException();
359                    _result = _reply.readInt();
360                } finally {
361                    _reply.recycle();
362                    _data.recycle();
363                }
364                return _result;
365            }
366
367            /*
368             * Returns true if the specified container is mounted
369             */
370            public boolean isSecureContainerMounted(String id) throws RemoteException {
371                Parcel _data = Parcel.obtain();
372                Parcel _reply = Parcel.obtain();
373                boolean _result;
374                try {
375                    _data.writeInterfaceToken(DESCRIPTOR);
376                    _data.writeString(id);
377                    mRemote.transact(Stub.TRANSACTION_isSecureContainerMounted, _data, _reply, 0);
378                    _reply.readException();
379                    _result = 0 != _reply.readInt();
380                } finally {
381                    _reply.recycle();
382                    _data.recycle();
383                }
384                return _result;
385            }
386
387            /*
388             * Rename an unmounted secure container. Returns an int consistent
389             * with MountServiceResultCode
390             */
391            public int renameSecureContainer(String oldId, String newId) throws RemoteException {
392                Parcel _data = Parcel.obtain();
393                Parcel _reply = Parcel.obtain();
394                int _result;
395                try {
396                    _data.writeInterfaceToken(DESCRIPTOR);
397                    _data.writeString(oldId);
398                    _data.writeString(newId);
399                    mRemote.transact(Stub.TRANSACTION_renameSecureContainer, _data, _reply, 0);
400                    _reply.readException();
401                    _result = _reply.readInt();
402                } finally {
403                    _reply.recycle();
404                    _data.recycle();
405                }
406                return _result;
407            }
408
409            /*
410             * Returns the filesystem path of a mounted secure container.
411             */
412            public String getSecureContainerPath(String id) throws RemoteException {
413                Parcel _data = Parcel.obtain();
414                Parcel _reply = Parcel.obtain();
415                String _result;
416                try {
417                    _data.writeInterfaceToken(DESCRIPTOR);
418                    _data.writeString(id);
419                    mRemote.transact(Stub.TRANSACTION_getSecureContainerPath, _data, _reply, 0);
420                    _reply.readException();
421                    _result = _reply.readString();
422                } finally {
423                    _reply.recycle();
424                    _data.recycle();
425                }
426                return _result;
427            }
428
429            /**
430             * Gets an Array of currently known secure container IDs
431             */
432            public String[] getSecureContainerList() throws RemoteException {
433                Parcel _data = Parcel.obtain();
434                Parcel _reply = Parcel.obtain();
435                String[] _result;
436                try {
437                    _data.writeInterfaceToken(DESCRIPTOR);
438                    mRemote.transact(Stub.TRANSACTION_getSecureContainerList, _data, _reply, 0);
439                    _reply.readException();
440                    _result = _reply.createStringArray();
441                } finally {
442                    _reply.recycle();
443                    _data.recycle();
444                }
445                return _result;
446            }
447
448            /**
449             * Shuts down the MountService and gracefully unmounts all external
450             * media. Invokes call back once the shutdown is complete.
451             */
452            public void shutdown(IMountShutdownObserver observer)
453                    throws RemoteException {
454                Parcel _data = Parcel.obtain();
455                Parcel _reply = Parcel.obtain();
456                try {
457                    _data.writeInterfaceToken(DESCRIPTOR);
458                    _data.writeStrongBinder((observer != null ? observer.asBinder() : null));
459                    mRemote.transact(Stub.TRANSACTION_shutdown, _data, _reply, 0);
460                    _reply.readException();
461                } finally {
462                    _reply.recycle();
463                    _data.recycle();
464                }
465            }
466
467            /**
468             * Call into MountService by PackageManager to notify that its done
469             * processing the media status update request.
470             */
471            public void finishMediaUpdate() throws RemoteException {
472                Parcel _data = Parcel.obtain();
473                Parcel _reply = Parcel.obtain();
474                try {
475                    _data.writeInterfaceToken(DESCRIPTOR);
476                    mRemote.transact(Stub.TRANSACTION_finishMediaUpdate, _data, _reply, 0);
477                    _reply.readException();
478                } finally {
479                    _reply.recycle();
480                    _data.recycle();
481                }
482            }
483
484            /**
485             * Mounts an Opaque Binary Blob (OBB) with the specified decryption
486             * key and only allows the calling process's UID access to the
487             * contents. MountService will call back to the supplied
488             * IObbActionListener to inform it of the terminal state of the
489             * call.
490             */
491            public void mountObb(String filename, String key, IObbActionListener token, int nonce)
492                    throws RemoteException {
493                Parcel _data = Parcel.obtain();
494                Parcel _reply = Parcel.obtain();
495                try {
496                    _data.writeInterfaceToken(DESCRIPTOR);
497                    _data.writeString(filename);
498                    _data.writeString(key);
499                    _data.writeStrongBinder((token != null ? token.asBinder() : null));
500                    _data.writeInt(nonce);
501                    mRemote.transact(Stub.TRANSACTION_mountObb, _data, _reply, 0);
502                    _reply.readException();
503                } finally {
504                    _reply.recycle();
505                    _data.recycle();
506                }
507            }
508
509            /**
510             * Unmounts an Opaque Binary Blob (OBB). When the force flag is
511             * specified, any program using it will be forcibly killed to
512             * unmount the image. MountService will call back to the supplied
513             * IObbActionListener to inform it of the terminal state of the
514             * call.
515             */
516            public void unmountObb(String filename, boolean force, IObbActionListener token,
517                    int nonce) throws RemoteException {
518                Parcel _data = Parcel.obtain();
519                Parcel _reply = Parcel.obtain();
520                try {
521                    _data.writeInterfaceToken(DESCRIPTOR);
522                    _data.writeString(filename);
523                    _data.writeInt((force ? 1 : 0));
524                    _data.writeStrongBinder((token != null ? token.asBinder() : null));
525                    _data.writeInt(nonce);
526                    mRemote.transact(Stub.TRANSACTION_unmountObb, _data, _reply, 0);
527                    _reply.readException();
528                } finally {
529                    _reply.recycle();
530                    _data.recycle();
531                }
532            }
533
534            /**
535             * Checks whether the specified Opaque Binary Blob (OBB) is mounted
536             * somewhere.
537             */
538            public boolean isObbMounted(String filename) throws RemoteException {
539                Parcel _data = Parcel.obtain();
540                Parcel _reply = Parcel.obtain();
541                boolean _result;
542                try {
543                    _data.writeInterfaceToken(DESCRIPTOR);
544                    _data.writeString(filename);
545                    mRemote.transact(Stub.TRANSACTION_isObbMounted, _data, _reply, 0);
546                    _reply.readException();
547                    _result = 0 != _reply.readInt();
548                } finally {
549                    _reply.recycle();
550                    _data.recycle();
551                }
552                return _result;
553            }
554
555            /**
556             * Gets the path to the mounted Opaque Binary Blob (OBB).
557             */
558            public String getMountedObbPath(String filename) throws RemoteException {
559                Parcel _data = Parcel.obtain();
560                Parcel _reply = Parcel.obtain();
561                String _result;
562                try {
563                    _data.writeInterfaceToken(DESCRIPTOR);
564                    _data.writeString(filename);
565                    mRemote.transact(Stub.TRANSACTION_getMountedObbPath, _data, _reply, 0);
566                    _reply.readException();
567                    _result = _reply.readString();
568                } finally {
569                    _reply.recycle();
570                    _data.recycle();
571                }
572                return _result;
573            }
574
575            /**
576             * Returns whether the external storage is emulated.
577             */
578            public boolean isExternalStorageEmulated() throws RemoteException {
579                Parcel _data = Parcel.obtain();
580                Parcel _reply = Parcel.obtain();
581                boolean _result;
582                try {
583                    _data.writeInterfaceToken(DESCRIPTOR);
584                    mRemote.transact(Stub.TRANSACTION_isExternalStorageEmulated, _data, _reply, 0);
585                    _reply.readException();
586                    _result = 0 != _reply.readInt();
587                } finally {
588                    _reply.recycle();
589                    _data.recycle();
590                }
591                return _result;
592            }
593
594            public int getEncryptionState() throws RemoteException {
595                Parcel _data = Parcel.obtain();
596                Parcel _reply = Parcel.obtain();
597                int _result;
598                try {
599                    _data.writeInterfaceToken(DESCRIPTOR);
600                    mRemote.transact(Stub.TRANSACTION_getEncryptionState, _data, _reply, 0);
601                    _reply.readException();
602                    _result = _reply.readInt();
603                } finally {
604                    _reply.recycle();
605                    _data.recycle();
606                }
607                return _result;
608            }
609
610            public int decryptStorage(String password) throws RemoteException {
611                Parcel _data = Parcel.obtain();
612                Parcel _reply = Parcel.obtain();
613                int _result;
614                try {
615                    _data.writeInterfaceToken(DESCRIPTOR);
616                    _data.writeString(password);
617                    mRemote.transact(Stub.TRANSACTION_decryptStorage, _data, _reply, 0);
618                    _reply.readException();
619                    _result = _reply.readInt();
620                } finally {
621                    _reply.recycle();
622                    _data.recycle();
623                }
624                return _result;
625            }
626
627            public int encryptStorage(String password) throws RemoteException {
628                Parcel _data = Parcel.obtain();
629                Parcel _reply = Parcel.obtain();
630                int _result;
631                try {
632                    _data.writeInterfaceToken(DESCRIPTOR);
633                    _data.writeString(password);
634                    mRemote.transact(Stub.TRANSACTION_encryptStorage, _data, _reply, 0);
635                    _reply.readException();
636                    _result = _reply.readInt();
637                } finally {
638                    _reply.recycle();
639                    _data.recycle();
640                }
641                return _result;
642            }
643
644            public int changeEncryptionPassword(String password) throws RemoteException {
645                Parcel _data = Parcel.obtain();
646                Parcel _reply = Parcel.obtain();
647                int _result;
648                try {
649                    _data.writeInterfaceToken(DESCRIPTOR);
650                    _data.writeString(password);
651                    mRemote.transact(Stub.TRANSACTION_changeEncryptionPassword, _data, _reply, 0);
652                    _reply.readException();
653                    _result = _reply.readInt();
654                } finally {
655                    _reply.recycle();
656                    _data.recycle();
657                }
658                return _result;
659            }
660
661            public Parcelable[] getVolumeList() throws RemoteException {
662                Parcel _data = Parcel.obtain();
663                Parcel _reply = Parcel.obtain();
664                Parcelable[] _result;
665                try {
666                    _data.writeInterfaceToken(DESCRIPTOR);
667                    mRemote.transact(Stub.TRANSACTION_getVolumeList, _data, _reply, 0);
668                    _reply.readException();
669                    _result = _reply.readParcelableArray(StorageVolume.class.getClassLoader());
670                } finally {
671                    _reply.recycle();
672                    _data.recycle();
673                }
674                return _result;
675            }
676
677            /*
678             * Returns the filesystem path of a mounted secure container.
679             */
680            public String getSecureContainerFilesystemPath(String id) throws RemoteException {
681                Parcel _data = Parcel.obtain();
682                Parcel _reply = Parcel.obtain();
683                String _result;
684                try {
685                    _data.writeInterfaceToken(DESCRIPTOR);
686                    _data.writeString(id);
687                    mRemote.transact(Stub.TRANSACTION_getSecureContainerFilesystemPath, _data, _reply, 0);
688                    _reply.readException();
689                    _result = _reply.readString();
690                } finally {
691                    _reply.recycle();
692                    _data.recycle();
693                }
694                return _result;
695            }
696        }
697
698        private static final String DESCRIPTOR = "IMountService";
699
700        static final int TRANSACTION_registerListener = IBinder.FIRST_CALL_TRANSACTION + 0;
701
702        static final int TRANSACTION_unregisterListener = IBinder.FIRST_CALL_TRANSACTION + 1;
703
704        static final int TRANSACTION_isUsbMassStorageConnected = IBinder.FIRST_CALL_TRANSACTION + 2;
705
706        static final int TRANSACTION_setUsbMassStorageEnabled = IBinder.FIRST_CALL_TRANSACTION + 3;
707
708        static final int TRANSACTION_isUsbMassStorageEnabled = IBinder.FIRST_CALL_TRANSACTION + 4;
709
710        static final int TRANSACTION_mountVolume = IBinder.FIRST_CALL_TRANSACTION + 5;
711
712        static final int TRANSACTION_unmountVolume = IBinder.FIRST_CALL_TRANSACTION + 6;
713
714        static final int TRANSACTION_formatVolume = IBinder.FIRST_CALL_TRANSACTION + 7;
715
716        static final int TRANSACTION_getStorageUsers = IBinder.FIRST_CALL_TRANSACTION + 8;
717
718        static final int TRANSACTION_getVolumeState = IBinder.FIRST_CALL_TRANSACTION + 9;
719
720        static final int TRANSACTION_createSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 10;
721
722        static final int TRANSACTION_finalizeSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 11;
723
724        static final int TRANSACTION_destroySecureContainer = IBinder.FIRST_CALL_TRANSACTION + 12;
725
726        static final int TRANSACTION_mountSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 13;
727
728        static final int TRANSACTION_unmountSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 14;
729
730        static final int TRANSACTION_isSecureContainerMounted = IBinder.FIRST_CALL_TRANSACTION + 15;
731
732        static final int TRANSACTION_renameSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 16;
733
734        static final int TRANSACTION_getSecureContainerPath = IBinder.FIRST_CALL_TRANSACTION + 17;
735
736        static final int TRANSACTION_getSecureContainerList = IBinder.FIRST_CALL_TRANSACTION + 18;
737
738        static final int TRANSACTION_shutdown = IBinder.FIRST_CALL_TRANSACTION + 19;
739
740        static final int TRANSACTION_finishMediaUpdate = IBinder.FIRST_CALL_TRANSACTION + 20;
741
742        static final int TRANSACTION_mountObb = IBinder.FIRST_CALL_TRANSACTION + 21;
743
744        static final int TRANSACTION_unmountObb = IBinder.FIRST_CALL_TRANSACTION + 22;
745
746        static final int TRANSACTION_isObbMounted = IBinder.FIRST_CALL_TRANSACTION + 23;
747
748        static final int TRANSACTION_getMountedObbPath = IBinder.FIRST_CALL_TRANSACTION + 24;
749
750        static final int TRANSACTION_isExternalStorageEmulated = IBinder.FIRST_CALL_TRANSACTION + 25;
751
752        static final int TRANSACTION_decryptStorage = IBinder.FIRST_CALL_TRANSACTION + 26;
753
754        static final int TRANSACTION_encryptStorage = IBinder.FIRST_CALL_TRANSACTION + 27;
755
756        static final int TRANSACTION_changeEncryptionPassword = IBinder.FIRST_CALL_TRANSACTION + 28;
757
758        static final int TRANSACTION_getVolumeList = IBinder.FIRST_CALL_TRANSACTION + 29;
759
760        static final int TRANSACTION_getSecureContainerFilesystemPath = IBinder.FIRST_CALL_TRANSACTION + 30;
761
762        static final int TRANSACTION_getEncryptionState = IBinder.FIRST_CALL_TRANSACTION + 31;
763
764        /**
765         * Cast an IBinder object into an IMountService interface, generating a
766         * proxy if needed.
767         */
768        public static IMountService asInterface(IBinder obj) {
769            if (obj == null) {
770                return null;
771            }
772            IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
773            if (iin != null && iin instanceof IMountService) {
774                return (IMountService) iin;
775            }
776            return new IMountService.Stub.Proxy(obj);
777        }
778
779        /** Construct the stub at attach it to the interface. */
780        public Stub() {
781            attachInterface(this, DESCRIPTOR);
782        }
783
784        public IBinder asBinder() {
785            return this;
786        }
787
788        @Override
789        public boolean onTransact(int code, Parcel data, Parcel reply,
790                int flags) throws RemoteException {
791            switch (code) {
792                case INTERFACE_TRANSACTION: {
793                    reply.writeString(DESCRIPTOR);
794                    return true;
795                }
796                case TRANSACTION_registerListener: {
797                    data.enforceInterface(DESCRIPTOR);
798                    IMountServiceListener listener;
799                    listener = IMountServiceListener.Stub.asInterface(data.readStrongBinder());
800                    registerListener(listener);
801                    reply.writeNoException();
802                    return true;
803                }
804                case TRANSACTION_unregisterListener: {
805                    data.enforceInterface(DESCRIPTOR);
806                    IMountServiceListener listener;
807                    listener = IMountServiceListener.Stub.asInterface(data.readStrongBinder());
808                    unregisterListener(listener);
809                    reply.writeNoException();
810                    return true;
811                }
812                case TRANSACTION_isUsbMassStorageConnected: {
813                    data.enforceInterface(DESCRIPTOR);
814                    boolean result = isUsbMassStorageConnected();
815                    reply.writeNoException();
816                    reply.writeInt((result ? 1 : 0));
817                    return true;
818                }
819                case TRANSACTION_setUsbMassStorageEnabled: {
820                    data.enforceInterface(DESCRIPTOR);
821                    boolean enable;
822                    enable = 0 != data.readInt();
823                    setUsbMassStorageEnabled(enable);
824                    reply.writeNoException();
825                    return true;
826                }
827                case TRANSACTION_isUsbMassStorageEnabled: {
828                    data.enforceInterface(DESCRIPTOR);
829                    boolean result = isUsbMassStorageEnabled();
830                    reply.writeNoException();
831                    reply.writeInt((result ? 1 : 0));
832                    return true;
833                }
834                case TRANSACTION_mountVolume: {
835                    data.enforceInterface(DESCRIPTOR);
836                    String mountPoint;
837                    mountPoint = data.readString();
838                    int resultCode = mountVolume(mountPoint);
839                    reply.writeNoException();
840                    reply.writeInt(resultCode);
841                    return true;
842                }
843                case TRANSACTION_unmountVolume: {
844                    data.enforceInterface(DESCRIPTOR);
845                    String mountPoint;
846                    mountPoint = data.readString();
847                    boolean force = 0 != data.readInt();
848                    boolean removeEncrypt = 0 != data.readInt();
849                    unmountVolume(mountPoint, force, removeEncrypt);
850                    reply.writeNoException();
851                    return true;
852                }
853                case TRANSACTION_formatVolume: {
854                    data.enforceInterface(DESCRIPTOR);
855                    String mountPoint;
856                    mountPoint = data.readString();
857                    int result = formatVolume(mountPoint);
858                    reply.writeNoException();
859                    reply.writeInt(result);
860                    return true;
861                }
862                case TRANSACTION_getStorageUsers: {
863                    data.enforceInterface(DESCRIPTOR);
864                    String path;
865                    path = data.readString();
866                    int[] pids = getStorageUsers(path);
867                    reply.writeNoException();
868                    reply.writeIntArray(pids);
869                    return true;
870                }
871                case TRANSACTION_getVolumeState: {
872                    data.enforceInterface(DESCRIPTOR);
873                    String mountPoint;
874                    mountPoint = data.readString();
875                    String state = getVolumeState(mountPoint);
876                    reply.writeNoException();
877                    reply.writeString(state);
878                    return true;
879                }
880                case TRANSACTION_createSecureContainer: {
881                    data.enforceInterface(DESCRIPTOR);
882                    String id;
883                    id = data.readString();
884                    int sizeMb;
885                    sizeMb = data.readInt();
886                    String fstype;
887                    fstype = data.readString();
888                    String key;
889                    key = data.readString();
890                    int ownerUid;
891                    ownerUid = data.readInt();
892                    int resultCode = createSecureContainer(id, sizeMb, fstype, key, ownerUid);
893                    reply.writeNoException();
894                    reply.writeInt(resultCode);
895                    return true;
896                }
897                case TRANSACTION_finalizeSecureContainer: {
898                    data.enforceInterface(DESCRIPTOR);
899                    String id;
900                    id = data.readString();
901                    int resultCode = finalizeSecureContainer(id);
902                    reply.writeNoException();
903                    reply.writeInt(resultCode);
904                    return true;
905                }
906                case TRANSACTION_destroySecureContainer: {
907                    data.enforceInterface(DESCRIPTOR);
908                    String id;
909                    id = data.readString();
910                    boolean force;
911                    force = 0 != data.readInt();
912                    int resultCode = destroySecureContainer(id, force);
913                    reply.writeNoException();
914                    reply.writeInt(resultCode);
915                    return true;
916                }
917                case TRANSACTION_mountSecureContainer: {
918                    data.enforceInterface(DESCRIPTOR);
919                    String id;
920                    id = data.readString();
921                    String key;
922                    key = data.readString();
923                    int ownerUid;
924                    ownerUid = data.readInt();
925                    int resultCode = mountSecureContainer(id, key, ownerUid);
926                    reply.writeNoException();
927                    reply.writeInt(resultCode);
928                    return true;
929                }
930                case TRANSACTION_unmountSecureContainer: {
931                    data.enforceInterface(DESCRIPTOR);
932                    String id;
933                    id = data.readString();
934                    boolean force;
935                    force = 0 != data.readInt();
936                    int resultCode = unmountSecureContainer(id, force);
937                    reply.writeNoException();
938                    reply.writeInt(resultCode);
939                    return true;
940                }
941                case TRANSACTION_isSecureContainerMounted: {
942                    data.enforceInterface(DESCRIPTOR);
943                    String id;
944                    id = data.readString();
945                    boolean status = isSecureContainerMounted(id);
946                    reply.writeNoException();
947                    reply.writeInt((status ? 1 : 0));
948                    return true;
949                }
950                case TRANSACTION_renameSecureContainer: {
951                    data.enforceInterface(DESCRIPTOR);
952                    String oldId;
953                    oldId = data.readString();
954                    String newId;
955                    newId = data.readString();
956                    int resultCode = renameSecureContainer(oldId, newId);
957                    reply.writeNoException();
958                    reply.writeInt(resultCode);
959                    return true;
960                }
961                case TRANSACTION_getSecureContainerPath: {
962                    data.enforceInterface(DESCRIPTOR);
963                    String id;
964                    id = data.readString();
965                    String path = getSecureContainerPath(id);
966                    reply.writeNoException();
967                    reply.writeString(path);
968                    return true;
969                }
970                case TRANSACTION_getSecureContainerList: {
971                    data.enforceInterface(DESCRIPTOR);
972                    String[] ids = getSecureContainerList();
973                    reply.writeNoException();
974                    reply.writeStringArray(ids);
975                    return true;
976                }
977                case TRANSACTION_shutdown: {
978                    data.enforceInterface(DESCRIPTOR);
979                    IMountShutdownObserver observer;
980                    observer = IMountShutdownObserver.Stub.asInterface(data
981                            .readStrongBinder());
982                    shutdown(observer);
983                    reply.writeNoException();
984                    return true;
985                }
986                case TRANSACTION_finishMediaUpdate: {
987                    data.enforceInterface(DESCRIPTOR);
988                    finishMediaUpdate();
989                    reply.writeNoException();
990                    return true;
991                }
992                case TRANSACTION_mountObb: {
993                    data.enforceInterface(DESCRIPTOR);
994                    String filename;
995                    filename = data.readString();
996                    String key;
997                    key = data.readString();
998                    IObbActionListener observer;
999                    observer = IObbActionListener.Stub.asInterface(data.readStrongBinder());
1000                    int nonce;
1001                    nonce = data.readInt();
1002                    mountObb(filename, key, observer, nonce);
1003                    reply.writeNoException();
1004                    return true;
1005                }
1006                case TRANSACTION_unmountObb: {
1007                    data.enforceInterface(DESCRIPTOR);
1008                    String filename;
1009                    filename = data.readString();
1010                    boolean force;
1011                    force = 0 != data.readInt();
1012                    IObbActionListener observer;
1013                    observer = IObbActionListener.Stub.asInterface(data.readStrongBinder());
1014                    int nonce;
1015                    nonce = data.readInt();
1016                    unmountObb(filename, force, observer, nonce);
1017                    reply.writeNoException();
1018                    return true;
1019                }
1020                case TRANSACTION_isObbMounted: {
1021                    data.enforceInterface(DESCRIPTOR);
1022                    String filename;
1023                    filename = data.readString();
1024                    boolean status = isObbMounted(filename);
1025                    reply.writeNoException();
1026                    reply.writeInt((status ? 1 : 0));
1027                    return true;
1028                }
1029                case TRANSACTION_getMountedObbPath: {
1030                    data.enforceInterface(DESCRIPTOR);
1031                    String filename;
1032                    filename = data.readString();
1033                    String mountedPath = getMountedObbPath(filename);
1034                    reply.writeNoException();
1035                    reply.writeString(mountedPath);
1036                    return true;
1037                }
1038                case TRANSACTION_isExternalStorageEmulated: {
1039                    data.enforceInterface(DESCRIPTOR);
1040                    boolean emulated = isExternalStorageEmulated();
1041                    reply.writeNoException();
1042                    reply.writeInt(emulated ? 1 : 0);
1043                    return true;
1044                }
1045                case TRANSACTION_decryptStorage: {
1046                    data.enforceInterface(DESCRIPTOR);
1047                    String password = data.readString();
1048                    int result = decryptStorage(password);
1049                    reply.writeNoException();
1050                    reply.writeInt(result);
1051                    return true;
1052                }
1053                case TRANSACTION_encryptStorage: {
1054                    data.enforceInterface(DESCRIPTOR);
1055                    String password = data.readString();
1056                    int result = encryptStorage(password);
1057                    reply.writeNoException();
1058                    reply.writeInt(result);
1059                    return true;
1060                }
1061                case TRANSACTION_changeEncryptionPassword: {
1062                    data.enforceInterface(DESCRIPTOR);
1063                    String password = data.readString();
1064                    int result = changeEncryptionPassword(password);
1065                    reply.writeNoException();
1066                    reply.writeInt(result);
1067                    return true;
1068                }
1069                case TRANSACTION_getVolumeList: {
1070                    data.enforceInterface(DESCRIPTOR);
1071                    Parcelable[] result = getVolumeList();
1072                    reply.writeNoException();
1073                    reply.writeParcelableArray(result, 0);
1074                    return true;
1075                }
1076                case TRANSACTION_getSecureContainerFilesystemPath: {
1077                    data.enforceInterface(DESCRIPTOR);
1078                    String id;
1079                    id = data.readString();
1080                    String path = getSecureContainerFilesystemPath(id);
1081                    reply.writeNoException();
1082                    reply.writeString(path);
1083                    return true;
1084                }
1085                case TRANSACTION_getEncryptionState: {
1086                    data.enforceInterface(DESCRIPTOR);
1087                    int result = getEncryptionState();
1088                    reply.writeNoException();
1089                    reply.writeInt(result);
1090                    return true;
1091                }
1092            }
1093            return super.onTransact(code, data, reply, flags);
1094        }
1095    }
1096
1097    /*
1098     * Creates a secure container with the specified parameters. Returns an int
1099     * consistent with MountServiceResultCode
1100     */
1101    public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid)
1102            throws RemoteException;
1103
1104    /*
1105     * Destroy a secure container, and free up all resources associated with it.
1106     * NOTE: Ensure all references are released prior to deleting. Returns an
1107     * int consistent with MountServiceResultCode
1108     */
1109    public int destroySecureContainer(String id, boolean force) throws RemoteException;
1110
1111    /*
1112     * Finalize a container which has just been created and populated. After
1113     * finalization, the container is immutable. Returns an int consistent with
1114     * MountServiceResultCode
1115     */
1116    public int finalizeSecureContainer(String id) throws RemoteException;
1117
1118    /**
1119     * Call into MountService by PackageManager to notify that its done
1120     * processing the media status update request.
1121     */
1122    public void finishMediaUpdate() throws RemoteException;
1123
1124    /**
1125     * Format external storage given a mount point. Returns an int consistent
1126     * with MountServiceResultCode
1127     */
1128    public int formatVolume(String mountPoint) throws RemoteException;
1129
1130    /**
1131     * Gets the path to the mounted Opaque Binary Blob (OBB).
1132     */
1133    public String getMountedObbPath(String filename) throws RemoteException;
1134
1135    /**
1136     * Gets an Array of currently known secure container IDs
1137     */
1138    public String[] getSecureContainerList() throws RemoteException;
1139
1140    /*
1141     * Returns the filesystem path of a mounted secure container.
1142     */
1143    public String getSecureContainerPath(String id) throws RemoteException;
1144
1145    /**
1146     * Returns an array of pids with open files on the specified path.
1147     */
1148    public int[] getStorageUsers(String path) throws RemoteException;
1149
1150    /**
1151     * Gets the state of a volume via its mountpoint.
1152     */
1153    public String getVolumeState(String mountPoint) throws RemoteException;
1154
1155    /**
1156     * Checks whether the specified Opaque Binary Blob (OBB) is mounted
1157     * somewhere.
1158     */
1159    public boolean isObbMounted(String filename) throws RemoteException;
1160
1161    /*
1162     * Returns true if the specified container is mounted
1163     */
1164    public boolean isSecureContainerMounted(String id) throws RemoteException;
1165
1166    /**
1167     * Returns true if a USB mass storage host is connected
1168     */
1169    public boolean isUsbMassStorageConnected() throws RemoteException;
1170
1171    /**
1172     * Returns true if a USB mass storage host is enabled (media is shared)
1173     */
1174    public boolean isUsbMassStorageEnabled() throws RemoteException;
1175
1176    /**
1177     * Mounts an Opaque Binary Blob (OBB) with the specified decryption key and
1178     * only allows the calling process's UID access to the contents.
1179     * MountService will call back to the supplied IObbActionListener to inform
1180     * it of the terminal state of the call.
1181     */
1182    public void mountObb(String filename, String key, IObbActionListener token, int nonce)
1183            throws RemoteException;
1184
1185    /*
1186     * Mount a secure container with the specified key and owner UID. Returns an
1187     * int consistent with MountServiceResultCode
1188     */
1189    public int mountSecureContainer(String id, String key, int ownerUid) throws RemoteException;
1190
1191    /**
1192     * Mount external storage at given mount point. Returns an int consistent
1193     * with MountServiceResultCode
1194     */
1195    public int mountVolume(String mountPoint) throws RemoteException;
1196
1197    /**
1198     * Registers an IMountServiceListener for receiving async notifications.
1199     */
1200    public void registerListener(IMountServiceListener listener) throws RemoteException;
1201
1202    /*
1203     * Rename an unmounted secure container. Returns an int consistent with
1204     * MountServiceResultCode
1205     */
1206    public int renameSecureContainer(String oldId, String newId) throws RemoteException;
1207
1208    /**
1209     * Enables / disables USB mass storage. The caller should check actual
1210     * status of enabling/disabling USB mass storage via StorageEventListener.
1211     */
1212    public void setUsbMassStorageEnabled(boolean enable) throws RemoteException;
1213
1214    /**
1215     * Shuts down the MountService and gracefully unmounts all external media.
1216     * Invokes call back once the shutdown is complete.
1217     */
1218    public void shutdown(IMountShutdownObserver observer) throws RemoteException;
1219
1220    /**
1221     * Unmounts an Opaque Binary Blob (OBB). When the force flag is specified,
1222     * any program using it will be forcibly killed to unmount the image.
1223     * MountService will call back to the supplied IObbActionListener to inform
1224     * it of the terminal state of the call.
1225     */
1226    public void unmountObb(String filename, boolean force, IObbActionListener token, int nonce)
1227            throws RemoteException;
1228
1229    /*
1230     * Unount a secure container. Returns an int consistent with
1231     * MountServiceResultCode
1232     */
1233    public int unmountSecureContainer(String id, boolean force) throws RemoteException;
1234
1235    /**
1236     * Safely unmount external storage at given mount point. The unmount is an
1237     * asynchronous operation. Applications should register StorageEventListener
1238     * for storage related status changes.
1239     * @param mountPoint the mount point
1240     * @param force whether or not to forcefully unmount it (e.g. even if programs are using this
1241     *     data currently)
1242     * @param removeEncryption whether or not encryption mapping should be removed from the volume.
1243     *     This value implies {@code force}.
1244     */
1245    public void unmountVolume(String mountPoint, boolean force, boolean removeEncryption)
1246            throws RemoteException;
1247
1248    /**
1249     * Unregisters an IMountServiceListener
1250     */
1251    public void unregisterListener(IMountServiceListener listener) throws RemoteException;
1252
1253    /**
1254     * Returns whether or not the external storage is emulated.
1255     */
1256    public boolean isExternalStorageEmulated() throws RemoteException;
1257
1258    /** The volume is not encrypted. */
1259    static final int ENCRYPTION_STATE_NONE = 1;
1260    /** The volume has been encrypted succesfully. */
1261    static final int ENCRYPTION_STATE_OK = 0;
1262    /** The volume is in a bad state. */
1263    static final int ENCRYPTION_STATE_ERROR_UNKNOWN = -1;
1264    /** The volume is in a bad state - partially encrypted. Data is likely irrecoverable. */
1265    static final int ENCRYPTION_STATE_ERROR_INCOMPLETE = -2;
1266
1267    /**
1268     * Determines the encryption state of the volume.
1269     * @return a numerical value. See {@code ENCRYPTION_STATE_*} for possible values.
1270     */
1271    public int getEncryptionState() throws RemoteException;
1272
1273    /**
1274     * Decrypts any encrypted volumes.
1275     */
1276    public int decryptStorage(String password) throws RemoteException;
1277
1278    /**
1279     * Encrypts storage.
1280     */
1281    public int encryptStorage(String password) throws RemoteException;
1282
1283    /**
1284     * Changes the encryption password.
1285     */
1286    public int changeEncryptionPassword(String password) throws RemoteException;
1287
1288    /**
1289     * Returns list of all mountable volumes.
1290     */
1291    public Parcelable[] getVolumeList() throws RemoteException;
1292
1293    public String getSecureContainerFilesystemPath(String id) throws RemoteException;
1294}
1295