Home | History | Annotate | Download | only in storage
      1 /*
      2  * Copyright (C) 2009 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  * Callback class for receiving events from MountService.
     27  *
     28  * @hide - Applications should use IStorageEventListener for storage event
     29  *       callbacks.
     30  */
     31 public interface IMountServiceListener extends IInterface {
     32     /** Local-side IPC implementation stub class. */
     33     public static abstract class Stub extends Binder implements IMountServiceListener {
     34         private static final String DESCRIPTOR = "IMountServiceListener";
     35 
     36         /** Construct the stub at attach it to the interface. */
     37         public Stub() {
     38             this.attachInterface(this, DESCRIPTOR);
     39         }
     40 
     41         /**
     42          * Cast an IBinder object into an IMountServiceListener interface,
     43          * generating a proxy if needed.
     44          */
     45         public static IMountServiceListener asInterface(IBinder obj) {
     46             if ((obj == null)) {
     47                 return null;
     48             }
     49             IInterface iin = (IInterface) obj.queryLocalInterface(DESCRIPTOR);
     50             if (((iin != null) && (iin instanceof IMountServiceListener))) {
     51                 return ((IMountServiceListener) iin);
     52             }
     53             return new IMountServiceListener.Stub.Proxy(obj);
     54         }
     55 
     56         public IBinder asBinder() {
     57             return this;
     58         }
     59 
     60         @Override
     61         public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
     62                 throws RemoteException {
     63             switch (code) {
     64                 case INTERFACE_TRANSACTION: {
     65                     reply.writeString(DESCRIPTOR);
     66                     return true;
     67                 }
     68                 case TRANSACTION_onUsbMassStorageConnectionChanged: {
     69                     data.enforceInterface(DESCRIPTOR);
     70                     boolean connected;
     71                     connected = (0 != data.readInt());
     72                     this.onUsbMassStorageConnectionChanged(connected);
     73                     reply.writeNoException();
     74                     return true;
     75                 }
     76                 case TRANSACTION_onStorageStateChanged: {
     77                     data.enforceInterface(DESCRIPTOR);
     78                     String path;
     79                     path = data.readString();
     80                     String oldState;
     81                     oldState = data.readString();
     82                     String newState;
     83                     newState = data.readString();
     84                     this.onStorageStateChanged(path, oldState, newState);
     85                     reply.writeNoException();
     86                     return true;
     87                 }
     88             }
     89             return super.onTransact(code, data, reply, flags);
     90         }
     91 
     92         private static class Proxy implements IMountServiceListener {
     93             private IBinder mRemote;
     94 
     95             Proxy(IBinder remote) {
     96                 mRemote = remote;
     97             }
     98 
     99             public IBinder asBinder() {
    100                 return mRemote;
    101             }
    102 
    103             public String getInterfaceDescriptor() {
    104                 return DESCRIPTOR;
    105             }
    106 
    107             /**
    108              * Detection state of USB Mass Storage has changed
    109              *
    110              * @param available true if a UMS host is connected.
    111              */
    112             public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException {
    113                 Parcel _data = Parcel.obtain();
    114                 Parcel _reply = Parcel.obtain();
    115                 try {
    116                     _data.writeInterfaceToken(DESCRIPTOR);
    117                     _data.writeInt(((connected) ? (1) : (0)));
    118                     mRemote.transact(Stub.TRANSACTION_onUsbMassStorageConnectionChanged, _data,
    119                             _reply, 0);
    120                     _reply.readException();
    121                 } finally {
    122                     _reply.recycle();
    123                     _data.recycle();
    124                 }
    125             }
    126 
    127             /**
    128              * Storage state has changed.
    129              *
    130              * @param path The volume mount path.
    131              * @param oldState The old state of the volume.
    132              * @param newState The new state of the volume. Note: State is one
    133              *            of the values returned by
    134              *            Environment.getExternalStorageState()
    135              */
    136             public void onStorageStateChanged(String path, String oldState, String newState)
    137                     throws RemoteException {
    138                 Parcel _data = Parcel.obtain();
    139                 Parcel _reply = Parcel.obtain();
    140                 try {
    141                     _data.writeInterfaceToken(DESCRIPTOR);
    142                     _data.writeString(path);
    143                     _data.writeString(oldState);
    144                     _data.writeString(newState);
    145                     mRemote.transact(Stub.TRANSACTION_onStorageStateChanged, _data, _reply, 0);
    146                     _reply.readException();
    147                 } finally {
    148                     _reply.recycle();
    149                     _data.recycle();
    150                 }
    151             }
    152         }
    153 
    154         static final int TRANSACTION_onUsbMassStorageConnectionChanged = (IBinder.FIRST_CALL_TRANSACTION + 0);
    155 
    156         static final int TRANSACTION_onStorageStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 1);
    157     }
    158 
    159     /**
    160      * Detection state of USB Mass Storage has changed
    161      *
    162      * @param available true if a UMS host is connected.
    163      */
    164     public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException;
    165 
    166     /**
    167      * Storage state has changed.
    168      *
    169      * @param path The volume mount path.
    170      * @param oldState The old state of the volume.
    171      * @param newState The new state of the volume. Note: State is one of the
    172      *            values returned by Environment.getExternalStorageState()
    173      */
    174     public void onStorageStateChanged(String path, String oldState, String newState)
    175             throws RemoteException;
    176 }
    177