Home | History | Annotate | Download | only in storage
      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 package android.os.storage;
     18 
     19 import android.os.Binder;
     20 import android.os.IBinder;
     21 import android.os.IInterface;
     22 import android.os.Parcel;
     23 import android.os.RemoteException;
     24 
     25 /**
     26  * WARNING! Update IMountService.h and IMountService.cpp if you change this
     27  * file. In particular, the ordering of the methods below must match the
     28  * _TRANSACTION enum in IMountService.cpp
     29  *
     30  * @hide - Applications should use android.os.storage.StorageManager to access
     31  *       storage functions.
     32  */
     33 public interface IMountService extends IInterface {
     34     /** Local-side IPC implementation stub class. */
     35     public static abstract class Stub extends Binder implements IMountService {
     36         private static class Proxy implements IMountService {
     37             private final IBinder mRemote;
     38 
     39             Proxy(IBinder remote) {
     40                 mRemote = remote;
     41             }
     42 
     43             public IBinder asBinder() {
     44                 return mRemote;
     45             }
     46 
     47             public String getInterfaceDescriptor() {
     48                 return DESCRIPTOR;
     49             }
     50 
     51             /**
     52              * Registers an IMountServiceListener for receiving async
     53              * notifications.
     54              */
     55             public void registerListener(IMountServiceListener listener) throws RemoteException {
     56                 Parcel _data = Parcel.obtain();
     57                 Parcel _reply = Parcel.obtain();
     58                 try {
     59                     _data.writeInterfaceToken(DESCRIPTOR);
     60                     _data.writeStrongBinder((listener != null ? listener.asBinder() : null));
     61                     mRemote.transact(Stub.TRANSACTION_registerListener, _data, _reply, 0);
     62                     _reply.readException();
     63                 } finally {
     64                     _reply.recycle();
     65                     _data.recycle();
     66                 }
     67             }
     68 
     69             /**
     70              * Unregisters an IMountServiceListener
     71              */
     72             public void unregisterListener(IMountServiceListener listener) throws RemoteException {
     73                 Parcel _data = Parcel.obtain();
     74                 Parcel _reply = Parcel.obtain();
     75                 try {
     76                     _data.writeInterfaceToken(DESCRIPTOR);
     77                     _data.writeStrongBinder((listener != null ? listener.asBinder() : null));
     78                     mRemote.transact(Stub.TRANSACTION_unregisterListener, _data, _reply, 0);
     79                     _reply.readException();
     80                 } finally {
     81                     _reply.recycle();
     82                     _data.recycle();
     83                 }
     84             }
     85 
     86             /**
     87              * Returns true if a USB mass storage host is connected
     88              */
     89             public boolean isUsbMassStorageConnected() throws RemoteException {
     90                 Parcel _data = Parcel.obtain();
     91                 Parcel _reply = Parcel.obtain();
     92                 boolean _result;
     93                 try {
     94                     _data.writeInterfaceToken(DESCRIPTOR);
     95                     mRemote.transact(Stub.TRANSACTION_isUsbMassStorageConnected, _data, _reply, 0);
     96                     _reply.readException();
     97                     _result = 0 != _reply.readInt();
     98                 } finally {
     99                     _reply.recycle();
    100                     _data.recycle();
    101                 }
    102                 return _result;
    103             }
    104 
    105             /**
    106              * Enables / disables USB mass storage. The caller should check
    107              * actual status of enabling/disabling USB mass storage via
    108              * StorageEventListener.
    109              */
    110             public void setUsbMassStorageEnabled(boolean enable) throws RemoteException {
    111                 Parcel _data = Parcel.obtain();
    112                 Parcel _reply = Parcel.obtain();
    113                 try {
    114                     _data.writeInterfaceToken(DESCRIPTOR);
    115                     _data.writeInt((enable ? 1 : 0));
    116                     mRemote.transact(Stub.TRANSACTION_setUsbMassStorageEnabled, _data, _reply, 0);
    117                     _reply.readException();
    118                 } finally {
    119                     _reply.recycle();
    120                     _data.recycle();
    121                 }
    122             }
    123 
    124             /**
    125              * Returns true if a USB mass storage host is enabled (media is
    126              * shared)
    127              */
    128             public boolean isUsbMassStorageEnabled() throws RemoteException {
    129                 Parcel _data = Parcel.obtain();
    130                 Parcel _reply = Parcel.obtain();
    131                 boolean _result;
    132                 try {
    133                     _data.writeInterfaceToken(DESCRIPTOR);
    134                     mRemote.transact(Stub.TRANSACTION_isUsbMassStorageEnabled, _data, _reply, 0);
    135                     _reply.readException();
    136                     _result = 0 != _reply.readInt();
    137                 } finally {
    138                     _reply.recycle();
    139                     _data.recycle();
    140                 }
    141                 return _result;
    142             }
    143 
    144             /**
    145              * Mount external storage at given mount point. Returns an int
    146              * consistent with MountServiceResultCode
    147              */
    148             public int mountVolume(String mountPoint) throws RemoteException {
    149                 Parcel _data = Parcel.obtain();
    150                 Parcel _reply = Parcel.obtain();
    151                 int _result;
    152                 try {
    153                     _data.writeInterfaceToken(DESCRIPTOR);
    154                     _data.writeString(mountPoint);
    155                     mRemote.transact(Stub.TRANSACTION_mountVolume, _data, _reply, 0);
    156                     _reply.readException();
    157                     _result = _reply.readInt();
    158                 } finally {
    159                     _reply.recycle();
    160                     _data.recycle();
    161                 }
    162                 return _result;
    163             }
    164 
    165             /**
    166              * Safely unmount external storage at given mount point. The unmount
    167              * is an asynchronous operation. Applications should register
    168              * StorageEventListener for storage related status changes.
    169              */
    170             public void unmountVolume(String mountPoint, boolean force, boolean removeEncryption)
    171                     throws RemoteException {
    172                 Parcel _data = Parcel.obtain();
    173                 Parcel _reply = Parcel.obtain();
    174                 try {
    175                     _data.writeInterfaceToken(DESCRIPTOR);
    176                     _data.writeString(mountPoint);
    177                     _data.writeInt((force ? 1 : 0));
    178                     _data.writeInt((removeEncryption ? 1 : 0));
    179                     mRemote.transact(Stub.TRANSACTION_unmountVolume, _data, _reply, 0);
    180                     _reply.readException();
    181                 } finally {
    182                     _reply.recycle();
    183                     _data.recycle();
    184                 }
    185             }
    186 
    187             /**
    188              * Format external storage given a mount point. Returns an int
    189              * consistent with MountServiceResultCode
    190              */
    191             public int formatVolume(String mountPoint) throws RemoteException {
    192                 Parcel _data = Parcel.obtain();
    193                 Parcel _reply = Parcel.obtain();
    194                 int _result;
    195                 try {
    196                     _data.writeInterfaceToken(DESCRIPTOR);
    197                     _data.writeString(mountPoint);
    198                     mRemote.transact(Stub.TRANSACTION_formatVolume, _data, _reply, 0);
    199                     _reply.readException();
    200                     _result = _reply.readInt();
    201                 } finally {
    202                     _reply.recycle();
    203                     _data.recycle();
    204                 }
    205                 return _result;
    206             }
    207 
    208             /**
    209              * Returns an array of pids with open files on the specified path.
    210              */
    211             public int[] getStorageUsers(String path) throws RemoteException {
    212                 Parcel _data = Parcel.obtain();
    213                 Parcel _reply = Parcel.obtain();
    214                 int[] _result;
    215                 try {
    216                     _data.writeInterfaceToken(DESCRIPTOR);
    217                     _data.writeString(path);
    218                     mRemote.transact(Stub.TRANSACTION_getStorageUsers, _data, _reply, 0);
    219                     _reply.readException();
    220                     _result = _reply.createIntArray();
    221                 } finally {
    222                     _reply.recycle();
    223                     _data.recycle();
    224                 }
    225                 return _result;
    226             }
    227 
    228             /**
    229              * Gets the state of a volume via its mountpoint.
    230              */
    231             public String getVolumeState(String mountPoint) throws RemoteException {
    232                 Parcel _data = Parcel.obtain();
    233                 Parcel _reply = Parcel.obtain();
    234                 String _result;
    235                 try {
    236                     _data.writeInterfaceToken(DESCRIPTOR);
    237                     _data.writeString(mountPoint);
    238                     mRemote.transact(Stub.TRANSACTION_getVolumeState, _data, _reply, 0);
    239                     _reply.readException();
    240                     _result = _reply.readString();
    241                 } finally {
    242                     _reply.recycle();
    243                     _data.recycle();
    244                 }
    245                 return _result;
    246             }
    247 
    248             /*
    249              * Creates a secure container with the specified parameters. Returns
    250              * an int consistent with MountServiceResultCode
    251              */
    252             public int createSecureContainer(String id, int sizeMb, String fstype, String key,
    253                     int ownerUid, boolean external) throws RemoteException {
    254                 Parcel _data = Parcel.obtain();
    255                 Parcel _reply = Parcel.obtain();
    256                 int _result;
    257                 try {
    258                     _data.writeInterfaceToken(DESCRIPTOR);
    259                     _data.writeString(id);
    260                     _data.writeInt(sizeMb);
    261                     _data.writeString(fstype);
    262                     _data.writeString(key);
    263                     _data.writeInt(ownerUid);
    264                     _data.writeInt(external ? 1 : 0);
    265                     mRemote.transact(Stub.TRANSACTION_createSecureContainer, _data, _reply, 0);
    266                     _reply.readException();
    267                     _result = _reply.readInt();
    268                 } finally {
    269                     _reply.recycle();
    270                     _data.recycle();
    271                 }
    272                 return _result;
    273             }
    274 
    275             /*
    276              * Destroy a secure container, and free up all resources associated
    277              * with it. NOTE: Ensure all references are released prior to
    278              * deleting. Returns an int consistent with MountServiceResultCode
    279              */
    280             public int destroySecureContainer(String id, boolean force) throws RemoteException {
    281                 Parcel _data = Parcel.obtain();
    282                 Parcel _reply = Parcel.obtain();
    283                 int _result;
    284                 try {
    285                     _data.writeInterfaceToken(DESCRIPTOR);
    286                     _data.writeString(id);
    287                     _data.writeInt((force ? 1 : 0));
    288                     mRemote.transact(Stub.TRANSACTION_destroySecureContainer, _data, _reply, 0);
    289                     _reply.readException();
    290                     _result = _reply.readInt();
    291                 } finally {
    292                     _reply.recycle();
    293                     _data.recycle();
    294                 }
    295                 return _result;
    296             }
    297 
    298             /*
    299              * Finalize a container which has just been created and populated.
    300              * After finalization, the container is immutable. Returns an int
    301              * consistent with MountServiceResultCode
    302              */
    303             public int finalizeSecureContainer(String id) throws RemoteException {
    304                 Parcel _data = Parcel.obtain();
    305                 Parcel _reply = Parcel.obtain();
    306                 int _result;
    307                 try {
    308                     _data.writeInterfaceToken(DESCRIPTOR);
    309                     _data.writeString(id);
    310                     mRemote.transact(Stub.TRANSACTION_finalizeSecureContainer, _data, _reply, 0);
    311                     _reply.readException();
    312                     _result = _reply.readInt();
    313                 } finally {
    314                     _reply.recycle();
    315                     _data.recycle();
    316                 }
    317                 return _result;
    318             }
    319 
    320             /*
    321              * Mount a secure container with the specified key and owner UID.
    322              * Returns an int consistent with MountServiceResultCode
    323              */
    324             public int mountSecureContainer(String id, String key, int ownerUid, boolean readOnly)
    325                     throws RemoteException {
    326                 Parcel _data = Parcel.obtain();
    327                 Parcel _reply = Parcel.obtain();
    328                 int _result;
    329                 try {
    330                     _data.writeInterfaceToken(DESCRIPTOR);
    331                     _data.writeString(id);
    332                     _data.writeString(key);
    333                     _data.writeInt(ownerUid);
    334                     _data.writeInt(readOnly ? 1 : 0);
    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 rawPath, String canonicalPath, String key,
    492                     IObbActionListener token, int nonce) throws RemoteException {
    493                 Parcel _data = Parcel.obtain();
    494                 Parcel _reply = Parcel.obtain();
    495                 try {
    496                     _data.writeInterfaceToken(DESCRIPTOR);
    497                     _data.writeString(rawPath);
    498                     _data.writeString(canonicalPath);
    499                     _data.writeString(key);
    500                     _data.writeStrongBinder((token != null ? token.asBinder() : null));
    501                     _data.writeInt(nonce);
    502                     mRemote.transact(Stub.TRANSACTION_mountObb, _data, _reply, 0);
    503                     _reply.readException();
    504                 } finally {
    505                     _reply.recycle();
    506                     _data.recycle();
    507                 }
    508             }
    509 
    510             /**
    511              * Unmounts an Opaque Binary Blob (OBB). When the force flag is
    512              * specified, any program using it will be forcibly killed to
    513              * unmount the image. MountService will call back to the supplied
    514              * IObbActionListener to inform it of the terminal state of the
    515              * call.
    516              */
    517             public void unmountObb(
    518                     String rawPath, boolean force, IObbActionListener token, int nonce)
    519                     throws RemoteException {
    520                 Parcel _data = Parcel.obtain();
    521                 Parcel _reply = Parcel.obtain();
    522                 try {
    523                     _data.writeInterfaceToken(DESCRIPTOR);
    524                     _data.writeString(rawPath);
    525                     _data.writeInt((force ? 1 : 0));
    526                     _data.writeStrongBinder((token != null ? token.asBinder() : null));
    527                     _data.writeInt(nonce);
    528                     mRemote.transact(Stub.TRANSACTION_unmountObb, _data, _reply, 0);
    529                     _reply.readException();
    530                 } finally {
    531                     _reply.recycle();
    532                     _data.recycle();
    533                 }
    534             }
    535 
    536             /**
    537              * Checks whether the specified Opaque Binary Blob (OBB) is mounted
    538              * somewhere.
    539              */
    540             public boolean isObbMounted(String rawPath) throws RemoteException {
    541                 Parcel _data = Parcel.obtain();
    542                 Parcel _reply = Parcel.obtain();
    543                 boolean _result;
    544                 try {
    545                     _data.writeInterfaceToken(DESCRIPTOR);
    546                     _data.writeString(rawPath);
    547                     mRemote.transact(Stub.TRANSACTION_isObbMounted, _data, _reply, 0);
    548                     _reply.readException();
    549                     _result = 0 != _reply.readInt();
    550                 } finally {
    551                     _reply.recycle();
    552                     _data.recycle();
    553                 }
    554                 return _result;
    555             }
    556 
    557             /**
    558              * Gets the path to the mounted Opaque Binary Blob (OBB).
    559              */
    560             public String getMountedObbPath(String rawPath) throws RemoteException {
    561                 Parcel _data = Parcel.obtain();
    562                 Parcel _reply = Parcel.obtain();
    563                 String _result;
    564                 try {
    565                     _data.writeInterfaceToken(DESCRIPTOR);
    566                     _data.writeString(rawPath);
    567                     mRemote.transact(Stub.TRANSACTION_getMountedObbPath, _data, _reply, 0);
    568                     _reply.readException();
    569                     _result = _reply.readString();
    570                 } finally {
    571                     _reply.recycle();
    572                     _data.recycle();
    573                 }
    574                 return _result;
    575             }
    576 
    577             /**
    578              * Returns whether the external storage is emulated.
    579              */
    580             public boolean isExternalStorageEmulated() throws RemoteException {
    581                 Parcel _data = Parcel.obtain();
    582                 Parcel _reply = Parcel.obtain();
    583                 boolean _result;
    584                 try {
    585                     _data.writeInterfaceToken(DESCRIPTOR);
    586                     mRemote.transact(Stub.TRANSACTION_isExternalStorageEmulated, _data, _reply, 0);
    587                     _reply.readException();
    588                     _result = 0 != _reply.readInt();
    589                 } finally {
    590                     _reply.recycle();
    591                     _data.recycle();
    592                 }
    593                 return _result;
    594             }
    595 
    596             public int getEncryptionState() throws RemoteException {
    597                 Parcel _data = Parcel.obtain();
    598                 Parcel _reply = Parcel.obtain();
    599                 int _result;
    600                 try {
    601                     _data.writeInterfaceToken(DESCRIPTOR);
    602                     mRemote.transact(Stub.TRANSACTION_getEncryptionState, _data, _reply, 0);
    603                     _reply.readException();
    604                     _result = _reply.readInt();
    605                 } finally {
    606                     _reply.recycle();
    607                     _data.recycle();
    608                 }
    609                 return _result;
    610             }
    611 
    612             public int decryptStorage(String password) throws RemoteException {
    613                 Parcel _data = Parcel.obtain();
    614                 Parcel _reply = Parcel.obtain();
    615                 int _result;
    616                 try {
    617                     _data.writeInterfaceToken(DESCRIPTOR);
    618                     _data.writeString(password);
    619                     mRemote.transact(Stub.TRANSACTION_decryptStorage, _data, _reply, 0);
    620                     _reply.readException();
    621                     _result = _reply.readInt();
    622                 } finally {
    623                     _reply.recycle();
    624                     _data.recycle();
    625                 }
    626                 return _result;
    627             }
    628 
    629             public int encryptStorage(int type, String password) throws RemoteException {
    630                 Parcel _data = Parcel.obtain();
    631                 Parcel _reply = Parcel.obtain();
    632                 int _result;
    633                 try {
    634                     _data.writeInterfaceToken(DESCRIPTOR);
    635                     _data.writeInt(type);
    636                     _data.writeString(password);
    637                     mRemote.transact(Stub.TRANSACTION_encryptStorage, _data, _reply, 0);
    638                     _reply.readException();
    639                     _result = _reply.readInt();
    640                 } finally {
    641                     _reply.recycle();
    642                     _data.recycle();
    643                 }
    644                 return _result;
    645             }
    646 
    647             public int changeEncryptionPassword(int type, String password) throws RemoteException {
    648                 Parcel _data = Parcel.obtain();
    649                 Parcel _reply = Parcel.obtain();
    650                 int _result;
    651                 try {
    652                     _data.writeInterfaceToken(DESCRIPTOR);
    653                     _data.writeInt(type);
    654                     _data.writeString(password);
    655                     mRemote.transact(Stub.TRANSACTION_changeEncryptionPassword, _data, _reply, 0);
    656                     _reply.readException();
    657                     _result = _reply.readInt();
    658                 } finally {
    659                     _reply.recycle();
    660                     _data.recycle();
    661                 }
    662                 return _result;
    663             }
    664 
    665             @Override
    666             public int verifyEncryptionPassword(String password) throws RemoteException {
    667                 Parcel _data = Parcel.obtain();
    668                 Parcel _reply = Parcel.obtain();
    669                 int _result;
    670                 try {
    671                     _data.writeInterfaceToken(DESCRIPTOR);
    672                     _data.writeString(password);
    673                     mRemote.transact(Stub.TRANSACTION_verifyEncryptionPassword, _data, _reply, 0);
    674                     _reply.readException();
    675                     _result = _reply.readInt();
    676                 } finally {
    677                     _reply.recycle();
    678                     _data.recycle();
    679                 }
    680                 return _result;
    681             }
    682 
    683             public int getPasswordType() throws RemoteException {
    684                 Parcel _data = Parcel.obtain();
    685                 Parcel _reply = Parcel.obtain();
    686                 int _result;
    687                 try {
    688                     _data.writeInterfaceToken(DESCRIPTOR);
    689                     mRemote.transact(Stub.TRANSACTION_getPasswordType, _data, _reply, 0);
    690                     _reply.readException();
    691                     _result = _reply.readInt();
    692                 } finally {
    693                     _reply.recycle();
    694                     _data.recycle();
    695                 }
    696                 return _result;
    697             }
    698 
    699             public String getPassword() throws RemoteException {
    700                 Parcel _data = Parcel.obtain();
    701                 Parcel _reply = Parcel.obtain();
    702                 String _result;
    703                 try {
    704                     _data.writeInterfaceToken(DESCRIPTOR);
    705                     mRemote.transact(Stub.TRANSACTION_getPassword, _data, _reply, 0);
    706                     _reply.readException();
    707                     _result = _reply.readString();
    708                 } finally {
    709                     _reply.recycle();
    710                     _data.recycle();
    711                 }
    712                 return _result;
    713             }
    714 
    715             public void clearPassword() throws RemoteException {
    716                 Parcel _data = Parcel.obtain();
    717                 Parcel _reply = Parcel.obtain();
    718                 try {
    719                     _data.writeInterfaceToken(DESCRIPTOR);
    720                     mRemote.transact(Stub.TRANSACTION_clearPassword, _data, _reply, IBinder.FLAG_ONEWAY);
    721                     _reply.readException();
    722                 } finally {
    723                     _reply.recycle();
    724                     _data.recycle();
    725                 }
    726             }
    727 
    728             public void setField(String field, String data) throws RemoteException {
    729                 Parcel _data = Parcel.obtain();
    730                 Parcel _reply = Parcel.obtain();
    731                 try {
    732                     _data.writeInterfaceToken(DESCRIPTOR);
    733                     _data.writeString(field);
    734                     _data.writeString(data);
    735                     mRemote.transact(Stub.TRANSACTION_setField, _data, _reply, IBinder.FLAG_ONEWAY);
    736                     _reply.readException();
    737                 } finally {
    738                     _reply.recycle();
    739                     _data.recycle();
    740                 }
    741             }
    742 
    743             public String getField(String field) throws RemoteException {
    744                 Parcel _data = Parcel.obtain();
    745                 Parcel _reply = Parcel.obtain();
    746                 String _result;
    747                 try {
    748                     _data.writeInterfaceToken(DESCRIPTOR);
    749                     _data.writeString(field);
    750                     mRemote.transact(Stub.TRANSACTION_getField, _data, _reply, 0);
    751                     _reply.readException();
    752                     _result = _reply.readString();
    753                 } finally {
    754                     _reply.recycle();
    755                     _data.recycle();
    756                 }
    757                 return _result;
    758             }
    759 
    760             public StorageVolume[] getVolumeList() throws RemoteException {
    761                 Parcel _data = Parcel.obtain();
    762                 Parcel _reply = Parcel.obtain();
    763                 StorageVolume[] _result;
    764                 try {
    765                     _data.writeInterfaceToken(DESCRIPTOR);
    766                     mRemote.transact(Stub.TRANSACTION_getVolumeList, _data, _reply, 0);
    767                     _reply.readException();
    768                     _result = _reply.createTypedArray(StorageVolume.CREATOR);
    769                 } finally {
    770                     _reply.recycle();
    771                     _data.recycle();
    772                 }
    773                 return _result;
    774             }
    775 
    776             /*
    777              * Returns the filesystem path of a mounted secure container.
    778              */
    779             public String getSecureContainerFilesystemPath(String id) throws RemoteException {
    780                 Parcel _data = Parcel.obtain();
    781                 Parcel _reply = Parcel.obtain();
    782                 String _result;
    783                 try {
    784                     _data.writeInterfaceToken(DESCRIPTOR);
    785                     _data.writeString(id);
    786                     mRemote.transact(Stub.TRANSACTION_getSecureContainerFilesystemPath, _data, _reply, 0);
    787                     _reply.readException();
    788                     _result = _reply.readString();
    789                 } finally {
    790                     _reply.recycle();
    791                     _data.recycle();
    792                 }
    793                 return _result;
    794             }
    795 
    796             /**
    797              * Fix permissions in a container which has just been created and
    798              * populated. Returns an int consistent with MountServiceResultCode
    799              */
    800             public int fixPermissionsSecureContainer(String id, int gid, String filename)
    801                     throws RemoteException {
    802                 Parcel _data = Parcel.obtain();
    803                 Parcel _reply = Parcel.obtain();
    804                 int _result;
    805                 try {
    806                     _data.writeInterfaceToken(DESCRIPTOR);
    807                     _data.writeString(id);
    808                     _data.writeInt(gid);
    809                     _data.writeString(filename);
    810                     mRemote.transact(Stub.TRANSACTION_fixPermissionsSecureContainer, _data, _reply, 0);
    811                     _reply.readException();
    812                     _result = _reply.readInt();
    813                 } finally {
    814                     _reply.recycle();
    815                     _data.recycle();
    816                 }
    817                 return _result;
    818             }
    819 
    820             @Override
    821             public int mkdirs(String callingPkg, String path) throws RemoteException {
    822                 Parcel _data = Parcel.obtain();
    823                 Parcel _reply = Parcel.obtain();
    824                 int _result;
    825                 try {
    826                     _data.writeInterfaceToken(DESCRIPTOR);
    827                     _data.writeString(callingPkg);
    828                     _data.writeString(path);
    829                     mRemote.transact(Stub.TRANSACTION_mkdirs, _data, _reply, 0);
    830                     _reply.readException();
    831                     _result = _reply.readInt();
    832                 } finally {
    833                     _reply.recycle();
    834                     _data.recycle();
    835                 }
    836                 return _result;
    837             }
    838 
    839             @Override
    840             public int resizeSecureContainer(String id, int sizeMb, String key)
    841                     throws RemoteException {
    842                 Parcel _data = Parcel.obtain();
    843                 Parcel _reply = Parcel.obtain();
    844                 int _result;
    845                 try {
    846                     _data.writeInterfaceToken(DESCRIPTOR);
    847                     _data.writeString(id);
    848                     _data.writeInt(sizeMb);
    849                     _data.writeString(key);
    850                     mRemote.transact(Stub.TRANSACTION_resizeSecureContainer, _data, _reply, 0);
    851                     _reply.readException();
    852                     _result = _reply.readInt();
    853                 } finally {
    854                     _reply.recycle();
    855                     _data.recycle();
    856                 }
    857                 return _result;
    858             }
    859         }
    860 
    861         private static final String DESCRIPTOR = "IMountService";
    862 
    863         static final int TRANSACTION_registerListener = IBinder.FIRST_CALL_TRANSACTION + 0;
    864 
    865         static final int TRANSACTION_unregisterListener = IBinder.FIRST_CALL_TRANSACTION + 1;
    866 
    867         static final int TRANSACTION_isUsbMassStorageConnected = IBinder.FIRST_CALL_TRANSACTION + 2;
    868 
    869         static final int TRANSACTION_setUsbMassStorageEnabled = IBinder.FIRST_CALL_TRANSACTION + 3;
    870 
    871         static final int TRANSACTION_isUsbMassStorageEnabled = IBinder.FIRST_CALL_TRANSACTION + 4;
    872 
    873         static final int TRANSACTION_mountVolume = IBinder.FIRST_CALL_TRANSACTION + 5;
    874 
    875         static final int TRANSACTION_unmountVolume = IBinder.FIRST_CALL_TRANSACTION + 6;
    876 
    877         static final int TRANSACTION_formatVolume = IBinder.FIRST_CALL_TRANSACTION + 7;
    878 
    879         static final int TRANSACTION_getStorageUsers = IBinder.FIRST_CALL_TRANSACTION + 8;
    880 
    881         static final int TRANSACTION_getVolumeState = IBinder.FIRST_CALL_TRANSACTION + 9;
    882 
    883         static final int TRANSACTION_createSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 10;
    884 
    885         static final int TRANSACTION_finalizeSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 11;
    886 
    887         static final int TRANSACTION_destroySecureContainer = IBinder.FIRST_CALL_TRANSACTION + 12;
    888 
    889         static final int TRANSACTION_mountSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 13;
    890 
    891         static final int TRANSACTION_unmountSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 14;
    892 
    893         static final int TRANSACTION_isSecureContainerMounted = IBinder.FIRST_CALL_TRANSACTION + 15;
    894 
    895         static final int TRANSACTION_renameSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 16;
    896 
    897         static final int TRANSACTION_getSecureContainerPath = IBinder.FIRST_CALL_TRANSACTION + 17;
    898 
    899         static final int TRANSACTION_getSecureContainerList = IBinder.FIRST_CALL_TRANSACTION + 18;
    900 
    901         static final int TRANSACTION_shutdown = IBinder.FIRST_CALL_TRANSACTION + 19;
    902 
    903         static final int TRANSACTION_finishMediaUpdate = IBinder.FIRST_CALL_TRANSACTION + 20;
    904 
    905         static final int TRANSACTION_mountObb = IBinder.FIRST_CALL_TRANSACTION + 21;
    906 
    907         static final int TRANSACTION_unmountObb = IBinder.FIRST_CALL_TRANSACTION + 22;
    908 
    909         static final int TRANSACTION_isObbMounted = IBinder.FIRST_CALL_TRANSACTION + 23;
    910 
    911         static final int TRANSACTION_getMountedObbPath = IBinder.FIRST_CALL_TRANSACTION + 24;
    912 
    913         static final int TRANSACTION_isExternalStorageEmulated = IBinder.FIRST_CALL_TRANSACTION + 25;
    914 
    915         static final int TRANSACTION_decryptStorage = IBinder.FIRST_CALL_TRANSACTION + 26;
    916 
    917         static final int TRANSACTION_encryptStorage = IBinder.FIRST_CALL_TRANSACTION + 27;
    918 
    919         static final int TRANSACTION_changeEncryptionPassword = IBinder.FIRST_CALL_TRANSACTION + 28;
    920 
    921         static final int TRANSACTION_getVolumeList = IBinder.FIRST_CALL_TRANSACTION + 29;
    922 
    923         static final int TRANSACTION_getSecureContainerFilesystemPath = IBinder.FIRST_CALL_TRANSACTION + 30;
    924 
    925         static final int TRANSACTION_getEncryptionState = IBinder.FIRST_CALL_TRANSACTION + 31;
    926 
    927         static final int TRANSACTION_verifyEncryptionPassword = IBinder.FIRST_CALL_TRANSACTION + 32;
    928 
    929         static final int TRANSACTION_fixPermissionsSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 33;
    930 
    931         static final int TRANSACTION_mkdirs = IBinder.FIRST_CALL_TRANSACTION + 34;
    932 
    933         static final int TRANSACTION_getPasswordType = IBinder.FIRST_CALL_TRANSACTION + 35;
    934 
    935         static final int TRANSACTION_getPassword = IBinder.FIRST_CALL_TRANSACTION + 36;
    936 
    937         static final int TRANSACTION_clearPassword = IBinder.FIRST_CALL_TRANSACTION + 37;
    938 
    939         static final int TRANSACTION_setField = IBinder.FIRST_CALL_TRANSACTION + 38;
    940 
    941         static final int TRANSACTION_getField = IBinder.FIRST_CALL_TRANSACTION + 39;
    942 
    943         static final int TRANSACTION_resizeSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 40;
    944 
    945         /**
    946          * Cast an IBinder object into an IMountService interface, generating a
    947          * proxy if needed.
    948          */
    949         public static IMountService asInterface(IBinder obj) {
    950             if (obj == null) {
    951                 return null;
    952             }
    953             IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
    954             if (iin != null && iin instanceof IMountService) {
    955                 return (IMountService) iin;
    956             }
    957             return new IMountService.Stub.Proxy(obj);
    958         }
    959 
    960         /** Construct the stub at attach it to the interface. */
    961         public Stub() {
    962             attachInterface(this, DESCRIPTOR);
    963         }
    964 
    965         public IBinder asBinder() {
    966             return this;
    967         }
    968 
    969         @Override
    970         public boolean onTransact(int code, Parcel data, Parcel reply,
    971                 int flags) throws RemoteException {
    972             switch (code) {
    973                 case INTERFACE_TRANSACTION: {
    974                     reply.writeString(DESCRIPTOR);
    975                     return true;
    976                 }
    977                 case TRANSACTION_registerListener: {
    978                     data.enforceInterface(DESCRIPTOR);
    979                     IMountServiceListener listener;
    980                     listener = IMountServiceListener.Stub.asInterface(data.readStrongBinder());
    981                     registerListener(listener);
    982                     reply.writeNoException();
    983                     return true;
    984                 }
    985                 case TRANSACTION_unregisterListener: {
    986                     data.enforceInterface(DESCRIPTOR);
    987                     IMountServiceListener listener;
    988                     listener = IMountServiceListener.Stub.asInterface(data.readStrongBinder());
    989                     unregisterListener(listener);
    990                     reply.writeNoException();
    991                     return true;
    992                 }
    993                 case TRANSACTION_isUsbMassStorageConnected: {
    994                     data.enforceInterface(DESCRIPTOR);
    995                     boolean result = isUsbMassStorageConnected();
    996                     reply.writeNoException();
    997                     reply.writeInt((result ? 1 : 0));
    998                     return true;
    999                 }
   1000                 case TRANSACTION_setUsbMassStorageEnabled: {
   1001                     data.enforceInterface(DESCRIPTOR);
   1002                     boolean enable;
   1003                     enable = 0 != data.readInt();
   1004                     setUsbMassStorageEnabled(enable);
   1005                     reply.writeNoException();
   1006                     return true;
   1007                 }
   1008                 case TRANSACTION_isUsbMassStorageEnabled: {
   1009                     data.enforceInterface(DESCRIPTOR);
   1010                     boolean result = isUsbMassStorageEnabled();
   1011                     reply.writeNoException();
   1012                     reply.writeInt((result ? 1 : 0));
   1013                     return true;
   1014                 }
   1015                 case TRANSACTION_mountVolume: {
   1016                     data.enforceInterface(DESCRIPTOR);
   1017                     String mountPoint;
   1018                     mountPoint = data.readString();
   1019                     int resultCode = mountVolume(mountPoint);
   1020                     reply.writeNoException();
   1021                     reply.writeInt(resultCode);
   1022                     return true;
   1023                 }
   1024                 case TRANSACTION_unmountVolume: {
   1025                     data.enforceInterface(DESCRIPTOR);
   1026                     String mountPoint;
   1027                     mountPoint = data.readString();
   1028                     boolean force = 0 != data.readInt();
   1029                     boolean removeEncrypt = 0 != data.readInt();
   1030                     unmountVolume(mountPoint, force, removeEncrypt);
   1031                     reply.writeNoException();
   1032                     return true;
   1033                 }
   1034                 case TRANSACTION_formatVolume: {
   1035                     data.enforceInterface(DESCRIPTOR);
   1036                     String mountPoint;
   1037                     mountPoint = data.readString();
   1038                     int result = formatVolume(mountPoint);
   1039                     reply.writeNoException();
   1040                     reply.writeInt(result);
   1041                     return true;
   1042                 }
   1043                 case TRANSACTION_getStorageUsers: {
   1044                     data.enforceInterface(DESCRIPTOR);
   1045                     String path;
   1046                     path = data.readString();
   1047                     int[] pids = getStorageUsers(path);
   1048                     reply.writeNoException();
   1049                     reply.writeIntArray(pids);
   1050                     return true;
   1051                 }
   1052                 case TRANSACTION_getVolumeState: {
   1053                     data.enforceInterface(DESCRIPTOR);
   1054                     String mountPoint;
   1055                     mountPoint = data.readString();
   1056                     String state = getVolumeState(mountPoint);
   1057                     reply.writeNoException();
   1058                     reply.writeString(state);
   1059                     return true;
   1060                 }
   1061                 case TRANSACTION_createSecureContainer: {
   1062                     data.enforceInterface(DESCRIPTOR);
   1063                     String id;
   1064                     id = data.readString();
   1065                     int sizeMb;
   1066                     sizeMb = data.readInt();
   1067                     String fstype;
   1068                     fstype = data.readString();
   1069                     String key;
   1070                     key = data.readString();
   1071                     int ownerUid;
   1072                     ownerUid = data.readInt();
   1073                     boolean external;
   1074                     external = 0 != data.readInt();
   1075                     int resultCode = createSecureContainer(id, sizeMb, fstype, key, ownerUid,
   1076                             external);
   1077                     reply.writeNoException();
   1078                     reply.writeInt(resultCode);
   1079                     return true;
   1080                 }
   1081                 case TRANSACTION_finalizeSecureContainer: {
   1082                     data.enforceInterface(DESCRIPTOR);
   1083                     String id;
   1084                     id = data.readString();
   1085                     int resultCode = finalizeSecureContainer(id);
   1086                     reply.writeNoException();
   1087                     reply.writeInt(resultCode);
   1088                     return true;
   1089                 }
   1090                 case TRANSACTION_destroySecureContainer: {
   1091                     data.enforceInterface(DESCRIPTOR);
   1092                     String id;
   1093                     id = data.readString();
   1094                     boolean force;
   1095                     force = 0 != data.readInt();
   1096                     int resultCode = destroySecureContainer(id, force);
   1097                     reply.writeNoException();
   1098                     reply.writeInt(resultCode);
   1099                     return true;
   1100                 }
   1101                 case TRANSACTION_mountSecureContainer: {
   1102                     data.enforceInterface(DESCRIPTOR);
   1103                     String id;
   1104                     id = data.readString();
   1105                     String key;
   1106                     key = data.readString();
   1107                     int ownerUid;
   1108                     ownerUid = data.readInt();
   1109                     boolean readOnly;
   1110                     readOnly = data.readInt() != 0;
   1111                     int resultCode = mountSecureContainer(id, key, ownerUid, readOnly);
   1112                     reply.writeNoException();
   1113                     reply.writeInt(resultCode);
   1114                     return true;
   1115                 }
   1116                 case TRANSACTION_unmountSecureContainer: {
   1117                     data.enforceInterface(DESCRIPTOR);
   1118                     String id;
   1119                     id = data.readString();
   1120                     boolean force;
   1121                     force = 0 != data.readInt();
   1122                     int resultCode = unmountSecureContainer(id, force);
   1123                     reply.writeNoException();
   1124                     reply.writeInt(resultCode);
   1125                     return true;
   1126                 }
   1127                 case TRANSACTION_isSecureContainerMounted: {
   1128                     data.enforceInterface(DESCRIPTOR);
   1129                     String id;
   1130                     id = data.readString();
   1131                     boolean status = isSecureContainerMounted(id);
   1132                     reply.writeNoException();
   1133                     reply.writeInt((status ? 1 : 0));
   1134                     return true;
   1135                 }
   1136                 case TRANSACTION_renameSecureContainer: {
   1137                     data.enforceInterface(DESCRIPTOR);
   1138                     String oldId;
   1139                     oldId = data.readString();
   1140                     String newId;
   1141                     newId = data.readString();
   1142                     int resultCode = renameSecureContainer(oldId, newId);
   1143                     reply.writeNoException();
   1144                     reply.writeInt(resultCode);
   1145                     return true;
   1146                 }
   1147                 case TRANSACTION_getSecureContainerPath: {
   1148                     data.enforceInterface(DESCRIPTOR);
   1149                     String id;
   1150                     id = data.readString();
   1151                     String path = getSecureContainerPath(id);
   1152                     reply.writeNoException();
   1153                     reply.writeString(path);
   1154                     return true;
   1155                 }
   1156                 case TRANSACTION_getSecureContainerList: {
   1157                     data.enforceInterface(DESCRIPTOR);
   1158                     String[] ids = getSecureContainerList();
   1159                     reply.writeNoException();
   1160                     reply.writeStringArray(ids);
   1161                     return true;
   1162                 }
   1163                 case TRANSACTION_shutdown: {
   1164                     data.enforceInterface(DESCRIPTOR);
   1165                     IMountShutdownObserver observer;
   1166                     observer = IMountShutdownObserver.Stub.asInterface(data
   1167                             .readStrongBinder());
   1168                     shutdown(observer);
   1169                     reply.writeNoException();
   1170                     return true;
   1171                 }
   1172                 case TRANSACTION_finishMediaUpdate: {
   1173                     data.enforceInterface(DESCRIPTOR);
   1174                     finishMediaUpdate();
   1175                     reply.writeNoException();
   1176                     return true;
   1177                 }
   1178                 case TRANSACTION_mountObb: {
   1179                     data.enforceInterface(DESCRIPTOR);
   1180                     final String rawPath = data.readString();
   1181                     final String canonicalPath = data.readString();
   1182                     final String key = data.readString();
   1183                     IObbActionListener observer;
   1184                     observer = IObbActionListener.Stub.asInterface(data.readStrongBinder());
   1185                     int nonce;
   1186                     nonce = data.readInt();
   1187                     mountObb(rawPath, canonicalPath, key, observer, nonce);
   1188                     reply.writeNoException();
   1189                     return true;
   1190                 }
   1191                 case TRANSACTION_unmountObb: {
   1192                     data.enforceInterface(DESCRIPTOR);
   1193                     String filename;
   1194                     filename = data.readString();
   1195                     boolean force;
   1196                     force = 0 != data.readInt();
   1197                     IObbActionListener observer;
   1198                     observer = IObbActionListener.Stub.asInterface(data.readStrongBinder());
   1199                     int nonce;
   1200                     nonce = data.readInt();
   1201                     unmountObb(filename, force, observer, nonce);
   1202                     reply.writeNoException();
   1203                     return true;
   1204                 }
   1205                 case TRANSACTION_isObbMounted: {
   1206                     data.enforceInterface(DESCRIPTOR);
   1207                     String filename;
   1208                     filename = data.readString();
   1209                     boolean status = isObbMounted(filename);
   1210                     reply.writeNoException();
   1211                     reply.writeInt((status ? 1 : 0));
   1212                     return true;
   1213                 }
   1214                 case TRANSACTION_getMountedObbPath: {
   1215                     data.enforceInterface(DESCRIPTOR);
   1216                     String filename;
   1217                     filename = data.readString();
   1218                     String mountedPath = getMountedObbPath(filename);
   1219                     reply.writeNoException();
   1220                     reply.writeString(mountedPath);
   1221                     return true;
   1222                 }
   1223                 case TRANSACTION_isExternalStorageEmulated: {
   1224                     data.enforceInterface(DESCRIPTOR);
   1225                     boolean emulated = isExternalStorageEmulated();
   1226                     reply.writeNoException();
   1227                     reply.writeInt(emulated ? 1 : 0);
   1228                     return true;
   1229                 }
   1230                 case TRANSACTION_decryptStorage: {
   1231                     data.enforceInterface(DESCRIPTOR);
   1232                     String password = data.readString();
   1233                     int result = decryptStorage(password);
   1234                     reply.writeNoException();
   1235                     reply.writeInt(result);
   1236                     return true;
   1237                 }
   1238                 case TRANSACTION_encryptStorage: {
   1239                     data.enforceInterface(DESCRIPTOR);
   1240                     int type = data.readInt();
   1241                     String password = data.readString();
   1242                     int result = encryptStorage(type, password);
   1243                     reply.writeNoException();
   1244                     reply.writeInt(result);
   1245                     return true;
   1246                 }
   1247                 case TRANSACTION_changeEncryptionPassword: {
   1248                     data.enforceInterface(DESCRIPTOR);
   1249                     int type = data.readInt();
   1250                     String password = data.readString();
   1251                     int result = changeEncryptionPassword(type, password);
   1252                     reply.writeNoException();
   1253                     reply.writeInt(result);
   1254                     return true;
   1255                 }
   1256                 case TRANSACTION_getVolumeList: {
   1257                     data.enforceInterface(DESCRIPTOR);
   1258                     StorageVolume[] result = getVolumeList();
   1259                     reply.writeNoException();
   1260                     reply.writeTypedArray(result, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
   1261                     return true;
   1262                 }
   1263                 case TRANSACTION_getSecureContainerFilesystemPath: {
   1264                     data.enforceInterface(DESCRIPTOR);
   1265                     String id;
   1266                     id = data.readString();
   1267                     String path = getSecureContainerFilesystemPath(id);
   1268                     reply.writeNoException();
   1269                     reply.writeString(path);
   1270                     return true;
   1271                 }
   1272                 case TRANSACTION_getEncryptionState: {
   1273                     data.enforceInterface(DESCRIPTOR);
   1274                     int result = getEncryptionState();
   1275                     reply.writeNoException();
   1276                     reply.writeInt(result);
   1277                     return true;
   1278                 }
   1279                 case TRANSACTION_fixPermissionsSecureContainer: {
   1280                     data.enforceInterface(DESCRIPTOR);
   1281                     String id;
   1282                     id = data.readString();
   1283                     int gid;
   1284                     gid = data.readInt();
   1285                     String filename;
   1286                     filename = data.readString();
   1287                     int resultCode = fixPermissionsSecureContainer(id, gid, filename);
   1288                     reply.writeNoException();
   1289                     reply.writeInt(resultCode);
   1290                     return true;
   1291                 }
   1292                 case TRANSACTION_mkdirs: {
   1293                     data.enforceInterface(DESCRIPTOR);
   1294                     String callingPkg = data.readString();
   1295                     String path = data.readString();
   1296                     int result = mkdirs(callingPkg, path);
   1297                     reply.writeNoException();
   1298                     reply.writeInt(result);
   1299                     return true;
   1300                 }
   1301                 case TRANSACTION_getPasswordType: {
   1302                     data.enforceInterface(DESCRIPTOR);
   1303                     int result = getPasswordType();
   1304                     reply.writeNoException();
   1305                     reply.writeInt(result);
   1306                     return true;
   1307                 }
   1308                 case TRANSACTION_getPassword: {
   1309                     data.enforceInterface(DESCRIPTOR);
   1310                     String result = getPassword();
   1311                     reply.writeNoException();
   1312                     reply.writeString(result);
   1313                     return true;
   1314                 }
   1315                 case TRANSACTION_clearPassword: {
   1316                     data.enforceInterface(DESCRIPTOR);
   1317                     clearPassword();
   1318                     reply.writeNoException();
   1319                     return true;
   1320                 }
   1321                 case TRANSACTION_setField: {
   1322                     data.enforceInterface(DESCRIPTOR);
   1323                     String field = data.readString();
   1324                     String contents = data.readString();
   1325                     setField(field, contents);
   1326                     reply.writeNoException();
   1327                     return true;
   1328                 }
   1329                 case TRANSACTION_getField: {
   1330                     data.enforceInterface(DESCRIPTOR);
   1331                     String field = data.readString();
   1332                     String contents = getField(field);
   1333                     reply.writeNoException();
   1334                     reply.writeString(contents);
   1335                     return true;
   1336                 }
   1337                 case TRANSACTION_resizeSecureContainer: {
   1338                     data.enforceInterface(DESCRIPTOR);
   1339                     String id;
   1340                     id = data.readString();
   1341                     int sizeMb;
   1342                     sizeMb = data.readInt();
   1343                     String key;
   1344                     key = data.readString();
   1345                     int resultCode = resizeSecureContainer(id, sizeMb, key);
   1346                     reply.writeNoException();
   1347                     reply.writeInt(resultCode);
   1348                     return true;
   1349                 }
   1350             }
   1351             return super.onTransact(code, data, reply, flags);
   1352         }
   1353     }
   1354 
   1355     /*
   1356      * Creates a secure container with the specified parameters. Returns an int
   1357      * consistent with MountServiceResultCode
   1358      */
   1359     public int createSecureContainer(String id, int sizeMb, String fstype, String key,
   1360             int ownerUid, boolean external) throws RemoteException;
   1361 
   1362     /*
   1363      * Destroy a secure container, and free up all resources associated with it.
   1364      * NOTE: Ensure all references are released prior to deleting. Returns an
   1365      * int consistent with MountServiceResultCode
   1366      */
   1367     public int destroySecureContainer(String id, boolean force) throws RemoteException;
   1368 
   1369     /*
   1370      * Finalize a container which has just been created and populated. After
   1371      * finalization, the container is immutable. Returns an int consistent with
   1372      * MountServiceResultCode
   1373      */
   1374     public int finalizeSecureContainer(String id) throws RemoteException;
   1375 
   1376     /**
   1377      * Call into MountService by PackageManager to notify that its done
   1378      * processing the media status update request.
   1379      */
   1380     public void finishMediaUpdate() throws RemoteException;
   1381 
   1382     /**
   1383      * Format external storage given a mount point. Returns an int consistent
   1384      * with MountServiceResultCode
   1385      */
   1386     public int formatVolume(String mountPoint) throws RemoteException;
   1387 
   1388     /**
   1389      * Gets the path to the mounted Opaque Binary Blob (OBB).
   1390      */
   1391     public String getMountedObbPath(String rawPath) throws RemoteException;
   1392 
   1393     /**
   1394      * Gets an Array of currently known secure container IDs
   1395      */
   1396     public String[] getSecureContainerList() throws RemoteException;
   1397 
   1398     /*
   1399      * Returns the filesystem path of a mounted secure container.
   1400      */
   1401     public String getSecureContainerPath(String id) throws RemoteException;
   1402 
   1403     /**
   1404      * Returns an array of pids with open files on the specified path.
   1405      */
   1406     public int[] getStorageUsers(String path) throws RemoteException;
   1407 
   1408     /**
   1409      * Gets the state of a volume via its mountpoint.
   1410      */
   1411     public String getVolumeState(String mountPoint) throws RemoteException;
   1412 
   1413     /**
   1414      * Checks whether the specified Opaque Binary Blob (OBB) is mounted
   1415      * somewhere.
   1416      */
   1417     public boolean isObbMounted(String rawPath) throws RemoteException;
   1418 
   1419     /*
   1420      * Returns true if the specified container is mounted
   1421      */
   1422     public boolean isSecureContainerMounted(String id) throws RemoteException;
   1423 
   1424     /**
   1425      * Returns true if a USB mass storage host is connected
   1426      */
   1427     public boolean isUsbMassStorageConnected() throws RemoteException;
   1428 
   1429     /**
   1430      * Returns true if a USB mass storage host is enabled (media is shared)
   1431      */
   1432     public boolean isUsbMassStorageEnabled() throws RemoteException;
   1433 
   1434     /**
   1435      * Mounts an Opaque Binary Blob (OBB) with the specified decryption key and
   1436      * only allows the calling process's UID access to the contents.
   1437      * MountService will call back to the supplied IObbActionListener to inform
   1438      * it of the terminal state of the call.
   1439      */
   1440     public void mountObb(String rawPath, String canonicalPath, String key,
   1441             IObbActionListener token, int nonce) throws RemoteException;
   1442 
   1443     /*
   1444      * Mount a secure container with the specified key and owner UID. Returns an
   1445      * int consistent with MountServiceResultCode
   1446      */
   1447     public int mountSecureContainer(String id, String key, int ownerUid, boolean readOnly)
   1448             throws RemoteException;
   1449 
   1450     /**
   1451      * Mount external storage at given mount point. Returns an int consistent
   1452      * with MountServiceResultCode
   1453      */
   1454     public int mountVolume(String mountPoint) throws RemoteException;
   1455 
   1456     /**
   1457      * Registers an IMountServiceListener for receiving async notifications.
   1458      */
   1459     public void registerListener(IMountServiceListener listener) throws RemoteException;
   1460 
   1461     /*
   1462      * Rename an unmounted secure container. Returns an int consistent with
   1463      * MountServiceResultCode
   1464      */
   1465     public int renameSecureContainer(String oldId, String newId) throws RemoteException;
   1466 
   1467     /**
   1468      * Enables / disables USB mass storage. The caller should check actual
   1469      * status of enabling/disabling USB mass storage via StorageEventListener.
   1470      */
   1471     public void setUsbMassStorageEnabled(boolean enable) throws RemoteException;
   1472 
   1473     /**
   1474      * Shuts down the MountService and gracefully unmounts all external media.
   1475      * Invokes call back once the shutdown is complete.
   1476      */
   1477     public void shutdown(IMountShutdownObserver observer) throws RemoteException;
   1478 
   1479     /**
   1480      * Unmounts an Opaque Binary Blob (OBB). When the force flag is specified,
   1481      * any program using it will be forcibly killed to unmount the image.
   1482      * MountService will call back to the supplied IObbActionListener to inform
   1483      * it of the terminal state of the call.
   1484      */
   1485     public void unmountObb(String rawPath, boolean force, IObbActionListener token, int nonce)
   1486             throws RemoteException;
   1487 
   1488     /*
   1489      * Unount a secure container. Returns an int consistent with
   1490      * MountServiceResultCode
   1491      */
   1492     public int unmountSecureContainer(String id, boolean force) throws RemoteException;
   1493 
   1494     /**
   1495      * Safely unmount external storage at given mount point. The unmount is an
   1496      * asynchronous operation. Applications should register StorageEventListener
   1497      * for storage related status changes.
   1498      * @param mountPoint the mount point
   1499      * @param force whether or not to forcefully unmount it (e.g. even if programs are using this
   1500      *     data currently)
   1501      * @param removeEncryption whether or not encryption mapping should be removed from the volume.
   1502      *     This value implies {@code force}.
   1503      */
   1504     public void unmountVolume(String mountPoint, boolean force, boolean removeEncryption)
   1505             throws RemoteException;
   1506 
   1507     /**
   1508      * Unregisters an IMountServiceListener
   1509      */
   1510     public void unregisterListener(IMountServiceListener listener) throws RemoteException;
   1511 
   1512     /**
   1513      * Returns whether or not the external storage is emulated.
   1514      */
   1515     public boolean isExternalStorageEmulated() throws RemoteException;
   1516 
   1517     /** The volume is not encrypted. */
   1518     static final int ENCRYPTION_STATE_NONE = 1;
   1519     /** The volume has been encrypted succesfully. */
   1520     static final int ENCRYPTION_STATE_OK = 0;
   1521     /** The volume is in a bad state.*/
   1522     static final int ENCRYPTION_STATE_ERROR_UNKNOWN = -1;
   1523     /** Encryption is incomplete */
   1524     static final int ENCRYPTION_STATE_ERROR_INCOMPLETE = -2;
   1525     /** Encryption is incomplete and irrecoverable */
   1526     static final int ENCRYPTION_STATE_ERROR_INCONSISTENT = -3;
   1527     /** Underlying data is corrupt */
   1528     static final int ENCRYPTION_STATE_ERROR_CORRUPT = -4;
   1529 
   1530     /**
   1531      * Determines the encryption state of the volume.
   1532      * @return a numerical value. See {@code ENCRYPTION_STATE_*} for possible values.
   1533      */
   1534     public int getEncryptionState() throws RemoteException;
   1535 
   1536     /**
   1537      * Decrypts any encrypted volumes.
   1538      */
   1539     public int decryptStorage(String password) throws RemoteException;
   1540 
   1541     /**
   1542      * Encrypts storage.
   1543      */
   1544     public int encryptStorage(int type, String password) throws RemoteException;
   1545 
   1546     /**
   1547      * Changes the encryption password.
   1548      */
   1549     public int changeEncryptionPassword(int type, String password)
   1550         throws RemoteException;
   1551 
   1552     /**
   1553      * Verify the encryption password against the stored volume.  This method
   1554      * may only be called by the system process.
   1555      */
   1556     public int verifyEncryptionPassword(String password) throws RemoteException;
   1557 
   1558     /**
   1559      * Returns list of all mountable volumes.
   1560      */
   1561     public StorageVolume[] getVolumeList() throws RemoteException;
   1562 
   1563     /**
   1564      * Gets the path on the filesystem for the ASEC container itself.
   1565      *
   1566      * @param cid ASEC container ID
   1567      * @return path to filesystem or {@code null} if it's not found
   1568      * @throws RemoteException
   1569      */
   1570     public String getSecureContainerFilesystemPath(String cid) throws RemoteException;
   1571 
   1572     /*
   1573      * Fix permissions in a container which has just been created and populated.
   1574      * Returns an int consistent with MountServiceResultCode
   1575      */
   1576     public int fixPermissionsSecureContainer(String id, int gid, String filename)
   1577             throws RemoteException;
   1578 
   1579     /**
   1580      * Ensure that all directories along given path exist, creating parent
   1581      * directories as needed. Validates that given path is absolute and that it
   1582      * contains no relative "." or ".." paths or symlinks. Also ensures that
   1583      * path belongs to a volume managed by vold, and that path is either
   1584      * external storage data or OBB directory belonging to calling app.
   1585      */
   1586     public int mkdirs(String callingPkg, String path) throws RemoteException;
   1587 
   1588     /**
   1589      * Determines the type of the encryption password
   1590      * @return PasswordType
   1591      */
   1592     public int getPasswordType() throws RemoteException;
   1593 
   1594     /**
   1595      * Get password from vold
   1596      * @return password or empty string
   1597      */
   1598     public String getPassword() throws RemoteException;
   1599 
   1600     /**
   1601      * Securely clear password from vold
   1602      */
   1603     public void clearPassword() throws RemoteException;
   1604 
   1605     /**
   1606      * Set a field in the crypto header.
   1607      * @param field field to set
   1608      * @param contents contents to set in field
   1609      */
   1610     public void setField(String field, String contents) throws RemoteException;
   1611 
   1612     /**
   1613      * Gets a field from the crypto header.
   1614      * @param field field to get
   1615      * @return contents of field
   1616      */
   1617     public String getField(String field) throws RemoteException;
   1618 
   1619     public int resizeSecureContainer(String id, int sizeMb, String key) throws RemoteException;
   1620 }
   1621