• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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. */
Stub()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          */
asInterface(IBinder obj)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 
asBinder()56         public IBinder asBinder() {
57             return this;
58         }
59 
60         @Override
onTransact(int code, Parcel data, Parcel reply, int flags)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                     final String path = data.readString();
79                     final String oldState = data.readString();
80                     final String newState = data.readString();
81                     this.onStorageStateChanged(path, oldState, newState);
82                     reply.writeNoException();
83                     return true;
84                 }
85                 case TRANSACTION_onVolumeStateChanged: {
86                     data.enforceInterface(DESCRIPTOR);
87                     final VolumeInfo vol = (VolumeInfo) data.readParcelable(null);
88                     final int oldState = data.readInt();
89                     final int newState = data.readInt();
90                     onVolumeStateChanged(vol, oldState, newState);
91                     reply.writeNoException();
92                     return true;
93                 }
94                 case TRANSACTION_onVolumeRecordChanged: {
95                     data.enforceInterface(DESCRIPTOR);
96                     final VolumeRecord rec = (VolumeRecord) data.readParcelable(null);
97                     onVolumeRecordChanged(rec);
98                     reply.writeNoException();
99                     return true;
100                 }
101                 case TRANSACTION_onVolumeForgotten: {
102                     data.enforceInterface(DESCRIPTOR);
103                     final String fsUuid = data.readString();
104                     onVolumeForgotten(fsUuid);
105                     reply.writeNoException();
106                     return true;
107                 }
108                 case TRANSACTION_onDiskScanned: {
109                     data.enforceInterface(DESCRIPTOR);
110                     final DiskInfo disk = (DiskInfo) data.readParcelable(null);
111                     final int volumeCount = data.readInt();
112                     onDiskScanned(disk, volumeCount);
113                     reply.writeNoException();
114                     return true;
115                 }
116                 case TRANSACTION_onDiskDestroyed: {
117                     data.enforceInterface(DESCRIPTOR);
118                     final DiskInfo disk = (DiskInfo) data.readParcelable(null);
119                     onDiskDestroyed(disk);
120                     reply.writeNoException();
121                     return true;
122                 }
123             }
124             return super.onTransact(code, data, reply, flags);
125         }
126 
127         private static class Proxy implements IMountServiceListener {
128             private IBinder mRemote;
129 
Proxy(IBinder remote)130             Proxy(IBinder remote) {
131                 mRemote = remote;
132             }
133 
asBinder()134             public IBinder asBinder() {
135                 return mRemote;
136             }
137 
getInterfaceDescriptor()138             public String getInterfaceDescriptor() {
139                 return DESCRIPTOR;
140             }
141 
142             /**
143              * Detection state of USB Mass Storage has changed
144              *
145              * @param available true if a UMS host is connected.
146              */
onUsbMassStorageConnectionChanged(boolean connected)147             public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException {
148                 Parcel _data = Parcel.obtain();
149                 Parcel _reply = Parcel.obtain();
150                 try {
151                     _data.writeInterfaceToken(DESCRIPTOR);
152                     _data.writeInt(((connected) ? (1) : (0)));
153                     mRemote.transact(Stub.TRANSACTION_onUsbMassStorageConnectionChanged, _data,
154                             _reply, android.os.IBinder.FLAG_ONEWAY);
155                     _reply.readException();
156                 } finally {
157                     _reply.recycle();
158                     _data.recycle();
159                 }
160             }
161 
162             /**
163              * Storage state has changed.
164              *
165              * @param path The volume mount path.
166              * @param oldState The old state of the volume.
167              * @param newState The new state of the volume. Note: State is one
168              *            of the values returned by
169              *            Environment.getExternalStorageState()
170              */
onStorageStateChanged(String path, String oldState, String newState)171             public void onStorageStateChanged(String path, String oldState, String newState)
172                     throws RemoteException {
173                 Parcel _data = Parcel.obtain();
174                 Parcel _reply = Parcel.obtain();
175                 try {
176                     _data.writeInterfaceToken(DESCRIPTOR);
177                     _data.writeString(path);
178                     _data.writeString(oldState);
179                     _data.writeString(newState);
180                     mRemote.transact(Stub.TRANSACTION_onStorageStateChanged, _data, _reply,
181                             android.os.IBinder.FLAG_ONEWAY);
182                     _reply.readException();
183                 } finally {
184                     _reply.recycle();
185                     _data.recycle();
186                 }
187             }
188 
189             @Override
onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)190             public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
191                     throws RemoteException {
192                 Parcel _data = Parcel.obtain();
193                 Parcel _reply = Parcel.obtain();
194                 try {
195                     _data.writeInterfaceToken(DESCRIPTOR);
196                     _data.writeParcelable(vol, 0);
197                     _data.writeInt(oldState);
198                     _data.writeInt(newState);
199                     mRemote.transact(Stub.TRANSACTION_onVolumeStateChanged, _data, _reply,
200                             android.os.IBinder.FLAG_ONEWAY);
201                     _reply.readException();
202                 } finally {
203                     _reply.recycle();
204                     _data.recycle();
205                 }
206             }
207 
208             @Override
onVolumeRecordChanged(VolumeRecord rec)209             public void onVolumeRecordChanged(VolumeRecord rec) throws RemoteException {
210                 Parcel _data = Parcel.obtain();
211                 Parcel _reply = Parcel.obtain();
212                 try {
213                     _data.writeInterfaceToken(DESCRIPTOR);
214                     _data.writeParcelable(rec, 0);
215                     mRemote.transact(Stub.TRANSACTION_onVolumeRecordChanged, _data, _reply,
216                             android.os.IBinder.FLAG_ONEWAY);
217                     _reply.readException();
218                 } finally {
219                     _reply.recycle();
220                     _data.recycle();
221                 }
222             }
223 
224             @Override
onVolumeForgotten(String fsUuid)225             public void onVolumeForgotten(String fsUuid) throws RemoteException {
226                 Parcel _data = Parcel.obtain();
227                 Parcel _reply = Parcel.obtain();
228                 try {
229                     _data.writeInterfaceToken(DESCRIPTOR);
230                     _data.writeString(fsUuid);
231                     mRemote.transact(Stub.TRANSACTION_onVolumeForgotten, _data, _reply,
232                             android.os.IBinder.FLAG_ONEWAY);
233                     _reply.readException();
234                 } finally {
235                     _reply.recycle();
236                     _data.recycle();
237                 }
238             }
239 
240             @Override
onDiskScanned(DiskInfo disk, int volumeCount)241             public void onDiskScanned(DiskInfo disk, int volumeCount) throws RemoteException {
242                 Parcel _data = Parcel.obtain();
243                 Parcel _reply = Parcel.obtain();
244                 try {
245                     _data.writeInterfaceToken(DESCRIPTOR);
246                     _data.writeParcelable(disk, 0);
247                     _data.writeInt(volumeCount);
248                     mRemote.transact(Stub.TRANSACTION_onDiskScanned, _data, _reply,
249                             android.os.IBinder.FLAG_ONEWAY);
250                     _reply.readException();
251                 } finally {
252                     _reply.recycle();
253                     _data.recycle();
254                 }
255             }
256 
257             @Override
onDiskDestroyed(DiskInfo disk)258             public void onDiskDestroyed(DiskInfo disk) throws RemoteException {
259                 Parcel _data = Parcel.obtain();
260                 Parcel _reply = Parcel.obtain();
261                 try {
262                     _data.writeInterfaceToken(DESCRIPTOR);
263                     _data.writeParcelable(disk, 0);
264                     mRemote.transact(Stub.TRANSACTION_onDiskDestroyed, _data, _reply,
265                             android.os.IBinder.FLAG_ONEWAY);
266                     _reply.readException();
267                 } finally {
268                     _reply.recycle();
269                     _data.recycle();
270                 }
271             }
272         }
273 
274         static final int TRANSACTION_onUsbMassStorageConnectionChanged = (IBinder.FIRST_CALL_TRANSACTION + 0);
275         static final int TRANSACTION_onStorageStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 1);
276         static final int TRANSACTION_onVolumeStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 2);
277         static final int TRANSACTION_onVolumeRecordChanged = (IBinder.FIRST_CALL_TRANSACTION + 3);
278         static final int TRANSACTION_onVolumeForgotten = (IBinder.FIRST_CALL_TRANSACTION + 4);
279         static final int TRANSACTION_onDiskScanned = (IBinder.FIRST_CALL_TRANSACTION + 5);
280         static final int TRANSACTION_onDiskDestroyed = (IBinder.FIRST_CALL_TRANSACTION + 6);
281     }
282 
283     /**
284      * Detection state of USB Mass Storage has changed
285      *
286      * @param available true if a UMS host is connected.
287      */
onUsbMassStorageConnectionChanged(boolean connected)288     public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException;
289 
290     /**
291      * Storage state has changed.
292      *
293      * @param path The volume mount path.
294      * @param oldState The old state of the volume.
295      * @param newState The new state of the volume. Note: State is one of the
296      *            values returned by Environment.getExternalStorageState()
297      */
onStorageStateChanged(String path, String oldState, String newState)298     public void onStorageStateChanged(String path, String oldState, String newState)
299             throws RemoteException;
300 
onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)301     public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
302             throws RemoteException;
onVolumeRecordChanged(VolumeRecord rec)303     public void onVolumeRecordChanged(VolumeRecord rec) throws RemoteException;
onVolumeForgotten(String fsUuid)304     public void onVolumeForgotten(String fsUuid) throws RemoteException;
305 
onDiskScanned(DiskInfo disk, int volumeCount)306     public void onDiskScanned(DiskInfo disk, int volumeCount) throws RemoteException;
307 
onDiskDestroyed(DiskInfo disk)308     public void onDiskDestroyed(DiskInfo disk) throws RemoteException;
309 }
310