IMountServiceListener.java revision 50a05454795c93ac483f5cb6819e74cb17be1b5b
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
17package android.os.storage;
18
19import android.os.Binder;
20import android.os.IBinder;
21import android.os.IInterface;
22import android.os.Parcel;
23import 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 */
31public 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                    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            }
117            return super.onTransact(code, data, reply, flags);
118        }
119
120        private static class Proxy implements IMountServiceListener {
121            private IBinder mRemote;
122
123            Proxy(IBinder remote) {
124                mRemote = remote;
125            }
126
127            public IBinder asBinder() {
128                return mRemote;
129            }
130
131            public String getInterfaceDescriptor() {
132                return DESCRIPTOR;
133            }
134
135            /**
136             * Detection state of USB Mass Storage has changed
137             *
138             * @param available true if a UMS host is connected.
139             */
140            public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException {
141                Parcel _data = Parcel.obtain();
142                Parcel _reply = Parcel.obtain();
143                try {
144                    _data.writeInterfaceToken(DESCRIPTOR);
145                    _data.writeInt(((connected) ? (1) : (0)));
146                    mRemote.transact(Stub.TRANSACTION_onUsbMassStorageConnectionChanged, _data,
147                            _reply, android.os.IBinder.FLAG_ONEWAY);
148                    _reply.readException();
149                } finally {
150                    _reply.recycle();
151                    _data.recycle();
152                }
153            }
154
155            /**
156             * Storage state has changed.
157             *
158             * @param path The volume mount path.
159             * @param oldState The old state of the volume.
160             * @param newState The new state of the volume. Note: State is one
161             *            of the values returned by
162             *            Environment.getExternalStorageState()
163             */
164            public void onStorageStateChanged(String path, String oldState, String newState)
165                    throws RemoteException {
166                Parcel _data = Parcel.obtain();
167                Parcel _reply = Parcel.obtain();
168                try {
169                    _data.writeInterfaceToken(DESCRIPTOR);
170                    _data.writeString(path);
171                    _data.writeString(oldState);
172                    _data.writeString(newState);
173                    mRemote.transact(Stub.TRANSACTION_onStorageStateChanged, _data, _reply,
174                            android.os.IBinder.FLAG_ONEWAY);
175                    _reply.readException();
176                } finally {
177                    _reply.recycle();
178                    _data.recycle();
179                }
180            }
181
182            @Override
183            public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
184                    throws RemoteException {
185                Parcel _data = Parcel.obtain();
186                Parcel _reply = Parcel.obtain();
187                try {
188                    _data.writeInterfaceToken(DESCRIPTOR);
189                    _data.writeParcelable(vol, 0);
190                    _data.writeInt(oldState);
191                    _data.writeInt(newState);
192                    mRemote.transact(Stub.TRANSACTION_onVolumeStateChanged, _data, _reply,
193                            android.os.IBinder.FLAG_ONEWAY);
194                    _reply.readException();
195                } finally {
196                    _reply.recycle();
197                    _data.recycle();
198                }
199            }
200
201            @Override
202            public void onVolumeRecordChanged(VolumeRecord rec) throws RemoteException {
203                Parcel _data = Parcel.obtain();
204                Parcel _reply = Parcel.obtain();
205                try {
206                    _data.writeInterfaceToken(DESCRIPTOR);
207                    _data.writeParcelable(rec, 0);
208                    mRemote.transact(Stub.TRANSACTION_onVolumeRecordChanged, _data, _reply,
209                            android.os.IBinder.FLAG_ONEWAY);
210                    _reply.readException();
211                } finally {
212                    _reply.recycle();
213                    _data.recycle();
214                }
215            }
216
217            @Override
218            public void onVolumeForgotten(String fsUuid) throws RemoteException {
219                Parcel _data = Parcel.obtain();
220                Parcel _reply = Parcel.obtain();
221                try {
222                    _data.writeInterfaceToken(DESCRIPTOR);
223                    _data.writeString(fsUuid);
224                    mRemote.transact(Stub.TRANSACTION_onVolumeForgotten, _data, _reply,
225                            android.os.IBinder.FLAG_ONEWAY);
226                    _reply.readException();
227                } finally {
228                    _reply.recycle();
229                    _data.recycle();
230                }
231            }
232
233            @Override
234            public void onDiskScanned(DiskInfo disk, int volumeCount) throws RemoteException {
235                Parcel _data = Parcel.obtain();
236                Parcel _reply = Parcel.obtain();
237                try {
238                    _data.writeInterfaceToken(DESCRIPTOR);
239                    _data.writeParcelable(disk, 0);
240                    _data.writeInt(volumeCount);
241                    mRemote.transact(Stub.TRANSACTION_onDiskScanned, _data, _reply,
242                            android.os.IBinder.FLAG_ONEWAY);
243                    _reply.readException();
244                } finally {
245                    _reply.recycle();
246                    _data.recycle();
247                }
248            }
249        }
250
251        static final int TRANSACTION_onUsbMassStorageConnectionChanged = (IBinder.FIRST_CALL_TRANSACTION + 0);
252        static final int TRANSACTION_onStorageStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 1);
253        static final int TRANSACTION_onVolumeStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 2);
254        static final int TRANSACTION_onVolumeRecordChanged = (IBinder.FIRST_CALL_TRANSACTION + 3);
255        static final int TRANSACTION_onVolumeForgotten = (IBinder.FIRST_CALL_TRANSACTION + 4);
256        static final int TRANSACTION_onDiskScanned = (IBinder.FIRST_CALL_TRANSACTION + 5);
257    }
258
259    /**
260     * Detection state of USB Mass Storage has changed
261     *
262     * @param available true if a UMS host is connected.
263     */
264    public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException;
265
266    /**
267     * Storage state has changed.
268     *
269     * @param path The volume mount path.
270     * @param oldState The old state of the volume.
271     * @param newState The new state of the volume. Note: State is one of the
272     *            values returned by Environment.getExternalStorageState()
273     */
274    public void onStorageStateChanged(String path, String oldState, String newState)
275            throws RemoteException;
276
277    public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
278            throws RemoteException;
279    public void onVolumeRecordChanged(VolumeRecord rec) throws RemoteException;
280    public void onVolumeForgotten(String fsUuid) throws RemoteException;
281
282    public void onDiskScanned(DiskInfo disk, int volumeCount) throws RemoteException;
283}
284